<?php
require('common.php');

$pagetitle = '修改密码';
$fileurl = 'editpwd.php';
$tempfile = 'editpwd.html';
$table = $DB->table('admin');

if ($action == 'saveedit') {
	$user_name = trim($_POST['user_name']);
	$user_pass = trim($_POST['user_pass']);
	$new_pass = trim($_POST['new_pass']);
	$new_pass1 = trim($_POST['new_pass1']);
	
	if (empty($user_name)) {
		msgbox('请输入账户名称！');
	}
	if (empty($user_pass)) {
		msgbox('请输入原始密码！');
	}
	if (empty($new_pass)) {
		msgbox('请输入新密码！');
	}
	if (empty($new_pass1)) {
		msgbox('请输入确认密码！');
	}
	if ($new_pass != $new_pass1) {
		msgbox('您两次输入的密码不一致！');
	}
	
	$user_pass = md5($user_pass);
	$new_pass = md5($new_pass);
	
	$admin = $DB->fetch_one("SELECT admin_id, admin_pass FROM $table WHERE admin_name='$user_name'");
	if (!$admin) {
		msgbox('不存在此用户！');
	} else {
		if ($user_pass != $admin['admin_pass']) {
			msgbox('您输入的原始密码不正确！');
		}
		$DB->update($table, array('admin_name' => $user_name, 'admin_pass' => $new_pass), array('admin_id' => $admin['admin_id']));
	}
	
	msgbox('密码修改成功！', $fileurl);
}

$smarty->assign('login_user', $myself['user_name']);
smarty_output($tempfile);
?>