Example #1
0
 public function editAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '编辑成功');
     $request = $this->getRequest()->getParams();
     $now = date('Y-m-d H:i:s');
     $user_session = new Zend_Session_Namespace('user');
     $user_id = $user_session->user_info['user_id'];
     $json = json_decode($request['json']);
     $updated = $json->updated;
     $account = new Application_Model_User();
     if (count($updated) > 0) {
         foreach ($updated as $val) {
             $data = array('active' => $val->active, 'remark' => $val->remark, 'update_time' => $now, 'update_user' => $user_id);
             $where = "id = " . $val->id;
             try {
                 $account->update($data, $where);
             } catch (Exception $e) {
                 $result['result'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Example #2
0
 public function editpwdAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '修改密码成功');
     $user_session = new Zend_Session_Namespace('user');
     $user_id = $user_session->user_info['user_id'];
     $request = $this->getRequest()->getParams();
     $pwd0 = isset($request['pwd0']) ? $request['pwd0'] : null;
     $pwd1 = isset($request['pwd1']) ? $request['pwd1'] : null;
     $pwd2 = isset($request['pwd2']) ? $request['pwd2'] : null;
     if ($pwd0 && $pwd1 && $pwd2) {
         $user = new Application_Model_User();
         if ($user->checkUserPwdById($user_id, $pwd0)) {
             $employeeInfo = $user->getEmployeeInfoById($user_id);
             $pwd = md5($employeeInfo['number'] . $pwd1);
             try {
                 $user->update(array('password' => $pwd), "id = " . $user_id);
                 $computer_name = gethostbyaddr(getenv("REMOTE_ADDR"));
                 // 计算机名
                 $now = date('Y-m-d H:i:s');
                 $data = array('operate' => '修改密码', 'target' => 'UserAccount', 'computer_name' => $computer_name, 'ip' => $_SERVER['REMOTE_ADDR'], 'time' => $now);
                 $operate = new Application_Model_Log_Operate();
                 try {
                     $operate->insert($data);
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             } catch (Exception $e) {
                 $result['success'] = false;
                 $result['info'] = $e->getMessage();
                 echo Zend_Json::encode($result);
                 exit;
             }
         } else {
             $result['success'] = false;
             $result['info'] = '旧密码输入错误!';
         }
     } else {
         $result['success'] = false;
         $result['info'] = '新、旧密码不能为空!';
     }
     echo Zend_Json::encode($result);
     exit;
 }
Example #3
0
 /**
  * Método utilizado para editar Users, testando a existência de uma requisão do tipo POST.
  * Seus valores são resgatados validados e atualizados no banco de dados.
  * @param int $id
  * @method updateAction
  * @access public
  * @return resource
  */
 public function updateAction()
 {
     $form = new Application_Form_User();
     $form->setAction('/user/update');
     $users = new Application_Model_User();
     if ($this->_request->isPost()) {
         if ($form->isValid($this->_request->getPost())) {
             $values = $form->getValues();
             $users->update($values, 'id = ' . $values['id']);
             $this->_redirect('/user/retrieve');
         }
     } else {
         $id = $this->_getParam('id');
         $user = $users->fetchRow("id ={$id}")->toArray();
         $form->populate($user);
     }
     $this->view->form = $form;
 }
Example #4
0
 function changepermissionAction()
 {
     $this->view->title = "Change user permission";
     $user = new Application_Model_User();
     $id = (int) $this->_request->getParam('id');
     $userRow = $user->fetchRow($user->select()->where('id = ?', $id));
     $userArray = $userRow->toArray();
     if ($userArray['permission'] == 0) {
         $insertValue = "1";
     }
     if ($userArray['permission'] == 1) {
         $insertValue = "0";
     }
     $data = array('permission' => $insertValue);
     $where = 'id = ' . $id;
     $user->update($data, $where);
     $this->_redirect('/users');
     return;
 }
 /**
  * This method is used to save the new patient or update the information of 
  * an existing patient. a user with the mrn.no is create with the username and
  * password same as mrn. no.
  * it also enters the order of patient
  * @param type $dataPosted
  * @return array id of patient and order
  */
 public function save($dataPosted)
 {
     $userObj = new Application_Model_User();
     $arrayCols = $userObj->fetchNew()->toArray();
     $patientObj = new Application_Model_Patient();
     $arrayColsPat = $patientObj->fetchNew()->toArray();
     $dataPosted['updated_at'] = date('Y-m-d H:i:s');
     $dataPosted['created_at'] = date('Y-m-d H:i:s');
     $user_data = array_intersect_key($dataPosted, $arrayCols);
     // filter the posted data to model attributes
     $patient_data = array_intersect_key($dataPosted, $arrayColsPat);
     unset($patient_data['id']);
     $user_data['username'] = $dataPosted['m_r_no'];
     $user_data['password'] = md5($dataPosted['m_r_no']);
     $user_data['user_type'] = 'patient';
     //update user and patient if id  passed
     if (!empty($user_data['id'])) {
         unset($user_data['created_at']);
         unset($patient_data['created_at']);
         $userObj->update($user_data, 'id=' . $user_data['id']);
         $user_id = $user_data['id'];
         $patient_data['user_id'] = $user_id;
         $patientObj->update($patient_data, 'user_id=' . $user_id);
     } else {
         //insert new user and patient if id not passed
         unset($user_data['id']);
         $user_id = $userObj->insert($user_data);
         $patient_data['user_id'] = $user_id;
         $patientObj->insert($patient_data);
     }
     $result['id'] = $user_id;
     $result['order_id'] = '';
     // Save patient Tests
     $patient_orders_obj = new Application_Model_DbTable_PatientOrders();
     if (isset($dataPosted['test_id'])) {
         $testIds = $dataPosted['test_id'];
     } else {
         $testIds = [];
     }
     if (!empty($dataPosted['order_id']) || count($testIds)) {
         if (empty($dataPosted['order_id'])) {
             $dataOrder['user_id'] = $user_id;
             $dataOrder['created_at'] = date('Y-m-d H:i:s');
             $dataOrder['total_tests'] = count($testIds);
             $order_id = $patient_orders_obj->insert($dataOrder);
         } else {
             $order_id = $dataPosted['order_id'];
             $dataOrder['total_tests'] = count($testIds);
             $patient_orders_obj->update($dataOrder, 'id = ' . $order_id);
         }
         $result['order_id'] = $order_id;
         // Delete the removed tests
         $OrderTestsObj = new Application_Model_DbTable_OrderTests();
         $oldTests = $OrderTestsObj->fetchAll('order_id = ' . $order_id);
         $oldTestsArr = [];
         foreach ($oldTests as $oldTest) {
             if (!in_array($oldTest['test_id'], $testIds)) {
                 $OrderTestsObj->delete('test_id = ' . $oldTest['test_id'] . ' and order_id = ' . $order_id);
             }
             $oldTestsArr[] = $oldTest['test_id'];
         }
         // Add new tests
         foreach ($testIds as $newTest) {
             if (!in_array($newTest, $oldTestsArr)) {
                 $OrderTestsObj->insert(['test_id' => $newTest, 'order_id' => $order_id]);
             }
         }
     }
     return $result;
 }
Example #6
0
 /**
  * 编辑员工信息
  */
 public function editAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '编辑成功');
     $request = $this->getRequest()->getParams();
     $now = date('Y-m-d H:i:s');
     $user_session = new Zend_Session_Namespace('user');
     $user_id = $user_session->user_info['user_id'];
     $json = json_decode($request['json']);
     $updated = $json->updated;
     $inserted = $json->inserted;
     $deleted = $json->deleted;
     $employee = new Hra_Model_Employee();
     $user = new Application_Model_User();
     if (count($updated) > 0) {
         foreach ($updated as $val) {
             if ($employee->fetchAll("id != " . $val->id . " and email = '" . $val->email . "'")->count() > 0) {
                 $result['success'] = false;
                 $result['info'] = '更新失败,邮箱地址重复!';
                 echo Zend_Json::encode($result);
                 exit;
             } else {
                 if ($employee->fetchAll("id != " . $val->id . " and number = '" . $val->number . "'")->count() > 0) {
                     $result['success'] = false;
                     $result['info'] = '更新失败,工号重复!';
                     echo Zend_Json::encode($result);
                     exit;
                 } else {
                     $dept_manager_id = $val->dept_manager_id == '' ? null : $val->dept_manager_id;
                     $manager_id = $val->manager_id == '' ? null : $val->manager_id;
                     $dept_id = $val->dept_id == '' ? null : $val->dept_id;
                     $post_id = $val->post_id == '' ? null : $val->post_id;
                     $area_id = $val->area_id == '' ? null : $val->area_id;
                     $professional_qualifications_id = $val->professional_qualifications_id == '' ? null : $val->professional_qualifications_id;
                     $data = array('hide' => $val->hide, 'active' => $val->active, 'leader' => $val->leader, 'number' => $val->number, 'cname' => $val->cname, 'ename' => $val->ename, 'sex' => $val->sex, 'birthday' => $val->birthday, 'id_card' => $val->id_card, 'dept_id' => $dept_id, 'post_id' => $post_id, 'area_id' => $area_id, 'professional_qualifications_id' => $professional_qualifications_id, 'dept_manager_id' => $dept_manager_id, 'manager_id' => $manager_id, 'salary' => $val->salary, 'email' => $val->email, 'tel' => $val->tel, 'official_qq' => $val->official_qq, 'work_place' => $val->work_place, 'short_num' => $val->short_num, 'msn' => $val->msn, 'address' => $val->address, 'remark' => $val->remark, 'marital_status' => $val->marital_status, 'marry_day' => $val->marry_day, 'children_birthday' => $val->children_birthday, 'insurcode' => $val->insurcode, 'accumulation_fund_code' => $val->accumulation_fund_code, 'education' => $val->education, 'school' => $val->school, 'major' => $val->major, 'entry_date' => $val->entry_date, 'regularization_date' => $val->regularization_date, 'labor_contract_start' => $val->labor_contract_start, 'labor_contract_end' => $val->labor_contract_end, 'offical_address' => $val->offical_address, 'other_contact' => $val->other_contact, 'other_relationship' => $val->other_relationship, 'other_contact_way' => $val->other_contact_way, 'work_years' => $val->work_years, 'politics_status' => $val->politics_status, 'employment_type' => $val->employment_type, 'leave_date' => $val->leave_date, 'ext' => $val->ext, 'driving_license' => $val->driving_license, 'salary' => $val->salary, 'bank' => $val->bank, 'bank_num' => $val->bank_num, 'update_time' => $now, 'update_user' => $user_id);
                     $where = "id = " . $val->id;
                     try {
                         $employee->update($data, $where);
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                         echo Zend_Json::encode($result);
                         exit;
                     }
                     if ($val->account == 1) {
                         if ($user->fetchAll("employee_id = " . $val->id)->count() > 0) {
                             $account_active = $val->account_active == true ? 1 : 0;
                             // 当员工系统账号已存在时,如需要改变账号状态,则更新系统账号状态信息
                             if ($user->fetchAll("active = " . $account_active . " and employee_id = " . $val->id)->count() == 0) {
                                 try {
                                     $user->update(array('active' => $account_active, 'update_user' => $user_id, 'update_time' => $now), "employee_id = " . $val->id);
                                 } catch (Exception $e) {
                                     $result['success'] = false;
                                     $result['info'] = $e->getMessage();
                                     echo Zend_Json::encode($result);
                                     exit;
                                 }
                             }
                         } else {
                             // 当员工系统账号不存在时,则添加新的系统账号信息
                             $data = array('employee_id' => $val->id, 'active' => $val->account_active, 'password' => md5($val->number . '123456'), 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id);
                             try {
                                 $newUserId = $user->insert($data);
                                 // 初始化用户角色为普通用户
                                 $roleMember = new Admin_Model_Member();
                                 try {
                                     $roleMember->insert(array('user_id' => $newUserId));
                                 } catch (Exception $e) {
                                     $result['success'] = false;
                                     $result['info'] = $e->getMessage();
                                     echo Zend_Json::encode($result);
                                     exit;
                                 }
                             } catch (Exception $e) {
                                 $result['success'] = false;
                                 $result['info'] = $e->getMessage();
                                 echo Zend_Json::encode($result);
                                 exit;
                             }
                         }
                     } else {
                         if ($user->fetchAll("employee_id = " . $val->id)->count() > 0) {
                             // 当员工系统账号已存在时,如需要改变账号状态,则更新系统账号状态信息
                             if ($user->fetchAll("active = " . $val->account_active . " and employee_id = " . $val->id)->count() == 0) {
                                 try {
                                     $user->update(array('active' => $val->account_active, 'update_user' => $user_id, 'update_time' => $now), "employee_id = " . $val->id);
                                 } catch (Exception $e) {
                                     $result['success'] = false;
                                     $result['info'] = $e->getMessage();
                                     echo Zend_Json::encode($result);
                                     exit;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($inserted) > 0) {
         foreach ($inserted as $val) {
             if ($employee->fetchAll("email = '" . $val->email . "'")->count() > 0) {
                 $result['success'] = false;
                 $result['info'] = '添加失败,邮箱地址重复!';
                 echo Zend_Json::encode($result);
                 exit;
             } else {
                 if ($employee->fetchAll("number = '" . $val->number . "'")->count() > 0) {
                     $result['success'] = false;
                     $result['info'] = '添加失败,工号重复!';
                     echo Zend_Json::encode($result);
                     exit;
                 } else {
                     $data = array('hide' => isset($val->hide) ? $val->hide : 0, 'active' => $val->active, 'leader' => $val->leader, 'number' => $val->number, 'cname' => $val->cname, 'ename' => $val->ename, 'sex' => $val->sex, 'birthday' => $val->birthday, 'id_card' => $val->id_card, 'dept_id' => $val->dept_id, 'post_id' => $val->post_id, 'area_id' => $val->area_id, 'professional_qualifications_id' => $val->professional_qualifications_id, 'dept_manager_id' => $val->dept_manager_id, 'manager_id' => $val->manager_id, 'salary' => $val->salary, 'email' => $val->email, 'tel' => $val->tel, 'official_qq' => $val->official_qq, 'work_place' => $val->work_place, 'short_num' => $val->short_num, 'msn' => $val->msn, 'address' => $val->address, 'remark' => $val->remark, 'marital_status' => $val->marital_status, 'marry_day' => $val->marry_day, 'children_birthday' => $val->children_birthday, 'insurcode' => $val->insurcode, 'accumulation_fund_code' => $val->accumulation_fund_code, 'education' => $val->education, 'school' => $val->school, 'major' => $val->major, 'entry_date' => $val->entry_date, 'regularization_date' => $val->regularization_date, 'labor_contract_start' => $val->labor_contract_start, 'labor_contract_end' => $val->labor_contract_end, 'offical_address' => $val->offical_address, 'other_contact' => $val->other_contact, 'other_relationship' => $val->other_relationship, 'other_contact_way' => $val->other_contact_way, 'work_years' => $val->work_years, 'politics_status' => $val->politics_status, 'employment_type' => $val->employment_type, 'leave_date' => $val->leave_date, 'ext' => $val->ext, 'driving_license' => $val->driving_license, 'salary' => $val->salary, 'bank' => $val->bank, 'bank_num' => $val->bank_num, 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id);
                     try {
                         $employee_id = $employee->insert($data);
                     } catch (Exception $e) {
                         $result['success'] = false;
                         $result['info'] = $e->getMessage();
                         echo Zend_Json::encode($result);
                         exit;
                     }
                     if ($val->account == 1 && $user->fetchAll("employee_id = " . $employee_id)->count() == 0) {
                         try {
                             $data = array('employee_id' => $employee_id, 'active' => $val->account_active, 'password' => md5($val->number . '123456'), 'create_time' => $now, 'create_user' => $user_id, 'update_time' => $now, 'update_user' => $user_id);
                             $newUserId = $user->insert($data);
                             // 初始化用户角色为普通用户
                             $roleMember = new Admin_Model_Member();
                             try {
                                 $roleMember->insert(array('user_id' => $newUserId));
                             } catch (Exception $e) {
                                 $result['success'] = false;
                                 $result['info'] = $e->getMessage();
                                 echo Zend_Json::encode($result);
                                 exit;
                             }
                         } catch (Exception $e) {
                             $result['success'] = false;
                             $result['info'] = $e->getMessage();
                             echo Zend_Json::encode($result);
                             exit;
                         }
                     }
                 }
             }
         }
     }
     if (count($deleted) > 0) {
         foreach ($deleted as $val) {
             if ($user->fetchAll("employee_id = " . $val->id)->count() == 0) {
                 try {
                     $employee->delete("id = " . $val->id);
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             } else {
                 $result['success'] = false;
                 $result['info'] = '员工ID' . $val->id . '存在关联系统账号,不能删除';
                 echo Zend_Json::encode($result);
                 exit;
             }
         }
     }
     echo Zend_Json::encode($result);
     exit;
 }
Example #7
0
 public function savepasswordAction()
 {
     // 返回值数组
     $result = array('success' => true, 'info' => '修改密码成功');
     $request = $this->getRequest()->getParams();
     $user_id = isset($request['user_id']) ? $request['user_id'] : null;
     $key = isset($request['key']) ? $request['key'] : null;
     $pwd = isset($request['pwd1']) ? $request['pwd1'] : null;
     // 检查输入
     if ($user_id && $pwd) {
         $user = new Application_Model_User();
         $employeeInfo = $user->getEmployeeInfoById($user_id);
         $pwd = md5($employeeInfo['number'] . $pwd);
         try {
             $user->update(array('password' => $pwd), "id = " . $user_id);
             // 当检查到key,更新重置密码邮件key
             if ($key) {
                 $mail = new Application_Model_Log_Mail();
                 try {
                     $mail->clearKey($key);
                 } catch (Exception $e) {
                     $result['success'] = false;
                     $result['info'] = $e->getMessage();
                     echo Zend_Json::encode($result);
                     exit;
                 }
             }
         } catch (Exception $e) {
             $result['success'] = false;
             $result['info'] = $e->getMessage();
             echo Zend_Json::encode($result);
             exit;
         }
     } else {
         $result['success'] = false;
         $result['info'] = '输入错误,请重新输入!';
     }
     echo Zend_Json::encode($result);
     exit;
 }