<?php
define('THIS_SCRIPT', 'plus_tools_magiclist');
require_once 'global.php';
$lang = load_lang($lang, 'plus_tools_magiclist' );
$stats = $lang["HtmlTitle"];
$istoptable = 0;
head();
if( $userid <= 0 ){
	showmsg($lang['MustLogin'],0,'',false);
	exit;
}
if( !is_numeric($s) || ($s != 0 & $s != 1) ){
	$s = 0;
}
if( $s == 0 ){
	$strSV = $lang['template.strings1'];
} else{
	$strSV = $lang['template.strings2'];
}
require printout('plus_tools_magiclist');

function &getMagicFace(){
	global $dv,$db,$page,$s,$stype;
	$returnVal = array('RecordCount'=>-1,'PageCount'=>0,'AbsolutePage'=>1,'PageSize'=>21,'ResultSets'=>false);
	$stmt = "";
	if( $s == 0 ){
		$subFld = ',tmoney AS money,tticket AS ticket';
	} else{
		$subFld = ',imoney AS money,iticket AS ticket';
	}
	if( $stype == -2 ){
		$countStmt = "SELECT COUNT(1) FROM {$dv}plus_tools_magicface";
		$stmt = "SELECT id,title,magicface_s,magictype{$subFld},magicsetting FROM {$dv}plus_tools_magicface ORDER BY id DESC";
	} elseif( $stype == -1 ){
		$countStmt = "SELECT COUNT(1) FROM {$dv}plus_tools_magicface WHERE imoney=0 OR tmoney=0";
		$stmt = "SELECT id,title,magicface_s,magictype{$subFld},magicsetting FROM {$dv}plus_tools_magicface WHERE imoney=0 OR tmoney=0 ORDER BY id DESC";
	} else{
		$countStmt = "SELECT COUNT(1) FROM {$dv}plus_tools_magicface WHERE magictype='{$stype}'";
		$stmt = "SELECT id,title,magicface_s,magictype{$subFld},magicsetting FROM {$dv}plus_tools_magicface WHERE magictype=".$stype." ORDER BY id DESC";
	}
	$returnVal['RecordCount'] = $db->scalar($countStmt);
	if( $returnVal['RecordCount'] > 0 ){
		$returnVal['PageCount'] = ceil( (float)$returnVal['RecordCount'] / (float)$returnVal['PageSize'] );
		if( $page > $returnVal['PageCount'] ){
			$page = $returnVal['PageCount'];
		}
		if( $page < 1 ){
			$page = 1;
		}
		$returnVal['AbsolutePage'] = $page;
		$returnVal['ResultSets'] =& $db->getResultSet($stmt,array('absolutePage'=>$returnVal['AbsolutePage'],'pageSize'=>$returnVal['PageSize']));
	}
	return $returnVal;
}
?>