/**
  * 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 editpopupAction()
 {
     $auth = Zend_Auth::getInstance();
     $inter_options = array();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserGroup = $auth->getStorage()->read()->group_id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
     }
     $editpermission = 'No';
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $cand_model = new Default_Model_Candidatedetails();
     $requi_model = new Default_Model_Requisition();
     $jobtitleModel = new Default_Model_Jobtitles();
     $intrvwModel = new Default_Model_Interviewdetails();
     $interview_round_model = new Default_Model_Interviewrounddetails();
     $user_model = new Default_Model_Usermanagement();
     $cancel_name = 'Cancel';
     $auth = Zend_Auth::getInstance();
     $jobtitle = '';
     $deptid = $this->getRequest()->getParam('deptid');
     if ($deptid == '') {
         $deptid = $this->getRequest()->getParam('deptidform');
     }
     $intId = $this->getRequest()->getParam('unitId');
     $roundId = $this->getRequest()->getParam('id');
     $ir_form = new Default_Form_Interviewrounds();
     $ir_form->setAttrib('action', BASE_URL . 'interviewrounds/editpopup/unitId/' . $intId . '/id/' . $roundId);
     $intData = $intrvwModel->getReqByintrvwID($intId);
     $ir_form->removeElement('req_id');
     $ir_form->removeElement('candidate_name');
     $ir_form->removeElement('interview_status');
     $ir_form->removeElement('cand_status');
     $roundData = $interview_round_model->getSingleRoundData($roundId);
     if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP) {
         $editpermission = sapp_Global::_checkprivileges(SCHEDULEINTERVIEWS, $loginuserGroup, $loginuserRole, 'edit');
     }
     if ($loginuserGroup == HR_GROUP || $loginuserGroup == MANAGEMENT_GROUP || $loginuserGroup == '' || $editpermission == 'Yes') {
         $countryId = $roundData['int_country'];
         if (isset($_POST['country'])) {
             $countryId = $_POST['country'];
         }
         $stateId = $roundData['int_state'];
         if (isset($_POST['state'])) {
             $stateId = $_POST['state'];
         }
         $cityId = $roundData['int_city'];
         if (isset($_POST['city'])) {
             $cityId = $_POST['city'];
         }
         $country_name = '';
         $state_name = '';
         $city_name = '';
         $countryModal = new Default_Model_Countries();
         $countriesData = $countryModal->fetchAll('isactive=1', 'country');
         foreach ($countriesData as $cdata) {
             if ($roundData['int_country'] == $cdata['country_id_org']) {
                 $country_name = $cdata['country'];
                 break;
             }
         }
         $ir_form->setDefault('country', $countryId);
         if ($countryId != '') {
             $statesmodel = new Default_Model_States();
             $statesData = $statesmodel->getBasicStatesList($countryId);
             foreach ($statesData as $res) {
                 $ir_form->state->addMultiOption($res['state_id_org'], utf8_encode($res['state']));
                 if ($roundData['int_state'] == $res['state_id_org']) {
                     $state_name = $res['state'];
                 }
             }
         }
         if ($stateId != '') {
             $citiesmodel = new Default_Model_Cities();
             $citiesData = $citiesmodel->getBasicCitiesList($stateId);
             foreach ($citiesData as $res) {
                 $ir_form->city->addMultiOption($res['city_org_id'], utf8_encode($res['city']));
                 if ($roundData['int_city'] == $res['city_org_id']) {
                     $city_name = $res['city'];
                 }
             }
             $ir_form->setDefault('state', $stateId);
             $ir_form->setDefault('city', $cityId);
         }
         $interviewer_data = $requi_model->getReportingmanagers('', $loginUserId, '', $deptid, 'interviewer');
         $inter_options = $interviewer_data;
         $inter_data = $user_model->getUserDataById($roundData['interviewer_id']);
         $jobttlArr = $jobtitleModel->getsingleJobTitleData($inter_data['jobtitle_id']);
         if (!empty($jobttlArr) && $jobttlArr != 'norows') {
             $jobtitle = ', ' . $jobttlArr[0]['jobtitlename'];
             $data['jobtitlename'] = $jobttlArr[0]['jobtitlename'];
         }
         $roundData['interviewer_name'] = $inter_data['userfullname'] . $jobtitle;
         $roundData['interview_date'] = sapp_Global::change_date($roundData['interview_date'], 'view');
         $roundData['interview_time'] = sapp_Global::change_time($roundData['interview_time'], 'view');
         $ir_form->populate($roundData);
         // 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'));
         }
         if ($roundData['round_status'] != '') {
             $ir_form->round_status->setValue($roundData['round_status']);
         }
         $future_rcnt = $interview_round_model->getFutureRoundCnt($roundData['interview_id'], $roundData['interview_round_number']);
         if ($roundData['round_status'] != '') {
             if ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP || ($loginuserGroup == HR_GROUP || $loginuserGroup == MANAGEMENT_GROUP) && $loginUserId == $roundData['interviewer_id']) {
                 $elements = $ir_form->getElements();
                 if (count($elements) > 0) {
                     foreach ($elements as $key => $element) {
                         if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments") {
                             $element->setAttrib("disabled", "disabled");
                         }
                     }
                 }
                 $ir_form->removeElement('submit');
                 $cancel_name = 'Close';
             } else {
                 if ($loginuserGroup == HR_GROUP || $loginuserGroup == '' || $loginuserGroup == MANAGEMENT_GROUP) {
                     $elements = $ir_form->getElements();
                     if (count($elements) > 0) {
                         if ($future_rcnt == 0) {
                             foreach ($elements as $key => $element) {
                                 if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments" && $key != "round_status" && $key != "submit") {
                                     $element->setAttrib("disabled", "disabled");
                                 }
                             }
                         } else {
                             foreach ($elements as $key => $element) {
                                 if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments") {
                                     $element->setAttrib("disabled", "disabled");
                                 }
                             }
                             $ir_form->removeElement('submit');
                             $cancel_name = 'Close';
                         }
                     }
                 }
             }
         } else {
             if ($roundData['interviewer_id'] != $loginUserId && ($loginuserGroup == MANAGER_GROUP || $loginuserGroup == EMPLOYEE_GROUP || $loginuserGroup == SYSTEMADMIN_GROUP)) {
                 $elements = $ir_form->getElements();
                 if (count($elements) > 0) {
                     foreach ($elements as $key => $element) {
                         if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments") {
                             $element->setAttrib("disabled", "disabled");
                         }
                     }
                 }
                 $ir_form->removeElement('submit');
                 $cancel_name = 'Close';
             }
         }
         $this->view->deptid = $deptid;
         $this->view->data = $roundData;
         $this->view->interviewer_data = $interviewer_data;
         $this->view->country_name = $country_name;
         $this->view->state_name = $state_name;
         $this->view->city_name = $city_name;
         $this->view->cancel_name = $cancel_name;
         $this->view->form = $ir_form;
         $this->view->inter_options = $inter_options;
         if ($this->getRequest()->getPost()) {
             $result = $this->save($ir_form);
             $this->view->msgarray = $result;
             $this->view->messages = $result;
         }
         $this->view->ermsg = '';
     } else {
         $this->view->ermsg = 'nodata';
     }
     $this->view->loginuserGroup = $loginuserGroup;
     $this->view->loginUserId = $loginUserId;
 }