<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：QQ877873666
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop();

echo('
<script language="javascript" type="text/javascript" src="js/inc/list.js?v='. OT_VERSION .'"></script>
<script language="javascript" type="text/javascript" src="js/type.js?v='. OT_VERSION .'"></script>
');


$MB->IsSecMenuRight('alertBack',300,$dataType);

switch ($mudi){
	case 'add': case 'rev':
		AddOrRev();
		break;

	case 'manage':
		manage();
		break;

	default:
		die('err');
}

$skin->WebBottom();

$MB->Close();
$DB->Close();





// 新增、修改信息
function AddOrRev(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN;

	$dataMode		= OT::GetStr('dataMode');
	$dataModeStr	= OT::GetStr('dataModeStr');
	$backURL		= OT::GetStr('backURL');
	$dataID			= OT::GetInt('dataID');

	if ($mudi == 'rev'){
		$revexe=$DB->query('select * from '. OT_dbPref .'xingwaiServ where XS_ID='. $dataID);
			if (! $row = $revexe->fetch()){
				JS::AlertBackEnd('无该记录！');
			}
			$XS_num			= $row['XS_num'];
			$XS_theme		= $row['XS_theme'];
			$XS_useArea		= $row['XS_useArea'];
			$XS_isSel		= $row['XS_isSel'];
			$XS_startNum	= $row['XS_startNum'];
			$XS_maxNum		= $row['XS_maxNum'];
			$XS_rank		= $row['XS_rank'];
			$XS_state		= $row['XS_state'];
		unset($revexe);

		$mudiCN='修改';
	}else{
		$XS_num			= '';
		$XS_theme		= '';
		$XS_useArea		= '';
		$XS_isSel		= '';
		$XS_startNum	= '';
		$XS_maxNum		= '';
		$XS_rank		= intval($DB->GetOne('select max(XS_rank) from '. OT_dbPref .'xingwaiServ'))+10;
		$XS_state		= 1;

		$mudiCN='添加';
	}

	echo('
	<form id="dealForm" name="dealForm" method="post" action="xingwaiServ_deal.php?mudi='. $mudi .'&nohrefStr=close" onsubmit="return CheckForm()">
	<input type="hidden" id="dataID" name="dataID" value="'. $dataID .'" />
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataMode" name="dataMode" value="'. $dataMode .'" />
	<input type="hidden" id="dataModeStr" name="dataModeStr" value="'. $dataModeStr .'" />
	'. Area::BackUrlInput($backURL) .'
	');

	$skin->TableTop('share_'. $mudi .'.gif','',$mudiCN . $dataTypeCN);
		echo('
		<table width="98%" align="center" cellpadding="0" cellspacing="0" summary="" class="padd3">
		<tr>
			<td width="12%"></td>
			<td width="88%"></td>
		</tr>
		<tr>
			<td align="right">星外编号：</td>
			<td align="left">
				<input type="text" id="num" name="num" size="50" style="width:50px;" value="'. $XS_num .'" />
			</td>
		</tr>
		<tr>
			<td align="right">'. Skin::RedSign() .'母机名称：</td>
			<td align="left">
				<input type="text" id="theme" name="theme" size="50" style="width:400px;" value="'. Str::MoreReplace($XS_theme,'input') .'" />
			</td>
		</tr>
		<tr>
			<td align="right" valign="top" style="padding-top:6px;">'. Skin::RedSign() .'使用范围：</td>
			<td align="left">
				<fieldset style="padding:10px;"><legend class="font2_1">&ensp;云服务器&ensp;</legend>
				');

				$loadexe = $DB->query('select VAD_ID,VAD_theme from '. OT_dbPref .'vpsApiData where VAD_apiID in (1,6) order by VAD_rank ASC');
				while ($row = $loadexe->fetch()){
					echo('
					<div style="float:left;width:200px;padding:2px;"><label><input type="checkbox" name="useArea[]" value="[vpsApi'. $row['VAD_ID'] .']'. $row['VAD_theme'] .'" '. Is::InstrChecked($XS_useArea,'[vpsApi'. $row['VAD_ID'] .']') .' />'. $row['VAD_theme'] .'</label></div>
					');
				}

				echo('
				</fieldset>
				');

				if (AppDialing::Jud()){
					echo('
					<fieldset style="padding:10px;margin-top:8px;"><legend class="font2_1">&ensp;拨号VPS&ensp;</legend>
					');
					$loadexe = $DB->query('select DD_ID,DD_theme from '. OT_dbPref .'dialingData where DD_apiID in (1,6) order by DD_rank ASC');
					while ($row = $loadexe->fetch()){
						echo('
						<div style="float:left;width:200px;padding:2px;"><label><input type="checkbox" name="useArea[]" value="|dialing'. $row['DD_ID'] .'|" '. Is::InstrChecked($XS_useArea,'|dialing'. $row['DD_ID'] .'|') .' />'. $row['DD_theme'] .'</label></div>
						');
					}
					echo('
					</fieldset>
					');
				}
			echo('
			</td>
		</tr>
		<tr>
			<td align="right">初始化数量：</td>
			<td align="left"><input type="text" id="startNum" name="startNum" size="50" style="width:50px;" value="'. $XS_startNum .'" /></td>
		</tr>
		<tr>
			<td align="right">最大数量：</td>
			<td align="left"><input type="text" id="maxNum" name="maxNum" size="50" style="width:50px;" value="'. $XS_maxNum .'" /></td>
		</tr>
		<tr>
			<td align="right">排序：</td>
			<td align="left"><input type="text" id="rank" name="rank" size="50" style="width:50px;" value="'. $XS_rank .'" /></td>
		</tr>
		<tr>
			<td align="right">默认值：</td>
			<td align="left">
				<label><input type="radio" name="isSel" value="1" '. Is::Checked($XS_isSel,1) .' />启用</label>&ensp;&ensp;
				<label><input type="radio" name="isSel" value="0" '. Is::Checked($XS_isSel,0) .' />禁用</label>&ensp;&ensp;
			</td>
		</tr>
		<tr>
			<td align="right">状态：</td>
			<td align="left">
				<label><input type="radio" name="state" value="1" '. Is::Checked($XS_state,1) .' />显示</label>&ensp;&ensp;
				<label><input type="radio" name="state" value="0" '. Is::Checked($XS_state,0) .' />隐藏</label>&ensp;&ensp;
			</td>
		</tr>
		</table>
		');

	$skin->TableBottom();

	echo('
	<table style="height:16px;" cellpadding="0" cellspacing="0" summary=""><tr><td></td></tr></table>

	<center><input type="image" src="'. AdmTpl::ImgSrc('button_'. $mudi) .'" /></center>

	</form>
	');

	if ($mudi == 'rev'){
		echo('<br /><center><span onclick="history.back();" class="font2_1 pointer">【返回】</span></center>');
	}
}



function manage(){
	global $DB,$MB,$skin,$mudi,$dataType,$dataTypeCN,$pageCount,$recordCount;

	$dataMode	= OT::GetStr('dataMode');
	$dataModeStr= OT::GetStr('dataModeStr');

	echo('
	<div class="padd5">
		<div style="float:right;padding:0 5px;">
			'. AppIdcServ::XingwaiServItem() .'
			<span style="color:red;">该功能主要用于星外类接口和网钛IDC接口，如果你不懂这块，不要设置。</span>
		</div>
		<input type="button" value="新增母机记录" onclick=\'document.location.href="xingwaiServ.php?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&backURL="+ encodeURIComponent(document.location.href) +"";\' />&ensp;&ensp;&ensp;&ensp;
	</div>
	');

	$skin->TableTop2('share_list.gif','',$dataTypeCN .'管理');
	$skin->TableItemTitle('5%,6%,16%,40%,5%,5%,5%,5%,5%,8%','编号,星外编号,母机名称,使用范围,初始,最大,排序,默认值,状态,修改　删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit("select * from ". OT_dbPref ."xingwaiServ order by XS_rank ASC",$pageSize,$page);
	if (! $showRow){
		// $skin->TableNoData();
	}else{
		$recordCount=$DB->GetRowCount();
		$pageCount=ceil($recordCount/$pageSize);
		if ($page < 1 || $page > $pageCount){$page=1;}

		echo('
		<tbody class="tabBody padd3td">
		');
		$number=1+($page-1)*$pageSize;
		$rowCount = count($showRow);
		for ($i=0; $i<$rowCount; $i++){
			if ($i % 2 == 1){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }

			echo('
			<tr id="data'. $showRow[$i]['XS_ID'] .'" '. $bgcolor .'>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['XS_num'] .'</td>
				<td align="center">'. $showRow[$i]['XS_theme'] .'</td>
				<td align="left" style="line-height:1.4;">'. str_replace(',','<span style="color:red;">、</span>',preg_replace("/\[([a-zA-Z]+)[^\]]*\]/si",'',$showRow[$i]['XS_useArea'])) .'</td>
				<td align="center">'. $showRow[$i]['XS_startNum'] .'</td>
				<td align="center">'. $showRow[$i]['XS_maxNum'] .'</td>
				<td align="center">'. $showRow[$i]['XS_rank'] .'</td>
				<td align="center">'. Adm::SwitchBtn('xingwaiServ',$showRow[$i]['XS_ID'],$showRow[$i]['XS_isSel'],'isSel') .'</td>
				<td align="center">'. Adm::SwitchBtn('xingwaiServ',$showRow[$i]['XS_ID'],$showRow[$i]['XS_state'],'state') .'</td>
				<td align="center">
					<!-- <img src="images/img_rev.gif" style="cursor:pointer;" onclick=\'DataDeal.location.href="xingwaiServ_deal.php?mudi=send&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataID='. $showRow[$i]['XS_ID'] .'&typeNum='. $number .'"\' alt="" />&ensp;&ensp; -->
					<img src="images/img_rev.gif" class="pointer" onclick=\'document.location.href="xingwaiServ.php?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&dataModeStr='. $dataModeStr .'&dataID='. $showRow[$i]['XS_ID'] .'&typeNum='. $number .'&backURL="+ encodeURIComponent(document.location.href) +""\' alt="修改" />&ensp;&ensp;
					<img src="images/img_del.gif" style="cursor:pointer;" onclick=\'if(confirm("确定删除？")==true){DataDeal.location.href="xingwaiServ_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['XS_theme']) .'&dataID='. $showRow[$i]['XS_ID'] .'"}\' alt="" />
				</td>
			</tr>
			');
		$number ++;
		}
		echo('
		</tbody>
		');
	}
	unset($showRow);
	
	/*
	echo('
	<form method="post" id="dealForm" name="dealForm" action="xingwaiServ_deal.php?mudi=add" onsubmit="return CheckForm(this)">
	<script language="javascript" type="text/javascript">document.write(\'<input type="hidden" name="backURL" value="\'+ document.location.href +\'">\')</script>
	<input type="hidden" id="dataType" name="dataType" value="'. $dataType .'" />
	<input type="hidden" id="dataTypeCN" name="dataTypeCN" value="'. $dataTypeCN .'" />
	<input type="hidden" id="dataID" name="dataID" value="0" />
	<tr>
		<td id="numID" align="center"><br /></td>
		<td align="center"><input type="text" id="num" name="num" size="5" /></td>
		<td align="center"><input type="text" id="theme" name="theme" size="25" /></td>
		<td align="center"><input type="text" id="rank" name="rank" size="3" value="'. (intval($DB->GetOne("select max(XS_rank) from ". OT_dbPref ."xingwaiServ"))+10) .'" onkeyUp="this.value=FiltInt(this.value)" /></td>
		<td align="center"><select id="state" name="state"><option value="1">显示</option><option value="0">隐藏</option></select></td>
		<td align="center"><input id="subButton" type="image" src="'. AdmTpl::ImgSrc('button_add') .'" /></td>
	</tr>
	</form>
	');
	*/

	$skin->TableBottom2($pageCount, $pageSize, $recordCount);

}

?>