PEEL Shopping
Open source ecommerce : PEEL Shopping
tarifs.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: tarifs.php 46935 2015-09-18 08:49:48Z gboussin $
14 define('IN_PEEL_ADMIN', true);
15 include("../configuration.inc.php");
17 necessite_priv("admin_manage");
18 
19 $GLOBALS['DOC_TITLE'] = $GLOBALS['STR_ADMIN_TARIFS_TITLE'];
20 include($GLOBALS['repertoire_modele'] . "/admin_haut.php");
21 
22 $frm = $_POST;
24 
25 switch (vb($_REQUEST['mode'])) {
26  case "ajout" :
28  break;
29 
30  case "modif" :
32  break;
33 
34  case "suppr" :
35  supprime_tarif($_GET['id']);
37  break;
38 
39  case "insere" :
40  if (!verify_token($_SERVER['PHP_SELF'] . $frm['mode'] . $frm['id'])) {
41  $form_error_object->add('token', $GLOBALS['STR_INVALID_TOKEN']);
42  }
43  if (!$form_error_object->count()) {
44  insere_tarif($_POST);
45  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_TARIFS_MSG_CREATED_OK'], vb($_POST['tarif']))))->fetch();
47  } else {
48  if ($form_error_object->has_error('token')) {
49  echo $form_error_object->text('token');
50  }
52  }
53  break;
54 
55  case "maj" :
56  if (!verify_token($_SERVER['PHP_SELF'] . $frm['mode'] . $frm['id'])) {
57  $form_error_object->add('token', $GLOBALS['STR_INVALID_TOKEN']);
58  }
59  if (!$form_error_object->count()) {
60  maj_tarif($_POST['id'], $_POST);
61  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_TARIFS_MSG_UPDATED_OK'], vn($_POST['id']))))->fetch();
63  } else {
64  if ($form_error_object->has_error('token')) {
65  echo $form_error_object->text('token');
66  }
67  affiche_formulaire_modif_tarif($frm['id'], $frm);
68  }
69  break;
70 
71  default :
73  break;
74 }
75 
76 include($GLOBALS['repertoire_modele'] . "/admin_bas.php");
77 
89 {
90  /* Valeurs par défaut */
91  if(empty($frm)) {
92  $frm = array();
93  $frm['zone'] = "";
94  $frm['type'] = "";
95  $frm['poidsmin'] = "";
96  $frm['poidsmax'] = "";
97  $frm['totalmin'] = "";
98  $frm['tarif'] = "";
99  $frm["totalmax"] = "";
100  $frm['tva'] = 0;
101  $frm['site_id'] = '';
102  }
103  $frm['nouveau_mode'] = "insere";
104  $frm['id'] = "";
105  $frm['titre_bouton'] = $GLOBALS['STR_ADMIN_TARIFS_CREATE'];
106 
108 }
109 
118 {
119  if(empty($frm)){
120  // Pas de données venant de validation de formulaire, donc on charge le contenu de la base de données
121  /* Charge les informations du produit */
122  $qid = query("SELECT *
123  FROM peel_tarifs
124  WHERE id =" . intval($id) . " AND " . get_filter_site_cond('tarifs', null, true) . "");
125  if ($frm = fetch_assoc($qid)) {
126  } else {
127  echo $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_TARIFS_NOT_FOUND']))->fetch();
128  return false;
129  }
130  }
131  $frm['id'] = $id;
132 
133  $frm["nouveau_mode"] = "maj";
134  $frm["titre_bouton"] = $GLOBALS['STR_ADMIN_FORM_SAVE_CHANGES'];
135 
137 }
138 
146 {
147  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_formulaire_tarif.tpl');
148  $tpl->assign('mode_transport', $GLOBALS['site_parameters']['mode_transport']);
149  $tpl->assign('action', get_current_url(false) . '?start=0');
150  $tpl->assign('form_token', get_form_token_input($_SERVER['PHP_SELF'] . $frm['nouveau_mode'] . intval($frm['id'])));
151  $tpl->assign('mode', vb($frm['nouveau_mode']));
152  $tpl->assign('id', intval(vn($frm['id'])));
153  $tpl->assign('site_id_select_options', get_site_id_select_options(vb($frm['site_id'])));
154  $tpl->assign('site_id_select_multiple', !empty($GLOBALS['site_parameters']['multisite_using_array_for_site_id']));
155 
156  $tpl_zones_options = array();
157  $sql_zone = "SELECT id, nom_" . $_SESSION['session_langue'] . "
158  FROM peel_zones
159  WHERE " . get_filter_site_cond('zones') . "
160  ORDER BY nom_" . $_SESSION['session_langue'];
161  $res_zone = query($sql_zone);
162  while ($tab_zone = fetch_assoc($res_zone)) {
163  $tpl_zones_options[] = array('value' => intval($tab_zone['id']),
164  'issel' => vb($frm['zone']) == $tab_zone['id'],
165  'name' => $tab_zone['nom_' . $_SESSION['session_langue']]
166  );
167  }
168  $tpl->assign('zones_options', $tpl_zones_options);
169 
170  $tpl_type_options = array();
171  $sql_type = "SELECT id, nom_" . $_SESSION['session_langue'] . "
172  FROM peel_types
173  WHERE " . get_filter_site_cond('types') . "
174  ORDER BY nom_" . $_SESSION['session_langue'];
175  $res_type = query($sql_type);
176  while ($tab_type = fetch_assoc($res_type)) {
177  $tpl_type_options[] = array('value' => intval($tab_type['id']),
178  'issel' => vb($frm['type']) == $tab_type['id'],
179  'name' => $tab_type['nom_' . $_SESSION['session_langue']]
180  );
181  }
182  $tpl->assign('type_options', $tpl_type_options);
183  $tpl->assign('site_symbole', $GLOBALS['site_parameters']['symbole']);
184  $tpl->assign('poidsmin', $frm['poidsmin']);
185  $tpl->assign('poidsmax', $frm['poidsmax']);
186  $tpl->assign('totalmin', $frm['totalmin']);
187  $tpl->assign('totalmax', $frm['totalmax']);
188  $tpl->assign('tarif', $frm['tarif']);
189  $tpl->assign('vat_select_options', get_vat_select_options(vb($frm['tva'])));
190  $tpl->assign('titre_bouton', $frm['titre_bouton']);
191  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
192  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
193  $tpl->assign('STR_ADMIN_TARIFS_CONFIG_STATUS', $GLOBALS['STR_ADMIN_TARIFS_CONFIG_STATUS']);
194  $tpl->assign('STR_ADMIN_ACTIVATED', $GLOBALS['STR_ADMIN_ACTIVATED']);
195  $tpl->assign('STR_ADMIN_DEACTIVATED', $GLOBALS['STR_ADMIN_DEACTIVATED']);
196  $tpl->assign('STR_ADMIN_TARIFS_CONFIG_DEACTIVATED_COMMENT', $GLOBALS['STR_ADMIN_TARIFS_CONFIG_DEACTIVATED_COMMENT']);
197  $tpl->assign('STR_ADMIN_TARIFS_FORM_TITLE', $GLOBALS['STR_ADMIN_TARIFS_FORM_TITLE']);
198  $tpl->assign('STR_SHIPPING_ZONE', $GLOBALS['STR_SHIPPING_ZONE']);
199  $tpl->assign('STR_SHIPPING_TYPE', $GLOBALS['STR_SHIPPING_TYPE']);
200  $tpl->assign('STR_ADMIN_TARIFS_MINIMAL_WEIGHT', $GLOBALS['STR_ADMIN_TARIFS_MINIMAL_WEIGHT']);
201  $tpl->assign('STR_ADMIN_TARIFS_MAXIMAL_WEIGHT', $GLOBALS['STR_ADMIN_TARIFS_MAXIMAL_WEIGHT']);
202  $tpl->assign('STR_ADMIN_TARIFS_MINIMAL_TOTAL', $GLOBALS['STR_ADMIN_TARIFS_MINIMAL_TOTAL']);
203  $tpl->assign('STR_TTC', $GLOBALS['STR_TTC']);
204  $tpl->assign('STR_ADMIN_TARIFS_MAXIMAL_TOTAL', $GLOBALS['STR_ADMIN_TARIFS_MAXIMAL_TOTAL']);
205  $tpl->assign('STR_ADMIN_TARIF', $GLOBALS['STR_ADMIN_TARIF']);
206  $tpl->assign('STR_ADMIN_VAT_PERCENTAGE', $GLOBALS['STR_ADMIN_VAT_PERCENTAGE']);
207  echo $tpl->fetch();
208 }
209 
217 {
218  /* Efface le tarif */
219  query("DELETE FROM peel_tarifs WHERE id=" . intval($id) . " AND " . get_filter_site_cond('tarifs', null, true) . "");
220  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => $GLOBALS['STR_ADMIN_TARIFS_MSG_DELETED_OK']))->fetch();
221 }
222 
230 {
231  $qid = query("INSERT INTO peel_tarifs (
232  zone
233  , type
234  , poidsmin
235  , poidsmax
236  , totalmin
237  , totalmax
238  , tarif
239  , tva
240  , site_id
241  ) VALUES (
242  '" . nohtml_real_escape_string($frm['zone']) . "'
243  ,'" . nohtml_real_escape_string($frm['type']) . "'
244  ,'" . nohtml_real_escape_string($frm['poidsmin']) . "'
245  ,'" . nohtml_real_escape_string($frm['poidsmax']) . "'
246  ,'" . nohtml_real_escape_string($frm['totalmin']) . "'
247  ,'" . nohtml_real_escape_string($frm['totalmax']) . "'
248  ,'" . nohtml_real_escape_string($frm['tarif']) . "'
249  ,'" . nohtml_real_escape_string($frm['tva']) . "'
250  ,'" . real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'
251  )");
252 }
253 
261 function maj_tarif($id, $frm)
262 {
263  query("UPDATE peel_tarifs SET
264  zone = '" . nohtml_real_escape_string($frm['zone']) . "'
265  ,type = '" . nohtml_real_escape_string($frm['type']) . "'
266  ,poidsmin = '" . nohtml_real_escape_string($frm['poidsmin']) . "'
267  ,poidsmax = '" . nohtml_real_escape_string($frm['poidsmax']) . "'
268  ,totalmin = '" . nohtml_real_escape_string($frm['totalmin']) . "'
269  ,totalmax = '" . nohtml_real_escape_string($frm['totalmax']) . "'
270  ,tarif = '" . nohtml_real_escape_string($frm['tarif']) . "'
271  ,tva = '" . nohtml_real_escape_string($frm['tva']) . "'
272  ,site_id = '" . real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'
273  WHERE id = '" . intval($id) . "' AND " . get_filter_site_cond('tarifs', null, true) . "");
274 }
275 
282 {
283  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_liste_tarif.tpl');
284  $tpl->assign('mode_transport', $GLOBALS['site_parameters']['mode_transport']);
285  $tpl->assign('add_src', $GLOBALS['administrer_url'] . '/images/add.png');
286  $tpl->assign('drop_src', $GLOBALS['administrer_url'] . '/images/b_drop.png');
287  $tpl->assign('edit_src', $GLOBALS['administrer_url'] . '/images/b_edit.png');
288  $tpl->assign('add_href', get_current_url(false) . '?mode=ajout');
289  $tpl->assign('site_symbole', $GLOBALS['site_parameters']['symbole']);
290 
291  $result = query("SELECT t.*, z.nom_" . $_SESSION['session_langue'] . " AS zone_name
292  FROM peel_tarifs t
293  LEFT JOIN peel_zones z ON z.id=t.zone AND " . get_filter_site_cond('zones', 'z') . "
294  WHERE " . get_filter_site_cond('tarifs', 't', true) . "
295  ORDER BY zone_name ASC, t.type ASC, t.tarif ASC");
296  if (!(num_rows($result) == 0)) {
297  $tpl_results = array();
298  $i = 0;
299  while ($ligne = fetch_assoc($result)) {
300  $tpl_results[] = array('tr_rollover' => tr_rollover($i, true),
301  'poidsmin' => $ligne['poidsmin'],
302  'poidsmax' => $ligne['poidsmax'],
303  'tarif' => $ligne['tarif'],
304  'drop_href' => get_current_url(false) . '?mode=suppr&id=' . $ligne['id'],
305  'modif_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'],
306  'zone_name' => vb($ligne['zone_name']),
307  'delivery_type_name' => get_delivery_type_name($ligne['type']),
308  'totalmin' => $ligne['totalmin'],
309  'totalmax' => $ligne['totalmax'],
310  'site_name' => get_site_name($ligne['site_id'])
311  );
312  $i++;
313  }
314  $tpl->assign('results', $tpl_results);
315  }
316  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
317  $tpl->assign('STR_ADMIN_TARIFS_TITLE', $GLOBALS['STR_ADMIN_TARIFS_TITLE']);
318  $tpl->assign('STR_ADMIN_TARIFS_CONFIG_STATUS', $GLOBALS['STR_ADMIN_TARIFS_CONFIG_STATUS']);
319  $tpl->assign('STR_ADMIN_ACTIVATED', $GLOBALS['STR_ADMIN_ACTIVATED']);
320  $tpl->assign('STR_ADMIN_DEACTIVATED', $GLOBALS['STR_ADMIN_DEACTIVATED']);
321  $tpl->assign('STR_ADMIN_TARIFS_CONFIG_DEACTIVATED_COMMENT', $GLOBALS['STR_ADMIN_TARIFS_CONFIG_DEACTIVATED_COMMENT']);
322  $tpl->assign('STR_ADMIN_TARIFS_CREATE', $GLOBALS['STR_ADMIN_TARIFS_CREATE']);
323  $tpl->assign('STR_ADMIN_ACTION', $GLOBALS['STR_ADMIN_ACTION']);
324  $tpl->assign('STR_SHIPPING_ZONE', $GLOBALS['STR_SHIPPING_ZONE']);
325  $tpl->assign('STR_SHIPPING_TYPE', $GLOBALS['STR_SHIPPING_TYPE']);
326  $tpl->assign('STR_ADMIN_TARIFS_MINIMAL_WEIGHT_SHORT', $GLOBALS['STR_ADMIN_TARIFS_MINIMAL_WEIGHT_SHORT']);
327  $tpl->assign('STR_ADMIN_TARIFS_MAXIMAL_WEIGHT_SHORT', $GLOBALS['STR_ADMIN_TARIFS_MAXIMAL_WEIGHT_SHORT']);
328  $tpl->assign('STR_ADMIN_TARIFS_MINIMAL_TOTAL_SHORT', $GLOBALS['STR_ADMIN_TARIFS_MINIMAL_TOTAL_SHORT']);
329  $tpl->assign('STR_ADMIN_TARIFS_MAXIMAL_TOTAL_SHORT', $GLOBALS['STR_ADMIN_TARIFS_MAXIMAL_TOTAL_SHORT']);
330  $tpl->assign('STR_ADMIN_TARIFS_TARIFS', $GLOBALS['STR_ADMIN_TARIFS_TARIFS']);
331  $tpl->assign('STR_TTC', $GLOBALS['STR_TTC']);
332  $tpl->assign('STR_ADMIN_DELETE_WARNING', $GLOBALS['STR_ADMIN_DELETE_WARNING']);
333  $tpl->assign('STR_DELETE', $GLOBALS['STR_DELETE']);
334  $tpl->assign('STR_ADMIN_GRAMS_SHORT', $GLOBALS['STR_ADMIN_GRAMS_SHORT']);
335  $tpl->assign('STR_ADMIN_TARIFS_UPDATE', $GLOBALS['STR_ADMIN_TARIFS_UPDATE']);
336  $tpl->assign('STR_ADMIN_TARIFS_NOTHING_FOUND', $GLOBALS['STR_ADMIN_TARIFS_NOTHING_FOUND']);
337  $tpl->assign('STR_ADMIN_TARIFS_SETUP_FREE_EXPLAIN', $GLOBALS['STR_ADMIN_TARIFS_SETUP_FREE_EXPLAIN']);
338 
339  echo $tpl->fetch();
340 }
341 
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
$result
get_delivery_type_name($id)
get_delivery_type_name()
Definition: order.php:1109
get_current_url($with_get=true, $get_short_url=false, $take_away_get_args_array=null)
get_current_url()
Definition: fonctions.php:1743
$form_error_object
Definition: tarifs.php:23
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.
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
affiche_formulaire_tarif(&$frm)
affiche_formulaire_tarif()
Definition: tarifs.php:145
real_escape_string($value)
real_escape_string()
Definition: database.php:374
get_vat_select_options($selected_vat=null, $approximative_amount_selected=false)
get_vat_select_options()
necessite_priv($priv, $demo_allowed=true, $configuration_modification=false)
Cette fonction vérifie si l'utilisateur a les privilèges de $priv.
Definition: fonctions.php:1575
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
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
affiche_formulaire_modif_tarif($id, &$frm)
Affiche le formulaire de modification pour le tarif sélectionné
Definition: tarifs.php:117
necessite_identification()
Si l'utilisateur n'est pas connecté à un compte, on affiche une page d'identification et arrête le sc...
Definition: fonctions.php:1596
num_rows($query_result)
num_rows()
Definition: database.php:321
affiche_formulaire_ajout_tarif(&$frm)
FONCTIONS.
Definition: tarifs.php:88
affiche_liste_tarif()
affiche_liste_tarif()
Definition: tarifs.php:281
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
$frm
Definition: tarifs.php:22
get_form_token_input($name= 'general', $use_existing_token=true, $return_as_input_form=true)
get_form_token_input()
Definition: fonctions.php:94
vn(&$var, $default=0)
Variable nulle if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:110
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
insere_tarif($frm)
Ajoute le tarif dans la table tarif.
Definition: tarifs.php:229
verify_token($name= 'general', $delay_in_minutes=60, $check_referer_if_set_by_server=true, $cancel_token=true, $minimum_wait_in_seconds_before_use=0)
Vérification de la validité d'un token Par défaut, un token est valide 1h, et utilisable 1 seule fois...
Definition: fonctions.php:118
$id
Definition: articles.php:22
$GLOBALS['DOC_TITLE']
Definition: tarifs.php:19
supprime_tarif($id)
Supprime le tarif spécifié par $id.
Definition: tarifs.php:216
maj_tarif($id, $frm)
Met à jour le tarif $id avec de nouvelles valeurs.
Definition: tarifs.php:261
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:29:39 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.