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