[5056] | 1 | <?php |
---|
[5181] | 2 | include_once (UAM_PATH.'include/constants.php'); |
---|
| 3 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 4 | |
---|
[10144] | 5 | |
---|
[7968] | 6 | /** |
---|
| 7 | * Triggered on get_admin_plugin_menu_links |
---|
| 8 | * |
---|
| 9 | * Plugin's administration menu |
---|
| 10 | */ |
---|
| 11 | function UAM_admin_menu($menu) |
---|
| 12 | { |
---|
| 13 | // +-----------------------------------------------------------------------+ |
---|
| 14 | // | Getting plugin name | |
---|
| 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | $plugin = PluginInfos(UAM_PATH); |
---|
| 17 | $name = $plugin['name']; |
---|
| 18 | |
---|
| 19 | array_push($menu, |
---|
| 20 | array( |
---|
[17944] | 21 | 'NAME' => $name, |
---|
| 22 | 'URL' => get_root_url().'admin.php?page=plugin-'.basename(UAM_PATH) |
---|
[7968] | 23 | ) |
---|
| 24 | ); |
---|
| 25 | |
---|
| 26 | return $menu; |
---|
| 27 | } |
---|
| 28 | |
---|
[10144] | 29 | |
---|
[7968] | 30 | /** |
---|
[17507] | 31 | * Triggered on loc_begin_admin_page |
---|
| 32 | * |
---|
| 33 | * Check options compatibility |
---|
| 34 | */ |
---|
| 35 | function UAM_check_compat() |
---|
| 36 | { |
---|
| 37 | global $conf, $page; |
---|
[17846] | 38 | |
---|
| 39 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[17507] | 40 | |
---|
| 41 | // Check mandatory email address for email exclusion |
---|
| 42 | if (!$conf['obligatory_user_mail_address'] and $conf_UAM[10] = 'true') |
---|
| 43 | { |
---|
| 44 | array_push($page['warnings'], l10n('UAM_mail_exclusion_error')); |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | /** |
---|
[7968] | 50 | * Triggered on loc_begin_index |
---|
| 51 | * |
---|
[17804] | 52 | * Initiating GhostTracker - Perform user logout after registration if not validated |
---|
[7968] | 53 | */ |
---|
[17889] | 54 | function UAM_Init() |
---|
[7968] | 55 | { |
---|
| 56 | global $conf, $user; |
---|
| 57 | |
---|
[17804] | 58 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 59 | |
---|
[7968] | 60 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 61 | |
---|
| 62 | // Admins, Guests and Adult_Content users are not tracked for Ghost Tracker or Users Tracker |
---|
[12271] | 63 | // ----------------------------------------------------------------------------------------- |
---|
[7968] | 64 | if (!is_admin() and !is_a_guest() and $user['username'] != "16" and $user['username'] != "18") |
---|
| 65 | { |
---|
[11018] | 66 | if ((isset($conf_UAM[15]) and $conf_UAM[15] == 'true') or (isset($conf_UAM[18]) and $conf_UAM[18] == 'true')) |
---|
[7968] | 67 | { |
---|
| 68 | |
---|
[17944] | 69 | $userid = get_userid($user['username']); |
---|
[17887] | 70 | |
---|
[7968] | 71 | // Looking for existing entry in last visit table |
---|
[12271] | 72 | // ---------------------------------------------- |
---|
[7968] | 73 | $query = ' |
---|
| 74 | SELECT * |
---|
| 75 | FROM '.USER_LASTVISIT_TABLE.' |
---|
| 76 | WHERE user_id = '.$userid.' |
---|
| 77 | ;'; |
---|
| 78 | |
---|
| 79 | $count = pwg_db_num_rows(pwg_query($query)); |
---|
| 80 | |
---|
| 81 | if ($count == 0) |
---|
| 82 | { |
---|
| 83 | // If not, data are inserted in table |
---|
[12271] | 84 | // ---------------------------------- |
---|
[7968] | 85 | $query = ' |
---|
| 86 | INSERT INTO '.USER_LASTVISIT_TABLE.' (user_id, lastvisit, reminder) |
---|
| 87 | VALUES ('.$userid.', now(), "false") |
---|
| 88 | ;'; |
---|
| 89 | pwg_query($query); |
---|
| 90 | } |
---|
| 91 | else if ($count > 0) |
---|
| 92 | { |
---|
| 93 | // If yes, data are updated in table |
---|
[12271] | 94 | // --------------------------------- |
---|
[7968] | 95 | $query = ' |
---|
| 96 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
| 97 | SET lastvisit = now(), reminder = "false" |
---|
| 98 | WHERE user_id = '.$userid.' |
---|
| 99 | LIMIT 1 |
---|
| 100 | ;'; |
---|
| 101 | pwg_query($query); |
---|
| 102 | } |
---|
| 103 | } |
---|
[17804] | 104 | |
---|
[17968] | 105 | // Perform user logout after registration if not validated |
---|
| 106 | if ((isset($conf_UAM[39]) and $conf_UAM[39] == 'true') and !UAM_UsrReg_Verif($user['id']) and !is_admin() and !is_webmaster() ) |
---|
| 107 | { |
---|
| 108 | invalidate_user_cache(); |
---|
| 109 | logout_user(); |
---|
[17969] | 110 | if ( $conf['guest_access'] ) |
---|
| 111 | { |
---|
| 112 | redirect( make_index_url().'?UAM_msg=rejected', 0); |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | { |
---|
| 116 | redirect( get_root_url().'identification.php?UAM_msg=rejected' , 0); |
---|
| 117 | } |
---|
[17968] | 118 | } |
---|
[17887] | 119 | } |
---|
[7968] | 120 | } |
---|
| 121 | |
---|
[10144] | 122 | |
---|
[7968] | 123 | /** |
---|
| 124 | * Triggered on register_user |
---|
| 125 | * |
---|
| 126 | * Additional controls on user registration |
---|
| 127 | */ |
---|
| 128 | function UAM_Adduser($register_user) |
---|
| 129 | { |
---|
| 130 | global $conf; |
---|
| 131 | |
---|
| 132 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 133 | |
---|
| 134 | // Exclusion of Adult_Content users |
---|
[12271] | 135 | // -------------------------------- |
---|
[7968] | 136 | if ($register_user['username'] != "16" and $register_user['username'] != "18") |
---|
| 137 | { |
---|
[13822] | 138 | $passwd = (isset($_POST['password'])) ? $_POST['password'] : ''; |
---|
[14366] | 139 | |
---|
| 140 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'local') |
---|
[7968] | 141 | { |
---|
[14366] | 142 | // This is to set user to "waiting" group or status and without ConfirMail until admin validation |
---|
| 143 | // ---------------------------------------------------------------------------------------------- |
---|
[12189] | 144 | SetPermission($register_user['id']);// Set to "waiting" group or status until admin validation |
---|
[17918] | 145 | |
---|
| 146 | // This is to set UAM_validated field to false in #_users table - Usefull if no "waiting" group or status is set |
---|
| 147 | // ------------------------------------------------------------------------------------------------------------- |
---|
| 148 | SetUnvalidated($register_user['id']); |
---|
[17946] | 149 | |
---|
| 150 | // This is to send the validation key by email to admins for their manual validation without having to connect the gallery |
---|
| 151 | // ----------------------------------------------------------------------------------------------------------------------- |
---|
| 152 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
[7968] | 153 | } |
---|
| 154 | // Sending registration confirmation by email |
---|
[12271] | 155 | // ------------------------------------------ |
---|
[14366] | 156 | elseif (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') |
---|
[7968] | 157 | { |
---|
[11018] | 158 | if (is_admin() and isset($conf_UAM[19]) and $conf_UAM[19] == 'true') |
---|
[7968] | 159 | { |
---|
| 160 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
| 161 | } |
---|
[11018] | 162 | elseif (is_admin() and isset($conf_UAM[19]) and $conf_UAM[19] == 'false') |
---|
[7968] | 163 | { |
---|
| 164 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false); |
---|
| 165 | } |
---|
| 166 | elseif (!is_admin()) |
---|
| 167 | { |
---|
| 168 | SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true); |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
[10144] | 174 | |
---|
[7968] | 175 | /** |
---|
| 176 | * Triggered on delete_user |
---|
| 177 | * |
---|
| 178 | * Database cleanup on user deletion |
---|
| 179 | */ |
---|
| 180 | function UAM_Deluser($user_id) |
---|
| 181 | { |
---|
| 182 | // Cleanup for ConfirmMail table |
---|
[12271] | 183 | // ----------------------------- |
---|
[7968] | 184 | DeleteConfirmMail($user_id); |
---|
| 185 | // Cleanup for LastVisit table |
---|
[12271] | 186 | // --------------------------- |
---|
[7968] | 187 | DeleteLastVisit($user_id); |
---|
| 188 | // Cleanup Redirection settings |
---|
[12271] | 189 | // ---------------------------- |
---|
[7968] | 190 | DeleteRedir($user_id); |
---|
| 191 | } |
---|
| 192 | |
---|
[10144] | 193 | |
---|
[7968] | 194 | /** |
---|
| 195 | * Triggered on register_user_check |
---|
| 196 | * |
---|
| 197 | * Additional controls on user registration check |
---|
| 198 | */ |
---|
[8065] | 199 | function UAM_RegistrationCheck($errors, $user) |
---|
[7968] | 200 | { |
---|
[8065] | 201 | global $conf; |
---|
[7968] | 202 | |
---|
| 203 | // Exclusion of Adult_Content users |
---|
[12271] | 204 | // -------------------------------- |
---|
[7968] | 205 | if ($user['username'] != "16" and $user['username'] != "18") |
---|
| 206 | { |
---|
[8065] | 207 | load_language('plugin.lang', UAM_PATH); |
---|
[7968] | 208 | |
---|
| 209 | $PasswordCheck = 0; |
---|
| 210 | |
---|
| 211 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 212 | |
---|
| 213 | // Password enforcement control |
---|
[12271] | 214 | // ---------------------------- |
---|
[11018] | 215 | if (isset($conf_UAM[12]) and $conf_UAM[12] == 'true' and !empty($conf_UAM[13])) |
---|
[7968] | 216 | { |
---|
| 217 | if (!empty($user['password']) and !is_admin()) |
---|
| 218 | { |
---|
| 219 | $PasswordCheck = testpassword($user['password']); |
---|
| 220 | |
---|
[11018] | 221 | if ($PasswordCheck < $conf_UAM[13]) |
---|
[7968] | 222 | { |
---|
[9177] | 223 | $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck); |
---|
[11018] | 224 | $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[13]; |
---|
[8065] | 225 | array_push($errors, $lang['reg_err_pass']); |
---|
[7968] | 226 | } |
---|
| 227 | } |
---|
[11018] | 228 | else if (!empty($user['password']) and is_admin() and isset($conf_UAM[14]) and $conf_UAM[14] == 'true') |
---|
[7968] | 229 | { |
---|
| 230 | $PasswordCheck = testpassword($user['password']); |
---|
| 231 | |
---|
[11018] | 232 | if ($PasswordCheck < $conf_UAM[13]) |
---|
[7968] | 233 | { |
---|
[9177] | 234 | $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck); |
---|
[11018] | 235 | $lang['reg_err_pass'] = l10n_args($message).$conf_UAM[13]; |
---|
[8065] | 236 | array_push($errors, $lang['reg_err_pass']); |
---|
[7968] | 237 | } |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | // Username without forbidden keys |
---|
[12271] | 242 | // ------------------------------- |
---|
[11018] | 243 | if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and !empty($user['username']) and ValidateUsername($user['username']) and !is_admin()) |
---|
[7968] | 244 | { |
---|
[11018] | 245 | $lang['reg_err_login1'] = l10n('UAM_reg_err_login2')."'".$conf_UAM[6]."'"; |
---|
[8065] | 246 | array_push($errors, $lang['reg_err_login1']); |
---|
[7968] | 247 | } |
---|
| 248 | |
---|
| 249 | // Email without forbidden domains |
---|
[12271] | 250 | // ------------------------------- |
---|
[11018] | 251 | if (isset($conf_UAM[10]) and $conf_UAM[10] == 'true' and !empty($user['email']) and ValidateEmailProvider($user['email']) and !is_admin()) |
---|
[7968] | 252 | { |
---|
[11018] | 253 | $lang['reg_err_login1'] = l10n('UAM_reg_err_login5')."'".$conf_UAM[11]."'"; |
---|
[8065] | 254 | array_push($errors, $lang['reg_err_login1']); |
---|
[7968] | 255 | } |
---|
[8065] | 256 | return $errors; |
---|
[7968] | 257 | } |
---|
| 258 | } |
---|
| 259 | |
---|
[10144] | 260 | |
---|
[7968] | 261 | /** |
---|
| 262 | * Triggered on loc_begin_profile |
---|
| 263 | */ |
---|
| 264 | function UAM_Profile_Init() |
---|
| 265 | { |
---|
| 266 | global $conf, $user, $template; |
---|
| 267 | |
---|
| 268 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[12239] | 269 | |
---|
| 270 | // Update first redirection parameter |
---|
[12271] | 271 | // ---------------------------------- |
---|
[11018] | 272 | if ((isset($conf_UAM[20]) and $conf_UAM[20] == 'true')) |
---|
[7968] | 273 | { |
---|
| 274 | $user_idsOK = array(); |
---|
[8065] | 275 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
[7968] | 276 | { |
---|
| 277 | $user_idsOK[] = $user['id']; |
---|
| 278 | |
---|
[17918] | 279 | $query = ' |
---|
| 280 | UPDATE '.CONFIG_TABLE.' |
---|
| 281 | SET value = "'.implode(',', $user_idsOK).'" |
---|
| 282 | WHERE param = "UserAdvManager_Redir";'; |
---|
[7968] | 283 | |
---|
| 284 | pwg_query($query); |
---|
| 285 | } |
---|
| 286 | } |
---|
| 287 | |
---|
[12239] | 288 | // Special message display for password reset |
---|
[12271] | 289 | // ------------------------------------------ |
---|
[12239] | 290 | if ((isset($conf_UAM[38]) and $conf_UAM[38] == 'true')) |
---|
| 291 | { |
---|
| 292 | if (UAM_check_pwgreset($user['id'])) |
---|
| 293 | { |
---|
| 294 | $template->append('errors', l10n('UAM_Password_Reset_Msg')); |
---|
| 295 | } |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | // Controls on profile page submission |
---|
[12271] | 299 | // ----------------------------------- |
---|
[7968] | 300 | if (isset($_POST['validate']) and !is_admin()) |
---|
| 301 | { |
---|
| 302 | // Email without forbidden domains |
---|
[12271] | 303 | // ------------------------------- |
---|
[11018] | 304 | if (isset($conf_UAM[10]) and $conf_UAM[10] == 'true' and !empty($_POST['mail_address'])) |
---|
[7968] | 305 | { |
---|
| 306 | if (ValidateEmailProvider($_POST['mail_address'])) |
---|
| 307 | { |
---|
[11018] | 308 | $template->append('errors', l10n('UAM_reg_err_login5')."'".$conf_UAM[11]."'"); |
---|
[7968] | 309 | unset($_POST['validate']); |
---|
| 310 | } |
---|
| 311 | } |
---|
| 312 | |
---|
[12239] | 313 | // Password reset control |
---|
[12271] | 314 | // ---------------------- |
---|
[12239] | 315 | if (isset($conf_UAM[38]) and $conf_UAM[38] == 'true' and UAM_check_pwgreset($user['id'])) |
---|
| 316 | { |
---|
[13841] | 317 | // if password not changed then pwdreset field = true else pwdreset field = false |
---|
[12271] | 318 | // ------------------------------------------------------------------------------ |
---|
[12239] | 319 | if (!empty($_POST['use_new_pwd'])) |
---|
| 320 | { |
---|
| 321 | $query = ' |
---|
| 322 | UPDATE '.USERS_TABLE.' |
---|
| 323 | SET UAM_pwdreset = "false" |
---|
| 324 | WHERE id = '.$user['id'].' |
---|
| 325 | LIMIT 1 |
---|
| 326 | ;'; |
---|
| 327 | pwg_query($query); |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
[14366] | 331 | $typemail = 3; // Only information email send to user on user profile update if checked |
---|
[7968] | 332 | |
---|
| 333 | if (!empty($_POST['use_new_pwd'])) |
---|
| 334 | { |
---|
[17918] | 335 | $typemail = 2; // Confirmation email on user profile update - With information email |
---|
[7968] | 336 | |
---|
| 337 | // Password enforcement control |
---|
[12271] | 338 | // ---------------------------- |
---|
[11018] | 339 | if (isset($conf_UAM[12]) and $conf_UAM[12] == 'true' and !empty($conf_UAM[13])) |
---|
[7968] | 340 | { |
---|
| 341 | $PasswordCheck = testpassword($_POST['use_new_pwd']); |
---|
| 342 | |
---|
[11018] | 343 | if ($PasswordCheck < $conf_UAM[13]) |
---|
[7968] | 344 | { |
---|
[9177] | 345 | $message = get_l10n_args('UAM_reg_err_login4_%s', $PasswordCheck); |
---|
[11018] | 346 | $template->append('errors', l10n_args($message).$conf_UAM[13]); |
---|
[7968] | 347 | unset($_POST['use_new_pwd']); |
---|
| 348 | unset($_POST['validate']); |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | // Sending registration confirmation by email |
---|
[12271] | 354 | // ------------------------------------------ |
---|
[14857] | 355 | if ((isset($conf_UAM[1]) and $conf_UAM[1] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
---|
[7968] | 356 | { |
---|
| 357 | $confirm_mail_need = false; |
---|
| 358 | |
---|
| 359 | if (!empty($_POST['mail_address'])) |
---|
| 360 | { |
---|
| 361 | $query = ' |
---|
| 362 | SELECT '.$conf['user_fields']['email'].' AS email |
---|
| 363 | FROM '.USERS_TABLE.' |
---|
| 364 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
| 365 | ;'; |
---|
| 366 | |
---|
| 367 | list($current_email) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 368 | |
---|
| 369 | // This is to send a new validation key |
---|
[12271] | 370 | // ------------------------------------ |
---|
[7968] | 371 | if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true')) |
---|
[14366] | 372 | { |
---|
| 373 | SetPermission($user['id']);// Set to "waiting" group or status until user validation |
---|
[17918] | 374 | SetUnvalidated($user['id']); // Set UAM_validated field to false in #_users table |
---|
[7968] | 375 | $confirm_mail_need = true; |
---|
[14366] | 376 | } |
---|
[7968] | 377 | |
---|
| 378 | // This is to set the user to "waiting" group or status until admin validation |
---|
[12271] | 379 | // --------------------------------------------------------------------------- |
---|
[14366] | 380 | elseif ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local')) |
---|
| 381 | { |
---|
[13841] | 382 | SetPermission($user['id']);// Set to "waiting" group or status until admin validation |
---|
[17918] | 383 | SetUnvalidated($user['id']); // Set UAM_validated field to false in #_users table |
---|
[7968] | 384 | $confirm_mail_need = false; |
---|
[14366] | 385 | } |
---|
[7968] | 386 | } |
---|
| 387 | |
---|
[14366] | 388 | if (((!empty($_POST['use_new_pwd']) and (isset($conf_UAM[0]) and $conf_UAM[0] == 'true')) or $confirm_mail_need)) |
---|
[7968] | 389 | { |
---|
| 390 | $query = ' |
---|
| 391 | SELECT '.$conf['user_fields']['username'].' |
---|
| 392 | FROM '.USERS_TABLE.' |
---|
| 393 | WHERE '.$conf['user_fields']['id'].' = \''.$user['id'].'\' |
---|
| 394 | ;'; |
---|
| 395 | |
---|
| 396 | list($username) = pwg_db_fetch_row(pwg_query($query)); |
---|
| 397 | SendMail2User($typemail, $user['id'], $username, $_POST['use_new_pwd'], $_POST['mail_address'], $confirm_mail_need); |
---|
| 398 | } |
---|
| 399 | } |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | |
---|
[10144] | 403 | |
---|
[7968] | 404 | /** |
---|
| 405 | * Triggered on login_success |
---|
| 406 | * |
---|
[8065] | 407 | * Triggers scheduled tasks at login |
---|
| 408 | * Redirects a visitor (except for admins, webmasters and generic statuses) to his profile.php page (Thx to LucMorizur) |
---|
[7968] | 409 | * |
---|
| 410 | */ |
---|
[8065] | 411 | function UAM_LoginTasks() |
---|
[7968] | 412 | { |
---|
| 413 | global $conf, $user; |
---|
| 414 | |
---|
[12661] | 415 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 416 | |
---|
[7968] | 417 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 418 | |
---|
[9253] | 419 | // Performing GhostTracker scheduled tasks |
---|
[12271] | 420 | // --------------------------------------- |
---|
[11018] | 421 | if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true')) |
---|
[8065] | 422 | { |
---|
[9253] | 423 | UAM_GT_ScheduledTasks(); |
---|
[8065] | 424 | } |
---|
| 425 | |
---|
[9266] | 426 | // Performing User validation scheduled tasks |
---|
[12271] | 427 | // ------------------------------------------ |
---|
[11018] | 428 | if ((isset($conf_UAM[30]) and $conf_UAM[30] == 'true')) |
---|
[9266] | 429 | { |
---|
| 430 | UAM_USR_ScheduledTasks(); |
---|
| 431 | } |
---|
| 432 | |
---|
[12661] | 433 | // Avoid login into public galleries until registration confirmation is done |
---|
| 434 | if ((isset($conf_UAM[39]) and $conf_UAM[39] == 'false') or ((isset($conf_UAM[39]) and $conf_UAM[39] == 'true') and UAM_UsrReg_Verif($user['id']))) |
---|
[12314] | 435 | { |
---|
[12661] | 436 | // Performing redirection to profile page on first login |
---|
| 437 | // ----------------------------------------------------- |
---|
| 438 | if ((isset($conf_UAM[20]) and $conf_UAM[20] == 'true')) |
---|
| 439 | { |
---|
| 440 | $query =' |
---|
[7968] | 441 | SELECT user_id, status |
---|
| 442 | FROM '.USER_INFOS_TABLE.' |
---|
| 443 | WHERE user_id = '.$user['id'].' |
---|
| 444 | ;'; |
---|
[12661] | 445 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[8065] | 446 | |
---|
[12661] | 447 | if ($data['status'] <> "admin" and $data['status'] <> "webmaster" and $data['status'] <> "generic") // Exclusion of specific accounts |
---|
| 448 | { |
---|
| 449 | $user_idsOK = array(); |
---|
| 450 | if (!UAM_check_profile($user['id'], $user_idsOK)) |
---|
| 451 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
---|
| 452 | } |
---|
[8087] | 453 | } |
---|
[12239] | 454 | |
---|
[12661] | 455 | // Performing redirection to profile page for password reset |
---|
| 456 | // --------------------------------------------------------- |
---|
| 457 | if ((isset($conf_UAM[38]) and $conf_UAM[38] == 'true')) |
---|
| 458 | { |
---|
| 459 | $query =' |
---|
[12239] | 460 | SELECT user_id, status |
---|
| 461 | FROM '.USER_INFOS_TABLE.' |
---|
| 462 | WHERE user_id = '.$user['id'].' |
---|
| 463 | ;'; |
---|
[12661] | 464 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[12239] | 465 | |
---|
[12661] | 466 | if ($data['status'] <> "webmaster" and $data['status'] <> "generic") // Exclusion of specific accounts |
---|
[12239] | 467 | { |
---|
[12661] | 468 | if (UAM_check_pwgreset($user['id'])) |
---|
| 469 | { |
---|
| 470 | redirect(PHPWG_ROOT_PATH.'profile.php'); |
---|
| 471 | } |
---|
[12239] | 472 | } |
---|
| 473 | } |
---|
| 474 | } |
---|
[17892] | 475 | elseif ((isset($conf_UAM[39]) and $conf_UAM[39] == 'true') and !UAM_UsrReg_Verif($user['id']) and !is_admin() and !is_webmaster()) |
---|
[12661] | 476 | { |
---|
| 477 | // Logged-in user cleanup, session destruction and redirected to custom page |
---|
| 478 | // ------------------------------------------------------------------------- |
---|
[17892] | 479 | invalidate_user_cache(); |
---|
| 480 | logout_user(); |
---|
[17969] | 481 | if ( $conf['guest_access'] ) |
---|
| 482 | { |
---|
| 483 | redirect( make_index_url().'?UAM_msg=rejected', 0); |
---|
| 484 | } |
---|
| 485 | else |
---|
| 486 | { |
---|
| 487 | redirect( get_root_url().'identification.php?UAM_msg=rejected' , 0); |
---|
| 488 | } |
---|
[12661] | 489 | } |
---|
[7968] | 490 | } |
---|
| 491 | |
---|
[9908] | 492 | |
---|
[7968] | 493 | /** |
---|
[9908] | 494 | * Adds a new module settable in PWG_Stuffs - Triggered on get_stuffs_modules in main.inc.php |
---|
| 495 | * Useful to inform unvalidated user for their status |
---|
| 496 | * |
---|
| 497 | */ |
---|
| 498 | function register_UAM_stuffs_module($modules) |
---|
| 499 | { |
---|
| 500 | array_push($modules, array( |
---|
| 501 | 'path' => UAM_PATH.'/stuffs_module', |
---|
| 502 | 'name' => l10n('UAM_Stuffs_Title'), |
---|
| 503 | 'description' => l10n('UAM_Stuffs_Desc'), |
---|
| 504 | ) |
---|
| 505 | ); |
---|
| 506 | return $modules; |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | |
---|
| 510 | /** |
---|
[8065] | 511 | * Triggered on UAM_LoginTasks() |
---|
[7968] | 512 | * |
---|
[9253] | 513 | * Executes optional post-login tasks for Ghost users |
---|
[7968] | 514 | * |
---|
| 515 | */ |
---|
[9253] | 516 | function UAM_GT_ScheduledTasks() |
---|
[7968] | 517 | { |
---|
[8065] | 518 | global $conf, $user, $page; |
---|
[9253] | 519 | |
---|
| 520 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 521 | { |
---|
| 522 | die('Hacking attempt!'); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 526 | |
---|
[7968] | 527 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[8065] | 528 | |
---|
| 529 | $collection = array(); |
---|
[8087] | 530 | $reminder = false; |
---|
[8065] | 531 | |
---|
| 532 | $page['filtered_users'] = get_ghosts_autotasks(); |
---|
[7968] | 533 | |
---|
[8087] | 534 | foreach($page['filtered_users'] as $listed_user) |
---|
| 535 | { |
---|
| 536 | array_push($collection, $listed_user['id']); |
---|
| 537 | } |
---|
[8065] | 538 | |
---|
[17846] | 539 | // Auto group, status or privacy level downgrade and autodeletion if user already reminded |
---|
| 540 | // --------------------------------------------------------------------------------------- |
---|
[12189] | 541 | if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true') and ((isset($conf_UAM[25]) and $conf_UAM[25] <> -1) or (isset($conf_UAM[26]) and $conf_UAM[26] <> -1) or (isset($conf_UAM[37]) and $conf_UAM[37] <> -1))) |
---|
[8087] | 542 | { |
---|
[8065] | 543 | if (count($collection) > 0) |
---|
[17944] | 544 | { |
---|
[8087] | 545 | // Process if a non-admin nor webmaster user is logged |
---|
[12271] | 546 | // --------------------------------------------------- |
---|
[8087] | 547 | if (in_array($user['id'], $collection)) |
---|
[17944] | 548 | { |
---|
[9253] | 549 | // Check lastvisit reminder state |
---|
[12271] | 550 | // ------------------------------ |
---|
[9253] | 551 | $query = ' |
---|
[8087] | 552 | SELECT reminder |
---|
| 553 | FROM '.USER_LASTVISIT_TABLE.' |
---|
[9253] | 554 | WHERE user_id = '.$user['id'].';'; |
---|
[8087] | 555 | |
---|
[9253] | 556 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[8087] | 557 | |
---|
[9253] | 558 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
| 559 | { |
---|
| 560 | $reminder = true; |
---|
[8065] | 561 | } |
---|
[9253] | 562 | else |
---|
[8092] | 563 | { |
---|
[9253] | 564 | $reminder = false; |
---|
[8092] | 565 | } |
---|
[9253] | 566 | |
---|
[9266] | 567 | // If user already reminded for ghost account |
---|
[12271] | 568 | // ------------------------------------------ |
---|
[9266] | 569 | if ($reminder) |
---|
[8092] | 570 | { |
---|
[12271] | 571 | // Delete account |
---|
| 572 | // -------------- |
---|
[9253] | 573 | delete_user($user['id']); |
---|
| 574 | |
---|
| 575 | // Logged-in user cleanup, session destruction and redirected to custom page |
---|
[12271] | 576 | // ------------------------------------------------------------------------- |
---|
[8092] | 577 | invalidate_user_cache(); |
---|
[9253] | 578 | logout_user(); |
---|
[9266] | 579 | redirect(UAM_PATH.'GT_del_account.php'); |
---|
[8092] | 580 | } |
---|
[17944] | 581 | } |
---|
[8087] | 582 | else // Process if an admin or webmaster user is logged |
---|
[8065] | 583 | { |
---|
| 584 | foreach ($collection as $user_id) |
---|
| 585 | { |
---|
[8087] | 586 | // Check lastvisit reminder state |
---|
[12271] | 587 | // ------------------------------ |
---|
[8087] | 588 | $query = ' |
---|
| 589 | SELECT reminder |
---|
| 590 | FROM '.USER_LASTVISIT_TABLE.' |
---|
| 591 | WHERE user_id = '.$user_id.';'; |
---|
| 592 | |
---|
| 593 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 594 | |
---|
| 595 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
| 596 | { |
---|
| 597 | $reminder = true; |
---|
| 598 | } |
---|
| 599 | else |
---|
| 600 | { |
---|
| 601 | $reminder = false; |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | // If never reminded before |
---|
[12271] | 605 | // ------------------------ |
---|
[8087] | 606 | if (!$reminder) |
---|
| 607 | { |
---|
[12271] | 608 | // Reset of lastvisit date |
---|
| 609 | // ----------------------- |
---|
[8087] | 610 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 611 | |
---|
[17918] | 612 | $query = ' |
---|
| 613 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
| 614 | SET lastvisit="'.$dbnow.'" |
---|
| 615 | WHERE user_id = '.$user_id.' |
---|
| 616 | ;'; |
---|
[8087] | 617 | pwg_query($query); |
---|
| 618 | |
---|
[8065] | 619 | // Auto change group and / or status |
---|
[12271] | 620 | // --------------------------------- |
---|
[8087] | 621 | // Delete user from all groups |
---|
[12271] | 622 | // --------------------------- |
---|
[17944] | 623 | if ($conf_UAM[2] <> -1 and $conf_UAM[3] <> -1) |
---|
| 624 | { |
---|
| 625 | $query = ' |
---|
[17918] | 626 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 627 | WHERE user_id = '.$user_id.' |
---|
[8065] | 628 | AND ( |
---|
[17946] | 629 | group_id = '.$conf_UAM[2].' |
---|
[8065] | 630 | OR |
---|
[17946] | 631 | group_id = '.$conf_UAM[3].' |
---|
[8065] | 632 | ) |
---|
[17918] | 633 | ;'; |
---|
[17944] | 634 | pwg_query($query); |
---|
| 635 | } |
---|
[8065] | 636 | |
---|
[8087] | 637 | // Change user status |
---|
[12271] | 638 | // ------------------ |
---|
[11018] | 639 | if ($conf_UAM[26] <> -1) |
---|
[8087] | 640 | { |
---|
[17918] | 641 | $query = ' |
---|
| 642 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 643 | SET status = "'.$conf_UAM[26].'" |
---|
| 644 | WHERE user_id = '.$user_id.' |
---|
| 645 | ;'; |
---|
[8087] | 646 | pwg_query($query); |
---|
| 647 | } |
---|
[8065] | 648 | |
---|
[8087] | 649 | // Change user group |
---|
[12271] | 650 | // ----------------- |
---|
[11018] | 651 | if ($conf_UAM[25] <> -1) |
---|
[8087] | 652 | { |
---|
[17918] | 653 | $query = ' |
---|
| 654 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
[8065] | 655 | (user_id, group_id) |
---|
| 656 | VALUES |
---|
[17918] | 657 | ('.$user_id.', "'.$conf_UAM[25].'") |
---|
| 658 | ;'; |
---|
[8087] | 659 | pwg_query($query); |
---|
| 660 | } |
---|
[8065] | 661 | |
---|
[12189] | 662 | // Change user privacy level |
---|
[12271] | 663 | // ------------------------- |
---|
[12189] | 664 | if ($conf_UAM[37] <> -1) |
---|
| 665 | { |
---|
[17918] | 666 | $query = ' |
---|
| 667 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 668 | SET level = "'.$conf_UAM[37].'" |
---|
| 669 | WHERE user_id = '.$user_id.' |
---|
| 670 | ;'; |
---|
[12189] | 671 | pwg_query($query); |
---|
| 672 | } |
---|
| 673 | |
---|
[8087] | 674 | // Auto send email notification on group / status downgrade |
---|
[12271] | 675 | // -------------------------------------------------------- |
---|
[11018] | 676 | if (isset($conf_UAM[22]) and $conf_UAM[22] == 'true') |
---|
[8087] | 677 | { |
---|
| 678 | // Set reminder true |
---|
[12271] | 679 | // ----------------- |
---|
[17918] | 680 | $query = ' |
---|
| 681 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
| 682 | SET reminder = "true" |
---|
| 683 | WHERE user_id = '.$user_id.' |
---|
| 684 | ;'; |
---|
[8087] | 685 | pwg_query($query); |
---|
| 686 | |
---|
| 687 | // Reset confirmed user status to unvalidated |
---|
[12271] | 688 | // ------------------------------------------ |
---|
[17944] | 689 | $query = ' |
---|
[8065] | 690 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 691 | SET date_check = NULL |
---|
[17918] | 692 | WHERE user_id = '.$user_id.' |
---|
[8065] | 693 | ;'; |
---|
[17944] | 694 | pwg_query($query); |
---|
[8065] | 695 | |
---|
[8087] | 696 | // Get users information for email notification |
---|
[12271] | 697 | // -------------------------------------------- |
---|
[17944] | 698 | $query = ' |
---|
[8065] | 699 | SELECT id, username, mail_address |
---|
| 700 | FROM '.USERS_TABLE.' |
---|
| 701 | WHERE id = '.$user_id.' |
---|
| 702 | ;'; |
---|
[17944] | 703 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[8065] | 704 | |
---|
[8087] | 705 | demotion_mail($user_id, $data['username'], $data['mail_address']); |
---|
| 706 | } |
---|
[8065] | 707 | } |
---|
[8087] | 708 | elseif ($reminder) // If user already reminded for ghost account |
---|
| 709 | { |
---|
[12271] | 710 | // Delete account |
---|
| 711 | // -------------- |
---|
[8087] | 712 | delete_user($user_id); |
---|
| 713 | } |
---|
[8065] | 714 | } |
---|
| 715 | } |
---|
| 716 | } |
---|
[7968] | 717 | } |
---|
| 718 | } |
---|
| 719 | |
---|
[10144] | 720 | |
---|
[7968] | 721 | /** |
---|
[9266] | 722 | * Triggered on UAM_LoginTasks() |
---|
| 723 | * |
---|
| 724 | * Executes optional post-login tasks for unvalidated users |
---|
| 725 | * |
---|
| 726 | */ |
---|
| 727 | function UAM_USR_ScheduledTasks() |
---|
| 728 | { |
---|
| 729 | global $conf, $user, $page; |
---|
| 730 | |
---|
| 731 | if (!defined('PHPWG_ROOT_PATH')) |
---|
| 732 | { |
---|
| 733 | die('Hacking attempt!'); |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 737 | |
---|
| 738 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 739 | |
---|
| 740 | $collection = array(); |
---|
| 741 | $reminder = false; |
---|
| 742 | |
---|
| 743 | $page['filtered_users'] = get_unvalid_user_autotasks(); |
---|
| 744 | |
---|
| 745 | foreach($page['filtered_users'] as $listed_user) |
---|
| 746 | { |
---|
| 747 | array_push($collection, $listed_user['id']); |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | // Unvalidated accounts auto email sending and autodeletion if user already reminded |
---|
[12271] | 751 | // --------------------------------------------------------------------------------- |
---|
[11018] | 752 | if ((isset($conf_UAM[30]) and $conf_UAM[30] == 'true')) |
---|
[9266] | 753 | { |
---|
| 754 | if (count($collection) > 0) |
---|
[17944] | 755 | { |
---|
[9266] | 756 | // Process if a non-admin nor webmaster user is logged |
---|
[12271] | 757 | // --------------------------------------------------- |
---|
[9266] | 758 | if (in_array($user['id'], $collection)) |
---|
[17944] | 759 | { |
---|
[9266] | 760 | // Check ConfirmMail reminder state |
---|
[12271] | 761 | // -------------------------------- |
---|
[9266] | 762 | $query = ' |
---|
| 763 | SELECT reminder |
---|
| 764 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 765 | WHERE user_id = '.$user['id'].';'; |
---|
| 766 | |
---|
| 767 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 768 | |
---|
| 769 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
| 770 | { |
---|
| 771 | $reminder = true; |
---|
| 772 | } |
---|
| 773 | else |
---|
| 774 | { |
---|
| 775 | $reminder = false; |
---|
| 776 | } |
---|
| 777 | |
---|
| 778 | // If never reminded before, send reminder and set reminder True |
---|
[12271] | 779 | // ------------------------------------------------------------- |
---|
[11018] | 780 | if (!$reminder and isset($conf_UAM[32]) and $conf_UAM[32] == 'true') |
---|
[9266] | 781 | { |
---|
[17944] | 782 | $typemail = 1; |
---|
[9266] | 783 | |
---|
| 784 | // Get current user informations |
---|
[12271] | 785 | // ----------------------------- |
---|
[17918] | 786 | $query = ' |
---|
[9266] | 787 | SELECT id, username, mail_address |
---|
[17918] | 788 | FROM '.USERS_TABLE.' |
---|
| 789 | WHERE id = '.$user['id'].' |
---|
| 790 | ;'; |
---|
[9266] | 791 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 792 | |
---|
| 793 | ResendMail2User($typemail,$user['id'],stripslashes($data['username']),$data['mail_address'],true); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | // If already reminded before, delete user |
---|
[12271] | 797 | // --------------------------------------- |
---|
[9266] | 798 | if ($reminder) |
---|
| 799 | { |
---|
| 800 | // delete account |
---|
| 801 | delete_user($user['id']); |
---|
| 802 | |
---|
| 803 | // Logged-in user cleanup, session destruction and redirected to custom page |
---|
[12271] | 804 | // ------------------------------------------------------------------------- |
---|
[9266] | 805 | invalidate_user_cache(); |
---|
| 806 | logout_user(); |
---|
| 807 | redirect(UAM_PATH.'USR_del_account.php'); |
---|
| 808 | } |
---|
[17944] | 809 | } |
---|
[9266] | 810 | else // Process if an admin or webmaster user is logged |
---|
| 811 | { |
---|
| 812 | foreach ($collection as $user_id) |
---|
| 813 | { |
---|
| 814 | // Check reminder state |
---|
[12271] | 815 | // -------------------- |
---|
[9266] | 816 | $query = ' |
---|
| 817 | SELECT reminder |
---|
| 818 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 819 | WHERE user_id = '.$user_id.';'; |
---|
| 820 | |
---|
| 821 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 822 | |
---|
| 823 | if (isset($result['reminder']) and $result['reminder'] == 'true') |
---|
| 824 | { |
---|
| 825 | $reminder = true; |
---|
| 826 | } |
---|
| 827 | else |
---|
| 828 | { |
---|
| 829 | $reminder = false; |
---|
| 830 | } |
---|
| 831 | |
---|
| 832 | // If never reminded before, send reminder and set reminder True |
---|
[12271] | 833 | // ------------------------------------------------------------- |
---|
[11018] | 834 | if (!$reminder and isset($conf_UAM[32]) and $conf_UAM[32] == 'true') |
---|
[9266] | 835 | { |
---|
| 836 | $typemail = 1; |
---|
| 837 | |
---|
| 838 | // Get current user informations |
---|
[12271] | 839 | // ----------------------------- |
---|
[17918] | 840 | $query = ' |
---|
[9266] | 841 | SELECT id, username, mail_address |
---|
[17918] | 842 | FROM '.USERS_TABLE.' |
---|
| 843 | WHERE id = '.$user_id.' |
---|
| 844 | ;'; |
---|
[9266] | 845 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 846 | |
---|
| 847 | ResendMail2User($typemail,$user_id,stripslashes($data['username']),$data['mail_address'],true); |
---|
| 848 | } |
---|
| 849 | elseif ($reminder) // If user already reminded for account validation |
---|
| 850 | { |
---|
[12271] | 851 | // Delete account |
---|
| 852 | // -------------- |
---|
[9266] | 853 | delete_user($user_id); |
---|
| 854 | } |
---|
| 855 | } |
---|
| 856 | } |
---|
| 857 | } |
---|
| 858 | } |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | |
---|
| 862 | /** |
---|
[7968] | 863 | * Triggered on init |
---|
| 864 | * |
---|
| 865 | * Check for forbidden email domains in admin's users management panel |
---|
| 866 | */ |
---|
| 867 | function UAM_InitPage() |
---|
| 868 | { |
---|
| 869 | load_language('plugin.lang', UAM_PATH); |
---|
| 870 | global $conf, $template, $page, $lang, $errors; |
---|
| 871 | |
---|
| 872 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 873 | |
---|
| 874 | // Admin user management |
---|
[12271] | 875 | // --------------------- |
---|
[7968] | 876 | if (script_basename() == 'admin' and isset($_GET['page']) and $_GET['page'] == 'user_list') |
---|
| 877 | { |
---|
| 878 | if (isset($_POST['submit_add'])) |
---|
| 879 | { |
---|
| 880 | // Email without forbidden domains |
---|
[12271] | 881 | // ------------------------------- |
---|
[11018] | 882 | if (isset($conf_UAM[10]) and $conf_UAM[10] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email'])) |
---|
[7968] | 883 | { |
---|
[11018] | 884 | $template->append('errors', l10n('UAM_reg_err_login5')."'".$conf_UAM[11]."'"); |
---|
[7968] | 885 | unset($_POST['submit_add']); |
---|
| 886 | } |
---|
| 887 | } |
---|
| 888 | } |
---|
[18205] | 889 | if( isset($_GET['UAM_msg'])) |
---|
| 890 | { |
---|
| 891 | UAM_DisplayMsg(); |
---|
| 892 | } |
---|
| 893 | elseif (isset($_GET['key']) and isset($_GET['userid'])) |
---|
| 894 | { |
---|
| 895 | UAM_ConfirmMail(); |
---|
| 896 | } |
---|
| 897 | |
---|
[7968] | 898 | } |
---|
| 899 | |
---|
[17969] | 900 | /** |
---|
| 901 | * Triggered on init |
---|
| 902 | * |
---|
| 903 | * Display a message according to $_GET['UAM_msg'] |
---|
| 904 | */ |
---|
| 905 | function UAM_DisplayMsg() |
---|
| 906 | { |
---|
| 907 | if( isset($_GET['UAM_msg'])) |
---|
| 908 | { |
---|
| 909 | global $user, $lang, $conf, $page; |
---|
| 910 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 911 | |
---|
| 912 | if (isset($conf_UAM[40]) and $conf_UAM[40] <> '' and $_GET['UAM_msg']="rejected") |
---|
| 913 | { |
---|
| 914 | // Management of Extension flags ([mygallery], [myurl]) |
---|
| 915 | // --------------------------------------------------- |
---|
| 916 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 917 | $replacements[] = $conf['gallery_title']; |
---|
| 918 | $patterns[] = '#\[myurl\]#i'; |
---|
| 919 | $replacements[] = get_gallery_home_url(); |
---|
| 920 | |
---|
| 921 | if (function_exists('get_user_language_desc')) |
---|
| 922 | { |
---|
| 923 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[40])); |
---|
| 924 | } |
---|
| 925 | else $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM[40])); |
---|
| 926 | $page["errors"][]=$custom_text; |
---|
| 927 | } |
---|
| 928 | } |
---|
| 929 | } |
---|
[18205] | 930 | /** |
---|
| 931 | * Triggered on init |
---|
| 932 | * |
---|
| 933 | * Check the key and display a message |
---|
| 934 | */ |
---|
| 935 | function UAM_ConfirmMail() |
---|
| 936 | { |
---|
[9135] | 937 | |
---|
[18205] | 938 | if (isset($_GET['key']) and isset($_GET['userid'])) |
---|
| 939 | { |
---|
| 940 | |
---|
| 941 | global $user, $lang, $conf, $page; |
---|
| 942 | |
---|
| 943 | $key = $_GET['key']; |
---|
| 944 | $userid = $_GET['userid']; |
---|
| 945 | |
---|
| 946 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
| 947 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 948 | |
---|
| 949 | $query = ' |
---|
| 950 | SELECT '.USERS_TABLE.'.username |
---|
| 951 | FROM '.USERS_TABLE.' |
---|
| 952 | WHERE ('.USERS_TABLE.'.id ='.$userid.') |
---|
| 953 | ;'; |
---|
| 954 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 955 | |
---|
| 956 | if (VerifyConfirmMail($key)) |
---|
| 957 | { |
---|
| 958 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'local') |
---|
| 959 | { |
---|
| 960 | validation_mail($userid); |
---|
| 961 | } |
---|
| 962 | // We have to get the user's language in database |
---|
| 963 | // ---------------------------------------------- |
---|
| 964 | $query = ' |
---|
| 965 | SELECT language |
---|
| 966 | FROM '.USER_INFOS_TABLE.' |
---|
| 967 | WHERE '.USER_INFOS_TABLE.'.user_id ='.$userid.' |
---|
| 968 | ;'; |
---|
| 969 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 970 | |
---|
| 971 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
| 972 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
| 973 | if (empty($data)) |
---|
| 974 | { |
---|
| 975 | // And switch gallery to this language before using personalized and multilangual contents |
---|
| 976 | // --------------------------------------------------------------------------------------- |
---|
| 977 | $language = pwg_get_session_var('lang_switch', $user['language']); |
---|
| 978 | switch_lang_to($language); |
---|
| 979 | } |
---|
| 980 | else |
---|
| 981 | { |
---|
| 982 | // And switch gallery to this language before using personalized and multilangual contents |
---|
| 983 | // --------------------------------------------------------------------------------------- |
---|
| 984 | switch_lang_to($data['language']); |
---|
| 985 | load_language('plugin.lang', UAM_PATH); |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | if (isset($conf_UAM_ConfirmMail[5]) and $conf_UAM_ConfirmMail[5] <> '') |
---|
| 989 | { |
---|
| 990 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
| 991 | // ---------------------------------------------------------------- |
---|
| 992 | $patterns[] = '#\[username\]#i'; |
---|
| 993 | $replacements[] = $result['username']; |
---|
| 994 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 995 | $replacements[] = $conf['gallery_title']; |
---|
| 996 | $patterns[] = '#\[myurl\]#i'; |
---|
| 997 | $replacements[] = get_gallery_home_url(); |
---|
| 998 | |
---|
| 999 | if (function_exists('get_user_language_desc')) |
---|
| 1000 | { |
---|
| 1001 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[5])); |
---|
| 1002 | } |
---|
| 1003 | else |
---|
| 1004 | { |
---|
| 1005 | $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[5])); |
---|
| 1006 | } |
---|
| 1007 | $page['infos'][]=$custom_text; |
---|
| 1008 | //print_r($custom_text); |
---|
| 1009 | } |
---|
| 1010 | //log_user($userid, true); |
---|
| 1011 | } |
---|
| 1012 | else |
---|
| 1013 | { |
---|
| 1014 | if (isset($conf_UAM_ConfirmMail[6]) and $conf_UAM_ConfirmMail[6] <> '') |
---|
| 1015 | { |
---|
| 1016 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
| 1017 | // ---------------------------------------------------------------- |
---|
| 1018 | $patterns[] = '#\[username\]#i'; |
---|
| 1019 | $replacements[] = $result['username']; |
---|
| 1020 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1021 | $replacements[] = $conf['gallery_title']; |
---|
| 1022 | $patterns[] = '#\[myurl\]#i'; |
---|
| 1023 | $replacements[] = get_gallery_home_url(); |
---|
| 1024 | |
---|
| 1025 | if (function_exists('get_user_language_desc')) |
---|
| 1026 | { |
---|
| 1027 | $custom_text = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[6])); |
---|
| 1028 | } |
---|
| 1029 | else |
---|
| 1030 | { |
---|
| 1031 | $custom_text = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[6])); |
---|
| 1032 | } |
---|
| 1033 | |
---|
| 1034 | $page['errors'][]=$custom_text; |
---|
| 1035 | } |
---|
| 1036 | } |
---|
| 1037 | } |
---|
| 1038 | } |
---|
[7968] | 1039 | /** |
---|
[9135] | 1040 | * Triggered on render_lost_password_mail_content |
---|
| 1041 | * |
---|
| 1042 | * Adds a customized text in lost password email content |
---|
| 1043 | * Added text is inserted before users login name and new password |
---|
| 1044 | * |
---|
| 1045 | * @param : Standard Piwigo email content |
---|
| 1046 | * |
---|
| 1047 | * @return : Customized content added to standard content |
---|
| 1048 | * |
---|
| 1049 | */ |
---|
| 1050 | function UAM_lost_password_mail_content($infos) |
---|
| 1051 | { |
---|
| 1052 | global $conf; |
---|
| 1053 | |
---|
| 1054 | load_language('plugin.lang', UAM_PATH); |
---|
| 1055 | |
---|
| 1056 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 1057 | |
---|
[11018] | 1058 | if (isset($conf_UAM[28]) and $conf_UAM[28] == 'true') |
---|
[9135] | 1059 | { |
---|
[9381] | 1060 | // Management of Extension flags ([mygallery], [myurl]) |
---|
[9160] | 1061 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1062 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1063 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1064 | $replacements[] = get_gallery_home_url(); |
---|
[9160] | 1065 | |
---|
[11018] | 1066 | $infos = preg_replace($patterns, $replacements, $conf_UAM[29])."\n"."\n".$infos; |
---|
[9135] | 1067 | } |
---|
| 1068 | return $infos; |
---|
| 1069 | } |
---|
| 1070 | |
---|
| 1071 | |
---|
| 1072 | /** |
---|
[7968] | 1073 | * Function called from main.inc.php to send validation email |
---|
| 1074 | * |
---|
| 1075 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
| 1076 | * |
---|
| 1077 | */ |
---|
[5056] | 1078 | function SendMail2User($typemail, $id, $username, $password, $email, $confirm) |
---|
| 1079 | { |
---|
[5064] | 1080 | global $conf; |
---|
[5056] | 1081 | |
---|
[5181] | 1082 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[17944] | 1083 | |
---|
| 1084 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
| 1085 | |
---|
| 1086 | $infos1_perso = ""; |
---|
[5056] | 1087 | $infos2_perso = ""; |
---|
[14729] | 1088 | $subject = ""; |
---|
[5056] | 1089 | |
---|
[7968] | 1090 | // We have to get the user's language in database |
---|
[12271] | 1091 | // ---------------------------------------------- |
---|
[5056] | 1092 | $query =' |
---|
| 1093 | SELECT user_id, language |
---|
| 1094 | FROM '.USER_INFOS_TABLE.' |
---|
| 1095 | WHERE user_id = '.$id.' |
---|
| 1096 | ;'; |
---|
[5633] | 1097 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 1098 | |
---|
[7968] | 1099 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
[12271] | 1100 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
[5056] | 1101 | if (empty($data)) |
---|
| 1102 | { |
---|
[7968] | 1103 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1104 | // --------------------------------------------------------------------------------------- |
---|
[5056] | 1105 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
| 1106 | switch_lang_to($language); |
---|
| 1107 | } |
---|
| 1108 | else |
---|
| 1109 | { |
---|
[7968] | 1110 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1111 | // --------------------------------------------------------------------------------------- |
---|
| 1112 | //$language = $data['language']; // Usefull for debugging |
---|
[5056] | 1113 | switch_lang_to($data['language']); |
---|
[5181] | 1114 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 1115 | } |
---|
| 1116 | |
---|
| 1117 | switch($typemail) |
---|
| 1118 | { |
---|
[14366] | 1119 | case 1: // Confirmation email on user registration - Without information email (already managed by Piwigo) |
---|
[14729] | 1120 | if (isset($conf_UAM[41]) and $conf_UAM[41] <> '') |
---|
| 1121 | { |
---|
| 1122 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1123 | // ------------------------------------------------------- |
---|
| 1124 | $patterns[] = '#\[username\]#i'; |
---|
| 1125 | $replacements[] = $username; |
---|
| 1126 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1127 | $replacements[] = $conf['gallery_title']; |
---|
| 1128 | |
---|
| 1129 | if (function_exists('get_user_language_desc')) |
---|
| 1130 | { |
---|
| 1131 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[41]))."\n\n"; |
---|
| 1132 | } |
---|
| 1133 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[41]))."\n\n"; |
---|
| 1134 | } |
---|
[14366] | 1135 | |
---|
| 1136 | break; |
---|
| 1137 | |
---|
[17946] | 1138 | case 2: // Confirmation email on user profile update - With information email if modification done in user profile |
---|
[14729] | 1139 | if (isset($conf_UAM[41]) and $conf_UAM[41] <> '') |
---|
| 1140 | { |
---|
| 1141 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1142 | // ------------------------------------------------------- |
---|
| 1143 | $patterns[] = '#\[username\]#i'; |
---|
| 1144 | $replacements[] = $username; |
---|
| 1145 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1146 | $replacements[] = $conf['gallery_title']; |
---|
| 1147 | |
---|
| 1148 | if (function_exists('get_user_language_desc')) |
---|
| 1149 | { |
---|
| 1150 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[41]))."\n\n"; |
---|
| 1151 | } |
---|
| 1152 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[41]))."\n\n"; |
---|
| 1153 | } |
---|
| 1154 | |
---|
[5056] | 1155 | $password = $password <> '' ? $password : l10n('UAM_empty_pwd'); |
---|
[14366] | 1156 | |
---|
[11018] | 1157 | if (isset($conf_UAM[8]) and $conf_UAM[8] <> '') |
---|
[5056] | 1158 | { |
---|
[9197] | 1159 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
[12271] | 1160 | // ---------------------------------------------------------------- |
---|
[9160] | 1161 | $patterns[] = '#\[username\]#i'; |
---|
| 1162 | $replacements[] = $username; |
---|
| 1163 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1164 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1165 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1166 | $replacements[] = get_gallery_home_url(); |
---|
[9160] | 1167 | |
---|
[5056] | 1168 | if (function_exists('get_user_language_desc')) |
---|
| 1169 | { |
---|
[11018] | 1170 | $infos1_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[8]))."\n\n"; |
---|
[5056] | 1171 | } |
---|
[11018] | 1172 | else $infos1_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM[8]))."\n\n"; |
---|
[5056] | 1173 | } |
---|
| 1174 | |
---|
[14366] | 1175 | if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') |
---|
| 1176 | { |
---|
| 1177 | if (isset($conf_UAM[34]) and $conf_UAM[34] == 'true') // Allow display of clear password in email |
---|
| 1178 | { |
---|
| 1179 | $infos1 = array( |
---|
| 1180 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
| 1181 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
| 1182 | get_l10n_args('UAM_Password: %s', $password), |
---|
| 1183 | get_l10n_args('Email: %s', $email), |
---|
| 1184 | get_l10n_args('', ''), |
---|
| 1185 | ); |
---|
| 1186 | } |
---|
| 1187 | else // Do not allow display of clear password in email |
---|
| 1188 | { |
---|
| 1189 | $infos1 = array( |
---|
| 1190 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
| 1191 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
| 1192 | get_l10n_args('Email: %s', $email), |
---|
| 1193 | get_l10n_args('', ''), |
---|
| 1194 | ); |
---|
| 1195 | } |
---|
| 1196 | } |
---|
| 1197 | |
---|
[5056] | 1198 | break; |
---|
| 1199 | |
---|
[14366] | 1200 | case 3: // Only information email send to user if checked |
---|
[14729] | 1201 | if (isset($conf_UAM[43]) and $conf_UAM[43] <> '') |
---|
| 1202 | { |
---|
| 1203 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1204 | // ------------------------------------------------------- |
---|
| 1205 | $patterns[] = '#\[username\]#i'; |
---|
| 1206 | $replacements[] = $username; |
---|
| 1207 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1208 | $replacements[] = $conf['gallery_title']; |
---|
| 1209 | |
---|
| 1210 | if (function_exists('get_user_language_desc')) |
---|
| 1211 | { |
---|
| 1212 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[43]))."\n\n"; |
---|
| 1213 | } |
---|
| 1214 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[43]))."\n\n"; |
---|
| 1215 | } |
---|
| 1216 | |
---|
[5056] | 1217 | $password = $password <> '' ? $password : l10n('UAM_no_update_pwd'); |
---|
| 1218 | |
---|
[14366] | 1219 | if (isset($conf_UAM[8]) and $conf_UAM[8] <> '') |
---|
| 1220 | { |
---|
| 1221 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
| 1222 | // ---------------------------------------------------------------- |
---|
| 1223 | $patterns[] = '#\[username\]#i'; |
---|
| 1224 | $replacements[] = $username; |
---|
| 1225 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1226 | $replacements[] = $conf['gallery_title']; |
---|
| 1227 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1228 | $replacements[] = get_gallery_home_url(); |
---|
[14366] | 1229 | |
---|
| 1230 | if (function_exists('get_user_language_desc')) |
---|
| 1231 | { |
---|
| 1232 | $infos1_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[8]))."\n\n"; |
---|
| 1233 | } |
---|
| 1234 | else $infos1_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM[8]))."\n\n"; |
---|
| 1235 | } |
---|
| 1236 | |
---|
| 1237 | if (isset($conf_UAM[0]) and $conf_UAM[0] == 'true') |
---|
| 1238 | { |
---|
| 1239 | if (isset($conf_UAM[34]) and $conf_UAM[34] == 'true') // Allow display of clear password in email |
---|
| 1240 | { |
---|
| 1241 | $infos1 = array( |
---|
| 1242 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
| 1243 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
| 1244 | get_l10n_args('UAM_Password: %s', $password), |
---|
| 1245 | get_l10n_args('Email: %s', $email), |
---|
| 1246 | get_l10n_args('', ''), |
---|
| 1247 | ); |
---|
| 1248 | } |
---|
| 1249 | else // Do not allow display of clear password in email |
---|
| 1250 | { |
---|
| 1251 | $infos1 = array( |
---|
| 1252 | get_l10n_args('UAM_infos_mail %s', stripslashes($username)), |
---|
| 1253 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
| 1254 | get_l10n_args('Email: %s', $email), |
---|
| 1255 | get_l10n_args('', ''), |
---|
| 1256 | ); |
---|
| 1257 | } |
---|
| 1258 | } |
---|
| 1259 | |
---|
[5056] | 1260 | break; |
---|
| 1261 | } |
---|
| 1262 | |
---|
[17946] | 1263 | if (isset($conf_UAM[1]) and ($conf_UAM[1] == 'true' or $conf_UAM[1] == 'local') and $confirm) // Add confirmation link ? |
---|
[5056] | 1264 | { |
---|
| 1265 | $infos2 = array |
---|
| 1266 | ( |
---|
[9177] | 1267 | get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)), |
---|
[5056] | 1268 | get_l10n_args('', ''), |
---|
| 1269 | ); |
---|
| 1270 | |
---|
[12271] | 1271 | if (isset($conf_UAM[9]) and $conf_UAM[9] <> '') // Add personal text in confirmation email ? |
---|
[5056] | 1272 | { |
---|
[11318] | 1273 | // Management of Extension flags ([username], [mygallery], [myurl], [Kdays]) |
---|
[12271] | 1274 | // ------------------------------------------------------------------------- |
---|
[9160] | 1275 | $patterns[] = '#\[username\]#i'; |
---|
| 1276 | $replacements[] = $username; |
---|
| 1277 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1278 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1279 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1280 | $replacements[] = get_gallery_home_url(); |
---|
[9160] | 1281 | |
---|
[11318] | 1282 | if (isset($conf_UAM_ConfirmMail[0]) and $conf_UAM_ConfirmMail[0] == 'true') // [Kdays] replacement only if related option is active |
---|
| 1283 | { |
---|
| 1284 | $patterns[] = '#\[Kdays\]#i'; |
---|
| 1285 | $replacements[] = $conf_UAM_ConfirmMail[1]; |
---|
| 1286 | } |
---|
| 1287 | |
---|
[5056] | 1288 | if (function_exists('get_user_language_desc')) |
---|
| 1289 | { |
---|
[11018] | 1290 | $infos2_perso = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[9]))."\n\n"; |
---|
[5056] | 1291 | } |
---|
[11018] | 1292 | else $infos2_perso = l10n(preg_replace($patterns, $replacements, $conf_UAM[9]))."\n\n"; |
---|
[5056] | 1293 | } |
---|
| 1294 | } |
---|
| 1295 | |
---|
[7968] | 1296 | // Sending the email with subject and contents |
---|
[12271] | 1297 | // ------------------------------------------- |
---|
[17946] | 1298 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'local') |
---|
| 1299 | { |
---|
[18125] | 1300 | switch_lang_to(get_default_language()); |
---|
| 1301 | |
---|
| 1302 | load_language('plugin.lang', UAM_PATH); |
---|
| 1303 | $subject = get_l10n_args('UAM_Subject admin validation for %s',$username); |
---|
| 1304 | |
---|
| 1305 | $content = array( |
---|
| 1306 | get_l10n_args('UAM_Manual_validation_needed_for %s', stripslashes($username)), |
---|
| 1307 | get_l10n_args('', ''), |
---|
| 1308 | get_l10n_args('UAM_Link: %s', AddConfirmMail($id, $email)), |
---|
| 1309 | ); |
---|
| 1310 | |
---|
| 1311 | UAM_mail_notification_admins($subject, $content); |
---|
[17946] | 1312 | } |
---|
| 1313 | else |
---|
| 1314 | { |
---|
| 1315 | pwg_mail($email, array( |
---|
| 1316 | 'subject' => $subject, |
---|
| 1317 | 'content' => (isset($infos1) ? $infos1_perso.l10n_args($infos1)."\n\n" : "").(isset($infos2) ? $infos2_perso.l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
| 1318 | )); |
---|
| 1319 | } |
---|
[7968] | 1320 | // Switching back to default language |
---|
[12271] | 1321 | // ---------------------------------- |
---|
[5056] | 1322 | switch_lang_back(); |
---|
| 1323 | } |
---|
| 1324 | |
---|
[10144] | 1325 | |
---|
[18125] | 1326 | /** |
---|
| 1327 | * Function called from SendMail2User in functions.inc.php to notify admins on user registration validation with validation key |
---|
| 1328 | * |
---|
| 1329 | * @param: |
---|
| 1330 | * - keyargs_subject: mail subject on l10n_args format |
---|
| 1331 | * - keyargs_content: mail content on l10n_args format |
---|
| 1332 | * |
---|
| 1333 | * @return boolean (Ok or not) |
---|
| 1334 | */ |
---|
| 1335 | function UAM_mail_notification_admins($keyargs_subject, $keyargs_content) |
---|
[18087] | 1336 | { |
---|
[18125] | 1337 | global $conf, $user; |
---|
| 1338 | |
---|
| 1339 | // Check arguments |
---|
| 1340 | if (empty($keyargs_subject) or empty($keyargs_content)) |
---|
| 1341 | { |
---|
| 1342 | return false; |
---|
| 1343 | } |
---|
[18087] | 1344 | |
---|
[18125] | 1345 | $return = true; |
---|
| 1346 | |
---|
| 1347 | $admins = array(); |
---|
| 1348 | |
---|
| 1349 | $query = ' |
---|
| 1350 | SELECT |
---|
| 1351 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 1352 | u.'.$conf['user_fields']['email'].' AS mail_address |
---|
| 1353 | FROM '.USERS_TABLE.' AS u |
---|
| 1354 | JOIN '.USER_INFOS_TABLE.' AS i ON i.user_id = u.'.$conf['user_fields']['id'].' |
---|
| 1355 | WHERE i.status in (\'webmaster\', \'admin\') |
---|
| 1356 | AND '.$conf['user_fields']['email'].' IS NOT NULL |
---|
| 1357 | AND i.user_id <> '.$user['id'].' |
---|
| 1358 | ORDER BY username |
---|
| 1359 | ;'; |
---|
| 1360 | |
---|
| 1361 | $datas = pwg_query($query); |
---|
| 1362 | if (!empty($datas)) |
---|
| 1363 | { |
---|
| 1364 | while ($admin = pwg_db_fetch_assoc($datas)) |
---|
| 1365 | { |
---|
| 1366 | if (!empty($admin['mail_address'])) |
---|
| 1367 | { |
---|
| 1368 | array_push($admins, format_email($admin['username'], $admin['mail_address'])); |
---|
| 1369 | } |
---|
| 1370 | } |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | if (count($admins) > 0) |
---|
| 1374 | { |
---|
| 1375 | $content = l10n_args($keyargs_content)."\n"; |
---|
| 1376 | |
---|
| 1377 | $return = pwg_mail( |
---|
| 1378 | implode(', ', $admins), |
---|
| 1379 | array( |
---|
| 1380 | 'subject' => '['.$conf['gallery_title'].'] '.l10n_args($keyargs_subject), |
---|
| 1381 | 'content' => $content, |
---|
| 1382 | 'content_format' => 'text/plain', |
---|
| 1383 | 'email_format' => 'text/plain', |
---|
| 1384 | ) |
---|
| 1385 | ); |
---|
| 1386 | } |
---|
| 1387 | |
---|
| 1388 | return $return; |
---|
[18087] | 1389 | } |
---|
| 1390 | |
---|
| 1391 | |
---|
[7968] | 1392 | /** |
---|
| 1393 | * Function called from UAM_admin.php to resend validation email with or without new validation key |
---|
| 1394 | * |
---|
| 1395 | * @param : Type of email, user id, username, email address, confirmation (optional) |
---|
| 1396 | * |
---|
| 1397 | */ |
---|
[5056] | 1398 | function ResendMail2User($typemail, $user_id, $username, $email, $confirm) |
---|
| 1399 | { |
---|
[5064] | 1400 | global $conf; |
---|
[14729] | 1401 | |
---|
| 1402 | $subject = ""; |
---|
[5056] | 1403 | |
---|
[5181] | 1404 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 1405 | |
---|
[5181] | 1406 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 1407 | |
---|
[17944] | 1408 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[5056] | 1409 | |
---|
[7968] | 1410 | // We have to get the user's language in database |
---|
[12271] | 1411 | // ---------------------------------------------- |
---|
[5056] | 1412 | $query =' |
---|
| 1413 | SELECT user_id, language |
---|
| 1414 | FROM '.USER_INFOS_TABLE.' |
---|
| 1415 | WHERE user_id = '.$user_id.' |
---|
| 1416 | ;'; |
---|
[5633] | 1417 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 1418 | $language = $data['language']; |
---|
| 1419 | |
---|
[7968] | 1420 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1421 | // --------------------------------------------------------------------------------------- |
---|
[5056] | 1422 | switch_lang_to($data['language']); |
---|
| 1423 | |
---|
[5181] | 1424 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 1425 | |
---|
| 1426 | switch($typemail) |
---|
| 1427 | { |
---|
[14366] | 1428 | case 1: //Generating email content for remind with a new key |
---|
[14729] | 1429 | if (isset($conf_UAM[42]) and $conf_UAM[42] <> '') |
---|
| 1430 | { |
---|
| 1431 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1432 | // ------------------------------------------------------- |
---|
| 1433 | $patterns[] = '#\[username\]#i'; |
---|
| 1434 | $replacements[] = $username; |
---|
| 1435 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1436 | $replacements[] = $conf['gallery_title']; |
---|
| 1437 | |
---|
| 1438 | if (function_exists('get_user_language_desc')) |
---|
| 1439 | { |
---|
| 1440 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[42]))."\n\n"; |
---|
| 1441 | } |
---|
| 1442 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[42]))."\n\n"; |
---|
| 1443 | } |
---|
[5056] | 1444 | |
---|
| 1445 | if (isset($conf_UAM_ConfirmMail[2]) and $conf_UAM_ConfirmMail[2] <> '' and isset($conf_UAM_ConfirmMail[3]) and $conf_UAM_ConfirmMail[3] == 'true' and $confirm) |
---|
| 1446 | { |
---|
[17944] | 1447 | // Management of Extension flags ([username], [mygallery], [myurl], [Kdays]) |
---|
[12271] | 1448 | // ------------------------------------------------------------------------- |
---|
[9160] | 1449 | $patterns[] = '#\[username\]#i'; |
---|
| 1450 | $replacements[] = $username; |
---|
| 1451 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1452 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1453 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1454 | $replacements[] = get_gallery_home_url(); |
---|
[9160] | 1455 | |
---|
[11318] | 1456 | if (isset($conf_UAM_ConfirmMail[0]) and $conf_UAM_ConfirmMail[0] == 'true') // [Kdays] replacement only if related option is active |
---|
| 1457 | { |
---|
| 1458 | $patterns[] = '#\[Kdays\]#i'; |
---|
| 1459 | $replacements[] = $conf_UAM_ConfirmMail[1]; |
---|
| 1460 | } |
---|
| 1461 | |
---|
[5056] | 1462 | if (function_exists('get_user_language_desc')) |
---|
| 1463 | { |
---|
[9160] | 1464 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[2]))."\n\n"; |
---|
[5056] | 1465 | } |
---|
[17887] | 1466 | else $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[2]))."\n\n"; |
---|
[5056] | 1467 | |
---|
| 1468 | $infos2 = array |
---|
| 1469 | ( |
---|
[9177] | 1470 | get_l10n_args('UAM_Link: %s', ResetConfirmMail($user_id)), |
---|
[5056] | 1471 | get_l10n_args('', ''), |
---|
| 1472 | ); |
---|
[17944] | 1473 | } |
---|
[5056] | 1474 | |
---|
[12271] | 1475 | // Set reminder true |
---|
| 1476 | // ----------------- |
---|
[17918] | 1477 | $query = ' |
---|
| 1478 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 1479 | SET reminder = "true" |
---|
| 1480 | WHERE user_id = '.$user_id.' |
---|
| 1481 | ;'; |
---|
[5056] | 1482 | pwg_query($query); |
---|
| 1483 | |
---|
[17944] | 1484 | break; |
---|
[5056] | 1485 | |
---|
[14366] | 1486 | case 2: //Generating email content for remind without a new key |
---|
[14729] | 1487 | if (isset($conf_UAM[42]) and $conf_UAM[42] <> '') |
---|
| 1488 | { |
---|
| 1489 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1490 | // ------------------------------------------------------- |
---|
| 1491 | $patterns[] = '#\[username\]#i'; |
---|
| 1492 | $replacements[] = $username; |
---|
| 1493 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1494 | $replacements[] = $conf['gallery_title']; |
---|
| 1495 | |
---|
| 1496 | if (function_exists('get_user_language_desc')) |
---|
| 1497 | { |
---|
| 1498 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[42]))."\n\n"; |
---|
| 1499 | } |
---|
| 1500 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[42]))."\n\n"; |
---|
| 1501 | } |
---|
[5056] | 1502 | |
---|
[9160] | 1503 | if (isset($conf_UAM_ConfirmMail[4]) and $conf_UAM_ConfirmMail[4] <> '' and isset($conf_UAM_ConfirmMail[3]) and $conf_UAM_ConfirmMail[3] == 'true' and !$confirm) |
---|
[5056] | 1504 | { |
---|
[11318] | 1505 | // Management of Extension flags ([username], [mygallery], [myurl], [Kdays]) |
---|
[12271] | 1506 | // ------------------------------------------------------------------------- |
---|
[9160] | 1507 | $patterns[] = '#\[username\]#i'; |
---|
| 1508 | $replacements[] = $username; |
---|
| 1509 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1510 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1511 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1512 | $replacements[] = get_gallery_home_url(); |
---|
[11318] | 1513 | |
---|
| 1514 | if (isset($conf_UAM_ConfirmMail[0]) and $conf_UAM_ConfirmMail[0] == 'true') // [Kdays] replacement only if related option is active |
---|
| 1515 | { |
---|
| 1516 | $patterns[] = '#\[Kdays\]#i'; |
---|
| 1517 | $replacements[] = $conf_UAM_ConfirmMail[1]; |
---|
| 1518 | } |
---|
[9160] | 1519 | |
---|
[5056] | 1520 | if (function_exists('get_user_language_desc')) |
---|
| 1521 | { |
---|
[9160] | 1522 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[4]))."\n\n"; |
---|
[5056] | 1523 | } |
---|
[9160] | 1524 | else $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM_ConfirmMail[4]))."\n\n"; |
---|
[5056] | 1525 | } |
---|
| 1526 | |
---|
[12271] | 1527 | // Set reminder true |
---|
| 1528 | // ----------------- |
---|
[17918] | 1529 | $query = ' |
---|
| 1530 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 1531 | SET reminder = "true" |
---|
| 1532 | WHERE user_id = '.$user_id.' |
---|
| 1533 | ;'; |
---|
[5056] | 1534 | pwg_query($query); |
---|
| 1535 | |
---|
| 1536 | break; |
---|
[17887] | 1537 | } |
---|
[5056] | 1538 | |
---|
| 1539 | pwg_mail($email, array( |
---|
| 1540 | 'subject' => $subject, |
---|
| 1541 | 'content' => ($infos1."\n\n").(isset($infos2) ? l10n_args($infos2)."\n\n" : "").get_absolute_root_url(), |
---|
| 1542 | )); |
---|
| 1543 | |
---|
[17944] | 1544 | // Switching back to default language |
---|
| 1545 | // ---------------------------------- |
---|
| 1546 | switch_lang_back(); |
---|
[5056] | 1547 | } |
---|
| 1548 | |
---|
[10144] | 1549 | |
---|
[7968] | 1550 | /** |
---|
| 1551 | * Function called from UAM_admin.php to send a reminder mail for ghost users |
---|
| 1552 | * |
---|
| 1553 | * @param : User id, username, email address |
---|
| 1554 | * |
---|
| 1555 | */ |
---|
[5056] | 1556 | function ghostreminder($user_id, $username, $email) |
---|
| 1557 | { |
---|
[5064] | 1558 | global $conf; |
---|
[5056] | 1559 | |
---|
[5181] | 1560 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[14729] | 1561 | $subject = ""; |
---|
[5056] | 1562 | |
---|
[17944] | 1563 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[5056] | 1564 | |
---|
[7968] | 1565 | // We have to get the user's language in database |
---|
[12271] | 1566 | // ---------------------------------------------- |
---|
[5056] | 1567 | $query =' |
---|
| 1568 | SELECT user_id, language |
---|
| 1569 | FROM '.USER_INFOS_TABLE.' |
---|
| 1570 | WHERE user_id = '.$user_id.' |
---|
| 1571 | ;'; |
---|
[5633] | 1572 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[5056] | 1573 | $language = $data['language']; |
---|
| 1574 | |
---|
[7968] | 1575 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1576 | // --------------------------------------------------------------------------------------- |
---|
[5056] | 1577 | switch_lang_to($data['language']); |
---|
| 1578 | |
---|
[5181] | 1579 | load_language('plugin.lang', UAM_PATH); |
---|
[5056] | 1580 | |
---|
[14729] | 1581 | if (isset($conf_UAM[45]) and $conf_UAM[45] <> '') |
---|
| 1582 | { |
---|
| 1583 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1584 | // ------------------------------------------------------- |
---|
| 1585 | $patterns[] = '#\[username\]#i'; |
---|
| 1586 | $replacements[] = $username; |
---|
| 1587 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1588 | $replacements[] = $conf['gallery_title']; |
---|
| 1589 | |
---|
| 1590 | if (function_exists('get_user_language_desc')) |
---|
| 1591 | { |
---|
| 1592 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[45]))."\n\n"; |
---|
| 1593 | } |
---|
| 1594 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[45]))."\n\n"; |
---|
| 1595 | } |
---|
| 1596 | |
---|
[11018] | 1597 | if (isset($conf_UAM[17]) and $conf_UAM[17] <> '' and isset($conf_UAM[15]) and $conf_UAM[15] == 'true') |
---|
[5056] | 1598 | { |
---|
[11255] | 1599 | // Management of Extension flags ([username], [mygallery], [myurl], [days]) |
---|
[12271] | 1600 | // ------------------------------------------------------------------------ |
---|
[9160] | 1601 | $patterns[] = '#\[username\]#i'; |
---|
| 1602 | $replacements[] = $username; |
---|
| 1603 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1604 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1605 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1606 | $replacements[] = get_gallery_home_url(); |
---|
[11255] | 1607 | $patterns[] = '#\[days\]#i'; |
---|
| 1608 | $replacements[] = $conf_UAM[16]; |
---|
[9160] | 1609 | |
---|
[5056] | 1610 | if (function_exists('get_user_language_desc')) |
---|
| 1611 | { |
---|
[11018] | 1612 | $infos1 = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[17]))."\n\n"; |
---|
[5056] | 1613 | } |
---|
| 1614 | else |
---|
| 1615 | { |
---|
[11018] | 1616 | $infos1 = l10n(preg_replace($patterns, $replacements, $conf_UAM[17]))."\n\n"; |
---|
[5056] | 1617 | } |
---|
| 1618 | |
---|
| 1619 | resetlastvisit($user_id); |
---|
| 1620 | } |
---|
| 1621 | |
---|
| 1622 | pwg_mail($email, array( |
---|
| 1623 | 'subject' => $subject, |
---|
| 1624 | 'content' => $infos1.get_absolute_root_url(), |
---|
| 1625 | )); |
---|
| 1626 | |
---|
[17944] | 1627 | // Switching back to default language |
---|
| 1628 | // ---------------------------------- |
---|
| 1629 | switch_lang_back(); |
---|
[5056] | 1630 | } |
---|
| 1631 | |
---|
[10144] | 1632 | |
---|
[7968] | 1633 | /** |
---|
[8065] | 1634 | * Function called from functions.inc.php to send notification email when user have been downgraded |
---|
| 1635 | * |
---|
[8092] | 1636 | * @param : user id, username, email address |
---|
[8065] | 1637 | * |
---|
| 1638 | */ |
---|
| 1639 | function demotion_mail($id, $username, $email) |
---|
| 1640 | { |
---|
| 1641 | global $conf; |
---|
| 1642 | |
---|
| 1643 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 1644 | |
---|
[17944] | 1645 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[8065] | 1646 | |
---|
[17944] | 1647 | $custom_txt = ""; |
---|
| 1648 | $subject = ""; |
---|
[8065] | 1649 | |
---|
| 1650 | // We have to get the user's language in database |
---|
[12271] | 1651 | // ---------------------------------------------- |
---|
[17944] | 1652 | $query = ' |
---|
[8065] | 1653 | SELECT user_id, language |
---|
| 1654 | FROM '.USER_INFOS_TABLE.' |
---|
| 1655 | WHERE user_id = '.$id.' |
---|
| 1656 | ;'; |
---|
| 1657 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 1658 | |
---|
| 1659 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
[12271] | 1660 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
[8065] | 1661 | if (empty($data)) |
---|
| 1662 | { |
---|
| 1663 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1664 | // --------------------------------------------------------------------------------------- |
---|
[8065] | 1665 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
| 1666 | switch_lang_to($language); |
---|
| 1667 | } |
---|
| 1668 | else |
---|
| 1669 | { |
---|
| 1670 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1671 | // --------------------------------------------------------------------------------------- |
---|
[8065] | 1672 | $language = $data['language']; // Usefull for debugging |
---|
| 1673 | switch_lang_to($data['language']); |
---|
| 1674 | load_language('plugin.lang', UAM_PATH); |
---|
| 1675 | } |
---|
| 1676 | |
---|
[14729] | 1677 | if (isset($conf_UAM[44]) and $conf_UAM[44] <> '') |
---|
| 1678 | { |
---|
| 1679 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1680 | // ------------------------------------------------------- |
---|
| 1681 | $patterns[] = '#\[username\]#i'; |
---|
| 1682 | $replacements[] = $username; |
---|
| 1683 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1684 | $replacements[] = $conf['gallery_title']; |
---|
| 1685 | |
---|
| 1686 | if (function_exists('get_user_language_desc')) |
---|
| 1687 | { |
---|
| 1688 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[44]))."\n\n"; |
---|
| 1689 | } |
---|
| 1690 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[44]))."\n\n"; |
---|
| 1691 | } |
---|
[8065] | 1692 | |
---|
[11018] | 1693 | if (isset($conf_UAM[24]) and $conf_UAM[24] <> '') |
---|
[8065] | 1694 | { |
---|
[9197] | 1695 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
[12271] | 1696 | // ---------------------------------------------------------------- |
---|
[9160] | 1697 | $patterns[] = '#\[username\]#i'; |
---|
[9253] | 1698 | $replacements[] = stripslashes($username); |
---|
[9160] | 1699 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1700 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1701 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1702 | $replacements[] = get_gallery_home_url(); |
---|
[9160] | 1703 | |
---|
[8065] | 1704 | if (function_exists('get_user_language_desc')) |
---|
| 1705 | { |
---|
[11018] | 1706 | $custom_txt = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[24]))."\n\n"; |
---|
[8065] | 1707 | } |
---|
[11018] | 1708 | else $custom_txt = l10n(preg_replace($patterns, $replacements, $conf_UAM[24]))."\n\n"; |
---|
[8065] | 1709 | } |
---|
| 1710 | |
---|
| 1711 | $infos1 = array( |
---|
[9177] | 1712 | get_l10n_args('UAM_User: %s', stripslashes($username)), |
---|
[8065] | 1713 | get_l10n_args('Email: %s', $email), |
---|
| 1714 | get_l10n_args('', ''), |
---|
| 1715 | ); |
---|
| 1716 | |
---|
| 1717 | $infos2 = array |
---|
| 1718 | ( |
---|
[9177] | 1719 | get_l10n_args('UAM_Link: %s', ResetConfirmMail($id)), |
---|
[8065] | 1720 | get_l10n_args('', ''), |
---|
| 1721 | ); |
---|
| 1722 | |
---|
[9253] | 1723 | resetlastvisit($id); |
---|
[8065] | 1724 | |
---|
| 1725 | // Sending the email with subject and contents |
---|
[12271] | 1726 | // ------------------------------------------- |
---|
[8065] | 1727 | pwg_mail($email, array( |
---|
| 1728 | 'subject' => $subject, |
---|
| 1729 | 'content' => ($custom_txt.l10n_args($infos1)."\n\n".l10n_args($infos2)."\n\n").get_absolute_root_url(), |
---|
| 1730 | )); |
---|
| 1731 | |
---|
[17944] | 1732 | // Switching back to default language |
---|
| 1733 | // ---------------------------------- |
---|
| 1734 | switch_lang_back(); |
---|
[8065] | 1735 | } |
---|
| 1736 | |
---|
[10144] | 1737 | |
---|
[8065] | 1738 | /** |
---|
[8092] | 1739 | * Function called from UAM_admin.php to send notification email when user registration have been manually validated by admin |
---|
| 1740 | * |
---|
| 1741 | * @param : user id |
---|
| 1742 | * |
---|
| 1743 | */ |
---|
| 1744 | function validation_mail($id) |
---|
| 1745 | { |
---|
| 1746 | global $conf; |
---|
| 1747 | |
---|
| 1748 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 1749 | |
---|
[17944] | 1750 | include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php'); |
---|
[8092] | 1751 | |
---|
[17944] | 1752 | $custom_txt = ""; |
---|
[14729] | 1753 | $subject = ""; |
---|
[8092] | 1754 | |
---|
| 1755 | // We have to get the user's language in database |
---|
[12271] | 1756 | // ---------------------------------------------- |
---|
[8092] | 1757 | $query =' |
---|
| 1758 | SELECT user_id, language |
---|
| 1759 | FROM '.USER_INFOS_TABLE.' |
---|
| 1760 | WHERE user_id = '.$id.' |
---|
| 1761 | ;'; |
---|
| 1762 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 1763 | |
---|
| 1764 | // Check if user is already registered (profile changing) - If not (new registration), language is set to current gallery language |
---|
[12271] | 1765 | // ------------------------------------------------------------------------------------------------------------------------------- |
---|
[8092] | 1766 | if (empty($data)) |
---|
| 1767 | { |
---|
| 1768 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1769 | // --------------------------------------------------------------------------------------- |
---|
[8092] | 1770 | $language = pwg_get_session_var( 'lang_switch', $user['language'] ); |
---|
| 1771 | switch_lang_to($language); |
---|
| 1772 | } |
---|
| 1773 | else |
---|
| 1774 | { |
---|
| 1775 | // And switch gallery to this language before using personalized and multilangual contents |
---|
[12271] | 1776 | // --------------------------------------------------------------------------------------- |
---|
[8092] | 1777 | $language = $data['language']; // Usefull for debugging |
---|
| 1778 | switch_lang_to($data['language']); |
---|
| 1779 | load_language('plugin.lang', UAM_PATH); |
---|
| 1780 | } |
---|
| 1781 | |
---|
| 1782 | // Retreive users email and user name from id |
---|
[12271] | 1783 | // ------------------------------------------ |
---|
[8092] | 1784 | $query =' |
---|
| 1785 | SELECT id, username, mail_address |
---|
| 1786 | FROM '.USERS_TABLE.' |
---|
| 1787 | WHERE id = '.$id.' |
---|
| 1788 | ;'; |
---|
| 1789 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 1790 | |
---|
[14729] | 1791 | if (isset($conf_UAM[46]) and $conf_UAM[46] <> '') |
---|
| 1792 | { |
---|
| 1793 | // Management of Extension flags ([username], [mygallery]) |
---|
| 1794 | // ------------------------------------------------------- |
---|
| 1795 | $patterns[] = '#\[username\]#i'; |
---|
[17804] | 1796 | $replacements[] = $result['username']; |
---|
[14729] | 1797 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1798 | $replacements[] = $conf['gallery_title']; |
---|
[17989] | 1799 | |
---|
[14729] | 1800 | if (function_exists('get_user_language_desc')) |
---|
| 1801 | { |
---|
| 1802 | $subject = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[46]))."\n\n"; |
---|
| 1803 | } |
---|
[17987] | 1804 | else $subject = l10n(preg_replace($patterns, $replacements, $conf_UAM[46]))."\n\n"; |
---|
[14729] | 1805 | } |
---|
[8092] | 1806 | |
---|
[11018] | 1807 | if (isset($conf_UAM[27]) and $conf_UAM[27] <> '') |
---|
[8092] | 1808 | { |
---|
[9197] | 1809 | // Management of Extension flags ([username], [mygallery], [myurl]) |
---|
[12271] | 1810 | // ---------------------------------------------------------------- |
---|
[9160] | 1811 | $patterns[] = '#\[username\]#i'; |
---|
[9253] | 1812 | $replacements[] = $result['username']; |
---|
[9160] | 1813 | $patterns[] = '#\[mygallery\]#i'; |
---|
| 1814 | $replacements[] = $conf['gallery_title']; |
---|
[9197] | 1815 | $patterns[] = '#\[myurl\]#i'; |
---|
[14651] | 1816 | $replacements[] = get_gallery_home_url(); |
---|
[8092] | 1817 | if (function_exists('get_user_language_desc')) |
---|
| 1818 | { |
---|
[11018] | 1819 | $custom_txt = get_user_language_desc(preg_replace($patterns, $replacements, $conf_UAM[27]))."\n\n"; |
---|
[8092] | 1820 | } |
---|
[17987] | 1821 | else $custom_txt = l10n(preg_replace($patterns, $replacements, $conf_UAM[27]))."\n\n"; |
---|
[8092] | 1822 | } |
---|
| 1823 | |
---|
| 1824 | $infos = array( |
---|
[9177] | 1825 | get_l10n_args('UAM_User: %s', stripslashes($result['username'])), |
---|
[8092] | 1826 | get_l10n_args('Email: %s', $result['mail_address']), |
---|
| 1827 | get_l10n_args('', ''), |
---|
| 1828 | ); |
---|
| 1829 | |
---|
| 1830 | // Sending the email with subject and contents |
---|
[12271] | 1831 | // ------------------------------------------- |
---|
[8092] | 1832 | pwg_mail($result['mail_address'], array( |
---|
| 1833 | 'subject' => $subject, |
---|
| 1834 | 'content' => (l10n_args($infos)."\n\n".$custom_txt), |
---|
| 1835 | )); |
---|
| 1836 | |
---|
[17944] | 1837 | // Switching back to default language |
---|
| 1838 | // ---------------------------------- |
---|
| 1839 | switch_lang_back(); |
---|
[8092] | 1840 | } |
---|
| 1841 | |
---|
[10144] | 1842 | |
---|
[8092] | 1843 | /** |
---|
[7968] | 1844 | * Function called from functions AddConfirmMail and ResetConfirmMail for validation key generation |
---|
| 1845 | * |
---|
| 1846 | * @return : validation key |
---|
| 1847 | * |
---|
| 1848 | */ |
---|
[5056] | 1849 | function FindAvailableConfirmMailID() |
---|
| 1850 | { |
---|
| 1851 | while (true) |
---|
| 1852 | { |
---|
| 1853 | $id = generate_key(16); |
---|
[17918] | 1854 | $query = ' |
---|
[5056] | 1855 | SELECT COUNT(*) |
---|
[17918] | 1856 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
[17968] | 1857 | WHERE id = "'.$id.'" |
---|
[17918] | 1858 | ;'; |
---|
[5633] | 1859 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 1860 | |
---|
| 1861 | if ($count == 0) |
---|
| 1862 | return $id; |
---|
| 1863 | } |
---|
| 1864 | } |
---|
| 1865 | |
---|
[10144] | 1866 | |
---|
[7968] | 1867 | /** |
---|
| 1868 | * Function called from functions SendMail2User to process unvalidated users and generate validation key link |
---|
| 1869 | * |
---|
| 1870 | * @param : User id, email address |
---|
| 1871 | * |
---|
| 1872 | * @return : Build validation key in URL |
---|
| 1873 | * |
---|
| 1874 | */ |
---|
[5056] | 1875 | function AddConfirmMail($user_id, $email) |
---|
| 1876 | { |
---|
| 1877 | global $conf; |
---|
| 1878 | |
---|
[5181] | 1879 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 1880 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
| 1881 | |
---|
[5633] | 1882 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 1883 | |
---|
| 1884 | if (isset($Confirm_Mail_ID)) |
---|
| 1885 | { |
---|
[17918] | 1886 | $query = ' |
---|
[5056] | 1887 | SELECT status |
---|
[17918] | 1888 | FROM '.USER_INFOS_TABLE.' |
---|
| 1889 | WHERE user_id = '.$user_id.' |
---|
| 1890 | ;'; |
---|
[5633] | 1891 | list($status) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 1892 | |
---|
[17918] | 1893 | $query = ' |
---|
| 1894 | INSERT INTO '.USER_CONFIRM_MAIL_TABLE.' |
---|
[5056] | 1895 | (id, user_id, mail_address, status, date_check) |
---|
| 1896 | VALUES |
---|
[17918] | 1897 | ("'.$Confirm_Mail_ID.'", '.$user_id.', "'.$email.'", "'.$status.'", null) |
---|
| 1898 | ;'; |
---|
[5056] | 1899 | pwg_query($query); |
---|
| 1900 | |
---|
[8065] | 1901 | // Delete user from all groups |
---|
[12271] | 1902 | // --------------------------- |
---|
[17918] | 1903 | $query = ' |
---|
| 1904 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 1905 | WHERE user_id = '.$user_id.' |
---|
[5056] | 1906 | AND ( |
---|
[17946] | 1907 | group_id = '.$conf_UAM[2].' |
---|
[6354] | 1908 | OR |
---|
[17946] | 1909 | group_id = '.$conf_UAM[3].' |
---|
[5056] | 1910 | ) |
---|
[17918] | 1911 | ;'; |
---|
[5056] | 1912 | pwg_query($query); |
---|
| 1913 | |
---|
[8065] | 1914 | // Set user unvalidated status |
---|
[12271] | 1915 | // --------------------------- |
---|
[11018] | 1916 | if (!is_admin() and $conf_UAM[7] <> -1) |
---|
[5056] | 1917 | { |
---|
[17918] | 1918 | $query = ' |
---|
| 1919 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 1920 | SET status = "'.$conf_UAM[7].'" |
---|
| 1921 | WHERE user_id = '.$user_id.' |
---|
| 1922 | ;'; |
---|
[5056] | 1923 | pwg_query($query); |
---|
| 1924 | } |
---|
| 1925 | |
---|
[8065] | 1926 | // Set user unvalidated group |
---|
[12271] | 1927 | // -------------------------- |
---|
[8065] | 1928 | if (!is_admin() and $conf_UAM[2] <> -1) |
---|
[5056] | 1929 | { |
---|
[17918] | 1930 | $query = ' |
---|
| 1931 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
[5056] | 1932 | (user_id, group_id) |
---|
| 1933 | VALUES |
---|
[17946] | 1934 | ('.$user_id.', '.$conf_UAM[2].') |
---|
[17918] | 1935 | ;'; |
---|
[5056] | 1936 | pwg_query($query); |
---|
| 1937 | } |
---|
[12189] | 1938 | |
---|
| 1939 | // Set user unvalidated privacy level |
---|
[12271] | 1940 | // ---------------------------------- |
---|
[12189] | 1941 | if (!is_admin() and $conf_UAM[35] <> -1) |
---|
| 1942 | { |
---|
[17918] | 1943 | $query = ' |
---|
| 1944 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 1945 | SET level = "'.$conf_UAM[35].'" |
---|
| 1946 | WHERE user_id = '.$user_id.' |
---|
| 1947 | ;'; |
---|
[12189] | 1948 | pwg_query($query); |
---|
| 1949 | } |
---|
[5056] | 1950 | |
---|
[17918] | 1951 | // Set UAM_validated field to false in #_users table |
---|
| 1952 | // ------------------------------------------------- |
---|
| 1953 | SetUnvalidated($user_id); |
---|
| 1954 | |
---|
[18205] | 1955 | if ( $conf['guest_access'] ) |
---|
| 1956 | { |
---|
| 1957 | return( get_absolute_root_url().'?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
| 1958 | } |
---|
| 1959 | else |
---|
| 1960 | { |
---|
| 1961 | return( get_absolute_root_url().'identification.php?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
| 1962 | } |
---|
[5056] | 1963 | } |
---|
| 1964 | } |
---|
| 1965 | |
---|
[10144] | 1966 | |
---|
[7968] | 1967 | /** |
---|
[12189] | 1968 | * Function called from UAM_Adduser() to set group/status/level to new users if manual validation is set |
---|
[7968] | 1969 | * |
---|
| 1970 | * @param : User id |
---|
| 1971 | * |
---|
| 1972 | * |
---|
| 1973 | */ |
---|
[12189] | 1974 | function SetPermission($user_id) |
---|
[6757] | 1975 | { |
---|
| 1976 | global $conf; |
---|
| 1977 | |
---|
| 1978 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 1979 | |
---|
[12189] | 1980 | // Groups cleanup |
---|
[12271] | 1981 | // -------------- |
---|
[17918] | 1982 | $query = ' |
---|
| 1983 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 1984 | WHERE user_id = '.$user_id.' |
---|
[6757] | 1985 | AND ( |
---|
[17946] | 1986 | group_id = '.$conf_UAM[2].' |
---|
[6757] | 1987 | OR |
---|
[17946] | 1988 | group_id = '.$conf_UAM[3].' |
---|
[6757] | 1989 | ) |
---|
[17918] | 1990 | ;'; |
---|
[6757] | 1991 | pwg_query($query); |
---|
| 1992 | |
---|
[12189] | 1993 | if (!is_admin() and $conf_UAM[7] <> -1) // Set status |
---|
[6757] | 1994 | { |
---|
[17918] | 1995 | $query = ' |
---|
| 1996 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 1997 | SET status = "'.$conf_UAM[7].'" |
---|
| 1998 | WHERE user_id = '.$user_id.' |
---|
| 1999 | ;'; |
---|
[6757] | 2000 | pwg_query($query); |
---|
| 2001 | } |
---|
| 2002 | |
---|
[12189] | 2003 | if (!is_admin() and $conf_UAM[2] <> -1) // Set group |
---|
[6757] | 2004 | { |
---|
[17918] | 2005 | $query = ' |
---|
| 2006 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
[6757] | 2007 | (user_id, group_id) |
---|
| 2008 | VALUES |
---|
[17946] | 2009 | ('.$user_id.', '.$conf_UAM[2].') |
---|
[17918] | 2010 | ;'; |
---|
[6757] | 2011 | pwg_query($query); |
---|
| 2012 | } |
---|
[12189] | 2013 | |
---|
[13822] | 2014 | if (!is_admin() and $conf_UAM[35] <> -1) // Set privacy level |
---|
[12189] | 2015 | { |
---|
[17918] | 2016 | $query = ' |
---|
| 2017 | INSERT INTO '.USER_INFOS_TABLE.' |
---|
[12189] | 2018 | (user_id, level) |
---|
| 2019 | VALUES |
---|
[17918] | 2020 | ('.$user_id.', "'.$conf_UAM[35].'") |
---|
| 2021 | ;'; |
---|
[12189] | 2022 | pwg_query($query); |
---|
| 2023 | } |
---|
[6757] | 2024 | } |
---|
| 2025 | |
---|
[10144] | 2026 | |
---|
[7968] | 2027 | /** |
---|
| 2028 | * Function called from UAM_admin.php to reset validation key |
---|
| 2029 | * |
---|
| 2030 | * @param : User id |
---|
| 2031 | * |
---|
| 2032 | * @return : Build validation key in URL |
---|
| 2033 | * |
---|
| 2034 | */ |
---|
[5056] | 2035 | function ResetConfirmMail($user_id) |
---|
| 2036 | { |
---|
| 2037 | global $conf; |
---|
| 2038 | |
---|
| 2039 | $Confirm_Mail_ID = FindAvailableConfirmMailID(); |
---|
| 2040 | |
---|
[5633] | 2041 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 2042 | |
---|
| 2043 | if (isset($Confirm_Mail_ID)) |
---|
| 2044 | { |
---|
[17918] | 2045 | $query = ' |
---|
| 2046 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 2047 | SET id = "'.$Confirm_Mail_ID.'" |
---|
| 2048 | WHERE user_id = '.$user_id.' |
---|
| 2049 | ;'; |
---|
[5056] | 2050 | pwg_query($query); |
---|
| 2051 | |
---|
[18205] | 2052 | $query = ' |
---|
[17918] | 2053 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 2054 | SET registration_date = "'.$dbnow.'" |
---|
| 2055 | WHERE user_id = '.$user_id.' |
---|
| 2056 | ;'; |
---|
[18205] | 2057 | pwg_query($query); |
---|
[5056] | 2058 | |
---|
[18205] | 2059 | if ( $conf['guest_access'] ) |
---|
| 2060 | { |
---|
| 2061 | return( get_absolute_root_url().'?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
| 2062 | } |
---|
| 2063 | else |
---|
| 2064 | { |
---|
| 2065 | return( get_absolute_root_url().'identification.php?key='.$Confirm_Mail_ID.'&userid='.$user_id); |
---|
| 2066 | } |
---|
[5056] | 2067 | } |
---|
| 2068 | } |
---|
| 2069 | |
---|
[10144] | 2070 | |
---|
[7968] | 2071 | /** |
---|
| 2072 | * Function called from functions.inc.php to reset last visit date after sending a reminder |
---|
| 2073 | * |
---|
| 2074 | * @param : User id |
---|
| 2075 | * |
---|
| 2076 | */ |
---|
[5056] | 2077 | function resetlastvisit($user_id) |
---|
| 2078 | { |
---|
| 2079 | global $conf; |
---|
| 2080 | |
---|
[5633] | 2081 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 2082 | |
---|
[17918] | 2083 | $query = ' |
---|
| 2084 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
| 2085 | SET lastvisit = "'.$dbnow.'", reminder = "true" |
---|
| 2086 | WHERE user_id = '.$user_id.' |
---|
| 2087 | ;'; |
---|
[5056] | 2088 | pwg_query($query); |
---|
| 2089 | } |
---|
| 2090 | |
---|
| 2091 | |
---|
[7968] | 2092 | /** |
---|
| 2093 | * Function called from main.inc.php - Triggered on user deletion |
---|
| 2094 | * |
---|
| 2095 | */ |
---|
[5056] | 2096 | function DeleteConfirmMail($user_id) |
---|
| 2097 | { |
---|
[17918] | 2098 | $query = ' |
---|
| 2099 | DELETE FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 2100 | WHERE user_id = '.$user_id.' |
---|
| 2101 | ;'; |
---|
[5056] | 2102 | pwg_query($query); |
---|
| 2103 | } |
---|
| 2104 | |
---|
[7968] | 2105 | /** |
---|
| 2106 | * Function called from main.inc.php - Triggered on user deletion |
---|
| 2107 | * |
---|
| 2108 | */ |
---|
[5056] | 2109 | function DeleteLastVisit($user_id) |
---|
| 2110 | { |
---|
[17918] | 2111 | $query = ' |
---|
| 2112 | DELETE FROM '.USER_LASTVISIT_TABLE.' |
---|
| 2113 | WHERE user_id = '.$user_id.' |
---|
| 2114 | ;'; |
---|
[5056] | 2115 | pwg_query($query); |
---|
| 2116 | } |
---|
| 2117 | |
---|
[10144] | 2118 | |
---|
[7968] | 2119 | /** |
---|
| 2120 | * Function called from main.inc.php - Triggered on user deletion |
---|
| 2121 | * |
---|
| 2122 | * @param : User id |
---|
| 2123 | * |
---|
| 2124 | */ |
---|
[6775] | 2125 | function DeleteRedir($user_id) |
---|
| 2126 | { |
---|
| 2127 | $tab = array(); |
---|
| 2128 | |
---|
[6785] | 2129 | $query = ' |
---|
[6775] | 2130 | SELECT value |
---|
[6785] | 2131 | FROM '.CONFIG_TABLE.' |
---|
| 2132 | WHERE param = "UserAdvManager_Redir" |
---|
| 2133 | ;'; |
---|
[6775] | 2134 | |
---|
| 2135 | $tab = pwg_db_fetch_row(pwg_query($query)); |
---|
| 2136 | |
---|
| 2137 | $values = explode(',', $tab[0]); |
---|
| 2138 | |
---|
| 2139 | unset($values[array_search($user_id, $values)]); |
---|
| 2140 | |
---|
[17918] | 2141 | $query = ' |
---|
| 2142 | UPDATE '.CONFIG_TABLE.' |
---|
| 2143 | SET value = "'.implode(',', $values).'" |
---|
| 2144 | WHERE param = "UserAdvManager_Redir";'; |
---|
[6775] | 2145 | |
---|
| 2146 | pwg_query($query); |
---|
| 2147 | } |
---|
| 2148 | |
---|
[10144] | 2149 | |
---|
[7968] | 2150 | /** |
---|
| 2151 | * Function called from ConfirmMail.php to verify validation key used by user according time limit |
---|
| 2152 | * Return true is key validation is OK else return false |
---|
| 2153 | * |
---|
| 2154 | * @param : User id |
---|
| 2155 | * |
---|
| 2156 | * @return : Bool |
---|
| 2157 | * |
---|
| 2158 | */ |
---|
[5056] | 2159 | function VerifyConfirmMail($id) |
---|
| 2160 | { |
---|
| 2161 | global $conf; |
---|
| 2162 | |
---|
| 2163 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 2164 | |
---|
[5181] | 2165 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 2166 | |
---|
[5181] | 2167 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 2168 | |
---|
[17918] | 2169 | $query = ' |
---|
[5056] | 2170 | SELECT COUNT(*) |
---|
[17918] | 2171 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
[17946] | 2172 | WHERE id = "'.$id.'" |
---|
[17918] | 2173 | ;'; |
---|
[5633] | 2174 | list($count) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 2175 | |
---|
| 2176 | if ($count == 1) |
---|
| 2177 | { |
---|
[17918] | 2178 | $query = ' |
---|
[5056] | 2179 | SELECT user_id, status, date_check |
---|
[17918] | 2180 | FROM '.USER_CONFIRM_MAIL_TABLE.' |
---|
[17946] | 2181 | WHERE id = "'.$id.'" |
---|
[17918] | 2182 | ;'; |
---|
[5633] | 2183 | $data = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[9266] | 2184 | |
---|
[12227] | 2185 | if (!empty($data) and isset($data['user_id']) and is_null($data['date_check'])) |
---|
[5056] | 2186 | { |
---|
[17918] | 2187 | $query = ' |
---|
[5056] | 2188 | SELECT registration_date |
---|
[17918] | 2189 | FROM '.USER_INFOS_TABLE.' |
---|
| 2190 | WHERE user_id = '.$data['user_id'].' |
---|
| 2191 | ;'; |
---|
[5633] | 2192 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 2193 | |
---|
[7968] | 2194 | // Time limit process |
---|
| 2195 | // ******************************************** |
---|
[5056] | 2196 | if (!empty($registration_date)) |
---|
| 2197 | { |
---|
[17944] | 2198 | // Verify Confirmmail with time limit ON |
---|
| 2199 | // ------------------------------------- |
---|
| 2200 | if (isset ($conf_UAM_ConfirmMail[1])) |
---|
| 2201 | { |
---|
| 2202 | // Dates formating and compare |
---|
| 2203 | // --------------------------- |
---|
| 2204 | $today = date("d-m-Y"); // Get today's date |
---|
| 2205 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
| 2206 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
[5056] | 2207 | |
---|
[17944] | 2208 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
| 2209 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
| 2210 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
[5056] | 2211 | |
---|
[17944] | 2212 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
| 2213 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
| 2214 | |
---|
| 2215 | // Condition with the value set for time limit |
---|
| 2216 | // ------------------------------------------- |
---|
| 2217 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
| 2218 | { |
---|
| 2219 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 2220 | |
---|
| 2221 | // Update ConfirmMail table |
---|
| 2222 | // ------------------------ |
---|
| 2223 | $query = ' |
---|
[5056] | 2224 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
[9266] | 2225 | SET date_check="'.$dbnow.'", reminder="false" |
---|
[5056] | 2226 | WHERE id = "'.$id.'" |
---|
| 2227 | ;'; |
---|
[17944] | 2228 | pwg_query($query); |
---|
[12189] | 2229 | |
---|
[17944] | 2230 | // Update LastVisit table - Force reminder field to false |
---|
| 2231 | // Usefull when a user has been automatically downgraded and revalidate its registration |
---|
| 2232 | // ------------------------------------------------------------------------------------- |
---|
| 2233 | $query = ' |
---|
[12189] | 2234 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
| 2235 | SET reminder="false" |
---|
| 2236 | WHERE user_id = "'.$data['user_id'].'" |
---|
| 2237 | ;'; |
---|
[17944] | 2238 | pwg_query($query); |
---|
[5056] | 2239 | |
---|
[17944] | 2240 | if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group |
---|
| 2241 | { |
---|
| 2242 | $query = ' |
---|
[17918] | 2243 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 2244 | WHERE user_id = '.$data['user_id'].' |
---|
[17946] | 2245 | AND group_id = '.$conf_UAM[2].' |
---|
[17918] | 2246 | ;'; |
---|
[17944] | 2247 | pwg_query($query); |
---|
| 2248 | } |
---|
| 2249 | |
---|
| 2250 | if ($conf_UAM[3] <> -1) // Add user to validated users group |
---|
| 2251 | { |
---|
| 2252 | $query = ' |
---|
[17918] | 2253 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
[5056] | 2254 | (user_id, group_id) |
---|
| 2255 | VALUES |
---|
[17946] | 2256 | ('.$data['user_id'].', '.$conf_UAM[3].') |
---|
[17918] | 2257 | ;'; |
---|
[17944] | 2258 | pwg_query($query); |
---|
| 2259 | } |
---|
[5056] | 2260 | |
---|
[17946] | 2261 | if ($conf_UAM[4] <> -1) // Change user's status |
---|
[17944] | 2262 | { |
---|
| 2263 | $query = ' |
---|
[17918] | 2264 | UPDATE '.USER_INFOS_TABLE.' |
---|
[17946] | 2265 | SET status = "'.$conf_UAM[4].'" |
---|
[17918] | 2266 | WHERE user_id = '.$data['user_id'].' |
---|
| 2267 | ;'; |
---|
[17944] | 2268 | pwg_query($query); |
---|
| 2269 | } |
---|
[12189] | 2270 | |
---|
[17946] | 2271 | if ($conf_UAM[36] <> -1) // Change user's privacy level |
---|
[17944] | 2272 | { |
---|
| 2273 | $query = ' |
---|
[17918] | 2274 | UPDATE '.USER_INFOS_TABLE.' |
---|
[17946] | 2275 | SET level = "'.$conf_UAM[36].'" |
---|
[17918] | 2276 | WHERE user_id = '.$data['user_id'].' |
---|
| 2277 | ;'; |
---|
[17944] | 2278 | pwg_query($query); |
---|
| 2279 | } |
---|
[12189] | 2280 | |
---|
[17946] | 2281 | // Set UAM_validated field to True in #_users table |
---|
| 2282 | $query = ' |
---|
| 2283 | UPDATE '.USERS_TABLE.' |
---|
| 2284 | SET UAM_validated = "true" |
---|
| 2285 | WHERE id = '.$data['user_id'].' |
---|
| 2286 | ;'; |
---|
| 2287 | pwg_query($query); |
---|
| 2288 | |
---|
[17944] | 2289 | // Refresh user's category cache |
---|
| 2290 | // ----------------------------- |
---|
| 2291 | invalidate_user_cache(); |
---|
[5056] | 2292 | |
---|
[17944] | 2293 | return true; |
---|
| 2294 | } |
---|
| 2295 | elseif ($deltadays > $conf_UAM_ConfirmMail[1]) // If timelimit exeeds |
---|
| 2296 | { |
---|
| 2297 | return false; |
---|
| 2298 | } |
---|
| 2299 | } |
---|
| 2300 | // Verify Confirmmail with time limit OFF |
---|
| 2301 | // -------------------------------------- |
---|
| 2302 | else |
---|
| 2303 | { |
---|
| 2304 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
| 2305 | |
---|
| 2306 | // Update ConfirmMail table |
---|
| 2307 | // ------------------------ |
---|
| 2308 | $query = ' |
---|
[5056] | 2309 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 2310 | SET date_check="'.$dbnow.'" |
---|
| 2311 | WHERE id = "'.$id.'" |
---|
| 2312 | ;'; |
---|
[17944] | 2313 | pwg_query($query); |
---|
[12189] | 2314 | |
---|
[17944] | 2315 | // Update LastVisit table - Force reminder field to false |
---|
| 2316 | // Usefull when a user has been automatically downgraded and revalidate its registration |
---|
| 2317 | // ------------------------------------------------------------------------------------- |
---|
| 2318 | $query = ' |
---|
[12189] | 2319 | UPDATE '.USER_LASTVISIT_TABLE.' |
---|
| 2320 | SET reminder="false" |
---|
| 2321 | WHERE user_id = "'.$data['user_id'].'" |
---|
| 2322 | ;'; |
---|
[17944] | 2323 | pwg_query($query); |
---|
| 2324 | |
---|
| 2325 | if ($conf_UAM[2] <> -1) // Delete user from unvalidated users group |
---|
| 2326 | { |
---|
| 2327 | $query = ' |
---|
[17918] | 2328 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 2329 | WHERE user_id = '.$data['user_id'].' |
---|
[17946] | 2330 | AND group_id = '.$conf_UAM[2].' |
---|
[17918] | 2331 | ;'; |
---|
[17944] | 2332 | pwg_query($query); |
---|
| 2333 | } |
---|
| 2334 | |
---|
| 2335 | if ($conf_UAM[3] <> -1) |
---|
| 2336 | { |
---|
| 2337 | $query = ' |
---|
[17918] | 2338 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 2339 | WHERE user_id = '.$data['user_id'].' |
---|
[17946] | 2340 | AND group_id = '.$conf_UAM[3].' |
---|
[17918] | 2341 | ;'; |
---|
[17944] | 2342 | pwg_query($query); |
---|
[5056] | 2343 | |
---|
[17944] | 2344 | $query = ' |
---|
[17918] | 2345 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
[5056] | 2346 | (user_id, group_id) |
---|
| 2347 | VALUES |
---|
[17946] | 2348 | ('.$data['user_id'].', '.$conf_UAM[3].') |
---|
[17918] | 2349 | ;'; |
---|
[17944] | 2350 | pwg_query($query); |
---|
| 2351 | } |
---|
[5056] | 2352 | |
---|
[17946] | 2353 | if ($conf_UAM[4] <> -1) // Change user's status |
---|
[17944] | 2354 | { |
---|
| 2355 | $query = ' |
---|
[17918] | 2356 | UPDATE '.USER_INFOS_TABLE.' |
---|
[17946] | 2357 | SET status = "'.$conf_UAM[4].'" |
---|
[17918] | 2358 | WHERE user_id = '.$data['user_id'].' |
---|
| 2359 | ;'; |
---|
[17944] | 2360 | pwg_query($query); |
---|
| 2361 | } |
---|
[12189] | 2362 | |
---|
[17946] | 2363 | if ($conf_UAM[36] <> -1) // Change user's privacy level |
---|
[17944] | 2364 | { |
---|
| 2365 | $query = ' |
---|
[17918] | 2366 | UPDATE '.USER_INFOS_TABLE.' |
---|
[17946] | 2367 | SET level = "'.$conf_UAM[36].'" |
---|
[17918] | 2368 | WHERE user_id = '.$data['user_id'].' |
---|
| 2369 | ;'; |
---|
[17944] | 2370 | pwg_query($query); |
---|
| 2371 | } |
---|
[12189] | 2372 | |
---|
[17946] | 2373 | // Set UAM_validated field to True in #_users table |
---|
| 2374 | $query = ' |
---|
| 2375 | UPDATE '.USERS_TABLE.' |
---|
| 2376 | SET UAM_validated = "true" |
---|
| 2377 | WHERE id = '.$data['user_id'].' |
---|
| 2378 | ;'; |
---|
| 2379 | pwg_query($query); |
---|
| 2380 | |
---|
[17944] | 2381 | // Refresh user's category cache |
---|
| 2382 | // ----------------------------- |
---|
| 2383 | invalidate_user_cache(); |
---|
| 2384 | |
---|
| 2385 | return true; |
---|
| 2386 | } |
---|
| 2387 | } |
---|
[17887] | 2388 | } |
---|
[12227] | 2389 | else if (!empty($data) and !is_null($data['date_check'])) |
---|
| 2390 | { |
---|
| 2391 | return false; |
---|
| 2392 | } |
---|
[17944] | 2393 | } |
---|
[5056] | 2394 | else |
---|
| 2395 | return false; |
---|
| 2396 | } |
---|
| 2397 | |
---|
[10144] | 2398 | |
---|
[7968] | 2399 | /** |
---|
[17918] | 2400 | * Function called from UAM_admin.php for manual validation by admin |
---|
[7968] | 2401 | * |
---|
| 2402 | * @param : User id |
---|
| 2403 | * |
---|
| 2404 | */ |
---|
[17918] | 2405 | function ManualValidation($id) |
---|
[5056] | 2406 | { |
---|
[17918] | 2407 | global $conf; |
---|
[5056] | 2408 | |
---|
[17918] | 2409 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 2410 | |
---|
[17918] | 2411 | if (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') // Set date of validation |
---|
| 2412 | { |
---|
| 2413 | list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); |
---|
[5056] | 2414 | |
---|
[17918] | 2415 | $query = ' |
---|
| 2416 | UPDATE '.USER_CONFIRM_MAIL_TABLE.' |
---|
| 2417 | SET date_check="'.$dbnow.'" |
---|
| 2418 | WHERE user_id = '.$id.' |
---|
| 2419 | ;'; |
---|
| 2420 | pwg_query($query); |
---|
| 2421 | } |
---|
[17846] | 2422 | |
---|
[17918] | 2423 | if ($conf_UAM[2] <> -1) // Delete user from waiting group |
---|
| 2424 | { |
---|
| 2425 | $query = ' |
---|
| 2426 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 2427 | WHERE user_id = '.$id.' |
---|
[17946] | 2428 | AND group_id = '.$conf_UAM[2].' |
---|
[17918] | 2429 | ;'; |
---|
| 2430 | pwg_query($query); |
---|
| 2431 | } |
---|
[5056] | 2432 | |
---|
[17918] | 2433 | if ($conf_UAM[3] <> -1) // Set user's valid group |
---|
| 2434 | { |
---|
| 2435 | $query = ' |
---|
| 2436 | DELETE FROM '.USER_GROUP_TABLE.' |
---|
| 2437 | WHERE user_id = '.$id.' |
---|
[17946] | 2438 | AND group_id = '.$conf_UAM[3].' |
---|
[17918] | 2439 | ;'; |
---|
| 2440 | pwg_query($query); |
---|
[17887] | 2441 | |
---|
[17918] | 2442 | $query = ' |
---|
| 2443 | INSERT INTO '.USER_GROUP_TABLE.' |
---|
| 2444 | (user_id, group_id) |
---|
[5056] | 2445 | VALUES |
---|
[17946] | 2446 | ('.$id.', '.$conf_UAM[3].') |
---|
[17918] | 2447 | ;'; |
---|
| 2448 | pwg_query($query); |
---|
| 2449 | } |
---|
[5056] | 2450 | |
---|
[17918] | 2451 | if ($conf_UAM[4] <> -1) // Set user's valid status |
---|
| 2452 | { |
---|
| 2453 | $query = ' |
---|
| 2454 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 2455 | SET status = "'.$conf_UAM[4].'" |
---|
| 2456 | WHERE user_id = '.$id.' |
---|
| 2457 | ;'; |
---|
| 2458 | pwg_query($query); |
---|
| 2459 | } |
---|
[8072] | 2460 | |
---|
[17918] | 2461 | if ($conf_UAM[36] <> -1) // Set user's valid privacy level |
---|
| 2462 | { |
---|
| 2463 | $query = ' |
---|
| 2464 | UPDATE '.USER_INFOS_TABLE.' |
---|
| 2465 | SET level = "'.$conf_UAM[36].'" |
---|
| 2466 | WHERE user_id = '.$id.' |
---|
| 2467 | ;'; |
---|
| 2468 | pwg_query($query); |
---|
| 2469 | } |
---|
| 2470 | |
---|
| 2471 | // Set UAM_validated field to True in #_users table |
---|
| 2472 | $query = ' |
---|
| 2473 | UPDATE '.USERS_TABLE.' |
---|
| 2474 | SET UAM_validated = "true" |
---|
| 2475 | WHERE id = '.$id.' |
---|
| 2476 | ;'; |
---|
[17887] | 2477 | pwg_query($query); |
---|
[5056] | 2478 | } |
---|
| 2479 | |
---|
[10144] | 2480 | |
---|
[7968] | 2481 | /** |
---|
[18087] | 2482 | * Function called from functions.inc.php - Check if username matches forbidden characters |
---|
[7968] | 2483 | * |
---|
| 2484 | * @param : User login |
---|
| 2485 | * |
---|
| 2486 | * @return : Bool |
---|
| 2487 | * |
---|
| 2488 | */ |
---|
[5056] | 2489 | function ValidateUsername($login) |
---|
| 2490 | { |
---|
| 2491 | global $conf; |
---|
| 2492 | |
---|
[5181] | 2493 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 2494 | |
---|
[11018] | 2495 | if (isset($login) and isset($conf_UAM[6]) and $conf_UAM[6] <> '') |
---|
[5056] | 2496 | { |
---|
[11018] | 2497 | $conf_CharExclusion = preg_split("/,/",$conf_UAM[6]); |
---|
[5181] | 2498 | for ($i = 0 ; $i < count($conf_CharExclusion) ; $i++) |
---|
[5056] | 2499 | { |
---|
[18158] | 2500 | //Detect meta-characters (# ! ^ $ ( ) [ ] { } ? + * . \ -) for special pattern |
---|
| 2501 | if ($conf_CharExclusion[$i] == "#" |
---|
| 2502 | or $conf_CharExclusion[$i] == "$" |
---|
| 2503 | or $conf_CharExclusion[$i] == "!" |
---|
| 2504 | or $conf_CharExclusion[$i] == "^" |
---|
| 2505 | or $conf_CharExclusion[$i] == "*" |
---|
| 2506 | or $conf_CharExclusion[$i] == "?" |
---|
| 2507 | or $conf_CharExclusion[$i] == "+" |
---|
| 2508 | or $conf_CharExclusion[$i] == "." |
---|
| 2509 | or $conf_CharExclusion[$i] == "\\" |
---|
| 2510 | or $conf_CharExclusion[$i] == "|" |
---|
| 2511 | or $conf_CharExclusion[$i] == "[" |
---|
| 2512 | or $conf_CharExclusion[$i] == "]" |
---|
| 2513 | or $conf_CharExclusion[$i] == "(" |
---|
| 2514 | or $conf_CharExclusion[$i] == ")" |
---|
| 2515 | or $conf_CharExclusion[$i] == "{" |
---|
| 2516 | or $conf_CharExclusion[$i] == "}" |
---|
| 2517 | or $conf_CharExclusion[$i] == "-") |
---|
| 2518 | { |
---|
| 2519 | $pattern = '/[][^$.\*+?(){}#|-]/i'; |
---|
| 2520 | } |
---|
| 2521 | else |
---|
| 2522 | { |
---|
| 2523 | $pattern = '/'.$conf_CharExclusion[$i].'/i'; |
---|
| 2524 | } |
---|
[18152] | 2525 | |
---|
[5056] | 2526 | if (preg_match($pattern, $login)) |
---|
| 2527 | { |
---|
| 2528 | return true; |
---|
| 2529 | } |
---|
| 2530 | } |
---|
| 2531 | } |
---|
| 2532 | else |
---|
| 2533 | { |
---|
| 2534 | return false; |
---|
| 2535 | } |
---|
| 2536 | } |
---|
| 2537 | |
---|
[10144] | 2538 | |
---|
[7968] | 2539 | /** |
---|
| 2540 | * Function called from main.inc.php - Check if user's email is in excluded email providers list |
---|
| 2541 | * Doesn't work on call - Must be copied in main.inc.php to work |
---|
| 2542 | * |
---|
| 2543 | * @param : Email address |
---|
| 2544 | * |
---|
| 2545 | * @return : Bool |
---|
| 2546 | * |
---|
| 2547 | */ |
---|
[5056] | 2548 | function ValidateEmailProvider($email) |
---|
| 2549 | { |
---|
| 2550 | global $conf; |
---|
| 2551 | |
---|
[5181] | 2552 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 2553 | |
---|
[17944] | 2554 | if (isset($email) and isset($conf_UAM[11]) and $conf_UAM[11] <> '') |
---|
[17887] | 2555 | { |
---|
[17944] | 2556 | $conf_MailExclusion = preg_split("/[\s,]+/",$conf_UAM[11]); |
---|
| 2557 | for ($i = 0 ; $i < count($conf_MailExclusion) ; $i++) |
---|
| 2558 | { |
---|
| 2559 | $pattern = '/'.$conf_MailExclusion[$i].'/i'; |
---|
| 2560 | if (preg_match($pattern, $email)) |
---|
[5056] | 2561 | { |
---|
[17944] | 2562 | return true; |
---|
[5056] | 2563 | } |
---|
[17944] | 2564 | } |
---|
[17887] | 2565 | } |
---|
[5056] | 2566 | else |
---|
| 2567 | { |
---|
| 2568 | return false; |
---|
| 2569 | } |
---|
| 2570 | } |
---|
| 2571 | |
---|
[10144] | 2572 | |
---|
[7968] | 2573 | /** |
---|
| 2574 | * Function called from UAM_admin.php - Get unvalidated users according time limit |
---|
| 2575 | * |
---|
| 2576 | * @return : List of users |
---|
| 2577 | * |
---|
| 2578 | */ |
---|
[5056] | 2579 | function get_unvalid_user_list() |
---|
| 2580 | { |
---|
[17944] | 2581 | global $conf, $page; |
---|
[5056] | 2582 | |
---|
[17944] | 2583 | // Get ConfirmMail configuration |
---|
[12271] | 2584 | // ----------------------------- |
---|
[5181] | 2585 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[7968] | 2586 | // Get UAM configuration |
---|
[12271] | 2587 | // --------------------- |
---|
[5181] | 2588 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[5056] | 2589 | |
---|
| 2590 | $users = array(); |
---|
| 2591 | |
---|
[17944] | 2592 | // Search users depending expiration date |
---|
[12271] | 2593 | // -------------------------------------- |
---|
[5056] | 2594 | $query = ' |
---|
| 2595 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 2596 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 2597 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 2598 | ui.status, |
---|
| 2599 | ui.enabled_high, |
---|
| 2600 | ui.level, |
---|
| 2601 | ui.registration_date |
---|
| 2602 | FROM '.USERS_TABLE.' AS u |
---|
| 2603 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 2604 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 2605 | LEFT JOIN '.USER_GROUP_TABLE.' AS ug |
---|
| 2606 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
| 2607 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
| 2608 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'" |
---|
[17974] | 2609 | OR TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) < "'.$conf_UAM_ConfirmMail[1].'") |
---|
| 2610 | AND u.UAM_validated = "false" |
---|
[6399] | 2611 | ORDER BY ui.registration_date ASC |
---|
[5056] | 2612 | ;'; |
---|
| 2613 | |
---|
[17944] | 2614 | $result = pwg_query($query); |
---|
[5056] | 2615 | |
---|
[5633] | 2616 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 2617 | { |
---|
[17944] | 2618 | $user = $row; |
---|
[5056] | 2619 | $user['groups'] = array(); |
---|
| 2620 | |
---|
| 2621 | array_push($users, $user); |
---|
[17944] | 2622 | } |
---|
[5056] | 2623 | |
---|
[17944] | 2624 | // Add groups list |
---|
[12271] | 2625 | // --------------- |
---|
[5056] | 2626 | $user_ids = array(); |
---|
| 2627 | foreach ($users as $i => $user) |
---|
| 2628 | { |
---|
[17944] | 2629 | $user_ids[$i] = $user['id']; |
---|
| 2630 | } |
---|
[5056] | 2631 | |
---|
[17944] | 2632 | $user_nums = array_flip($user_ids); |
---|
| 2633 | |
---|
[5056] | 2634 | if (count($user_ids) > 0) |
---|
| 2635 | { |
---|
[17944] | 2636 | $query = ' |
---|
[5056] | 2637 | SELECT user_id, group_id |
---|
| 2638 | FROM '.USER_GROUP_TABLE.' |
---|
| 2639 | WHERE user_id IN ('.implode(',', $user_ids).') |
---|
| 2640 | ;'; |
---|
| 2641 | |
---|
[17944] | 2642 | $result = pwg_query($query); |
---|
[5056] | 2643 | |
---|
[5633] | 2644 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 2645 | { |
---|
[17944] | 2646 | array_push( |
---|
| 2647 | $users[$user_nums[$row['user_id']]]['groups'], |
---|
[5056] | 2648 | $row['group_id'] |
---|
[17944] | 2649 | ); |
---|
| 2650 | } |
---|
[17887] | 2651 | } |
---|
[5056] | 2652 | |
---|
[17944] | 2653 | return $users; |
---|
[5056] | 2654 | } |
---|
| 2655 | |
---|
[10144] | 2656 | |
---|
[7968] | 2657 | /** |
---|
[9266] | 2658 | * Function called from functions.inc.php - Get all users who haven't validate their registration in configured time |
---|
| 2659 | * to delete or remail them automatically |
---|
| 2660 | * |
---|
| 2661 | * @return : List of users |
---|
| 2662 | * |
---|
| 2663 | */ |
---|
| 2664 | function get_unvalid_user_autotasks() |
---|
| 2665 | { |
---|
[17944] | 2666 | global $conf, $page; |
---|
[9266] | 2667 | |
---|
[17944] | 2668 | // Get ConfirmMail configuration |
---|
[12271] | 2669 | // ----------------------------- |
---|
[9266] | 2670 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
| 2671 | |
---|
| 2672 | $users = array(); |
---|
| 2673 | |
---|
[17944] | 2674 | // search users depending expiration date |
---|
[12271] | 2675 | // -------------------------------------- |
---|
[9266] | 2676 | $query = ' |
---|
| 2677 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 2678 | ui.registration_date |
---|
| 2679 | FROM '.USERS_TABLE.' AS u |
---|
| 2680 | INNER JOIN '.USER_INFOS_TABLE.' AS ui |
---|
| 2681 | ON u.'.$conf['user_fields']['id'].' = ui.user_id |
---|
| 2682 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
| 2683 | AND (TO_DAYS(NOW()) - TO_DAYS(ui.registration_date) >= "'.$conf_UAM_ConfirmMail[1].'") |
---|
| 2684 | ORDER BY ui.registration_date ASC;'; |
---|
| 2685 | |
---|
[17944] | 2686 | $result = pwg_query($query); |
---|
| 2687 | |
---|
[9266] | 2688 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 2689 | { |
---|
| 2690 | array_push($users, $row); |
---|
[17944] | 2691 | } |
---|
[9266] | 2692 | |
---|
[17944] | 2693 | return $users; |
---|
[9266] | 2694 | } |
---|
| 2695 | |
---|
[10144] | 2696 | |
---|
[9266] | 2697 | /** |
---|
[7968] | 2698 | * Function called from UAM_admin.php - Get ghost users |
---|
| 2699 | * |
---|
| 2700 | * @return : List of users |
---|
| 2701 | * |
---|
| 2702 | */ |
---|
[5056] | 2703 | function get_ghost_user_list() |
---|
| 2704 | { |
---|
[17944] | 2705 | global $conf, $page; |
---|
[5056] | 2706 | |
---|
[5181] | 2707 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[17944] | 2708 | |
---|
[5056] | 2709 | $users = array(); |
---|
| 2710 | |
---|
[17944] | 2711 | // Search users depending expiration date |
---|
[12271] | 2712 | // -------------------------------------- |
---|
[5056] | 2713 | $query = ' |
---|
| 2714 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 2715 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 2716 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 2717 | lv.lastvisit, |
---|
| 2718 | lv.reminder |
---|
| 2719 | FROM '.USERS_TABLE.' AS u |
---|
| 2720 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
| 2721 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
[11018] | 2722 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[16].'") |
---|
[6399] | 2723 | ORDER BY lv.lastvisit ASC;'; |
---|
[5056] | 2724 | |
---|
[17944] | 2725 | $result = pwg_query($query); |
---|
[5056] | 2726 | |
---|
[5633] | 2727 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 2728 | { |
---|
[17944] | 2729 | $user = $row; |
---|
[5056] | 2730 | $user['groups'] = array(); |
---|
| 2731 | |
---|
| 2732 | array_push($users, $user); |
---|
[17944] | 2733 | } |
---|
[5056] | 2734 | |
---|
[17944] | 2735 | // Add groups list |
---|
[12271] | 2736 | // --------------- |
---|
[5056] | 2737 | $user_ids = array(); |
---|
| 2738 | foreach ($users as $i => $user) |
---|
| 2739 | { |
---|
[17887] | 2740 | $user_ids[$i] = $user['id']; |
---|
[17944] | 2741 | } |
---|
[5056] | 2742 | |
---|
[17944] | 2743 | return $users; |
---|
[5056] | 2744 | } |
---|
| 2745 | |
---|
[8065] | 2746 | |
---|
[7968] | 2747 | /** |
---|
[8065] | 2748 | * Function called from functions.inc.php - Get all ghost users to delete or downgrade automatically on any user login |
---|
| 2749 | * |
---|
| 2750 | * @return : List of users to delete or downgrade automatically |
---|
| 2751 | * |
---|
| 2752 | */ |
---|
| 2753 | function get_ghosts_autotasks() |
---|
| 2754 | { |
---|
[17944] | 2755 | global $conf, $page; |
---|
[8065] | 2756 | |
---|
| 2757 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
| 2758 | |
---|
| 2759 | $users = array(); |
---|
| 2760 | |
---|
[17944] | 2761 | // Search users depending expiration date and reminder sent |
---|
[12271] | 2762 | // -------------------------------------------------------- |
---|
[8065] | 2763 | $query = ' |
---|
| 2764 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
[8087] | 2765 | lv.lastvisit |
---|
[8065] | 2766 | FROM '.USERS_TABLE.' AS u |
---|
| 2767 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS lv |
---|
| 2768 | ON u.'.$conf['user_fields']['id'].' = lv.user_id |
---|
[11018] | 2769 | WHERE (TO_DAYS(NOW()) - TO_DAYS(lv.lastvisit) >= "'.$conf_UAM[16].'") |
---|
[8065] | 2770 | ORDER BY lv.lastvisit ASC;'; |
---|
| 2771 | |
---|
[17944] | 2772 | $result = pwg_query($query); |
---|
[8065] | 2773 | |
---|
[17944] | 2774 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[8065] | 2775 | { |
---|
[9266] | 2776 | array_push($users, $row); |
---|
[17944] | 2777 | } |
---|
[8065] | 2778 | |
---|
[17944] | 2779 | return $users; |
---|
[8065] | 2780 | } |
---|
| 2781 | |
---|
| 2782 | |
---|
| 2783 | /** |
---|
[7968] | 2784 | * Function called from UAM_admin.php - Get all users to display the number of days since their last visit |
---|
| 2785 | * |
---|
| 2786 | * @return : List of users |
---|
| 2787 | * |
---|
| 2788 | */ |
---|
[5056] | 2789 | function get_user_list() |
---|
| 2790 | { |
---|
[17944] | 2791 | global $conf, $page; |
---|
[5056] | 2792 | |
---|
| 2793 | $users = array(); |
---|
| 2794 | |
---|
[17944] | 2795 | // Search users depending expiration date with exclusion of Adult_Content generic users |
---|
[13528] | 2796 | // ------------------------------------------------------------------------------------ |
---|
[5056] | 2797 | $query = ' |
---|
| 2798 | SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id, |
---|
| 2799 | u.'.$conf['user_fields']['username'].' AS username, |
---|
| 2800 | u.'.$conf['user_fields']['email'].' AS email, |
---|
| 2801 | ug.lastvisit |
---|
| 2802 | FROM '.USERS_TABLE.' AS u |
---|
| 2803 | INNER JOIN '.USER_LASTVISIT_TABLE.' AS ug |
---|
| 2804 | ON u.'.$conf['user_fields']['id'].' = ug.user_id |
---|
| 2805 | WHERE u.'.$conf['user_fields']['id'].' >= 3 |
---|
[13528] | 2806 | AND u.username NOT LIKE "16" |
---|
| 2807 | AND u.username NOT LIKE "18" |
---|
[6399] | 2808 | ORDER BY ug.lastvisit DESC |
---|
[5056] | 2809 | ;'; |
---|
| 2810 | |
---|
[17944] | 2811 | $result = pwg_query($query); |
---|
[5056] | 2812 | |
---|
[5633] | 2813 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[5056] | 2814 | { |
---|
[17944] | 2815 | $user = $row; |
---|
[5056] | 2816 | $user['groups'] = array(); |
---|
| 2817 | |
---|
| 2818 | array_push($users, $user); |
---|
[17944] | 2819 | } |
---|
[5056] | 2820 | |
---|
[17944] | 2821 | // Add groups list |
---|
[12271] | 2822 | // --------------- |
---|
[5056] | 2823 | $user_ids = array(); |
---|
| 2824 | foreach ($users as $i => $user) |
---|
| 2825 | { |
---|
[17944] | 2826 | $user_ids[$i] = $user['id']; |
---|
| 2827 | } |
---|
[5056] | 2828 | |
---|
[17944] | 2829 | return $users; |
---|
[5056] | 2830 | } |
---|
| 2831 | |
---|
[10144] | 2832 | |
---|
[7968] | 2833 | /** |
---|
| 2834 | * Function called from UAM_admin.php - to determine who is expired or not and giving a different display color |
---|
| 2835 | * |
---|
| 2836 | * @param : user id |
---|
| 2837 | * |
---|
| 2838 | * @return : Bool |
---|
| 2839 | * |
---|
| 2840 | */ |
---|
[5056] | 2841 | function expiration($id) |
---|
| 2842 | { |
---|
[17887] | 2843 | global $conf, $page; |
---|
[5056] | 2844 | |
---|
[17944] | 2845 | // Get ConfirmMail configuration |
---|
[12271] | 2846 | // ----------------------------- |
---|
[5181] | 2847 | $conf_UAM_ConfirmMail = unserialize($conf['UserAdvManager_ConfirmMail']); |
---|
[5056] | 2848 | |
---|
[17944] | 2849 | // Get UAM configuration |
---|
[12271] | 2850 | // --------------------- |
---|
[5181] | 2851 | $conf_UAM = unserialize($conf['UserAdvManager']); |
---|
[17887] | 2852 | |
---|
[17944] | 2853 | $query = ' |
---|
[5056] | 2854 | SELECT registration_date |
---|
[17918] | 2855 | FROM '.USER_INFOS_TABLE.' |
---|
| 2856 | WHERE user_id = '.$id.' |
---|
| 2857 | ;'; |
---|
[17944] | 2858 | list($registration_date) = pwg_db_fetch_row(pwg_query($query)); |
---|
[5056] | 2859 | |
---|
[7968] | 2860 | // Time limit process |
---|
| 2861 | // ******************************************** |
---|
[17944] | 2862 | if (!empty($registration_date)) |
---|
[5056] | 2863 | { |
---|
[17944] | 2864 | // Dates formating and compare |
---|
| 2865 | // --------------------------- |
---|
| 2866 | $today = date("d-m-Y"); // Get today's date |
---|
| 2867 | list($day, $month, $year) = explode('-', $today); // explode date of today |
---|
| 2868 | $daytimestamp = mktime(0, 0, 0, $month, $day, $year);// Generate UNIX timestamp |
---|
[17887] | 2869 | |
---|
[17944] | 2870 | list($regdate, $regtime) = explode(' ', $registration_date); // Explode date and time from registration date |
---|
| 2871 | list($regyear, $regmonth, $regday) = explode('-', $regdate); // Explode date from registration date |
---|
| 2872 | $regtimestamp = mktime(0, 0, 0, $regmonth, $regday, $regyear);// Generate UNIX timestamp |
---|
[17887] | 2873 | |
---|
[17944] | 2874 | $deltasecs = $daytimestamp - $regtimestamp;// Compare the 2 UNIX timestamps |
---|
| 2875 | $deltadays = floor($deltasecs / 86400);// Convert result from seconds to days |
---|
[5056] | 2876 | |
---|
[17944] | 2877 | // Condition with the value set for time limit |
---|
[12271] | 2878 | // ------------------------------------------- |
---|
[17944] | 2879 | if ($deltadays <= $conf_UAM_ConfirmMail[1]) // If Nb of days is less than the limit set |
---|
| 2880 | { |
---|
| 2881 | return false; |
---|
| 2882 | } |
---|
| 2883 | else |
---|
| 2884 | { |
---|
| 2885 | return true; |
---|
| 2886 | } |
---|
[17887] | 2887 | } |
---|
[5056] | 2888 | } |
---|
| 2889 | |
---|
| 2890 | |
---|
| 2891 | /** |
---|
| 2892 | * Returns a password's score for password complexity check |
---|
| 2893 | * |
---|
[7968] | 2894 | * @param : password filled by user |
---|
[5056] | 2895 | * |
---|
[7968] | 2896 | * @return : Score calculation |
---|
| 2897 | * |
---|
[5056] | 2898 | * Thanx to MathieuGut from http://m-gut.developpez.com |
---|
| 2899 | */ |
---|
[17944] | 2900 | function testpassword($password) // $password given by user |
---|
[5056] | 2901 | { |
---|
| 2902 | |
---|
[17944] | 2903 | // Variables initiation |
---|
| 2904 | // -------------------- |
---|
[5056] | 2905 | $points = 0; |
---|
| 2906 | $point_lowercase = 0; |
---|
| 2907 | $point_uppercase = 0; |
---|
| 2908 | $point_numbers = 0; |
---|
| 2909 | $point_characters = 0; |
---|
| 2910 | |
---|
[17944] | 2911 | // Getting password lengh |
---|
| 2912 | // ---------------------- |
---|
[5056] | 2913 | $length = strlen($password); |
---|
[17944] | 2914 | |
---|
| 2915 | // Loop to read password characters |
---|
[5056] | 2916 | for($i = 0; $i < $length; $i++) |
---|
| 2917 | { |
---|
[17944] | 2918 | // Select each letters |
---|
| 2919 | // $i is 0 at first turn |
---|
| 2920 | // --------------------- |
---|
[5056] | 2921 | $letters = $password[$i]; |
---|
| 2922 | |
---|
| 2923 | if ($letters>='a' && $letters<='z') |
---|
| 2924 | { |
---|
[17944] | 2925 | // Adding 1 point to score for a lowercase |
---|
| 2926 | // --------------------------------------- |
---|
| 2927 | $points = $points + 1; |
---|
[5056] | 2928 | |
---|
[17944] | 2929 | // Adding bonus points for lowercase |
---|
| 2930 | // --------------------------------- |
---|
[17887] | 2931 | $point_lowercase = 1; |
---|
[5056] | 2932 | } |
---|
| 2933 | else if ($letters>='A' && $letters <='Z') |
---|
| 2934 | { |
---|
[17944] | 2935 | // Adding 2 points to score for uppercase |
---|
| 2936 | // -------------------------------------- |
---|
[5056] | 2937 | $points = $points + 2; |
---|
[17887] | 2938 | |
---|
[17944] | 2939 | // Adding bonus points for uppercase |
---|
| 2940 | // --------------------------------- |
---|
[5056] | 2941 | $point_uppercase = 2; |
---|
| 2942 | } |
---|
| 2943 | else if ($letters>='0' && $letters<='9') |
---|
| 2944 | { |
---|
[17944] | 2945 | // Adding 3 points to score for numbers |
---|
| 2946 | // ------------------------------------ |
---|
[5056] | 2947 | $points = $points + 3; |
---|
[17887] | 2948 | |
---|
[17944] | 2949 | // Adding bonus points for numbers |
---|
| 2950 | // ------------------------------- |
---|
[5056] | 2951 | $point_numbers = 3; |
---|
| 2952 | } |
---|
| 2953 | else |
---|
| 2954 | { |
---|
[17944] | 2955 | // Adding 5 points to score for special characters |
---|
| 2956 | // ----------------------------------------------- |
---|
[5056] | 2957 | $points = $points + 5; |
---|
[17887] | 2958 | |
---|
[17944] | 2959 | // Adding bonus points for special characters |
---|
| 2960 | // ------------------------------------------ |
---|
[5056] | 2961 | $point_characters = 5; |
---|
| 2962 | } |
---|
| 2963 | } |
---|
| 2964 | |
---|
[17944] | 2965 | // Calculating the coefficient points/length |
---|
| 2966 | // ----------------------------------------- |
---|
[5056] | 2967 | $step1 = $points / $length; |
---|
| 2968 | |
---|
[17944] | 2969 | // Calculation of the diversity of character types... |
---|
| 2970 | // -------------------------------------------------- |
---|
[5056] | 2971 | $step2 = $point_lowercase + $point_uppercase + $point_numbers + $point_characters; |
---|
| 2972 | |
---|
[17944] | 2973 | // Multiplying the coefficient of diversity with that of the length |
---|
| 2974 | // ---------------------------------------------------------------- |
---|
[5056] | 2975 | $score = $step1 * $step2; |
---|
| 2976 | |
---|
[17944] | 2977 | // Multiplying the result by the length of the string |
---|
| 2978 | // -------------------------------------------------- |
---|
[5056] | 2979 | $finalscore = $score * $length; |
---|
| 2980 | |
---|
| 2981 | return $finalscore; |
---|
| 2982 | } |
---|
| 2983 | |
---|
[10144] | 2984 | |
---|
[7968] | 2985 | /** |
---|
[8065] | 2986 | * UAM_check_profile - Thx to LucMorizur |
---|
[7968] | 2987 | * checks if a user id is registered as having already |
---|
[12661] | 2988 | * visited his profile page. |
---|
[7968] | 2989 | * |
---|
| 2990 | * @uid : the user id |
---|
| 2991 | * |
---|
| 2992 | * @user_idsOK : (returned) array of all users ids having already visited |
---|
| 2993 | * their profile.php pages |
---|
| 2994 | * |
---|
| 2995 | * @returns : true or false whether the users has already visited his |
---|
| 2996 | * profile.php page or not |
---|
| 2997 | * |
---|
| 2998 | */ |
---|
[8065] | 2999 | function UAM_check_profile($uid, &$user_idsOK) |
---|
[6775] | 3000 | { |
---|
| 3001 | $t = array(); |
---|
| 3002 | $v = false; |
---|
| 3003 | |
---|
[12239] | 3004 | $query = ' |
---|
[6775] | 3005 | SELECT value |
---|
[12239] | 3006 | FROM '.CONFIG_TABLE.' |
---|
| 3007 | WHERE param = "UserAdvManager_Redir" |
---|
| 3008 | ;'; |
---|
[6775] | 3009 | |
---|
| 3010 | if ($v = (($t = pwg_db_fetch_row(pwg_query($query))) !== false)) |
---|
| 3011 | { |
---|
| 3012 | $user_idsOK = explode(',', $t[0]); |
---|
| 3013 | $v = (in_array($uid, $user_idsOK)); |
---|
| 3014 | } |
---|
| 3015 | return $v; |
---|
| 3016 | } |
---|
[10144] | 3017 | |
---|
| 3018 | |
---|
| 3019 | /** |
---|
[12239] | 3020 | * UAM_check_pwdreset |
---|
| 3021 | * checks if a user id is registered as having already |
---|
[12661] | 3022 | * changed his password. |
---|
[12239] | 3023 | * |
---|
| 3024 | * @uid : the user id |
---|
| 3025 | * |
---|
| 3026 | * @returns : true or false whether the users has already changed his password |
---|
| 3027 | * |
---|
| 3028 | */ |
---|
| 3029 | function UAM_check_pwgreset($uid) |
---|
| 3030 | { |
---|
| 3031 | $query = ' |
---|
| 3032 | SELECT UAM_pwdreset |
---|
| 3033 | FROM '.USERS_TABLE.' |
---|
| 3034 | WHERE id='.$uid.' |
---|
| 3035 | ;'; |
---|
| 3036 | |
---|
| 3037 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 3038 | |
---|
| 3039 | if($result['UAM_pwdreset'] == 'true') |
---|
| 3040 | { |
---|
| 3041 | return true; |
---|
| 3042 | } |
---|
| 3043 | else return false; |
---|
| 3044 | } |
---|
| 3045 | |
---|
[12661] | 3046 | |
---|
[12239] | 3047 | /** |
---|
[12661] | 3048 | * UAM_UsrReg_Verif |
---|
| 3049 | * Check if the user who logged-in have validate his registration |
---|
| 3050 | * |
---|
| 3051 | * @returns : True if validation is OK else False |
---|
| 3052 | */ |
---|
| 3053 | function UAM_UsrReg_Verif($user_id) |
---|
| 3054 | { |
---|
| 3055 | global $conf; |
---|
| 3056 | |
---|
| 3057 | $query = ' |
---|
[17887] | 3058 | SELECT UAM_validated |
---|
| 3059 | FROM '.USERS_TABLE.' |
---|
| 3060 | WHERE id='.$user_id.' |
---|
[12661] | 3061 | ;'; |
---|
| 3062 | |
---|
[17887] | 3063 | $result = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[17846] | 3064 | |
---|
[17887] | 3065 | if($result['UAM_validated'] == 'true') |
---|
[12661] | 3066 | { |
---|
[17887] | 3067 | return true; |
---|
[12661] | 3068 | } |
---|
[17887] | 3069 | else return false; |
---|
[12661] | 3070 | } |
---|
| 3071 | |
---|
| 3072 | |
---|
| 3073 | /** |
---|
[17918] | 3074 | * SetUnvalidated |
---|
| 3075 | * Set UAM_validated field to false in #_users table |
---|
| 3076 | * |
---|
| 3077 | **/ |
---|
| 3078 | function SetUnvalidated($user_id) |
---|
| 3079 | { |
---|
| 3080 | $query =' |
---|
| 3081 | UPDATE '.USERS_TABLE.' |
---|
| 3082 | SET UAM_validated = "false" |
---|
| 3083 | WHERE id = '.$user_id.' |
---|
| 3084 | LIMIT 1 |
---|
| 3085 | ;'; |
---|
| 3086 | |
---|
| 3087 | pwg_query($query); |
---|
| 3088 | } |
---|
| 3089 | |
---|
| 3090 | |
---|
| 3091 | /** |
---|
[12239] | 3092 | * UAM_Set_PwdReset |
---|
| 3093 | * Action in user_list to set a password reset for a user |
---|
| 3094 | */ |
---|
| 3095 | function UAM_Set_PwdReset($uid) |
---|
| 3096 | { |
---|
| 3097 | $query =' |
---|
| 3098 | UPDATE '.USERS_TABLE.' |
---|
| 3099 | SET UAM_pwdreset = "true" |
---|
| 3100 | WHERE id = '.$uid.' |
---|
| 3101 | LIMIT 1 |
---|
| 3102 | ;'; |
---|
| 3103 | |
---|
| 3104 | pwg_query($query); |
---|
| 3105 | } |
---|
| 3106 | |
---|
| 3107 | |
---|
| 3108 | /** |
---|
| 3109 | * UAM_loc_visible_user_list |
---|
| 3110 | * Adds a new feature in user_list to allow password reset for selected users by admin |
---|
| 3111 | * |
---|
| 3112 | */ |
---|
| 3113 | function UAM_loc_visible_user_list($visible_user_list) |
---|
| 3114 | { |
---|
| 3115 | global $template; |
---|
| 3116 | |
---|
| 3117 | $template->append('plugin_user_list_column_titles', l10n('UAM_PwdReset')); |
---|
| 3118 | |
---|
| 3119 | $user_ids = array(); |
---|
| 3120 | |
---|
| 3121 | foreach ($visible_user_list as $i => $user) |
---|
| 3122 | { |
---|
| 3123 | $user_ids[$i] = $user['id']; |
---|
| 3124 | } |
---|
| 3125 | |
---|
| 3126 | $user_nums = array_flip($user_ids); |
---|
| 3127 | |
---|
| 3128 | // Query to get informations in database |
---|
[12271] | 3129 | // ------------------------------------- |
---|
[12239] | 3130 | if (!empty($user_ids)) |
---|
| 3131 | { |
---|
| 3132 | $query = ' |
---|
| 3133 | SELECT DISTINCT id, UAM_pwdreset |
---|
| 3134 | FROM '.USERS_TABLE.' |
---|
| 3135 | WHERE id IN ('.implode(',', $user_ids).') |
---|
| 3136 | ;'; |
---|
| 3137 | $result = pwg_query($query); |
---|
| 3138 | |
---|
| 3139 | while ($row = mysql_fetch_array($result)) |
---|
| 3140 | { |
---|
| 3141 | if ($row['UAM_pwdreset'] == 'false') |
---|
| 3142 | { |
---|
| 3143 | $pwdreset = l10n('UAM_PwdReset_Done'); |
---|
| 3144 | } |
---|
| 3145 | else if ($row['UAM_pwdreset'] == 'true') |
---|
| 3146 | { |
---|
| 3147 | $pwdreset = l10n('UAM_PwdReset_Todo'); |
---|
| 3148 | } |
---|
| 3149 | else $pwdreset = l10n('UAM_PwdReset_NA'); |
---|
| 3150 | |
---|
[17887] | 3151 | $visible_user_list[$user_nums[$row['id']]]['plugin_columns'][] = $pwdreset; // Shows users password state in user_list |
---|
[12239] | 3152 | } |
---|
| 3153 | } |
---|
| 3154 | return $visible_user_list; |
---|
| 3155 | } |
---|
| 3156 | |
---|
| 3157 | |
---|
| 3158 | /** |
---|
[10342] | 3159 | * UAM specific database dump (only for MySql !) |
---|
| 3160 | * Creates an SQL dump of UAM specific tables and configuration settings |
---|
| 3161 | * |
---|
| 3162 | * @returns : Boolean to manage appropriate message display |
---|
| 3163 | * |
---|
| 3164 | */ |
---|
[12239] | 3165 | function UAM_dump($download) |
---|
[10342] | 3166 | { |
---|
| 3167 | global $conf; |
---|
[12314] | 3168 | |
---|
| 3169 | $plugin = PluginInfos(UAM_PATH); |
---|
| 3170 | $version = $plugin['version']; |
---|
| 3171 | |
---|
[10342] | 3172 | // Initial backup folder creation and file initialisation |
---|
[12271] | 3173 | // ------------------------------------------------------ |
---|
[10342] | 3174 | if (!is_dir(UAM_PATH.'/include/backup')) |
---|
| 3175 | mkdir(UAM_PATH.'/include/backup'); |
---|
| 3176 | |
---|
| 3177 | $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql'; |
---|
| 3178 | |
---|
| 3179 | $fp = fopen($Backup_File, 'w'); |
---|
| 3180 | |
---|
[12314] | 3181 | // Writing plugin version |
---|
| 3182 | $insertions = "-- ".$version." --\n\n"; |
---|
| 3183 | fwrite($fp, $insertions); |
---|
[10342] | 3184 | |
---|
| 3185 | // Saving UAM specific tables |
---|
[12271] | 3186 | // -------------------------- |
---|
[10342] | 3187 | $ListTables = array(USER_CONFIRM_MAIL_TABLE, USER_LASTVISIT_TABLE); |
---|
| 3188 | $j=0; |
---|
[17944] | 3189 | |
---|
[10342] | 3190 | while($j < count($ListTables)) |
---|
| 3191 | { |
---|
| 3192 | $sql = 'SHOW CREATE TABLE '.$ListTables[$j]; |
---|
| 3193 | $res = pwg_query($sql); |
---|
| 3194 | |
---|
| 3195 | if ($res) |
---|
| 3196 | { |
---|
| 3197 | $insertions = "-- -------------------------------------------------------\n"; |
---|
| 3198 | $insertions .= "-- Create ".$ListTables[$j]." table\n"; |
---|
| 3199 | $insertions .= "-- ------------------------------------------------------\n\n"; |
---|
| 3200 | |
---|
| 3201 | $insertions .= "DROP TABLE IF EXISTS ".$ListTables[$j].";\n\n"; |
---|
| 3202 | |
---|
| 3203 | $array = mysql_fetch_array($res); |
---|
| 3204 | $array[1] .= ";\n\n"; |
---|
| 3205 | $insertions .= $array[1]; |
---|
| 3206 | |
---|
| 3207 | $req_table = pwg_query('SELECT * FROM '.$ListTables[$j]) or die(mysql_error()); |
---|
| 3208 | $nb_fields = mysql_num_fields($req_table); |
---|
| 3209 | while ($line = mysql_fetch_array($req_table)) |
---|
| 3210 | { |
---|
| 3211 | $insertions .= 'INSERT INTO '.$ListTables[$j].' VALUES ('; |
---|
| 3212 | for ($i=0; $i<$nb_fields; $i++) |
---|
| 3213 | { |
---|
[12275] | 3214 | $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; |
---|
[10342] | 3215 | } |
---|
| 3216 | $insertions = substr($insertions, 0, -2); |
---|
| 3217 | $insertions .= ");\n"; |
---|
| 3218 | } |
---|
| 3219 | $insertions .= "\n\n"; |
---|
| 3220 | } |
---|
| 3221 | |
---|
| 3222 | fwrite($fp, $insertions); |
---|
| 3223 | $j++; |
---|
| 3224 | } |
---|
| 3225 | |
---|
| 3226 | // Saving UAM configuration |
---|
[12271] | 3227 | // ------------------------ |
---|
[10342] | 3228 | $insertions = "-- -------------------------------------------------------\n"; |
---|
| 3229 | $insertions .= "-- Insert UAM configuration in ".CONFIG_TABLE."\n"; |
---|
| 3230 | $insertions .= "-- ------------------------------------------------------\n\n"; |
---|
| 3231 | |
---|
| 3232 | fwrite($fp, $insertions); |
---|
| 3233 | |
---|
| 3234 | $pattern = "UserAdvManager%"; |
---|
| 3235 | $req_table = pwg_query('SELECT * FROM '.CONFIG_TABLE.' WHERE param LIKE "'.$pattern.'";') or die(mysql_error()); |
---|
| 3236 | $nb_fields = mysql_num_fields($req_table); |
---|
| 3237 | |
---|
| 3238 | while ($line = mysql_fetch_array($req_table)) |
---|
| 3239 | { |
---|
| 3240 | $insertions = 'INSERT INTO '.CONFIG_TABLE.' VALUES ('; |
---|
| 3241 | for ($i=0; $i<$nb_fields; $i++) |
---|
| 3242 | { |
---|
[12275] | 3243 | $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', '; |
---|
[10342] | 3244 | } |
---|
| 3245 | $insertions = substr($insertions, 0, -2); |
---|
| 3246 | $insertions .= ");\n"; |
---|
| 3247 | |
---|
| 3248 | fwrite($fp, $insertions); |
---|
| 3249 | } |
---|
| 3250 | |
---|
| 3251 | fclose($fp); |
---|
| 3252 | |
---|
| 3253 | // Download generated dump file |
---|
[12271] | 3254 | // ---------------------------- |
---|
[10342] | 3255 | if ($download == 'true') |
---|
| 3256 | { |
---|
| 3257 | if (@filesize($Backup_File)) |
---|
| 3258 | { |
---|
| 3259 | $http_headers = array( |
---|
| 3260 | 'Content-Length: '.@filesize($Backup_File), |
---|
| 3261 | 'Content-Type: text/x-sql', |
---|
| 3262 | 'Content-Disposition: attachment; filename="UAM_dbbackup.sql";', |
---|
| 3263 | 'Content-Transfer-Encoding: binary', |
---|
| 3264 | ); |
---|
| 3265 | |
---|
| 3266 | foreach ($http_headers as $header) |
---|
| 3267 | { |
---|
| 3268 | header($header); |
---|
| 3269 | } |
---|
| 3270 | |
---|
| 3271 | @readfile($Backup_File); |
---|
| 3272 | exit(); |
---|
| 3273 | } |
---|
| 3274 | } |
---|
| 3275 | |
---|
| 3276 | return true; |
---|
| 3277 | } |
---|
| 3278 | |
---|
| 3279 | |
---|
| 3280 | /** |
---|
[12275] | 3281 | * UAM_Restore_backup_file |
---|
| 3282 | * Restore backup database file |
---|
| 3283 | * |
---|
| 3284 | * @returns : Boolean |
---|
| 3285 | */ |
---|
| 3286 | function UAM_Restore_backup_file() |
---|
| 3287 | { |
---|
| 3288 | global $prefixeTable, $dblayer, $conf; |
---|
| 3289 | |
---|
| 3290 | define('DEFAULT_PREFIX_TABLE', 'piwigo_'); |
---|
| 3291 | |
---|
| 3292 | $Backup_File = UAM_PATH.'/include/backup/UAM_dbbackup.sql'; |
---|
| 3293 | |
---|
| 3294 | // Cleanup database before restoring |
---|
| 3295 | // --------------------------------- |
---|
| 3296 | |
---|
| 3297 | // Delete UserAdvManager global config in #_config table |
---|
| 3298 | $q = ' |
---|
| 3299 | DELETE FROM '.CONFIG_TABLE.' |
---|
| 3300 | WHERE param="UserAdvManager" |
---|
| 3301 | ;'; |
---|
| 3302 | |
---|
| 3303 | pwg_query($q); |
---|
| 3304 | |
---|
| 3305 | // Delete UserAdvManager_ConfirmMail global config in #_config table |
---|
| 3306 | $q = ' |
---|
| 3307 | DELETE FROM '.CONFIG_TABLE.' |
---|
| 3308 | WHERE param="UserAdvManager_ConfirmMail" |
---|
| 3309 | ;'; |
---|
| 3310 | |
---|
| 3311 | pwg_query($q); |
---|
| 3312 | |
---|
| 3313 | // Delete UserAdvManager_Redir config in #_config table |
---|
| 3314 | $q = ' |
---|
| 3315 | DELETE FROM '.CONFIG_TABLE.' |
---|
| 3316 | WHERE param="UserAdvManager_Redir" |
---|
| 3317 | ;'; |
---|
| 3318 | |
---|
| 3319 | pwg_query($q); |
---|
| 3320 | |
---|
| 3321 | // Delete UserAdvManager_Version config in #_config table |
---|
| 3322 | $q = ' |
---|
| 3323 | DELETE FROM '.CONFIG_TABLE.' |
---|
| 3324 | WHERE param="UserAdvManager_Version" |
---|
| 3325 | ;'; |
---|
| 3326 | |
---|
| 3327 | pwg_query($q); |
---|
| 3328 | |
---|
| 3329 | // Restore sql backup file - DROP TABLE queries are executed |
---|
| 3330 | // --------------------------------------------------------- |
---|
| 3331 | UAM_execute_sqlfile( |
---|
| 3332 | $Backup_File, |
---|
| 3333 | DEFAULT_PREFIX_TABLE, |
---|
| 3334 | $prefixeTable, |
---|
| 3335 | $dblayer |
---|
| 3336 | ); |
---|
| 3337 | } |
---|
| 3338 | |
---|
| 3339 | |
---|
| 3340 | /** |
---|
| 3341 | * loads an sql file and executes all queries / Based on Piwigo's original install file |
---|
| 3342 | * |
---|
| 3343 | * Before executing a query, $replaced is... replaced by $replacing. This is |
---|
| 3344 | * useful when the SQL file contains generic words. |
---|
| 3345 | * |
---|
| 3346 | * @param string filepath |
---|
| 3347 | * @param string replaced |
---|
| 3348 | * @param string replacing |
---|
| 3349 | * @return void |
---|
| 3350 | */ |
---|
| 3351 | function UAM_execute_sqlfile($filepath, $replaced, $replacing, $dblayer) |
---|
| 3352 | { |
---|
| 3353 | $sql_lines = file($filepath); |
---|
| 3354 | $query = ''; |
---|
| 3355 | foreach ($sql_lines as $sql_line) |
---|
| 3356 | { |
---|
| 3357 | $sql_line = trim($sql_line); |
---|
| 3358 | if (preg_match('/(^--|^$)/', $sql_line)) |
---|
| 3359 | { |
---|
| 3360 | continue; |
---|
| 3361 | } |
---|
| 3362 | |
---|
| 3363 | $query.= ' '.$sql_line; |
---|
| 3364 | |
---|
| 3365 | // if we reached the end of query, we execute it and reinitialize the |
---|
| 3366 | // variable "query" |
---|
| 3367 | if (preg_match('/;$/', $sql_line)) |
---|
| 3368 | { |
---|
| 3369 | $query = trim($query); |
---|
| 3370 | $query = str_replace($replaced, $replacing, $query); |
---|
| 3371 | if ('mysql' == $dblayer) |
---|
| 3372 | { |
---|
| 3373 | if (preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches)) |
---|
| 3374 | { |
---|
| 3375 | $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';'; |
---|
| 3376 | } |
---|
| 3377 | } |
---|
| 3378 | pwg_query($query); |
---|
| 3379 | $query = ''; |
---|
| 3380 | } |
---|
| 3381 | } |
---|
| 3382 | } |
---|
| 3383 | |
---|
| 3384 | |
---|
[12661] | 3385 | /** |
---|
| 3386 | * Delete obsolete files on plugin upgrade |
---|
| 3387 | * Obsolete files are listed in file obsolete.list |
---|
| 3388 | * |
---|
| 3389 | */ |
---|
| 3390 | function clean_obsolete_files() |
---|
| 3391 | { |
---|
| 3392 | if (file_exists(UAM_PATH.'obsolete.list') |
---|
| 3393 | and $old_files = file(UAM_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES) |
---|
| 3394 | and !empty($old_files)) |
---|
| 3395 | { |
---|
| 3396 | array_push($old_files, 'obsolete.list'); |
---|
| 3397 | foreach($old_files as $old_file) |
---|
| 3398 | { |
---|
| 3399 | $path = UAM_PATH.$old_file; |
---|
| 3400 | if (is_file($path)) |
---|
| 3401 | { |
---|
| 3402 | @unlink($path); |
---|
| 3403 | } |
---|
| 3404 | elseif (is_dir($path)) |
---|
| 3405 | { |
---|
| 3406 | @rmdir($path); |
---|
| 3407 | } |
---|
| 3408 | } |
---|
| 3409 | } |
---|
| 3410 | } |
---|
[12275] | 3411 | |
---|
[12661] | 3412 | |
---|
[12275] | 3413 | /** |
---|
[12661] | 3414 | * Function called from maintain.inc.php - to check if database upgrade is needed |
---|
| 3415 | * |
---|
| 3416 | * @param : table name |
---|
| 3417 | * |
---|
| 3418 | * @return : boolean |
---|
| 3419 | * |
---|
| 3420 | */ |
---|
| 3421 | function table_exist($table) |
---|
| 3422 | { |
---|
| 3423 | $query = 'DESC '.$table.';'; |
---|
| 3424 | return (bool)($res=pwg_query($query)); |
---|
| 3425 | } |
---|
| 3426 | |
---|
| 3427 | |
---|
| 3428 | /** |
---|
| 3429 | * Function called from UAM_admin.php and main.inc.php to get the plugin version and name |
---|
| 3430 | * |
---|
| 3431 | * @param : plugin directory |
---|
| 3432 | * |
---|
| 3433 | * @return : plugin's version and name |
---|
| 3434 | * |
---|
| 3435 | */ |
---|
| 3436 | function PluginInfos($dir) |
---|
| 3437 | { |
---|
| 3438 | $path = $dir; |
---|
| 3439 | |
---|
| 3440 | $plg_data = implode( '', file($path.'main.inc.php') ); |
---|
| 3441 | if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) ) |
---|
| 3442 | { |
---|
| 3443 | $plugin['name'] = trim( $val[1] ); |
---|
| 3444 | } |
---|
| 3445 | if (preg_match("|Version: (.*)|", $plg_data, $val)) |
---|
| 3446 | { |
---|
| 3447 | $plugin['version'] = trim($val[1]); |
---|
| 3448 | } |
---|
| 3449 | if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) ) |
---|
| 3450 | { |
---|
| 3451 | $plugin['uri'] = trim($val[1]); |
---|
| 3452 | } |
---|
| 3453 | if ($desc = load_language('description.txt', $path.'/', array('return' => true))) |
---|
| 3454 | { |
---|
| 3455 | $plugin['description'] = trim($desc); |
---|
| 3456 | } |
---|
| 3457 | elseif ( preg_match("|Description: (.*)|", $plg_data, $val) ) |
---|
| 3458 | { |
---|
| 3459 | $plugin['description'] = trim($val[1]); |
---|
| 3460 | } |
---|
| 3461 | if ( preg_match("|Author: (.*)|", $plg_data, $val) ) |
---|
| 3462 | { |
---|
| 3463 | $plugin['author'] = trim($val[1]); |
---|
| 3464 | } |
---|
| 3465 | if ( preg_match("|Author URI: (.*)|", $plg_data, $val) ) |
---|
| 3466 | { |
---|
| 3467 | $plugin['author uri'] = trim($val[1]); |
---|
| 3468 | } |
---|
| 3469 | if (!empty($plugin['uri']) and strpos($plugin['uri'] , 'extension_view.php?eid=')) |
---|
| 3470 | { |
---|
| 3471 | list( , $extension) = explode('extension_view.php?eid=', $plugin['uri']); |
---|
| 3472 | if (is_numeric($extension)) $plugin['extension'] = $extension; |
---|
| 3473 | } |
---|
| 3474 | // IMPORTANT SECURITY ! |
---|
| 3475 | // -------------------- |
---|
| 3476 | $plugin = array_map('htmlspecialchars', $plugin); |
---|
| 3477 | |
---|
| 3478 | return $plugin ; |
---|
| 3479 | } |
---|
| 3480 | |
---|
| 3481 | |
---|
| 3482 | /** |
---|
[10144] | 3483 | * Useful for debugging - 4 vars can be set |
---|
| 3484 | * Output result to log.txt file |
---|
| 3485 | * |
---|
| 3486 | */ |
---|
| 3487 | function UAMLog($var1, $var2, $var3, $var4) |
---|
| 3488 | { |
---|
| 3489 | $fo=fopen (UAM_PATH.'log.txt','a') ; |
---|
| 3490 | fwrite($fo,"======================\n") ; |
---|
| 3491 | fwrite($fo,'le ' . date('D, d M Y H:i:s') . "\r\n"); |
---|
| 3492 | fwrite($fo,$var1 ."\r\n") ; |
---|
| 3493 | fwrite($fo,$var2 ."\r\n") ; |
---|
| 3494 | fwrite($fo,$var3 ."\r\n") ; |
---|
| 3495 | fwrite($fo,$var4 ."\r\n") ; |
---|
| 3496 | fclose($fo) ; |
---|
| 3497 | } |
---|
[17969] | 3498 | |
---|
[5056] | 3499 | ?> |
---|