minor things to make wiki more readable
[platal.git] / htdocs / profil.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2004 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("xorg.inc.php");
23 new_skinned_page('profil.tpl',AUTH_MDP);
24 $page->addCssLink('css/profil.css');
25
26 require_once('tabs.inc.php');
27 require_once('profil.func.inc.php');
28
29 if (Post::has('register_from_ax_question')) {
30 $globals->xdb->query('UPDATE auth_user_quick SET profile_from_ax = 1 WHERE user_id = {?}', Session::getInt('uid'));
31 require_once('synchro_ax.inc.php');
32 copy_from_ax(Session::getInt('uid'));
33 }
34
35 //on met a jour $opened_tab et $new_tab qui sont le tab du POST et le tab demande
36 // Tout d'abord, quel est le tab actuel ?
37 // si on vient d'un POST, old_tab etait le tab courant
38 if (Env::has('old_tab') && isset($tabname_array[Env::get('old_tab')])) {
39 // on verifie que la valeur postee existe bien
40 $opened_tab = Env::get('old_tab');
41 }
42 $new_tab = Env::has('suivant') ? get_next_tab($opened_tab) : $opened_tab;
43
44 // pour tous les tabs, la date de naissance pour verifier
45 // quelle est bien rentree et la date.
46 $res = $globals->xdb->query(
47 "SELECT naissance, DATE_FORMAT(date,'%d.%m.%Y')
48 FROM auth_user_md5
49 WHERE user_id={?}", Session::getInt('uid'));
50 list($naissance, $date_modif_profil) = $res->fetchOneRow();
51
52 // lorsqu'on n'a pas la date de naissance en base de données
53 if (!$naissance) {
54 // la date de naissance n'existait pas et vient d'être soumise dans la variable
55 if (Env::has('birth')) {
56 //en cas d'erreur :
57 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) {
58 $page->assign('etat_naissance', 'query');
59 $page->trig_run('Date de naissance incorrecte ou incohérente.');
60 }
61
62 //sinon
63 $birth = sprintf("%s-%s-%s", substr(Env::get('birth'),4,4), substr(Env::get('birth'),2,2), substr(Env::get('birth'),0,2));
64 $globals->xdb->execute("UPDATE auth_user_md5 SET naissance={?} WHERE user_id={?}", $birth, Session::getInt('uid'));
65 $page->assign('etat_naissance','ok');
66 $page->run();
67 } else {
68 $page->assign('etat_naissance','query');
69 }
70 $page->run();//on affiche le formulaire pour naissance
71 }
72
73 //doit-on faire un update ?
74 if (Env::has('modifier') || Env::has('suivant')) {
75 require_once("profil/get_{$opened_tab}.inc.php");
76 require_once("profil/verif_{$opened_tab}.inc.php");
77
78 if($page->nb_errs()) {
79 require_once("profil/assign_{$opened_tab}.inc.php");
80 $page->assign('onglet',$opened_tab);
81 $page->assign('onglet_last',get_last_tab());
82 $page->assign('onglet_tpl',"profil/$opened_tab.tpl");
83 $page->run();
84 }
85
86 $date=date("Y-m-j");//nouvelle date de mise a jour
87
88 //On sauvegarde l'uid pour l'AX
89 /* on sauvegarde les changements dans user_changes :
90 * on a juste besoin d'insérer le user_id de la personne dans la table
91 */
92 $globals->xdb->execute('REPLACE INTO user_changes SET user_id={?}', Session::getInt('uid'));
93
94 if (!Session::has('suid')) {
95 require_once('notifs.inc.php');
96 register_watch_op(Session::getInt('uid'), WATCH_FICHE);
97 }
98
99 // mise a jour des champs relatifs au tab ouvert
100 require_once("profil/update_{$opened_tab}.inc.php");
101
102 $log =& Session::getMixed('log');
103 $log->log('profil', $opened_tab);
104 $page->assign('etat_update', 'ok');
105 }
106
107 require_once("profil/get_{$new_tab}.inc.php");
108 require_once("profil/verif_{$new_tab}.inc.php");
109 require_once("profil/assign_{$new_tab}.inc.php");
110
111 $page->assign('onglet',$new_tab);
112 $page->assign('onglet_last',get_last_tab());
113 $page->assign('onglet_tpl',"profil/$new_tab.tpl");
114 $page->run();
115
116 // vim:set et sws=4 sw=4 sts=4:
117 ?>