PageRenderTime 28ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/admin/user.php

http://speedcms.googlecode.com/
PHP | 170 lines | 129 code | 19 blank | 22 comment | 16 complexity | f257b9bf113742f0f30bdcc54c5a2c76 MD5 | raw file
  1. <?php
  2. if (!defined('SPEEDCMS')) { exit(1);}
  3. import ($GLOBALS['spConfig']['controller_path'].'/general.php');
  4. /**
  5. * ???????
  6. * @author Harrie
  7. * @version 1.0
  8. * @created 2010-06-28
  9. */
  10. class user extends general
  11. {
  12. public function __construct(){ // ??
  13. parent::__construct(); // ?????
  14. $this->tpl_title = T("Users");
  15. $this->navigation_current = 'user';
  16. }
  17. public function index(){ // ?????
  18. $current_page = $this->spArgs("page",1);
  19. $page_size = $this->spArgs("size",10);
  20. $objUser = spClass("userModel");
  21. $arrUser = $objUser->spPager($current_page, $page_size)->findAll(null,'uid desc');
  22. $arrBar = $objUser->spPager()->getPager();
  23. $this->tPageBar = $arrBar;
  24. $this->tUsers = $arrUser;
  25. $this->display("admin/user_index.html");
  26. }
  27. public function add(){
  28. $intNid = $this->spArgs("nid");
  29. $objUser = spClass("userModel");
  30. $this->tUserEnabled = $objUser->userEnabled();
  31. $objUsergroup = spClass("usergroupModel");
  32. $this->tUserGroup = $objUsergroup->glist($this->getLang());
  33. $this->action = 'add';
  34. $this->display("admin/user_form.html");
  35. }
  36. public function edit(){
  37. $uid = $this->spArgs("uid");
  38. $objUser = spClass("userModel");
  39. $this->user = $objUser->userDetail($uid);
  40. $this->tUserEnabled = $objUser->userEnabled();
  41. $objUsergroup = spClass("usergroupModel");
  42. $this->tUserGroup = $objUsergroup->glist($this->getLang());
  43. $this->action = 'edit';
  44. $this->display("admin/user_form.html");
  45. }
  46. public function profile(){
  47. $uid = $this->spArgs("uid");
  48. $objUser = spClass("userModel");
  49. $this->user = $objUser->userDetail($uid);
  50. $this->tUserEnabled = $objUser->userEnabled();
  51. $objUsergroup = spClass("usergroupModel");
  52. $this->tUserGroup = $objUsergroup->glist($this->getLang());
  53. $this->display("admin/user_profile.html");
  54. }
  55. public function post(){
  56. $uid = $this->spArgs("uid");
  57. $strAction = $this->spArgs("action");
  58. $data = array(
  59. 'uname' => $this->spArgs("uname"),
  60. 'firstname' => $this->spArgs("firstname"),
  61. 'lastname' => $this->spArgs("lastname"),
  62. 'email' => $this->spArgs("email"),
  63. 'street' => $this->spArgs("street"),
  64. 'city' => $this->spArgs("city"),
  65. 'country' => $this->spArgs("country"),
  66. 'state' => $this->spArgs("state"),
  67. 'zip' => $this->spArgs("zip"),
  68. 'tel' => $this->spArgs("tel"),
  69. 'enabled' => $this->spArgs("enabled"),
  70. );
  71. $password = $this->spArgs("upass");
  72. $confirmpassword = $this->spArgs("confirmpassword");
  73. if($password!='' && $password=$confirmpassword){
  74. $data['upass'] = md5($password);
  75. }
  76. $objUser = spClass("userModel");
  77. $userExist = $objUser->userExist($data['uname'], $uid);
  78. if($userExist){
  79. $this->jsonerror("'uname': '".T('Username occupied.')."'");
  80. }
  81. $emailExist = $objUser->emailExist($data['email'], $uid);
  82. if($emailExist){
  83. $this->jsonerror("'email': '".T('Email occupied.')."'");
  84. }
  85. if ($strAction == 'add'){
  86. $objUser->create($data);
  87. }elseif($strAction == 'edit'){
  88. $conditions = array('uid'=>$uid);
  89. $objUser->update($conditions, $data);
  90. }
  91. $this->jsonsuccess(T('Successfully ' . $strAction . 'ed!' ), spUrl("user","index"));
  92. }
  93. public function delete(){
  94. $uid = $this->spArgs("uid");
  95. $objUser = spClass("userModel");
  96. $conditions = array('uid' => $uid);
  97. $objUser->delete($conditions); // ????
  98. $this->success(T('Successfully deleted!' ), spUrl("user","index"));
  99. }
  100. // ????
  101. public function logout(){
  102. // ???PHP.net????SESSION???
  103. $_SESSION = array();
  104. if (isset($_COOKIE[session_name()])) {setcookie(session_name(), '', time()-42000, '/');}
  105. session_destroy();
  106. $userObj = spClass("userModel"); // ???userModel?
  107. // ?????
  108. $this->success(T("You are now signed out."), spUrl("user","login"));// ?????????
  109. }
  110. // ?????????????????
  111. public function login(){
  112. import("spAcl.php"); // ??Acl?????????????????
  113. $userObj = spClass("userModel"); // ???userModel?
  114. if( $uname = $this->spArgs("uname") ){ // ???????????????
  115. $upass = $this->spArgs("upass"); // ??acl?upass???????
  116. // ??spVerifier???????
  117. $rows = array('uname' => $uname, 'upass' => upass);
  118. $results = $userObj->spVerifier($rows);
  119. if( false == $results ){ // ?spVerifier??false?????????????????????
  120. // ??lib_user???????userlogin???????????
  121. if( false == $userObj->userlogin($uname, $upass) ){
  122. // ???????????????
  123. $this->error(T("The username address or password you provided does not match our records."), spUrl("user","login"));//"???/???????????"
  124. }else{
  125. // ??????????????????
  126. // ???????GBADMIN?????????admin/index?????
  127. // ???????GBUSER????????????
  128. $useracl = spClass("spAcl")->get(); // ??acl?get??????????????
  129. if( "WEBMASTER" == $useracl ){
  130. $this->success(T("Welcome, the administrator"), spUrl("main","index"));//?????????????
  131. }else{
  132. $this->success(T("Welcome, Dear Member."), spUrl("main","index"));//???????????????
  133. }
  134. }
  135. }else{
  136. // $results??false???????????????$results
  137. // dump($results);
  138. foreach($results as $item){ // ???????????????????
  139. // ????????????????????????????$item???????
  140. foreach($item as $msg){
  141. // ?????????????????????????????
  142. // ????????????????????$this->error??????
  143. $this->error($msg,spUrl("user","login"));
  144. }
  145. }
  146. }
  147. }
  148. // ???????????????????main_login.html?????
  149. $this->display("admin/user_login.html");
  150. }
  151. }