+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-global $adresses;
-
-//on génère une éventuelle nouvelle adresse
-if (!isset($adresses) || (count($adresses) < $nb_adr_max)){
- $adrid = generate_new_adrid();
- $adresses[$adrid]['adrid'] = $adrid;
- $adr = &$adresses[$adrid];
- $adr['adr1'] = '';
- $adr['adr2'] = '';
- $adr['adr3'] = '';
- $adr['postcode'] = '';
- $adr['city'] = '';
- $adr['country'] = '00';
- $adr['region'] = '';
- $adr['secondaire'] = 1;
- $adr['courrier'] = 0;
- $adr['active'] = 0;
- $adr['temporaire'] = 1;
- $adr['pub'] = 'private';
- $adr['nouvelle'] = 'new'; //n'est pas issue d'un formulaire (sert dans update_adresses...)
-}
-
-unset($adr);
-unset($adrid);
-
-reset($adresses);
-//on génère un éventuel nouveau tel pour chaque adresse
-foreach($adresses as $adrid => $adr){
- if (!isset($adr['tels']) || count($adr['tels']) == 0) {
- $adresses[$adrid]['tels'] = array(
- array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Tél.', 'telid' => 0, 'new_tel' => true),
- array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Fax', 'telid' => 1, 'new_tel' => true));
- } elseif (count($adr['tels']) < $nb_tel_max) {
- $adresses[$adrid]['tels'][] =
- array('tel' => '', 'tel_pub' => 'private', 'tel_type' => 'Autre', 'telid' => generate_new_telid($adr), 'new_tel' => true);
- }
-}
-
-unset($adr);
-unset($adrid);
-
-//tri des adresses :
-
-reset($adresses);
-$i = 1;
-foreach($adresses as $adrid_ => $adr_){
- if(($adresses[$adrid_]['active']) && ($adr_['nouvelle'] != 'new')){
- $ordre_des_adrid[$i] = $adrid_;
- $i++;
- $est_attribuee[$adrid_] = 1;
- }
- else
- $est_attribuee[$adrid_] = 0;
-}
-
-reset($adresses);
-foreach($adresses as $adrid_ => $adr_){
- if(($adresses[$adrid_]['secondaire'] == 0) && ($est_attribuee[$adrid_] == 0) && ($adr_['nouvelle'] != 'new')){ // principale et non attribuee
- $ordre_des_adrid[$i] = $adrid_;
- $i++;
- $est_attribuee[$adrid_] = 1;
- }
-}
-
-reset($adresses);
-foreach($adresses as $adrid_ => $adr_){
- if(($adresses[$adrid_]['temporaire'] == 0) && ($est_attribuee[$adrid_] == 0) && ($adr_['nouvelle'] != 'new')){ // permanente et non attribuee
- $ordre_des_adrid[$i] = $adrid_;
- $i++;
- $est_attribuee[$adrid_] = 1;
- }
-}
-reset($adresses);
-foreach($adresses as $adrid_ => $adr_){
- if($est_attribuee[$adrid_] == 0){ // non attribuee
- $ordre_des_adrid[$i] = $adrid_;
- $i++;
- $est_attribuee[$adrid_] = 1;
- }
-}
-
-$nb_adr = $i - 1;
-$page->assign_by_ref('ordre_adrid',$ordre_des_adrid);
-$page->assign('nb_adr',$nb_adr+1);
-
-$page->assign('adresses', $adresses);
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-$uid = S::v('uid');
-
-$res = XDB::query(
- "SELECT text,id
- FROM binets_ins, binets_def
- WHERE binets_def.id=binets_ins.binet_id AND user_id={?}", $uid);
-$page->assign('binets', $res->fetchAllAssoc());
-
-$res = XDB::query(
- "SELECT text,id
- FROM groupesx_ins, groupesx_def
- WHERE groupesx_def.id=groupesx_ins.gid AND guid={?}", $uid);
-$page->assign('groupesx', $res->fetchAllAssoc());
-
-$page->assign('section', $section);
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-require_once('geoloc.inc.php');
-
-global $adresses, $nb_adr_max, $nb_tel_max;
-
-// on limite à 6 adresses personnelles par utilisateur
-$nb_adr_max = 6; // ( = max(adrid possibles)
-// on limite à 4 numéros de téléphone par adresse
-$nb_tel_max = 4; // ( = max(telid possibles)
-
-//les adresses sont stockées dans un tableau global indéxé par adrid;
-
-function is_adr_empty($adrid){
- $adr = &$GLOBALS['adresses'][$adrid];
- $emptytel = count($adr['tels']) == 0;
- if (!$emptytel) {
- $emptytel = true;
- foreach ($adr['tels'] as $t) if ($t['tel']) {
- $emptytel = false;
- break;
- }
- }
- return (
- ($adr['adr1'] == '') && ($adr['adr2'] == '') && ($adr['adr3'] == '') &&
- ($adr['postcode'] == '') && ($adr['city'] == '') && ($adr['country'] == '00') &&
- ($emptytel)
- );
-}
-
-function delete_address($adrid, $in_request_array = false){
- XDB::execute("DELETE FROM adresses WHERE uid = {?} AND adrid = {?}",
- S::v('uid', -1), $adrid);
- XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?}",
- S::v('uid', -1), $adrid);
- if ($in_request_array == true){
- unset($_REQUEST['adrid'][$adrid]);
- } else{
- unset($GLOBALS['adresses'][$adrid]);
- }
-}
-
-//on verifie si on nous a demande une suppression
-$req_adrid_del = Env::v('adrid_del', Array());
-for ($i = 1; $i <= $nb_adr_max; $i++) {
- if (isset($req_adrid_del[$i])) {
- delete_address($i,true);
- }
-}
-if (Env::i('deltel')) {
- XDB::execute("DELETE FROM tels WHERE uid = {?} AND adrid = {?} AND telid = {?}",
- S::v('uid', -1), Env::i('adrid'), Env::i('telid'));
-}
-
-//$sql_order = "ORDER BY (NOT FIND_IN_SET('active', statut)), FIND_IN_SET('temporaire', statut)";
-$sql_order = '';
-
-//recuperation des adrid
-$res = XDB::query("SELECT adrid FROM adresses WHERE uid = {?} AND NOT FIND_IN_SET('pro', statut) ".$sql_order, S::v('uid', -1));
-$adrids = $res->fetchColumn();
-
-//recuperation des donnees de la bd
-$res = XDB::iterRow(
- "SELECT
- FIND_IN_SET('res-secondaire', statut), FIND_IN_SET('courrier', statut),
- FIND_IN_SET('active', statut), FIND_IN_SET('temporaire', statut),
- adr1, adr2, adr3, postcode, city, cityid,
- a.country, region, regiontxt, pub,
- gp.pays AS countrytxt, gp.display
- FROM adresses AS a INNER JOIN geoloc_pays AS gp ON(gp.a2 = a.country)
- WHERE uid = {?} AND NOT FIND_IN_SET('pro',statut) ".$sql_order
-, S::v('uid', -1)
-);
-
-$nb_adr = $res->total();
-
-for ($i = 0; $i < $nb_adr; $i++) {
- $adrid = $adrids[$i];
- $adresses[$adrid]['adrid'] = $adrid;
- list(
- $adresses[$adrid]['secondaire'], $adresses[$adrid]['courrier'],
- $adresses[$adrid]['active'], $adresses[$adrid]['temporaire'],
- $adresses[$adrid]['adr1'], $adresses[$adrid]['adr2'], $adresses[$adrid]['adr3'], $adresses[$adrid]['postcode'], $adresses[$adrid]['city'], $adresses[$adrid]['cityid'],
- $adresses[$adrid]['country'], $adresses[$adrid]['region'], $adresses[$adrid]['regiontxt'],
- $adresses[$adrid]['pub'],
- $adresses[$adrid]['countrytxt'],$adresses[$adrid]['display']) = $res->next();
- $adresses[$adrid]['nouvelle'] = 'modif';
- $adresses[$adrid]['numero_formulaire'] = -1;
- require_once('geoloc.inc.php');
- $adresses[$adrid]['txt'] = get_address_text($adresses[$adrid]);
-}
-
-$restels = XDB::iterator(
- "SELECT
- t.adrid, telid, tel_type, t.tel_pub, t.tel
- FROM tels AS t INNER JOIN adresses AS a ON(t.uid = a.uid AND t.adrid = a.adrid)
- WHERE t.uid = {?} AND NOT FIND_IN_SET('pro',statut) ORDER BY t.adrid, tel_type DESC, telid"
-, S::v('uid', -1)
-);
-while ($tel = $restels->next()) {
- $adrid = $tel['adrid'];
- unset($tel['adrid']);
- if (!isset($adresses[$adrid]['tels']))
- $adresses[$adrid]['tels'] = array($tel);
- else
- $adresses[$adrid]['tels'][] = $tel;
-}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-
-//declaration des fonctions msarty pour les binets et groupex
-
-$sql = "SELECT section".
- " FROM auth_user_md5 AS u".
- " WHERE user_id = {?}";
-
-$result = XDB::query($sql, S::v('uid', -1));
-$section = $result->fetchOneCell();
-
-replace_ifset($section,'section');
-
-/************* gestion des binets ************/
-if (Env::has('binet_op')) {
- // retrait binet
- if( (Env::v('binet_op', '')=='retirer')&&(Env::i('binet_id', 0) != 0)) {
- XDB::execute("DELETE FROM binets_ins WHERE user_id = {?} AND binet_id = {?}", S::v('uid', -1), Env::i('binet_id', -1));
- }
- // ajout binet
- if (Env::v('binet_op')=="ajouter" && (Env::i('binet_id', 0) != 0)) {
- XDB::execute("INSERT INTO binets_ins (user_id,binet_id) VALUES({?}, {?})", S::v('uid', -1), Env::i('binet_id', -1));
- }
-}
-/************* gestion des groupes X ************/
-if (Env::has('groupex_op')) {
- // retrait groupe X
- if (Env::v('groupex_op')=="retirer" && (Env::i('groupex_id', 0) != 0)) {
- XDB::execute("DELETE FROM groupesx_ins WHERE guid = {?} AND gid = {?}", S::v('uid', -1), Env::i('groupex_id', -1));
- }
- // ajout groupe X
- if (Env::v('groupex_op')=="ajouter" && (Env::i('groupex_id', 0) != 0)) {
- XDB::execute("INSERT INTO groupesx_ins (guid, gid) VALUES ({?}, {?})", S::v('uid', -1), Env::i('groupex_id', -1));
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************/
-class ProfileGroups extends ProfilePage
+class ProfileSection implements ProfileSetting
{
- protected $pg_template = 'profile/poly.tpl';
+ public function value(ProfilePage &$page, $field, $value, &$success)
+ {
+ $success = true;
+ if (is_null($value)) {
+ $res = XDB::query("SELECT section
+ FROM auth_user_md5
+ WHERE user_id = {?}",
+ S::i('uid'));
+ return intval($res->fetchOneCell());
+ }
+ return intval($value);
+ }
- public function __construct(PlWizard &$wiz)
+ public function save(ProfilePage &$page, $field, $value)
{
- parent::__construct($wiz);
- $this->settings['section'] = $this->settings['binets']
- = $this->settings['groupesx']
- = null;
+ XDB::execute("UPDATE auth_user_md5
+ SET section = {?}
+ WHERE user_id = {?}",
+ $value, S::i('uid'));
+ }
+}
+
+class ProfileGroup implements ProfileSetting
+{
+ private $table;
+ private $user_field;
+ private $group_field;
+
+ public function __construct($table, $user, $group)
+ {
+ $this->table = $table;
+ $this->user_field = $user;
+ $this->group_field = $group;
}
- protected function fetchData()
+ public function value(ProfilePage &$page, $field, $value, &$success)
{
- parent::fetchData();
+ if (is_null($value)) {
+ $value = array();
+ $res = XDB::iterRow("SELECT g.id, g.text
+ FROM {$this->table}_def AS g
+ INNER JOIN {$this->table}_ins AS i ON (i.{$this->group_field} = g.id)
+ WHERE i.{$this->user_field} = {?}",
+ S::i('uid'));
+ while (list($gid, $text) = $res->next()) {
+ $value[intval($gid)] = $text;
+ }
+ }
+ if (!is_array($value)) {
+ $value = array();
+ }
+ ksort($value);
+ $success = true;
+ return $value;
}
- public function prepare(PlatalPage &$page)
+ public function save(ProfilePage &$page, $field, $value)
+ {
+ XDB::execute("DELETE FROM {$this->table}_ins
+ WHERE {$this->user_field} = {?}",
+ S::i('uid'));
+ if (!count($value)) {
+ return;
+ }
+ $insert = array();
+ foreach ($value as $id=>$text) {
+ $insert[] = '(' . S::i('uid') . ", $id)";
+ }
+ XDB::execute("INSERT INTO {$this->table}_ins ({$this->user_field}, {$this->group_field})
+ VALUES " . implode(',', $insert));
+ }
+}
+
+class ProfileGroups extends ProfilePage
+{
+ protected $pg_template = 'profile/groups.tpl';
+
+ public function __construct(PlWizard &$wiz)
{
- parent::prepare($page);
+ parent::__construct($wiz);
+ $this->settings['section'] = new ProfileSection();
+ $this->settings['binets'] = new ProfileGroup('binets', 'user_id', 'binet_id');
+ $this->settings['groupesx'] = new ProfileGroup('groupesx', 'guid', 'gid');
}
}
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-global $adresses;
-reset($adresses);
-
-function insert_new_tel($adrid, $tel) {
- if ($tel['tel'] == "")
- return;
- $r = XDB::query("SELECT MAX(telid+1) FROM tels WHERE uid = {?} AND adrid = {?}", S::v('uid',-1), $adrid);
- $newid = $r->fetchOneCell();
- if (!$newid) $newid = 0;
- XDB::execute( "INSERT INTO tels SET tel_type = {?}, tel_pub = {?},
- tel = {?}, uid = {?}, adrid = {?}, telid = {?}",
- $tel['tel_type'], $tel['tel_pub'], $tel['tel'],
- S::v('uid', -1), $adrid, $newid);
-}
-
-foreach ($adresses as $adrid => $adr) {
- if ($adr['nouvelle'] != 'new') {
- // test si on vient de creer cette adresse dans verif_adresse.inc.php
-
- //construction des bits
- $statut = "";
- if ($adr["secondaire"]) $statut .= 'res-secondaire,';
- if ($adr["courrier"]) $statut .= 'courrier,';
- if ($adr["active"]) $statut .= 'active,';
- if ($adr["temporaire"]) $statut .= 'temporaire,';
- if (! empty($statut)) $statut = substr($statut, 0, -1);
- $precise_coords = "";
- if (isset($adr['precise_lat']) && isset($adr['precise_lon'])) {
- $precise_coords = ", glat = '".$adr['precise_lat']."'";
- $precise_coords .= ", glng = '".$adr['precise_lon']."'";
- }
-
- if ($adr["nouvelle"] == 'ajout') {
- //nouvelle adresse
- if (is_adr_empty($adrid)) {
- unset($adresses[$adrid]);
- continue;
- }
- XDB::execute("INSERT INTO adresses SET adr1 = {?}, adr2 = {?},
- adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
- country = {?}, region = {?}, regiontxt = {?},
- pub = {?}, datemaj = NOW(), statut = {?}, uid = {?},
- adrid = {?}".$precise_coords, $adr['adr1'], $adr['adr2'],
- $adr['adr3'], $adr['postcode'], $adr['city'],
- $adr['cityid'], $adr['country'], $adr['region'],
- $adr['regiontxt'], $adr['pub'], $statut,
- S::v('uid', -1), $adrid);
- $telsvalues = "";
- foreach ($adr['tels'] as $tel) {
- insert_new_tel($adrid, $tel);
- }
- } else {
- //c'est une mise à jour
- XDB::execute("UPDATE adresses SET adr1 = {?}, adr2 = {?},
- adr3 = {?}, postcode = {?}, city = {?}, cityid = {?},
- country = {?}, region = {?}, regiontxt = {?},
- pub = {?}, datemaj = NOW(), statut = {?}".$precise_coords."
- WHERE uid = {?} AND adrid = {?}", $adr['adr1'],
- $adr['adr2'], $adr['adr3'], $adr['postcode'],
- $adr['city'], $adr['cityid'], $adr['country'],
- $adr['region'], $adr['regiontxt'], $adr['pub'],
- $statut, S::v('uid', -1), $adrid);
- foreach ($adr['tels'] as $tel) {
- if (isset($tel['new_tel'])) {
- if ($tel['new_tel'])
- insert_new_tel($adrid, $tel);
- } else {
- if ($tel['tel'] != "") {
- XDB::execute(
- "UPDATE tels SET
- tel_type = {?},
- tel_pub = {?},
- tel = {?}
- WHERE
- uid = {?} AND
- adrid = {?} AND
- telid = {?}",
- $tel['tel_type'],
- $tel['tel_pub'],
- $tel['tel'],
- S::v('uid', -1),
- $adrid,
- $tel['telid']);
- } else {
- XDB::execute(
- "DELETE FROM tels WHERE
- uid = {?} AND
- adrid = {?} AND
- telid = {?}",
- S::v('uid', -1),
- $adrid,
- $tel['telid']);
- }
- }
- }
- }// fin nouvelle / ancienne adresse
- }//fin if nouvellement crée
-}//fin foreach
-
-
-//on vire les adresses vides :
-if(isset($adresses)){ // s'il y en a
- reset($adresses);
- foreach($adresses as $adrid => $adr){
- // on vire les tels vides
- foreach ($adr['tels'] as $telid => $tel) {
- if ($tel['tel'] == '') unset($adresses[$adrid]['tels'][$telid]);
- }
- if(is_adr_empty($adrid)){
- delete_address($adrid);
- }
- }
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-$sql = "UPDATE auth_user_md5 set section= {?} WHERE user_id= {?}";
-
-XDB::execute($sql, $section, S::v('uid', -1));
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-
-global $adresses;
-
-function generate_new_adrid(){
- global $adresses;
- if(!isset($adresses)) //aucune adresses => retourne 1
- return 1;
- reset($adresses);
- $i = 0;
- $adrid_array = Array();
- foreach($adresses as $numero => $adr){
- $adrid_array[$i] = $numero;
- $i++;
- }
- sort($adrid_array,SORT_NUMERIC); // classe les adrid dans l'ordre croissant
- $new_adrid = 1;
- while(list($key,$current_adrid) = each($adrid_array)){
- if($current_adrid == $new_adrid)
- $new_adrid++;
- else
- return $new_adrid; //s'ils sont differents, il y a un trou dans la liste des adrid donc new_adrid convient
- }
- //si aucun convient, on retourne le plus grand des adrid actuel + 1
- return $new_adrid;
-}
-
-function generate_new_telid($adr){
- $i = 0;
- $telid_array = Array();
- foreach($adr['tels'] as $tel){
- $telid_array[$i] = $tel['telid'];
- $i++;
- }
- sort($telid_array,SORT_NUMERIC); // classe les adrid dans l'ordre croissant
- $new_telid = 0;
- foreach($telid_array as $current_telid)
- if ($current_telid == $new_telid)
- $new_telid ++;
- else
- return $new_telid;//s'ils sont differents, il y a un trou dans la liste des telid donc new_telid convient
- //si aucun convient, on retourne le plus grand des telid actuel + 1
- return $new_telid;
-}
-
-function replace_ifset_adr($varname, $i){
- $tab = Env::v($varname, Array());
- if (isset($tab[$i]))
- $GLOBALS['adresses'][$i][$varname] = $tab[$i];
-}
-
-function replace_ifset_tel($varname, $i, $t){
- $tab = Env::v($varname.$t, Array());
- if (isset($tab[$i]))
- $GLOBALS['adresses'][$i]['tels'][$t][$varname] = $tab[$i];
-}
-
-function get_adr_arg($varname, $i) {
- $tab = Env::v($varname, Array());
- return @$tab[$i];
-}
-
-function set_flag_adr($varname,$i){
- $tab = Env::v($varname, Array());
- if (isset($tab[$i])){
- $GLOBALS['adresses'][$i][$varname] = 1;
- }
- else
- $GLOBALS['adresses'][$i][$varname] = '0';
-}
-
-function replace_tel($i, $t){
- replace_ifset_tel('telid', $i, $t);
- replace_ifset_tel('tel', $i, $t);
- replace_ifset_tel('tel_pub', $i, $t);
- replace_ifset_tel('tel_type', $i, $t);
- replace_ifset_tel('new_tel', $i, $t);
-}
-
-function replace_address($i){
- global $adresses, $nb_tel_max;
- if(!isset($adresses[$i])){
- $adresses[$i]['nouvelle'] = 'ajout';
- $adresses[$i]['adrid'] = $i;
- }
-
- replace_ifset_adr('secondaire', $i);
- set_flag_adr('courrier', $i);
- replace_ifset_adr('temporaire', $i);
- if(Env::i('adrid_active', $i+1) == $i)
- $adresses[$i]['active'] = 1;
- else
- $adresses[$i]['active'] = 0;
- replace_ifset_adr('adr1', $i);
- replace_ifset_adr('adr2', $i);
- replace_ifset_adr('adr3', $i);
- replace_ifset_adr('postcode', $i);
- replace_ifset_adr('city', $i);
- replace_ifset_adr('cityid', $i);
- replace_ifset_adr('country', $i);
- replace_ifset_adr('region', $i);
- replace_ifset_adr('pub', $i);
-
- for ($telid = 0; $telid <= $nb_tel_max; $telid++) {
- $tab = Env::v('telid'.$telid, Array());
- if(isset($tab[$i])){ //ce telid etait donc present dans le formulaire
- replace_tel($i, $telid);
- }
- }
-
- if (!get_adr_arg('parsevalid', $i)) replace_ifset_adr('txt', $i);
- $tab = Env::v('numero_formulaire', Array());
- if($tab[$i])
- $adresses[$i]['numero_formulaire'] = $tab[$i];
- else
- $adresses[$i]['numero_formulaire'] = -1;
-}
-
-function geoloc_adresse($i) {
- global $adresses;
- $change = Env::v('change'.$i);
- if (get_adr_arg('parsevalid', $i) || ($adresses[$i]['txt'] && $change) || (!$adresses[$i]['cityid'])) {
- require_once('geoloc.inc.php');
- // erases the previous address (but not the phone or pub)
- $adresses[$i] = array_merge($adresses[$i], empty_address());
- // localize new address
- $new = get_address_infos($adresses[$i]['txt']);
- if (compare_addresses_text($adresses[$i]['txt'], $geotxt = get_address_text($new)) || get_adr_arg('parsevalid', $i))
- $adresses[$i] = array_merge($adresses[$i], $new);
- else {
- $adresses[$i] = array_merge($adresses[$i], cut_address($adresses[$i]['txt']));
- $adresses[$i]['geoloc'] = $geotxt;
- $adresses[$i]['geoloc_cityid'] = $new['cityid'];
- }
- }
- $adresses[$i]['txt'] = get_address_text($adresses[$i]);
-}
-
-//remplace par les eventuelles nouvelles valeurs :
-for ($adrid = 1; $adrid <= $nb_adr_max; $adrid++) {
- $tab = Env::v('adrid', Array());
- if(isset($tab[$adrid])){ //cet adrid etait donc present dans le formulaire
- replace_address($adrid);
- }
- if (isset($adresses[$adrid]['txt']))
- geoloc_adresse($adrid);
-}
-
-if ($opened_tab == 'adresses' && Env::has('modifier')){ // on ne valide que qd on vient du formulaire
-$adresses_principales = 0;
-reset($adresses);
-foreach($adresses as $adrid => $adr) {
- //validité de chaque adresse
- $description = (($adr['numero_formulaire'] > 0)?"Adresse n°{$adr['numero_formulaire']}":"Nouvelle adresse");
- if (strlen(strtok($adr['adr1'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['adr1'])) {
- $page->trig("Le champ '$description - Ligne 1' contient un caractère interdit.");
- }
- if (strlen(strtok($adr['adr2'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['adr2'])) {
- $page->trig("Le champ '$description - Ligne 2' contient un caractère interdit.");
- }
- if (strlen(strtok($adr['adr3'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['adr3'])) {
- $page->trig("Le champ '$description - Ligne 3' contient un caractère interdit.");
- }
- if (strlen(strtok($adr['postcode'],"<>{}@~?!§*`|%$^=+")) < strlen($adr['postcode'])) {
- $page->trig("Le champ '$description - Code Postal' contient un caractère interdit.");
- }
- if (is_array($adr['tels'])) {
- foreach ($adr['tels'] as $tel) {
- if (strlen(strtok($tel['tel'],"<>{}@&#~:;?,!§*_`[]|%$^=\"")) < strlen($tel['tel'])) {
- $page->trig("Le champ '$description - ".$tel['tel_type']."' contient un caractère interdit.");
- }
- }
- }
- if(!$adr['secondaire']) {
- if($adresses_principales == 1) { //deja une adresse principale
- $page->trig("Tu ne peux avoir qu'une résidence principale.");
- $adresses_principales++; //pour eviter de repeter le message plusieurs fois
- } else {
- $adresses_principales = 1;
- }
- }
-}
-
-}
-
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
+++ /dev/null
-<?php
-/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
- * http://opensource.polytechnique.org/ *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., *
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- ***************************************************************************/
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
function update(type)
{
- if (document.forms.prof_annu[type + '_sel'].value == '0') {
+ var val = document.forms.prof_annu[type + '_sel'].value;
+ if (val == '0' || document.getElementById(type + '_' + val) != null) {
document.getElementById(type + '_add').style.display = 'none';
} else {
document.getElementById(type + '_add').style.display = '';
}
}
+ function remove(cat, id)
+ {
+ $('#' + cat + '_' + id).remove();
+ }
+
+ function add(cat)
+ {
+ var cb = document.forms.prof_annu[cat + '_sel'];
+ var id = cb.value;
+ var text = cb.options[cb.selectedIndex].text;
+ var html = '<tr id="' + cat + '_' + id + '">'
+ + ' <td>'
+ + ' <input type="hidden" name="' + cat + '[' + id + ']" value="' + text + '" />'
+ + ' </td>'
+ + ' <td>'
+ + text
+ + ' <a href="javascript:remove(\'' + cat + '\', ' + id + ')">'
+ + ' <img src="images/icons/cross.gif" alt="cross" title="Supprimer ce groupe" />'
+ + ' </a>'
+ + ' </td>'
+ + '</tr>';
+ $('#' + cat).after(html);
+ }
+
//]]>
</script>
{/literal}
</td>
</tr>
<!-- Binets -->
- <tr>
+ <tr id="binets">
<td class="titre">
<script type="text/javascript">printTitle("Binet(s)")</script>
</td>
<td>
- <select name="binet_sel" onchange="update('binet')">
+ <select name="binets_sel" onchange="update('binets')">
{select_db_table table="binets_def" valeur=0 champ="text" pad='1'}
</select>
- <a id="binet_add" href="javascript:addBinet()">{icon name="add" title="Ajouter ce binet"}</a>
+ <a id="binets_add" href="javascript:add('binets')">{icon name="add" title="Ajouter ce binet"}</a>
+ </td>
+ </tr>
+ {foreach item=text key=bid from=$binets}
+ <tr id="binets_{$bid}">
+ <td>
+ <input type="hidden" name="binets[{$bid}]" value="{$text}" />
+ </td>
+ <td>
+ {$text}
+ <a href="javascript:remove('binets', {$bid})">{icon name="cross" title="Supprimer ce binet"}</a>
</td>
</tr>
+ {/foreach}
<!-- Groupes X -->
- <tr>
+ <tr id="groupesx">
<td class="titre">Groupe(s) X</td>
<td>
- <select name="groupex_sel" onchange="update('groupex')">
+ <select name="groupesx_sel" onchange="update('groupesx')">
{select_db_table table="groupesx_def" valeur=0 champ="text" pad='1'}
</select>
- <a id="groupex_add" href="javascript:addGroupex()">{icon name="add" title="Ajouter ce groupe X"}</a>
+ <a id="groupesx_add" href="javascript:add('groupesx')">{icon name="add" title="Ajouter ce groupe X"}</a>
+ </td>
+ </tr>
+ {foreach item=text key=bid from=$groupesx}
+ <tr id="groupesx_{$bid}">
+ <td>
+ <input type="hidden" name="groupesx[{$bid}]" value="{$text}" />
+ </td>
+ <td>
+ {$text}
+ <a href="javascript:remove('groupesx', {$bid})">{icon name="cross" title="Supprimer ce groupe X"}</a>
</td>
</tr>
+ {/foreach}
</table>
<script type="text/javascript">
-update('groupex');
-update('binet');
+update('groupesx');
+update('binets');
</script>
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}