public function viewAction_27092013()
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->getRequest()->getParam('userid');
     $callval = $this->getRequest()->getParam('call');
     if ($callval == 'ajaxcall') {
         $this->_helper->layout->disableLayout();
     }
     $objName = 'empcommunicationdetails';
     $empcommdetailsform = new Default_Form_empcommunicationdetails();
     $empcommdetailsform->removeElement("submit");
     $elements = $empcommdetailsform->getElements();
     if (count($elements) > 0) {
         foreach ($elements as $key => $element) {
             if ($key != "Cancel" && $key != "Edit" && $key != "Delete" && $key != "Attachments") {
                 $element->setAttrib("disabled", "disabled");
             }
         }
     }
     try {
         if ($id) {
             $employeeModal = new Default_Model_Employee();
             $isrowexist = $employeeModal->getsingleEmployeeData($id);
             if ($isrowexist == 'norows') {
                 $this->view->rowexist = "norows";
             } else {
                 $this->view->rowexist = "rows";
             }
             $empdata = $employeeModal->getActiveEmployeeData($id);
             if (!empty($empdata)) {
                 //TO get the Employee  profile information....
                 $usersModel = new Default_Model_Users();
                 $employeeData = $usersModel->getUserDetailsByIDandFlag($id);
                 $empcommdetailsModal = new Default_Model_Empcommunicationdetails();
                 $usersModel = new Default_Model_Users();
                 $countriesModel = new Default_Model_Countries();
                 $statesmodel = new Default_Model_States();
                 $citiesmodel = new Default_Model_Cities();
                 $orgInfoModel = new Default_Model_Organisationinfo();
                 $msgarray = array();
                 $orgid = 1;
                 $orgdata = $orgInfoModel->getOrganisationData($orgid);
                 $countryId = $orgdata['country'];
                 $stateId = $orgdata['state'];
                 $cityId = $orgdata['city'];
                 if ($countryId != '') {
                     $countryData = $countriesModel->getActiveCountryName($countryId);
                     $orgdata['country'] = $countryData[0]['country'];
                 }
                 if ($stateId != '') {
                     $stateData = $statesmodel->getStateNameData($stateId);
                     $orgdata['state'] = $stateData[0]['state'];
                 }
                 if ($cityId != '') {
                     $citiesData = $citiesmodel->getCitiesNameData($cityId);
                     $orgdata['city'] = $citiesData[0]['city'];
                 }
                 $countrieslistArr = $countriesModel->getActiveCountriesList();
                 if (sizeof($countrieslistArr) > 0) {
                     $empcommdetailsform->perm_country->addMultiOption('', 'Select Country');
                     $empcommdetailsform->current_country->addMultiOption('', 'Select Country');
                     foreach ($countrieslistArr as $countrieslistres) {
                         $empcommdetailsform->perm_country->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
                         $empcommdetailsform->current_country->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
                     }
                 } else {
                     $msgarray['perm_country'] = 'Countries are not configured yet.';
                     $msgarray['current_country'] = 'Countries are not configured yet.';
                 }
                 $data = $empcommdetailsModal->getsingleEmpCommDetailsData($id);
                 if (!empty($data)) {
                     $statePermlistArr = $statesmodel->getStatesList($data[0]['perm_country']);
                     if (sizeof($statePermlistArr) > 0) {
                         $empcommdetailsform->perm_state->addMultiOption('', 'Select State');
                         foreach ($statePermlistArr as $statelistres) {
                             $empcommdetailsform->perm_state->addMultiOption($statelistres['id'] . '!@#' . $statelistres['state_name'], $statelistres['state_name']);
                         }
                     }
                     $cityPermlistArr = $citiesmodel->getCitiesList($data[0]['perm_state']);
                     if (sizeof($cityPermlistArr) > 0) {
                         $empcommdetailsform->perm_city->addMultiOption('', 'Select City');
                         foreach ($cityPermlistArr as $cityPermlistres) {
                             $empcommdetailsform->perm_city->addMultiOption($cityPermlistres['id'] . '!@#' . $cityPermlistres['city_name'], $cityPermlistres['city_name']);
                         }
                     }
                     if ($data[0]['current_country'] != '' && $data[0]['current_state'] != '') {
                         $statecurrlistArr = $statesmodel->getStatesList($data[0]['current_country']);
                         if (sizeof($statecurrlistArr) > 0) {
                             $empcommdetailsform->current_state->addMultiOption('', 'Select State');
                             foreach ($statecurrlistArr as $statecurrlistres) {
                                 $empcommdetailsform->current_state->addMultiOption($statecurrlistres['id'] . '!@#' . $statecurrlistres['state_name'], $statecurrlistres['state_name']);
                             }
                         }
                         $currstateNameArr = $statesmodel->getStateName($data[0]['current_state']);
                     }
                     if ($data[0]['current_country'] != '' && $data[0]['current_state'] != '' && $data[0]['current_city'] != '') {
                         $cityCurrlistArr = $citiesmodel->getCitiesList($data[0]['current_state']);
                         if (sizeof($cityCurrlistArr) > 0) {
                             $empcommdetailsform->current_city->addMultiOption('', 'Select State');
                             foreach ($cityCurrlistArr as $cityCurrlistres) {
                                 $empcommdetailsform->current_city->addMultiOption($cityCurrlistres['id'] . '!@#' . $cityCurrlistres['city_name'], $cityCurrlistres['city_name']);
                             }
                         }
                         $currcityNameArr = $citiesmodel->getCityName($data[0]['current_city']);
                     }
                     $permstateNameArr = $statesmodel->getStateName($data[0]['perm_state']);
                     $permcityNameArr = $citiesmodel->getCityName($data[0]['perm_city']);
                     $empcommdetailsform->populate($data[0]);
                     $empcommdetailsform->setDefault('perm_country', $data[0]['perm_country']);
                     $empcommdetailsform->setDefault('perm_state', $permstateNameArr[0]['id'] . '!@#' . $permstateNameArr[0]['statename']);
                     $empcommdetailsform->setDefault('perm_city', $permcityNameArr[0]['id'] . '!@#' . $permcityNameArr[0]['cityname']);
                     if ($data[0]['current_country'] != '') {
                         $empcommdetailsform->setDefault('current_country', $data[0]['current_country']);
                     }
                     if ($data[0]['current_state'] != '') {
                         $empcommdetailsform->setDefault('current_state', $currstateNameArr[0]['id'] . '!@#' . $currstateNameArr[0]['statename']);
                     }
                     if ($data[0]['current_city'] != '') {
                         $empcommdetailsform->setDefault('current_city', $currcityNameArr[0]['id'] . '!@#' . $currcityNameArr[0]['cityname']);
                     }
                 }
                 $this->view->controllername = $objName;
                 $this->view->data = $data;
                 $this->view->dataArray = $orgdata;
                 $this->view->id = $id;
                 $this->view->employeedata = $employeeData[0];
                 $this->view->form = $empcommdetailsform;
             }
             $this->view->empdata = $empdata;
         }
     } catch (Exception $e) {
         $this->view->rowexist = "norows";
     }
 }
