Advertisement
Guest User

myfaultymod

a guest
Sep 6th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.84 KB | None | 0 0
  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.     var $rank_themes = array();
  27.  
  28.     function main($id, $mode)
  29.     {
  30.         global $db, $user, $auth, $template, $cache;
  31.         global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  32.  
  33.         $user->add_lang('acp/posting');
  34.  
  35.         // Set up general vars
  36.         $action = request_var('action', '');
  37.         $action = (isset($_POST['add'])) ? 'add' : $action;
  38.         $action = (isset($_POST['add_theme'])) ? 'add_theme' : $action;
  39.         $action = (isset($_POST['save'])) ? 'save' : $action;
  40.         $rank_id = request_var('id', 0);
  41.  
  42.         $this->tpl_name = 'acp_ranks';
  43.         $this->page_title = 'ACP_MANAGE_RANKS';
  44.  
  45.         $form_name = 'acp_ranks';
  46.         add_form_key($form_name);
  47.  
  48.         switch ($action)
  49.         {
  50.             case 'save':
  51.  
  52.                 if (!check_form_key($form_name))
  53.                 {
  54.                     trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
  55.                 }
  56.                 $rank_title = utf8_normalize_nfc(request_var('title', '', true));
  57.                 //Multi-rank theme mod: special rank now calculated another way
  58.                 //$special_rank = request_var('special_rank', 0);
  59.                 $rank_theme = request_var('rank_theme', DEFAULT_RANK_THEME_ID);
  60.  
  61.                 if ($rank_theme < 0)
  62.                 {
  63.                     $special_rank = 1; //Stick with the phpBB convention and use magic numbers for the "special rank" value
  64.                     $rank_theme = SPECIAL_RANK_THEME_ID;
  65.                 }
  66.                 else
  67.                 {
  68.                     $special_rank = 0;
  69.                 }
  70.                 $min_posts = ($special_rank) ? 0 : max(0, request_var('min_posts', 0));
  71.                 $rank_image = request_var('rank_image', '');
  72.  
  73.                 // The rank image has to be a jpg, gif or png
  74.                 if ($rank_image != '' && !preg_match('#(\.gif|\.png|\.jpg|\.jpeg)$#i', $rank_image))
  75.                 {
  76.                     $rank_image = '';
  77.                 }
  78.  
  79.                 if (!$rank_title)
  80.                 {
  81.                     trigger_error($user->lang['NO_RANK_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
  82.                 }
  83.  
  84.                 $sql_ary = array(
  85.                     'rank_title'        => $rank_title,
  86.                     'rank_special'      => $special_rank,
  87.                     'rank_min'          => $min_posts,
  88.                     'rank_theme'        => $rank_theme,
  89.                     'rank_image'        => htmlspecialchars_decode($rank_image)
  90.                 );
  91.                
  92.                 if ($rank_id)
  93.                 {
  94.                     $sql = 'UPDATE ' . RANKS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rank_id = $rank_id";
  95.                     $message = $user->lang['RANK_UPDATED'];
  96.  
  97.                     add_log('admin', 'LOG_RANK_UPDATED', $rank_title);
  98.                 }
  99.                 else
  100.                 {
  101.                     $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  102.                     $message = $user->lang['RANK_ADDED'];
  103.  
  104.                     add_log('admin', 'LOG_RANK_ADDED', $rank_title);
  105.                 }
  106.                 $db->sql_query($sql);
  107.  
  108.                 $cache->destroy('_ranks');
  109.  
  110.                 trigger_error($message . adm_back_link($this->u_action));
  111.  
  112.             break;
  113.  
  114.             case 'delete':
  115.  
  116.                 if (!$rank_id)
  117.                 {
  118.                     trigger_error($user->lang['MUST_SELECT_RANK'] . adm_back_link($this->u_action), E_USER_WARNING);
  119.                 }
  120.  
  121.                 if (confirm_box(true))
  122.                 {
  123.                     $sql = 'SELECT rank_title
  124.                         FROM ' . RANKS_TABLE . '
  125.                         WHERE rank_id = ' . $rank_id;
  126.                     $result = $db->sql_query($sql);
  127.                     $rank_title = (string) $db->sql_fetchfield('rank_title');
  128.                     $db->sql_freeresult($result);
  129.  
  130.                     $sql = 'DELETE FROM ' . RANKS_TABLE . "
  131.                         WHERE rank_id = $rank_id";
  132.                     $db->sql_query($sql);
  133.  
  134.                     $sql = 'UPDATE ' . USERS_TABLE . "
  135.                         SET user_rank = 0
  136.                         WHERE user_rank = $rank_id";
  137.                     $db->sql_query($sql);
  138.  
  139.                     $cache->destroy('_ranks');
  140.  
  141.                     add_log('admin', 'LOG_RANK_REMOVED', $rank_title);
  142.                     trigger_error($user->lang['RANK_REMOVED'] . adm_back_link($this->u_action));
  143.                 }
  144.                 else
  145.                 {
  146.                     confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  147.                         'i'         => $id,
  148.                         'mode'      => $mode,
  149.                         'rank_id'   => $rank_id,
  150.                         'action'    => 'delete',
  151.                     )));
  152.                 }
  153.  
  154.             break;
  155.  
  156.             case 'edit':
  157.             case 'add':
  158.  
  159.                 $data = $ranks = $existing_imgs = array();
  160.                
  161.                 $this->load_rank_themes();
  162.  
  163.                 $ranks = array();
  164.  
  165.         foreach ($this->rank_themes as $theme)
  166.         {
  167.             $ranks[$theme['rtheme_id']] = array();
  168.         }
  169.                
  170.                 $sql = 'SELECT *
  171.                     FROM ' . RANKS_TABLE . '
  172.                     ORDER BY rank_min ASC, rank_special ASC';
  173.                 $result = $db->sql_query($sql);
  174.  
  175.                 while ($row = $db->sql_fetchrow($result))
  176.                 {
  177.                     $existing_imgs[] = $row['rank_image'];
  178.  
  179.                     if ($action == 'edit' && $rank_id == $row['rank_id'])
  180.                     {
  181.                         $ranks = $row;
  182.                     }
  183.                 }
  184.                 $db->sql_freeresult($result);
  185.                
  186.                 $this->load_rank_themes();
  187.  
  188.                 $rank_theme_list = '';
  189.                 $rank_theme = (isset($ranks['rank_theme']) ? $ranks['rank_theme'] : DEFAULT_RANK_THEME_ID);
  190.  
  191.                 foreach ($this->rank_themes as $id => $theme_data)
  192.                 {
  193.                     $rank_theme_list.= '<option value="' . $id . '"' . ($rank_theme == $id ? ' selected="selected"' : '') . '>' . $theme_data['rtheme_title'] . '</option>';
  194.                 }
  195.  
  196.                 $imglist = filelist($phpbb_root_path . $config['ranks_path'], '');
  197.                 $edit_img = $filename_list = '';
  198.  
  199.                 foreach ($imglist as $path => $img_ary)
  200.                 {
  201.                     sort($img_ary);
  202.  
  203.                     foreach ($img_ary as $img)
  204.                     {
  205.                         $img = $path . $img;
  206.  
  207.                         if ($ranks && $img == $ranks['rank_image'])
  208.                         {
  209.                             $selected = ' selected="selected"';
  210.                             $edit_img = $img;
  211.                         }
  212.                         else
  213.                         {
  214.                             $selected = '';
  215.                         }
  216.  
  217.                         if (strlen($img) > 255)
  218.                         {
  219.                             continue;
  220.                         }
  221.  
  222.                         $filename_list .= '<option value="' . htmlspecialchars($img) . '"' . $selected . '>' . $img . ((in_array($img, $existing_imgs)) ? ' ' . $user->lang['RANK_IMAGE_IN_USE'] : '') . '</option>';
  223.                     }
  224.                 }
  225.  
  226.                 $filename_list = '<option value=""' . (($edit_img == '') ? ' selected="selected"' : '') . '>----------</option>' . $filename_list;
  227.                 unset($existing_imgs, $imglist);
  228.  
  229.                 $template->assign_vars(array(
  230.                     'S_EDIT'            => true,
  231.                     'U_BACK'            => $this->u_action,
  232.                     'RANKS_PATH'        => $phpbb_root_path . $config['ranks_path'],
  233.                     'U_ACTION'          => $this->u_action . '&amp;id=' . $rank_id,
  234.  
  235.                     'RANK_TITLE'        => (isset($ranks['rank_title'])) ? $ranks['rank_title'] : '',
  236.                     'S_FILENAME_LIST'   => $filename_list,
  237.                     'RANK_IMAGE'        => ($edit_img) ? $phpbb_root_path . $config['ranks_path'] . '/' . $edit_img : $phpbb_admin_path . 'images/spacer.gif',
  238.                     'S_SPECIAL_RANK'    => (isset($ranks['rank_special']) && $ranks['rank_special']) ? true : false,
  239.                     'S_RANK_THEME_LIST' => $rank_theme_list,
  240.                     'MIN_POSTS'         => (isset($ranks['rank_min']) && !$ranks['rank_special']) ? $ranks['rank_min'] : 0)
  241.                 );
  242.                        
  243.  
  244.                 return;
  245.  
  246.             break;
  247.            
  248.             //Multi-rank theme mod: Add separate theme saving, deleting, adding and editing rather than overriding a single mode
  249.             case 'save_theme':
  250.  
  251.                 $theme_title = utf8_normalize_nfc(request_var('title', '', true));
  252.                 $theme_public = request_var('theme_public', RANK_THEME_PUBLIC);
  253.  
  254.                 if (!$theme_title)
  255.                 {
  256.                     trigger_error($user->lang['NO_RANK_THEME_TITLE'] . adm_back_link($this->u_action), E_USER_WARNING);
  257.                 }
  258.  
  259.                 if ($rank_id == DEFAULT_RANK_THEME_ID || $rank_id == SPECIAL_RANK_THEME_ID || $rank_id < 0)
  260.                 {
  261.                     trigger_error($user->lang['MUST_SELECT_RANK_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
  262.                 }
  263.  
  264.                 $sql_ary = array(
  265.                     'rtheme_title'      => $theme_title,
  266.                     'rtheme_public'     => $theme_public
  267.                 );
  268.  
  269.                 if ($rank_id)
  270.                 {
  271.                     $sql = 'UPDATE ' . RANK_THEMES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE rtheme_id = $rank_id";
  272.                     $message = $user->lang['RANK_THEME_UPDATED'];
  273.  
  274.                     add_log('admin', 'LOG_RANK_THEME_UPDATED', $theme_title);
  275.                 }
  276.                 else
  277.                 {
  278.                     $sql = 'INSERT INTO ' . RANK_THEMES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  279.                     $message = $user->lang['RANK_THEME_ADDED'];
  280.  
  281.                     add_log('admin', 'LOG_RANK_THEME_ADDED', $theme_title);
  282.                 }
  283.  
  284.                 $db->sql_query($sql);
  285.  
  286.                 $cache->destroy('_ranks');
  287.  
  288.                 trigger_error($message . adm_back_link($this->u_action));
  289.  
  290.             break;
  291.  
  292.             case 'delete_theme':
  293.                 //Don't allow deletion of special or default rank sets
  294.                 if ($rank_id == DEFAULT_RANK_THEME_ID || $rank_id == SPECIAL_RANK_THEME_ID || $rank_id < 0)
  295.                 {
  296.                     trigger_error($user->lang['MUST_SELECT_RANK_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
  297.                 }
  298.  
  299.                 if (confirm_box(true))
  300.                 {
  301.                     $sql = 'SELECT rtheme_title
  302.                         FROM ' . RANK_THEMES_TABLE . '
  303.                         WHERE rtheme_id = ' . $rank_id;
  304.                     $result = $db->sql_query($sql);
  305.                     $theme_title = (string) $db->sql_fetchfield('rtheme_title');
  306.                     $db->sql_freeresult($result);
  307.  
  308.                     $sql = 'DELETE FROM ' . RANKS_TABLE . "
  309.                         WHERE rank_theme = $rank_id";
  310.                     $db->sql_query($sql);
  311.  
  312.                     $sql = 'DELETE FROM ' . RANK_THEMES_TABLE . "
  313.                         WHERE rtheme_id = $rank_id";
  314.                     $db->sql_query($sql);
  315.  
  316.                     $sql = 'UPDATE ' . USERS_TABLE . "
  317.                         SET user_rank_theme = ".DEFAULT_RANK_THEME_ID."
  318.                         WHERE user_rank_theme = $rank_id";
  319.                     $db->sql_query($sql);
  320.  
  321.                     $cache->destroy('_ranks');
  322.  
  323.                     add_log('admin', 'LOG_RANK_THEME_REMOVED', $theme_title);
  324.  
  325.                     trigger_error($user->lang['RANK_THEME_REMOVED'] . adm_back_link($this->u_action));
  326.                 }
  327.                 else
  328.                 {
  329.                     confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
  330.                         'i'         => $id,
  331.                         'mode'      => $mode,
  332.                         'rank_id'   => $rank_id,
  333.                         'action'    => 'delete_theme',
  334.                     )));
  335.                 }
  336.  
  337.             break;
  338.  
  339.             case 'edit_theme':
  340.             case 'add_theme':
  341.  
  342.                 $theme = array();
  343.  
  344.                 $sql = 'SELECT *
  345.                     FROM ' . RANK_THEMES_TABLE . '
  346.                     WHERE rtheme_id = ' . $rank_id;
  347.                 $result = $db->sql_query($sql);
  348.  
  349.                 while ($row = $db->sql_fetchrow($result))
  350.                 {
  351.                     $theme = $row;
  352.                 }
  353.                 $db->sql_freeresult($result);
  354.  
  355.                 $template->assign_vars(array(
  356.                     'S_EDIT_THEME'      => true,
  357.                     'U_BACK'            => $this->u_action,
  358.                     'U_ACTION'          => $this->u_action . '&amp;id=' . $rank_id,
  359.                     'RANK_THEME_TITLE'  => (isset($theme['rtheme_title'])) ? $theme['rtheme_title'] : '',
  360.                     'S_RANK_THEME_PUBLIC'   => (isset($theme['rtheme_public']) && $theme['rtheme_public']) ? true : false)
  361.                 );
  362.  
  363.  
  364.                 return;
  365.  
  366.             break;
  367.            
  368.         }
  369.    
  370.         $template->assign_vars(array(
  371.             'U_ACTION'      => $this->u_action)
  372.         );
  373.  
  374.         print_r($this->rank_themes);
  375.        
  376.         $sql = 'SELECT *
  377.             FROM ' . RANKS_TABLE . '
  378.             ORDER BY rank_special DESC, rank_min ASC, rank_title ASC';
  379.         $result = $db->sql_query($sql);
  380.  
  381.         while ($row = $db->sql_fetchrow($result))
  382.         {
  383.             $ranks[$row['rank_theme']][] = $row;
  384.         }
  385.  
  386.         foreach ($this->rank_themes as $theme)
  387.         {
  388.        
  389.         print_r($theme);
  390.        
  391.             $template->assign_block_vars('themes', array(
  392.                 'RANK_THEME_TITLE'  => $theme['rtheme_title'],
  393.                 'S_THEME_PUBLIC'    => $theme['rtheme_public'],
  394.                 'U_EDIT_THEME'      => ($theme['rtheme_id'] != DEFAULT_RANK_THEME_ID && $theme['rtheme_id'] != SPECIAL_RANK_THEME_ID ? $this->u_action . '&amp;action=edit_theme&amp;id=' . $theme['rtheme_id'] : ''),
  395.                 'U_DELETE_THEME'    => ($theme['rtheme_id'] != DEFAULT_RANK_THEME_ID && $theme['rtheme_id'] != SPECIAL_RANK_THEME_ID ? $this->u_action . '&amp;action=delete_theme&amp;id=' . $theme['rtheme_id'] : '')));
  396.  
  397.             if (sizeof($ranks[$theme['rtheme_id']]) > 0)
  398.             {
  399.                 foreach ($ranks[$theme['rtheme_id']] as $row)
  400.                 {
  401.                
  402.                 print_r($row);
  403.                
  404.                     $template->assign_block_vars('themes.ranks', array(
  405.                 'S_RANK_IMAGE'      => ($row['rank_image']) ? true : false,
  406.                 'S_SPECIAL_RANK'    => ($row['rank_special']) ? true : false,
  407.  
  408.                 'RANK_IMAGE'        => $phpbb_root_path . $config['ranks_path'] . '/' . $row['rank_image'],
  409.                 'RANK_TITLE'        => $row['rank_title'],
  410.                 'MIN_POSTS'         => $row['rank_min'],
  411.  
  412.                 'U_EDIT'            => $this->u_action . '&amp;action=edit&amp;id=' . $row['rank_id'],
  413.                 'U_DELETE'          => $this->u_action . '&amp;action=delete&amp;id=' . $row['rank_id'])
  414.             ); 
  415.         }
  416.             }
  417.         }
  418.         $db->sql_freeresult($result);
  419.     }
  420.  
  421.     function load_rank_themes()
  422.    {
  423. echo "Start load_rank_themes()";
  424.       if (sizeof($this->rank_themes) > 0) {
  425. echo "Cached ".sizeof($this->rank_themes)." themes";
  426.          return;
  427.       }
  428.  
  429.       global $db, $user;
  430.  
  431.       $sql = 'SELECT * FROM ' . RANK_THEMES_TABLE. " WHERE rtheme_id > 1 ORDER BY rtheme_title";
  432. echo $sql;
  433.       $result = $db->sql_query($sql);
  434.  
  435.       $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),
  436.                            DEFAULT_RANK_THEME_ID => array('rtheme_id' => DEFAULT_RANK_THEME_ID, 'rtheme_title' => $user->lang['DEFAULT_RANK_THEME'], 'rtheme_public' => true));
  437. print_r($this->rank_themes);
  438.       while ($row = $db->sql_fetchrow($result))
  439.       {
  440. print_r($row);
  441.          $this->rank_themes[$row['rtheme_id']] = $row;
  442.       }
  443. print_r($this->rank_themes);
  444. echo "End load_rank_themes()";
  445.       $db->sql_freeresult($result);
  446.    }
  447. }
  448.  
  449. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement