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