/**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of requisition.
  *
  * @return Zend_Form.
  */
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id', null);
     $auth = Zend_Auth::getInstance();
     $data = array();
     $data_m = array();
     $ipreporting_idData = array();
     $ipreporting_ids = array();
     $technicalskills_all = array();
     $technicalskills_selected = array();
     $nontechnicalskills_all = array();
     $nontechnicalskills_selected = array();
     $job_title_permission = NULL;
     if ($auth->hasIdentity()) {
         $sess_vals = $auth->getStorage()->read();
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $job_title_permission = sapp_Global::_checkprivileges(JOBTITLES, $loginuserGroup, $loginuserRole, 'add');
     //$positions_permission = sapp_Global::_checkprivileges(POSITIONS, $loginuserGroup, $loginuserRole, 'add');
     $emp_status_permission = sapp_Global::_checkprivileges(EMPLOYMENTSTATUS, $loginuserGroup, $loginuserRole, 'add');
     $form = new Default_Form_Requisition();
     $requi_model = new Default_Model_Requisition();
     $usersModel = new Default_Model_Users();
     $user_model = new Default_Model_Usermanagement();
     $ipreporting_idData = $requi_model->getAllEmployees();
     $ipreporting_ids = $requi_model->getRequisitionInterviewPanelIDs($id);
     $technicalskills_all = $requi_model->getAllActiveTechnicalSkills();
     $technicalskills_selected = $requi_model->getRequisitionSkillIDs($id, "Technical");
     $nontechnicalskills_all = $requi_model->getAllActiveNonTechnicalSkills();
     $nontechnicalskills_selected = $requi_model->getRequisitionSkillIDs($id, "Non-Technical");
     $form->setAttrib('action', DOMAIN . 'requisition/edit/id/' . $id);
     $form->submit->setLabel('Update');
     $edit_flag = '';
     $edit_order = '';
     $approver1_opt = array();
     $approver2_opt = array();
     $reportingManagerData = array();
     $hrexecutivesData = array();
     try {
         if ($id > 0 && is_numeric($id)) {
             $id = abs($id);
             //$data['id'] = $id;
             $data = $requi_model->getRequisitionForEdit($id, $loginUserId);
             //$data['requ_jd'] = "<span title='" . htmlentities(trim($data['requ_jd']), ENT_QUOTES, "UTF-8") . "'><a href='" . DOMAIN . 'requisition/download/id/' . $id . "'>" . $data['requ_jd'] . "</a></span>";
             $getempId = $requi_model->getrequisitionDataonid($id);
             if (!empty($getempId['billable_empname'])) {
                 $getdatampname = $requi_model->getEmployeeNameonId($getempId['billable_empname']);
             }
             $aflag = $data['aflag'];
             if ($aflag == "approver") {
                 $aorder = 1;
             }
             //$aorder = $data['aorder'];
             if (!empty($data) && $data['req_status'] == 'Initiated') {
                 if ($loginuserGroup != MANAGEMENT_GROUP || $loginuserGroup == MANAGEMENT_GROUP || $loginuserGroup == '') {
                     if ($aflag == 'approver' && $data['appstatus' . $aorder] == 'Initiated') {
                         $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                         $business_units_list = $requi_model->getBusinessUnitsList();
                         $data['bunit_name'] = $business_units_list[$data['businessunit_id']];
                         $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                         $data['dept_name'] = $departments_list[$data['department_id']];
                         $job_data = $requi_model->getJobTitleList();
                         if (isset($job_data[$data['jobtitle']])) {
                             $data['jtitle_name'] = $job_data[$data['jobtitle']];
                         } else {
                             $data['jtitle_name'] = 'Select Job Title';
                         }
                         //                            $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                         //                            $data['position_name'] = $pos_data[$data['position_id']];
                         $emptype_options = $requi_model->getStatusOptionsForRequi();
                         if (isset($emptype_options[$data['emp_type']])) {
                             $data['emptype_name'] = $emptype_options[$data['emp_type']];
                         } else {
                             $data['emptype_name'] = 'Select Employment Status';
                         }
                         $report_manager_data = $user_model->getUserDataById($data['reporting_id']);
                         $data['mngrname'] = $report_manager_data['userfullname'];
                         $form->req_status->addMultiOptions(array('0' => 'Select status', '2' => 'Approved', '3' => 'Rejected'));
                         $form->req_status->setRequired(true)->addErrorMessage('Please select the status.');
                         $form->req_status->addFilter('Int')->addValidator('NotEmpty', true, array('integer', 'zero'));
                         $elements = $form->getElements();
                         if (count($elements) > 0) {
                             foreach ($elements as $key => $element) {
                                 if ($key != 'req_status') {
                                     $element->setRequired(false);
                                 }
                             }
                         }
                         if ($data['approver1'] != '') {
                             $app1_opt = $user_model->getUserDataById($data['approver1']);
                             $data_m['approver1'] = $app1_opt['userfullname'];
                         }
                         if ($data['approver2'] != '') {
                             $app2_opt = $user_model->getUserDataById($data['approver2']);
                             $data_m['approver2'] = $app2_opt['userfullname'];
                         }
                     } else {
                         $edit_flag = 'no';
                         if (in_array('Approved', array($data['appstatus1'], $data['appstatus2'], $data['appstatus3']))) {
                             $edit_flag = 'yes';
                         }
                         if ($edit_flag == 'yes') {
                             $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                             $business_units_list = $requi_model->getBusinessUnitsList();
                             $data['bunit_name'] = $business_units_list[$data['businessunit_id']];
                             $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                             $data['dept_name'] = $departments_list[$data['department_id']];
                             $job_data = $requi_model->getJobTitleList();
                             if (isset($job_data[$data['jobtitle']])) {
                                 $data['jtitle_name'] = $job_data[$data['jobtitle']];
                             } else {
                                 $data['jtitle_name'] = 'Select Job Title';
                             }
                             //                                $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                             //                                $data['position_name'] = $pos_data[$data['position_id']];
                             $emptype_options = $requi_model->getStatusOptionsForRequi();
                             if (isset($emptype_options[$data['emp_type']])) {
                                 $data['emptype_name'] = $emptype_options[$data['emp_type']];
                             } else {
                                 $data['emptype_name'] = 'Select Employment Status';
                             }
                             $report_manager_data = $user_model->getUserDataById($data['reporting_id']);
                             $data['mngrname'] = $report_manager_data['userfullname'];
                             $elements = $form->getElements();
                             if (count($elements) > 0) {
                                 foreach ($elements as $key => $element) {
                                     $element->setRequired(false);
                                 }
                             }
                             if ($data['appstatus1'] == 'Approved') {
                                 $edit_order = 1;
                                 $app1_opt = $user_model->getUserDataById($data['approver1']);
                                 $data_m['approver1'] = $app1_opt['userfullname'];
                                 $report_manager_options = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                                 $form->setDefault('approver1', $data['approver1']);
                             }
                         } else {
                             #$form->setDefault('requ_jd', $data['requ_jd']);
                             $business_units_list = $requi_model->getBusinessUnitsList();
                             $form->business_unit->addMultiOptions(array('' => 'Select Business Unit') + $business_units_list);
                             $form->setDefault('business_unit', $data['businessunit_id']);
                             $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                             $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                             $form->setDefault('department', $data['department_id']);
                             $job_data = $requi_model->getJobTitleList();
                             $form->jobtitle->addMultiOptions(array('' => 'Select Job Title') + $job_data);
                             $form->setDefault('jobtitle', $data['jobtitle']);
                             //                                $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                             //                                $form->position_id->addMultiOptions(array('' => 'Select Position') + $pos_data);
                             //                                $form->setDefault('position_id', $data['position_id']);
                             $emptype_options = $requi_model->getStatusOptionsForRequi();
                             $form->emp_type->addMultiOptions(array('' => 'Select Employment Status') + $emptype_options);
                             $form->technology->addMultiOptions(array('' => 'Select Technology') + $requi_model->getTechnologySkillIDName());
                             $form->setDefault('technology', $data['technology']);
                             $form->setDefault('reporting_id', $data['reporting_id']);
                             $form->billablefor->addMultiOptions(array('' => 'Select Billable Type', 'New' => 'New', 'Replacement' => 'Replacement', 'Backup' => 'Backup'));
                             $form->setDefault('billablefor', $getempId['billable_for']);
                             $form->setDefault('requ_jd', $getempId['upload_jd']);
                             $form->requ_jd->setRequired(false);
                             //$form->requisition_code->setValue($ipreporting_ids);
                             //$form->ipreporting_id->addMultiOptions(array('' => 'Select Technical Panel') + $ipreporting_idData);
                             //$form->ipreporting_id->setValue($data['requisition_code']);
                             //$form->ipreporting_id->setMultiOptions($ipreporting_ids);
                             $form->req_status->addMultiOptions(array('1' => 'Initiated'));
                             if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
                                 if ($loginuserGroup == '') {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', $loginUserId, '', $data['department_id'], 'requisition');
                                 } else {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', '', '', $data['department_id'], 'requisition');
                                 }
                                 if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
                                     if ($loginuserGroup == '') {
                                         $getEmployeelistonBunit = $requi_model->getEmployeelistonBunit('', $data['business_unit'], 'requisition');
                                     } else {
                                         $getEmployeelistonBunit = $requi_model->getEmployeelistonBunit('', $data['business_unit'], 'requisition');
                                     }
                                     //for hr,management
                                     $re_arr = array();
                                 }
                                 if (isset($_POST['business_unit']) && $_POST['business_unit'] != '') {
                                     $departments_list = $requi_model->getDepartmentList($_POST['business_unit']);
                                     $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                                 }
                                 if (isset($_POST['department']) && $_POST['department'] != '') {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', $loginUserId, '', $_POST['department'], 'requisition');
                                 }
                                 $form->reporting_id->addMultiOptions(array('' => 'Select Reporting Manager') + $reportingManagerData);
                                 $form->setDefault('reporting_id', $data['reporting_id']);
                                 $form->setDefault('req_status', $data['req_status']);
                                 $form->req_status->setAttrib("disabled", "disabled");
                                 if ($loginuserGroup == HR_GROUP) {
                                     $departments_list = $requi_model->getDepartmentList($sess_vals->businessunit_id);
                                     $data_m['bunit_data']['id'] = $sess_vals->businessunit_id;
                                     $data_m['bunit_data']['name'] = $business_units_list[$sess_vals->businessunit_id];
                                     $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                                 }
                             } else {
                                 //for managers login
                                 $report_manager_options = $user_model->getUserDataById($data['reporting_id']);
                                 $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                                 $data_m['manager_data']['id'] = $data['reporting_id'];
                                 $data_m['manager_data']['name'] = $report_manager_options['userfullname'];
                                 $data_m['bunit_data']['id'] = $data['businessunit_id'];
                                 $data_m['bunit_data']['name'] = $business_units_list[$data['businessunit_id']];
                                 $data_m['dept_data']['id'] = $data['department_id'];
                                 $data_m['dept_data']['name'] = $departments_list[$data['department_id']];
                                 $form->setDefault('reporting_id', $data['reporting_id']);
                                 $form->setDefault('req_status', $data['req_status']);
                                 $form->req_status->setAttrib("disabled", "disabled");
                             }
                             $hrexecutivesData = $requi_model->getHRExecutives();
                             //start of approvers options
                             $approver_opt = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                             $app1_opt = array();
                             if (count($approver_opt) > 0 && count($_POST) == 0) {
                                 foreach ($approver_opt as $app1) {
                                     $approver1_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                 }
                             }
                             //end of approvers options
                             foreach ($data as $key => $val) {
                                 $data[$key] = htmlentities(addslashes($val), ENT_QUOTES, "UTF-8");
                             }
                             $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                             $form->populate($data);
                             if (isset($_POST['business_unit']) && $_POST['business_unit'] != '') {
                                 $departments_list = $requi_model->getDepartmentList($_POST['business_unit']);
                                 $form->department->clearMultiOptions();
                                 $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                             }
                             //                                if (isset($_POST['jobtitle']) && $_POST['jobtitle'] != '') {
                             //                                    $pos_data = $requi_model->getPositionOptions($_POST['jobtitle']);
                             //                                    $form->position_id->clearMultiOptions();
                             //                                    $form->position_id->addMultiOptions(array('' => 'Select Position') + $pos_data);
                             //                                }
                             if (isset($_POST['reporting_id']) && $_POST['reporting_id'] != '') {
                                 $app1_data = $requi_model->getapprovers($_POST['reporting_id'], $_POST['department']);
                                 $app1_opt = array();
                                 if (count($app1_data) > 0) {
                                     foreach ($app1_data as $app1) {
                                         $app1_opt[$app1['id']] = ucwords($app1['name']);
                                         $approver1_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                     }
                                     $form->reporting_id->setValue($_POST['reporting_id']);
                                 }
                             }
                         }
                     }
                     //end of else of aflag.
                     $this->view->loginuserGroup = $loginuserGroup;
                     $this->view->form = $form;
                     $this->view->data = $data;
                     $this->view->data_m = $data_m;
                     $this->view->aflag = $aflag;
                     $this->view->aorder = $aorder;
                     $this->view->edit_flag = $edit_flag;
                     $this->view->edit_order = $edit_order;
                     $this->view->reportingManagerData = $reportingManagerData;
                     $this->view->hrexecutivesData = $hrexecutivesData;
                     $this->view->approver1_opt = $approver1_opt;
                     $this->view->approver2_opt = $approver2_opt;
                     $this->view->ipreporting_idData = $ipreporting_idData;
                     $this->view->ipreporting_ids = $ipreporting_ids;
                     $this->view->technicalskills_all = $technicalskills_all;
                     $this->view->technicalskills_selected = $technicalskills_selected;
                     $this->view->nontechnicalskills_all = $nontechnicalskills_all;
                     $this->view->nontechnicalskills_selected = $nontechnicalskills_selected;
                     $this->view->getEmployeelistonBunit = $getEmployeelistonBunit;
                     $this->view->getempId = $getempId;
                     $this->view->getdatampname = $getdatampname;
                     if ($this->getRequest()->getPost()) {
                         $result = $this->save($form, $data);
                         $this->view->msgarray = $result;
                         $this->view->messages = $result;
                     }
                     $this->view->ermsg = '';
                 } else {
                     $this->view->nodata = 'nodata';
                 }
             } else {
                 $this->view->nodata = 'nodata';
             }
         } else {
             $this->view->nodata = 'nodata';
         }
         // To check whether to display Employment Status configuration link or not
         $employmentstatusmodel = new Default_Model_Employmentstatus();
         $activeEmploymentStatusArr = $employmentstatusmodel->getEmploymentStatuslist();
         $this->view->job_title_permission = $job_title_permission;
         $this->view->positions_permission = $positions_permission;
         $this->view->emp_status_permission = $emp_status_permission;
     } catch (Exception $e) {
         $this->view->nodata = 'nodata';
     }
 }
 /**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of requisition.
  *
  * @return Zend_Form.
  */
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id', null);
     $auth = Zend_Auth::getInstance();
     $data = array();
     $data_m = array();
     $job_title_permission = NULL;
     if ($auth->hasIdentity()) {
         $sess_vals = $auth->getStorage()->read();
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $job_title_permission = sapp_Global::_checkprivileges(JOBTITLES, $loginuserGroup, $loginuserRole, 'add');
     $positions_permission = sapp_Global::_checkprivileges(POSITIONS, $loginuserGroup, $loginuserRole, 'add');
     $emp_status_permission = sapp_Global::_checkprivileges(EMPLOYMENTSTATUS, $loginuserGroup, $loginuserRole, 'add');
     $form = new Default_Form_Requisition();
     $requi_model = new Default_Model_Requisition();
     $usersModel = new Default_Model_Users();
     $user_model = new Default_Model_Usermanagement();
     $form->setAttrib('action', DOMAIN . 'requisition/edit/id/' . $id);
     $form->submit->setLabel('Update');
     $edit_flag = '';
     $edit_order = '';
     $approver1_opt = array();
     $approver2_opt = array();
     $approver3_opt = array();
     $reportingManagerData = array();
     try {
         if ($id > 0 && is_numeric($id)) {
             $id = abs($id);
             $data = $requi_model->getRequisitionForEdit($id, $loginUserId);
             $aflag = $data['aflag'];
             $aorder = $data['aorder'];
             if (!empty($data) && $data['req_status'] == 'Initiated') {
                 if ($loginuserGroup != MANAGEMENT_GROUP || $loginuserGroup == MANAGEMENT_GROUP || $loginuserGroup == '') {
                     if ($aflag == 'approver' && $data['appstatus' . $aorder] == 'Initiated') {
                         $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                         $business_units_list = $requi_model->getBusinessUnitsList();
                         $data['bunit_name'] = $business_units_list[$data['businessunit_id']];
                         $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                         $data['dept_name'] = $departments_list[$data['department_id']];
                         $job_data = $requi_model->getJobTitleList();
                         if (isset($job_data[$data['jobtitle']])) {
                             $data['jtitle_name'] = $job_data[$data['jobtitle']];
                         } else {
                             $data['jtitle_name'] = 'Select Job Title';
                         }
                         $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                         $data['position_name'] = $pos_data[$data['position_id']];
                         $emptype_options = $requi_model->getStatusOptionsForRequi();
                         if (isset($emptype_options[$data['emp_type']])) {
                             $data['emptype_name'] = $emptype_options[$data['emp_type']];
                         } else {
                             $data['emptype_name'] = 'Select Employment Status';
                         }
                         $report_manager_data = $user_model->getUserDataById($data['reporting_id']);
                         $data['mngrname'] = $report_manager_data['userfullname'];
                         $form->req_status->addMultiOptions(array('0' => 'Select status', '2' => 'Approved', '3' => 'Rejected'));
                         $form->req_status->setRequired(true)->addErrorMessage('Please select the status.');
                         $form->req_status->addFilter('Int')->addValidator('NotEmpty', true, array('integer', 'zero'));
                         $elements = $form->getElements();
                         if (count($elements) > 0) {
                             foreach ($elements as $key => $element) {
                                 if ($key != 'req_status') {
                                     $element->setRequired(false);
                                 }
                             }
                         }
                         if ($data['approver1'] != '') {
                             $app1_opt = $user_model->getUserDataById($data['approver1']);
                             $data_m['approver1'] = $app1_opt['userfullname'];
                         }
                         if ($data['approver2'] != '') {
                             $app2_opt = $user_model->getUserDataById($data['approver2']);
                             $data_m['approver2'] = $app2_opt['userfullname'];
                         }
                         if ($data['approver3'] != '') {
                             $app3_opt = $user_model->getUserDataById($data['approver3']);
                             $data_m['approver3'] = $app3_opt['userfullname'];
                         }
                     } else {
                         $edit_flag = 'no';
                         if (in_array('Approved', array($data['appstatus1'], $data['appstatus2'], $data['appstatus3']))) {
                             $edit_flag = 'yes';
                         }
                         if ($edit_flag == 'yes') {
                             $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                             $business_units_list = $requi_model->getBusinessUnitsList();
                             $data['bunit_name'] = $business_units_list[$data['businessunit_id']];
                             $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                             $data['dept_name'] = $departments_list[$data['department_id']];
                             $job_data = $requi_model->getJobTitleList();
                             if (isset($job_data[$data['jobtitle']])) {
                                 $data['jtitle_name'] = $job_data[$data['jobtitle']];
                             } else {
                                 $data['jtitle_name'] = 'Select Job Title';
                             }
                             $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                             $data['position_name'] = $pos_data[$data['position_id']];
                             $emptype_options = $requi_model->getStatusOptionsForRequi();
                             if (isset($emptype_options[$data['emp_type']])) {
                                 $data['emptype_name'] = $emptype_options[$data['emp_type']];
                             } else {
                                 $data['emptype_name'] = 'Select Employment Status';
                             }
                             $report_manager_data = $user_model->getUserDataById($data['reporting_id']);
                             $data['mngrname'] = $report_manager_data['userfullname'];
                             $elements = $form->getElements();
                             if (count($elements) > 0) {
                                 foreach ($elements as $key => $element) {
                                     $element->setRequired(false);
                                 }
                             }
                             if ($data['appstatus1'] == 'Approved') {
                                 $edit_order = 1;
                                 $app1_opt = $user_model->getUserDataById($data['approver1']);
                                 $data_m['approver1'] = $app1_opt['userfullname'];
                                 $report_manager_options = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                                 $app2_options = array();
                                 foreach ($report_manager_options as $app1) {
                                     if ($app1['id'] != $loginUserId && $app1['id'] != $data['approver1']) {
                                         $approver2_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                     }
                                 }
                                 $form->setDefault('approver1', $data['approver1']);
                                 $form->approver2->clearMultiOptions();
                                 $form->setDefault('approver2', $data['approver2']);
                                 if ($data['approver2'] != '') {
                                     $app3_options = array();
                                     foreach ($report_manager_options as $app1) {
                                         if ($app1['id'] != $loginUserId && $app1['id'] != $data['approver1'] && $app1['id'] != $data['approver2']) {
                                             $approver3_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                         }
                                     }
                                     $form->approver3->clearMultiOptions();
                                     $form->setDefault('approver3', $data['approver3']);
                                 }
                             }
                             if ($data['appstatus2'] == 'Approved') {
                                 $edit_order = 2;
                                 $app2_opt = $user_model->getUserDataById($data['approver2']);
                                 $data_m['approver2'] = $app2_opt['userfullname'];
                                 $report_manager_options = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                                 $app3_options = array();
                                 foreach ($report_manager_options as $app1) {
                                     if ($app1['id'] != $loginUserId && $app1['id'] != $data['approver1'] && $app1['id'] != $data['approver2']) {
                                         $app3_options[$app1['id']] = ucwords($app1['name']);
                                     }
                                 }
                                 $form->approver3->clearMultiOptions();
                                 $form->approver3->addMultiOptions(array('' => 'Select Approver -3') + $app3_options);
                                 $form->setDefault('approver3', $data['approver3']);
                             }
                             if ($data['appstatus3'] == 'Approved') {
                                 $edit_order = 3;
                                 $app3_opt = $user_model->getUserDataById($data['approver3']);
                                 $data_m['approver3'] = $app3_opt['userfullname'];
                             }
                         } else {
                             $business_units_list = $requi_model->getBusinessUnitsList();
                             $form->business_unit->addMultiOptions(array('' => 'Select Business Unit') + $business_units_list);
                             $form->setDefault('business_unit', $data['businessunit_id']);
                             $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                             $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                             $form->setDefault('department', $data['department_id']);
                             $job_data = $requi_model->getJobTitleList();
                             $form->jobtitle->addMultiOptions(array('' => 'Select Job Title') + $job_data);
                             $form->setDefault('jobtitle', $data['jobtitle']);
                             $pos_data = $requi_model->getPositionOptions($data['jobtitle']);
                             $form->position_id->addMultiOptions(array('' => 'Select Position') + $pos_data);
                             $form->setDefault('position_id', $data['position_id']);
                             $emptype_options = $requi_model->getStatusOptionsForRequi();
                             $form->emp_type->addMultiOptions(array('' => 'Select Employment Status') + $emptype_options);
                             $form->requisition_code->setValue($data['requisition_code']);
                             $form->req_status->addMultiOptions(array('1' => 'Initiated'));
                             if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
                                 if ($loginuserGroup == '') {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', $loginUserId, '', $data['department_id'], 'requisition');
                                 } else {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', '', '', $data['department_id'], 'requisition');
                                 }
                                 if (isset($_POST['business_unit']) && $_POST['business_unit'] != '') {
                                     $departments_list = $requi_model->getDepartmentList($_POST['business_unit']);
                                     $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                                 }
                                 if (isset($_POST['department']) && $_POST['department'] != '') {
                                     $reportingManagerData = $requi_model->getReportingmanagers('', $loginUserId, '', $_POST['department'], 'requisition');
                                 }
                                 $form->setDefault('reporting_id', $data['reporting_id']);
                                 $form->setDefault('req_status', $data['req_status']);
                                 $form->req_status->setAttrib("disabled", "disabled");
                                 if ($loginuserGroup == HR_GROUP) {
                                     $departments_list = $requi_model->getDepartmentList($sess_vals->businessunit_id);
                                     $data_m['bunit_data']['id'] = $sess_vals->businessunit_id;
                                     $data_m['bunit_data']['name'] = $business_units_list[$sess_vals->businessunit_id];
                                     $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                                 }
                             } else {
                                 $report_manager_options = $user_model->getUserDataById($data['reporting_id']);
                                 $departments_list = $requi_model->getDepartmentList($data['businessunit_id']);
                                 $data_m['manager_data']['id'] = $data['reporting_id'];
                                 $data_m['manager_data']['name'] = $report_manager_options['userfullname'];
                                 $data_m['bunit_data']['id'] = $data['businessunit_id'];
                                 $data_m['bunit_data']['name'] = $business_units_list[$data['businessunit_id']];
                                 $data_m['dept_data']['id'] = $data['department_id'];
                                 $data_m['dept_data']['name'] = $departments_list[$data['department_id']];
                                 $form->setDefault('req_status', $data['req_status']);
                                 $form->req_status->setAttrib("disabled", "disabled");
                             }
                             //start of approvers options
                             $approver_opt = $requi_model->getapprovers($data['reporting_id'], $data['department_id']);
                             $app1_opt = array();
                             $app2_opt = array();
                             $app3_opt = array();
                             if (count($approver_opt) > 0 && count($_POST) == 0) {
                                 foreach ($approver_opt as $app1) {
                                     $approver1_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                 }
                                 foreach ($approver_opt as $app1) {
                                     if ($app1['id'] != $data['approver1']) {
                                         $approver2_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                     }
                                 }
                                 foreach ($approver_opt as $app1) {
                                     if ($app1['id'] != $data['approver1'] && $app1['id'] != $data['approver2']) {
                                         $approver3_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                     }
                                 }
                                 if ($data['approver2'] == '') {
                                     $approver3_opt = array();
                                 }
                             }
                             //end of approvers options
                             foreach ($data as $key => $val) {
                                 $data[$key] = htmlentities(addslashes($val), ENT_QUOTES, "UTF-8");
                             }
                             $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                             $form->populate($data);
                             if (isset($_POST['business_unit']) && $_POST['business_unit'] != '') {
                                 $departments_list = $requi_model->getDepartmentList($_POST['business_unit']);
                                 $form->department->clearMultiOptions();
                                 $form->department->addMultiOptions(array('' => 'Select Department') + $departments_list);
                             }
                             if (isset($_POST['jobtitle']) && $_POST['jobtitle'] != '') {
                                 $pos_data = $requi_model->getPositionOptions($_POST['jobtitle']);
                                 $form->position_id->clearMultiOptions();
                                 $form->position_id->addMultiOptions(array('' => 'Select Position') + $pos_data);
                             }
                             if (isset($_POST['reporting_id']) && $_POST['reporting_id'] != '') {
                                 $app1_data = $requi_model->getapprovers($_POST['reporting_id'], $_POST['department']);
                                 $app1_opt = array();
                                 if (count($app1_data) > 0) {
                                     foreach ($app1_data as $app1) {
                                         $app1_opt[$app1['id']] = ucwords($app1['name']);
                                         $approver1_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                     }
                                     $form->reporting_id->setValue($_POST['reporting_id']);
                                 }
                             }
                             if (isset($_POST['approver1']) && $_POST['approver1'] != '') {
                                 $app1_data = $requi_model->getapprovers($_POST['reporting_id'], $_POST['department']);
                                 $app1_opt = array();
                                 if (count($app1_data) > 0) {
                                     foreach ($app1_data as $app1) {
                                         if ($app1['id'] != $_POST['approver1']) {
                                             $approver2_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                         }
                                     }
                                     $form->approver1->setValue($_POST['approver1']);
                                 }
                             }
                             if (isset($_POST['approver2']) && $_POST['approver2'] != '') {
                                 $app1_data = $requi_model->getapprovers($_POST['reporting_id'], $_POST['department']);
                                 $app1_opt = array();
                                 if (count($app1_data) > 0) {
                                     foreach ($app1_data as $app1) {
                                         if ($app1['id'] != $_POST['approver1'] && $app1['id'] != $_POST['approver2']) {
                                             $approver3_opt[] = array('id' => $app1['id'], 'name' => ucwords($app1['name']), 'profileimg' => $app1['profileimg']);
                                         }
                                     }
                                     $form->approver2->setValue($_POST['approver2']);
                                 }
                             }
                             if (isset($_POST['approver3']) && $_POST['approver3'] != '') {
                                 $form->approver3->setValue($_POST['approver3']);
                             }
                         }
                     }
                     //end of else of aflag.
                     $this->view->loginuserGroup = $loginuserGroup;
                     $this->view->form = $form;
                     $this->view->data = $data;
                     $this->view->data_m = $data_m;
                     $this->view->aflag = $aflag;
                     $this->view->aorder = $aorder;
                     $this->view->edit_flag = $edit_flag;
                     $this->view->edit_order = $edit_order;
                     $this->view->reportingManagerData = $reportingManagerData;
                     $this->view->approver1_opt = $approver1_opt;
                     $this->view->approver2_opt = $approver2_opt;
                     $this->view->approver3_opt = $approver3_opt;
                     if ($this->getRequest()->getPost()) {
                         $result = $this->save($form, $data);
                         $this->view->msgarray = $result;
                         $this->view->messages = $result;
                     }
                     $this->view->ermsg = '';
                 } else {
                     $this->view->nodata = 'nodata';
                 }
             } else {
                 $this->view->nodata = 'nodata';
             }
         } else {
             $this->view->nodata = 'nodata';
         }
         // To check whether to display Employment Status configuration link or not
         $employmentstatusmodel = new Default_Model_Employmentstatus();
         $activeEmploymentStatusArr = $employmentstatusmodel->getEmploymentStatuslist();
         $this->view->job_title_permission = $job_title_permission;
         $this->view->positions_permission = $positions_permission;
         $this->view->emp_status_permission = $emp_status_permission;
     } catch (Exception $e) {
         $this->view->nodata = 'nodata';
     }
 }
 public function addpopupAction()
 {
     $screenFlag = "";
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->getRequest()->getParam('id');
     if ($this->getRequest()->getParam('screenflag')) {
         $screenFlag = $this->getRequest()->getParam('screenflag');
     }
     $boxid = $this->_getParam('boxid', null);
     $fromcontroller = $this->_getParam('fromcontroller', null);
     $msgarray = array();
     $controllername = 'employmentstatus';
     $employmentstatusform = new Default_Form_employmentstatus();
     $employmentstatusmodel = new Default_Model_Employmentstatus();
     $employmentstatusform->setAction(BASE_URL . 'employmentstatus/addpopup');
     $activeEmploymentStatusArr = $employmentstatusmodel->getEmploymentStatuslist();
     $newarr = array();
     $empstatusstr = '';
     if (!empty($activeEmploymentStatusArr)) {
         for ($i = 0; $i < sizeof($activeEmploymentStatusArr); $i++) {
             $newarr1[] = $activeEmploymentStatusArr[$i]['workcodename'];
         }
         if ($screenFlag == 'add') {
             array_push($newarr1, 8, 9, 10);
         }
         $empstatusstr = implode(",", $newarr1);
     }
     if ($empstatusstr != '') {
         $statusArr = $employmentstatusmodel->getStatuslist($empstatusstr);
     } else {
         $statusArr = $employmentstatusmodel->getCompleteStatuslist();
     }
     if (!empty($statusArr)) {
         $employmentstatusform->workcodename->addMultiOption('', 'Select Work Code');
         for ($i = 0; $i < sizeof($statusArr); $i++) {
             if ($fromcontroller == 'requisition') {
                 if (!in_array($statusArr[$i]['id'], array(5, 7, 8, 9, 10))) {
                     $employmentstatusform->workcodename->addMultiOption($statusArr[$i]['id'], utf8_encode($statusArr[$i]['employemnt_status']));
                 }
             } else {
                 $employmentstatusform->workcodename->addMultiOption($statusArr[$i]['id'], utf8_encode($statusArr[$i]['employemnt_status']));
             }
         }
     }
     $this->view->statusArr = $statusArr;
     $this->view->ermsg = '';
     if ($this->getRequest()->getPost()) {
         if ($employmentstatusform->isValid($this->_request->getPost())) {
             $id = $this->_request->getParam('id');
             $workcode = $this->_request->getParam('workcode');
             $workcodename = $this->_request->getParam('workcodename');
             $default_leaves = $this->_request->getParam('default_leaves');
             $description = $this->_request->getParam('description');
             $screenFlag = $this->getRequest()->getParam('screenflag');
             $date = new Zend_Date();
             $actionflag = '';
             $tableid = '';
             $data = array('workcode' => trim($workcode), 'workcodename' => trim($workcodename), 'description' => trim($description), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($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;
             }
             $Id = $employmentstatusmodel->SaveorUpdateEmploymentStatusData($data, $where);
             $tableid = $Id;
             $menuID = EMPLOYMENTSTATUS;
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             $this->view->eventact = 'added';
             $close = 'close';
             $this->view->popup = $close;
             if (isset($_POST['fromcontroller']) && $_POST['fromcontroller'] != '') {
                 $fromcontroller = $_POST['fromcontroller'];
             }
             if (isset($_POST['boxid']) && $_POST['boxid'] != '') {
                 $boxid = $_POST['boxid'];
             }
         } else {
             $messages = $employmentstatusform->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             $this->view->msgarray = $msgarray;
         }
     }
     $opt = '';
     if ($fromcontroller == '') {
         if ($screenFlag == 'edit') {
             $empstatusData = $employmentstatusmodel->getempstatuslist();
         }
         if ($screenFlag == 'add') {
             $empstatusData = $employmentstatusmodel->getempstatusActivelist();
         }
         if (!empty($empstatusData)) {
             foreach ($empstatusData as $record) {
                 $opt .= sapp_Global::selectOptionBuilder($record['workcodename'], $record['statusname']);
             }
         }
     } else {
         if ($fromcontroller == 'requisition') {
             $requi_model = new Default_Model_Requisition();
             $empstatusData = $requi_model->getStatusOptionsForRequi();
             foreach ($empstatusData as $stat_id => $stat_name) {
                 $opt .= sapp_Global::selectOptionBuilder($stat_id, $stat_name);
             }
         }
     }
     $this->view->empstatusData = $opt;
     $this->view->screenFlag = $screenFlag;
     $this->view->controllername = $controllername;
     $this->view->form = $employmentstatusform;
     $this->view->ermsg = '';
     $this->view->boxid = $boxid;
     $this->view->fromcontroller = $fromcontroller;
 }