remove fail() that is not used
[platal.git] / modules / platal.php
index ce6e34f..b5dfe4a 100644 (file)
@@ -43,11 +43,11 @@ class PlatalModule extends PLModule
             'changelog'   => $this->make_hook('changelog', AUTH_PUBLIC),
 
             // Preferences thingies
-            'prefs'     => $this->make_hook('prefs',     AUTH_COOKIE),
-            'prefs/rss' => $this->make_hook('prefs_rss', AUTH_COOKIE),
+            'prefs'       => $this->make_hook('prefs',     AUTH_COOKIE),
+            'prefs/rss'   => $this->make_hook('prefs_rss', AUTH_COOKIE),
             'prefs/webredirect'
-                        => $this->make_hook('webredir',  AUTH_MDP),
-            'skin'      => $this->make_hook('skin',      AUTH_COOKIE),
+                          => $this->make_hook('webredir',  AUTH_MDP),
+            'prefs/skin'  => $this->make_hook('skin',      AUTH_COOKIE),
 
             // password related thingies
             'password'      => $this->make_hook('password',  AUTH_MDP),
@@ -63,8 +63,8 @@ class PlatalModule extends PLModule
 
     function handler_index(&$page)
     {
-        if (logged()) {
-            redirect("events");
+        if (S::logged()) {
+            pl_redirect('events');
         }
     }
 
@@ -88,69 +88,59 @@ class PlatalModule extends PLModule
 
     function __set_rss_state($state)
     {
-        global $globals;
-
         if ($state) {
             $_SESSION['core_rss_hash'] = rand_url_id(16);
             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 {
             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');
         }
     }
 
     function handler_prefs(&$page)
     {
-        global $globals;
-
         $page->changeTpl('preferences.tpl');
         $page->assign('xorg_title','Polytechnique.org - Mes préférences');
 
-        if (Env::has('mail_fmt')) {
-            $fmt = Env::get('mail_fmt');
+        if (Post::has('mail_fmt')) {
+            $fmt = Post::get('mail_fmt');
             if ($fmt != 'texte') $fmt = 'html';
             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');
         }
 
-        if (Env::has('rss')) {
-            $this->__set_rss_state(Env::getBool('rss'));
+        if (Post::has('rss')) {
+            $this->__set_rss_state(Post::getBool('rss'));
         }
-
-        $page->assign('prefs', $globals->hook->prefs());
     }
 
     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')) {
             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") {
             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');
@@ -159,14 +149,12 @@ class PlatalModule extends PLModule
         $res = XDB::query('SELECT redirecturl
                                        FROM auth_user_quick
                                       WHERE user_id = {?}',
-                                    Session::getInt('uid'));
+                                    S::v('uid'));
         $page->assign('carva', $res->fetchOneCell());
     }
 
     function handler_prefs_rss(&$page)
     {
-        global $globals;
-
         $page->changeTpl('filrss.tpl');
 
         $page->assign('goback', Env::get('referer', 'login'));
@@ -179,8 +167,6 @@ class PlatalModule extends PLModule
 
     function handler_password(&$page)
     {
-        global $globals;
-
         if (Post::has('response2'))  {
             require_once 'secure_hash.inc.php';
 
@@ -189,9 +175,9 @@ class PlatalModule extends PLModule
             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')) {
@@ -209,14 +195,12 @@ class PlatalModule extends PLModule
 
     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')) 
@@ -249,9 +233,14 @@ class PlatalModule extends PLModule
         }
 
         if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) {
-            $page->trig_run('Date de naissance incorrecte ou incohérente');
+            $page->trig('Date de naissance incorrecte ou incohérente');
+            return;
         }
-        $birth   = sprintf('%s-%s-%s', substr(Env::get('birth'),4,4), substr(Env::get('birth'),2,2), substr(Env::get('birth'),0,2));
+
+        $birth   = sprintf('%s-%s-%s',
+                           substr(Env::get('birth'), 4, 4),
+                           substr(Env::get('birth'), 2, 2),
+                           substr(Env::get('birth'), 0, 2));
 
         $mailorg = strtok(Env::get('login'), '@');
 
@@ -303,8 +292,6 @@ Mail envoy
 
     function handler_tmpPWD(&$page, $certif = null)
     {
-        global $globals;
-
         XDB::execute('DELETE FROM perte_pass
                                       WHERE DATE_SUB(NOW(), INTERVAL 380 MINUTE) > created');
 
@@ -335,21 +322,20 @@ Mail envoy
     {
         global $globals;
 
-        if (!$globals->skin->enable) {
-            redirect('./');
-        }
-
         $page->changeTpl('skins.tpl');
         $page->assign('xorg_title','Polytechnique.org - Skins');
 
         if (Env::has('newskin'))  {  // formulaire soumis, traitons les données envoyées
             XDB::execute('UPDATE auth_user_quick
-                                       SET skin={?} WHERE user_id={?}',
-                                    Env::getInt('newskin'),
-                                    Session::getInt('uid'));
+                             SET skin={?} WHERE user_id={?}',
+                         Env::getInt('newskin'), S::v('uid'));
+            S::kill('skin');
             set_skin();
         }
 
+        $res = XDB::query('SELECT id FROM skins WHERE skin_tpl={?}', S::v('skin'));
+        $page->assign('skin_id', $res->fetchOneCell());
+
         $sql = "SELECT s.*,auteur,count(*) AS nb
                   FROM skins AS s
              LEFT JOIN auth_user_quick AS a ON s.id=a.skin
@@ -360,17 +346,17 @@ Mail envoy
 
     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');
-                redirect($globals->baseurl.'/admin/utilisateurs.php?login='.$a4l);
+                S::kill('suid');
+                pl_redirect('admin/utilisateurs.php', 'login='.$a4l);
             } else {
-                redirect("events");
+                pl_redirect('events');
             }
         }
 
@@ -396,7 +382,7 @@ Mail envoy
         XorgSession::destroy();
 
         if (Get::has('redirect')) {
-            redirect(rawurldecode(Get::get('redirect')));
+            http_redirect(rawurldecode(Get::get('redirect')));
         } else {
             $page->changeTpl('exit.tpl');
         }
@@ -404,8 +390,6 @@ Mail envoy
 
     function handler_rss(&$page, $user = null, $hash = null)
     {
-        global $globals;
-
         require_once 'rss.inc.php';
 
         $uid = init_rss('rss.tpl', $user, $hash);