<?php
/*
'**************************************************************************************************
' 软件名称: 搜一次 Content Management System
' 版本编号: Version 1.X
' 官方网站: http://www.syccms.com
' 官方论坛：http://bbs.syccms.com
' 版权所有: 搜一次运营团队
' 法律顾问: 杭州市元茂律师事务所 严飞律师
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、搜一次网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "admin_loginstate.php";
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link  href="images/style.css" rel="stylesheet" type="text/css" />
<title>友情链接</title>
<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>
<script src="js/jquery.js"></script>
<script language="javascript" src="js/alerts.js"></script>
<link type="text/css" href="images/alerts.css" rel="stylesheet" media="screen">
</head>
<script language="javascript">
 $(document).ready(function(){
	$("#ChkAll").click(function(){
		if($(this).attr("checked")==true){
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",true);									 
			})							
		}else{
			$("input[id='S_ID']").each(function(){
				$(this).attr("checked",false);									 
			})							
		}
	})	
	$("#addlink").click(function(){
		 $("#S_Name").css("border-color","#666 #ccc #ccc #666");
		 $("#sname").text("");
		 $("#SInPut").text("");
		 $("#S_Pic").text("");
		 $("#S_Url").css("border-color","#666 #ccc #ccc #666");
		 $("#SWebUrl").text("").css("color","red");
		 var S_Name=$("#S_Name").val();
		 var S_Url=$("#S_Url").val();
		 var S_Pic=$("#S_Pic").val();
		 var S_InPut=$("#S_InPut").val();
		 if (S_Name==""){
			 $("#S_Name").css("border","1px solid red");
			 $("#sname").text("请填写网站名！").css("color","red");
			 return false;}
		 else if(S_Name.length > 50){
		 	 $("#S_Name").css("border","1px solid red");
			 $("#sname").text("网站名不能超过50个字符！").css("color","red");
			 return false;}
		 else if(S_Url==""){
			 $("#S_Url").css("border","1px solid red");
			 $("#SWebUrl").text("请填写网站链接！").css("color","red");
			 return false;}
		 else if(S_Url.length > 100){
		 	 $("#S_Url").css("border","1px solid red");
			 $("#SWebUrl").text("网站链接不能超过100个字符！").css("color","red");
			 return false;} 
		 else if(S_Pic.length > 150){
			 $("#SPic").text("申请网站地址不能超过100个字符！").css("color","red");	
			 return false;
			 }
		 else if(S_InPut.length > 100){
			 $("#SInPut").text("申请网站地址不能超过100个字符！").css("color","red");
			 return false;
			 }
		 })
	
	$("#btn_editall").click(function(){
		var page=$("#page").val();							 
		jConfirm('确定要编辑选中的友情链接吗?', '操作提示', function(r) {
				if(r==true){
					document.Link.action='?action=editall'
					Link.submit();}
				});
	 })
		
	 $("#btn_delall").click(function(){
		var page=$("#page").val();							 
		jConfirm('确定要删除选中的友情链接吗?', '操作提示', function(r) {
				if(r==true){
					document.Link.action='?action=delall'
					Link.submit();}
				});
	 })
		
})

function del(id,page){
	jConfirm('确定要删除该友情连吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}

</script>

<body>
<?php
	class ui_link{
		
		public function editdata($Arr,$url){
					$name=$Arr[0];
					$lurl=$Arr[1];
					$pic=$Arr[2];
					$class=$Arr[3];
					$input=$Arr[4];
					$isverify=$Arr[5];
					$isindex=$Arr[6];
					$order=$Arr[7];

			
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tb_style">
			<form name="form1" method="post" action="<?php echo $url?>" >
			  <tr>
				<td height="30" colspan="2" class="td_title">&nbsp;<?php echo $name?>友情链接</td>
			</tr>
			  <tr>
				<td width="26%" height="30" align="right" class="td_border">网站名称：</td>
				<td width="74%" class="td_border">&nbsp;<input name="S_Name" type="text" id="S_Name" value="<?php echo $name?>" size="40" />
                    <font color="#FF0000">＊</font>
                <label id="sname"></label>
				</td>
			  </tr>
			  <tr>
				<td height="30" align="right" class="td_border">网站（Url）：</td>
				<td class="td_border">&nbsp;<input name="S_Url" type="text" id="S_Url" value="<?php echo $lurl?>" size="40" />
				    <font color="#FF0000">＊</font>
				  <label id="SWebUrl"></label></td>
			  </tr>
			  <tr>
				<td height="30" align="right" class="td_border">网站Logo地址：</td>
				<td class="td_border">&nbsp;<input name="S_Pic" type="text" id="S_Pic" value="<?php echo $pic?>" size="40" /></td>
			  </tr>
			  
			  <tr>
				<td height="30" align="right" class="td_border" valign="middle">友情链接类型：</td>
				<td class="td_border"><input type="radio" id="S_ClassID" name="S_ClassID"  class="radio" value="1" <?php if($class==1){echo "checked";}?>/> 文字链接&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" id="S_ClassID" name="S_ClassID"  class="radio" value="2" <?php if($class==2){echo "checked";}?>/> 图片链接&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" id="S_ClassID" name="S_ClassID" class="radio"  value="3" <?php if($class==3){echo "checked";}?>/> 合作伙伴&nbsp;&nbsp;&nbsp;&nbsp;
				</td>
			  </tr>
			  <tr>
				<td height="30" align="right" class="td_border">网站说明：</td>
				<td class="td_border">&nbsp;<input type="text" name="S_InPut" id="S_InPut" value="<?php echo $input?>"  size="40" /><label id="SInPut"></label></td>
			  </tr>
			  <tr>
				<td align="right" class="td_border" height="30">是否审核通过：</td>
				<td class="td_border">
					<input type="radio" name="S_IsVerify" class="radio" id="S_IsVerify" value="0" <?php if($isverify==0){echo "checked";}?>/>是&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="radio" name="S_IsVerify" class="radio" id="S_IsVerify" value="1" <?php if($isverify==1){echo "checked";}?>/>否</td>
			  </tr>
			  <tr>
				<td align="right" class="td_border" height="30" >是否首页显示：</td>
				<td class="td_border" >
				
					<input type="radio" name="S_IsIndex" class="radio" id="S_IsIndex" value="0"  <?php if($isindex==0){echo "checked";}?>/>是&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="radio" name="S_IsIndex" class="radio" id="S_IsIndex" value="1"  <?php if($isindex==1){echo "checked";}?>/>否</td>
			  </tr>
			  <tr>
				<td height="30" align="right" class="td_border">&nbsp;</td>
				<td class="td_border" height="30"> &nbsp;
				  <input type="submit" name="Submit" value="确定提交" class="rb1" id="addlink"/>
				  &nbsp;&nbsp; <input type="reset" name="Submit2" value="清除重置" class="rb1" /></td>
			  </tr>
			</form>  
</table>
		</div>
	</div>
</div>
<?php			
			}
		
		public function main(){
			global $db;
			$Arr=getpagerow("select * from s_link",20);//sql,每页显示条数
			$result=$db->query($Arr[2]);
			$linknum=$db->num_rows($result);
?>
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
					<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style" >
                      <form method="post" name="Link" action="">
                      <tr>
                        <td colspan="8" class="td_title" height="30">&nbsp;友情链接管理</td>
                      </tr>
                      <tr>
                        <td width="79" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;&nbsp;编号</td>
                        <td width="180" align="center" bgcolor="#FFFFFF" class="td_border">网站名称<font color="#FF0000">(＊)</font></td>
                        <td width="272" align="center" bgcolor="#FFFFFF" class="td_border">网站地址<font color="#FF0000">(＊)</font></td>
                        <td width="84" align="center" bgcolor="#FFFFFF" class="td_border">排序</td>
                        <td width="123" align="center" bgcolor="#FFFFFF" class="td_border">类型</td>
                        <td width="72" align="center" bgcolor="#FFFFFF" class="td_border">审核</td>
                         <td width="69" align="center" bgcolor="#FFFFFF" class="td_border">首页</td>
                         <td width="127" align="center" bgcolor="#FFFFFF" class="td_border">操作</td>
                      </tr>
                       <?php
					   if($linknum==0) echo "
							<tr>
                            	<td colspan=\"8\" class=\"td_border\" height=\"30\" align=center><b>暂无友情链接,请添加！</b></td>
                            </tr>";						   
                       if($result){
						   while ($row = $db ->fetch_array($result)){

					   ?>   
				<tr>
				  <td width="79" height="28" bgcolor="#FFFFFF" class="td_border">&nbsp;
			      <input type="checkbox" name="S_ID[]" id="S_ID" value="<?php echo $row["S_ID"]?>" class="checkbox"/><?php echo $row["S_ID"]?>、</td>
				  <td align="center" bgcolor="#FFFFFF" class="td_border">
			      <input type="text" name="S_Name<?php echo $row["S_ID"]?>" value="<?php echo $row["S_Name"]?>" size="15" /></td>
				  <td align="center" bgcolor="#FFFFFF" class="td_border"><input type="text" name="S_Url<?php echo $row["S_ID"]?>" value="<?php echo $row["S_Url"]?>" size="30" /></td>
                  <td align="center" bgcolor="#FFFFFF" class="td_border"><input type="text" name="S_TheOrder<?php echo $row["S_ID"]?>" value="<?php echo $row["S_TheOrder"]?>"size="5"/></td>
				  <td align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;	
				  <?php 
				  if($row['S_ClassID']==1){echo "文字连接";}
				  elseif($row['S_ClassID']==2){echo "图片连接";}
				  else{echo "合作伙伴";}
				  ?></td>
				  <td align="center" bgcolor="#FFFFFF" class="td_border">&nbsp;<?php if($row['S_IsVerify']==0){echo "<a style='cursor:pointer;' onclick=window.location='?action=changeverify&isverify=1&id=".$row['S_ID']."'><img src='../images/common/yes.gif'/></a>";}else{echo "<a style='cursor:pointer;' onclick=window.location='?action=changeverify&isverify=0&id=".$row['S_ID']."'><img src='../images/common/no.gif'/></a>";}?></td>
				  <td align="center" bgcolor="#FFFFFF" class="td_border"><a href="#"><?php if($row['S_IsIndex']==0){echo "<a style='cursor:pointer;' onclick=window.location='?action=changeindex&isindex=1&id=".$row['S_ID']."'><img src='../images/common/yes.gif'/></a>";}else{echo "<a style='cursor:pointer;' onclick=window.location='?action=changeindex&isindex=0&id=".$row['S_ID']."'><img src='../images/common/no.gif'/></a>";}?></a></td>
					<td align="center" bgcolor="#FFFFFF" class="td_border"><a href="?action=editdata&S_ID=<?php echo $row['S_ID']?>">编辑</a>&nbsp;&nbsp;<a style="cursor:pointer;"  onclick="del(<?php echo $row['S_ID']?>)">删除</a></td>
	  </tr>
   <?php
                         							   
		 }
	 }
?> 
      <tr>
            <td height="30" colspan="8" align="left" bgcolor="#FFFFFF" class="td_border">&nbsp;
   <input type="hidden" name="page" id="page" value="<?php echo page?>"><input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID"  class="checkbox"/>全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="" id="btn_editall" value="修改所选链接" class="rb1"   />&nbsp;&nbsp;
  <input type="button" name="" value="删除所选链接"  class="rb1" id="btn_delall" />
 &nbsp; <input type="button" value="添加友情链接"  class="rb1" id="btn_add" onclick="window.location='?action=add'" />
  </td></tr>
      </form>
      <tr><td height="30" colspan="8" align="right" class="td_border" style="font-size:12px; color:#033d61;">
        <?php echo $Arr[0];?></td></tr>
</table>
		</div>
	</div>
</div>
<?php			
				
			}
		}//end class

?>

<?php
	$ui=new ui_link;
	$action=SafeRequest("action","get");
	switch ($action){
		case 'main':
			$ui->main();
			break;
		case 'editdata':
			editdata();
			break;
		case 'saveedit':
			saveedit();
			break;
		case 'add':
			add();
			break;
		case 'saveadd':
			saveadd();
			break;
		case 'del':
			del();
			break;
		case 'delall':
			delall();
			break;
		case 'editall':
			editall();
			break;
		case 'changeverify':
			changeverify();
			break;
		case 'changeindex':
			changeindex();
			break;
		default:
			$ui->main();
		}
	function changeindex(){
		global $db;
		$isindex=SafeRequest("isindex","get");
		$id=SafeRequest("id","get");
		if(!IsNum($isindex)) $isindex=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");
		$sql="update s_link set S_IsIndex=$isindex where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_link.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");
			}			

		}		
		
	function changeverify(){
		global $db;
		$isverify=SafeRequest("isverify","get");
		$id=SafeRequest("id","get");
		if(!IsNum($isverify)) $isverify=0;
		if(!IsNum($id)) die("<script>jAlert('id传输错误?','操作提示',function(R){history.back();})</script>");
		$sql="update s_link set S_IsVerify=$isverify where S_ID=$id";
		if($db->query($sql)){
			die("<script>window.location='admin_link.php';</script>");
			}
		else{
			die("<script>jAlert('未知错误!','操作提示',function(R){history.back();})</script>");
			}			

		}
	function editall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		if($S_ID=="0"){
			die("<script>jAlert('请选择要编辑的友情链接?','操作提示',function(R){history.back();})</script>");
			}
		else{
			$ID=explode(",",$S_ID);
			
			for($i=0;$i<count($ID);$i++){
				$S_Name=SafeRequest("S_Name".$ID[$i]."","post");
				$S_Url=SafeRequest("S_Url".$ID[$i]."","post");
				$S_Order=SafeRequest("S_TheOrder".$ID[$i]."","post");
			if(!IsNul($S_Name)){echo "<script>jAlert('友情链接名称不能为空!','操作提示',function(R){history.back();})</script>";}
			if(!IsNul($S_Url)){echo "<script>jAlert('友情链接地址不能为空!','操作提示',function(R){history.back();})</script>";}
				$sql="update s_link set S_Name='".$S_Name."',S_Url='".$S_Url."',S_TheOrder=".$S_Order." where S_ID=".$ID[$i]."";
				$db->query($sql);
				}
			die("<script>jAlert('恭喜！友情链接编辑完毕!','操作提示',function(R){window.location='admin_link.php';})</script>");
			}	
		}
		
	function add(){
		global $ui;
		$Arr=array("","","",1,"",0,0,0);
		$ui->editdata($Arr,"?action=saveadd");
		}
		
	function saveadd(){
		global $db;
		$S_Name=SafeRequest("S_Name","post");
		$S_Url=SafeRequest("S_Url","post");
		$S_Pic=SafeRequest("S_Pic","post");
		$S_ClassID=SafeRequest("S_ClassID","post");
		$S_InPut=SafeRequest("S_InPut","post");
		$S_IsVerify=SafeRequest("S_IsVerify","post");
		$S_IsIndex=SafeRequest("S_IsIndex","post");
		$sql="Insert s_link  (S_Name,S_Url,S_Pic,S_ClassID,S_InPut,S_IsVerify,S_IsIndex) values ('".$S_Name."','".$S_Url."','".$S_Pic."','".$S_ClassID."','".$S_InPut."','".$S_IsVerify."',".$S_IsIndex.")";
		//die($sql);
		$db->query($sql);
		echo "<script>window.location='admin_link.php';</script>";
		}


	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_link where S_ID in ($S_ID)";
		//die($S_ID);
		if($S_ID=="0"){
			die("<script>jAlert('请选择要删除的链接?','操作提示',function(R){history.back();})</script>");
			}
		else{
			if($db->query($sql)){
				die("<script>jAlert('恭喜你！操作成功了！','成功提示',function(R){window.location='admin_link.php';})</script>");
				}
			}	
		}

	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$sql="delete from s_link where S_ID='".$S_ID."'";
		//die($sql);
		if($db->query($sql)){
			echo "<script>window.location='admin_link.php';</script>";
			}
		}


	function saveedit(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		$S_Name=SafeRequest("S_Name","post");
		$S_Url=SafeRequest("S_Url","post");
		$S_Pic=SafeRequest("S_Pic","post");
		$S_ClassID=SafeRequest("S_ClassID","post");
		$S_InPut=SafeRequest("S_InPut","post");
		$S_IsVerify=SafeRequest("S_IsVerify","post");
		$S_IsIndex=SafeRequest("S_IsIndex","post");
		$sql="update s_link set S_Name='".$S_Name."',S_Url='".$S_Url."',S_Pic='".$S_Pic."',S_ClassID=".$S_ClassID.",S_InPut='".$S_InPut."',S_IsVerify=".$S_IsVerify.",S_IsIndex=".$S_IsIndex." where S_ID=".$S_ID."";
		$db->query($sql);
		echo "<script>window.location='admin_link.php';</script>";
		}

	function editdata(){
		global $db;
		global $ui;
		$S_ID=SafeRequest("S_ID","get");
		if(IsNum($S_ID)){
			$sql="SELECT * FROM `s_link` Where S_ID='".$S_ID."'";
			$row=$db->Getrow($sql);
				if($row){
					$Arr=array($row['S_Name'],$row['S_Url'],$row['S_Pic'],$row['S_ClassID'],$row['S_InPut'],$row['S_IsVerify'],$row['S_IsIndex'],$row['S_TheOrder']);
					}
				$ui->editdata($Arr,"?action=saveedit&S_ID=".$S_ID."");
			}
		}

	
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>