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 ($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);
         $firstname = trim($this->_getParam('firstname', null));
         $lastname = trim($this->_getParam('lastname', null));
         $userfullname = $firstname . ' ' . $lastname;
         $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);
         //end of user table
         $date = new Zend_Date();
         $menumodel = new Default_Model_Menu();
         $empstatusarray = array(8, 9, 10);
         $actionflag = '';
         $tableid = '';
         $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, 'userfullname' => $userfullname, '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' => 0, 'userstatus' => 'old');
             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']);
             } else {
                 $user_data['createdby'] = $loginUserId;
                 $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $user_data['isactive'] = 1;
                 $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 = $userfullname;
                 $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."));
             }
             $menuidArr = $menumodel->getMenuObjID('/employee');
             $menuID = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $user_id);
             $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('myemployees/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($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;
     }
 }
Esempio n. 2
0
 public function savesitepreference($wizardpreferenceform, $wizardData)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     if ($wizardpreferenceform->isValid($this->_request->getPost())) {
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             $systempreferencemodel = new Default_Model_Sitepreference();
             $currencymodel = new Default_Model_Currency();
             $orgInfoModel = new Default_Model_Organisationinfo();
             $wizard_model = new Default_Model_Wizard();
             $IdentityCodesModel = new Default_Model_Identitycodes();
             $employmentstatusmodel = new Default_Model_Employmentstatus();
             $countriesmodel = new Default_Model_Countries();
             $statesmodel = new Default_Model_States();
             $citiesmodel = new Default_Model_Cities();
             $id = (int) $this->_request->getParam('id');
             $currencyid = (int) $this->_request->getParam('currencyid');
             $organisationid = (int) $this->_request->getParam('organisationid');
             $empcodeid = (int) $this->_request->getParam('empcodeid');
             $dateformatid = $this->_request->getParam('dateformatid');
             $timeformatid = $this->_request->getParam('timeformatid');
             $timezoneid = $this->_request->getParam('timezoneid');
             $currencyname = $this->_request->getParam('currencyname');
             $currencycode = $this->_request->getParam('currencycode');
             $passwordid = $this->_request->getParam('passwordid');
             $perm_country = $this->_request->getParam('perm_country');
             $perm_stateparam = $this->_request->getParam('perm_state');
             $perm_stateArr = explode("!@#", $this->_request->getParam('perm_state'));
             $perm_state = $perm_stateArr[0];
             $perm_cityparam = $this->_request->getParam('perm_city');
             $perm_cityArr = explode("!@#", $this->_request->getParam('perm_city'));
             $perm_city = $perm_cityArr[0];
             $employee_code = $this->_request->getParam('employee_code');
             $workcodename = $this->_request->getParam('workcodename');
             $date = new Zend_Date();
             $menumodel = new Default_Model_Menu();
             /*
              * Save or Update - Currency name in currency table based on currency ID
              */
             $currency_data = array('currencyname' => trim($currencyname), 'currencycode' => trim($currencycode), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($currencyid != '') {
                 $currencywhere = array('id=?' => $currencyid);
             } else {
                 $currency_data['createdby'] = $loginUserId;
                 $currency_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $currency_data['isactive'] = 1;
                 $currencywhere = '';
             }
             $CurrencyId = $currencymodel->SaveorUpdateCurrencyData($currency_data, $currencywhere);
             /*
              * End 
              */
             /*
              * Start -  Updating and Inserting Site Preference Data after fetching currency id
              */
             $siteprference_data = array('dateformatid' => $dateformatid, 'timeformatid' => $timeformatid, 'timezoneid' => $timezoneid, 'currencyid' => $currencyid != '' ? $currencyid : $CurrencyId, 'passwordid' => $passwordid, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'isactive' => 1);
             $site_update_arr = array('isactive' => 0, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId);
             $systempreferencemodel->SaveorUpdateSystemPreferanceData($site_update_arr, 'isactive = 1');
             $Id = $systempreferencemodel->SaveorUpdateSystemPreferanceData($siteprference_data, '');
             /*
              *  End
              */
             /*
              * Updating Country,state and city based on organisation id
              */
             // Inserting into main_countries if not added
             $countryExistsArr = $countriesmodel->getActiveCountryName($perm_country);
             if (empty($countryExistsArr)) {
                 $countrynamearr = $countriesmodel->getCountryCode($perm_country);
                 if (!empty($countrynamearr)) {
                     $country_data = array('country' => trim($countrynamearr[0]['country_name']), 'countrycode' => trim($countrynamearr[0]['country_code']), 'citizenship' => NULL, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'country_id_org' => $perm_country, 'isactive' => 1);
                     $Country_Id = $countriesmodel->SaveorUpdateCountryData($country_data, '');
                 }
             }
             // Inserting into main_state if not added
             $State_Id = $statesmodel->SaveorUpdateStatesData($perm_country, $perm_stateArr[1], $perm_state, $loginUserId);
             // Inserting into main_cities if not added
             $City_Id = $citiesmodel->SaveorUpdateCitiesData($perm_country, $perm_state, $perm_cityArr[1], $perm_city, $loginUserId);
             $location_data = array('country' => $perm_country, 'state' => $perm_state, 'city' => $perm_city, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
             if ($organisationid != '') {
                 $locwhere = array('id=?' => $organisationid);
                 $LocationId = $orgInfoModel->SaveorUpdateData($location_data, $orgwhere);
             }
             $LocationId = $wizard_model->SaveorUpdateWizardData($location_data, '');
             /*
              * End
              */
             /*
              * Start - Updating Employee Code
              */
             $empcode_data = array('employee_code' => trim($employee_code), 'modifiedBy' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($empcodeid != '') {
                 $empcodewhere = array('id=?' => $empcodeid);
             } else {
                 $empcode_data['createdby'] = $loginUserId;
                 $empcode_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $empcodewhere = '';
             }
             $EmpCodeId = $IdentityCodesModel->SaveorUpdateIdentitycodesData($empcode_data, $empcodewhere);
             /*
              * End
              */
             /*
              * Start - Update employment status data
              */
             if (!empty($workcodename)) {
                 $empstat_update_arr = array('isactive' => 0, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId);
                 $Empstat_update_Id = $employmentstatusmodel->SaveorUpdateEmploymentStatusData($empstat_update_arr, 'isactive=1');
                 for ($j = 0; $j < sizeof($workcodename); $j++) {
                     switch ($workcodename[$j]) {
                         case 1:
                             $workcode = 'FT';
                             break;
                         case 2:
                             $workcode = 'PT';
                             break;
                         case 3:
                             $workcode = 'PERM';
                             break;
                         case 4:
                             $workcode = 'TEMP';
                             break;
                         case 5:
                             $workcode = 'PROB';
                             break;
                         case 6:
                             $workcode = 'CONT';
                             break;
                         case 7:
                             $workcode = 'DEP';
                             break;
                         case 8:
                             $workcode = 'RES';
                             break;
                         case 9:
                             $workcode = 'LEFT';
                             break;
                         case 10:
                             $workcode = 'SUSP';
                             break;
                         default:
                             $workcode = 'FT';
                     }
                     $empstatus_data = array('workcode' => trim($workcode), 'workcodename' => trim($workcodename[$j]), 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                     $Empstat_Id = $employmentstatusmodel->SaveorUpdateEmploymentStatusData($empstatus_data, '');
                 }
             }
             /*
              * End
              */
             /*
              * Update Wizard Table
              */
             $wizardarray = array('site_config' => 2, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($wizardData['org_details'] == 2) {
                 $wizardarray['iscomplete'] = 2;
             }
             $wizard_model->SaveorUpdateWizardData($wizardarray, '');
             $trDb->commit();
             $this->_helper->getHelper("FlashMessenger")->addMessage("Site Preference updated successfully.");
             $this->_redirect('wizard/configuresite');
         } catch (Exception $e) {
             $trDb->rollBack();
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Something went wrong,please try again later."));
             $this->_redirect('wizard/configuresite');
         }
     } else {
         $messages = $wizardpreferenceform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
Esempio n. 3
0
 public static function process_emp_excel($file_name)
 {
     require_once 'Classes/PHPExcel.php';
     require_once 'Classes/PHPExcel/IOFactory.php';
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $emp_model = new Default_Model_Employee();
     $usersModel = new Default_Model_Usermanagement();
     $identity_code_model = new Default_Model_Identitycodes();
     $objReader = PHPExcel_IOFactory::createReaderForFile($file_name);
     $objPHPExcel = $objReader->load($file_name);
     //Read first sheet
     $sheet = $objPHPExcel->getSheet(0);
     // Get worksheet dimensions
     $sizeOfWorksheet = $sheet->getHighestDataRow();
     $highestColumn = $sheet->getHighestDataColumn();
     if ($sizeOfWorksheet > 1) {
         $arrReqHeaders = array('Prefix', 'First name', 'Last name', 'Role Type', 'Email', 'Business Unit', 'Department', 'Reporting manager', 'Job Title', 'Position', 'Employment Status', 'Date of joining', 'Date of leaving', 'Experience', 'Extension', 'Work telephone number', 'Fax');
         //Get first/header from excel
         $firstRow = $sheet->rangeToArray('A' . 1 . ':' . $highestColumn . 1, NULL, TRUE, TRUE);
         $arrGivenHeaders = $firstRow[0];
         $diffArray = array_diff_assoc($arrReqHeaders, $arrGivenHeaders);
         $prefix_arr = $emp_model->getPrefix_emp_excel();
         $roles_arr = $emp_model->getRoles_emp_excel();
         $bu_arr = $emp_model->getBU_emp_excel();
         $dep_arr = $emp_model->getDep_emp_excel();
         $job_arr = $emp_model->getJobs_emp_excel();
         $positions_arr = $emp_model->getPositions_emp_excel();
         $users_arr = $emp_model->getUsers_emp_excel();
         $emp_stat_arr = $emp_model->getEstat_emp_excel();
         $dol_emp_stat_arr = $emp_model->getDOLEstat_emp_excel();
         $mng_roles_arr = $emp_model->getMngRoles_emp_excel();
         $emps_arr = $emp_model->getEmps_emp_excel();
         $emails_arr = $emps_arr['email'];
         $emp_ids_arr = $emps_arr['ids'];
         $emp_depts_arr = $emp_model->getEmpsDeptWise();
         $dept_bu_arr = $emp_model->getDeptBUWise();
         $pos_jt_arr = $emp_model->getPosJTWise();
         $identity_codes = $identity_code_model->getIdentitycodesRecord();
         $emp_identity_code = isset($identity_codes[0]) ? $identity_codes[0]['employee_code'] : "";
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             //start of validations
             $ex_prefix_arr = array();
             //$ex_fullname_arr = array();
             $ex_firstname_arr = array();
             $ex_lastname_arr = array();
             $ex_role_arr = array();
             $ex_email_arr = array();
             $ex_bu_arr = array();
             $ex_dep_arr = array();
             $ex_rm_arr = array();
             $ex_jt_arr = array();
             $ex_pos_arr = array();
             $ex_es_arr = array();
             $ex_doj_arr = array();
             $ex_dol_arr = array();
             $ex_exp_arr = array();
             $ex_ext_arr = array();
             $ex_wn_arr = array();
             $ex_fax_arr = array();
             $tot_rec_cnt = 0;
             $err_msg = "";
             for ($i = 2; $i <= $sizeOfWorksheet; $i++) {
                 $rowData_org = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, TRUE);
                 $rowData = $rowData_org[0];
                 $rowData_cpy = $rowData;
                 foreach ($rowData_cpy as $rkey => $rvalue) {
                     $rowData[$rkey] = trim($rvalue);
                 }
                 //start of mandatory checking
                 if (empty($rowData[0])) {
                     $err_msg = "Prefix cannot be empty at row " . $i . ".";
                     break;
                 }
                 /* if(empty($rowData[1]))
                    {
                        $err_msg = "Full Name cannot be empty at row ".$i.".";
                        break;
                    }*/
                 if (empty($rowData[1])) {
                     $err_msg = "First name cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[2])) {
                     $err_msg = "Last name cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[3])) {
                     $err_msg = "Role type cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[4])) {
                     $err_msg = "Email cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[7])) {
                     $err_msg = "Reporting manager cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[8])) {
                     $err_msg = "Job title cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[9])) {
                     $err_msg = "Position cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[10])) {
                     $err_msg = "Employment status cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (empty($rowData[11])) {
                     $err_msg = "Date of joining cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (!in_array($rowData[3], $mng_roles_arr) && empty($rowData[6])) {
                     $err_msg = "Department cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (in_array($rowData[10], $dol_emp_stat_arr) && empty($rowData[12])) {
                     $err_msg = "Date of leaving cannot be empty at row " . $i . ".";
                     break;
                 }
                 if (!in_array($rowData[10], $dol_emp_stat_arr) && !empty($rowData[12]) && in_array($rowData[10], $emp_stat_arr)) {
                     $err_msg = "Date of leaving must be empty for '" . $rowData[10] . "' at row " . $i . ".";
                     break;
                 }
                 // end of mandatory checking
                 // start of pattern checking
                 if (!preg_match("/^(?=.*[a-zA-Z])([^ ][a-zA-Z0-9 ]*)\$/", trim($rowData[0])) && !empty($rowData[0])) {
                     $err_msg = "Prefix is not a valid format at row " . $i . ".";
                     break;
                 }
                 /* if (!preg_match("/^([a-zA-Z.]+ ?)+$/", $rowData[1])  && !empty($rowData[1]))
                    {
                        $err_msg = "Full Name is not a valid format at row ".$i.".";
                        break;
                    }*/
                 if (!preg_match("/^([a-zA-Z.]+ ?)+\$/", $rowData[1]) && !empty($rowData[1])) {
                     $err_msg = "First name is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^([a-zA-Z.]+ ?)+\$/", $rowData[2]) && !empty($rowData[2])) {
                     $err_msg = "Last name is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z]+?\$/", $rowData[3]) && !empty($rowData[3])) {
                     $err_msg = "Role type is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^(?!.*\\.{2})[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+\$/", $rowData[4]) && !empty($rowData[4])) {
                     $err_msg = "Email is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z0-9\\&\\'\\.\\s]+\$/", $rowData[5]) && !empty($rowData[5])) {
                     $err_msg = "Business unit is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z0-9\\&\\'\\.\\s]+\$/", $rowData[6]) && !empty($rowData[6])) {
                     $err_msg = "Department is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z0-9\\&\\'\\.\\s]+\$/", $rowData[7]) && !empty($rowData[7])) {
                     $err_msg = "Reporting manager is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z][a-zA-Z0-9\\s]*\$/", $rowData[8]) && !empty($rowData[8])) {
                     $err_msg = "Job title is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[a-zA-Z][a-zA-Z0-9\\-\\s]*\$/i", $rowData[9]) && !empty($rowData[9])) {
                     $err_msg = "Position is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^(?=.*[a-zA-Z])([^ ][a-zA-Z0-9 ]*)\$/", $rowData[10]) && !empty($rowData[10])) {
                     $err_msg = "Employment status is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!empty($rowData[11])) {
                     try {
                         $test_doj = new DateTime($rowData[11]);
                     } catch (Exception $ex) {
                         return array('status' => 'error', 'msg' => "Date of joining is not a valid format at row " . $i . ".");
                     }
                 }
                 if (!empty($rowData[12])) {
                     try {
                         $test_dol = new DateTime($rowData[12]);
                     } catch (Exception $ex) {
                         return array('status' => 'error', 'msg' => "Date of leaving is not a valid format at row " . $i . ".");
                     }
                 }
                 if (!empty($rowData[12]) && $rowData[12] < $rowData[11]) {
                     $err_msg = "Date of leaving must be greater than date of joining at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[0-9]\\d{0,1}(\\.\\d*)?\$/", $rowData[13]) && !empty($rowData[13])) {
                     $err_msg = "Experience is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[0-9]+\$/", $rowData[14]) && !empty($rowData[14])) {
                     $err_msg = "Extension is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^(?!0{10})[0-9\\+\\-\\)\\(]+\$/", $rowData[15]) && !empty($rowData[15])) {
                     $err_msg = "Work telephone number is not a valid format at row " . $i . ".";
                     break;
                 }
                 if (!preg_match("/^[0-9\\+\\-\\)\\(]+\$/", $rowData[16]) && !empty($rowData[16])) {
                     $err_msg = "Fax is not a valid format at row " . $i . ".";
                     break;
                 }
                 // end of pattern checking
                 // start of checking existence in the system.
                 if (!array_key_exists(strtolower($rowData[0]), $prefix_arr) && !empty($rowData[0])) {
                     $err_msg = "Unknown prefix at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[3]), $roles_arr) && !empty($rowData[3])) {
                     $err_msg = "Unknown role type at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[5]), $bu_arr) && !empty($rowData[5])) {
                     $err_msg = "Unknown business unit at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[6]), $dep_arr) && !empty($rowData[6])) {
                     $err_msg = "Unknown department at row " . $i . ".";
                     break;
                 }
                 if (in_array(strtolower($rowData[4]), $emails_arr) && !empty($rowData[4])) {
                     $err_msg = "Email already exists at row " . $i . ".";
                     break;
                 }
                 if (!in_array(strtolower($rowData[7]), $emp_ids_arr) && !empty($rowData[7])) {
                     $err_msg = "Unknown reporting manager at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[8]), $job_arr) && !empty($rowData[8])) {
                     $err_msg = "Unknown job title at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[9]), $positions_arr) && !empty($rowData[9])) {
                     $err_msg = "Unknown position at row " . $i . ".";
                     break;
                 }
                 if (!array_key_exists(strtolower($rowData[10]), $emp_stat_arr) && !empty($rowData[10])) {
                     $err_msg = "Unknown employment status at row " . $i . ".";
                     break;
                 }
                 // end of checking existence in the system.
                 if (!empty($rowData[6])) {
                     if (isset($emp_depts_arr[$dep_arr[strtolower($rowData[6])]]) && !in_array(strtolower($rowData[7]), $emp_depts_arr[$dep_arr[strtolower($rowData[6])]])) {
                         if (isset($emp_depts_arr[0]) && is_array($emp_depts_arr[0])) {
                             if (!in_array(strtolower($rowData[7]), $emp_depts_arr[0])) {
                                 $err_msg = "Reporting manager is not belongs to '" . $rowData[6] . "' department at row " . $i . ".";
                                 break;
                             }
                         }
                     }
                 } else {
                     if (isset($emp_depts_arr[0]) && is_array($emp_depts_arr[0])) {
                         if (!in_array(strtolower($rowData[7]), $emp_depts_arr[0])) {
                             $err_msg = "Reporting manager is not belongs to management group at row " . $i . ".";
                             break;
                         }
                     }
                 }
                 if (!empty($rowData[6])) {
                     if (isset($dept_bu_arr[0]) && is_array($dept_bu_arr[0])) {
                         if (in_array(strtolower($rowData[6]), $dept_bu_arr[0]) && !empty($rowData[5])) {
                             $err_msg = "Business unit not needed for this department '" . $rowData[6] . "' at row " . $i . ".";
                             break;
                         }
                         if (!in_array(strtolower($rowData[6]), $dept_bu_arr[0]) && empty($rowData[5])) {
                             $err_msg = "Business unit cannot be empty at row " . $i . ".";
                             break;
                         }
                     }
                     if (!empty($rowData[5])) {
                         if (isset($dept_bu_arr[$bu_arr[strtolower($rowData[5])]]) && !in_array(strtolower($rowData[6]), $dept_bu_arr[$bu_arr[strtolower($rowData[5])]]) && !empty($rowData[5])) {
                             $err_msg = "Department is not belongs to '" . $rowData[5] . "' business unit at row " . $i . ".";
                             break;
                         }
                     }
                 }
                 if (!empty($rowData[8]) && !empty($rowData[9])) {
                     if (isset($pos_jt_arr[$job_arr[strtolower($rowData[8])]]) && !in_array(strtolower($rowData[9]), $pos_jt_arr[$job_arr[strtolower($rowData[8])]]) && !empty($rowData[8])) {
                         $err_msg = "Position is not belongs to '" . $rowData[8] . "' job title at row " . $i . ".";
                         break;
                     }
                 }
             }
             //end of for loop
             if (!empty($err_msg)) {
                 return array('status' => 'error', 'msg' => $err_msg);
             }
             $err_msg = "";
             for ($i = 2; $i <= $sizeOfWorksheet; $i++) {
                 $rowData_org = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, TRUE);
                 $rowData = $rowData_org[0];
                 $rowData_cpy = $rowData;
                 foreach ($rowData_cpy as $rkey => $rvalue) {
                     $rowData[$rkey] = trim($rvalue);
                 }
                 $ex_prefix_arr[] = $rowData[0];
                 //$ex_fullname_arr[] = $rowData[1];
                 $ex_firstname_arr[] = $rowData[1];
                 $ex_lastname_arr[] = $rowData[2];
                 $ex_role_arr[] = $rowData[3];
                 $ex_email_arr[$i] = $rowData[4];
                 $ex_bu_arr[] = $rowData[5];
                 $ex_dep_arr[] = $rowData[6];
                 $ex_rm_arr[] = $rowData[7];
                 $ex_jt_arr[] = $rowData[8];
                 $ex_pos_arr[] = $rowData[9];
                 $ex_es_arr[] = $rowData[10];
                 $ex_doj_arr[] = $rowData[11];
                 $ex_dol_arr[] = $rowData[12];
                 $ex_exp_arr[] = $rowData[13];
                 $ex_ext_arr[] = $rowData[14];
                 $ex_wn_arr[] = $rowData[15];
                 $ex_fax_arr[] = $rowData[16];
                 $tot_rec_cnt++;
             }
             foreach ($ex_email_arr as $key1 => $value1) {
                 $d = 0;
                 foreach ($ex_email_arr as $key2 => $value2) {
                     if ($key1 != $key2 && $value1 == $value2) {
                         $err_msg = "Duplicate email entry at row " . $key2 . ".";
                         $d++;
                         break;
                     }
                 }
                 if ($d > 0) {
                     break;
                 }
             }
             if (!empty($err_msg)) {
                 return array('status' => 'error', 'msg' => $err_msg);
             }
             //end of validations
             //start of saving
             if ($tot_rec_cnt > 0) {
                 for ($i = 2; $i <= $sizeOfWorksheet; $i++) {
                     $emp_id = $emp_identity_code . str_pad($usersModel->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
                     $rowData_org = $sheet->rangeToArray('A' . $i . ':' . $highestColumn . $i, NULL, TRUE, TRUE);
                     $rowData = $rowData_org[0];
                     $rowData_cpy = $rowData;
                     foreach ($rowData_cpy as $rkey => $rvalue) {
                         $rowData[$rkey] = trim($rvalue);
                     }
                     $emppassword = sapp_Global::generatePassword();
                     $date = new DateTime($rowData[11]);
                     $date_of_joining = $date->format('Y-m-d');
                     $date_of_leaving = "";
                     if ($rowData[12] != '') {
                         $ldate = new DateTime($rowData[12]);
                         $date_of_leaving = $ldate->format('Y-m-d');
                     }
                     $userfullname = $rowData[1] . ' ' . $rowData[2];
                     $user_data = array('emprole' => $roles_arr[strtolower($rowData[3])], 'userfullname' => $userfullname, 'firstname' => $rowData[1], 'lastname' => $rowData[2], 'emailaddress' => $rowData[4], 'jobtitle_id' => $job_arr[strtolower($rowData[8])], 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $emp_id, 'modeofentry' => "Direct", 'selecteddate' => $date_of_joining, 'userstatus' => 'old');
                     $user_data['createdby'] = $loginUserId;
                     $user_data['createddate'] = gmdate("Y-m-d H:i:s");
                     $user_data['isactive'] = 1;
                     $user_id = $usersModel->SaveorUpdateUserData($user_data, '');
                     $data = array('user_id' => $user_id, 'reporting_manager' => $users_arr[strtolower($rowData[7])], 'emp_status_id' => $emp_stat_arr[strtolower($rowData[10])], 'businessunit_id' => !empty($rowData[4]) ? $bu_arr[strtolower($rowData[5])] : 0, 'department_id' => !empty($rowData[5]) ? $dep_arr[strtolower($rowData[6])] : null, 'jobtitle_id' => $job_arr[strtolower($rowData[8])], 'position_id' => $positions_arr[strtolower($rowData[9])], 'prefix_id' => $prefix_arr[strtolower($rowData[0])], 'extension_number' => $rowData[13] != '' ? $rowData[14] : NULL, 'office_number' => $rowData[14] != '' ? $rowData[15] : NULL, 'office_faxnumber' => $rowData[15] != '' ? $rowData[16] : NULL, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'years_exp' => $rowData[13] == '' ? null : $rowData[13], 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                     $data['createdby'] = $loginUserId;
                     $data['createddate'] = gmdate("Y-m-d H:i:s");
                     $data['isactive'] = 1;
                     $emp_model->SaveorUpdateEmployeeData($data, '');
                     $text = "<div style='padding: 0; text-align: left; font-size:14px; font-family:Arial, Helvetica, sans-serif;'>\t\t\t\t\n\t<span style='color:#3b3b3b;'>Hello " . ucfirst($userfullname) . ",</span><br />\n\t\n\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>You have been added to " . APPLICATION_NAME . ". The login credentials for your Sentrifugo account are:</div>\n\t\n\t<div style='padding:20px 0 0 0;color:#3b3b3b;'>Username: <strong>" . $emp_id . "</strong></div>\n\t<div style='padding:5px 0 0 0;color:#3b3b3b;'>Password: <strong>" . $emppassword . "</strong></div>\n\t\n\t<div style='padding:20px 0 10px 0;'>Please <a href='" . DOMAIN . "index/popup' target='_blank' style='color:#b3512f;'>click here</a> to login  to your Sentrifugo account.</div>\n\n</div>";
                     $options['subject'] = APPLICATION_NAME . ': Login Credentials';
                     $options['header'] = 'Greetings from Sentrifugo';
                     $options['toEmail'] = $rowData[4];
                     $options['toName'] = $userfullname;
                     $options['message'] = $text;
                     $options['cron'] = 'yes';
                     $result = sapp_Global::_sendEmail($options);
                 }
                 //end of for loop
                 $trDb->commit();
                 return array('status' => "success", 'msg' => 'Employees saved successfully.');
             } else {
                 return array('status' => 'error', 'msg' => "No records to save.");
             }
             //end of saving
         } catch (Exception $e) {
             $trDb->rollBack();
             return array('status' => 'error', 'msg' => "Something went wrong,please try again.");
         }
     } else {
         return array('status' => 'error', 'msg' => "No records to save.");
     }
 }
 public function save($IdentityCodesform, $redirect_flag = '')
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $date = new Zend_Date();
     if ($IdentityCodesform->isValid($this->_request->getPost())) {
         $IdentityCodesModel = new Default_Model_Identitycodes();
         $id = $this->_request->getParam('id');
         $employeeCode = $this->_request->getParam('employee_code');
         $bgAgencyCode = $this->_request->getParam('bg_code');
         $vendorCode = $this->_request->getParam('vendor_code');
         $staffingCode = $this->_request->getParam('staffing_code');
         $users_code = $this->_request->getParam('users_code');
         $requisition_code = $this->_request->getParam('requisition_code');
         $data = array('employee_code' => $employeeCode, 'backgroundagency_code' => $bgAgencyCode, 'vendor_code' => $vendorCode, 'staffing_code' => $staffingCode, 'users_code' => $users_code, 'requisition_code' => $requisition_code, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
         /* Removing the codes which we are not being using for the first phase*/
         unset($data['vendor_code']);
         unset($data['staffing_code']);
         if (!sapp_Global::_isactivemodule(RESOURCEREQUISITION)) {
             unset($data['requisition_code']);
         }
         if (!sapp_Global::_isactivemodule(BGCHECKS)) {
             unset($data['backgroundagency_code']);
         }
         if ($id != '') {
             $where = array('id=?' => $id);
             $actionflag = 2;
         } else {
             $data['createdby'] = $loginUserId;
             $data['createddate'] = gmdate("Y-m-d H:i:s");
             $where = '';
             $actionflag = 1;
         }
         $Id = $IdentityCodesModel->SaveorUpdateIdentitycodesData($data, $where);
         if ($Id == 'update') {
             $tableid = $id;
             if ($redirect_flag == '') {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Identity codes updated successfully."));
             }
             $smessage = "Identity codes updated successfully.";
         } else {
             $tableid = $Id;
             if ($redirect_flag == '') {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Identity codes added successfully."));
             }
             $smessage = "Identity codes added successfully.";
         }
         $menuID = IDENTITYCODES;
         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
         if ($redirect_flag == '') {
             $this->_redirect('identitycodes');
         } else {
             return array('msg' => $smessage);
         }
     } else {
         $messages = $IdentityCodesform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
Esempio n. 5
0
 public function addemppopupAction()
 {
     $flag = 'true';
     $controllername = 'employee';
     $msgarray = array();
     $emptyFlag = 0;
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $deptidforhead = $this->_getParam('deptidforhead', null);
     $report_opt = array();
     $emp_form = new Default_Form_employee();
     $user_model = new Default_Model_Usermanagement();
     $role_model = new Default_Model_Roles();
     $prefixModel = new Default_Model_Prefix();
     $identity_code_model = new Default_Model_Identitycodes();
     $jobtitlesModel = new Default_Model_Jobtitles();
     $deptModel = new Default_Model_Departments();
     $positionsmodel = new Default_Model_Positions();
     $employeeModal = new Default_Model_Employee();
     $usersModel2 = new Default_Model_Users();
     $employmentstatusModel = new Default_Model_Employmentstatus();
     $emp_form->setAction(BASE_URL . 'employee/addemppopup/deptidforhead/' . $deptidforhead);
     $emp_form->removeElement('department_id');
     $emp_form->removeElement('modeofentry');
     $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($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
     } else {
         $emp_id = '';
         $msgarray['employeeId'] = 'Identity codes are not configured yet.';
         $flag = 'false';
     }
     $emp_form->employeeId->setValue($emp_id);
     $role_data = $role_model->getRolesList_Dept();
     $emp_form->emprole->addMultiOptions(array('' => 'Select Role') + $role_data);
     if (empty($role_data)) {
         $msgarray['emprole'] = 'Roles are not configured yet.';
         $flag = 'false';
     }
     $prefixData = $prefixModel->getPrefixList();
     $emp_form->prefix_id->addMultiOption('', 'Select Prefix');
     if (!empty($prefixData)) {
         foreach ($prefixData as $prefixres) {
             $emp_form->prefix_id->addMultiOption($prefixres['id'], $prefixres['prefix']);
         }
     } else {
         $msgarray['prefix_id'] = 'Prefixes are not configured yet.';
         //$flag = 'false';
     }
     $jobtitleData = $jobtitlesModel->getJobTitleList();
     if (!empty($jobtitleData)) {
         foreach ($jobtitleData as $jobtitleres) {
             $emp_form->jobtitle_id->addMultiOption($jobtitleres['id'], $jobtitleres['jobtitlename']);
         }
     } else {
         $msgarray['jobtitle_id'] = 'Job titles are not configured yet.';
         $msgarray['position_id'] = 'Positions are not configured yet.';
         //$flag = 'false';
     }
     if (isset($_POST['jobtitle_id']) && $_POST['jobtitle_id'] != '') {
         $positionlistArr = $positionsmodel->getPositionList($_POST['jobtitle_id']);
         if (sizeof($positionlistArr) > 0) {
             $emp_form->position_id->addMultiOption('', 'Select Position');
             foreach ($positionlistArr as $positionlistres) {
                 $emp_form->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
             }
         }
     }
     $employmentStatusData = $employmentstatusModel->getempstatusActivelist();
     $emp_form->emp_status_id->addMultiOption('', 'Select Employment Status');
     if (!empty($employmentStatusData)) {
         foreach ($employmentStatusData as $employmentStatusres) {
             $emp_form->emp_status_id->addMultiOption($employmentStatusres['workcodename'], $employmentStatusres['statusname']);
         }
     } else {
         $msgarray['emp_status_id'] = 'Employment status is not configured yet.';
         $emptyFlag++;
     }
     $reportingManagerData = $usersModel2->getReportingManagerList_employees('', '', MANAGEMENT_GROUP);
     if (!empty($reportingManagerData)) {
         $report_opt = $reportingManagerData;
         if (isset($_POST['reporting_manager']) && $_POST['reporting_manager'] != '') {
             $emp_form->setDefault('reporting_manager', $_POST['reporting_manager']);
         }
     } else {
         $msgarray['reporting_manager'] = 'Reporting managers are not added yet.';
         $flag = 'false';
     }
     if ($this->getRequest()->getPost()) {
         if ($emp_form->isValid($this->_request->getPost()) && $flag == 'true') {
             $jobtitle_id = $this->_request->getParam('jobtitle_id', null);
             $position_id = $this->_request->getParam('position_id', null);
             $date_of_joining = sapp_Global::change_date($this->_request->getParam('date_of_joining', null), 'database');
             $date_of_leaving = $this->_request->getParam('date_of_leaving', null);
             $date_of_leaving = sapp_Global::change_date($date_of_leaving, 'database');
             $employeeId = $this->_getParam('employeeId', null);
             $emprole = $this->_getParam('emprole', null);
             $reporting_manager = $this->_getParam('reporting_manager', null);
             $emailaddress = $this->_getParam('emailaddress', null);
             $emppassword = sapp_Global::generatePassword();
             $firstname = trim($this->_getParam('firstname', null));
             $lastname = trim($this->_getParam('lastname', null));
             $userfullname = $firstname . ' ' . $lastname;
             //$userfullname = trim($this->_request->getParam('userfullname',null));
             $prefix_id = $this->_getParam('prefix_id', null);
             $user_id = $this->_getParam('user_id', null);
             $emp_status_id = $this->_getParam('emp_status_id', null);
             $user_data = array('emprole' => $emprole, 'firstname' => $firstname != '' ? $firstname : NULL, 'lastname' => $lastname != '' ? $lastname : NULL, 'userfullname' => $userfullname, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'modeofentry' => 'Direct', 'selecteddate' => $date_of_joining, 'userstatus' => 'old');
             $emp_data = array('user_id' => $user_id, 'jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'department_id' => $deptidforhead, 'reporting_manager' => $reporting_manager, 'date_of_joining' => $date_of_joining, 'date_of_leaving' => $date_of_leaving != '' ? $date_of_leaving : NULL, 'emp_status_id' => $emp_status_id, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $user_data['createdby'] = $loginUserId;
             $user_data['createddate'] = gmdate("Y-m-d H:i:s");
             $user_data['isactive'] = 1;
             if ($emp_identity_code != '') {
                 $emp_id = $emp_identity_code . str_pad($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
             } else {
                 $emp_id = '';
             }
             $user_data['employeeId'] = $emp_id;
             $user_id = $user_model->SaveorUpdateUserData($user_data, '');
             $emp_data['user_id'] = $user_id;
             $emp_data['createdby'] = $loginUserId;
             $emp_data['createddate'] = gmdate("Y-m-d H:i:s");
             $emp_data['isactive'] = 1;
             $employeeModal->SaveorUpdateEmployeeData($emp_data, '');
             //end of saving into employee table.
             $tableid = $user_id;
             $actionflag = 1;
             $menuID = ORGANISATIONINFO;
             try {
                 $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             } catch (Exception $e) {
             }
             $managementUsersData = $deptModel->getDeptHeads();
             $opt = '';
             foreach ($managementUsersData as $record) {
                 $opt .= sapp_Global::selectOptionBuilder($record['id'], $record['userfullname']);
             }
             $this->view->managementUsersData = $opt;
             /* Send Mail to the user */
             $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
             $view = $this->getHelper('ViewRenderer')->view;
             $this->view->emp_name = $userfullname;
             $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 */
             $this->view->eventact = 'added';
             $close = 'close';
             $this->view->popup = $close;
         } else {
             $messages = $emp_form->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             $this->view->msgarray = $msgarray;
         }
     }
     $this->view->msgarray = $msgarray;
     $this->view->report_opt = $report_opt;
     $this->view->controllername = $controllername;
     $this->view->emp_form = $emp_form;
 }
Esempio n. 6
0
    /**
     * @name save
     *
     * This function is used to save the data that comes from add and edit actions.
     *  @author Asma
     *  @version 1.0
     */
    public function save($agencylistform)
    {
        $baseUrl = BASE_URL;
        $baseUrl = rtrim($baseUrl, '/');
        $auth = Zend_Auth::getInstance();
        if ($auth->hasIdentity()) {
            $loginUserId = $auth->getStorage()->read()->id;
        }
        $id = $this->_request->getParam('id');
        $agencyEmail = '';
        $agencyContactNum = '';
        $agencyuserid = '';
        $agencylistmodel = new Default_Model_Agencylist();
        $pocModel = new Default_Model_Bgpocdetails();
        $usersModel = new Default_Model_Users();
        $statesmodel = new Default_Model_States();
        $citiesmodel = new Default_Model_Cities();
        $pocData_1 = array();
        $pocData_2 = array();
        $pocData_3 = array();
        $contact_type_1 = $this->_request->getParam('contact_type_1');
        $contact_type_2 = $this->_request->getParam('contact_type_2');
        $contact_type_3 = $this->_request->getParam('contact_type_3');
        $checktypeModal = new Default_Model_Bgscreeningtype();
        $errorflag = "true";
        $primaryphone = $this->_request->getParam('primaryphone');
        $secondaryphone = $this->_request->getParam('secondaryphone');
        if ($primaryphone == $secondaryphone && $secondaryphone != '' && $primaryphone != '') {
            $msgarray['secondaryphone'] = 'Primary and secondary phone numbers must not be same.';
            $errorflag = 'false';
        }
        if ($agencylistform->isValid($this->_request->getPost())) {
            if ($contact_type_1 == 1 || $contact_type_2 == 1 || $contact_type_3 == 1) {
                if ($contact_type_1 == 1 && $contact_type_2 == 1 || $contact_type_1 == 1 && $contact_type_3 == 1 || $contact_type_2 == 1 && $contact_type_3 == 1 || $contact_type_1 == 1 && $contact_type_2 == 1 && $contact_type_3 == 1) {
                    $msgarray['contacttype'] = "Please set one contact type as primary.";
                    $errorflag = "false";
                }
            } else {
                $msgarray['contacttype'] = "Please set one contact type as primary.";
                $errorflag = "false";
            }
        }
        /* Check for duplicate entry of mobile and email*/
        $pocid_1 = $this->_request->getParam('pocid_1');
        $mobile_1 = $this->_request->getParam('mobile_1');
        $email_1 = $this->_request->getParam('email_1');
        if ($mobile_1 != '' && $email_1 != '') {
            $exists_M1 = $pocModel->checkMobileDuplicates($pocid_1, $mobile_1);
            if ($exists_M1) {
                $msgarray['mobile_1'] = "Mobile number already exists.";
                $errorflag = "false";
            }
            $exists_E1 = $pocModel->checkEmailDuplicates($pocid_1, $email_1);
            if ($exists_E1) {
                $msgarray['email_1'] = "Email already exists.";
                $errorflag = "false";
            }
        }
        $pocid_2 = $this->_request->getParam('pocid_2');
        $mobile_2 = $this->_request->getParam('mobile_2');
        $email_2 = $this->_request->getParam('email_2');
        if ($mobile_2 != '' && $email_2 != '') {
            $exists_M2 = $pocModel->checkMobileDuplicates($pocid_2, $mobile_2);
            if ($exists_M2) {
                $msgarray['mobile_2'] = "Mobile number already exists.";
                $errorflag = "false";
            }
            $exists_E2 = $pocModel->checkEmailDuplicates($pocid_2, $email_2);
            if ($exists_E2) {
                $msgarray['email_2'] = "Email already exists.";
                $errorflag = "false";
            }
        }
        $pocid_3 = $this->_request->getParam('pocid_3');
        $mobile_3 = $this->_request->getParam('mobile_3');
        $email_3 = $this->_request->getParam('email_3');
        if ($mobile_3 != '' && $email_3 != '') {
            $exists_M3 = $pocModel->checkMobileDuplicates($pocid_3, $mobile_3);
            if ($exists_M3) {
                $msgarray['mobile_3'] = "Mobile number already exists.";
                $errorflag = "false";
            }
            $exists_E3 = $pocModel->checkEmailDuplicates($pocid_3, $email_3);
            if ($exists_E3) {
                $msgarray['email_3'] = "Email already exists.";
                $errorflag = "false";
            }
        }
        $contact_type_1 = $this->_request->getParam('contact_type_1');
        $contact_type_2 = $this->_request->getParam('contact_type_2');
        $contact_type_3 = $this->_request->getParam('contact_type_3');
        if ($contact_type_1 == 1) {
            $agid = $id;
            $agencyEmail = $email_1;
            $agencyContactNum = $mobile_1;
            $pocuseremail = $pocModel->checkEmailInUsers($email_1, $agid);
            if (!empty($pocuseremail)) {
                $msgarray['email_1'] = "Email already exists.";
                $errorflag = "false";
            }
        } else {
            if ($contact_type_2 == 1) {
                $agencyEmail = $email_2;
                $agencyContactNum = $mobile_2;
                $pocuseremail = $pocModel->checkEmailInUsers($email_2, $agid);
                if (!empty($pocuseremail)) {
                    $msgarray['email_2'] = "Email already exists.";
                    $errorflag = "false";
                }
            } else {
                if ($contact_type_3 == 1) {
                    $agencyEmail = $email_3;
                    $agencyContactNum = $mobile_3;
                    $pocuseremail = $pocModel->checkEmailInUsers($email_3, $agid);
                    if (!empty($pocuseremail)) {
                        $msgarray['email_3'] = "Email already exists.";
                        $errorflag = "false";
                    }
                }
            }
        }
        if ($mobile_1 != '' && ($mobile_2 != '' || $mobile_3 != '')) {
            if ($mobile_2 != '' && $mobile_1 == $mobile_2) {
                $msgarray['mobile_2'] = "Contact 1 and contact 2 mobile numbers cannot be same.";
                $errorflag = "false";
            }
            if ($mobile_3 != '' && $mobile_1 == $mobile_3) {
                $msgarray['mobile_3'] = "Contact 1 and contact 3 mobile numbers cannot be same.";
                $errorflag = "false";
            }
            if ($mobile_3 != '' && $mobile_2 != '' && $mobile_2 == $mobile_3) {
                $msgarray['mobile_3'] = "Contact 2 and contact 3 mobile numbers cannot be same.";
                $errorflag = "false";
            }
        }
        if ($email_1 != '' && ($email_2 != '' || $email_3 != '')) {
            if ($email_2 != '' && $email_1 == $email_2) {
                $msgarray['email_2'] = "Contact 1 and contact 2 emails cannot be same.";
                $errorflag = "false";
            }
            if ($email_3 != '' && $email_1 == $email_3) {
                $msgarray['email_3'] = "Contact 1 and contact 3 emails cannot be same.";
                $errorflag = "false";
            }
            if ($email_3 != '' && $email_2 != '' && $email_2 == $email_3) {
                $msgarray['email_3'] = "Contact 2 and contact 3 emails cannot be same.";
                $errorflag = "false";
            }
        }
        /* Duplicate check END */
        $country_1 = $this->_request->getParam('country_1');
        $state_1 = intVal($this->_request->getParam('state_1'));
        $city_1 = intVal($this->_request->getParam('city_1'));
        if (isset($country_1) && $country_1 != 0 && $country_1 != '') {
            $statesData = $statesmodel->getStatesList($country_1);
            foreach ($statesData as $res) {
                $agencylistform->state_1->addMultiOption($res['id'], utf8_encode($res['state_name']));
            }
            if (isset($state_1) && $state_1 != 0 && $state_1 != '') {
                $agencylistform->setDefault('state_1', $state_1);
            }
        }
        if (isset($state_1) && $state_1 != 0 && $state_1 != '') {
            $citiesData = $citiesmodel->getCitiesList($state_1);
            foreach ($citiesData as $res) {
                $agencylistform->city_1->addMultiOption($res['id'], utf8_encode($res['city_name']));
            }
            if (isset($city_1) && $city_1 != 0 && $city_1 != '') {
                $agencylistform->setDefault('city_1', $city_1);
            }
        }
        $country_2 = $this->_request->getParam('country_2');
        $state_2 = intVal($this->_request->getParam('state_2'));
        $city_2 = intVal($this->_request->getParam('city_2'));
        if (isset($country_2) && $country_2 != 0 && $country_2 != '') {
            $statesData = $statesmodel->getStatesList($country_2);
            foreach ($statesData as $res) {
                $agencylistform->state_2->addMultiOption($res['id'], utf8_encode($res['state_name']));
            }
            if (isset($state_2) && $state_2 != 0 && $state_2 != '') {
                $agencylistform->setDefault('state_2', $state_2);
            }
        }
        if (isset($state_2) && $state_2 != 0 && $state_2 != '') {
            $citiesData = $citiesmodel->getCitiesList($state_2);
            foreach ($citiesData as $res) {
                $agencylistform->city_2->addMultiOption($res['id'], utf8_encode($res['city_name']));
            }
            if (isset($city_2) && $city_2 != 0 && $city_2 != '') {
                $agencylistform->setDefault('city_2', $city_2);
            }
        }
        $country_3 = $this->_request->getParam('country_3');
        $state_3 = intVal($this->_request->getParam('state_3'));
        $city_3 = intVal($this->_request->getParam('city_3'));
        if (isset($country_3) && $country_3 != 0 && $country_3 != '') {
            $statesData = $statesmodel->getStatesList($country_3);
            foreach ($statesData as $res) {
                $agencylistform->state_3->addMultiOption($res['id'], utf8_encode($res['state_name']));
            }
            if (isset($state_3) && $state_3 != 0 && $state_3 != '') {
                $agencylistform->setDefault('state_3', $state_3);
            }
        }
        if (isset($state_3) && $state_3 != 0 && $state_3 != '') {
            $citiesData = $citiesmodel->getCitiesList($state_3);
            foreach ($citiesData as $res) {
                $agencylistform->city_3->addMultiOption($res['id'], utf8_encode($res['city_name']));
            }
            if (isset($city_3) && $city_3 != 0 && $city_3 != '') {
                $agencylistform->setDefault('city_3', $city_3);
            }
        }
        $typesData = $checktypeModal->fetchAll('isactive=1', 'type')->toArray();
        if (!empty($typesData)) {
            $this->view->configure = '';
        } else {
            $msgarray['bg_checktype'] = 'Screening types are not configured yet.';
            $errorflag = 'false';
            $this->view->configure = 'notconfigured';
        }
        $rolesData = $agencylistmodel->getagencyrole();
        if (!empty($rolesData)) {
            $this->view->rolesconfigure = '';
        } else {
            $msgarray['emprole'] = 'Roles are not configured yet.';
            $errorflag = 'false';
            $this->view->rolesconfigure = 'notconfigured';
        }
        /* Email address validation */
        $email_1 = $this->_request->getParam('email_1');
        $isvalidemail = filter_var($email_1, FILTER_VALIDATE_EMAIL);
        if ($email_1 == $isvalidemail) {
        } else {
            $msgarray['email_1'] = "Please enter valid email.";
            $errorflag = "false";
        }
        $email_2 = $this->_request->getParam('email_2');
        if ($email_2 != '') {
            $isvalidemail = filter_var($email_2, FILTER_VALIDATE_EMAIL);
            if ($email_2 == $isvalidemail) {
            } else {
                $msgarray['email_2'] = "Please enter valid email.";
                $errorflag = "false";
            }
        }
        $email_3 = $this->_request->getParam('email_3');
        if ($email_3 != '') {
            $isvalidemail = filter_var($email_3, FILTER_VALIDATE_EMAIL);
            if ($email_3 == $isvalidemail) {
            } else {
                $msgarray['email_3'] = "Please enter valid email.";
                $errorflag = "false";
            }
        }
        /* Email address validation END	 */
        /* Website validation */
        $id = $this->_request->getParam('id');
        $website_url = $this->_request->getParam('website_url');
        $websiteExistance = $agencylistmodel->checkSiteDuplicates($website_url, $id);
        if (!empty($websiteExistance)) {
            $eid = isset($websiteExistance['employeeId']) ? $websiteExistance['employeeId'] : 'An agency';
            if ($websiteExistance['isactive'] == '1') {
                $msgarray['website_url'] = $eid . " with the given website URL already exists.";
            } else {
                $msgarray['website_url'] = $eid . " with the given website URL already exists but it might be inactive. Please activate it from manage external users.";
            }
            $errorflag = "false";
        }
        /* Website validation END */
        if ($agencylistform->isValid($this->_request->getPost()) && $errorflag != 'false') {
            $agencyname = $this->_request->getParam('agencyname');
            $address = $this->_request->getParam('address');
            $primaryphone = $this->_request->getParam('primaryphone');
            $secondaryphone = $this->_request->getParam('secondaryphone');
            $bg_checktype = $this->_request->getParam('bg_checktype');
            $bg_checktype = implode(',', $bg_checktype);
            $website_url = $this->_request->getParam('website_url');
            $pocid_1 = $this->_request->getParam('pocid_1');
            $firstname_1 = $this->_request->getParam('firstname_1');
            $lastname_1 = $this->_request->getParam('lastname_1');
            $mobile_1 = $this->_request->getParam('mobile_1');
            $email_1 = $this->_request->getParam('email_1');
            $location_1 = $this->_request->getParam('location_1');
            $country_1 = $this->_request->getParam('country_1');
            $state_1 = $this->_request->getParam('state_1');
            $city_1 = $this->_request->getParam('city_1');
            $contact_type_1 = $this->_request->getParam('contact_type_1');
            $pocid_2 = $this->_request->getParam('pocid_2');
            $firstname_2 = $this->_request->getParam('firstname_2');
            $lastname_2 = $this->_request->getParam('lastname_2');
            $mobile_2 = $this->_request->getParam('mobile_2');
            $email_2 = $this->_request->getParam('email_2');
            $location_2 = $this->_request->getParam('location_2');
            $country_2 = $this->_request->getParam('country_2');
            $state_2 = $this->_request->getParam('state_2');
            $city_2 = $this->_request->getParam('city_2');
            $contact_type_2 = $this->_request->getParam('contact_type_2');
            $pocid_3 = $this->_request->getParam('pocid_3');
            $firstname_3 = $this->_request->getParam('firstname_3');
            $lastname_3 = $this->_request->getParam('lastname_3');
            $mobile_3 = $this->_request->getParam('mobile_3');
            $email_3 = $this->_request->getParam('email_3');
            $location_3 = $this->_request->getParam('location_3');
            $country_3 = $this->_request->getParam('country_3');
            $state_3 = $this->_request->getParam('state_3');
            $city_3 = $this->_request->getParam('city_3');
            $contact_type_3 = $this->_request->getParam('contact_type_3');
            $emprole = $this->_request->getParam('emprole');
            if (empty($websiteExistance)) {
                $date = new Zend_Date();
                if ($contact_type_1 == 1) {
                    $agencyEmail = $email_1;
                    $agencyContactNum = $mobile_1;
                    $pocfn = $firstname_1;
                    $pocln = $lastname_1;
                } else {
                    if ($contact_type_2 == 1) {
                        $agencyEmail = $email_2;
                        $agencyContactNum = $mobile_2;
                        $pocfn = $firstname_2;
                        $pocln = $lastname_2;
                    } else {
                        if ($contact_type_3 == 1) {
                            $agencyEmail = $email_3;
                            $agencyContactNum = $mobile_3;
                            $pocfn = $firstname_3;
                            $pocln = $lastname_3;
                        }
                    }
                }
                $primary_poc_name = ucfirst($pocfn);
                /* Create user for the agency */
                if ($id == '') {
                    $pswd = uniqid();
                    $userdata = array('emprole' => $emprole, 'userstatus' => 'old', 'firstname' => $firstname_1, 'lastname' => $lastname_1, 'userfullname' => $firstname_1 . ' ' . $lastname_1, 'emailaddress' => $agencyEmail, 'contactnumber' => $agencyContactNum, 'emppassword' => md5($pswd), 'isactive' => 1, 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $userWhere = '';
                    $usersModel = new Default_Model_Users();
                    $usersTableId = $usersModel->addOrUpdateUserModel($userdata, $userWhere);
                    $agencyuserid = $usersTableId;
                    $idcodeModel = new Default_Model_Identitycodes();
                    $idcode = $idcodeModel->getallcodes('bgcheck');
                    $userdata = array('employeeId' => $idcode . $usersTableId, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $userWhere = array('id=?' => $usersTableId);
                    $usersTableId = $usersModel->addOrUpdateUserModel($userdata, $userWhere);
                    $options['subject'] = APPLICATION_NAME . ' :: Agency is created';
                    $options['header'] = 'Greetings from ' . APPLICATION_NAME;
                    $options['toEmail'] = $agencyEmail;
                    $options['toName'] = $pocfn . ' ' . $pocln;
                    $options['message'] = '<div>Dear ' . $pocfn . ',</div>
											<div>' . ucfirst($agencyname) . ' agency has been created. The credentials to login to your ' . APPLICATION_NAME . ' account are:
												<div>Login ID : ' . $idcode . $agencyuserid . ' </div>
												<div>Password : '******'</div>
												<div></div>											
												<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the agency details.</div>
											</div>';
                    $result = sapp_Global::_sendEmail($options);
                    $emailids = $agencylistmodel->getAllHRManagementEMails();
                    foreach ($emailids as $email) {
                        $options['subject'] = APPLICATION_NAME . ' :: Agency is created';
                        $options['header'] = 'Agency created';
                        $options['toEmail'] = $email['groupEmail'];
                        $options['toName'] = $email['group_name'];
                        if ($email['group_id'] == 4) {
                            $salutation = 'Dear HR,';
                            $options['toName'] = 'HR';
                        } else {
                            $salutation = 'Dear Management,';
                            $options['toName'] = 'Management';
                        }
                        $options['message'] = '<div>
													<div>' . $salutation . ' </div>
													<div></div>	
													' . ucfirst($agencyname) . ' agency has been created with ' . $pocfn . ' ' . $pocln . ' as primary point of contact.
													<div></div>											
													<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the agency details.</div>
												</div>';
                        $options['cron'] = 'yes';
                        $result = sapp_Global::_sendEmail($options);
                    }
                } else {
                    $agencyInfo = $agencylistmodel->getSingleagencyPOCData($id);
                    $userid = $agencyInfo[0]['user_id'];
                    $agencyoldname = $agencyInfo[0]['agencyname'];
                    $userdata = array('emprole' => $emprole, 'userfullname' => $agencyname, 'emailaddress' => $agencyEmail, 'contactnumber' => $agencyContactNum, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    $userWhere = array('id=?' => $userid);
                    $usersModel->addOrUpdateUserModel($userdata, $userWhere);
                    if ($agencyoldname != $agencyname) {
                        $agencynamemsg = '<div>Hello ' . ucfirst($primary_poc_name) . ',</div><div>Your agency name is changed to ' . ucfirst($agencyname) . '.</div>';
                    } else {
                        $agencynamemsg = '<div>Hello ' . ucfirst($primary_poc_name) . ',</div><div>Your agency information has been modified. Please find the details below:</div>';
                    }
                    $options['subject'] = APPLICATION_NAME . ' :: Agency details are updated';
                    $options['header'] = 'Agency information';
                    $options['toEmail'] = $agencyEmail;
                    $options['toName'] = $pocfn . ' ' . $pocln;
                    $options['message'] = '<div>' . $agencynamemsg . '
											<div><table border="1" style="border-collapse:collapse;"><tr><td>Primary email</td><td>' . $agencyEmail . '</td></tr><tr><td>Primary Contact Number</td><td>' . $agencyContactNum . '</td></tr></table></div>
											<div style="padding:20px 0 10px 0;">Please <a href="' . $baseUrl . '/index/popup" target="_blank" style="color:#b3512f;">click here</a> to login and check the agency details.
											</div>
											</div>';
                    $options['cron'] = 'yes';
                    $result = sapp_Global::_sendEmail($options);
                }
                $actionflag = '';
                $tableid = '';
                $data = array('user_id' => $agencyuserid, 'agencyname' => $agencyname, 'address' => $address, 'primaryphone' => $primaryphone, 'secondaryphone' => $secondaryphone, 'bg_checktype' => $bg_checktype, 'website_url' => $website_url, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                if ($id != '') {
                    unset($data['user_id']);
                    $where = array('id=?' => $id);
                    $actionflag = 2;
                } else {
                    $data['createdby'] = $loginUserId;
                    $data['createddate'] = gmdate("Y-m-d H:i:s");
                    $data['isactive'] = 1;
                    $where = '';
                    $actionflag = 1;
                }
                $agencyId = $agencylistmodel->SaveorUpdateAgency($data, $where);
                if ($agencyId == 'update') {
                    $tableid = $id;
                } else {
                    $tableid = $agencyId;
                }
                $menuID = AGENCYLIST;
                $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
                if ($firstname_1 != '' && $mobile_1 != '') {
                    $pocData_1 = array('bg_agencyid' => $tableid, 'first_name' => $firstname_1, 'last_name' => $lastname_1, 'contact_no' => $mobile_1, 'email' => $email_1, 'location' => $location_1, 'country' => $country_1, 'state' => $state_1, 'city' => $city_1, 'contact_type' => $contact_type_1, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    if ($pocid_1 != '') {
                        $pocWhere_1 = array('id=?' => $pocid_1);
                        $actionflag = 2;
                    } else {
                        $pocData_1['createdby'] = $loginUserId;
                        $pocData_1['createddate'] = gmdate("Y-m-d H:i:s");
                        $pocData_1['isactive'] = 1;
                        $pocWhere_1 = '';
                        $actionflag = 1;
                    }
                    $savedpocId_1 = $pocModel->SaveorUpdatePOCDetails($pocData_1, $pocWhere_1);
                    if ($savedpocId_1 == 'update') {
                        $newpocid_1 = $pocid_1;
                    } else {
                        $newpocid_1 = $savedpocId_1;
                    }
                }
                if ($firstname_2 != '' && $mobile_2 != '') {
                    $pocData_2 = array('bg_agencyid' => $tableid, 'first_name' => $firstname_2, 'last_name' => $lastname_2, 'contact_no' => $mobile_2, 'email' => $email_2, 'location' => $location_2, 'country' => $country_2, 'state' => $state_2, 'city' => $city_2, 'contact_type' => $contact_type_2, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    if ($pocid_2 != '') {
                        $pocWhere_2 = array('id=?' => $pocid_2);
                        $actionflag = 2;
                    } else {
                        $pocData_2['createdby'] = $loginUserId;
                        $pocData_2['createddate'] = gmdate("Y-m-d H:i:s");
                        $pocData_2['isactive'] = 1;
                        $pocWhere_2 = '';
                        $actionflag = 1;
                    }
                    $savedpocId_2 = $pocModel->SaveorUpdatePOCDetails($pocData_2, $pocWhere_2);
                    if ($savedpocId_2 == 'update') {
                        $newpocid_2 = $pocid_2;
                    } else {
                        $newpocid_2 = $savedpocId_2;
                    }
                }
                if ($firstname_3 != '' && $mobile_3 != '') {
                    $pocData_3 = array('bg_agencyid' => $tableid, 'first_name' => $firstname_3, 'last_name' => $lastname_3, 'contact_no' => $mobile_3, 'email' => $email_3, 'location' => $location_3, 'country' => $country_3, 'state' => $state_3, 'city' => $city_3, 'contact_type' => $contact_type_3, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                    if ($pocid_3 != '') {
                        $pocWhere_3 = array('id=?' => $pocid_3);
                        $actionflag = 2;
                    } else {
                        $pocData_3['createdby'] = $loginUserId;
                        $pocData_3['createddate'] = gmdate("Y-m-d H:i:s");
                        $pocData_3['isactive'] = 1;
                        $pocWhere_3 = '';
                        $actionflag = 1;
                    }
                    $savedpocId_3 = $pocModel->SaveorUpdatePOCDetails($pocData_3, $pocWhere_3);
                    if ($savedpocId_3 == 'update') {
                        $newpocid_3 = $pocid_3;
                    } else {
                        $newpocid_3 = $savedpocId_3;
                    }
                }
                if ($agencyId == 'update') {
                    $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Agency data updated successfully."));
                } else {
                    $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Agency data added successfully."));
                }
                $this->_redirect('agencylist');
            } else {
                $msgarray['message'] = 'An Agency, with the given website address, already exists.';
                $msgarray['msgtype'] = 'error';
                return $msgarray;
            }
        } else {
            $messages = $agencylistform->getMessages();
            if (isset($msgarray['mobile_1']) && !isset($messages['mobile_1'])) {
                $messages['mobile_1'] = $msgarray['mobile_1'];
            }
            if (isset($msgarray['email_1']) && !isset($messages['email_1'])) {
                $messages['email_1'] = $msgarray['email_1'];
            }
            if (isset($msgarray['mobile_2']) && !isset($messages['mobile_2'])) {
                $messages['mobile_2'] = $msgarray['mobile_2'];
            }
            if (isset($msgarray['email_2']) && !isset($messages['email_2'])) {
                $messages['email_2'] = $msgarray['email_2'];
            }
            if (isset($msgarray['mobile_3']) && !isset($messages['mobile_3'])) {
                $messages['mobile_3'] = $msgarray['mobile_3'];
            }
            if (isset($msgarray['email_3']) && !isset($messages['email_3'])) {
                $messages['email_3'] = $msgarray['email_3'];
            }
            $i = 0;
            $msgarray['error1dv'] = '';
            $msgarray['error2dv'] = '';
            $msgarray['error3dv'] = '';
            foreach ($messages as $key => $val) {
                if (strpos($key, '_1') !== false) {
                    $msgarray['error1dv'] = 'first';
                }
                if (strpos($key, '_2') !== false) {
                    $msgarray['error2dv'] = 'second';
                }
                if (strpos($key, '_3') !== false) {
                    $msgarray['error3dv'] = 'third';
                }
                if (!isset($msgarray[$key])) {
                    foreach ($val as $key2 => $val2) {
                        $msgarray[$key] = $val2;
                        break;
                    }
                }
                $i = $i + 1;
                if (empty($typesData)) {
                    $msgarray['bg_checktype'] = 'Screening types are not configured yet.';
                }
                if (empty($rolesData)) {
                    $msgarray['emprole'] = 'Roles are not configured yet.';
                }
            }
            return $msgarray;
        }
    }
 public function save($requisitionform, $data)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $requi_model = new Default_Model_Requisition();
     $user_model = new Default_Model_Usermanagement();
     $jobtitleModel = new Default_Model_Jobtitles();
     $appr_mail = '';
     $appr_per = '';
     if ($requisitionform->isValid($this->_request->getPost())) {
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             $id = (int) $this->_getParam('id', null);
             $requisition_code = $this->_getParam('requisition_code', null);
             $onboard_date = $this->_getParam('onboard_date', null);
             $business_unit = $this->_getParam('business_unit', null);
             $department = $this->_getParam('department', null);
             $jobtitle = $this->_getParam('jobtitle', null);
             $position_id = $this->_getParam('position_id', null);
             $reporting_id = $this->_getParam('reporting_id', null);
             $req_no_positions = $this->_getParam('req_no_positions', null);
             $jobdescription = $this->_getParam('jobdescription', null);
             $req_skills = $this->_getParam('req_skills', null);
             $req_qualification = $this->_getParam('req_qualification', null);
             $req_exp_years = $this->_getParam('req_exp_years', null);
             $emp_type = $this->_getParam('emp_type', null);
             $req_priority = $this->_getParam('req_priority', null);
             $additional_info = $this->_getParam('additional_info', null);
             $req_status = $this->_getParam('req_status', null);
             $approver1 = $this->_getParam('approver1', null);
             $approver2 = $this->_getParam('approver2', null);
             $approver3 = $this->_getParam('approver3', null);
             $aflag = $this->_getParam('aflag', null);
             $edit_flag = $this->_getParam('edit_flag', null);
             $edit_order = $this->_getParam('edit_order', null);
             $aorder = $this->_getParam('aorder', null);
             //1= approver1,2=approver2,3=approver3
             if ($aflag != '' && $aflag == 'approver') {
                 if ($req_status == 3) {
                     $data = array('modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'appstatus' . $aorder => $req_status, 'req_status' => $req_status);
                 } else {
                     if ($aorder == 1) {
                         if ($approver2 != '') {
                             $data = array('appstatus1' => $req_status, 'appstatus2' => 'Initiated');
                             $appr_mail = $approver2;
                             $appr_per = $approver1;
                         } else {
                             $data = array('appstatus1' => $req_status, 'req_status' => $req_status);
                             $appr_mail = 'approved';
                         }
                     } else {
                         if ($aorder == 2) {
                             if ($approver3 != '') {
                                 $data = array('appstatus2' => $req_status, 'appstatus3' => 'Initiated');
                                 $appr_mail = $approver3;
                                 $appr_per = $approver2;
                             } else {
                                 $data = array('appstatus2' => $req_status, 'req_status' => $req_status);
                                 $appr_mail = 'approved';
                             }
                         } else {
                             if ($aorder == 3) {
                                 $data = array('appstatus3' => $req_status, 'req_status' => $req_status);
                                 $appr_mail = 'approved';
                             }
                         }
                     }
                     $data['modifiedby'] = trim($loginUserId);
                     $data['modifiedon'] = gmdate("Y-m-d H:i:s");
                 }
             } else {
                 $data = array('requisition_code' => trim($requisition_code), 'onboard_date' => sapp_Global::change_date(trim($onboard_date), 'database'), 'position_id' => trim($position_id), 'reporting_id' => trim($reporting_id), 'businessunit_id' => trim($business_unit), 'department_id' => trim($department), 'req_no_positions' => trim($req_no_positions), 'jobdescription' => trim($jobdescription), 'jobtitle' => trim($jobtitle), 'req_skills' => trim($req_skills), 'req_qualification' => trim($req_qualification), 'req_exp_years' => trim($req_exp_years), 'emp_type' => trim($emp_type), 'req_priority' => trim($req_priority), 'additional_info' => trim($additional_info), 'approver1' => $approver1, 'approver2' => $approver2 == '' ? null : $approver2, 'approver3' => $approver3 == '' ? null : $approver3, 'req_status' => 'Initiated', 'appstatus1' => 'Initiated', 'appstatus2' => null, 'appstatus3' => null, 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createdon' => gmdate("Y-m-d H:i:s"), 'modifiedon' => gmdate("Y-m-d H:i:s"));
                 if ($loginuserGroup == MANAGER_GROUP) {
                     $data['reporting_id'] = $loginUserId;
                 }
                 if ($edit_flag != '' && $edit_flag == 'yes') {
                     if ($edit_order == 1) {
                         $data = array('modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'approver2' => $approver2 == '' ? null : $approver2, 'approver3' => $approver3 == '' ? null : $approver3, 'appstatus2' => 'Initiated');
                         if ($approver2 == '') {
                             $data['appstatus2'] = null;
                         } else {
                             $appr_per = $edit_order;
                             $appr_mail = $approver2;
                         }
                     }
                     if ($edit_order == 2) {
                         $data = array('modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'approver3' => $approver3 == '' ? null : $approver3, 'appstatus3' => 'Initiated');
                         if ($approver3 == '') {
                             $data['appstatus3'] = null;
                         } else {
                             $appr_per = $edit_order;
                             $appr_mail = $approver3;
                         }
                     }
                 }
             }
             $where = "";
             $actionflag = 1;
             //for mailing
             if ($id == '') {
                 //for requisition code
                 $identity_code_model = new Default_Model_Identitycodes();
                 $identity_codes = $identity_code_model->getIdentitycodesRecord();
                 $irequistion_code = isset($identity_codes[0]) ? $identity_codes[0]['requisition_code'] : "";
                 if ($irequistion_code != '') {
                     $req_id = $requi_model->getMaxReqCode($irequistion_code . "/");
                 } else {
                     $req_id = '';
                 }
                 $data['requisition_code'] = $req_id;
                 //end of requisition code
                 $report_person_data = $user_model->getUserDataById($data['reporting_id']);
                 $approver1_person_data = $user_model->getUserDataById($approver1);
                 $Raisedby_person_data = $user_model->getUserDataById($data['createdby']);
                 $jobttlArr = $jobtitleModel->getsingleJobTitleData(trim($jobtitle));
                 if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                     $jobtitlename = ' - ' . $jobttlArr[0]['jobtitlename'];
                 } else {
                     $jobtitlename = '';
                 }
                 $mail_arr[0]['name'] = 'HR';
                 $mail_arr[0]['email'] = defined('REQ_HR_' . $business_unit) ? constant('REQ_HR_' . $business_unit) : "";
                 $mail_arr[0]['type'] = 'HR';
                 $mail_arr[1]['name'] = 'Management';
                 $mail_arr[1]['email'] = defined('REQ_MGMT_' . $business_unit) ? constant('REQ_MGMT_' . $business_unit) : "";
                 $mail_arr[1]['type'] = 'Management';
                 $mail_arr[2]['name'] = $Raisedby_person_data['userfullname'];
                 $mail_arr[2]['email'] = $Raisedby_person_data['emailaddress'];
                 $mail_arr[2]['type'] = 'Raise';
                 $mail_arr[3]['name'] = $approver1_person_data['userfullname'];
                 $mail_arr[3]['email'] = $approver1_person_data['emailaddress'];
                 $mail_arr[3]['type'] = 'Approver';
                 $appr_str = "";
                 $appr_str = $approver1_person_data['userfullname'];
                 if ($data['approver2'] != '') {
                     $approver2_person_data = $user_model->getUserDataById($data['approver2']);
                     $appr_str .= ", " . $approver2_person_data['userfullname'];
                     $mail_arr[4]['name'] = $approver2_person_data['userfullname'];
                     $mail_arr[4]['email'] = $approver2_person_data['emailaddress'];
                     $mail_arr[4]['type'] = 'Approver';
                 }
                 if ($data['approver3'] != '') {
                     $approver3_person_data = $user_model->getUserDataById($data['approver3']);
                     $appr_str .= " and " . $approver3_person_data['userfullname'];
                     $mail_arr[5]['name'] = $approver3_person_data['userfullname'];
                     $mail_arr[5]['email'] = $approver3_person_data['emailaddress'];
                     $mail_arr[5]['type'] = 'Approver';
                 }
                 for ($ii = 0; $ii < count($mail_arr); $ii++) {
                     $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                     $view = $this->getHelper('ViewRenderer')->view;
                     $this->view->emp_name = $mail_arr[$ii]['name'];
                     $this->view->base_url = $base_url;
                     $this->view->type = $mail_arr[$ii]['type'];
                     $this->view->jobtitle = $jobtitlename;
                     $this->view->requisition_code = $requisition_code;
                     $this->view->approver_str = $appr_str;
                     $this->view->raised_name = $Raisedby_person_data['userfullname'];
                     $text = $view->render('mailtemplates/requisition.phtml');
                     $options['subject'] = APPLICATION_NAME . ': Requisition for approval';
                     $options['header'] = 'Requisition Status';
                     $options['toEmail'] = $mail_arr[$ii]['email'];
                     $options['toName'] = $mail_arr[$ii]['name'];
                     $options['message'] = $text;
                     $options['cron'] = 'yes';
                     if ($options['toEmail'] != '') {
                         sapp_Global::_sendEmail($options);
                     }
                 }
             }
             if ($id != '') {
                 unset($data['createdby']);
                 unset($data['createdon']);
                 unset($data['isactive']);
                 $where = "id = " . $id;
                 $tableid = $id;
                 $actionflag = 2;
             }
             $result = $requi_model->SaveorUpdateRequisitionData($data, $where);
             if ($id == '') {
                 $tableid = $result;
             }
             if ($result != '') {
                 if ($actionflag == 2) {
                     //start of mailing
                     $requisition_data = $requi_model->getRequisitionDataById($id);
                     $report_person_data = $user_model->getUserDataById($requisition_data['reporting_id']);
                     $st_arr = array('0' => 'Select status', '2' => 'Approved', '3' => 'Rejected');
                     if ($req_status == 3 || $appr_mail == 'approved') {
                         $approver1_person_data = $user_model->getUserDataById($requisition_data['approver1']);
                         $Raisedby_person_data = $user_model->getUserDataById($requisition_data['createdby']);
                         $jobttlArr = $jobtitleModel->getsingleJobTitleData(trim($requisition_data['jobtitle']));
                         if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                             $jobtitlename = ' - ' . $jobttlArr[0]['jobtitlename'];
                         } else {
                             $jobtitlename = '';
                         }
                         $mail_arr[0]['name'] = 'HR';
                         $mail_arr[0]['email'] = defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "";
                         $mail_arr[0]['type'] = 'HR';
                         $mail_arr[1]['name'] = 'Management';
                         $mail_arr[1]['email'] = defined('REQ_MGMT_' . $requisition_data['businessunit_id']) ? constant('REQ_MGMT_' . $requisition_data['businessunit_id']) : "";
                         $mail_arr[1]['type'] = 'Management';
                         $mail_arr[2]['name'] = $Raisedby_person_data['userfullname'];
                         $mail_arr[2]['email'] = $Raisedby_person_data['emailaddress'];
                         $mail_arr[2]['type'] = 'Raise';
                         $mail_arr[3]['name'] = $approver1_person_data['userfullname'];
                         $mail_arr[3]['email'] = $approver1_person_data['emailaddress'];
                         $mail_arr[3]['type'] = 'Approver';
                         // Check if the reporting person and raised person are same - Requisition raised by Manager case
                         if ($requisition_data['reporting_id'] != $requisition_data['createdby']) {
                             $mail_arr[4]['name'] = $report_person_data['userfullname'];
                             $mail_arr[4]['email'] = $report_person_data['emailaddress'];
                             $mail_arr[4]['type'] = 'Report';
                         }
                         $appr_str = "";
                         $appr_str = $approver1_person_data['userfullname'];
                         if ($requisition_data['approver2'] != '') {
                             $approver2_person_data = $user_model->getUserDataById($requisition_data['approver2']);
                             $appr_str .= ", " . $approver2_person_data['userfullname'];
                             $mail_arr[5]['name'] = $approver2_person_data['userfullname'];
                             $mail_arr[5]['email'] = $approver2_person_data['emailaddress'];
                             $mail_arr[5]['type'] = 'Approver';
                         }
                         if ($requisition_data['approver3'] != '') {
                             $approver3_person_data = $user_model->getUserDataById($requisition_data['approver3']);
                             $appr_str .= " and " . $approver3_person_data['userfullname'];
                             $mail_arr[6]['name'] = $approver3_person_data['userfullname'];
                             $mail_arr[6]['email'] = $approver3_person_data['emailaddress'];
                             $mail_arr[6]['type'] = 'Approver';
                         }
                         $mail = array();
                         for ($ii = 0; $ii < count($mail_arr); $ii++) {
                             $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                             $view = $this->getHelper('ViewRenderer')->view;
                             $this->view->emp_name = !empty($mail_arr[$ii]['name']) ? $mail_arr[$ii]['name'] : '';
                             $this->view->base_url = $base_url;
                             $this->view->type = !empty($mail_arr[$ii]['type']) ? $mail_arr[$ii]['type'] : '';
                             $this->view->jobtitle = $jobtitlename;
                             $this->view->requisition_code = $requisition_data['requisition_code'];
                             $this->view->approver_str = $appr_str;
                             $this->view->raised_name = $Raisedby_person_data['userfullname'];
                             $this->view->req_status = $st_arr[$req_status];
                             $this->view->reporting_manager = $report_person_data['userfullname'];
                             $text = $view->render('mailtemplates/changedrequisition.phtml');
                             $options['subject'] = $st_arr[$req_status] == 'approved' ? APPLICATION_NAME . ': Requisition is approved' : APPLICATION_NAME . ': Requisition is rejected';
                             $options['header'] = 'Requisition Status';
                             $options['toEmail'] = !empty($mail_arr[$ii]['email']) ? $mail_arr[$ii]['email'] : '';
                             $options['toName'] = !empty($mail_arr[$ii]['name']) ? $mail_arr[$ii]['name'] : '';
                             $options['message'] = $text;
                             $mail[$ii] = $options;
                             $options['cron'] = 'yes';
                             if ($options['toEmail'] != '') {
                                 sapp_Global::_sendEmail($options);
                             }
                         }
                     } else {
                         if ($req_status == 2) {
                             $approver_person_data = $user_model->getUserDataById($appr_mail);
                             $mail_arr[0]['name'] = $approver_person_data['userfullname'];
                             $mail_arr[0]['email'] = $approver_person_data['emailaddress'];
                             $mail_arr[0]['type'] = 'Approver';
                             if ($edit_flag == 'yes') {
                                 $approved_by_data = $user_model->getUserDataById($requisition_data['approver' . $appr_per]);
                                 $req_status = 2;
                             } else {
                                 $approved_by_data = $user_model->getUserDataById($appr_per);
                             }
                             $Raisedby_person_data = $user_model->getUserDataById($requisition_data['createdby']);
                             $appr_str = $approved_by_data['userfullname'];
                             for ($ii = 0; $ii < count($mail_arr); $ii++) {
                                 $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                                 $view = $this->getHelper('ViewRenderer')->view;
                                 $this->view->emp_name = $mail_arr[$ii]['name'];
                                 $this->view->base_url = $base_url;
                                 $this->view->type = $mail_arr[$ii]['type'];
                                 $this->view->requisition_code = $requisition_data['requisition_code'];
                                 $this->view->req_status = $st_arr[$req_status];
                                 $this->view->raised_name = $Raisedby_person_data['userfullname'];
                                 $this->view->approver_str = $appr_str;
                                 $text = $view->render('mailtemplates/changedrequisition.phtml');
                                 $options['subject'] = $st_arr[$req_status] == 'approved' ? APPLICATION_NAME . ': Requisition is approved' : APPLICATION_NAME . ': Requisition is rejected';
                                 $options['header'] = 'Requisition Status';
                                 $options['toEmail'] = $mail_arr[$ii]['email'];
                                 $options['toName'] = $mail_arr[$ii]['name'];
                                 $options['message'] = $text;
                                 $options['cron'] = 'yes';
                                 if ($options['toEmail'] != '') {
                                     sapp_Global::_sendEmail($options);
                                 }
                             }
                         }
                     }
                     //end of mailing
                 }
                 $menumodel = new Default_Model_Menu();
                 $objidArr = $menumodel->getMenuObjID('/requisition');
                 $objID = $objidArr[0]['id'];
                 $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
                 if ($id != '') {
                     $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Resource requisition updated successfully."));
                 } else {
                     $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Resource requisition added successfully."));
                 }
                 $trDb->commit();
                 $this->_redirect('/requisition');
             }
         } catch (Exception $e) {
             $trDb->rollBack();
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Something went wrong, please try again later."));
             $this->_redirect('/requisition');
         }
     } else {
         $messages = $requisitionform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 /**
  * 
  * @param type $requisitionform
  * @param type $data
  * @return type
  */
 public function save($requisitionform, $data)
 {
     $ipreporting_id = "";
     $technicalskill_id = "";
     $nontechnicalskill_id = "";
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $requi_model = new Default_Model_Requisition();
     $user_model = new Default_Model_Usermanagement();
     $jobtitleModel = new Default_Model_Jobtitles();
     $appr_mail = '';
     $appr_per = '';
     if ($requisitionform->isValid($this->_request->getPost())) {
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             $id = (int) $this->_getParam('id', null);
             $requisition_code = $this->_getParam('requisition_code', null);
             $onboard_date = $this->_getParam('onboard_date', null);
             $business_unit = $this->_getParam('business_unit', null);
             $department = $this->_getParam('department', null);
             $jobtitle = $this->_getParam('jobtitle', null);
             $position_id = $this->_getParam('position_id', null);
             $reporting_id = $this->_getParam('reporting_id', null);
             $req_no_positions = $this->_getParam('req_no_positions', null);
             $jobdescription = $this->_getParam('jobdescription', null);
             $req_skills = $this->_getParam('req_skills', null);
             $req_qualification = $this->_getParam('req_qualification', null);
             $req_exp_years = $this->_getParam('req_exp_years', null);
             $emp_type = $this->_getParam('emp_type', null);
             $req_priority = $this->_getParam('req_priority', null);
             $additional_info = $this->_getParam('additional_info', null);
             $req_status = $this->_getParam('req_status', null);
             $approver1 = $this->_getParam('approver1', null);
             $approver2 = $this->_getParam('approver2', null);
             $approver3 = $this->_getParam('approver3', null);
             $aflag = $this->_getParam('aflag', null);
             $edit_flag = $this->_getParam('edit_flag', null);
             $edit_order = $this->_getParam('edit_order', null);
             $requ_jd = $this->_getParam('requ_jd', null);
             $billable = $this->_getParam('billable', null);
             $billablefor = $this->_getParam('billablefor', null);
             $billable_empname = $this->_getParam('billable_empname', null);
             $interviewroundscount = $this->_getParam('interviewroundscount', null);
             $technology = $this->_getParam('technology', null);
             try {
                 $ipbusiness_unit = 1;
                 $ipdepartment = 1;
                 $ipreporting_id = $this->_getParam('ipreporting_id', null);
                 $technicalskill_id = $this->_getParam('technicalskill_id', null);
                 $nontechnicalskill_id = $this->_getParam('nontechnicalskill_id', null);
             } catch (Exception $abc) {
             }
             $aorder = $this->_getParam('aorder', null);
             //1= approver1,2=approver2,3=approver3
             if ($aflag != '' && $aflag == 'approver') {
                 if ($req_status == 3) {
                     //for rejected
                     $data = array('modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'appstatus' . $aorder => $req_status, 'req_status' => $req_status);
                 } else {
                     //for approved
                     if ($aorder == 1) {
                         if ($approver2 != '') {
                             $data = array('appstatus1' => $req_status, 'req_status' => $req_status);
                             $appr_mail = $approver1;
                             $appr_per = $approver1;
                         } else {
                             $data = array('appstatus1' => $req_status, 'req_status' => $req_status);
                             $appr_mail = 'approved';
                         }
                     } else {
                         if ($aorder == 2) {
                             if ($approver3 != '') {
                                 $data = array('appstatus2' => $req_status, 'req_status' => $req_status);
                                 $appr_mail = $approver2;
                                 $appr_per = $approver2;
                             } else {
                                 $data = array('appstatus2' => $req_status, 'req_status' => $req_status);
                                 $appr_mail = 'approved';
                             }
                         }
                     }
                     $data['modifiedby'] = trim($loginUserId);
                     $data['modifiedon'] = gmdate("Y-m-d H:i:s");
                 }
             } else {
                 $data = array('requisition_code' => trim($requisition_code), 'onboard_date' => sapp_Global::change_date(trim($onboard_date), 'database'), 'position_id' => trim($position_id), 'reporting_id' => trim($reporting_id), 'businessunit_id' => trim($business_unit), 'department_id' => trim($department), 'req_no_positions' => trim($req_no_positions), 'jobdescription' => trim($jobdescription), 'jobtitle' => trim($jobtitle), 'req_skills' => trim($req_skills), 'req_qualification' => trim($req_qualification), 'req_exp_years' => trim($req_exp_years), 'emp_type' => trim($emp_type), 'req_priority' => trim($req_priority), 'additional_info' => trim($additional_info), 'billable' => trim($billable), 'interviewroundscount' => trim($interviewroundscount), 'technology' => trim($technology), 'approver1' => $approver1, 'approver2' => $approver2 == '' ? null : $approver2, 'approver3' => $approver3 == '' ? null : $approver3, 'req_status' => 'Initiated', 'appstatus1' => 'Initiated', 'appstatus2' => null, 'appstatus3' => null, 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createdon' => gmdate("Y-m-d H:i:s"), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'upload_jd' => trim($requ_jd), 'billable_for' => trim($billablefor), 'billable_empname' => trim($billable_empname));
                 if ($loginuserGroup == MANAGER_GROUP) {
                     $data['reporting_id'] = $loginUserId;
                 }
                 if ($edit_flag != '' && $edit_flag == 'yes') {
                     if ($edit_order == 1) {
                         $data = array('modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'approver2' => $approver2 == '' ? null : $approver2, 'approver3' => $approver3 == '' ? null : $approver3, 'appstatus2' => 'Initiated');
                         if ($approver2 == '') {
                             $data['appstatus2'] = null;
                         } else {
                             $appr_per = $edit_order;
                             $appr_mail = $approver2;
                         }
                     }
                     if ($edit_order == 2) {
                         $data = array('modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'approver3' => $approver3 == '' ? null : $approver3, 'appstatus3' => 'Initiated');
                         if ($approver3 == '') {
                             $data['appstatus3'] = null;
                         } else {
                             $appr_per = $edit_order;
                             $appr_mail = $approver3;
                         }
                     }
                 }
             }
             $where = "";
             $actionflag = 1;
             //for mailing
             if ($id == '') {
                 //for requisition code
                 $identity_code_model = new Default_Model_Identitycodes();
                 $identity_codes = $identity_code_model->getIdentitycodesRecord();
                 $irequistion_code = isset($identity_codes[0]) ? $identity_codes[0]['requisition_code'] : "";
                 if ($irequistion_code != '') {
                     $req_id = $requi_model->getMaxReqCode($irequistion_code . "/");
                 } else {
                     $req_id = '';
                 }
                 $data['requisition_code'] = $req_id;
                 //end of requisition code
                 $report_person_data = $user_model->getUserDataById($data['reporting_id']);
                 $approver1_person_data = $user_model->getUserDataById($approver1);
                 $Raisedby_person_data = $user_model->getUserDataById($data['createdby']);
                 $jobttlArr = $jobtitleModel->getsingleJobTitleData(trim($jobtitle));
                 if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                     $jobtitlename = ' - ' . $jobttlArr[0]['jobtitlename'];
                 } else {
                     $jobtitlename = '';
                 }
                 //$hrgroupemail = $requi_model->getgroupemailid("REQ_HR", $business_unit);
                 //if (isset($hrgroupemail)) {
                 //HR Group
                 $mail_arr[0]['name'] = 'HR';
                 $mail_arr[0]['email'] = constant('REQ_HR_0');
                 $mail_arr[0]['type'] = 'HR';
                 //}
                 //$mgmtgroupemail = $requi_model->getgroupemailid("REQ_MGMT", $business_unit);
                 //if (isset($mgmtgroupemail)) {
                 //HR Group
                 $mail_arr[1]['name'] = 'Management';
                 $mail_arr[1]['email'] = constant('REQ_MGMT_0');
                 $mail_arr[1]['type'] = 'Management';
                 //}
                 $mail_arr[2]['name'] = $Raisedby_person_data['userfullname'];
                 $mail_arr[2]['email'] = $Raisedby_person_data['emailaddress'];
                 $mail_arr[2]['type'] = 'RaiseNew';
                 $mail_arr[3]['name'] = $approver1_person_data['userfullname'];
                 $mail_arr[3]['email'] = $approver1_person_data['emailaddress'];
                 $mail_arr[3]['type'] = 'Approver';
                 $appr_str = "";
                 $appr_str = $approver1_person_data['userfullname'];
                 $req_selected_skills = sprintf("Technical Skills (%s), Non-Technical Skills (%s).", $requi_model->getSkillNamesByIds(implode(",", $technicalskill_id), "Technical"), $requi_model->getSkillNamesByIds(implode(",", $nontechnicalskill_id), "Non-Technical"));
                 for ($ii = 0; $ii < count($mail_arr); $ii++) {
                     $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                     $view = $this->getHelper('ViewRenderer')->view;
                     $this->view->emp_name = $mail_arr[$ii]['name'];
                     $this->view->base_url = $base_url;
                     $this->view->type = $mail_arr[$ii]['type'];
                     $this->view->jobtitle = $jobtitlename;
                     $this->view->requisition_code = $requisition_code;
                     $this->view->approver_str = $appr_str;
                     $this->view->raised_name = $Raisedby_person_data['userfullname'];
                     if ($mail_arr[$ii]['type'] == "RaiseNew" || $mail_arr[$ii]['type'] == 'Raise' || $mail_arr[$ii]['type'] == 'RaiseNew' || $mail_arr[$ii]['type'] == 'HR' || $mail_arr[$ii]['type'] == 'Management' || $mail_arr[$ii]['type'] == 'Approver' || $mail_arr[$ii]['type'] == 'ReportingManager') {
                         //values for new email template
                         $bu_dept = $requi_model->getBusinessUnitDepartmentName(trim($department));
                         $this->view->department_name = $bu_dept['DepartmentName'];
                         $this->view->businessunit_name = $bu_dept['BusinessUnitName'];
                         $this->view->noofopenings = trim($req_no_positions);
                         $this->view->position_name = trim($jobtitlename);
                         $this->view->skills = trim($req_selected_skills);
                         $this->view->application_name = APPLICATION_NAME;
                     }
                     $text = $view->render('mailtemplates/requisition.phtml');
                     $options['subject'] = APPLICATION_NAME . ': ' . $requisition_code . '-Requisition for approval';
                     $options['header'] = 'Requisition Status';
                     $options['toEmail'] = $mail_arr[$ii]['email'];
                     $options['toName'] = $mail_arr[$ii]['name'];
                     $options['message'] = $text;
                     //var_dump($text);
                     //$options['cron'] = 'yes';
                     if ($options['toEmail'] != '') {
                         if ($mail_arr[$ii]['type'] == "RaiseNew" || $mail_arr[$ii]['type'] == 'Raise' || $mail_arr[$ii]['type'] == 'RaiseNew' || $mail_arr[$ii]['type'] == 'HR' || $mail_arr[$ii]['type'] == 'Management' || $mail_arr[$ii]['type'] == 'Approver' || $mail_arr[$ii]['type'] == 'ReportingManager') {
                             sapp_Global::_sendEmail($options, "New", REQUISITIONMODULESENDEMAIL);
                         } else {
                             sapp_Global::_sendEmail($options, '', REQUISITIONMODULESENDEMAIL);
                         }
                     }
                 }
             }
             if ($id != '') {
                 unset($data['createdby']);
                 unset($data['createdon']);
                 unset($data['isactive']);
                 $where = "id = " . $id;
                 $tableid = $id;
                 $actionflag = 2;
             }
             $result = $requi_model->SaveorUpdateRequisitionData($data, $where);
             //log approvals by approver
             if ($loginUserId == $approver1) {
                 $requisition_data1 = $requi_model->getRequisitionDataById($id);
                 $result1 = $requi_model->insert_requisition_approvalLog($id, $requisition_data1['requisition_code'], $req_status, $loginUserId, gmdate("Y-m-d H:i:s"));
             }
             /*
              * To Insert Interview Panel & Skill details when a new Requisition created
              */
             $currReqIDinDB = $id;
             if ($currReqIDinDB <= 0) {
                 $currReqIDinDB = $result;
             }
             $requisition_data2 = $requi_model->getRequisitionDataById($currReqIDinDB);
             $result1 = $requi_model->insert_requisition_interview_panel($requisition_data2['requisition_code'], $ipbusiness_unit, $ipdepartment, $ipreporting_id, $requ_jd);
             $result2 = $requi_model->insert_requisition_skills($requisition_data2['requisition_code'], $technicalskill_id, "Technical");
             $result3 = $requi_model->insert_requisition_skills($requisition_data2['requisition_code'], $nontechnicalskill_id, "Non-Technical");
             if ($id == '') {
                 $tableid = $result;
             }
             if ($result != '') {
                 if ($actionflag == 2) {
                     //start of mailing
                     $requisition_data = $requi_model->getRequisitionDataById($id);
                     $report_person_data = $user_model->getUserDataById($requisition_data['reporting_id']);
                     $st_arr = array('0' => 'Select status', '2' => 'Approved', '3' => 'Rejected');
                     if ($req_status == 3 || $appr_mail == 'approved') {
                         //for rejected
                         $approver1_person_data = $user_model->getUserDataById($requisition_data['approver1']);
                         $Raisedby_person_data = $user_model->getUserDataById($requisition_data['createdby']);
                         $jobttlArr = $jobtitleModel->getsingleJobTitleData(trim($requisition_data['jobtitle']));
                         if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                             $jobtitlename = ' - ' . $jobttlArr[0]['jobtitlename'];
                         } else {
                             $jobtitlename = '';
                         }
                         /* $mail_arr[0]['name'] = 'HR';
                            $mail_arr[0]['email'] = defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "";
                            $mail_arr[0]['type'] = 'HR';
                            $mail_arr[1]['name'] = 'Management';
                            $mail_arr[1]['email'] = defined('REQ_MGMT_' . $requisition_data['businessunit_id']) ? constant('REQ_MGMT_' . $requisition_data['businessunit_id']) : "";
                            $mail_arr[1]['type'] = 'Management'; */
                         //$hrgroupemail = $requi_model->getgroupemailid("REQ_HR", $requisition_data['businessunit_id']);
                         //if (isset($hrgroupemail)) {
                         //HR Group
                         $mail_arr[0]['name'] = 'HR';
                         $mail_arr[0]['email'] = constant('REQ_HR_0');
                         $mail_arr[0]['type'] = 'HR';
                         //}
                         //$mgmtgroupemail = $requi_model->getgroupemailid("REQ_MGMT", $requisition_data['businessunit_id']);
                         //if (isset($mgmtgroupemail)) {
                         //HR Group
                         $mail_arr[1]['name'] = 'Management';
                         $mail_arr[1]['email'] = constant('REQ_MGMT_0');
                         $mail_arr[1]['type'] = 'Management';
                         //}
                         $mail_arr[2]['name'] = $Raisedby_person_data['userfullname'];
                         $mail_arr[2]['email'] = $Raisedby_person_data['emailaddress'];
                         $mail_arr[2]['type'] = 'Raise';
                         $mail_arr[3]['name'] = $approver1_person_data['userfullname'];
                         $mail_arr[3]['email'] = $approver1_person_data['emailaddress'];
                         $mail_arr[3]['type'] = 'Approver';
                         // Check if the reporting person and raised person are same - Requisition raised by Manager case
                         if ($requisition_data['reporting_id'] != $requisition_data['createdby']) {
                             $mail_arr[4]['name'] = $report_person_data['userfullname'];
                             $mail_arr[4]['email'] = $report_person_data['emailaddress'];
                             $mail_arr[4]['type'] = 'ReportingManager';
                         }
                         $appr_str = "";
                         $appr_str = $approver1_person_data['userfullname'];
                         if ($requisition_data['approver2'] != '') {
                             $approver2_person_data = $user_model->getUserDataById($requisition_data['approver2']);
                             $appr_str .= ", " . $approver2_person_data['userfullname'];
                             $mail_arr[5]['name'] = $approver2_person_data['userfullname'];
                             $mail_arr[5]['email'] = $approver2_person_data['emailaddress'];
                             $mail_arr[5]['type'] = 'Approver';
                         }
                         if ($requisition_data['approver3'] != '') {
                             $approver3_person_data = $user_model->getUserDataById($requisition_data['approver3']);
                             $appr_str .= " and " . $approver3_person_data['userfullname'];
                             $mail_arr[6]['name'] = $approver3_person_data['userfullname'];
                             $mail_arr[6]['email'] = $approver3_person_data['emailaddress'];
                             $mail_arr[6]['type'] = 'Approver';
                         }
                         $mail = array();
                         for ($ii = 0; $ii < count($mail_arr); $ii++) {
                             $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                             $view = $this->getHelper('ViewRenderer')->view;
                             $this->view->emp_name = !empty($mail_arr[$ii]['name']) ? $mail_arr[$ii]['name'] : '';
                             $this->view->base_url = $base_url;
                             $this->view->type = !empty($mail_arr[$ii]['type']) ? $mail_arr[$ii]['type'] : '';
                             $this->view->jobtitle = $jobtitlename;
                             $this->view->requisition_code = $requisition_data['requisition_code'];
                             $this->view->approver_str = $appr_str;
                             $this->view->raised_name = $Raisedby_person_data['userfullname'];
                             $this->view->req_status = $st_arr[$req_status];
                             $this->view->reporting_manager = $report_person_data['userfullname'];
                             $text = $view->render('mailtemplates/changedrequisition.phtml');
                             $options['subject'] = strtolower($st_arr[$req_status]) == 'approved' ? APPLICATION_NAME . ': ' . $requisition_data['requisition_code'] . '-Requisition is approved' : APPLICATION_NAME . ': Requisition is rejected';
                             $options['header'] = 'Requisition Status';
                             $options['toEmail'] = !empty($mail_arr[$ii]['email']) ? $mail_arr[$ii]['email'] : '';
                             $options['toName'] = !empty($mail_arr[$ii]['name']) ? $mail_arr[$ii]['name'] : '';
                             $options['message'] = $text;
                             $mail[$ii] = $options;
                             //$options['cron'] = 'yes';
                             if ($options['toEmail'] != '') {
                                 sapp_Global::_sendEmail($options, "by_approver1", REQUISITIONMODULESENDEMAIL);
                             } else {
                                 sapp_Global::_sendEmail($options, '', REQUISITIONMODULESENDEMAIL);
                             }
                         }
                     } else {
                         if ($req_status == 2) {
                             //Approver
                             $approver_person_data = $user_model->getUserDataById($appr_mail);
                             $mail_arr[0]['name'] = $approver_person_data['userfullname'];
                             $mail_arr[0]['email'] = $approver_person_data['emailaddress'];
                             $mail_arr[0]['type'] = 'Approver';
                             //HR Group
                             $mail_arr[1]['name'] = 'HR';
                             $mail_arr[1]['email'] = constant('REQ_HR_0');
                             $mail_arr[1]['type'] = 'HR';
                             //Management Group
                             $mail_arr[2]['name'] = 'Management';
                             $mail_arr[2]['email'] = constant('REQ_MGMT_0');
                             $mail_arr[2]['type'] = 'Management';
                             //Requester
                             $Raisedby_person_data = $user_model->getUserDataById($requisition_data['createdby']);
                             $mail_arr[3]['name'] = $Raisedby_person_data['userfullname'];
                             $mail_arr[3]['email'] = $Raisedby_person_data['emailaddress'];
                             $mail_arr[3]['type'] = 'Raise';
                             if ($edit_flag == 'yes') {
                                 $approved_by_data = $user_model->getUserDataById($requisition_data['approver' . $appr_per]);
                                 $req_status = 2;
                             } else {
                                 $approved_by_data = $user_model->getUserDataById($appr_per);
                             }
                             $Raisedby_person_data = $user_model->getUserDataById($requisition_data['createdby']);
                             $appr_str = $approved_by_data['userfullname'];
                             for ($ii = 0; $ii < count($mail_arr); $ii++) {
                                 $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                                 $view = $this->getHelper('ViewRenderer')->view;
                                 $this->view->emp_name = $mail_arr[$ii]['name'];
                                 $this->view->base_url = $base_url;
                                 $this->view->type = $mail_arr[$ii]['type'];
                                 $this->view->requisition_code = $requisition_data['requisition_code'];
                                 $this->view->req_status = $st_arr[$req_status];
                                 $this->view->raised_name = $Raisedby_person_data['userfullname'];
                                 $this->view->approver_str = $appr_str;
                                 $text = $view->render('mailtemplates/changedrequisition.phtml');
                                 $options['subject'] = strtolower($st_arr[$req_status]) == 'approved' ? APPLICATION_NAME . ':' . $requisition_data['requisition_code'] . '-Requisition is approved' : APPLICATION_NAME . ': Requisition is rejected';
                                 $options['header'] = 'Requisition Status';
                                 $options['toEmail'] = $mail_arr[$ii]['email'];
                                 $options['toName'] = $mail_arr[$ii]['name'];
                                 $options['message'] = $text;
                                 //$options['cron'] = 'yes';
                                 if ($options['toEmail'] != '') {
                                     sapp_Global::_sendEmail($options, "by_approver2", REQUISITIONMODULESENDEMAIL);
                                 } else {
                                     sapp_Global::_sendEmail($options, '', REQUISITIONMODULESENDEMAIL);
                                 }
                             }
                         }
                     }
                     //end of mailing
                 }
                 $menumodel = new Default_Model_Menu();
                 $objidArr = $menumodel->getMenuObjID('/requisition');
                 $objID = $objidArr[0]['id'];
                 $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
                 if ($id != '') {
                     $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Resource requisition updated successfully."));
                 } else {
                     $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Resource requisition added successfully."));
                 }
                 $trDb->commit();
                 $this->_redirect('/requisition');
             }
         } catch (Exception $e) {
             $trDb->rollBack();
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Something went wrong, please try again later."));
             $this->_redirect('/requisition');
         }
     } else {
         $messages = $requisitionform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 public function addorgheadAction()
 {
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $org_id = $this->_request->getParam('orgid', null);
     $msgarray = array();
     $prevorgheadId = '';
     $posted_prevorghead_rm = '';
     try {
         $user_model = new Default_Model_Usermanagement();
         $orgInfoModel = new Default_Model_Organisationinfo();
         $countriesModel = new Default_Model_Countries();
         $statesmodel = new Default_Model_States();
         $citiesmodel = new Default_Model_Cities();
         $role_model = new Default_Model_Roles();
         $prefixModel = new Default_Model_Prefix();
         $identity_code_model = new Default_Model_Identitycodes();
         $jobtitlesModel = new Default_Model_Jobtitles();
         $employeeModal = new Default_Model_Employee();
         $positionsmodel = new Default_Model_Positions();
         $form = new Default_Form_Organisationhead();
         $form->setAttrib('action', BASE_URL . 'organisationinfo/addorghead/orgid/' . $org_id);
         $identity_codes = $identity_code_model->getIdentitycodesRecord();
         $role_data = $role_model->getRolesList_orginfo();
         $flag = 'true';
         $emp_identity_code = isset($identity_codes[0]) ? $identity_codes[0]['employee_code'] : "";
         if ($emp_identity_code != '') {
             $emp_id = $emp_identity_code . str_pad($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
         } else {
             $emp_id = '';
             $msgarray['employeeId'] = 'Identity codes are not configured yet.';
             $flag = 'false';
         }
         $form->employeeId->setValue($emp_id);
         $form->emprole->addMultiOptions(array('' => 'Select Role') + $role_data);
         if (empty($role_data)) {
             $msgarray['emprole'] = 'Roles are not added yet.';
             $flag = 'false';
         }
         $prefixData = $prefixModel->getPrefixList();
         $form->prefix_id->addMultiOption('', 'Select Prefix');
         if (!empty($prefixData)) {
             foreach ($prefixData as $prefixres) {
                 $form->prefix_id->addMultiOption($prefixres['id'], $prefixres['prefix']);
             }
         } else {
             $msgarray['prefix_id'] = 'Prefixes are not configured yet.';
         }
         $jobtitleData = $jobtitlesModel->getJobTitleList();
         if (!empty($jobtitleData)) {
             foreach ($jobtitleData as $jobtitleres) {
                 $form->jobtitle_id->addMultiOption($jobtitleres['id'], $jobtitleres['jobtitlename']);
             }
         } else {
             $msgarray['jobtitle_id'] = 'Job titles are not configured yet.';
             $msgarray['position_id'] = 'Positions are not configured yet.';
         }
         $form->position_id->addMultiOption('', 'Select a Position');
         if (isset($_POST['jobtitle_id']) && $_POST['jobtitle_id'] != '') {
             $jobtitle_id = $_POST['jobtitle_id'];
             $positionlistArr = $positionsmodel->getPositionList($jobtitle_id);
             if (sizeof($positionlistArr) > 0) {
                 foreach ($positionlistArr as $positionlistres) {
                     $form->position_id->addMultiOption($positionlistres['id'], $positionlistres['positionname']);
                 }
             }
         }
         if (isset($_POST['prevorghead_rm']) && $_POST['prevorghead_rm'] != '') {
             $posted_prevorghead_rm = $_POST['prevorghead_rm'];
         }
         $orgheadsData = $employeeModal->getEmployeesForOrgHead();
         $emp_data = $employeeModal->fetchRow("is_orghead = 1");
         if (!empty($emp_data)) {
             $user_data = $user_model->fetchRow("id = " . $emp_data->user_id);
             if (!empty($user_data)) {
                 $prevorgheadId = $user_data->id;
             } else {
                 $form->removeElement('prevorghead_rm');
             }
         } else {
             $form->removeElement('prevorghead_rm');
         }
         if ($this->getRequest()->getPost()) {
             if ($form->isValid($this->_request->getPost()) && $flag != 'false') {
                 $jobtitle_id = $this->_request->getParam('jobtitle_id', null);
                 $position_id = $this->_request->getParam('position_id', null);
                 $date_of_joining = sapp_Global::change_date($this->_request->getParam('date_of_joining_head', null), 'database');
                 $employeeId = $this->_request->getParam('employeeId', null);
                 $emprole = $this->_request->getParam('emprole', null);
                 $emailaddress = $this->_request->getParam('emailaddress', null);
                 $emppassword = sapp_Global::generatePassword();
                 $first_name = trim($this->_request->getParam('firstname_orghead', null));
                 $last_name = trim($this->_request->getParam('lastname_orghead', null));
                 //$userfullname = trim($this->_request->getParam('orghead',null));
                 $userfullname = $first_name . ' ' . $last_name;
                 $prefix_id = $this->_request->getParam('prefix_id', null);
                 $user_id = $this->_request->getParam('user_id', null);
                 $prevorghead_rm = $this->_request->getParam('prevorghead_rm', null);
                 $prevheadid = $this->_request->getParam('prevheadid', null);
                 $user_data = array('emprole' => $emprole, 'firstname' => $first_name, 'lastname' => $last_name, 'userfullname' => $userfullname, 'emailaddress' => $emailaddress, 'jobtitle_id' => $jobtitle_id, 'emppassword' => md5($emppassword), 'employeeId' => $employeeId, 'selecteddate' => $date_of_joining, 'userstatus' => 'old', 'modeofentry' => 'Direct', 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                 $emp_data = array('jobtitle_id' => $jobtitle_id, 'position_id' => $position_id, 'prefix_id' => $prefix_id, 'reporting_manager' => 0, 'date_of_joining' => $date_of_joining, 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1, 'is_orghead' => 1);
                 $org_data = array('modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 if ($emp_identity_code != '') {
                     $emp_id = $emp_identity_code . str_pad($user_model->getMaxEmpId($emp_identity_code), 4, '0', STR_PAD_LEFT);
                 } else {
                     $emp_id = '';
                 }
                 $user_data['employeeId'] = $emp_id;
                 $db = Zend_Db_Table::getDefaultAdapter();
                 $db->beginTransaction();
                 try {
                     $user_id = $user_model->SaveorUpdateUserData($user_data, '');
                     $emp_data['user_id'] = $user_id;
                     $employeeModal->SaveorUpdateEmployeeData($emp_data, '');
                     if (isset($prevheadid) && $prevheadid != '') {
                         $org_data['orghead'] = $user_id;
                         $orgwhere = array('id=?' => $org_id);
                         $orgInfoModel->SaveorUpdateData($org_data, $orgwhere);
                         $orgInfoModel->changeOrgHead($prevheadid, $user_id, $prevorghead_rm);
                         $this->sendmailstoemployees($prevheadid, $user_id);
                     }
                     $tableid = $user_id;
                     $actionflag = 1;
                     $menuID = EMPLOYEE;
                     try {
                         $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
                     } catch (Exception $e) {
                         echo $e->getMessage();
                     }
                     $close = 'close';
                     $this->view->popup = $close;
                     $this->view->eventact = 'added';
                     $db->commit();
                 } catch (Exception $e) {
                     $db->rollBack();
                 }
             } else {
                 $messages = $form->getMessages();
                 foreach ($messages as $key => $val) {
                     foreach ($val as $key2 => $val2) {
                         $msgarray[$key] = $val2;
                         break;
                     }
                 }
             }
         }
         $this->view->prevorgheadId = $prevorgheadId;
         $this->view->form = $form;
         $this->view->msgarray = $msgarray;
         $this->view->orgheadsData = $orgheadsData;
         $this->view->posted_prevorghead_rm = $posted_prevorghead_rm;
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
 }
 /**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of users (optional)
  * 
  * @return Zend_Form.
  */
 public function editAction()
 {
     $popConfigPermission = array();
     $user_model = new Default_Model_Usermanagement();
     $role_model = new Default_Model_Roles();
     $identity_code_model = new Default_Model_Identitycodes();
     $identity_codes = $identity_code_model->getIdentitycodesRecord();
     $identity_codes = isset($identity_codes[0]) ? $identity_codes[0] : array();
     $id = $this->getRequest()->getParam('id', null);
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $login_group_id = $auth->getStorage()->read()->group_id;
         $login_role_id = $auth->getStorage()->read()->emprole;
     }
     if (sapp_Global::_checkprivileges(IDENTITYCODES, $login_group_id, $login_role_id, 'edit') == 'Yes') {
         array_push($popConfigPermission, 'identitycodes');
     }
     $this->view->popConfigPermission = $popConfigPermission;
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $form = new Default_Form_Usermanagement();
     $err_messages = array();
     $roles_arr = $role_model->getRolesListForUsers('');
     $form->emprole->addMultiOptions(array('' => 'Select Role') + $roles_arr);
     $emp_identity_code = isset($identity_codes['backgroundagency_code']) ? $identity_codes['backgroundagency_code'] : "";
     $identity_arr = array();
     if ($emp_identity_code != '') {
         $identity_arr = array($identity_codes['users_code'] => "Users (" . $identity_codes['users_code'] . ")");
     } else {
         $emp_id = '';
     }
     $form->employeeId->addMultiOptions($identity_arr);
     if ($id != '' && $id > 0) {
         try {
             $id = (int) $id;
             $id = abs($id);
             $form->submit->setLabel('Update');
             $data = $user_model->getUserDataById($id);
             if (count($data) > 0) {
                 if ($data['jobtitle_id'] != '') {
                     $this->_redirect('/employee/edit/id/' . $id);
                 }
                 $role_data = $role_model->getRoleDataById($data['emprole']);
                 $data['emplockeddate'] = sapp_Global::change_date($data['emplockeddate'], 'view');
                 $form->populate($data);
                 $this->view->data = $data;
                 //$id_arr = preg_split('/-/', $data['employeeId']);
                 $id_arr = preg_split('/(?=\\d)/', $data['employeeId'], 2);
                 $identity_arr[$identity_codes['backgroundagency_code']] = "Background Agency (" . $identity_codes['backgroundagency_code'] . ")";
                 if (isset($identity_arr[$id_arr[0]]) && !empty($identity_arr[$id_arr[0]])) {
                     $empIDSetVal = $identity_arr[$id_arr[0]];
                 } else {
                     $empIDSetVal = '';
                 }
                 $form->employeeId->setValue($empIDSetVal);
                 if ($role_data['group_id'] == USERS_GROUP) {
                     $form->emprole->clearMultiOptions();
                     $roles_arr = $role_model->getRolesListForUsers($id, $empIDSetVal);
                     $form->emprole->addMultiOptions(array('' => 'Select Role') + $roles_arr);
                 }
             } else {
                 $this->view->nodata = "nodata";
             }
         } catch (Exception $e) {
             $this->view->nodata = "nodata";
         }
     } else {
         if ($id == '') {
         } else {
             echo $this->view->nodata = "nodata";
         }
     }
     if ($id == '') {
         if ($emp_identity_code == '') {
             $err_messages['employeeId'] = "Identity codes are not configured yet.";
         }
         if (count($roles_arr) == 0) {
             $err_messages['emprole'] = "Roles are not added yet.";
         }
     }
     $this->view->messages = $err_messages;
     $this->view->form = $form;
 }
 /**
  * 
  * @param array $data
  * @param type $requisition_code
  * @param type $hrExecutiveID
  */
 public function hrexecutive_to_requisition_emails($data, $requisition_code, $hrExecutiveID)
 {
     $user_model = new Default_Model_Usermanagement();
     $requi_model = new Default_Model_Requisition();
     $identity_code_model = new Default_Model_Identitycodes();
     //for requisition code
     $identity_codes = $identity_code_model->getIdentitycodesRecord();
     $irequistion_code = isset($identity_codes[0]) ? $identity_codes[0]['requisition_code'] : "";
     if ($irequistion_code != '') {
         $req_id = $requi_model->getMaxReqCode($irequistion_code . "/");
     } else {
         $req_id = '';
     }
     $data['requisition_code'] = $req_id;
     //end of requisition code
     $Raisedby_person_data = $user_model->getUserDataById($data['createdby']);
     $business_unit = $data['businessunit_id'];
     //HR Group
     $mail_arr[0]['name'] = 'HR';
     $mail_arr[0]['email'] = constant('REQ_HR_0');
     $mail_arr[0]['type'] = 'HR';
     //Management Group
     $mail_arr[1]['name'] = 'Management';
     $mail_arr[1]['email'] = constant('REQ_MGMT_0');
     $mail_arr[1]['type'] = 'Management';
     //Requester
     $mail_arr[2]['name'] = $Raisedby_person_data['userfullname'];
     $mail_arr[2]['email'] = $Raisedby_person_data['emailaddress'];
     $mail_arr[2]['type'] = 'Raise';
     $currEmailCount = 3;
     foreach ($hrExecutiveID as $ipid) {
         $hrexecutive_person_data = $user_model->getUserDataById($ipid);
         $mail_arr[$currEmailCount]['name'] = $hrexecutive_person_data['userfullname'];
         $mail_arr[$currEmailCount]['email'] = $hrexecutive_person_data['emailaddress'];
         $mail_arr[$currEmailCount]['type'] = 'HRExecutive';
         $currEmailCount = $currEmailCount + 1;
     }
     #$appr_str = $hrexecutive_person_data['userfullname'];
     $appr_str = $Raisedby_person_data['userfullname'];
     for ($ii = 0; $ii < count($mail_arr); $ii++) {
         $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
         $view = $this->getHelper('ViewRenderer')->view;
         $this->view->emp_name = $mail_arr[$ii]['name'];
         $this->view->base_url = $base_url;
         $this->view->type = $mail_arr[$ii]['type'];
         $this->view->jobtitle = "";
         //Job doesnt require for this emails
         $this->view->requisition_code = $requisition_code;
         $this->view->approver_str = $appr_str;
         $this->view->raised_name = $Raisedby_person_data['userfullname'];
         $text = $view->render('mailtemplates/requisition.phtml');
         $options['subject'] = APPLICATION_NAME . ':' . $requisition_code . '-Recruiter allocated for requisition.';
         $options['header'] = 'Requisition Status';
         $options['toEmail'] = $mail_arr[$ii]['email'];
         $options['toName'] = $mail_arr[$ii]['name'];
         $options['message'] = $text;
         //$options['cron'] = 'yes';
         if ($options['toEmail'] != '') {
             sapp_Global::_sendEmail($options, "requisition", REQUISITIONMODULESENDEMAIL);
         }
     }
 }