/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     /**
      * Locale is enabled and allowed to be changed
      */
     if (config('locale.status')) {
         if (session()->has('locale') && in_array(session()->get('locale'), array_keys(config('locale.languages')))) {
             /**
              * Set the Laravel locale
              */
             app()->setLocale(session()->get('locale'));
             /**
              * setLocale for php. Enables ->formatLocalized() with localized values for dates
              */
             setLocale(LC_TIME, config('locale.languages')[session()->get('locale')][1]);
             /**
              * setLocale to use Carbon source locales. Enables diffForHumans() localized
              */
             Carbon::setLocale(config('locale.languages')[session()->get('locale')][0]);
             /**
              * Set the session variable for whether or not the app is using RTL support
              * for the current language being selected
              * For use in the blade directive in BladeServiceProvider
              */
             if (config('locale.languages')[session()->get('locale')][2]) {
                 session(['lang-rtl' => true]);
             } else {
                 session()->forget('lang-rtl');
             }
         }
     }
     return $next($request);
 }
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     /**
      * Application locale defaults for various components
      *
      * These will be overridden by LocaleMiddleware if the session local is set
      */
     /**
      * setLocale for php. Enables ->formatLocalized() with localized values for dates
      */
     setLocale(LC_TIME, config('app.locale_php'));
     /**
      * setLocale to use Carbon source locales. Enables diffForHumans() localized
      */
     Carbon::setLocale(config('app.locale'));
     /**
      * Set the session variable for whether or not the app is using RTL support
      * For use in the blade directive in BladeServiceProvider
      */
     if (config('locale.languages')[config('app.locale')][2]) {
         session(['lang-rtl' => true]);
     } else {
         session()->forget('lang-rtl');
     }
 }
Пример #3
0
 /**
  * Constructs the Website. Page- and theme-specific logic won't be loaded yet.
  */
 function __construct()
 {
     // We're loaded (included files test for the existance this constant)
     define("WEBSITE", "Loaded");
     // Site settings and database connection
     $this->config = new Config(dirname(dirname(__DIR__)) . '/' . self::CONFIG_FILE);
     $this->text = new Text(new Uri($this->getConfig()->get('url_web')), $this->getUriTranslations(Config::DEFAULT_LANGUAGE), $this->getUrlJavaScripts());
     // Connect to database, read settings
     try {
         $dataSource = "mysql:dbname={$this->config->get(Config::OPTION_DATABASE_NAME)};host={$this->config->get(Config::OPTION_DATABASE_HOST)}";
         $this->databaseObject = new TablePrefixedPDO($dataSource, $this->config->get(Config::OPTION_DATABASE_USER), $this->config->get(Config::OPTION_DATABASE_PASSWORD), ["table_prefix" => $this->config->get(Config::OPTION_DATABASE_TABLE_PREFIX)]);
         $this->databaseObject->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $this->databaseObject->prefixTables(["categories", "users", "links", "artikel", "comments", "menus", "widgets", "documents", "settings", "gebruikers", "reacties", "categorie"]);
         $this->config->readFromDatabase($this->databaseObject);
     } catch (PDOException $e) {
         // No database connection - safe to ignore this error, as the page
         // renderer will start the installation procedure, based on the lack
         // of settings
         $this->text->addError($this->text->tReplaced("install.no_database_connection", $e->getMessage()));
     }
     // Set updated properties of Text object, now that settings are read
     // from the database
     $this->text->setTranslationsDirectory($this->getUriTranslations($this->config->get("language")));
     $this->text->setUrlRewrite($this->config->get("url_rewrite"));
     // Init other objects
     if ($this->databaseObject == null) {
         $this->authenticationObject = new Authentication($this, null);
     } else {
         $this->authenticationObject = new Authentication($this, new UserRepository($this->databaseObject));
     }
     $this->themesObject = new ThemeManager($this);
     // Locales
     setLocale(LC_ALL, explode("|", $this->text->t("main.locales")));
 }
 function it_is_able_to_detect_language_code_based_on_environment_settings()
 {
     $previousLocale = setlocale(LC_ALL, 0);
     setLocale(LC_TIME, 'de_DE.UTF-8');
     $this->detectLanguage()->shouldContain('de');
     setlocale(LC_ALL, $previousLocale);
 }
Пример #5
0
 public static function replaceAccentedCharacters($string)
 {
     $currentLocale = setlocale(LC_ALL, NULL);
     setlocale(LC_ALL, 'en_US.UTF8');
     $cleanedString = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
     setLocale(LC_ALL, $currentLocale);
     return $cleanedString;
 }
Пример #6
0
 public function formatMoney($price = 0.0, $currency = 'USD')
 {
     $def = "en_US";
     //get the locale from the currency code
     $c = array("USD" => "en_US", "EUR" => "de_DE", "AUS" => "en_AU", "GBP" => "en_GB", "BRZ" => "pt_BR", "CAD" => "en_CA");
     $cLocale = $c[$currency];
     setLocale(LC_MONETARY, $cLocale);
     $s = money_format("%#1n", $price);
     setLocale(LC_MONETARY, "en_US");
     return $s;
 }
Пример #7
0
 public static function replaceAccentedCharacters($string)
 {
     if (function_exists('iconv')) {
         $currentLocale = setlocale(LC_ALL, NULL);
         setlocale(LC_ALL, 'en_US.UTF8');
         $cleanedString = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
         setLocale(LC_ALL, $currentLocale);
     } else {
         $cleanedString = strtr($string, 'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ', 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
     }
     return $cleanedString;
 }
Пример #8
0
 /**
  * Set Locale
  *
  * Example:
  * <code>
  * I18Nv2::setLocale('en_GB');
  * </code>
  *
  * @static
  * @access  public
  * @return  mixed   &type.string; used locale or false on failure
  * @param   string  $locale     a valid locale like en_US or de_DE
  * @param   int     $cat        the locale category - usually LC_ALL
  */
 static function setLocale($locale = null, $cat = LC_ALL)
 {
     if (!strlen($locale)) {
         return setLocale($cat, null);
     }
     $locales = I18Nv2::getStaticProperty('locales');
     // get complete standard locale code (en => en_US)
     if (isset($locales[$locale])) {
         $locale = $locales[$locale];
     }
     // get Win32 locale code (en_US => enu)
     if (I18Nv2_WIN) {
         $windows = I18Nv2::getStaticProperty('windows');
         $setlocale = isset($windows[$locale]) ? $windows[$locale] : $locale;
     } else {
         $setlocale = $locale;
     }
     $syslocale = setLocale($cat, $setlocale);
     // if the locale is not recognized by the system, check if there
     // is a fallback locale and try that, otherwise return false
     if (!$syslocale) {
         $fallbacks =& I18Nv2::getStaticProperty('fallbacks');
         if (isset($fallbacks[$locale])) {
             // avoid endless recursion with circular fallbacks
             $trylocale = $fallbacks[$locale];
             unset($fallbacks[$locale]);
             if ($retlocale = I18Nv2::setLocale($trylocale, $cat)) {
                 $fallbacks[$locale] = $trylocale;
                 return $retlocale;
             }
         }
         return false;
     }
     $language = substr($locale, 0, 2);
     if (I18Nv2_WIN) {
         @putEnv('LANG=' . $language);
         @putEnv('LANGUAGE=' . $language);
     } else {
         @putEnv('LANG=' . $locale);
         @putEnv('LANGUAGE=' . $locale);
     }
     // unshift locale stack
     $last =& I18Nv2::getStaticProperty('last');
     array_unshift($last, array(0 => $locale, 1 => $language, 2 => $syslocale, 'locale' => $locale, 'language' => $language, 'syslocale' => $syslocale));
     // fetch locale specific information
     $info =& I18Nv2::getStaticProperty('info');
     $info = localeConv();
     //For some reason Windows can return bogus locale data where frac_digits is 127, in that case just fall back to default english values
     if (isset($info['frac_digits']) and $info['frac_digits'] == 127) {
         $info = array('decimal_point' => '.', 'thousands_sep' => ',', 'int_curr_symbol' => '', 'currency_symbol' => '$', 'mon_decimal_point' => '.', 'mon_thousands_sep' => ',', 'positive_sign' => '', 'negative_sign' => '-', 'int_frac_digits' => 2, 'frac_digits' => 2, 'p_cs_precedes' => 1, 'p_sep_by_space' => 0, 'n_cs_precedes' => 1, 'n_sep_by_space' => 0, 'p_sign_posn' => 1, 'n_sign_posn' => 1, 'grouping' => array(3, 3), 'mon_grouping' => array(3, 3));
     }
     return $syslocale;
 }
Пример #9
0
 /**
  * Set Locale
  * 
  * Example:
  * <code>
  * I18Nv2::setLocale('en_GB');
  * </code>
  * 
  * @static
  * @access  public
  * @return  mixed   &type.string; used locale or false on failure
  * @param   string  $locale     a valid locale like en_US or de_DE
  * @param   int     $cat        the locale category - usually LC_ALL
  */
 function setLocale($locale = null, $cat = LC_ALL)
 {
     static $triedFallbacks;
     if (!strlen($locale)) {
         return setLocale($cat, null);
     }
     $locales = I18Nv2::getStaticProperty('locales');
     // get complete standard locale code (en => en_US)
     if (isset($locales[$locale])) {
         $locale = $locales[$locale];
     }
     // get Win32 locale code (en_US => enu)
     if (I18Nv2_WIN) {
         $windows = I18Nv2::getStaticProperty('windows');
         $setlocale = isset($windows[$locale]) ? $windows[$locale] : $locale;
     } else {
         $setlocale = $locale;
     }
     if (!isset($triedFallbacks[$locale])) {
         $triedFallbacks[$locale] = false;
     }
     $syslocale = setLocale($cat, $setlocale);
     // if the locale is not recognized by the system, check if there
     // is a fallback locale and try that, otherwise return false
     if (!$syslocale) {
         if (!$triedFallbacks[$locale]) {
             $triedFallbacks[$locale] = $setlocale;
             $fallbacks = I18Nv2::getStaticProperty('fallbacks');
             if (isset($fallbacks[$locale])) {
                 return I18Nv2::setLocale($fallbacks[$locale], $cat);
             }
         }
         return false;
     }
     $language = substr($locale, 0, 2);
     if (I18Nv2_WIN) {
         @putEnv('LANG=' . $language);
         @putEnv('LANGUAGE=' . $language);
     } else {
         @putEnv('LANG=' . $locale);
         @putEnv('LANGUAGE=' . $locale);
     }
     // unshift locale stack
     $last =& I18Nv2::getStaticProperty('last');
     array_unshift($last, array(0 => $locale, 1 => $language, 2 => $syslocale, 'locale' => $locale, 'language' => $language, 'syslocale' => $syslocale));
     // fetch locale specific information
     $info =& I18Nv2::getStaticProperty('info');
     $info = localeConv();
     return $syslocale;
 }
 public function handle($request, Closure $next)
 {
     $language = $request->route()->parameter('lang');
     App::setLocale($language);
     // Not super necessary unless you really want to use
     // number_format or even money_format.
     if ($language == "en") {
         setLocale(LC_ALL, "en_US.UTF-8");
     } else {
         setLocale(LC_ALL, $language . "_CH.UTF-8");
     }
     View::share('lang', $language);
     return $next($request);
 }
Пример #11
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     /**
      * Application locale defaults for various components
      *
      * These will be overridden by LocaleMiddleware if the session local is set
      */
     /**
      * setLocale for php. Enables ->formatLocalized() with localized values for dates
      */
     setLocale(LC_TIME, config('app.locale_php'));
     /**
      * setLocale to use Carbon source locales. Enables diffForHumans() localized
      */
     Carbon::setLocale(config('app.locale'));
 }
