/modules/admin/user.php
PHP | 170 lines | 129 code | 19 blank | 22 comment | 16 complexity | f257b9bf113742f0f30bdcc54c5a2c76 MD5 | raw file
- <?php
- if (!defined('SPEEDCMS')) { exit(1);}
- import ($GLOBALS['spConfig']['controller_path'].'/general.php');
-
- /**
- * ???????
- * @author Harrie
- * @version 1.0
- * @created 2010-06-28
- */
- class user extends general
- {
- public function __construct(){ // ??
- parent::__construct(); // ?????
- $this->tpl_title = T("Users");
- $this->navigation_current = 'user';
- }
-
- public function index(){ // ?????
- $current_page = $this->spArgs("page",1);
- $page_size = $this->spArgs("size",10);
-
- $objUser = spClass("userModel");
- $arrUser = $objUser->spPager($current_page, $page_size)->findAll(null,'uid desc');
- $arrBar = $objUser->spPager()->getPager();
- $this->tPageBar = $arrBar;
- $this->tUsers = $arrUser;
- $this->display("admin/user_index.html");
- }
-
- public function add(){
- $intNid = $this->spArgs("nid");
- $objUser = spClass("userModel");
- $this->tUserEnabled = $objUser->userEnabled();
- $objUsergroup = spClass("usergroupModel");
- $this->tUserGroup = $objUsergroup->glist($this->getLang());
- $this->action = 'add';
- $this->display("admin/user_form.html");
- }
-
- public function edit(){
- $uid = $this->spArgs("uid");
- $objUser = spClass("userModel");
- $this->user = $objUser->userDetail($uid);
- $this->tUserEnabled = $objUser->userEnabled();
- $objUsergroup = spClass("usergroupModel");
- $this->tUserGroup = $objUsergroup->glist($this->getLang());
- $this->action = 'edit';
- $this->display("admin/user_form.html");
- }
-
- public function profile(){
- $uid = $this->spArgs("uid");
- $objUser = spClass("userModel");
- $this->user = $objUser->userDetail($uid);
- $this->tUserEnabled = $objUser->userEnabled();
- $objUsergroup = spClass("usergroupModel");
- $this->tUserGroup = $objUsergroup->glist($this->getLang());
- $this->display("admin/user_profile.html");
- }
-
- public function post(){
- $uid = $this->spArgs("uid");
- $strAction = $this->spArgs("action");
- $data = array(
- 'uname' => $this->spArgs("uname"),
- 'firstname' => $this->spArgs("firstname"),
- 'lastname' => $this->spArgs("lastname"),
- 'email' => $this->spArgs("email"),
- 'street' => $this->spArgs("street"),
- 'city' => $this->spArgs("city"),
- 'country' => $this->spArgs("country"),
- 'state' => $this->spArgs("state"),
- 'zip' => $this->spArgs("zip"),
- 'tel' => $this->spArgs("tel"),
- 'enabled' => $this->spArgs("enabled"),
- );
- $password = $this->spArgs("upass");
- $confirmpassword = $this->spArgs("confirmpassword");
- if($password!='' && $password=$confirmpassword){
- $data['upass'] = md5($password);
- }
-
- $objUser = spClass("userModel");
- $userExist = $objUser->userExist($data['uname'], $uid);
- if($userExist){
- $this->jsonerror("'uname': '".T('Username occupied.')."'");
- }
-
- $emailExist = $objUser->emailExist($data['email'], $uid);
- if($emailExist){
- $this->jsonerror("'email': '".T('Email occupied.')."'");
- }
- if ($strAction == 'add'){
-
- $objUser->create($data);
- }elseif($strAction == 'edit'){
- $conditions = array('uid'=>$uid);
- $objUser->update($conditions, $data);
- }
- $this->jsonsuccess(T('Successfully ' . $strAction . 'ed!' ), spUrl("user","index"));
- }
-
- public function delete(){
- $uid = $this->spArgs("uid");
- $objUser = spClass("userModel");
- $conditions = array('uid' => $uid);
- $objUser->delete($conditions); // ????
- $this->success(T('Successfully deleted!' ), spUrl("user","index"));
- }
-
- // ????
- public function logout(){
- // ???PHP.net????SESSION???
- $_SESSION = array();
- if (isset($_COOKIE[session_name()])) {setcookie(session_name(), '', time()-42000, '/');}
- session_destroy();
- $userObj = spClass("userModel"); // ???userModel?
- // ?????
- $this->success(T("You are now signed out."), spUrl("user","login"));// ?????????
- }
-
- // ?????????????????
- public function login(){
- import("spAcl.php"); // ??Acl?????????????????
- $userObj = spClass("userModel"); // ???userModel?
- if( $uname = $this->spArgs("uname") ){ // ???????????????
- $upass = $this->spArgs("upass"); // ??acl?upass???????
-
- // ??spVerifier???????
- $rows = array('uname' => $uname, 'upass' => upass);
- $results = $userObj->spVerifier($rows);
-
- if( false == $results ){ // ?spVerifier??false?????????????????????
-
- // ??lib_user???????userlogin???????????
- if( false == $userObj->userlogin($uname, $upass) ){
- // ???????????????
- $this->error(T("The username address or password you provided does not match our records."), spUrl("user","login"));//"???/???????????"
-
- }else{
- // ??????????????????
- // ???????GBADMIN?????????admin/index?????
- // ???????GBUSER????????????
- $useracl = spClass("spAcl")->get(); // ??acl?get??????????????
- if( "WEBMASTER" == $useracl ){
- $this->success(T("Welcome, the administrator"), spUrl("main","index"));//?????????????
- }else{
- $this->success(T("Welcome, Dear Member."), spUrl("main","index"));//???????????????
- }
- }
- }else{
- // $results??false???????????????$results
- // dump($results);
- foreach($results as $item){ // ???????????????????
- // ????????????????????????????$item???????
- foreach($item as $msg){
- // ?????????????????????????????
- // ????????????????????$this->error??????
- $this->error($msg,spUrl("user","login"));
- }
- }
- }
- }
- // ???????????????????main_login.html?????
- $this->display("admin/user_login.html");
- }
-
-
- }