コード例 #1
0
 /**
  * This function is used to active/inactive employees.
  */
 public function makeactiveinactiveAction()
 {
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $emp_id = $this->_getParam('emp_id', null);
     $status = trim($this->_getParam('status', null));
     $hasteam = trim($this->_getParam('hasteam', null));
     $employeeModal = new Default_Model_Employee();
     $user_model = new Default_Model_Usermanagement();
     $usermodel = new Default_Model_Users();
     $role_model = new Default_Model_Roles();
     $logmanagermodel = new Default_Model_Logmanager();
     $menumodel = new Default_Model_Menu();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $empData = $employeeModal->getsingleEmployeeData($emp_id);
     if ($hasteam == 'true') {
         $employessunderEmpId = array();
         $reportingmanagersList = array();
         $employessunderEmpId = $employeeModal->getEmployeesUnderRM($emp_id);
         if ($empData[0]['is_orghead'] == 1) {
             $reportingmanagersList = $usermodel->getReportingManagerList_employees('', '', MANAGEMENT_GROUP);
         } else {
             $role_data = $role_model->getRoleDataById($empData[0]['emprole']);
             $reportingmanagersList = $usermodel->getReportingManagerList_employees($empData[0]['department_id'], $emp_id, $role_data['group_id']);
         }
         $reportingmanagersList = sapp_Global::removeElementWithValue($reportingmanagersList, 'id', $emp_id);
         $this->view->emp_id = $emp_id;
         $this->view->status = $status;
         $this->view->ishead = $empData[0]['is_orghead'];
         $this->view->empName = $empData[0]['userfullname'];
         $this->view->employessunderEmpId = $employessunderEmpId;
         $this->view->reportingmanagersList = $reportingmanagersList;
     } else {
         $db = Zend_Db_Table::getDefaultAdapter();
         $db->beginTransaction();
         try {
             if ($status == 'active') {
                 $data = array('isactive' => 1, 'emptemplock' => 0);
                 $empdata = array('isactive' => 1);
                 $logarr = array('userid' => $loginUserId, 'recordid' => $emp_id, 'date' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                 $jsonlogarr = json_encode($logarr);
             } else {
                 if ($status == 'inactive') {
                     $data = array('isactive' => 0, 'emptemplock' => 1);
                     $empdata = array('isactive' => 0);
                     $logarr = array('userid' => $loginUserId, 'recordid' => $emp_id, 'date' => gmdate("Y-m-d H:i:s"), 'isactive' => 0);
                     $jsonlogarr = json_encode($logarr);
                 }
             }
             $where = "id = " . $emp_id;
             $user_model->SaveorUpdateUserData($data, $where);
             $employeeModal->SaveorUpdateEmployeeData($empdata, "user_id =" . $emp_id);
             if ($empData[0]['is_orghead'] == '1') {
                 $headData = array('is_orghead' => 0);
                 $headWhere = "user_id = " . $emp_id;
                 $employeeModal->SaveorUpdateEmployeeData($headData, $headWhere);
             }
             $menuidArr = $menumodel->getMenuObjID('/employee');
             $menuID = $menuidArr[0]['id'];
             $id = $logmanagermodel->addOrUpdateLogManager($menuID, 4, $jsonlogarr, $loginUserId, $emp_id);
             $db->commit();
             $result = 'update';
         } catch (Exception $e) {
             $db->rollBack();
             $result = 'failed';
         }
         $this->_helper->json(array('result' => $result == 'update' ? "yes" : "no"));
     }
 }