Пример #1
0
function updateAddress($addr, $keep_photo = true)
{
    global $keep_history, $domain_id, $base_from_where, $table, $table_grp_adr, $table_groups, $only_phone;
    $addresses = Addresses::withID($addr['id']);
    $resultsnumber = $addresses->count();
    $homepage = str_replace('http://', '', $addr['homepage']);
    $is_valid = $resultsnumber > 0;
    if ($is_valid) {
        if ($keep_history) {
            // Get current photo, if "$keep_photo"
            if ($keep_photo) {
                $r = $addresses->nextAddress()->getData();
                $addr['photo'] = $r['photo'];
            }
            $sql = "UPDATE {$table}\n\t               SET deprecated = now()\n\t\t           WHERE deprecated is null\n\t\t             AND id\t       = '" . $addr['id'] . "'\n\t\t             AND domain_id = '" . $domain_id . "';";
            $result = mysql_query($sql);
            saveAddress($addr);
        } else {
            $sql = "UPDATE {$table} SET firstname = '" . $addr['firstname'] . "'\n\t                            , lastname  = '" . $addr['lastname'] . "'\n\t                            , middlename  = '" . $addr['middlename'] . "'\n\t                            , nickname  = '" . $addr['nickname'] . "'\n\t                            , company   = '" . $addr['company'] . "'\n\t                            , title     = '" . $addr['title'] . "'\n\t                            , address   = '" . $addr['address'] . "'\n\t                            , home      = '" . $addr['home'] . "'\n\t                            , mobile    = '" . $addr['mobile'] . "'\n\t                            , work      = '" . $addr['work'] . "'\n\t                            , fax       = '" . $addr['fax'] . "'\n\t                            , email     = '" . $addr['email'] . "'\n\t                            , email2    = '" . $addr['email2'] . "'\n\t                            , email3    = '" . $addr['email3'] . "'\n\t                            , homepage  = '" . $addr['homepage'] . "'\n\t                            , aday      = '" . $addr['aday'] . "'\n\t                            , amonth    = '" . $addr['amonth'] . "'\n\t                            , ayear     = '" . $addr['ayear'] . "'\n\t                            , bday      = '" . $addr['bday'] . "'\n\t                            , bmonth    = '" . $addr['bmonth'] . "'\n\t                            , byear     = '" . $addr['byear'] . "'\n\t                            , address2  = '" . $addr['address2'] . "'\n\t                            , phone2    = '" . $addr['phone2'] . "'\n\t                            , notes     = '" . $addr['notes'] . "'\n\t    " . ($keep_photo ? "" : ", photo     = '" . $addr['photo'] . "'") . "\n\t                            , modified  = now()\n\t\t                        WHERE id        = '" . $addr['id'] . "'\n\t\t                          AND domain_id = '{$domain_id}';";
            $result = mysql_query($sql);
        }
        // header("Location: view?id=$id");
    }
    return $is_valid;
}