PEEL Shopping
Open source ecommerce : PEEL Shopping
fonctions.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: fonctions.php 47154 2015-10-05 07:55:09Z sdelaporte $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
24 function devises_hook_configuration_end($params) {
25  if (!empty($_GET['devise'])) {
26  set_current_devise($_GET['devise']);
27  // On redirige 302 après avoir défini la devise (les moteurs ont déjà plus tôt eu droit à redirection 301)
28  redirect_and_die(get_current_url(true, false, array('devise')));
29  }
30 }
31 
39  // Mise à jour des devises
40  return update_currencies_rates(vb($GLOBALS['site_parameters']['code']));
41 }
42 
50 function set_current_devise($currency_id_or_code, $reference_country_id = null)
51 {
52  if (!empty($_SESSION['session_utilisateur']['devise']) || !empty($currency_id_or_code) || !empty($reference_country_id)) {
53  if(!empty($_SESSION['session_utilisateur']['devise'])) {
54  // Devise forcée pour l'utilisateur, pas de possibilité d'en choisir une autre
55  $cond = "d.id='" . intval($_SESSION['session_utilisateur']['devise']) . "'";
56  } elseif(!empty($currency_id_or_code)) {
57  // On prend en priorité la devise demandée, sinon la prochaine devise trouvée disponible sur le site
58  if(is_numeric($currency_id_or_code)) {
59  $cond = "d.id='" . intval($currency_id_or_code) . "'";
60  } else {
61  $cond = "d.code='" . word_real_escape_string($currency_id_or_code) . "'";
62  }
63  } elseif(!empty($reference_country_id)) {
64  // On cherche uniquement la devise correspondant au pays donné. Si pas disponible sur le site, on ne modifie pas session_devise
65  $cond = "c.id='" . intval($reference_country_id) . "'";
66  $join = "INNER JOIN peel_pays c ON c.devise=d.code";
67  }
68  $sql = "SELECT d.*
69  FROM peel_devises d
70  " . vb($join) . "
71  WHERE d.etat='1' AND " . get_filter_site_cond('devises', 'd') . "
72  ORDER BY IF(" . $cond . ", -1, 1) ASC
73  LIMIT 1";
74  $resDevise = query($sql);
75  if ($Devise = fetch_object($resDevise)) {
76  $_SESSION['session_devise']['symbole'] = String::html_entity_decode(str_replace('&euro;', '€', $Devise->symbole));
77  $_SESSION['session_devise']['symbole_place'] = $Devise->symbole_place;
78  $_SESSION['session_devise']['conversion'] = $Devise->conversion;
79  $_SESSION['session_devise']['code'] = $Devise->code;
80  }
81  }
82 }
83 
90 function affiche_module_devise($return_mode = false)
91 {
92  if(!empty($_SESSION['session_utilisateur']['devise'])) {
93  // Devise imposée
94  return null;
95  }
96  $output = '';
97  if(empty($GLOBALS['site_parameters']['currencies_select_in_front_office_disabled'])) {
98  $resDevise = query("SELECT *
99  FROM peel_devises
100  WHERE etat='1' AND " . get_filter_site_cond('devises') . "
101  ORDER BY devise");
102  $url_part = str_replace(array('?devise=' . vb($_GET['devise']), '&devise=' . vb($_GET['devise'])), array('', ''), $_SERVER['REQUEST_URI']);
103  if (String::strpos($url_part, '?') === false) {
104  $url_part .= '?devise=';
105  } else {
106  $url_part .= '&devise=';
107  }
108  $tpl_options = array();
109  while ($Devise = fetch_assoc($resDevise)) {
110  $tpl_options[] = array(
111  'value' => intval($Devise['id']),
112  'issel' => $Devise['code'] == $_SESSION['session_devise']['code'],
113  'name' => $Devise['devise']
114  );
115  }
116  if(count($tpl_options)>1) {
117  $tpl = $GLOBALS['tplEngine']->createTemplate('modules/devises.tpl');
118  $tpl->assign('STR_MODULE_DEVISES_CHOISIR_DEVISE', $GLOBALS['STR_MODULE_DEVISES_CHOISIR_DEVISE']);
119  $tpl->assign('url_part', $url_part);
120  $tpl->assign('options', $tpl_options);
121  $output .= $tpl->fetch();
122  }
123  }
124  if ($return_mode) {
125  return $output;
126  } else {
127  echo $output;
128  }
129 }
static strpos($haystack, $needle, $offset=0)
Returns the numeric position of the first occurrence of needle in the haystack string.
Definition: String.php:54
get_current_url($with_get=true, $get_short_url=false, $take_away_get_args_array=null)
get_current_url()
Definition: fonctions.php:1743
if(!defined('IN_PEEL')) devises_hook_configuration_end($params)
Initialisation de la devise si demandée par l'utilisateur.
Definition: fonctions.php:24
redirect_and_die($url, $permanent_redirection=false, $avoid_loop=false)
Redirige vers l'URL demandée et arrête le programme.
Definition: fonctions.php:1551
affiche_module_devise($return_mode=false)
affiche_module_devise()
Definition: fonctions.php:90
word_real_escape_string($value)
Applique real_escape_string dans le cas où on n'insère qu'un seul mot, de moins de 30 caractères...
Definition: database.php:424
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
if(!defined('IN_PEEL')) $GLOBALS['page_types_array']
Definition: fonctions.php:19
$tpl_options
get_filter_site_cond($table_technical_code, $table_alias=null, $use_strict_rights_if_in_admin=false, $specific_site_id=null, $exclude_public_items=false, $admin_force_multisite_if_allowed=false)
Retourne la condition SQL permettant de filtrer les données pour une table.
Definition: fonctions.php:4643
query($query, $die_if_error=false, $database_object=null, $silent_if_error=false, $security_sql_filter=true)
The query() function is meant to be called anywhere you want to make a query.
Definition: database.php:158
update_currencies_rates($base_currency_code, $commission_percentage=2.5)
Mise à jour de la table peel_devises.
Definition: fonctions.php:250
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
fetch_object($query_result)
fetch_object()
Definition: database.php:302
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
devises_hook_general_actions_24h($params)
Effectue les actions journalières si le module cron est actif.
Definition: fonctions.php:38
set_current_devise($currency_id_or_code, $reference_country_id=null)
set_current_devise()
Definition: fonctions.php:50
static html_entity_decode($string, $quote_style=ENT_COMPAT, $charset=GENERAL_ENCODING)
String::html_entity_decode()
Definition: String.php:517
if(defined('IN_PEEL_ADMIN')||IN_INSTALLATION) $_SESSION['session_langue']

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:30:59 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.