<?php

if(!defined('OT_ROOT')) {
	exit('Access Denied');
}



class Skin{

	// 后台参数设置
	protected $mSysArr;

	// 后台GET参数
	protected $mMudi;
	protected $mRightBody;
	protected $mNohrefStr;


	// 构造函数
	public function __construct($sysArr, $optionArr){
		$this->mSysArr		= $sysArr;
		$this->mMudi		= $optionArr['mudi'];
		$this->mRightBody	= $optionArr['rightBody'];
		$this->mNohrefStr	= $optionArr['nohrefStr'];
	}

	// 通用配置文件
	function WebConfig($judGet=false){
		$retStr = AdmTpl::WebConfig();

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	// 通用内容
	function WebCommon($judGet=false){
		global $sysAdminArr;

		$menuID	= OT::GetInt('menuID');

		if ($sysAdminArr['SA_isSubMenu'] == 1){
			$jsStr = '
				var csmID = '. $menuID .';
				try {
					if (csmID == 0){ csmID = parent.$id("currSubMenuID").value; }
				}catch (e){}
				';
		}else{
			$jsStr = '
				var csmID = 0;
				';
		}
		$retStr = '
		<noscript><iframe src="*.htm"></iframe></noscript><!-- 防止另存为 -->

		<script language="javascript" type="text/javascript">
		var timeStamp=(new Date()).getTime();
		// 调整父窗口RightContentIframe的高度
		// num：-1 不缩高度，直接调高
		function WindowHeight(num){
			'. $jsStr .'
			if (typeof(num)=="undefined"){
				try { console.log("WindowHeight[num]未定义"); }catch(e){}
				num = 0;
			}
			try {
				/* if (navigator.userAgent.indexOf("Firefox") >= 0){
					if ((new Date()).getTime() < timeStamp+1000 && num > -1){
						parent.$id("RightFrm"+ csmID).style.height = 5000 +"px";
						try { console.log( "Firefox内容框"+ csmID +"高度：5000px" ); }catch(e){}
					}
				}else if (navigator.userAgent.indexOf("Chrome") >= 0){
					if ((new Date()).getTime() < timeStamp+1000 && num > -1){
						parent.$id("RightFrm"+ csmID).style.height = "600px";
						// try { console.log( "Chrome内容框"+ csmID +"高度：600px" ); }catch(e){}
					}
				} */
				if (num < 0){ num = 0; }

				var stepHeight = 10;
				var minHeight = 300;
				var currFrmHeight = (document.body.scrollHeight < minHeight ? minHeight : document.body.scrollHeight);
				
				var tempHeight = currFrmHeight;
				var tempJud = false;
				while (currFrmHeight > 500 && tempJud == false){
					tempHeight = tempHeight - stepHeight;
					parent.$id("RightFrm"+ csmID).style.height = tempHeight +"px";
					var newTemp = document.body.scrollHeight;
					if (newTemp > tempHeight){
						tempJud = true;
						currFrmHeight = newTemp;
					}
				}
				var currFrmHeight = currFrmHeight + num;
				parent.$id("RightFrm"+ csmID).style.height = currFrmHeight +"px";
				// try { console.log( "内容框"+ csmID +"高度："+ currFrmHeight +"px" ); }catch(e){}

				// if (num > -1){
					$id("currIframeHeight").value = currFrmHeight;
					// try { console.log( "currIframeHeight值："+ currFrmHeight +"" ); }catch(e){}
				// }
			}catch (e){
				try { console.log( "RightFrm"+ csmID +"框架调整高度出错" ); }catch(e){}
			}

			try {
				parent.StartCalcTime();
			}catch (e){}
		}
		</script>

		<iframe id="DataDeal" name="DataDeal" src="about:blank" width="0" height="0" style="display:none"></iframe>
		<input type="hidden" id="currIframeHeight" name="currIframeHeight" value="0" />
		
		<div id="divAlert" class="divAlert" style="display:none;"></div><!-- 浮层警示框 -->
		';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	// 页头通用
	function WebTop($title='',$bodyStr='', $judGet=false){
		$retStr = '
		<!DOCTYPE html>
		<html>
		<head>
			<title>'. $title .'</title>
			'. $this->WebConfig(true) .'
		</head>
		';
		if ($bodyStr != ''){
			$retStr .= '<body '. $bodyStr .'>';
		}elseif (in_array($this->mMudi,array('show','show2','selectFile','meihua','userManage')) || $this->mNohrefStr == 'close'){
			$retStr .= '<body '. $bodyStr .'>';
		}else{
			$retStr .= $this->mRightBody;
		}
		$retStr .= $this->WebCommon(true);

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	// 页尾通用
	function WebBottom($judGet=false){
		$retStr = '
		<div class="clr"></div>
		<div style="height:40px;">&ensp;</div>
		</body></html>
		';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}


	// *****      通用表格框架 START     *****
	function TableTopId($str){
		static $STTCInum=1;
		$STTCInum ++;
		if ($str==''){
			return 'STTCInull'. $STTCInum;
		}else{
			return $str;
		}
	}

	function TableTop($img, $IDname, $CNname, $judGet=false){
		$retStr = AdmTpl::TableTop($img, $IDname, $CNname);

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	function TableBottom($judGet=false){
		$retStr = '
		</td></tr>
		<tr><td style="height:11px;" class="tabColorB" colspan="20"></td></tr>
		</table>
		';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	function TableTop2($img, $IDname, $CNname, $judGet=false){
		$retStr = AdmTpl::TableTop2($img, $IDname, $CNname);

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	function TableItemTitle($perSZ, $nameSZ, $judGet=false){
		$perSZ	= explode(',',$perSZ);
		$nameSZ	= explode(',',$nameSZ);
		$perCount = count($perSZ);

		$retStr = '<tr class="tabColor1">';
		for ($i=0; $i<$perCount; $i++){
			if ($i == 0){ $classStr = 'border1_1'; }else{ $classStr = 'border1_2'; }
			$retStr .= '<td width="'. $perSZ[$i] .'" align="center" class="'. $classStr .' font1_2" style="padding:5px">'. $nameSZ[$i] .'</td>';
		}
		$retStr .= '</tr>';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	function TableTitleArr($itemArr, $judGet=false){
		$retStr = '';
		if (isset($itemArr[0]['width']) && isset($itemArr[0]['name'])) {
			$key0 = 'width';
			$key1 = 'name';
		}else{
			$key0 = 0;
			$key1 = 1;
		}
		foreach ($itemArr as $val){
			if (strlen($retStr) == 0){ $classStr = 'border1_1'; }else{ $classStr = 'border1_2'; }
			$retStr .= '<td width="'. $val[$key0] .'" align="center" class="'. $classStr .' font1_2" style="padding:5px">'. $val[$key1] .'</td>';
		}
		$retStr = '<tr class="tabColor1">'. $retStr .'</tr>';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	function TableNoData($str='暂无内容', $judGet=false){
		$retStr = '<tr><td style="padding:8px;background" colspan="30" class="font2_1" align="center">'. $str .'</td></tr>';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}

	function TableBottom2($pageCount, $pageSize, $recordCount, $judGet=false){
		$retStr = '
		<tr class="tabColor2"><td style="height:3px;" colspan="30"></td></tr>
		</table><a name="tabBottom"></a>
		<script language="javascript" type="text/javascript">
		if ($id("tabToBottomBtn")){ $id("tabToBottomBtn").style.display = ""; }
		</script>

		<table style="width:99%;" align="center" cellpadding="0" cellspacing="0" border="0" summary="">
		<tr><td>
			'. $this->ShowNavigation('?mudi='. $this->mMudi, $pageCount, $pageSize, $recordCount, 'img', true) .'
		</td></tr>
		</table>
		';

		if ($judGet){
			return $retStr;
		}else{
			echo($retStr);
		}
	}
	//*****         通用表格框架 END      *****



	// 检查是否在框架中
	function CheckIframe(){
		if ($this->mNohrefStr == 'close2'){
			if(empty($_SERVER['HTTP_REFERER']) || preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) !== preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])){
				echo('
				<center style="padding:10px;">
					<div style="width:500px; padding:6px; border:1px red dashed; color:red; font-size:13px">
						由于你打开浏览器的多窗口（强制在新标签中打开链接）功能，<br />
						导致该页面脱离框架，部分功能将失效和无法使用！<br />
						建议你关闭浏览器的多窗口功能来使用该网站后台.
					</div>
				</center>
				');
			}
		}
	}


	// 显示箭头
	// menuName:菜单名称；str:显示箭头的值，str2:与str值对比；sort:上/下箭头；
	function ShowArrow($menuName,$str,$str2,$sort){
		$arrowStr = '';
		$URL = OT::GetParam(array('orderName','orderSort'), array('orderName'=>$str));
		if ($str==$str2){
			if ($sort=='ASC'){
				$URL .= '&amp;orderSort=DESC';
				$arrowStr = '<small>▲</small>';
			}else{
				$URL .= '&amp;orderSort=ASC';
				$arrowStr = '<small>▼</small>';
			}
		}else{
			$URL .= '&amp;orderSort=ASC';
		}
		return '<a href="'. $URL .'" class="font1_2">'. $menuName . $arrowStr .'</a>';
	}


	// 提示框
	function TishiBox($tishiStr,$tishiStr2=''){
		static $tishiNum = 0;
		$tishiNum ++;

		if (strlen($tishiStr2) == 0){ $tishiStr2 = $tishiStr; }
		return '<img src="images/img_tishi3.gif" alt="'. $tishiStr .'" title="'. $tishiStr .'" style="cursor:pointer;" align="center" onclick=\'if ($id("tishiStr'. $tishiNum .'").style.display==""){$id("tishiStr'. $tishiNum .'").style.display="none";}else{$id("tishiStr'. $tishiNum .'").style.display="";}\' /><span id="tishiStr'. $tishiNum .'" style="color:red;display:none;">('. $tishiStr2 .')</span>';
	}


	// 获取不到远程授权页面内容提示框
	function PaySoftBox($idStr,$contStr,$isShow=false,$isGet=false){
		$retStr = '
			<table id="'. $idStr .'" style="display:'. ($isShow?'':'none') .';" cellpadding="0" cellspacing="0" summary="" class="padd3">
			<tr><td class="tabLeftWidth"></td><td></td></tr>
			<tr>
				<td align="right">原因：</td>
				<td>'. $contStr .'</td>
			</tr>
			</table>		
			';
		if ($isGet){
			return $retStr;
		}else{
			echo $retStr;
		}
	}


	// 内网模式提示语（废弃 TixingLan()代替）
	function LanPaySoft(){
		return '内网模式不加载.';
	}

	// 提示语_内网模式
	function TixingLan(){
		return '内网模式不加载.';
	}

	// 提示语_没相应插件
	function TixingNoApp($str){
		return '您尚未购买【<span style="color:red;">'. $str .'</span>】插件，无法使用该功能。';
	}

	// 提示语_没字体
	function TixingNoFont(){
		return '尚未找到字体，请到【管理员区→程序文件检查 - 可选文件下载】下载字体，或自行到网络下载字体放到 tools/simsun.ttc（扩展名也可以otf、ttf）。';
	}

	// 提示语_没获取远程信息
	function TixingNoGet($str){
		$retStr = '未知原因（'. $str .'）';
		if (strpos($str,'<!-- noRemote -->') !== false){
			$retStr = '无法访问外网';
		}elseif (strpos($str,'<!-- noUse -->') !== false){
			$retStr = '授权禁用';
		}
		return '因'. $retStr .'而无法使用';
	}


	//导航
	function ShowNavigation($URL, $pageCount, $pageSize, $recordCount, $skin, $judGet=false){
		//页码风格
		switch($skin){
			case 'zn':
				$first_page='[第一页]';
				$prev_page='[上一页]';
				$next_page='[下一页]';
				$last_page='[最后页]';
				break;
			case 'img':
				$first_page='<img src="images/right_narStart.gif" border="0" alt="" />';
				$prev_page='<img src="images/right_narLast.gif" border="0" alt="" />';
				$next_page='<img src="images/right_narNext.gif" border="0" alt="" />';
				$last_page='<img src="images/right_narEnd.gif" border="0" alt="" />';
				break;
			default:
				$first_page='<span style="font-family:webdings;">9</span>';
				$prev_page='<span style="font-family:webdings;">7</span>';
				$next_page='<span style="font-family:webdings;">8</span>';
				$last_page='<span style="font-family:webdings;">:</span>';
				break;
		}

		$URL = OT::GetParam(array('page'));

		$page=intval(@$_GET['page']);

		$retStr = '
		<table style="width:100%;border:1px #dadada solid;border-top:none;" cellpadding="0" cellspacing="0" border="0" summary="">
		<tr>
			<td align="center" class="tabColorB padd5">';

		if ($page<1 || $page>$pageCount){$page=1;}
			$retStr .= '<span class="font1_2">第'. $page .'页/共'. $pageCount .'页　　共'. $recordCount .'条记录</span>　　';

		if ($page<=1){
			$retStr .= '
			<span class="font1_2d">'. $first_page .'</span>&ensp;
			<span class="font1_2d">'. $prev_page .'</span>';
		}else{
			$retStr .= '
			<a href="'. $URL .'&page=1" class="font1_2">'. $first_page .'</a>&ensp;
			<a href="'. $URL .'&page='. ($page - 1) .'" class="font1_2">'. $prev_page .'</a>';
		}

		$retStr .= '&ensp;';

		if ($pageCount <= 7){
			$startpage = 1;
			$endpage = $pageCount;
		}elseif ($page-3 >= 1 && $page+3 <= $pageCount){
			$startpage = $page-3;
			$endpage = $page+3;
		}elseif ($page-3 < 1){
			$startpage = 1;
			$endpage = 7;
		}elseif ($page+3 > $pageCount){
			$startpage = $pageCount-6;
			$endpage = $pageCount;
		}
		
		for ($i=$startpage; $i<=$endpage; $i++){
			if ($i == $page){
				$retStr .= '<span class="font2_2">'. $i .'</span>&ensp;';
			}else{
				$retStr .= '<a class="font1_2" href="'. $URL .'&page='. $i .'">'. $i .'</a>&ensp;';
			}
		}

		if ($page >= $pageCount){
			$retStr .= '
			<span class="font1_2d">'. $next_page .'</span>&ensp;
			<span class="font1_2d">'. $last_page .'</span>';
		}else{
			$retStr .= '
			<a href="'. $URL .'&page='. ($page + 1) .'" class="font1_2">'. $next_page .'</a>&ensp;
			<a href="'. $URL .'&page='. $pageCount .'" class="font1_2">'. $last_page .'</a>';
		}

		if ($pageCount<100){
			$retStr .= '　<select onchange=\'if(this.value!=""){document.location.href="'. $URL .'&amp;page="+ this.value}\'><option value="">&ensp;</option>';
				for ($i=1; $i<=$pageCount; $i++){
			$retStr .= '<option value="'. $i .'">'. $i .'</option>';
				}
			$retStr .= '</select>';
		}else{
			$retStr .= '　<input type="text" id="goPageNum" name="goPageNum" size="2" style="width:50px;" value="" onkeyup=\'if (this.value!=FiltInt(this.value)){this.value=FiltInt(this.value)}\' /><input type="button" value="GO" onclick=\'if ($id("goPageNum").value==""){alert("请输入要跳转的页码.");$id("goPageNum").focus();}else{document.location.href="'. $URL .'&amp;page="+ $id("goPageNum").value}\' />';
		}


		$retStr .= '
			</td>
			<td style="padding:5px" align="center" class="tabColorB">
				<form name="itemNumForm" method="post" action="admin_cl.php?mudi=itemNum">
				<script language="javascript" type="text/javascript">document.write (\'<input type="hidden" name="itemNumURL" value="\'+ document.location.href +\'" />\')</script>
				每页显示记录数：<input type="text" id="itemNum" name="itemNum" size="2" style="width:55px;" value="'. $pageSize .'" onKeyDown="if(event.keyCode==13) {$id(\'itemBtn\').click();return false;};"/>
				&ensp;<input type="button" value="保存" id="itemBtn" onclick=\'document.location.href="admin_cl.php?mudi=itemNum&itemNum="+ $id("itemNum").value +"&itemNumURL="+ encodeURIComponent(document.location.href)\' />
				</form>
			</td>
		</tr>
		</table>
		';

		if ($judGet){
			return $retStr;
		}else{
			echo $retStr;
		}
	}

	// 显示必填标志
	public static function RedSign($num=true){
		if ($num){ return '<span style="color:red;">*</span>&ensp;'; }
	}

	// 显示插件标志
	public static function PluSign($str='',$align='top'){
		return '<img src="images/img_plugin.png" title="'. $str .' 插件" alt="'. $str .' 插件" align="'. $align .'" />&ensp;';
	}

	// 显示插件标志2
	public static function PluSign0($str='',$align='top'){
		return '<img src="images/img_plugin0.png" title="'. $str .' 插件" alt="'. $str .' 插件" align="'. $align .'" />&ensp;';
	}

	// 显示电脑版标志
	public static function ImgPc(){
		return '<img src="images/imgPc.gif" title="电脑版" alt="电脑版" align="top" />&ensp;';
	}

	// 显示手机版标志
	public static function ImgWap(){
		return '<img src="images/imgWap.gif" title="手机版" alt="手机版" align="top" />&ensp;';
	}

	// 颜色选择器
	public static function ColorBox($mode,$valueId,$styleId){
		return '<img src="images/img_color.gif" style="cursor:pointer; margin:3px; vertical-align:top;" onclick=\'OT_OpenColor("'. $mode .'","'. $valueId .'","'. $styleId .'");\' alt="选择颜色" />';
	}

	// 明码/暗码 切换按钮
	public static function HiCodeBtn($idName){
		return '<input type="button" id="'. $idName .'Btn" value="明码" onclick=\'PwdTextBtn("'. $idName .'")\' />';
	}

	// 项目区头部
	public static $len1 = 0;
	public static $len2 = 0;
	public static $width1 = 10;
	public static $width2 = 20;
	public static function ItemTrTop($str1,$str2=''){
		if (strlen($str2) > 0){
			$str1 = '【'. $str1;
			$str2 .= '】';
		}else{
			$str1 = '【'. $str1 .'】';
		}
		self::$len1 = ceil(Str::ClacStrWidth($str1)/2);
		self::$len2 = ceil(Str::ClacStrWidth($str2)/2);
		return '
			<tr>
				<td align="right" class="itemArea" style="padding-right:0px;">
					┏'. str_repeat('━', self::$width1 - self::$len1) .'<b>'. str_replace(' ','&ensp;',$str1) .'</b>
				</td>
				<td align="left" class="itemArea" style="padding-left:0px;">
					<b>'. str_replace(' ','&ensp;',$str2) .'</b>'. str_repeat('━', self::$width2 - self::$len2) .'┓
				</td>
			</tr>
			';
	}

	// 项目区尾部  self::$len1
	public static function ItemTrBottom(){
		return '
			<tr>
				<td align="right" class="itemArea" style="padding-right:0px;">
					┗'. str_repeat('━', self::$width1) .'
				</td>
				<td align="left" class="itemArea" style="padding-left:0px;">
					'. str_repeat('━', self::$width2) .'┛
				</td>
			</tr>
			';
	}

}