PEEL Shopping
Open source ecommerce : PEEL Shopping
pays.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: pays.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_PAYS_TITLE'];
20 
21 $frm = $_POST;
23 $output = '';
24 
25 switch (vb($_REQUEST['mode'])) {
26  case "ajout" :
28  break;
29 
30  case "modif" :
32  break;
33 
34  case "suppr" :
35  $output .= supprime_pays($_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  $_POST['image'] = upload('image', false, 'image', $GLOBALS['site_parameters']['image_max_width'], $GLOBALS['site_parameters']['image_max_height'], null, null, vb($_POST['image']));
45  $output .= insere_pays($_POST);
46  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_PAYS_MSG_CREATED_OK'], vb($_POST['pays_' . $_SESSION["session_langue"]]))))->fetch();
48  } else {
49  if ($form_error_object->has_error('token')) {
50  $output .= $form_error_object->text('token');
51  }
53  }
54  break;
55 
56  case "maj" :
57  if (!verify_token($_SERVER['PHP_SELF'] . $frm['mode'] . $frm['id'])) {
58  $form_error_object->add('token', $GLOBALS['STR_INVALID_TOKEN']);
59  }
60  if (!$form_error_object->count()) {
61  $_POST['image'] = upload('image', false, 'image', $GLOBALS['site_parameters']['image_max_width'], $GLOBALS['site_parameters']['image_max_height'], null, null, vb($_POST['image']));
62  $output .= maj_pays($_POST['id'], $_POST);
63  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_PAYS_MSG_UPDATED_OK'], vn($_POST['id']))))->fetch();
65  } else {
66  if ($form_error_object->has_error('token')) {
67  $output .= $form_error_object->text('token');
68  }
70  }
71  break;
72 
73  default :
75  break;
76 }
77 
78 include($GLOBALS['repertoire_modele'] . "/admin_haut.php");
79 echo $output;
80 include($GLOBALS['repertoire_modele'] . "/admin_bas.php");
81 
93 {
94  /* Valeurs par défaut */
95  if(empty($frm)) {
96  $frm = array();
97  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
98  $frm['pays_' . $lng] = "";
99  }
100  $frm['etat'] = "";
101  $frm['zone'] = "";
102  $frm['lang'] = "";
103  $frm['iso'] = "";
104  $frm['iso3'] = "";
105  $frm['iso_num'] = "";
106  $frm['position'] = "";
107  }
108  $frm['nouveau_mode'] = "insere";
109  $frm['id'] = "";
110  $frm['titre_bouton'] = $GLOBALS['STR_ADMIN_ADD'];
111 
113 }
114 
123 {
124  $output = '';
125  if(empty($frm)){
126  // Pas de données venant de validation de formulaire, donc on charge le contenu de la base de données
127  /* Charge les informations du pays */
128  $qid = query("SELECT *
129  FROM peel_pays
130  WHERE id = " . intval($id) . ' AND ' . get_filter_site_cond('pays', null, true));
131  if ($frm = fetch_assoc($qid)) {
132  } else {
133  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_PAYS_ERR_NOT_FOUND']))->fetch();
134  }
135  }
136  $frm['id'] = $id;
137  $frm["nouveau_mode"] = "maj";
138  $frm["titre_bouton"] = $GLOBALS['STR_ADMIN_FORM_SAVE_CHANGES'];
139  $output .= affiche_formulaire_pays($frm);
140  return $output;
141 }
142 
150 {
151  $output = '';
152  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_formulaire_pays.tpl');
153  $tpl->assign('action', get_current_url(false) . '?start=0');
154  $tpl->assign('form_token', get_form_token_input($_SERVER['PHP_SELF'] . $frm['nouveau_mode'] . intval($frm['id'])));
155  $tpl->assign('mode', $frm["nouveau_mode"]);
156  $tpl->assign('id', intval($frm['id']));
157  $tpl->assign('iso', $frm["iso"]);
158  $tpl->assign('iso3', $frm["iso3"]);
159  $tpl->assign('iso_num', $frm["iso_num"]);
160  $tpl->assign('etat', $frm["etat"]);
161  $tpl_langs = array();
162  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
163  $tpl_langs[] = array('lng' => $lng,
164  'pays' => $frm['pays_' . $lng],
165  );
166  }
167  $tpl->assign('langs', $tpl_langs);
168 
169  $tpl_options = array();
170  $sql_zone = "SELECT id, nom_" . $_SESSION['session_langue'] . "
171  FROM peel_zones
172  WHERE " . get_filter_site_cond('zones') . "
173  ORDER BY nom_" . $_SESSION['session_langue'];
174  $res_zone = query($sql_zone);
175  while ($tab_zone = fetch_assoc($res_zone)) {
176  $tpl_options[] = array('value' => intval($tab_zone['id']),
177  'issel' => vb($frm['zone']) == $tab_zone['id'],
178  'name' => $tab_zone['nom_' . $_SESSION['session_langue']]
179  );
180  }
181  $tpl->assign('site_id_select_options', get_site_id_select_options(vb($frm['site_id'])));
182  $tpl->assign('options', $tpl_options);
183  $tpl->assign('position', $frm["position"]);
184  $tpl->assign('titre_bouton', $frm["titre_bouton"]);
185  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
186  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
187  $tpl->assign('STR_ADMIN_PAYS_ADD_COUNTRY', $GLOBALS['STR_ADMIN_PAYS_ADD_COUNTRY']);
188  $tpl->assign('STR_ADMIN_LANGUAGES_SECTION_HEADER', $GLOBALS['STR_ADMIN_LANGUAGES_SECTION_HEADER']);
189  $tpl->assign('STR_COUNTRY', $GLOBALS['STR_COUNTRY']);
190  $tpl->assign('STR_ADMIN_PAYS_ISO_CODES_HEADER', $GLOBALS['STR_ADMIN_PAYS_ISO_CODES_HEADER']);
191  $tpl->assign('STR_ADMIN_PAYS_ISO_2', $GLOBALS['STR_ADMIN_PAYS_ISO_2']);
192  $tpl->assign('STR_ADMIN_PAYS_ISO_3', $GLOBALS['STR_ADMIN_PAYS_ISO_3']);
193  $tpl->assign('STR_ADMIN_PAYS_ISO_NUMERIC', $GLOBALS['STR_ADMIN_PAYS_ISO_NUMERIC']);
194  $tpl->assign('STR_ADMIN_VARIOUS_INFORMATION_HEADER', $GLOBALS['STR_ADMIN_VARIOUS_INFORMATION_HEADER']);
195  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
196  $tpl->assign('STR_YES', $GLOBALS['STR_YES']);
197  $tpl->assign('STR_NO', $GLOBALS['STR_NO']);
198  $tpl->assign('STR_SHIPPING_ZONE', $GLOBALS['STR_SHIPPING_ZONE']);
199  $tpl->assign('STR_ADMIN_POSITION', $GLOBALS['STR_ADMIN_POSITION']);
200  $output .= $tpl->fetch();
201  return $output;
202 }
203 
211 {
212  $qid = query("SELECT pays_" . $_SESSION['session_langue'] . "
213  FROM peel_pays
214  WHERE id = " . intval($id) . ' AND ' . get_filter_site_cond('pays', null, true));
215  $p = fetch_assoc($qid);
216 
217  /* Efface le pays */
218  query("DELETE FROM peel_pays
219  WHERE id = " . intval($id) . '" AND ' . get_filter_site_cond('pays', null, true));
220  return $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_PAYS_MSG_DELETED_OK'], $p['pays_' . $_SESSION['session_langue']])))->fetch();
221 }
222 
229 function insere_pays(&$frm)
230 {
231  $sql = "INSERT INTO peel_pays (
232  zone
233  , etat
234  , iso
235  , iso3
236  , iso_num
237  , position
238  , site_id";
239  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
240  $sql .= ", pays_" . $lng;
241  }
242  $sql .= "
243  ) VALUES (
244  '" . intval($frm['zone']) . "'
245  , '" . intval(vb($frm['etat'])) . "'
246  , '" . nohtml_real_escape_string($frm['iso']) . "'
247  , '" . nohtml_real_escape_string($frm['iso3']) . "'
248  , '" . intval($frm['iso_num']) . "'
249  , '" . intval($frm['position']) . "'
250  , '" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'";
251  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
252  $sql .= ", '" . nohtml_real_escape_string($frm['pays_' . $lng]) . "'";
253  }
254  $sql .= "
255  )";
256 
257  query($sql);
258 }
259 
267 function maj_pays($id, $frm)
268 {
269  $sql = "UPDATE peel_pays
270  SET zone = '" . intval($frm['zone']) . "'";
271  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
272  $sql .= " , pays_" . $lng . " = '" . nohtml_real_escape_string($frm['pays_' . $lng]) . "'";
273  }
274  $sql .= "
275  , site_id = '" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'
276  , iso = '" . nohtml_real_escape_string($frm['iso']) . "'
277  , iso3 = '" . nohtml_real_escape_string($frm['iso3']) . "'
278  , iso_num = '" . intval($frm['iso_num']) . "'
279  , etat = '" . intval(vb($frm['etat'])) . "'
280  , position = '" . intval($frm['position']) . "'
281  WHERE id = '" . intval($id) . "'";
282  query($sql);
283 }
284 
291 {
292  if (isset($_POST['etat']) && isset($_POST['zones'])) {
293  if ($_POST['etat'] == 1) {
294  $etat = 1;
295  } else {
296  $etat = 0;
297  }
298  $sql = "UPDATE peel_pays
299  SET etat='" . intval($etat) . "'
300  WHERE zone='" . intval($_POST['zones']) . "' AND " . get_filter_site_cond('pays', null, true);
301  query($sql);
302  }
303 
304  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_liste_pays.tpl');
305  $tpl->assign('add_src', $GLOBALS['administrer_url'] . '/images/add.png');
306  $tpl->assign('add_href', get_current_url(false) . '?mode=ajout');
307  $tpl->assign('action', get_current_url(false));
308 
309  $tpl_options = array();
310  $sql_zone = "SELECT id, nom_" . $_SESSION['session_langue'] . "
311  FROM peel_zones
312  WHERE " . get_filter_site_cond('zones') . "
313  ORDER BY nom_" . $_SESSION['session_langue'];
314  $res_zone = query($sql_zone);
315  while ($result = fetch_assoc($res_zone)) {
316  $tpl_options[] = array('value' => intval($result['id']),
317  'name' => $result['nom_' . $_SESSION['session_langue']]
318  );
319  }
320  $tpl->assign('options', $tpl_options);
321 
322  $result = query("SELECT p.*, z.nom_" . $_SESSION['session_langue'] . " AS zone_name
323  FROM peel_pays p
324  LEFT JOIN peel_zones z ON z.id=p.zone AND " . get_filter_site_cond('zones', 'z') . "
325  WHERE " . get_filter_site_cond('pays', "p", true) . "
326  ORDER BY p.position ASC, p.pays_" . $_SESSION['session_langue'] . " ASC");
327 
328  $tpl->assign('drop_src', $GLOBALS['administrer_url'] . '/images/b_drop.png');
329  $tpl->assign('edit_src', $GLOBALS['administrer_url'] . '/images/b_edit.png');
330  if (!(num_rows($result) == 0)) {
331  $tpl_results = array();
332  $i = 0;
333  while ($ligne = fetch_assoc($result)) {
334  $zone = String::html_entity_decode_if_needed($ligne['zone_name']);
335  $tpl_results[] = array('tr_rollover' => tr_rollover($i, true, null, null, 'sortable_'.$ligne['id']),
336  'nom' => $ligne['pays_' . $_SESSION['session_langue']],
337  'drop_href' => get_current_url(false) . '?mode=suppr&id=' . $ligne['id'],
338  'edit_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'],
339  'pays' => $ligne['pays_' . $_SESSION['session_langue']],
340  'flag' => getFlag($ligne['iso'], $ligne['pays_' . $_SESSION['session_langue']]),
341  'zone' => vb($zone),
342  'position' => $ligne['position'],
343  'etat_onclick' => 'change_status("countries", "' . $ligne['id'] . '", this, "'.$GLOBALS['administrer_url'] . '")',
344  'etat_src' => $GLOBALS['administrer_url'] . '/images/' . (empty($ligne['etat']) ? 'puce-blanche.gif' : 'puce-verte.gif'),
345  'site_name' => get_site_name($ligne['site_id'])
346  );
347  $i++;
348  }
349  $tpl->assign('results', $tpl_results);
350  }
351  $GLOBALS['sortable_rpc'] = 'rpc_positions.php?mode=countries';
352 
353  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
354  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
355  $tpl->assign('STR_ADMIN_PAYS_LIST_EXPLAIN', $GLOBALS['STR_ADMIN_PAYS_LIST_EXPLAIN']);
356  $tpl->assign('STR_ADMIN_PAYS_TITLE', $GLOBALS['STR_ADMIN_PAYS_TITLE']);
357  $tpl->assign('STR_ADMIN_PAYS_CREATE', $GLOBALS['STR_ADMIN_PAYS_CREATE']);
358  $tpl->assign('STR_ADMIN_PAYS_ZONE_UPDATE_LABEL', $GLOBALS['STR_ADMIN_PAYS_ZONE_UPDATE_LABEL']);
359  $tpl->assign('STR_ADMIN_ACTIVATE', $GLOBALS['STR_ADMIN_ACTIVATE']);
360  $tpl->assign('STR_ADMIN_DEACTIVATE', $GLOBALS['STR_ADMIN_DEACTIVATE']);
361  $tpl->assign('STR_VALIDATE', $GLOBALS['STR_VALIDATE']);
362  $tpl->assign('STR_ADMIN_ACTION', $GLOBALS['STR_ADMIN_ACTION']);
363  $tpl->assign('STR_COUNTRY', $GLOBALS['STR_COUNTRY']);
364  $tpl->assign('STR_ADMIN_MENU_MANAGE_ZONES', $GLOBALS['STR_ADMIN_MENU_MANAGE_ZONES']);
365  $tpl->assign('STR_ADMIN_POSITION', $GLOBALS['STR_ADMIN_POSITION']);
366  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
367  $tpl->assign('STR_ADMIN_DELETE_WARNING', $GLOBALS['STR_ADMIN_DELETE_WARNING']);
368  $tpl->assign('STR_DELETE', $GLOBALS['STR_DELETE']);
369  $tpl->assign('STR_ADMIN_PAYS_MODIFY', $GLOBALS['STR_ADMIN_PAYS_MODIFY']);
370  $tpl->assign('STR_ADMIN_PAYS_NOTHING_FOUND', $GLOBALS['STR_ADMIN_PAYS_NOTHING_FOUND']);
371  return $tpl->fetch();
372 }
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_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: pays.php:22
upload($field_name, $rename_file=true, $file_kind=null, $image_max_width=null, $image_max_height=null, $path=null, $new_file_name_without_extension=null, $default_return_value=null)
Fonction d'upload de fichiers.
Definition: fonctions.php:3302
$tpl_langs
affiche_formulaire_ajout_pays(&$frm)
FONCTIONS.
Definition: pays.php:92
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.
static html_entity_decode_if_needed($string)
String::html_entity_decode_if_needed()
Definition: String.php:533
insere_pays(&$frm)
Ajoute le pays dans la table pays.
Definition: pays.php:229
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_liste_pays()
affiche_liste_pays()
Definition: pays.php:290
affiche_formulaire_modif_pays($id, &$frm)
Affiche le formulaire de modification pour le pays sélectionné
Definition: pays.php:122
$tpl_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
maj_pays($id, $frm)
Met à jour le pays $id avec de nouvelles valeurs.
Definition: pays.php:267
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
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
get_form_token_input($name= 'general', $use_existing_token=true, $return_as_input_form=true)
get_form_token_input()
Definition: fonctions.php:94
affiche_formulaire_pays(&$frm)
affiche_formulaire_pays()
Definition: pays.php:149
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
$output
Definition: pays.php:23
$frm
Definition: pays.php:21
supprime_pays($id)
Supprime le pays spécifié par $id.
Definition: pays.php:210
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: pays.php:19
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:19 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.