<?php
/***************************************************************************
- * Copyright (C) 2003-2009 Polytechnique.org *
+ * Copyright (C) 2003-2010 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-class ProfileAddress extends ProfileGeocoding
+class ProfileSettingAddress extends ProfileSettingGeocoding
{
private $bool;
private $pub;
public function __construct()
{
- $this->bool = new ProfileBool();
- $this->pub = new ProfilePub();
+ $this->bool = new ProfileSettingBool();
+ $this->pub = new ProfileSettingPub();
}
private function cleanAddress(ProfilePage &$page, $addrid, array &$address)
{
- if (!isset($address['tel'])) {
- $address['tel'] = array();
- }
- $profiletel = new ProfilePhones('address', $addrid);
- $address['tel'] = $profiletel->value($page, 'tel', $address['tel'], $s);
+ $address['tel'] = Phone::formatFormArray($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);
}
foreach ($value as $key => &$address) {
if (isset($address['removed']) && $address['removed']) {
- unset($value[$key]);
+ array_splice($value, $key, 1);
}
}
$current = 0;
}
}
if ($current == 0 && count($value) > 0) {
- foreach ($value as $address) {
+ foreach ($value as &$address) {
$address['current'] = true;
break;
}
return $value;
}
- private function saveAddress($pid, $addrid, array &$address, $type)
+ public function saveAddress($pid, $addrid, array &$address, $type)
{
- require_once "geocoding.inc.php";
+ require_once 'geocoding.inc.php';
$flags = new PlFlagSet();
$flags->addFlag('current', $address['current']);
XDB::execute("DELETE FROM profile_addresses
WHERE pid = {?} AND type = 'home'",
$page->pid());
- XDB::execute("DELETE FROM profile_phones
- WHERE uid = {?} AND link_type = 'address'",
- $page->pid());
+ Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS);
foreach ($value as $addrid => &$address) {
$this->saveAddress($page->pid(), $addrid, $address, 'home');
- $profiletel = new ProfilePhones('address', $addrid);
- $profiletel->saveTels($page->pid(), 'tel', $address['tel']);
+ Phone::savePhones($address['tel'], $page->pid(), Phone::LINK_ADDRESS, $addrid);
}
}
+
+ public function getText($value) {
+ $addresses = array();
+ foreach ($value as $addrid => $address) {
+ $phones = Phone::formArrayToString($address['tel']);
+ $addresses[] = 'Adresse : ' . $address['text'] . ', affichage : ' . $address['pub']
+ . ', commentaire : ' . $address['comment'] . ', actuelle : ' . ($address['current'] ? 'oui' : 'non')
+ . ', temporaire : ' . ($address['temporary'] ? 'oui' : 'non') . ', secondaire : '
+ . ($address['secondary'] ? 'oui' : 'non') . ', conctactable par courier : '
+ . ($address['mail'] ? 'oui' : 'non') . ($phones ? ', ' . $phones : '');
+ }
+ return implode(' ; ' , $addresses);
+ }
}
-class ProfileAddresses extends ProfilePage
+class ProfileSettingAddresses extends ProfilePage
{
protected $pg_template = 'profile/adresses.tpl';
public function __construct(PlWizard &$wiz)
{
parent::__construct($wiz);
- $this->settings['addresses'] = new ProfileAddress();
+ $this->settings['addresses'] = new ProfileSettingAddress();
$this->watched['addresses'] = true;
}
{
$res = XDB::query("SELECT id, accuracy, text, postalText,
postalCode, localityId, subAdministrativeAreaId, administrativeAreaId,
- countryId, latitude, longitude, pub, comment, updateTime,
+ countryId, latitude, longitude, pub, comment, UNIX_TIMESTAMP(updateTime) AS updateTime,
north, south, east, west,
FIND_IN_SET('current', flags) AS current,
FIND_IN_SET('temporary', flags) AS temporary,
$this->values['addresses'] = $res->fetchAllAssoc();
}
- $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",
- $this->pid());
- $i = 0;
- $adrNb = count($this->values['addresses']);
- while ($tel = $res->next()) {
- $addrid = $tel['addrid'];
- unset($tel['addrid']);
- while ($i < $adrNb && $this->values['addresses'][$i]['id'] < $addrid) {
- $i++;
- }
- if ($i >= $adrNb) {
- break;
- }
- $address =& $this->values['addresses'][$i];
- if (!isset($address['tel'])) {
- $address['tel'] = array();
- }
- if ($address['id'] == $addrid) {
- $address['tel'][] = $tel;
- }
+ // Adds phones to addresses.
+ $it = Phone::iterate(array($this->pid()), array(Phone::LINK_ADDRESS));
+ while ($phone = $it->next()) {
+ $this->values['addresses'][$phone->linkId()]['tel'][$phone->id()] = $phone->toFormArray();
}
+
+ // Properly formats addresses.
foreach ($this->values['addresses'] as $id => &$address) {
+ $phone = new Phone();
if (!isset($address['tel'])) {
- $address['tel'] = array();
+ $address['tel'] = array(0 => $phone->toFormArray());
}
unset($address['id']);
+ $address['changed'] = 0;
+ $address['removed'] = 0;
}
+ //var_dump($this->values['addresses']['tel']);
}
}