From 8f1dcb82d4d4e287ee51f0d53af4bee218be5550 Mon Sep 17 00:00:00 2001 From: "Pierre Habouzit (MadCoder" Date: Mon, 18 Apr 2005 14:46:50 +0000 Subject: [PATCH] page constructors for x.net : new_page, new_group_page, new_groupadmin_page, new_admin_page git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-571 --- htdocs.net/groupe/asso.php | 2 +- htdocs.net/groupe/listes-admin.php | 2 +- htdocs.net/groupe/listes-archives.php | 4 ++-- htdocs.net/groupe/listes-delete.php | 2 +- htdocs.net/groupe/listes-members.php | 2 +- htdocs.net/groupe/listes-moderate.php | 2 +- htdocs.net/groupe/listes-options.php | 2 +- include/xnet.inc.php | 34 +++++++++++++++++++-------- include/xnet/page.inc.php | 43 ++++++++++++++++++++++++++++++++++- include/xnet/session.inc.php | 24 +++++++++++++++++++ 10 files changed, 98 insertions(+), 19 deletions(-) diff --git a/htdocs.net/groupe/asso.php b/htdocs.net/groupe/asso.php index 7042f73..b809768 100644 --- a/htdocs.net/groupe/asso.php +++ b/htdocs.net/groupe/asso.php @@ -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: ../"); } diff --git a/htdocs.net/groupe/listes-admin.php b/htdocs.net/groupe/listes-admin.php index f9d6c17..827f226 100644 --- a/htdocs.net/groupe/listes-admin.php +++ b/htdocs.net/groupe/listes-admin.php @@ -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(); diff --git a/htdocs.net/groupe/listes-archives.php b/htdocs.net/groupe/listes-archives.php index d8ebbe7..db288f9 100644 --- a/htdocs.net/groupe/listes-archives.php +++ b/htdocs.net/groupe/listes-archives.php @@ -20,10 +20,10 @@ ***************************************************************************/ 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(); diff --git a/htdocs.net/groupe/listes-delete.php b/htdocs.net/groupe/listes-delete.php index 83ff0b5..309ee07 100644 --- a/htdocs.net/groupe/listes-delete.php +++ b/htdocs.net/groupe/listes-delete.php @@ -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(); diff --git a/htdocs.net/groupe/listes-members.php b/htdocs.net/groupe/listes-members.php index 19f587c..c6dc60c 100644 --- a/htdocs.net/groupe/listes-members.php +++ b/htdocs.net/groupe/listes-members.php @@ -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(); diff --git a/htdocs.net/groupe/listes-moderate.php b/htdocs.net/groupe/listes-moderate.php index 2f604d9..8a1f20f 100644 --- a/htdocs.net/groupe/listes-moderate.php +++ b/htdocs.net/groupe/listes-moderate.php @@ -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(); diff --git a/htdocs.net/groupe/listes-options.php b/htdocs.net/groupe/listes-options.php index 68ebce7..c5cd1ee 100644 --- a/htdocs.net/groupe/listes-options.php +++ b/htdocs.net/groupe/listes-options.php @@ -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(); diff --git a/include/xnet.inc.php b/include/xnet.inc.php index 2cca4f0..fb298c9 100644 --- a/include/xnet.inc.php +++ b/include/xnet.inc.php @@ -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); } // }}} diff --git a/include/xnet/page.inc.php b/include/xnet/page.inc.php index 8c194eb..b4d0a57 100644 --- a/include/xnet/page.inc.php +++ b/include/xnet/page.inc.php @@ -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: ?> diff --git a/include/xnet/session.inc.php b/include/xnet/session.inc.php index b06fef1..c1ff469 100644 --- a/include/xnet/session.inc.php +++ b/include/xnet/session.inc.php @@ -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: ?> -- 2.1.4