pending commit, finished during MQ/S download ...
[platal.git] / modules / platal.php
index 737d5ee..646656f 100644 (file)
@@ -38,7 +38,8 @@ class PlatalModule extends PLModule
     function handlers()
     {
         return array(
-            'cacert.pem'  => $this->make_hook('cacert', AUTH_PUBLIC),
+            'index'       => $this->make_hook('index',     AUTH_PUBLIC),
+            'cacert.pem'  => $this->make_hook('cacert',    AUTH_PUBLIC),
             'changelog'   => $this->make_hook('changelog', AUTH_PUBLIC),
 
             // Preferences thingies
@@ -60,6 +61,13 @@ class PlatalModule extends PLModule
         );
     }
 
+    function handler_index(&$page)
+    {
+        if (S::logged()) {
+            redirect("events");
+        }
+    }
+
     function handler_cacert(&$page)
     {
         $data = file_get_contents('/etc/ssl/xorgCA/cacert.pem');
@@ -80,19 +88,16 @@ class PlatalModule extends PLModule
 
     function __set_rss_state($state)
     {
-        global $globals;
-
         if ($state) {
             $_SESSION['core_rss_hash'] = rand_url_id(16);
-            $globals->xdb->execute('UPDATE  auth_user_quick
+            XDB::execute('UPDATE  auth_user_quick
                                    SET  core_rss_hash={?} WHERE user_id={?}',
-                                   Session::get('core_rss_hash'),
-                                   Session::getInt('uid'));
+                                   S::v('core_rss_hash'), S::v('uid'));
         } else {
-            $globals->xdb->execute('UPDATE  auth_user_quick
+            XDB::execute('UPDATE  auth_user_quick
                                    SET  core_rss_hash="" WHERE user_id={?}',
-                                   Session::getInt('uid'));
-            Session::kill('core_rss_hash');
+                                   S::v('uid'));
+            S::kill('core_rss_hash');
         }
     }
 
@@ -106,10 +111,10 @@ class PlatalModule extends PLModule
         if (Env::has('mail_fmt')) {
             $fmt = Env::get('mail_fmt');
             if ($fmt != 'texte') $fmt = 'html';
-            $globals->xdb->execute("UPDATE auth_user_quick
+            XDB::execute("UPDATE auth_user_quick
                                        SET core_mail_fmt = '$fmt'
                                      WHERE user_id = {?}",
-                                     Session::getInt('uid'));
+                                     S::v('uid'));
             $_SESSION['mail_fmt'] = $fmt;
             redirect($globals->baseurl.'/preferences');
         }
@@ -119,50 +124,42 @@ class PlatalModule extends PLModule
         }
 
         $page->assign('prefs', $globals->hook->prefs());
-
-        return PL_OK;
     }
 
     function handler_webredir(&$page)
     {
-        global $globals;
-
         $page->changeTpl('webredirect.tpl');
 
         $page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
 
-        $log =& Session::getMixed('log');
+        $log =& S::v('log');
         $url = Env::get('url');
 
         if (Env::get('submit') == 'Valider' and Env::has('url')) {
-            $globals->xdb->execute('UPDATE auth_user_quick
+            XDB::execute('UPDATE auth_user_quick
                                        SET redirecturl = {?} WHERE user_id = {?}',
-                                   $url, Session::getInt('uid'));
+                                   $url, S::v('uid'));
             $log->log('carva_add', 'http://'.Env::get('url'));
             $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
         } elseif (Env::get('submit') == "Supprimer") {
-            $globals->xdb->execute("UPDATE auth_user_quick
+            XDB::execute("UPDATE auth_user_quick
                                        SET redirecturl = ''
                                      WHERE user_id = {?}",
-                                   Session::getInt('uid'));
+                                   S::v('uid'));
             $log->log("carva_del", $url);
             Post::kill('url');
             $page->trig('Redirection supprimée');
         }
 
-        $res = $globals->xdb->query('SELECT redirecturl
+        $res = XDB::query('SELECT redirecturl
                                        FROM auth_user_quick
                                       WHERE user_id = {?}',
-                                    Session::getInt('uid'));
+                                    S::v('uid'));
         $page->assign('carva', $res->fetchOneCell());
-
-        return PL_OK;
     }
 
     function handler_prefs_rss(&$page)
     {
-        global $globals;
-
         $page->changeTpl('filrss.tpl');
 
         $page->assign('goback', Env::get('referer', 'login'));
@@ -171,25 +168,21 @@ class PlatalModule extends PLModule
             $this->__set_rss_state(true);
             $page->trig("Ton Fil RSS est activé.");
         }
