source: extensions/UserAdvManager/trunk/main.inc.php @ 17969

Revision 17969, 8.0 KB checked in by flop25, 7 years ago (diff)

No more need of rejected.php and tpl (je te laisse les supprimer, si tu valides ce changement)

  • Property svn:eol-style set to LF
Line 
1<?php
2/*
3Plugin Name: UserAdvManager
4Version: auto
5Description: Renforcer la gestion des utilisateurs - Enforce users management
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=216
7Author: Nicco, Eric
8Author URI: http://gallery-nicco.no-ip.org, http://www.infernoweb.net
9*/
10
11/* History:  UAM_PATH.'Changelog.txt.php' */
12
13/*
14 ***** TODO List *****
15See project bugtracker: http://piwigo.org/bugs/my_view_page.php
16*/
17
18if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
19if (!defined('UAM_PATH')) define('UAM_PATH' , PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
20
21global $conf;
22
23include_once (UAM_PATH.'include/constants.php');
24include_once (UAM_PATH.'include/functions.inc.php');
25
26load_language('plugin.lang', UAM_PATH);
27load_language('help.lang', UAM_PATH);
28$conf_UAM = unserialize($conf['UserAdvManager']);
29
30
31// Plugin administration panel
32// ---------------------------
33add_event_handler('get_admin_plugin_menu_links', 'UAM_admin_menu');
34
35// Features and controls on user connexion
36// ---------------------------------------
37add_event_handler('loc_begin_index', 'UAM_Init');
38
39// User creation
40// -------------
41add_event_handler('register_user', 'UAM_Adduser');
42
43// User deletion
44// -------------
45add_event_handler('delete_user', 'UAM_Deluser');
46
47// Check users registration
48// ------------------------
49add_event_handler('register_user_check', 'UAM_RegistrationCheck', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
50
51if (script_basename() == 'profile')
52{
53  add_event_handler('loc_begin_profile', 'UAM_Profile_Init');
54}
55
56// Redirection to profile page
57// ---------------------------
58add_event_handler('login_success', 'UAM_LoginTasks');
59
60// Adding customized text to lost password email
61// ---------------------------------------------
62add_event_handler('render_lost_password_mail_content', 'UAM_lost_password_mail_content');
63
64// *** Important ! This is necessary to make email exclusion work in admin's users management panel ***
65// ----------------------------------------------------------------------------------------------------
66add_event_handler('init', 'UAM_InitPage');
67
68// Display messages about Login rejected, etc
69// ---------------------------
70add_event_handler('init','UAM_DisplayMsg');
71add_event_handler('identification','UAM_DisplayMsg');
72// PWG_Stuffs module
73// -----------------
74if (isset($conf_UAM[33]) and $conf_UAM[33] == 'true')
75{
76  add_event_handler('get_stuffs_modules', 'register_UAM_stuffs_module');
77}
78
79// Add new feature in user_list - Password Reset
80// ---------------------------------------------
81if (isset($conf_UAM[38]) and $conf_UAM[38] == 'true')
82{
83  // Add new column on user_list
84  // ---------------------------
85  add_event_handler('loc_visible_user_list', 'UAM_loc_visible_user_list');
86
87  // Add prefilter on user_list
88  // --------------------------
89  add_event_handler('loc_begin_admin', 'UAM_PwdReset_Action',60);
90
91  /**
92   * UAM_PwdReset_Action - Triggered on UAM_PwdReset_Action
93   * Handle password reset action in user_list.php
94   */
95  function UAM_PwdReset_Action()
96  {
97    global $conf, $user, $template, $lang, $errors;
98
99    $page['errors'] = array();
100    $page['infos'] = array();
101    $page['filtered_users'] = array();
102
103    if (isset($_POST['pwdreset']))
104    {
105      $collection = array();
106
107      switch ($_POST['target'])
108      {
109        case 'all' :
110        {
111          foreach($page['filtered_users'] as $local_user)
112          {
113            array_push($collection, $local_user['id']);
114          }
115          break;
116        }
117        case 'selection' :
118        {
119          if (isset($_POST['selection']))
120          {
121            $collection = $_POST['selection'];
122          }
123          break;
124        }
125      }
126
127      if (count($collection) == 0)
128      {
129        array_push($page['errors'], l10n('Select at least one user'));
130      }
131    }
132
133    if (isset($_POST['pwdreset']) and count($collection) > 0)
134    {
135      if (in_array($conf['guest_id'], $collection))
136      {
137        array_push($page['errors'], l10n('UAM_Guest cannot be pwdreset'));
138        $template->append('errors', l10n('UAM_Guest cannot be pwdreset'));
139      }
140      if (($conf['guest_id'] != $conf['default_user_id']) and
141        in_array($conf['default_user_id'], $collection))
142      {
143        array_push($page['errors'], l10n('UAM_Default user cannot be pwgreset'));
144        $template->append('errors', l10n('UAM_Default user cannot be pwgreset'));
145      }
146      if (in_array($conf['webmaster_id'], $collection))
147      {
148        array_push($page['errors'], l10n('UAM_Webmaster cannot be pwdreset'));
149        $template->append('errors', l10n('UAM_Webmaster cannot be pwdreset'));
150      }
151      if (in_array($user['id'], $collection))
152      {
153        array_push($page['errors'], l10n('UAM_You cannot pwdreset your account'));
154        $template->append('errors', l10n('UAM_You cannot pwdreset your account'));
155      }
156
157      // Generic accounts exclusion (including Adult_Content generic users)
158      // ------------------------------------------------------------------
159      $query ='
160SELECT u.id
161FROM '.USERS_TABLE.' AS u
162INNER JOIN '.USER_INFOS_TABLE.' AS ui
163  ON u.id = ui.user_id
164WHERE ui.status = "generic"
165;';
166
167            $result = pwg_query($query);
168
169      while ($row = pwg_db_fetch_assoc($result))
170      {
171        if (in_array($row['id'], $collection))
172        {
173          array_push($page['errors'], l10n('UAM_Generic cannot be pwdreset'));
174          $errors = l10n('UAM_Generic cannot be pwdreset');
175        }
176      }
177
178      // Admins accounts exclusion
179      // --------------------------
180      $query ='
181SELECT u.id
182FROM '.USERS_TABLE.' AS u
183INNER JOIN '.USER_INFOS_TABLE.' AS ui
184  ON u.id = ui.user_id
185WHERE ui.status = "admin"
186;';
187
188            $result = pwg_query($query);
189
190      while ($row = pwg_db_fetch_assoc($result))
191      {
192        if (in_array($row['id'], $collection))
193        {
194          array_push($page['errors'], l10n('UAM_Admins cannot be pwdreset'));
195          $errors = l10n('UAM_Admins cannot be pwdreset');
196        }
197      }
198
199      $template->append('errors', $errors);
200
201      if (count($page['errors']) == 0)
202      {
203        if (isset($_POST['confirm_pwdreset']) and 1 == $_POST['confirm_pwdreset'])
204        {
205          foreach ($collection as $user_id)
206          {
207            UAM_Set_PwdReset($user_id);
208          }
209          array_push(
210            $page['infos'],
211            l10n_dec(
212              'UAM %d user pwdreseted', 'UAM %d users pwdreseted',
213              count($collection)
214              )
215            );
216          $template->append('infos', l10n_dec(
217              'UAM %d user pwdreseted', 'UAM %d users pwdreseted',
218              count($collection)));
219          foreach ($page['filtered_users'] as $filter_key => $filter_user)
220          {
221            if (in_array($filter_user['id'], $collection))
222            {
223              unset($page['filtered_users'][$filter_key]);
224            }
225          }
226        }
227        else
228        {
229          array_push($page['errors'], l10n('UAM_You need to confirm pwdreset'));
230          $template->append('errors', l10n('UAM_You need to confirm pwdreset'));
231        }
232      }
233    }
234    $template->set_prefilter('user_list', 'UAM_PwdReset_Prefilter');
235  }
236
237  /**
238   * UAM_PwdReset_Prefilter
239   * Adds action field for password reset in user_list.tpl
240   */
241  function UAM_PwdReset_Prefilter($content, &$smarty)
242  {
243    $search = '
244<fieldset>
245  <legend>{\'Deletions\'|@translate}</legend>
246  <label><input type="checkbox" name="confirm_deletion" value="1"> {\'confirm\'|@translate}</label>
247  <input class="submit" type="submit" value="{\'Delete selected users\'|@translate}" name="delete">
248</fieldset>
249';
250 
251    $addon = '
252<fieldset>
253  <legend>{\'UAM_PwdReset\'|@translate}</legend>
254  <label><input type="checkbox" name="confirm_pwdreset" value="1"> {\'confirm\'|@translate}</label>
255  <input class="submit" type="submit" value="{\'UAM_Password reset selected users\'|@translate}" name="pwdreset">
256</fieldset>
257';
258
259    $replacement = $addon.$search;
260
261    return str_replace($search, $replacement, $content);
262  }
263}
264
265
266// Check options compatibility between UAM and Piwigo at admin page load
267// ---------------------------------------------------------------------
268add_event_handler('loc_begin_admin_page', 'UAM_check_compat');
269?>
Note: See TracBrowser for help on using the repository browser.