/**
  * 
  * @param type $form
  * @return type
  */
 public function save($form)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
         $loginuserRole = $auth->getStorage()->read()->emprole;
     }
     $candDetails = "";
     $canProcess = true;
     $flag = 'true';
     $profile_model = new Default_Model_Profiles();
     $req_model = new Default_Model_Requisition();
     $cand_model = new Default_Model_Candidatedetails();
     if ($form->isValid($this->_request->getPost())) {
         $id = $this->getRequest()->getParam('id');
         $technology = $this->_getParam('technology', null);
         $firstname = $this->_getParam('firstname', null);
         $lastname = $this->_getParam('lastname', null);
         $fullname = $firstname . ' ' . $lastname;
         $email = $this->_getParam('emailaddress', null);
         $contact = $this->_getParam('contact', null);
         $totalexprience = $this->_getParam('totalexprience', null);
         $releventexprience = $this->_getParam('releventexprience', null);
         $currentCTC = $this->_getParam('currentCTC', null);
         $expectedCTC = $this->_getParam('expectedCTC', null);
         $currentcompany = $this->_getParam('currentcompany', null);
         $currentlocation = $this->_getParam('currentlocation', null);
         $noticeperiod = $this->_getParam('noticeperiod', null);
         $requisition_id = $this->_getParam('requisition_id', null);
         $cvcommentdescription = $this->_getParam('cvcommentdescription', null);
         $candresume = $this->_getParam('cand_resume', null);
         $data = array('requisition_id' => $requisition_id, 'technology' => $technology, 'firstname' => trim($firstname), 'lastname' => trim($lastname), 'fullname' => trim($fullname), 'emailaddress' => trim($email), 'contact' => trim($contact), 'totalexprience' => $totalexprience, 'releventexprience' => $releventexprience, 'currentCTC' => $currentCTC, 'expectedCTC' => $expectedCTC, 'currentcompany' => $currentcompany, 'currentlocation' => $currentlocation, 'noticeperiod' => $noticeperiod, 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createdon' => gmdate("Y-m-d H:i:s"), 'modifiedon' => gmdate("Y-m-d H:i:s"), 'profilelastmodifiedon' => gmdate("Y-m-d H:i:s"), 'cvcommentdescription' => $cvcommentdescription, 'cand_resume' => $candresume);
         $data1 = array('requisition_id' => $requisition_id, 'candidate_firstname' => trim($firstname), 'candidate_lastname' => trim($lastname), 'candidate_name' => trim($fullname), 'emailid' => trim($email), 'contact_number' => trim($contact) == '' ? NULL : trim($contact), 'cand_resume' => $candresume, 'cand_status' => "Not Scheduled", 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"), 'cand_technology' => trim($technology), 'totalexprience' => trim($totalexprience), 'releventexprience' => trim($releventexprience), 'currentCTC' => trim($currentCTC), 'expectedCTC' => trim($expectedCTC), 'currentcompany' => trim($currentcompany), 'currentlocation' => trim($currentlocation), 'noticeperiod' => trim($noticeperiod));
         $where = "";
         $actionflag = 1;
         if ($id != '') {
             unset($data['createdby']);
             unset($data['createddate']);
             unset($data['isactive']);
             $where = "id = " . $id;
             $tableid = $id;
             $actionflag = 2;
             if ($canProcess) {
                 $result1 = $cand_model->SaveorUpdateCandidateData($data1, "");
             }
             //perform this action only if login user role is not HRRECRUITER role
             if ($loginuserRole != HRRECRUITER) {
                 $cvshortlistedstatus = "";
                 try {
                     //CV Shortlisted status and comments
                     $cvshortlistedstatus = 1;
                     $cvcommentdescription = $this->_getParam('cvcommentdescription', null);
                     $insertCVShortlistDetailsResult = $req_model->insertCVShortlistDetails($id, $requisition_id, $cvshortlistedstatus, $cvcommentdescription, trim($loginUserId), gmdate("Y-m-d H:i:s"));
                 } catch (Exception $xyz) {
                 }
             }
         }
         if ($where == '') {
             $canProcess = true;
             //$canProcess = $cand_model->IsCandidateExists($candidate_firstname, $candidate_lastname, $contact_number, $emailid, $cand_technology);
         }
         if ($canProcess) {
             $result = $profile_model->SaveorUpdateCandidateData($data, $where);
         } else {
             echo "<script> alert('Profile already exists....!'); </script>";
         }
         $candData = $cand_model->getCandidateForView($result1);
         if (isset($cvshortlistedstatus) || strlen(trim($cvshortlistedstatus)) > 0) {
             //updating existing CV
             $this->requisition_cvupload_emails($requisition_id, "Update", $candData);
         } else {
             if ($requisition_id !== NULL) {
                 //new CV
                 $this->requisition_cvupload_emails($requisition_id, "New", $candData);
             }
         }
         //send email end -------------------------------------------------
         if ($id == '') {
             $tableid = $result;
         }
         if ($result != '') {
             $menumodel = new Default_Model_Menu();
             $objidArr = $menumodel->getMenuObjID('/profiles');
             $objID = $objidArr[0]['id'];
             $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
             if ($id == '') {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Profile details added successfully."));
             } elseif ($id !== '' && $requisition_id !== '') {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Profile details Added successfully to Resource Pooling."));
             } else {
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Profile details updated successfully."));
             }
             $this->_redirect('/profiles');
         }
     } 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;
         $loginuserRole = $auth->getStorage()->read()->emprole;
     }
     $canProcess = true;
     $cand_model = new Default_Model_Candidatedetails();
     $candwork_model = new Default_Model_Candidateworkdetails();
     $req_model = new Default_Model_Requisition();
     $requisition_id = $this->_getParam('requisition_id', null);
     $cand_status = $this->_getParam('cand_status', null);
     $ststidflag1 = $this->_getParam('ststidflag1', null);
     $flag = 'true';
     if ($form->isValid($this->_request->getPost())) {
         $id = $this->getRequest()->getParam('id');
     }
     if ($ststidflag1 == 'true') {
         if ($requisition_id == '') {
             $msgarray['requisition_id'] = 'Please select requisition id.';
             $flag = 'false';
         }
         //perform this action only if login user role is not HRRECRUITER role
         if ($loginuserRole != HRRECRUITER) {
             if ($cand_status == '') {
                 $msgarray['cand_status'] = 'Please select status.';
                 $flag = 'false';
             }
         }
     }
     $contact_number = $this->_getParam('contact_number', null);
     if ($contact_number == null) {
         $contact_number = $this->_getParam('candidate_phonenumber', null);
         if ($id == '') {
             if ($contact_number != null) {
                 if (!$cand_model->isPhoneNumberEmailAlreadyExists($contact_number)) {
                     echo "<script> alert('Candidate phone number already exists.'); </script>";
                     #$msgarray['errors-candidate_phonenumber'] = 'Candidate phone number already exists.';
                     $canProcess = 'false';
                 }
             }
         }
     }
     $emailid = $this->_getParam('emailid', null);
     if ($emailid == null) {
         $emailid = $this->_getParam('candidate_emailaddress', null);
         if ($id == '') {
             if ($emailid != null) {
                 if (!$cand_model->isPhoneNumberEmailAlreadyExists($emailid)) {
                     echo "<script> alert('Candidate email address already exists.'); </script>";
                     #$msgarray['errors-candidate_emailaddress'] = 'Candidate email address already exists.';
                     $canProcess = 'false';
                 }
             }
         }
     }
     $this->view->ststidflag1 = $ststidflag1;
     if ($form->isValid($this->_request->getPost()) && $flag == 'true' && $canProcess == 'true') {
         $id = $this->getRequest()->getParam('id');
         $requisition_id = $this->_getParam('requisition_id', null);
         $candidate_firstname = $this->_getParam('candidate_firstname', null);
         $candidate_lastname = $this->_getParam('candidate_lastname', null);
         $candidate_name = $candidate_firstname . ' ' . $candidate_lastname;
         $cand_resume = $this->_getParam('cand_resume', null);
         $req_status = $this->_getParam('req_status', null);
         $cand_technology = $this->_getParam('candidate_technology', null);
         $totalexprience = $this->_getParam('totalexprience', null);
         $releventexprience = $this->_getParam('releventexprience', null);
         $currentCTC = $this->_getParam('currentCTC', null);
         $expectedCTC = $this->_getParam('expectedCTC', null);
         $currentcompany = $this->_getParam('currentcompany', null);
         $currentlocation = $this->_getParam('currentlocation', null);
         $noticeperiod = $this->_getParam('noticeperiod', null);
         $req_records = $cand_model->getcountofrecords($requisition_id);
         if (empty($req_records) || !empty($req_records)) {
             $rdata = array('req_status' => 'In process', 'modifiedby' => trim($loginUserId), 'modifiedon' => gmdate("Y-m-d H:i:s"));
             $rwhere = ' id = ' . $requisition_id;
             $req_model->SaveorUpdateRequisitionData($rdata, $rwhere);
         }
         $data = array('requisition_id' => $requisition_id, 'candidate_firstname' => trim($candidate_firstname), 'candidate_lastname' => trim($candidate_lastname), 'candidate_name' => trim($candidate_name), 'emailid' => trim($emailid), 'contact_number' => trim($contact_number) == '' ? NULL : trim($contact_number), 'cand_resume' => $cand_resume, 'cand_status' => $cand_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"), 'cand_technology' => trim($cand_technology), 'totalexprience' => trim($totalexprience), 'releventexprience' => trim($releventexprience), 'currentCTC' => trim($currentCTC), 'expectedCTC' => trim($expectedCTC), 'currentcompany' => trim($currentcompany), 'currentlocation' => trim($currentlocation), 'noticeperiod' => trim($noticeperiod));
         if (trim($contact_number) == '') {
             unset($data['contact_number']);
         }
         if (trim($emailid) == '') {
             unset($data['emailid']);
         }
         $where = "";
         $actionflag = 1;
         if ($id != '') {
             unset($data['createdby']);
             unset($data['createddate']);
             unset($data['isactive']);
             $where = "id = " . $id;
             $tableid = $id;
             $actionflag = 2;
             //perform this action only if login user role is not HRRECRUITER role
             if ($loginuserRole != HRRECRUITER) {
                 $cvshortlistedstatus = "";
                 try {
                     //CV Shortlisted status and comments
                     $cvshortlistedstatus = $this->_getParam('cvshortlistedstatusid', null);
                     $cvcommentdescription = $this->_getParam('cvcommentdescription', null);
                     $insertCVShortlistDetailsResult = $req_model->insertCVShortlistDetails($id, $requisition_id, $cvshortlistedstatus, $cvcommentdescription, trim($loginUserId), gmdate("Y-m-d H:i:s"));
                 } catch (Exception $xyz) {
                 }
             }
         }
         if ($where == '') {
             $canProcess = $cand_model->IsCandidateExists($candidate_firstname, $candidate_lastname, $contact_number, $emailid, $cand_technology);
         }
         if ($canProcess) {
             $result = $cand_model->SaveorUpdateCandidateData($data, $where);
         } else {
             //$this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Candidate already exists....!"));
             //$msgarray['requisition_id'] = 'Candidate already exists....!';
             //$flag = 'false';
             echo "<script> alert('Candidate already exists....!'); </script>";
         }
         //send email start -------------------------------------------------
         if ($id == '') {
             $id = $result;
         }
         $candData = $cand_model->getCandidateForView($id);
         if (isset($cvshortlistedstatus) || strlen(trim($cvshortlistedstatus)) > 0) {
             //updating existing CV
             $this->requisition_cvupload_emails($requisition_id, "Update", $candData);
         } else {
             //new CV
             $this->requisition_cvupload_emails($requisition_id, "New", $candData);
         }
         //send email end -------------------------------------------------
         if ($id == '') {
             $tableid = $result;
         }
         if ($result != '') {
             //saving of candidate work details
             if (count($txt_cname) > 0) {
                 $k = 0;
                 foreach ($txt_cname as $cname) {
                     if ($cname != '') {
                         $cdata = array('cand_id' => $tableid, 'company_name' => $cname, 'contact_number' => $txt_cnumber[$k], 'company_address' => $txt_address[$k], 'company_website' => $txt_website[$k], 'cand_designation' => $txt_desig[$k], 'cand_fromdate' => sapp_Global::change_date($txt_from[$k], 'database'), 'cand_todate' => sapp_Global::change_date($txt_to[$k], 'database'), 'isactive' => 1, 'createdby' => trim($loginUserId), 'modifiedby' => trim($loginUserId), 'createddate' => gmdate("Y-m-d H:i:s"), 'modifieddate' => gmdate("Y-m-d H:i:s"));
                         $cwhere = $hidworkdata[$k] != '' ? "id = " . $hidworkdata[$k] : "";
                         $candwork_model->SaveorUpdateCandidateWorkData($cdata, $cwhere);
                     }
                     $k++;
                 }
             }
             //end of saving of candidate work details
             $menumodel = new Default_Model_Menu();
             $objidArr = $menumodel->getMenuObjID('/candidatedetails');
             $objID = $objidArr[0]['id'];
             $result = sapp_Global::logManager($objID, $actionflag, $loginUserId, $tableid);
             if ($id == '') {
                 //$this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Candidate details added successfully.');
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Candidate details added successfully."));
             } else {
                 //$this->_helper->FlashMessenger()->setNamespace('success')->addMessage('Candidate details updated successfully.');
                 $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Candidate details updated successfully."));
             }
             $this->_redirect('/candidatedetails');
         }
     } else {
         $messages = $form->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         if (isset($country) && $country != 0 && $country != '') {
             $statesmodel = new Default_Model_States();
             $statesmodeldata = $statesmodel->getStatesList(intval($country));
             $form->state->clearMultiOptions();
             $form->city->clearMultiOptions();
             $form->state->addMultiOption('', 'Select State');
             foreach ($statesmodeldata as $res) {
                 $form->state->addMultiOption($res['id'], utf8_encode($res['state_name']));
             }
             if (isset($state) && $state != 0 && $state != '') {
                 $form->setDefault('state', $state);
             }
         }
         if (isset($state) && $state != 0 && $state != '') {
             $citiesmodel = new Default_Model_Cities();
             $citiesmodeldata = $citiesmodel->getCitiesList(intval($state));
             $form->city->addMultiOption('', 'Select City');
             foreach ($citiesmodeldata as $res) {
                 $form->city->addMultiOption($res['id'], utf8_encode($res['city_name']));
             }
             if (isset($city) && $city != 0 && $city != '') {
                 $form->setDefault('city', $city);
             }
         }
         return $msgarray;
     }
 }