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