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


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

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

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

	case 'show':
		$MB->IsSecMenuRight('alertClose',301,$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 .'vpsCompany where VC_ID='. $dataID);
		if (! $row = $revexe->fetch()){
			JS::AlertBackEnd('无该记录！');
		}
		$VC_theme			= $row['VC_theme'];
		$VC_url				= $row['VC_url'];
		$VC_qq				= $row['VC_qq'];
		$VC_note			= $row['VC_note'];
		$VC_isApi			= $row['VC_isApi'];
		$VC_apiID			= $row['VC_apiID'];
		$VC_apiDomain		= $row['VC_apiDomain'];
		$VC_apiManageUrl	= $row['VC_apiManageUrl'];
		$VC_apiUsername		= $row['VC_apiUsername'];
		$VC_apiUserPwd		= Encrypt::SyEnDe('de',$row['VC_apiUserPwd']);	// '********'
		$VC_apiUsername2	= $row['VC_apiUsername'];
		$VC_apiUserPwd2		= Encrypt::SyEnDe('de',$row['VC_apiUserPwd']);
		$VC_apiUsername5	= $row['VC_apiUsername'];
		$VC_apiUserPwd5		= Encrypt::SyEnDe('de',$row['VC_apiUserPwd']);
		$VC_rateDay			= floatval($row['VC_rateDay']);
		$VC_rateWeek		= floatval($row['VC_rateWeek']);
		$VC_rateMonth		= floatval($row['VC_rateMonth']);
		$VC_rate3Month		= floatval($row['VC_rate3Month']);
		$VC_rate6Month		= floatval($row['VC_rate6Month']);
		$VC_rateYear		= floatval($row['VC_rateYear']);
		$VC_rate2Year		= floatval($row['VC_rate2Year']);
		$VC_rate3Year		= floatval($row['VC_rate3Year']);
		$VC_rate4Year		= floatval($row['VC_rate4Year']);
		$VC_rate5Year		= floatval($row['VC_rate5Year']);
		$VC_area			= $row['VC_area'];
		$VC_rank			= $row['VC_rank'];
		$VC_state			= $row['VC_state'];
		unset($revexe);

		$mudiCN='修改';
	}else{
		$VC_theme			= '';
		$VC_url				= 'http://';
		$VC_qq				= '';
		$VC_note			= '';
		$VC_isApi			= 0;
		$VC_apiID			= 0;
		$VC_apiDomain		= '';
		$VC_apiManageUrl	= '';
		$VC_apiUsername		= '';
		$VC_apiUserPwd		= '';
		$VC_apiUsername2	= '';
		$VC_apiUserPwd2		= '';
		$VC_apiUsername5	= '';
		$VC_apiUserPwd5		= '';
		$VC_rateDay			= '';
		$VC_rateWeek		= '';
		$VC_rateMonth		= '';
		$VC_rate3Month		= '';
		$VC_rate6Month		= '';
		$VC_rateYear		= '';
		$VC_rate2Year		= '';
		$VC_rate3Year		= '';
		$VC_rate4Year		= '';
		$VC_rate5Year		= '';
		$VC_area			= '';
		$VC_rank			= intval($DB->GetOne('select max(VC_rank) from '. OT_dbPref .'vpsCompany'))+10;
		$VC_state			= 1;

		$mudiCN='添加';
	}

	echo('
	<form id="dealForm" name="dealForm" method="post" action="vpsCompany_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 .'" />
	<input type="hidden" id="rateDayApi" name="rateDayApi" value="" />
	<input type="hidden" id="rateWeekApi" name="rateWeekApi" value="" />
	<input type="hidden" id="rateMonthApi" name="rateMonthApi" value="" />
	<input type="hidden" id="rate3MonthApi" name="rate3MonthApi" value="" />
	<input type="hidden" id="rate6MonthApi" name="rate6MonthApi" value="" />
	<input type="hidden" id="rateYearApi" name="rateYearApi" value="" />
	<input type="hidden" id="rate2YearApi" name="rate2YearApi" value="" />
	<input type="hidden" id="rate3YearApi" name="rate3YearApi" value="" />
	<input type="hidden" id="rate4YearApi" name="rate4YearApi" value="" />
	<input type="hidden" id="rate5YearApi" name="rate5YearApi" value="" />
	'. 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">'. Skin::RedSign() .'上级渠道商名称：</td>
			<td align="left">
				<input type="text" id="theme" name="theme" size="50" style="width:400px;" value="'. $VC_theme .'" />
				<span class="font2_2">&ensp;（指代理产品的提供商）</span>
			</td>
		</tr>
		<tr>
			<td align="right">上级渠道商网址：</td>
			<td align="left">
				<input type="text" id="url" name="url" size="50" style="width:400px;" value="'. $VC_url .'" />
			</td>
		</tr>
		<tr>
			<td align="right">上级渠道商联系QQ：</td>
			<td align="left">
				<input type="text" id="qq" name="qq" size="50" style="width:400px;" value="'. $VC_qq .'" />
				<span class="font2_2">&ensp;如多个QQ用逗号“,”隔开</span>
			</td>
		</tr>
		<tr>
			<td align="right">上级渠道商备注：</td>
			<td align="left">
				<textarea id="note" name="note" style="width:400px;height:60px;">'. $VC_note .'</textarea>
			</td>
		</tr>
		<tr>
			<td align="right">使用范围：</td>
			<td align="left">
				<label><input type="checkbox" name="area[]" value="[host]" '. Is::InstrChecked($VC_area,'[host]') .'>虚拟主机</label>&ensp;&ensp;
				<label><input type="checkbox" name="area[]" value="[vpsApi]" '. Is::InstrChecked($VC_area,'[vpsApi]') .'>云服务器</label>&ensp;&ensp;
				<label><input type="checkbox" name="area[]" value="[dialing]" '. Is::InstrChecked($VC_area,'[dialing]') .'>拨号VPS</label>&ensp;&ensp;
				<label><input type="checkbox" name="area[]" value="[serv]" '. Is::InstrChecked($VC_area,'[serv]') .'>服务器租用</label>&ensp;&ensp;
				<!-- <label><input type="checkbox" name="area[]" value="[pptp]" '. Is::InstrChecked($VC_area,'[pptp]') .'>PPTP</label>&ensp;&ensp; -->
			</td>
		</tr>
		<tr>
			<td align="right">是否有API：</td>
			<td align="left">
				<label><input type="radio" id="isApi1" name="isApi" value="1" '. Is::Checked($VC_isApi,1) .' onclick="CheckApiBox()" />有</label>&ensp;&ensp;&ensp;&ensp;
				<label><input type="radio" id="isApi0" name="isApi" value="0" '. Is::Checked($VC_isApi,0) .' onclick="CheckApiBox()" />无</label>&ensp;&ensp;&ensp;&ensp;
			</td>
		</tr>
		<tbody id="apiBox" style="display:none;">
		<tr>
			<td align="right">'. Skin::RedSign() .'API接口：</td>
			<td align="left">
				<select id="apiID" name="apiID" onchange="LoadApiRate()">
					<option value=""></option>
					');
					$payArr = AdmArea::GetAppIdArr();
					$vpsApiArr = IdcArea::VpsApiArr();

					foreach ($vpsApiArr as $item){
						if ($item['state'] == 1){
							if (in_array($item['appID'],$payArr)){
								echo('<option value="'. $item['id'] .'" '. Is::Selected($item['id'],$VC_apiID) .'>'. $item['name'] .'</option>');
							}else{
								echo('<optgroup label="'. $row['VA_theme'] .'（“IDC接口_'. $item['name'] .'”插件未购买，无法使用该接口）" style="color:#b5b5b5;font-weight:normal;"></optgroup>');
							}
						}
					}
					unset($apiexe);
				echo('
				</select>
			</td>
		</tr>
		<tr class="api16Class">
			<td align="right">'. Skin::RedSign() .'API网址/域名：</td>
			<td align="left">
				<input type="text" id="apiDomain" name="apiDomain" size="50" style="width:400px;" value="'. $VC_apiDomain .'" />
				&ensp;<span class="font2_2">如：api.idccms.com 或 http://api.idccms.com/</span>
			</td>
		</tr>
		<tr class="api16Class">
			<td align="right">'. Skin::RedSign() .'面板管理网址/域名：</td>
			<td align="left">
				<input type="text" id="apiManageUrl" name="apiManageUrl" size="50" style="width:400px;" value="'. $VC_apiManageUrl .'" />
				&ensp;<span class="font2_2">如：panle.idccms.com 或 http://panle.idccms.com/</span>
			</td>
		</tr>
		<tr class="api16Class">
			<td align="right">'. Skin::RedSign() .'上级代理名：</td>
			<td align="left">
				<input type="text" id="apiUsername" name="apiUsername" size="50" style="width:400px;" value="'. $VC_apiUsername .'" />
			</td>
		</tr>
		<tr class="api16Class">
			<td align="right">'. Skin::RedSign() .'上级代理密码：</td>
			<td align="left">
				<input type="password" id="apiUserPwd" name="apiUserPwd" size="50" style="width:400px;" value="'. $VC_apiUserPwd .'" /><input type="button" id="apiUserPwdBtn" value="明码" onclick=\'PwdTextBtn("apiUserPwd")\' />
			</td>
		</tr>
		<tr class="api2Class">
			<td align="right">'. Skin::RedSign() .'Access Id(身份标识)：</td>
			<td align="left">
				<input type="text" id="apiUsername2" name="apiUsername2" size="50" style="width:400px;" value="'. $VC_apiUsername2 .'" />
			</td>
		</tr>
		<tr class="api2Class">
			<td align="right">'. Skin::RedSign() .'Access Key(密钥)：</td>
			<td align="left">
				<input type="password" id="apiUserPwd2" name="apiUserPwd2" size="50" style="width:400px;" value="'. $VC_apiUserPwd2 .'" /><input type="button" id="apiUserPwd2Btn" value="明码" onclick=\'PwdTextBtn("apiUserPwd2")\' />
			</td>
		</tr>
		<tr class="api5Class">
			<td align="right">'. Skin::RedSign() .'Api ID：</td>
			<td align="left">
				<input type="text" id="apiUsername5" name="apiUsername5" size="50" style="width:400px;" value="'. $VC_apiUsername5 .'" />
			</td>
		</tr>
		<tr class="api5Class">
			<td align="right">'. Skin::RedSign() .'密钥：</td>
			<td align="left">
				<input type="password" id="apiUserPwd5" name="apiUserPwd5" size="50" style="width:400px;" value="'. $VC_apiUserPwd5 .'" /><input type="button" id="apiUserPwd5Btn" value="明码" onclick=\'PwdTextBtn("apiUserPwd5")\' />
			</td>
		</tr>
		<tr class="api1Class">
			<td align="right" valign="top" style="padding-top:6px;">上级费率：</td>
			<td align="left">
				<table cellspacing="0" cellpadding="0" style="width:620px;">
				<tr>
					<td align="right">
						日付费率：<input type="text" id="rateDay" name="rateDay" size="50" style="width:60px;" value="'. $VC_rateDay .'" />
						<div id="rateDayApiStr" style="color:red;"></div>
					</td>
					<td align="right">
						周付费率：<input type="text" id="rateWeek" name="rateWeek" size="50" style="width:60px;" value="'. $VC_rateWeek .'" />
						<div id="rateWeekApiStr" style="color:red;"></div>
					</td>
					<td align="right" colspan="2">
						<input type="button" value="恢复默认费率" onclick="LoadDefRate()" style="margin-left:196px;color:blue;" />
					</td>
				</tr>
				<tr>
					<td align="right" width="25%">
						月付费率：<input type="text" id="rateMonth" name="rateMonth" size="50" style="width:60px;" value="'. $VC_rateMonth .'" />
						<div id="rateMonthApiStr" style="color:red;"></div>
					</td>
					<td align="right" width="25%">
						季付费率：<input type="text" id="rate3Month" name="rate3Month" size="50" style="width:60px;" value="'. $VC_rate3Month .'" />
						<div id="rate3MonthApiStr" style="color:red;"></div>
					</td>
					<td align="right" width="25%">
						半年付费率：<input type="text" id="rate6Month" name="rate6Month" size="50" style="width:60px;" value="'. $VC_rate6Month .'" />
						<div id="rate6MonthApiStr" style="color:red;"></div>
					</td>
					<td align="right" width="25%">
						年付费率：<input type="text" id="rateYear" name="rateYear" size="50" style="width:60px;" value="'. $VC_rateYear .'" />
						<div id="rateYearApiStr" style="color:red;"></div>
					</td>
				</tr>
				<tr>
					<td align="right">
						二年付费率：<input type="text" id="rate2Year" name="rate2Year" size="50" style="width:60px;" value="'. $VC_rate2Year .'" />
						<div id="rate2YearApiStr" style="color:red;"></div>
					</td>
					<td align="right">
						三年付费率：<input type="text" id="rate3Year" name="rate3Year" size="50" style="width:60px;" value="'. $VC_rate3Year .'" />
						<div id="rate3YearApiStr" style="color:red;"></div>
					</td>
					<td align="right">
						四年付费率：<input type="text" id="rate4Year" name="rate4Year" size="50" style="width:60px;" value="'. $VC_rate4Year .'" />
						<div id="rate4YearApiStr" style="color:red;"></div>
					</td>
					<td align="right">
						五年付费率：<input type="text" id="rate5Year" name="rate5Year" size="50" style="width:60px;" value="'. $VC_rate5Year .'" />
						<div id="rate5YearApiStr" style="color:red;"></div>
					</td>
				</tr>
				</table>
				<div class="font2_2">说明：费率得与上级系统的费率一致，否则会开通不了。</div>
			</td>
		</tr>
		</tbody>
		<tr>
			<td align="right">排序：</td>
			<td align="left"><input type="text" id="rank" name="rank" size="50" style="width:60px;" value="'. $VC_rank .'" /></td>
		</tr>
		<tr>
			<td align="right">状态：</td>
			<td align="left">
				<label><input type="radio" name="state" value="1" '. Is::Checked($VC_state,1) .' />显示</label>&ensp;&ensp;&ensp;&ensp;
				<label><input type="radio" name="state" value="0" '. Is::Checked($VC_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="?mudi=add&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&backURL="+ encodeURIComponent(document.location.href);\' /></div>
	');

	$skin->TableTop2('share_list.gif','',''. $dataTypeCN .'管理');
	$skin->TableItemTitle('4%,4%,16%,16%,19%,23%,5%,5%,8%','序号,ID,上级渠道商名称,联系QQ/网址,备注,API接口信息,排序,状态,修改　删除');

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

		/* $apiArr = array();
		$apiexe = $DB->query('select VA_ID,VA_theme from '. OT_dbPref .'vpsApi');
		while ($ars = $apiexe->fetch()){
			$apiArr[$ars['VA_ID']] = $ars['VA_theme'];
		}
		unset($apiexe); */
		$apiArr = IdcArea::VpsApiArr('','name');

		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=''; }

			$apiStr = $apiImg = '';
			switch ($showRow[$i]['VC_apiID']){
				case 1: case 6:
					$apiStr = '<span style="color:blue;">API：</span>'. $showRow[$i]['VC_apiDomain'] .'　<span style="color:blue;">面板：</span>'. $showRow[$i]['VC_apiManageUrl'] .'　<span style="color:blue;">代理名：</span>'. $showRow[$i]['VC_apiUsername'] .'';
					break;
			
				case 2:
					$apiStr = '<span style="color:blue;">Access Id(身份标识)：</span>'. $showRow[$i]['VC_apiUsername'] .'';
					break;
			}
			if ($showRow[$i]['VC_isApi'] == 1){
				$apiImg = '<img src="images/usb.png" style="margin:0 2px;" align="top" title="有API接口" alt="有API接口" />';
			}
			if ($showRow[$i]['VC_apiID'] >= 1){
				$apiImg .= '<div style="padding:3px;color:#c9c9c9;">'. $apiArr[$showRow[$i]['VC_apiID']] .'</div>';
			}

			echo('
			<tr id="data'. $showRow[$i]['VC_ID'] .'" '. $bgcolor .'>
				<td align="center">'. $number .'</td>
				<td align="center">'. $showRow[$i]['VC_ID'] .'</td>
				<td align="center">
					'. $showRow[$i]['VC_theme'] . $apiImg .'
					'. ($showRow[$i]['VC_apiID'] == 6 ? '<div style="padding-top:5px;color:blue;cursor:pointer;" onclick="AjaxGetDeal(\'vpsCompany_deal.php?mudi=userInfo&dataID='. $showRow[$i]['VC_ID'] .'\');">[查询账户余额]</div>' : '') .'
				</td>
				<td align="center" style="word-break:break-all;">
					'. AdmArea::UserQQ($showRow[$i]['VC_qq']) .'
					<div style="padding-top:5px;"><a href="'. $showRow[$i]['VC_url'] .'" target="_blank" class="font1_2">'. $showRow[$i]['VC_url'] .'</a></div>
				</td>
				<td align="center" style="word-break:break-all;line-height:1.4;">
					'. $showRow[$i]['VC_note'] .'
					<div>'. AreaStrCN($showRow[$i]['VC_area']) .'</div>
				</td>
				<td align="center" style="word-break:break-all;line-height:1.4;">'. $apiStr .'</td>
				<td align="center">'. $showRow[$i]['VC_rank'] .'</td>
				<td align="center">'. Adm::SwitchBtn('vpsCompany',$showRow[$i]['VC_ID'],$showRow[$i]['VC_state'],'state') .'</td>
				<td align="center">
					<img src="images/img_rev.gif" class="pointer" onclick=\'document.location.href="vpsCompany.php?mudi=rev&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&dataID='. $showRow[$i]['VC_ID'] .'&backURL="+ encodeURIComponent(document.location.href)\' alt="修改" />&ensp;&ensp;
					<img src="images/img_del.gif" class="pointer" onclick=\'if(confirm("确定删除？")==true){DataDeal.location.href="vpsCompany_deal.php?mudi=del&dataType='. $dataType .'&dataTypeCN='. urlencode($dataTypeCN) .'&theme='. urlencode($showRow[$i]['VC_theme']) .'&dataID='. $showRow[$i]['VC_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 .'vpsCompany where VC_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>'. $row['VC_theme'] .'</td>
		</tr>
		<tr>
			<td align="right">公司网址：</td>
			<td><a href="'. $row['VC_url'] .'" target="_blank" class="font1_2">'. $row['VC_url'] .'</a></td>
		</tr>
		<tr>
			<td align="right">联系QQ：</td>
			<td>'. AdmArea::UserQQ($row['VC_qq']) .'</td>
		</tr>
		<tr>
			<td align="right">备注：</td>
			<td>'. $row['VC_note'] .'</td>
		</tr>
		</table>
		');

		$skin->TableBottom();


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


function AreaStrCN($str){
	$retArr = array();
	if (strpos(''. $str,'[host]') !== false){ $retArr[] = '虚拟主机'; }
	if (strpos(''. $str,'[vpsApi]') !== false){ $retArr[] = '云服务器'; }
	if (strpos(''. $str,'[dialing]') !== false){ $retArr[] = '拨号VPS'; }
	if (strpos(''. $str,'[serv]') !== false){ $retArr[] = '服务器租用'; }
	if (strpos(''. $str,'[pptp]') !== false){ $retArr[] = 'PPTP'; }

	if (empty($retArr)){
		return '';
	}else{
		return '<div style="padding:5px 0 2px 0;color:blue;width:98%;text-align:left;">范围：'. implode('、',$retArr) .'</div>';
	}
}

?>