<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../include/conn.php";
include "../include/function.php";
include "admin_version.php";
include "admin_loginstate.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">
<script S_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);									 
			})							
		}
	})	
	$("#addarea").click(function(){
		 var S_AreaName=$("#S_AreaName").val();
		 var S_TheOrder=$("#S_TheOrder").val();
		 var S_Language=$("#S_Language").val();
		 var reg = /^\-?([1-9]\d*|0)(\.\d+)?$/;
		 $("#S_AreaName").css("border-color","#666 #ccc #ccc #666");
		 $("#S_Language").css("border-color","#666 #ccc #ccc #666");
		 $("#S_TheOrder").css("border-color","#666 #ccc #ccc #666");
		 $("#tishi").text("");
		 if (S_AreaName==""){
			 $("#S_AreaName").css("border","1px solid red");
			 return false;}
		 else if(S_AreaName.length > 50){
			 $("#tishi").text("地区名长度不能超过50个字符！").css("color","red");
			 return false;}
		 else if(S_Language==""){
			 $("#S_Language").css("border","1px solid red");
			 return false;}
		 else if(S_Language.length > 50){
			 $("#tishi").text("语言名长度不能超过50个字符！").css("color","red");
			 return false;}
		 else if(S_TheOrder==""){
			 $("#S_TheOrder").css("border","1px solid red");
			 return false;}
		 else if(S_TheOrder.length > 10){
			 $("#tishi").text("排序长度不能超过10个字符！").css("color","red");
			 return false;}
		 else if(!reg.test(S_TheOrder)){
			 $("#S_TheOrder").css("border","1px solid red");
			 return false;}
	})
$("#btn_editall").click(function(){
		jConfirm('您确定要修改选中的数据吗?', '操作提示', function(r) {
				if(r==true){
					RecoClass.action='?action=editall';
					RecoClass.submit();
					}
				});
	 })
	
$("#btn_delall").click(function(){
		jConfirm('您确定要删除选中的数据吗?', '操作提示', function(r) {
				if(r==true){
					RecoClass.action='?action=delall';
					RecoClass.submit();
					}
				});
	 })

	
})

function del(id){
	jConfirm('您确定要删除此条数据吗?', '操作提示', function(r) {
		if(r==true){
			window.location='?action=del&S_ID='+id;
			}
				});
		
		}
</script>
</head>

<body>
<?php
SystemPer(2);
	class ui_area{
		public function main(){
			global $db;
			$sql="select * from s_area";
			$result=$db->query($sql);
			$areanum=$db->num_rows($result);
?>	
<div class="r_main">
	<div class="r_content">
		<div class="r_content_1">
	<form method="post" name="RecoClass" action=""> 
		<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">
             <tr>
              <td colspan="5" class="td_title">&nbsp;地区语言管理</td>
             </tr>
           <tr>
 <?php
 		if($areanum==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)){
?>
           <td width="66" height="30" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="checkbox" name="S_ID[]" value="<?php echo $row['S_ID']?>" class="checkbox" id="S_ID"/><?php echo $row['S_ID']?>、</td>
            <td width="217" height="30" bgcolor="#FFFFFF" class="td_border">国家地区：
              <input name="S_AreaName<?php echo $row['S_ID']?>" type="text" value="<?php echo $row['S_AreaName']?>" size="20" /></td>
            <td width="220" height="30" bgcolor="#FFFFFF" class="td_border">语言种类：
             <input name="S_Language<?php echo $row['S_ID']?>" type="text" value="<?php echo $row['S_Language']?>" size="20" /></td>
            <td width="107" height="30" 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 width="83" height="30" align="center" bgcolor="#FFFFFF" class="td_border">
<input type="button" value="删除" onclick="del(<?php echo $row['S_ID']?>)"  class="rb1">
			 </td>
          </tr>

<?php					
					}
				}
 ?>          


		<tr>
  <td height="30" colspan="5" align="left" bgcolor="#FFFFFF" class="td_border">&nbsp;<input type="checkbox" name="ChkAll" id="ChkAll" ids="S_ID"  class="checkbox"/>
  全选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="button" name="" value="修改所选地区" class="rb1"  id="btn_editall"/>&nbsp;&nbsp;<input type="button" name="" value="删除所选地区"  class="rb1" id="btn_delall"/></td>
          </tr>
        </table> 
          </form>
        
			  <form id="form1" name="form1" method="post" action="?action=saveadd">
					<table width="100%" border="0" cellpadding="0" cellspacing="0"   class="tb_style">

		<tr>
              <td colspan="5" class="td_title">&nbsp;地区语言添加&nbsp;&nbsp;&nbsp;<label id="tishi"></label></td>
             </tr>
					  
					<tr >
						<td width="66"  height="30" align="center" bgcolor="#FFFFFF"  class="td_border" >&nbsp;</td>
                         <td width="217" bgcolor="#FFFFFF"  class="td_border" >&nbsp;国家地区：
                         <input name="S_AreaName" type="text" id="S_AreaName" value="" size="20" /></td>
                         <td width="220"  height="30" bgcolor="#FFFFFF" class="td_border">
						  语言种类：
					    <input name="S_Language" type="text" id="S_Language" value="" size="20" />						</td>
						<td width="107"  height="30" bgcolor="#FFFFFF"  class="td_border">排序：						  
						  <input type="text" name="S_TheOrder" id="S_TheOrder" value="0" size="5" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"/></td>
                        <td width="83"  height="30" align="center" bgcolor="#FFFFFF"  class="td_border"><input type="submit" name="button" id="addarea" value="增加" class="rb1" /></td>
					  </tr>
				</table>
		  </form>
		</div>
	</div>
