<?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);
}
?>
<!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
$action=_post('action');
if($action=="edit")
{
$oldpass=md5(_post('user'));
$newpass=md5(_post('pass'));
$user=$_SESSION["tm_admin"];
$id=$_SESSION["tm_id"];
$sql="select * from tm_admin where id='$id' and pass='$oldpass'";
$result=mysql_fetch_row(mysql_query($sql));
if($result){
 $sql="update tm_admin set pass='$newpass' where id='$id'";
  mysql_query($sql);
  echo "<script>alert('更新成功');location.href='adminpass.php';</script>";
}
else
{
echo ("<script type='text/javascript'> alert('不可更新，旧密码错误');history.go(-1);</script>");
exit();
}
}
?>
<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 width="80%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 CALLPADDING="0">
              <TR BORDER="0" WIDTH="100%">
                <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left width="100%" bgColor=#ffffff height=30><?php echo "用户：";?><font color=red><?php echo $_SESSION["tm_admin"];?></font>,你好！</TD>
              </TR>
			  <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'">
               <form id="form2" name="form2" method="post" action="adminpass.php"> 
                 <TD style="PADDING-LEFT: 8px; PADDING-TOP: 8px" vAlign=top 
                align=left height=30>
                   
                   
                   <div align="left">原密码：
                     <input name="user" type="password" id="user" size="15" />
                   新密码：  
                   <input name="pass" type="password" id="pass" size="15" />
                     <span class="help">
                     <input type="image" src="images/submit.gif" align="absmiddle" border="0" name="submit2" />
                     </span>
                     <input name="action" type="hidden" id="action" value="edit" />
                   </div></TD></form>
              </TR>
      </TBODY></TABLE>	</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>