AdminController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. session_start(); // starts new or resumes existing session
  3. Doo::loadModelAt('auser', 'admin');
  4. Doo::loadModelAt('ausers', 'admin');
  5. Doo::loadModel('users');
  6. Doo::loadClass('profile');
  7. Doo::loadClass('PasswordHash');
  8. Doo::loadClass('mailer');
  9. Doo::loadClass('measureauditact');
  10. Doo::loadClass('project');
  11. Doo::loadClass('actmeasure');
  12. /*
  13. * To change this license header, choose License Headers in Project Properties.
  14. * To change this template file, choose Tools | Templates
  15. * and open the template in the editor.
  16. */
  17. // 列表停用 编辑 重置密码
  18. // 管理员权限管理
  19. // 管理员修改密码
  20. class AdminController extends DooController
  21. {
  22. private $data, $users, $user, $profile, $ph, $userz, $mailer, $project, $actmeasure, $measureauditact;
  23. public function beforeRun($resource, $action)
  24. {
  25. if (!isset($_SESSION['auid'])) {
  26. return Doo::conf()->APP_URL . 'manage';
  27. }
  28. }
  29. public function __construct()
  30. {
  31. $this->users = new AUsers();
  32. $this->user = new AUser();
  33. $this->userz = new Users();
  34. $this->profile = new Profile();
  35. $this->mailer = new Mailer();
  36. $this->project = new Project();
  37. $this->actmeasure = new actMeasure();
  38. $this->measureauditact = new MeasureauditAct();
  39. $this->ph = new PasswordHash(8, FALSE);
  40. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  41. }
  42. function addUser()
  43. {
  44. $params = NULL;
  45. if (isset($_POST['email'])) {
  46. if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  47. $postArray = $_POST;
  48. $passwdStr = $this->randomPassword();
  49. $postArray['userid'] = $this->users->createUser($_POST['email'], $passwdStr);
  50. if (isset($postArray['userid'])) {
  51. $this->profile->insertProfile($postArray);
  52. $this->mailer->setEmails($_POST['email']);
  53. $this->mailer->seteTitle('新账号开通');
  54. $this->mailer->setClientName($postArray['realname']);
  55. $signupConfigStr = '<p>开通了计量支付云版的帐号:</p><p>登录帐号(邮箱):<b><a href="mailto:' . $_POST['email'] . '" target="_blank">' . $_POST['email'] . '</a></b></p><p>登录密码:<b>' . $passwdStr . '</b></p><p>请及时登录并修改您的个人信息及密码。</p>';
  56. $this->mailer->setContent($signupConfigStr);
  57. $this->mailer->send_mail();
  58. return Doo::conf()->APP_URL . 'manage/user/list';
  59. } else {
  60. return Doo::conf()->APP_URL . 'manage/user/add';
  61. }
  62. } else {
  63. return Doo::conf()->APP_URL . 'manage/user/add';
  64. }
  65. }
  66. $this->data['menu'] = 3;
  67. $this->render('admin-addUser', $this->data, TRUE);
  68. }
  69. public function randomPassword()
  70. {
  71. $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  72. $pass = array(); //remember to declare $pass as an array
  73. $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  74. for ($i = 0; $i < 8; $i++) {
  75. $n = rand(0, $alphaLength);
  76. $pass[] = $alphabet[$n];
  77. }
  78. return implode($pass); //turn the array into a string
  79. }
  80. function editUser()
  81. {
  82. $this->data['users'] = $this->users->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  83. $this->data['profile'] = $this->profile->getProWithUid($this->params['uid']);
  84. if (isset($_POST['email']) && ($_POST['email'] != $this->data['users']['uemail']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  85. if (!$this->userz->getOne(array('where' => 'uemail = ?', 'param' => array($_POST['email']), 'asArray' => TRUE))) {
  86. $this->userz->uemail = $_POST['email'];
  87. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  88. }
  89. }
  90. if (isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['name']) && isset($_POST['phone'])) {
  91. $this->profile->upProfile($this->params['uid'], $_POST);
  92. return Doo::conf()->APP_URL . 'manage/user/list';
  93. }
  94. //获取该用户审批标段,创建的标段,创建的项目
  95. $mnflist = $this->measureauditact->getUserPmid($this->params['uid']);
  96. if(!empty($mnflist)){
  97. foreach($mnflist as $k => $v){
  98. $pmmsg = $this->actmeasure->getRowByPmid($v['pmid']);
  99. $mnflist[$k]['pmname'] = $pmmsg['pmname'];
  100. $promsg = $this->project->getRowByPid($pmmsg['pid']);
  101. $mnflist[$k]['pname'] = $promsg['pname'];
  102. }
  103. $this->data['mnflist'] = $mnflist;
  104. }
  105. $mnflist2 = $this->actmeasure->getPmidRow($this->params['uid']);
  106. if(!empty($mnflist2)){
  107. foreach($mnflist2 as $k2 => $v2){
  108. $promsg = $this->project->getRowByPid($v2['pid']);
  109. $mnflist2[$k2]['pname'] = $promsg['pname'];
  110. $mnflist2[$k2]['intime'] = date('Y-m-d H:i:s',$v2['intime']);
  111. }
  112. $this->data['mnflist2'] = $mnflist2;
  113. }
  114. $prolist = $this->project->getRowUid($this->params['uid']);
  115. if(!empty($prolist)){
  116. foreach($prolist as $k3 => $v3){
  117. $prolist[$k3]['intime'] = date('Y-m-d H:i:s',$v3['intime']);
  118. }
  119. $this->data['prolist'] = $prolist;
  120. }
  121. $this->data['menu'] = 2;
  122. $this->render('admin-editUser', $this->data, TRUE);
  123. }
  124. function option()
  125. {
  126. $this->data['auser'] = $this->user->getOne(array('where' => 'auid = ?', 'param' => array($_SESSION['auid']), 'asArray' => TRUE));
  127. if (isset($_POST['oldpasswd']) && isset($_POST['newpasswd']) && isset($_POST['renewpasswd']) && ($_POST['newpasswd'] == $_POST['renewpasswd']) && $this->ph->CheckPassword($_POST['oldpasswd'], $this->data['auser']['aupass'])) {
  128. $this->user->upPasswWd($_SESSION['auid'], $this->ph->HashPassword($_POST['newpasswd']));
  129. return Doo::conf()->APP_URL . 'manage/user/list';
  130. }
  131. $this->render('admin-option', $this->data, TRUE);
  132. }
  133. function userSwitch()
  134. {
  135. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  136. if (isset($userzArray['uid']) && $userzArray['isstop']) {
  137. $this->userz->isstop = 0;
  138. } else {
  139. $this->userz->isstop = 1;
  140. }
  141. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  142. return Doo::conf()->APP_URL . 'manage/user/list';
  143. }
  144. function userRepasswd()
  145. {
  146. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  147. if (isset($userzArray['uemail'])) {
  148. $passwdStr = $this->randomPassword();
  149. $this->userz->upass = $this->ph->HashPassword($passwdStr);
  150. if ($this->userz->update(array('where' => 'uid=?', 'param' => array($this->params['uid'])))) {
  151. $proArray = $this->profile->getProWithUid($this->params['uid']);
  152. $this->mailer->setEmails($userzArray['uemail']);
  153. $this->mailer->seteTitle('密码重置');
  154. $this->mailer->setClientName($proArray['name']);
  155. $signupConfigStr = '<p>重置了计量支付云版的帐号密码:</p><p>登录帐号(邮箱):<b><a href="mailto:' . $userzArray['uemail'] . '" target="_blank">' . $userzArray['uemail'] . '</a></b></p><p>登录密码:<b>' . $passwdStr . '</b></p><p>请及时登录并修改您的新密码。</p>';
  156. $this->mailer->setContent($signupConfigStr);
  157. $this->mailer->send_mail();
  158. echo $userzArray['uemail'];
  159. }
  160. }
  161. }
  162. function userList()
  163. {
  164. if (isset($_SESSION['passwd'])) {
  165. echo '添加用户的密码是:' . $_SESSION['passwd'];
  166. }
  167. $this->data['userlist'] = $this->users->getRowAll();
  168. foreach ($this->data['userlist'] as $key => $value) {
  169. $proArray = $this->profile->getProWithUid($value['uid']);
  170. if (isset($proArray)) {
  171. $this->data['userlist'][$key]['name'] = $proArray['name'];
  172. $this->data['userlist'][$key]['company'] = $proArray['company'];
  173. $this->data['userlist'][$key]['jobs'] = $proArray['jobs'];
  174. $this->data['userlist'][$key]['remark'] = $proArray['remark'];
  175. $this->data['userlist'][$key]['phone'] = $proArray['phone'];
  176. $this->data['userlist'][$key]['mobile'] = $proArray['mobile'];
  177. $this->data['userlist'][$key]['isstop'] = $value['isstop'];
  178. }
  179. unset($proArray);
  180. $this->data['userlist'][$key]['email'] = $value['uemail'];
  181. }
  182. $this->data['menu'] = 2;
  183. $this->render('admin-userlist', $this->data, TRUE);
  184. }
  185. }