Пример #12
0
function quoted_printable_encode($str, $wrap = true)
{
    $ret = '';
    $l = strLen($str);
    $current_locale = setLocale(LC_CTYPE, 0);
    setLocale(LC_CTYPE, 'C');
    for ($i = 0; $i < $l; ++$i) {
        $char = $str[$i];
        if (ctype_print($char) && !ctype_cntrl($char) && $char !== '=') {
            $ret .= $char;
        } else {
            $ret .= sPrintF('=%02X', ord($char));
        }
    }
    setLocale(LC_CTYPE, $current_locale);
    return $wrap ? wordWrap($ret, 67, " =\n") : $ret;
}
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     /**
      * Locale is enabled and allowed to be changed
      */
     if (config('locale.status')) {
         if (session()->has('locale') && in_array(session()->get('locale'), array_keys(config('locale.languages')))) {
             /**
              * Set the Laravel locale
              */
             app()->setLocale(session()->get('locale'));
             /**
              * setLocale for php. Enables ->formatLocalized() with localized values for dates
              */
             setLocale(LC_TIME, config('locale.languages')[session()->get('locale')][1]);
             /**
              * setLocale to use Carbon source locales. Enables diffForHumans() localized
              */
             Carbon::setLocale(config('locale.languages')[session()->get('locale')][0]);
         }
     }
     return $next($request);
 }
