+ function handler_photo_change(&$page)
+ {
+ global $globals;
+
+ $page->changeTpl('trombino.tpl');
+
+ require_once('validations.inc.php');
+
+ $trombi_x = '/home/web/trombino/photos'.Session::get('promo')
+ .'/'.Session::get('forlife').'.jpg';
+
+ if (Env::has('upload')) {
+ $file = isset($_FILES['userfile']['tmp_name'])
+ ? $_FILES['userfile']['tmp_name']
+ : Env::get('photo');
+ if ($data = file_get_contents($file)) {
+ if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) {
+ $myphoto->submit();
+ }
+ } else {
+ $page->trig('Fichier inexistant ou vide');
+ }
+ } elseif (Env::has('trombi')) {
+ $myphoto = new PhotoReq(Session::getInt('uid'),
+ file_get_contents($trombi_x));
+ if ($myphoto) {
+ $myphoto->commit();
+ $myphoto->clean();
+ }
+ } elseif (Env::get('suppr')) {
+ $globals->xdb->execute('DELETE FROM photo WHERE uid = {?}',
+ Session::getInt('uid'));
+ $globals->xdb->execute('DELETE FROM requests
+ WHERE user_id = {?} AND type="photo"',
+ Session::getInt('uid'));
+ } elseif (Env::get('cancel')) {
+ $sql = $globals->xdb->query('DELETE FROM requests
+ WHERE user_id={?} AND type="photo"',
+ Session::getInt('uid'));
+ }
+
+ $sql = $globals->xdb->query('SELECT COUNT(*) FROM requests
+ WHERE user_id={?} AND type="photo"',
+ Session::getInt('uid'));
+ $page->assign('submited', $sql->fetchOneCell());
+ $page->assign('has_trombi_x', file_exists($trombi_x));
+
+ return PL_OK;
+ }
+
+ function handler_p_orange(&$page)
+ {
+ global $globals;
+
+ $page->changeTpl('orange.tpl');
+
+ require_once 'validations.inc.php';
+ require_once 'xorg.misc.inc.php';
+
+ $res = $globals->xdb->query(
+ "SELECT u.promo,u.promo_sortie
+ FROM auth_user_md5 AS u
+ WHERE user_id={?}", Session::getInt('uid'));
+
+ list($promo,$promo_sortie_old) = $res->fetchOneRow();
+ $page->assign('promo_sortie_old', $promo_sortie_old);
+ $page->assign('promo', $promo);
+
+ if (!Env::has('promo_sortie')) {
+ return PL_OK;
+ }
+
+ $promo_sortie = Env::getInt('promo_sortie');
+
+ if ($promo_sortie < 1000 || $promo_sortie > 9999) {
+ $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
+ }
+ elseif ($promo_sortie < $promo + 3) {
+ $page->trig('Trop tôt');
+ }
+ elseif ($promo_sortie == $promo_sortie_old) {
+ $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
+ }
+ elseif ($promo_sortie == $promo + 3) {
+ $globals->xdb->execute(
+ "UPDATE auth_user_md5 set promo_sortie={?}
+ WHERE user_id={?}",$promo_sortie,Session::getInt('uid'));
+ $page->trig('Ton statut "orange" a été supprimé.');
+ $page->assign('promo_sortie_old', $promo_sortie);
+ }
+ else {
+ $page->assign('promo_sortie', $promo_sortie);
+
+ if (Env::has('submit')) {
+ $myorange = new OrangeReq(Session::getInt('uid'),
+ $promo_sortie);
+ $myorange->submit();
+ $page->assign('myorange', $myorange);
+ }
+ }
+
+ return PL_OK;
+ }
+
+ function handler_p_usage(&$page)
+ {
+ global $globals;
+
+ $page->changeTpl('nomusage.tpl');
+
+ require_once 'validations.inc.php';
+ require_once 'xorg.misc.inc.php';
+
+ $res = $globals->xdb->query(
+ "SELECT u.nom,u.nom_usage,u.flags,e.alias
+ FROM auth_user_md5 AS u
+ LEFT JOIN aliases AS e ON(u.user_id = e.id AND FIND_IN_SET('usage',e.flags))
+ WHERE user_id={?}", Session::getInt('uid'));
+
+ list($nom,$usage_old,$flags,$alias_old) = $res->fetchOneRow();
+ $flags = new flagset($flags);
+ $page->assign('usage_old', $usage_old);
+ $page->assign('alias_old', $alias_old);
+
+ $nom_usage = replace_accent(trim(Env::get('nom_usage')));
+ $nom_usage = strtoupper($nom_usage);
+ $page->assign('usage_req', $nom_usage);
+
+ if (Env::has('submit') && ($nom_usage != $usage_old)) {
+ // on vient de recevoir une requete, differente de l'ancien nom d'usage
+ if ($nom_usage == $nom) {
+ $page->assign('same', true);
+ } else { // le nom de mariage est distinct du nom à l'X
+ // on calcule l'alias pour l'afficher
+ $reason = Env::get('reason');
+ if ($reason == 'other') {
+ $reason = Env::get('other_reason');
+ }
+ $myusage = new UsageReq(Session::getInt('uid'), $nom_usage, $reason);
+ $myusage->submit();
+ $page->assign('myusage', $myusage);
+ }
+ }
+
+ return PL_OK;
+ }
+