/**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of candidate (optional)
  * 
  * @return Zend_Form.
  */
 public function editAction()
 {
     $req_model = new Default_Model_Requisition();
     $jobtitleModel = new Default_Model_Jobtitles();
     $cand_model = new Default_Model_Candidatedetails();
     $candwork_model = new Default_Model_Candidateworkdetails();
     $country_model = new Default_Model_Countries();
     $role_model = new Default_Model_Roles();
     $auth = Zend_Auth::getInstance();
     $data = array();
     $jobtitle = '';
     $req_data['jobtitlename'] = '';
     $popConfigPermission = array();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     if (sapp_Global::_checkprivileges(COUNTRIES, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'country');
     }
     if (sapp_Global::_checkprivileges(STATES, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'state');
     }
     if (sapp_Global::_checkprivileges(CITIES, $loginuserGroup, $loginuserRole, 'add') == 'Yes') {
         array_push($popConfigPermission, 'city');
     }
     $id = trim($this->getRequest()->getParam('id'));
     if (is_numeric($id) && $id > 0) {
         try {
             $candidateData = $cand_model->getcandidateData($id);
             $form = new Default_Form_Candidatedetails($candidateData['requisition_id']);
             $form->setAction(DOMAIN . 'candidatedetails/edit/id/' . $id);
             $statsflag = 'false';
             if (count($candidateData) > 0) {
                 try {
                     $candidateworkData = $candwork_model->getcandidateworkData($id);
                     $req_data = $req_model->getRequisitionDataById($candidateData['requisition_id']);
                     // To show it on edit view
                     $data['cand_resume'] = isset($candidateData['cand_resume']) ? $candidateData['cand_resume'] : NULL;
                     $data['rec_id'] = isset($id) ? $id : NULL;
                     $data['selected_option'] = $this->_getParam('selected_option');
                     $req_data['jobtitlename'] = '';
                     $jobttlArr = $jobtitleModel->getsingleJobTitleData($req_data['jobtitle']);
                     if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                         $jobtitle = $jobttlArr[0]['jobtitlename'];
                         $req_data['jobtitlename'] = $jobttlArr[0]['jobtitlename'];
                     }
                     if (($req_data['req_status'] == 'Closed' || $req_data['req_status'] == 'On hold' || $req_data['req_status'] == 'Complete') && ($candidateData['cand_status'] == 'Requisition Closed/Completed' || $candidateData['cand_status'] == 'On hold' || $candidateData['cand_status'] == 'Not Scheduled')) {
                         //|| $candidateData['cand_status'] == 'Rejected' || $candidateData['cand_status'] == 'Disqualified'
                         $statsflag = 'true';
                         $reqforcv_data = $req_model->getRequisitionsForCV("'Approved','In process'");
                         $req_options = array();
                         foreach ($reqforcv_data as $req) {
                             $req_options[$req['id']] = $req['requisition_code'] . ' - ' . $req['jobtitlename'];
                         }
                         $form->requisition_id->addMultiOptions(array('' => 'Select Requisition ID') + $req_options);
                         $form->cand_status->addMultiOption('', 'Select Status');
                         $form->cand_status->addMultiOption('Not Scheduled', 'Not Scheduled');
                     }
                     $countryId = $candidateData['country'];
                     if (isset($_POST['country'])) {
                         $countryId = $_POST['country'];
                     }
                     $stateId = $candidateData['state'];
                     if (isset($_POST['state'])) {
                         $stateId = $_POST['state'];
                     }
                     $cityId = $candidateData['city'];
                     if (isset($_POST['city'])) {
                         $cityId = $_POST['city'];
                     }
                     if ($countryId != '') {
                         $statesmodel = new Default_Model_States();
                         $statesData = $statesmodel->getStatesList($countryId);
                         foreach ($statesData as $res) {
                             $form->state->addMultiOption($res['id'], utf8_encode($res['state_name']));
                         }
                         $form->setDefault('country', $countryId);
                     }
                     if ($stateId != '') {
                         $citiesmodel = new Default_Model_Cities();
                         $citiesData = $citiesmodel->getCitiesList($stateId);
                         foreach ($citiesData as $res) {
                             $form->city->addMultiOption($res['id'], utf8_encode($res['city_name']));
                         }
                         $form->setDefault('state', $stateId);
                     }
                     $form->setDefault('city', $cityId);
                     $form->setDefault('job_title', $jobtitle);
                     $countrieslistArr = $country_model->getTotalCountriesList();
                     if (sizeof($countrieslistArr) > 0) {
                         $form->country->addMultiOption('', 'Select Country');
                         foreach ($countrieslistArr as $countrieslistres) {
                             $form->country->addMultiOption($countrieslistres['id'], utf8_encode($countrieslistres['country_name']));
                         }
                     } else {
                         $msgarray['country'] = 'Countries are not configured yet';
                     }
                     $data['requisition_code'] = $req_data['requisition_code'];
                     $data['requisition_id'] = $req_data['id'];
                     $data['jobtitlename'] = $req_data['jobtitlename'];
                     if ($id) {
                         $form->submit->setLabel('Update');
                         foreach ($candidateData as $key => $val) {
                             $candidateData[$key] = htmlentities(addslashes($val), ENT_QUOTES, "UTF-8");
                         }
                         $form->populate($candidateworkData);
                         $form->populate($candidateData);
                     }
                     $this->view->candidate_data = $candidateData;
                     $this->view->form = $form;
                     $this->view->workdata = $candidateworkData;
                     $this->view->data = $data;
                     $this->view->popConfigPermission = $popConfigPermission;
                     $this->view->statsflag = $statsflag;
                     $this->view->ermsg = '';
                     if ($this->getRequest()->getPost()) {
                         $result = $this->save($form);
                         $this->view->msgarray = $result;
                         $this->view->messages = $result;
                     }
                 } catch (Exception $e) {
                     $this->view->ermsg = 'nodata';
                 }
             } else {
                 $this->view->ermsg = 'nodata';
             }
         } catch (Exception $e) {
             $this->view->ermsg = 'nodata';
         }
     } else {
         $this->view->ermsg = 'nodata';
     }
 }
 /**
  * 
  * @param type $form
  * @param type $data
  * @return type
  */
 public function save($form, $data)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $cand_model = new Default_Model_Candidatedetails();
     $requi_model = new Default_Model_Requisition();
     $interview_model = new Default_Model_Interviewdetails();
     $user_model = new Default_Model_Usermanagement();
     $interview_round_model = new Default_Model_Interviewrounddetails();
     $form->round_status->setRequired(false);
     $form->interview_feedback->setRequired(false);
     $cand_status = $this->_getParam('cand_status', null);
     $interview_status = $this->_getParam('interview_status', null);
     $flag = 'true';
     if ($interview_status == 'On hold' && $cand_status != 'On hold') {
         $msgarray['statusErr'] = 'Since the interview status is onhold, the candidate status should be onhold.';
         $flag = 'false';
     }
     if ($interview_status == 'Completed' && ($cand_status != 'Disqualified' && $cand_status != 'Shortlisted')) {
         $msgarray['statusErr'] = 'Since interview status is completed, the candidate status can be either disqualified or shortlisted.';
         $flag = 'false';
     }
     if ($interview_status == 'In process' && ($cand_status == 'Disqualified' || $cand_status == 'Shortlisted')) {
         $msgarray['statusErr'] = 'Since the interview status is in process, the candidate cannot be shortlisted or disqualified.';
         $flag = 'false';
     }
     if ($form->isValid($this->_request->getPost()) && $flag != 'false') {
         $id = $this->_getParam('id', null);
         $requisition_id = $this->_getParam('req_id', null);
         $candidate_id = $this->_getParam('candidate_name', null);
         $interviewer_ids = $this->_getParam('interviewer_id', null);
         $interview_panel = implode(",", $interviewer_ids);
         $interviewer_id = 0;
         foreach ($interviewer_ids as $interview) {
             $interviewer_id = $interview;
             break;
         }
         $int_location = $this->_getParam('int_location', null);
         $country = $this->_getParam('country', null);
         $state = $this->_getParam('state', null);
         $city = $this->_getParam('city', null);
         $interview_mode = $this->_getParam('interview_mode', null);
         $interview_type_details = $this->_getParam('interview_Type_Details', null);
         $interview_time = $this->_getParam('interview_time', null);
         $interview_date = $this->_getParam('interview_date', null);
         $interview_round = $this->_getParam('interview_round', null);
         if (!isset($candidate_id)) {
             $candidate_id = $data['id'];
         }
         if (empty($data)) {
             $getExistingCandidateRecord = $interview_model->getCandidateInInterviewProcess(trim($candidate_id));
             if ($getExistingCandidateRecord > 0) {
                 $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Interview already scheduled for this candidate.');
                 $this->_redirect('/scheduleinterviews');
             }
         }
         if (empty($data)) {
             $idata = array('req_id' => $requisition_id, 'candidate_id' => trim($candidate_id), 'interview_status' => trim($interview_status), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $idata['interview_status'] = 'In process';
             $iwhere = "";
             $actionflag = 1;
             $iresult = $interview_model->SaveorUpdateInterviewData($idata, $iwhere);
             if ($id == '') {
                 $tableid = $iresult;
             }
             if ($iresult != '') {
                 $irdata = array('interview_id' => $iresult, 'req_id' => $requisition_id, 'candidate_id' => $candidate_id, 'interviewer_id' => $interviewer_id, 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date($interview_date, 'database'), 'interview_mode' => $interview_mode, 'interview_mode_details' => $interview_type_details, 'interview_round_number' => 1, 'interview_round' => trim($interview_round), 'int_location' => trim($int_location), 'int_country' => trim(intval($country)), 'int_state' => trim(intval($state)), 'int_city' => trim(intval($city)), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"), 'interview_panel' => $interview_panel);
                 $ir_result = $interview_round_model->SaveorUpdateInterviewroundData($irdata, '');
                 $requisition_data = $requi_model->getRequisitionDataById($requisition_id);
                 $cand_data = $cand_model->getCandidateById($candidate_id);
                 $hrgroupemail = $requi_model->getgroupemailid("REQ_HR", $requisition_data["department_id"]);
                 $requisition_data = $requi_model->getrequisitiondetails($requisition_id);
                 $requesteremailaddress = $requi_model->getemployeeemailaddress($requisition_data["createdby"]);
                 $reportingmanageremailaddress = $requi_model->getemployeeemailaddress($requisition_data["reporting_id"]);
                 $mail_arr = array('HR' => $hrgroupemail["groupEmail"], $requesteremailaddress['userfullname'] => $requesteremailaddress['emailaddress'], $reportingmanageremailaddress['userfullname'] => $reportingmanageremailaddress['emailaddress']);
                 $loginuser_person_data = $user_model->getUserDataById($loginUserId);
                 $interview_panel = $interview_panel . "," . $loginUserId;
                 $interviewpanelnamesemailaddresss = $requi_model->GetInterviewPanelMamesEmailaddress($interview_panel);
                 /* $emailtemp = array();
                    $nametemp = array();
                    foreach ($interviewpanelnamesemailaddress as $row) {
                    array_push($emailtemp, $row['emailaddress']);
                    array_push($nametemp, $row['userfullname']);
                    }
                    $email = implode(";", $emailtemp);
                    $ename = implode(";", $nametemp); */
                 $cal_unique_id = $this->getCalendarUniqueID();
                 foreach ($interviewpanelnamesemailaddresss as $interviewpanelnamesemailaddress) {
                     $description = "Meeting From : " . $from_name . "\r\n" . "Candidate Name : " . $cand_data['candidate_name'] . "\r\n" . "Interview Type : " . $interview_mode . "\r\n" . "Interview Location : " . $int_location . "\r\n" . "Interview Date : " . $interview_date . "\r\n" . "Interview Time : " . sapp_Global::change_time($interview_time, 'view') . "\r\n" . " " . " " . "\r\n";
                     /* $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                                               $options['subject'] = APPLICATION_NAME . ': Interview schedule';
                                               $options['header'] = 'Interview schedule';
                                               $options['toEmail'] = $interviewpanelnamesemailaddress['emailaddress'];
                                               $options['toName'] = $interviewpanelnamesemailaddress['userfullname'];
                                               $options['message'] = $description;
                                               $options['location'] = $int_location;
                                               $options['interviewdate'] = $interview_date;
                                               $options['starttime'] = sapp_Global::add_time($interview_time, 'view', 0);
                                               $options['endtime'] = sapp_Global::add_time($interview_time, 'view', 3600);
                     
                                               //Interview Calendar Invite will be send from login user account
                                               $options['fromEmail'] = trim($loginuser_person_data['emailaddress']);
                                               $options['fromName'] = $loginuser_person_data['userfullname'];
                                               $options['calUniqueID'] = $cal_unique_id;
                                               $options['method'] = 'REQUEST';
                     
                                               //sapp_Global::_sendCalendarEmail($options); */
                     $from_name = trim($loginuser_person_data['userfullname']);
                     $from_address = trim($loginuser_person_data['emailaddress']);
                     $to_name = trim($interviewpanelnamesemailaddress['userfullname']);
                     $to_address = trim($interviewpanelnamesemailaddress['emailaddress']);
                     $startTime = sapp_Global::_getInterviewStartDateTime(sapp_Global::change_date($interview_date), sapp_Global::change_time(trim($interview_time)), 3600);
                     $endTime = sapp_Global::_getInterviewStartDateTime(sapp_Global::change_date($interview_date), sapp_Global::change_time(trim($interview_time)));
                     $subject = APPLICATION_NAME . ': Interview schedule';
                     $location = $int_location;
                     $calRequest = 'REQUEST';
                     sapp_Global::sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $calRequest, $cal_unique_id);
                 }
                 // update Calendar Invite ID to DB
                 $where = "id = " . $ir_result;
                 $irdata = array('calendarinviteid' => $cal_unique_id);
                 $ir_result1 = $interview_round_model->SaveorUpdateInterviewroundData($irdata, $where);
                 $candData = array('cand_status' => 'Scheduled', 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $where = "id = " . $candidate_id;
                 $candResult = $cand_model->SaveorUpdateCandidateData($candData, $where);
             }
         } else {
             $idata = array('interview_status' => trim($interview_status), 'isactive' => 1, 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $iwhere = "id = " . $id;
             $tableid = $id;
             $actionflag = 2;
             $iresult = $interview_model->SaveorUpdateInterviewData($idata, $iwhere);
             $candData = array('cand_status' => 'Scheduled', 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($cand_status && $cand_status != '0') {
                 $candData['cand_status'] = $cand_status;
             }
             $where = "id = " . $candidate_id;
             $candResult = $cand_model->SaveorUpdateCandidateData($candData, $where);
             //send email
             $currentInterviewData = $requi_model->getinterviewdetails($id);
             $requisition_data = $requi_model->getrequisitiondetails($currentInterviewData["req_id"]);
             $currentrequisition_data = $requi_model->getrequisitiondetails($currentInterviewData["req_id"]);
             $cand_data = $cand_model->getCandidateById($candidate_id);
             //$hrgroupemail = $requi_model->getgroupemailid("REQ_HR", $requisition_data["department_id"]);
             $requesteremailaddress = $requi_model->getemployeeemailaddress($requisition_data["createdby"]);
             $reportingmanageremailaddress = $requi_model->getemployeeemailaddress($requisition_data["reporting_id"]);
             //HR Group
             $mail_arr[0]['name'] = 'HR';
             $mail_arr[0]['email'] = constant('REQ_HR_0');
             //Requester
             $mail_arr[1]['name'] = $requesteremailaddress['userfullname'];
             $mail_arr[1]['email'] = $requesteremailaddress['emailaddress'];
             //Reporting Manager
             $mail_arr[2]['name'] = $reportingmanageremailaddress['userfullname'];
             $mail_arr[2]['email'] = $reportingmanageremailaddress['emailaddress'];
             //Management Group
             $mail_arr[3]['name'] = 'Management';
             $mail_arr[3]['email'] = constant('REQ_MGMT_0');
             //Recruiter Panel
             $requisition_recruiters_data = $requi_model->GetRequisitionRecruiterEmailaddress($currentrequisition_data["requisition_code"]);
             $emailCnt = 4;
             foreach ($requisition_recruiters_data as $requisition_recruiters_data1) {
                 $mail_arr[$emailCnt]['name'] = $requisition_recruiters_data1['userfullname'];
                 $mail_arr[$emailCnt]['email'] = $requisition_recruiters_data1['emailaddress'];
                 $emailCnt = $emailCnt + 1;
             }
             //Technical Panel
             $pnlIDS = implode(',', $requi_model->getRequisitionInterviewPanelIDs($currentInterviewData["req_id"]));
             $interviewpanelnamesemailaddresss = $requi_model->GetInterviewPanelMamesEmailaddress($pnlIDS);
             foreach ($interviewpanelnamesemailaddresss as $interviewpanelnamesemailaddress1) {
                 $mail_arr[$emailCnt]['name'] = $interviewpanelnamesemailaddress1['userfullname'];
                 $mail_arr[$emailCnt]['email'] = $interviewpanelnamesemailaddress1['emailaddress'];
                 $emailCnt = $emailCnt + 1;
             }
             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->type = 'InterviewSummary';
                 $this->view->requisition_data = $currentrequisition_data;
                 $this->view->candidate_details = $cand_data;
                 $this->view->round_data = $currentInterviewData;
                 $this->view->base_url = $base_url;
                 $text = $view->render('mailtemplates/requisition.phtml');
                 $options['subject'] = APPLICATION_NAME . ': Interview feedback';
                 //$options['header'] = 'Interview feedback';
                 $options['toEmail'] = $mail_arr[$ii]['email'];
                 $options['toName'] = $mail_arr[$ii]['name'];
                 $options['message'] = $text;
                 sapp_Global::_sendEmail($options, "interviewrounds_feedback", REQUISITIONMODULESENDEMAIL);
             }
         }
         $menumodel = new Default_Model_Menu();
         $objidArr = $menumodel->getMenuObjID('/scheduleinterviews');
         $objID = $objidArr[0]['id'];
         $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
         if ($id == '') {
             $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Interview scheduled successfully.');
         } else {
             $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Interview details updated successfully.');
         }
         $this->_redirect('/scheduleinterviews');
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 public function chkreqforcloseAction()
 {
     $req_id = $this->_getParam('req_id', null);
     $requ_model = new Default_Model_Requisition();
     $req_data = $requ_model->getRequisitionDataById($req_id);
     if ($req_data['req_no_positions'] == $req_data['filled_positions']) {
         $result = 'yes';
     } else {
         $result = 'no';
     }
     $this->_helper->_json(array('result' => $result));
 }
 public function save($form, $data)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $cand_model = new Default_Model_Candidatedetails();
     $requi_model = new Default_Model_Requisition();
     $interview_model = new Default_Model_Interviewdetails();
     $user_model = new Default_Model_Usermanagement();
     $interview_round_model = new Default_Model_Interviewrounddetails();
     $cand_status = $this->_getParam('cand_status', null);
     $interview_status = $this->_getParam('interview_status', null);
     $flag = 'true';
     if ($interview_status == 'On hold' && $cand_status != 'On hold') {
         $msgarray['statusErr'] = 'Since the interview status is onhold, the candidate status should be onhold.';
         $flag = 'false';
     }
     if ($interview_status == 'Completed' && ($cand_status != 'Disqualified' && $cand_status != 'Shortlisted')) {
         $msgarray['statusErr'] = 'Since interview status is completed, the candidate status can be either disqualified or shortlisted.';
         $flag = 'false';
     }
     if ($interview_status == 'In process' && ($cand_status == 'Disqualified' || $cand_status == 'Shortlisted')) {
         $msgarray['statusErr'] = 'Since the interview status is in process, the candidate cannot be shortlisted or disqualified.';
         $flag = 'false';
     }
     if ($form->isValid($this->_request->getPost()) && $flag != 'false') {
         $id = $this->_getParam('id', null);
         $requisition_id = $this->_getParam('req_id', null);
         $candidate_id = $this->_getParam('candidate_name', null);
         $interviewer_id = $this->_getParam('interviewer_id', null);
         $int_location = $this->_getParam('int_location', null);
         $country = $this->_getParam('country', null);
         $state = $this->_getParam('state', null);
         $city = $this->_getParam('city', null);
         $interview_mode = $this->_getParam('interview_mode', null);
         $interview_time = $this->_getParam('interview_time', null);
         $interview_date = $this->_getParam('interview_date', null);
         $interview_round = $this->_getParam('interview_round', null);
         if (!isset($candidate_id)) {
             $candidate_id = $data['id'];
         }
         if (empty($data)) {
             $getExistingCandidateRecord = $interview_model->getCandidateInInterviewProcess(trim($candidate_id));
             if ($getExistingCandidateRecord > 0) {
                 $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Interview already scheduled for this candidate.');
                 $this->_redirect('/scheduleinterviews');
             }
         }
         if (empty($data)) {
             $idata = array('req_id' => $requisition_id, 'candidate_id' => trim($candidate_id), 'interview_status' => trim($interview_status), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $idata['interview_status'] = 'In process';
             $iwhere = "";
             $actionflag = 1;
             $iresult = $interview_model->SaveorUpdateInterviewData($idata, $iwhere);
             if ($id == '') {
                 $tableid = $iresult;
             }
             if ($iresult != '') {
                 $irdata = array('interview_id' => $iresult, 'req_id' => $requisition_id, 'candidate_id' => $candidate_id, 'interviewer_id' => $interviewer_id, 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date($interview_date, 'database'), 'interview_mode' => $interview_mode, 'interview_round_number' => 1, 'interview_round' => trim($interview_round), 'int_location' => trim($int_location), 'int_country' => trim(intval($country)), 'int_state' => trim(intval($state)), 'int_city' => trim(intval($city)), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $ir_result = $interview_round_model->SaveorUpdateInterviewroundData($irdata, '');
                 $requisition_data = $requi_model->getRequisitionDataById($requisition_id);
                 $cand_data = $cand_model->getCandidateById($candidate_id);
                 $report_person_data = $user_model->getUserDataById($interviewer_id);
                 $mail_arr = array('HR' => defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "", $report_person_data['userfullname'] => $report_person_data['emailaddress']);
                 foreach ($mail_arr as $ename => $email) {
                     $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                     $view = $this->getHelper('ViewRenderer')->view;
                     $this->view->emp_name = $ename;
                     $this->view->base_url = $base_url;
                     $this->view->candidate_name = $cand_data['candidate_name'];
                     $this->view->interview_type = $interview_mode;
                     $this->view->interview_location = $int_location;
                     $this->view->interview_date = $interview_date;
                     $this->view->interview_time = sapp_Global::change_time($interview_time, 'view');
                     $this->view->requisition_code = $requisition_data['requisition_code'];
                     $text = $view->render('mailtemplates/interviewrounds.phtml');
                     $options['subject'] = APPLICATION_NAME . ': Interview schedule';
                     $options['header'] = 'Interview schedule';
                     $options['toEmail'] = $email;
                     $options['toName'] = $ename;
                     $options['message'] = $text;
                     $options['cron'] = 'yes';
                     sapp_Global::_sendEmail($options);
                 }
                 $candData = array('cand_status' => 'Scheduled', 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 $where = "id = " . $candidate_id;
                 $candResult = $cand_model->SaveorUpdateCandidateData($candData, $where);
             }
         } else {
             $idata = array('interview_status' => trim($interview_status), 'isactive' => 1, 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $iwhere = "id = " . $id;
             $tableid = $id;
             $actionflag = 2;
             $iresult = $interview_model->SaveorUpdateInterviewData($idata, $iwhere);
             $candData = array('cand_status' => 'Scheduled', 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($cand_status && $cand_status != '0') {
                 $candData['cand_status'] = $cand_status;
             }
             $where = "id = " . $candidate_id;
             $candResult = $cand_model->SaveorUpdateCandidateData($candData, $where);
         }
         $menumodel = new Default_Model_Menu();
         $objidArr = $menumodel->getMenuObjID('/scheduleinterviews');
         $objID = $objidArr[0]['id'];
         $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
         if ($id == '') {
             $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Interview scheduled successfully.');
         } else {
             $this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Interview details updated successfully.');
         }
         $this->_redirect('/scheduleinterviews');
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 public function editAction()
 {
     $id = $this->getRequest()->getParam('id');
     $data = array();
     $jobtitle = '';
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $form = new Default_Form_Requisition();
     $requi_model = new Default_Model_Requisition();
     $user_model = new Default_Model_Usermanagement();
     $jobtitleModel = new Default_Model_Jobtitles();
     $form->setAttrib('action', BASE_URL . 'approvedrequisitions/edit/id/' . $id);
     $form->submit->setLabel('Update');
     $elements = $form->getElements();
     if (count($elements) > 0) {
         foreach ($elements as $key => $element) {
             if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments" && $key != "submit" && $key != 'req_status' && $key != 'onboard_date') {
                 $form->removeElement($key);
             }
         }
     }
     try {
         if ($id > 0 && is_numeric($id)) {
             $data = $requi_model->getRequisitionDataById($id);
             if (count($data) > 0 && $data['req_status'] != 'Initiated' && $data['req_status'] != 'Rejected') {
                 $data['jobtitlename'] = '';
                 $business_units_list = $requi_model->getBusinessUnitsList($data['businessunit_id']);
                 $data['businessunit_name'] = $business_units_list['unitname'];
                 $departments_list = $requi_model->getDepartmentList($data['businessunit_id'], $data['department_id']);
                 $data['dept_name'] = $departments_list['deptname'];
                 $job_data = $requi_model->getJobTitleList($data['jobtitle']);
                 $data['titlename'] = $job_data['jobtitlename'];
                 $pos_data = $requi_model->getPositionOptions($data['jobtitle'], $data['position_id']);
                 $data['posname'] = $pos_data['positionname'];
                 $emptype_options = $requi_model->getEmpStatusOptions($data['emp_type']);
                 $data['empttype'] = $emptype_options['employemnt_status'];
                 $report_manager_options = $user_model->getUserDataById($data['reporting_id']);
                 $data['mngrname'] = $report_manager_options['userfullname'];
                 $raisedby = $requi_model->getrequisitioncreatername($data['createdby']);
                 $data['raisedby'] = $raisedby['userfullname'];
                 $app1_data = $user_model->getUserDataById($data['approver1']);
                 $data['app1_name'] = $app1_data['userfullname'];
                 if ($data['approver2'] != '') {
                     $app2_data = $user_model->getUserDataById($data['approver2']);
                     $data['app2_name'] = $app2_data['userfullname'];
                 } else {
                     $data['app2_name'] = 'No Approver';
                 }
                 if ($data['approver3'] != '') {
                     $app3_data = $user_model->getUserDataById($data['approver3']);
                     $data['app3_name'] = $app3_data['userfullname'];
                 } else {
                     $data['app3_name'] = 'No Approver';
                 }
                 $jobttlArr = $jobtitleModel->getsingleJobTitleData($data['jobtitle']);
                 if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                     $jobtitle = $jobttlArr[0]['jobtitlename'];
                     $data['jobtitlename'] = $jobttlArr[0]['jobtitlename'];
                 }
                 foreach ($data as $key => $val) {
                     $data[$key] = htmlentities($val, ENT_QUOTES, "UTF-8");
                 }
                 $onboard_date_org = $data['onboard_date'];
                 $data['onboard_date'] = sapp_Global::change_date($data['onboard_date'], 'view');
                 if ($data['req_status'] == 'Approved') {
                     $form->req_status->addMultiOptions(array('Approved' => 'Approved', 'Closed' => 'Closed', 'On hold' => 'On hold', 'Complete' => 'Complete'));
                 } else {
                     if ($data['req_status'] == 'Complete') {
                         $form->req_status->addMultiOptions(array('Complete' => 'Complete'));
                         $form->req_status->setAttrib('disabled', 'disabled');
                         $form->removeElement('submit');
                     } else {
                         $form->req_status->addMultiOptions(array('' => 'Select status', 'Closed' => 'Closed', 'On hold' => 'On hold', 'Complete' => 'Complete', 'In process' => 'In process'));
                     }
                 }
                 $form->req_status->setRequired(true);
                 $form->req_status->addValidator('NotEmpty', false, array('messages' => 'Please select option.'));
                 $form->populate($data);
                 $form->setDefault('req_status', $data['req_status']);
                 $this->view->data = $data;
                 $this->view->loginuserGroup = $loginuserGroup;
                 $this->view->form = $form;
                 $this->view->id = $id;
                 $this->view->edit_duedate = 'no';
                 if ($onboard_date_org < date('Y-m-d') && ($loginuserGroup == HR_GROUP || $loginuserGroup == MANAGEMENT_GROUP || $loginuserGroup == '')) {
                     $this->view->edit_duedate = 'yes';
                 } else {
                     $form->removeElement('onboard_date');
                 }
                 $sort = $this->_getParam('sort') != '' ? $this->_getParam('sort') : 'DESC';
                 $by = $this->_getParam('by') != '' ? $this->_getParam('by') : 'c.createddate';
                 $perPage = $this->_getParam('per_page', 10);
                 $pageNo = $this->_getParam('page', 1);
                 $searchQuery = '';
                 $searchArray = array();
                 $tablecontent = '';
                 /** search from grid - START **/
                 $searchData = $this->_getParam('searchData');
                 if ($searchData != '' && $searchData != 'undefined') {
                     $searchValues = json_decode($searchData);
                     if (count($searchValues) > 0) {
                         foreach ($searchValues as $key => $val) {
                             $searchQuery .= " " . $key . " like '%" . $val . "%' AND ";
                             $searchArray[$key] = $val;
                         }
                         $searchQuery = rtrim($searchQuery, " AND");
                     }
                 }
                 /** search from grid - END **/
                 $objName = 'apprreqcandidates';
                 $tableFields = array('action' => 'Action', 'candidate_name' => 'Candidate Name', 'cand_status' => 'Candidate Status');
                 $candidate_model = new Default_Model_Candidatedetails();
                 $tablecontent = $candidate_model->getCandidatesData_requisition($sort, $by, $pageNo, $perPage, $searchQuery, $id);
                 $cand_status_opt = array('' => 'All', 'Shortlisted' => 'Shortlisted', 'Selected' => 'Selected', 'Rejected' => 'Rejected', 'On hold' => 'On hold', 'Disqualified' => 'Disqualified', 'Scheduled' => 'Scheduled', 'Not Scheduled' => 'Not Scheduled', 'Recruited' => 'Recruited', 'Requisition Closed/Completed' => 'Requisition Closed/Completed');
                 $dataTmp = array('sort' => $sort, 'by' => $by, 'pageNo' => $pageNo, 'perPage' => $perPage, 'tablecontent' => $tablecontent, 'objectname' => $objName, 'extra' => array(), 'tableheader' => $tableFields, 'jsGridFnName' => 'getAjaxgridData', 'jsFillFnName' => '', 'formgrid' => 'true', 'searchArray' => $searchArray, 'menuName' => 'Candidate details', 'call' => '', 'search_filters' => array('cand_status' => array('type' => 'select', 'filter_data' => $cand_status_opt)));
                 array_push($data, $dataTmp);
                 $this->view->dataArray = $dataTmp;
                 if ($this->getRequest()->getPost()) {
                     $result = $this->save($form, $data);
                     $this->view->msgarray = $result;
                     $this->view->messages = $result;
                 }
                 $this->view->nodata = '';
             } else {
                 $this->view->nodata = 'nodata';
             }
         } else {
             $this->view->nodata = 'nodata';
         }
     } catch (Exception $e) {
         $this->view->nodata = 'nodata';
     }
 }
 public function save($form)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $requi_model = new Default_Model_Requisition();
     $round_model = new Default_Model_Interviewrounddetails();
     $intrvwModel = new Default_Model_Interviewdetails();
     $user_model = new Default_Model_Usermanagement();
     $cand_model = new Default_Model_Candidatedetails();
     $intrvwId = $this->getRequest()->getParam('unitId');
     if ($form->isValid($this->_request->getPost())) {
         $reqData = $intrvwModel->getReqByintrvwID($intrvwId);
         if (!empty($reqData)) {
             $reqId = $reqData['req_id'];
             $candid = $reqData['candidate_id'];
             $id = $this->getRequest()->getParam('id');
             $interview_id = $intrvwId;
             $interviewer_id = $this->getRequest()->getParam('interviewer_id');
             $interview_round = $this->getRequest()->getParam('interview_round');
             $interview_mode = $this->getRequest()->getParam('interview_mode');
             $int_location = $this->getRequest()->getParam('int_location');
             $interview_time = $this->getRequest()->getParam('interview_time');
             $interview_date = $this->getRequest()->getParam('interview_date');
             $interview_feedback = $this->getRequest()->getParam('interview_feedback');
             $interview_comments = $this->getRequest()->getParam('interview_comments');
             $round_status = $this->getRequest()->getParam('round_status', null);
             $hid_round_status = $this->getRequest()->getParam('hid_round_status', null);
             $data = array('candidate_id' => $candid, 'req_id' => $reqId, 'interview_id' => trim($intrvwId), 'interviewer_id' => trim($interviewer_id), 'interview_mode' => trim($interview_mode), 'int_location' => trim($int_location), 'int_country' => trim($this->_getParam('country', null)), 'int_state' => trim($this->_getParam('state', null)), 'int_city' => trim($this->_getParam('city', null)), 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date(trim($interview_date), 'database'), 'interview_round' => trim($interview_round), 'interview_feedback' => trim($interview_feedback), 'interview_comments' => trim($interview_comments), 'round_status' => trim($round_status), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
             $roundnumberData = $intrvwModel->getinterviewroundnumber($interview_id);
             $roundnumber = $roundnumberData['interview_round_number'];
             $data['interview_round_number'] = $roundnumber + 1;
             $where = "";
             $actionflag = 1;
             if ($id != '') {
                 unset($data['createdby']);
                 unset($data['createdon']);
                 unset($data['isactive']);
                 unset($data['interview_round_number']);
                 $where = array("id = " . $id);
                 $tableid = $id;
                 $actionflag = 2;
                 if ($hid_round_status != '') {
                     $data = array();
                     $data['round_status'] = trim($round_status);
                 }
             }
             if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP || $loginuserGroup == EMPLOYEE_GROUP || ($loginuserGroup == HR_GROUP || $loginuserGroup == MANAGEMENT_GROUP) && $interviewer_id == $loginUserId) {
                 unset($data['interviewer_id']);
                 unset($data['interview_mode']);
                 unset($data['int_location']);
                 unset($data['int_country']);
                 unset($data['int_state']);
                 unset($data['int_city']);
                 unset($data['interview_time']);
                 unset($data['interview_date']);
                 unset($data['interview_round']);
             }
             $result = $round_model->SaveorUpdateInterviewroundData($data, $where);
             if ($id == '') {
                 //start of mailing
                 $requisition_data = $requi_model->getRequisitionDataById($reqId);
                 $cand_data = $cand_model->getCandidateById($candid);
                 $report_person_data = $user_model->getUserDataById($interviewer_id);
                 $mail_arr = array('HR' => defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "", $report_person_data['userfullname'] => $report_person_data['emailaddress']);
                 foreach ($mail_arr as $ename => $email) {
                     $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                     $view = $this->getHelper('ViewRenderer')->view;
                     $this->view->emp_name = $ename;
                     $this->view->base_url = $base_url;
                     $this->view->candidate_name = $cand_data['candidate_name'];
                     $this->view->interview_type = $interview_mode;
                     $this->view->interview_location = $int_location;
                     $this->view->interview_date = $interview_date;
                     $this->view->interview_time = sapp_Global::change_time($interview_time, 'view');
                     $this->view->requisition_code = $requisition_data['requisition_code'];
                     $text = $view->render('mailtemplates/interviewrounds.phtml');
                     $options['subject'] = APPLICATION_NAME . ': Interview schedule';
                     $options['header'] = 'Interview schedule';
                     $options['toEmail'] = $email;
                     $options['toName'] = $ename;
                     $options['message'] = $text;
                     $options['cron'] = 'yes';
                     sapp_Global::_sendEmail($options);
                 }
                 //end of mailing
                 $tableid = $result;
                 $this->view->eventact = 'scheduled';
             } else {
                 if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == MANAGEMENT_GROUP) {
                     $requisition_data = $requi_model->getRequisitionDataById($reqId);
                     $cand_data = $cand_model->getCandidateById($candid);
                     $round_data = $round_model->getSingleRoundData($id);
                     $report_person_data = $user_model->getUserDataById($loginUserId);
                     $mail_arr = array('HR' => defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "", $report_person_data['userfullname'] => $report_person_data['emailaddress']);
                     foreach ($mail_arr as $ename => $email) {
                         $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                         $view = $this->getHelper('ViewRenderer')->view;
                         $this->view->emp_name = $ename;
                         $this->view->base_url = $base_url;
                         $this->view->candidate_name = $cand_data['candidate_name'];
                         $this->view->interview_type = $round_data['interview_mode'];
                         $this->view->interview_location = $round_data['int_location'];
                         $this->view->interview_date = sapp_Global::change_date($round_data['interview_date'], 'view');
                         $this->view->interview_time = sapp_Global::change_time($round_data['interview_time'], 'view');
                         $this->view->interview_feedback = $interview_feedback;
                         $this->view->interview_comments = $interview_comments;
                         $this->view->round_status = $round_status;
                         $this->view->reporting_person = $report_person_data['userfullname'];
                         $text = $view->render('mailtemplates/interviewrounds_feedback.phtml');
                         $options['subject'] = APPLICATION_NAME . ': Interview feedback';
                         $options['header'] = 'Interview feedback';
                         $options['toEmail'] = $email;
                         $options['toName'] = $ename;
                         $options['message'] = $text;
                         $options['cron'] = 'yes';
                         sapp_Global::_sendEmail($options);
                     }
                 }
                 $tableid = $id;
                 $this->view->eventact = 'updated';
             }
             $menumodel = new Default_Model_Menu();
             $objidArr = $menumodel->getMenuObjID('/scheduleinterviews');
             $objID = $objidArr[0]['id'];
             $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $intrvwId);
             $close = 'close';
             $this->view->popup = $close;
             $this->view->ermsg = '';
         } else {
             $this->view->ermsg = 'nodata';
         }
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 public function save($form)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $candidatesmodel = new Default_Model_Shortlistedcandidates();
     $cand_model = new Default_Model_Candidatedetails();
     $requimodel = new Default_Model_Requisition();
     $user_model = new Default_Model_Usermanagement();
     if ($form->isValid($this->_request->getPost())) {
         $id = $this->getRequest()->getParam('id');
         $status = $this->getRequest()->getParam('selectionstatus');
         $txtReason = $this->getRequest()->getParam('txtReason');
         $txtJoiningDate = $this->getRequest()->getParam('txtJoiningDate');
         $candidateData = $candidatesmodel->getcandidateData($id);
         $req_id = $candidateData['requisition_id'];
         $selsctionopt = array('0' => 'Select status', '1' => 'Selected', '2' => 'Rejected', '3' => 'Offered', '4' => 'Offer Accepted', '5' => 'Joined', '6' => 'On Hold', '7' => 'Offer Declined', '8' => 'Yet to offer');
         //validation
         if ($status == "4" && $txtJoiningDate == "") {
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("failure" => "Joining Date required."));
             $messages = $form->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             return $msgarray;
         } else {
             if (($status == "7" || $status == "2" || $status == "6" || $status == "8") && $txtReason == "") {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("failure" => "Comments required."));
                 $messages = $form->getMessages();
                 foreach ($messages as $key => $val) {
                     foreach ($val as $key2 => $val2) {
                         $msgarray[$key] = $val2;
                         break;
                     }
                 }
                 return $msgarray;
             } else {
                 if ($txtReason == '' && $txtJoiningDate == '') {
                     $data = array('cand_status' => $selsctionopt[$status], 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                 } else {
                     if ($txtReason == '' && $txtJoiningDate != '') {
                         $data = array('cand_status' => $selsctionopt[$status], 'joiningdate' => sapp_Global::change_date(trim($txtJoiningDate), 'database'), 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                     } else {
                         if ($txtReason != '' && $txtJoiningDate == '') {
                             $data = array('cand_status' => $selsctionopt[$status], 'comments' => $txtReason, 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                         } else {
                             $data = array('cand_status' => $selsctionopt[$status], 'comments' => $txtReason, 'joiningdate' => sapp_Global::change_date(trim($txtJoiningDate), 'database'), 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                         }
                     }
                 }
                 $where = "id = " . $id;
                 $result = $candidatesmodel->SaveorUpdateCandidateDetails($data, $where);
                 //if (($status == '1' || $status == 'Selected' ) && ($result != '')) {
                 //increment selected members count
                 $requimodel->incrementselected_members($req_id);
                 //start of mailing
                 $cand_data = $cand_model->getCandidateById($id);
                 $requisition_data = $requimodel->getRequisitionDataById($req_id);
                 $requisition_data_view = $requimodel->getReqDataForView($req_id);
                 $report_person_data = $user_model->getUserDataById($requisition_data['reporting_id']);
                 $requester_person_data = $user_model->getUserDataById($requisition_data['createdby']);
                 /* $mail_arr = array(
                    'HR' => defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "",
                    'Management' => defined("REQ_MGMT_" . $requisition_data['businessunit_id']) ? constant("REQ_MGMT_" . $requisition_data['businessunit_id']) : "",
                    $report_person_data['userfullname'] => $report_person_data['emailaddress']
                    );
                    $cstat_arr = array(
                    '0' => 'Select status',
                    '1' => 'Selected',
                    '2' => 'Rejected'
                    ); */
                 //HR Group
                 $mail_arr[0]['name'] = 'HR';
                 $mail_arr[0]['email'] = constant('REQ_HR_0');
                 $mail_arr[0]['type'] = 'CandidateFinalChange';
                 //Requester
                 $mail_arr[1]['name'] = $requester_person_data['userfullname'];
                 $mail_arr[1]['email'] = $requester_person_data['emailaddress'];
                 $mail_arr[1]['type'] = 'CandidateFinalChange';
                 //Management Group
                 $mail_arr[2]['name'] = 'Management';
                 $mail_arr[2]['email'] = constant('REQ_MGMT_0');
                 $mail_arr[2]['type'] = 'CandidateFinalChange';
                 //Reporting Manager
                 $mail_arr[3]['name'] = $report_person_data['userfullname'];
                 $mail_arr[3]['email'] = $report_person_data['emailaddress'];
                 $mail_arr[3]['type'] = 'CandidateFinalChange';
                 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->type = $mail_arr[$ii]['type'];
                     $this->view->base_url = $base_url;
                     $this->view->requisition_data = $requisition_data_view[0];
                     $this->view->candidate_details = $cand_data;
                     $text = $view->render('mailtemplates/requisition.phtml');
                     $options['subject'] = APPLICATION_NAME . ':Candidate ' . $cand_data['cand_status'];
                     $options['header'] = 'Candidate ' . $cstat_arr[$status];
                     $options['toEmail'] = $mail_arr[$ii]['email'];
                     $options['toName'] = $mail_arr[$ii]['name'];
                     $options['message'] = $text;
                     sapp_Global::_sendEmail($options, "selectedcandidates", REQUISITIONMODULESENDEMAIL);
                 }
                 //end of mailing
                 //}
                 $actionflag = 2;
                 $tableid = $id;
                 $menumodel = new Default_Model_Menu();
                 $objidArr = $menumodel->getMenuObjID('/shortlistedcandidates');
                 $objID = $objidArr[0]['id'];
                 $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Request updated successfully."));
                 $this->_redirect('/shortlistedcandidates');
             }
         }
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 /**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of candidate (optional)
  * 
  * @return Zend_Form.
  */
 public function editAction()
 {
     $req_model = new Default_Model_Requisition();
     $jobtitleModel = new Default_Model_Jobtitles();
     $cand_model = new Default_Model_Candidatedetails();
     $candwork_model = new Default_Model_Candidateworkdetails();
     $country_model = new Default_Model_Countries();
     $role_model = new Default_Model_Roles();
     $auth = Zend_Auth::getInstance();
     $data = array();
     $statusData = array();
     $jobtitle = '';
     $req_data['jobtitlename'] = '';
     $popConfigPermission = array();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $id = trim($this->getRequest()->getParam('id'));
     if (is_numeric($id) && $id > 0) {
         try {
             try {
                 $statusData = $req_model->getYesNoStatus();
                 $this->view->statusData = $statusData;
             } catch (Exception $err1) {
             }
             $candidateData = $cand_model->getcandidateData($id);
             $form = new Default_Form_Candidatedetails($candidateData['requisition_id']);
             $form->setAction(DOMAIN . 'candidatedetails/edit/id/' . $id);
             $statsflag = 'false';
             if (count($candidateData) > 0) {
                 try {
                     $candidateworkData = $candwork_model->getcandidateworkData($id);
                     $req_data = $req_model->getRequisitionDataById($candidateData['requisition_id']);
                     // To show it on edit view
                     $data['cand_resume'] = isset($candidateData['cand_resume']) ? $candidateData['cand_resume'] : NULL;
                     $data['rec_id'] = isset($id) ? $id : NULL;
                     $data['selected_option'] = $this->_getParam('selected_option');
                     if (($req_data['req_status'] == 'Closed' || $req_data['req_status'] == 'On hold' || $req_data['req_status'] == 'Complete') && ($candidateData['cand_status'] == 'Requisition Closed/Completed' || $candidateData['cand_status'] == 'On hold' || $candidateData['cand_status'] == 'Not Scheduled')) {
                         //|| $candidateData['cand_status'] == 'Rejected' || $candidateData['cand_status'] == 'Disqualified'
                         $statsflag = 'true';
                         $reqforcv_data = $req_model->getRequisitionsForCV("'Approved','In process'");
                         $req_options = array();
                         foreach ($reqforcv_data as $req) {
                             $req_options[$req['id']] = $req['requisition_code'] . ' - ' . $req['jobtitlename'];
                         }
                         $form->requisition_id->addMultiOptions(array('' => 'Select Requisition ID') + $req_options);
                         $form->cand_status->addMultiOption('', 'Select Status');
                         $form->cand_status->addMultiOption('Not Scheduled', 'Not Scheduled');
                     }
                     $data['requisition_code'] = $req_data['requisition_code'];
                     $data['requisition_id'] = $req_data['id'];
                     $candidateData['candidate_phonenumber'] = $candidateData['contact_number'];
                     $candidateData['candidate_emailaddress'] = $candidateData['emailid'];
                     $candidateData['candidate_technology'] = $candidateData['cand_technology'];
                     if ($id) {
                         $form->submit->setLabel('Update');
                         foreach ($candidateData as $key => $val) {
                             $candidateData[$key] = htmlentities(addslashes($val), ENT_QUOTES, "UTF-8");
                         }
                         $form->populate($candidateworkData);
                         $form->populate($candidateData);
                     }
                     $this->view->candidate_data = $candidateData;
                     $this->view->form = $form;
                     $this->view->workdata = $candidateworkData;
                     $this->view->data = $data;
                     $this->view->popConfigPermission = $popConfigPermission;
                     $this->view->statsflag = $statsflag;
                     $this->view->ermsg = '';
                     if ($this->getRequest()->getPost()) {
                         $result = $this->save($form);
                         $this->view->msgarray = $result;
                         $this->view->messages = $result;
                     }
                 } catch (Exception $e) {
                     $this->view->ermsg = 'nodata';
                 }
             } else {
                 $this->view->ermsg = 'nodata';
             }
         } catch (Exception $e) {
             $this->view->ermsg = 'nodata';
         }
     } else {
         $this->view->ermsg = 'nodata';
     }
 }
 public function save($form)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $candidatesmodel = new Default_Model_Shortlistedcandidates();
     $cand_model = new Default_Model_Candidatedetails();
     $requimodel = new Default_Model_Requisition();
     $user_model = new Default_Model_Usermanagement();
     if ($form->isValid($this->_request->getPost())) {
         $id = $this->getRequest()->getParam('id');
         $status = $this->getRequest()->getParam('selectionstatus');
         $candidateData = $candidatesmodel->getcandidateData($id);
         $req_id = $candidateData['requisition_id'];
         $data = array('cand_status' => trim($status), 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"));
         $where = "id = " . $id;
         $result = $candidatesmodel->SaveorUpdateCandidateDetails($data, $where);
         if (($status == '2' || $status == 'Selected') && $result != '') {
             //increment selected members count
             $requimodel->incrementselected_members($req_id);
             //start of mailing
             $cand_data = $cand_model->getCandidateById($id);
             $requisition_data = $requimodel->getRequisitionDataById($req_id);
             $report_person_data = $user_model->getUserDataById($requisition_data['reporting_id']);
             $mail_arr = array('HR' => defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "", 'Management' => defined("REQ_MGMT_" . $requisition_data['businessunit_id']) ? constant("REQ_MGMT_" . $requisition_data['businessunit_id']) : "", $report_person_data['userfullname'] => $report_person_data['emailaddress']);
             $cstat_arr = array('0' => 'Select status', '2' => 'Selected', '3' => 'Rejected');
             foreach ($mail_arr as $ename => $email) {
                 $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                 $view = $this->getHelper('ViewRenderer')->view;
                 $this->view->emp_name = $ename;
                 $this->view->base_url = $base_url;
                 $this->view->requisition_code = $requisition_data['requisition_code'];
                 $this->view->candidate_name = $cand_data['candidate_name'];
                 $this->view->status = $cstat_arr[$status];
                 $text = $view->render('mailtemplates/selectedcandidates.phtml');
                 $options['subject'] = APPLICATION_NAME . ': Candidate ' . $cstat_arr[$status];
                 $options['header'] = 'Candidate ' . $cstat_arr[$status];
                 $options['toEmail'] = $email;
                 $options['toName'] = $ename;
                 $options['message'] = $text;
                 $options['cron'] = 'yes';
                 sapp_Global::_sendEmail($options);
             }
             //end of mailing
         }
         $actionflag = 2;
         $tableid = $id;
         $menumodel = new Default_Model_Menu();
         $objidArr = $menumodel->getMenuObjID('/shortlistedcandidates');
         $objID = $objidArr[0]['id'];
         $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
         $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Request updated successfully."));
         $this->_redirect('/shortlistedcandidates');
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
 /**
  * 
  * @param type $form
  * @return type
  */
 public function save($form)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $requi_model = new Default_Model_Requisition();
     $round_model = new Default_Model_Interviewrounddetails();
     $round_reschedule_model = new Default_Model_Interviewroundrescheduledetails();
     $intrvwModel = new Default_Model_Interviewdetails();
     $user_model = new Default_Model_Usermanagement();
     $cand_model = new Default_Model_Candidatedetails();
     $roundId = $this->getRequest()->getParam('id');
     $intrvwId = $this->getRequest()->getParam('unitId');
     if ($form->isValid($this->_request->getPost())) {
         $reqData = $intrvwModel->getReqByintrvwID($intrvwId);
         if (!empty($reqData)) {
             $reqId = $reqData['req_id'];
             $candid = $reqData['candidate_id'];
             $id = $this->getRequest()->getParam('id');
             $interviewrnd_id = $intrvwId;
             $interviewer_id1 = $this->getRequest()->getParam('interviewer_id');
             if (is_array($interviewer_id1)) {
                 $interview_id = $interviewer_id1[0];
             } else {
                 $interview_id = $interviewer_id1;
             }
             $interview_round = $this->getRequest()->getParam('interview_round');
             $interview_mode = $this->getRequest()->getParam('interview_mode');
             $interview_Type_Details = $this->getRequest()->getParam('interview_Type_Details');
             $int_location = $this->getRequest()->getParam('int_location');
             $interview_time = $this->getRequest()->getParam('interview_time');
             $interview_date = $this->getRequest()->getParam('interview_date');
             $interview_feedback = $this->getRequest()->getParam('interview_feedback');
             $interview_comments = $this->getRequest()->getParam('interview_comments');
             $round_status = $this->getRequest()->getParam('round_status', null);
             $hid_round_status = $this->getRequest()->getParam('hid_round_status', null);
             if (is_array($interviewer_id1)) {
                 $interview_panel = implode(",", $this->getRequest()->getParam('interviewer_id', null));
             } else {
                 $interview_id = $interviewer_id1;
             }
             if ($id != null) {
                 //get Feedback Matrix values from Request
                 $requisitionSkillMatrix = $round_model->getRequisitionSkillMatrix($id);
                 $currRowCount = 0;
                 foreach ($requisitionSkillMatrix as $skill) {
                     $unqCode = $skill['uniquecode'];
                     $skillSelValue = $this->getRequest()->getParam($unqCode, null);
                     if ($skillSelValue != null) {
                         $requisitionSkillMatrix[$currRowCount]['Rating'] = $skillSelValue;
                     }
                     $currRowCount++;
                 }
             }
             //check if Skill matrix is filled as per business logic
             $skillsmatrixvalidate = true;
             if ($round_status == "Schedule for next round" || $round_status == "Qualified" || $round_status == "Selected" || $round_status == "Disqualified") {
                 if ($interview_round == "Technical") {
                     foreach ($requisitionSkillMatrix as $skill) {
                         if ($skill['Category'] == "Technical" && ($skill['Rating'] <= 0 || $skill['Rating'] == null)) {
                             $skillsmatrixvalidate = false;
                             break;
                         }
                     }
                 }
                 /* else if ($interview_round == "Managerial") {
                    foreach ($requisitionSkillMatrix as $skill) {
                    if ($skill['Category'] == "Non-Technical" && ($skill['Rating'] <= 0 || $skill['Rating'] == null)) {
                    $skillsmatrixvalidate = false;
                    break;
                    }
                    }
                    } */
             }
             if ($skillsmatrixvalidate != true) {
                 $alertMsg = ($interview_round == "Managerial" ? 'Non-Technical' : 'Technical') . " Skill Rating is Mandatory...!";
                 echo '<script language="javascript">';
                 echo 'alert("' . $alertMsg . '")';
                 echo '</script>';
             } else {
                 // for Interview Reschedule & Cancellations
                 if ($round_status == "Re-Scheduled-Interviewer Request" || $round_status == "Re-Scheduled-Candidate Request" || $round_status == "Cancelled") {
                     $round_data = $round_model->getSingleRoundData($id);
                     $cand_data = $cand_model->getCandidateById($candid);
                     $requisition_data = $requi_model->getRequisitionDataById($reqId);
                     $interviewpanelnamesemailaddress = $requi_model->GetInterviewPanelMamesEmailaddress($round_data['interview_panel']);
                     $loginuser_person_data = $user_model->getUserDataById($loginUserId);
                     $data = array('interviewround_id' => $id, 'interview_id' => trim($intrvwId), 'req_id' => $reqId, 'candidate_id' => $candid, 'interview_location_old' => $round_data['int_location'], 'interview_round_old' => $round_data['interview_round'], 'interview_date_old' => $round_data['interview_date'], 'interview_time_old' => $round_data['interview_time'], 'interview_mode_old' => $round_data['interview_mode'], 'interview_mode_details_old' => $round_data['interview_mode_details'], 'interview_location' => $int_location, 'interview_round' => $interview_round, 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date(trim($interview_date), 'database'), 'interview_mode' => $interview_mode, 'interview_mode_details' => $interview_Type_Details, 'interview_feedback' => trim($interview_feedback), 'round_status' => trim($round_status), 'createdby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"));
                     $result1 = $round_reschedule_model->SaveorUpdateInterviewroundData($data, "");
                     $intRound_where = array("id = " . $id);
                     if ($round_status == "Cancelled") {
                         $data_intRound = array('int_location' => $int_location, 'interview_round' => $interview_round, 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date(trim($interview_date), 'database'), 'interview_mode' => $interview_mode, 'interview_mode_details' => $interview_Type_Details, 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 0);
                     } else {
                         $data_intRound = array('int_location' => $int_location, 'interview_round' => $interview_round, 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date(trim($interview_date), 'database'), 'interview_mode' => $interview_mode, 'interview_mode_details' => $interview_Type_Details, 'modifiedby' => trim($loginUserId), 'modifieddate' => gmdate("Y-m-d H:i:s"), 'interview_panel' => $interview_panel);
                     }
                     $result2 = $round_model->SaveorUpdateInterviewroundData($data_intRound, $intRound_where);
                     if ($result1 > 0 && $result2 == "update") {
                         //send Reschedule meeting invite
                         $emailtemp = array();
                         $nametemp = array();
                         foreach ($interviewpanelnamesemailaddress as $row) {
                             array_push($emailtemp, $row['emailaddress']);
                             array_push($nametemp, $row['userfullname']);
                         }
                         $email = implode(";", $emailtemp);
                         $ename = implode(";", $nametemp);
                         $cal_unique_id = $round_data['calendarinviteid'];
                         $base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                         $description = "Meeting From : " . $ename . "\r\n" . "Candidate Name : " . $cand_data['candidate_name'] . "\r\n" . "Interview Type : " . $interview_mode . "\r\n" . "Interview Location : " . $int_location . "\r\n" . "Interview Date : " . $interview_date . "\r\n" . "Interview Time : " . sapp_Global::change_time($interview_time, 'view') . "\r\n" . " " . " " . "\r\n";
                         //$view = $this->getHelper('ViewRenderer')->view;
                         //$this->view->emp_name = "Interviewer";
                         //$this->view->base_url = $base_url;
                         //$this->view->candidate_name = $cand_data['candidate_name'];
                         //$this->view->interview_type = $interview_mode;
                         //$this->view->interview_mode_details = $interview_Type_Details;
                         //$this->view->interview_location = $int_location;
                         //$this->view->interview_date = $interview_date;
                         //$this->view->interview_time = sapp_Global::change_time($interview_time, 'view');
                         //$this->view->requisition_code = $requisition_data['requisition_code'];
                         //$text = $view->render('mailtemplates/interviewrounds.phtml');
                         //$options['subject'] = APPLICATION_NAME . ': Interview schedule';
                         //$options['header'] = 'Interview schedule';
                         //$options['toEmail'] = $email;
                         //$options['toName'] = $ename;
                         //$options['message'] = $description;
                         //$options['location'] = $int_location;
                         //$options['interviewdate'] = $interview_date;
                         //$options['starttime'] = sapp_Global::add_time($interview_time, 'view', 0);
                         //$options['endtime'] = sapp_Global::add_time($interview_time, 'view', 3600);
                         //Interview Calendar Invite will be send from login user account
                         //$options['fromEmail'] = $loginuser_person_data['emailaddress'];
                         //$options['fromName'] = $loginuser_person_data['userfullname'];
                         //$options['fromEmail'] = SUPERADMIN_EMAIL;
                         //$options['fromName'] = "*****@*****.**";
                         //$options['calUniqueID'] = $cal_unique_id;
                         $calRequest = 'REQUEST';
                         if ($round_status == "Cancelled") {
                             $calRequest = 'CANCEL';
                         }
                         $interviewpanelnamesemailaddresss = $requi_model->GetInterviewPanelMamesEmailaddress($interview_panel);
                         foreach ($interviewpanelnamesemailaddresss as $interviewpanelnamesemailaddress) {
                             //sapp_Global::_sendCalendarEmail($options);
                             $from_name = trim($loginuser_person_data['userfullname']);
                             $from_address = trim($loginuser_person_data['emailaddress']);
                             $to_name = trim($interviewpanelnamesemailaddress['userfullname']);
                             $to_address = trim($interviewpanelnamesemailaddress['emailaddress']);
                             $startTime = sapp_Global::_getInterviewStartDateTime(sapp_Global::change_date($interview_date), sapp_Global::change_time(trim($interview_time)), 3600);
                             $endTime = sapp_Global::_getInterviewStartDateTime(sapp_Global::change_date($interview_date), sapp_Global::change_time(trim($interview_time)));
                             $subject = APPLICATION_NAME . ': Interview schedule';
                             $location = $int_location;
                             sapp_Global::sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $calRequest, $cal_unique_id);
                         }
                         $irwhere = "id = " . $result1;
                         $irdata = array('calendarinviteid' => $cal_unique_id);
                         $interview_round_model = new Default_Model_Interviewrounddetails();
                         $ir_result1 = $interview_round_model->SaveorUpdateInterviewroundData($irdata, $irwhere);
                         $this->view->eventact = 'updated';
                         $actionflag = 1;
                         $menumodel = new Default_Model_Menu();
                         $objidArr = $menumodel->getMenuObjID('/scheduleinterviews');
                         $objID = $objidArr[0]['id'];
                         $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $intrvwId);
                         $close = 'close';
                         $this->view->popup = $close;
                         $this->view->ermsg = '';
                     }
                 } else {
                     $data = array('candidate_id' => $candid, 'req_id' => $reqId, 'interview_id' => trim($intrvwId), 'interviewer_id' => $interview_id, 'interview_mode' => trim($interview_mode), 'interview_mode_details' => $interview_Type_Details, 'int_location' => trim($int_location), 'int_country' => trim($this->_getParam('country', null)), 'int_state' => trim($this->_getParam('state', null)), 'int_city' => trim($this->_getParam('city', null)), 'interview_time' => sapp_Global::change_time(trim($interview_time), 'database'), 'interview_date' => sapp_Global::change_date(trim($interview_date), 'database'), 'interview_round' => trim($interview_round), 'interview_feedback' => trim($interview_feedback), 'interview_comments' => trim($interview_comments), 'round_status' => trim($round_status), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"), 'interview_panel' => $interview_panel);
                     if ($interviewrnd_id != null) {
                         $roundnumberData = $intrvwModel->getinterviewroundnumber($interviewrnd_id);
                         $roundnumber = $roundnumberData['interview_round_number'];
                     }
                     $data['interview_round_number'] = $roundnumber + 1;
                     $currentinterviewroundnumber = $roundnumber;
                     $where = "";
                     $actionflag = 1;
                     if ($id != '') {
                         //update skill matrix to DB
                         if ($round_status == "Schedule for next round" || $round_status == "Qualified" || $round_status == "Selected" || $round_status == "Disqualified") {
                             $skillupdateresult = $round_model->UpdateOrInsertCandidateSkillMatrix($requisitionSkillMatrix, $id, $intrvwId, $reqId, $candid, $loginUserId, $currentinterviewroundnumber);
                         }
                         unset($data['interview_panel']);
                         unset($data['createdby']);
                         unset($data['createdon']);
                         unset($data['isactive']);
                         unset($data['interview_round_number']);
                         $where = array("id = " . $id);
                         $tableid = $id;
                         $actionflag = 2;
                         if ($hid_round_status != '') {
                             $data = array();
                             $data['round_status'] = trim($round_status);
                         }
                     }
                     if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP || $loginuserGroup == EMPLOYEE_GROUP || ($loginuserGroup == HR_GROUP || $loginuserGroup == MANAGEMENT_GROUP) && $interviewer_id == $loginUserId) {
                         unset($data['interviewer_id']);
                         unset($data['interview_mode']);
                         unset($data['int_location']);
                         unset($data['int_country']);
                         unset($data['int_state']);
                         unset($data['int_city']);
                         unset($data['interview_time']);
                         unset($data['interview_date']);
                         unset($data['interview_round']);
                     }
                     $result = $round_model->SaveorUpdateInterviewroundData($data, $where);
                     //upadating invite calander id if interview round id is numeric
                     if (is_numeric($result)) {
                         //updating calendarinviteid column in main_interviewrounddetails tabel - start
                         $startTime = sapp_Global::add_time($interview_time, 'view', 0);
                         //$domain = 'deltaintech.com';
                         //$cal_unique_id = date("Ymd\TGis", strtotime($startTime)) . rand() . "@" . $domain;
                         $irwhere = "id = " . $result;
                         $irdata = array('calendarinviteid' => $cal_unique_id);
                         $interview_round_model1 = new Default_Model_Interviewrounddetails();
                         $ir_result1 = $interview_round_model1->SaveorUpdateInterviewroundData($irdata, $irwhere);
                     }
                     //upadating invite calander id if interview round id is numeric - End
                     if ($id == '') {
                         //start of mailing
                         $requisition_data = $requi_model->getRequisitionDataById($reqId);
                         $cand_data = $cand_model->getCandidateById($candid);
                         /* $report_person_data = $user_model->getUserDataById($interviewer_id);
                            $mail_arr = array('HR' => defined('REQ_HR_' . $requisition_data['businessunit_id']) ? constant('REQ_HR_' . $requisition_data['businessunit_id']) : "",
                            $report_person_data['userfullname'] => $report_person_data['emailaddress']
                            ); */
                         $report_person_data = $user_model->getUserDataById($interviewer_id);
                         $currentrequisition_data = $requi_model->getrequisitiondetails($reqId);
                         $requesteremailaddress = $requi_model->getemployeeemailaddress($currentrequisition_data["createdby"]);
                         $reportingmanageremailaddress = $requi_model->getemployeeemailaddress($currentrequisition_data["reporting_id"]);
                         $hrgroupemail = $requi_model->getgroupemailid("REQ_HR", $requisition_data["department_id"]);
                         $mail_arr = array('HR' => $hrgroupemail["groupEmail"], $report_person_data['userfullname'] => $report_person_data['emailaddress'], $requesteremailaddress['userfullname'] => $requesteremailaddress['emailaddress'], $reportingmanageremailaddress['userfullname'] => $reportingmanageremailaddress['emailaddress']);
                         //foreach ($mail_arr as $ename => $email) {
                         //$base_url = 'http://' . $this->getRequest()->getHttpHost() . $this->getRequest()->getBaseUrl();
                         $description = "Meeting From : " . $ename . "\r\n" . "Candidate Name : " . $cand_data['candidate_name'] . "\r\n" . "Interview Type : " . $interview_mode . "\r\n" . "Interview Location : " . $int_location . "\r\n" . "Interview Date : " . $interview_date . "\r\n" . "Interview Time : " . sapp_Global::change_time($interview_time, 'view') . "\r\n" . " " . " " . "\r\n";
                         //$view = $this->getHelper('ViewRenderer')->view;
                         //$this->view->emp_name = $ename;
                         //$this->view->base_url = $base_url;
                         //$this->view->candidate_name = $cand_data['candidate_name'];
                         //$this->view->interview_type = $interview_mode;
                         //$interview_Type_Details
                         //$this->view->interview_location = $int_location;
                         //$this->view->interview_date = $interview_date;
                         //$this->view->interview_time = sapp_Global::change_time($interview_time, 'view');
                         //$this->view->requisition_code = $requisition_data['requisition_code'];
                         //$text = $view->render('mailtemplates/interviewrounds.phtml');
                         //$options['subject'] = APPLICATION_NAME . ': Interview schedule';
                         //$options['header'] = 'Interview schedule';
                         //$options['toEmail'] = $email;
                         //$options['toName'] = $ename;
                         //$options['message'] = $description;
                         ////$options['cron'] = 'yes';
                         //additional properties for Calendar invite -------------------START
                         //$options['interviewdate'] = $interview_date;
                         //$options['location'] = $int_location;
                         //$options['starttime'] = sapp_Global::add_time($interview_time, 'view', 0);
                         //$options['endtime'] = sapp_Global::add_time($interview_time, 'view', 3600);
                         //$options['calUniqueID'] = $cal_unique_id;
                         //additional properties for Calendar invite -------------------END
                         //sapp_Global::_sendCalendarEmail($options);
                         $loginuser_person_data = $user_model->getUserDataById($loginUserId);
                         $interviewpanelnamesemailaddresss = $requi_model->GetInterviewPanelMamesEmailaddress($interview_panel);
                         foreach ($interviewpanelnamesemailaddresss as $interviewpanelnamesemailaddress) {
                             $cal_unique_id = $this->getCalendarUniqueID();
                             $from_name = trim($loginuser_person_data['userfullname']);
                             $from_address = trim($loginuser_person_data['emailaddress']);
                             $to_name = trim($interviewpanelnamesemailaddress['userfullname']);
                             $to_address = trim($interviewpanelnamesemailaddress['emailaddress']);
                             $startTime = sapp_Global::_getInterviewStartDateTime(sapp_Global::change_date($interview_date), sapp_Global::change_time(trim($interview_time)), 3600);
                             $endTime = sapp_Global::_getInterviewStartDateTime(sapp_Global::change_date($interview_date), sapp_Global::change_time(trim($interview_time)));
                             $subject = APPLICATION_NAME . ': Interview schedule';
                             $location = $int_location;
                             $calRequest = 'REQUEST';
                             sapp_Global::sendIcalEvent($from_name, $from_address, $to_name, $to_address, $startTime, $endTime, $subject, $description, $location, $calRequest, $cal_unique_id);
                         }
                         //}
                         //end of mailing
                         $tableid = $result;
                         $this->view->eventact = 'scheduled';
                     } else {
                         if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == MANAGEMENT_GROUP) {
                             $requisition_data = $requi_model->getRequisitionDataById($reqId);
                             $requisition_data_View = $requi_model->getReqDataForView($reqId);
                             $cand_data = $cand_model->getCandidateById($candid);
                             $round_data = $round_model->getSingleRoundData($id);
                             $report_person_data = $user_model->getUserDataById($interviewer_id);
                             $currentrequisition_data = $requi_model->getrequisitiondetails($reqId);
                             $requesteremailaddress = $requi_model->getemployeeemailaddress($currentrequisition_data["createdby"]);
                             $reportingmanageremailaddress = $requi_model->getemployeeemailaddress($currentrequisition_data["reporting_id"]);
                             //$hrgroupemail = $requi_model->getgroupemailid("REQ_HR", $requisition_data["department_id"]);
                             //HR Group
                             $mail_arr[0]['name'] = 'HR';
                             $mail_arr[0]['email'] = constant('REQ_HR_0');
                             //Requester
                             $mail_arr[1]['name'] = $requesteremailaddress['userfullname'];
                             $mail_arr[1]['email'] = $requesteremailaddress['emailaddress'];
                             //Reporting Manager
                             $mail_arr[2]['name'] = $reportingmanageremailaddress['userfullname'];
                             $mail_arr[2]['email'] = $reportingmanageremailaddress['emailaddress'];
                             //Management Group
                             $mail_arr[3]['name'] = 'Management';
                             $mail_arr[3]['email'] = constant('REQ_MGMT_0');
                             //Recruiter Panel
                             $requisition_recruiters_data = $requi_model->GetRequisitionRecruiterEmailaddress($currentrequisition_data["requisition_code"]);
                             $emailCnt = 4;
                             foreach ($requisition_recruiters_data as $requisition_recruiters_data1) {
                                 $mail_arr[$emailCnt]['name'] = $requisition_recruiters_data1['userfullname'];
                                 $mail_arr[$emailCnt]['email'] = $requisition_recruiters_data1['emailaddress'];
                                 $emailCnt = $emailCnt + 1;
                             }
                             //Technical Panel
                             $interviewpanelnamesemailaddresss = $requi_model->GetInterviewPanelMamesEmailaddress($round_data['interview_panel']);
                             foreach ($interviewpanelnamesemailaddresss as $interviewpanelnamesemailaddress1) {
                                 $mail_arr[$emailCnt]['name'] = $interviewpanelnamesemailaddress1['userfullname'];
                                 $mail_arr[$emailCnt]['email'] = $interviewpanelnamesemailaddress1['emailaddress'];
                                 $emailCnt = $emailCnt + 1;
                             }
                             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->type = 'InterviewFeedback';
                                 $this->view->requisition_data = $requisition_data_View[0];
                                 $this->view->candidate_details = $cand_data;
                                 $this->view->round_data = $round_data;
                                 $this->view->base_url = $base_url;
                                 $text = $view->render('mailtemplates/requisition.phtml');
                                 $options['subject'] = APPLICATION_NAME . ': Interview feedback';
                                 //$options['header'] = 'Interview feedback';
                                 $options['toEmail'] = $mail_arr[$ii]['email'];
                                 $options['toName'] = $mail_arr[$ii]['name'];
                                 $options['message'] = $text;
                                 sapp_Global::_sendEmail($options, "interviewrounds_feedback", REQUISITIONMODULESENDEMAIL);
                             }
                         }
                         $tableid = $id;
                         $this->view->eventact = 'updated';
                     }
                     $menumodel = new Default_Model_Menu();
                     $objidArr = $menumodel->getMenuObjID('/scheduleinterviews');
                     $objID = $objidArr[0]['id'];
                     $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $intrvwId);
                     $close = 'close';
                     $this->view->popup = $close;
                     $this->view->ermsg = '';
                 }
             }
         } else {
             $this->view->ermsg = 'nodata';
         }
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }