page admin pour le wiki
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 27 Jul 2006 07:55:34 +0000 (07:55 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 27 Jul 2006 07:55:34 +0000 (07:55 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@670 839d8a87-29fc-0310-9880-83ba4fa771e5

htdocs/wiki.php
include/wiki.inc.php
modules/admin.php
templates/admin/index.tpl
templates/admin/wiki.tpl [new file with mode: 0644]

index 33697b1..5c65266 100644 (file)
@@ -92,9 +92,7 @@ if (Env::v('action')) {
 }
 
 $page->assign('perms', $perms);
-$page->assign('perms_opts',
-              array('public' => 'Public', 'logged' => 'Connecté',
-                    'mdp' => 'Authentifié', 'admin' => 'Admin'));
+$page->assign('perms_opts', wiki_perms_options());
 
 $page->assign('canedit',    wiki_may_have_perms($perms[1]));
 $page->assign('has_perms',  wiki_may_have_perms('admin'));
index 6ad7cbc..40dc108 100644 (file)
@@ -46,6 +46,11 @@ function wiki_clear_all_cache()
     system('rm -f '.wiki_work_dir().'/cache_*');
 }
 
+function wiki_perms_options() {
+    return array('public' => 'Public', 'logged' => 'Connecté',
+                  'mdp' => 'Authentifié', 'admin' => 'Admin');
+}
+
 function wiki_get_perms($n)
 {
     $file  = wiki_work_dir().'/'.str_replace('/', '.', $n);
index 4a311ad..83eebdf 100644 (file)
@@ -53,6 +53,7 @@ class AdminModule extends PLModule
             'admin/trombino'               => $this->make_hook('trombino', AUTH_MDP, 'admin'),
             'admin/user'                   => $this->make_hook('user', AUTH_MDP, 'admin'),
             'admin/validate'               => $this->make_hook('validate', AUTH_MDP, 'admin'),
+            'admin/wiki'                   => $this->make_hook('wiki', AUTH_MDP, 'admin'),
         );
     }
 
@@ -864,6 +865,47 @@ class AdminModule extends PLModule
             $page->assign('grades', $res);
         }
     }  
+    function handler_wiki(&$page, $action='list') {
+        require_once 'wiki.inc.php';
+        
+        // update wiki perms
+        if ($action == 'update') {
+            $perms_read = Post::v('read');
+            $perms_edot = Post::v('edit');
+            if ($perms_read || $perms_edit) {
+                foreach ($_POST as $wiki_page => $val) if ($val == 'on') {
+                    $wiki_page = str_replace('_', '/', $wiki_page);
+                    if (!$perms_read || !$perms_edit)
+                        list($perms0, $perms1) = wiki_get_perms($wiki_page);                    
+                    if ($perms_read)
+                        $perms0 = $perms_read;
+                    if ($perms_edit)
+                        $perms1 = $perms_edit;
+                    wiki_set_perms($wiki_page, $perms0, $perms1);
+                }
+            }
+        }
+        
+        $perms = wiki_perms_options();
+        
+        // list wiki pages and their perms
+        $wiki_pages = array();
+        $dir = wiki_work_dir();
+        if (is_dir($dir)) {
+            if ($dh = opendir($dir)) {
+                while (($file = readdir($dh)) !== false) if (substr($file,0,1) >= 'A' && substr($file,0,1) <= 'Z') {
+                    list($read,$edit) = wiki_get_perms($file);
+                    $wiki_pages[$file] = array('read' => $perms[$read], 'edit' => $perms[$edit]);
+                }
+                closedir($dh);
+            }
+        }
+        ksort($wiki_pages);
+        
+        $page->changeTpl('admin/wiki.tpl');
+        $page->assign('wiki_pages', $wiki_pages);        
+        $page->assign('perms_opts', $perms);
+    }
 }
 
 ?>
index 8ed4f97..6515294 100644 (file)
       <a href="admin/geoloc/dynamap">Dynamap</a>
     </td>
   </tr>
+  <tr class="impair">
+    <td>
+      <strong>Wiki :</strong>&nbsp;&nbsp;
+      <a href="admin/wiki">Pages et permissions</a>
+    </td>
+  </tr>
 </table>
 
 {* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/templates/admin/wiki.tpl b/templates/admin/wiki.tpl
new file mode 100644 (file)
index 0000000..fb8fa6b
--- /dev/null
@@ -0,0 +1,79 @@
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2006 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+
+<h1>Pages wiki du site</h1>
+
+<form action="admin/wiki/update" method="post">
+<table class="bicol">
+  <tr>
+    <th>
+      page
+    </th>
+    <th>
+      lecture
+    </th>
+    <th>
+      écriture
+    </th>
+    <th class="action">
+      action
+    </th>
+  </tr>
+{foreach from=$wiki_pages item=perm key=page}
+  <tr class="{cycle values="impair,pair"}">
+    <td>
+      <a href="{$page|replace:'.':'/'}">{$page}</a> <a href="{$page|replace:'.':'/'}?action=edit" class="indice">{icon name=date_edit title='éditer'}</a>
+    </td>
+    <td class="center">
+      {$perm.read}
+    </td>
+    <td class="center">
+      {$perm.edit}
+    </td>
+    <td class="action">
+      <input type="checkbox" name="{$page|replace:'.':'/'}"/>
+    </td>
+  </tr>
+{/foreach}
+  <tr>
+    <td>
+      Attribue les permissions aux pages cochées :
+    </td>
+    <td>
+      <select name="read">
+        <option value=""> - </option>
+        {html_options options=$perms_opts}
+      </select>
+    </td>
+    <td>
+      <select name="edit">
+        <option value=""> - </option>
+        {html_options options=$perms_opts}
+      </select>
+    </td>
+    <td class="option">
+      <input type="submit" value="ok"/>
+    </td>
+  </tr>
+</table>
+</form>
+{* vim:set et sw=2 sts=2 sws=2: *}