+ function handler_photo_change(&$page)
+ {
+ $page->changeTpl('profile/trombino.tpl');
+
+ require_once('validations.inc.php');
+
+ $trombi_x = '/home/web/trombino/photos'.S::v('promo')
+ .'/'.S::v('forlife').'.jpg';
+
+ if (Env::has('upload')) {
+ $upload = new PlUpload(S::v('forlife'), 'photo');
+ if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
+ $page->trig('Une erreur est survenue lors du téléchargement du fichier');
+ } else {
+ $myphoto = new PhotoReq(S::v('uid'), $upload);
+ if ($myphoto->isValid()) {
+ $myphoto->submit();
+ }
+ }
+ } elseif (Env::has('trombi')) {
+ $upload = new PlUpload(S::v('forlife'), 'photo');
+ if ($upload->copyFrom($trombi_x)) {
+ $myphoto = new PhotoReq(S::v('uid'), $upload);
+ if ($myphoto->isValid()) {
+ $myphoto->commit();
+ $myphoto->clean();
+ }
+ }
+ } elseif (Env::v('suppr')) {
+ XDB::execute('DELETE FROM photo WHERE uid = {?}',
+ S::v('uid'));
+ XDB::execute('DELETE FROM requests
+ WHERE user_id = {?} AND type="photo"',
+ S::v('uid'));
+ } elseif (Env::v('cancel')) {
+ $sql = XDB::query('DELETE FROM requests
+ WHERE user_id={?} AND type="photo"',
+ S::v('uid'));
+ }
+
+ $sql = XDB::query('SELECT COUNT(*) FROM requests
+ WHERE user_id={?} AND type="photo"',
+ S::v('uid'));
+ $page->assign('submited', $sql->fetchOneCell());
+ $page->assign('has_trombi_x', file_exists($trombi_x));
+ }
+
+ function handler_profile(&$page, $x = null)
+ {
+ if (is_null($x)) {
+ return PL_NOT_FOUND;
+ }
+
+ global $globals;
+ require_once 'user.func.inc.php';
+
+ $page->changeTpl('profile/profile.tpl', SIMPLE);
+
+ $view = 'private';
+ if (!S::logged() || Env::v('view') == 'public') $view = 'public';
+ if (S::logged() && Env::v('view') == 'ax') $view = 'ax';
+
+ if (is_numeric($x)) {
+ $res = XDB::query(
+ "SELECT alias
+ FROM aliases AS a
+ INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
+ WHERE matricule={?}", $x);
+ $login = $res->fetchOneCell();
+ } else {
+ $login = get_user_forlife($x);
+ }
+
+ if (empty($login)) {
+ if (preg_match('/([-a-z]+)\.([-a-z]+)\.([0-9]{4})/i', $x, $matches)) {
+ $matches = str_replace('-', '_', $matches);
+ $res = XDB::query("SELECT user_id
+ FROM auth_user_md5
+ WHERE prenom LIKE {?} AND nom LIKE {?} AND promo = {?}
+ AND perms = 'pending'",
+ $matches[1], $matches[2], $matches[3]);
+ if ($res->numRows() == 1) {
+ $uid = $res->fetchOneCell();
+ pl_redirect('marketing/public/' . $uid);
+ }
+ }
+ return PL_NOT_FOUND;
+ }
+
+ $new = Env::v('modif') == 'new';
+ $user = get_user_details($login, S::v('uid'), $view);
+ require_once('url_catcher.inc.php');
+ $user['freetext'] = url_catcher($user['freetext'], false);
+ $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'];
+ $page->assign('xorg_title', $title);
+
+ // photo
+
+ $photo = 'photo/'.$user['forlife'].($new ? '/req' : '');
+
+ if (!isset($user['y']) and !isset($user['x'])) {
+ list($user['x'], $user['y']) = getimagesize("images/none.png");
+ }
+ if (!isset($user['y']) or $user['y'] < 1) $user['y']=1;
+ if (!isset($user['x']) or $user['x'] < 1) $user['x']=1;
+ if ($user['x'] > 240) {
+ $user['y'] = (integer)($user['y']*240/$user['x']);
+ $user['x'] = 240;
+ }
+ if ($user['y'] > 300) {
+ $user['x'] = (integer)($user['x']*300/$user['y']);
+ $user['y'] = 300;
+ }
+ if ($user['x'] < 160) {
+ $user['y'] = (integer)($user['y']*160/$user['x']);
+ $user['x'] = 160;
+ }
+
+ $page->assign('logged', has_user_right('private', $view));
+ if (!has_user_right($user['photo_pub'], $view)) {
+ $photo = "";
+ }
+
+ $page->assign_by_ref('x', $user);
+ $page->assign('photo_url', $photo);
+ // alias virtual
+ $res = XDB::query(
+ "SELECT alias
+ FROM virtual
+ INNER JOIN virtual_redirect USING(vid)
+ INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
+ WHERE ( redirect={?} OR redirect={?} )
+ AND alias LIKE '%@{$globals->mail->alias_dom}'",
+ S::v('uid'),
+ $user['forlife'].'@'.$globals->mail->domain,
+ $user['forlife'].'@'.$globals->mail->domain2);
+ $page->assign('virtualalias', $res->fetchOneCell());
+
+ $page->addJsLink('close_on_esc.js');
+ header('Last-Modified: ' . date('r', strtotime($user['date'])));
+ }
+
+ function handler_p_edit(&$page, $opened_tab = 'general')
+ {
+ global $globals;
+
+ $page->changeTpl('profile/edit.tpl');
+
+ $page->addCssLink('profil.css');
+ $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
+
+ require_once 'tabs.inc.php';
+ require_once 'profil.func.inc.php';
+ require_once 'synchro_ax.inc.php';
+
+ if (Post::v('register_from_ax_question')) {
+ XDB::execute('UPDATE auth_user_quick
+ SET profile_from_ax = 1
+ WHERE user_id = {?}',
+ S::v('uid'));
+ }
+ if (Post::v('add_to_nl')) {
+ require_once 'newsletter.inc.php';
+ NewsLetter::subscribe();
+ }
+ if (Post::v('add_to_ax')) {
+ require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
+ AXLetter::subscribe();
+ }
+ if (Post::v('add_to_promo')) {
+ $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}',
+ S::v('promo'));
+ $asso_id = $r->fetchOneCell();
+ XDB::execute('REPLACE INTO groupex.membres (uid,asso_id)
+ VALUES ({?}, {?})',
+ S::v('uid'), $asso_id);
+ $mmlist = new MMList(S::v('uid'), S::v('password'));
+ $mmlist->subscribe("promo".S::v('promo'));
+ }
+ if (Post::v('sub_ml')) {
+ $subs = array_keys(Post::v('sub_ml'));
+ $current_domain = null;
+ foreach ($subs as $list) {
+ list($sub, $domain) = explode('@', $list);
+ if ($domain != $current_domain) {
+ $current_domain = $domain;
+ $client = new MMList(S::v('uid'), S::v('password'), $domain);
+ }
+ $client->subscribe($sub);
+ }
+ }
+
+ if (is_ax_key_missing()) {
+ $page->assign('no_private_key', true);
+ }
+
+ if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
+ ax_synchronize(S::v('bestalias'), S::v('uid'));
+ $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com');
+ }
+
+ // pour tous les tabs, la date de naissance pour verifier
+ // quelle est bien rentree et la date.
+ $res = XDB::query(
+ "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y')
+ FROM auth_user_md5
+ WHERE user_id={?}", S::v('uid'));
+ list($naissance, $date_modif_profil) = $res->fetchOneRow();
+
+ // lorsqu'on n'a pas la date de naissance en base de données
+ if (!$naissance) {
+ // la date de naissance n'existait pas et vient d'être soumise dans la variable
+ if (Env::has('birth')) {
+ //en cas d'erreur :
+ if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::v('birth'))) {
+ $page->assign('etat_naissance', 'query');
+ $page->trig('Date de naissance incorrecte ou incohérente.');
+ return;
+ }
+
+ //sinon
+ $birth = sprintf("%s-%s-%s", substr(Env::v('birth'), 4, 4),
+ substr(Env::v('birth'), 2, 2),
+ substr(Env::v('birth'), 0, 2));
+ XDB::execute("UPDATE auth_user_md5
+ SET naissance={?}
+ WHERE user_id={?}", $birth,
+ S::v('uid'));
+ $page->assign('etat_naissance', 'ok');
+ return;
+ }
+
+ $page->assign('etat_naissance', 'query');
+ return; // on affiche le formulaire pour naissance
+ }
+
+ //doit-on faire un update ?
+ if (Env::has('modifier') || Env::has('suivant')) {
+ require_once dirname(__FILE__) . "/profile/get_{$opened_tab}.inc.php";
+ require_once dirname(__FILE__) . "/profile/verif_{$opened_tab}.inc.php";
+
+ if($page->nb_errs()) {
+ require_once dirname(__FILE__) . "/profile/assign_{$opened_tab}.inc.php";
+ $page->assign('onglet', $opened_tab);
+ $page->assign('onglet_tpl', "profile/$opened_tab.tpl");
+ return;
+ }
+
+ $date=date("Y-m-j");//nouvelle date de mise a jour
+
+ //On sauvegarde l'uid pour l'AX
+ /* on sauvegarde les changements dans user_changes :
+ * on a juste besoin d'insérer le user_id de la personne dans la table
+ */
+ XDB::execute('REPLACE INTO user_changes SET user_id={?}',
+ S::v('uid'));
+
+ if (!S::has('suid')) {
+ require_once 'notifs.inc.php';
+ register_watch_op(S::v('uid'), WATCH_FICHE);
+ }
+
+ // mise a jour des champs relatifs au tab ouvert
+ require_once dirname(__FILE__) . "/profile/update_{$opened_tab}.inc.php";
+
+ $log =& $_SESSION['log'];
+ $log->log('profil', $opened_tab);
+ $page->assign('etat_update', 'ok');
+ }
+
+ if (Env::has('suivant')) {
+ pl_redirect('profile/edit/' . get_next_tab($opened_tab));
+ }
+
+ require_once dirname(__FILE__) . "/profile/get_{$opened_tab}.inc.php";
+ require_once dirname(__FILE__) . "/profile/verif_{$opened_tab}.inc.php";
+ require_once dirname(__FILE__) . "/profile/assign_{$opened_tab}.inc.php";
+
+ $page->assign('onglet', $opened_tab);
+ $page->assign('onglet_tpl', "profile/$opened_tab.tpl");
+
+ return;
+ }
+
+ function handler_p_orange(&$page)