<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2009 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
{
private $bool;
private $pub;
- private $tel;
public function __construct()
{
$this->bool = new ProfileBool();
$this->pub = new ProfilePub();
- $this->tel = new ProfileTel();
}
- private function cleanAddress(ProfilePage &$page, array &$address, &$success)
+ private function cleanAddress(ProfilePage &$page, $adrid, array &$address, &$success)
{
if (@$address['changed']) {
$address['datemaj'] = time();
}
$success = true;
- 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'], $s);
- $tel['tel'] = $this->tel->value($page, 'tel', $tel['tel'], $s);
- if (!$s) {
- $tel['error'] = true;
- $success = false;
- }
- }
- unset($tel['removed']);
+ if (!isset($address['tel'])) {
+ $address['tel'] = array();
}
+ $profiletel = new ProfilePhones('address', $adrid);
+ $address['tel'] = $profiletel->value($page, 'tel', $address['tel'], $s);
$address['checked'] = $this->bool->value($page, 'checked', $address['checked'], $s);
$address['secondaire'] = $this->bool->value($page, 'secondaire', $address['secondaire'], $s);
$address['mail'] = $this->bool->value($page, 'mail', $address['mail'], $s);
$ls = true;
$this->geolocAddress($adr, $s);
$ls = ($ls && $s);
- $this->cleanAddress($page, $adr, $s);
+ $this->cleanAddress($page, $key, $adr, $s);
$ls = ($ls && $s);
if (!trim($adr['text'])) {
unset($value[$key]);
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']);
- }
-
- private function saveAddress($adrid, array &$address)
+ private function saveAddress($pid, $adrid, array &$address)
{
$flags = new PlFlagSet();
- if ($address['secondaire']) {
- $flags->addFlag('res-secondaire');
- }
- if ($address['mail']) {
- $flags->addFlag('courrier');
- }
- if ($address['temporary']) {
- $flags->addFlag('temporaire');
- }
- if ($address['current']) {
- $flags->addFlag('active');
- }
- if ($address['checked']) {
- $flags->addFlag('coord-checked');
- }
+ $flags->addFlag('res-secondaire', $address['secondaire']);
+ $flags->addFlag('courrier', $address['mail']);
+ $flags->addFlag('temporaire', $address['temporary']);
+ $flags->addFlag('active', $address['current']);
+ $flags->addFlag('coord-checked', $address['checked']);
XDB::execute("INSERT INTO adresses (adr1, adr2, adr3,
postcode, city, cityid,
country, region, regiontxt,
pub, datemaj, statut,
- uid, adrid, glat, glng)
+ uid, adrid, glat, glng, comment)
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, $address['precise_lat'], $address['precise_lon']);
- foreach ($address['tel'] as $telid=>&$tel) {
- $this->saveTel($adrid, $telid, $tel);
- }
+ $pid, $adrid, $address['precise_lat'], $address['precise_lon'], $address['comment']);
}
public function save(ProfilePage &$page, $field, $value)
{
XDB::execute("DELETE FROM adresses
WHERE uid = {?}",
- S::i('uid'));
- XDB::execute("DELETE FROM tels
- WHERE uid = {?}",
- S::i('uid'));
+ $page->pid());
+ XDB::execute("DELETE FROM profile_phones
+ WHERE uid = {?} AND link_type = 'address'",
+ $page->pid());
foreach ($value as $adrid=>&$address) {
- $this->saveAddress($adrid, $address);
+ $this->saveAddress($page->pid(), $adrid, $address);
+ $profiletel = new ProfilePhones('address', $adrid);
+ $profiletel->saveTels($page->pid(), 'tel', $address['tel']);
}
}
}
FIND_IN_SET('courrier', a.statut) AS mail,
FIND_IN_SET('temporaire', a.statut) AS temporary,
FIND_IN_SET('active', a.statut) AS current,
- a.glat AS precise_lat, a.glng AS precise_lon
+ a.glat AS precise_lat, a.glng AS precise_lon,
+ a.comment
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'));
+ $this->pid());
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'));
+ $res = XDB::iterator("SELECT link_id AS adrid, 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()) {