Пример #14
0
 /**
  * Ajax request to submit data
  * @param array $request   the request
  * @return array           ajax format status
  */
 public function submitFormData($request)
 {
     $errors = array();
     $db = ezcDbInstance::get();
     $request = array_merge(array('ac_object_id' => null, 'gc_id' => null), $request);
     $request['wo_id'] = null;
     $request['ac_id'] = $request['id'];
     if (isset($request['mu_name'])) {
         $request['mu_id'] = R3EcoGisHelper::getMunicipalityIdByName($this->do_id, $request['mu_name'], $this->auth->getParam('mu_id'));
     }
     if ($this->act != 'del') {
         $request['ac_green_electricity_purchase'] = forceFloat($request['ac_green_electricity_purchase_mwh'], null, '.') * 1000;
         // Convert MWh to kWh
         $request['ac_co2_reduction'] = forceFloat($request['ac_co2_reduction_tco2'], null, '.') * 1000;
         // Convert tCO2 to kCO2
         $tmpGesIdConsumption = array();
         $tmpEsIdConsumption = array();
         $tmpUdmIdConsumption = array();
         $tmpAcExpectedEnergySaving = array();
         $tmpAcExpectedEnergySavingMwh = array();
         for ($i = 0; $i < count($request['es_id_consumption']); $i++) {
             if ($request['udm_id_consumption'][$i] != '' || $request['ac_expected_energy_saving'][$i] != '') {
                 $tmpGesIdConsumption[] = $request['ges_id_consumption'][$i];
                 $tmpEsIdConsumption[] = $request['es_id_consumption'][$i];
                 $tmpUdmIdConsumption[] = $request['udm_id_consumption'][$i];
                 $tmpAcExpectedEnergySaving[] = $request['ac_expected_energy_saving'][$i];
                 $tmpAcExpectedEnergySavingMwh[] = $request['ac_expected_energy_saving_mwh'][$i];
             }
         }
         $request['ges_id_consumption'] = $tmpGesIdConsumption;
         $request['es_id_consumption'] = $tmpEsIdConsumption;
         $request['udm_id_consumption'] = $tmpUdmIdConsumption;
         $request['ac_expected_energy_saving'] = $tmpAcExpectedEnergySaving;
         $request['ac_expected_energy_saving_mwh'] = $tmpAcExpectedEnergySavingMwh;
         $request['esu_id_consumption'] = R3EcoGisHelper::getMultipleEnergySourceUdmID($_SESSION['do_id'], $request['es_id_consumption'], $request['udm_id_consumption'], $request['mu_id']);
         $request['esu_id_production'] = R3EcoGisHelper::getEnergySourceUdmID($_SESSION['do_id'], $request['es_id_production'], $request['udm_id_production'], $request['mu_id'], true);
         $request['emo_id'] = self::getEnergyMeterObjectByID($request['mu_id'], $request['ac_object_id'], $request['gc_id']);
         if (isset($request['mu_name']) && $request['mu_name'] != '' && $request['mu_id'] == '') {
             $errors['mu_name'] = array('CUSTOM_ERROR' => _('Il comune immesso non è stato trovato'));
         }
         if (!isset($request['gc_id_parent']) || $request['gc_id_parent'] == '') {
             $errors['gc_id_parent'] = array('CUSTOM_ERROR' => _('Il campo "Macro-settore" è obbligatorio'));
         }
         $errors = $this->checkFormData($request, $errors);
         $selectedRelatedActions = array();
         if (isset($request['related_required_action_id'])) {
             for ($i = 0; $i < count($request['related_required_action_id']); $i++) {
                 if ($request['related_required_action_id'][$i] > 0 && in_array($request['related_required_action_id'][$i], $selectedRelatedActions)) {
                     $errors['related_required_action_' . $i] = array('CUSTOM_ERROR' => _("L'azione ") . $this->getActionName($request['related_required_action_id'][$i]) . _(" è già stata selezionata"));
                 }
                 array_push($selectedRelatedActions, $request['related_required_action_id'][$i]);
             }
         }
         if (isset($request['related_action_id'])) {
             for ($i = 0; $i < count($request['related_action_id']); $i++) {
                 if ($request['related_action_id'][$i] > 0 && in_array($request['related_action_id'][$i], $selectedRelatedActions)) {
                     $errors['related_action_' . $i] = array('CUSTOM_ERROR' => _("L'azione ") . $this->getActionName($request['related_action_id'][$i]) . _(" è già stata selezionata"));
                 }
                 array_push($selectedRelatedActions, $request['related_action_id'][$i]);
             }
         }
         if (isset($request['related_excluded_action_id'])) {
             for ($i = 0; $i < count($request['related_excluded_action_id']); $i++) {
                 if ($request['related_excluded_action_id'][$i] > 0 && in_array($request['related_excluded_action_id'][$i], $selectedRelatedActions)) {
                     $errors['related_required_action_' . $i] = array('CUSTOM_ERROR' => _("L'azione ") . $this->getActionName($request['related_excluded_action_id'][$i]) . _(" è già stata selezionata"));
                 }
                 array_push($selectedRelatedActions, $request['related_excluded_action_id'][$i]);
             }
         }
         if (isset($request['enable_benefit_year']) && $request['enable_benefit_year'] == 'T' && isset($request['benefit_year'])) {
             $startBenefitYear = (int) substr($request['ac_benefit_start_date'], 0, 4);
             $endBenefitYear = (int) substr($request['ac_benefit_end_date'], 0, 4);
             $lastBenefitPerc = 0;
             for ($i = 0; $i < count($request['benefit_year']); $i++) {
                 if ($request['benefit_year'][$i] != '' && $request['benefit_year'][$i] < $startBenefitYear) {
                     $errors['benefit_year_' . $i] = array('CUSTOM_ERROR' => sprintf(_("L'anno del beneficio \"%s\" è antecedente al %s (anno inizio beneficio)"), $request['benefit_year'][$i], $startBenefitYear));
                 } else {
                     if ($request['benefit_year'][$i] != '' && $request['benefit_year'][$i] > $endBenefitYear) {
                         $errors['benefit_year_' . $i] = array('CUSTOM_ERROR' => sprintf(_("L'anno del beneficio \"%s\" è oltre al %s (anno fine beneficio)"), $request['benefit_year'][$i], $endBenefitYear));
                     }
                 }
                 if ($request['benefit_benefit'][$i] != '' && $request['benefit_benefit'][$i] < 0 || $request['benefit_benefit'][$i] != '' && $request['benefit_benefit'][$i] > 100) {
                     $errors['benefit_benefit_' . $i] = array('CUSTOM_ERROR' => _("Il valore del beneficio deve essere compreso tra 0 e 100"));
                 }
             }
         }
     }
     if (count($errors) > 0) {
         return $this->getAjaxErrorResult($errors);
     } else {
         setLocale(LC_ALL, 'C');
         $db->beginTransaction();
         $id = $this->applyData($request);
         $sql = "DELETE FROM ecogis.action_catalog_energy WHERE ac_id=" . $db->quote($id, PDO::PARAM_INT);
         $db->exec($sql);
         if ($this->act != 'del') {
             for ($i = 0; $i < count($request['esu_id_consumption']); $i++) {
                 $sql = "INSERT INTO ecogis.action_catalog_energy  (ac_id, esu_id, ace_expected_energy_saving) " . " VALUES (" . $db->quote($id, PDO::PARAM_INT) . ", " . $db->quote($request['esu_id_consumption'][$i], PDO::PARAM_INT) . ", " . $db->quote($request['ac_expected_energy_saving'][$i], PDO::PARAM_INT) . ")";
                 $db->exec($sql);
             }
         }
         $sql = "DELETE FROM ecogis.action_catalog_dependencies WHERE ac_id=" . $db->quote($id, PDO::PARAM_INT);
         $db->exec($sql);
         if ($this->act != 'del') {
             $relatedActions = array();
             if (isset($request['related_action_id'])) {
                 for ($i = 0; $i < count($request['related_action_id']); $i++) {
                     array_push($relatedActions, array('related_action_id' => $request['related_action_id'][$i], 'acd_required' => 'D'));
                 }
             }
             if (isset($request['related_required_action_id'])) {
                 for ($i = 0; $i < count($request['related_required_action_id']); $i++) {
                     array_push($relatedActions, array('related_action_id' => $request['related_required_action_id'][$i], 'acd_required' => 'R'));
                 }
             }
             if (isset($request['related_excluded_action_id'])) {
                 for ($i = 0; $i < count($request['related_excluded_action_id']); $i++) {
                     array_push($relatedActions, array('related_action_id' => $request['related_excluded_action_id'][$i], 'acd_required' => 'E'));
                 }
             }
             foreach ($relatedActions as $relatedAction) {
                 $sql = "INSERT INTO ecogis.action_catalog_dependencies  (ac_id, ac_related_id, acd_type) " . " VALUES (" . $db->quote($id, PDO::PARAM_INT) . ", " . $db->quote($relatedAction['related_action_id'], PDO::PARAM_INT) . ", " . $db->quote($relatedAction['acd_required'], PDO::PARAM_BOOL) . ")";
                 if ($relatedAction['related_action_id'] > 0) {
                     $db->exec($sql);
                 }
             }
         }
         $sql = "DELETE FROM ecogis.action_catalog_benefit_year WHERE ac_id=" . $db->quote($id);
         $db->exec($sql);
         if ($this->act != 'del') {
             if (isset($request['enable_benefit_year']) && $request['enable_benefit_year'] == 'T') {
                 for ($i = 0; $i < count($request['benefit_year']); $i++) {
                     $year = forceInteger($request['benefit_year'][$i]);
                     $benefit = forceFloat($request['benefit_benefit'][$i], null, '.');
                     if ($year > 1970 && $request['benefit_benefit'][$i] != '') {
                         $sql = "INSERT INTO ecogis.action_catalog_benefit_year  (ac_id, acby_year, acby_benefit) " . "VALUES ({$id}, {$year}, {$benefit})";
                         $db->exec($sql);
                     }
                 }
             }
         }
         $db->commit();
         R3EcoGisCacheHelper::resetMapPreviewCache(null);
         R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true));
         if ($this->bu_id == '') {
             return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneActionCatalog({$id})");
         } else {
             return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataDoneActionCatalogFromBuilding({$id})");
         }
     }
 }
Пример #15
0
 /**
  * For the number for a certain pattern. The valid patterns are
  * 'c', 'd', 'e', 'p' or a custom pattern, such as "#.000" for
  * 3 decimal places.
  * @param mixed the number to format.
  * @param string the format pattern, either, 'c', 'd', 'e', 'p'
  * or a custom pattern. E.g. "#.000" will format the number to
  * 3 decimal places.
  * @param string 3-letter ISO 4217 code. For example, the code
  * "USD" represents the US Dollar and "EUR" represents the Euro currency.
  * @return string formatted number string
  */
 function format($number, $pattern = 'd', $currency = 'USD', $charset = 'UTF-8')
 {
     $oldLocale = setLocale(LC_NUMERIC, '0');
     setlocale(LC_NUMERIC, 'C');
     $this->setPattern($pattern);
     if (strtolower($pattern) == 'p') {
         $number = $number * 100;
     }
     $string = (string) $number;
     $decimal = $this->formatDecimal($string);
     $integer = $this->formatInteger(abs($number));
     if (strlen($decimal) > 0) {
         $result = $integer . $decimal;
     } else {
         $result = $integer;
     }
     //get the suffix
     if ($number >= 0) {
         $suffix = $this->formatInfo->PositivePattern;
     } else {
         if ($number < 0) {
             $suffix = $this->formatInfo->NegativePattern;
         } else {
             $suffix = array("", "");
         }
     }
     //append and prepend suffix
     $result = $suffix[0] . $result . $suffix[1];
     //replace currency sign
     $symbol = @$this->formatInfo->getCurrencySymbol($currency);
     if ($symbol === null) {
         $symbol = $currency;
     }
     $result = str_replace('¤', $symbol, $result);
     setlocale(LC_NUMERIC, $oldLocale);
     return I18N_toEncoding($result, $charset);
 }
Пример #16
0
 public function setLocale($locale)
 {
     if ($this->isWindows()) {
         throw new KurogoConfigurationException("Setting locale in Windows is not supported at this time");
     }
     // this is platform dependent.
     if (!($return = setLocale(LC_TIME, $locale))) {
         throw new KurogoConfigurationException("Unknown locale setting {$locale}");
     }
     $this->locale = $return;
     return $this->locale;
 }
Пример #17
0
 public function getSQLFields($data, array &$fields, array &$values)
 {
     $oldLocale = getLocale();
     setLocale(LC_ALL, 'C');
     $db = ezcDbInstance::get();
     foreach ($this->fields as $key => $field) {
         $default = isset($field['default']) ? $field['default'] : null;
         if (isset($field['is_primary_key']) && $field['is_primary_key'] === true) {
             continue;
             // ignore primary key
         }
         if (isset($field['calculated']) && $field['calculated'] === true) {
             continue;
             // ignore primary key
         }
         if (isset($field['name'])) {
             $key = $field['name'];
         }
         $fields[] = $key;
         if (isset($field['value'])) {
             $values[] = $db->quote($field['value']);
         } else {
             if ($field['type'] == 'NOW') {
                 $values[] = 'now()';
             } else {
                 if ($field['type'] == 'UID') {
                     $values[] = $this->auth->getUID();
                 } else {
                     if (isset($data[$key])) {
                         $values[] = $this->prepareFieldValue($this->act, $key, $data[$key], $field['type'], isset($field['size']) ? $field['size'] : null, $default);
                     } else {
                         $values[] = $this->prepareFieldValue($this->act, $key, null, $field['type'], isset($field['size']) ? $field['size'] : null, $default);
                     }
                 }
             }
         }
     }
     setLocale(LC_ALL, $oldLocale);
 }
