Merge branch 'master' of /home/git/platal into profile_edit
[platal.git] / modules / profile / get_adresses.inc.php
CommitLineData
0337d704 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 Polytechnique.org *
0337d704 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
22require_once('geoloc.inc.php');
23
5ee95138 24global $adresses, $nb_adr_max, $nb_tel_max;
8303b851 25
a7de4ef7 26// on limite à 6 adresses personnelles par utilisateur
0337d704 27$nb_adr_max = 6; // ( = max(adrid possibles)
a7de4ef7 28// on limite à 4 numéros de téléphone par adresse
79a5acea 29$nb_tel_max = 4; // ( = max(telid possibles)
0337d704 30
a7de4ef7 31//les adresses sont stockées dans un tableau global indéxé par adrid;
0337d704 32
33function is_adr_empty($adrid){
34 $adr = &$GLOBALS['adresses'][$adrid];
5ee95138 35 $emptytel = count($adr['tels']) == 0;
36 if (!$emptytel) {
37 $emptytel = true;
38 foreach ($adr['tels'] as $t) if ($t['tel']) {
39 $emptytel = false;
40 break;
41 }
42 }
787bb3d7 43 return (
0337d704 44 ($adr['adr1'] == '') && ($adr['adr2'] == '') && ($adr['adr3'] == '') &&
45 ($adr['postcode'] == '') && ($adr['city'] == '') && ($adr['country'] == '00') &&
5ee95138 46 ($emptytel)
0337d704 47 );
48}
49
50function delete_address($adrid, $in_request_array = false){
a3a049fc 51 XDB::execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}",
cab08090 52 S::v('uid', -1), $adrid);
a3a049fc 53 XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}",
cab08090 54 S::v('uid', -1), $adrid);
a3a049fc 55 if ($in_request_array == true){
56 unset($_REQUEST['adrid'][$adrid]);
57 } else{
58 unset($GLOBALS['adresses'][$adrid]);
0337d704 59 }
60}
61
62//on verifie si on nous a demande une suppression
5e2307dc 63$req_adrid_del = Env::v('adrid_del', Array());
a3a049fc 64for ($i = 1; $i <= $nb_adr_max; $i++) {
65 if (isset($req_adrid_del[$i])) {
66 delete_address($i,true);
67 }
0337d704 68}
5ee95138 69if (Env::i('deltel')) {
70 XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?} AND telid = {?}",
71 S::v('uid', -1), Env::i('adrid'), Env::i('telid'));
72}
0337d704 73
74//$sql_order = "ORDER BY (NOT FIND_IN_SET('active', statut)), FIND_IN_SET('temporaire', statut)";
75$sql_order = '';
76
77//recuperation des adrid
cab08090 78$res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) ".$sql_order, S::v('uid', -1));
0337d704 79$adrids = $res->fetchColumn();
80
81//recuperation des donnees de la bd
08cce2ff 82$res = XDB::iterRow(
0337d704 83 "SELECT
84 FIND_IN_SET('res-secondaire', statut), FIND_IN_SET('courrier', statut),
85 FIND_IN_SET('active', statut), FIND_IN_SET('temporaire', statut),
86 adr1, adr2, adr3, postcode, city, cityid,
79a5acea 87 a.country, region, regiontxt, pub,
80ca1b4e 88 gp.pays AS countrytxt, gp.display
0337d704 89 FROM adresses AS a INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
90 WHERE uid = {?} AND NOT FIND_IN_SET('pro',statut) ".$sql_order
cab08090 91, S::v('uid', -1)
0337d704 92);
93
94$nb_adr = $res->total();
95
96for ($i = 0; $i < $nb_adr; $i++) {
97 $adrid = $adrids[$i];
98 $adresses[$adrid]['adrid'] = $adrid;
99 list(
100 $adresses[$adrid]['secondaire'], $adresses[$adrid]['courrier'],
101 $adresses[$adrid]['active'], $adresses[$adrid]['temporaire'],
102 $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], $adresses[$adrid]['cityid'],
79a5acea 103 $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['regiontxt'],
0337d704 104 $adresses[$adrid]['pub'],
79a5acea 105 $adresses[$adrid]['countrytxt'],$adresses[$adrid]['display']) = $res->next();
0337d704 106 $adresses[$adrid]['nouvelle'] = 'modif';
107 $adresses[$adrid]['numero_formulaire'] = -1;
108 require_once('geoloc.inc.php');
109 $adresses[$adrid]['txt'] = get_address_text($adresses[$adrid]);
110}
111
08cce2ff 112$restels = XDB::iterator(
79a5acea 113 "SELECT
114 t.adrid, telid, tel_type, t.tel_pub, t.tel
115 FROM tels AS t INNER JOIN adresses AS a ON(t.uid = a.uid AND t.adrid = a.adrid)
116 WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',statut) ORDER BY t.adrid, tel_type DESC, telid"
787bb3d7 117, S::v('uid', -1)
79a5acea 118);
119while ($tel = $restels->next()) {
120 $adrid = $tel['adrid'];
121 unset($tel['adrid']);
122 if (!isset($adresses[$adrid]['tels']))
123 $adresses[$adrid]['tels'] = array($tel);
124 else
125 $adresses[$adrid]['tels'][] = $tel;
126}
a7de4ef7 127// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 128?>