ItemController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. session_start(); // starts new or resumes existing session
  3. Doo::loadModelAt('auser', 'admin');
  4. Doo::loadModelAt('ausers', 'admin');
  5. Doo::loadModelAt('ameasure', 'admin');
  6. Doo::loadModelAt('fileup', 'admin');
  7. Doo::loadModelAt('measureaudit', 'admin');
  8. Doo::loadModelAt('numofper', 'admin');
  9. Doo::loadModel('users');
  10. Doo::loadClass('profile');
  11. Doo::loadClass('contractact');
  12. Doo::loadClass('PasswordHash');
  13. Doo::loadClass('mailer');
  14. Doo::loadClass('project');
  15. /*
  16. * To change this license header, choose License Headers in Project Properties.
  17. * To change this template file, choose Tools | Templates
  18. * and open the template in the editor.
  19. */
  20. // 列表停用 编辑 重置密码
  21. // 管理员权限管理
  22. // 管理员修改密码
  23. class ItemController extends DooController {
  24. private $data, $users, $user, $profile, $ph, $userz, $mailer, $project, $am, $cc, $an, $ama, $statusArray = array('checking' => '审批中', 'checked' => '完成', 'checkno' => '不通过'), $colorArray = array('checking' => 'colOrange', 'checked' => 'colGreen', 'checkno' => 'colRed');
  25. public function beforeRun($resource, $action) {
  26. if (!isset($_SESSION['auid'])) {
  27. return Doo::conf()->APP_URL . 'manage';
  28. }
  29. }
  30. public function __construct() {
  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->ph = new PasswordHash(8, FALSE);
  37. $this->am = new Ameasure();
  38. $this->ama = new AmeasureAudit();
  39. $this->af = new Afileup();
  40. $this->an = new Anumofper();
  41. $this->project = new Project();
  42. $this->cc = new Contractact();
  43. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  44. }
  45. function addUser() {
  46. $params = NULL;
  47. if (isset($_POST['email'])) {
  48. if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  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><br><a href="'.Doo::conf()->APP_URL.'" style="font-size:20px">'.Doo::conf()->APP_URL.'</a></p>';
  58. $this->mailer->setContent($signupConfigStr);
  59. $this->mailer->send_mail();
  60. return Doo::conf()->APP_URL . 'manage/user/list';
  61. } else {
  62. return Doo::conf()->APP_URL . 'manage/user/add';
  63. }
  64. } else {
  65. return Doo::conf()->APP_URL . 'manage/user/add';
  66. }
  67. }
  68. $this->render('admin-addUser', $this->data, TRUE);
  69. }
  70. public function randomPassword() {
  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. $this->data['users'] = $this->users->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  82. $this->data['profile'] = $this->profile->getProWithUid($this->params['uid']);
  83. if (isset($_POST['email']) && ($_POST['email'] != $this->data['users']['uemail']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  84. if (!$this->userz->getOne(array('where' => 'uemail = ?', 'param' => array($_POST['email']), 'asArray' => TRUE))) {
  85. $this->userz->uemail = $_POST['email'];
  86. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  87. }
  88. }
  89. if (isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['name']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
  90. $this->profile->upProfile($this->params['uid'], $_POST);
  91. return Doo::conf()->APP_URL . 'manage/user/list';
  92. }
  93. $this->render('admin-editUser', $this->data, TRUE);
  94. }
  95. function option() {
  96. $this->data['auser'] = $this->user->getOne(array('where' => 'auid = ?', 'param' => array($_SESSION['auid']), 'asArray' => TRUE));
  97. if (isset($_POST['oldpasswd']) && isset($_POST['newpasswd']) && isset($_POST['renewpasswd']) && ($_POST['newpasswd'] == $_POST['renewpasswd']) && $this->ph->CheckPassword($_POST['oldpasswd'], $this->data['auser']['aupass'])) {
  98. $this->user->upPasswWd($_SESSION['auid'], $this->ph->HashPassword($_POST['newpasswd']));
  99. return Doo::conf()->APP_URL . 'manage/user/list';
  100. }
  101. $this->render('admin-option', $this->data, TRUE);
  102. }
  103. function userSwitch() {
  104. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  105. if (isset($userzArray['uid']) && $userzArray['isstop']) {
  106. $this->userz->isstop = 0;
  107. } else {
  108. $this->userz->isstop = 1;
  109. }
  110. $this->userz->update(array('where' => 'uid = ?', 'param' => array($this->params['uid'])));
  111. return Doo::conf()->APP_URL . 'manage/user/list';
  112. }
  113. function userRepasswd() {
  114. $userzArray = $this->userz->getOne(array('where' => 'uid = ?', 'param' => array($this->params['uid']), 'asArray' => TRUE));
  115. if (isset($userzArray['uemail'])) {
  116. $passwdStr = $this->randomPassword();
  117. $this->userz->upass = $this->ph->HashPassword($passwdStr);
  118. if ($this->userz->update(array('where' => 'uid=?', 'param' => array($this->params['uid'])))) {
  119. $proArray = $this->profile->getProWithUid($this->params['uid']);
  120. $this->mailer->setEmails($userzArray['uemail']);
  121. $this->mailer->seteTitle('密码重置');
  122. $this->mailer->setClientName($proArray['name']);
  123. $signupConfigStr = '<p>重置了计量支付云版的帐号密码:</p><p>登录帐号(邮箱):<b><a href="mailto:' . $userzArray['uemail'] . '" target="_blank">' . $userzArray['uemail'] . '</a></b></p><p>登录密码:<b>' . $passwdStr . '</b></p><p>请及时登录并修改您的新密码。</p>';
  124. $this->mailer->setContent($signupConfigStr);
  125. $this->mailer->send_mail();
  126. echo $userzArray['uemail'];
  127. }
  128. }
  129. }
  130. function userList() {
  131. if (isset($_SESSION['passwd'])) {
  132. echo '添加用户的密码是:' . $_SESSION['passwd'];
  133. }
  134. $this->data['userlist'] = $this->users->getRowAll();
  135. foreach ($this->data['userlist'] as $key => $value) {
  136. $proArray = $this->profile->getProWithUid($value['uid']);
  137. if (isset($proArray)) {
  138. $this->data['userlist'][$key]['name'] = $proArray['name'];
  139. $this->data['userlist'][$key]['company'] = $proArray['company'];
  140. $this->data['userlist'][$key]['jobs'] = $proArray['jobs'];
  141. $this->data['userlist'][$key]['phone'] = $proArray['phone'];
  142. $this->data['userlist'][$key]['mobile'] = $proArray['mobile'];
  143. $this->data['userlist'][$key]['isstop'] = $value['isstop'];
  144. }
  145. unset($proArray);
  146. $this->data['userlist'][$key]['email'] = $value['uemail'];
  147. }
  148. $this->data['menu'] = 2;
  149. $this->render('admin-userlist', $this->data, TRUE);
  150. }
  151. function itemList() {
  152. // TODO:增加判断审批人期数和上报最新期数比较来显示是否需要显示删除审批人操作
  153. // TODO:提示信息:可能显示的是瞬时状态,需要与客户经过确认之后方可删除。
  154. // TODO:审批人状态和标段状态暂未加入审批人与标段是否一直的判断
  155. if ($this->params['pid'] > 0) {
  156. $mArray = $this->am->getRowAll($this->params['pid']);
  157. $this->data['pid'] = $this->params['pid'];
  158. }
  159. foreach ($mArray as $key => $value) {
  160. $mArray[$key]['contracttotal'] = number_format($value['contracttotal'], 2, '.', ',');
  161. $mArray[$key]['stname'] = $this->cc->getRowByStid($value['stid'])['stname'];
  162. $tmp = $this->an->getOne(array('where' => 'pmid=?', 'param' => array($value['pmid']), 'groupby' => 'numpname', 'desc' => 'numpname', 'asArray' => TRUE));
  163. if ($tmp) {// 没有标段数据
  164. $mArray[$key]['has'] = 1;
  165. $mArray[$key]['status'] = $this->statusArray[$tmp['currstatus']];
  166. $mArray[$key]['color'] = $this->colorArray[$tmp['currstatus']];
  167. $mArray[$key]['numpname'] = $tmp['numpname'];
  168. $intTimes = $this->ama->getOne(array('where' => 'pmid=? and numpname=?', 'param' => array($value['pmid'], $tmp['numpname']), 'groupby' => 'times', 'desc' => 'times', 'asArray' => TRUE))['times'];
  169. $auditArray = $this->ama->find(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($value['pmid'], $tmp['numpname'], $intTimes), 'asArray' => TRUE));
  170. foreach ($auditArray as $k => $v) {
  171. if (($v['last'] == 1) && ($v['mastatus'] != 'uncheck')) {
  172. $mArray[$key]['auditor'] = $this->profile->getProWithUid($v['auditoruid'])['name'];
  173. $mArray[$key]['auditor'] = '终审-' . $mArray[$key]['auditor'];
  174. $mArray[$key]['auditstatus'] = $this->statusArray[$v['mastatus']];
  175. break;
  176. } elseif (($v['last'] == 2) && ($v['mastatus'] != 'uncheck')) {
  177. $mArray[$key]['auditor'] = $this->profile->getProWithUid($v['auditoruid'])['name'];
  178. $mArray[$key]['auditstatus'] = $this->statusArray[$v['mastatus']];
  179. $mArray[$key]['auditnum'] = $k . '审';
  180. }
  181. }
  182. } else {
  183. $mArray[$key]['has'] = 0;
  184. }
  185. }
  186. $pArray = $this->project->getAll();
  187. $this->data['userlist'] = $mArray;
  188. $this->data['pArray'] = $pArray;
  189. $this->data['menu'] = 4;
  190. $this->render('admin-item', $this->data, TRUE);
  191. }
  192. function itemDel() {
  193. $this->am->delete(array('where' => 'pmid=?', 'param' => array($this->params['pmid'])));
  194. $this->ama->delete(array('where' => 'pmid=?', 'param' => array($this->params['pmid'])));
  195. $this->af->delete(array('where' => 'pmid=?', 'param' => array($this->params['pmid'])));
  196. $this->an->delete(array('where' => 'pmid=?', 'param' => array($this->params['pmid'])));
  197. return Doo::conf()->APP_URL . 'manage/item/list';
  198. }
  199. }