<?php
include("qs.php");
require( '../data/config.php');
$conn=mysql_connect($db_host,$db_user,$db_pass);
mysql_query("set names 'utf8'");
mysql_select_db($db_name);
if (PHP_VERSION >= '5.1' && !empty($timezone))
{
    date_default_timezone_set($timezone);
}
$qs=explode(",",$_SESSION["tm_qs"]);
if($qs[0]==0)
   {
   echo "<script>location.href='main.php';</script>";
   exit();
   }
?>
<!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=UTF-8" />
<META http-equiv="Pragma" content="no-cache" />
<LINK href="css/general.css" rel="stylesheet" type="text/css" />
<LINK href="css/main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
</HEAD><BODY>
<?php 
if(_post('action')=="edit")
{
$id=_post('id');
if($id==1)
   {
   echo "<script>alert('最高管理员不可改权限！');location.href='admin.php';</script>";
   exit();
   }
$rs=mysql_fetch_object(mysql_query("select * from tm_admin where id='$id'"));
if(!$rs)
  {
  echo "<script>alert('管理员不存在！');location.href='admin.php';</script>";
   exit();
  }
$qs="";
for($i=1;$i<=10;$i++)
   {
   if(_post("qs".$i)==1)
      {
	  if($i==20)
	  $qs.="1";
	  else
      $qs.="1,";
	  }
   else 
      {
	  if($i==10)
	  $qs.="0";
	  else
      $qs.="0,";
	  }
   }
mysql_query("update tm_admin set qs='$qs' where id='$id'");
echo "<script>alert('权限修改成功！');location.href='admin.php';</script>";
exit();
}
$id=_get('id');
if($id==1)
   {
   echo "<script>alert('最高管理员不可改权限！');location.href='admin.php';</script>";
   exit();
   }
$rs=mysql_fetch_object(mysql_query("select * from tm_admin where id='$id'"));
if(!$rs)
  {
  echo "<script>alert('管理员不存在！');location.href='admin.php';</script>";
   exit();
  }
$qs=array();
$qs=explode(",",$rs->qs);
?>
<div class="h2">系统管理 >> 帐号管理</div>
<div class="list-div">

<table cellspacing='1' cellpadding='3'>
<tr>
  <th align='left'><table width="100" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><div align="left">&nbsp;&nbsp;帐号管理</div></td>
        <td width="150">&nbsp;</td>
      </tr>
    </table></th>
</tr>
<tr><td align="left" valign="top" style="background:#F5F5F5;padding-bottom:8px;"><TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 CALLPADDING="0">
<?php 
if(_post('action')=="edit")
{
$id=_post('id');
if($id==1)
   {
   echo "<script>alert('最高管理员不可改权限！');location.href='admin.php';</script>";
   exit();
   }
$rs=mysql_fetch_object(mysql_query("select * from tm_admin where id='$id'"));
if(!$rs)
  {
  echo "<script>alert('管理员不存在！');location.href='admin.php';</script>";
   exit();
  }
$qs="";
for($i=1;$i<=10;$i++)
   {
   if($_POST["qs".$i]==1)
      {
	  if($i==20)
	  $qs.="1";
	  else
      $qs.="1,";
	  }
   else 
      {
	  if($i==10)
	  $qs.="0";
	  else
      $qs.="0,";
	  }
   }
mysql_query("update tm_admin set qs='$qs' where id='$id'");
echo "<script>alert('权限修改成功！');location.href='admin.php';</script>";
exit();
}
$id=_get('id');
if($id==1)
   {
   echo "<script>alert('最高管理员不可改权限！');location.href='admin.php';</script>";
   exit();
   }
$rs=mysql_fetch_object(mysql_query("select * from tm_admin where id='$id'"));
if(!$rs)
  {
  echo "<script>alert('管理员不存在！');location.href='admin.php';</script>";
   exit();
  }
$qs=array();
$qs=explode(",",$rs->qs);
?>
			  <form id="form2" name="form2" method="post" action="qs_w.php">
              <TR BORDER="0" WIDTH="100%" bgcolor="#EEEEEE" onmousemove="this.style.color='#000000';this.style.backgroundColor='#D5D5D5'" onmouseout="this.style.backgroundColor='#EEEEEE';this.style.color='#000000'">
                <TD  height=25 
                align=left vAlign=top style="PADDING-LEFT: 8px; PADDING-TOP: 8px; border-bottom:#666666 dotted 1px;"><input name="qs1" type="checkbox" id="qs1" value="1" <?php if($qs[0]==1) echo 'checked="checked"';?> />
                系统信息</TD>
                <TD 
                align=left vAlign=top style="PADDING-LEFT: 8px; PADDING-TOP: 8px; border-bottom:#666666 dotted 1px;"><input name="qs2" type="checkbox" id="qs2" value="1" <?php if($qs[1]==1) echo 'checked="checked"';?> />
                日志管理</TD>
                <TD 
                align=left vAlign=top style="PADDING-LEFT: 8px; PADDING-TOP: 8px; border-bottom:#666666 dotted 1px;"><input name="qs3" type="checkbox" id="qs3" value="1" <?php if($qs[2]==1) echo 'checked="checked"';?> />
                广告管理</TD>
              </TR>
			<TR BORDER="0" WIDTH="100%">
              <TD height="30" colspan="7">&nbsp;&nbsp;<span class="help">
                <input type="image" 
                        src="images/submit.gif" align="absmiddle" border="0" 
                        name="submit" onclick="return checkform(this.form)" />
              </span>&nbsp;&nbsp;
                <input name="action" type="hidden" id="action" value="edit" />
                <input name="id" type="hidden" id="id" value="<?php echo $id;?>" /></TD>
			</TR>
		  </form>
<TR BORDER="0" WIDTH="100%">
    <TD height="30" colspan="7">&nbsp;</TD>
  </TR>
      </TABLE></td>
</tr></table></div>

<?php include "boot.php";?>
</body></html>
<script language="JavaScript" >

function chkform(theForm,msg,action){
	if (confirm(msg)){

		document.forms[theForm].action.value = action;
		document.forms[theForm].submit();
		return true;
	}else{
		return false;
	}
}

// -------- 全選或取消 checkbox 方塊
<!--
function select_all(formName, elementName, selectAllName) {
	if(document.forms[formName].elements[selectAllName].checked) {
		
		if(document.forms[formName].elements[selectAllName].length = 1 &&
		    typeof(document.forms[formName].elements[elementName]) != "undefined" ) {
		
			document.forms[formName].elements[elementName].checked = true;

		    for(var i = 0; i < document.forms[formName].elements[elementName].length; i++)
			document.forms[formName].elements[elementName][i].checked = true;
		}
	}
	else {
		if(document.forms[formName].elements[selectAllName].length = 1 &&
		    typeof(document.forms[formName].elements[elementName]) != "undefined" ) {
			document.forms[formName].elements[elementName].checked = false;

		    for(var i = 0; i < document.forms[formName].elements[elementName].length; i++)
				document.forms[formName].elements[elementName][i].checked = false;
		}
	}
}
//-->
</script>