X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Faddresses.inc.php;h=49b7f959777569062e395e764e8abc8e7441e611;hb=98e827e273c7c5e473c0c8a4839efc4c5bb1225b;hp=4243527cca00d3273a29c824d65497aeacb2ef11;hpb=9a1cb88385e06f1ce1514a367d6b1bbfd3780e44;p=platal.git diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index 4243527..49b7f95 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -1,6 +1,6 @@ pub = new ProfilePub(); } - private function geolocAddress(array &$address, &$success) + private function cleanAddress(ProfilePage &$page, $addrid, array &$address) { - require_once 'geoloc.inc.php'; - $success = true; - if (@$address['parsevalid'] || (@$address['text'] && @$address['changed']) || !@$address['cityid']) { - $address = array_merge($address, empty_address()); - $new = get_address_infos(@$address['text']); - if (compare_addresses_text(@$adress['text'], $geotxt = get_address_text($new)) - || @$address['parsevalid']) { - $address = array_merge($address, $new); - } else { - $success = false; - $address = array_merge($address, cut_address(@$address['text'])); - $address['geoloc'] = $geotxt; - $address['geoloc_cityid'] = $new['cityid']; - } - } - if (@$address['changed']) { - $address['datemaj'] = time(); - } - $address['text'] = get_address_text($address); - } - - private function cleanAddress(ProfilePage &$page, array &$address) - { - if (@$address['changed']) { - $address['datemaj'] = time(); - } - foreach ($address['tel'] as $t=>&$tel) { - if (@$tel['removed'] || !trim($tel['tel'])) { - unset($address['tel'][$t]); - } else { - $tel['pub'] = $this->pub->value($page, 'pub', $tel['pub'], $success); - } - unset($tel['removed']); - } - if (@$address['changed']) { - $address['datemaj'] = time(); - } - $success = true; - $address['secondaire'] = $this->bool->value($page, 'secondaire', $address['secondaire'], $success); - $address['mail'] = $this->bool->value($page, 'mail', $address['mail'], $success); - $address['temporary'] = $this->bool->value($page, 'temporary', $address['temporary'], $success); - $address['current'] = $this->bool->value($page, 'current', @$address['current'], $success); - $address['pub'] = $this->pub->value($page, 'pub', $address['pub'], $success); - unset($address['parsevalid']); - unset($address['changed']); - unset($address['removed']); - unset($address['display']); + if (!isset($address['tel'])) { + $address['tel'] = array(); + } + $profiletel = new ProfilePhones('address', $addrid); + $address['tel'] = $profiletel->value($page, 'tel', $address['tel'], $s); + $address['current'] = $this->bool->value($page, 'current', $address['current'], $s); + $address['temporary'] = $this->bool->value($page, 'temporary', $address['temporary'], $s); + $address['secondary'] = $this->bool->value($page, 'secondary', $address['secondary'], $s); + $address['mail'] = $this->bool->value($page, 'mail', $address['mail'], $s); + $address['pub'] = $this->pub->value($page, 'pub', $address['pub'], $s); } public function value(ProfilePage &$page, $field, $value, &$success) @@ -86,93 +49,102 @@ class ProfileAddress $init = false; if (is_null($value)) { $value = $page->values['addresses']; - $init = true; + $init = true; } - foreach ($value as $key=>&$adr) { - if (@$adr['removed']) { + foreach ($value as $key => &$address) { + if (isset($address['removed']) && $address['removed']) { unset($value[$key]); } } $current = 0; - foreach ($value as $key=>&$adr) { - if (@$adr['current']) { + $success = true; + foreach ($value as $key => &$address) { + if (isset($address['current']) && $address['current']) { $current++; } } - if (!$init && $current != 1 && count($value) > 0) { + if ($current == 0 && count($value) > 0) { + foreach ($value as $address) { + $address['current'] = true; + break; + } + } elseif ($current > 1) { $success = false; - } else { - $success = true; } - foreach ($value as $key=>&$adr) { - $this->geolocAddress($adr, $s); - $this->cleanAddress($page, $adr); - if (!$init) { - $success = $success && $s; - } - if (!trim($adr['text'])) { + foreach ($value as $key => &$address) { + if (!trim($address['text'])) { unset($value[$key]); + } elseif (!$init) { + $this->geocodeAddress($address, $s); + $success = $success && $s; } + $this->cleanAddress($page, $key, $address); } return $value; } - private function saveTel($adrid, $telid, array &$tel) + private function saveTel($addrid, $telid, array &$tel) { - XDB::execute("INSERT INTO tels (uid, adrid, telid, - tel_type, tel_pub, tel) - VALUES ({?}, {?}, {?}, + XDB::execute("INSERT INTO profile_phones (uid, link_type, link_id, tel_id, tel_type, + search_tel, display_tel, pub) + VALUES ({?}, 'address', {?}, {?}, {?}, {?}, {?}, {?})", - S::i('uid'), $adrid, $telid, - $tel['type'], $tel['pub'], $tel['tel']); + S::i('uid'), $addrid, $telid, $tel['type'], + format_phone_number($tel['tel']), $tel['tel'], $tel['pub']); } - private function saveAddress($adrid, array &$address) + public function saveAddress($addrid, array &$address, $type) { - $flags = array(); - if ($address['secondaire']) { - $flags[] = 'res-secondaire'; - } - if ($address['mail']) { - $flags[] = 'courrier'; + require_once "geocoding.inc.php"; + + $flags = new PlFlagSet(); + if ($address['current']) { + $flags->addFlag('current'); } if ($address['temporary']) { - $flags[] = 'temporaire'; - } - if ($address['current']) { - $flags[] = 'active'; + $flags->addFlag('temporary'); } - $flags = implode(',', $flags); - XDB::execute("INSERT INTO adresses (adr1, adr2, adr3, - postcode, city, cityid, - country, region, regiontxt, - pub, datemaj, statut, - uid, adrid) - VALUES ({?}, {?}, {?}, - {?}, {?}, {?}, - {?}, {?}, {?}, - {?}, FROM_UNIXTIME({?}), {?}, - {?}, {?})", - $address['adr1'], $address['adr2'], $address['adr3'], - $address['postcode'], $address['city'], $address['cityid'], - $address['country'], $address['region'], $address['regiontxt'], - $address['pub'], $address['datemaj'], $flags, - S::i('uid'), $adrid); - foreach ($address['tel'] as $telid=>&$tel) { - $this->saveTel($adrid, $telid, $tel); + if ($address['secondary']) { + $flags->addFlag('secondary'); } + if ($address['mail']) { + $flags->addFlag('mail'); + } + if ($address['cedex'] = + (strpos(strtoupper(preg_replace(array("/[0-9,\"'#~:;_\- ]/", "/\r\n/"), + array("", "\n"), $address['text'])), 'CEDEX')) !== false) { + $flags->addFlag('cedex'); + } + Geocoder::getAreaId($address, "administrativeArea"); + Geocoder::getAreaId($address, "subAdministrativeArea"); + Geocoder::getAreaId($address, "locality"); + XDB::execute("INSERT INTO profile_addresses (pid, type, id, flags, accuracy, + text, postalText, postalCode, localityId, + subAdministrativeAreaId, administrativeAreaId, + countryId, latitude, longitude, updateTime, pub, comment, + north, south, east, west) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, + {?}, {?}, FROM_UNIXTIME({?}), {?}, {?}, {?}, {?}, {?}, {?})", + S::i('uid'), $type, $addrid, $flags, $address['accuracy'], + $address['text'], $address['postalText'], $address['postalCode'], $address['localityId'], + $address['subAdministrativeAreaId'], $address['administrativeAreaId'], + $address['countryId'], $address['latitude'], $address['longitude'], + $address['updateTime'], $address['pub'], $address['comment'], + $address['north'], $address['south'], $address['east'], $address['west']); } public function save(ProfilePage &$page, $field, $value) { - XDB::execute("DELETE FROM adresses - WHERE uid = {?}", + XDB::execute("DELETE FROM profile_addresses + WHERE pid = {?} AND type = 'home'", S::i('uid')); - XDB::execute("DELETE FROM tels - WHERE uid = {?}", + XDB::execute("DELETE FROM profile_phones + WHERE uid = {?} AND link_type = 'address'", S::i('uid')); - foreach ($value as $adrid=>&$address) { - $this->saveAddress($adrid, $address); + foreach ($value as $addrid => &$address) { + $this->saveAddress($addrid, $address, 'home'); + $profiletel = new ProfilePhones('address', $addrid); + $profiletel->saveTels('tel', $address['tel']); } } } @@ -185,27 +157,23 @@ class ProfileAddresses extends ProfilePage { parent::__construct($wiz); $this->settings['addresses'] = new ProfileAddress(); + $this->watched['addresses'] = true; } - protected function fetchData() + protected function _fetchData() { - if (count($this->orig) > 0) { - $this->values = $this->orig; - return; - } - // Build the addresses tree - $res = XDB::query("SELECT a.adrid AS id, a.adr1, a.adr2, a.adr3, - UNIX_TIMESTAMP(a.datemaj) AS datemaj, - a.postcode, a.city, a.cityid, a.region, a.regiontxt, - a.pub, a.country, gp.pays AS countrytxt, gp.display, - FIND_IN_SET('res-secondaire', a.statut) AS secondaire, - FIND_IN_SET('courrier', a.statut) AS mail, - FIND_IN_SET('temporaire', a.statut) AS temporary, - FIND_IN_SET('active', a.statut) AS current - FROM adresses AS a - INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country) - WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) - ORDER BY adrid", + $res = XDB::query("SELECT id, accuracy, text, postalText, + postalCode, localityId, subAdministrativeAreaId, administrativeAreaId, + countryId, latitude, longitude, pub, comment, updateTime, + north, south, east, west, + FIND_IN_SET('current', flags) AS current, + FIND_IN_SET('temporary', flags) AS temporary, + FIND_IN_SET('secondary', flags) AS secondary, + FIND_IN_SET('mail', flags) AS mail, + FIND_IN_SET('cedex', flags) AS cedex + FROM profile_addresses + WHERE pid = {?} AND type = 'home' + ORDER BY id", S::i('uid')); if ($res->numRows() == 0) { $this->values['addresses'] = array(); @@ -213,16 +181,16 @@ class ProfileAddresses extends ProfilePage $this->values['addresses'] = $res->fetchAllAssoc(); } - $res = XDB::iterator("SELECT adrid, tel_type AS type, tel_pub AS pub, tel - FROM tels - WHERE uid = {?} - ORDER BY adrid", + $res = XDB::iterator("SELECT link_id AS addrid, tel_type AS type, pub, display_tel AS tel, comment + FROM profile_phones + WHERE uid = {?} AND link_type = 'address' + ORDER BY link_id", S::i('uid')); $i = 0; $adrNb = count($this->values['addresses']); while ($tel = $res->next()) { - $adrid = $tel['adrid']; - unset($tel['adrid']); + $adrid = $tel['addrid']; + unset($tel['addrid']); while ($i < $adrNb && $this->values['addresses'][$i]['id'] < $adrid) { $i++; } @@ -237,13 +205,12 @@ class ProfileAddresses extends ProfilePage $address['tel'][] = $tel; } } - foreach ($this->values['addresses'] as $id=>&$address) { + foreach ($this->values['addresses'] as $id => &$address) { if (!isset($address['tel'])) { $address['tel'] = array(); } unset($address['id']); } - parent::fetchData(); } }