PEEL Shopping
Open source ecommerce : PEEL Shopping
zones.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: zones.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_ZONES_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" :
31  affiche_formulaire_modif_zone($_GET['id'], $frm);
32  break;
33 
34  case "suppr" :
35  supprime_zone($_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_zone($_POST);
45  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_ZONES_MSG_CREATED_OK'], vb($_POST['nom_' . $_SESSION["session_langue"]]))))->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_zone($_POST['id'], $_POST);
61  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_ZONES_MSG_UPDATED_OK'], vn($_POST['id']))))->fetch();
63  } else {
64  if ($form_error_object->has_error('token')) {
65  echo $form_error_object->text('token');
67  } else {
68  affiche_formulaire_modif_zone(vn($_GET['id']), $frm);
69  }
70  }
71  break;
72 
73  default :
75  break;
76 }
77 
78 include($GLOBALS['repertoire_modele'] . "/admin_bas.php");
79 
91 {
92  /* Valeurs par défaut */
93  if(empty($frm)) {
94  $frm = array();
95  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
96  $frm['nom_' . $lng] = "";
97  }
98  $frm['tva'] = "";
99  $frm['on_franco'] = "";
100  $frm['on_franco_amount'] = "";
101  $frm['on_franco_reseller_amount'] = "";
102  $frm['on_franco_nb_products'] = "";
103  $frm['position'] = "";
104  $frm['site_id'] = "";
105  $frm['technical_code'] = "";
106  }
107  $frm['nouveau_mode'] = "insere";
108  $frm['id'] = "";
109  $frm['titre_bouton'] = $GLOBALS['STR_ADMIN_ZONES_CREATE'];
110 
112 }
113 
122 {
123  if(empty($frm)){
124  // Pas de données venant de validation de formulaire, donc on charge le contenu de la base de données
125  /* Charge les informations de la zone */
126  $qid = query("SELECT *
127  FROM peel_zones z
128  WHERE id = " . intval($id) . " AND " . get_filter_site_cond('zones', 'z', true) . "");
129  if ($frm = fetch_assoc($qid)) {
130  } else {
131  echo $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_ZONES_NOT_FOUND']))->fetch();
132  return false;
133  }
134  }
135  $frm['id'] = $id;
136  $frm["nouveau_mode"] = "maj";
137  $frm["titre_bouton"] = $GLOBALS['STR_ADMIN_FORM_SAVE_CHANGES'];
139 }
140 
148 {
149  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_formulaire_zone.tpl');
150  $tpl->assign('action', get_current_url(false) . '?start=0');
151  $tpl->assign('form_token', get_form_token_input($_SERVER['PHP_SELF'] . $frm['nouveau_mode'] . intval($frm['id'])));
152  $tpl->assign('mode', vb($frm['nouveau_mode']));
153  $tpl->assign('id', intval(vb($frm['id'])));
154  $tpl_langs = array();
155  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
156  $tpl_langs[] = array('lng' => $lng,
157  'nom' => $frm['nom_' . $lng]
158  );
159  }
160  $tpl->assign('langs', $tpl_langs);
161  $tpl->assign('tva', $frm['tva']);
162  $tpl->assign('site_id_select_options', get_site_id_select_options(vb($frm['site_id'])));
163  $tpl->assign('site_id_select_multiple', !empty($GLOBALS['site_parameters']['multisite_using_array_for_site_id']));
164  $tpl->assign('on_franco', $frm['on_franco']);
165  $tpl->assign('on_franco_amount', $frm['on_franco_amount']);
166  $tpl->assign('on_franco_reseller_amount', $frm['on_franco_reseller_amount']);
167  $tpl->assign('on_franco_nb_products', $frm['on_franco_nb_products']);
168  $tpl->assign('position', $frm['position']);
169  $tpl->assign('is_fianet_module_active', check_if_module_active('fianet'));
170  $tpl->assign('technical_code', $frm['technical_code']);
171  $tpl->assign('titre_bouton', $frm['titre_bouton']);
172  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
173  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
174  $tpl->assign('STR_ADMIN_ZONES_FORM_TITLE', $GLOBALS['STR_ADMIN_ZONES_FORM_TITLE']);
175  $tpl->assign('STR_ADMIN_LANGUAGES_SECTION_HEADER', $GLOBALS['STR_ADMIN_LANGUAGES_SECTION_HEADER']);
176  $tpl->assign('STR_ADMIN_NAME', $GLOBALS['STR_ADMIN_NAME']);
177  $tpl->assign('STR_ADMIN_VARIOUS_INFORMATION_HEADER', $GLOBALS['STR_ADMIN_VARIOUS_INFORMATION_HEADER']);
178  $tpl->assign('STR_ADMIN_ZONES_DOES_VAT_APPLY_IN_ZONE', $GLOBALS['STR_ADMIN_ZONES_DOES_VAT_APPLY_IN_ZONE']);
179  $tpl->assign('STR_ADMIN_ZONES_DELIVERY_COSTS_IN_ZONE', $GLOBALS['STR_ADMIN_ZONES_DELIVERY_COSTS_IN_ZONE']);
180  $tpl->assign('STR_ADMIN_ZONES_DELIVERY_COSTS_EXPLAIN', $GLOBALS['STR_ADMIN_ZONES_DELIVERY_COSTS_EXPLAIN']);
181  $tpl->assign('STR_ADMIN_SITES_DELIVERY_COST_RESELLER_FRANCO_LIMIT', $GLOBALS['STR_ADMIN_SITES_DELIVERY_COST_RESELLER_FRANCO_LIMIT']);
182  $tpl->assign('STR_ADMIN_ZONES_FRANCO_LIMIT_AMOUNT', $GLOBALS['STR_ADMIN_ZONES_FRANCO_LIMIT_AMOUNT']);
183  $tpl->assign('STR_ADMIN_ZONES_FRANCO_LIMIT_AMOUNT_EXPLAIN', $GLOBALS['STR_ADMIN_ZONES_FRANCO_LIMIT_AMOUNT_EXPLAIN']);
184  $tpl->assign('STR_ADMIN_ZONES_FRANCO_LIMIT_PRODUCTS', $GLOBALS['STR_ADMIN_ZONES_FRANCO_LIMIT_PRODUCTS']);
185  $tpl->assign('STR_ADMIN_ZONES_FRANCO_LIMIT_PRODUCTS_EXPLAIN', $GLOBALS['STR_ADMIN_ZONES_FRANCO_LIMIT_PRODUCTS_EXPLAIN']);
186  $tpl->assign('STR_ADMIN_POSITION', $GLOBALS['STR_ADMIN_POSITION']);
187  $tpl->assign('STR_ADMIN_ZONES_TECHNICAL_CODE_EXPLAIN', $GLOBALS['STR_ADMIN_ZONES_TECHNICAL_CODE_EXPLAIN']);
188  $tpl->assign('STR_ADMIN_TECHNICAL_CODE', $GLOBALS['STR_ADMIN_TECHNICAL_CODE']);
189  $tpl->assign('STR_ADMIN_VAT_PERCENTAGE', $GLOBALS['STR_ADMIN_VAT_PERCENTAGE']);
190  $tpl->assign('STR_HT', $GLOBALS['STR_HT']);
191  $tpl->assign('STR_PRICE', $GLOBALS['STR_PRICE']);
192  echo $tpl->fetch();
193 }
194 
202 {
203  $qid = query("SELECT nom_" . $_SESSION['session_langue'] . "
204  FROM peel_zones z
205  WHERE id=" . intval($id) . " AND " . get_filter_site_cond('zones', 'z', true) . "");
206  $col = fetch_assoc($qid);
207 
208  /* Efface la zone */
209  query("DELETE FROM peel_zones
210  WHERE id=" . intval($id) . " AND " . get_filter_site_cond('zones', null, true) . "");
211  echo $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_ZONES_MSG_DELETED_OK'], $col['nom_' . $_SESSION['session_langue']])))->fetch();
212 }
213 
220 function insere_zone($frm)
221 {
222  $sql = "INSERT INTO peel_zones (
223  tva
224  , site_id
225  , position
226  , on_franco
227  , on_franco_amount
228  , on_franco_reseller_amount
229  , on_franco_nb_products";
230  if (check_if_module_active('fianet')) {
231  $sql .= ", technical_code";
232  }
233  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
234  $sql .= ", nom_" . $lng;
235  }
236  $sql .= "
237  ) VALUES (
238  '" . nohtml_real_escape_string(vn($frm['tva'])) . "'
240  , '" . intval($frm['position']) . "'
241  , '" . intval(vn($frm['on_franco'])) . "'
242  , '" . nohtml_real_escape_string(vn($frm['on_franco_amount'])) . "'
243  , '" . nohtml_real_escape_string(vn($frm['on_franco_reseller_amount'])) . "'
244  , '" . nohtml_real_escape_string(vn($frm['on_franco_nb_products'])) . "'";
245  if (check_if_module_active('fianet')) {
246  $sql .= ", '" . nohtml_real_escape_string(vb($frm['technical_code'])) . "'";
247  }
248  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
249  $sql .= ", '" . nohtml_real_escape_string($frm['nom_' . $lng]) . "'";
250  }
251  $sql .= ")";
252 
253  query($sql);
254 }
255 
263 function maj_zone($id, $frm)
264 {
265  $sql = "UPDATE peel_zones
266  SET tva = '" . nohtml_real_escape_string(vn($frm['tva'])) . "'
267  ";
268  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
269  $sql .= ", nom_" . $lng . " = '" . nohtml_real_escape_string($frm['nom_' . $lng]) . "'";
270  }
271  if (check_if_module_active('fianet')) {
272  $sql .= ", technical_code = '" . nohtml_real_escape_string($frm['technical_code']) . "'";
273  }
274  $sql .= "
275  , site_id = '" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'
276  , position = '" . nohtml_real_escape_string($frm['position']) . "'
277  , on_franco_amount = '" . nohtml_real_escape_string($frm['on_franco_amount']) . "'
278  , on_franco_reseller_amount = '" . nohtml_real_escape_string($frm['on_franco_reseller_amount']) . "'
279  , on_franco_nb_products = '" . nohtml_real_escape_string($frm['on_franco_nb_products']) . "', on_franco = '" . intval(vn($frm['on_franco'])) . "'
280  WHERE id = '" . intval($id) . "' AND " . get_filter_site_cond('zones', null, true) . "";
281  query($sql);
282 }
283 
290 {
291  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_liste_zone.tpl');
292  $tpl->assign('add_src', $GLOBALS['administrer_url'] . '/images/add.png');
293  $tpl->assign('drop_src', $GLOBALS['administrer_url'] . '/images/b_drop.png');
294  $tpl->assign('edit_src', $GLOBALS['administrer_url'] . '/images/b_edit.png');
295  $tpl->assign('add_href', get_current_url(false) . '?mode=ajout');
296  $result = query("SELECT *
297  FROM peel_zones z
298  WHERE " . get_filter_site_cond('zones', 'z', true) . "
299  ORDER BY position");
300  if (!(num_rows($result) == 0)) {
301  $tpl_results = array();
302  $i = 0;
303  while ($ligne = fetch_assoc($result)) {
304  $tpl_results[] = array('tr_rollover' => tr_rollover($i, true),
305  'nom' => (!empty($ligne['nom_' . $_SESSION['session_langue']])?$ligne['nom_' . $_SESSION['session_langue']]:'['.$ligne['id'].']'),
306  'drop_href' => get_current_url(false) . '?mode=suppr&id=' . $ligne['id'],
307  'modif_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'],
308  'tva' => $ligne['tva'],
309  'site_name' => get_site_name($ligne['site_id']),
310  'on_franco' => $ligne['on_franco'],
311  'position' => $ligne['position'],
312  );
313  $i++;
314  }
315  $tpl->assign('results', $tpl_results);
316  }
317  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
318  $tpl->assign('STR_ADMIN_ZONES_TITLE', $GLOBALS['STR_ADMIN_ZONES_TITLE']);
319  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
320  $tpl->assign('STR_ADMIN_ZONES_CREATE', $GLOBALS['STR_ADMIN_ZONES_CREATE']);
321  $tpl->assign('STR_ADMIN_ACTION', $GLOBALS['STR_ADMIN_ACTION']);
322  $tpl->assign('STR_SHIPPING_ZONE', $GLOBALS['STR_SHIPPING_ZONE']);
323  $tpl->assign('STR_VAT', $GLOBALS['STR_VAT']);
324  $tpl->assign('STR_ADMIN_ZONES_FREE_DELIVERY', $GLOBALS['STR_ADMIN_ZONES_FREE_DELIVERY']);
325  $tpl->assign('STR_ADMIN_POSITION', $GLOBALS['STR_ADMIN_POSITION']);
326  $tpl->assign('STR_ADMIN_DELETE_WARNING', $GLOBALS['STR_ADMIN_DELETE_WARNING']);
327  $tpl->assign('STR_DELETE', $GLOBALS['STR_DELETE']);
328  $tpl->assign('STR_ADMIN_ZONES_UPDATE', $GLOBALS['STR_ADMIN_ZONES_UPDATE']);
329  $tpl->assign('STR_YES', $GLOBALS['STR_YES']);
330  $tpl->assign('STR_NO', $GLOBALS['STR_NO']);
331  $tpl->assign('STR_ADMIN_ZONES_NOTHING_FOUND', $GLOBALS['STR_ADMIN_ZONES_NOTHING_FOUND']);
332  echo $tpl->fetch();
333 }
334 
maj_zone($id, $frm)
Met à jour la zone $id avec de nouvelles valeurs.
Definition: zones.php:263
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
supprime_zone($id)
Supprime la zone spécifiée par $id.
Definition: zones.php:201
$result
get_current_url($with_get=true, $get_short_url=false, $take_away_get_args_array=null)
get_current_url()
Definition: fonctions.php:1743
affiche_liste_zone()
affiche_liste_zone()
Definition: zones.php:289
$tpl_langs
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.
affiche_formulaire_zone(&$frm)
affiche_formulaire_zone()
Definition: zones.php:147
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_ajout_zone(&$frm)
FONCTIONS.
Definition: zones.php:90
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
insere_zone($frm)
Ajoute la zone dans la table zone.
Definition: zones.php:220
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
$GLOBALS['DOC_TITLE']
Definition: zones.php:19
$frm
Definition: zones.php:22
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
affiche_formulaire_modif_zone($id, &$frm)
Affiche le formulaire de modification pour la zone sélectionnée.
Definition: zones.php:121
$form_error_object
Definition: zones.php:23
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
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
check_if_module_active($module_name, $specific_file_name=null)
Renvoie si un module est présent et activé ou non - Peut être appelé avant ou après le chargement d'u...
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:48 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.