inutile de verifier la ville : elle vient direct de geoloc
[platal.git] / include / profil / get_adresses.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once('geoloc.inc.php');
23
24 global $adresses;
25
26 // on limite à 6 adresses personnelles par utilisateur
27 $nb_adr_max = 6; // ( = max(adrid possibles)
28 // on limite à 4 numéros de téléphone par adresse
29 $nb_tel_max = 4; // ( = max(telid possibles)
30
31 //les adresses sont stockées dans un tableau global indéxé par adrid;
32
33 function is_adr_empty($adrid){
34 $adr = &$GLOBALS['adresses'][$adrid];
35 return (
36 ($adr['adr1'] == '') && ($adr['adr2'] == '') && ($adr['adr3'] == '') &&
37 ($adr['postcode'] == '') && ($adr['city'] == '') && ($adr['country'] == '00') &&
38 (count($adr['tels']) == 0)
39 );
40 }
41
42 function delete_address($adrid, $in_request_array = false){
43 XDB::execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}",
44 S::v('uid', -1), $adrid);
45 XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}",
46 S::v('uid', -1), $adrid);
47 if ($in_request_array == true){
48 unset($_REQUEST['adrid'][$adrid]);
49 } else{
50 unset($GLOBALS['adresses'][$adrid]);
51 }
52 }
53
54 //on verifie si on nous a demande une suppression
55 $req_adrid_del = Env::v('adrid_del', Array());
56 for ($i = 1; $i <= $nb_adr_max; $i++) {
57 if (isset($req_adrid_del[$i])) {
58 delete_address($i,true);
59 }
60 }
61
62 //$sql_order = "ORDER BY (NOT FIND_IN_SET('active', statut)), FIND_IN_SET('temporaire', statut)";
63 $sql_order = '';
64
65 //recuperation des adrid
66 $res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) ".$sql_order, S::v('uid', -1));
67 $adrids = $res->fetchColumn();
68
69 //recuperation des donnees de la bd
70 $res = XDB::iterRow(
71 "SELECT
72 FIND_IN_SET('res-secondaire', statut), FIND_IN_SET('courrier', statut),
73 FIND_IN_SET('active', statut), FIND_IN_SET('temporaire', statut),
74 adr1, adr2, adr3, postcode, city, cityid,
75 a.country, region, regiontxt, pub,
76 gp.pays AS countrytxt, gp.display
77 FROM adresses AS a INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
78 WHERE uid = {?} AND NOT FIND_IN_SET('pro',statut) ".$sql_order
79 , S::v('uid', -1)
80 );
81
82 $nb_adr = $res->total();
83
84 for ($i = 0; $i < $nb_adr; $i++) {
85 $adrid = $adrids[$i];
86 $adresses[$adrid]['adrid'] = $adrid;
87 list(
88 $adresses[$adrid]['secondaire'], $adresses[$adrid]['courrier'],
89 $adresses[$adrid]['active'], $adresses[$adrid]['temporaire'],
90 $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], $adresses[$adrid]['cityid'],
91 $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['regiontxt'],
92 $adresses[$adrid]['pub'],
93 $adresses[$adrid]['countrytxt'],$adresses[$adrid]['display']) = $res->next();
94 $adresses[$adrid]['nouvelle'] = 'modif';
95 $adresses[$adrid]['numero_formulaire'] = -1;
96 require_once('geoloc.inc.php');
97 $adresses[$adrid]['txt'] = get_address_text($adresses[$adrid]);
98 }
99
100 $restels = XDB::iterator(
101 "SELECT
102 t.adrid, telid, tel_type, t.tel_pub, t.tel
103 FROM tels AS t INNER JOIN adresses AS a ON(t.uid = a.uid AND t.adrid = a.adrid)
104 WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',statut) ORDER BY t.adrid, tel_type DESC, telid"
105 , S::v('uid', -1)
106 );
107 while ($tel = $restels->next()) {
108 $adrid = $tel['adrid'];
109 unset($tel['adrid']);
110 if (!isset($adresses[$adrid]['tels']))
111 $adresses[$adrid]['tels'] = array($tel);
112 else
113 $adresses[$adrid]['tels'][] = $tel;
114 }
115 ?>