Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #20  
Old 06-21-2009, 02:23 PM
orion808 orion808 is offline
 
Join Date: Dec 2006
Posts: 11
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ranks.php for vBulletin 3.8.0 Release Candidate 2
(I still need to update to the latest vBulletin)
Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vBulletin 3.8.0 Release Candidate 2 
|| # ---------------------------------------------------------------- # ||
|| # Copyright ?2000-2009 Jelsoft Enterprises Ltd. All Rights Reserved. ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('CVS_REVISION', '$RCSfile$ - $Revision: 12761 $');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
$phrasegroups = array('user', 'cpuser', 'cprank');
$specialtemplates = array();

// ########################## REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_ranks.php');

// ######################## CHECK ADMIN PERMISSIONS #######################
if (!can_administer('canadminusers'))
{
	print_cp_no_permission();
}

$vbulletin->input->clean_array_gpc('r', array('rankid' => TYPE_UINT));

// ############################# LOG ACTION ###############################
log_admin_action(!empty($vbulletin->GPC['rankid']) ? "rank id = " . $vbulletin->GPC['rankid'] : '');

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

print_cp_header($vbphrase['user_rank_manager']);


if (empty($_REQUEST['do']))
{
	$_REQUEST['do'] = 'modify';
}

// ###################### Start insert #######################
if ($_POST['do'] == 'insert')
{
	$vbulletin->input->clean_array_gpc('p', array(
		'ranklevel'   => TYPE_UINT,
		'minposts'    => TYPE_UINT,
		'rankimg'     => TYPE_STR,
		'usergroupid' => TYPE_INT,
		'doinsert'    => TYPE_STR,
		'rankhtml'    => TYPE_NOTRIM,
		'stack'       => TYPE_UINT,
		'display'     => TYPE_UINT,
		'rankorder'	  => TYPE_UNIT,
	));

	if (!$vbulletin->GPC['ranklevel'] OR (!$vbulletin->GPC['rankimg'] AND !$vbulletin->GPC['rankhtml']))
	{
		if ($vbulletin->GPC['doinsert'])
		{
			echo '<p><b>' . $vbphrase['invalid_file_path_specified'] . '</b></p>';
			$vbulletin->GPC['rankimg'] = $vbulletin->GPC['doinsert'];
		}
		else
		{
			print_stop_message('please_complete_required_fields');
		}

	}

	if ($vbulletin->GPC['usergroupid'] == -1)
	{
		$vbulletin->GPC['usergroupid'] = 0;
	}

	if (!$vbulletin->GPC['rankhtml'])
	{
		$vbulletin->GPC['rankimg'] = preg_replace('/\/$/s', '', $vbulletin->GPC['rankimg']);
		if($dirhandle = @opendir(DIR . '/' . $vbulletin->GPC['rankimg']))
		{ // Valid directory!
			readdir($dirhandle);
			readdir($dirhandle);
			while ($filename = readdir($dirhandle))
			{
				if (is_file(DIR . "/{$vbulletin->GPC['rankimg']}/" . $filename) AND (($filelen = strlen($filename)) >= 5))
				{
					$fileext = strtolower(substr($filename, $filelen - 4, $filelen - 1));
					if ($fileext == '.gif' OR $fileext == '.bmp' OR $fileext == '.jpg' OR $fileext == 'jpeg' OR $fileext == 'png')
					{
						$FileArray[] = htmlspecialchars_uni($filename);
					}
				}
			}
			if (!is_array($FileArray))
			{
				print_stop_message('no_matches_found');
			}

			print_form_header('ranks', 'insert', 0, 1, 'name', '');
			print_table_header($vbphrase['images']);
			construct_hidden_code('usergroupid', $vbulletin->GPC['usergroupid']);
			construct_hidden_code('ranklevel', $vbulletin->GPC['ranklevel']);
			construct_hidden_code('minposts', $vbulletin->GPC['minposts']);
			construct_hidden_code('rankorder', $vbulletin->GPC['rankorder']); 
			construct_hidden_code('doinsert', $vbulletin->GPC['rankimg']);
			foreach ($FileArray AS $key => $val)
			{
				print_yes_row("<img src='../" . $vbulletin->GPC['rankimg'] . "/$val' border='0' alt='' align='center' />", 'rankimg', '', '', $vbulletin->GPC['rankimg'] . "/$val");
			}
			print_submit_row($vbphrase['save']);
			closedir($dirhandle);
			exit;
		}
		else
		{ // Not a valid dir so assume it is a filename
			if (!(@is_file(DIR . '/' . $vbulletin->GPC['rankimg'])))
			{
				print_stop_message('invalid_file_path_specified');
			}
		}
		$type = 0;
	}
	else
	{
		$vbulletin->GPC['rankimg'] = $vbulletin->GPC['rankhtml'];
		$type = 1;
	}

	build_ranks();

	/*insert query*/
	$db->query_write("
		INSERT INTO " . TABLE_PREFIX . "ranks
			(ranklevel, minposts, rankimg, usergroupid, type, stack, display, rankorder)
		VALUES
			(
			" . $vbulletin->GPC['ranklevel'] . ",
			" . $vbulletin->GPC['minposts'] . ",
			'" . $db->escape_string($vbulletin->GPC['rankimg']) . "',
			" . $vbulletin->GPC['usergroupid'] . ",
			$type,
			" . $vbulletin->GPC['stack'] . ",
			" . $vbulletin->GPC['display'] . ",
			" . $vbulletin->GPC['rankorder'] . "
			)
	");

	build_ranks();

	define('CP_REDIRECT', 'ranks.php?do=modify');
	print_stop_message('saved_user_rank_successfully');
}

// ###################### Start edit #######################
if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
{

	if ($_REQUEST['do'] == 'edit')
	{
		$ranks = $db->query_first("
			SELECT *
			FROM " . TABLE_PREFIX . "ranks
			WHERE rankid = " . $vbulletin->GPC['rankid'] . "
		");
		print_form_header('ranks', 'doupdate');
	}
	else
	{
		$ranks = array(
			'ranklevel'   => 1,
			'usergroupid' => -1,
			'minposts'    => 10,
			'rankimg'     => 'images/',
		);
		print_form_header('ranks', 'insert');
	}

	if ($ranks['type'])
	{
		$ranktext = $ranks['rankimg'];
	}
	else
	{
		$rankimg = $ranks['rankimg'];
	}

	$displaytype = array(
		$vbphrase['always'],
		$vbphrase['if_displaygroup_equals_this_group'],
	);

	construct_hidden_code('rankid', $vbulletin->GPC['rankid']);
	print_table_header(construct_phrase($vbphrase['x_y_id_z'], $vbphrase['user_rank'], '', $vbulletin->GPC['rankid']));
	print_input_row($vbphrase['times_to_repeat_rank'], 'ranklevel', $ranks['ranklevel']);
	print_chooser_row($vbphrase['usergroup'], 'usergroupid', 'usergroup', $ranks['usergroupid'], $vbphrase['all_usergroups']);
	print_input_row($vbphrase['minimum_posts'], 'minposts', $ranks['minposts']);
	print_yes_no_row($vbphrase['stack_rank'], 'stack', $ranks['stack']);
	print_select_row($vbphrase['display_type'], 'display', $displaytype, $ranks['display']);
	print_table_header($vbphrase['rank_type']);
	print_input_row($vbphrase['user_rank_file_path'], 'rankimg', $rankimg);
	print_input_row($vbphrase['or_you_may_enter_text'], 'rankhtml', $ranktext);
	print_input_row('Rank Order', 'rankorder', $ranks['rankorder']);  

	print_submit_row();
}

// ###################### Start do update #######################
if ($_POST['do'] == 'doupdate')
{
	$vbulletin->input->clean_array_gpc('p', array(
		'ranklevel'   => TYPE_UINT,
		'minposts'    => TYPE_UINT,
		'rankimg'     => TYPE_STR,
		'usergroupid' => TYPE_INT,
		'rankhtml'    => TYPE_NOTRIM,
		'stack'       => TYPE_UINT,
		'display'     => TYPE_UINT,
		'rankorder'   => TYPE_UNIT,
	));

	if (!$vbulletin->GPC['ranklevel'] OR (!$vbulletin->GPC['rankimg'] AND !$vbulletin->GPC['rankhtml']))
	{
		print_stop_message('please_complete_required_fields');
	}

	if ($vbulletin->GPC['rankhtml'])
	{
		$type = 1;
		$vbulletin->GPC['rankimg'] = $vbulletin->GPC['rankhtml'];
	}
	else
	{
		$type = 0;
		if (!(@is_file(DIR . '/' . $vbulletin->GPC['rankimg'])))
		{
			print_stop_message('invalid_file_path_specified');
		}
	}

	$db->query_write("
		UPDATE " . TABLE_PREFIX . "ranks
		SET ranklevel = " . $vbulletin->GPC['ranklevel'] . ",
			minposts = " . $vbulletin->GPC['minposts'] . ",
			rankimg = '" . $db->escape_string($vbulletin->GPC['rankimg']) . "',
			usergroupid = " . $vbulletin->GPC['usergroupid'] . ",
			type = $type,
			stack = " . $vbulletin->GPC['stack'] . ",
			display = " . $vbulletin->GPC['display'] . ",
			rankorder = " . $vbulletin->GPC['rankorder'] . "
		WHERE rankid = " . $vbulletin->GPC['rankid'] . "
	");
	build_ranks();

	define('CP_REDIRECT', 'ranks.php?do=modify');
	print_stop_message('saved_user_rank_successfully');
}
// ###################### Start Remove #######################

if ($_REQUEST['do'] == 'remove')
{

	print_form_header('ranks', 'kill');
	construct_hidden_code('rankid', $vbulletin->GPC['rankid']);
	print_table_header($vbphrase['confirm_deletion']);
	print_description_row($vbphrase['are_you_sure_you_want_to_delete_this_user_rank']);
	print_submit_row($vbphrase['yes'], '', 2, $vbphrase['no']);

}

// ###################### Start Kill #######################

if ($_POST['do'] == 'kill')
{

	$db->query_write("DELETE FROM " . TABLE_PREFIX . "ranks WHERE rankid = " . $vbulletin->GPC['rankid']);
	build_ranks();

	define('CP_REDIRECT', 'ranks.php?do=modify');
	print_stop_message('deleted_user_rank_successfully');
}

// ###################### Start modify #######################
if ($_REQUEST['do'] == 'modify')
{
    $ranks = $db->query_write("
        SELECT rankid, ranklevel, minposts, rankimg, ranks. usergroupid,title, type, display, stack, rankorder
        FROM " . TABLE_PREFIX . "ranks AS ranks
        LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup USING(usergroupid)
        ORDER BY rankorder, ranks.usergroupid, minposts
    "); 

	print_form_header('', '');
	print_table_header($vbphrase['user_rank_manager']);
	print_description_row($vbphrase['user_ranks_desc'] . '<br /><br />' . 
	construct_phrase($vbphrase['it_is_recommended_that_you_update_user_titles'], $vbulletin->session->vars['sessionurl'])
	,'',0);
	print_table_footer();

	if ($db->num_rows($ranks) == 0)
	{
		print_stop_message('no_user_ranks_defined');
	}

	print_form_header('', '');
	while ($rank = $db->fetch_array($ranks))
	{
		if ($tempgroup != $rank['usergroupid'])
		{
			if (isset($tempgroup))
			{
				print_table_break();
			}
			$tempgroup = $rank['usergroupid'];

			print_table_header(iif($rank['usergroupid'] == 0, $vbphrase['all_usergroups'], $rank['title']), 6, 1);
			print_cells_row(array($vbphrase['user_rank'], $vbphrase['minimum_posts'], $vbphrase['display_type'], $vbphrase['stack_rank'], 'Rank Order', $vbphrase['controls']), 1, '', -1);
		}

		$count = 0;
		$rankhtml = '';
		while ($count++ < $rank['ranklevel'])
		{
			if (!$rank['type'])
			{
				$rankhtml .= "<img src=\"../$rank[rankimg]\" border=\"0\" alt=\"\" />";
			}
			else
			{
				$rankhtml .= $rank['rankimg'];
			}
		}

		$cell = array(
            $rankhtml,
            vb_number_format($rank['minposts']),
            ($rank['display'] ? $vbphrase['displaygroup'] : $vbphrase['always']),
            ($rank['stack'] ? $vbphrase['yes'] : $vbphrase['no']),
            vb_number_format($rank['rankorder']),
            construct_link_code($vbphrase['edit'], "ranks.php?" . $vbulletin->session->vars['sessionurl'] . "do=edit&rankid=$rank[rankid]") . construct_link_code($vbphrase['delete'], "ranks.php?" . $vbulletin->session->vars['sessionurl'] . "do=remove&rankid=$rank[rankid]")
        ); 
		print_cells_row($cell, 0, '', -1);

	}
	print_table_footer();

}

print_cp_footer();

/*======================================================================*\
|| ####################################################################
|| # Downloaded: 09:08, Thu Jan 1st 2009
|| # CVS: $RCSfile$ - $Revision: 12761 $
|| ####################################################################
\*======================================================================*/
?>
Hope this helps.

Also noticed something. My version is a working version. I haven't had any issues with it. However, there appears to be a typo. Any know if it is truly one or if it's intended?

This occurs in a couple places:
Code:
		'display'     => TYPE_UINT,
		'rankorder'   => TYPE_UNIT,
Note that it's "TYPE_UINT" vs "TYPE_UNIT". Thoughts?

--------------- Added [DATE]1245598267[/DATE] at [TIME]1245598267[/TIME] ---------------

Quote:
Originally Posted by rrudeboy View Post
thanks orion808, i did post 20, and i think i did what post 21 advised.. after doing post 21 nothing changed, so i also need to do post 24 ? did you see my screen shot of how it looks in my ACP ? how am i sure i did the add entry to my database correctly ?

there's no way you can share your working ranks.php ? with possible edits to protect sensitive information ?

again thanks...
Post 24 is responsible for showing the rankorder in your screenshot above. If it's not listed there like mine, 24 is definitely not completed.

As for the database, this is how mine looks on the ranks table. I just added another field with these values:


Hope that helps.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07832 seconds
  • Memory Usage 3,524KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (11)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (40)post_thanks_box
  • (1)post_thanks_box_bit
  • (40)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (40)post_thanks_postbit_info
  • (40)postbit
  • (40)postbit_onlinestatus
  • (40)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete