[ Index ] |
PHP Cross Reference of phpBB 3.0 Beta 3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * @package acp 5 * @version $Id: acp_ranks.php,v 1.9 2006/11/03 21:04:09 acydburn Exp $ 6 * @copyright (c) 2005 phpBB Group 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 8 * 9 */ 10 11 /** 12 * @package acp 13 */ 14 class acp_ranks 15 { 16 var $u_action; 17 18 function main($id, $mode) 19 { 20 global $db, $user, $auth, $template, $cache; 21 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; 22 23 $user->add_lang('acp/posting'); 24 25 // Set up general vars 26 $action = request_var('action', ''); 27 $action = (isset($_POST['add'])) ? 'add' : $action; 28 $action = (isset($_POST['save'])) ? 'save' : $action; 29 $rank_id = request_var('id', 0); 30 31 $this->tpl_name = 'acp_ranks'; 32 $this->page_title = 'ACP_MANAGE_RANKS'; 33 34 switch ($action) 35 { 36 case 'save': 37 38 $rank_title = request_var('title', '', true); 39 $special_rank = request_var('special_rank', 0); 40 $min_posts = ($special_rank) ? 0 : request_var('min_posts', 0); 41 $rank_image = request_var('rank_image', ''); 42 43 // The rank image has to be a jpg, gif or png 44 if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image)) 45 { 46 $rank_image = ''; 47 } 48 49 if (!$rank_title) 50 { 51 trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING); 52 } 53 54 $sql_ary = array( 55 'rank_title' => $rank_title, 56 'rank_special' => $special_rank, 57 'rank_min' => $min_posts, 58 'rank_image' => htmlspecialchars_decode($rank_image) 59 ); 60 61 if ($rank_id) 62 { 63 $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id"; 64 $message = $user->lang['RANK_UPDATED']; 65 } 66 else 67 { 68 $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); 69 $message = $user->lang['RANK_ADDED']; 70 } 71 $db->sql_query($sql); 72 73 $cache->destroy('ranks'); 74 75 trigger_error($message . adm_back_link($this->u_action)); 76 77 break; 78 79 case 'delete': 80 81 // Ok, they want to delete their rank 82 if ($rank_id) 83 { 84 $sql = 'DELETE FROM ' . RANKS_TABLE . " 85 WHERE rank_id = $rank_id"; 86 $db->sql_query($sql); 87 88 $sql = 'UPDATE ' . USERS_TABLE . " 89 SET user_rank = 0 90 WHERE user_rank = $rank_id"; 91 $db->sql_query($sql); 92 93 $cache->destroy('ranks'); 94 95 trigger_error($user->lang['RANK_REMOVED'] . adm_back_link($this->u_action)); 96 } 97 else 98 { 99 trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING); 100 } 101 102 break; 103 104 case 'edit': 105 case 'add': 106 107 $data = $ranks = $existing_imgs = array(); 108 109 $sql = 'SELECT * 110 FROM ' . RANKS_TABLE . ' 111 ORDER BY rank_min ASC, rank_special ASC'; 112 $result = $db->sql_query($sql); 113 114 while ($row = $db->sql_fetchrow($result)) 115 { 116 $existing_imgs[] = $row['rank_image']; 117 118 if ($action == 'edit' && $rank_id == $row['rank_id']) 119 { 120 $ranks = $row; 121 } 122 } 123 $db->sql_freeresult($result); 124 125 $imglist = filelist($phpbb_root_path . $config['ranks_path'], ''); 126 127 $edit_img = $filename_list = ''; 128 129 foreach ($imglist as $path => $img_ary) 130 { 131 foreach ($img_ary as $img) 132 { 133 $img = $path . $img; 134 135 if (!in_array($img, $existing_imgs) || $action == 'edit') 136 { 137 if ($ranks && $img == $ranks['rank_image']) 138 { 139 $selected = ' selected="selected"'; 140 $edit_img = $img; 141 } 142 else 143 { 144 $selected = ''; 145 } 146 147 $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . '</option>'; 148 } 149 } 150 } 151 152 $filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list; 153 unset($existing_imgs, $imglist); 154 155 $template->assign_vars(array( 156 'S_EDIT' => true, 157 'U_BACK' => $this->u_action, 158 'RANKS_PATH' => $phpbb_root_path . $config['ranks_path'], 159 'U_ACTION' => $this->u_action . '&id=' . $rank_id, 160 161 'RANK_TITLE' => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '', 162 'S_FILENAME_LIST' => $filename_list, 163 'RANK_IMAGE' => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif', 164 'S_SPECIAL_RANK' => (!isset($ranks['rank_special']) || $ranks['rank_special']) ? true : false, 165 'MIN_POSTS' => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0) 166 ); 167 168 169 return; 170 171 break; 172 } 173 174 $template->assign_vars(array( 175 'U_ACTION' => $this->u_action) 176 ); 177 178 $sql = 'SELECT * 179 FROM ' . RANKS_TABLE . ' 180 ORDER BY rank_min ASC, rank_special ASC, rank_title ASC'; 181 $result = $db->sql_query($sql); 182 183 while ($row = $db->sql_fetchrow($result)) 184 { 185 $template->assign_block_vars('ranks', array( 186 'S_RANK_IMAGE' => ($row['rank_image']) ? true : false, 187 'S_SPECIAL_RANK' => ($row['rank_special']) ? true : false, 188 189 'RANK_IMAGE' => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'], 190 'RANK_TITLE' => $row['rank_title'], 191 'MIN_POSTS' => $row['rank_min'], 192 193 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['rank_id'], 194 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['rank_id']) 195 ); 196 } 197 $db->sql_freeresult($result); 198 199 } 200 } 201 202 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 22 00:35:05 2006 | Cross-referenced by PHPXref 0.6 |