X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fuser.func.inc.php;h=4c4373158f319eb0b55b2b9a42e8afdc43b5d092;hb=a1ee34a40854bad35ee0663f17352ec51ab83365;hp=7da7ada2c8e3b0dce0aeacd7df3bc1a180468c97;hpb=21c7c593d7100a887f984c49a82c03eb32169fc4;p=platal.git diff --git a/include/user.func.inc.php b/include/user.func.inc.php index 7da7ada..4c43731 100644 --- a/include/user.func.inc.php +++ b/include/user.func.inc.php @@ -103,8 +103,10 @@ function get_not_registered_user($login, $iterator = false) return null; } @list($prenom, $nom, $promo) = explode('.', $login); - $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%") - AND REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "") LIKE CONCAT("%", {?}, "%")'; + $where = 'REPLACE(REPLACE(REPLACE(nom, " ", ""), "-", ""), "\'", "") + LIKE CONCAT("%", REPLACE(REPLACE(REPLACE({?}, " ", ""), "-", ""), "\'", ""), "%") + AND REPLACE(REPLACE(REPLACE(prenom, " ", ""), "-", ""), "\'", "") + LIKE CONCAT("%", REPLACE(REPLACE(REPLACE({?}, " ", ""), "-", ""), "\'", ""), "%")'; if ($promo) { if (preg_match('/^[0-9]{2}$/', $promo)) { $where .= 'AND MOD(promo, 100) = {?}'; @@ -528,18 +530,17 @@ function remove_user_pro($uid, $entrid) { // }}} // {{{ function set_user_details() function set_user_details_addresses($uid, $adrs) { - $res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND adrid >= 1 ORDER BY adrid", $uid); - $adrids = $res->fetchColumn(); + $req = XDB::query('SELECT MAX(adrid) + 1 + FROM adresses + WHERE uid = {?}', $uid); + $adrid = $req->fetchOneCell(); + if (is_null($adrid)) { + $adrid = 0; + } foreach ($adrs as $adr) { - if (isset($adr['adrid']) && isset($adr['remove']) && $adr['remove']) { - remove_user_address($uid, $adr['adrid']); - if (isset($adrids[$adr['adrid']])) unset($adrids[$adr['adrid']]); - } else if (isset($adr['adrid'])) { - update_user_address($uid, $adr['adrid'], $adr); - } else { - for ($adrid = 1; isset($adrids[$adrid-1]) && ($adrids[$adrid-1] == $adrid); $adrid++); + if (!@$adr['remove']) { add_user_address($uid, $adrid, $adr); - $adrids[$adrid-1] = $adrid; + ++$adrid; } } require_once 'geoloc.inc.php'; @@ -550,17 +551,17 @@ function set_user_details_addresses($uid, $adrs) { function set_user_details_pro($uid, $pros) { - $res = XDB::query("SELECT entrid FROM entreprises WHERE uid = {?} ORDER BY entrid", $uid); - $entrids = $res->fetchColumn(); + $req = XDB::query('SELECT MAX(entrid) + 1 + FROM entreprises + WHERE uid = {?}', $uid); + $entrid = $req->fetchOneCell(); + if (is_null($entrid)) { + $entrid = 0; + } foreach ($pros as $pro) { - if (isset($pro['entrid']) && isset($pro['remove']) && $pro['remove']) { - remove_user_pro($uid, $pro['entrid']); - if (isset($entrids[$pro['entrid']])) unset($entrids[$pro['entrid']]); - } else if (isset($pro['entrid'])) { - update_user_pro($uid, $pro['entrid'], $pro); - } else { - for ($entrid = 0; isset($entrids[$entrid]) && ($entrids[$entrid] == $entrid); $entrid++); + if (!@$pro['remove']) { add_user_pro($uid, $entrid, $pro); + ++$entrid; } } }