-
-        return PL_OK;
     }
 
     function handler_password(&$page)
     {
-        global $globals;
-
         if (Post::has('response2'))  {
             require_once 'secure_hash.inc.php';
 
             $_SESSION['password'] = $password = Post::get('response2');
 
-            $globals->xdb->execute('UPDATE  auth_user_md5 
+            XDB::execute('UPDATE  auth_user_md5 
                                        SET  password={?}
                                      WHERE  user_id={?}', $password,
-                                     Session::getInt('uid'));
+                                     S::v('uid'));
 
-            $log =& Session::getMixed('log');
+            $log =& S::v('log');
             $log->log('passwd', '');
 
             if (Cookie::get('ORGaccess')) {
@@ -203,41 +196,35 @@ class PlatalModule extends PLModule
         $page->changeTpl('motdepasse.tpl');
         $page->addJsLink('javascript/motdepasse.js');
         $page->assign('xorg_title','Polytechnique.org - Mon mot de passe');
-
-        return PL_OK;
     }
 
     function handler_smtppass(&$page)
     {
-        global $globals;
-
         $page->changeTpl('acces_smtp.tpl');
         $page->assign('xorg_title','Polytechnique.org - Acces SMTP/NNTP');
 
-        $uid  = Session::getInt('uid');
+        $uid  = S::v('uid');
         $pass = Env::get('smtppass1');
-        $log  = Session::getMixed('log');
+        $log  = S::v('log');
 
         if (Env::get('op') == "Valider" && strlen($pass) >= 6 
         &&  Env::get('smtppass1') == Env::get('smtppass2')) 
         {
-            $globals->xdb->execute('UPDATE auth_user_md5 SET smtppass = {?}
+            XDB::execute('UPDATE auth_user_md5 SET smtppass = {?}
                                      WHERE user_id = {?}', $pass, $uid);
             $page->trig('Mot de passe enregistré');
             $log->log("passwd_ssl");
         } elseif (Env::get('op') == "Supprimer") {
-            $globals->xdb->execute('UPDATE auth_user_md5 SET smtppass = ""
+            XDB::execute('UPDATE auth_user_md5 SET smtppass = ""
                                      WHERE user_id = {?}', $uid);
             $page->trig('Compte SMTP et NNTP supprimé');
             $log->log("passwd_del");
         }
 
-        $res = $globals->xdb->query("SELECT IF(smtppass != '', 'actif', '') 
+        $res = XDB::query("SELECT IF(smtppass != '', 'actif', '') 
                                        FROM auth_user_md5
                                       WHERE user_id = {?}", $uid);
         $page->assign('actif', $res->fetchOneCell());
-
-        return PL_OK;
     }
 
     function handler_recovery(&$page)
@@ -247,7 +234,7 @@ class PlatalModule extends PLModule
         $page->changeTpl('recovery.tpl');
 
         if (!Env::has('login') || !Env::has('birth')) {
-            return PL_OK;
+            return;
         }
 
         if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) {
@@ -260,7 +247,7 @@ class PlatalModule extends PLModule
         // paragraphe rajouté : si la date de naissance dans la base n'existe pas, on l'update
         // avec celle fournie ici en espérant que c'est la bonne
 
-        $res = $globals->xdb->query(
+        $res = XDB::query(
                 "SELECT  user_id, naissance
                    FROM  auth_user_md5 AS u
              INNER JOIN  aliases       AS a ON (u.user_id=a.id AND type!='homonyme')
@@ -271,8 +258,8 @@ class PlatalModule extends PLModule
             $page->assign('ok', true);
 
             $url   = rand_url_id(); 
-            $globals->xdb->execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
-            $res   = $globals->xdb->query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
+            XDB::execute('INSERT INTO perte_pass (certificat,uid,created) VALUES ({?},{?},NOW())', $url, $uid);
+            $res   = XDB::query('SELECT email FROM emails WHERE uid = {?} AND NOT FIND_IN_SET("filter", flags)', $uid);
             $mails = implode(', ', $res->fetchColumn());
 
             require_once "diogenes/diogenes.hermes.inc.php";
@@ -301,18 +288,14 @@ Mail envoy
         } else {
             $page->trig('Pas de résultat correspondant aux champs entrés dans notre base de données.');
         }
-
-        return PL_OK;
     }
 
     function handler_tmpPWD(&$page, $certif = null)
     {
-        global $globals;
-
-        $globals->xdb->execute('DELETE FROM perte_pass
+        XDB::execute('DELETE FROM perte_pass
                                       WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
 
-        $res   = $globals->xdb->query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
+        $res   = XDB::query('SELECT uid FROM perte_pass WHERE certificat={?}', $certif);
         $ligne = $res->fetchOneAssoc();
         if (!$ligne) {
             $page->changeTpl('index.tpl');
@@ -323,18 +306,16 @@ Mail envoy
         if (Post::has('response2')) {
             $password = Post::get('response2');
             $logger   = new DiogenesCoreLogger($uid);
-            $globals->xdb->query('UPDATE  auth_user_md5 SET password={?}
+            XDB::query('UPDATE  auth_user_md5 SET password={?}
                                    WHERE  user_id={?} AND perms IN("admin","user")',
                                  $password, $uid);
-            $globals->xdb->query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
+            XDB::query('DELETE FROM perte_pass WHERE certificat={?}', $certif);
             $logger->log("passwd","");
             $page->changeTpl('tmpPWD.success.tpl');
         } else {
             $page->changeTpl('motdepasse.tpl');
             $page->addJsLink('javascript/motdepasse.js');
         }
-
-        return PL_OK;
     }
 
     function handler_skin(&$page)
@@ -349,10 +330,10 @@ Mail envoy
         $page->assign('xorg_title','Polytechnique.org - Skins');
 
         if (Env::has('newskin'))  {  // formulaire soumis, traitons les données envoyées
-            $globals->xdb->execute('UPDATE auth_user_quick
+            XDB::execute('UPDATE auth_user_quick
                                        SET skin={?} WHERE user_id={?}',
                                     Env::getInt('newskin'),
-                                    Session::getInt('uid'));
+                                    S::v('uid'));
             set_skin();
         }
 
@@ -361,20 +342,19 @@ Mail envoy
              LEFT JOIN auth_user_quick AS a ON s.id=a.skin
                  WHERE skin_tpl != '' AND ext != ''
               GROUP BY id ORDER BY s.date DESC";
-        $page->assign_by_ref('skins', $globals->xdb->iterator($sql));
-        return PL_OK;
+        $page->assign_by_ref('skins', XDB::iterator($sql));
     }
 
     function handler_exit(&$page, $level = null)
     {
-        if (Session::has('suid')) {
-            if (Session::has('suid')) {
-                $a4l  = Session::get('forlife');
-                $suid = Session::getMixed('suid');
-                $log  = Session::getMixed('log');
-                $log->log("suid_stop", Session::get('forlife') . " by " . $suid['forlife']);
+        if (S::has('suid')) {
+            if (S::has('suid')) {
+                $a4l  = S::v('forlife');
+                $suid = S::v('suid');
+                $log  = S::v('log');
+                $log->log("suid_stop", S::v('forlife') . " by " . $suid['forlife']);
                 $_SESSION = $suid;
-                Session::kill('suid');
+                S::kill('suid');
                 redirect($globals->baseurl.'/admin/utilisateurs.php?login='.$a4l);
             } else {
                 redirect("events");
@@ -407,18 +387,15 @@ Mail envoy
         } else {
             $page->changeTpl('exit.tpl');
         }
-        return PL_OK;
     }
 
     function handler_rss(&$page, $user = null, $hash = null)
     {
-        global $globals;
-
         require_once 'rss.inc.php';
 
         $uid = init_rss('rss.tpl', $user, $hash);
 
-        $rss = $globals->xdb->iterator(
+        $rss = XDB::iterator(
                 'SELECT  e.id, e.titre, e.texte, e.creation_date
                    FROM  auth_user_md5   AS u
              INNER JOIN  evenements      AS e ON ( (e.promo_min = 0 || e.promo_min <= u.promo)
@@ -426,8 +403,6 @@ Mail envoy
                   WHERE  u.user_id = {?} AND FIND_IN_SET(e.flags, "valide")
                                          AND peremption >= NOW()', $uid);
         $page->assign('rss', $rss);
-
-        return PL_OK;
     }
 }