page constructors for x.net : new_page, new_group_page, new_groupadmin_page, new_admi...
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Mon, 18 Apr 2005 14:46:50 +0000 (14:46 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:28:40 +0000 (23:28 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-571

htdocs.net/groupe/asso.php
htdocs.net/groupe/listes-admin.php
htdocs.net/groupe/listes-archives.php
htdocs.net/groupe/listes-delete.php
htdocs.net/groupe/listes-members.php
htdocs.net/groupe/listes-moderate.php
htdocs.net/groupe/listes-options.php
include/xnet.inc.php
include/xnet/page.inc.php
include/xnet/session.inc.php

index 7042f73..b809768 100644 (file)
@@ -2,7 +2,7 @@
 
 require 'xnet.inc.php';
 
-new_skinned_page('xnet/groupe/asso.tpl', AUTH_PUBLIC);
+new_page('xnet/groupe/asso.tpl', AUTH);
 if (!$globals->asso('id')) {
     header("Location: ../");
 }
index f9d6c17..827f226 100644 (file)
@@ -23,7 +23,7 @@ require_once 'xnet.inc.php';
 if (!Env::has('liste')) header('Location: listes.php');
 $liste = strtolower(Env::get('liste'));
 
-new_skinned_page('listes/admin.tpl', AUTH_MDP);
+new_page('listes/admin.tpl', AUTH_MDP);
 $page->setType($globals->asso('cat'));
 $page->useMenu();
 
index d8ebbe7..db288f9 100644 (file)
  ***************************************************************************/
 
 require_once 'xnet.inc.php';
-if (!Env::has('liste')) header('Location: index.php');
+if (!Env::has('liste')) header('Location: listes.php');
 $liste = strtolower(Env::get('liste'));
 
-new_skinned_page('listes/archives.tpl', AUTH_COOKIE);
+new_page('listes/archives.tpl');
 $page->setType($globals->asso('cat'));
 $page->useMenu();
 
index 83ff0b5..309ee07 100644 (file)
@@ -23,7 +23,7 @@ require_once 'xnet.inc.php';
 if (!Env::has('liste')) header('Location: listes.php');
 $liste = strtolower(Env::get('liste'));
 
-new_skinned_page('listes/delete.tpl', AUTH_MDP);
+new_page('listes/delete.tpl', AUTH_MDP);
 $page->setType($globals->asso('cat'));
 $page->useMenu();
 
index 19f587c..c6dc60c 100644 (file)
@@ -23,7 +23,7 @@ require_once 'xnet.inc.php';
 if (!Env::has('liste')) header('Location: listes.php');
 $liste = strtolower(Env::get('liste'));
 
-new_skinned_page('listes/members.tpl', AUTH_MDP);
+new_page('listes/members.tpl', AUTH_MDP);
 $page->setType($globals->asso('cat'));
 $page->useMenu();
 
index 2f604d9..8a1f20f 100644 (file)
@@ -27,7 +27,7 @@ if (preg_match("!(?:[a-z0-9]+\\.)?{".$globals->asso('mail_domain')."}_(.*)!", $l
     header("Location: {$_SERVER['PHP_SELF']}?liste={$matches[1]}");
 }
 
-new_skinned_page('listes/moderate.tpl', AUTH_MDP);
+new_page('listes/moderate.tpl', AUTH_MDP);
 $page->setType($globals->asso('cat'));
 $page->useMenu();
 
index 68ebce7..c5cd1ee 100644 (file)
@@ -23,7 +23,7 @@ require_once 'xnet.inc.php';
 if (!Env::has('liste')) header('Location: listes.php');
 $liste = strtolower(Env::get('liste'));
 
-new_skinned_page('listes/options.tpl', AUTH_MDP);
+new_page('listes/options.tpl', AUTH_MDP);
 $page->setType($globals->asso('cat'));
 $page->useMenu();
 
index 2cca4f0..fb298c9 100644 (file)
@@ -25,32 +25,43 @@ require_once('xnet/session.inc.php');
 XnetGlobals::init();
 XnetSession::init();
 
-// {{{ function _new_page()
+// {{{ function new_skinned_page()
 
-function _new_page($type, $tpl_name, $min_auth, $admin=false)
+function new_page($tpl_name, $min_auth)
 {
     global $page,$globals;
     require_once("xnet/page.inc.php");
-    if (!empty($admin)) {
-        $page = new XnetAdmin($tpl_name, $type);
-    } else switch($min_auth) {
+    switch($min_auth) {
         case AUTH_PUBLIC:
             $page = new XnetPage($tpl_name, $type);
             break;
 
-        case AUTH_MDP:
+        default:
             $page = new XnetAuth($tpl_name, $type);
     }
+    $page->assign('xorg_tpl', $tpl_name);
+}
+
+// }}}
+// {{{ function new_group_page()
 
+function new_group_page($tpl_name)
+{
+    global $page,$globals;
+    require_once("xnet/page.inc.php");
+    $page = new XnetGroupPage($tpl_name);
     $page->assign('xorg_tpl', $tpl_name);
 }
 
 // }}}
-// {{{ function new_skinned_page()
+// {{{ function new_groupadmin_page()
 
-function new_skinned_page($tpl_name, $min_auth)
+function new_groupadmin_page($tpl_name)
 {
-    _new_page(SKINNED, $tpl_name, $min_auth);
+    global $page,$globals;
+    require_once("xnet/page.inc.php");
+    $page = new XnetGroupAdmin($tpl_name);
+    $page->assign('xorg_tpl', $tpl_name);
 }
 
 // }}}
@@ -58,7 +69,10 @@ function new_skinned_page($tpl_name, $min_auth)
 
 function new_admin_page($tpl_name)
 {
-    _new_page(SKINNED, $tpl_name, AUTH_MDP, true);
+    global $page,$globals;
+    require_once("xnet/page.inc.php");
+    $page = new XnetAdmin($tpl_name);
+    $page->assign('xorg_tpl', $tpl_name);
 }
 
 // }}}
index 8c194eb..b4d0a57 100644 (file)
@@ -68,6 +68,8 @@ class XnetPage extends PlatalPage
             $_SESSION['session']->doAuthX($this);
         }
     }
+
+    // }}}
 }
 
 // }}}
@@ -98,6 +100,46 @@ class XnetAuth extends XnetPage
 }
 
 // }}}
