Dotclear

source: admin/users_actions.php @ 1499:fc4bc1ece727

Revision 1499:fc4bc1ece727, 7.4 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Let fieldsets be fieldsets (work in progress): blogpref, category, blogtheme, langs, media, plugins, user actions, antispam, importexport.

Line 
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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::checkSuper();
16
17$users = array();
18if (!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();
29if (!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-------------------------------------------------------- */
41if (!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-------------------------------------------------------- */
133if (!empty($users) && empty($blogs) && $action == 'blogs') {
134     $breadcrumb = dcPage::breadcrumb(
135          array(
136               __('System') => '',
137               __('Users') => 'users.php',
138               '<span class="page-title">'.__('Permissions').'</span>' => ''
139          ));
140} else {
141     $breadcrumb = dcPage::breadcrumb(
142          array(
143               __('System') => '',
144               __('Users') => 'users.php',
145               '<span class="page-title">'.__('Actions').'</span>' => ''
146          ));
147}
148
149dcPage::open(
150     __('Users'),
151     dcPage::jsLoad('js/_users_actions.js').
152     # --BEHAVIOR-- adminUsersActionsHeaders
153     $core->callBehavior('adminUsersActionsHeaders'),
154     $breadcrumb
155);
156
157if (!isset($action)) {
158     dcPage::close();
159     exit;
160}
161
162$hidden_fields = '';
163foreach($users as $u) {
164     $hidden_fields .= form::hidden(array('users[]'),$u);
165}
166
167if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
168{
169     $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir']));
170}
171else
172{
173     $hidden_fields .=
174     form::hidden(array('q'),html::escapeHTML($_POST['q'])).
175     form::hidden(array('sortby'),$_POST['sortby']).
176     form::hidden(array('order'),$_POST['order']).
177     form::hidden(array('page'),$_POST['page']).
178     form::hidden(array('nb'),$_POST['nb']);
179}
180
181echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('Back to user profile').'</a></p>';
182
183# --BEHAVIOR-- adminUsersActionsContent
184$core->callBehavior('adminUsersActionsContent',$core,$action,$hidden_fields);
185
186# Blog list where to set permissions
187if (!empty($users) && empty($blogs) && $action == 'blogs')
188{
189     try {
190          $rs = $core->getBlogs();
191          $nb_blog = $rs->count();
192     } catch (Exception $e) { }
193     
194     foreach ($users as $u) {
195          $user_list[] = '<a href="user.php?id='.$u.'">'.$u.'</a>';
196     }
197     
198     echo
199     '<p>'.sprintf(
200          __('Choose one or more blogs to which you want to give permissions to users %s.'),
201          implode(', ',$user_list)
202     ).'</p>';
203     
204     if ($nb_blog == 0)
205     {
206          echo '<p><strong>'.__('No blog').'</strong></p>';
207     }
208     else
209     {
210          echo
211          '<form action="users_actions.php" method="post" id="form-blogs">'.
212          '<table class="clear"><tr>'.
213          '<th class="nowrap" colspan="2">'.__('Blog ID').'</th>'.
214          '<th class="nowrap">'.__('Blog name').'</th>'.
215          '<th class="nowrap">'.__('Entries').'</th>'.
216          '<th class="nowrap">'.__('Status').'</th>'.
217          '</tr>';
218         
219          while ($rs->fetch())
220          {
221               $img_status = $rs->blog_status == 1 ? 'check-on' : 'check-off';
222               $txt_status = $core->getBlogStatus($rs->blog_status);
223               $img_status = sprintf('<img src="images/%1$s.png" alt="%2$s" title="%2$s" />',$img_status,$txt_status);
224               
225               echo
226               '<tr class="line">'.
227               '<td class="nowrap">'.
228               form::checkbox(array('blogs[]'),$rs->blog_id,'','','',false,'title="'.__('select').' '.$rs->blog_id.'"').'</td>'.
229               '<td class="nowrap">'.$rs->blog_id.'</td>'.
230               '<td class="maximal">'.html::escapeHTML($rs->blog_name).'</td>'.
231               '<td class="nowrap">'.$core->countBlogPosts($rs->blog_id).'</td>'.
232               '<td class="status">'.$img_status.'</td>'.
233               '</tr>';
234          }
235         
236          echo
237          '</table>'.
238          '<p class="checkboxes-helpers"></p>'.
239          '<p><input type="submit" value="'.__('Set permissions').'" />'.
240          $hidden_fields.
241          form::hidden(array('action'),'perms').
242          $core->formNonce().'</p>'.
243          '</form>';
244     }
245}
246# Permissions list for each selected blogs
247elseif (!empty($blogs) && !empty($users) && $action == 'perms')
248{
249     $user_perm = array();
250     if (count($users) == 1) {
251               $user_perm = $core->getUserPermissions($users[0]);     
252     }
253     
254     foreach ($users as $u) {
255          $user_list[] = '<a href="user.php?id='.$u.'">'.$u.'</a>';
256     }
257     
258     echo 
259     '<p>'.sprintf(
260          __('You are about to change permissions on the following blogs for users %s.'),
261          implode(', ',$user_list)
262     ).'</p>'.
263     '<form id="permissions-form" action="users_actions.php" method="post">';
264     
265     foreach ($blogs as $b)
266     {
267          echo '<h3>'.('Blog:').' <a href="blog.php?id='.html::escapeHTML($b).'">'.html::escapeHTML($b).'</a>'.
268          form::hidden(array('blogs[]'),$b).'</h3>';
269         
270          foreach ($core->auth->getPermissionsTypes() as $perm_id => $perm)
271          {
272               $checked = false;
273               
274               if (count($users) == 1) {
275                    $checked = isset($user_perm[$b]['p'][$perm_id]) && $user_perm[$b]['p'][$perm_id];
276               }
277               
278               echo
279               '<p><label for="perm'.html::escapeHTML($b).html::escapeHTML($perm_id).'" class="classic">'.
280               form::checkbox(array('perm['.html::escapeHTML($b).']['.html::escapeHTML($perm_id).']','perm'.html::escapeHTML($b).html::escapeHTML($perm_id)),
281               1,$checked).' '.
282               __($perm).'</label></p>';
283          }
284     }
285     
286     echo
287     '<div class="fieldset">'.
288     '<h3>'.__('Validate permissions').'</h3>'.
289     '<p><label for="your_pwd">'.__('Your password:').'</label>'.
290     form::password('your_pwd',20,255).'</p>'.
291     '<p><input type="submit" accesskey="s" value="'.__('Save').'" />'.
292     $hidden_fields.
293     form::hidden(array('action'),'updateperm').
294     $core->formNonce().'</p>'.
295     '</div>'.
296     '</form>';
297}
298
299dcPage::close();
300?>
Note: See TracBrowser for help on using the repository browser.

Sites map