<?php
define('THIS_SCRIPT', 'plus_tools_center');
require_once 'global.php';
$lang = load_lang($lang, 'plus_tools_center' );
$stats = $lang['HtmlTitle'];
$arrNavMenu = array(
	 0=>array('linktitle'=>$lang['NavTitle1'],'linkurl'=>$lang['NavUrl1'])
	,1=>array('linktitle'=>$lang['HtmlTitle'])
);
head(1,0,0,$arrNavMenu);

if( $userid <= 0 ){
	showmsg($lang['MustLogin']);
}
if( $fsetting['plus_tools_sale'] == 0 ){
	showmsg($lang['Error.strings1']);
}

require printout('plus_tools_center.navlink');
require printout('plus_tools_center.main');

footer();

function getUserToolsCount(){
	global $db,$dv,$userid;
	$UserToolsCount = $db->scalar("SELECT SUM(toolscount) FROM {$dv}plus_tools_buss WHERE userid='{$userid}'");
	if( !is_numeric($UserToolsCount) ){
		$UserToolsCount = 0;
	}
	return $UserToolsCount;
}

function &getUserToolsList(){
	global $db,$dv,$userid;
	return $db->getResultSet("SELECT id,userid,username,toolsid,toolsname,toolscount,salecount,updatetime,salemoney,saleticket FROM {$dv}plus_tools_buss WHERE userid='{$userid}' ORDER BY toolscount DESC",array('pageSize'=>20));
}

function &getToolsList(){
	global $db,$dv,$userid,$page;
	if( !is_numeric($page) || $page <= 0 ){
		$page = 1;
	}
	$returnVal['RecordTotal'] = $db->scalar("SELECT COUNT(1) FROM {$dv}plus_tools_info");
	if( $returnVal['RecordTotal'] <= 0 ){
		return false;
	}
	$returnVal['max_rows'] = 9;
	$returnVal['page_total'] = ceil((float)$returnVal['RecordTotal']/$returnVal['max_rows']);
	if( $page > $returnVal['page_total'] ){
		$page = $returnVal['page_total'];
	}
	if( $page < 1 ){
		$page = 1;
	}
	$returnVal['page'] = $page;
	$stmt = "SELECT id,toolsname,toolsinfo,isstar,sysstock,userstock,userticket,usermoney,buytype,toolsimg FROM {$dv}plus_tools_info ORDER BY sysstock DESC";
	$returnVal['result_set'] =& $db->getResultSet($stmt,array('absolutePage'=>$returnVal['page'],'pageSize'=>$returnVal['max_rows']));
	if( $returnVal['result_set'] === false ){
		return false;
	}
	return $returnVal;
}

function &getUserBussToolsList(){
	global $dv,$db,$userid,$user_id,$page;
	$returnVal['RecordTotal'] = $db->scalar("SELECT COUNT(1) FROM {$dv}plus_tools_buss WHERE salecount>0 ".(is_numeric($user_id)&&$user_id>0?" AND userid='{$user_id}'":"")."");
	if( $returnVal['RecordTotal'] <= 0 ){
		return false;
	}
	$returnVal['max_rows'] = 20;
	$returnVal['page_total'] = ceil((float)$returnVal['RecordTotal']/$returnVal['max_rows']);
	if( $page > $returnVal['page_total'] ){
		$page = $returnVal['page_total'];
	}
	if( $page < 1 ){
		$page = 1;
	}
	$returnVal['page'] = $page;
	$stmt = "SELECT id,userid,username,toolsid,toolsname,toolscount,salecount,updatetime,salemoney,saleticket FROM {$dv}plus_tools_buss WHERE salecount>0 ".(is_numeric($user_id)&&$user_id>0?" AND userid='{$user_id}'":"")." ORDER BY SaleCount Desc";
	$returnVal['result_set'] =& $db->getResultSet($stmt,array('absolutePage'=>$returnVal['page'],'pageSize'=>$returnVal['max_rows']));
	if( $returnVal['result_set'] === false ){
		return false;
	}
	return $returnVal;
}
?>