<?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/vpsApi.js?v='. OT_VERSION .'"></script>
');


switch ($mudi){
	case 'add': case 'rev':
		$MB->IsSecMenuRight('alertBack',300,$dataType);
		AddOrRev();
		break;

	case 'manage':
		$MB->IsSecMenuRight('alertBack',300,$dataType);
		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');

	$vpsSysArr = Cache::PhpFile('vpsSys');

	if ($mudi=='rev'){
		$revexe=$DB->query('select * from '. OT_dbPref .'vpsApi where VA_ID='. $dataID);
		if (! $row = $revexe->fetch()){
			JS::AlertBackEnd('无该记录！');
		}
		$VA_theme			= $row['VA_theme'];
		$VA_rateDay			= floatval($row['VA_rateDay']);
		$VA_rateWeek		= floatval($row['VA_rateWeek']);
		$VA_rateMonth		= floatval($row['VA_rateMonth']);
		$VA_rate3Month		= floatval($row['VA_rate3Month']);
		$VA_rate6Month		= floatval($row['VA_rate6Month']);
		$VA_rateYear		= floatval($row['VA_rateYear']);
		$VA_rate2Year		= floatval($row['VA_rate2Year']);
		$VA_rate3Year		= floatval($row['VA_rate3Year']);
		$VA_rate4Year		= floatval($row['VA_rate4Year']);
		$VA_rate5Year		= floatval($row['VA_rate5Year']);
		$VA_note			= $row['VA_note'];
		$VA_rank			= $row['VA_rank'];
		$VA_state			= $row['VA_state'];
		unset($revexe);

		$mudiCN='修改';
	}else{
		$VA_theme			= '';
		$VA_rateDay			= '';
		$VA_rateWeek		= '';
		$VA_rateMonth		= '';
		$VA_rate3Month		= '';
		$VA_rate6Month		= '';
		$VA_rateYear		= '';
		$VA_rate2Year		= '';
		$VA_rate3Year		= '';
		$VA_rate4Year		= '';
		$VA_rate5Year		= '';
		$VA_note			= '';
		$VA_rank			= intval($DB->GetOne('select max(VA_rank) from '. OT_dbPref .'vpsApi'))+10;
		$VA_state			= 1;

		$mudiCN='添加';
	}

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

	$addiItem = '';
	if ($dataID == 1){
		$addiItem = '
			<tr>
				<td align="right" valign="top" style="padding-top:6px;">默认费率：</td>
				<td align="left" style="line-height:2;">
					&ensp;&ensp;日付费率：<input type="text" id="rateDay" name="rateDay" size="50" style="width:60px;" value="'. $VA_rateDay .'" />&ensp;&ensp;
					&ensp;&ensp;周付费率：<input type="text" id="rateWeek" name="rateWeek" size="50" style="width:60px;" value="'. $VA_rateWeek .'" />&ensp;&ensp;
					<br />
					&ensp;&ensp;月付费率：<input type="text" id="rateMonth" name="rateMonth" size="50" style="width:60px;" value="'. $VA_rateMonth .'" />&ensp;&ensp;
					&ensp;&ensp;季付费率：<input type="text" id="rate3Month" name="rate3Month" size="50" style="width:60px;" value="'. $VA_rate3Month .'" />&ensp;&ensp;
					半年付费率：<input type="text" id="rate6Month" name="rate6Month" size="50" style="width:60px;" value="'. $VA_rate6Month .'" />&ensp;&ensp;
					&ensp;&ensp;年付费率：<input type="text" id="rateYear" name="rateYear" size="50" style="width:60px;" value="'. $VA_rateYear .'" />&ensp;&ensp;
					<br />
					二年付费率：<input type="text" id="rate2Year" name="rate2Year" size="50" style="width:60px;" value="'. $VA_rate2Year .'" />&ensp;&ensp;
					三年付费率：<input type="text" id="rate3Year" name="rate3Year" size="50" style="width:60px;" value="'. $VA_rate3Year .'" />&ensp;&ensp;
					四年付费率：<input type="text" id="rate4Year" name="rate4Year" size="50" style="width:60px;" value="'. $VA_rate4Year .'" />&ensp;&ensp;
					五年付费率：<input type="text" id="rate5Year" name="rate5Year" size="50" style="width:60px;" value="'. $VA_rate5Year .'" />&ensp;&ensp;
					<div class="font2_2">说明：费率得与上级系统的费率一致，否则会开通不了。</div>
				</td>
			</tr>
			';
	}
	$skin->TableTop('share_'. $mudi .'.gif','',$mudiCN . $dataTypeCN);
		echo('
		<table width="98%" align="center" cellpadding="0" cellspacing="0" summary="" class="padd3td">
		<tr>
			<td width="160"></td>
			<td></td>
		</tr>
		<tr>
			<td align="right">'. Skin::RedSign() .'接口名称：</td>
			<td align="left">
			');
			if ($mudi=='rev'){
				echo($VA_theme);
			}else{
				echo('<input type="text" id="theme" name="theme" size="50" style="width:200px;" value="'. $VA_theme .'" />');
			}
			echo('
			</td>
		</tr>
		'. $addiItem .'
		<tr>
			<td align="right" valign="top" style="padding-top:6px;">备注：</td>
			<td align="left">
				<textarea id="note" name="note" style="width:400px;height:60px;">'. $VA_note .'</textarea>
			</td>
		</tr>
		</tbody>
		<tr>
			<td align="right">排序：</td>
			<td align="left"><input type="text" id="rank" name="rank" size="50" style="width:30px;" value="'. $VA_rank .'" /></td>
		</tr>
		<tr>
			<td align="right">状态：</td>
			<td align="left">
				<label><input type="radio" name="state" value="1" '. Is::Checked($VA_state,1) .' />显示</label>&ensp;&ensp;&ensp;&ensp;
				<label><input type="radio" name="state" value="0" '. Is::Checked($VA_state,0) .' />隐藏</label>&ensp;&ensp;&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>
	');
}



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

	echo('
	<!-- <div style="padding:6px;">
		<input type="button" value="母机列表设置" onclick=\'document.location.href="xingwaiServ.php?mudi=manage&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&backURL="+ encodeURIComponent(document.location.href);\' />&ensp;&ensp;
		<input type="button" value="景安测试码管理" onclick=\'document.location.href="jinganCode.php?mudi=manage&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&backURL="+ encodeURIComponent(document.location.href);\' />&ensp;&ensp;
		<input type="button" value="新增接口" onclick=\'document.location.href="?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&backURL="+ encodeURIComponent(document.location.href);\' />
	</div> -->
	');

	$payArr = AdmArea::GetAppIdArr();	// 获取已购买插件appID数组   in ('. implode(',',$payArr) .')

	$skin->TableTop2('share_list.gif','',''. $dataTypeCN .'管理');
	$skin->TableItemTitle('4%,5%,20%,31%,18%,8%,6%,8%','序号,ID,接口名称,属性,备注,排序,状态,修改');	// 　删除

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit('select * from '. OT_dbPref .'vpsApi where VA_appID<>999 and VA_ID<>3 order by VA_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=''; }

			$themeAddi = $addiStr = '';
			if ($showRow[$i]['VA_ID'] == 1){
				$themeAddi = Skin::PluSign('IDC接口_星外','bottom');
				if (! in_array($showRow[$i]['VA_appID'],$payArr)){
					$addiStr .= '<div style="color:red;">该“IDC接口_星外”插件未购买，无法使用该接口</div>';
				}else{
					$addiStr .= '【费率】日付：'. floatval($showRow[$i]['VA_rateDay']) .'；周付：'. floatval($showRow[$i]['VA_rateWeek']) .'；月付：'. floatval($showRow[$i]['VA_rateMonth']) .'；季付：'. floatval($showRow[$i]['VA_rate3Month']) .'；半年付：'. floatval($showRow[$i]['VA_rate6Month']) .'；年付：'. floatval($showRow[$i]['VA_rateYear']) .'；';
				}
			}elseif ($showRow[$i]['VA_ID'] == 2){
				$themeAddi = Skin::PluSign('IDC接口_景安网络','bottom');
				if (! in_array($showRow[$i]['VA_appID'],$payArr)){
					$addiStr .= '<div style="color:red;">该“IDC接口_景安网络”插件未购买，无法使用该接口</div>';
				}
			}elseif ($showRow[$i]['VA_ID'] == 3){
				$themeAddi = Skin::PluSign('IDC接口_创梦','bottom');
				if (! in_array($showRow[$i]['VA_appID'],$payArr)){
					$addiStr .= '<div style="color:red;">该“IDC接口_创梦”插件未购买，无法使用该接口</div>';
				}
			}elseif ($showRow[$i]['VA_ID'] == 4){
				$themeAddi = Skin::PluSign('IDC接口_ZKEYS阿帕云','bottom');
				if (! in_array($showRow[$i]['VA_appID'],$payArr)){
					$addiStr .= '<div style="color:red;">该“IDC接口_ZKEYS阿帕云”插件未购买，无法使用该接口</div>';
				}
			}

			echo('
			<tr id="data'. $showRow[$i]['VA_ID'] .'" '. $bgcolor .'>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['VA_ID'] .'</td>
				<td align="center">'. $showRow[$i]['VA_theme'] . $themeAddi .'</td>
				<td align="left">'. $addiStr .'</td>
				<td align="center">'. $showRow[$i]['VA_note'] .'</td>
				<td align="center">'. $showRow[$i]['VA_rank'] .'</td>
				<td align="center">'. Adm::SwitchBtn('vpsApi',$showRow[$i]['VA_ID'],$showRow[$i]['VA_state'],'state') .'<br /></td>
				<td align="center">
					<img src="images/img_rev.gif" class="pointer" onclick=\'document.location.href="vpsApi.php?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['VA_ID'] .'&backURL="+ encodeURIComponent(document.location.href)\' alt="修改" /><!-- &ensp;&ensp;
					<img src="images/img_del.gif" class="pointer" onclick=\'if(confirm("确定删除？")==true){DataDeal.location.href="vpsApi_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['VA_theme']) .'&dataID='. $showRow[$i]['VA_ID'] .'"}\' alt="删除" /> -->
				</td>
			</tr>
			');
			$number ++;
		}
		echo('
		</tbody>
		');
	}
	unset($showRow);

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

}

?>