[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/mcp/ -> mcp_ban.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package mcp
   5  * @version $Id$
   6  * @copyright (c) 2005 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 mcp
  21  */
  22  class mcp_ban
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $config, $db, $user, $auth, $template, $cache;
  29          global $phpbb_root_path, $phpEx;
  30  
  31          include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  32  
  33          // Include the admin banning interface...
  34          include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
  35  
  36          $bansubmit        = (isset($_POST['bansubmit'])) ? true : false;
  37          $unbansubmit    = (isset($_POST['unbansubmit'])) ? true : false;
  38          $current_time    = time();
  39  
  40          $user->add_lang(array('acp/ban', 'acp/users'));
  41          $this->tpl_name = 'mcp_ban';
  42  
  43          // Ban submitted?
  44          if ($bansubmit)
  45          {
  46              // Grab the list of entries
  47              $ban                = request_var('ban', '', ($mode === 'user') ? true : false);
  48  
  49              if ($mode === 'user')
  50              {
  51                  $ban = utf8_normalize_nfc($ban);
  52              }
  53  
  54              $ban_len            = request_var('banlength', 0);
  55              $ban_len_other        = request_var('banlengthother', '');
  56              $ban_exclude        = request_var('banexclude', 0);
  57              $ban_reason            = utf8_normalize_nfc(request_var('banreason', '', true));
  58              $ban_give_reason    = utf8_normalize_nfc(request_var('bangivereason', '', true));
  59  
  60              if ($ban)
  61              {
  62                  if (confirm_box(true))
  63                  {
  64                      user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
  65  
  66                      trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
  67                  }
  68                  else
  69                  {
  70                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  71                          'mode'                => $mode,
  72                          'ban'                => $ban,
  73                          'bansubmit'            => true,
  74                          'banlength'            => $ban_len,
  75                          'banlengthother'    => $ban_len_other,
  76                          'banexclude'        => $ban_exclude,
  77                          'banreason'            => $ban_reason,
  78                          'bangivereason'        => $ban_give_reason)));
  79                  }
  80              }
  81          }
  82          else if ($unbansubmit)
  83          {
  84              $ban = request_var('unban', array(''));
  85  
  86              if ($ban)
  87              {
  88                  if (confirm_box(true))
  89                  {
  90                      user_unban($mode, $ban);
  91  
  92                      trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
  93                  }
  94                  else
  95                  {
  96                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  97                          'mode'            => $mode,
  98                          'unbansubmit'    => true,
  99                          'unban'            => $ban)));
 100                  }
 101              }
 102          }
 103  
 104          // Ban length options
 105          $ban_end_text = array(0 => $user->lang['PERMANENT'], 30 => $user->lang['30_MINS'], 60 => $user->lang['1_HOUR'], 360 => $user->lang['6_HOURS'], 1440 => $user->lang['1_DAY'], 10080 => $user->lang['7_DAYS'], 20160 => $user->lang['2_WEEKS'], 40320 => $user->lang['1_MONTH'], -1 => $user->lang['UNTIL'] . ' -&gt; ');
 106  
 107          $ban_end_options = '';
 108          foreach ($ban_end_text as $length => $text)
 109          {
 110              $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
 111          }
 112  
 113          // Define language vars
 114          $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
 115  
 116          $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
 117          $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
 118          $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
 119          $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
 120          $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
 121  
 122          switch ($mode)
 123          {
 124              case 'user':
 125                  $l_ban_cell = $user->lang['USERNAME'];
 126              break;
 127  
 128              case 'ip':
 129                  $l_ban_cell = $user->lang['IP_HOSTNAME'];
 130              break;
 131  
 132              case 'email':
 133                  $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
 134              break;
 135          }
 136  
 137          acp_ban::display_ban_options($mode);
 138  
 139          $template->assign_vars(array(
 140              'L_TITLE'                => $this->page_title,
 141              'L_EXPLAIN'                => $l_ban_explain,
 142              'L_UNBAN_TITLE'            => $l_unban_title,
 143              'L_UNBAN_EXPLAIN'        => $l_unban_explain,
 144              'L_BAN_CELL'            => $l_ban_cell,
 145              'L_BAN_EXCLUDE_EXPLAIN'    => $l_ban_exclude_explain,
 146              'L_NO_BAN_CELL'            => $l_no_ban_cell,
 147  
 148              'S_USERNAME_BAN'    => ($mode == 'user') ? true : false,
 149  
 150              'U_ACTION'            => $this->u_action,
 151              'U_FIND_USERNAME'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_ban&amp;field=ban'),
 152          ));
 153  
 154          if ($mode === 'email' && !$auth->acl_get('a_user'))
 155          {
 156              return;
 157          }
 158  
 159          // As a "service" we will check if any post id is specified and populate the username of the poster id if given
 160          $post_id = request_var('p', 0);
 161          $user_id = request_var('u', 0);
 162          $username = $pre_fill = false;
 163  
 164          if ($user_id && $user_id <> ANONYMOUS)
 165          {
 166              $sql = 'SELECT username, user_email, user_ip
 167                  FROM ' . USERS_TABLE . '
 168                  WHERE user_id = ' . $user_id;
 169              $result = $db->sql_query($sql);
 170              switch ($mode)
 171              {
 172                  case 'user':
 173                      $pre_fill = (string) $db->sql_fetchfield('username');
 174                  break;
 175                  
 176                  case 'ip':
 177                      $pre_fill = (string) $db->sql_fetchfield('user_ip');
 178                  break;
 179  
 180                  case 'email':
 181                      $pre_fill = (string) $db->sql_fetchfield('user_email');
 182                  break;
 183              }
 184              $db->sql_freeresult($result);
 185          }
 186          else if ($post_id)
 187          {
 188              $post_info = get_post_data($post_id, 'm_ban');
 189  
 190              if (sizeof($post_info) && !empty($post_info[$post_id]))
 191              {
 192                  switch ($mode)
 193                  {
 194                      case 'user':
 195                          $pre_fill = $post_info[$post_id]['username'];
 196                      break;
 197  
 198                      case 'ip':
 199                          $pre_fill = $post_info[$post_id]['poster_ip'];
 200                      break;
 201  
 202                      case 'email':
 203                          $pre_fill = $post_info[$post_id]['user_email'];
 204                      break;
 205                  }
 206  
 207              }
 208          }
 209  
 210          if ($pre_fill)
 211          {
 212              // left for legacy template compatibility
 213              $template->assign_var('USERNAMES', $pre_fill);
 214              $template->assign_var('BAN_QUANTIFIER', $pre_fill);
 215          }
 216      }
 217  }
 218  
 219  ?>


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