示例#2
0
 public function addpopupAction()
 {
     Zend_Layout::getMvcInstance()->setLayoutPath(APPLICATION_PATH . "/layouts/scripts/popup/");
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     $id = $this->getRequest()->getParam('id');
     $selectedcountryid = $this->_request->getParam('selectcountryid', null);
     $countryid = $this->_request->getParam('countryid');
     $msgarray = array();
     $controllername = 'states';
     $statestring = '';
     $statesform = new Default_Form_states();
     $statesmodel = new Default_Model_States();
     $countriesModel = new Default_Model_Countries();
     $statesform->setAction(BASE_URL . 'states/addpopup/selectcountryid/' . $selectedcountryid);
     $countrieslistArr = $countriesModel->getActiveCountriesList();
     if (sizeof($countrieslistArr) > 0) {
         $statesform->countryid->addMultiOption('', 'Select Country');
         foreach ($countrieslistArr as $countrieslistres) {
             if (isset($selectedcountryid)) {
                 if ($countrieslistres['country_id_org'] == $selectedcountryid) {
                     $statesform->countryid->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
                     $statesform->setDefault('countryid', $selectedcountryid);
                 }
             } else {
                 $statesform->countryid->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
             }
         }
     } else {
         $msgarray['countryid'] = 'Countries are not configured yet';
     }
     if (isset($selectedcountryid) && $selectedcountryid != 0 && $selectedcountryid != '') {
         $statesmodeldata = $statesmodel->getStatesList($selectedcountryid, 'addstate');
         $statesform->state->addMultiOption('', 'Select State');
         foreach ($statesmodeldata as $res) {
             $statesform->state->addMultiOption($res['id'] . '!@#' . utf8_encode($res['state_name']), utf8_encode($res['state_name']));
         }
         $statesform->state->addMultiOption('other', 'Other');
         if ($statestring == 'other') {
             $statesform->setDefault('state', 'other');
         }
     }
     if ($this->getRequest()->getPost()) {
         $id = $this->_request->getParam('id');
         $errorflag = "true";
         $msgarray = array();
         $newstateArr = array();
         $dbstate = '';
         $dbcountryid = '';
         $statestring = '';
         $stateArr = $this->_request->getParam('state');
         if (!empty($stateArr)) {
             $otherstatename = $this->_request->getParam('otherstatename');
             if (in_array('other', $stateArr)) {
                 if ($otherstatename == '') {
                     $msgarray['otherstatename'] = "Please enter state name.";
                     $msgarray['dupstatename'] = '';
                     $msgarray['countid'] = $countryid;
                     $errorflag = "false";
                 } else {
                     $isDuplicateStateNameArr = $statesmodel->getDuplicateStateName($otherstatename, $countryid);
                     if ($isDuplicateStateNameArr[0]['count'] > 0) {
                         $errorflag = "false";
                         $msgarray['otherstatename'] = "State already exists";
                         $msgarray['dupstatename'] = $otherstatename;
                         $msgarray['countid'] = $countryid;
                     } else {
                         $statestring = implode(",", $stateArr);
                         if (sizeof($stateArr) > 1) {
                             $newstateArr = $stateArr;
                             array_pop($newstateArr);
                             $statestring = implode(",", $newstateArr);
                             $statestringcomma = trim(str_replace("!@#", ",", $statestring), ',');
                             $statestringArr = explode(",", $statestringcomma);
                             foreach ($statestringArr as $key => $val) {
                                 if (is_numeric($val)) {
                                     $stateid[] = $val;
                                 } else {
                                     $statename[] = $val;
                                 }
                             }
                         }
                         $dbstate = $otherstatename;
                         $errorflag = "true";
                     }
                 }
             } else {
                 $statestring = implode(",", $stateArr);
                 $statestringcomma = trim(str_replace("!@#", ",", $statestring), ',');
                 $statestringArr = explode(",", $statestringcomma);
                 foreach ($statestringArr as $key => $val) {
                     if (is_numeric($val)) {
                         $stateid[] = $val;
                     } else {
                         $statename[] = $val;
                     }
                 }
                 $errorflag = "true";
             }
         } else {
             $msgarray['countid'] = $countryid;
             $errorflag = "false";
         }
         if ($statesform->isValid($this->_request->getPost()) && $errorflag == "true" && $statestring != '') {
             $menumodel = new Default_Model_Menu();
             $actionflag = '';
             $tableid = '';
             if (in_array('other', $stateArr)) {
                 if ($otherstatename != '') {
                     $NewStateId = $statesmodel->SaveMainStateData($countryid, $otherstatename);
                     $NewStateInsertedId = $statesmodel->SaveorUpdateStatesData($countryid, $otherstatename, $NewStateId, $loginUserId);
                     if (sizeof($stateArr) > 1) {
                         if (!empty($stateid)) {
                             for ($j = 0; $j < sizeof($stateid); $j++) {
                                 $Id = $statesmodel->SaveorUpdateStatesData($countryid, $statename[$j], $stateid[$j], $loginUserId);
                             }
                         }
                     }
                     $actionflag = 1;
                     $tableid = $NewStateInsertedId;
                 }
             } else {
                 for ($j = 0; $j < sizeof($stateid); $j++) {
                     $Id = $statesmodel->SaveorUpdateStatesData($countryid, $statename[$j], $stateid[$j], $loginUserId);
                 }
                 $tableid = $Id;
                 $actionflag = 1;
             }
             $menuidArr = $menumodel->getMenuObjID('/states');
             $menuID = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             if (isset($selectedcountryid)) {
                 $stateData = $statesmodel->fetchAll('isactive = 1 and countryid = ' . $selectedcountryid, 'state')->toArray();
             } else {
                 $stateData = array();
             }
             $opt = '';
             foreach ($stateData as $record) {
                 $opt .= sapp_Global::selectOptionBuilder($record['state_id_org'], $record['state']);
             }
             $this->view->stateData = $opt;
             $this->view->eventact = 'added';
             $close = 'close';
             $this->view->popup = $close;
         } else {
             $messages = $statesform->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             if (isset($countryid) && $countryid != 0 && $countryid != '') {
                 $statesmodeldata = $statesmodel->getStatesList($countryid);
                 $statesform->state->addMultiOption('', 'Select State');
                 foreach ($statesmodeldata as $res) {
                     $statesform->state->addMultiOption($res['id'] . '!@#' . utf8_encode($res['state_name']), utf8_encode($res['state_name']));
                 }
                 $statesform->state->addMultiOption('other', 'Other');
                 if ($statestring == 'other') {
                     $statesform->setDefault('state', 'other');
                 }
             }
         }
     }
     $this->view->ermsg = '';
     $this->view->form = $statesform;
     $this->view->msgarray = $msgarray;
     $this->view->controllername = $controllername;
 }