AdminController.php 11 KB

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