<?php
include_once("./head2.php");
?>
<script type="text/javascript">
function FikCdn_AddDomain(){
	var txtDomain	 =document.getElementById("txtDomain").value;
	var productSelect=document.getElementById("productSelect").value;
	var txtSrcIP     =document.getElementById("txtSrcIP").value;
	var txtICP     =document.getElementById("txtICP").value;
	var txtUnicomIP   =document.getElementById("txtUnicomIP").value;
	//var txtDNSName     =document.getElementById("txtDNSName").value;
	var txtBackup    =document.getElementById("txtBackup").value;
	
	var selUpstreatType = 0;
	var objRadio = document.getElementsByName("selUpstreatType");
	for(var i=0;i<objRadio.length;i++){
		if(objRadio[i].checked){  
			selUpstreatType = objRadio[i].value;
		}   
	}
		
	var txtDNSName = "";

	if (txtDomain.length==0 ){
		var boxURL="msg.php?1.9&msg=请输入要加速的域名";
		showMSGBOX('',350,100,BT,BL,120,boxURL,'操作提示:');
		document.getElementById("txtDomain").focus();
	  	return false;
	}

	if (productSelect.length==0 ){ 
		var boxURL="msg.php?1.9&msg=请先购买一个产品套餐再添加域名。";
		showMSGBOX('',350,100,BT,BL,120,boxURL,'操作提示:');
		return;
	}

	if (txtSrcIP.length==0 && txtUnicomIP.length==0){ 
		var boxURL="msg.php?1.9&msg=电信源站 IP 和联通源站 IP 至少填一个。";
		showMSGBOX('',350,100,BT,BL,120,boxURL,'操作提示:');	
		document.getElementById("txtSrcIP").focus();
	  	return false;
	}
	
	var postURL="./ajax_domain.php?mod=domain&action=add";
	var postStr="buy_id="+UrlEncode(productSelect)+"&domain=" + UrlEncode(txtDomain) + "&srcip=" + UrlEncode(txtSrcIP) + "&unicom_ip="+UrlEncode(txtUnicomIP)+ "&upstream_add_type=" +selUpstreatType+
			"&icp=" + UrlEncode(txtICP) +"&dns_name=" + UrlEncode(txtDNSName) +"&backup=" + UrlEncode(txtBackup);		
	AjaxBasePost("domain","add","POST",postURL,postStr);
}

function FikCdn_AddDomainResult(sResponse){
	var json = eval("("+sResponse+")");
	if(json["Return"]=="True"){
		var nDomainId = json["id"];
		var sDomain = json["domain"];
		var sUpstream = json["upstream"];
		var sUnicomIp = json["unicom_ip"];
		var sUsername = json["username"];
		var sProductName = json["show_product_name"];
		var sStatus = json["status"];
		var sNote = json["note"];
		
		var sNewItem = '<tr bgcolor="#FFFFFF" align="center" onMouseMove="Event_trOnMouseOver(this)" onMouseOut="Event_trOnMouseOut(this)">';
		sNewItem   	+= '<td title="'+sNote+'" align="left">'+sDomain+'</td>';
		sNewItem   	+= '<td align="right">'+sUpstream+'</td>';
		sNewItem   	+= '<td align="right">'+sUnicomIp+'</td>';
		sNewItem   	+= '<td align="left">'+sProductName+'</td>';
		sNewItem   	+= '<td align="right">0 GB</td>';
		sNewItem   	+= '<td>'+sStatus+'</td>';
						
		sNewItem	+= '<td>  <a href="stat_domain_bandwidth.php?domain_id='+nDomainId+'" onclick="javescript:FikCdn_SelectDomainStat();" title="查看此域名流量统计信息">流量统计</a>&nbsp;';
		sNewItem    += '<a href="javascript:void(0);" onclick="javescript:FikCdn_ModifyDomainBox('+nDomainId+');" title="修改域名信息">修改</a>&nbsp;';
		sNewItem    += '<a href="javascript:void(0);" onclick="javescript:FikCdn_VerifyDomainBox('+nDomainId+');" title="开始加速域名到节点组">通过审核</a>';
		sNewItem    += '&nbsp;<a href="javascript:void(0);" onclick="javescript:FikCdn_DelDomainBox('+nDomainId+');" title="删除节点信息">删除</a> </td>';
		sNewItem    += '</tr></table>';
								
		var boxURL="msg.php?1.8&msg=添加域名成功。";
		showMSGBOX('',300,100,BT,BL,120,boxURL,'操作提示:');
		document.getElementById("txtDomain").value="";
		
		var nowHTML=parent.document.getElementById("div_search_result").innerHTML;
		var showHTML = nowHTML.split("</table>")[0];
			
		nowHTML = showHTML + sNewItem;		
		parent.document.getElementById("div_search_result").innerHTML=nowHTML;		
		
				
		//document.getElementById("txtSrcIP").value="";
		//document.getElementById("txtICP").value="";
		//document.getElementById("txtUnicomIP").value="";
		//document.getElementById("txtDNSName").value="";
		//document.getElementById("txtBackup").value="";		
	}else{
		var nErrorNo = json["ErrorNo"];
		var strErr = json["ErrorMsg"];
	
		if(nErrorNo==30000){
			parent.location.href = "./login.php"; 
		}else{
			var boxURL="msg.php?1.9&msg="+strErr;
			showMSGBOX('',350,100,BT,BL,120,boxURL,'操作提示:');
		}
	}		
}

