AdminController.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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($_FILES['sign']) && !empty($_FILES['sign']['name']) && $_FILES['sign']['type'] == "image/png"){
  91. $dir = 'global/signpath';
  92. if ($_FILES['sign']['error'] > 0) {
  93. } else {
  94. $fileName = date("YmdHis") . '_' . floor(microtime() * 1000) . '_' . self::createRandomCode(8);
  95. $virtualPath = "$dir/php_sign_$fileName.jpg";
  96. move_uploaded_file($_FILES['sign']["tmp_name"], Doo::conf()->SITE_PATH .$virtualPath);
  97. $this->profile->setSignPath($this->params['uid'], $virtualPath);
  98. }
  99. }
  100. if (isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['name']) && isset($_POST['phone'])) {
  101. $this->profile->upProfile($this->params['uid'], $_POST);
  102. return Doo::conf()->APP_URL . 'manage/user/list';
  103. }
  104. //获取该用户审批标段,创建的标段,创建的项目
  105. $mnflist = $this->measureauditact->getUserPmid($this->params['uid']);
  106. if(!empty($mnflist)){
  107. foreach($mnflist as $k => $v){
  108. $pmmsg = $this->actmeasure->getRowByPmid($v['pmid']);
  109. $mnflist[$k]['pmname'] = $pmmsg['pmname'];
  110. $promsg = $this->project->getRowByPid($pmmsg['pid']);
  111. $mnflist[$k]['pname'] = $promsg['pname'];
  112. }
  113. $this->data['mnflist'] = $mnflist;
  114. }
  115. $mnflist2 = $this->actmeasure->getPmidRow($this->params['uid']);
  116. if(!empty($mnflist2)){
  117. foreach($mnflist2 as $k2 => $v2){
  118. $promsg = $this->project->getRowByPid($v2['pid']);
  119. $mnflist2[$k2]['pname'] = $promsg['pname'];
  120. $mnflist2[$k2]['intime'] = date('Y-m-d H:i:s',$v2['intime']);
  121. }
  122. $this->data['mnflist2'] = $mnflist2;
  123. }
  124. $prolist = $this->project->getRowUid($this->params['uid']);
  125. if(!empty($prolist)){
  126. foreach($prolist as $k3 => $v3){
  127. $prolist[$k3]['intime'] = date('Y-m-d H:i:s',$v3['intime']);
  128. }
  129. $this->data['prolist'] = $prolist;
  130. }
  131. $this->data['menu'] = 2;
  132. $this->render('admin-editUser', $this->data, TRUE);
  133. }
  134. function option()
  135. {
  136. $this->data['auser'] = $this->user->getOne(array('where' => 'auid = ?', 'param' => array($_SESSION['auid']), 'asArray' => TRUE));
  137. if (isset($_POST['oldpasswd']) && isset($_POST['newpasswd']) && isset($_POST['renewpasswd']) && ($_POST['newpasswd'] == $_POST['renewpasswd']) && $this->ph->CheckPassword($_POST['oldpasswd'], $this->data['auser']['aupass'])) {
  138. $this->user->upPasswWd($_SESSION['auid'], $this->ph->HashPassword($_POST['newpasswd']));
  139. return Doo::conf()->APP_URL . 'manage/user/list';
  140. }
  141. $this->render('admin-option', $this->data, TRUE);
  142. }
  143. function userSwitch()
  144. {
  145. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  146. if (isset($userzArray['uid']) && $userzArray['isstop']) {
  147. $this->userz->isstop = 0;
  148. } else {
  149. $this->userz->isstop = 1;
  150. }
  151. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  152. return Doo::conf()->APP_URL . 'manage/user/list';
  153. }
  154. function userRepasswd()
  155. {
  156. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  157. if (isset($userzArray['uemail'])) {
  158. $passwdStr = $this->randomPassword();
  159. $this->userz->upass = $this->ph->HashPassword($passwdStr);
  160. if ($this->userz->update(array('where' => 'uid=?', 'param' => array($this->params['uid'])))) {
  161. $proArray = $this->profile->getProWithUid($this->params['uid']);
  162. $this->mailer->setEmails($userzArray['uemail']);
  163. $this->mailer->seteTitle('密码重置');
  164. $this->mailer->setClientName($proArray['name']);
  165. $signupConfigStr = '<p>重置了计量支付云版的帐号密码:</p><p>登录帐号(邮箱):<b><a href="mailto:' . $userzArray['uemail'] . '" target="_blank">' . $userzArray['uemail'] . '</a></b></p><p>登录密码:<b>' . $passwdStr . '</b></p><p>请及时登录并修改您的新密码。</p>';
  166. $this->mailer->setContent($signupConfigStr);
  167. $this->mailer->send_mail();
  168. echo $userzArray['uemail'];
  169. }
  170. }
  171. }
  172. function userList()
  173. {
  174. if (isset($_SESSION['passwd'])) {
  175. echo '添加用户的密码是:' . $_SESSION['passwd'];
  176. }
  177. $this->data['userlist'] = $this->users->getRowAll();
  178. foreach ($this->data['userlist'] as $key => $value) {
  179. $proArray = $this->profile->getProWithUid($value['uid']);
  180. if (isset($proArray)) {
  181. $this->data['userlist'][$key]['name'] = $proArray['name'];
  182. $this->data['userlist'][$key]['company'] = $proArray['company'];
  183. $this->data['userlist'][$key]['jobs'] = $proArray['jobs'];
  184. $this->data['userlist'][$key]['remark'] = $proArray['remark'];
  185. $this->data['userlist'][$key]['phone'] = $proArray['phone'];
  186. $this->data['userlist'][$key]['mobile'] = $proArray['mobile'];
  187. $this->data['userlist'][$key]['isstop'] = $value['isstop'];
  188. }
  189. unset($proArray);
  190. $this->data['userlist'][$key]['email'] = $value['uemail'];
  191. }
  192. $this->data['menu'] = 2;
  193. $this->render('admin-userlist', $this->data, TRUE);
  194. }
  195. /* * ************************************************************
  196. * 生成指定长度的随机码。
  197. * @param int $length 随机码的长度。
  198. * @access public
  199. * ************************************************************ */
  200. function createRandomCode($length)
  201. {
  202. $randomCode = "";
  203. $randomChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  204. for ($i = 0; $i < $length; $i++) {
  205. $randomCode .= $randomChars{mt_rand(0, 35)};
  206. }
  207. return $randomCode;
  208. }
  209. }