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


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

	case 'rev':
		$MB->IsSecMenuRight('alertBack',508,$dataType);
		AddOrRev();
		break;

	case 'manage':
		$MB->IsSecMenuRight('alertBack',505,$dataType);
		manage();
		break;

	case 'show':
		$MB->IsSecMenuRight('alertClose',506,$dataType);
		show();
		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 .'vpsDealerList where VDL_ID='. $dataID);
		if (! $row = $revexe->fetch()){
			JS::AlertBackEnd('无该记录！');
		}
		$VDL_type			= $row['VDL_type'];
		$VDL_theme			= $row['VDL_theme'];
		$VDL_qq				= $row['VDL_qq'];
		$VDL_note			= $row['VDL_note'];
		$VDL_rank			= $row['VDL_rank'];
		$VDL_state			= $row['VDL_state'];
		unset($revexe);

		$mudiCN='修改';
	}else{
		$VDL_type			= '';
		$VDL_theme			= '';
		$VDL_qq				= '';
		$VDL_note			= '';
		$VDL_rank			= intval($DB->GetOne('select max(VDL_rank) from '. OT_dbPref .'vpsDealerList'))+10;
		$VDL_state			= 1;

		$mudiCN='添加';
	}

	echo('
	<form id="dealForm" name="dealForm" method="post" action="vpsDealerList_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) .'
	');

	$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">类型：</td>
			<td align="left">
				<select id="type" name="type">
					<!-- <option value="host" '. Is::Selected($VDL_type, 'host') .'>虚拟主机</option>
					<option value="vpsApi" '. Is::Selected($VDL_type, 'vpsApi') .'>云服务器</option> -->
					<option value="serv" '. Is::Selected($VDL_type, 'serv') .'>服务器租用</option>
					<!-- <option value="dialing" '. Is::Selected($VDL_type, 'dialing') .'>拨号VPS</option>
					<option value="ssl" '. Is::Selected($VDL_type, 'ssl') .'>SSL证书</option>
					<option value="idcServ" '. Is::Selected($VDL_type, 'idcServ') .'>主控机器</option> -->
				</select>
			</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="'. $VDL_theme .'" />
				<span class="font2_2">&ensp;（指代理产品的提供商）</span>
			</td>
		</tr>
		<tr>
			<td align="right">上家联系QQ：</td>
			<td align="left">
				<input type="text" id="qq" name="qq" size="50" style="width:400px;" value="'. $VDL_qq .'" />
				<span class="font2_2">&ensp;如多个QQ用逗号“,”隔开</span>
			</td>
		</tr>
		<tr>
			<td align="right" valign="top" style="padding-top:6px;">上家备注：</td>
			<td align="left">
				<textarea id="note" name="note" style="width:400px;height:150px;">'. $VDL_note .'</textarea>
				<span class="font2_2">&ensp;可填联系方式、开通流程等</span>
			</td>
		</tr>
		<tr>
			<td align="right">排序：</td>
			<td align="left"><input type="text" id="rank" name="rank" size="50" style="width:30px;" value="'. $VDL_rank .'" /></td>
		</tr>
		<tr>
			<td align="right">状态：</td>
			<td align="left">
				<label><input type="radio" name="state" value="1" '. Is::Checked($VDL_state,1) .' />显示</label>&ensp;&ensp;&ensp;&ensp;
				<label><input type="radio" name="state" value="0" '. Is::Checked($VDL_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;

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

	if (in_array($dataMode, array('host', 'vpsApi', 'serv', 'dialing', 'ssl', 'idcServ'))){
		$whereStr = ' where VDL_type='. $DB->ForStr($dataMode);
	}else{
		$dataMode = '';
		$whereStr = '';
	}

	echo('
	<div style="padding:6px;"><input type="button" value="新增上家名单" onclick=\'document.location.href="?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataMode='. $dataMode .'&backURL="+ encodeURIComponent(document.location.href);\' /></div>
	');

	$skin->TableTop2('share_list.gif','',''. $dataTypeCN .'管理');
	$skin->TableItemTitle('4%,4%,10%,12%,15%,35%,6%,6%,8%','序号,ID,类型,名称,联系QQ,备注,排序,状态,修改　删除');

	$pageSize	= $MB->mMbRow['MB_itemNum'];		//每页条数
	$page		= OT::GetInt('page');
	$showRow=$DB->GetLimit('select * from '. OT_dbPref .'vpsDealerList '. $whereStr .' order by VDL_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]['VDL_ID'] .'" '. $bgcolor .'>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['VDL_ID'] .'</td>
				<td align="center">'. TypeCN($showRow[$i]['VDL_type']) .'</td>
				<td align="center">'. $showRow[$i]['VDL_theme'] .'</td>
				<td align="center" style="word-break:break-all;">'. AdmArea::UserQQ($showRow[$i]['VDL_qq']) .'</td>
				<td align="center" style="word-break:break-all;line-height:1.4;">'. $showRow[$i]['VDL_note'] .'</td>
				<td align="center">'. $showRow[$i]['VDL_rank'] .'</td>
				<td align="center">'. Adm::SwitchBtn('vpsDealerList',$showRow[$i]['VDL_ID'],$showRow[$i]['VDL_state'],'state') .'</td>
				<td align="center">
					<img src="images/img_rev.gif" class="pointer" onclick=\'document.location.href="vpsDealerList.php?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['VDL_ID'] .'&backURL="+ encodeURIComponent(document.location.href)\' alt="修改" />&ensp;&ensp;
					<img src="images/img_del.gif" class="pointer" onclick=\'if(confirm("确定删除？")==true){DataDeal.location.href="vpsDealerList_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['VDL_theme']) .'&dataID='. $showRow[$i]['VDL_ID'] .'"}\' alt="删除" />
				</td>
			</tr>
			');
			$number ++;
		}
		echo('
		</tbody>
		');
	}
	unset($showRow);

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

}



function show(){
	global $DB,$skin,$dataType,$dataTypeCN,$userSysArr;

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

	$showexe=$DB->query('select * from '. OT_dbPref .'vpsDealerList where VDL_ID='. $dataID);
	if (! $row = $showexe->fetch()){
		JS::AlertCloseEnd('指定ID错误！');
	}else{
		echo('
		<script language="javascript" type="text/javascript">document.title="上家名单详细信息";</script>
		<table style="width:450px;" align="center" cellpadding="0" cellspacing="0" border="0" summary=""><tr><td>
		');
		$skin->TableTop('share_list.gif','','上家名单详细信息');

		echo('
		<table style="width:100%;" align="center" cellpadding="0" cellspacing="0" border="0" summary="" class="padd3">
		<tr>
			<td align="right" width="80">类型：</td>
			<td>'. TypeCN($row['VDL_type']) .'</td>
		</tr>
		<tr>
			<td align="right" width="80">上家名称：</td>
			<td>'. $row['VDL_theme'] .'</td>
		</tr>
		<tr>
			<td align="right">联系QQ：</td>
			<td>'. AdmArea::UserQQ($row['VDL_qq']) .'</td>
		</tr>
		<tr>
			<td align="right">备注：</td>
			<td>'. $row['VDL_note'] .'</td>
		</tr>
		</table>
		');

		$skin->TableBottom();


		echo('
		</td></tr></table>
		');
	}
}



function TypeCN($str){
	switch ($str){
		case 'serv':
			return '服务器租用';
	
		default :
			return $str;
	}
}

?>