+// {{{ class XnetGroupPage
+
+/** Une classe pour les pages réservées aux admins (authentifiés!).
+ */
+class XnetGroupPage extends XnetAuth
+{
+    // {{{ function XnetAdmin()
+    
+    function XnetGroupPage($tpl, $type=SKINNED)
+    {
+        $this->XnetAuth($tpl, $type);
+        if (!is_member() && !has_perms()) {
+            $this->kill("You have not sufficient credentials");
+        }
+    }
+    
+    // }}}
+}
+
+// }}}
+// {{{ class XnetGroupAdmin
+
+/** Une classe pour les pages réservées aux admins (authentifiés!).
+ */
+class XnetGroupAdmin extends XnetAuth
+{
+    // {{{ function XnetAdmin()
+    
+    function XnetGroupAdmin($tpl, $type=SKINNED)
+    {
+        $this->XnetAuth($tpl, $type);
+        if (!may_update()) {
+            $this->kill("You have not sufficient credentials");
+        }
+    }
+    
+    // }}}
+}
+
+// }}}
 // {{{ class XnetAdmin
 
 /** Une classe pour les pages réservées aux admins (authentifiés!).
@@ -116,6 +158,5 @@ class XnetAdmin extends XnetAuth
 }
 
 // }}}
-
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index b06fef1..c1ff469 100644 (file)
@@ -134,6 +134,30 @@ class XnetSession extends DiogenesCoreSession
 }
 
 // }}}
+// {{{ may_update
+
+function may_update() {
+    global $globals;
+    if (has_perms()) { return true; }
+    $res = $globals->xdb->query(
+            "SELECT  perms
+               FROM  groupex.membres
+              WHERE  uid={?} AND asso_id={?}", Session::getInt('uid'), $globals->asso('id'));
+    return $res->fetchOneCell() == 'admin';
+}
 
+// }}}
+// {{{ is_member
+
+function is_member() {
+    global $globals;
+    $res = $globals->xdb->query(
+            "SELECT  COUNT(*)
+               FROM  groupex.membres
+              WHERE  uid={?} AND asso_id={?}", Session::getInt('uid'), $globals->asso('id'));
+    return $res->fetchOneCell() == 1;
+}
+
+// }}}
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>