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