public function languageAction() { require_once 'models/Session.php'; require_once 'models/table/User.php'; if ($this->isLoggedIn() and array_key_exists($this->getSanParam('opt'), ITechTranslate::getLanguages())) { $user = new User(); $userRow = $user->find(Session::getCurrentUserId())->current(); $user->updateLocale($this->getSanParam('opt'), Session::getCurrentUserId()); $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); $identity->locale = $this->getSanParam('opt'); $auth->getStorage()->write($identity); setcookie('locale', $this->getSanParam('opt'), null, Globals::$BASE_PATH); } $this->_redirect($_SERVER['HTTP_REFERER']); }
public function preDispatch() { require_once 'models/table/User.php'; //add identity to view variables $auth = Zend_Auth::getInstance(); $identity = null; if ($auth->hasIdentity()) { //get ACLs and add to identity $acls = User::getACLs($auth->getIdentity()->id); $identity = $auth->getIdentity(); $identity->acls = $acls; $auth->getStorage()->write($identity); $this->view->assign('identity', $identity); } //set up localization //get country default locale, then check user settings if (isset($_COOKIE['locale']) and array_key_exists($_COOKIE['locale'], ITechTranslate::getLanguages())) { $locale = $_COOKIE['locale']; } else { $locale = $this->_countrySettings['locale']; } if (!$locale) { $locale = 'en_EN.UTF-8'; } if ($auth->hasIdentity() and $auth->getIdentity()->locale) { $locale = $auth->getIdentity()->locale; } //set up localization ITechTranslate::init($locale); // get Country-specific phrases for fields self::$_translations = Translation::getAll(); $this->view->assign('translation', self::translations()); //look for any status messages in the session and put the validation container in the view scope $statusObj = ValidationContainer::instance(); if (isset($_SESSION['status'])) { $statusObj->setStatusMessage($_SESSION['status']); unset($_SESSION['status']); } $this->view->assign('status', $statusObj); }
public function countrySettingsAction() { require_once 'models/table/System.php'; $sysTable = new System(); // For "Labels" require_once 'models/table/Translation.php'; $labelNames = array('label_country' => 'Country', 'label_regiona' => 'Region A (Province)', 'label_regionb' => 'Region B (Health District)', 'label_regionc' => 'Region C (Local Region)', 'label_regiond' => 'Region D', 'label_regione' => 'Region E', 'label_regionf' => 'Region F', 'label_regiong' => 'Region G', 'label_regionh' => 'Region H', 'label_regioni' => 'Region I', 'label_citytown' => 'City or Town', 'label_application_name' => 'Application Name', 'label_training' => 'Training', 'label_trainings' => 'Trainings', 'label_trainer' => 'Trainer', 'label_trainers' => 'Trainers', 'label_training_center' => 'Training Center', 'label_participant' => 'Participant', 'label_participants' => 'Participants'); // _system settings $checkboxFields = array('check_mod_eval' => 'module_evaluation_enabled', 'check_mod_approvals' => 'module_approvals_enabled', 'check_mod_historical' => 'module_historical_data_enabled', 'check_mod_unknown' => 'module_unknown_participants_enabled', 'check_mod_attendance' => 'module_attendance_enabled', 'display_training_partner' => 'display_training_partner', 'display_mod_skillsmart' => 'display_mod_skillsmart', 'fiscal_year_start' => 'fiscal_year_start', 'check_mod_employee' => 'module_employee_enabled'); if ($this->getRequest()->isPost()) { // Update db $updateData = array(); $country = $this->_getParam('country'); $this->putSetting('country', $country); // update translation labels $tranTable = new Translation(); foreach ($labelNames as $input_key => $db_key) { if ($this->_getParam($input_key)) { try { $tranTable->update(array('phrase' => $this->_getParam($input_key)), "key_phrase = '{$db_key}'"); $this->viewAssignEscaped($input_key, $this->_getParam($input_key)); } catch (Zend_Exception $e) { error_log($e); } } } // save locale $updateData['locale_enabled'] = implode(',', $this->_getParam('locales')); if ($this->_getParam('locale_default')) { $updateData['locale'] = $this->_getParam('locale_default'); } // update _system (checkboxes) foreach ($checkboxFields as $input_key => $db_field) { $value = $this->_getParam($input_key) == NULL ? 0 : 1; $updateData[$db_field] = $value; $this->view->assign($input_key, $value); } $updateData['fiscal_year_start'] = $this->_getParam('fiscal_year_start'); $sysTable->update($updateData, ''); } else { // view // labels $t = Translation::getAll(); foreach ($labelNames as $input_key => $db_key) { $this->viewAssignEscaped($input_key, $t[$db_key]); } // checkboxes $sysRows = $sysTable->fetchRow($sysTable->select()->limit(1)); foreach ($checkboxFields as $input_key => $field_key) { $this->view->assign($input_key, $sysRows->{$field_key}); } } // country $country = $this->getSetting('country'); $this->view->assign('country', htmlspecialchars($country)); // locale $this->view->assign('languages', ITechTranslate::getLanguages()); $this->view->assign('locale', $this->getSetting('locale')); $this->view->assign('locale_enabled', ITechTranslate::getLocaleEnabled()); // redirect to next page if ($this->_getParam('saveonly')) { $status = ValidationContainer::instance(); $status->setStatusMessage(t('Your settings have been updated.')); //reload the page $this->_redirect('admin/country-settings'); } else { if ($this->_getParam('redirect')) { header("Location: " . $this->_getParam('redirect')); exit; } } }