PageRenderTime 36ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/adm/admin_prune_users.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 141 lines | 86 code | 22 blank | 33 comment | 6 complexity | 2a573e042651c768bea0b984a882450e MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Niels (ncr@db9.dk)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if(!empty($setmodules))
  18. {
  19. $filename = basename(__FILE__);
  20. //$module['Users'][$lang['Prune_users']] = $filename;
  21. $module['1610_Users']['190_Prune_users'] = $filename;
  22. return;
  23. }
  24. // Load default header
  25. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './../');
  26. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  27. $no_page_header = true;
  28. require('pagestart.' . PHP_EXT);
  29. // ********************************************************************************
  30. // from here you can define you own delete criterias, if you makes more, then you shall also
  31. // edit the files lang_main.php, and the file delete_users.php, so they hold the same amount
  32. // of options
  33. $sql_up = array();
  34. $default = array();
  35. // Initial selection
  36. // Zero posters
  37. $default[0] = 180;
  38. $sql_up[0] = ' AND user_posts = \'0\'';
  39. // Users who have never logged in
  40. $default[1] = 180;
  41. $sql_up[1] = ' AND user_lastvisit = \'0\'';
  42. // Not activated users
  43. $default[2] = 180;
  44. $sql_up[2] = ' AND user_lastvisit = \'0\' AND user_active = \'0\'';
  45. //$sql_up[2] = ' AND user_active = \'0\'';
  46. // Users not visiting since 60 days
  47. $default[3] = 180;
  48. $sql_up[3] = ' AND user_lastvisit < ' . (time() - (86400 * 60));
  49. // Users with less than 0.1 posts per day avg.
  50. $default[4] = 360;
  51. $sql_up[4] = ' AND user_posts / ((user_lastvisit - user_regdate) / 86400) < "0.1"';
  52. // Zero posters not visiting
  53. $default[5] = 180;
  54. $sql_up[5] = ' AND user_posts = \'0\' AND user_lastvisit < ' . (time() - (86400 * $default[5]));
  55. // ********************************************************************************
  56. // ****************** Do not change any thing below *******************************
  57. $options = '<option value="1">&nbsp;' . $lang['1_DAY'] . '</option>
  58. <option value="7">&nbsp;' . $lang['7_DAYS'] . '</option>
  59. <option value="14">&nbsp;' . $lang['2_WEEKS'] . '</option>
  60. <option value="21">&nbsp;' . sprintf($lang['X_WEEKS'], 3) . '</option>
  61. <option value="30">&nbsp;' . $lang['1_MONTH'] . '</option>
  62. <option value="60">&nbsp;' . sprintf($lang['X_MONTHS'], 2) . '</option>
  63. <option value="90">&nbsp;' . $lang['3_MONTHS'] . '</option>
  64. <option value="180">&nbsp;' . $lang['6_MONTHS'] . '</option>
  65. <option value="365">&nbsp;' . $lang['1_YEAR'] . '</option>
  66. </select>';
  67. // Generate page
  68. include('page_header_admin.' . PHP_EXT);
  69. $template->set_filenames(array('body' => ADM_TPL . 'prune_users_body.tpl'));
  70. $n = 0;
  71. while (!empty($sql_up[$n]))
  72. {
  73. $vars = 'days_' . $n;
  74. $default [$n] = ($default[$n]) ? $default[$n] : 10;
  75. $days [$n] = isset($_GET[$vars]) ? $_GET[$vars] : (isset($_POST[$vars]) ? intval($_POST[$vars]) : $default[$n]);
  76. // make a extra option if the parsed days value does not already exisit
  77. if (!strpos($options, 'value="' . $days[$n]))
  78. {
  79. $options = '<option value="' . $days[$n] . '">&nbsp;' . sprintf($lang['X_DAYS'], $days[$n]) . '</option>' . $options;
  80. }
  81. $select[$n] = '<select name="days_' . $n . '" size="1" onchange="SetDays();" class="gensmall">' . str_replace('value="' . $days[$n] . '">&nbsp;', 'value="' . $days[$n] . '" selected="selected">&nbsp;*', $options);
  82. $sql_full = "SELECT user_id , username, user_active, user_color, user_level
  83. FROM " . USERS_TABLE . "
  84. WHERE user_id <> '" . ANONYMOUS . "'
  85. " . $sql_up[$n] . "
  86. AND user_regdate < '" . (time() - (86400 * $days[$n])) . "'
  87. ORDER BY username LIMIT 800";
  88. $result = $db->sql_query($sql_full);
  89. $user_list = $db->sql_fetchrowset($result);
  90. $user_count = sizeof($user_list);
  91. for($i = 0; $i < $user_count; $i++)
  92. {
  93. $list[$n] .= ' ' . colorize_username($user_list[$i]['user_id'], $user_list[$i]['username'], $user_list[$i]['user_color'], $user_list[$i]['user_active']);
  94. }
  95. $db->sql_freeresult($result);
  96. $template->assign_block_vars('prune_list', array(
  97. 'LIST' => ($list[$n]) ? $list[$n] : $lang['None'],
  98. 'USER_COUNT' => $user_count,
  99. 'L_PRUNE' => $lang['Prune_commands'][$n],
  100. 'L_PRUNE_EXPLAIN' => sprintf($lang['Prune_explain'][$n], $days[$n]),
  101. 'S_PRUNE_USERS' => append_sid('admin_prune_users.' . PHP_EXT),
  102. 'S_DAYS' => $select[$n],
  103. //'U_PRUNE' => '<a href="' . append_sid(IP_ROOT_PATH . 'delete_users.' . PHP_EXT . '?mode=prune_' . $n . '&amp;days=' . $days[$n]) . '" onclick="return confirm(\'' . sprintf($lang['Prune_on_click'], $user_count) . '\')">' . $lang['Prune_commands'][$n] . '</a>',
  104. 'U_PRUNE' => '<a href="' . append_sid(IP_ROOT_PATH . ADM . '/admin_prune_users_loop.' . PHP_EXT . '?mode=prune_' . $n . '&amp;days=' . $days[$n]) . '" onclick="return confirm(\'' . sprintf($lang['Prune_on_click'], $user_count) . '\')">' . $lang['Prune_commands'][$n] . '</a>',
  105. )
  106. );
  107. $n++;
  108. }
  109. $template->assign_vars(array(
  110. 'L_PRUNE_ACTION' => $lang['Prune_Action'],
  111. 'L_PRUNE_LIST' => $lang['Prune_user_list'],
  112. 'L_DAYS' => $lang['Days'],
  113. 'L_PRUNE_USERS' => $lang['Prune_users'],
  114. 'L_PRUNE_USERS_EXPLAIN' => $lang['Prune_users_explain'],
  115. )
  116. );
  117. $template->pparse('body');
  118. include('page_footer_admin.' . PHP_EXT);
  119. ?>