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