<?php
namespace Home\Controller;
use Think\Controller;
class AdminController extends CommonController {
    public function index(){
		$mems=D('members');
		//$card=$per_card;
		$card=session("card");
		//var_dump($card);die;
		$result=$mems->where("mem_number='$card'")->find();
		$this->assign('result',$result);
	   if(IS_POST){
		     $condition['mem_id']=I('mem_id');
		  	 //$condition['ad_name']=I('ad_name');
	         $condition['mem_password']=MD5(I('mem_password'));
			 $condition['old_password']=MD5(I('old_password'));
		if($condition['mem_password']==$condition['old_password']){
				  if($mems->create($condition)){
			  if($mems->save($condition)){
				  $this->show_msg('密码修改成功','/salary/index.php/Home/index/index');
				  }else{
				  /*echo "<script type='text/javascript' >alert('密码修改失败')</script>";	*/
				  $this->show_msg('密码修改失败');
					  }
			  }else{
				 $this->error($mems->getError());  
				  }
			  //return;		
			}else{
		
	      $this->show_msg('密码不一致，请重新输入','/salary/index.php/Home/Admin/index');
		        	}
		 
		            }
		
        $this->display();
    }
	
	
		 //封装的消息提示方法，控制器调用此方法 
	  public function show_msg($msg="", $url=""){
             @header("Content-Type:text/html;charset=utf-8");
              echo '<script type="text/javascript">';
              echo 'alert("'.$msg.'");';
              if(!empty($url)){
              echo 'location.href = "'.$url.'"';
                              }else{
                                    echo 'history.go(-1);';
                                   }
              echo '</script>';
              exit;
}


	    public function logout(){
		 session('card',null);
		 $this->redirect('Login/index');
		}
  
	
	
	

}
