Non significant spaces suck.
[platal.git] / modules / profile / assign_adresses.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2007 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 global $adresses;
23
24 //on génère une éventuelle nouvelle adresse
25 if (!isset($adresses) || (count($adresses) < $nb_adr_max)){
26 $adrid = generate_new_adrid();
27 $adresses[$adrid]['adrid'] = $adrid;
28 $adr = &$adresses[$adrid];
29 $adr['adr1'] = '';
30 $adr['adr2'] = '';
31 $adr['adr3'] = '';
32 $adr['postcode'] = '';
33 $adr['city'] = '';
34 $adr['country'] = '00';
35 $adr['region'] = '';
36 $adr['secondaire'] = 1;
37 $adr['courrier'] = 0;
38 $adr['active'] = 0;
39 $adr['temporaire'] = 1;
40 $adr['pub'] = 'private';
41 $adr['nouvelle'] = 'new'; //n'est pas issue d'un formulaire (sert dans update_adresses...)
42 }
43
44 unset($adr);
45 unset($adrid);
46
47 reset($adresses);
48 //on génère un éventuel nouveau tel pour chaque adresse
49 foreach($adresses as $adrid => $adr){
50 if (!isset($adr['tels']) || count($adr['tels']) == 0) {
51 $adresses[$adrid]['tels'] = array(
52 array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Tél.', 'telid' => 0, 'new_tel' => true),
53 array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Fax', 'telid' => 1, 'new_tel' => true));
54 } elseif (count($adr['tels']) < $nb_tel_max) {
55 $adresses[$adrid]['tels'][] =
56 array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Autre', 'telid' => generate_new_telid($adr), 'new_tel' => true);
57 }
58 }
59
60 unset($adr);
61 unset($adrid);
62
63 //tri des adresses :
64
65 reset($adresses);
66 $i = 1;
67 foreach($adresses as $adrid_ => $adr_){
68 if(($adresses[$adrid_]['active']) && ($adr_['nouvelle'] != 'new')){
69 $ordre_des_adrid[$i] = $adrid_;
70 $i++;
71 $est_attribuee[$adrid_] = 1;
72 }
73 else
74 $est_attribuee[$adrid_] = 0;
75 }
76
77 reset($adresses);
78 foreach($adresses as $adrid_ => $adr_){
79 if(($adresses[$adrid_]['secondaire'] == 0) && ($est_attribuee[$adrid_] == 0) && ($adr_['nouvelle'] != 'new')){ // principale et non attribuee
80 $ordre_des_adrid[$i] = $adrid_;
81 $i++;
82 $est_attribuee[$adrid_] = 1;
83 }
84 }
85
86 reset($adresses);
87 foreach($adresses as $adrid_ => $adr_){
88 if(($adresses[$adrid_]['temporaire'] == 0) && ($est_attribuee[$adrid_] == 0) && ($adr_['nouvelle'] != 'new')){ // permanente et non attribuee
89 $ordre_des_adrid[$i] = $adrid_;
90 $i++;
91 $est_attribuee[$adrid_] = 1;
92 }
93 }
94 reset($adresses);
95 foreach($adresses as $adrid_ => $adr_){
96 if($est_attribuee[$adrid_] == 0){ // non attribuee
97 $ordre_des_adrid[$i] = $adrid_;
98 $i++;
99 $est_attribuee[$adrid_] = 1;
100 }
101 }
102
103 $nb_adr = $i - 1;
104 $page->assign_by_ref('ordre_adrid',$ordre_des_adrid);
105 $page->assign('nb_adr',$nb_adr+1);
106
107 $page->assign('adresses', $adresses);
108
109 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
110 ?>