<?php
require("session_check.php");	
	
	//语言包引入
	$f_langpackage=new foundationlp;
	
	//变量区
	$module=short_check(get_argg('module'));	
	$str='';
	
	$dbo = new dbex;
	dbtarget('w',$dbServs);
	
	if($module=="group"){
		
		$mod="group";
		
		$str=$f_langpackage->f_group_sort;
				
		$t_group_type=$tablePreStr."group_type";
		
		$sql="select * from $t_group_type order by order_num desc";
	}
	
	if($module=="pals"){
		
		$mod="pals";
		
		$str=$f_langpackage->f_fir_sort;
		
		$t_pals_def_sort=$tablePreStr."pals_def_sort";
		
		$sql="select * from $t_pals_def_sort order by order_num desc";
	}
	
	$sort_rs=$dbo->getRs($sql);
	

?>
<html>
<head>
<title>类别管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/right.css">
<script type='text/javascript'>
	
	function create_xmlhttp()
{
     if(window.ActiveXObject)
	 		{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	 		}else{
	 			xmlhttp=new XMLHttpRequest();
	 			}
}

function manager_sort(modules,sort_id,type_value)
{
	 create_xmlhttp();
	 if(type_value=="add"){var sort_name=document.getElementById("add_value").value;var sort_order=document.getElementById("add_order_num").value;}
	 if(type_value=="change"){var sort_name=document.getElementById("input_title_"+sort_id).value;var sort_order=document.getElementById("input_num_"+sort_id).value;}	 
	 xmlhttp.open("post","manager_sort.action.php?module="+modules+"&type_value="+type_value+"&sort_id="+sort_id,true);
	 xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	 xmlhttp.onreadystatechange=function()
	 {
	 		if(xmlhttp.readyState==4&&xmlhttp.status==200)
	 			{
			 	var return_str=xmlhttp.responseText;
				var	return_text=return_str.replace(/[\s\n\r]/g,"");
		  	window.location.reload();
	 			}
	 	}
	 	xmlhttp.send("sort_name="+sort_name+"&sort_order="+sort_order);
}

function add_sort(show_1,show_2,hidden_1,hidden_2){
	document.getElementById(show_1).style.display="none";
	document.getElementById(show_2).style.display="";
	document.getElementById(hidden_1).style.display="";
	document.getElementById(hidden_2).style.display="";
	}
	
function cancel_sort(show_1,show_2,hidden_1,hidden_2){
	document.getElementById("add_value").value="";
	document.getElementById(show_1).style.display="";
	document.getElementById(show_2).style.display="none";
	document.getElementById(hidden_1).style.display="none";
	document.getElementById(hidden_2).style.display="none";
	}	
	
function change_sort(show_1,show_2,show_3,hidden_1,hidden_2,hidden_3){
	document.getElementById(show_1).style.display="none";
	document.getElementById(show_2).style.display="none";
	document.getElementById(show_3).style.display="none";	
	document.getElementById(hidden_1).style.display="";
	document.getElementById(hidden_2).style.display="";	
	document.getElementById(hidden_3).style.display="";
	}
	
function cancel_change(show_1,show_2,show_3,hidden_1,hidden_2,hidden_3){
	document.getElementById(show_1).style.display="";
	document.getElementById(show_2).style.display="";
	document.getElementById(show_3).style.display="";
	document.getElementById(hidden_1).style.display="none";
	document.getElementById(hidden_2).style.display="none";	
	document.getElementById(hidden_3).style.display="none";
	}

</script>
</head>
<body>
<div class="container">
	<div class="rs_head"><?php echo $str;?></div>
</div>
<table class='main' cellspacing=0 id="mytable">
	<tr><th width="100px"><?php echo $f_langpackage->f_arrange_num?></th><th><?php echo $f_langpackage->f_name?></th><th width="300px"><?php echo $f_langpackage->f_handle?></th></tr>
<?php foreach($sort_rs as $rs){?>
	<tr>
		<td>
			<div id="show_num_<?php echo $rs['id'];?>"><?php echo $rs['order_num'];?></div>
			<div id="order_by_<?php echo $rs['id'];?>" style="display:none">
			<input type="text" size="5" id="input_num_<?php echo $rs['id'];?>" maxlength="15" value="<?php echo $rs['order_num'];?>" />
			</div>
		</td>
		<td>
		<div id="show_title_<?php echo $rs['id'];?>"><?php echo $rs['name'];?></div>
		<div id="title_<?php echo $rs['id'];?>" style="display:none">
		<input type="text" id="input_title_<?php echo $rs['id'];?>" maxlength="30" value="<?php echo $rs['name'];?>" />
		</div>
		</td>
		<td>	
		<div id="button_<?php echo $rs['id'];?>">
			<a href="javascript:change_sort('show_num_<?php echo $rs['id'];?>','show_title_<?php echo $rs['id'];?>','button_<?php echo $rs['id'];?>','order_by_<?php echo $rs['id'];?>','title_<?php echo $rs['id'];?>','action_<?php echo $rs['id'];?>')"><?php echo $f_langpackage->f_amend?></a> | 
			<a href="javascript:manager_sort('<?php echo $mod;?>','<?php echo $rs[id];?>','del')" onclick='return confirm("<?php echo $f_langpackage->f_del_con?>");'><?php echo $f_langpackage->f_del?></a>
		</div>
		<div id="action_<?php echo $rs['id'];?>" style="display:none">
			<input type='button' onclick='manager_sort("<?php echo $mod;?>","<?php echo $rs[id];?>","change")' class='top_button' value='<?php echo $f_langpackage->f_confirm?>' />
			<input type='button' onclick=cancel_change('show_num_<?php echo $rs['id'];?>','show_title_<?php echo $rs['id'];?>','button_<?php echo $rs['id'];?>','order_by_<?php echo $rs['id'];?>','title_<?php echo $rs['id'];?>','action_<?php echo $rs['id'];?>') class='top_button' value='<?php echo $f_langpackage->f_cancel?>' />
		</div>
		</td>
	</tr>
	<tr><td class="dotted_line" colspan="3" style="line-height:100%;">&nbsp</td></tr>
<?php }?>
<tr height="40px">
	<td>
		<div id="order_num" style="display:none">
			<input type='text' id='add_order_num' name='add_order_num' maxlength='15' value='' size='5' />
		</div>
	</td>
	<td>
		<div id="sort_input" style="display:none">
			<input type='text' id='add_value' name='add_value' maxlength='15' value='' size='30' />
		</div>
	</td>
	<td><div id="add_button"><input type="button" onclick='add_sort("add_button","order_num","sort_input","add_action");' class="top_button" style="width:60px" value="<?php echo $f_langpackage->f_add_sort?>" /></div>
			<div id="add_action" style="display:none">
				<input type='button' onclick=manager_sort('<?php echo $mod;?>','0','add') class='top_button' value='<?php echo $f_langpackage->f_confirm?>' />
				<input type='button' onclick='cancel_sort("add_button","order_num","sort_input","add_action");' class='top_button' value='<?php echo $f_langpackage->f_cancel?>' />
		 </div>
	</td>
</tr>
</table>	
</div>
</body>
</html>