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

Last change on this file since 17972 was 17972, checked in by Eric, 12 years ago

Delete rejected.php and rejected.tpl. Unusefull since Flop25's recoding (thx !)
Small typo fix

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