public function save($employeeform) { $emproleStr = ''; $roleArr = array(); $empgroupStr = ''; $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $usersModel = new Default_Model_Usermanagement(); $employeeModal = new Default_Model_Employee(); $requimodel = new Default_Model_Requisition(); $candidate_model = new Default_Model_Candidatedetails(); $orgInfoModel = new Default_Model_Organisationinfo(); $unitid = ''; $deptid = ''; $errorflag = 'true'; $msgarray = array(); $id = $this->_request->getParam('id'); $businessunit_id = $this->_request->getParam('businessunit_id', null); $department_id = $this->_request->getParam('department_id', null); $reporting_manager = $this->_request->getParam('reporting_manager', null); $jobtitle_id = $this->_request->getParam('jobtitle_id', null); $position_id = $this->_request->getParam('position_id', null); $user_id = $this->_getParam('user_id', null); $prefix_id = $this->_getParam('prefix_id', null); $extension_number = $this->_getParam('extension_number', null); $office_number = $this->_request->getParam('office_number', null); $office_faxnumber = $this->_request->getParam('office_faxnumber', null); $date_of_joining = $this->_request->getParam('date_of_joining', null); $date_of_joining = sapp_Global::change_date($date_of_joining, 'database'); $isvalidorgstartdate = $orgInfoModel->validateEmployeeJoiningDate($date_of_joining, $unitid, $deptid); if (!empty($isvalidorgstartdate)) { $msgarray['date_of_joining'] = 'Employee joining date should be greater than organization start date.'; $errorflag = 'false'; } if ($id) { $data = $employeeModal->getsingleEmployeeData($id); if (!empty($data) && $data[0]['is_orghead'] == 1) { $reporting_manager = $this->_request->getParam('reporting_manager', '0'); } } if ($employeeform->isValid($this->_request->getPost()) && $errorflag == 'true') { $id = $this->_request->getParam('id'); $emp_status_id = $this->_request->getParam('emp_status_id', null); $date_of_leaving = $this->_request->getParam('date_of_leaving', null); $date_of_leaving = sapp_Global::change_date($date_of_leaving, 'database'); $years_exp = $this->_request->getParam('years_exp'); //FOR USER table $employeeId = $this->_getParam('employeeId', null); $modeofentry = $this->_getParam('modeofentry', null); $hid_modeofentry = $this->_getParam('hid_modeofentry', null); $other_modeofentry = $this->_getParam('other_modeofentry', null); $firstname = trim($this->_getParam('firstname', null)); $lastname = trim($this->_getParam('lastname', null)); $userfullname = $firstname . ' ' . $lastname; $candidatereferredby = $this->_getParam('candidatereferredby', null); $rccandidatename = $this->_getParam('rccandidatename', null); $emprole = $this->_getParam('emprole', null); //roleid_group_id if ($emprole != "") { $roleArr = explode('_', $emprole); if (!empty($roleArr)) { $emproleStr = $roleArr[0]; $empgroupStr = $roleArr[0]; } } $emailaddress = $this->_getParam('emailaddress', null); $tmp_name = $this->_request->getParam('tmp_emp_name', null); $act_inact = $this->_request->getParam("act_inact", null); //end of user table $date = new Zend_Date(); $menumodel = new Default_Model_Menu(); $empstatusarray = array(8, 9, 10); $actionflag = ''; $tableid = ''; if ($modeofentry == 'Direct' || $hid_modeofentry == 'Direct') { $candidate_key = 'userfullname'; $candidate_value = $userfullname; $emp_name = $userfullname; $candidate_flag = 'no'; } else { $candidate_key = 'rccandidatename'; $candidate_value = $rccandidatename; $emp_name = $tmp_name; $candidate_flag = 'yes'; } $trDb = Zend_Db_Table::getDefaultAdapter(); // starting transaction $trDb->beginTransaction(); try { $emppassword = sapp_Global::generatePassword(); $user_data = array('emprole' => $emproleStr, 'firstname' => $firstname != '' ? $firstname : NULL, 'lastname' => $lastname != '' ? $lastname : NULL, $candidate_key => $candidate_value, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'modeofentry' => $id == '' ? $modeofentry : "", 'selecteddate' => $date_of_joining, 'candidatereferredby' => $candidatereferredby, 'userstatus' => 'old', 'other_modeofentry' => $other_modeofentry); if ($id != '') { $where = array('user_id=?' => $user_id); $actionflag = 2; $user_where = "id = " . $user_id; unset($user_data['candidatereferredby']); unset($user_data['userstatus']); unset($user_data['emppassword']); unset($user_data['employeeId']); unset($user_data['modeofentry']); unset($user_data['other_modeofentry']); } else { $user_data['createdby'] = $loginUserId; $user_data['createddate'] = gmdate("Y-m-d H:i:s"); $user_data['isactive'] = 1; if ($modeofentry != 'Direct') { $user_data['userfullname'] = $emp_name; } $where = ''; $actionflag = 1; $user_where = ''; $identity_code_model = new Default_Model_Identitycodes(); $identity_codes = $identity_code_model->getIdentitycodesRecord(); $emp_identity_code = isset($identity_codes[0]) ? $identity_codes[0]['employee_code'] : ""; if ($emp_identity_code != '') { $emp_id = $emp_identity_code . str_pad($usersModel->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT); } else { $emp_id = ''; } $user_data['employeeId'] = $emp_id; } $user_status = $usersModel->SaveorUpdateUserData($user_data, $user_where); if ($id == '') { $user_id = $user_status; } $data = array('user_id' => $user_id, 'reporting_manager' => $reporting_manager, 'emp_status_id' => $emp_status_id, 'businessunit_id' => $businessunit_id, 'department_id' => $department_id, 'jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'extension_number' => $extension_number != '' ? $extension_number : NULL, 'office_number' => $office_number != '' ? $office_number : NULL, 'office_faxnumber' => $office_faxnumber != '' ? $office_faxnumber : NULL, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'years_exp' => $years_exp == '' ? null : $years_exp, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s")); if ($id == '') { $data['createdby'] = $loginUserId; $data['createddate'] = gmdate("Y-m-d H:i:s"); $data['isactive'] = 1; } $Id = $employeeModal->SaveorUpdateEmployeeData($data, $where); $statuswhere = array('id=?' => $user_id); if ($id != '') { if (in_array($emp_status_id, $empstatusarray)) { $isactivestatus = ''; if ($emp_status_id == 8) { $isactivestatus = 2; } else { if ($emp_status_id == 9) { $isactivestatus = 3; } else { if ($emp_status_id == 10) { $isactivestatus = 4; } } } $statusdata = array('isactive' => $isactivestatus); $empstatusId = $usersModel->SaveorUpdateUserData($statusdata, $statuswhere); $employeeModal->SaveorUpdateEmployeeData($statusdata, "user_id = " . $user_id); } else { $edata = $usersModel->getUserDataById($id); $statusdata = array('isactive' => 1); if ($edata['isactive'] != 0) { if ($edata['emptemplock'] == 1) { $statusdata = array('isactive' => 0); } $empstatusId = $usersModel->SaveorUpdateUserData($statusdata, $statuswhere); $employeeModal->SaveorUpdateEmployeeData($statusdata, "user_id = " . $user_id); } } } if ($Id == 'update') { $tableid = $id; $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Employee details updated successfully.")); } else { //start of mailing $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl(); $view = $this->getHelper('ViewRenderer')->view; $this->view->emp_name = $emp_name; $this->view->password = $emppassword; $this->view->emp_id = $employeeId; $this->view->base_url = $base_url; $text = $view->render('mailtemplates/newpassword.phtml'); $options['subject'] = APPLICATION_NAME . ': Login Credentials'; $options['header'] = 'Greetings from Sentrifugo'; $options['toEmail'] = $emailaddress; $options['toName'] = $this->view->emp_name; $options['message'] = $text; $result = sapp_Global::_sendEmail($options); //end of mailing $tableid = $Id; $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Employee details added successfully.")); //incrementing requisition id if ($candidate_flag == 'yes') { $cand_data = $candidate_model->getCandidateById($rccandidatename); $candidate_model->SaveorUpdateCandidateData(array('cand_status' => 'Recruited', 'modifieddate' => gmdate("Y-m-d H:i:s")), " id = " . $rccandidatename); $reqData = $requimodel->incrementfilledpositions($cand_data['requisition_id']); if ($reqData['req_no_positions'] == $reqData['filled_positions']) { $req_status = '6'; $data = array('req_status' => $req_status, 'modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s")); $where = "id = " . $cand_data['requisition_id']; $result = $requimodel->SaveorUpdateRequisitionData($data, $where); $requimodel->change_to_requisition_closed($cand_data['requisition_id']); $this->send_requi_mail($cand_data['requisition_id'], $requimodel, $usersModel, $loginUserId); } } } $menuidArr = $menumodel->getMenuObjID('/employee'); $menuID = $menuidArr[0]['id']; $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $user_id); if ($act_inact == 1) { if ($user_data['isactive'] == 1) { } else { } } $trDb->commit(); // Send email to employee when his details are edited by other user. $options['subject'] = APPLICATION_NAME . ': Employee details updated'; $options['header'] = 'Employee details updated'; $options['toEmail'] = $emailaddress; $options['toName'] = $userfullname; $options['message'] = 'Dear ' . $userfullname . ', your employee details are updated.'; $options['cron'] = 'yes'; if (!empty($id)) { sapp_Global::_sendEmail($options); } $this->_redirect('employee/edit/id/' . $user_id); } catch (Exception $e) { $trDb->rollBack(); $msgarray['employeeId'] = "Something went wrong, please try again later."; return $msgarray; } } else { $messages = $employeeform->getMessages(); foreach ($messages as $key => $val) { foreach ($val as $key2 => $val2) { $msgarray[$key] = $val2; break; } } if (isset($businessunit_id) && $businessunit_id != '') { $departmentsmodel = new Default_Model_Departments(); $departmentlistArr = $departmentsmodel->getDepartmentList($businessunit_id); $employeeform->department_id->clearMultiOptions(); $employeeform->reporting_manager->clearMultiOptions(); $employeeform->department_id->addMultiOption('', 'Select Department'); foreach ($departmentlistArr as $departmentlistresult) { $employeeform->department_id->addMultiOption($departmentlistresult['id'], utf8_encode($departmentlistresult['deptname'])); } if (isset($department_id) && $department_id != 0 && $department_id != '') { $employeeform->setDefault('department_id', $department_id); } } if (isset($jobtitle_id) && $jobtitle_id != 0 && $jobtitle_id != '') { $positionsmodel = new Default_Model_Positions(); $positionlistArr = $positionsmodel->getPositionList($jobtitle_id); $employeeform->position_id->clearMultiOptions(); $employeeform->position_id->addMultiOption('', 'Select Position'); foreach ($positionlistArr as $positionlistRes) { $employeeform->position_id->addMultiOption($positionlistRes['id'], utf8_encode($positionlistRes['positionname'])); } if (isset($position_id) && $position_id != 0 && $position_id != '') { $employeeform->setDefault('position_id', $position_id); } } return $msgarray; } }