[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/acp/ -> acp_inactive.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package acp
   5  * @version $Id$
   6  * @copyright (c) 2006 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  if (!defined('IN_PHPBB'))
  15  {
  16      exit;
  17  }
  18  
  19  /**
  20  * @package acp
  21  */
  22  class acp_inactive
  23  {
  24      var $u_action;
  25      var $p_master;
  26  
  27  	function acp_inactive(&$p_master)
  28      {
  29          $this->p_master = &$p_master;
  30      }
  31  
  32  	function main($id, $mode)
  33      {
  34          global $config, $db, $user, $auth, $template;
  35          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
  36  
  37          include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  38  
  39          $user->add_lang('memberlist');
  40  
  41          $action = request_var('action', '');
  42          $mark    = (isset($_REQUEST['mark'])) ? request_var('mark', array(0)) : array();
  43          $start    = request_var('start', 0);
  44          $submit = isset($_POST['submit']);
  45  
  46          // Sort keys
  47          $sort_days    = request_var('st', 0);
  48          $sort_key    = request_var('sk', 'i');
  49          $sort_dir    = request_var('sd', 'd');
  50  
  51          $form_key = 'acp_inactive';
  52          add_form_key($form_key);
  53  
  54          // We build the sort key and per page settings here, because they may be needed later
  55  
  56          // Number of entries to display
  57          $per_page = request_var('users_per_page', (int) $config['topics_per_page']);
  58  
  59          // Sorting
  60          $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  61          $sort_by_text = array('i' => $user->lang['SORT_INACTIVE'], 'j' => $user->lang['SORT_REG_DATE'], 'l' => $user->lang['SORT_LAST_VISIT'], 'd' => $user->lang['SORT_LAST_REMINDER'], 'r' => $user->lang['SORT_REASON'], 'u' => $user->lang['SORT_USERNAME'], 'p' => $user->lang['SORT_POSTS'], 'e' => $user->lang['SORT_REMINDER']);
  62          $sort_by_sql = array('i' => 'user_inactive_time', 'j' => 'user_regdate', 'l' => 'user_lastvisit', 'd' => 'user_reminded_time', 'r' => 'user_inactive_reason', 'u' => 'username_clean', 'p' => 'user_posts', 'e' => 'user_reminded');
  63  
  64          $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  65          gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
  66  
  67          if ($submit && sizeof($mark))
  68          {
  69              if ($action !== 'delete' && !check_form_key($form_key))
  70              {
  71                  trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  72              }
  73  
  74              switch ($action)
  75              {
  76                  case 'activate':
  77                  case 'delete':
  78  
  79                      $sql = 'SELECT user_id, username
  80                          FROM ' . USERS_TABLE . '
  81                          WHERE ' . $db->sql_in_set('user_id', $mark);
  82                      $result = $db->sql_query($sql);
  83  
  84                      $user_affected = array();
  85                      while ($row = $db->sql_fetchrow($result))
  86                      {
  87                          $user_affected[$row['user_id']] = $row['username'];
  88                      }
  89                      $db->sql_freeresult($result);
  90  
  91                      if ($action == 'activate')
  92                      {
  93                          // Get those 'being activated'...
  94                          $sql = 'SELECT user_id, username' . (($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ', user_email, user_lang' : '') . '
  95                              FROM ' . USERS_TABLE . '
  96                              WHERE ' . $db->sql_in_set('user_id', $mark) . '
  97                                  AND user_type = ' . USER_INACTIVE;
  98                          $result = $db->sql_query($sql);
  99  
 100                          $inactive_users = array();
 101                          while ($row = $db->sql_fetchrow($result))
 102                          {
 103                              $inactive_users[] = $row;
 104                          }
 105                          $db->sql_freeresult($result);
 106  
 107                          user_active_flip('activate', $mark);
 108  
 109                          if ($config['require_activation'] == USER_ACTIVATION_ADMIN && !empty($inactive_users))
 110                          {
 111                              include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 112  
 113                              $messenger = new messenger(false);
 114  
 115                              foreach ($inactive_users as $row)
 116                              {
 117                                  $messenger->template('admin_welcome_activated', $row['user_lang']);
 118  
 119                                  $messenger->to($row['user_email'], $row['username']);
 120  
 121                                  $messenger->anti_abuse_headers($config, $user);
 122  
 123                                  $messenger->assign_vars(array(
 124                                      'USERNAME'    => htmlspecialchars_decode($row['username']))
 125                                  );
 126  
 127                                  $messenger->send(NOTIFY_EMAIL);
 128                              }
 129  
 130                              $messenger->save_queue();
 131                          }
 132  
 133                          if (!empty($inactive_users))
 134                          {
 135                              foreach ($inactive_users as $row)
 136                              {
 137                                  add_log('admin', 'LOG_USER_ACTIVE', $row['username']);
 138                                  add_log('user', $row['user_id'], 'LOG_USER_ACTIVE_USER');
 139                              }
 140                          }
 141  
 142                          // For activate we really need to redirect, else a refresh can result in users being deactivated again
 143                          $u_action = $this->u_action . "&amp;$u_sort_param&amp;start=$start";
 144                          $u_action .= ($per_page != $config['topics_per_page']) ? "&amp;users_per_page=$per_page" : '';
 145  
 146                          redirect($u_action);
 147                      }
 148                      else if ($action == 'delete')
 149                      {
 150                          if (confirm_box(true))
 151                          {
 152                              if (!$auth->acl_get('a_userdel'))
 153                              {
 154                                  trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
 155                              }
 156  
 157                              foreach ($mark as $user_id)
 158                              {
 159                                  user_delete('retain', $user_id, $user_affected[$user_id]);
 160                              }
 161  
 162                              add_log('admin', 'LOG_INACTIVE_' . strtoupper($action), implode(', ', $user_affected));
 163                          }
 164                          else
 165                          {
 166                              $s_hidden_fields = array(
 167                                  'mode'            => $mode,
 168                                  'action'        => $action,
 169                                  'mark'            => $mark,
 170                                  'submit'        => 1,
 171                                  'start'            => $start,
 172                              );
 173                              confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
 174                          }
 175                      }
 176  
 177                  break;
 178  
 179                  case 'remind':
 180                      if (empty($config['email_enable']))
 181                      {
 182                          trigger_error($user->lang['EMAIL_DISABLED'] . adm_back_link($this->u_action), E_USER_WARNING);
 183                      }
 184  
 185                      $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type, user_regdate, user_actkey
 186                          FROM ' . USERS_TABLE . '
 187                          WHERE ' . $db->sql_in_set('user_id', $mark) . '
 188                              AND user_inactive_reason';
 189  
 190                      $sql .= ($config['require_activation'] == USER_ACTIVATION_ADMIN) ? ' = ' . INACTIVE_REMIND : ' <> ' . INACTIVE_MANUAL;
 191  
 192                      $result = $db->sql_query($sql);
 193  
 194                      if ($row = $db->sql_fetchrow($result))
 195                      {
 196                          // Send the messages
 197                          include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 198  
 199                          $messenger = new messenger();
 200                          $usernames = $user_ids = array();
 201  
 202                          do
 203                          {
 204                              $messenger->template('user_remind_inactive', $row['user_lang']);
 205  
 206                              $messenger->to($row['user_email'], $row['username']);
 207                              $messenger->im($row['user_jabber'], $row['username']);
 208  
 209                              $messenger->anti_abuse_headers($config, $user);
 210  
 211                              $messenger->assign_vars(array(
 212                                  'USERNAME'        => htmlspecialchars_decode($row['username']),
 213                                  'REGISTER_DATE'    => $user->format_date($row['user_regdate'], false, true),
 214                                  'U_ACTIVATE'    => generate_board_url() . "/ucp.$phpEx?mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey'])
 215                              );
 216  
 217                              $messenger->send($row['user_notify_type']);
 218  
 219                              $usernames[] = $row['username'];
 220                              $user_ids[] = (int) $row['user_id'];
 221                          }
 222                          while ($row = $db->sql_fetchrow($result));
 223  
 224                          $messenger->save_queue();
 225  
 226                          // Add the remind state to the database
 227                          $sql = 'UPDATE ' . USERS_TABLE . '
 228                              SET user_reminded = user_reminded + 1,
 229                                  user_reminded_time = ' . time() . '
 230                              WHERE ' . $db->sql_in_set('user_id', $user_ids);
 231                          $db->sql_query($sql);
 232  
 233                          add_log('admin', 'LOG_INACTIVE_REMIND', implode(', ', $usernames));
 234                          unset($usernames);
 235                      }
 236                      $db->sql_freeresult($result);
 237  
 238                      // For remind we really need to redirect, else a refresh can result in more than one reminder
 239                      $u_action = $this->u_action . "&amp;$u_sort_param&amp;start=$start";
 240                      $u_action .= ($per_page != $config['topics_per_page']) ? "&amp;users_per_page=$per_page" : '';
 241  
 242                      redirect($u_action);
 243  
 244                  break;
 245              }
 246          }
 247  
 248          // Define where and sort sql for use in displaying logs
 249          $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
 250          $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
 251  
 252          $inactive = array();
 253          $inactive_count = 0;
 254  
 255          $start = view_inactive_users($inactive, $inactive_count, $per_page, $start, $sql_where, $sql_sort);
 256  
 257          foreach ($inactive as $row)
 258          {
 259              $template->assign_block_vars('inactive', array(
 260                  'INACTIVE_DATE'    => $user->format_date($row['user_inactive_time']),
 261                  'REMINDED_DATE'    => $user->format_date($row['user_reminded_time']),
 262                  'JOINED'        => $user->format_date($row['user_regdate']),
 263                  'LAST_VISIT'    => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
 264  
 265                  'REASON'        => $row['inactive_reason'],
 266                  'USER_ID'        => $row['user_id'],
 267                  'POSTS'            => ($row['user_posts']) ? $row['user_posts'] : 0,
 268                  'REMINDED'        => $row['user_reminded'],
 269  
 270                  'REMINDED_EXPLAIN'    => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])),
 271  
 272                  'USERNAME_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=overview')),
 273                  'USERNAME'            => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
 274                  'USER_COLOR'        => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
 275  
 276                  'U_USER_ADMIN'    => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"),
 277                  'U_SEARCH_USER'    => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id={$row['user_id']}&amp;sr=posts") : '',
 278              ));
 279          }
 280  
 281          $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
 282          if ($config['email_enable'])
 283          {
 284              $option_ary += array('remind' => 'REMIND');
 285          }
 286  
 287          $template->assign_vars(array(
 288              'S_INACTIVE_USERS'        => true,
 289              'S_INACTIVE_OPTIONS'    => build_select($option_ary),
 290  
 291              'S_LIMIT_DAYS'    => $s_limit_days,
 292              'S_SORT_KEY'    => $s_sort_key,
 293              'S_SORT_DIR'    => $s_sort_dir,
 294              'S_ON_PAGE'        => on_page($inactive_count, $per_page, $start),
 295              'PAGINATION'    => generate_pagination($this->u_action . "&amp;$u_sort_param&amp;users_per_page=$per_page", $inactive_count, $per_page, $start, true),
 296              'USERS_PER_PAGE'    => $per_page,
 297  
 298              'U_ACTION'        => $this->u_action . "&amp;$u_sort_param&amp;users_per_page=$per_page&amp;start=$start",
 299          ));
 300  
 301          $this->tpl_name = 'acp_inactive';
 302          $this->page_title = 'ACP_INACTIVE_USERS';
 303      }
 304  }
 305  
 306  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1