public function save($appraisalconfigform) { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $appraisalconfigmodel = new Default_Model_Appraisalconfig(); $departmentsmodel = new Default_Model_Departments(); $businessunitsmodel = new Default_Model_Businessunits(); $msgarray = array(); $resultArr = array(); $arrData = array(); $prevBusinessunit = ''; $errorflag = "true"; $id = $this->_request->getParam('id'); $businessunit_id = $this->_request->getParam('businessunit_id'); $performance_app_flag = $this->_request->getParam('performance_app_flag'); $department_id = $this->_request->getParam('department_id'); $appraisal_mode = $this->_request->getParam('appraisal_mode'); $approval_selection = $this->_request->getParam('approval_selection'); $appraisal_ratings = $this->_request->getParam('appraisal_ratings'); // Validation to check duplicate combinations $arrData = array("business_unit_id" => $businessunit_id, "department_id" => $department_id, "id" => $id); if ($appraisalconfigmodel->combinationExists($arrData)) { $msgarray['businessunit_id'] = 'Business unit or department configuration already exists.'; $errorflag = "false"; } /** Start * Validating selection of department if implementaion is department wise */ if ($performance_app_flag == 0) { if ($department_id == '') { $msgarray['department_id'] = 'Please select department.'; $errorflag = "false"; } } /** End validating selection of department */ /** Start Validating unique service desk department */ if ($businessunit_id != '' && $id == '') { $appraisalconigfArr = $appraisalconfigmodel->checkuniqueAppraisalConfigData($businessunit_id, $performance_app_flag, $department_id); if (!empty($appraisalconigfArr)) { if ($appraisalconigfArr[0]['count'] > 0) { $msgarray['department_id'] = 'Please select a different department.'; $errorflag = "false"; } } } /** End * Validating uniques department */ $db = Zend_Db_Table::getDefaultAdapter(); $db->beginTransaction(); if ($appraisalconfigform->isValid($this->_request->getPost()) && $errorflag == 'true') { try { $menumodel = new Default_Model_Menu(); $actionflag = ''; $tableid = ''; $data = array('businessunit_id' => $businessunit_id, 'department_id' => $department_id != '' ? $department_id : NULL, 'performance_app_flag' => $performance_app_flag, 'appraisal_mode' => $appraisal_mode, 'appraisal_ratings' => $appraisal_ratings, 'module_flag' => 1, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s")); if ($id != '') { /* for Update record */ $where = array('id=?' => $id); $actionflag = 2; } else { /* for Insert new record */ $data['createdby'] = $loginUserId; $data['createddate'] = gmdate("Y-m-d H:i:s"); $data['isactive'] = 1; $where = ''; $actionflag = 1; } $Id = $appraisalconfigmodel->SaveorUpdateAppraisalConfigData($data, $where); if ($Id == 'update') { $tableid = $id; $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Appraisal settings updated successfully")); } else { $tableid = $Id; $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Appraisal settings added successfully")); } $menuidArr = $menumodel->getMenuObjID('/appraisalconfig'); $menuID = $menuidArr[0]['id']; $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid); /** Start * Sending Mails to employees */ /* if($performance_app_flag == 0) $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessunit_id,$department_id); else $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessunit_id,''); $msg_add_update = ($Id == 'update') ? "updated" : "added" ; //Sending mail to Super admin $options['subject'] = APPLICATION_NAME.': Performance Appraisal Settings '.ucfirst($msg_add_update); $options['header'] = 'Performance Appraisal Configuration'; $options['toEmail'] = SUPERADMIN_EMAIL; $options['toName'] = 'Super Admin'; $options['message'] = 'Dear Super Admin, performance appraisal configuration '.$msg_add_update; // $mail_id = sapp_Global::_sendEmail($options); //sending mail to others if(!empty($employeeDetailsArr)) { foreach($employeeDetailsArr as $emp) { $options['subject'] = APPLICATION_NAME.': Performance Appraisal Settings Added.'; $options['header'] = 'Performance Appraisal Configuration'; $options['toEmail'] = $emp['emailaddress']; $options['toName'] = $emp['userfullname']; $options['message'] = 'Dear '.$emp['userfullname'].', performance appraisal configuration '.$msg_add_update; // $mail_id = sapp_Global::_sendEmail($options); } } /** * End */ $db->commit(); $this->_redirect('appraisalconfig'); throw new Exception("Some error message"); } catch (Exception $e) { $db->rollBack(); echo $e->getMessage(); echo $e->getTraceAsString(); return $msgarray; } } else { $messages = $appraisalconfigform->getMessages(); foreach ($messages as $key => $val) { foreach ($val as $key2 => $val2) { $msgarray[$key] = $val2; break; } } if (isset($businessunit_id) && $businessunit_id != '') { if ($performance_app_flag == 0) { $departmentlistArr = $departmentsmodel->getDepartmentList($businessunit_id); if (!empty($departmentlistArr)) { foreach ($departmentlistArr as $departmentlist) { $appraisalconfigform->department_id->addMultiOption($departmentlist['id'], utf8_encode($departmentlist['deptname'])); } } } if (isset($department_id) && $department_id != 0 && $department_id != '') { $appraisalconfigform->setDefault('department_id', $department_id); } } return $msgarray; } }
public function save($appraisalconfigform) { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; $loginuserRole = $auth->getStorage()->read()->emprole; $loginUserEmpId = $auth->getStorage()->read()->employeeId; $loginUserEmail = $auth->getStorage()->read()->emailaddress; $loginUsername = $auth->getStorage()->read()->userfullname; } $appraisalconfigmodel = new Default_Model_Appraisalconfig(); $departmentsmodel = new Default_Model_Departments(); $businessunitsmodel = new Default_Model_Businessunits(); $msgarray = array(); $resultArr = array(); $arrData = array(); $prevBusinessunit = ''; $errorflag = "true"; $id = $this->_request->getParam('id'); $businessunit_id = $this->_request->getParam('businessunit_id'); $performance_app_flag = $this->_request->getParam('performance_app_flag'); $department_id = $this->_request->getParam('department_id'); $appraisal_mode = $this->_request->getParam('appraisal_mode'); $approval_selection = $this->_request->getParam('approval_selection'); $appraisal_ratings = $this->_request->getParam('appraisal_ratings'); // Validation to check duplicate combinations $arrData = array("business_unit_id" => $businessunit_id, "department_id" => $department_id, "id" => $id); if ($appraisalconfigmodel->combinationExists($arrData)) { $msgarray['businessunit_id'] = 'Business unit or department configuration already exists.'; $errorflag = "false"; } /** Start * Validating selection of department if implementaion is department wise */ if ($performance_app_flag == 0) { if ($department_id == '') { $msgarray['department_id'] = 'Please select department.'; $errorflag = "false"; } } /** End validating selection of department */ /** Start Validating unique service desk department */ if ($businessunit_id != '' && $id == '') { $appraisalconigfArr = $appraisalconfigmodel->checkuniqueAppraisalConfigData($businessunit_id, $performance_app_flag, $department_id); if (!empty($appraisalconigfArr)) { if ($appraisalconigfArr[0]['count'] > 0) { $msgarray['department_id'] = 'Please select a different department.'; $errorflag = "false"; } } } /** End * Validating uniques department */ $db = Zend_Db_Table::getDefaultAdapter(); $db->beginTransaction(); if ($appraisalconfigform->isValid($this->_request->getPost()) && $errorflag == 'true') { try { $actionflag = ''; $tableid = ''; $data = array('businessunit_id' => $businessunit_id, 'department_id' => $department_id != '' ? $department_id : NULL, 'performance_app_flag' => $performance_app_flag, 'appraisal_mode' => $appraisal_mode, 'appraisal_ratings' => $appraisal_ratings, 'module_flag' => 1, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s")); if ($id != '') { /* for Update record */ $where = array('id=?' => $id); $actionflag = 2; } else { /* for Insert new record */ $data['createdby'] = $loginUserId; $data['createddate'] = gmdate("Y-m-d H:i:s"); $data['isactive'] = 1; $where = ''; $actionflag = 1; } $Id = $appraisalconfigmodel->SaveorUpdateAppraisalConfigData($data, $where); if ($Id == 'update') { $tableid = $id; $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Appraisal settings updated successfully")); } else { $tableid = $Id; $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Appraisal settings added successfully")); } /* * Logs Storing */ $menuID = APPRAISAL_SETTINGS; $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid); /* * Logs storing ends */ /** Start * Sending Mails to employees */ if ($performance_app_flag == 0) { $appraisal_details = $appraisalconfigmodel->getBunitDept($businessunit_id, $department_id); } else { $appraisal_details = $appraisalconfigmodel->getBunit($businessunit_id); } $employeeDetailsArr = $appraisalconfigmodel->getUserDetailsByID($businessunit_id, $department_id); if (!empty($appraisal_details)) { $bunit = $appraisal_details['unitname']; $dept = $appraisal_details['deptname']; } $msg_add_update = $Id == 'update' ? "Updated" : "Configured"; $dept_str = $dept == '' ? " " : "and <b>{$dept}</b> department"; $emp_id_str = $loginuserRole == SUPERADMINROLE ? " " : "({$loginUserEmpId})"; //Preparing Employee array for BCc $empArr = array(); if (!empty($employeeDetailsArr)) { $empArrList = ''; foreach ($employeeDetailsArr as $emp) { array_push($empArr, $emp['emailaddress']); } } //Sending mail to Super admin $options['subject'] = APPLICATION_NAME . ': Performance Appraisal Configuration ' . ucfirst($msg_add_update); $options['header'] = 'Performance Appraisal'; $options['toEmail'] = SUPERADMIN_EMAIL; $options['bcc'] = $empArr; $options['toName'] = 'Super Admin'; $options['message'] = "<div style='padding: 0; text-align: left; font-size:14px; font-family:Arial, Helvetica, sans-serif;'>\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span style='color:#3b3b3b;'>Hi,</span><br />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Performance appraisal settings are {$msg_add_update} for <b>{$bunit}</b> business unit {$dept_str} by " . $loginUsername . $emp_id_str . " </div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div style='padding:20px 0 10px 0;'>Please <a href=" . BASE_URL . " target='_blank' style='color:#b3512f;'>click here</a> to login to <b>" . APPLICATION_NAME . "</b> and check the details.</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div> "; $mail_id = sapp_Global::_sendEmail($options); /** * End */ $db->commit(); $this->_redirect('appraisalconfig'); throw new Exception("Some error message"); } catch (Exception $e) { $db->rollBack(); echo $e->getMessage(); echo $e->getTraceAsString(); return $msgarray; } } else { $messages = $appraisalconfigform->getMessages(); foreach ($messages as $key => $val) { foreach ($val as $key2 => $val2) { $msgarray[$key] = $val2; break; } } if (isset($businessunit_id) && $businessunit_id != '') { if ($performance_app_flag == 0) { $departmentlistArr = $departmentsmodel->getDepartmentList($businessunit_id); if (!empty($departmentlistArr)) { foreach ($departmentlistArr as $departmentlist) { $appraisalconfigform->department_id->addMultiOption($departmentlist['id'], utf8_encode($departmentlist['deptname'])); } } } if (isset($department_id) && $department_id != 0 && $department_id != '') { $appraisalconfigform->setDefault('department_id', $department_id); } } return $msgarray; } }