<?php

namespace Admin\Controller;

use Think\Controller;

/**
 * 安全管理（控制器）
 *
 * @author sunxiaodong
 */
class SafeController extends CheckController {

    public function index() {
        if(IS_POST)
        {
        $id = session('id');
        $list = M('admin')->find($id);
        $oldpwd =$list['password'];
        $password = md5(I('post.oldpassword'));
        $data['password'] = md5(I('post.password'));
        if($oldpwd!=$password)
        {
            echo "<script>alert('原密码输入不正确！');parent.location.href='/index.php/Admin/Safe/index?column=xgmm'; </script>"; 
        }
        else
        {
            if(M('admin')->where("id=$id")->save($data))
            {
                 $id = session('id');
                 session('id', null);
                 session('name', null);
                 session('[destroy]');
                echo "<script>alert('修改成功！,请重新登陆！');parent.location.href='/index.php/Admin/Safe/index?column=xgmm'; </script>";
            }
            else
            {
                $this->error("修改失败");
            }
        }
        }
        $on = I('column');
        $this->assign('list',$list);
        $this->assign("on", $on);
        $this->display();
    }

}
