| Current Path : /home/m/a/g/magalijoj/www/blog/admin/ |
| Current File : /home/m/a/g/magalijoj/www/blog/admin/permissions.php |
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of DotClear.
# Copyright (c) 2005 Olivier Meunier and contributors. All rights
# reserved.
#
# DotClear 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.
#
# DotClear 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 DotClear; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ***** END LICENSE BLOCK *****
require dirname(__FILE__).'/../inc/admin/prepend.php';
dcPage::checkSuper();
$changes = false;
$blogs = array();
$users = array();
# Check users
if (!empty($_REQUEST['user_id']) && is_array($_REQUEST['user_id']))
{
foreach ($_REQUEST['user_id'] as $u)
{
if ($core->userExists($u)) {
$users[] = $u;
}
}
}
# Check blogs
if (!empty($_REQUEST['blog_id']) && is_array($_REQUEST['blog_id']))
{
foreach ($_REQUEST['blog_id'] as $b)
{
if ($core->blogExists($b)) {
$blogs[] = $b;
}
}
}
# Update permissions
if (!empty($_POST['upd_perm']) && !empty($users) && !empty($blogs))
{
$redir = 'permissions.php?upd=1';
foreach ($users as $u)
{
foreach ($blogs as $b)
{
if (!$core->error->flag())
{
$set_perms = array();
if (!empty($_POST['perm'][$b]))
{
foreach ($_POST['perm'][$b] as $perm_id => $v)
{
if ($v) {
$set_perms[$perm_id] = true;
}
}
}
try {
$core->setUserBlogPermissions($u, $b, $set_perms, true);
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
}
$redir .= '&user_id[]='.$u;
}
if (!$core->error->flag())
{
foreach ($blogs as $b) {
$redir .= '&blog_id[]='.$b;
}
http::redirect($redir);
}
}
if (empty($blogs) || empty($users)) {
$core->error->add(__('No blog or user given.'));
}
/* DISPLAY
-------------------------------------------------------- */
dcPage::open(__('permissions'),
dcPage::jsLoad('js/_permissions.js')
);
echo '<h2><a href="users.php">'.__('Users').'</a> > '.__('Permissions').'</h2>';
if (!empty($_GET['upd'])) {
echo '<p class="message">'.__('The permissions have been successfully updated.').'</p>';
}
if (!empty($blogs) && !empty($users))
{
$perm_form = '';
if (count($users) == 1) {
$user_perm = $core->getUserPermissions($users[0]);
}
foreach ($users as $u) {
$user_list[] = '<a href="user.php?id='.$u.'">'.$u.'</a>';
}
echo '<p>'.sprintf(__('You are about to change permissions on the following blogs for users %s.'),
implode(', ',$user_list));
echo '<form id="permissions-form" action="permissions.php" method="post">';
foreach ($blogs as $b)
{
echo '<h3><a href="blog.php?id='.html::escapeHTML($b).'">'.html::escapeHTML($b).'</a>'.
form::hidden(array('blog_id[]'),$b).'</h3>';
foreach ($core->auth->getPermissionsTypes() as $perm_id => $perm)
{
$checked = false;
if (count($users) == 1) {
$checked = isset($user_perm[$b]['p'][$perm_id]) && $user_perm[$b]['p'][$perm_id];
}
echo
'<p><label class="classic">'.
form::checkbox(array('perm['.html::escapeHTML($b).']['.html::escapeHTML($perm_id).']'),
1,$checked).' '.
__($perm).'</label></p>';
}
}
echo
'<p><input type="submit" accesskey="s" value="'.__('save').'" />'.
$core->formNonce();
foreach ($users as $u) {
echo form::hidden(array('user_id[]'),$u);
}
echo form::hidden('upd_perm',1).'</p></form>';
}
dcPage::close();
?>