public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
 {
     //$renderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     //$view = new ITechView(array('basePath' => Globals::$BASE_PATH.'/app/views'));
     //$renderer->setView($view);
     parent::__construct($request, $response, $invokeArgs);
     //not sure if we need this stuff
     require_once 'Zend/Filter/Digits.php';
     require_once 'Zend/Filter/Alpha.php';
     $this->digitsFilter = new Zend_Filter_Digits(false);
     //no whitespace
     $this->alphaFilter = new Zend_Filter_Alpha(false);
     //no whitespace
     //Zend_Json::$useBuiltinEncoderDecoder = false;
     //set default template variables
     $this->view->assign('base_url', Settings::$COUNTRY_BASE_URL);
     $this->view->setHelperPath(Globals::$BASE_PATH . '/app/views/helpers');
     // get Country-specific settings
     try {
         $this->_countrySettings = array();
         $this->_countrySettings = System::getAll();
         $this->_countrySettings['num_location_tiers'] = 2 + $this->_countrySettings['display_region_b'] + $this->_countrySettings['display_region_c'] + $this->_countrySettings['display_region_d'] + $this->_countrySettings['display_region_e'] + $this->_countrySettings['display_region_f'] + $this->_countrySettings['display_region_g'] + $this->_countrySettings['display_region_h'] + $this->_countrySettings['display_region_i'];
         $this->view->assign('setting', $this->_countrySettings);
         $this->view->assign('languages', ITechTranslate::getLanguages());
         $this->view->assign('languages_enabled', ITechTranslate::getLocaleEnabled());
     } catch (exception $e) {
         throw new Exception('Could not connect to a database associated with this country. Please double check that you have the correct URL and that the site is configured correctly.');
     }
     # TRY loop is not returning values on system::getall()
     # Adding settings outside loop
     # CDL, 5.25.2012
     $sys = System::getAll();
     foreach ($sys as $key => $val) {
         $this->_countrySettings[$key] = $val;
     }
     $this->_countrySettings['num_location_tiers'] = 2 + $this->_countrySettings['display_region_b'] + $this->_countrySettings['display_region_c'] + $this->_countrySettings['display_region_d'] + $this->_countrySettings['display_region_e'] + $this->_countrySettings['display_region_f'] + $this->_countrySettings['display_region_g'] + $this->_countrySettings['display_region_h'] + $this->_countrySettings['display_region_i'];
     $response->setHeader('Content-Type', 'text/html; charset=utf-8', true);
 }
 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;
         }
     }
 }