[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  /**
   3  *
   4  * @package acp
   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 acp
  21  */
  22  class acp_ranks
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $db, $user, $auth, $template, $cache;
  29          global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  30  
  31          $user->add_lang('acp/posting');
  32  
  33          // Set up general vars
  34          $action = request_var('action', '');
  35          $action = (isset($_POST['add'])) ? 'add' : $action;
  36          $action = (isset($_POST['save'])) ? 'save' : $action;
  37          $rank_id = request_var('id', 0);
  38  
  39          $this->tpl_name = 'acp_ranks';
  40          $this->page_title = 'ACP_MANAGE_RANKS';
  41  
  42          $form_name = 'acp_ranks';
  43          add_form_key($form_name);
  44  
  45          switch ($action)
  46          {
  47              case 'save':
  48  
  49                  if (!check_form_key($form_name))
  50                  {
  51                      trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
  52                  }
  53                  $rank_title = utf8_normalize_nfc(request_var('title', '', true));
  54                  $special_rank = request_var('special_rank', 0);
  55                  $min_posts = ($special_rank) ? 0 : max(0, request_var('min_posts', 0));
  56                  $rank_image = request_var('rank_image', '');
  57  
  58                  // The rank image has to be a jpg, gif or png
  59                  if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image))
  60                  {
  61                      $rank_image = '';
  62                  }
  63  
  64                  if (!$rank_title)
  65                  {
  66                      trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
  67                  }
  68  
  69                  $sql_ary = array(
  70                      'rank_title'        => $rank_title,
  71                      'rank_special'        => $special_rank,
  72                      'rank_min'            => $min_posts,
  73                      'rank_image'        => htmlspecialchars_decode($rank_image)
  74                  );
  75                  
  76                  if ($rank_id)
  77                  {
  78                      $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id";
  79                      $message = $user->lang['RANK_UPDATED'];
  80  
  81                      add_log('admin', 'LOG_RANK_UPDATED', $rank_title);
  82                  }
  83                  else
  84                  {
  85                      $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  86                      $message = $user->lang['RANK_ADDED'];
  87  
  88                      add_log('admin', 'LOG_RANK_ADDED', $rank_title);
  89                  }
  90                  $db->sql_query($sql);
  91  
  92                  $cache->destroy('_ranks');
  93  
  94                  trigger_error($message . adm_back_link($this->u_action));
  95  
  96              break;
  97  
  98              case 'delete':
  99  
 100                  if (!$rank_id)
 101                  {
 102                      trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING);
 103                  }
 104  
 105                  if (confirm_box(true))
 106                  {
 107                      $sql = 'SELECT rank_title
 108                          FROM ' . RANKS_TABLE . '
 109                          WHERE rank_id = ' . $rank_id;
 110                      $result = $db->sql_query($sql);
 111                      $rank_title = (string) $db->sql_fetchfield('rank_title');
 112                      $db->sql_freeresult($result);
 113  
 114                      $sql = 'DELETE FROM ' . RANKS_TABLE . "
 115                          WHERE rank_id = $rank_id";
 116                      $db->sql_query($sql);
 117  
 118                      $sql = 'UPDATE ' . USERS_TABLE . "
 119                          SET user_rank = 0
 120                          WHERE user_rank = $rank_id";
 121                      $db->sql_query($sql);
 122  
 123                      $cache->destroy('_ranks');
 124  
 125                      add_log('admin', 'LOG_RANK_REMOVED', $rank_title);
 126                  }
 127                  else
 128                  {
 129                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 130                          'i'            => $id,
 131                          'mode'        => $mode,
 132                          'rank_id'    => $rank_id,
 133                          'action'    => 'delete',
 134                      )));
 135                  }
 136  
 137              break;
 138  
 139              case 'edit':
 140              case 'add':
 141  
 142                  $data = $ranks = $existing_imgs = array();
 143                  
 144                  $sql = 'SELECT *
 145                      FROM ' . RANKS_TABLE . '
 146                      ORDER BY rank_min ASC, rank_special ASC';
 147                  $result = $db->sql_query($sql);
 148  
 149                  while ($row = $db->sql_fetchrow($result))
 150                  {
 151                      $existing_imgs[] = $row['rank_image'];
 152  
 153                      if ($action == 'edit' && $rank_id == $row['rank_id'])
 154                      {
 155                          $ranks = $row;
 156                      }
 157                  }
 158                  $db->sql_freeresult($result);
 159  
 160                  $imglist = filelist($phpbb_root_path . $config['ranks_path'], '');
 161                  $edit_img = $filename_list = '';
 162  
 163                  foreach ($imglist as $path => $img_ary)
 164                  {
 165                      sort($img_ary);
 166  
 167                      foreach ($img_ary as $img)
 168                      {
 169                          $img = $path . $img;
 170  
 171                          if ($ranks && $img == $ranks['rank_image'])
 172                          {
 173                              $selected = ' selected="selected"';
 174                              $edit_img = $img;
 175                          }
 176                          else
 177                          {
 178                              $selected = '';
 179                          }
 180  
 181                          if (strlen($img) > 255)
 182                          {
 183                              continue;
 184                          }
 185  
 186                          $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . ((in_array($img, $existing_imgs)) ? ' ' . $user->lang['RANK_IMAGE_IN_USE'] : '') . '</option>';
 187                      }
 188                  }
 189  
 190                  $filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
 191                  unset($existing_imgs, $imglist);
 192  
 193                  $template->assign_vars(array(
 194                      'S_EDIT'            => true,
 195                      'U_BACK'            => $this->u_action,
 196                      'RANKS_PATH'        => $phpbb_root_path . $config['ranks_path'],
 197                      'U_ACTION'            => $this->u_action . '&amp;id=' . $rank_id,
 198  
 199                      'RANK_TITLE'        => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '',
 200                      'S_FILENAME_LIST'    => $filename_list,
 201                      'RANK_IMAGE'        => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif',
 202                      'S_SPECIAL_RANK'    => (isset($ranks['rank_special']) && $ranks['rank_special']) ? true : false,
 203                      'MIN_POSTS'            => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0)
 204                  );
 205                          
 206  
 207                  return;
 208  
 209              break;
 210          }
 211      
 212          $template->assign_vars(array(
 213              'U_ACTION'        => $this->u_action)
 214          );
 215  
 216          $sql = 'SELECT *
 217              FROM ' . RANKS_TABLE . '
 218              ORDER BY rank_special DESC, rank_min ASC, rank_title ASC';
 219          $result = $db->sql_query($sql);
 220  
 221          while ($row = $db->sql_fetchrow($result))
 222          {
 223              $template->assign_block_vars('ranks', array(
 224                  'S_RANK_IMAGE'        => ($row['rank_image']) ? true : false,
 225                  'S_SPECIAL_RANK'    => ($row['rank_special']) ? true : false,
 226  
 227                  'RANK_IMAGE'        => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'],
 228                  'RANK_TITLE'        => $row['rank_title'],
 229                  'MIN_POSTS'            => $row['rank_min'],
 230  
 231                  'U_EDIT'            => $this->u_action . '&amp;action=edit&amp;id=' . $row['rank_id'],
 232                  'U_DELETE'            => $this->u_action . '&amp;action=delete&amp;id=' . $row['rank_id'])
 233              );    
 234          }
 235          $db->sql_freeresult($result);
 236  
 237      }
 238  }
 239  
 240  ?>


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