Merge branch 'master' of /home/git/platal into profile_edit
[platal.git] / modules / profile / assign_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 ***************************************************************************/
8303b851 21
22global $adresses;
23
a7de4ef7 24//on génère une éventuelle nouvelle adresse
79a5acea 25if (!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
44unset($adr);
45unset($adrid);
46
47reset($adresses);
a7de4ef7 48//on génère un éventuel nouveau tel pour chaque adresse
79a5acea 49foreach($adresses as $adrid => $adr){
5ee95138 50 if (!isset($adr['tels']) || count($adr['tels']) == 0) {
79a5acea 51 $adresses[$adrid]['tels'] = array(
a7de4ef7 52 array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Tél.', 'telid' => 0, 'new_tel' => true),
79a5acea 53 array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Fax', 'telid' => 1, 'new_tel' => true));
54 } elseif (count($adr['tels']) < $nb_tel_max) {
787bb3d7 55 $adresses[$adrid]['tels'][] =
79a5acea 56 array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Autre', 'telid' => generate_new_telid($adr), 'new_tel' => true);
57 }
58}
59
60unset($adr);
61unset($adrid);
62
63//tri des adresses :
64
65reset($adresses);
66$i = 1;
67foreach($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
77reset($adresses);
78foreach($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
86reset($adresses);
87foreach($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}
94reset($adresses);
95foreach($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);
0337d704 106
107$page->assign('adresses', $adresses);
108
a7de4ef7 109// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
0337d704 110?>