function FikCdn_ToTaskList(){
	parent.parent.window.leftFrame.window.OnSelectNav("span_task_list");
	parent.window.location.href="task_list.php";
}

</script>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0" class="normal">
  <tr>
    <td width="100" height="25" class="objTitle" title="" ><span class="input_red_tips">*</span>域名：</td>
    <td width="220">
		<input id="txtDomain" type="text" size="36" maxlength="128"  /> <span class="input_tips_txt" id="tipsDomain" name="tipsDomain" ></span>
	</td>
  </tr>
  <tr>
    <td height="6" colspan="2"></td>
  </tr>
  <tr>
    <td height="25" class="objTitle"  title="如果有多个电信源站，可用“;”间隔，如：211.155.23.66;234.34.55.123" ><span class="input_red_tips">*</span>源站电信 IP：</td>
    <td>
		<input id="txtSrcIP" type="text" size="36" maxlength="64"  title="如果有多个电信源站，可用“;”间隔，如：211.155.23.66;234.34.55.123" /> <span class="input_tips_txt" id="tipsSrcIP" name="tipsSrcIP" ></span>  
	</td>
  </tr>
  <tr>
    <td height="6" colspan="2"></td>
  </tr>
  <tr>
    <td height="25" class="objTitle" title="如果有多个联通源站，可用“;”间隔，如：211.155.23.66;234.34.55.123"  >源站联通 IP：</td>
    <td>
		<input id="txtUnicomIP" type="text" size="36" maxlength="64"  title="如果有多个联通源站，可用“;”间隔，如：211.155.23.66;234.34.55.123"  /><span class="input_tips_txt4" id="tipsUnicomIP" ></span>
	</td>
  </tr>
  
 <tr>
    <td height="6" colspan="2"></td>
  </tr>
  <tr>
    <td height="25" class="objTitle" title="" >源站配置方式：</td>
    <td>
	  <input name="selUpstreatType" type="radio" class="radio" id="selUpstreatType" value="0" checked="checked" title="根据节点服务器线路类型匹配相同线路的源站添加到源站列表中。"/><label title="根据节点服务器线路类型匹配相同线路的源站添加到源站列表中。">自动匹配线路</label>&nbsp;&nbsp;
      <input name="selUpstreatType" type="radio" class="radio" id="selUpstreatType" value="1" title="电信和联通源站IP全部添加到节点服务器的源站列表中。"/><label title="电信和联通源站IP全部添加到节点服务器的源站列表中。">双源站配置</label>&nbsp;&nbsp;
	</td>
  </tr>
    
  <tr>
    <td height="6" colspan="2"></td>
  </tr>
  <tr>
    <td height="25" class="objTitle" title="仅作为记录域名的 ICP 备案号，方便管理。" >域名 ICP 备案号：</td>
    <td>
		<input id="txtICP" type="text" size="36" maxlength="64" title="仅作为记录域名的 ICP 备案号，方便管理。" /> <span class="input_tips_txt" id="tipsICP" ></span>
	</td>
  </tr>
  <tr>
    <td height="6" colspan="2"></td>
  </tr>
  <tr>
    <td height="25" class="objTitle" title="" >已出售产品套餐：</td>
    <td>
		<select id="productSelect" style="width:255px">
 <?php
 	$db_link = FikCDNDB_Connect();
	if($db_link)
	{
		do
		{
			$sql = "SELECT * FROM fikcdn_buy;";
			$result = mysql_query($sql,$db_link);
			if(!$result)
			{
				break;
			}
			
			$row_count=mysql_num_rows($result);
			if(!$row_count)
			{
				break;
			}
			
			for($i=0;$i<$row_count;$i++)
			{
				$this_buy_id  		= mysql_result($result,$i,"id");	
				$product_id  	= mysql_result($result,$i,"product_id");	
				$this_username	= mysql_result($result,$i,"username");
			
				$sql = "SELECT * FROM fikcdn_product WHERE id='$product_id'";
				$result2 = mysql_query($sql,$db_link);
				if($result2 && mysql_num_rows($result2)>0)
				{
					$product_name  			= mysql_result($result2,0,"name");	
					
					if($buy_id==$this_buy_id)
					{
						echo '<option value="'.$this_buy_id.'" selected="selected">'.$product_name.'('.$this_username.")</option>";
					}
					else
					{
						echo '<option value="'.$this_buy_id.'">'.$product_name.'('.$this_username.")</option>";				
					}			
				}

			}
		}while(0);
		
		mysql_close($db_link);
	}			
 ?>
				</select> <span class="input_tips_txt" id="tipsProductSelect" ></span>
	</td>
  </tr>
  <tr>
    <td height="6" colspan="2"></td>
  </tr>
  <tr>
    <td height="25" class="objTitle" title="" >备注：</td>
    <td>
		<textarea id="txtBackup" name="txtBackup" style="width:320px;height:46px;font-size:14px;border:1px solid #94C7E7;overflow:auto;" ></textarea>
	</td>
  </tr>
  <tr>
    <td height="10" colspan="2"></td>
  </tr>
  <tr>
    <td colspan="2">
	    <center><input name="btnAddDomain"  type="submit" style="width:95px;height:28px" id="btnAddDomain" value="保存" style="cursor:pointer;" onclick="FikCdn_AddDomain();" /></center></td>
  </tr>
</table>
 <table width="480" border="0">
	<tr>
	<td><p style="padding-left:20px;">说明：<br />
	1. 电信和联通 IP 至少输入一个，双线源站服务器则可两个都输入，其他<br />&nbsp;&nbsp;&nbsp;&nbsp;线路则任意输入一个即可；<br />
	2. 如果同时填写了电信源站 IP 和联通源站 IP，则系统会根据 Fikker 节<br />&nbsp;&nbsp;&nbsp;&nbsp;点服务器的线路类型选择相同线路的源站 IP 作为此域名的源站；<br />
	3. 如果电信或联通有多个源站，则可用“;”间隔填入多个源站IP，如：<br />&nbsp;&nbsp;&nbsp;&nbsp;211.155.23.66;234.34.55.123<br />
	4. 域名添加成功后，需要管理员审核通过才最终通过“<a href="javascript:void(0);" onclick="javescript:FikCdn_ToTaskList();" title="查看后台任务列表">后台任务</a>"方式同步<br />&nbsp;&nbsp;&nbsp;&nbsp;到所有 Fikker 节点服务器的主机管理中；<br />
	</p></td>
	</tr>
</table>

<?php

include_once("./tail.php");
?>
