Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * @package acp
- * @version $Id$
- * @copyright (c) 2005 phpBB Group
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- *
- */
- /**
- * @ignore
- */
- if (!defined('IN_PHPBB'))
- {
- exit;
- }
- /**
- * @package acp
- */
- class acp_ranks
- {
- var $u_action;
- var $rank_themes = array();
- function main($id, $mode)
- {
- global $db, $user, $auth, $template, $cache;
- global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
- $user->add_lang('acp/posting');
- // Set up general vars
- $action = request_var('action', '');
- $action = (isset($_POST['add'])) ? 'add' : $action;
- $action = (isset($_POST['add_theme'])) ? 'add_theme' : $action;
- $action = (isset($_POST['save'])) ? 'save' : $action;
- $rank_id = request_var('id', 0);
- $this->tpl_name = 'acp_ranks';
- $this->page_title = 'ACP_MANAGE_RANKS';
- $form_name = 'acp_ranks';
- add_form_key($form_name);
- switch ($action)
- {
- case 'save':
- if (!check_form_key($form_name))
- {
- trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
- }
- $rank_title = utf8_normalize_nfc(request_var('title', '', true));
- //Multi-rank theme mod: special rank now calculated another way
- //$special_rank = request_var('special_rank', 0);
- $rank_theme = request_var('rank_theme', DEFAULT_RANK_THEME_ID);
- if ($rank_theme < 0)
- {
- $special_rank = 1; //Stick with the phpBB convention and use magic numbers for the "special rank" value
- $rank_theme = SPECIAL_RANK_THEME_ID;
- }
- else
- {
- $special_rank = 0;
- }
- $min_posts = ($special_rank) ? 0 : max(0, request_var('min_posts', 0));
- $rank_image = request_var('rank_image', '');
- // The rank image has to be a jpg, gif or png
- if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image))
- {
- $rank_image = '';
- }
- if (!$rank_title)
- {
- trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- $sql_ary = array(
- 'rank_title' => $rank_title,
- 'rank_special' => $special_rank,
- 'rank_min' => $min_posts,
- 'rank_theme' => $rank_theme,
- 'rank_image' => htmlspecialchars_decode($rank_image)
- );
- if ($rank_id)
- {
- $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id";
- $message = $user->lang['RANK_UPDATED'];
- add_log('admin', 'LOG_RANK_UPDATED', $rank_title);
- }
- else
- {
- $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
- $message = $user->lang['RANK_ADDED'];
- add_log('admin', 'LOG_RANK_ADDED', $rank_title);
- }
- $db->sql_query($sql);
- $cache->destroy('_ranks');
- trigger_error($message . adm_back_link($this->u_action));
- break;
- case 'delete':
- if (!$rank_id)
- {
- trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- if (confirm_box(true))
- {
- $sql = 'SELECT rank_title
- FROM ' . RANKS_TABLE . '
- WHERE rank_id = ' . $rank_id;
- $result = $db->sql_query($sql);
- $rank_title = (string) $db->sql_fetchfield('rank_title');
- $db->sql_freeresult($result);
- $sql = 'DELETE FROM ' . RANKS_TABLE . "
- WHERE rank_id = $rank_id";
- $db->sql_query($sql);
- $sql = 'UPDATE ' . USERS_TABLE . "
- SET user_rank = 0
- WHERE user_rank = $rank_id";
- $db->sql_query($sql);
- $cache->destroy('_ranks');
- add_log('admin', 'LOG_RANK_REMOVED', $rank_title);
- trigger_error($user->lang['RANK_REMOVED'] . adm_back_link($this->u_action));
- }
- else
- {
- confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
- 'i' => $id,
- 'mode' => $mode,
- 'rank_id' => $rank_id,
- 'action' => 'delete',
- )));
- }
- break;
- case 'edit':
- case 'add':
- $data = $ranks = $existing_imgs = array();
- $this->load_rank_themes();
- $ranks = array();
- foreach ($this->rank_themes as $theme)
- {
- $ranks[$theme['rtheme_id']] = array();
- }
- $sql = 'SELECT *
- FROM ' . RANKS_TABLE . '
- ORDER BY rank_min ASC, rank_special ASC';
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- $existing_imgs[] = $row['rank_image'];
- if ($action == 'edit' && $rank_id == $row['rank_id'])
- {
- $ranks = $row;
- }
- }
- $db->sql_freeresult($result);
- $this->load_rank_themes();
- $rank_theme_list = '';
- $rank_theme = (isset($ranks['rank_theme']) ? $ranks['rank_theme'] : DEFAULT_RANK_THEME_ID);
- foreach ($this->rank_themes as $id => $theme_data)
- {
- $rank_theme_list.= '<option value="' . $id . '"' . ($rank_theme == $id ? ' selected="selected"' : '') . '>' . $theme_data['rtheme_title'] . '</option>';
- }
- $imglist = filelist($phpbb_root_path . $config['ranks_path'], '');
- $edit_img = $filename_list = '';
- foreach ($imglist as $path => $img_ary)
- {
- sort($img_ary);
- foreach ($img_ary as $img)
- {
- $img = $path . $img;
- if ($ranks && $img == $ranks['rank_image'])
- {
- $selected = ' selected="selected"';
- $edit_img = $img;
- }
- else
- {
- $selected = '';
- }
- if (strlen($img) > 255)
- {
- continue;
- }
- $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . ((in_array($img, $existing_imgs)) ? ' ' . $user->lang['RANK_IMAGE_IN_USE'] : '') . '</option>';
- }
- }
- $filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
- unset($existing_imgs, $imglist);
- $template->assign_vars(array(
- 'S_EDIT' => true,
- 'U_BACK' => $this->u_action,
- 'RANKS_PATH' => $phpbb_root_path . $config['ranks_path'],
- 'U_ACTION' => $this->u_action . '&id=' . $rank_id,
- 'RANK_TITLE' => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '',
- 'S_FILENAME_LIST' => $filename_list,
- 'RANK_IMAGE' => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif',
- 'S_SPECIAL_RANK' => (isset($ranks['rank_special']) && $ranks['rank_special']) ? true : false,
- 'S_RANK_THEME_LIST' => $rank_theme_list,
- 'MIN_POSTS' => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0)
- );
- return;
- break;
- //Multi-rank theme mod: Add separate theme saving, deleting, adding and editing rather than overriding a single mode
- case 'save_theme':
- $theme_title = utf8_normalize_nfc(request_var('title', '', true));
- $theme_public = request_var('theme_public', RANK_THEME_PUBLIC);
- if (!$theme_title)
- {
- trigger_error($user->lang['NO_RANK_THEME_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- if ($rank_id == DEFAULT_RANK_THEME_ID || $rank_id == SPECIAL_RANK_THEME_ID || $rank_id < 0)
- {
- trigger_error($user->lang['MUST_SELECT_RANK_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- $sql_ary = array(
- 'rtheme_title' => $theme_title,
- 'rtheme_public' => $theme_public
- );
- if ($rank_id)
- {
- $sql = 'UPDATE ' . RANK_THEMES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rtheme_id = $rank_id";
- $message = $user->lang['RANK_THEME_UPDATED'];
- add_log('admin', 'LOG_RANK_THEME_UPDATED', $theme_title);
- }
- else
- {
- $sql = 'INSERT INTO ' . RANK_THEMES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
- $message = $user->lang['RANK_THEME_ADDED'];
- add_log('admin', 'LOG_RANK_THEME_ADDED', $theme_title);
- }
- $db->sql_query($sql);
- $cache->destroy('_ranks');
- trigger_error($message . adm_back_link($this->u_action));
- break;
- case 'delete_theme':
- //Don't allow deletion of special or default rank sets
- if ($rank_id == DEFAULT_RANK_THEME_ID || $rank_id == SPECIAL_RANK_THEME_ID || $rank_id < 0)
- {
- trigger_error($user->lang['MUST_SELECT_RANK_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
- }
- if (confirm_box(true))
- {
- $sql = 'SELECT rtheme_title
- FROM ' . RANK_THEMES_TABLE . '
- WHERE rtheme_id = ' . $rank_id;
- $result = $db->sql_query($sql);
- $theme_title = (string) $db->sql_fetchfield('rtheme_title');
- $db->sql_freeresult($result);
- $sql = 'DELETE FROM ' . RANKS_TABLE . "
- WHERE rank_theme = $rank_id";
- $db->sql_query($sql);
- $sql = 'DELETE FROM ' . RANK_THEMES_TABLE . "
- WHERE rtheme_id = $rank_id";
- $db->sql_query($sql);
- $sql = 'UPDATE ' . USERS_TABLE . "
- SET user_rank_theme = ".DEFAULT_RANK_THEME_ID."
- WHERE user_rank_theme = $rank_id";
- $db->sql_query($sql);
- $cache->destroy('_ranks');
- add_log('admin', 'LOG_RANK_THEME_REMOVED', $theme_title);
- trigger_error($user->lang['RANK_THEME_REMOVED'] . adm_back_link($this->u_action));
- }
- else
- {
- confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
- 'i' => $id,
- 'mode' => $mode,
- 'rank_id' => $rank_id,
- 'action' => 'delete_theme',
- )));
- }
- break;
- case 'edit_theme':
- case 'add_theme':
- $theme = array();
- $sql = 'SELECT *
- FROM ' . RANK_THEMES_TABLE . '
- WHERE rtheme_id = ' . $rank_id;
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- $theme = $row;
- }
- $db->sql_freeresult($result);
- $template->assign_vars(array(
- 'S_EDIT_THEME' => true,
- 'U_BACK' => $this->u_action,
- 'U_ACTION' => $this->u_action . '&id=' . $rank_id,
- 'RANK_THEME_TITLE' => (isset($theme['rtheme_title'])) ? $theme['rtheme_title'] : '',
- 'S_RANK_THEME_PUBLIC' => (isset($theme['rtheme_public']) && $theme['rtheme_public']) ? true : false)
- );
- return;
- break;
- }
- $template->assign_vars(array(
- 'U_ACTION' => $this->u_action)
- );
- print_r($this->rank_themes);
- $sql = 'SELECT *
- FROM ' . RANKS_TABLE . '
- ORDER BY rank_special DESC, rank_min ASC, rank_title ASC';
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- $ranks[$row['rank_theme']][] = $row;
- }
- foreach ($this->rank_themes as $theme)
- {
- print_r($theme);
- $template->assign_block_vars('themes', array(
- 'RANK_THEME_TITLE' => $theme['rtheme_title'],
- 'S_THEME_PUBLIC' => $theme['rtheme_public'],
- 'U_EDIT_THEME' => ($theme['rtheme_id'] != DEFAULT_RANK_THEME_ID && $theme['rtheme_id'] != SPECIAL_RANK_THEME_ID ? $this->u_action . '&action=edit_theme&id=' . $theme['rtheme_id'] : ''),
- 'U_DELETE_THEME' => ($theme['rtheme_id'] != DEFAULT_RANK_THEME_ID && $theme['rtheme_id'] != SPECIAL_RANK_THEME_ID ? $this->u_action . '&action=delete_theme&id=' . $theme['rtheme_id'] : '')));
- if (sizeof($ranks[$theme['rtheme_id']]) > 0)
- {
- foreach ($ranks[$theme['rtheme_id']] as $row)
- {
- print_r($row);
- $template->assign_block_vars('themes.ranks', array(
- 'S_RANK_IMAGE' => ($row['rank_image']) ? true : false,
- 'S_SPECIAL_RANK' => ($row['rank_special']) ? true : false,
- 'RANK_IMAGE' => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'],
- 'RANK_TITLE' => $row['rank_title'],
- 'MIN_POSTS' => $row['rank_min'],
- 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['rank_id'],
- 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['rank_id'])
- );
- }
- }
- }
- $db->sql_freeresult($result);
- }
- function load_rank_themes()
- {
- echo "Start load_rank_themes()";
- if (sizeof($this->rank_themes) > 0) {
- echo "Cached ".sizeof($this->rank_themes)." themes";
- return;
- }
- global $db, $user;
- $sql = 'SELECT * FROM ' . RANK_THEMES_TABLE. " WHERE rtheme_id > 1 ORDER BY rtheme_title";
- echo $sql;
- $result = $db->sql_query($sql);
- $this->rank_themes = array(SPECIAL_RANK_THEME_ID => array('rtheme_id' => SPECIAL_RANK_THEME_ID, 'rtheme_title' => $user->lang['SPECIAL_RANK_THEME'], 'rtheme_public' => false),
- DEFAULT_RANK_THEME_ID => array('rtheme_id' => DEFAULT_RANK_THEME_ID, 'rtheme_title' => $user->lang['DEFAULT_RANK_THEME'], 'rtheme_public' => true));
- print_r($this->rank_themes);
- while ($row = $db->sql_fetchrow($result))
- {
- print_r($row);
- $this->rank_themes[$row['rtheme_id']] = $row;
- }
- print_r($this->rank_themes);
- echo "End load_rank_themes()";
- $db->sql_freeresult($result);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement