/**
  * 
  */
 public function candidatepopupAction()
 {
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $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();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $login_group_id = $auth->getStorage()->read()->group_id;
         $login_role_id = $auth->getStorage()->read()->emprole;
     }
     $id = $this->getRequest()->getParam('cand_id');
     $form = new Default_Form_Candidatedetails();
     $req_data = array();
     $jobtitle = '';
     $req_data['jobtitlename'] = '';
     try {
         $candidateData = $cand_model->getcandidateData($id);
         $req_data = $req_model->getRequisitionDataById($candidateData['requisition_id']);
         $req_data['cand_resume'] = !empty($candidateData['cand_resume']) ? $candidateData['cand_resume'] : '';
         $req_data['rec_id'] = $id;
         $jobttlArr = $jobtitleModel->getsingleJobTitleData($req_data['jobtitle']);
         if (!empty($jobttlArr) && $jobttlArr != 'norows') {
             $jobtitle = $jobttlArr[0]['jobtitlename'];
             $req_data['jobtitlename'] = $jobttlArr[0]['jobtitlename'];
         }
         $req_options = array();
         $req_options[$req_data['id']] = $req_data['requisition_code'];
         try {
             $candidateworkData = $candwork_model->getcandidateworkData($id);
             $countryId = $candidateData['country'];
             $stateId = $candidateData['state'];
             $cityId = $candidateData['city'];
             if ($countryId && $stateId) {
                 $statesmodel = new Default_Model_States();
                 $citiesmodel = new Default_Model_Cities();
                 $statesData = $statesmodel->getStatesList($countryId);
                 $citiesData = $citiesmodel->getCitiesList($stateId);
                 foreach ($statesData as $res) {
                     $form->state->addMultiOption($res['id'], utf8_encode($res['state_name']));
                 }
                 foreach ($citiesData as $res) {
                     $form->city->addMultiOption($res['id'], utf8_encode($res['city_name']));
                 }
                 $form->setDefault('country', $countryId);
                 $form->setDefault('state', $stateId);
                 $form->setDefault('city', $cityId);
                 $form->setDefault('job_title', $jobtitle);
             }
             $countrieslistArr = $country_model->getTotalCountriesList();
             if (sizeof($countrieslistArr) > 0) {
                 $form->country->addMultiOption('0', 'Select Country');
                 foreach ($countrieslistArr as $countrieslistres) {
                     $form->country->addMultiOption($countrieslistres['id'], utf8_encode($countrieslistres['country_name']));
                 }
             } else {
                 $msgarray['country'] = 'Countries not configured yet';
             }
             $form->requisition_id->addMultiOptions(array('' => 'Select Requisition ID') + $req_options);
             if ($id) {
                 $form->submit->setLabel('Update');
                 $form->populate($candidateworkData);
                 $form->populate($candidateData);
             }
             $elements = $form->getElements();
             if (count($elements) > 0) {
                 foreach ($elements as $key => $element) {
                     if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments") {
                         $element->setAttrib("disabled", "disabled");
                     }
                 }
             }
             $previ_data = sapp_Global::_checkprivileges(CANDIDATEDETAILS, $login_group_id, $login_role_id, 'edit');
             $this->view->form = $form;
             $this->view->previ_data = $previ_data;
             $this->view->workdata = $candidateworkData;
             $this->view->ermsg = '';
             $this->view->req_data = $req_data;
             $objName = 'candidatedetails';
             $this->view->id = $id;
             $this->view->controllername = $objName;
         } catch (Exception $e) {
             $this->view->nodata = 'nodata';
         }
     } catch (Exception $e) {
         $this->view->nodata = 'nodata';
     }
 }
 /**
  * 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';
     }
 }
 /**
  * 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';
     }
 }