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