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;
     }
 }
 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;
     }
 }