X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fprofile%2Faddresses.inc.php;h=27c2362cfa3b9fadc2b422b7332caf2330945a02;hb=10a574ea3b9a39b61ca7280278be7fe2b84aa3d0;hp=c94e1192d67d7daa58c0bda1b7f7cca17b6ee4f8;hpb=c6a7beb27785ec788a90d86124960b1b92d79cf4;p=platal.git diff --git a/modules/profile/addresses.inc.php b/modules/profile/addresses.inc.php index c94e119..27c2362 100644 --- a/modules/profile/addresses.inc.php +++ b/modules/profile/addresses.inc.php @@ -1,6 +1,6 @@ bool = new ProfileBool(); - $this->pub = new ProfilePub(); - } - - private function geolocAddress(array &$address, &$success) + public function value(ProfilePage &$page, $field, $value, &$success) { - 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); - } + $addresses = array(); - 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']); - } - - public function value(ProfilePage &$page, $field, $value, &$success) - { - $init = false; if (is_null($value)) { - $value = $page->values['addresses']; - $init = true; - } - foreach ($value as $key=>&$adr) { - if (@$adr['removed']) { - unset($value[$key]); - } - } - $success = true; - foreach ($value as $key=>&$adr) { - $this->geolocAddress($adr, $s); - $this->cleanAddress($page, $adr); - if (!$init) { - $success = $success && $s; + $it = Address::iterate(array($page->pid()), array(Address::LINK_PROFILE), array(0)); + while ($address = $it->next()) { + $addresses[] = $address->toFormArray(); } - if (!trim($adr['text'])) { - unset($value[$key]); + if (count($addresses) == 0) { + $address = new Address(); + $addresses[] = $address->toFormArray(); } + return $addresses; } - return $value; - } - private function saveTel($adrid, $telid, array &$tel) - { - XDB::execute("INSERT INTO tels (uid, adrid, telid, - tel_type, tel_pub, tel) - VALUES ({?}, {?}, {?}, - {?}, {?}, {?})", - S::i('uid'), $adrid, $telid, - $tel['type'], $tel['pub'], $tel['tel']); + return Address::formatFormArray($value, $success); } - private function saveAddress($adrid, array &$address) + public function save(ProfilePage &$page, $field, $value) { - $flags = array(); - if ($address['secondaire']) { - $flags[] = 'res-secondaire'; - } - if ($address['mail']) { - $flags[] = 'courrier'; - } - if ($address['temporary']) { - $flags[] = 'temporaire'; - } - if ($address['current']) { - $flags[] = 'active'; - } - $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); - } + Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS); + Address::delete($page->pid(), Address::LINK_PROFILE); + Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE); } - public function save(ProfilePage &$page, $field, $value) + public function getText($value) { - XDB::execute("DELETE FROM adresses - WHERE uid = {?}", - S::i('uid')); - XDB::execute("DELETE FROM tels - WHERE uid = {?}", - S::i('uid')); - foreach ($value as $adrid=>&$address) { - $this->saveAddress($adrid, $address); - } + return Address::formArrayToString($value); } } -class ProfileAddresses extends ProfilePage +class ProfilePageAddresses extends ProfilePage { protected $pg_template = 'profile/adresses.tpl'; public function __construct(PlWizard &$wiz) { parent::__construct($wiz); - $this->settings['addresses'] = new ProfileAddress(); - } - - 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", - S::i('uid')); - if ($res->numRows() == 0) { - $this->values['addresses'] = array(); - } else { - $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", - S::i('uid')); - $i = 0; - $adrNb = count($this->values['addresses']); - while ($tel = $res->next()) { - $adrid = $tel['adrid']; - unset($tel['adrid']); - while ($i < $adrNb && $this->values['addresses'][$i]['id'] < $adrid) { - $i++; - } - if ($i >= $adrNb) { - break; - } - $address =& $this->values['addresses'][$i]; - if (!isset($address['tel'])) { - $address['tel'] = array(); - } - if ($address['id'] == $adrid) { - $address['tel'][] = $tel; - } - } - foreach ($this->values['addresses'] as $id=>&$address) { - if (!isset($address['tel'])) { - $address['tel'] = array(); - } - unset($address['id']); - } - parent::fetchData(); + $this->settings['addresses'] = new ProfileSettingAddresses(); + $this->watched['addresses'] = true; } }