/**
  * This action is used for adding/updating data.
  * @parameters
  * @param $id  =  id of candidate (optional)
  * 
  * @return Zend_Form.
  */
 public function editAction()
 {
     $cand_model = new Default_Model_Candidatedetails();
     $requi_model = new Default_Model_Requisition();
     $interview_model = new Default_Model_Interviewdetails();
     $interview_round_model = new Default_Model_Interviewrounddetails();
     $jobtitleModel = new Default_Model_Jobtitles();
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $id = $this->getRequest()->getParam('id');
     $intId = $id;
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $previousroundstatus = '';
     $cancel_name = "Cancel";
     $form = new Default_Form_Interviewrounds();
     $form->setAction(DOMAIN . 'scheduleinterviews/edit/id/' . $id);
     $form->id->setValue($id);
     $submitButon = $form->getElement("submit");
     $submitButon->setAttrib('style', 'display:none;');
     $form->removeElement('req_id');
     $form->removeElement('candidate_name');
     $form->removeElement('interviewer_id');
     $form->removeElement('interview_mode');
     $form->removeElement('int_location');
     $form->removeElement('country');
     $form->removeElement('state');
     $form->removeElement('city');
     $form->removeElement('interview_time');
     $form->removeElement('interview_date');
     $form->removeElement('interview_round');
     $data = array();
     $jobtitle = '';
     $interviewData = array();
     try {
         if ($id > 0 && is_numeric($id)) {
             $interviewData = $interview_model->getSingleInterviewData($intId);
             $reqstatusArray = array('On hold', 'Closed', 'Complete');
             $previousroundstatus = $interview_model->getinterviewroundnumber($intId);
             $previousroundstatus = $previousroundstatus['round_status'];
             $data = $interview_model->getCandidateDetailsById($intId);
             if (!empty($data) && $data['interview_status'] != 'Requisition Closed/Completed' && $data['interview_status'] != 'Completed' && !in_array($data['req_status'], $reqstatusArray)) {
                 if ($data['interview_status'] == 'On hold' && ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP)) {
                     $this->view->ermsg = 'nodata';
                 } else {
                     $data['jobtitlename'] = '';
                     $round_count = $interview_round_model->getRoundCnt($data['id'], $id);
                     $jobttlArr = $jobtitleModel->getsingleJobTitleData($data['jobtitle']);
                     if (!empty($jobttlArr) && $jobttlArr != 'norows') {
                         $jobtitle = $jobttlArr[0]['jobtitlename'];
                         $data['jobtitlename'] = $jobttlArr[0]['jobtitlename'];
                     }
                     $irData = $this->interviewRoundsGrid($id, $interviewData['interview_status']);
                     $this->view->dataArray = $irData[0];
                     $form->setDefault('interview_status', $interviewData['interview_status']);
                     $cand_arr = array();
                     if ($interviewData['interview_status'] == 'In process') {
                         $cand_arr['Scheduled'] = 'Scheduled';
                     } elseif ($interviewData['interview_status'] == 'Completed') {
                         $cand_arr['Disqualified'] = 'Disqualified';
                         $cand_arr['Shortlisted'] = 'Shortlisted';
                     } elseif ($interviewData['interview_status'] == 'On hold') {
                         $cand_arr['On hold'] = 'On hold';
                     }
                     $form->cand_status->clearMultiOptions();
                     $form->cand_status->addMultiOptions(array('' => 'Select status') + $cand_arr);
                     $form->setDefault('cand_status', $data['cand_status']);
                     $this->view->form = $form;
                     $this->view->data = $data;
                     $this->view->id = $id;
                     $this->view->round_count = $round_count;
                     if ($this->getRequest()->getPost()) {
                         $result = $this->save($form, $data);
                         $this->view->msgarray = $result;
                         $this->view->messages = $result;
                     }
                     $this->view->ermsg = '';
                     if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP || $interviewData['interview_status'] == 'Completed') {
                         $form->removeElement('submit');
                         $cancel_name = "Back";
                         $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");
                                 }
                             }
                         }
                         if ($interviewData['interview_status'] == 'Completed') {
                             $this->view->ermsg = 'interviewcompleted';
                         }
                     }
                 }
             } else {
                 $this->view->ermsg = 'nodata';
             }
         } else {
             $this->view->ermsg = 'nodata';
         }
         $this->view->interview_status = $interviewData['interview_status'];
         $this->view->previousroundstatus = $previousroundstatus;
         $this->view->loginuserGroup = $loginuserGroup;
         $this->view->cancel_name = $cancel_name;
     } catch (EXception $e) {
         $this->view->ermsg = 'nodata';
     }
 }
 public function addpopupAction()
 {
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $cand_model = new Default_Model_Candidatedetails();
     $requi_model = new Default_Model_Requisition();
     $interview_model = new Default_Model_Interviewdetails();
     $interview_round_model = new Default_Model_Interviewrounddetails();
     $auth = Zend_Auth::getInstance();
     $inter_options = array();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
     }
     $deptid = $this->getRequest()->getParam('deptid');
     if ($deptid == '') {
         $deptid = $this->getRequest()->getParam('deptidform');
     }
     $idData = $this->getRequest()->getParam('unitId');
     $ir_form = new Default_Form_Interviewrounds();
     $ir_form->setAttrib('action', BASE_URL . 'interviewrounds/addpopup/unitId/' . $idData);
     $ir_form->removeElement("sel_inter_status");
     $ir_form->removeElement('req_id');
     $ir_form->removeElement('candidate_name');
     $ir_form->removeElement('cand_status');
     $ir_form->removeElement('interview_status');
     $data = array();
     if (isset($_POST['country']) && $_POST['country'] != '') {
         $ir_form->country->setValue(intval($_POST['country']));
         $statesmodel = new Default_Model_States();
         $statesmodeldata = $statesmodel->getBasicStatesList(intval($_POST['country']));
         $st_opt = array();
         if (count($statesmodeldata) > 0) {
             foreach ($statesmodeldata as $dstate) {
                 $st_opt[$dstate['state_id_org'] . '!@#' . $dstate['state']] = $dstate['state'];
             }
         }
         $ir_form->state->addMultiOptions(array('' => 'Select State') + $st_opt);
     }
     if (isset($_POST['state']) && $_POST['state'] != '') {
         $citiesmodel = new Default_Model_Cities();
         $citiesmodeldata = $citiesmodel->getBasicCitiesList(intval($_POST['state']));
         $ct_opt = array();
         if (count($citiesmodeldata) > 0) {
             foreach ($citiesmodeldata as $dcity) {
                 $ct_opt[$dcity['city_org_id'] . '!@#' . $dcity['city']] = $dcity['city'];
             }
         }
         $ir_form->city->addMultiOptions(array('' => 'Select City') + $ct_opt);
     }
     //giving only for hr,management and super admin
     if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
         $ir_form->round_status->addMultiOptions(array('Decision pending' => 'Decision pending', 'On hold' => 'On hold'));
     }
     $data = $cand_model->getCandidateById($idData);
     $allData = $interview_model->getCandidateDetailsById($idData);
     $interview_status = $allData['interview_status'];
     $previousroundstatus = $interview_model->getinterviewroundnumber($idData);
     $interview_max_date = $interview_round_model->getMaxRoundDateByInterviewId($idData);
     $previousroundstatus = $previousroundstatus['round_status'];
     if ($interview_status != 'Completed' || $previousroundstatus == 'Schedule for next round') {
         $round_count = $interview_round_model->getRoundCnt($data['candidate_id'], $idData);
         $interviewer_data = $requi_model->getReportingmanagers('', $loginUserId, '', $deptid, 'interviewer');
         $inter_options = $interviewer_data;
         $ir_form->submit->setLabel('Add');
         $this->view->form = $ir_form;
         $this->view->data = $data;
         $this->view->deptid = $deptid;
         $this->view->round_count = $round_count;
         $this->view->interview_status = $interview_status;
         $this->view->interview_max_date = $interview_max_date;
         $this->view->inter_options = $inter_options;
         if ($this->getRequest()->getPost()) {
             $result = $this->save($ir_form);
             $this->view->msgarray = $result;
             $this->view->messages = $result;
         }
     } else {
         if ($interview_status == 'Completed') {
             $this->view->ermsg = 'completed';
         } else {
             if ($previousroundstatus == 'Schedule for next round') {
                 $this->view->ermsg = 'notscheduled';
             } else {
                 $this->view->ermsg = 'nodata';
             }
         }
     }
 }