Пример #18
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    return Redirect::to('/br');
});
Route::get('/{locale}', function ($locale) {
    App::setLocale($locale);
    return view('home');
});
Route::get('/{locale}/login', function ($locale) {
    App:
    setLocale($locale);
    return view('login');
});
Пример #19
0
/**
 * set the locale from the lang code
 *
 * @param string    the lang code
 * @param           category (@see setlocale). Default LC_ALL 
 * @return boolean  return true on success
 * @see localeconv
 */
function setLang($lang, $category = LC_ALL)
{
    if (($locale = getLocaleByLang($lang)) === null) {
        return false;
    }
    return setLocale($category, $locale);
}
Пример #20
0
    phpinfo();
    ?>
		<?php 
}
?>
	</div>
	
	<h1><a style="color:inherit" href="<?php 
echo URL()->addParam('open', 'locale');
?>
">Locales</a></h1>
	<div class="be_contentTextBox">
		<?php 
if ($_GET['open'] == 'locale') {
    ?>
			active: "<?php 
    echo setLocale(0, 0);
    ?>
"
			<hr>
			available on the system:
			<pre><?php 
    system('locale -a');
    ?>
</pre>
		<?php 
}
?>
	</div>
</div>
</div>
Пример #21
0
    } else {
        $lfound = setLocale(LC_TIME, $out);
        if ($lfound === false) {
            gs_log(GS_LOG_NOTICE, 'Your system does not have any locales like "' . $lang . '_*"');
        } else {
            gs_log(GS_LOG_NOTICE, 'Using locale "' . $lfound . '" as a fallback');
        }
    }
}
$wdays = array('mo' => 'Mon', 'tu' => 'Tue', 'we' => 'Wed', 'th' => 'Thu', 'fr' => 'Fri', 'sa' => 'Sat', 'su' => 'Sun');
$wdaysl = array();
foreach ($wdays as $col => $wdca) {
    $wdaysl[$col] = mb_subStr(strFTime('%a', strToTime('last ' . $wdca)), 0, 1);
}
unset($wdays);
setLocale(LC_TIME, array($oldLocale, 'C'));
$i = 0;
$rs = $DB->execute('SELECT * from `queue_cf_timerules` WHERE `_queue_id`=' . $queue_id . ' ORDER BY `ord`');
while ($route = $rs->fetchRow()) {
    echo '<input type="hidden" name="tr_' . $route['id'] . '" value="' . $route['id'] . '" />';
    echo '<tr><td>';
    echo $route['ord'];
    echo '</td><td>';
    foreach ($wdaysl as $col => $v) {
        echo '<span class="nobr"><input type="checkbox" name="' . $route['id'] . '-d_', $col, '" id="ipt-' . $route['id'] . '-r_d_', $col, '" value="1" ', $route['d_' . $col] ? 'checked="checked" ' : '', '/>';
        echo '<label for="ipt-r_d_', $col, '">', $v, '</label></span>';
    }
    echo '</td>', "\n";
    echo '<td>';
    $tmp = explode(':', $route['h_from']);
    $hf = (int) lTrim(@$tmp[0], '0-');
Пример #22
0
 /**
  * Ajax request to submit data
  * @param array $request   the request
  * @return array           ajax format status
  */
 public function submitFormData($request)
 {
     $errors = array();
     $db = ezcDbInstance::get();
     $request['us_id'] = (int) $request['id'];
     $request['do_id'] = $this->do_id;
     if ($this->act != 'del') {
         $errors = $this->checkFormData($request);
     }
     if (count($errors) > 0) {
         return $this->getAjaxErrorResult($errors);
     } else {
         $oldLocale = getLocale();
         setLocale(LC_ALL, 'C');
         $db->beginTransaction();
         $oldIds = R3EcoGisUtilityHelper::getProductId($request['us_id']);
         if ($this->act == 'del') {
             // Cancella comuni vecchi
             R3EcoGisUtilityHelper::setMunicipality($request['us_id'], array());
             foreach ($db->query("SELECT up_id FROM utility_product WHERE us_id=" . (int) $request['us_id']) as $row) {
                 R3EcoGisUtilityHelper::deleteProduct(array('up_id' => $row['up_id']));
             }
         }
         $id = $this->applyData($request);
         $newIds = array(0, 1, 2);
         // valori nuovo
         $cantDelete = 'F';
         if ($this->act == 'add' || $this->act == 'mod') {
             $order = 0;
             R3EcoGisUtilityHelper::setMunicipality($id, explode(',', $request['municipality']));
             // Modifica valori vecchi
             foreach ($oldIds as $up_id) {
                 $order += 10;
                 if (isset($request["up_name_1_{$up_id}"]) && $request["up_name_1_{$up_id}"] != '') {
                     R3EcoGisUtilityHelper::updateProduct(array('up_id' => $up_id, 'up_name_1' => $request["up_name_1_{$up_id}"], 'up_name_2' => @$request["up_name_2_{$up_id}"], 'esu_co2_factor' => $request["esu_co2_factor_{$up_id}"], 'ges_id' => $request["ges_id_{$up_id}"], 'up_order' => $order));
                 } else {
                     try {
                         R3EcoGisUtilityHelper::deleteProduct(array('up_id' => $up_id));
                     } catch (Exception $e) {
                         $cantDelete = 'T';
                     }
                 }
             }
             // Aggiunge valori nuovi
             foreach ($newIds as $up_id) {
                 // echo $request["up_name_1_new_{$up_id}"];
                 $order += 10;
                 if (isset($request["up_name_1_new_{$up_id}"]) && $request["up_name_1_new_{$up_id}"] != '') {
                     R3EcoGisUtilityHelper::addProduct(array('do_id' => $this->do_id, 'us_id' => $id, 'up_name_1' => $request["up_name_1_new_{$up_id}"], 'up_name_2' => @$request["up_name_2_new_{$up_id}"], 'up_order' => $order, 'esu_co2_factor' => $request["esu_co2_factor_new_{$up_id}"], 'ges_id' => $request["ges_id_new_{$up_id}"], 'et_code' => $request["et_code_new_{$up_id}"]));
                 }
             }
         }
         $db->commit();
         R3EcoGisEventNotifier::notifyDataChanged($this, array('data_changed' => true));
         setLocale(LC_ALL, $oldLocale);
         return array('status' => R3_AJAX_NO_ERROR, 'js' => "submitFormDataUtilityDone({$id}, '{$cantDelete}')");
     }
 }
Пример #23
0
 function __construct()
 {
     parent::__construct();
     $this->set_error_delimiters("", "");
     setLocale(LC_CTYPE, 'es_VE.UTF-8');
 }
Пример #24
0
 function getImportInfo()
 {
     $this->onExecuteBefore('getImportInfo');
     $encoding = $this->getState('encoding');
     if ($encoding == 'cp1251') {
         setLocale(LC_ALL, 'ru_RU.CP1251');
     }
     if ($_FILES['photos_zip']['tmp_name'] != '') {
         $import_dir = JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'import' . DS;
         JFolder::delete($import_dir);
         JFolder::create($import_dir, 0777);
         copy($_FILES['photos_zip']['tmp_name'], $import_dir . 'import.zip');
         $result = JArchive::extract(JPath::clean($import_dir . 'import.zip'), JPath::clean($import_dir));
     }
     $unic = JRequest::getVar('unic');
     $f = fopen(JPATH_COMPONENT . DS . 'tmp' . DS . 'import.csv', "rt") or die("Ошибка!");
     $info = array('insert' => '', 'update' => '');
     $relatives = array();
     for ($k = 0; $data = fgetcsv($f, 10000, ";"); $k++) {
         if ($k == 0) {
             $headers = $data;
             continue;
         }
         $product_data = array();
         if ($k > 0) {
             if (isset($_POST['title']) && $_POST['title'] != '') {
                 $product_data['title'] = $this->encode($data[$_POST['title']]);
             }
             if (isset($_POST['parent_id']) && $_POST['parent_id'] != '') {
                 $product_data['parent_id'] = $this->encode($data[$_POST['parent_id']]);
             }
             if (isset($_POST['categories']) && $_POST['categories'] != '') {
                 $product_data['categories'] = $this->encode($data[$_POST['categories']]);
             }
             if (isset($_POST['childs_group']) && $_POST['childs_group'] != '') {
                 $product_data['childs_group'] = $this->encode($data[$_POST['childs_group']]);
             }
             if (isset($_POST['price']) && $_POST['price'] != '') {
                 $product_data['price'] = str_replace(' ', '', $this->encode($data[$_POST['price']]));
             }
             if (isset($_POST['promotion_price']) && $_POST['promotion_price'] != '') {
                 $product_data['promotion_price'] = (double) str_replace(' ', '', $this->encode($data[$_POST['promotion_price']]));
             }
             if (isset($_POST['price_type']) && $_POST['price_type'] != '') {
                 $product_data['price_type'] = str_replace(' ', '', $this->encode($data[$_POST['price_type']]));
             }
             if (isset($_POST['product_code']) && $_POST['product_code'] != '') {
                 $product_data['product_code'] = $this->encode($data[$_POST['product_code']]);
             }
             if (isset($_POST['product_packaging']) && $_POST['product_packaging'] != '') {
                 $product_data['product_packaging'] = (double) str_replace(' ', '', $this->encode($data[$_POST['product_packaging']]));
             }
             if (isset($_POST['product_unit']) && $_POST['product_unit'] != '') {
                 $product_data['product_unit'] = str_replace(' ', '', $this->encode($data[$_POST['product_unit']]));
             }
             if (isset($_POST['in_stock']) && $_POST['in_stock'] != '') {
                 $product_data['in_stock'] = (double) $this->encode($data[$_POST['in_stock']]);
             }
             if (isset($_POST['promotion']) && $_POST['promotion'] != '') {
                 $product_data['promotion'] = $this->encode($data[$_POST['promotion']]);
             }
             if (isset($_POST['manufacturer']) && $_POST['manufacturer'] != '') {
                 $product_data['manufacturer'] = $this->encode($data[$_POST['manufacturer']]);
             }
             if (isset($_POST['country']) && $_POST['country'] != '') {
                 $product_data['country'] = $this->encode($data[$_POST['country']]);
             }
             if (isset($_POST['content']) && $_POST['content'] != '') {
                 $product_data['content'] = $this->encode($data[$_POST['content']]);
             }
             if (isset($_POST['photos']) && $_POST['photos'] != '') {
                 $product_data['photos'] = $this->encode($data[$_POST['photos']]);
             }
             if (isset($_POST['relative']) && $_POST['relative'] != '') {
                 $product_data['relative'] = $this->encode($data[$_POST['relative']]);
             }
             if (isset($_POST['tags']) && $_POST['tags'] != '') {
                 $product_data['tags'] = $this->encode($data[$_POST['tags']]);
             }
             if (isset($_POST['metatitle']) && $_POST['metatitle'] != '') {
                 $product_data['metatitle'] = $this->encode($data[$_POST['metatitle']]);
             } else {
                 $product_data['metatitle'] = '';
             }
             if (isset($_POST['metadescription']) && $_POST['metadescription'] != '') {
                 $product_data['metadescription'] = $this->encode($data[$_POST['metadescription']]);
             } else {
                 $product_data['metadescription'] = '';
             }
             if (isset($_POST['metakeywords']) && $_POST['metakeywords'] != '') {
                 $product_data['metakeywords'] = $this->encode($data[$_POST['metakeywords']]);
             } else {
                 $product_data['metakeywords'] = '';
             }
             $product_data['type'] = 'product';
             $query = $this->_db->getQuery(true);
             $query->select('*')->from('#__ksenmart_properties')->order('ordering');
             $this->_db->setQuery($query);
             $properties = $this->_db->loadObjectList();
             foreach ($properties as $property) {
                 if (isset($_POST['property_' . $property->id]) && $_POST['property_' . $property->id] != '') {
                     $product_data['property_' . $property->id] = $this->encode($data[$_POST['property_' . $property->id]]);
                 }
             }
             $query = $this->_db->getQuery(true);
             $query->select('id')->from('#__ksenmart_currencies')->where('`default`=1');
             $this->_db->setQuery($query);
             $def_price_type = $this->_db->loadResult();
             $query = $this->_db->getQuery(true);
             $query->select('id')->from('#__ksenmart_product_units');
             $this->_db->setQuery($query, 0, 1);
             $def_unit = $this->_db->loadResult();
             if (isset($product_data['parent_id']) && $product_data['parent_id'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('id')->from('#__ksenmart_products')->where($unic . '=' . $this->_db->quote($product_data['parent_id']))->where('parent_id=0');
                 $this->_db->setQuery($query);
                 $parent_id = $this->_db->loadResult();
                 if (empty($parent_id)) {
                     $product_data['parent_id'] = 0;
                 } else {
                     $product_data['type'] = 'child';
                     $product_data['parent_id'] = $parent_id;
                     $query = $this->_db->getQuery(true);
                     $query->update('#__ksenmart_products')->set('is_parent=1')->where('id=' . $parent_id);
                     $this->_db->setQuery($query);
                     $this->_db->query();
                 }
             } else {
                 $product_data['parent_id'] = 0;
             }
             if (isset($product_data['childs_group']) && $product_data['childs_group'] != '' && $product_data['parent_id'] != 0) {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_products_child_groups')->where('title like ' . $this->_db->quote($product_data['childs_group']))->where('product_id=' . $product_data['parent_id']);
                 $this->_db->setQuery($query);
                 $childs_group = $this->_db->loadObject();
                 if (count($childs_group) == 0) {
                     $qvalues = array($this->_db->quote($product_data['childs_group']), $product_data['parent_id']);
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_products_child_groups')->columns('title,product_id')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $childs_group_id = $this->_db->insertid();
                     $product_data['childs_group'] = $childs_group_id;
                 } else {
                     $product_data['childs_group'] = $childs_group->id;
                 }
             } else {
                 $product_data['childs_group'] = 0;
             }
             if (isset($product_data['price_type']) && $product_data['price_type'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_currencies')->where('title=' . $this->_db->quote($product_data['price_type']));
                 $this->_db->setQuery($query);
                 $price_type = $this->_db->loadObject();
                 if (count($price_type) == 0) {
                     $product_data['price_type'] = $def_price_type;
                 } else {
                     $product_data['price_type'] = $price_type->id;
                 }
             } else {
                 $product_data['price_type'] = $def_price_type;
             }
             if (isset($product_data['product_unit']) && $product_data['product_unit'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_product_units')->where('form1=' . $this->_db->quote($product_data['product_unit']));
                 $this->_db->setQuery($query);
                 $unit = $this->_db->loadObject();
                 if (count($unit) == 0) {
                     $qvalues = array($this->_db->quote($product_data['product_unit']), $this->_db->quote($product_data['product_unit']), $this->_db->quote($product_data['product_unit']));
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_product_units')->columns('form1,form2,form5')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $unit_id = $this->_db->insertid();
                     $product_data['product_unit'] = $unit_id;
                 } else {
                     $product_data['product_unit'] = $unit->id;
                 }
             } else {
                 $product_data['product_unit'] = $def_unit;
             }
             if (isset($product_data['promotion_price']) && $product_data['promotion_price'] != '') {
                 $product_data['promotion'] = 1;
                 $product_data['old_price'] = $product_data['price'];
                 $product_data['price'] = $product_data['promotion_price'];
             } else {
                 $product_data['promotion'] = 0;
                 $product_data['old_price'] = 0;
             }
             if (isset($product_data['country']) && $product_data['country'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_countries')->where('title=' . $this->_db->quote($product_data['country']));
                 $this->_db->setQuery($query);
                 $country = $this->_db->loadObject();
                 if (count($country) == 0) {
                     $alias = KSFunctions::GenAlias($product_data['country']);
                     $qvalues = array($this->_db->quote($product_data['country']), $this->_db->quote($alias), 1, $this->_db->quote($product_data['country']));
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_countries')->columns('title,alias,published,metatitle')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $country_id = $this->_db->insertid();
                     $product_data['country'] = $country_id;
                 } else {
                     $product_data['country'] = $country->id;
                 }
             } else {
                 $product_data['country'] = 0;
             }
             if (isset($product_data['manufacturer']) && $product_data['manufacturer'] != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_manufacturers')->where('title=' . $this->_db->quote($product_data['manufacturer']));
                 $this->_db->setQuery($query);
                 $manufacturer = $this->_db->loadObject();
                 if (count($manufacturer) == 0) {
                     $alias = KSFunctions::GenAlias($product_data['manufacturer']);
                     $qvalues = array($this->_db->quote($product_data['manufacturer']), $this->_db->quote($alias), $this->_db->quote($product_data['country']), 1, $this->_db->quote($product_data['manufacturer']));
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_manufacturers')->columns('title,alias,country,published,metatitle')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $manufacturer_id = $this->_db->insertid();
                     $product_data['manufacturer'] = $manufacturer_id;
                 } else {
                     $product_data['manufacturer'] = $manufacturer->id;
                 }
             } else {
                 $product_data['manufacturer'] = 0;
             }
             $categories = explode(';', $product_data['categories']);
             $prd_cats = array();
             foreach ($categories as $cats) {
                 $parent = 0;
                 $prd_cat = 0;
                 $cats = explode(':', $cats);
                 foreach ($cats as $cat) {
                     $cat = trim($cat);
                     if ($cat != '') {
                         $query = $this->_db->getQuery(true);
                         $query->select('*')->from('#__ksenmart_categories')->where('title=' . $this->_db->quote($cat))->where('parent_id=' . $parent);
                         $this->_db->setQuery($query);
                         $category = $this->_db->loadObject();
                         if (!$category) {
                             $alias = KSFunctions::GenAlias($cat);
                             $qvalues = array($this->_db->quote($cat), $this->_db->quote($alias), $parent, 1);
                             $query = $this->_db->getQuery(true);
                             $query->insert('#__ksenmart_categories')->columns('title,alias,parent_id,published')->values(implode(',', $qvalues));
                             $this->_db->setQuery($query);
                             $this->_db->query();
                             $prd_cat = $this->_db->insertid();
                             $parent = $prd_cat;
                         } else {
                             $prd_cat = $category->id;
                             $parent = $prd_cat;
                         }
                         $prd_cats[] = $prd_cat;
                     }
                 }
             }
             if ($product_data['parent_id'] != 0) {
                 $prd_cats = array();
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_products_categories')->where('product_id=' . $product_data['parent_id']);
                 $this->_db->setQuery($query);
                 $cats = $this->_db->loadObjectList();
                 foreach ($cats as $cat) {
                     $prd_cats[] = $cat->category_id;
                 }
             }
             if (!isset($product_data['price'])) {
                 $product_data['price'] = 0;
             }
             if (!isset($product_data['product_code'])) {
                 $product_data['product_code'] = '';
             }
             if (!isset($product_data['product_packaging'])) {
                 $product_data['product_packaging'] = 1;
             }
             if (!isset($product_data['in_stock'])) {
                 $product_data['in_stock'] = 1;
             }
             if (!isset($product_data['content'])) {
                 $product_data['content'] = '';
             }
             if ($unic != '') {
                 $query = $this->_db->getQuery(true);
                 $query->select('*')->from('#__ksenmart_products')->where($unic . '=' . $this->_db->quote($product_data[$unic]))->where('parent_id=' . $product_data['parent_id']);
                 $this->_db->setQuery($query);
                 $product = $this->_db->loadObjectList();
             }
             if (count($product) == 0) {
                 $alias = KSFunctions::GenAlias($product_data['title']);
                 $values = array('parent_id' => $product_data['parent_id'], 'childs_group' => $product_data['childs_group'], 'title' => $this->_db->quote($product_data['title']), 'alias' => $this->_db->quote($alias), 'price' => $this->_db->quote($product_data['price']), 'old_price' => $this->_db->quote($product_data['old_price']), 'price_type' => $product_data['price_type'], 'in_stock' => $product_data['in_stock'], 'product_code' => $this->_db->quote($product_data['product_code']), 'product_packaging' => $product_data['product_packaging'], 'product_unit' => $product_data['product_unit'], 'content' => $this->_db->quote($product_data['content']), 'promotion' => $product_data['promotion'], 'manufacturer' => $product_data['manufacturer'], 'published' => 1, 'metatitle' => $this->_db->quote($product_data['metatitle']), 'metadescription' => $this->_db->quote($product_data['metadescription']), 'metakeywords' => $this->_db->quote($product_data['metakeywords']), 'date_added' => 'NOW()', 'type' => $this->_db->quote($product_data['type']));
                 $query = $this->_db->getQuery(true);
                 $query->update('#__ksenmart_products')->set('ordering=ordering+1');
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 $query = $this->_db->getQuery(true);
                 $query->insert('#__ksenmart_products')->columns(implode(',', array_keys($values)))->values(implode(',', $values));
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 $product_id = $this->_db->insertid();
                 $is_default = true;
                 foreach ($prd_cats as $prd_cat) {
                     $qvalues = array($product_id, $prd_cat, (int) $is_default);
                     $query = $this->_db->getQuery(true);
                     $query->insert('#__ksenmart_products_categories')->columns('product_id,category_id,is_default')->values(implode(',', $qvalues));
                     $this->_db->setQuery($query);
                     $this->_db->query();
                     $is_default = false;
                 }
                 $info['insert']++;
             } else {
                 $product_id = $product[0]->id;
                 $to_update = array();
                 $to_update[] = 'date_added=NOW()';
                 if (isset($product_data['title'])) {
                     $to_update[] = 'title=' . $this->_db->quote($product_data['title']);
                 }
                 if (isset($product_data['product_code'])) {
                     $to_update[] = 'product_code=' . $this->_db->quote($product_data['product_code']);
                 }
                 if (isset($product_data['in_stock'])) {
                     $to_update[] = 'in_stock=' . $this->_db->quote($product_data['in_stock']);
                 }
                 if (isset($product_data['content'])) {
                     $to_update[] = 'content=' . $this->_db->quote($product_data['content']);
                 }
                 if (isset($product_data['introcontent'])) {
                     $to_update[] = 'introcontent=' . $this->_db->quote($product_data['introcontent']);
                 }
                 if (isset($product_data['product_packaging'])) {
                     $to_update[] = 'product_packaging=' . $this->_db->quote($product_data['product_packaging']);
                 }
                 if ($product_data['metatitle'] != '') {
                     $to_update[] = 'metatitle=' . $this->_db->quote($product_data['metatitle']);
                 }
                 if ($product_data['metadescription'] != '') {
                     $to_update[] = 'metadescription=' . $this->_db->quote($product_data['metadescription']);
                 }
                 if ($product_data['metakeywords'] != '') {
                     $to_update[] = 'metakeywords=' . $this->_db->quote($product_data['metakeywords']);
                 }
                 if (isset($product_data['price'])) {
                     $to_update[] = 'price=' . $this->_db->quote($product_data['price']);
                 }
                 if (isset($product_data['manufacturer'])) {
                     $to_update[] = 'manufacturer=' . $this->_db->quote($product_data['manufacturer']);
                 }
                 if (isset($product_data['price_type'])) {
                     $to_update[] = 'price_type=' . $this->_db->quote($product_data['price_type']);
                 }
                 if (isset($product_data['product_unit'])) {
                     $to_update[] = 'product_unit=' . $this->_db->quote($product_data['product_unit']);
                 }
                 if (isset($product_data['old_price'])) {
                     $to_update[] = 'old_price=' . $this->_db->quote($product_data['old_price']);
                 }
                 if (isset($product_data['promotion'])) {
                     $to_update[] = 'promotion=' . $this->_db->quote($product_data['promotion']);
                 }
                 foreach ($prd_cats as $prd_cat) {
                     $query = $this->_db->getQuery(true);
                     $query->select('*')->from('#__ksenmart_products_categories')->where('product_id=' . $product_id)->where('category_id=' . $prd_cat);
                     $this->_db->setQuery($query);
                     $db_cat = $this->_db->loadObject();
                     if (count($db_cat) == 0) {
                         $qvalues = array($product_id, $prd_cat);
                         $query = $this->_db->getQuery(true);
                         $query->insert('#__ksenmart_products_categories')->columns('product_id,category_id')->values(implode(',', $qvalues));
                         $this->_db->setQuery($query);
                         $this->_db->query();
                     }
                 }
                 $query = $this->_db->getQuery(true);
                 $query->update('#__ksenmart_products')->set($to_update)->where('id=' . $product_id);
                 $this->_db->setQuery($query);
                 $this->_db->query();
                 if (isset($product_data['photos']) && $product_data['photos'] != '') {
                     $query = $this->_db->getQuery(true);
                     $query->select('*')->from('#__ksenmart_files')->where(array("media_type='image'", "owner_type='product'", "owner_id=" . $product_id))->order('ordering');
                     $this->_db->setQuery($query);
                     $images = $this->_db->loadObjectList('id');
                     $i = count($images);
                     foreach ($images as $image) {
                         $this->delPhoto($image->filename, $image->folder);
                     }
                 }
                 $info['update']++;
             }
             if (isset($product_data['relative']) && $product_data['relative'] != '') {
                 $relatives[$product_id] = $product_data['relative'];
             }
             if (isset($product_data['tags']) && $product_data['tags'] != '') {
                 $product_data['tags'] = explode(',', $product_data['tags']);
                 foreach ($product_data['tags'] as $key => $value) {
                     $value = trim($value);
                     $query = $this->_db->getQuery(true);
                     $query->select('id')->from('#__tags')->where('title=' . $this->_db->quote($value));
                     $this->_db->setQuery($query);
                     $tag_id = $this->_db->loadResult();
                     if (!empty($tag_id)) {
                         $product_data['tags'][$key] = $tag_id;
                     } else {
                         $product_data['tags'][$key] = '#new#' . $value;
                     }
                 }
                 $tableProducts = $this->getTable('Products');
                 JObserverMapper::attachAllObservers($tableProducts);
                 JObserverMapper::addObserverClassToClass('JTableObserverTags', 'KsenmartTableProducts', array('typeAlias' => 'com_ksenmart.product'));
                 $tableProducts->load($product_id);
                 $tagsObserver = $tableProducts->getObserverOfClass('JTableObserverTags');
                 $result = $tagsObserver->setNewTags($product_data['tags'], true);
             }
             if (isset($product_data['photos']) && $product_data['photos'] != '') {
                 $product_data['photos'] = explode(',', $product_data['photos']);
                 $i = 1;
                 foreach ($product_data['photos'] as $photo) {
                     $photo = trim($photo);
                     if (!empty($photo)) {
                         $file = basename($photo);
                         $nameParts = explode('.', $file);
                         $file = microtime(true) . '.' . $nameParts[count($nameParts) - 1];
                         $copied = false;
                         if (strpos($photo, 'http://') !== false) {
                             if ($photo_content = file_get_contents($photo)) {
                                 if (file_put_contents(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'images' . DS . 'products' . DS . 'original' . DS . $file, $photo_content)) {
                                     $copied = true;
                                 }
                             }
                         } else {
                             if (file_exists(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'import' . DS . $photo)) {
                                 if (copy(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'import' . DS . $photo, JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'images' . DS . 'products' . DS . 'original' . DS . $file)) {
                                     $copied = true;
                                 }
                             }
                         }
                         if ($copied) {
                             $mime = mime_content_type(JPATH_ROOT . DS . 'media' . DS . 'com_ksenmart' . DS . 'images' . DS . 'products' . DS . 'original' . DS . $file);
                             $qvalues = array($product_id, $this->_db->quote('image'), $this->_db->quote('product'), $this->_db->quote('products'), $this->_db->quote($file), $this->_db->quote($mime), $this->_db->quote(''), $i);
                             $query = $this->_db->getQuery(true);
                             $query->insert('#__ksenmart_files')->columns('owner_id,media_type,owner_type,folder,filename,mime_type,title,ordering')->values(implode(',', $qvalues));
                             $this->_db->setQuery($query);
                             $this->_db->query();
                             $i++;
                         }
                     }
                 }
             }
             foreach ($properties as $property) {
                 if (isset($product_data['property_' . $property->id]) && $product_data['property_' . $property->id] != '') {
                     switch ($property->type) {
                         case 'text':
                             if ($product_data['property_' . $property->id] != '') {
                                 $query = $this->_db->getQuery(true);
                                 $query->select('*')->from('#__ksenmart_property_values')->where('property_id=' . $property->id)->where('title=' . $this->_db->quote($product_data['property_' . $property->id]));
                                 $this->_db->setQuery($query);
                                 $prop_value = $this->_db->loadObject();
                                 if (count($prop_value) == 0) {
                                     $alias = KSFunctions::GenAlias($product_data['property_' . $property->id]);
                                     $qvalues = array($property->id, $this->_db->quote($product_data['property_' . $property->id]), $this->_db->quote($alias));
                                     $query = $this->_db->getQuery(true);
                                     $query->insert('#__ksenmart_property_values')->columns('property_id,title,alias')->values(implode(',', $qvalues));
                                     $this->_db->setQuery($query);
                                     $this->_db->query();
                                     $prop_value_id = $this->_db->insertid();
                                 } else {
                                     $prop_value_id = $prop_value->id;
                                 }
                                 $query = $this->_db->getQuery(true);
                                 $query->select('*')->from('#__ksenmart_product_properties_values')->where('product_id=' . $product_id)->where('property_id=' . $property->id)->where('value_id=' . $prop_value_id);
                                 $this->_db->setQuery($query);
                                 $prod_prop_value = $this->_db->loadObject();
                                 if (count($prod_prop_value) == 0) {
                                     $qvalues = array($product_id, $property->id, $prop_value_id, $this->_db->quote($product_data['property_' . $property->id]));
                                     $query = $this->_db->getQuery(true);
                                     $query->insert('#__ksenmart_product_properties_values')->columns('product_id,property_id,value_id,text')->values(implode(',', $qvalues));
                                     $this->_db->setQuery($query);
                                     $this->_db->query();
                                 }
                             }
                             break;
                         default:
                             $prop_vals = explode(';', $product_data['property_' . $property->id]);
                             $prop_values = '';
                             foreach ($prop_vals as $prop_val) {
                                 if ($prop_val != '') {
                                     $val_parts = explode('=', $prop_val);
                                     if (count($val_parts) == 2) {
                                         $prop_val = $val_parts[0];
                                         $val_price = $val_parts[1];
                                     } else {
                                         $val_price = '';
                                     }
                                     $query = $this->_db->getQuery(true);
                                     $query->select('*')->from('#__ksenmart_property_values')->where('property_id=' . $property->id)->where('title=' . $this->_db->quote($prop_val));
                                     $this->_db->setQuery($query);
                                     $prop_value = $this->_db->loadObject();
                                     if (count($prop_value) == 0) {
                                         $alias = KSFunctions::GenAlias($prop_val);
                                         $qvalues = array($property->id, $this->_db->quote($prop_val), $this->_db->quote($alias));
                                         $query = $this->_db->getQuery(true);
                                         $query->insert('#__ksenmart_property_values')->columns('property_id,title,alias')->values(implode(',', $qvalues));
                                         $this->_db->setQuery($query);
                                         $this->_db->query();
                                         $prop_value_id = $this->_db->insertid();
                                     } else {
                                         $prop_value_id = $prop_value->id;
                                     }
                                     $query = $this->_db->getQuery(true);
                                     $query->select('*')->from('#__ksenmart_product_properties_values')->where('product_id=' . $product_id)->where('property_id=' . $property->id)->where('value_id=' . $prop_value_id);
                                     $this->_db->setQuery($query);
                                     $prod_prop_value = $this->_db->loadObject();
                                     if (count($prod_prop_value) == 0) {
                                         $qvalues = array($product_id, $property->id, $prop_value_id, $this->_db->quote($val_price));
                                         $query = $this->_db->getQuery(true);
                                         $query->insert('#__ksenmart_product_properties_values')->columns('product_id,property_id,value_id,price')->values(implode(',', $qvalues));
                                         $this->_db->setQuery($query);
                                         $this->_db->query();
                                     } else {
                                         $query = $this->_db->getQuery(true);
                                         $query->update('#__ksenmart_product_properties_values')->set('price=' . $this->_db->quote($val_price))->where('id=' . $prod_prop_value->id);
                                         $this->_db->setQuery($query);
                                         $this->_db->query();
                                     }
                                 }
                             }
                     }
                     foreach ($prd_cats as $prd_cat) {
                         $query = $this->_db->getQuery(true);
                         $query->select('id')->from('#__ksenmart_product_categories_properties')->where('category_id=' . $prd_cat)->where('property_id=' . $property->id);
                         $this->_db->setQuery($query);
                         $res = $this->_db->loadResult();
                         if (empty($res)) {
                             $qvalues = array($prd_cat, $property->id);
                             $query = $this->_db->getQuery(true);
                             $query->insert('#__ksenmart_product_categories_properties')->columns('category_id,property_id')->values(implode(',', $qvalues));
                             $this->_db->setQuery($query);
                             $this->_db->query();
                         }
                     }
                 }
             }
         }
     }
     foreach ($relatives as $product_id => $relative) {
         $relative = explode(';', $relative);
         foreach ($relative as $relative_title) {
             if (!empty($relative_title)) {
                 $query = $this->_db->getQuery(true);
                 $query->select('id')->from('#__ksenmart_products')->where('title like ' . $this->_db->quote($relative_title));
                 $this->_db->setQuery($query);
                 $relative_id = $this->_db->loadResult();
                 if (!empty($relative_id)) {
                     $query = $this->_db->getQuery(true);
                     $query->select('*')->from('#__ksenmart_products_relations')->where('product_id=' . $product_id)->where('relative_id=' . $relative_id)->where('relation_type=' . $this->_db->quote('relation'));
                     $this->_db->setQuery($query);
                     $db_rel = $this->_db->loadObject();
                     if (count($db_rel) == 0) {
                         $qvalues = array($product_id, $relative_id, $this->_db->quote('relation'));
                         $query = $this->_db->getQuery(true);
                         $query->insert('#__ksenmart_products_relations')->columns('product_id,relative_id,relation_type')->values(implode(',', $qvalues));
                         $this->_db->setQuery($query);
                         $this->_db->query();
                     }
                 }
             }
         }
     }
     fclose($f);
     $dir = scandir(JPATH_COMPONENT . DS . 'tmp' . DS);
     foreach ($dir as $d) {
         if ($d != '.' && $d != '..') {
             unlink(JPATH_COMPONENT . DS . 'tmp' . DS . $d);
         }
     }
     $this->onExecuteAfter('getImportInfo', array(&$info));
     return $info;
 }
Пример #25
0
 /**
  * Renvoie la date selon le format précisé en paramètre. Si aucun paramètre n'est renseigné, c'est le format par défaut qui s'applique.
  * 
  * @param string $sOutputFormat Le format peut être un de ceux de <i>strftime()</i> ou de <i>date()</i>. Si le format comporte un signe <i>"%"</i>, le format est
  * systématiquement interprété comme un format strftime, sinon comme un format date. Pour le format date, afin qu'une lettre ne soit pas interprétée comme un symbole,
  * il faut l'échapper avec un antislash.
  * @return string La date formatée
  * @see http://php.net/manual/fr/function.strftime.php et http://www.php.net/manual/fr/function.date.php
  */
 public function format($sOutputFormat = null)
 {
     if ($sOutputFormat == null) {
         $sOutputFormat = self::$_sDefaultOutputFormat;
     }
     $bStrftimeOutputFormat = preg_match('/%/', $sOutputFormat);
     $bUseLocale = $this->_sLocale != null;
     if ($bUseLocale && !$bStrftimeOutputFormat) {
         $sOutputFormat = self::_localeConversion($sOutputFormat);
     }
     if (preg_match('/%/', $sOutputFormat)) {
         if ($bUseLocale) {
             $sCurrentLocaleTime = setLocale(LC_TIME, 0);
             setLocale(LC_TIME, $this->_sLocale);
             $sFormattedDate = strftime($sOutputFormat, $this->_oDateTime->getTimestamp());
             setLocale(LC_TIME, $sCurrentLocaleTime);
             return $sFormattedDate;
         } else {
             return strftime($sOutputFormat, $this->_oDateTime->getTimestamp());
         }
     } else {
         return $this->_oDateTime->format($sOutputFormat);
     }
 }
Пример #26
0
 /**
  * @ignore
  * @param Request $request
  * @param array $options
  * @param bool $subrequest
  * @return Response\Json|Response\PageNotFound|Response\Redirect
  * @throws Exception
  * @ignore
  */
 public function _handleOnlyRequest(\Ip\Request $request, $options = array(), $subrequest = true)
 {
     if (empty($options['skipInitEvents'])) {
         \Ip\ServiceLocator::dispatcher()->_bindApplicationEvents();
     }
     $result = ipJob('ipRouteLanguage', array('request' => $request, 'relativeUri' => $request->getRelativePath()));
     if ($result) {
         $requestLanguage = $result['language'];
         $routeLanguage = $requestLanguage->getCode();
         ipRequest()->_setRoutePath($result['relativeUri']);
     } else {
         $routeLanguage = null;
         $requestLanguage = ipJob('ipRequestLanguage', array('request' => $request));
         ipRequest()->_setRoutePath($request->getRelativePath());
     }
     //find out and set locale
     $locale = $requestLanguage->getCode();
     if (strlen($locale) == '2') {
         $locale = strtolower($locale) . '_' . strtoupper($locale);
     } else {
         $locale = str_replace('-', '_', $locale);
     }
     $locale .= '.utf8';
     if ($locale == "tr_TR.utf8" && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5)) {
         //Overcoming this bug https://bugs.php.net/bug.php?id=18556
         setlocale(LC_COLLATE, $locale);
         setlocale(LC_MONETARY, $locale);
         setlocale(LC_NUMERIC, $locale);
         setlocale(LC_TIME, $locale);
         setlocale(LC_MESSAGES, $locale);
         setlocale(LC_CTYPE, "en_US.utf8");
     } else {
         setLocale(LC_ALL, $locale);
     }
     setlocale(LC_NUMERIC, "C");
     //user standard C syntax for numbers. Otherwise you will get funny things with when autogenerating CSS, etc.
     ipContent()->_setCurrentLanguage($requestLanguage);
     $_SESSION['ipLastLanguageId'] = $requestLanguage->getId();
     if (empty($options['skipTranslationsInit'])) {
         if (!empty($options['translationsLanguageCode'])) {
             $languageCode = $options['translationsLanguageCode'];
         } else {
             $languageCode = $requestLanguage->getCode();
         }
         $this->initTranslations($languageCode);
     }
     if (empty($options['skipModuleInit'])) {
         $this->modulesInit();
     }
     ipEvent('ipInitFinished');
     $routeAction = ipJob('ipRouteAction', array('request' => $request, 'relativeUri' => ipRequest()->getRoutePath(), 'routeLanguage' => $routeLanguage));
     if (!empty($routeAction)) {
         if (!empty($routeAction['page'])) {
             ipContent()->_setCurrentPage($routeAction['page']);
         }
         if (!empty($routeAction['environment'])) {
             ipRoute()->setEnvironment($routeAction['environment']);
         } else {
             if (!empty($routeAction['controller']) && $routeAction['controller'] == 'AdminController') {
                 ipRoute()->setEnvironment(\Ip\Route::ENVIRONMENT_ADMIN);
             } else {
                 ipRoute()->setEnvironment(\Ip\Route::ENVIRONMENT_PUBLIC);
             }
         }
         if (!empty($routeAction['controller'])) {
             ipRoute()->setController($routeAction['controller']);
         }
         if (!empty($routeAction['plugin'])) {
             ipRoute()->setPlugin($routeAction['plugin']);
         }
         if (!empty($routeAction['name'])) {
             ipRoute()->setName($routeAction['name']);
         }
         if (!empty($routeAction['action'])) {
             ipRoute()->setAction($routeAction['action']);
         }
     }
     //check for CSRF attack
     if (empty($options['skipCsrfCheck']) && $request->isPost() && $request->getPost('securityToken') != $this->getSecurityToken() && (empty($routeAction['controller']) || $routeAction['controller'] != 'PublicController')) {
         ipLog()->error('Core.possibleCsrfAttack', array('post' => ipRequest()->getPost()));
         $data = array('status' => 'error');
         if (ipConfig()->isDevelopmentEnvironment()) {
             $data['errors'] = array('securityToken' => __('Possible CSRF attack. Please pass correct securityToken.', 'Ip-admin'));
         }
         // TODO JSONRPC
         return new \Ip\Response\Json($data);
     }
     if (empty($routeAction)) {
         $routeAction = array('plugin' => 'Core', 'controller' => 'PublicController', 'action' => 'pageNotFound');
     }
     $eventInfo = $routeAction;
     if (!empty($routeAction['plugin'])) {
         $plugin = $routeAction['plugin'];
         $controller = $routeAction['controller'];
         if (in_array($plugin, \Ip\Internal\Plugins\Model::getModules())) {
             $controllerClass = 'Ip\\Internal\\' . $plugin . '\\' . $controller;
         } else {
             if (!in_array($plugin, \Ip\Internal\Plugins\Service::getActivePluginNames())) {
                 throw new \Ip\Exception("Plugin '" . esc($plugin) . "' doesn't exist or isn't activated.");
             }
             $controllerClass = 'Plugin\\' . $plugin . '\\' . $controller;
         }
         if (!class_exists($controllerClass)) {
             throw new \Ip\Exception('Requested controller doesn\'t exist. ' . esc($controllerClass));
         }
         // check if user is logged in
         if ($controller == 'AdminController' && !\Ip\Internal\Admin\Backend::userId()) {
             if (ipConfig()->get('rewritesDisabled')) {
                 return new \Ip\Response\Redirect(ipConfig()->baseUrl() . 'index.php/admin');
             } else {
                 return new \Ip\Response\Redirect(ipConfig()->baseUrl() . 'admin');
             }
         }
         if ($controller == 'AdminController') {
             if (!ipAdminPermission($plugin)) {
                 throw new \Ip\Exception('User has no permission to access ' . esc($plugin) . '');
             }
         }
         $eventInfo['controllerClass'] = $controllerClass;
         $eventInfo['controllerType'] = $controller;
     }
     if (empty($eventInfo['page'])) {
         $eventInfo['page'] = null;
     }
     // change layout if safe mode
     if (\Ip\Internal\Admin\Service::isSafeMode()) {
         ipSetLayout(ipFile('Ip/Internal/Admin/view/safeModeLayout.php'));
     } else {
         if ($eventInfo['page']) {
             ipSetLayout($eventInfo['page']->getLayout());
         }
     }
     ipEvent('ipBeforeController', $eventInfo);
     $controllerAnswer = ipJob('ipExecuteController', $eventInfo);
     return $controllerAnswer;
 }
/**
* this call back is called when displaying the link for some last post processing
*
*/
function chat_link_post_processing($title)
{
    global $CFG;
    setLocale(LC_TIME, substr(current_language(), 0, 2));
    $title = preg_replace('/TT_(.*)_TT/e', "userdate(\\1)", $title);
    if ($CFG->block_search_utf8dir) {
        return mb_convert_encoding($title, 'UTF-8', 'auto');
    }
    return mb_convert_encoding($title, 'auto', 'UTF-8');
}
Пример #28
0
 /**
  * Locale date
  *
  * @access  public
  * @return  string
  * @param   int     $timestamp
  */
 function date($timestamp = null)
 {
     $this->paranoid and setLocale(LC_ALL, $this->usedLocale);
     $date = strftime('%x', isset($timestamp) ? $timestamp : time());
     $this->paranoid and setLocale(LC_ALL, 'C');
     return $date;
 }
Пример #29
0
<?php

/**
 * Tzn Framework
 * 
 * @package tzn_language
 * @author Stan Ozier <*****@*****.**>
 * @version 0.4
 * @copyright GNU Lesser General Public License (LGPL) version 3
 */
$GLOBALS['config']['lang']['specialchars'] = 2;
$GLOBALS['config']['lang']['ucfirst'] = false;
setLocale(LC_ALL, 'en_EN.UTF-8', 'en_GB.utf8', 'en_US.utf8', 'en_EN', 'en');
Пример #30
0
 public function load($fileName)
 {
     if (!file_exists($fileName)) {
         throw new exception("File \"{$fileName}\" not found");
     }
     setLocale(LC_ALL, 'C');
     $this->logger->debug("Reading XLS file");
     $this->xls = PHPExcel_IOFactory::load($fileName);
     $this->decodeSheetIndex();
     $this->data = array();
     $this->importGlobalStrategy();
     for ($i = 1; $i <= 2; $i++) {
         $this->importInventory($i);
     }
     $this->importSEAP();
 }