Administrators can easily switch between skins (without affecting their
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 8 Oct 2010 09:22:30 +0000 (11:22 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 8 Oct 2010 09:22:30 +0000 (11:22 +0200)
default skin), making tests with a specific skin much easier.

Note: Maybe it might be a better idea to enable this feature for all
users when the site is in debug mode and hide this (even for
administrators) when the site is in release mode.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/direnum.php
classes/xorgpage.php
modules/admin.php
templates/skin/common.menu.tpl

index f083af9..5350f0e 100644 (file)
@@ -57,6 +57,7 @@ class DirEnum
     const MEDALS         = 'medals';
 
     const ACCOUNTTYPES   = 'accounttypes';
+    const SKINS          = 'skins';
 
     static private $enumerations = array();
 
@@ -701,5 +702,16 @@ class DE_AccountTypes extends DirEnumeration
 }
 // }}}
 
+// {{{ class DE_Skins
+class DE_Skins extends DirEnumeration
+{
+    public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
+
+    protected $from      = 'skins';
+    protected $valfield  = 'name';
+    protected $idfield   = 'skin_tpl';
+}
+// }}}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 2bc6d59..6a62620 100644 (file)
@@ -44,6 +44,10 @@ class XorgPage extends PlPage
                 }
             }
             $this->assign('account_types_list', $types);
+
+            $skins = DirEnum::getOptions(DirEnum::SKINS);
+            asort($skins);
+            $this->assign('skin_list', $skins);
         }
     }
 
index afe3aa3..f203d78 100644 (file)
@@ -26,6 +26,7 @@ class AdminModule extends PLModule
         return array(
             'phpinfo'                      => $this->make_hook('phpinfo',                AUTH_MDP, 'admin'),
             'get_rights'                   => $this->make_hook('get_rights',             AUTH_COOKIE, 'admin'),
+            'set_skin'                     => $this->make_hook('set_skin',               AUTH_COOKIE, 'admin'),
             'admin'                        => $this->make_hook('default',                AUTH_MDP, 'admin'),
             'admin/dead-but-active'        => $this->make_hook('dead_but_active',        AUTH_MDP, 'admin'),
             'admin/deaths'                 => $this->make_hook('deaths',                 AUTH_MDP, 'admin'),
@@ -83,6 +84,17 @@ class AdminModule extends PLModule
         }
     }
 
+    function handler_set_skin(&$page)
+    {
+        S::assert_xsrf_token();
+        S::set('skin', Post::s('change_skin'));
+        if (!empty($_SERVER['HTTP_REFERER'])) {
+            http_redirect($_SERVER['HTTP_REFERER']);
+        } else {
+            pl_redirect('/');
+        }
+    }
+
     function handler_default(&$page)
     {
         $page->changeTpl('admin/index.tpl');
index 47165bd..58004c8 100644 (file)
 <div class="menu_item"><a href="purge_cache?token={xsrf_token}">Clear cache</a></div>
 <div class="menu_item"><a href="http://trackers.polytechnique.org">Trackers</a></div>
 <div class="menu_item"><a href="http://support.polytechnique.org">Support</a></div>
+<form method="post" action="set_skin">
+  {xsrf_token_field}
+  <div class="menu_item" style="clear: both">
+    Skin
+    <select name="change_skin" onchange="this.form.submit()" style="margin: 0; padding: 0; float:
+    right">
+      {foreach from=$skin_list item=name key=tpl}
+      <option value="{$tpl}" {if $smarty.session.skin eq $tpl}selected="selected"{/if}>{$name}</option>
+      {/foreach}
+    </select>
+  </div>
+</form>
 <form method="post" action="get_rights">
   {xsrf_token_field}
-  <div>
-    <select name="account_type" onchange="this.form.submit()" style="margin: 0; padding: 0">
+  <div class="menu_item" style="clear: both">
+    Droits
+    <select name="account_type" onchange="this.form.submit()" style="margin: 0; padding: 0; float:
+    right">
       <option value="admin">Administrateur</option>
       {foreach from=$account_types_list item=type}
       <option value="{$type}">{$type}</option>