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 47146 2015-10-04 12:21:16Z sdelaporte $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
24 function devises_hook_admin_menu_items($params) {
25  $result['menu_items']['manage_payments'][$GLOBALS['wwwroot_in_admin'] . '/modules/devises/administrer/devises.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_DEVISES"];
26  return $result;
27 }
28 
35 {
36  /* Default value*/
37  if(empty($frm)) {
38  $frm['devise'] = "";
39  $frm['conversion'] = 0;
40  $frm['symbole'] = "";
41  $frm['code'] = "";
42  $frm['etat'] = 0;
43  $frm['symbole_place'] = 1;
44  }
45  $frm['nouveau_mode'] = "insere";
46  $frm['id'] = "";
47  $frm['site_id'] = "";
48  $frm['titre_bouton'] = $GLOBALS['STR_ADMIN_ADD'];
49 
51 }
52 
60 {
61  if(empty($frm)){
62  // Pas de données venant de validation de formulaire, donc on charge le contenu de la base de données
63  /* Charge les informations de la devise */
64  $qid = query("SELECT *
65  FROM peel_devises
66  WHERE id = '" . intval($id) . "' AND " . get_filter_site_cond('devises', null, true) . "");
67  $frm = fetch_assoc($qid);
68  }
69  $frm['id'] = $id;
70  $frm["nouveau_mode"] = "maj";
71  $frm["titre_bouton"] = $GLOBALS['STR_ADMIN_FORM_SAVE_CHANGES'];
72 
74 }
75 
82 {
83  $tpl = $GLOBALS['tplEngine']->createTemplate('modules/devisesAdmin_formulaire.tpl');
84  $tpl->assign('action', get_current_url(false) . '?start=0');
85  $tpl->assign('mode', $frm["nouveau_mode"]);
86  $tpl->assign('id', intval($frm['id']));
87  $tpl->assign('etat', $frm["etat"]);
88  $tpl->assign('devise', $frm["devise"]);
89  $tpl->assign('symbole', $frm["symbole"]);
90  $tpl->assign('symbole_place', $frm["symbole_place"]);
91  $tpl->assign('code', $frm["code"]);
92  $tpl->assign('symbole_parameters', $GLOBALS['site_parameters']['symbole']);
93  $tpl->assign('conversion', $frm["conversion"]);
94  $tpl->assign('titre_bouton', $frm["titre_bouton"]);
95  $tpl->assign('site_id_select_options', get_site_id_select_options(vb($frm['site_id'])));
96  $tpl->assign('site_id_select_multiple', !empty($GLOBALS['site_parameters']['multisite_using_array_for_site_id']));
97  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
98  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
99  $tpl->assign('STR_MODULE_DEVISES_ADMIN_TITLE', $GLOBALS['STR_MODULE_DEVISES_ADMIN_TITLE']);
100  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
101  $tpl->assign('STR_ADMIN_ONLINE', $GLOBALS['STR_ADMIN_ONLINE']);
102  $tpl->assign('STR_ADMIN_OFFLINE', $GLOBALS['STR_ADMIN_OFFLINE']);
103  $tpl->assign('STR_DEVISE', $GLOBALS['STR_DEVISE']);
104  $tpl->assign('STR_ADMIN_SYMBOL', $GLOBALS['STR_ADMIN_SYMBOL']);
105  $tpl->assign('STR_MODULE_DEVISES_ADMIN_SYMBOL_AT_RIGHT', $GLOBALS['STR_MODULE_DEVISES_ADMIN_SYMBOL_AT_RIGHT']);
106  $tpl->assign('STR_MODULE_DEVISES_ADMIN_SYMBOL_AT_LEFT', $GLOBALS['STR_MODULE_DEVISES_ADMIN_SYMBOL_AT_LEFT']);
107  $tpl->assign('STR_ADMIN_CODE', $GLOBALS['STR_ADMIN_CODE']);
108  $tpl->assign('STR_ADMIN_CONVERSION', $GLOBALS['STR_ADMIN_CONVERSION']);
109  echo $tpl->fetch();
110 }
111 
119 {
120  $qid = query("SELECT devise
121  FROM peel_devises
122  WHERE id='" . intval($id) . "' AND " . get_filter_site_cond('devises', null, true) . "");
123  $col = fetch_assoc($qid);
124  /* Efface la devise */
125  query("DELETE FROM peel_devises WHERE id='" . intval($id) . "' AND " . get_filter_site_cond('devises', null, true) . "");
126  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_MODULE_DEVISES_ADMIN_MSG_DELETED_OK'], $col['devise'])))->fetch();
127 }
128 
136 {
137  $sql = "INSERT INTO peel_devises (
138  etat
139  , site_id
140  , symbole
141  , symbole_place
142  , devise
143  , conversion
144  , code
145  ) VALUES (
146  '" . intval($frm['etat']) . "'
148  , '" . nohtml_real_escape_string($frm['symbole']) . "'
149  , '" . nohtml_real_escape_string($frm['symbole_place']) . "'
150  , '" . nohtml_real_escape_string($frm['devise']) . "'
151  , '" . nohtml_real_escape_string(floatval(str_replace(",", ".", $frm['conversion']))) . "'
152  , '" . nohtml_real_escape_string($frm['code']) . "'
153  )";
154  query($sql);
155 }
156 
164 function maj_devise($id, $frm)
165 {
166  $conversion = str_replace(",", ".", $frm['conversion']);
167  $conversion = floatval($conversion);
168 
169  $sql = "UPDATE peel_devises
170  SET etat = '" . intval($frm['etat']) . "'
171  , symbole = '" . nohtml_real_escape_string($frm['symbole']) . "'
172  , symbole_place = '" . nohtml_real_escape_string($frm['symbole_place']) . "'
173  , devise = '" . nohtml_real_escape_string($frm['devise']) . "'
174  , conversion = '" . nohtml_real_escape_string($conversion) . "'
175  , code = '" . nohtml_real_escape_string($frm['code']) . "'
176  , site_id = '" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'
177  WHERE id = '" . intval($id) . "' AND " . get_filter_site_cond('devises', null, true) . "";
178 
179  query($sql);
180 }
181 
189 {
190  $tpl = $GLOBALS['tplEngine']->createTemplate('modules/devisesAdmin_liste.tpl');
191  $tpl->assign('ajout_href', get_current_url(false) . '?mode=ajout');
192  $tpl->assign('update_rates_href', get_current_url(false) . '?mode=update_rates');
193  $tpl->assign('drop_src', $GLOBALS['administrer_url'] . '/images/b_drop.png');
194  $tpl->assign('edit_src', $GLOBALS['administrer_url'] . '/images/b_edit.png');
195  $tpl_results = array();
196  $result = query("SELECT *
197  FROM peel_devises
198  WHERE " . get_filter_site_cond('devises', null, true) . "
199  ORDER BY devise");
200  if (!(num_rows($result) == 0)) {
201  $i = 0;
202  while ($ligne = fetch_assoc($result)) {
203  $tpl_results[] = array(
204  'tr_rollover' => tr_rollover($i, true),
205  'devise' => $ligne['devise'],
206  'drop_href' => get_current_url(false) . '?mode=suppr&id=' . $ligne['id'],
207  'edit_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'],
208  'symbole' => $ligne['symbole'],
209  'conversion' => $ligne['conversion'],
210  'code' => $ligne['code'],
211  'site_name' => get_site_name($ligne['site_id']),
212  'etat_onclick' => 'change_status("devises", "' . $ligne['id'] . '", this, "'.$GLOBALS['administrer_url'] . '")',
213  'etat_src' => $GLOBALS['administrer_url'] . '/images/' . (empty($ligne['etat']) ? 'puce-blanche.gif' : 'puce-verte.gif')
214  );
215  $i++;
216  }
217  }
218  $tpl->assign('results', $tpl_results);
219  $tpl->assign('site_code', vb($GLOBALS['site_parameters']['code']));
220  $tpl->assign('modif_href', $GLOBALS['administrer_url'] . '/sites.php?mode=modif&id=1');
221  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
222  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
223  $tpl->assign('STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY', sprintf($GLOBALS['STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY'], vb($GLOBALS['site_parameters']['code'])));
224  $tpl->assign('STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY_EXPLAIN', $GLOBALS['STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY_EXPLAIN']);
225  $tpl->assign('STR_MODULE_DEVISES_ADMIN_LIST_TITLE', $GLOBALS['STR_MODULE_DEVISES_ADMIN_LIST_TITLE']);
226  $tpl->assign('STR_MODULE_DEVISES_ADMIN_CREATE', $GLOBALS['STR_MODULE_DEVISES_ADMIN_CREATE']);
227  $tpl->assign('STR_MODULE_DEVISES_ADMIN_CREATE_EXPLAIN', $GLOBALS['STR_MODULE_DEVISES_ADMIN_CREATE_EXPLAIN']);
228  $tpl->assign('STR_ADMIN_ACTION', $GLOBALS['STR_BEFORE_TWO_POINTS']);
229  $tpl->assign('STR_DEVISE', $GLOBALS['STR_DEVISE']);
230  $tpl->assign('STR_ADMIN_SYMBOL', $GLOBALS['STR_ADMIN_SYMBOL']);
231  $tpl->assign('STR_ADMIN_CONVERSION', $GLOBALS['STR_ADMIN_CONVERSION']);
232  $tpl->assign('STR_ADMIN_CODE', $GLOBALS['STR_ADMIN_CODE']);
233  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
234  $tpl->assign('STR_ADMIN_DELETE_WARNING', $GLOBALS['STR_ADMIN_DELETE_WARNING']);
235  $tpl->assign('STR_DELETE', $GLOBALS['STR_DELETE']);
236  $tpl->assign('STR_MODULE_DEVISES_ADMIN_UPDATE', $GLOBALS['STR_MODULE_DEVISES_ADMIN_UPDATE']);
237  $tpl->assign('STR_MODULE_DEVISES_ADMIN_NOTHING_FOUND', $GLOBALS['STR_MODULE_DEVISES_ADMIN_NOTHING_FOUND']);
238  $tpl->assign('STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY', sprintf($GLOBALS['STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY'], vb($GLOBALS['site_parameters']['code'])));
239  $tpl->assign('STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY_EXPLAIN', $GLOBALS['STR_MODULE_DEVISES_ADMIN_DEFAULT_CURRENCY_EXPLAIN']);
240  echo $tpl->fetch();
241 }
242 
250 function update_currencies_rates($base_currency_code, $commission_percentage = 2.5)
251 {
252  $output = '<b>'.sprintf($GLOBALS['STR_MODULE_DEVISES_ADMIN_UPDATE_TITLE'], $commission_percentage).' :</b><br />';
253  $q = query("SELECT code, conversion
254  FROM peel_devises
255  WHERE code!='" . nohtml_real_escape_string($base_currency_code) . "' AND " . get_filter_site_cond('devises', null, true) . "");
256  while ($result = fetch_object($q)) {
257  unset($rate);
258  $rate = quote_xe_currency($result->code, $base_currency_code);
259  $output .= 'XE : ' . $result->code . '=' . $rate . '<br />';
260  if (empty($rate)) {
261  $rate = quote_google_currency($result->code, $base_currency_code);
262  $output .= 'Google : ' . $result->code . '=' . $rate . '<br />';
263  }
264  if (empty($rate)) {
265  $rate = quote_oanda_currency($result->code, $base_currency_code);
266  $output .= 'Oanda : ' . $result->code . '=' . $rate . '<br />';
267  }
268  if (!empty($rate) && is_numeric($rate)) {
269  $currency_update[$result->code] = $rate * (1 + $commission_percentage / 100);
270  }
271  if (rand(0, 3) == 1) {
272  // Ne pas surcharger les sites d'appels trop fréquents
273  sleep(1);
274  }
275  }
276  if (!empty($currency_update)) {
277  foreach($currency_update as $code => $rate) {
278  query("UPDATE peel_devises
279  SET conversion='" . str_replace(',', '.', $rate) . "'
280  WHERE code='" . nohtml_real_escape_string($code) . "' AND " . get_filter_site_cond('devises', null, true) . "");
281  }
282  $output = $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => $output))->fetch();
283  } else {
284  $output = $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $output . '<br />' . sprintf($GLOBALS['STR_MODULE_DEVISES_ADMIN_ERR_GET_DATA'], @ini_get("allow_url_fopen"))))->fetch();
285  }
286  return $output;
287 }
288 
296 function quote_oanda_currency($to, $from)
297 {
298  $page = @file('http://www.oanda.com/convert/fxdaily?value=1&redirected=1&exch=' . $to . '&format=CSV&dest=Get+Table&sel_list=' . $from);
299  $match = array();
300 
301  if (!empty($page)) {
302  preg_match('/(.+),(\w{3,4}),([0-9.]+),([0-9.]+)/i', String::strip_tags(str_replace(array("\r", "\n"), '', implode('', $page))), $match);
303  }
304  if (sizeof($match) > 0) {
305  return $match[3];
306  } else {
307  return false;
308  }
309 }
310 
318 function quote_xe_currency($to, $from)
319 {
320  $url = 'http://www.xe.com/ucc/convert?Amount=1&From=' . $from . '&To=' . $to;
321  $page = file($url);
322  // Debug : var_dump($url, $page);
323  $match = array();
324  if (!empty($page)) {
325  preg_match('/[0-9.]+\s*' . $from . '\s*=\s*([0-9.]+)\s*' . $to . '/', String::strip_tags(str_replace(array("\r", "\n", '&nbsp;'), array("", "", ' '), implode('', $page))), $match);
326  }
327  if (sizeof($match) > 0) {
328  return $match[1];
329  } else {
330  return false;
331  }
332 }
333 
341 function quote_google_currency($to, $from)
342 {
343  $page = @file('http://www.google.com/ig/calculator?hl=en&q=' . urlencode(1 . '' . $from . '=?' . $to));
344  $page = implode('', $page);
345  if (!empty($page)) {
346  $page = String::substr($page, String::strpos($page, 'rhs: "') + String::strlen('rhs: "'));
347  $amount = String::substr($page, 0, String::strpos($page, ' '));
348  }
349  if (!empty($amount) && is_numeric($amount)) {
350  return $amount;
351  } else {
352  return false;
353  }
354  return $matches[1] ? $matches[1] : false;
355 }
356 
get_site_name($site_ids, $skip_rights_check=false)
Retourne le nom d'un ou de plusieurs sites à partir de l'id.
Definition: fonctions.php:4763
static strip_tags($string, $allowed_tags=null)
String::strip_tags()
Definition: String.php:548
if(!empty($GLOBALS['site_parameters']['order_specific_field_titles'])) if(check_if_module_active('socolissimo')&&!empty($_REQUEST)&&!empty($_REQUEST['PUDOFOID'])&&!empty($_REQUEST['CEEMAIL'])&&!empty($_REQUEST['SIGNATURE'])&&!empty($_REQUEST['ORDERID'])) elseif(!empty($_POST)) elseif(check_if_module_active('socolissimo')&&!empty($_SESSION['session_commande']['is_socolissimo_order'])) foreach(array('bill'=> 1, 'ship'=> 2) as $address_type=> $session_commande_address_id) $frm['societe1']
$result
static strpos($haystack, $needle, $offset=0)
Returns the numeric position of the first occurrence of needle in the haystack string.
Definition: String.php:54
quote_google_currency($to, $from)
quote_google_currency()
Definition: fonctions.php:341
get_current_url($with_get=true, $get_short_url=false, $take_away_get_args_array=null)
get_current_url()
Definition: fonctions.php:1743
quote_xe_currency($to, $from)
quote_xe_currency()
Definition: fonctions.php:318
affiche_formulaire_devise($frm)
affiche_formulaire_devise()
Definition: fonctions.php:81
get_site_id_select_options($selected_site_id=null, $selected_site_name=null, $display_first_option=null, $select_current_site_id_by_default=false)
Créer les options pour le select qui liste les noms de sites configurés en back office.
supprime_devise($id)
Supprime la devise spécifié par $id.
Definition: fonctions.php:118
static strlen($string)
Returns the length of the given string.
Definition: String.php:36
nohtml_real_escape_string($value, $allowed_tags=null)
Protège les données pour insertion dans MySQL ET supprime les tags HTML pour protéger de toute sorte ...
Definition: database.php:400
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
maj_devise($id, $frm)
maj_devise()
Definition: fonctions.php:164
$start
Definition: attributs.php:22
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
affiche_formulaire_ajout_devise($frm)
Affiche un formulaire vierge pour ajouter une devise.
Definition: fonctions.php:34
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
num_rows($query_result)
num_rows()
Definition: database.php:321
affiche_formulaire_modif_devise($id, $frm)
Affiche le formulaire de modification pour la devise sélectionnée.
Definition: fonctions.php:59
fetch_object($query_result)
fetch_object()
Definition: database.php:302
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
if(!defined('IN_PEEL')) devises_hook_admin_menu_items($params)
Renvoie les éléments de menu affichables.
Definition: fonctions.php:24
insere_devise($frm)
insere_devise()
Definition: fonctions.php:135
quote_oanda_currency($to, $from)
Fonctions pour récupérer les taux de change.
Definition: fonctions.php:296
affiche_liste_devise($start)
affiche_liste_devise()
Definition: fonctions.php:188
get_site_id_sql_set_value($site_ids)
Retourne la valeur SQL d'un champ INT ou SET suivant que ce soit un entier ou un tableau.
Definition: fonctions.php:4747
$match
Definition: search.php:86
$id
Definition: articles.php:22
static substr($string, $start, $length=null)
Returns the portion of string specified by the start and length parameters.
Definition: String.php:112

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.