1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | |
---|
13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::checkSuper(); |
---|
16 | |
---|
17 | $changes = false; |
---|
18 | $blogs = array(); |
---|
19 | $users = array(); |
---|
20 | |
---|
21 | # Check users |
---|
22 | if (!empty($_REQUEST['user_id']) && is_array($_REQUEST['user_id'])) |
---|
23 | { |
---|
24 | foreach ($_REQUEST['user_id'] as $u) |
---|
25 | { |
---|
26 | if ($core->userExists($u)) { |
---|
27 | $users[] = $u; |
---|
28 | } |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | # Check blogs |
---|
33 | if (!empty($_REQUEST['blog_id']) && is_array($_REQUEST['blog_id'])) |
---|
34 | { |
---|
35 | foreach ($_REQUEST['blog_id'] as $b) |
---|
36 | { |
---|
37 | if ($core->blogExists($b)) { |
---|
38 | $blogs[] = $b; |
---|
39 | } |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | # Update permissions |
---|
44 | if (!empty($_POST['upd_perm']) && !empty($users) && !empty($blogs)) |
---|
45 | { |
---|
46 | $redir = 'permissions.php?upd=1'; |
---|
47 | |
---|
48 | try |
---|
49 | { |
---|
50 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { |
---|
51 | throw new Exception(__('Password verification failed')); |
---|
52 | } |
---|
53 | |
---|
54 | foreach ($users as $u) |
---|
55 | { |
---|
56 | foreach ($blogs as $b) |
---|
57 | { |
---|
58 | $set_perms = array(); |
---|
59 | |
---|
60 | if (!empty($_POST['perm'][$b])) |
---|
61 | { |
---|
62 | foreach ($_POST['perm'][$b] as $perm_id => $v) |
---|
63 | { |
---|
64 | if ($v) { |
---|
65 | $set_perms[$perm_id] = true; |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | $core->setUserBlogPermissions($u, $b, $set_perms, true); |
---|
71 | } |
---|
72 | |
---|
73 | $redir .= '&user_id[]='.$u; |
---|
74 | } |
---|
75 | |
---|
76 | foreach ($blogs as $b) { |
---|
77 | $redir .= '&blog_id[]='.$b; |
---|
78 | } |
---|
79 | http::redirect($redir); |
---|
80 | } |
---|
81 | catch (Exception $e) |
---|
82 | { |
---|
83 | $core->error->add($e->getMessage()); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | if (empty($blogs) || empty($users)) { |
---|
90 | $core->error->add(__('No blog or user given.')); |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | /* DISPLAY |
---|
95 | -------------------------------------------------------- */ |
---|
96 | dcPage::open(__('permissions'), |
---|
97 | dcPage::jsLoad('js/_permissions.js') |
---|
98 | ); |
---|
99 | |
---|
100 | echo '<h2><a href="users.php">'.__('Users').'</a> › <span class="page-title">'.__('Permissions').'</span></h2>'; |
---|
101 | |
---|
102 | if (!empty($_GET['upd'])) { |
---|
103 | echo '<p class="message">'.__('The permissions have been successfully updated.').'</p>'; |
---|
104 | } |
---|
105 | |
---|
106 | if (!empty($blogs) && !empty($users)) |
---|
107 | { |
---|
108 | $perm_form = ''; |
---|
109 | |
---|
110 | if (count($users) == 1) { |
---|
111 | $user_perm = $core->getUserPermissions($users[0]); |
---|
112 | } |
---|
113 | |
---|
114 | foreach ($users as $u) { |
---|
115 | $user_list[] = '<a href="user.php?id='.$u.'">'.$u.'</a>'; |
---|
116 | } |
---|
117 | |
---|
118 | echo '<p>'.sprintf(__('You are about to change permissions on the following blogs for users %s.'), |
---|
119 | implode(', ',$user_list)); |
---|
120 | |
---|
121 | echo '<form id="permissions-form" action="permissions.php" method="post">'; |
---|
122 | |
---|
123 | foreach ($blogs as $b) |
---|
124 | { |
---|
125 | echo '<h3><a href="blog.php?id='.html::escapeHTML($b).'">'.html::escapeHTML($b).'</a>'. |
---|
126 | form::hidden(array('blog_id[]'),$b).'</h3>'; |
---|
127 | |
---|
128 | foreach ($core->auth->getPermissionsTypes() as $perm_id => $perm) |
---|
129 | { |
---|
130 | $checked = false; |
---|
131 | |
---|
132 | if (count($users) == 1) { |
---|
133 | $checked = isset($user_perm[$b]['p'][$perm_id]) && $user_perm[$b]['p'][$perm_id]; |
---|
134 | } |
---|
135 | |
---|
136 | echo |
---|
137 | '<p><label for="perm'.html::escapeHTML($b).html::escapeHTML($perm_id).'" class="classic">'. |
---|
138 | form::checkbox(array('perm['.html::escapeHTML($b).']['.html::escapeHTML($perm_id).']','perm'.html::escapeHTML($b).html::escapeHTML($perm_id)), |
---|
139 | 1,$checked).' '. |
---|
140 | __($perm).'</label></p>'; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | echo |
---|
145 | '<fieldset>'. |
---|
146 | '<p><label for="your_pwd">'.__('Your password:'). |
---|
147 | form::password('your_pwd',20,255).'</label></p>'. |
---|
148 | '</fieldset>'. |
---|
149 | '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'. |
---|
150 | $core->formNonce(); |
---|
151 | |
---|
152 | foreach ($users as $u) { |
---|
153 | echo form::hidden(array('user_id[]'),$u); |
---|
154 | } |
---|
155 | |
---|
156 | echo form::hidden('upd_perm',1).'</p></form>'; |
---|
157 | } |
---|
158 | |
---|
159 | dcPage::close(); |
---|
160 | ?> |
---|