コード例 #1
0
 public function savesitepreference($wizardpreferenceform, $wizardData)
 {
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $loginUserId = $auth->getStorage()->read()->id;
     }
     if ($wizardpreferenceform->isValid($this->_request->getPost())) {
         $trDb = Zend_Db_Table::getDefaultAdapter();
         // starting transaction
         $trDb->beginTransaction();
         try {
             $systempreferencemodel = new Default_Model_Sitepreference();
             $currencymodel = new Default_Model_Currency();
             $orgInfoModel = new Default_Model_Organisationinfo();
             $wizard_model = new Default_Model_Wizard();
             $IdentityCodesModel = new Default_Model_Identitycodes();
             $employmentstatusmodel = new Default_Model_Employmentstatus();
             $countriesmodel = new Default_Model_Countries();
             $statesmodel = new Default_Model_States();
             $citiesmodel = new Default_Model_Cities();
             $id = (int) $this->_request->getParam('id');
             $currencyid = (int) $this->_request->getParam('currencyid');
             $organisationid = (int) $this->_request->getParam('organisationid');
             $empcodeid = (int) $this->_request->getParam('empcodeid');
             $dateformatid = $this->_request->getParam('dateformatid');
             $timeformatid = $this->_request->getParam('timeformatid');
             $timezoneid = $this->_request->getParam('timezoneid');
             $currencyname = $this->_request->getParam('currencyname');
             $currencycode = $this->_request->getParam('currencycode');
             $passwordid = $this->_request->getParam('passwordid');
             $perm_country = $this->_request->getParam('perm_country');
             $perm_stateparam = $this->_request->getParam('perm_state');
             $perm_stateArr = explode("!@#", $this->_request->getParam('perm_state'));
             $perm_state = $perm_stateArr[0];
             $perm_cityparam = $this->_request->getParam('perm_city');
             $perm_cityArr = explode("!@#", $this->_request->getParam('perm_city'));
             $perm_city = $perm_cityArr[0];
             $employee_code = $this->_request->getParam('employee_code');
             $workcodename = $this->_request->getParam('workcodename');
             $date = new Zend_Date();
             $menumodel = new Default_Model_Menu();
             /*
              * Save or Update - Currency name in currency table based on currency ID
              */
             $currency_data = array('currencyname' => trim($currencyname), 'currencycode' => trim($currencycode), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($currencyid != '') {
                 $currencywhere = array('id=?' => $currencyid);
             } else {
                 $currency_data['createdby'] = $loginUserId;
                 $currency_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $currency_data['isactive'] = 1;
                 $currencywhere = '';
             }
             $CurrencyId = $currencymodel->SaveorUpdateCurrencyData($currency_data, $currencywhere);
             /*
              * End 
              */
             /*
              * Start -  Updating and Inserting Site Preference Data after fetching currency id
              */
             $siteprference_data = array('dateformatid' => $dateformatid, 'timeformatid' => $timeformatid, 'timezoneid' => $timezoneid, 'currencyid' => $currencyid != '' ? $currencyid : $CurrencyId, 'passwordid' => $passwordid, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'isactive' => 1);
             $site_update_arr = array('isactive' => 0, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId);
             $systempreferencemodel->SaveorUpdateSystemPreferanceData($site_update_arr, 'isactive = 1');
             $Id = $systempreferencemodel->SaveorUpdateSystemPreferanceData($siteprference_data, '');
             /*
              *  End
              */
             /*
              * Updating Country,state and city based on organisation id
              */
             // Inserting into main_countries if not added
             $countryExistsArr = $countriesmodel->getActiveCountryName($perm_country);
             if (empty($countryExistsArr)) {
                 $countrynamearr = $countriesmodel->getCountryCode($perm_country);
                 if (!empty($countrynamearr)) {
                     $country_data = array('country' => trim($countrynamearr[0]['country_name']), 'countrycode' => trim($countrynamearr[0]['country_code']), 'citizenship' => NULL, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'country_id_org' => $perm_country, 'isactive' => 1);
                     $Country_Id = $countriesmodel->SaveorUpdateCountryData($country_data, '');
                 }
             }
             // Inserting into main_state if not added
             $State_Id = $statesmodel->SaveorUpdateStatesData($perm_country, $perm_stateArr[1], $perm_state, $loginUserId);
             // Inserting into main_cities if not added
             $City_Id = $citiesmodel->SaveorUpdateCitiesData($perm_country, $perm_state, $perm_cityArr[1], $perm_city, $loginUserId);
             $location_data = array('country' => $perm_country, 'state' => $perm_state, 'city' => $perm_city, 'createdby' => $loginUserId, 'createddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
             if ($organisationid != '') {
                 $locwhere = array('id=?' => $organisationid);
                 $LocationId = $orgInfoModel->SaveorUpdateData($location_data, $orgwhere);
             }
             $LocationId = $wizard_model->SaveorUpdateWizardData($location_data, '');
             /*
              * End
              */
             /*
              * Start - Updating Employee Code
              */
             $empcode_data = array('employee_code' => trim($employee_code), 'modifiedBy' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($empcodeid != '') {
                 $empcodewhere = array('id=?' => $empcodeid);
             } else {
                 $empcode_data['createdby'] = $loginUserId;
                 $empcode_data['createddate'] = gmdate("Y-m-d H:i:s");
                 $empcodewhere = '';
             }
             $EmpCodeId = $IdentityCodesModel->SaveorUpdateIdentitycodesData($empcode_data, $empcodewhere);
             /*
              * End
              */
             /*
              * Start - Update employment status data
              */
             if (!empty($workcodename)) {
                 $empstat_update_arr = array('isactive' => 0, 'modifieddate' => $date->get('yyyy-MM-dd HH:mm:ss'), 'modifiedby' => $loginUserId);
                 $Empstat_update_Id = $employmentstatusmodel->SaveorUpdateEmploymentStatusData($empstat_update_arr, 'isactive=1');
                 for ($j = 0; $j < sizeof($workcodename); $j++) {
                     switch ($workcodename[$j]) {
                         case 1:
                             $workcode = 'FT';
                             break;
                         case 2:
                             $workcode = 'PT';
                             break;
                         case 3:
                             $workcode = 'PERM';
                             break;
                         case 4:
                             $workcode = 'TEMP';
                             break;
                         case 5:
                             $workcode = 'PROB';
                             break;
                         case 6:
                             $workcode = 'CONT';
                             break;
                         case 7:
                             $workcode = 'DEP';
                             break;
                         case 8:
                             $workcode = 'RES';
                             break;
                         case 9:
                             $workcode = 'LEFT';
                             break;
                         case 10:
                             $workcode = 'SUSP';
                             break;
                         default:
                             $workcode = 'FT';
                     }
                     $empstatus_data = array('workcode' => trim($workcode), 'workcodename' => trim($workcodename[$j]), 'createdby' => $loginUserId, 'createddate' => gmdate("Y-m-d H:i:s"), 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"), 'isactive' => 1);
                     $Empstat_Id = $employmentstatusmodel->SaveorUpdateEmploymentStatusData($empstatus_data, '');
                 }
             }
             /*
              * End
              */
             /*
              * Update Wizard Table
              */
             $wizardarray = array('site_config' => 2, 'modifiedby' => $loginUserId, 'modifieddate' => gmdate("Y-m-d H:i:s"));
             if ($wizardData['org_details'] == 2) {
                 $wizardarray['iscomplete'] = 2;
             }
             $wizard_model->SaveorUpdateWizardData($wizardarray, '');
             $trDb->commit();
             $this->_helper->getHelper("FlashMessenger")->addMessage("Site Preference updated successfully.");
             $this->_redirect('wizard/configuresite');
         } catch (Exception $e) {
             $trDb->rollBack();
             $this->_helper->getHelper("FlashMessenger")->addMessage(array("success" => "Something went wrong,please try again later."));
             $this->_redirect('wizard/configuresite');
         }
     } else {
         $messages = $wizardpreferenceform->getMessages();
         foreach ($messages as $key => $val) {
             foreach ($val as $key2 => $val2) {
                 $msgarray[$key] = $val2;
                 break;
             }
         }
         return $msgarray;
     }
 }
コード例 #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');
     $selectedstateid = $this->_request->getParam('selectstateid');
     $msgarray = array();
     $setDefaultString = '';
     $citystring = '';
     $controllername = 'cities';
     $citiesform = new Default_Form_cities();
     $citiesmodel = new Default_Model_Cities();
     $countriesModel = new Default_Model_Countries();
     $citiesform->setAction(BASE_URL . 'cities/addpopup/selectcountryid/' . $selectedcountryid . '/selectstateid/' . $selectedstateid);
     $countrieslistArr = $countriesModel->getActiveCountriesList();
     if (sizeof($countrieslistArr) > 0) {
         $citiesform->countryid->addMultiOption('', 'Select Country');
         foreach ($countrieslistArr as $countrieslistres) {
             if ($selectedcountryid != '') {
                 if ($countrieslistres['country_id_org'] == $selectedcountryid) {
                     $citiesform->countryid->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
                     $citiesform->setDefault('countryid', $selectedcountryid);
                 }
             } else {
                 $citiesform->countryid->addMultiOption($countrieslistres['country_id_org'], $countrieslistres['country']);
             }
         }
     } else {
         $msgarray['countryid'] = 'Countries are not configured yet.';
     }
     if (isset($selectedcountryid) && $selectedcountryid != '') {
         $statesmodel = new Default_Model_States();
         $statesmodeldata = $statesmodel->getBasicStatesList($selectedcountryid);
         $citiesform->state->addMultiOption('', 'Select State');
         $setDefaultString = '';
         foreach ($statesmodeldata as $res) {
             $citiesform->state->addMultiOption($res['state_id_org'] . '!@#' . utf8_encode($res['state']), utf8_encode($res['state']));
             if ($selectedstateid != '' && $res['state_id_org'] == $selectedstateid) {
                 $setDefaultString = $res['state_id_org'] . '!@#' . utf8_encode($res['state']);
             }
         }
         $citiesform->setDefault('state', $setDefaultString);
     } else {
         $citiesform->state->addMultiOption('', 'Select State');
     }
     if ($selectedstateid != '' && $selectedcountryid != '') {
         $citiesmodel = new Default_Model_Cities();
         $citiesmodeldata = $citiesmodel->getCitiesList($selectedstateid, 'addcity');
         $citiesform->city->addMultiOption('', 'Select City');
         foreach ($citiesmodeldata as $res) {
             $citiesform->city->addMultiOption($res['id'] . '!@#' . utf8_encode($res['city_name']), utf8_encode($res['city_name']));
         }
         $citiesform->city->addMultiOption('other', 'Other');
         if ($citystring == 'other') {
             $citiesform->setDefault('city', 'other');
         }
     }
     if ($this->getRequest()->getPost()) {
         $id = $this->_request->getParam('id');
         $errorflag = "true";
         $msgarray = array();
         $newcityArr = array();
         $dbstate = '';
         $dbcountryid = '';
         $countryid = $this->_request->getParam('countryid');
         $stateidstr = $this->_request->getParam('state');
         $stateid = intval($stateidstr);
         $cityArr = $this->_request->getParam('city');
         if (!empty($cityArr)) {
             $othercityname = $this->_request->getParam('othercityname');
             if (in_array('other', $cityArr)) {
                 if ($othercityname == '') {
                     $msgarray['othercityname'] = "Please enter city name.";
                     $msgarray['dupcityname'] = '';
                     $msgarray['countid'] = $countryid;
                     $msgarray['stateidval'] = $stateid;
                     $errorflag = "false";
                 } else {
                     $isDuplicateCityNameArr = $citiesmodel->getDuplicateCityName($othercityname, $stateid);
                     if ($isDuplicateCityNameArr[0]['count'] > 0) {
                         $errorflag = "false";
                         $msgarray['othercityname'] = "City already exists.";
                         $msgarray['dupcityname'] = $othercityname;
                         $msgarray['countid'] = $countryid;
                         $msgarray['stateidval'] = $stateid;
                     } else {
                         $citystring = implode(",", $cityArr);
                         if (sizeof($cityArr) > 1) {
                             $newcityArr = $cityArr;
                             array_pop($newcityArr);
                             $citystring = implode(",", $newcityArr);
                             $citystringcomma = trim(str_replace("!@#", ",", $citystring), ',');
                             $citystringArr = explode(",", $citystringcomma);
                             foreach ($citystringArr as $key => $val) {
                                 if (is_numeric($val)) {
                                     $cityid[] = $val;
                                 } else {
                                     $cityname[] = $val;
                                 }
                             }
                         }
                         $dbstate = $othercityname;
                         $errorflag = "true";
                     }
                 }
             } else {
                 $citystring = implode(",", $cityArr);
                 $citystringcomma = trim(str_replace("!@#", ",", $citystring), ',');
                 $citystringArr = explode(",", $citystringcomma);
                 foreach ($citystringArr as $key => $val) {
                     if (is_numeric($val)) {
                         $cityid[] = $val;
                     } else {
                         $cityname[] = $val;
                     }
                 }
                 $errorflag = "true";
             }
         } else {
             $msgarray['countid'] = $countryid;
             $msgarray['stateidval'] = $stateid;
             $msgarray['stateiddropdown'] = $stateidstr;
             $errorflag = "false";
         }
         if ($citiesform->isValid($this->_request->getPost()) && $errorflag == "true" && $citystring != '') {
             $menumodel = new Default_Model_Menu();
             $actionflag = '';
             $tableid = '';
             if (in_array('other', $cityArr)) {
                 if ($othercityname != '') {
                     $NewCityId = $citiesmodel->SaveMainCityData($stateid, $othercityname);
                     $NewCityInsertedId = $citiesmodel->SaveorUpdateCitiesData($countryid, $stateid, $othercityname, $NewCityId, $loginUserId);
                     if (sizeof($cityArr) > 1) {
                         if (!empty($cityid)) {
                             for ($j = 0; $j < sizeof($cityid); $j++) {
                                 $Id = $citiesmodel->SaveorUpdateCitiesData($countryid, $stateid, $cityname[$j], $cityid[$j], $loginUserId);
                             }
                         }
                     }
                     $actionflag = 1;
                     $tableid = $NewCityInsertedId;
                 }
             } else {
                 for ($j = 0; $j < sizeof($cityid); $j++) {
                     $Id = $citiesmodel->SaveorUpdateCitiesData($countryid, $stateid, $cityname[$j], $cityid[$j], $loginUserId);
                 }
                 $actionflag = 1;
                 $tableid = $Id;
             }
             $menuidArr = $menumodel->getMenuObjID('/cities');
             $menuID = $menuidArr[0]['id'];
             $result = sapp_Global::logManager($menuID, $actionflag, $loginUserId, $tableid);
             if (isset($selectedstateid) && isset($selectedcountryid)) {
                 $cityData = $citiesmodel->fetchAll('isactive = 1 and state = ' . $selectedstateid . ' and countryid = ' . $selectedcountryid, 'city')->toArray();
             } else {
                 $cityData = array();
             }
             $opt = '';
             foreach ($cityData as $record) {
                 $opt .= sapp_Global::selectOptionBuilder($record['city_org_id'], $record['city']);
             }
             $this->view->cityData = $opt;
             $this->view->eventact = 'added';
             $close = 'close';
             $this->view->popup = $close;
         } else {
             $messages = $citiesform->getMessages();
             foreach ($messages as $key => $val) {
                 foreach ($val as $key2 => $val2) {
                     $msgarray[$key] = $val2;
                     break;
                 }
             }
             if (isset($countryid) && $countryid != 0 && $countryid != '') {
                 $statesmodel = new Default_Model_States();
                 $statesmodeldata = $statesmodel->getBasicStatesList($countryid);
                 foreach ($statesmodeldata as $res) {
                     $citiesform->state->addMultiOption($res['state_id_org'] . '!@#' . utf8_encode($res['state']), utf8_encode($res['state']));
                 }
                 if (isset($stateidstr) && $stateidstr != 0 && $stateidstr != '') {
                     $citiesform->setDefault('state', $stateidstr);
                 }
             }
             if (isset($stateidstr) && $stateidstr != 0 && $stateidstr != '') {
                 $citiesmodel = new Default_Model_Cities();
                 $citiesmodeldata = $citiesmodel->getCitiesList($stateid);
                 foreach ($citiesmodeldata as $res) {
                     $citiesform->city->addMultiOption($res['id'] . '!@#' . utf8_encode($res['city_name']), utf8_encode($res['city_name']));
                 }
                 $citiesform->city->addMultiOption('other', 'Other');
                 if ($citystring == 'other') {
                     $citiesform->setDefault('city', 'other');
                 }
             }
         }
     }
     $this->view->controllername = $controllername;
     $this->view->ermsg = '';
     $this->view->form = $citiesform;
     $this->view->msgarray = $msgarray;
 }