1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 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 | $users = array(); |
---|
18 | if (!empty($_POST['users']) && is_array($_POST['users'])) |
---|
19 | { |
---|
20 | foreach ($_POST['users'] as $u) |
---|
21 | { |
---|
22 | if ($core->userExists($u)) { |
---|
23 | $users[] = $u; |
---|
24 | } |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | $blogs = array(); |
---|
29 | if (!empty($_POST['blogs']) && is_array($_POST['blogs'])) |
---|
30 | { |
---|
31 | foreach ($_POST['blogs'] as $b) |
---|
32 | { |
---|
33 | if ($core->blogExists($b)) { |
---|
34 | $blogs[] = $b; |
---|
35 | } |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | /* Actions |
---|
40 | -------------------------------------------------------- */ |
---|
41 | if (!empty($_POST['action']) && !empty($_POST['users'])) |
---|
42 | { |
---|
43 | $action = $_POST['action']; |
---|
44 | |
---|
45 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
46 | { |
---|
47 | $redir = $_POST['redir']; |
---|
48 | } |
---|
49 | else |
---|
50 | { |
---|
51 | $redir = |
---|
52 | 'users.php?q='.$_POST['q']. |
---|
53 | '&sortby='.$_POST['sortby']. |
---|
54 | '&order='.$_POST['order']. |
---|
55 | '&page='.$_POST['page']. |
---|
56 | '&nb='.$_POST['nb']; |
---|
57 | } |
---|
58 | |
---|
59 | if (empty($users)) { |
---|
60 | $core->error->add(__('No blog or user given.')); |
---|
61 | } |
---|
62 | |
---|
63 | # --BEHAVIOR-- adminUsersActions |
---|
64 | $core->callBehavior('adminUsersActions',$core,$users,$blogs,$action,$redir); |
---|
65 | |
---|
66 | # Delete users |
---|
67 | if ($action == 'deleteuser' && !empty($users)) |
---|
68 | { |
---|
69 | foreach ($users as $u) |
---|
70 | { |
---|
71 | try |
---|
72 | { |
---|
73 | if ($u == $core->auth->userID()) { |
---|
74 | throw new Exception(__('Not delete yourself.')); |
---|
75 | } |
---|
76 | |
---|
77 | # --BEHAVIOR-- adminBeforeUserDelete |
---|
78 | $core->callBehavior('adminBeforeUserDelete',$u); |
---|
79 | |
---|
80 | $core->delUser($u); |
---|
81 | } |
---|
82 | catch (Exception $e) |
---|
83 | { |
---|
84 | $core->error->add($e->getMessage()); |
---|
85 | } |
---|
86 | } |
---|
87 | if (!$core->error->flag()) { |
---|
88 | http::redirect($redir.'&del=1'); |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | # Update users perms |
---|
93 | if ($action == 'updateperm' && !empty($users) && !empty($blogs)) |
---|
94 | { |
---|
95 | try |
---|
96 | { |
---|
97 | if (empty($_POST['your_pwd']) || !$core->auth->checkPassword(crypt::hmac(DC_MASTER_KEY,$_POST['your_pwd']))) { |
---|
98 | throw new Exception(__('Password verification failed')); |
---|
99 | } |
---|
100 | |
---|
101 | foreach ($users as $u) |
---|
102 | { |
---|
103 | foreach ($blogs as $b) |
---|
104 | { |
---|
105 | $set_perms = array(); |
---|
106 | |
---|
107 | if (!empty($_POST['perm'][$b])) |
---|
108 | { |
---|
109 | foreach ($_POST['perm'][$b] as $perm_id => $v) |
---|
110 | { |
---|
111 | if ($v) { |
---|
112 | $set_perms[$perm_id] = true; |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | $core->setUserBlogPermissions($u,$b,$set_perms,true); |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | catch (Exception $e) |
---|
122 | { |
---|
123 | $core->error->add($e->getMessage()); |
---|
124 | } |
---|
125 | if (!$core->error->flag()) { |
---|
126 | http::redirect($redir.'&upd=1'); |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | /* DISPLAY |
---|
132 | -------------------------------------------------------- */ |
---|
133 | dcPage::open( |
---|
134 | __('Users'), |
---|
135 | dcPage::jsLoad('js/_users_actions.js'). |
---|
136 | # --BEHAVIOR-- adminUsersActionsHeaders |
---|
137 | $core->callBehavior('adminUsersActionsHeaders') |
---|
138 | ); |
---|
139 | |
---|
140 | if (!isset($action)) { |
---|
141 | dcPage::close(); |
---|
142 | exit; |
---|
143 | } |
---|
144 | |
---|
145 | $hidden_fields = ''; |
---|
146 | foreach($users as $u) { |
---|
147 | $hidden_fields .= form::hidden(array('users[]'),$u); |
---|
148 | } |
---|
149 | |
---|
150 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
151 | { |
---|
152 | $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | $hidden_fields .= |
---|
157 | form::hidden(array('q'),html::escapeHTML($_POST['q'])). |
---|
158 | form::hidden(array('sortby'),$_POST['sortby']). |
---|
159 | form::hidden(array('order'),$_POST['order']). |
---|
160 | form::hidden(array('page'),$_POST['page']). |
---|
161 | form::hidden(array('nb'),$_POST['nb']); |
---|
162 | } |
---|
163 | |
---|
164 | # --BEHAVIOR-- adminUsersActionsContent |
---|
165 | $core->callBehavior('adminUsersActionsContent',$core,$action,$hidden_fields); |
---|
166 | |
---|
167 | # Blog list where to set permissions |
---|
168 | if (!empty($users) && empty($blogs) && $action == 'blogs') |
---|
169 | { |
---|
170 | try { |
---|
171 | $rs = $core->getBlogs(); |
---|
172 | $nb_blog = $rs->count(); |
---|
173 | } catch (Exception $e) { } |
---|
174 | |
---|
175 | foreach ($users as $u) { |
---|
176 | $user_list[] = '<a href="user.php?id='.$u.'">'.$u.'</a>'; |
---|
177 | } |
---|
178 | |
---|
179 | echo dcPage::breadcrumb( |
---|
180 | array( |
---|
181 | __('System') => '', |
---|
182 | __('Users') => 'users.php', |
---|
183 | '<span class="page-title">'.__('Permissions').'</span>' => '' |
---|
184 | )); |
---|
185 | |
---|
186 | echo |
---|
187 | '<p>'.sprintf( |
---|
188 | __('Choose one or more blogs to which you want to give permissions to users %s.'), |
---|
189 | implode(', ',$user_list) |
---|
190 | ).'</p>'; |
---|
191 | |
---|
192 | if ($nb_blog == 0) |
---|
193 | { |
---|
194 | echo '<p><strong>'.__('No blog').'</strong></p>'; |
---|
195 | } |
---|
196 | else |
---|
197 | { |
---|
198 | echo |
---|
199 | '<form action="users_actions.php" method="post" id="form-blogs">'. |
---|
200 | '<table class="clear"><tr>'. |
---|
201 | '<th class="nowrap" colspan="2">'.__('Blog ID').'</th>'. |
---|
202 | '<th class="nowrap">'.__('Blog name').'</th>'. |
---|
203 | '<th class="nowrap">'.__('Entries').'</th>'. |
---|
204 | '<th class="nowrap">'.__('Status').'</th>'. |
---|
205 | '</tr>'; |
---|
206 | |
---|
207 | while ($rs->fetch()) |
---|
208 | { |
---|
209 | $img_status = $rs->blog_status == 1 ? 'check-on' : 'check-off'; |
---|
210 | $txt_status = $core->getBlogStatus($rs->blog_status); |
---|
211 | $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status); |
---|
212 | |
---|
213 | echo |
---|
214 | '<tr class="line">'. |
---|
215 | '<td class="nowrap">'. |
---|
216 | form::checkbox(array('blogs[]'),$rs->blog_id,'','','',false,'title="'.__('select').' '.$rs->blog_id.'"').'</td>'. |
---|
217 | '<td class="nowrap">'.$rs->blog_id.'</td>'. |
---|
218 | '<td class="maximal">'.html::escapeHTML($rs->blog_name).'</td>'. |
---|
219 | '<td class="nowrap">'.$core->countBlogPosts($rs->blog_id).'</td>'. |
---|
220 | '<td class="status">'.$img_status.'</td>'. |
---|
221 | '</tr>'; |
---|
222 | } |
---|
223 | |
---|
224 | echo |
---|
225 | '</table>'. |
---|
226 | '<p class="checkboxes-helpers"></p>'. |
---|
227 | '<p><input type="submit" value="'.__('Set permissions').'" />'. |
---|
228 | $hidden_fields. |
---|
229 | form::hidden(array('action'),'perms'). |
---|
230 | $core->formNonce().'</p>'. |
---|
231 | '</form>'; |
---|
232 | } |
---|
233 | } |
---|
234 | # Permissions list for each selected blogs |
---|
235 | elseif (!empty($blogs) && !empty($users) && $action == 'perms') |
---|
236 | { |
---|
237 | $user_perm = array(); |
---|
238 | if (count($users) == 1) { |
---|
239 | $user_perm = $core->getUserPermissions($users[0]); |
---|
240 | } |
---|
241 | |
---|
242 | foreach ($users as $u) { |
---|
243 | $user_list[] = '<a href="user.php?id='.$u.'">'.$u.'</a>'; |
---|
244 | } |
---|
245 | |
---|
246 | echo |
---|
247 | '<h2><a href="users.php">'.__('Users').'</a> › <span class="page-title">'.__('Permissions').'</span></h2>'. |
---|
248 | '<p>'.sprintf( |
---|
249 | __('You are about to change permissions on the following blogs for users %s.'), |
---|
250 | implode(', ',$user_list) |
---|
251 | ).'</p>'. |
---|
252 | '<form id="permissions-form" action="users_actions.php" method="post">'; |
---|
253 | |
---|
254 | foreach ($blogs as $b) |
---|
255 | { |
---|
256 | echo '<h3><a href="blog.php?id='.html::escapeHTML($b).'">'.html::escapeHTML($b).'</a>'. |
---|
257 | form::hidden(array('blogs[]'),$b).'</h3>'; |
---|
258 | |
---|
259 | foreach ($core->auth->getPermissionsTypes() as $perm_id => $perm) |
---|
260 | { |
---|
261 | $checked = false; |
---|
262 | |
---|
263 | if (count($users) == 1) { |
---|
264 | $checked = isset($user_perm[$b]['p'][$perm_id]) && $user_perm[$b]['p'][$perm_id]; |
---|
265 | } |
---|
266 | |
---|
267 | echo |
---|
268 | '<p><label for="perm'.html::escapeHTML($b).html::escapeHTML($perm_id).'" class="classic">'. |
---|
269 | form::checkbox(array('perm['.html::escapeHTML($b).']['.html::escapeHTML($perm_id).']','perm'.html::escapeHTML($b).html::escapeHTML($perm_id)), |
---|
270 | 1,$checked).' '. |
---|
271 | __($perm).'</label></p>'; |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | echo |
---|
276 | '<fieldset><legend>'.__('Validate permissions').'</legend>'. |
---|
277 | '<p><label for="your_pwd">'.__('Your password:'). |
---|
278 | form::password('your_pwd',20,255).'</label></p>'. |
---|
279 | '</fieldset>'. |
---|
280 | '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'. |
---|
281 | $hidden_fields. |
---|
282 | form::hidden(array('action'),'updateperm'). |
---|
283 | $core->formNonce().'</p>'. |
---|
284 | '</form>'; |
---|
285 | } |
---|
286 | |
---|
287 | echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>'; |
---|
288 | |
---|
289 | dcPage::close(); |
---|
290 | ?> |
---|