</div>        
<?php			
			}
		}
?>        

<?php
$ui=new ui_area;
$action=SafeRequest("action","get");
switch($action){
		case 'main':
			$ui->main();
			break;
		case 'saveadd':
			saveadd();
			break;
		case 'del':
			del();
			break;
		case 'delall':
			delall();
			break;
		case 'editall':
			editall();
			break;
		default:
			$ui->main();
	}
	
	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_AreaName=SafeRequest("S_AreaName".$ID[$i]."","post");
				$S_Language=SafeRequest("S_Language".$ID[$i]."","post");
				$S_TheOrder=SafeRequest("S_TheOrder".$ID[$i]."","post");
			if(!IsNul($S_AreaName)){die("<script>jAlert('地区语言名称不能为空!','操作提示',function(R){history.back();})</script>");}
			if(!IsNul($S_Language)){die("<script>jAlert('地区语言别名称不能为空!','操作提示',function(R){history.back();})</script>");}
				$sql="update s_area set S_AreaName='".$S_AreaName."',S_Language='".$S_Language."',S_TheOrder=".$S_TheOrder." where S_ID=".$ID[$i]."";
				$db->query($sql);
				}
			die("<script>jAlert('恭喜！恭喜地区语言编辑成功!','操作提示',function(R){window.location='admin_area.php';})</script>");
			}			
		}
	
	function delall(){
		global $db;
		$S_ID=RequestBox("S_ID");
		$sql="delete from s_area where S_ID in ($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_area.php';})</script>");
				}
			}
		}
		
		
	function del(){
		global $db;
		$S_ID=SafeRequest("S_ID","get");
		if(!IsNum($S_ID)){die("<script>jAlert('ID传输错误?','操作提示',function(R){history.back();})</script>");}
		$sql="delete from s_area where S_ID=".$S_ID."";
		if($db->query($sql)){
		echo "<script>window.location='admin_area.php';</script>";
			}
		}
	
	function saveadd(){
		global $db;
		$S_AreaName=SafeRequest("S_AreaName","post");
		$S_Language=SafeRequest("S_Language","post");
		$S_TheOrder=SafeRequest("S_TheOrder","post");
		$sql="Insert s_area (S_AreaName,S_Language,S_TheOrder) values ('".$S_AreaName."','".$S_Language."',".$S_TheOrder.")";
		$db->query($sql);
		echo "<script>window.location='admin_area.php';</script>";
		}	
?>
<?php include "admin_bottom.php"; ?>
</body>
</html>