PEEL Shopping
Open source ecommerce : PEEL Shopping
fonctions_admin.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_admin.php 47339 2015-10-12 17:30:16Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
24  if (vn($GLOBALS['site_parameters']['display_prices_with_taxes_in_admin']) == '0') {
25  return false;
26  } else {
27  return true;
28  }
29 }
30 
36 function get_admin_menu()
37 {
38  if (IN_INSTALLATION) {
39  $GLOBALS['main_menu_items']['install'] = array($GLOBALS['wwwroot'] . '/installation/' => $GLOBALS['STR_INSTALLATION']);
40  $GLOBALS['menu_items']['install'][get_url('/installation/index.php')] = $GLOBALS['STR_ADMIN_INSTALL_STEP1_TITLE'];
41  $GLOBALS['menu_items']['install'][get_url('/installation/bdd.php')] = $GLOBALS['STR_ADMIN_INSTALL_STEP2_TITLE'];
42  $GLOBALS['menu_items']['install'][get_url('/installation/choixbase.php')] = $GLOBALS['STR_ADMIN_INSTALL_STEP3_TITLE'];
43  $GLOBALS['menu_items']['install'][get_url('/installation/verifdroits.php')] = $GLOBALS['STR_ADMIN_INSTALL_STEP4_TITLE'];
44  $GLOBALS['menu_items']['install'][get_url('/installation/configuration.php')] = $GLOBALS['STR_ADMIN_INSTALL_STEP5_TITLE'];
45  $GLOBALS['menu_items']['install'][get_url('/installation/fin.php')] = $GLOBALS['STR_ADMIN_INSTALL_STEP6_TITLE'];
46  } else {
47  $GLOBALS['main_menu_items']['home'] = array($GLOBALS['administrer_url'] . '/' => $GLOBALS["STR_ADMIN_MENU_HOME_TITLE"]);
48  $GLOBALS['menu_items']['home'][$GLOBALS['administrer_url'] . '/'] = $GLOBALS["STR_ADMIN_MENU_HOME_BACK"];
49  $GLOBALS['menu_items']['home'][$GLOBALS['wwwroot'] . '/'] = $GLOBALS["STR_ADMIN_MENU_HOME_FRONT"];
50  if (a_priv('admin_manage', true)) {
51  $GLOBALS['main_menu_items']['manage'] = array($GLOBALS['administrer_url'] . '/sites.php' => $GLOBALS["STR_ADMIN_MENU_MANAGE_TITLE"]);
52  $GLOBALS['menu_items']['manage']['manage_general'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_TITLE"];
53  $GLOBALS['menu_items']['manage_general'][$GLOBALS['administrer_url'] . '/sites.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_SITES"];
54  $GLOBALS['menu_items']['manage_general'][$GLOBALS['administrer_url'] . '/configuration.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_CONFIGURATION"];
55  $GLOBALS['menu_items']['manage_general'][$GLOBALS['administrer_url'] . '/societe.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_SOCIETE"];
56  $GLOBALS['menu_items']['manage_general'][$GLOBALS['administrer_url'] . '/langues.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_LANGUES"];
57  $GLOBALS['menu_items']['manage_general'][$GLOBALS['administrer_url'] . '/clean_folders.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_CLEAN_FOLDERS"];
58  $GLOBALS['menu_items']['manage']['manage_payments'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_PAYMENT_AND_TAXES"];
59  $GLOBALS['menu_items']['manage_payments'][$GLOBALS['administrer_url'] . '/paiement.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_PAYMENT"];
60  $GLOBALS['menu_items']['manage_payments'][$GLOBALS['administrer_url'] . '/tva.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_TVA"];
61  $GLOBALS['menu_items']['manage_payments'][$GLOBALS['administrer_url'] . '/statut_paiement.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_PAYMENT_STATUS"];
62  $GLOBALS['menu_items']['manage']['manage_delivery'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_DELIVERY_HEADER"];
63  $GLOBALS['menu_items']['manage_delivery'][$GLOBALS['administrer_url'] . '/pays.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_COUNTRIES"];
64  $GLOBALS['menu_items']['manage_delivery'][$GLOBALS['administrer_url'] . '/zones.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_ZONES"];
65  $GLOBALS['menu_items']['manage_delivery'][$GLOBALS['administrer_url'] . '/types.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_DELIVERY"];
66  $GLOBALS['menu_items']['manage_delivery'][$GLOBALS['administrer_url'] . '/tarifs.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_DELIVERY_COST"];
67  $GLOBALS['menu_items']['manage_delivery'][$GLOBALS['administrer_url'] . '/statut_livraison.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_DELIVERY_STATUS"];
68  $GLOBALS['menu_items']['manage']['manage_emails'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_EMAILS_HEADER"];
69  $GLOBALS['menu_items']['manage_emails'][$GLOBALS['administrer_url'] . '/email-templates.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_EMAIL"];
70  if (check_if_module_active('bounces', 'bounce_driver.php')) {
71  $GLOBALS['menu_items']['manage_emails'][$GLOBALS['wwwroot_in_admin'] . '/modules/bounces/administrer/bad_mails.php'] = $GLOBALS["STR_ADMIN_MENU_MANAGE_BOUNCE"];
72  }
73  }
74  if (a_priv('admin_users', true)) {
75  // Menu des utilisateurs
76  $GLOBALS['main_menu_items']['users'] = array($GLOBALS['administrer_url'] . '/utilisateurs.php' => $GLOBALS["STR_ADMIN_MENU_USERS_USERS"]);
77  $GLOBALS['menu_items']['users']['users_general'] = $GLOBALS["STR_ADMIN_MENU_USERS_USERS"];
78  $GLOBALS['menu_items']['users_general'][$GLOBALS['administrer_url'] . '/utilisateurs.php'] = $GLOBALS["STR_ADMIN_MENU_USERS_USERS_LIST"];
79  $GLOBALS['menu_items']['users_general'][$GLOBALS['administrer_url'] . '/utilisateurs.php?mode=ajout'] = $GLOBALS["STR_ADMIN_MENU_USERS_USER_CREATE"];
80  $GLOBALS['menu_items']['users_general'][$GLOBALS['administrer_url'] . '/utilisateurs.php?mode=liste&priv=supplier'] = $GLOBALS["STR_ADMIN_MENU_USERS_SUPPLIERS_LIST"];
81  $GLOBALS['menu_items']['users']['users_retaining'] = $GLOBALS["STR_ADMIN_MENU_USERS_RETAINING"];
82  $GLOBALS['menu_items']['users_retaining'][$GLOBALS['administrer_url'] . '/newsletter.php'] = $GLOBALS["STR_ADMIN_MENU_USERS_NEWSLETTER"];
83  $GLOBALS['menu_items']['users_retaining'][$GLOBALS['administrer_url'] . '/codes_promos.php'] = $GLOBALS["STR_ADMIN_MENU_USERS_CODE_PROMO"];
84  if (check_if_module_active('good_clients', 'administrer/bons_clients.php')) {
85  $GLOBALS['menu_items']['users_retaining'][$GLOBALS['wwwroot_in_admin'] . '/modules/good_clients/administrer/bons_clients.php'] = $GLOBALS["STR_ADMIN_MENU_USERS_BEST_CLIENTS"];
86  }
87  if (check_if_module_active('birthday', 'administrer/bons_anniversaires.php')) {
88  $GLOBALS['menu_items']['users_retaining'][$GLOBALS['wwwroot_in_admin'] . '/modules/birthday/administrer/bons_anniversaires.php'] = $GLOBALS["STR_ADMIN_MENU_USERS_BIRTHDAY"];
89  }
90  // On affichera le menu relation client uniquement si $GLOBALS['menu_items']['users_sales'] n'est pas vide
91  $GLOBALS['menu_items']['users']['users_sales'] = $GLOBALS["STR_ADMIN_MENU_USERS_SALES_MANAGEMENT"];
92  if (file_exists($GLOBALS['dirroot'] . '/modules/maps_users/administrer/map_google_search.php')) {
93  $GLOBALS['menu_items']['users_sales'][$GLOBALS['wwwroot_in_admin'] . '/modules/maps_users/administrer/map_google_search.php'] = $GLOBALS["STR_ADMIN_MENU_USERS_USERS_MAP"];
94  }
95  if (check_if_module_active('offres')) {
96  $GLOBALS['menu_items']['users']['users_offre'] = $GLOBALS["STR_ADMIN_OFFRES"];
97  $GLOBALS['menu_items']['users_offre'][get_url('/modules/offres/administrer/offres.php')] = $GLOBALS["STR_ADMIN_ADMIN_OFFRES_ALL_LIST"];
98  $GLOBALS['menu_items']['users_offre'][get_url('/modules/offres/administrer/list_utilisateurs_offres.php')] = $GLOBALS["STR_ADMIN_LIST_UTILISATEURS_TITLE"];
99  }
100  }
101  if (a_priv('admin_products', true)) {
102  $GLOBALS['main_menu_items']['products'] = array($GLOBALS['administrer_url'] . '/produits.php' => $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRODUCTS"]);
103  $GLOBALS['menu_items']['products']['products_general'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRODUCTS"];
104  $GLOBALS['menu_items']['products_general'][$GLOBALS['administrer_url'] . '/produits.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRODUCTS_LIST"];
105  $GLOBALS['menu_items']['products_general'][$GLOBALS['administrer_url'] . '/produits.php?mode=ajout'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRODUCT_ADD"];
106  $GLOBALS['menu_items']['products_general'][$GLOBALS['administrer_url'] . '/positions.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRODUCTS_ORDER"];
107  $GLOBALS['menu_items']['products_general'][$GLOBALS['administrer_url'] . '/prix.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRICE_UPDATE"];
108  $GLOBALS['menu_items']['products_general'][$GLOBALS['administrer_url'] . '/prix_pourcentage.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_PRICE_UPDATE_BY_PERCENTAGES"];
109  $GLOBALS['menu_items']['products']['products_categories'] = $GLOBALS["STR_ADMIN_CATEGORIES"];
110  $GLOBALS['menu_items']['products_categories'][$GLOBALS['administrer_url'] . '/categories.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_CATEGORIES_LIST"];
111  $GLOBALS['menu_items']['products_categories'][$GLOBALS['administrer_url'] . '/categories.php?mode=ajout'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_CATEGORY_ADD"];
112  $GLOBALS['menu_items']['products_categories'][$GLOBALS['administrer_url'] . '/marques.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_BRAND_LIST"];
113  $GLOBALS['menu_items']['products']['products_attributes'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_ATTRIBUTES_HEADER"];
114  $GLOBALS['menu_items']['products_attributes'][$GLOBALS['administrer_url'] . '/couleurs.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_COLORS"];
115  $GLOBALS['menu_items']['products_attributes'][$GLOBALS['administrer_url'] . '/tailles.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_SIZES"];
116  }
117  if (a_priv('admin_sales', true)) {
118  // Menu des ventes
119  $GLOBALS['main_menu_items']['sales'] = array($GLOBALS['administrer_url'] . '/commander.php' => $GLOBALS["STR_ADMIN_MENU_SALES_SALES_TITLE"]);
120  $GLOBALS['menu_items']['sales']['sales_general'] = $GLOBALS["STR_ADMIN_MENU_SALES_SALES_HEADER"];
121  $GLOBALS['menu_items']['sales_general'][$GLOBALS['administrer_url'] . '/commander.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_ORDERS"];
122  $GLOBALS['menu_items']['sales_general'][$GLOBALS['administrer_url'] . '/commander.php?mode=ajout'] = $GLOBALS["STR_ADMIN_MENU_SALES_ORDER_CREATION"];
123  if (check_if_module_active('export', 'administrer/export_ventes.php')) {
124  $GLOBALS['menu_items']['sales_general'][$GLOBALS['administrer_url'] . '/ventes.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_SALES_REPORT_HEADER"];
125  } else {
126  $GLOBALS['menu_items']['sales_general'][$GLOBALS['administrer_url'] . '/ventes.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_SALES_REPORT"];
127  }
128  if (file_exists($GLOBALS['dirroot'] . '/modules/hosting/administrer/hosting.php')) {
129  $GLOBALS['menu_items']['sales']['sales_hosting'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_HOSTING_HEADER"];
130  $GLOBALS['menu_items']['sales_hosting'][$GLOBALS['wwwroot_in_admin'] . '/modules/hosting/administrer/hosting.php'] = $GLOBALS["STR_ADMIN_MENU_PRODUCTS_HOSTING"];
131  }
132  // On affichera le menu relation client uniquement si $GLOBALS['menu_items']['users_sales'] n'est pas vide
133  $GLOBALS['menu_items']['sales']['sales_accounting'] = $GLOBALS["STR_ADMIN_MENU_SALES_ACCOUNTING_HEADER"];
134  if (check_if_module_active('statistiques')) {
135  $GLOBALS['menu_items']['sales_accounting'][$GLOBALS['wwwroot_in_admin'] . '/modules/statistiques/administrer/statcommande.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_SALES_STAT"];
136  }
137  if (check_if_module_active('marges')) {
138  $GLOBALS['menu_items']['sales_accounting'][$GLOBALS['wwwroot_in_admin'] . '/modules/marges/administrer/marges.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_MARGINS"];
139  }
140  if (check_if_module_active('facture_advanced', 'administrer/genere_pdf.php')) {
141  $GLOBALS['menu_items']['sales_accounting'][$GLOBALS['wwwroot_in_admin'] . '/modules/facture_advanced/administrer/genere_pdf.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_PDF_BILLS"];
142  }
143  $GLOBALS['menu_items']['sales']['sales_delivery'] = $GLOBALS["STR_ADMIN_MENU_SALES_DELIVERY_HEADER"];
144  if (check_if_module_active('export', 'administrer/export_livraisons.php')) {
145  $GLOBALS['menu_items']['sales_delivery'][$GLOBALS['administrer_url'] . '/livraisons.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_DELIVERY_EXPORT"];
146  } else {
147  $GLOBALS['menu_items']['sales_delivery'][$GLOBALS['administrer_url'] . '/livraisons.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_DELIVERY_REPORT"];
148  }
149  if (check_if_module_active('picking')) {
150  $GLOBALS['menu_items']['sales_delivery'][$GLOBALS['wwwroot_in_admin'] . '/modules/picking/administrer/picking.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_PICKING_LIST"];
151  }
152  if (check_if_module_active('exaprint')) {
153  $GLOBALS['menu_items']['sales_delivery'][$GLOBALS['wwwroot_in_admin'] . '/modules/exaprint/administrer/exaprint.php'] = $GLOBALS["STR_ADMIN_MENU_SALES_EXAPRINT"];
154  }
155  }
156  if (a_priv('admin_content', true)) {
157  $GLOBALS['main_menu_items']['content'] = array($GLOBALS['administrer_url'] . '/articles.php' => $GLOBALS["STR_ADMIN_MENU_CONTENT_TITLE"]);
158  $GLOBALS['menu_items']['content']['content_articles'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_ARTICLES_HEADER"];
159  $GLOBALS['menu_items']['content_articles'][$GLOBALS['administrer_url'] . '/articles.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_ARTICLES_LIST"];
160  $GLOBALS['menu_items']['content_articles'][$GLOBALS['administrer_url'] . '/articles.php?mode=ajout'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_ARTICLE_ADD"];
161  $GLOBALS['menu_items']['content_articles'][$GLOBALS['administrer_url'] . '/rubriques.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_CATEGORIES_LIST"];
162  $GLOBALS['menu_items']['content_articles'][$GLOBALS['administrer_url'] . '/rubriques.php?mode=ajout'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_CATEGORY_ADD"];
163 
164  $GLOBALS['menu_items']['content']['content_general'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_HTML_HEADER"];
165  $url_cgv = get_cgv_url(false);
166  $GLOBALS['menu_items']['content_general'][$GLOBALS['administrer_url'] . '/cgv.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_TERMS"];
167  if (file_exists($GLOBALS['dirroot'] . '/modules/cgu-template/administrer/cgu-update.php')) {
168  $GLOBALS['menu_items']['content_general'][$GLOBALS['wwwroot_in_admin'] . '/modules/cgu-template/administrer/cgu-update.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_TERMS_TEMPLATES"];
169  }
170  if (file_exists($GLOBALS['dirroot'] . '/modules/cgu-template/administrer/cgu.php')) {
171  $GLOBALS['menu_items']['content_general'][$GLOBALS['wwwroot_in_admin'] . '/modules/cgu-template/administrer/cgu.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_TERMS_GENERATE"];
172  }
173  $GLOBALS['menu_items']['content_general'][$GLOBALS['administrer_url'] . '/legal.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_LEGAL"];
174  $GLOBALS['menu_items']['content_general'][$GLOBALS['administrer_url'] . '/plan.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_GOOGLEMAP"];
175  $GLOBALS['menu_items']['content_general'][$GLOBALS['administrer_url'] . '/contacts.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_CONTACTS"];
176  $GLOBALS['menu_items']['content']['content_various'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_VARIOUS_HEADER"];
177  $GLOBALS['menu_items']['content_various'][$GLOBALS['administrer_url'] . '/html.php'] = $GLOBALS["STR_ADMIN_MENU_CONTENT_HTML"];
178  }
179  if (a_priv('admin_moderation', true) || a_priv('admin_webmastering', true)) {
180  $GLOBALS['main_menu_items']['webmastering'] = array($GLOBALS['administrer_url'] . '/produits_achetes.php' => $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_TITLE"]);
181  }
182  if (a_priv('admin_moderation', true)) {
183  $GLOBALS['menu_items']['webmastering']['moderation_various'] = $GLOBALS["STR_ADMIN_MENU_MODERATION_TITLE"];
184  $GLOBALS['menu_items']['moderation_various'][$GLOBALS['administrer_url'] . '/list_admin_actions.php?action_cat=PHONE'] = $GLOBALS["STR_ADMIN_MENU_MODERATION_PHONE_CALLS"];
185  $GLOBALS['menu_items']['moderation_various'][$GLOBALS['administrer_url'] . '/list_admin_actions.php'] = $GLOBALS["STR_ADMIN_MENU_MODERATION_ADMIN_ACTIONS"];
186  $GLOBALS['menu_items']['moderation_various'][$GLOBALS['administrer_url'] . '/connexion_user.php'] = $GLOBALS["STR_ADMIN_MENU_MODERATION_USER_CONNEXIONS"];
187  }
188  if (a_priv('admin_webmastering', true)) {
189  // Menu de webmastering
190  $GLOBALS['menu_items']['webmastering']['webmastering_marketing'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_MARKETING"];
191  $GLOBALS['menu_items']['webmastering_marketing'][$GLOBALS['administrer_url'] . '/produits_achetes.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_BEST_PRODUCTS"];
192  $GLOBALS['menu_items']['webmastering_marketing'][$GLOBALS['administrer_url'] . '/import_produits.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_IMPORT_PRODUCTS"];
193  $GLOBALS['menu_items']['webmastering_marketing'][$GLOBALS['administrer_url'] . '/export_produits.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_EXPORT_PRODUCTS"];
194  if (file_exists($GLOBALS['dirroot'] . '/modules/import/administrer/import_clients.php')) {
195  $GLOBALS['menu_items']['webmastering_marketing'][$GLOBALS['wwwroot_in_admin'] . '/modules/import/administrer/import_clients.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_CLIENTS_IMPORT"];
196  }
197  if (check_if_module_active('export', 'export_clients.php')) {
198  $GLOBALS['menu_items']['webmastering_marketing'][$GLOBALS['wwwroot_in_admin'] . '/modules/export/administrer/export_clients.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_CLIENTS_EXPORT"];
199  }
200  if (check_if_module_active('expeditor')) {
201  $GLOBALS['menu_items']['webmastering_marketing'][$GLOBALS['wwwroot_in_admin'] . '/modules/expeditor/administrer/expeditor.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_EXPEDITOR"];
202  }
203  $GLOBALS['menu_items']['webmastering']['webmastering_seo'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_SEO_HEADER"];
204  if (check_if_module_active('comparateur')) {
205  $GLOBALS['menu_items']['webmastering_seo'][$GLOBALS['wwwroot_in_admin'] . '/modules/comparateur/administrer/mysql2comparateur.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_COMPARATORS"];
206  }
207  if (empty($_SESSION['session_admin_multisite']) || $_SESSION['session_admin_multisite']==$GLOBALS['site_id']) {
208  // Possibilité de générer le sitemap uniquement pour le domaine en cours d'utilisation, et pas pour le site administré.
209  $GLOBALS['menu_items']['webmastering_seo'][$GLOBALS['administrer_url'] . '/sitemap.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_SITEMAP"];
210  $GLOBALS['menu_items']['webmastering_seo'][$GLOBALS['administrer_url'] . '/urllist.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_SITEMAP_URLLIST"];
211  }
212  $GLOBALS['menu_items']['webmastering_seo'][$GLOBALS['administrer_url'] . '/meta.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_META"];
213  if (file_exists($GLOBALS['dirroot'] . '/modules/projects_management/administrer/projects.php')) {
214  $GLOBALS['menu_items']['webmastering']['webmastering_projects'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_PROJECT_MANAGEMENT"];
215  $GLOBALS['menu_items']['webmastering_projects'][$GLOBALS['wwwroot_in_admin'] . '/modules/projects_management/administrer/projects.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_PROJECT_TASKS"];
216  $GLOBALS['menu_items']['webmastering_projects'][$GLOBALS['wwwroot_in_admin'] . '/modules/projects_management/administrer/project-custom-orders.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_PROJECT_SOLD"];
217  $GLOBALS['menu_items']['webmastering_projects'][$GLOBALS['wwwroot_in_admin'] . '/modules/projects_management/administrer/project-events.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_PROJECT_CONTENT"];
218  }
219  if (check_if_module_active('calc')) {
220  $GLOBALS['menu_items']['webmastering']['webmastering_various'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_VARIOUS_HEADER"];
221  $GLOBALS['menu_items']['webmastering_various'][$GLOBALS['wwwroot_in_admin'] . '/modules/calc/calc.php'] = $GLOBALS["STR_ADMIN_MENU_WEBMASTERING_CALC"];
222  }
223  }
224  if(!empty($GLOBALS['site_parameters']['admin_menu_items_additional_menus_array']) && !empty($GLOBALS['site_parameters']['admin_menu_items_additional_titles_array'])) {
225  foreach($GLOBALS['site_parameters']['admin_menu_items_additional_menus_array'] as $this_type => $this_url_list) {
226  foreach(explode(',', str_replace(' ', '', $this_url_list)) as $this_url) {
227  if(!empty($GLOBALS['site_parameters']['admin_menu_items_additional_titles_array'][$this_url])) {
228  if(!empty($GLOBALS['menu_items'][$this_type])) {
229  $this_title = $GLOBALS['site_parameters']['admin_menu_items_additional_titles_array'][$this_url];
230  if(String::strpos($this_url, '//') === false) {
231  $this_url = $GLOBALS['wwwroot_in_admin'] . $this_url;
232  }
233  // Si le tableau existe, c'est que les droits d'accès de l'utilisateur ont déjà été vérifiés
234  $GLOBALS['menu_items'][$this_type][$this_url] = $this_title;
235  }
236  }
237  }
238  }
239  }
240  $hook_result = call_module_hook('admin_menu_items', array(), 'array');
241  $GLOBALS['main_menu_items'] = array_merge_recursive($GLOBALS['main_menu_items'], vb($hook_result['main_menu_items'], array()));
242  $GLOBALS['menu_items'] = array_merge_recursive($GLOBALS['menu_items'], vb($hook_result['menu_items'], array()));
243  if (empty($GLOBALS['menu_items']['users_sales'])) {
244  // On affiche le menu relation client uniquement si $GLOBALS['menu_items']['users_sales'] n'est pas vide
245  unset($GLOBALS['menu_items']['users']['users_sales']);
246  }
247  if (empty($GLOBALS['menu_items']['sales_accounting'])) {
248  // On affiche le menu comptabilité uniquement si $GLOBALS['menu_items']['sales_accounting'] n'est pas vide
249  unset($GLOBALS['menu_items']['sales']['sales_accounting']);
250  }
251  }
252  $current_url = get_current_url(false);
253  $current_url_full = get_current_url(true);
254 
255  $output = '
256 ';
257  $i = 0;
258  foreach ($GLOBALS['main_menu_items'] as $this_main_item => $this_main_array) {
259  if (!empty($GLOBALS['menu_items'][$this_main_item]) && is_array($GLOBALS['menu_items'][$this_main_item])) {
260  foreach(array_keys($GLOBALS['menu_items'][$this_main_item]) as $this_key) {
261  $current_menu = (!empty($GLOBALS['menu_items'][$this_key][$current_url_full]));
262  $full_match = true;
263  if ($current_menu === false && !empty($GLOBALS['menu_items'][$this_key])) {
264  $current_menu = (!empty($GLOBALS['menu_items'][$this_key][$current_url]));
265  $full_match = false;
266  }
267  if(!empty($current_menu)) {
268  break;
269  }
270  }
271  } else {
272  $current_menu = (!empty($GLOBALS['menu_items'][$this_main_item][$current_url_full]));
273  $full_match = true;
274  if ($current_menu === false && !empty($GLOBALS['menu_items'][$this_main_item])) {
275  $current_menu = (!empty($GLOBALS['menu_items'][$this_main_item][$current_url]));
276  $full_match = false;
277  }
278  }
279  foreach ($this_main_array as $this_main_url => $this_main_title) {
280  $main_class = array();
281  $main_attributes = array();
282  if ($current_menu !== false || !empty($this_main_array[$current_url]) || !empty($this_main_array[$current_url_full])) {
283  $main_class[] = 'active';
284  }
285  if (!empty($GLOBALS['menu_items'][$this_main_item])) {
286  $main_class[] = 'dropdown-toggle';
287  $main_attributes[] = 'role="button" data-toggle="dropdown"';
288  $this_main_url = '#';
289  }
290  if ($this_main_item == 'home') {
291  $this_main_text = '<a id="menu_label_'.$this_main_item.'" title="' . $GLOBALS['STR_HOME'] . '" href="' . htmlspecialchars($this_main_url) . '" class="' . implode(' ', $main_class) . '" ' . implode(' ', $main_attributes) . '><span class="glyphicon glyphicon-home"></span></a>';
292  } else {
293  if (!empty($this_main_url) && !is_numeric($this_main_url)) {
294  $this_main_text = '<a id="menu_label_'.$this_main_item.'" href="' . htmlspecialchars($this_main_url) . '" class="' . implode(' ', $main_class) . '" ' . implode(' ', $main_attributes) . '>' . $this_main_title . (!empty($GLOBALS['menu_items'][$this_main_item])?'<b class="caret"></b>':'') . '</a>';
295  } else {
296  $this_main_text = '<a id="menu_label_'.$this_main_item.'" href="#">' . $this_main_title . '</a>';
297  }
298  }
299  if (!empty($GLOBALS['menu_items'][$this_main_item])) {
300  $this_main_text .= '<ul class="sousMenu dropdown-menu" role="menu" aria-labelledby="menu_label_'.$this_main_item.'">
301 ';
302  foreach ($GLOBALS['menu_items'][$this_main_item] as $this_url => $this_submenu) {
303  if (!empty($GLOBALS['menu_items'][$this_url]) && is_array($GLOBALS['menu_items'][$this_url])) {
304  $this_main_text .= '<li class="dropdown-submenu">
305  <a id="menu_'.substr(md5($this_url . $this_submenu),0,8).'" href="#" class="dropdown-toggle">' . String::strtoupper($this_submenu) . '</a>
306  <ul class="sousMenu dropdown-menu" role="menu" aria-labelledby="menu_'.substr(md5($this_url . $this_submenu),0,8).'">
307 ';
308  foreach ($GLOBALS['menu_items'][$this_url] as $this_url => $this_title) {
309  if (($current_url == $this_url && !$full_match) || $current_url_full == $this_url) {
310  $class = ' class="active"';
311  } elseif ($this_url == $GLOBALS['wwwroot_in_admin'] . '/modules/calc/calc.php') {
312  $class = ' onclick="return(window.open(this.href)?false:true);"';
313  } else {
314  $class = '';
315  }
316  if (!empty($this_url) && !is_numeric($this_url)) {
317  // var_dump($this_title, $this_url);
318  $this_text = '<a title="' . String::str_form_value($this_title) . '" href="' . htmlspecialchars($this_url) . '"' . $class . '>' . $this_title . '</a>';
319  } else {
320  $this_text = '<a href="#"' . $main_class . '>' . $this_title . '</a>';
321  }
322  $this_main_text .= '<li>' . $this_text . '</li>';
323  }
324  $this_main_text .= '
325  </ul>
326  </li>';
327  } else {
328  $this_title = $this_submenu;
329  if (($current_url == $this_url && !$full_match) || $current_url_full == $this_url) {
330  $class = ' class="active"';
331  } elseif ($this_url == $GLOBALS['wwwroot_in_admin'] . '/modules/calc/calc.php') {
332  $class = ' onclick="return(window.open(this.href)?false:true);"';
333  } else {
334  $class = '';
335  }
336  if (!empty($this_url) && !is_numeric($this_url)) {
337  $this_text = '<a title="' . $this_title . '" href="' . htmlspecialchars($this_url) . '"' . $class . '>' . $this_title . '</a>';
338  } else {
339  $this_text = '<a href="#"' . $main_class . '>' . $this_title . '</a>';
340  }
341  $this_main_text .= '<li>' . $this_text . '</li>';
342  }
343  }
344  $this_main_text .= '
345 </ul>';
346  }
347  $output .= '
348  <li class="menu_main_item menu_' . $this_main_item . ' dropdown">' . $this_main_text . '</li>
349 ';
350  }
351  $i++;
352  }
353  $output .= '
354 ';
355  return $output;
356 }
357 
364 {
365  $nb = 0;
366  $annee = date("Y");
367  $mois = date("m");
368  $jour = date("d");
369  $ladate = $annee . '-' . $mois . '-' . $jour;
370  $sql = "SELECT SUM(nb) AS nbp
371  FROM peel_nb_connexions_lien
372  WHERE la_date='" . nohtml_real_escape_string($ladate) . "'";
373  $query = query($sql);
374  $select = fetch_assoc($query);
375  $rep = $GLOBALS['STR_ADMIN_VISITS_TODAY']." : <span class='stat_data'>" . $select['nbp'] . "</span>";
376  $s = query("SELECT SUM(nb) AS nbp
377  FROM peel_nb_connexions_lien
378  WHERE la_date LIKE '" . nohtml_real_escape_string($annee . '-' . $mois) . "%'");
379  while ($select = fetch_assoc($s)) {
380  $nb = $nb + $select['nbp'];
381  }
382  $rep .= ", ".$GLOBALS['STR_ADMIN_VISITS_THIS_MONTH']." : <span class='stat_data'>" . $nb . "</span>";
383  $nb = 0;
384  $s = query("SELECT SUM(nb) AS nbp
385  FROM peel_nb_connexions_lien
386  WHERE la_date LIKE '" . nohtml_real_escape_string($annee) . "-%'");
387  while ($select = fetch_assoc($s)) {
388  $nb = $nb + $select['nbp'];
389  }
390  $rep .= ", ".$GLOBALS['STR_ADMIN_VISITS_THIS_YEAR']." : <span class='stat_data'>" . $nb . "</span>.";
391  return $rep;
392 }
393 
401 {
402  if (!empty($req['p1'])) {
403  $max_size = count($req['p1']);
404  for ($i = 1; $i <= $max_size; $i++) {
405  if ($req['l' . $i] != null && $req['l' . $i] != "" && floatval($req['q' . $i]) > 0 && floatval($req['p' . $i]) > 0)
406  return true;
407  }
408  }
409  return false;
410 }
411 
419 {
420  $max_size = count($req['produit']);
421  for ($i = 0; $i < $max_size; $i++) {
422  if ($req['produit'][$i] != null && $req['produit'][$i] != "" && floatval($req['quantite'][$i]) > 0 && floatval($req['prix'][$i]) > 0) {
423  return true;
424  }
425  }
426  return false;
427 }
428 
438 function sendclient($commandeid, $prefered_mode = 'html', $mode = 'bdc', $partial = '')
439 {
440  $sql = "SELECT *
441  FROM peel_commandes
442  WHERE id = '" . intval($commandeid) . "' AND " . get_filter_site_cond('commandes', null) . "";
443  $query = query($sql);
444  $commande = fetch_assoc($query);
445 
446  $custom_template_tags['ORDER_ID'] = $commandeid;
447  $custom_template_tags['MODE'] = $mode;
448  if ($prefered_mode == 'html' && check_if_module_active('factures', 'commande_html.php')) {
449  if(!empty($partial)) {
450  $custom_template_tags['AMOUNT'] = $partial;
451  } else {
452  $custom_template_tags['AMOUNT'] = fprix(vn($commande['montant']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false, false, null, false, true);
453  }
454  $template_technical_code = 'send_client_order_html';
455  $custom_template_tags['URL_FACTURE'] = get_site_wwwroot($commande['site_id']) . '/modules/factures/commande_html.php?currency_rate=' . vn($commande['currency_rate']) . '&code_facture=' . urlencode($commande['code_facture']) . '&partial=' . urlencode($partial) . '&mode=' . $mode;
456  } else {
457  $template_technical_code = 'send_client_order_pdf';
458  $custom_template_tags['URL_FACTURE'] = get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . urlencode($commande['code_facture']) . '&mode=' . $mode;
459  }
460  send_email($commande['email'], '', '', $template_technical_code, $custom_template_tags, null, $GLOBALS['support_commande']);
461 }
462 
470 function send_avis_expedition($commandeid, $delivery_tracking)
471 {
472  $resCom = query("SELECT c.*, sp.technical_code AS statut_paiement
473  FROM peel_commandes c
474  LEFT JOIN peel_statut_paiement sp ON sp.id=c.id_statut_paiement AND " . get_filter_site_cond('statut_paiement', 'sp') . "
475  WHERE c.id='" . intval($commandeid) . "' AND " . get_filter_site_cond('commandes', 'c') . "");
476  $commande = fetch_object($resCom);
477  $order_infos = get_order_infos_array($commande);
478 
479  $custom_template_tags['ORDER_ID'] = $commandeid;
480  $custom_template_tags['TYPE'] = $commande->type;
481  $custom_template_tags['COLIS'] = $delivery_tracking;
482  $custom_template_tags['NOM_FAMILLE'] = $commande->nom_bill;
483  $custom_template_tags['PRENOM'] = $commande->prenom_bill;
484  $custom_template_tags['CLIENT_INFOS_SHIP'] = $order_infos['client_infos_ship'];
485  $custom_template_tags['COUT_TRANSPORT'] = fprix($commande->cout_transport, true) . " " . $GLOBALS['STR_TTC'];
486 
487  $custom_template_tags['SHIPPED_ITEMS'] = '';
488  $product_infos_array = get_product_infos_array_in_order($commandeid, $commande->devise, $commande->currency_rate);
489  foreach ($product_infos_array as $this_ordered_product) {
490  $custom_template_tags['SHIPPED_ITEMS'] .= $this_ordered_product["product_text"] . "\n";
491  $custom_template_tags['SHIPPED_ITEMS'] .= $GLOBALS['STR_QUANTITY'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . $this_ordered_product["quantite"] . "\n";
492  $custom_template_tags['SHIPPED_ITEMS'] .= $GLOBALS['STR_PRICE'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ": " . fprix($this_ordered_product["total_prix"], true) . ' ' . $GLOBALS['STR_TTC'] . "\n\n";
493  }
494  send_email($commande->email, '', '', 'send_avis_expedition', $custom_template_tags, null, $GLOBALS['support_commande']);
495 }
496 
508 function ftp_download($host, $user, $password, $directory, $remote_filename, $local_filename)
509 {
510  if (empty($host) || empty($user)) {
511  return $GLOBALS['STR_FTP_CONNECT_FAILED'];
512  }
513  // FTP Connection
514  $connection = ftp_connect($host, 0, 20);
515  if (!$connection) {
516  return $GLOBALS['STR_FTP_CONNECT_FAILED'];
517  }
518  // FTP login
519  if (!ftp_login($connection, $user, $password)) {
520  return $GLOBALS['STR_FTP_AUTHENTIFICATION_FAILED'];
521  }
522  // FTP Passive mode active (in case of firewall)
523  ftp_pasv($connection, true);
524  // FTP change directory
525  if (!ftp_chdir($connection, $directory)) {
526  return $GLOBALS['STR_FTP_CHDIR_FAILED'];
527  }
528  // Create a file for the compressed file
529  if (!($handle = String::fopen_utf8($GLOBALS['uploaddir'] . '/' . $local_filename, 'wb'))) {
530  return $GLOBALS['STR_FOPEN_FAILED'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ':' . $GLOBALS['uploaddir'] . '/' . $local_filename;
531  }
532  // Get the compressed file in the temporary file
533  if (!ftp_fget($connection, $handle, $remote_filename, FTP_BINARY, 0)) {
534  return $GLOBALS['STR_FTP_GET_FAILED'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ':' . $remote_filename;
535  }
536 
537  fclose($handle);
538  ftp_close($connection);
539 
540  return true;
541 }
542 
550 function file_uncompress($source_filename, $destination_filename)
551 {
552  // Open the compresses file
553  if (!$zp = gzopen($GLOBALS['uploaddir'] . '/' . $source_filename, 'r')) {
554  return $GLOBALS['STR_GZOPEN_FAILED'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ':' . $GLOBALS['uploaddir'] . '/' . $source_filename;
555  }
556  // Open the local file
557  if (!($handle2 = String::fopen_utf8($GLOBALS['uploaddir'] . '/' . $destination_filename, 'wb'))) {
558  return $GLOBALS['STR_FOPEN_FAILED'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ':' . $GLOBALS['uploaddir'] . '/' . $destination_filename;
559  }
560  // read the compress temporary file and write it in an uncompressed one
561  if (!fwrite($handle2, gzread($zp, 9999999))) {
562  return $GLOBALS['STR_FWRITE_FAILED'] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ':' . $GLOBALS['uploaddir'] . '/' . $destination_filename;
563  }
564 
565  fclose($handle2);
566  gzclose($zp);
567 
568  return true;
569 }
570 
578 function get_product_id_by_name($name, $large_search = false)
579 {
580  // Si plusieurs produits existent avec un même nom, on prend celui qui est actif et mis à jour le plus récemment
581  // La collation UTF8 permet de trouver avec = la valeur sans tenir compte des majuscules
582  $sql = 'SELECT id
583  FROM peel_produits
584  WHERE (nom_'.(!empty($GLOBALS['site_parameters']['product_name_forced_lang'])?$GLOBALS['site_parameters']['product_name_forced_lang']:$_SESSION['session_langue']).'="' . nohtml_real_escape_string(trim($name)) . '"' . (trim($name)!=$name ? ' OR nom_'.(!empty($GLOBALS['site_parameters']['product_name_forced_lang'])?$GLOBALS['site_parameters']['product_name_forced_lang']:$_SESSION['session_langue']).'="' . nohtml_real_escape_string(String::strtolower($name)) . '"' : '') . ') AND ' . get_filter_site_cond('produits', null) . '
585  ORDER BY etat DESC, date_maj DESC
586  LIMIT 1';
587  $q = query($sql);
588  if ($result = fetch_assoc($q)) {
589  return $result['id'];
590  } else {
591  if($large_search) {
592  $sql = 'SELECT id
593  FROM peel_produits
594  WHERE nom_'.(!empty($GLOBALS['site_parameters']['product_name_forced_lang'])?$GLOBALS['site_parameters']['product_name_forced_lang']:$_SESSION['session_langue']).' LIKE "%' . nohtml_real_escape_string(String::strtolower(trim($name))) . '%" AND ' . get_filter_site_cond('produits', null) . '
595  ORDER BY IF(nom_'.(!empty($GLOBALS['site_parameters']['product_name_forced_lang'])?$GLOBALS['site_parameters']['product_name_forced_lang']:$_SESSION['session_langue']).' LIKE "' . nohtml_real_escape_string(String::strtolower(trim($name))) . '%",1,0) DESC, etat DESC, date_maj DESC
596  LIMIT 1';
597  $q = query($sql);
598  }
599  if ($result = fetch_assoc($q)) {
600  return $result['id'];
601  } else {
602  return false;
603  }
604  }
605 }
606 
614 function checkUserInfo($array_order_infos, $array_user_infos)
615 {
616  return (($array_user_infos['nom_famille'] == $array_order_infos['nom_bill']) &&
617  ($array_user_infos['prenom'] == $array_order_infos['prenom_bill']) &&
618  ($array_user_infos['code_postal'] == $array_order_infos['zip_bill']) &&
619  ($array_user_infos['ville'] == $array_order_infos['ville_bill']) &&
620  ($array_user_infos['telephone'] == $array_order_infos['telephone_bill']));
621 }
622 
635 function execute_sql($file_path, $max_sql_lines_at_once = 10000, $disable_echo = false, $site_id = 0, $regular_display = 100, $sql = null, $replace_tags = true)
636 {
637  $output = '';
638  // Ce tag est utilisé dans le fichier create_new_site.sql.
639  $custom_template_tags["SITE_ID"] = $site_id;
640  if($max_sql_lines_at_once === null) {
641  $_SESSION['session_sql_output'] = '';
642  if(!empty($file_path)) {
643  $sql .= str_replace("\r\n", "\n", String::file_get_contents_utf8($file_path));
644  }
645  $sql = str_replace("\r", "\n", $sql);
646  // Toutes les lignes comprenant du SQL doivent se finir par ; sans aucun commentaire, sinon ça ne marchera pas
647  while (String::strpos($sql, '; ') !== false) {
648  $sql = str_replace("; ", ";", $sql);
649  }
650  $sql = str_replace(";\r", ";\n", $sql);
651  // On supprime d'abord les commentaires
652  $tab = explode("\n", $sql);
653  $n = count($tab);
654  for ($i = 0; $i < $n; $i++) {
655  if ($tab[$i] == "" || String::substr(trim($tab[$i]), 0, 1) == '#' || String::substr(trim($tab[$i]), 0, 2) == '--') {
656  // Cette ligne est un commentaire
657  unset($tab[$i]);
658  }
659  }
660  $sql = implode("\n", $tab);
661  // On exécute les commandes SQL
662  $tab = explode(";\n", $sql);
663  ob_start();
664  for ($i = 0; $i < count($tab); $i++) {
665  // Remplacement des tags dans la ligne.
666  if($replace_tags) {
667  $tab[$i] = template_tags_replace($tab[$i], $custom_template_tags);
668  }
669  if(String::strpos($tab[$i], 'DELETE') === 0 || String::strpos($tab[$i], 'DROP TABLE') === 0 || (String::strpos($tab[$i], 'ALTER TABLE') === 0 && String::strpos($tab[$i], 'DROP INDEX') !== false && String::strpos($tab[$i], 'ADD INDEX') === false)) {
670  // On veut supprimer un élément, donc si cet élément ne peut pas être supprimé ce n'est probablement pas grave, on ne veut pas de message d'erreur
671  $silent_if_error = true;
672  } else {
673  $silent_if_error = false;
674  }
675  query($tab[$i], false, null, $silent_if_error);
676  }
677  $output .= ob_get_contents();
678  ob_end_clean();
679  $_SESSION['session_sql_output'] .= $output;
680  return $output;
681  } else {
682  // Affichage immédiat
683  // ini_set("zlib.output_compression", 0); // off
684  ob_implicit_flush(true);
685 
686  $handle = String::fopen_utf8($file_path, 'r');
687  if (!empty($_SESSION['session_sql_filepos']) && !isset($_GET['init'])) {
688  // Si la dernière exécution de ce modèle s'est mal terminée : on continue là
689  // où on en était resté
690  fseek($handle, $_SESSION['session_sql_filepos']);
691  $output .= '<p>OK : ' . $_SESSION['session_sql_ok'] . ' - NOK : ' . $_SESSION['session_sql_nok'] . ' - DROP TABLE : ' . $_SESSION['session_sql_drop'] . ' - CREATE TABLE : ' . $_SESSION['session_sql_create'] . '</p>';
692  } else {
693  $_SESSION['session_sql_ok'] = 0;
694  $_SESSION['session_sql_nok'] = 0;
695  $_SESSION['session_sql_create'] = 0;
696  $_SESSION['session_sql_drop'] = 0;
697  $_SESSION['session_sql_output'] = '';
698  }
699  $i = 0;
700  $sql_query='';
701  while (!String::feof($handle) && $i < $max_sql_lines_at_once) {
702  $row = fgets($handle, 4096);
703  $i++;
704  if (String::strlen($row) > 1 && String::strpos(trim($row), '#') !== 0 && String::substr(trim($row), 0, 2) !== '--') {
705  if (String::strpos($row, '; ') !== false || String::strpos($row, ";\r") !== false || String::strpos($row, ";\n") !== false || String::strpos($row, ";\t") !== false) {
706  // Remplacement des tags dans la ligne.
707  if($replace_tags) {
708  $sql_query .= template_tags_replace($row, $custom_template_tags);
709  } else {
710  $sql_query .= $row;
711  }
712  ob_start();
713  $result = query($sql_query);
714  $_SESSION['session_sql_output'] .= ob_get_contents();
715  ob_end_clean();
716 
717  if (!$result) {
718  if (String::strpos($sql_query, 'CREATE TABLE') !== false) {
719  $_SESSION['session_sql_create']++;
720  } elseif (String::strpos($sql_query, 'DROP TABLE') !== false) {
721  $_SESSION['session_sql_drop']++;
722  } else {
723  if (!$disable_echo && empty($no_output)) {
724  echo 'NOT OK : ' . $sql_query . '<br />';
725  }
726  $_SESSION['session_sql_nok']++;
727  }
728  $_SESSION['session_sql_filepos'] = ftell($handle);
729  } else {
730  // On met à jour après l'exécution de la requête
731  // Dans le pire des cas on quitte juste ici => on aura fait une execution de SQL
732  // qui n'aura pas été vue par $_SESSION['session_sql_filepos']
733  $_SESSION['session_sql_filepos'] = ftell($handle);
734  $_SESSION['session_sql_ok']++;
735  }
736  $sql_query = '';
737  } else {
738  $sql_query .= $row;
739  }
740  }
741  if (!$disable_echo && $_SESSION['session_sql_ok'] % $regular_display == 0 && $_SESSION['session_sql_ok'] > 0) {
742  $output .= 'Processing... OK : ' . $_SESSION['session_sql_ok'] . ' SQL position : ' . vn($_SESSION['session_sql_filepos']) . '<br />';
743  if (empty($no_output)) {
744  $_SESSION['session_sql_output'] .= $output;
745  flush();
746  ob_flush();
747  }
748  $output = '';
749  }
750  }
751  if ($_SESSION['session_sql_ok'] % $regular_display != 0) {
752  $output .= 'Processing... OK : ' . $_SESSION['session_sql_ok'] . ' SQL position : ' . vn($_SESSION['session_sql_filepos']) . '<br />';
753  }
754  if (!$disable_echo && empty($no_output)) {
755  $_SESSION['session_sql_output'] .= $output;
756  flush();
757  ob_flush();
758  }
759  fclose($handle);
760  if($i == $max_sql_lines_at_once){
761  $_SESSION['session_sql_output'] .= '<meta http-equiv="refresh" content="1; url=' . get_current_url(false). '?confirm=ok&lines_per_page='.vb($_GET['lines_per_page'], 10000).'"></meta>';
762  } elseif (!$disable_echo) {
763  $_SESSION['session_sql_output'] .= '<div class="alert alert-success">FINISHED</div>';
764  unset($_SESSION['session_sql_filepos']);
765  $_SESSION['session_sql_output'] .= '<p>Affichage des erreurs éventuelles lors de l\'exécution de toutes les pages : '.vb($_SESSION['session_sql_output']).'</p>';
766  }
767  }
768  return vb($_SESSION['session_sql_output']);
769 }
770 
776 function get_data_lang()
777 {
778  $get_options = '';
779  foreach ($_GET as $this_item => $this_value) {
780  if($this_item != 'langue') {
781  $get_options .= '<input type="hidden" name="' . $this_item . '" value="' . String::str_form_value($this_value) . '" />';
782  }
783  }
784  $lang_select = '
785 <form id="langue" method="get" action="' . String::str_form_value(get_current_url(false)) . '" class="entryform form-inline">
786  <div>'.$GLOBALS["STR_ADMIN_LANGUAGE"].$GLOBALS["STR_BEFORE_TWO_POINTS"].':
787  ' . $get_options . '<select name="langue" class="form-control" onchange="document.getElementById(\'langue\').submit()" style="width:200px;">
788  <option value="">' . $GLOBALS['STR_CHOOSE'] . '...</option>
789 ';
790  foreach ($GLOBALS['lang_names'] as $this_lang => $this_lang_name) {
791  $lang_select .= '<option value="' . $this_lang . '" ' . frmvalide($_SESSION['session_langue'] == $this_lang, ' selected="selected"') . '>' . $this_lang_name . '</option>';
792  }
793 
794  $i = 0;
795  $lang_select .= '
796  </select>
797  </div>
798 </form>
799 ';
800  return $lang_select;
801 }
802 
803 
812 {
813  if (!empty($id_codepromo) && !empty($id_utilisateur)) {
814  // on envoi un email à la personne demandée
815  $sql = "SELECT pcp.*, pc.nom_" . $_SESSION['session_langue'] . " AS nom_cat, DATE_FORMAT(date_fin, '%d/%m/%Y') AS date_fin, nombre_prevue, nb_used_per_client
816  FROM peel_codes_promos pcp
817  LEFT JOIN peel_categories pc ON pc.id=pcp.id_categorie AND " . get_filter_site_cond('categories', 'pc') . "
818  WHERE pcp.id = '" . intval($id_codepromo) . "' AND " . get_filter_site_cond('codes_promos', 'pcp') . "";
819  $query = query($sql);
820  $cp = fetch_assoc($query);
821  $la_date = date("Y-m-d");
822 
823  if (!empty($id_utilisateur)) {
824  $remise = get_discount_text($cp['remise_valeur'], $cp['remise_percent'], true);
825  $user_infos = get_user_information($id_utilisateur);
826  $email = $user_infos['email'];
827 
828  $requete = query("SELECT 1
829  FROM peel_utilisateurs_codes_promos
830  WHERE id_utilisateur = '" . intval($id_utilisateur) . "' AND id_code_promo = '" . intval($id_codepromo) . "'");
831  if ((num_rows($requete) == 0) || (num_rows($requete) > 0 && !empty($GLOBALS['site_parameters']['disable_limitation_promotional_code_sending']))) {
832  // si le code n'a pas déjà été associé à l'utilisateur : on veut se souvenir qu'on lui a envoyé
833  // ATTENTION : cette table peel_utilisateurs_codes_promos est pour la gestion commerciale, et n'a pas pour vocation à lister tous les usages de tous les codes promos
834  query("INSERT INTO peel_utilisateurs_codes_promos (id_utilisateur, id_code_promo, nom_code, la_date, utilise, valeur)
835  VALUES ('" . intval($id_utilisateur) . "', '" . intval($cp['id']) . "', '" . nohtml_real_escape_string($cp['nom']) . "', '" . nohtml_real_escape_string($la_date) . "','0', '" . nohtml_real_escape_string($remise) . "')");
836  // on récupère les informations nom prenom civilite et email du client
837  unset($custom_template_tags);
838  $custom_template_tags['CIVILITE'] = $user_infos['civilite'];
839  $custom_template_tags['PRENOM'] = $user_infos['prenom'];
840  $custom_template_tags['NOM_FAMILLE'] = $user_infos['nom_famille'];
841  $custom_template_tags['CIVILITE'] = $user_infos['civilite'];
842  $custom_template_tags['NOM_CODE_PROMO'] = $cp['nom'];
843  $custom_template_tags['REMISE'] = $remise;
844  // On récupère le nombre d'utilisations possibles
845  if ($cp['nb_used_per_client'] > 0 && $cp['nombre_prevue'] > 0) {
846  $nb_used_possible = min($cp['nb_used_per_client'], $cp['nombre_prevue']);
847  } elseif ($cp['nb_used_per_client'] > 0) {
848  $nb_used_possible = $cp['nb_used_per_client'];
849  } elseif ($cp['nb_used_per_client'] > 0) {
850  $nb_used_possible = $cp['nombre_prevue'];
851  } else {
852  $nb_used_possible = '-';
853  }
854  $custom_template_tags['NB_USED_POSSIBLE'] = $nb_used_possible;
855  if (!empty($cp['nom_cat'])) {
856  $custom_template_tags['REMISE'] .= $GLOBALS['STR_ON_CATEGORY'] . ' ' . $cp['nom_cat'];
857  }
858  $custom_template_tags['DATE_FIN'] = $cp['date_fin'];
859  send_email($email, '', '', 'envoie_client_code_promo', $custom_template_tags, null, $GLOBALS['support_sav_client']);
860  return $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS["STR_ADMIN_CODES_PROMOS_MSG_SENT_OK"], $cp['nom'], $user_infos['civilite'] . ' ' . $user_infos['prenom'] . ' ' . $user_infos['nom_famille'], $email)))->fetch();
861  } else {
862  return $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => sprintf($GLOBALS["STR_ADMIN_CODES_PROMOS_ERR_ALREADY_SENT"], $email . ' (' . $user_infos['prenom'] . ' ' . $user_infos['nom_famille'] . ')', $cp['nom'])))->fetch();
863  }
864  }
865  }
866  return false;
867 }
868 
876 {
877  $output = '';
878  $sql_inner = '';
879  $sql_cond = '';
880  $sql = "";
881  if(!empty($frm)) {
882  if (!empty($frm['client_info'])) {
883  $sql_cond .= ' AND (c.email LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"
884  OR u.email LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"
885  OR u.societe LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"
886  OR u.nom_famille LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"
887  OR u.prenom LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"';
888  foreach(array('_bill', '_ship') as $this_item) {
889  $sql_cond .= ' OR c.societe'.$this_item.' LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"';
890  $sql_cond .= ' OR c.email'.$this_item.' LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"';
891  $sql_cond .= ' OR c.nom'.$this_item.' LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"';
892  $sql_cond .= ' OR c.prenom'.$this_item.' LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%"';
893  }
894  $sql_cond .= ')';
895  $sql_inner .= ' INNER JOIN peel_utilisateurs u ON c.id_utilisateur=u.id_utilisateur AND ' . get_filter_site_cond('utilisateurs', 'u') . '';
896  }
897  if (!empty($frm['searchProd'])) {
898  $sql_cond .= ' AND ca.nom_produit LIKE "%' . nohtml_real_escape_string(String::strtolower(trim($frm['searchProd']))) . '%"';
899  $sql_inner .= ' INNER JOIN peel_commandes_articles ca ON ca.commande_id=c.id AND ' . get_filter_site_cond('commandes_articles', 'ca', true);
900  }
901  if (isset($frm['statut_paiement']) && is_numeric($frm['statut_paiement'])) {
902  $sql_cond .= ' AND c.id_statut_paiement="' . nohtml_real_escape_string($frm['statut_paiement']) . '"';
903  }
904  if (isset($frm['statut_livraison']) && is_numeric($frm['statut_livraison'])) {
905  $sql_cond .= ' AND c.id_statut_livraison="' . nohtml_real_escape_string($frm['statut_livraison']) . '"';
906  }
907  if (!empty($frm['id'])) {
908  $sql_cond .= ' AND (c.id="' . intval($frm['id']) . '" OR c.numero="' . nohtml_real_escape_string($frm['id']) . '")';
909  }
910  if (!empty($frm['affi'])) {
911  $sql_cond .= ' AND affilie = "1"';
912  }
913  }
914  $sql = "SELECT c.*
915  FROM peel_commandes c " . $sql_inner . "
916  WHERE " . get_filter_site_cond('commandes', 'c', true) . " " . $sql_cond . "";
917  if(!empty($sql_inner)){
918  $sql .="
919  GROUP BY c.id";
920  }
921  $Links = new Multipage($sql, 'affiche_liste_commandes_admin');
922  $HeaderTitlesArray = array($GLOBALS['STR_ADMIN_ACTION'], 'id' => $GLOBALS['STR_ADMIN_ID'], 'numero' => $GLOBALS["STR_ADMIN_COMMANDER_BILL_NUMBER"], 'o_timestamp' => $GLOBALS['STR_DATE'], 'montant' => $GLOBALS['STR_TOTAL'] . ' ' . (display_prices_with_taxes_in_admin() ? $GLOBALS['STR_TTC'] : $GLOBALS['STR_HT']), $GLOBALS['STR_AVOIR'], 'id_utilisateur' => $GLOBALS['STR_CUSTOMER'], $GLOBALS['STR_PAYMENT'], $GLOBALS['STR_PAYMENT'], 'id_statut_paiement' => $GLOBALS['STR_PAYMENT'], 'id_statut_livraison' => $GLOBALS['STR_DELIVERY'], 'site_id' => $GLOBALS['STR_ADMIN_WEBSITE']);
923  if(!empty($GLOBALS['site_parameters']['admin_order_list_display_delivery_mode_column'])) {
924  $HeaderTitlesArray['type'] = $GLOBALS['STR_ADMIN_MENU_MANAGE_DELIVERY'];
925  }
926  $Links->HeaderTitlesArray = $HeaderTitlesArray;
927  $Links->OrderDefault = vb($GLOBALS['site_parameters']['liste_commandes_admin_order_default'],'o_timestamp');
928  $Links->SortDefault = 'DESC';
929  $results_array = $Links->Query();
930  if (empty($results_array)) {
931  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_NO_RESULT']))->fetch();
932  }
933  // Affichage des commandes en liste
934  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_commande_liste.tpl');
935  $tpl->assign('links_nbRecord', vn($Links->nbRecord));
936  $tpl->assign('action', get_current_url(false));
937  $tpl->assign('id', vb($_GET['id']));
938  $tpl->assign('client_info', vb($_GET['client_info']));
939  $tpl->assign('searchProd', vb($_GET['searchProd']));
940  $tpl->assign('payment_status_options', get_payment_status_options(vb($_GET['statut_paiement'])));
941  $tpl->assign('delivery_status_options', get_delivery_status_options(vb($_GET['statut_livraison'])));
942 
943  $tpl->assign('action2', get_current_url(false) . '?mode=maj_statut');
944  $tpl->assign('form_token', get_form_token_input($_SERVER['PHP_SELF']));
945  $tpl->assign('is_fianet_sac_module_active', check_if_module_active('fianet_sac'));
946  $tpl->assign('is_duplicate_module_active', check_if_module_active('duplicate'));
947  $tpl->assign('is_module_genere_pdf_active', check_if_module_active('facture_advanced', 'administrer/genere_pdf.php'));
948  if (!empty($results_array)) {
949  $tpl_results = array();
950 
951  $tpl->assign('update_src', $GLOBALS['wwwroot_in_admin'] . '/images/update-on.png');
952  $tpl->assign('links_header_row', $Links->getHeaderRow());
953 
954  $i = 0;
955  foreach ($results_array as $order) {
956  $this_sac_status = null;
957  if (check_if_module_active('fianet')) {
958  // Même si la fonction get_sac_status permet de passer un tableau d'id de commande en paramètre, l'appel de la fonction ce fait ici pour des raisons
959  // de simplicité pour le moment. Une amélioration possible est d'appeler la fonction avant le foreach. Il faut pour cela récupérer
960  // les id de commandes du tableau $results_array.
961  $get_sac_status = get_sac_status($order['id'], vb($_POST['fianet_sac_update_status']));
962  $this_sac_status = $get_sac_status[$order['id']];
963  }
964  if ($affiliated_user = get_user_information($order['id_utilisateur'])) {
965  $modifUser = $affiliated_user['civilite'] . ' ' . $affiliated_user['prenom'] . ' ' . $affiliated_user['nom_famille'] . ' <br />' . $affiliated_user['societe'];
966  if(trim(strip_tags($modifUser)) == '') {
967  $modifUser = $order['email'];
968  }
969  $modifUser = (!checkUserInfo($order, $affiliated_user) ? '<img src="' . $GLOBALS['wwwroot_in_admin'] . '/images/update-on.png" alt="update-on.png" />' : '') . '<a href="utilisateurs.php?mode=modif&id_utilisateur=' . $affiliated_user['id_utilisateur'] . '">' . $modifUser . '</a>';
970  } else {
971  $modifUser = $order['prenom_bill'] . ' ' . $order['nom_bill'] . ' ' . $order['societe_bill'];
972  if(trim(strip_tags($modifUser)) == '') {
973  $modifUser = $order['email'];
974  }
975  if (!a_priv('demo') && !empty($order['id_utilisateur'])) {
976  // Si l'utilisateur est avec droits de démo, les utilisateurs admin ne sont pas trouvés, ce qui ne veut pas dire qu'ils sont supprimés
977  $modifUser .= '<br />(supprimé depuis)';
978  }
979  }
981  $montant_displayed = $order['montant'];
982  } else {
983  $montant_displayed = $order['montant_ht'];
984  }
985 
986  $picto_delivery_status_array = array();
987  if (!empty($GLOBALS['site_parameters']['statut_livraison_picto'])) {
988  foreach ($GLOBALS['site_parameters']['statut_livraison_picto'] as $this_status_id => $this_picto) {
989  if ($this_status_id == $order['id_statut_livraison']) {
990  $etat_src = $GLOBALS['administrer_url'] . '/images/' . $this_picto;
991  } else {
992  $etat_src = $GLOBALS['administrer_url'] . '/images/puce-blanche.gif';
993  }
994  $picto_delivery_status_array[$this_status_id] = array("etat_src" => $etat_src, 'etat_onclick' => 'change_status("delivery_status", "' . $order['id'] . '", this, "' . $GLOBALS['administrer_url'] . '", "'. $this_status_id . '")');
995  }
996  }
997  $tpl_array= array('tr_rollover' => tr_rollover($i, true),
998  'id' => $order['id'],
999  'order_id' => $order['order_id'],
1000  'numero' => $order['numero'],
1001  'date' => get_formatted_date($order['o_timestamp']),
1002  'montant_prix' => fprix($montant_displayed, true, $order['devise'], true, $order['currency_rate']),
1003  'avoir_prix' => fprix($order['avoir'], true, $order['devise'], true, $order['currency_rate']),
1004  'modifUser' => $modifUser,
1005  'payment_name' => get_payment_name($order['paiement']),
1006  'payment_status_name' => get_payment_status_name($order['id_statut_paiement']),
1007  'delivery_status_name' => get_delivery_status_name($order['id_statut_livraison']),
1008  'dup_href' => get_current_url(false) . '?mode=duplicate&id=' . $order['id'] . '&page=' . (!empty($_GET['page']) ? $_GET['page'] : 1),
1009  'dup_src' => $GLOBALS['administrer_url'] . '/images/duplicate.png',
1010  'this_sac_status' => $this_sac_status,
1011  'picto_delivery_status_array'=> $picto_delivery_status_array,
1012  'site_name' => get_site_name($order['site_id'])
1013  );
1014  if(!empty($GLOBALS['site_parameters']['admin_order_list_display_delivery_mode_column'])) {
1015  $tpl_array['type'] = $order['type'];
1016  }
1017  $tpl_results[] = $tpl_array;
1018  $i++;
1019  }
1020  $tpl->assign('results', $tpl_results);
1021 
1022  $tpl->assign('payment_status_options2', get_payment_status_options());
1023  $tpl->assign('delivery_status_options2', get_delivery_status_options());
1024  $tpl->assign('links_multipage', $Links->GetMultipage());
1025  }
1026  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
1027  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
1028  $tpl->assign('STR_ADMIN_CHECK_ALL', $GLOBALS['STR_ADMIN_CHECK_ALL']);
1029  $tpl->assign('STR_ADMIN_UNCHECK_ALL', $GLOBALS['STR_ADMIN_UNCHECK_ALL']);
1030  $tpl->assign('STR_ADMIN_COMMANDER_ORDERS_FOUND_COUNT', $GLOBALS['STR_ADMIN_COMMANDER_ORDERS_FOUND_COUNT']);
1031  $tpl->assign('STR_ORDER_NUMBER', $GLOBALS['STR_ORDER_NUMBER']);
1032  $tpl->assign('STR_EMAIL', $GLOBALS['STR_EMAIL']);
1033  $tpl->assign('STR_LAST_NAME', $GLOBALS['STR_LAST_NAME']);
1034  $tpl->assign('STR_FIRST_NAME', $GLOBALS['STR_FIRST_NAME']);
1035  $tpl->assign('STR_ADMIN_COMMANDER_ORDERED_PRODUCT', $GLOBALS['STR_ADMIN_COMMANDER_ORDERED_PRODUCT']);
1036  $tpl->assign('STR_ORDER_STATUT_PAIEMENT', $GLOBALS['STR_ORDER_STATUT_PAIEMENT']);
1037  $tpl->assign('STR_ORDER_STATUT_LIVRAISON', $GLOBALS['STR_ORDER_STATUT_LIVRAISON']);
1038  $tpl->assign('STR_ADMIN_ALL_ORDERS', $GLOBALS['STR_ADMIN_ALL_ORDERS']);
1039  $tpl->assign('STR_SEARCH', $GLOBALS['STR_SEARCH']);
1040  $tpl->assign('STR_ADMIN_COMMANDER_FIANET_UPDATE', $GLOBALS['STR_ADMIN_COMMANDER_FIANET_UPDATE']);
1041  $tpl->assign('STR_ADMIN_ORDER_DUPLICATE', $GLOBALS['STR_ADMIN_ORDER_DUPLICATE']);
1042  $tpl->assign('STR_ADMIN_ORDER_DUPLICATE_WARNING', $GLOBALS['STR_ADMIN_ORDER_DUPLICATE_WARNING']);
1043  $tpl->assign('STR_ADMIN_COMMANDER_CLIENT_UPDATED_ICON_EXPLAIN', $GLOBALS['STR_ADMIN_COMMANDER_CLIENT_UPDATED_ICON_EXPLAIN']);
1044  $tpl->assign('STR_MODIFY', $GLOBALS['STR_MODIFY']);
1045  $tpl->assign('STR_ADMIN_CHECK_ALL', $GLOBALS['STR_ADMIN_CHECK_ALL']);
1046  $tpl->assign('STR_ADMIN_UNCHECK_ALL', $GLOBALS['STR_ADMIN_UNCHECK_ALL']);
1047  $tpl->assign('STR_ADMIN_COMMANDER_UPDATED_STATUS_FOR_SELECTION', $GLOBALS['STR_ADMIN_COMMANDER_UPDATED_STATUS_FOR_SELECTION']);
1048  $tpl->assign('STR_ADMIN_COMMANDER_NO_ORDER_FOUND', $GLOBALS['STR_ADMIN_COMMANDER_NO_ORDER_FOUND']);
1049  $tpl->assign('STR_NOTA_BENE', $GLOBALS['STR_NOTA_BENE']);
1050  $tpl->assign('STR_MODULE_FACTURES_ADMIN_TITLE', $GLOBALS['STR_MODULE_FACTURES_ADMIN_TITLE']);
1051  $output .= $tpl->fetch();
1052  return $output;
1053 }
1054 
1063 function affiche_details_commande($id, $action, $user_id = 0)
1064 {
1065  if(!empty($id)){
1066  $qid_commande = query("SELECT *
1067  FROM peel_commandes
1068  WHERE " . get_filter_site_cond('commandes', null, true) . " AND id = '" . intval($id) . "'");
1069  $commande = fetch_assoc($qid_commande);
1070  }
1071  if (!empty($commande) || $action == 'insere' || $action == 'ajout') {
1072  // Si nous somme en mode modif, alors on cherche les details de la commande
1073  if ($action != 'insere' && $action != 'ajout') {
1074  $date_facture = get_formatted_date(vb($commande['a_timestamp']));
1075  // f_datetime est la date d'émission de la facture, insérée dans la BDD automatiquement au moment de l'insertion du numéro de facture, sinon par l'administrateur en back office.
1076  $f_datetime = get_formatted_date(vb($commande['f_datetime']));
1077  // e_datetime est la date d'expédition de la commande, insérée dans la BDD automatiquement au moment du changement du statut de livraison de la facture, sinon par l'administrateur en back office.
1078  $e_datetime = get_formatted_date(vb($commande['e_datetime']));
1079 
1081  $montant_displayed = $commande['montant'];
1082  } else {
1083  $montant_displayed = $commande['montant_ht'];
1084  }
1085  } else {
1086  // $date_facture = Date du jour
1087  $date_facture = get_formatted_date(time());
1088  $montant_displayed = 0;
1089  }
1090  // Affiche le modeles d'une commande en detail
1091  $is_order_modification_allowed = is_order_modification_allowed(vb($commande['o_timestamp']));
1092 
1093  if (!empty($user_id)) {
1094  // Dans le cas où on crée une commande, on initialise à partir des données de l'utilisateur. Sinon on recupère les informations de l'utilsateur par la commande
1095  $user_array = get_user_information($user_id);
1096  // Répétition pour les différente adresse de l'utilisateur
1097  for($i = 0;$i < 2;$i++) {
1098  if ($i == 0) {
1099  $state = 'bill';
1100  } else {
1101  $state = 'ship';
1102  }
1103  $commande['societe_' . $state] = vb($user_array['societe']);
1104  $commande['nom_' . $state] = vb($user_array['nom_famille']);
1105  $commande['prenom_' . $state] = vb($user_array['prenom']);
1106  $commande['email_' . $state] = vb($user_array['email']);
1107  $commande['telephone_' . $state] = vb($user_array['telephone']);
1108  $commande['adresse_' . $state] = vb($user_array['adresse']);
1109  $commande['zip_' . $state] = vb($user_array['code_postal']);
1110  $commande['ville_' . $state] = vb($user_array['ville']);
1111  $commande['pays_' . $state] = get_country_name(vn($user_array['pays']));
1112  if (!empty($GLOBALS['site_parameters']['user_specific_field_titles'])) {
1113  $user_table_fields_names = get_table_field_names('peel_utilisateurs');
1114  $order_table_fields_names = get_table_field_names('peel_commandes');
1115  foreach($GLOBALS['site_parameters']['user_specific_field_titles'] as $this_field => $this_title) {
1116  if (((String::substr($this_field, -5) == '_bill') || (String::substr($this_field, -5) == '_ship')) && in_array($this_field, $user_table_fields_names) && in_array($this_field, $order_table_fields_names)) {
1117  // On a ajouté dans la table utilisateurs un champ qui concerne l'adresse de livraison ou de facturation => Il faut préremplir les champs du formulaire d'adresse avec ces infos.
1118  $commande[$this_field] = vb($user_array[$this_field]);
1119  }
1120  }
1121  }
1122  }
1123  $commande['id_utilisateur'] = vn($user_id);
1124  $commande['intracom_for_billing'] = vb($user_array['intracom_for_billing']);
1125  // La TVA est-elle applicable pour cet utilisateur ?
1126  // D'abord on regarde si la zone de l'utilisateur est concernée par l'application de la TVA
1127  $sqlPays = 'SELECT p.id, p.pays_' . $_SESSION['session_langue'] . ' as pays, p.zone, z.tva, z.on_franco
1128  FROM peel_pays p
1129  LEFT JOIN peel_zones z ON z.id=p.zone AND ' . get_filter_site_cond('zones', 'z') . '
1130  WHERE p.etat = "1" AND p.id ="' . nohtml_real_escape_string($user_array['pays']) . '" AND ' . get_filter_site_cond('pays', 'p') . '
1131  LIMIT 1';
1132  $query = query($sqlPays);
1133  if ($result = fetch_assoc($query)) {
1134  $user_vat = $result['tva'];
1135  } else {
1136  $user_vat = 1;
1137  }
1138  // Ensuite on vérifie que l'utilisateur n'a pas rentré un n° de TVA intracom qui l'exonèrerait, et que la boutique n'est pas en statut micro entreprise
1139  $commande['zone_tva'] = ($user_vat && !is_user_tva_intracom_for_no_vat($user_id) && !check_if_module_active('micro_entreprise'));
1140  } elseif (!empty($id)) {
1141  $commande['payment_technical_code'] = vb($commande['paiement']);
1142  if (strpos($commande['paiement'], ' ') !== false) {
1143  // ADAPTATION POUR TABLES ANCIENNES avec paiement qui contient nom et pas technical_code
1144  $sql = 'SELECT technical_code
1145  FROM peel_paiement
1146  WHERE nom_' . $_SESSION['session_langue'] . '="' . nohtml_real_escape_string($commande['paiement']) . '" AND ' . get_filter_site_cond('paiement') . '
1147  LIMIT 1';
1148  $query = query($sql);
1149  if ($result = fetch_assoc($query)) {
1150  $commande['payment_technical_code'] = $result['technical_code'];
1151  }
1152  }
1153  if ($commande['cout_transport_ht'] > 0) {
1154  $commande['tva_transport'] = vn(round(($commande['tva_cout_transport'] / $commande['cout_transport_ht'] * 100), 2));
1155  } else {
1156  $commande['tva_transport'] = null;
1157  }
1158  } else {
1159  // Nouvelle commande : valeurs par défaut
1160  $commande['pays_bill'] = get_country_name(vn($GLOBALS['site_parameters']['default_country_id']));
1161  $commande['pays_ship'] = get_country_name(vn($GLOBALS['site_parameters']['default_country_id']));
1162  $commande['zone_tva'] = 1;
1163  }
1164  if (!empty($commande['numero'])) {
1165  // On reprend le numéro de la BDD, et on va pouvoir l'éditer si on veut
1166  $numero = $commande['numero'];
1167  } elseif (!empty($GLOBALS['site_parameters']['admin_fill_empty_bill_number_by_number_format'])) {
1168  $numero = vb($GLOBALS['site_parameters']['format_numero_facture']);
1169  } else {
1170  $numero = null;
1171  }
1172  if (empty($commande['devise'])) {
1173  $commande['devise'] = $GLOBALS['site_parameters']['code'];
1174  }
1175  if (!empty($commande['zone_tva'])) {
1176  $default_vat = get_default_vat();
1177  } else {
1178  // pas de TVA
1179  $default_vat = 0;
1180  }
1181  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_commande_details.tpl');
1182  $tpl->assign('action_name', $action);
1183  $tpl->assign('id', vn($id));
1184  $tpl->assign('order_id', vn($commande['order_id']));
1185  $tpl->assign('site_id_select_options', get_site_id_select_options(vb($commande['site_id']), null, null, true));
1186  $tpl->assign('site_id_select_multiple', !empty($GLOBALS['site_parameters']['multisite_using_array_for_site_id']));
1187  $tpl->assign('internal_order_enable', vn($GLOBALS['site_parameters']['internal_order_enable']));
1188  $tpl->assign('is_order_modification_allowed', $is_order_modification_allowed);
1189 
1190  $tpl->assign('pdf_src', $GLOBALS['wwwroot_in_admin'] . '/images/view_pdf.gif');
1191  if ($action != "insere" && $action != "ajout") {
1192  $tpl->assign('allow_display_invoice_link', !empty($commande['numero']));
1193  $tpl->assign('facture_pdf_href', get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . vb($commande['code_facture']) . '&mode=facture');
1194  $tpl->assign('sendfacture_pdf_href', $GLOBALS['administrer_url'] . '/commander.php?mode=sendfacturepdf&id=' . vn($commande['id']) . '&code_facture=' . vb($commande['code_facture']) . '&bill_type=facture');
1195  $tpl->assign('proforma_pdf_href', get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . vb($commande['code_facture']) . '&mode=proforma');
1196  $tpl->assign('sendproforma_pdf_href', $GLOBALS['administrer_url'] . '/commander.php?mode=sendfacturepdf&id=' . vn($commande['id']) . '&code_facture=' . vb($commande['code_facture']) . '&bill_type=proforma');
1197  $tpl->assign('devis_pdf_href', get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . vb($commande['code_facture']) . '&mode=devis');
1198  $tpl->assign('senddevis_pdf_href', $GLOBALS['administrer_url'] . '/commander.php?mode=sendfacturepdf&id=' . vn($commande['id']) . '&code_facture=' . vb($commande['code_facture']) . '&bill_type=devis');
1199  $tpl->assign('bdc_pdf_href', get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . vb($commande['code_facture']) . '&mode=bdc');
1200  $tpl->assign('duplicate', get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . vb($commande['code_facture']) . '&mode=bdc');
1201  $tpl->assign('bdc_pdf_href', get_site_wwwroot($commande['site_id']) . '/factures/commande_pdf.php?code_facture=' . vb($commande['code_facture']) . '&mode=bdc');
1202 
1203  $tpl->assign('is_duplicate_module_active', check_if_module_active('duplicate'));
1204  $tpl->assign('dup_href', get_current_url(false) . '?mode=duplicate&id=' . $commande['id']);
1205  $tpl->assign('dup_src', $GLOBALS['administrer_url'] . '/images/duplicate.png');
1206  $tpl->assign('STR_ADMIN_ORDER_DUPLICATE', $GLOBALS['STR_ADMIN_ORDER_DUPLICATE']);
1207  $tpl->assign('STR_ADMIN_ORDER_DUPLICATE_WARNING', $GLOBALS['STR_ADMIN_ORDER_DUPLICATE_WARNING']);
1208 
1209  $tpl->assign('is_module_factures_html_active', check_if_module_active('factures', 'commande_html.php'));
1210  if (check_if_module_active('factures', 'commande_html.php')) {
1211  $tpl->assign('facture_html_href', get_site_wwwroot($commande['site_id']) . '/modules/factures/commande_html.php?code_facture=' . vb($commande['code_facture']) . '&mode=facture');
1212  $tpl->assign('bdc_action', $GLOBALS['administrer_url'] . '/commander.php?mode=modif&commandeid=' . vn($commande['id']));
1213  $tpl->assign('bdc_code_facture', vb($commande['code_facture']));
1214  $tpl->assign('bdc_id', vn($commande['id']));
1215  $tpl->assign('bdc_partial', fprix(vn($commande['montant']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false, false, null, false, true));
1216  $tpl->assign('bdc_devise', vb($commande['devise']));
1217  $tpl->assign('partial_amount_link_js', get_site_wwwroot($commande['site_id']) . '/modules/factures/commande_html.php?currency_rate=' . vn($commande['currency_rate']) . '&code_facture=' . vb($commande['code_facture']) . '&mode=bdc&partial=');
1218  $tpl->assign('partial_amount_link_href', get_site_wwwroot($commande['site_id']) . '/modules/factures/commande_html.php?code_facture=' . vb($commande['code_facture']) . '&mode=bdc&partial=' .get_float_from_user_input(fprix(vn($commande['montant']), false, $GLOBALS['site_parameters']['code'], false, $commande['currency_rate'], false, false)));
1219  $tpl->assign('partial_amount_link_target', 'facture' . $commande['code_facture']);
1220  }
1221  if (check_if_module_active('tnt')) {
1222  $q_type = query('SELECT *
1223  FROM peel_types
1224  WHERE is_tnt="1" AND ' . get_filter_site_cond('types') . ' AND nom_' . $commande['lang'] . ' = "' . nohtml_real_escape_string($commande['type']) . '"');
1225  $result = fetch_assoc($q_type);
1226  if (!empty($result)) {
1227  $tpl->assign('etiquette_tnt', '<b>ETIQUETTE TNT : </b><a target="_blank" href="' . $GLOBALS['wwwroot'] . '/modules/tnt/administrer/etiquette.php?order_id='.$commande['id'] .'">Imprimer l\'étiquette tnt (ouvre une nouvelle fenêtre)</a>');
1228  }
1229  }
1230  $tpl->assign('action', get_current_url(false) . '?mode=modif&commandeid=' . vn($id));
1231  $tpl->assign('date_facture', (empty($date_facture) ? "" : vb($date_facture)));
1232  $tpl->assign('e_datetime', (empty($e_datetime) ? "" : vb($e_datetime)));
1233  $tpl->assign('f_datetime', (empty($f_datetime) ? "" : vb($f_datetime)));
1234  $tpl->assign('intracom_for_billing', vb($commande['intracom_for_billing']));
1235  $tpl->assign('commande_date', get_formatted_date(vb($commande['o_timestamp'])));
1236  $tpl->assign('email_href', $GLOBALS['administrer_url'] . '/utilisateurs.php?mode=modif&id_utilisateur=' . vn($commande['id_utilisateur']));
1237  $tpl->assign('email', vb($commande['email']));
1238  } else {
1239  $tpl->assign('action', get_current_url(false) . '?mode=modif&commandeid=' . vn($id));
1240  }
1241 
1242  $tpl->assign('numero', $numero);
1243  $tpl->assign('delivery_tracking', vb($commande['delivery_tracking']));
1244  $tpl->assign('is_icirelais_module_active', check_if_module_active('icirelais'));
1245  $tpl->assign('delivery_locationid', vb($commande['delivery_locationid']));
1246  $tpl->assign('is_tnt_module_active', check_if_module_active('tnt'));
1247  if (check_if_module_active('icirelais')) {
1248  $tpl->assign('icirelais', array(
1249  'src' => get_url('/modules/icirelais/js/icirelais.js'),
1250  'value' => vb($commande['delivery_tracking'])
1251  ));
1252  $tpl->assign('STR_MODULE_ICIRELAIS_CONFIGURATION_TRACKING_URL_TITLE', $GLOBALS['STR_MODULE_ICIRELAIS_CONFIGURATION_TRACKING_URL_TITLE']);
1253  $tpl->assign('MODULE_ICIRELAIS_SETUP_TRACKING_URL', MODULE_ICIRELAIS_SETUP_TRACKING_URL);
1254  $tpl->assign('STR_MODULE_ICIRELAIS_COMMENT_TRACKING', $GLOBALS['STR_MODULE_ICIRELAIS_COMMENT_TRACKING']);
1255  $tpl->assign('STR_MODULE_ICIRELAIS_ERROR_TRACKING', $GLOBALS['STR_MODULE_ICIRELAIS_ERROR_TRACKING']);
1256  $tpl->assign('STR_MODULE_ICIRELAIS_CREATE_TRACKING', $GLOBALS['STR_MODULE_ICIRELAIS_CREATE_TRACKING']);
1257  }
1258 
1259  if((!empty($id) && $commande['montant'] > 0) || empty($id)) {
1260  $tpl->assign('payment_select', get_payment_select(vb($commande['payment_technical_code']), false, true));
1261  }
1262 
1263  $tpl->assign('payment_status_options', get_payment_status_options(vn($commande['id_statut_paiement'])));
1264  $tpl->assign('delivery_status_options', get_delivery_status_options(vn($commande['id_statut_livraison'])));
1265 
1266  $tpl->assign('devise', vb($commande['devise']));
1267  $tpl->assign('mode_transport', vn($GLOBALS['site_parameters']['mode_transport']));
1268  if (!empty($GLOBALS['site_parameters']['mode_transport'])) {
1269  $tpl->assign('delivery_type_options', get_delivery_type_options(vb($commande['type'])));
1270  $tpl->assign('vat_select_options', get_vat_select_options(vb($commande['tva_transport']), true));
1271  } else {
1272  $tpl->assign('tva_transport', vb($commande['tva_transport']));
1273  $tpl->assign('type_transport', vb($commande['type_transport']));
1274  }
1275  if(isset($commande['cout_transport'])) {
1276  // Test sur if isset pour ne pas afficher une valeur dans le champ lors de la création d'une commmande.
1277  // => ça force le calcul automatique des frais de port
1278  $tpl->assign('cout_transport', fprix(vn($commande['cout_transport']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false));
1279  } else {
1280  $tpl->assign('cout_transport', '');
1281  }
1282  $tpl->assign('tva_transport', fprix(vn($commande['tva_transport']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false));
1283  $tpl->assign('transport', vb($commande['transport']));
1284 
1285  $tpl->assign('is_devises_module_active', check_if_module_active('devises'));
1286  if (check_if_module_active('devises')) {
1287  $tpl_devises_options = array();
1288  $res_devise = query("SELECT p.code
1289  FROM peel_devises p
1290  WHERE etat='1' AND " . get_filter_site_cond('devises', 'p') . "");
1291  while ($tab_devise = fetch_assoc($res_devise)) {
1292  $tpl_devises_options[] = array('value' => $tab_devise['code'],
1293  'issel' => $tab_devise['code'] == vb($commande['devise']),
1294  'name' => $tab_devise['code']
1295  );
1296  }
1297  $tpl->assign('devises_options', $tpl_devises_options);
1298  }
1299 
1300  $tpl->assign('small_order_overcost_amount', fprix(vn($commande['small_order_overcost_amount']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false));
1301  $tpl->assign('tva_small_order_overcost', fprix(vn($commande['tva_small_order_overcost']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false));
1302  $tpl->assign('site_symbole', $GLOBALS['site_parameters']['symbole']);
1303  $tpl->assign('currency_rate', vn($commande['currency_rate']));
1304  $tpl->assign('montant_displayed_prix', fprix($montant_displayed, true, vb($commande['devise']), true, vn($commande['currency_rate'])));
1305  $tpl->assign('ttc_ht', (display_prices_with_taxes_in_admin() ? $GLOBALS['STR_TTC'] : $GLOBALS['STR_HT']));
1306 
1307  if (!empty($commande['total_remise']) && $commande['total_remise'] > 0) {
1308  $tpl->assign('total_remise_prix', fprix((display_prices_with_taxes_in_admin()?$commande['total_remise']:$commande['total_remise_ht']), true, vb($commande['devise']), true, vn($commande['currency_rate'])));
1309  }
1310  $tpl->assign('avoir_prix', fprix(vn($commande['avoir']), false, vb($commande['devise']), true, vn($commande['currency_rate'])));
1311 
1312  if (!empty($commande['affilie']) && $commande['affilie'] == 1) {
1313  $affiliated_user = get_user_information($commande['id_affilie']);
1314  $tpl->assign('is_affilie', true);
1315  $tpl->assign('affilie_prix', fprix($commande['montant_affilie'], true, vb($commande['devise']), true, vn($commande['currency_rate'])));
1316  $tpl->assign('statut_affilie', $commande['statut_affilie']);
1317  $tpl->assign('affilie_href', $GLOBALS['administrer_url'] . '/utilisateurs.php?mode=modif&id_utilisateur=' . $affiliated_user['id_utilisateur']);
1318  $tpl->assign('affilie_email', $affiliated_user['email']);
1319  } else {
1320  $tpl->assign('is_affilie', false);
1321  }
1322 
1323 
1324  $tpl->assign('is_gifts_module_active', check_if_module_active('gifts'));
1325  if (check_if_module_active('gifts')) {
1326  $tpl->assign('total_points', vn($commande['total_points']));
1327  $tpl->assign('points_etat', vn($commande['points_etat']));
1328  }
1329  $tpl->assign('commande_interne', vb($commande['commande_interne']));
1330  $tpl->assign('commentaires', vb($commande['commentaires']));
1331  $tpl->assign('commentaires_admin', vb($commande['commentaires_admin']));
1332  $tpl->assign('specific_fields', get_specific_field_infos($commande, null, 'order'));
1333 
1334  $tpl_client_infos = array();
1335  for ($i = 1; $i < 3; $i++) {
1336  if ($i == 1) {
1337  $value = 'bill';
1338  } else {
1339  $value = 'ship';
1340  }
1341  $tpl_client_infos[] = array('value' => $value,
1342  'i' => $i,
1343  'societe' => vb($commande['societe_' . $value]),
1344  'nom' => vb($commande['nom_' . $value]),
1345  'prenom' => vb($commande['prenom_' . $value]),
1346  'email' => vb($commande['email_' . $value]),
1347  'telephone' => vb($commande['telephone_' . $value]),
1348  'adresse' => vb($commande['adresse_' . $value]),
1349  'zip' => vb($commande['zip_' . $value]),
1350  'ville' => vb($commande['ville_' . $value]),
1351  'country_select_options' => get_country_select_options(vb($commande['pays_' . $value]), null, 'name', false, null, true, vb($commande['lang']))
1352  );
1353  }
1354  $tpl->assign('client_infos', $tpl_client_infos);
1355 
1356  $tpl_order_lines = array();
1357  if (!empty($id)) {
1358  if(!empty($GLOBALS['site_parameters']['order_article_order_by']) && $GLOBALS['site_parameters']['order_article_order_by'] == 'name') {
1359  $order_by = 'oi.nom_produit ASC';
1360  } elseif(!empty($GLOBALS['site_parameters']['order_article_order_by']) && $GLOBALS['site_parameters']['order_article_order_by'] == 'reference') {
1361  $order_by = 'oi.reference ASC';
1362  } else {
1363  $order_by = 'oi.id ASC';
1364  }
1365  $sql = "SELECT
1366  oi.reference AS ref
1367  , oi.nom_produit AS nom
1368  , oi.prix AS purchase_prix
1369  , oi.prix_ht AS purchase_prix_ht
1370  , oi.prix_cat
1371  , oi.prix_cat_ht
1372  , oi.quantite
1373  , oi.tva
1374  , oi.tva_percent
1375  , oi.produit_id AS id
1376  , oi.nom_attribut
1377  , oi.total_prix_attribut
1378  , oi.couleur
1379  , oi.taille
1380  , oi.couleur_id
1381  , oi.taille_id
1382  , oi.remise
1383  , oi.remise_ht
1384  , oi.percent_remise_produit AS percent
1385  , oi.on_download ";
1386  if( check_if_module_active('listecadeau') ) {
1387  $sql .= ", oi.listcadeaux_owner ";
1388  }
1389  if( check_if_module_active('tnt') ) {
1390  $sql .= ", oi.tnt_parcel_number ";
1391  }
1392  $sql .= "FROM peel_commandes_articles oi
1393  WHERE commande_id = '" . intval($id) . "' AND " . get_filter_site_cond('commandes_articles', 'oi', true) . "
1394  ORDER BY ".$order_by;
1395  $result_requete = query($sql);
1396  $nb_produits = num_rows($result_requete);
1397  } else {
1398  $nb_produits = 0;
1399  }
1400  $i = 1;
1401  if (!empty($result_requete)) {
1402  while ($line_data = fetch_assoc($result_requete)) {
1403  $product_object = new Product($line_data['id'], null, false, null, true, !check_if_module_active('micro_entreprise'));
1404  // Code pour recupérer select des tailles
1405  $possible_sizes = $product_object->get_possible_sizes();
1406  // traitement particulier pour le prix. L'utilisation de la fonction vb() n'est pas approprié car il faut permettre l'insertion de produit au montant égal à zero (pour offir.)
1407  $line_data['image'] = $product_object->get_product_main_picture();
1408  $line_data['image_thumbs'] = String::str_form_value($GLOBALS['repertoire_upload'].'/thumbs/'.thumbs($product_object->get_product_main_picture(),50,50));
1409  $line_data['prix_cat'] = round($line_data['prix_cat'] * vn($commande['currency_rate']), 5);
1410  $line_data['prix_cat_ht'] = round($line_data['prix_cat_ht'] * vn($commande['currency_rate']), 5);
1411  $line_data['purchase_prix'] = round($line_data['purchase_prix'] * vn($commande['currency_rate']), 5);
1412  $line_data['purchase_prix_ht'] = round($line_data['purchase_prix_ht'] * vn($commande['currency_rate']), 5);
1413  $line_data['remise'] = round($line_data['remise'] * vn($commande['currency_rate']), 5);
1414  $line_data['remise_ht'] = round($line_data['remise_ht'] * vn($commande['currency_rate']), 5);
1415  if (!empty($line_data['taille']) && !in_array($line_data['taille'], $possible_sizes)) {
1416  $possible_sizes[$line_data['taille_id']] = $line_data['taille'];
1417  }
1418  $size_options_html = '';
1419  if (!empty($possible_sizes)) {
1420  foreach ($possible_sizes as $this_size_id => $this_size_name) {
1421  $size_options_html .= '<option value="' . intval($this_size_id) . '" ' . frmvalide($this_size_name == $line_data['taille'], ' selected="selected"') . '>' . $this_size_name . '</option>';
1422  }
1423  }
1424  $possible_colors = $product_object->get_possible_colors();
1425  if (!empty($line_data['couleur']) && !in_array($line_data['couleur'], $possible_colors)) {
1426  $possible_colors[$line_data['couleur_id']] = $line_data['couleur'];
1427  }
1428  $color_options_html = '';
1429  if (!empty($possible_colors)) {
1430  foreach ($possible_colors as $this_color_id => $this_color_name) {
1431  $color_options_html .= '<option value="' . intval($this_color_id) . '" ' . frmvalide($this_color_name == $line_data['couleur'], ' selected="selected"') . '>' . $this_color_name . '</option>';
1432  }
1433  }
1434  $tva_options_html = get_vat_select_options($line_data['tva_percent']);
1435  // print_r($line_data); die();
1436  $tpl_order_lines[] = get_order_line($line_data, $color_options_html, $size_options_html, $tva_options_html, $i);
1437  $i++;
1438  unset($product_object);
1439  }
1440  }
1441  $tpl->assign('order_lines', $tpl_order_lines);
1442 
1443  $tpl->assign('avoir', fprix(vn($commande['avoir']), false, vb($commande['devise']), true, vn($commande['currency_rate']), false));
1444  $tpl->assign('lang', vb($commande['lang']));
1445  $tpl->assign('code_promo', vb($commande['code_promo']));
1446  $tpl->assign('percent_code_promo', vn($commande['percent_code_promo']));
1447  $tpl->assign('valeur_code_promo', vn($commande['valeur_code_promo']));
1448 
1449  $tpl->assign('form_token', get_form_token_input('commander.php?mode=' . $action . '&commandeid=' . $id));
1450  $tpl->assign('id_utilisateur', vb($commande['id_utilisateur']));
1451  $tpl->assign('nb_produits', $nb_produits);
1452 
1453  $tpl->assign('get_mode', $_GET['mode']);
1454 
1455  $GLOBALS['js_content_array'][] = "new_order_line_html='".filtre_javascript(get_order_line(array('id' => '[id]', 'ref' => '[ref]', 'nom' => '[nom]', 'image_thumbs' => '[image_thumbs]', 'image' => '[image]', 'quantite' => '[quantite]', 'remise' => '[remise]', 'remise_ht' => '[remise_ht]', 'percent' => '[percent]', 'purchase_prix' => '[purchase_prix]', 'purchase_prix_ht' => '[purchase_prix_ht]', 'tva_percent' => '[tva_percent]', 'prix_cat' => '[prix_cat]', 'prix_cat_ht' => '[prix_cat_ht]'), '[color_options_html]', '[size_options_html]', '[tva_options_html]', '[i]'), true, true, false, true, false)."';";
1456 
1457  $tpl->assign('site_avoir', $GLOBALS['site_parameters']['avoir']);
1458  if (check_if_module_active('parrainage')) {
1459  // Si le client a été parrainé
1460  if (vb($commande['parrain']) == "parrain") {
1461  $Client = get_user_information($commande['id_parrain']);
1462  $tpl->assign('parrainage_form', array('action' => get_current_url(false),
1463  'id' => intval($commande['id']),
1464  'id_parrain' => intval($commande['id_parrain']),
1465  'email' => $Client['email'],
1466  'href' => $GLOBALS['administrer_url'] . '/utilisateurs.php?mode=modif&id_utilisateur=' . $commande['id_parrain']
1467  ));
1468  }
1469  }
1470  $tpl->assign('is_fianet_sac_module_active', check_if_module_active('fianet_sac'));
1471  if(check_if_module_active('fianet_sac')) {
1472  require_once($GLOBALS['fonctionsfianet_sac']);
1473  $tpl->assign('fianet_analyse_commandes', get_sac_order_link($id));
1474  }
1475  $tpl->assign('is_order_modification_allowed', $is_order_modification_allowed);
1476  $tpl->assign('zone_tva', vb($commande['zone_tva']));
1477  $tpl->assign('default_vat_select_options', get_vat_select_options($default_vat));
1478  $tpl->assign('STR_IMAGE', $GLOBALS['STR_IMAGE']);
1479  $tpl->assign('STR_ADMIN_TECHNICAL_ORDER_NUMBER', $GLOBALS['STR_ADMIN_TECHNICAL_ORDER_NUMBER']);
1480  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
1481  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
1482  $tpl->assign('STR_ADMIN_AUTOCOMPLETE_ORDER_ADRESSES', $GLOBALS['STR_ADMIN_AUTOCOMPLETE_ORDER_ADRESSES']);
1483  $tpl->assign('STR_ADMIN_COMMANDER_WARNING_EDITION_NOT_ALLOWED', $GLOBALS['STR_ADMIN_COMMANDER_WARNING_EDITION_NOT_ALLOWED']);
1484  $tpl->assign('STR_ADMIN_COMMANDER_CREATE_OR_UPDATE_TITLE', $GLOBALS['STR_ADMIN_COMMANDER_CREATE_OR_UPDATE_TITLE']);
1485  $tpl->assign('STR_INVOICE', $GLOBALS['STR_INVOICE']);
1486  $tpl->assign('STR_ADMIN_CREATE_BILL_NUMBER_BEFORE', $GLOBALS['STR_ADMIN_CREATE_BILL_NUMBER_BEFORE']);
1487  $tpl->assign('STR_PROFORMA', $GLOBALS['STR_PROFORMA']);
1488  $tpl->assign('STR_QUOTATION', $GLOBALS['STR_QUOTATION']);
1489  $tpl->assign('STR_ORDER_FORM', $GLOBALS['STR_ORDER_FORM']);
1490  $tpl->assign('STR_ADMIN_SEND_TO_CLIENT_BY_EMAIL', $GLOBALS['STR_ADMIN_SEND_TO_CLIENT_BY_EMAIL']);
1491  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
1492  $tpl->assign('STR_BY', $GLOBALS['STR_BY']);
1493  $tpl->assign('STR_ORDER_STATUT_PAIEMENT', $GLOBALS['STR_ORDER_STATUT_PAIEMENT']);
1494  $tpl->assign('STR_ORDER_STATUT_LIVRAISON', $GLOBALS['STR_ORDER_STATUT_LIVRAISON']);
1495  $tpl->assign('STR_TTC', $GLOBALS['STR_TTC']);
1496  $tpl->assign('STR_ADMIN_INCLUDING_VAT', $GLOBALS['STR_ADMIN_INCLUDING_VAT']);
1497  $tpl->assign('STR_ADMIN_USED_CURRENCY', $GLOBALS['STR_ADMIN_USED_CURRENCY']);
1498  $tpl->assign('STR_ADMIN_COMMENTS', $GLOBALS['STR_ADMIN_COMMENTS']);
1499  $tpl->assign('STR_COMMENTS', $GLOBALS['STR_COMMENTS']);
1500  $tpl->assign('STR_REFERENCE_IF_KNOWN', $GLOBALS['STR_REFERENCE_IF_KNOWN']);
1501  $tpl->assign('STR_ADMIN_COMMANDER_OR_ADD_PRODUCT_WITH_FAST_SEARCH', $GLOBALS['STR_ADMIN_COMMANDER_OR_ADD_PRODUCT_WITH_FAST_SEARCH']);
1502  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
1503  $tpl->assign('STR_ADMIN_ADD_EMPTY_LINE', $GLOBALS['STR_ADMIN_ADD_EMPTY_LINE']);
1504  $tpl->assign('STR_PAYMENT_MEAN', $GLOBALS['STR_PAYMENT_MEAN']);
1505  $tpl->assign('STR_SHIPPING_TYPE', $GLOBALS['STR_SHIPPING_TYPE']);
1506  $tpl->assign('STR_SHIPPING_COST', $GLOBALS['STR_SHIPPING_COST']);
1507  $tpl->assign('STR_GIFT_POINTS', $GLOBALS['STR_GIFT_POINTS']);
1508  $tpl->assign('STR_INVOICE_ADDRESS', $GLOBALS['STR_INVOICE_ADDRESS']);
1509  $tpl->assign('STR_FIRST_NAME', $GLOBALS['STR_FIRST_NAME']);
1510  $tpl->assign('STR_LAST_NAME', $GLOBALS['STR_LAST_NAME']);
1511  $tpl->assign('STR_SOCIETE', $GLOBALS['STR_SOCIETE']);
1512  $tpl->assign('STR_EMAIL', $GLOBALS['STR_EMAIL']);
1513  $tpl->assign('STR_TELEPHONE', $GLOBALS['STR_TELEPHONE']);
1514  $tpl->assign('STR_ADDRESS', $GLOBALS['STR_ADDRESS']);
1515  $tpl->assign('STR_ZIP', $GLOBALS['STR_ZIP']);
1516  $tpl->assign('STR_TOWN', $GLOBALS['STR_TOWN']);
1517  $tpl->assign('STR_COUNTRY', $GLOBALS['STR_COUNTRY']);
1518  $tpl->assign('STR_ADMIN_COMMANDER_ORDERED_PRODUCTS_LIST', $GLOBALS['STR_ADMIN_COMMANDER_ORDERED_PRODUCTS_LIST']);
1519  $tpl->assign('STR_ADMIN_ID', $GLOBALS['STR_ADMIN_ID']);
1520  $tpl->assign('STR_REFERENCE', $GLOBALS['STR_REFERENCE']);
1521  $tpl->assign('STR_SIZE', $GLOBALS['STR_SIZE']);
1522  $tpl->assign('STR_COLOR', $GLOBALS['STR_COLOR']);
1523  $tpl->assign('STR_QUANTITY_SHORT', $GLOBALS['STR_QUANTITY_SHORT']);
1524  $tpl->assign('STR_ADMIN_COMMANDER_PRODUCT_LISTED_PRICE', $GLOBALS['STR_ADMIN_COMMANDER_PRODUCT_LISTED_PRICE']);
1525  $tpl->assign('STR_REMISE', $GLOBALS['STR_REMISE']);
1526  $tpl->assign('STR_UNIT_PRICE', $GLOBALS['STR_UNIT_PRICE']);
1527  $tpl->assign('STR_ADMIN_CUSTOM_ATTRIBUTES', $GLOBALS['STR_ADMIN_CUSTOM_ATTRIBUTES']);
1528  $tpl->assign('STR_ADMIN_VAT_PERCENTAGE', $GLOBALS['STR_ADMIN_VAT_PERCENTAGE']);
1529  $tpl->assign('STR_ADMIN_COMMANDER_ADD_PRODUCTS_TO_ORDER', $GLOBALS['STR_ADMIN_COMMANDER_ADD_PRODUCTS_TO_ORDER']);
1530  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_EMITTED_BY_GODCHILD', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_EMITTED_BY_GODCHILD']);
1531  $tpl->assign('STR_ADMIN_COMMANDER_THANK_SPONSOR_WITH_CREDIT_OF', $GLOBALS['STR_ADMIN_COMMANDER_THANK_SPONSOR_WITH_CREDIT_OF']);
1532  $tpl->assign('STR_ADMIN_COMMANDER_THANK_SPONSOR_WITH_CREDIT_EXPLAIN', $GLOBALS['STR_ADMIN_COMMANDER_THANK_SPONSOR_WITH_CREDIT_EXPLAIN']);
1533  $tpl->assign('STR_ADMIN_COMMANDER_GIVE_CREDIT', $GLOBALS['STR_ADMIN_COMMANDER_GIVE_CREDIT']);
1534  $tpl->assign('STR_ADMIN_COMMANDER_SHIPPING_ADDRESS', $GLOBALS['STR_ADMIN_COMMANDER_SHIPPING_ADDRESS']);
1535  $tpl->assign('STR_ADMIN_COMMANDER_MSG_PURCHASE_ORDER_SENT_BY_EMAIL_OK', $GLOBALS['STR_ADMIN_COMMANDER_MSG_PURCHASE_ORDER_SENT_BY_EMAIL_OK']);
1536  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_UPDATED', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_UPDATED']);
1537  $tpl->assign('STR_ADMIN_COMMANDER_AND_STOCKS_UPDATED', $GLOBALS['STR_ADMIN_COMMANDER_AND_STOCKS_UPDATED']);
1538  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_CREATED', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_CREATED']);
1539  $tpl->assign('STR_ADMIN_COMMANDER_LINK_ORDER_SUMMARY', $GLOBALS['STR_ADMIN_COMMANDER_LINK_ORDER_SUMMARY']);
1540  $tpl->assign('STR_ADMIN_COMMANDER_AFFILIATION_MODULE_MISSING', $GLOBALS['STR_ADMIN_COMMANDER_AFFILIATION_MODULE_MISSING']);
1541  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_STATUS_UPDATED', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_STATUS_UPDATED']);
1542  $tpl->assign('STR_ADMIN_COMMANDER_MSG_AVOIR_SENT_BY_EMAIL_OK', $GLOBALS['STR_ADMIN_COMMANDER_MSG_AVOIR_SENT_BY_EMAIL_OK']);
1543  $tpl->assign('STR_ADMIN_COMMANDER_WARNING_EDITION_NOT_ALLOWED', $GLOBALS['STR_ADMIN_COMMANDER_WARNING_EDITION_NOT_ALLOWED']);
1544  $tpl->assign('STR_ADMIN_COMMANDER_OPEN_IN_BROWSER', $GLOBALS['STR_ADMIN_COMMANDER_OPEN_IN_BROWSER']);
1545  $tpl->assign('STR_ADMIN_COMMANDER_SEND_BY_EMAIL_CONFIRM', $GLOBALS['STR_ADMIN_COMMANDER_SEND_BY_EMAIL_CONFIRM']);
1546  $tpl->assign('STR_ADMIN_COMMANDER_CREATE_OR_UPDATE_TITLE', $GLOBALS['STR_ADMIN_COMMANDER_CREATE_OR_UPDATE_TITLE']);
1547  $tpl->assign('STR_ADMIN_COMMANDER_SEND_PDF_BILL_BY_EMAIL', $GLOBALS['STR_ADMIN_COMMANDER_SEND_PDF_BILL_BY_EMAIL']);
1548  $tpl->assign('STR_ADMIN_COMMANDER_SEND_PDF_BILL_BY_EMAIL_CONFIRM', $GLOBALS['STR_ADMIN_COMMANDER_SEND_PDF_BILL_BY_EMAIL_CONFIRM']);
1549  $tpl->assign('STR_ADMIN_COMMANDER_SEND_PDF_PROFORMA_BY_EMAIL', $GLOBALS['STR_ADMIN_COMMANDER_SEND_PDF_PROFORMA_BY_EMAIL']);
1550  $tpl->assign('STR_ADMIN_COMMANDER_SEND_PDF_PROFORMA_BY_EMAIL_CONFIRM', $GLOBALS['STR_ADMIN_COMMANDER_SEND_PDF_PROFORMA_BY_EMAIL_CONFIRM']);
1551  $tpl->assign('STR_ADMIN_COMMANDER_SEND_PDF_QUOTATION_BY_EMAIL', $GLOBALS['STR_ADMIN_COMMANDER_SEND_PDF_QUOTATION_BY_EMAIL']);
1552  $tpl->assign('STR_ADMIN_COMMANDER_SEND_PDF_QUOTATION_BY_EMAIL_CONFIRM', $GLOBALS['STR_ADMIN_COMMANDER_SEND_PDF_QUOTATION_BY_EMAIL_CONFIRM']);
1553  $tpl->assign('STR_ADMIN_COMMANDER_WITH_PARTIAL_AMOUNT', $GLOBALS['STR_ADMIN_COMMANDER_WITH_PARTIAL_AMOUNT']);
1554  $tpl->assign('STR_ADMIN_COMMANDER_FIANET_FUNCTIONS', $GLOBALS['STR_ADMIN_COMMANDER_FIANET_FUNCTIONS']);
1555  $tpl->assign('STR_ADMIN_COMMANDER_INFORMATION_ON_THIS_ORDER', $GLOBALS['STR_ADMIN_COMMANDER_INFORMATION_ON_THIS_ORDER']);
1556  $tpl->assign('STR_ORDER_NUMBER', $GLOBALS['STR_ORDER_NUMBER']);
1557  $tpl->assign('STR_ADMIN_COMMANDER_PAYMENT_DATE', $GLOBALS['STR_ADMIN_COMMANDER_PAYMENT_DATE']);
1558  $tpl->assign('STR_ADMIN_COMMANDER_DELIVERY_DATE', $GLOBALS['STR_ADMIN_COMMANDER_DELIVERY_DATE']);
1559  $tpl->assign('STR_ADMIN_COMMANDER_INVOICE_DATE', $GLOBALS['STR_ADMIN_COMMANDER_INVOICE_DATE']);
1560  $tpl->assign('STR_ADMIN_COMMANDER_VAT_INTRACOM', $GLOBALS['STR_ADMIN_COMMANDER_VAT_INTRACOM']);
1561  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_DATE', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_DATE']);
1562  $tpl->assign('STR_ADMIN_COMMANDER_BILL_NUMBER', $GLOBALS['STR_ADMIN_COMMANDER_BILL_NUMBER']);
1563  $tpl->assign('STR_ADMIN_COMMANDER_BILL_NUMBER_EXPLAIN', $GLOBALS['STR_ADMIN_COMMANDER_BILL_NUMBER_EXPLAIN']);
1564  $tpl->assign('STR_ADMIN_COMMANDER_TRACKING_NUMBER', $GLOBALS['STR_ADMIN_COMMANDER_TRACKING_NUMBER']);
1565  $tpl->assign('STR_ADMIN_COMMANDER_PAYMENT_MEAN_EXPLAIN', $GLOBALS['STR_ADMIN_COMMANDER_PAYMENT_MEAN_EXPLAIN']);
1566  $tpl->assign('STR_ADMIN_COMMANDER_SHIPPING_COST_EXPLAIN', $GLOBALS['STR_ADMIN_COMMANDER_SHIPPING_COST_EXPLAIN']);
1567  $tpl->assign('STR_ADMIN_COMMANDER_SMALL_ORDERS_OVERCOST', $GLOBALS['STR_ADMIN_COMMANDER_SMALL_ORDERS_OVERCOST']);
1568  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_TOTAL', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_TOTAL']);
1569  $tpl->assign('STR_ADMIN_COMMANDER_INCLUDING_DISCOUNT', $GLOBALS['STR_ADMIN_COMMANDER_INCLUDING_DISCOUNT']);
1570  $tpl->assign('STR_ADMIN_COMMANDER_COUPON_USED', $GLOBALS['STR_ADMIN_COMMANDER_COUPON_USED']);
1571  $tpl->assign('STR_ADMIN_COMMANDER_INCLUDING_CREDIT_NOTE', $GLOBALS['STR_ADMIN_COMMANDER_INCLUDING_CREDIT_NOTE']);
1572  $tpl->assign('STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION', $GLOBALS['STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION']);
1573  $tpl->assign('STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION_PAYMENT_STATUS', $GLOBALS['STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION_PAYMENT_STATUS']);
1574  $tpl->assign('STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION_PAYMENT_STATUS_TO_COME', $GLOBALS['STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION_PAYMENT_STATUS_TO_COME']);
1575  $tpl->assign('STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION_PAYMENT_STATUS_DONE', $GLOBALS['STR_ADMIN_COMMANDER_AFFILIATE_COMMISSION_PAYMENT_STATUS_DONE']);
1576  $tpl->assign('STR_ADMIN_COMMANDER_AFFILIATE_RELATED_TO_ORDER', $GLOBALS['STR_ADMIN_COMMANDER_AFFILIATE_RELATED_TO_ORDER']);
1577  $tpl->assign('STR_ADMIN_COMMANDER_GIFT_POINTS', $GLOBALS['STR_ADMIN_COMMANDER_GIFT_POINTS']);
1578  $tpl->assign('STR_ADMIN_COMMANDER_NOT_ATTRIBUTED', $GLOBALS['STR_ADMIN_COMMANDER_NOT_ATTRIBUTED']);
1579  $tpl->assign('STR_ADMIN_COMMANDER_ATTRIBUTED', $GLOBALS['STR_ADMIN_COMMANDER_ATTRIBUTED']);
1580  $tpl->assign('STR_ADMIN_COMMANDER_CANCELED', $GLOBALS['STR_ADMIN_COMMANDER_CANCELED']);
1581  $tpl->assign('STR_ADMIN_COMMANDER_CLIENT_INFORMATION', $GLOBALS['STR_ADMIN_COMMANDER_CLIENT_INFORMATION']);
1582  $tpl->assign('STR_ADMIN_COMMANDER_ORDER_AUTHOR_EMAIL', $GLOBALS['STR_ADMIN_COMMANDER_ORDER_AUTHOR_EMAIL']);
1583  $tpl->assign('STR_ADMIN_COMMANDER_BILL_ADDRESS_EXPLAIN', $GLOBALS['STR_ADMIN_COMMANDER_BILL_ADDRESS_EXPLAIN']);
1584  $tpl->assign('STR_ADMIN_COMMANDER_SHIPPING_ADDRESS', $GLOBALS['STR_ADMIN_COMMANDER_SHIPPING_ADDRESS']);
1585  $tpl->assign('STR_ADMIN_COMMANDER_ORDERED_PRODUCTS_LIST', $GLOBALS['STR_ADMIN_COMMANDER_ORDERED_PRODUCTS_LIST']);
1586  $tpl->assign('STR_ADMIN_COMMANDER_PRICES_MUST_BE_IN_ORDER_CURRENCY', $GLOBALS['STR_ADMIN_COMMANDER_PRICES_MUST_BE_IN_ORDER_CURRENCY']);
1587  $tpl->assign('STR_ADMIN_COMMANDER_PRODUCT_NAME', $GLOBALS['STR_ADMIN_COMMANDER_PRODUCT_NAME']);
1588  $tpl->assign('STR_ADMIN_COMMANDER_CURRENCY_EXCHANGE_USED', sprintf($GLOBALS['STR_ADMIN_COMMANDER_CURRENCY_EXCHANGE_USED'], $GLOBALS['site_parameters']['symbole']));
1589  $tpl->assign('STR_ADMIN_COMMANDER_ADD_LINE_TO_ORDER', $GLOBALS["STR_ADMIN_COMMANDER_ADD_LINE_TO_ORDER"]);
1590  $tpl->assign('STR_ADMIN_UTILISATEURS_CREATE_ORDER', $GLOBALS["STR_ADMIN_UTILISATEURS_CREATE_ORDER"]);
1591  $tpl->assign('STR_ADMIN_FORM_SAVE_CHANGES', $GLOBALS["STR_ADMIN_FORM_SAVE_CHANGES"]);
1592 
1593  return $tpl->fetch();
1594  } elseif (!empty($id)) {
1595  return $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => sprintf($GLOBALS["STR_ADMIN_COMMANDER_NO_ORDER_WITH_ID_FOUND"], $id)))->fetch();
1596  }
1597 }
1598 
1599 
1607 {
1608  $output = '';
1609  if (!empty($frm)) {
1610  $sql = "SELECT email
1611  FROM peel_commandes
1612  WHERE id = '" . intval($frm['id']) . "' AND " . get_filter_site_cond('commandes', null) . "";
1613  $query = query($sql);
1615  if (!empty($result['email'])) {
1616  if (vb($_REQUEST['mode']) != 'sendfacturepdf') {
1617  sendclient($frm['id'], 'html');
1618  } else {
1619  sendclient($frm['id'], 'pdf', $frm['bill_type']);
1620  }
1621  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_MSG_ORDER_SENT_OK'], intval($frm['id']), $result['email'])))->fetch();
1622  } else {
1623  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_ERR_NO_EMAIL_KNOWN_FOR_ORDER'], intval($frm['id']))))->fetch();
1624  }
1625  } else {
1626  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_ERR_NO_EMAIL_KNOWN_FOR_ORDER'], intval($frm['id']))))->fetch();
1627  }
1628  return $output;
1629 }
1630 
1631 
1639 {
1640  // Création des variables
1641  $total_produit = 0;
1642  $total_produit_ht = 0;
1643  $total_remise = 0;
1644  $total_remise_ht = 0;
1645  $frm['total_ecotaxe_ttc'] = 0;
1646  $frm['total_ecotaxe_ht'] = 0;
1647  $frm['total_poids'] = 0;
1648  $frm['total_points'] = 0;
1649  if (!isset($frm['delivery_tracking'])) {
1650  $frm['delivery_tracking'] = null;
1651  }
1652  if (empty($frm['societe2']) && empty($frm['nom2']) && empty($frm['prenom2'])) {
1653  // On ne remplit automatiquement la société et le nom que si vraiment l'ensemble de l'adresse de livraison n'était pas définie
1654  // On remplit ces champs même pour un mode de livraison ne nécessitant pas d'adresse, c'est utile pour savoir à qui est destiné le colis.
1655  $frm['societe2'] = vb($frm['societe1']);
1656  $frm['nom2'] = vb($frm['nom1']);
1657  $frm['prenom2'] = vb($frm['prenom1']);
1658  }
1659  handle_specific_fields($frm, 'order');
1660  if (is_delivery_address_necessary_for_delivery_type($frm['type_transport'])) {
1661  // Le type de transport nécessite une adresse de livraison.
1662  // Il faut compléter les champs de l'adresse de livraison uniquement si le mode de livraison n'est pas "Retrait en boutique"
1663  if(!empty($frm['adresses_fields_array'])) {
1664  // $frm['adresses_fields_array'] est défini dans handle_specific_fields. Il n'est pas rempli dans le cas où il n'y a aucun champ spécifique concernant les adresses d'utilisateurs (se terminant par _ship ou _bill)
1665  foreach ($frm['adresses_fields_array'] as $this_item) {
1666  if (empty($frm[$this_item . '2'])) {
1667  $frm[$this_item . '2'] = vb($frm[$this_item . '1']);
1668  }
1669  }
1670  }
1671  }
1672  if (empty($frm['nb_produits'])) {
1673  $frm['nb_produits'] = 5;
1674  }
1675  if (empty($frm['lang'])) {
1676  $frm['lang'] = $_SESSION['session_langue'];
1677  }
1678  if (empty($frm['site_id'])) {
1679  // Site id absent pour cette commande, il ne faut pas avoir de valeur vide ou à 0 pour une commande, elle est forcement associée à un site.
1680  if (!empty($_SESSION['session_admin_multisite'])) {
1681  // L'administrateur a choisi un site à administrer spécifiquement
1682  $frm['site_id'] = $_SESSION['session_admin_multisite'];
1683  } else {
1684  // on utilise l'id du site courant
1685  $frm['site_id'] = $GLOBALS['site_id'];
1686  }
1687  }
1688 
1689  if (empty($frm['commandeid'])) {
1690  if (!empty($frm['email1'])) {
1691  // On crée une nouvelle commande
1692  $sql = "SELECT id_utilisateur, email
1693  FROM peel_utilisateurs
1694  WHERE email = '" . nohtml_real_escape_string($frm['email1']) . "' AND " . get_filter_site_cond('utilisateurs', null) . "";
1695  $result = query($sql);
1696  }
1697  if (!empty($result) && $u = fetch_object($result)) {
1698  $frm['email'] = $u->email;
1699  $frm['id_utilisateur'] = $u->id_utilisateur;
1700  } elseif(!empty($frm['email1'])) {
1701  // Création de l'utilisateur si on ne le trouve pas uniquement si l'email est renseigné
1702  $frm['email'] = vb($frm['email1']);
1703  $new_user_infos = array('priv' => 'util',
1704  'email' => vb($frm['email1']),
1705  'mot_passe' => vb($frm['mot_passe']),
1706  'prenom' => vb($frm['prenom1']),
1707  'nom' => vb($frm['nom1']),
1708  'societe' => vb($frm['societe1']),
1709  'telephone' => vb($frm['contact1']),
1710  'adresse' => vb($frm['adresse1']),
1711  'code_postal' => vb($frm['code_postal1']),
1712  'ville' => vb($frm['ville1']),
1713  'pays' => vb($frm['pays1']),
1714  'newsletter' => 1,
1715  'commercial' => 1);
1716  $frm['id_utilisateur'] = insere_utilisateur($new_user_infos, false, false, false);
1717  } else {
1718  // commande sans utilisateur associé.
1719  $frm['id_utilisateur'] = 0;
1720  }
1721  } else {
1722  // Recherche d'information sur la commande avant modification
1723  $query = query('SELECT email
1724  FROM peel_commandes
1725  WHERE ' . get_filter_site_cond('commandes') . ' AND id = ' . intval(vn($frm['commandeid'])));
1727  if((!empty($frm['autocomplete_order_adresses_with_account_info_if_order_email_change']) && $result['email'] != $frm['email']) || !empty($frm['autocomplete_order_adresses_with_account_info'])) {
1728  // L'auteur de la commande a changé. On change les informations relative à l'utilisateur de cette commande.
1729  // Utile pour modifier une commande après une duplication de commande (module duplicate du module premium.)
1730  $query = query('SELECT societe, prenom, nom_famille AS nom, adresse, code_postal, ville, pays, email, telephone AS contact
1731  FROM peel_utilisateurs
1732  WHERE email = "' . nohtml_real_escape_string($frm['email']) . '" AND ' . get_filter_site_cond('utilisateurs'));
1733  if($result = fetch_assoc($query)) {
1734  if (!empty($frm['adresses_fields_array'])) {
1735  // $frm['adresses_fields_array'] est défini dans handle_specific_fields. Il n'est pas rempli dans le cas où il n'y a aucun champ spécifique concernant les adresses d'utilisateurs (se terminant par _ship ou _bill)
1736  foreach($frm['adresses_fields_array'] as $this_item) {
1737  $frm[$this_item . '1'] = $result[$this_item];
1738  $frm[$this_item . '2'] = $result[$this_item];
1739  }
1740  }
1741  }
1742  }
1743  }
1744  // Calcul des coûts et insertion de la commande
1745  if ((empty($frm['currency_rate']) || empty($frm['devise']))) {
1746  if (isset($frm['devise']) && $frm['devise'] != $GLOBALS['site_parameters']['code']) {
1747  // Si la devise de la commande n'est pas celle de la boutique, alors on récupère le taux de change de la devise
1748  $res = query("SELECT p.conversion
1749  FROM peel_devises p
1750  WHERE p.code = '" . nohtml_real_escape_string($frm['devise']) . "' AND " . get_filter_site_cond('devises', 'p') . "");
1751  }
1752  if (!empty($res) && $tab = fetch_assoc($res)) {
1753  $frm['currency_rate'] = $tab['conversion'];
1754  } else {
1755  // Valeur par défaut de la devise
1756  $frm['devise'] = $GLOBALS['site_parameters']['code'];
1757  $frm['currency_rate'] = $GLOBALS['site_parameters']['conversion'];
1758  }
1759  }
1760  // On récupère les informations sur les zones
1761  $sqlPays = 'SELECT p.id, p.pays_' . $frm['lang'] . ' as pays, p.zone, z.tva, z.on_franco
1762  FROM peel_pays p
1763  LEFT JOIN peel_zones z ON z.id=p.zone AND ' . get_filter_site_cond('zones', 'z') . '
1764  WHERE p.etat = "1" AND p.pays_' . $frm['lang'] . '="' . nohtml_real_escape_string($frm['pays2']) . '" AND ' . get_filter_site_cond('pays', 'p') . '
1765  LIMIT 1';
1766  $query = query($sqlPays);
1767  if ($result = fetch_assoc($query)) {
1768  $frm['pays'] = $result['pays'];
1769  $frm['zoneId'] = $result['zone'];
1770  if(!isset($frm['apply_vat'])){
1771  // Si $frm['apply_vat'] est déjà défini, alors on garde la valeur qui a priorité sur la configuration du pays en BDD
1772  $frm['apply_vat'] = ($result['tva'] && !is_user_tva_intracom_for_no_vat($frm['id_utilisateur']) && !check_if_module_active('micro_entreprise'));
1773  }
1774  $frm['zoneFranco'] = $result['on_franco'];
1775  } else {
1776  $frm['zoneId'] = false;
1777  $frm['pays'] = '';
1778  if(!isset($frm['apply_vat'])){
1779  // Si $frm['apply_vat'] est déjà défini, alors on garde la valeur qui a priorité sur la configuration du pays en BDD
1780  $frm['apply_vat'] = false;
1781  }
1782  $frm['zoneFranco'] = '';
1783  }
1784  // L'ordre des produits a peut-être été modifié par l'administrateur, donc on prend les produits dans l'ordre du POST. Le tableau product_order_array sert à faire un mappage de l'ordre des produits tel qu'affichée sur la page de détail de commade et les numéros de ligne. product_order_array contient les numéros des lignes de produit, mais dans l'ordre que l'admin a choisi.
1785  $product_order_array = array();
1786  foreach($frm as $key => $data) {
1787  if (String::substr($key, 0, 3) == "ref" && is_numeric(String::substr($key, 3))) {
1788  $product_order_array[]=String::substr($key, 3);
1789  }
1790  }
1791  // On calcul les totaux de produits
1792  foreach ($product_order_array as $i) {
1793  if (isset($frm["p" . $i]) && isset($frm["q" . $i]) && isset($frm["t" . $i])) {
1794  if (check_if_module_active('conditionnement') && !empty($frm["cdt" . $i])) {
1795  // Les produits sont conditionnés sous forme de lot, mais lorsque ce module est activé
1796  // on souhaite gérer les quantités et les stocks par produits individuels
1797  $real_stock_used = $frm["cdt" . $i] * $frm["q" . $i];
1798  } else {
1799  // Cas général de gestion des quantités
1800  $real_stock_used = intval($frm["q" . $i]);
1801  }
1803  $total_produit += get_float_from_user_input($frm["p" . $i], $frm['currency_rate']) * get_float_from_user_input($real_stock_used);
1804  $total_produit_ht += get_float_from_user_input($frm["p" . $i], $frm['currency_rate']) * get_float_from_user_input($real_stock_used) / (1 + get_float_from_user_input($frm["t" . $i]) / 100);
1805  // Remise en EUR
1806  $total_remise += get_float_from_user_input(vn($frm["remis" . $i]), $frm['currency_rate']) * get_float_from_user_input($real_stock_used);
1807  $total_remise_ht += get_float_from_user_input(vn($frm["remis" . $i]), $frm['currency_rate']) * get_float_from_user_input($real_stock_used) / (1 + get_float_from_user_input($frm["t" . $i]) / 100);
1808  } else {
1809  $total_produit += get_float_from_user_input($frm["p" . $i], $frm['currency_rate']) * get_float_from_user_input($real_stock_used) * (1 + get_float_from_user_input($frm["t" . $i]) / 100);
1810  $total_produit_ht += get_float_from_user_input($frm["p" . $i], $frm['currency_rate']) * get_float_from_user_input($real_stock_used);
1811  // Remise en EUR
1812  $total_remise += get_float_from_user_input(vn($frm["remis" . $i]), $frm['currency_rate']) * get_float_from_user_input($real_stock_used) * (1 + get_float_from_user_input($frm["t" . $i]) / 100);
1813  $total_remise_ht += get_float_from_user_input(vn($frm["remis" . $i]), $frm['currency_rate']) * get_float_from_user_input($real_stock_used);
1814  }
1815  if(!$frm['apply_vat']){
1816  // Pas de TVA applicable pour cette commande. Maintenant qu'on a bien calculé les HT, on fait en sorte que les TTC soient égaux aux HT
1817  $total_produit = $total_produit_ht;
1818  $total_remise = $total_remise_ht;
1819  }
1820  }
1821  }
1822  // Insertion des produits commandés
1823  $total_ttc = 0;
1824 
1825  foreach ($product_order_array as $i) {
1826  if (!isset($frm["l" . $i]) || empty($frm["q" . $i])) {
1827  continue;
1828  }
1829  // Récupère les variables dans le formulaire
1830  $nom = $frm["l" . $i];
1831  $quantite = get_float_from_user_input($frm["q" . $i]);
1832  if (empty($quantite)) {
1833  continue;
1834  }
1836  $prix_cat = get_float_from_user_input(vn($frm["p_cat" . $i]), $frm['currency_rate']);
1837  $prix_cat_ht = $prix_cat / (1 + vn($frm["t" . $i]) / 100);
1838  // Calcul remise en EUR
1839  $remise = get_float_from_user_input(vn($frm["remis" . $i]), $frm['currency_rate']);
1840  $remise_ht = $remise / (1 + $frm["t" . $i] / 100);
1841  // On charge la valeur du prix sans utiliser le calcul du prix après toutes les remises
1842  $prix = get_float_from_user_input($frm["p" . $i], $frm['currency_rate']);
1843  $prix_ht = $prix / (1 + vn($frm["t" . $i])/ 100);
1844  } else {
1845  $prix_cat_ht = get_float_from_user_input(vn($frm["p_cat" . $i]), $frm['currency_rate']);
1846  $prix_cat = $prix_cat_ht * (1 + vn($frm["t" . $i]) / 100);
1847  // Calcul remise en EUR
1848  $remise_ht = get_float_from_user_input(vn($frm["remis" . $i]), $frm['currency_rate']);
1849  $remise = $remise_ht * (1 + vn($frm["t" . $i]) / 100);
1850  // On charge la valeur du prix sans utiliser le calcul du prix après toutes les remises
1851  $prix_ht = get_float_from_user_input($frm["p" . $i], $frm['currency_rate']);
1852  $prix = $prix_ht * (1 + vn($frm["t" . $i]) / 100);
1853  }
1854  if(!$frm['apply_vat']){
1855  // Pas de TVA applicable pour cette commande. Maintenant qu'on a bien calculé les HT, on fait en sorte que les TTC soient égaux aux HT
1856  $frm["t" . $i] = 0;
1857  $prix_cat = $prix_cat_ht;
1858  $prix = $prix_ht;
1859  $remise = $remise_ht;
1860  }
1861  // Calcul remise en %
1862  $remise_percent = get_float_from_user_input(vn($frm["perc" . $i]));
1863  if (check_if_module_active('conditionnement') && !empty($frm["cdt" . $i])) {
1864  // Les produits sont conditionnés sous forme de lot, mais lorsque ce module est activé
1865  // on souhaite gérer les quantités et les stocks par produits individuels
1866  $real_stock_used = get_float_from_user_input($frm["cdt" . $i]) * $quantite;
1867  } else {
1868  // Cas général de gestion des quantités
1869  $real_stock_used = $quantite;
1870  }
1871  $total_prix = $prix * $real_stock_used;
1872  $total_prix_ht = $prix_ht * $real_stock_used;
1873  $tva = $total_prix - $total_prix_ht;
1874  // Lie la commande au produit
1875  if(!empty($frm["id" . $i])) {
1876  $this_article['product_id'] = $frm["id" . $i];
1877  } else {
1878  $this_article['product_id'] = get_product_id_by_name($nom);
1879  }
1880  $product_object = new Product($this_article['product_id'], null, false, null, true, !check_if_module_active('micro_entreprise'));
1881  $this_article['product_name'] = $nom;
1882  $this_article['quantite'] = $quantite;
1883  if (!empty($frm['color_' . $i]) && !is_numeric($frm['color_' . $i])) {
1884  $this_article['couleurId'] = 0;
1885  $this_article['couleur'] = vn($frm['color_' . $i]);
1886  } else {
1887  $this_article['couleurId'] = vn($frm['color_' . $i]);
1888  }
1889  if (!empty($frm['size_' . $i]) && !is_numeric($frm['size_' . $i])) {
1890  $this_article['tailleId'] = 0;
1891  $this_article['taille'] = vn($frm['size_' . $i]);
1892  } else {
1893  $this_article['tailleId'] = vn($frm['size_' . $i]);
1894  }
1895  $this_article['giftlist_owners'] = vn($frm['giftlist_owners_' . $i]);
1896  $this_article['prix'] = $prix;
1897  $this_article['prix_ht'] = $prix_ht;
1898  $this_article['prix_cat'] = $prix_cat;
1899  $this_article['prix_cat_ht'] = $prix_cat_ht;
1900  $this_article['total_prix'] = $total_prix;
1901  $this_article['total_prix_ht'] = $total_prix_ht;
1902  $this_article['tva_percent'] = $frm["t" . $i];
1903  $this_article['tva'] = $tva;
1904  $this_article['reference'] = vb($frm["ref" . $i]);
1905  $this_article['percent_remise_produit'] = vn($remise_percent);
1906  $this_article['remise'] = $remise * $quantite;
1907  $this_article['remise_ht'] = $remise_ht * $quantite;
1908  if (check_if_module_active('ecotaxe')) {
1909  $product_ecotaxe_infos_query = query("SELECT e.*
1910  FROM peel_ecotaxes e
1911  INNER JOIN peel_produits p ON e.id = p.id_ecotaxe AND " . get_filter_site_cond('produits', 'p') . "
1912  WHERE p.id='" . intval($this_article['product_id']) . "' AND " . get_filter_site_cond('ecotaxes', 'e') . "");
1913  if ($product_ecotaxe_infos = fetch_assoc($product_ecotaxe_infos_query)) {
1914  if (!empty($product_ecotaxe_infos['id'])) {
1915  $this_article['ecotaxe_ttc'] = $product_ecotaxe_infos['prix_ttc'];
1916  $this_article['ecotaxe_ht'] = $product_ecotaxe_infos['prix_ht'];
1917  } else {
1918  $this_article['ecotaxe_ttc'] = 0;
1919  $this_article['ecotaxe_ht'] = 0;
1920  }
1921  // Valeurs globales pour l'ensemble des produits
1922  $frm['total_ecotaxe_ht'] += $this_article['ecotaxe_ht'];
1923  $frm['total_ecotaxe_ttc'] += $this_article['ecotaxe_ttc'];
1924  }
1925  }
1926  $this_article['etat_stock'] = $product_object->on_stock;
1927 
1928  if (check_if_module_active('tnt')) {
1929  $this_article['tnt_parcel_number'] = vn($frm['tnt_parcel_number_' . $i]);
1930  }
1931  $this_article['nom_attribut'] = vn($frm['nom_attribut_' . $i]);
1932  $this_article['total_prix_attribut'] = vn($frm['total_prix_attribut_' . $i]);
1933 
1934  $total_prix_attribut_ht = $this_article['total_prix_attribut'] / (1 + $tva / 100); // recupération du prix des attributs en ht pour utiliser dans le calcul de option_ht
1935  // Informations supplémentaires (non modifiable dans la mofification de la commande)
1936  $this_article['delai_stock'] = $product_object->delai_stock;
1937 
1938  $product_object->set_configuration($this_article['couleurId'], $this_article['tailleId'], null, check_if_module_active('reseller') && is_reseller()); // on fixe les options
1939  $this_article['poids'] = ($product_object->poids + $product_object->configuration_overweight) * $this_article['quantite'];
1940  $frm['total_poids'] += $this_article['poids'];
1941  $this_article['option'] = $product_object->format_prices($product_object->configuration_size_price_ht + $product_object->configuration_total_original_price_attributs_ht, $frm['apply_vat'], false, false, false) + $this_article['total_prix_attribut'];
1942  $this_article['option_ht'] = $product_object->format_prices($product_object->configuration_size_price_ht + $product_object->configuration_total_original_price_attributs_ht, false, false, false, false) + $total_prix_attribut_ht;
1943 
1944  $this_article['option'] = round($this_article['option'], 2); //On doit arrondir les valeurs tarifaires officielles
1945  $this_article['option_ht'] = round($this_article['option_ht'], 2); //On doit arrondir les valeurs tarifaires officielles
1946  $this_article['points'] = $product_object->points * $this_article['quantite'];
1947  $frm['total_points'] += $this_article['points'];
1948 
1949  /*
1950  Non renseignés :
1951  $this_article['giftlist_owners'] = ;
1952  $this_article['email_check'] = ;
1953  */
1954  if (!empty($this_article['product_id']) || !empty($this_article['product_name']) || !empty($this_article['reference']) || !empty($this_article['prix'])) {
1955  // Article vide
1956  $articles[$i] = $this_article;
1957  }
1958  }
1959  // On récupère les frais de port
1960  if (!empty($GLOBALS['site_parameters']['mode_transport']) && (!isset($frm['cout_transport']) || $frm['cout_transport'] == '')) {
1961  // Calcul du coût du transport
1962  $delivery_cost_infos = get_delivery_cost_infos($frm['total_poids'], $total_produit, vb($frm['type_transport']), $frm['zoneId'], $frm['nb_produits']);
1963  if ($delivery_cost_infos !== false) {
1964  $shipping_costs['tva_percent'] = ($frm['apply_vat'] ? $delivery_cost_infos['tva'] : 0);
1965  $cout_transport_ht = $delivery_cost_infos['cost_ht'];
1966  } else {
1967  // Pas de port trouvé pour ce poids et ce total
1968  $shipping_costs['tva_percent'] = 0;
1969  $cout_transport_ht = 0;
1970  }
1971  $cout_transport = vn($cout_transport_ht) * (1 + vn($shipping_costs['tva_percent']) / 100);
1972  } else {
1973  // Récupération des données du formulaire
1974  $cout_transport = get_float_from_user_input(vn($frm['cout_transport']), $frm['currency_rate']);
1975  $cout_transport_ht = vn($cout_transport) / (1 + get_float_from_user_input(vn($frm['tva_transport'])) / 100);
1976  }
1977  // On récupère le type de transport
1978  if (!empty($frm['type_transport'])) {
1979  $frm['type'] = get_delivery_type_name(vb($frm['type_transport']));
1980  $frm['typeId'] = $frm['type_transport'];
1981  }
1982  if(a_priv('reve')) {
1983  $treshold_to_use = $GLOBALS['site_parameters']['minimal_amount_to_order_reve'];
1984  } else {
1985  $treshold_to_use = $GLOBALS['site_parameters']['minimal_amount_to_order'];
1986  }
1987  if ($frm['small_order_overcost_amount'] == '') {
1988  if($total_produit < $GLOBALS['site_parameters']['small_order_overcost_limit'] && $total_produit >= $treshold_to_use) {
1989  $small_order_overcost_amount = $GLOBALS['site_parameters']['small_order_overcost_amount'];
1990  } else {
1991  $small_order_overcost_amount = 0;
1992  }
1993  } else {
1994  $small_order_overcost_amount = get_float_from_user_input(vn($frm['small_order_overcost_amount']), $frm['currency_rate']);
1995  }
1996  $tva_small_order_overcost = get_float_from_user_input(vn($frm['tva_small_order_overcost']), $frm['currency_rate']);
1997  if (!empty($frm['avoir'])) {
1998  // L'avoir est limité au total de la commande.
1999  // L'avoir est uniquement sur le TTC et n'affecte pas le calcul de la TVA
2000  $avoir = max(0, min(get_float_from_user_input(vn($frm['avoir']), $frm['currency_rate']), vn($total_produit) + vn($cout_transport) + vn($small_order_overcost_amount)));
2001  } else {
2002  $avoir = 0;
2003  }
2004  // Calcul du sous total pour pouvoir appliquer le coût du paiement en pourcentage
2005  $frm['sub_total'] = vn($total_produit) - vn($avoir) + vn($cout_transport) + vn($small_order_overcost_amount);
2006  $frm['sub_total_ht'] = vn($total_produit_ht) + vn($cout_transport_ht) + (vn($small_order_overcost_amount) - vn($tva_small_order_overcost));
2007  // On recupère le coût de paiement. La fonction set_paiement définit les variables : $frm['tarif_paiement'], $frm['tarif_paiement_ht'] et $frm['tva_tarif_paiement']
2008  set_paiement($frm);
2009  $montant = $frm['sub_total'] + vn($frm['tarif_paiement']);
2010  $montant_ht = $frm['sub_total_ht'] + vn($frm['tarif_paiement_ht']);
2011  $total_tva = (vn($montant) + vn($avoir)) - vn($montant_ht);
2012 
2013  // Stockage des informations dans $frm pour envoi ensuite à create_or_update_order
2014  $frm['small_order_overcost_amount'] = $small_order_overcost_amount;
2015  $frm['tva_small_order_overcost'] = $tva_small_order_overcost;
2016  $frm['montant'] = $montant;
2017  $frm['montant_ht'] = $montant_ht;
2018  $frm['total_tva'] = $total_tva;
2019  $frm['total_produit'] = $total_produit;
2020  $frm['total_produit_ht'] = $total_produit_ht;
2021  $frm['tva_total_produit'] = $total_produit - $total_produit_ht;
2022  $frm['total_remise'] = $total_remise;
2023  $frm['total_remise_ht'] = $total_remise_ht;
2024  $frm['tva_total_remise'] = $total_remise - $total_remise_ht;
2025  $frm['cout_transport'] = vn($cout_transport);
2026  $frm['cout_transport_ht'] = vn($cout_transport_ht);
2027  $frm['tva_cout_transport'] = vn($cout_transport) - vn($cout_transport_ht);
2028  $frm['avoir'] = $avoir;
2029  // On crée la commande ou on la met à jour si elle existe déjà
2030  $order_id = create_or_update_order($frm, $articles);
2031  return $order_id;
2032 }
2033 
2044 function get_order_line($line_data, $color_options_html, $size_options_html, $tva_options_html, $i)
2045 {
2046  if (empty($size_options_html)) {
2047  $size_options_html = '<option value="">-</option>';
2048  }
2049  if (empty($color_options_html)) {
2050  $color_options_html = '<option value="">-</option>';
2051  }
2052  if (empty($tva_options_html)) {
2053  $tva_options_html = '<option value="">-</option>';
2054  }
2055 
2057  $prix_cat_displayed = $line_data['prix_cat'];
2058  $purchase_prix_displayed = $line_data['purchase_prix'];
2059  $unit_fixed_remise_displayed = $line_data['remise'];
2060  } else {
2061  $prix_cat_displayed = $line_data['prix_cat_ht'];
2062  $purchase_prix_displayed = $line_data['purchase_prix_ht'];
2063  $unit_fixed_remise_displayed = $line_data['remise_ht'];
2064  }
2065  // Si nous sommes en mode édition de la commande et nous souhaitons réafficher les données sur les produits
2066  if (is_numeric($purchase_prix_displayed)) {
2067  // Prix tout taxe avant remise = prix remisé + remise
2068  // On détermine le montant de la remise fixe en euro($remise_fixed). Pour cela on déduit le montant de la remise % du montant de la remise globale (limite a deux chiffre apres la virgule)
2069  $unit_fixed_remise_displayed = round($unit_fixed_remise_displayed / $line_data['quantite'],2);
2070  }
2071  if (check_if_module_active('attributs')) {
2072  $attribute_display = str_replace("\n", '<br />', display_option_image(vb($line_data['nom_attribut']), true));
2073  }
2074 
2075  $output = tr_rollover($i, true, null, null, 'sortable_'.$i) .'
2076  <td>
2077  <img src="' . $GLOBALS['administrer_url'] . '/images/b_drop.png" alt="'.String::str_form_value($GLOBALS['STR_DELETE']) . '" onclick="bootbox.confirm(\''.filtre_javascript($GLOBALS["STR_ADMIN_PRODUCT_ORDERED_DELETE_CONFIRM"], true, true, true) .'\', function(result) {if(result) {delete_products_list_line(' . $i . ', \'order\');}}); return false;" title="' . String::str_form_value($GLOBALS["STR_ADMIN_PRODUCT_ORDERED_DELETE"]) . '" style="cursor:pointer" />
2078  <input name="giftlist_owners_' . $i . '" type="hidden" value="' . String::str_form_value(vb($line_data['listcadeaux_owner'])) . '" />
2079  <input name="nom_attribut_' . $i . '" type="hidden" value="' . String::str_form_value(vb($line_data['nom_attribut'])) . '" />';
2080  if (check_if_module_active('tnt')) {
2081  $output .= '
2082  <input name="tnt_parcel_number_' . $i . '" type="hidden" value="' . String::str_form_value(vb($line_data['tnt_parcel_number'])) . '" />';
2083  }
2084  $output .= '
2085  </td>
2086  <td>
2087  <input class="form-control" name="id' . $i . '" style="width:100%" type="number" value="' . String::str_form_value(vb($line_data['id'])) . '" />
2088  </td>
2089  <td>
2090  <input class="form-control" id="ref' . $i . '" name="ref' . $i . '" style="width:100%" type="text" value="' . String::str_form_value(vb($line_data['ref'])) . '" />
2091  </td>
2092  <td>
2093  <input class="form-control" type="text" id="l' . $i . '" name="l' . $i . '" style="width:100%" value="' . String::str_form_value($line_data['nom']) . '" />' . (isset($line_data['on_download'])?($line_data['on_download'] == 1?'<br /><a href="' . get_current_url(false) . '?mode=download">'.$GLOBALS["STR_ADMIN_PRODUITS_NUMERIC_PRODUCT_SEND"].'</a>':''):'') . '
2094  </td>
2095  <td id="s' . $i . '" class="center"><select style="width:64px" name="size_' . $i . '" class="form-control">' . $size_options_html . '</select></td>
2096  <td id="c' . $i . '" class="center"><select style="width:64px" name="color_' . $i . '" class="form-control">' . $color_options_html . '</select></td>
2097  <td><input class="form-control" type="number" name="q' . $i . '" style="width:100%" value="' . String::str_form_value($line_data['quantite']) . '" id="q' . $i . '" /></td>
2098  <td><input class="form-control" type="text" name="p_cat' . $i . '" style="width:100%" value="' . String::str_form_value($prix_cat_displayed) . '" id="p_cat' . $i . '" onkeyup="order_line_calculate(' . $i . ', \'percentage\');" /></td>
2099  <td><input class="form-control" type="text" name="remis' . $i . '" style="width:100%" value="' . String::str_form_value($unit_fixed_remise_displayed) . '" id="remis' . $i . '" onkeyup="order_line_calculate(' . $i . ', \'amount\');" /></td>
2100  <td><input class="form-control" type="text" name="perc' . $i . '" style="width:100%" value="' . String::str_form_value($line_data['percent']) . '" id="perc' . $i . '" onkeyup="order_line_calculate(' . $i . ', \'percentage\');" /></td>
2101  <td><input class="form-control" type="text" name="p' . $i . '" style="width:100%" value="' . String::str_form_value($purchase_prix_displayed) . '" id="p' . $i . '" onkeyup="order_line_calculate(' . $i . ', \'final\');" /></td>
2102  <td id="t' . $i . '">
2103  <select name="t' . $i . '" class="form-control">' . $tva_options_html . '</select>
2104  </td>
2105  <td> ' . vb($attribute_display) . ' </td>';
2106  $output .= '
2107  <td>';
2108  if (!empty($line_data['image'])) {
2109  $output .= '
2110  <a target="_image" href="' . String::str_form_value($GLOBALS['repertoire_upload'].'/'.$line_data['image']) . '"><img src="' . $line_data['image_thumbs'] . '" alt="'.String::str_form_value($line_data['nom']) . '" /></a>';
2111  }
2112  $output .= '
2113  </td>
2114 ';
2115  $output .= '
2116  </tr>
2117 ';
2118 
2119  return $output;
2120 }
2121 
2128 {
2129  $countResultats = 0;
2130  $width = array();
2131  $width['date'] = 12;
2132  $width['login'] = 8;
2133  $width['action'] = 10;
2134  $width['raison'] = 5;
2135  $width['remarque'] = 25;
2136  $width['data'] = 25;
2137  $output = '';
2138  $q = query('SELECT a.id_user, a.id_membre, a.action, a.data, a.raison, a.remarque, a.date, u.id_utilisateur, u.pseudo, u.email
2139  FROM peel_admins_actions a
2140  LEFT JOIN peel_utilisateurs u ON u.id_utilisateur=a.id_user AND ' . get_filter_site_cond('utilisateurs', 'u') . '
2141  WHERE a.id_membre="' . intval($user_id) . '" AND ' . get_filter_site_cond('admins_actions', 'a') . '
2142  ORDER BY a.date DESC
2143  LIMIT 500');
2144  while ($res = fetch_assoc($q)) {
2145  if ($countResultats == 0) {
2146  $output .= '
2147  <table style="background-color:#FFFFFF; border:1px; width:100%">
2148  <tr>
2149  <th class="menu" style="width:' . $width['date'] . '%;">'.$GLOBALS['STR_DATE'].'</th>
2150  <th class="menu" style="width:' . $width['login'] . '%;">'.$GLOBALS['STR_BY'].'</th>
2151  <th class="menu" style="width:' . $width['action'] . '%;">'.$GLOBALS['STR_ADMIN_ACTION'].'</th>
2152  <th class="menu" style="width:' . $width['data'] . '%;">'.$GLOBALS['STR_ADMIN_ADMIN_ACTIONS_DATA'].'</th>
2153  <th class="menu" style="width:' . $width['raison'] . '%;">'.$GLOBALS['STR_ADMIN_REASON'].'</th>
2154  <th class="menu" style="width:' . $width['remarque'] . '%;">'.$GLOBALS['STR_COMMENTS'].'</th>
2155  </tr>';
2156  }
2157 
2158  $texte = nl2br($res['remarque']);
2159 
2160  if ($res['data'] != "" && $res['action'] == 'SEND_EMAIL') {
2161  // Si un template a été envoyé, alors on récupère le contenu de ce template
2162  $data = explode('_', $res['data']);
2163  if (count($data) == 2) {
2164  $template_id = $data[1];
2165  if (is_numeric($template_id)) {
2166  $result_template = query('SELECT name
2167  FROM peel_email_template
2168  WHERE id="' . intval($template_id) . '" AND ' . get_filter_site_cond('email_template', null) . '
2169  LIMIT 1');
2170  $template_text = fetch_assoc($result_template);
2171  $res['data'] = '<b>'.$GLOBALS['STR_ADMIN_EMAIL_TEMPLATE'].'</b> : <br />' . (strpos($res['remarque'], $GLOBALS['STR_ADMIN_MUTIPLE_SENDING']) !== false?'<i style="color:red;">'.$GLOBALS['STR_ADMIN_MUTIPLE_SENDING'].'</i><br />':'') . $template_text["name"];
2172  }
2173  }
2174  }
2175 
2176  $output .= '
2177  <tr' . (($countResultats % 2) ? '' : ' class="line"') . '>
2178  <td class="center">' . strftime('%d/%m/%Y %H:%M:%S', strtotime($res['date'])) . '</td>
2179  <td class="center">' . (!empty($res['pseudo'])?$res['pseudo']:$res['email']) . '</td>
2180  <td class="center">' . $res['action'] . '</td>
2181  <td class="center">' . $res['data'] . '</td>
2182  <td class="center">' . $res['raison'] . '</td>
2183  <td class="justify">' . htmlspecialchars($res['remarque']) . '</td>
2184  </tr>';
2185  $countResultats++;
2186  }
2187  if ($countResultats > 0) {
2188  $output .= '</table>';
2189  } else {
2190  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_NO_ADMIN_ACTION_FOUND_FOR_THIS_USER']))->fetch();
2191  }
2192  return $output;
2193 }
2194 
2209 function tracert_history_admin($member_id, $action, $data, $remarque = null, $raison = null)
2210 {
2211  query('INSERT INTO peel_admins_actions(id_user, action, id_membre, data, remarque, raison, date, site_id)
2212  VALUES("' . intval($_SESSION['session_utilisateur']['id_utilisateur']) . '", "' . nohtml_real_escape_string($action) . '", "' . intval(vn($member_id)) . '", "' . nohtml_real_escape_string($data) . '", "' . nohtml_real_escape_string($remarque) . '", "' . nohtml_real_escape_string($raison) . '", "' . date('Y-m-d H:i:s', time()) . '", "' . nohtml_real_escape_string(get_site_id_sql_set_value(vb($GLOBALS['site_id']))) . '")');
2213 }
2214 
2221 function affiche_recherche_connexion_user($frm = null, $display_search_form = true)
2222 {
2223  $sql_inner = '';
2224  $sql_cond = '';
2225  if (!empty($frm)) {
2226  if (!empty($frm['client_info'])) {
2227  $sql_cond .= ' AND (u.pseudo LIKE "%' . nohtml_real_escape_string($frm['client_info']) . '%")';
2228  $sql_inner .= ' INNER JOIN peel_utilisateurs u ON c.user_id=u.id_utilisateur AND ' . get_filter_site_cond('utilisateurs', 'u') . '';
2229  }
2230  if (!empty($frm['user_ip'])) {
2231  $sql_cond .= ' AND CONCAT(FLOOR(c.user_ip/(256*256*256)), ".", (FLOOR(c.user_ip/(256*256)))%256, ".", (FLOOR(c.user_ip/256))%256, ".", c.user_ip%256) LIKE "%' . nohtml_real_escape_string($frm['user_ip']) . '%"';
2232  }
2233  if (!empty($frm['user_id'])) {
2234  $sql_cond .= ' AND c.user_id="' . nohtml_real_escape_string($frm['user_id']) . '"';
2235  }
2236  if (!empty($frm['date'])) {
2237  $sql_cond .= ' AND c.date LIKE "%' . nohtml_real_escape_string(date('Y-m-d', strtotime(str_replace('/', '-', $frm['date'])))) . '%"';
2238  }
2239  }
2240  $sql = "SELECT c.*
2241  FROM peel_utilisateur_connexions c
2242  " . $sql_inner . "
2243  WHERE 1 " . $sql_cond . " AND " . get_filter_site_cond('utilisateur_connexions', 'c') . "";
2244 
2245  $Links = new Multipage($sql, 'affiche_liste_connexion_user');
2246  $HeaderTitlesArray = array('id' => $GLOBALS["STR_ADMIN_ID"], 'date' => $GLOBALS['STR_DATE'], 'user_ip' => $GLOBALS["STR_ADMIN_REMOTE_ADDR"]);
2247  if (check_if_module_active('geoip')) {
2248  if (!class_exists('geoIP')) {
2249  include_once($GLOBALS['dirroot'] . '/modules/geoip/class/geoIP.php');
2250  }
2251  $geoIP = new geoIP();
2252  $HeaderTitlesArray[] = $GLOBALS['STR_COUNTRY']. '-IP';
2253  $HeaderTitlesArray[] = $GLOBALS['STR_COUNTRY'];
2254  }
2255  if(check_if_module_active('annonces')) {
2256  $HeaderTitlesArray[] = $GLOBALS["STR_MODULE_ANNONCES_ADS"];
2257  }
2258  $HeaderTitlesArray['user_login'] = $GLOBALS["STR_ADMIN_LOGIN"];
2259  $HeaderTitlesArray['user_id'] = $GLOBALS["STR_ADMIN_USER"];
2260  $Links->HeaderTitlesArray = $HeaderTitlesArray;
2261  $Links->OrderDefault = 'id';
2262  $Links->SortDefault = 'DESC';
2263  $results_array = $Links->Query();
2264  if (!empty($results_array)) {
2265  // Affichage des connexions en liste
2266  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_connexion_user_liste.tpl');
2267  $tpl->assign('action', get_current_url(false));
2268  $tpl->assign('date', vb($_GET['date']));
2269  $tpl->assign('user_ip', vb($_GET['user_ip']));
2270  if (empty($GLOBALS['site_parameters']['pseudo_is_not_used'])) {
2271  $tpl->assign('client_info', vb($_GET['client_info']));
2272  $tpl->assign('STR_PSEUDO', $GLOBALS['STR_PSEUDO']);
2273  }
2274  $tpl->assign('user_id', vb($_GET['user_id']));
2275  $tpl->assign('action_maj', get_current_url(false) . '?mode=maj_statut');
2276  $tpl->assign('form_token', get_form_token_input($_SERVER['PHP_SELF']));
2277  $tpl->assign('display_search_form', $display_search_form);
2278 
2279  if (!empty($results_array)) {
2280  $tpl_results = array();
2281  $tpl->assign('links_header_row', $Links->getHeaderRow());
2282 
2283  $i = 0;
2284  foreach ($results_array as $connexion) {
2285  $current_user = get_user_information($connexion['user_id'], true);
2286  $tpl_result = array('id' => $connexion['id'],
2287  'date' => get_formatted_date($connexion['date'], 'short', true),
2288  'ip' => (!a_priv('demo') ? long2ip($connexion['user_ip']): '0.0.0.0 [demo]'),
2289  'user_id' => (!a_priv('demo')?'<a href="' . $GLOBALS['administrer_url'] . '/utilisateurs.php?mode=modif&amp;id_utilisateur=' . intval($connexion['user_id']) . '">'.$connexion['user_id'].'</a>':'private [demo]'),
2290  'prenom' => vb($current_user['prenom']),
2291  'nom_famille' => vb($current_user['nom_famille']),
2292  'user_login_displayed' => (!a_priv('demo')?(vb($current_user['etat'])?'<a href="' . $GLOBALS['administrer_url'] . '/utilisateurs.php?mode=modif&amp;id_utilisateur=' . intval($connexion['user_id']) . '">'.$connexion['user_login'].'</a>':'<span style="color:#AAAAAA">'.$connexion['user_login'].'</span>'):'private [demo]')
2293  );
2294  $rollover_style = null;
2295  if(!empty($geoIP)) {
2296  $country_id = $geoIP->geoIPCountryIDByAddr(long2ip($connexion['user_ip']));
2297  foreach(array('country_ip' => $country_id, 'country_account' => vn($current_user['pays'])) as $this_key => $this_value) {
2298  $sql = 'SELECT iso, pays_' . $_SESSION['session_langue'] . '
2299  FROM peel_pays
2300  WHERE id="' . intval($this_value) . '" AND ' . get_filter_site_cond('pays') . '
2301  LIMIT 1';
2302  $query = query($sql);
2303  if ($result = fetch_assoc($query)) {
2304  $tpl_result[$this_key] = getFlag($result['iso'], $result['pays_' . $_SESSION['session_langue']]);
2305  } else {
2306  $tpl_result[$this_key] = '?';
2307  }
2308  }
2309  if($country_id != $current_user['pays']) {
2310  $rollover_style = 'background-color:#FFAAAA';
2311  }
2312  }
2313  if(check_if_module_active('annonces')) {
2314  $tpl_result['active_ads_count'] = $current_user['active_ads_count'];
2315  }
2316  $tpl_result['tr_rollover'] = tr_rollover($i, true, $rollover_style);
2317  $tpl_results[] = $tpl_result;
2318  $i++;
2319  }
2320  if (!empty($geoIP)) {
2321  $geoIP->geoIPClose();
2322  }
2323  $tpl->assign('results', $tpl_results);
2324  $tpl->assign('links_multipage', $Links->GetMultipage());
2325  }
2326  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
2327  $tpl->assign('STR_ADMIN_CONNEXION_USER_TITLE', $GLOBALS['STR_ADMIN_CONNEXION_USER_TITLE']);
2328  $tpl->assign('STR_ADMIN_DATE', $GLOBALS['STR_ADMIN_DATE']);
2329  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
2330  $tpl->assign('STR_ADMIN_REMOTE_ADDR', $GLOBALS['STR_ADMIN_REMOTE_ADDR']);
2331  $tpl->assign('STR_ADMIN_USER', $GLOBALS['STR_ADMIN_USER']);
2332  $tpl->assign('STR_SEARCH', $GLOBALS['STR_SEARCH']);
2333  $tpl->assign('STR_ADMIN_CONNEXION_NOTHING_FOUND', $GLOBALS['STR_ADMIN_CONNEXION_NOTHING_FOUND']);
2334  return $tpl->fetch();
2335  } else {
2336  return $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['STR_ADMIN_NO_RESULT']))->fetch();
2337  }
2338 }
2339 
2345 function affiche_phone_event($user_id)
2346 {
2347  $countResultats = 0;
2348  $width = array();
2349  $width['date'] = 12;
2350  $width['login'] = 8;
2351  $width['action'] = 10;
2352  $width['raison'] = 5;
2353  $width['remarque'] = 25;
2354  $width['data'] = 25;
2355  $output = '';
2356  $q = query('SELECT paa.*,u.pseudo AS pseudo_membre
2357  FROM peel_admins_actions paa
2358  LEFT JOIN peel_utilisateurs u ON u.id_utilisateur= ' . intval($user_id) . ' AND ' . get_filter_site_cond('utilisateurs', 'u') . '
2359  WHERE paa.id_user= ' . intval($_SESSION['session_utilisateur']['id_utilisateur']) . ' AND paa.id_membre = ' . intval($user_id) . ' AND ((paa.action = "PHONE_EMITTED") OR (paa.action = "PHONE_RECEIVED")) AND paa.data="NOT_ENDED_CALL" AND ' . get_filter_site_cond('admins_actions', 'paa') . '
2360  ORDER BY paa.date DESC
2361  LIMIT 1');
2362  $res = fetch_assoc($q);
2363  $output = '
2364  <form class="entryform form-inline" method="post" id="phone" action="' . get_current_url(false) . '#phone_section" >
2365  <input type="hidden" name="mode" value="phone_call" />
2366  <input type="hidden" name="id_utilisateur" value="' . intval($user_id) . '" />';
2367  if (!empty($res)) {
2368  // warning : phone call not ended;
2369  $output .= '
2370  <hr /><h2 id="phone_section" style="color:green">' . sprintf(($res['action'] == 'PHONE_EMITTED'?$GLOBALS["STR_ADMIN_UTILISATEURS_CALL_STARTED_EMITTED"]:$GLOBALS["STR_ADMIN_UTILISATEURS_CALL_STARTED_RECEIVED"]), vb($res['pseudo_membre'])) . ' : '.$GLOBALS["STR_ADMIN_UTILISATEURS_CALL_STARTED_ON"].' ' . get_formatted_date($res['date']) . '</h2>
2371  <br />
2372  <center>
2373  <table class="full_width">
2374  <tr>
2375  <th>'.$GLOBALS["STR_COMMENTS"].'</th>
2376  <td class="center">
2377  <textarea class="form-control" name="form_phone_comment" rows="5" cols="50" id="phone_comment" >' . (!empty($res['remarque'])?vb($res['remarque']):'') . '</textarea>
2378  </td>
2379  </tr>
2380  <tr>
2381  <td></td>
2382  <td class="center"><input name="turn_off_phone" type="submit" value="'.$GLOBALS["STR_ADMIN_UTILISATEURS_CALL_CLOSE"].'" class="btn btn-primary" /></td>
2383  </tr>
2384  </table>
2385  </center>';
2386  } else {
2387  $output .= '
2388  <h2 id="phone_section">'.$GLOBALS["STR_ADMIN_UTILISATEURS_MANAGE_CALLS"].'</h2>
2389  <center>
2390  <table >
2391  <tr>
2392  <th>'.$GLOBALS["STR_COMMENTS"].'</th>
2393  </tr>
2394  <tr>
2395  <td class="center">
2396  <textarea class="form-control" name="form_phone_comment" rows="5" cols="50" id="phone_comment" >' . (!empty($_POST['phone_comment'])?$_POST['phone_comment']:'') . '</textarea>
2397  </td>
2398  </tr>
2399  </table>
2400  <table >
2401  <tr>
2402  <td class="center" style="width:50%;">
2403  <table class="full_width">
2404  <tr>
2405  <td class="center"><input name="phone_emitted_submit" type="submit" value="'.$GLOBALS["STR_ADMIN_UTILISATEURS_CALL_INITIATE"].'" class="btn btn-primary" /></td>
2406  </tr>
2407  </table>
2408  </td>
2409  <td class="center" style="width:50%;">
2410  <table class="full_width">
2411  <tr>
2412  <td class="center"><input name="phone_received_submit" type="submit" value="'.$GLOBALS["STR_ADMIN_UTILISATEURS_CALL_RECEIVED_INITIATE"].'" class="btn btn-primary" /></td>
2413  </tr>
2414  </table>
2415  </td>
2416  </tr>
2417  </table>
2418  </center>';
2419  }
2420  $output .= '
2421  </form>';
2422  return $output;
2423 }
2424 
2431 function getClientNote(&$user_infos)
2432 {
2433  // $tabseg = array('seg_buy', 'seg_want', 'seg_think', 'seg_followed', 'seg_who');
2434  $tabSeg['seg_buy'] = tab_buy_seg();
2435  $tabSeg['seg_want'] = tab_want_seg();
2436  $tabSeg['seg_who'] = tab_who_seg();
2437  $tabSeg['seg_followed'] = tab_followed_seg();
2438  $tabSeg['seg_think'] = tab_think_seg();
2439  $points = 0;
2440  foreach(array('seg_buy', 'seg_want', 'seg_think', 'seg_followed', 'seg_who') as $this_field) {
2441  if (!isset($user_infos[$this_field]) || !isset($tabSeg[$this_field][$user_infos[$this_field]])) {
2442  return null;
2443  } elseif ($tabSeg[$this_field][$user_infos[$this_field]] == 0) {
2444  // Tout 0 implique que le résultat vaut 0
2445  return 0;
2446  } else {
2447  $points += $tabSeg[$this_field][$user_infos[$this_field]];
2448  }
2449  }
2450  return $points;
2451 }
2452 
2457 function tab_who()
2458 {
2459  return array('independant' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_INDEPENDANT"],
2460  'partner' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_PARTNER"],
2461  'company_small' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_COMPANY_SMALL"],
2462  'company_medium' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_COMPANY_MEDIUM"],
2463  'company_big' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_COMPANY_BIG"],
2464  'person' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_PERSON"],
2465  'no_info' => $GLOBALS["STR_ADMIN_UTILISATEURS_WHO_NO_INFO"]);
2466 }
2467 
2472 function tab_who_seg()
2473 {
2474  return array('independant' => 2,
2475  'partner' => 5,
2476  'company_small' => 4,
2477  'company_medium' => 5,
2478  'company_big' => 3,
2479  'person' => 3,
2480  'no_info' => 3);
2481 }
2486 function tab_buy()
2487 {
2488  return array('one_old' => $GLOBALS["STR_ADMIN_UTILISATEURS_BUY_ONE_OLD"],
2489  'one_recent' => $GLOBALS["STR_ADMIN_UTILISATEURS_BUY_ONE_RECENT"],
2490  'multi_old' => $GLOBALS["STR_ADMIN_UTILISATEURS_BUY_MULTI_OLD"],
2491  'multi_recent' => $GLOBALS["STR_ADMIN_UTILISATEURS_BUY_MULTI_RECENT"],
2492  'no_info' => $GLOBALS["STR_ADMIN_UTILISATEURS_BUY_NO_INFO"]);
2493 }
2494 
2499 function tab_buy_seg()
2500 {
2501  return array('no' => 16,
2502  'one_old' => 20,
2503  'one_recent' => 20,
2504  'multi_old' => 18,
2505  'multi_recent' => 18,
2506  'no_info' => 18);
2507 }
2508 
2513 function tab_want()
2514 {
2515  return array('min_contact' => $GLOBALS["STR_ADMIN_UTILISATEURS_WANTS_MIN_CONTACT"],
2516  'max_contact' => $GLOBALS["STR_ADMIN_UTILISATEURS_WANTS_MAX_CONTACT"],
2517  'no_matter' => $GLOBALS["STR_ADMIN_UTILISATEURS_WANTS_NO_MATTER"],
2518  'no_info' => $GLOBALS["STR_ADMIN_UTILISATEURS_WANTS_NO_INFO"]);
2519 }
2520 
2525 function tab_want_seg()
2526 {
2527  return array('min_contact' => 0,
2528  'max_contact' => 25,
2529  'no_matter' => 10,
2530  'no_info' => 15);
2531 }
2532 
2537 function tab_think()
2538 {
2539  return array('never_budget' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_NEVER_BUDGET"],
2540  'no_budget' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_NO_BUDGET"],
2541  'unsatisfied' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_UNSATISFIED"],
2542  'satisfied' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_SATISFIED"],
2543  'not_interested' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_NOT_INTERESTED"],
2544  'interested' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_INTERESTED"],
2545  'newbie' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_NEWBIE"],
2546  'no_matter' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_NO_MATTER"],
2547  'no_info' => $GLOBALS["STR_ADMIN_UTILISATEURS_THINKS_NO_INFO"]
2548  );
2549 }
2550 
2555 function tab_think_seg()
2556 {
2557  return array('never_budget' => 4,
2558  'no_budget' => 6,
2559  'unsatisfied' => 6,
2560  'satisfied' => 6,
2561  'not_interested' => 0,
2562  'interested' => 20,
2563  'newbie' => 8,
2564  'no_matter' => 0,
2565  'no_info' => 20);
2566 }
2567 
2572 function tab_followed()
2573 {
2574  return array('no' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_NO"],
2575  'poor' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_POOR"],
2576  'correct' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_CORRECT"],
2577  'no_info' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_NO_INFO"]
2578  );
2579 }
2580 
2586 {
2587  return array('no' => 6,
2588  'poor' => 4,
2589  'correct' => 3,
2590  'no_info' => 4);
2591 }
2592 
2598 {
2599  return array('1' => $GLOBALS["STR_YES"],
2600  '0' => $GLOBALS["STR_NO"]);
2601 }
2602 
2608 {
2609  return array('YES' => 'Compte normal YES',
2610  'PROSP' => 'Compte PROSPECT',
2611  'AGENT' => 'Compte AGENT',
2612  'NO' => 'Compte non valide NO');
2613 }
2614 
2620 {
2621  return array('never' => $GLOBALS["STR_ADMIN_UTILISATEURS_SEARCH_SUBSCRIPTION_NEVER"],
2622  'no' => $GLOBALS["STR_ADMIN_UTILISATEURS_SEARCH_SUBSCRIPTION_NOT_NOW"],
2623  'earlier' => $GLOBALS["STR_ADMIN_UTILISATEURS_SEARCH_SUBSCRIPTION_NOT_NOW_BUT_EARLIER"],
2624  'any' => $GLOBALS["STR_ADMIN_UTILISATEURS_SEARCH_SUBSCRIPTION_ALL"],
2625  'platinum_until' => $GLOBALS["STR_MODULE_ABONNEMENT_PLATINUM"],
2626  'diamond_until' => $GLOBALS["STR_MODULE_ABONNEMENT_DIAMOND"]);
2627 }
2628 
2634 {
2635  $result = array('-1' => $GLOBALS["STR_ADMIN_UTILISATEURS_SEARCH_PRODUCTS_NEVER_BOUGHT"]);
2636  for($i=1; $i<=12; $i++) {
2637  $result[$i] = sprintf($GLOBALS["STR_ADMIN_UTILISATEURS_SEARCH_PRODUCTS_AT_LEAST_N"], $i);
2638  }
2639  return $result;
2640 }
2641 
2647 {
2648  return array('' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_REASON_INDIFFERENT"],
2649  'interesting_profile' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_REASON_INTERESTING_PROFILE"],
2650  'interested_by_product' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_REASON_INTERESTED_BY_PRODUCT"],
2651  'payment_expected' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_REASON_PAYMENT_EXPECTED"],
2652  'follow_up' => $GLOBALS["STR_ADMIN_UTILISATEURS_FOLLOWED_REASON_FOLLOW_UP"]);
2653 }
2654 
2663 function insere_langue($frm, $try_alter_table_even_if_modules_not_active = true, $force_update_database_lang_content = false)
2664 {
2665  $output = '';
2666  $new_lang = String::strtolower($frm['lang']);
2667  if (empty($new_lang) || String::strlen($new_lang) != 2) {
2668  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS["STR_ADMIN_LANGUES_ERR_LANGUAGE_TWO_CHARS"]))->fetch();
2669  return $output;
2670  }
2671  $sql = "SELECT *
2672  FROM peel_langues
2673  WHERE lang='" . word_real_escape_string($new_lang) . "'";
2674  if (num_rows(query($sql))) {
2675  // La langue existe déjà : on se met automatiquement en mode réparation des tables pour créer d'éventuelles colonnes manquantes
2676  $repair = true;
2677  // Par ailleurs on fera une insertion des infos de la langue spécifiquement au site demandé si nécessaire
2678  } else {
2679  $repair = false;
2680  }
2681 
2682  unset($query_alter_table);
2683  // On prépare ci-dessous la liste des modifications de base de données relatives à une langue donnée
2684  // A FAIRE EN CAS DE NOUVELLES TABLES : Ajouter les ALTER TABLE à la suite pour ajouter les champs de langues dans les différentes tables souhaitées.
2685  $query_alter_table[] = 'ALTER TABLE `peel_access_map` ADD `text_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2686  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('affiliation')) {
2687  $query_alter_table[] = 'ALTER TABLE `peel_affiliation` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2688  $query_alter_table[] = 'ALTER TABLE `peel_affiliation` ADD `texte_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2689  }
2690  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('attributs')) {
2691  $query_alter_table[] = 'ALTER TABLE `peel_attributs` ADD `descriptif_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2692  }
2693  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `surtitre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2694  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2695  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `texte_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2696  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `chapo_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2697  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2698  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `meta_key_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2699  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2700  if(!in_array('titre_'.$new_lang, get_table_index('peel_articles', null, true))) {
2701  $query_alter_table[] = 'ALTER TABLE `peel_articles` ADD INDEX (`titre_' . word_real_escape_string($new_lang) . '`)';
2702  }
2703  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2704  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2705  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2706  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `meta_key_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2707  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2708  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `header_html_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2709  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `image_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2710  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `alpha_' . word_real_escape_string($new_lang) . '` CHAR( 1 ) NOT NULL DEFAULT ""';
2711  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD `sentence_displayed_on_product_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2712  if(!in_array('nom_'.$new_lang, get_table_index('peel_categories', null, true))) {
2713  $query_alter_table[] = 'ALTER TABLE `peel_categories` ADD INDEX (`nom_' . word_real_escape_string($new_lang) . '`)';
2714  }
2715  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('annonces')) {
2716  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `alpha_' . word_real_escape_string($new_lang) . '` CHAR( 1 ) NOT NULL DEFAULT ""';
2717  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 100 ) NOT NULL DEFAULT ""';
2718  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2719  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `image_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2720  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2721  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2722  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `meta_key_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2723  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `header_html_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2724  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `presentation_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2725  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD `presentation2_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2726  if(!in_array('nom_'.$new_lang, get_table_index('peel_categories_annonces', null, true))) {
2727  $query_alter_table[] = 'ALTER TABLE `peel_categories_annonces` ADD INDEX (`nom_' . word_real_escape_string($new_lang) . '`)';
2728  }
2729  }
2730  $query_alter_table[] = 'ALTER TABLE `peel_cgv` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2731  $query_alter_table[] = 'ALTER TABLE `peel_cgv` ADD `texte_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2732  $query_alter_table[] = 'ALTER TABLE `peel_contacts` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2733  $query_alter_table[] = 'ALTER TABLE `peel_contacts` ADD `texte_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2734  $query_alter_table[] = 'ALTER TABLE `peel_couleurs` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2735  $query_alter_table[] = 'ALTER TABLE `peel_continents` ADD `name_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2736  $query_alter_table[] = 'ALTER TABLE `peel_ecotaxes` ADD `nom_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2737  $query_alter_table[] = 'ALTER TABLE `peel_email_template_cat` ADD `name_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2738  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('stock_advanced')) {
2739  $query_alter_table[] = 'ALTER TABLE `peel_etatstock` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2740  }
2741  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('faq')) {
2742  $query_alter_table[] = 'ALTER TABLE `peel_faq` ADD `question_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2743  $query_alter_table[] = 'ALTER TABLE `peel_faq` ADD `answer_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2744  }
2745  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('annonces')) {
2746  $query_alter_table[] = 'ALTER TABLE `peel_gold_ads` ADD `text_intro_' . word_real_escape_string($new_lang) . '` VARCHAR( 80 ) NOT NULL DEFAULT ""';
2747  }
2748  $query_alter_table[] = 'ALTER TABLE `peel_import_field` ADD `texte_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2749  $query_alter_table[] = 'ALTER TABLE `peel_langues` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2750  $query_alter_table[] = 'ALTER TABLE `peel_legal` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2751  $query_alter_table[] = 'ALTER TABLE `peel_legal` ADD `texte_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2752  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('lexique')) {
2753  $query_alter_table[] = 'ALTER TABLE `peel_lexique` ADD `word_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2754  $query_alter_table[] = 'ALTER TABLE `peel_lexique` ADD `definition_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2755  $query_alter_table[] = 'ALTER TABLE `peel_lexique` ADD `meta_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2756  $query_alter_table[] = 'ALTER TABLE `peel_lexique` ADD `meta_definition_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2757  }
2758  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('annonces')) {
2759  $query_alter_table[] = 'ALTER TABLE `peel_lot_vente` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2760  $query_alter_table[] = 'ALTER TABLE `peel_lot_vente` ADD `description_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2761  if(in_array('search_fulltext', get_table_index('peel_lot_vente', null, true))) {
2762  // On regénère l'index FULLTEXT sur le colonnes des langues actives
2763  // Attention, cette commande prendra du temps si la table est de taille importante
2764  $query_alter_table[] = 'DROP INDEX `search_fulltext` ON peel_lot_vente';
2765  }
2766  unset($index_array);
2767  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
2768  $index_array[]='titre_'.$lng;
2769  $index_array[]='description_'.$lng;
2770  }
2771  $query_alter_table[] = 'ALTER TABLE `peel_lot_vente` ADD FULLTEXT KEY `search_fulltext` ('.implode(',', real_escape_string($index_array)).')';
2772  }
2773  $query_alter_table[] = 'ALTER TABLE `peel_marques` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2774  $query_alter_table[] = 'ALTER TABLE `peel_marques` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2775  $query_alter_table[] = 'ALTER TABLE `peel_marques` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2776  $query_alter_table[] = 'ALTER TABLE `peel_marques` ADD `meta_key_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2777  $query_alter_table[] = 'ALTER TABLE `peel_marques` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2778  $query_alter_table[] = 'ALTER TABLE `peel_meta` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2779  $query_alter_table[] = 'ALTER TABLE `peel_meta` ADD `meta_key_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2780  $query_alter_table[] = 'ALTER TABLE `peel_meta` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2781  $query_alter_table[] = 'ALTER TABLE `peel_modules` ADD `title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2782  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('attributs')) {
2783  $query_alter_table[] = 'ALTER TABLE `peel_nom_attributs` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2784  }
2785  $query_alter_table[] = 'ALTER TABLE `peel_paiement` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2786  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('parrainage')) {
2787  $query_alter_table[] = 'ALTER TABLE `peel_parrain` ADD `titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2788  $query_alter_table[] = 'ALTER TABLE `peel_parrain` ADD `texte_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2789  }
2790  $query_alter_table[] = 'ALTER TABLE `peel_pays` ADD `pays_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2791  if(!in_array('pays_'.$new_lang, get_table_index('peel_pays', null, true))) {
2792  $query_alter_table[] = 'ALTER TABLE `peel_pays` ADD INDEX (`pays_' . word_real_escape_string($new_lang) . '`)';
2793  }
2794  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2795  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `descriptif_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2796  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2797  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2798  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `meta_key_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2799  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2800  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab1_html_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2801  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab2_html_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2802  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab3_html_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2803  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab4_html_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2804  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab5_html_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2805  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab6_html_' . word_real_escape_string($new_lang) . '` mediumtext NOT NULL';
2806  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab1_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2807  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab2_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2808  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab3_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2809  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab4_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2810  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab5_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2811  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD `tab6_title_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2812  if(!in_array('nom_'.$new_lang, get_table_index('peel_produits', null, true))) {
2813  // Index sur 2 lettres seulement pour éviter de prendre trop de mémoire si bcp de produits
2814  $query_alter_table[] = 'ALTER TABLE `peel_produits` ADD INDEX (`nom_' . word_real_escape_string($new_lang) . '` (2))';
2815  }
2816  $query_alter_table[] = 'ALTER TABLE `peel_profil` ADD `name_' . word_real_escape_string($new_lang) . '` VARCHAR( 100 ) NOT NULL DEFAULT ""';
2817  $query_alter_table[] = 'ALTER TABLE `peel_profil` ADD `description_document_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2818  $query_alter_table[] = 'ALTER TABLE `peel_profil` ADD `document_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2819  $query_alter_table[] = 'ALTER TABLE `peel_rubriques` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2820  $query_alter_table[] = 'ALTER TABLE `peel_rubriques` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2821  $query_alter_table[] = 'ALTER TABLE `peel_rubriques` ADD `meta_titre_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2822  $query_alter_table[] = 'ALTER TABLE `peel_rubriques` ADD `meta_key_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2823  $query_alter_table[] = 'ALTER TABLE `peel_rubriques` ADD `meta_desc_' . word_real_escape_string($new_lang) . '` TEXT NOT NULL';
2824  if(!in_array('nom_'.$new_lang, get_table_index('peel_rubriques', null, true))) {
2825  $query_alter_table[] = 'ALTER TABLE `peel_rubriques` ADD INDEX (`nom_' . word_real_escape_string($new_lang) . '`)';
2826  }
2827  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('vacances')) {
2828  set_configuration_variable(array('technical_code' => 'module_vacances_client_msg_' . word_real_escape_string($new_lang) . '', 'type' => 'string', 'string' => '', 'site_id' => vn($frm['site_id'])), true);
2829  }
2830  $query_alter_table[] = 'ALTER TABLE `peel_statut_paiement` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2831  $query_alter_table[] = 'ALTER TABLE `peel_statut_livraison` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2832  $query_alter_table[] = 'ALTER TABLE `peel_tailles` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2833  $query_alter_table[] = 'ALTER TABLE `peel_types` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2834  $query_alter_table[] = 'ALTER TABLE `peel_zones` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2835  // Ajout de la gestion des langues pour le contenu des newsletters qui sont géré en fonction de la langue définit par l'utilisateur
2836  $query_alter_table[] = 'ALTER TABLE `peel_newsletter` ADD `sujet_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2837  $query_alter_table[] = 'ALTER TABLE `peel_newsletter` ADD `message_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2838 
2839  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('references')) {
2840  $query_alter_table[] = 'ALTER TABLE `peel_references_categories` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2841  $query_alter_table[] = 'ALTER TABLE `peel_references_categories` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2842  $query_alter_table[] = 'ALTER TABLE `peel_references` ADD `descriptif_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2843  }
2844  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('partenaires')) {
2845  $query_alter_table[] = 'ALTER TABLE `peel_partenaires_categories` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2846  $query_alter_table[] = 'ALTER TABLE `peel_partenaires_categories` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2847  }
2848  // Ajout des langues au module vitrine
2849  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('vitrine')) {
2850  $query_alter_table[] = 'ALTER TABLE `peel_vitrine_grossiste` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2851  $query_alter_table[] = 'ALTER TABLE `peel_vitrine_grossiste` ADD `presentation_' . word_real_escape_string($new_lang) . '` text NOT NULL';
2852  }
2853  // Ajout des langues au module vitrine
2854  if ($try_alter_table_even_if_modules_not_active || check_if_module_active('agenda')) {
2855  $query_alter_table[] = 'ALTER TABLE `peel_agenda` ADD `title_event_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2856  $query_alter_table[] = 'ALTER TABLE `peel_agenda` ADD `description_' . word_real_escape_string($new_lang) . '` text NOT NULL';
2857  }
2858  // Ajout des langues au module carrousel
2859  if (check_if_module_active('carrousel')) {
2860  $query_alter_table[] = 'ALTER TABLE `peel_carrousels` ADD `langue_' . word_real_escape_string($new_lang) . '` tinyint(1) NOT NULL DEFAULT "0"';
2861  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `nom_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2862  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `descriptif_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2863  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `description_' . word_real_escape_string($new_lang) . '` MEDIUMTEXT NOT NULL';
2864  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `image1_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2865  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `image2_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2866  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `image3_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2867  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `lien1_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2868  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `lien2_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2869  $query_alter_table[] = 'ALTER TABLE `peel_vignettes_carrousels` ADD `lien3_' . word_real_escape_string($new_lang) . '` VARCHAR( 255 ) NOT NULL DEFAULT ""';
2870  }
2871  $created = 0;
2872  foreach ($query_alter_table as $this_alter_table) {
2873  // Si une colonne existe déjà, on n'affiche pas de message d'erreur si on est en mode réparation, sinon un message d'erreur va s'afficher mais de toutes façons on ne s'arrête pas
2874  $result = query($this_alter_table, false, null, true);
2875  if($result) {
2876  //var_dump($this_alter_table);
2877  $created++;
2878  }
2879  }
2880  $sql = "SELECT *
2881  FROM peel_langues
2882  WHERE lang = '" . word_real_escape_string($new_lang) . "' AND " . get_filter_site_cond('langues', null, false, vb($frm['site_id']), true) . "";
2883  $query = query($sql);
2884  if(!fetch_assoc($query)) {
2885  // La langue n'existe pas pour le site_id donné, on la crée en BDD
2886  if(empty($frm['flag'])) {
2887  if(!empty($GLOBALS['langs_flags_correspondance'][$new_lang])){
2888  $frm['flag'] = $GLOBALS['langs_flags_correspondance'][$new_lang];
2889  } else {
2890  $frm['flag'] = '/images/'.$new_lang.'.png';
2891  }
2892  }
2893  if(!isset($frm['etat'])) {
2894  $frm['etat'] = 1;
2895  }
2896  $sql = "INSERT INTO peel_langues (
2897  lang
2898  , site_id
2899  , flag
2900  , etat
2901  , url_rewriting
2902  , position";
2903  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
2904  if(!empty($frm['nom_' . $lng])) {
2905  $sql .= ", nom_" . $lng;
2906  }
2907  }
2908  $sql .= "
2909  ) VALUES (
2910  '" . word_real_escape_string($new_lang) . "'
2912  , '" . nohtml_real_escape_string(vb($frm['flag'])) . "'
2913  , '" . intval(vb($frm['etat'])) . "'
2914  , '" . nohtml_real_escape_string(vb($frm['url_rewriting'])) . "'
2915  , '" . intval(vb($frm['position'])) . "'";
2916  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
2917  if(!empty($frm['nom_' . $lng])) {
2918  $sql .= ", '" . nohtml_real_escape_string(vb($frm['nom_' . $lng])) . "'";
2919  }
2920  }
2921  $sql .= "
2922  )";
2923 
2924  query($sql);
2925  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => sprintf($GLOBALS['STR_ADMIN_LANGUES_MSG_LANGUAGE_CREATED'], (!empty($GLOBALS['lang_names'][$new_lang])?'"' . $GLOBALS['lang_names'][$new_lang] . '"':'"' . $new_lang . '"'))))->fetch();
2926  }
2927  if(!$repair || $force_update_database_lang_content) {
2928  // Import des données relatives à la langue créée
2929  $database_import_content = array(array('continents' => 'name'), array('pays' => 'pays'), array('ecotaxes' => 'nom'), array('email_template_cat' => 'name'), array('email_template' => 'name'), array('email_template' => 'subject'), array('email_template' => 'text'), array('etatstock' => 'nom'), array('langues' => 'nom'), array('import_field' => 'texte'), array('modules' => 'title'), array('paiement' => 'nom'), array('profil' => 'name'), array('statut_livraison' => 'nom'), array('statut_paiement' => 'nom'), array('types' => 'nom'), array('zones' => 'nom'));
2930  if(!is_bool($force_update_database_lang_content) && !is_array($force_update_database_lang_content) && String::strlen($force_update_database_lang_content)>1) {
2931  $force_update_database_lang_content = array($force_update_database_lang_content);
2932  }
2933  } else {
2934  // Par défaut, on rétablit le nom des langues qui seraient vides
2935  $database_import_content = array(array('langues' => 'nom'));
2936  }
2937  if(!empty($database_import_content)) {
2938  foreach($database_import_content as $this_field_prefix_array) {
2939  foreach($this_field_prefix_array as $this_table_short_name => $this_field_prefix) {
2940  if(is_array($force_update_database_lang_content) && !in_array($this_table_short_name, $force_update_database_lang_content)) {
2941  // On ne veut construire les contenus que pour les tables listées dans $force_update_database_lang_content
2942  continue;
2943  }
2944  $table_field_names = get_table_field_names('peel_' . $this_table_short_name, null, true);
2945  if(!empty($table_field_names)) {
2946  // Si la langue n'est pas trouvée, on prend par défaut en priorité anglais, sinon français
2947  $languages_for_files_tried = array($new_lang, 'en', 'fr');
2948  foreach($languages_for_files_tried as $tried_file_lang) {
2949  $database_file_name = $GLOBALS['dirroot'] . '/lib/lang/database_'.$this_table_short_name.'_'.$this_field_prefix.'_'.$tried_file_lang.'.php';
2950  if(file_exists($database_file_name)){
2951  break;
2952  } else {
2953  $database_file_name = $GLOBALS['dirroot'] . '/lib/lang/database_'.$this_table_short_name.'_'.$tried_file_lang.'.php';
2954  if(file_exists($database_file_name)){
2955  break;
2956  }
2957  }
2958  }
2959  if(file_exists($database_file_name)) {
2960  include ($database_file_name);
2961  $array_name = 'peel_'.$this_table_short_name;
2962  unset($this_array);
2963  if(isset($$array_name)){
2964  $this_array = $$array_name;
2965  }
2966  if(!empty($this_array) && !empty($this_array[$this_field_prefix])){
2967  foreach($this_array[$this_field_prefix] as $this_reference => $this_value) {
2968  unset($sql_set_array);
2969  unset($sql_line_array);
2970  if(in_array($this_table_short_name, array('langues'))) {
2971  $reference_column = 'lang';
2972  } elseif(in_array($this_table_short_name, array('import_field'))) {
2973  $reference_column = 'champs';
2974  } elseif(in_array($this_table_short_name, array('pays'))) {
2975  $reference_column = 'iso3';
2976  } elseif(in_array($this_table_short_name, array('profil'))) {
2977  $reference_column = 'priv';
2978  } elseif(in_array($this_table_short_name, array('etatstock'))) {
2979  $reference_column = 'valeur';
2980  } elseif(in_array($this_table_short_name, array('ecotaxes'))) {
2981  $reference_column = 'code';
2982  } elseif(is_numeric($this_reference)) {
2983  // Il faut laisser ce contrôle à la fin. is_numeric retourne true lors du test sur le champ 'code' de la table ecotaxes.
2984  $reference_column = 'id';
2985  } else {
2986  $reference_column = 'technical_code';
2987  }
2988  if(in_array('lang', $table_field_names) && !in_array($this_table_short_name, array('langues', 'pays'))){
2989  // La table a une colonne lang => on a une ligne par langue
2990  $column_name = $this_field_prefix;
2991  $sql_line_array[] = "lang='".real_escape_string($new_lang)."'";
2992  } else {
2993  // La table a une colonne par langue
2994  $column_name = $this_field_prefix."_".$new_lang;
2995  }
2996  if(in_array($this_table_short_name, array('langues'))) {
2997  $sql_set_array[] = word_real_escape_string($column_name)."=IF(".word_real_escape_string($column_name)."!='',".word_real_escape_string($column_name).",'".real_escape_string($this_value)."')";
2998  } else {
2999  $sql_set_array[] = word_real_escape_string($column_name)."='".real_escape_string($this_value)."'";
3000  }
3001  $sql_line_array[$reference_column] = word_real_escape_string($reference_column)."='".real_escape_string($this_reference)."'";
3002  if(in_array('position', $table_field_names) && $reference_column == 'id' && !in_array($this_table_short_name, array('pays', 'modules'))){
3003  // La table a une colonne lang => on a une ligne par langue
3004  $sql_set_array[] = "position=id";
3005  }
3006  // On cherche à mettre à jour la ligne pour remplir la nouvelle colonne de langue
3007  $sql = "SELECT 1
3008  FROM peel_".word_real_escape_string($this_table_short_name)."
3009  WHERE ".implode(' AND ', $sql_line_array) . " AND " . get_filter_site_cond($this_table_short_name, null, true) . " AND site_id='" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id'])) ."'";
3010  $query = query($sql);
3011  if(fetch_assoc($query)) {
3012  $sql = "UPDATE peel_".word_real_escape_string($this_table_short_name)."
3013  SET ".implode(', ', $sql_set_array)."
3014  WHERE ".implode(' AND ', $sql_line_array) . " AND " . get_filter_site_cond($this_table_short_name, null, true) . " AND site_id='" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id']))."'";
3015  query($sql);
3016  }elseif(!in_array($this_table_short_name, array('langues')) && !empty($this_value)){
3017  if(in_array('etat', $table_field_names)){
3018  // La table a une colonne etat => on a active la ligne
3019  $sql_line_array[] = "etat='1'";
3020  }
3021  if($column_name == $this_field_prefix) {
3022  unset($sql_line_array['id']);
3023  }
3024  $sql_set_array[] = "site_id='".nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id']))."'";
3025  // On crée la ligne si elle est manquante
3026  $sql = "INSERT INTO peel_".word_real_escape_string($this_table_short_name)."
3027  SET ".implode(', ', $sql_set_array);
3028  if(!empty($sql_line_array)){
3029  $sql .= ", ".implode(', ', $sql_line_array);
3030  }
3031  query($sql, false, null, true);
3032  }
3033  }
3034  $imported_texts[] = $this_table_short_name . ' ('.$this_field_prefix.')';
3035  } else {
3036  $not_imported_texts[] = $this_table_short_name . ' ('.$this_field_prefix.')';
3037  }
3038  } else {
3039  $not_imported_texts[] = $this_table_short_name . ' ('.$this_field_prefix.')';
3040  }
3041  }
3042  }
3043  }
3044  $sql = "SELECT url_rewriting
3045  FROM peel_langues
3046  WHERE url_rewriting='' AND lang!='" . real_escape_string($new_lang)."' AND etat=1 AND " . get_filter_site_cond('langues', null, true) . " AND site_id='" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id'])) . "'
3047  LIMIT 1";
3048  $query = query($sql);
3049  if(fetch_assoc($query)) {
3050  // Il y a déjà d'autres langues avec url_rewriting='' => on dit par défaut que cette langue est accessible dans le répertoire xx/ si pas d'autre règle existante
3051  $sql = "UPDATE peel_langues
3052  SET url_rewriting='".real_escape_string($new_lang)."/'
3053  WHERE lang='" . real_escape_string($new_lang)."' AND url_rewriting='' AND " . get_filter_site_cond('langues', null, true) . " AND site_id='" . nohtml_real_escape_string(get_site_id_sql_set_value($frm['site_id']))."'";
3054  query($sql);
3055  }
3056  if(!empty($imported_texts)){
3057  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => String::strtoupper($new_lang) . ' - ' . $GLOBALS["STR_ADMIN_LANGUES_MSG_CONTENT_IMPORTED"] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ': '.implode(', ', $imported_texts)))->fetch();
3058  }
3059  if(!empty($not_imported_texts)){
3060  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => String::strtoupper($new_lang) . ' - ' . $GLOBALS["STR_ADMIN_LANGUES_ERR_CONTENT_NOT_IMPORTED"] . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ': ' . implode(', ', $not_imported_texts)))->fetch();
3061  }
3062  } else {
3063  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => sprintf($GLOBALS["STR_ADMIN_LANGUES_ERR_LANGUAGE_ALREADY_INSTALLED"], $new_lang, $created)))->fetch();
3064  }
3065  return $output;
3066 }
3067 
3068 if (!function_exists('get_admin_date_filter_form')) {
3077  function get_admin_date_filter_form($form_title, $information_select_html, $submit_html=null, $only_information_select_html_displayed = false)
3078  {
3079  $output = '';
3080  $nowDay = date('d');
3081  $nowMonth = date('m');
3082  $nowYear = date('Y');
3083 
3084  // Génération de la liste des années de 2004 à maintenant
3085  for ($i = 2004; $i <= date('Y'); $i++) {
3086  $years1[]=$i;
3087  }
3088  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_date_filter_form.tpl');
3089  $tpl->assign('only_information_select_html_displayed', $only_information_select_html_displayed);
3090  $tpl->assign('action', get_current_url(false));
3091  $tpl->assign('form_title', $form_title);
3092  $tpl->assign('date', get_formatted_date(time()));
3093  $tpl->assign('information_select_html', $information_select_html);
3094  if($submit_html !== null) {
3095  $tpl->assign('submit_html', $submit_html);
3096  }
3097  $days_options = array();
3098  for ($c = 1; $c <= 31; $c++) {
3099  $days_options[] = array(
3100  'value' => $c,
3101  'name' => $c,
3102  'issel' => ((isset($_GET['jour1']) && $c == $_GET['jour1']) || (!isset($_GET['jour1']) && $c == $nowDay))
3103  );
3104  }
3105  $tpl->assign('days_options', $days_options);
3106 
3107  $months_options = array();
3108  foreach ($GLOBALS['months_names'] as $this_month_number => $this_month) {
3109  if(!empty($this_month)) {
3110  $months_options[] = array(
3111  'value' => $this_month_number,
3112  'name' => String::ucfirst($this_month),
3113  'issel' => ((isset($_GET['mois1']) && $this_month_number == $_GET['mois1']) || (!isset($_GET['mois1']) && $this_month_number == $nowMonth))
3114  );
3115  }
3116  }
3117  $tpl->assign('months_options', $months_options);
3118 
3119  $years_options = array();
3120  for ($x3 = 0; $x3 <= count($years1) - 1; $x3++) {
3121  $years_options[] = array(
3122  'value' => $years1[$x3],
3123  'name' => $years1[$x3],
3124  'issel' => ((isset($_GET['an1']) && $years1[$x3] == $_GET['an1']) || (!isset($_GET['an1']) && $years1[$x3] == $nowYear))
3125  );
3126  }
3127  $tpl->assign('years_options', $years_options);
3128 
3129  $days2_options = array();
3130  for ($c = 1; $c <= 31; $c++) {
3131  $days2_options[] = array(
3132  'value' => $c,
3133  'name' => $c,
3134  'issel' => ((isset($_GET['jour2']) && $c == $_GET['jour2']) || (!isset($_GET['jour2']) && $c == $nowDay))
3135  );
3136  }
3137  $tpl->assign('days2_options', $days2_options);
3138 
3139  $months2_options = array();
3140  foreach ($GLOBALS['months_names'] as $this_month_number => $this_month) {
3141  if(!empty($this_month)) {
3142  $months2_options[] = array(
3143  'value' => $this_month_number,
3144  'name' => String::ucfirst($this_month),
3145  'issel' => ((isset($_GET['mois2']) && $this_month_number == $_GET['mois2']) || (!isset($_GET['mois2']) && $this_month_number == $nowMonth))
3146  );
3147  }
3148  }
3149  $tpl->assign('months2_options', $months2_options);
3150 
3151  $years2_options = array();
3152  for ($x = 0; $x <= count($years1) - 1; $x++) {
3153  $years2_options[] = array(
3154  'value' => $years1[$x],
3155  'name' => $years1[$x],
3156  'issel' => ((isset($_GET['an2']) && $years1[$x] == $_GET['an2']) || (!isset($_GET['an2']) && $years1[$x] == $nowYear))
3157  );
3158  }
3159  $order_date_field_array = array($GLOBALS['STR_ADMIN_PAIEMENT_DATE']=>'a_timestamp',$GLOBALS['STR_ADMIN_ORDER_CREATION_DATE']=>'o_timestamp',$GLOBALS['STR_ADMIN_COMMANDER_INVOICE_DATE']=>'f_datetime',$GLOBALS['STR_EXPEDITION_DATE']=>'e_datetime');
3160  foreach($order_date_field_array as $name => $this_field) {
3161  $order_date_field_options[] = array(
3162  'value' => $this_field,
3163  'name' => $name,
3164  'issel' => ((isset($_GET['order_date_field_filter']) && $this_field == $_GET['order_date_field_filter']))
3165  );
3166  }
3167  $tpl->assign('order_date_field_options', $order_date_field_options);
3168  $tpl->assign('years2_options', $years2_options);
3169  $tpl->assign('from_date_txt', $GLOBALS['strStartingOn']);
3170  $tpl->assign('until_date_txt', $GLOBALS['strTillDay']);
3171  $tpl->assign('STR_ADMIN_ORDER_DATE_FIELD_FILTER', $GLOBALS['STR_ADMIN_ORDER_DATE_FIELD_FILTER']);
3172  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
3173  $tpl->assign('STR_ADMIN_TODAY_DATE', $GLOBALS['STR_ADMIN_TODAY_DATE']);
3174  $tpl->assign('STR_ADMIN_DISPLAY_RESULTS', $GLOBALS['STR_ADMIN_DISPLAY_RESULTS']);
3175  $output .= $tpl->fetch();
3176  return $output;
3177  }
3178 }
3179 
3180 if (!function_exists('check_admin_date_data')) {
3187  function check_admin_date_data(&$form_data)
3188  {
3189  $output = '';
3190  if (!checkdate($_GET['mois1'], $_GET['jour1'], $_GET['an1'])) {
3191  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $_GET['jour1'] . '-' . $_GET['mois1'] . '-' . $_GET['aa1'] . ' => '.$GLOBALS["STR_ERR_DATE_BAD"]))->fetch();
3192  } elseif (!checkdate($_GET['mois2'], $_GET['jour2'], $_GET['an2'])) {
3193  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $_GET['jour2'] . '-' . $_GET['mois2'] . '-' . $_GET['an2'] . ' => '.$GLOBALS["STR_ERR_DATE_BAD"]))->fetch();
3194  } else {
3195  $dateAdded1 = $_GET['an1'] . '-' . str_pad($_GET['mois1'], 2, 0, STR_PAD_LEFT) . '-' . str_pad($_GET['jour1'], 2, 0, STR_PAD_LEFT) . " 00:00:00";
3196  $dateAdded2 = $_GET['an2'] . '-' . str_pad($_GET['mois2'], 2, 0, STR_PAD_LEFT) . '-' . str_pad($_GET['jour2'], 2, 0, STR_PAD_LEFT) . " 23:59:59";
3197  if ($dateAdded2 < $dateAdded1) {
3198  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $GLOBALS['strStartingOn'] . ' ' . get_formatted_date($dateAdded1) . '&nbsp;' . $GLOBALS['strTillDay'] . ' ' . get_formatted_date($dateAdded2) . ' => ' . $GLOBALS["STR_ADMIN_DATE1_DATE2_INCOHERENT"]))->fetch();
3199  }
3200  }
3201  if(!empty($output)) {
3202  return $output;
3203  } else {
3204  return false;
3205  }
3206  }
3207 }
3208 
3209 if (!function_exists('affiche_liste_produits')) {
3216  function affiche_liste_produits($frm)
3217  {
3218  $categorie_options = get_categories_output(null, 'categories', vb($_GET['cat_search']));
3219  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_liste_produits.tpl');
3220  if (empty($categorie_options)) {
3221  $tpl->assign('is_empty', true);
3222  $tpl->assign('href', $GLOBALS['administrer_url'] . '/categories.php?mode=ajout');
3223  } else {
3224  $tpl->assign('is_empty', false);
3225  $tpl->assign('site_parameters_prices', vb($GLOBALS['site_parameters']['edit_prices_on_products_list']));
3226  $tpl->assign('administrer_url', $GLOBALS['administrer_url']);
3227  $tpl->assign('action', get_current_url(false) . '?page=' . (!empty($frm['page']) ? $frm['page'] : 1) . '&mode=recherche');
3228  $tpl->assign('categorie_options', $categorie_options);
3229  $tpl->assign('cat_search_zero_issel', (vb($frm['cat_search']) == '0'));
3230  $tpl->assign('home_search_one_issel', (vb($frm['home_search']) == 1));
3231  $tpl->assign('home_search_zero_issel', (vb($frm['home_search']) === "0"));
3232  $tpl->assign('new_search_one_issel', (vb($frm['new_search']) == 1));
3233  $tpl->assign('new_search_zero_issel', (vb($frm['new_search']) === "0"));
3234  $tpl->assign('promo_search_one_issel', (vb($frm['promo_search']) == 1));
3235  $tpl->assign('promo_search_zero_issel', (vb($frm['promo_search']) === "0"));
3236 
3237  $tpl->assign('is_best_seller_module_active', check_if_module_active('best_seller'));
3238  $tpl->assign('top_search_one_issel', (vb($frm['top_search']) == 1));
3239  $tpl->assign('top_search_zero_issel', (vb($frm['top_search']) === "0"));
3240 
3241  $tpl->assign('is_gifts_module_active', check_if_module_active('gifts'));
3242  $tpl->assign('on_gift_one_issel', (vb($frm['on_gift']) == 1));
3243  $tpl->assign('on_gift_zero_issel', (vb($frm['on_gift']) === "0"));
3244 
3245  $tpl->assign('blank_src', get_url('/images/blank.gif'));
3246  $tpl->assign('STR_PHOTO_NOT_AVAILABLE_ALT', $GLOBALS['STR_PHOTO_NOT_AVAILABLE_ALT']);
3247  if(!empty($GLOBALS['site_parameters']['default_picture'])) {
3248  $tpl->assign('photo_not_available_src', $GLOBALS['repertoire_upload'] . '/thumbs/' . thumbs($GLOBALS['site_parameters']['default_picture'], 80, 50, 'fit'));
3249  }
3251  $Links = new Multipage($sql, 'affiche_liste_produits');
3252  $HeaderTitlesArray = array($GLOBALS['STR_ADMIN_ACTION'], 'reference' => $GLOBALS['STR_REFERENCE'], $GLOBALS['STR_CATEGORY'], $GLOBALS['STR_WEBSITE'], ('nom_' . $_SESSION['session_langue']) => $GLOBALS['STR_ADMIN_NAME'], 'prix' => $GLOBALS['STR_PRICE'] . ' ' . $GLOBALS['site_parameters']['symbole'] . ' ' . (display_prices_with_taxes_in_admin() ? $GLOBALS['STR_TTC'] : $GLOBALS['STR_HT']), 'etat' => $GLOBALS['STR_STATUS']);
3253  if (check_if_module_active('stock_advanced')) {
3254  $HeaderTitlesArray['on_stock'] = $GLOBALS['STR_STOCK'];
3255  }
3256  if (check_if_module_active('gifts')) {
3257  $HeaderTitlesArray['points'] = $GLOBALS['STR_GIFT_POINTS'];
3258  $tpl->assign('STR_MODULE_GIFTS_ADMIN_GIFT', $GLOBALS['STR_MODULE_GIFTS_ADMIN_GIFT']);
3259  }
3260  $HeaderTitlesArray['date_maj'] = $GLOBALS['STR_ADMIN_UPDATED_DATE'];
3261  $HeaderTitlesArray[] = $GLOBALS['STR_ADMIN_SUPPLIER'];
3262  $HeaderTitlesArray[] = $GLOBALS['STR_PHOTO'];
3263  $HeaderTitlesArray['nb_view'] = $GLOBALS['STR_ADMIN_PRODUITS_VIEWS_COUNT'];
3264  $Links->HeaderTitlesArray = $HeaderTitlesArray;
3265  $Links->OrderDefault = vb($GLOBALS['site_parameters']['liste_produits_order_default'],"position, nom_".(!empty($GLOBALS['site_parameters']['product_name_forced_lang'])?$GLOBALS['site_parameters']['product_name_forced_lang']:$_SESSION['session_langue']).", prix");
3266  $Links->SortDefault = vb($GLOBALS['site_parameters']['liste_produits_sort_default'], "ASC");
3267  $results_array = $Links->Query();
3268 
3269  $tpl->assign('nombre_produits', $Links->nbRecord);
3270  $tpl->assign('ajout_produits_href', $GLOBALS['administrer_url'] . '/produits.php?mode=ajout');
3271  $tpl->assign('is_duplicate_module_active', check_if_module_active('duplicate'));
3272  $tpl->assign('is_stock_advanced_module_active', check_if_module_active('stock_advanced'));
3273  $tpl->assign('is_gifts_module_active', check_if_module_active('gifts'));
3274 
3275  $lignes = array();
3276  if (!empty($results_array)) {
3277  $i = 0;
3278  $tpl->assign('HeaderRow', $Links->getHeaderRow());
3279  foreach ($results_array as $ligne) {
3280  $product_object = new Product($ligne['id'], $ligne, true, null, true, !is_user_tva_intracom_for_no_vat() && !check_if_module_active('micro_entreprise'));
3281  $drop_href = get_current_url(true, false, array('nombre','multipage','mode','id','page'));
3282  if (strpos($_SERVER['REQUEST_URI'], '?') === false) {
3283  $drop_href .= '?';
3284  } else {
3285  $drop_href .= '&';
3286  }
3287  $drop_href .= 'mode=suppr&id=' . $ligne['id'] . '&page=' . (!empty($_GET['page']) ? $_GET['page'] : 1);
3288 
3289  // On affiche un formulaire avec les prix de chaque ligne qu'on peut changer - dans ce formulaire, on ne formatte pas les prix pour garder des prix avec plusieurs décimales additionnelles (utilisé dans des cas complexes)
3290  $tmpLigne = array('tr_rollover' => tr_rollover($i, true),
3291  'drop_confirm' => $GLOBALS["STR_ADMIN_DELETE_WARNING"],
3292  'id' => $ligne['id'],
3293  'name' => (!empty($product_object->name)?$product_object->name:'['.$ligne['id'].']'),
3294  'drop_href' => $drop_href,
3295  'drop_src' => $GLOBALS['administrer_url'] . '/images/b_drop.png',
3296  'edit_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'] . '&page=' . (!empty($frm['page']) ? $frm['page'] : 1),
3297  'edit_src' => $GLOBALS['administrer_url'] . '/images/b_edit.png',
3298  'dup_href' => get_current_url(false) . '?mode=duplicate&id=' . $ligne['id'] . '&page=' . (!empty($frm['page']) ? $frm['page'] : 1),
3299  'dup_src' => $GLOBALS['administrer_url'] . '/images/duplicate.png',
3300  'reference' => $ligne['reference'],
3301  'cats' => array(),
3302  'site_name' => get_site_name($ligne['site_id']),
3303  'modify_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'] . '&page=' . (!empty($frm['page']) ? $frm['page'] : 1),
3304  'modify_label' => $product_object->name . ($ligne['on_gift'] == 1 ? "&nbsp;(cadeau)" : ""),
3305  'prix' => fprix((display_prices_with_taxes_in_admin() ? $ligne['prix'] : $ligne['prix'] / (1 + $ligne['tva'] / 100)), false, $GLOBALS['site_parameters']['code'], false, null, false, false),
3306  'prix_suf' => (display_prices_with_taxes_in_admin() ? $GLOBALS['STR_TTC'] : $GLOBALS['STR_HT']),
3307  'etat_onclick' => 'change_status("produits", "' . $ligne['id'] . '", this, "'.$GLOBALS['administrer_url'] . '")',
3308  'etat_src' => $GLOBALS['administrer_url'] . '/images/' . (empty($ligne['etat']) ? 'puce-blanche.gif' : 'puce-verte.gif'),
3309  'date' => get_formatted_date($ligne['date_maj']),
3310  'product_name' => $product_object->name,
3311  'nb_view' => $ligne['nb_view'],
3312  );
3313  if(!empty($GLOBALS['site_parameters']['site_country_allowed_array'])) {
3314  $tmpLigne['site_country'] = get_country_name($ligne['site_country']);
3315  }
3316  $sqlCAT = "SELECT c.id, c.nom_" . $_SESSION['session_langue'] . ", c2.nom_" . $_SESSION['session_langue'] . " AS parent_nom_" . $_SESSION['session_langue'] . "
3317  FROM peel_produits_categories pc
3318  INNER JOIN peel_categories c ON c.id = pc.categorie_id AND " . get_filter_site_cond('categories', 'c') . "
3319  LEFT JOIN peel_categories c2 ON c2.id=c.parent_id AND " . get_filter_site_cond('categories', 'c2') . "
3320  WHERE pc.produit_id = " . intval($ligne['id']);
3321  $resCAT = query($sqlCAT);
3322  if (num_rows($resCAT) > 0) {
3323  while ($cat = fetch_assoc($resCAT)) {
3324  $tmpLigne['cats'][] = array(
3325  'parent_nom' => $cat['parent_nom_' . $_SESSION['session_langue']],
3326  'nom' => $cat['nom_' . $_SESSION['session_langue']]
3327  );
3328  }
3329  }
3330  $tmpLigne['site_id'] = $ligne['site_id'];
3331  if (check_if_module_active('stock_advanced')) {
3332  if ($ligne['on_stock'] == 1) {
3333  $tmpLigne['stock_href'] = get_current_url(false) . '?mode=stock&id=' . $ligne['id'];
3334  $tmpLigne['stock_src'] = $GLOBALS['administrer_url'] . '/images/stock.gif';
3335  }
3336  }
3337  if (check_if_module_active('gifts')) {
3338  $tmpLigne['points'] = $ligne['points'];
3339  }
3340  if (!empty($ligne['id_utilisateur']) && $user_infos = get_user_information($ligne['id_utilisateur'])) {
3341  $tmpLigne['utilisateur_href'] = $GLOBALS['administrer_url'] . "/utilisateurs.php?mode=modif&id_utilisateur=" . $user_infos['id_utilisateur'];
3342  $tmpLigne['societe'] = $user_infos['societe'];
3343  }
3344  //Récupération de l'image principale du produit
3345  $main_product_picture = $product_object->get_product_main_picture();
3346  //Si l'image principale est trouvée
3347  if (!empty($main_product_picture)) {
3348  $this_thumbs = thumbs($main_product_picture, 80, 50, 'fit');
3349  $tmpLigne['product_src'] = $GLOBALS['repertoire_upload'] . '/thumbs/' . $this_thumbs;
3350  }
3351  $i++;
3352  $lignes[] = $tmpLigne;
3353  }
3354  }
3355  $tpl->assign('lignes', $lignes);
3356  $tpl->assign('Multipage', $Links->GetMultipage());
3357 
3358  $tpl_marques_options = array();
3359  $select = query("SELECT id, nom_" . $_SESSION['session_langue'] . ", etat
3360  FROM peel_marques
3361  WHERE " . get_filter_site_cond('marques') . "
3362  ORDER BY position, nom_" . $_SESSION['session_langue'] . " ASC");
3363  while ($nom = fetch_assoc($select)) {
3364  $tpl_marques_options[] = array('value' => intval($nom['id']),
3365  'issel' => $nom['id'] == vb($frm['brand_search']),
3366  'name' => $nom['nom_' . $_SESSION['session_langue']] . (empty($nom['etat'])?' ('.$GLOBALS["STR_ADMIN_DEACTIVATED"].')':'')
3367  );
3368  }
3369  $tpl->assign('marques_options', $tpl_marques_options);
3370  }
3371  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
3372  if(!empty($GLOBALS['site_parameters']['site_country_allowed_array'])) {
3373  $tpl->assign('STR_ADMIN_SITE_COUNTRY', $GLOBALS['STR_ADMIN_SITE_COUNTRY']);
3374  }
3375  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
3376  $tpl->assign('STR_ADMIN_PRODUITS_CREATE_CATEGORY_FIRST', $GLOBALS['STR_ADMIN_PRODUITS_CREATE_CATEGORY_FIRST']);
3377  $tpl->assign('STR_ADMIN_SEARCH_CRITERIA', $GLOBALS['STR_ADMIN_SEARCH_CRITERIA']);
3378  $tpl->assign('STR_CATEGORY', $GLOBALS['STR_CATEGORY']);
3379  $tpl->assign('STR_ADMIN_ALL_CATEGORIES', $GLOBALS['STR_ADMIN_ALL_CATEGORIES']);
3380  $tpl->assign('STR_ADMIN_PRODUITS_NO_CATEGORY_RELATED', $GLOBALS['STR_ADMIN_PRODUITS_NO_CATEGORY_RELATED']);
3381  $tpl->assign('STR_ADMIN_PRODUITS_IS_PRODUCT_IN', $GLOBALS['STR_ADMIN_PRODUITS_IS_PRODUCT_IN']);
3382  $tpl->assign('STR_ADMIN_OUR_SELECTION', $GLOBALS['STR_ADMIN_OUR_SELECTION']);
3383  $tpl->assign('STR_ADMIN_ANY', $GLOBALS['STR_ADMIN_ANY']);
3384  $tpl->assign('STR_NOUVEAUTES', $GLOBALS['STR_NOUVEAUTES']);
3385  $tpl->assign('STR_YES', $GLOBALS['STR_YES']);
3386  $tpl->assign('STR_NO', $GLOBALS['STR_NO']);
3387  $tpl->assign('STR_PROMOTION', $GLOBALS['STR_PROMOTION']);
3388  $tpl->assign('STR_TOP', $GLOBALS['STR_TOP']);
3389  $tpl->assign('STR_ADMIN_PRODUITS_IS_PRODUCT', $GLOBALS['STR_ADMIN_PRODUITS_IS_PRODUCT']);
3390  $tpl->assign('STR_REFERENCE', $GLOBALS['STR_REFERENCE']);
3391  $tpl->assign('STR_ADMIN_PRODUCT_NAME', $GLOBALS['STR_ADMIN_PRODUCT_NAME']);
3392  $tpl->assign('STR_SEARCH', $GLOBALS['STR_SEARCH']);
3393  $tpl->assign('STR_ADMIN_PRODUITS_PRODUCTS_LIST', $GLOBALS['STR_ADMIN_PRODUITS_PRODUCTS_LIST']);
3394  $tpl->assign('STR_ADMIN_PRODUITS_PRODUCTS_COUNT', $GLOBALS['STR_ADMIN_PRODUITS_PRODUCTS_COUNT']);
3395  $tpl->assign('STR_ADMIN_CATEGORIES_ADD_PRODUCT', $GLOBALS['STR_ADMIN_CATEGORIES_ADD_PRODUCT']);
3396  $tpl->assign('STR_NOTA_BENE', $GLOBALS['STR_NOTA_BENE']);
3397  $tpl->assign('STR_ADMIN_PRODUITS_DUPLICATE_WARNING', $GLOBALS['STR_ADMIN_PRODUITS_DUPLICATE_WARNING']);
3398  $tpl->assign('STR_ADMIN_PRODUITS_NOTHING_FOUND', $GLOBALS['STR_ADMIN_PRODUITS_NOTHING_FOUND']);
3399  $tpl->assign('STR_DELETE', $GLOBALS['STR_DELETE']);
3400  $tpl->assign('STR_MODIFY', $GLOBALS['STR_MODIFY']);
3401  $tpl->assign('STR_ADMIN_PRODUITS_DUPLICATE', $GLOBALS['STR_ADMIN_PRODUITS_DUPLICATE']);
3402  $tpl->assign('STR_ADMIN_PRODUITS_UPDATE', $GLOBALS['STR_ADMIN_PRODUITS_UPDATE']);
3403  $tpl->assign('STR_PHOTO_NOT_AVAILABLE_ALT', $GLOBALS['STR_PHOTO_NOT_AVAILABLE_ALT']);
3404  $tpl->assign('STR_ADMIN_PRODUITS_MANAGE_STOCKS', $GLOBALS['STR_ADMIN_PRODUITS_MANAGE_STOCKS']);
3405  $tpl->assign('STR_ADMIN_DELETE_ALL_RESULTS', sprintf($GLOBALS['STR_ADMIN_DELETE_ALL_RESULTS'], vn($Links->nbRecord)));
3406  $delete_all_href = get_current_url(true, false, array('mode'));
3407  $tpl->assign('delete_all_href', $delete_all_href.(strpos($delete_all_href, '?')!==false?'&':'?') . 'mode=delete_results');
3408  $tpl->assign('STR_ADMIN_DELETE_WARNING', $GLOBALS['STR_ADMIN_DELETE_WARNING']);
3409  $tpl->assign('STR_BRAND', $GLOBALS['STR_BRAND']);
3410  $tpl->assign('STR_CHOOSE', $GLOBALS['STR_CHOOSE']);
3411  return $tpl->fetch();
3412  }
3413 }
3414 
3423 function get_admin_products_search_sql($frm, $delete = false, $get_only_product_with_images = false) {
3424  // Construction de la clause WHERE
3425  $table = "peel_produits AS p";
3426 
3427  $where = get_filter_site_cond('produits', 'p', true);
3428  if((!empty($frm['mode']) && $frm['mode'] != "maj") || empty($frm['mode'])) {
3429  // En cas de mise à jour de produit, $frm contient des index qui correspondent aux champs mis à jour. Il ne faut pas prendre en compte ces champs pour faire une recherche, ce n'est pas la demande de l'utilisateur.
3430  if($get_only_product_with_images) {
3431  $where .= " AND (image1!='' OR image2!='' OR image3!='' OR image4!='' OR image5!='' OR image6!='' OR image7!='' OR image8!='' OR image9!='' OR image10!='')";
3432  }
3433  if (isset($frm['reference_search']) && !empty($frm['reference_search'])) {
3434  $where .= " AND p.reference = '" . nohtml_real_escape_string($frm['reference_search']) . "'";
3435  }
3436  if (isset($frm['name_search']) && !empty($frm['name_search'])) {
3437  $where .= " AND p.nom_" . $_SESSION['session_langue'] . " LIKE '%" . nohtml_real_escape_string($frm['name_search']) . "%'";
3438  }
3439  if (!empty($frm['brand_search'])) {
3440  $where .= " AND p.id_marque = '" . nohtml_real_escape_string($frm['brand_search']) . "'";
3441  }
3442  if (isset($frm['home_search']) && $frm['home_search'] != "null") {
3443  $where .= " AND p.on_special = '" . nohtml_real_escape_string($frm['home_search']) . "'";
3444  }
3445  if (isset($frm['new_search']) && $frm['new_search'] != "null") {
3446  $where .= " AND p.on_new = '" . nohtml_real_escape_string($frm['new_search']) . "'";
3447  }
3448  if (isset($frm['promo_search']) && $frm['promo_search'] != "null") {
3449  $where .= " AND p.on_promo = '" . nohtml_real_escape_string($frm['promo_search']) . "'";
3450  }
3451  if (isset($frm['top_search']) && $frm['top_search'] != "null" && check_if_module_active('best_seller')) {
3452  $where .= " AND p.on_top = '" . nohtml_real_escape_string($frm['top_search']) . "'";
3453  }
3454  if (isset($frm['on_gift']) && $frm['on_gift'] != "null" && check_if_module_active('gifts')) {
3455  $where .= " AND p.on_gift = '" . nohtml_real_escape_string($frm['on_gift']) . "'";
3456  }
3457  if (isset($frm['cat_search']) && is_numeric($frm['cat_search'])) {
3458  $children_cat_list = get_children_cat_list(vn($frm['cat_search']));
3459  $where .= " AND pc.categorie_id IN (" . implode(',', $children_cat_list) . ")";
3460  }
3461  if (isset($frm['product_site_id']) && is_numeric($frm['product_site_id'])) {
3462  $where .= " AND p.site_id = '" . nohtml_real_escape_string($frm['product_site_id']) . "'";
3463  }
3464  if (isset($frm['cat_search']) && is_numeric($frm['cat_search']) || !empty($delete)) {
3465  $where .= "";
3466  $table .= "
3467  LEFT JOIN peel_produits_categories AS pc ON p.id = pc.produit_id";
3468  }
3469  if(!empty($delete)) {
3470  $alias = "p,pc,pr,pco,pt";
3471  // Pour effacer le contenu des autres tables, on ne fait pas de boucle sur chaque id sinon ce serait trop long
3472  $where .= "";
3473  $table .= "
3474  LEFT JOIN peel_produits_references AS pr ON p.id = pr.produit_id";
3475  $where .= "";
3476  $table .= "
3477  LEFT JOIN peel_produits_couleurs AS pco ON p.id = pco.produit_id";
3478  $where .= "";
3479  $table .= "
3480  LEFT JOIN peel_produits_tailles AS pt ON p.id = pt.produit_id";
3481  if (check_if_module_active('stock_advanced')) {
3482  $alias .= ",ps";
3483  $where .= "";
3484  $table .= "
3485  LEFT JOIN peel_stocks AS ps ON p.id = ps.produit_id";
3486  }
3487  }
3488  }
3489  $sql = ($delete ?"DELETE " . $alias :"SELECT p.*") . "
3490  FROM " . $table . "
3491  WHERE " . $where;
3492  $sql .= ($delete ?"":" GROUP BY p.id");
3493  return $sql;
3494 }
3495 
3496 if (!function_exists('affiche_liste_produits_acommander')) {
3502  function affiche_liste_produits_acommander()
3503  {
3504  $preselectionne = null;
3505 
3506  $sql = "SELECT p.id, oi.nom_produit as nom, oi.couleur, oi.taille, oi.delai_stock, oi.commande_id, oi.order_stock
3507  FROM peel_commandes_articles oi
3508  INNER JOIN peel_produits p ON oi.produit_id = p.id AND " . get_filter_site_cond('produits', 'p') . "
3509  WHERE oi.order_stock>0 AND " . get_filter_site_cond('commandes_articles', 'oi', true);
3510  $Links = new Multipage($sql, 'affiche_liste_produits_acommander');
3511  $Links->OrderDefault = "position, nom_" . $_SESSION['session_langue'] . ", prix";
3512  $Links->SortDefault = "ASC";
3513  $results_array = $Links->Query();
3514 
3515  $tpl = $GLOBALS['tplEngine']->createTemplate('admin_liste_produits_acommander.tpl');
3516  if (empty($results_array)) {
3517  $tpl->assign('is_empty', true);
3518  } else {
3519  $tpl->assign('is_empty', false);
3520  $products = array();
3521  foreach ($results_array as $this_product) {
3522  $products[] = array(
3523  'stock_href' => $GLOBALS['administrer_url'] . '/produits.php?mode=stock&id=' . $this_product['id'],
3524  'stock_src' => $GLOBALS['administrer_url'] . '/images/stock.gif',
3525  'modif_href' => $GLOBALS['administrer_url'] . '/produits.php?mode=modif&id=' . $this_product['id'],
3526  'nom' => $this_product['nom'],
3527  'couleur' => vb($this_product['couleur']),
3528  'taille' => vb($this_product['taille']),
3529  'delai_stock' => get_formatted_duration((intval($this_product['delai_stock']) * 24 * 3600), false, 'month'),
3530  'order_stock' => $this_product['order_stock'],
3531  'commander_href' => 'commander.php?mode=modif&id=' . $this_product['commande_id'],
3532  'commande_id' => $this_product['commande_id'],
3533  );
3534  }
3535  $tpl->assign('products', $products);
3536  $tpl->assign('Multipage', $Links->GetMultipage());
3537  }
3538  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
3539  $tpl->assign('STR_ADMIN_PRODUITS_NO_PRODUCT_TO_ORDER', $GLOBALS['STR_ADMIN_PRODUITS_NO_PRODUCT_TO_ORDER']);
3540  $tpl->assign('STR_ADMIN_PRODUITS_LIST_TO_ORDER_TITLE', $GLOBALS['STR_ADMIN_PRODUITS_LIST_TO_ORDER_TITLE']);
3541  $tpl->assign('STR_ADMIN_PRODUITS_TO_ORDER', $GLOBALS['STR_ADMIN_PRODUITS_TO_ORDER']);
3542  $tpl->assign('STR_ADMIN_ACTION', $GLOBALS['STR_ADMIN_ACTION']);
3543  $tpl->assign('STR_PRODUCT', $GLOBALS['STR_PRODUCT']);
3544  $tpl->assign('STR_ADMIN_PRODUITS_TO_ORDER', $GLOBALS['STR_ADMIN_PRODUITS_TO_ORDER']);
3545  $tpl->assign('STR_ADMIN_PRODUITS_ORDER_DETAIL', $GLOBALS['STR_ADMIN_PRODUITS_ORDER_DETAIL']);
3546  $tpl->assign('STR_COLOR', $GLOBALS['STR_COLOR']);
3547  $tpl->assign('STR_SIZE', $GLOBALS['STR_SIZE']);
3548  $tpl->assign('STR_ADMIN_PRODUITS_SUPPLY_FORECASTED', $GLOBALS['STR_ADMIN_PRODUITS_SUPPLY_FORECASTED']);
3549  $tpl->assign('STR_ORDER_NAME', $GLOBALS['STR_ORDER_NAME']);
3550  return $tpl->fetch();
3551  }
3552 }
3553 
3554 if (!function_exists('affiche_liste_articles')) {
3561  function affiche_liste_articles($frm)
3562  {
3563  if (isset($_POST['cat_search'])) {
3564  $rubrique_id = $_POST['cat_search'];
3565  } else {
3566  $rubrique_id = 'null';
3567  }
3568  $frm['rubriques'] = array($rubrique_id);
3569 
3570  // Construction de la clause WHERE
3571  $where = "WHERE " . get_filter_site_cond('articles', 'a', true) . "";
3572  $table = "";
3573  $inner = "";
3574  if (isset($frm['etat'])) {
3575  if ($frm['etat'] != "null") {
3576  $where .= " AND a.etat = '" . intval($frm['etat']) . "'";
3577  }
3578  }
3579  if (!empty($frm['text_in_title'])) {
3580  $where .= " AND a.titre_" . $_SESSION['session_langue'] . " LIKE '%" . nohtml_real_escape_string($frm['text_in_title']) . "%'";
3581  }
3582  if (!empty($frm['text_in_article'])) {
3583  $where .= " AND (a.texte_" . $_SESSION['session_langue'] . " LIKE '%" . real_escape_string($frm['text_in_article']) . "%' OR a.chapo_" . $_SESSION['session_langue'] . " LIKE '%" . real_escape_string($frm['text_in_article']) . "%')";
3584  }
3585  if (isset($frm['homepage'])) {
3586  if ($frm['homepage'] != "null") {
3587  $where .= " AND a.on_special = '" . nohtml_real_escape_string($frm['homepage']) . "'";
3588  }
3589  }
3590  if (isset($frm['cat_search']) || isset($_GET['catid'])) {
3591  if (vn($frm['cat_search']) != "null") {
3592  $inner .= "
3593  LEFT JOIN peel_articles_rubriques ar ON ar.article_id = a.id
3594  LEFT JOIN peel_rubriques r ON ar.rubrique_id = r.id AND " . get_filter_site_cond('rubriques', 'r') . "";
3595  if ($frm['cat_search'] === '0') {
3596  // recherche des articles sans association
3597  $rubrique_condition = ' ar.rubrique_id IS NULL OR ar.rubrique_id=0';
3598  } else {
3599  $rubrique_condition = ' ar.rubrique_id IN (' . implode(',', get_children_cat_list(vn($frm['cat_search']), array(), 'rubriques')) . ')';
3600  }
3601  $where .= ' AND '.$rubrique_condition;
3602  }
3603  }
3604  $sql = "SELECT a.id, a.titre_" . $_SESSION['session_langue'] . ", a.etat, a.site_id";
3605  if(!empty($GLOBALS['site_parameters']['site_country_allowed_array'])) {
3606  $sql .= ", a.site_country";
3607  }
3608  $sql .= " FROM peel_articles a " . $table . "
3609  " . $inner . "
3610  " . $where . "
3611  ORDER BY a.id DESC";
3612  $Links = new Multipage($sql, 'affiche_liste_articles');
3613  $results_array = $Links->Query();
3614 
3615  $tpl = $GLOBALS['tplEngine']->createTemplate('liste_articles.tpl');
3616  $tpl->assign('action', get_current_url(false) . '?start=0&mode=recherche');
3617  $tpl->assign('rubrique_options', get_categories_output(null, 'rubriques', vb($frm['rubriques'])));
3618  $tpl->assign('text_in_title', vb($_POST['text_in_title']));
3619  $tpl->assign('text_in_article', vb($_POST['text_in_article']));
3620  $tpl->assign('cat_search', vb($_GET['cat_search']));
3621  $tpl->assign('ajout_href', get_current_url(false) . '?mode=ajout');
3622  $tpl->assign('Multipage', $Links->GetMultipage());
3623  if (empty($results_array)) {
3624  $tpl->assign('is_empty', true);
3625  $tpl->assign('langue', $_SESSION['session_langue']);
3626  } else {
3627  $tpl->assign('is_empty', false);
3628  $lignes = array();
3629  $i = 0;
3630  foreach ($results_array as $ligne) {
3631  $tmpLigne = array(
3632  'tr_rollover' => tr_rollover($i, true),
3633  'titre' => (!empty($ligne['titre_' . $_SESSION['session_langue']])?String::html_entity_decode_if_needed($ligne['titre_' . $_SESSION['session_langue']]):'[' . $ligne['id'] . ']'),
3634  'drop_href' => get_current_url(false) . '?mode=suppr&id=' . $ligne['id'] . '&page=' . (!empty($_GET['page']) ? $_GET['page'] : 1),
3635  'drop_src' => $GLOBALS['administrer_url'] . '/images/b_drop.png',
3636  'rubs' => array(),
3637  'modif_href' => get_current_url(false) . '?mode=modif&id=' . $ligne['id'],
3638  'site_name' => get_site_name($ligne['site_id']),
3639  'etat_onclick' => 'change_status("articles", "' . $ligne['id'] . '", this, "'.$GLOBALS['administrer_url'] . '")',
3640  'modif_etat_src' => $GLOBALS['administrer_url'] . '/images/' . (empty($ligne['etat']) ? 'puce-blanche.gif' : 'puce-verte.gif'),
3641  );
3642  if(!empty($GLOBALS['site_parameters']['site_country_allowed_array'])) {
3643  $tmpLigne['site_country']= get_country_name($ligne['site_country']);
3644  }
3645  $sql = "SELECT r.id, r.nom_" . $_SESSION['session_langue'] . ", r2.nom_" . $_SESSION['session_langue'] . " AS parent_nom_" . $_SESSION['session_langue'] . "
3646  FROM peel_articles_rubriques pr
3647  LEFT JOIN peel_rubriques r ON r.id = pr.rubrique_id AND " . get_filter_site_cond('rubriques', 'r') . "
3648  LEFT JOIN peel_rubriques r2 ON r2.id=r.parent_id AND " . get_filter_site_cond('rubriques', 'r2') . "
3649  WHERE pr.article_id = " . intval($ligne['id']);
3650  $query = query($sql);
3651  if (num_rows($query) > 0) {
3652  while ($this_rub = fetch_assoc($query)) {
3653  if (!empty($this_rub['id'])) {
3654  $tmpLigne['rubs'][] = array(
3655  'parent_nom' => $this_rub['parent_nom_' . $_SESSION['session_langue']],
3656  'nom' => $this_rub['nom_' . $_SESSION['session_langue']]
3657  );
3658  } else {
3659  $tmpLigne['rubs'][] = null;
3660  }
3661  }
3662  }
3663  $tmpLigne['site_id'] = $ligne['site_id'];
3664  $i++;
3665  $lignes[] = $tmpLigne;
3666  }
3667  $tpl->assign('lignes', $lignes);
3668  }
3669  $tpl->assign('STR_ADMIN_CHOOSE_SEARCH_CRITERIA', $GLOBALS['STR_ADMIN_CHOOSE_SEARCH_CRITERIA']);
3670  $tpl->assign('STR_ADMIN_SEARCH_CRITERIA', $GLOBALS['STR_ADMIN_SEARCH_CRITERIA']);
3671  $tpl->assign('STR_BEFORE_TWO_POINTS', $GLOBALS['STR_BEFORE_TWO_POINTS']);
3672  $tpl->assign('STR_ADMIN_RUBRIQUE', $GLOBALS['STR_ADMIN_RUBRIQUE']);
3673  $tpl->assign('STR_ADMIN_RUBRIQUES_ALL', $GLOBALS['STR_ADMIN_RUBRIQUES_ALL']);
3674  $tpl->assign('STR_ADMIN_RUBRIQUES_NONE_RELATED', $GLOBALS['STR_ADMIN_RUBRIQUES_NONE_RELATED']);
3675  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
3676  $tpl->assign('STR_ADMIN_ARTICLES_ALL', $GLOBALS['STR_ADMIN_ARTICLES_ALL']);
3677  $tpl->assign('STR_ADMIN_ONLINE', $GLOBALS['STR_ADMIN_ONLINE']);
3678  $tpl->assign('STR_ADMIN_OFFLINE', $GLOBALS['STR_ADMIN_OFFLINE']);
3679  $tpl->assign('STR_ADMIN_SEARCH_IN_TITLE', $GLOBALS['STR_ADMIN_SEARCH_IN_TITLE']);
3680  $tpl->assign('STR_ADMIN_SEARCH_IN_ARTICLE', $GLOBALS['STR_ADMIN_SEARCH_IN_ARTICLE']);
3681  $tpl->assign('STR_SEARCH', $GLOBALS['STR_SEARCH']);
3682  $tpl->assign('STR_ADMIN_ARTICLES_ARTICLES_LIST', $GLOBALS['STR_ADMIN_ARTICLES_ARTICLES_LIST']);
3683  $tpl->assign('STR_ADMIN_ARTICLES_FORM_ADD', $GLOBALS['STR_ADMIN_ARTICLES_FORM_ADD']);
3684  $tpl->assign('STR_ADMIN_ARTICLES_NOTHING_FOUND_FOR_LANG', $GLOBALS['STR_ADMIN_ARTICLES_NOTHING_FOUND_FOR_LANG']);
3685  $tpl->assign('STR_ADMIN_ACTION', $GLOBALS['STR_ADMIN_ACTION']);
3686  $tpl->assign('STR_ADMIN_RUBRIQUE', $GLOBALS['STR_ADMIN_RUBRIQUE']);
3687  $tpl->assign('STR_ADMIN_TITLE', $GLOBALS['STR_ADMIN_TITLE']);
3688  $tpl->assign('STR_ADMIN_WEBSITE', $GLOBALS['STR_ADMIN_WEBSITE']);
3689  if(!empty($GLOBALS['site_parameters']['site_country_allowed_array'])) {
3690  $tpl->assign('STR_ADMIN_SITE_COUNTRY', $GLOBALS['STR_ADMIN_SITE_COUNTRY']);
3691  }
3692  $tpl->assign('STR_WEBSITE', $GLOBALS['STR_WEBSITE']);
3693  $tpl->assign('STR_STATUS', $GLOBALS['STR_STATUS']);
3694  $tpl->assign('STR_ADMIN_DELETE_WARNING', $GLOBALS['STR_ADMIN_DELETE_WARNING']);
3695  $tpl->assign('STR_DELETE', $GLOBALS['STR_DELETE']);
3696  $tpl->assign('STR_ADMIN_ARTICLES_FORM_MODIFY', $GLOBALS['STR_ADMIN_ARTICLES_FORM_MODIFY']);
3697  echo $tpl->fetch();
3698  }
3699 }
3700 
3706 function get_email_template_options($option_id_nature = 'id', $category_id = null, $lang = null, $value_select = null, $get_signature = null)
3707 {
3708  $output = '
3709  <option value="">'.$GLOBALS['STR_CHOOSE'].'...</option>';
3710  // Récupération des template email en fonction de la catégorie
3711  $result = query('SELECT id, technical_code, name, lang, site_id
3712  FROM peel_email_template
3713  WHERE active = "TRUE" AND ' . get_filter_site_cond('email_template', null) . ' ' . (!empty($get_signature)?' AND technical_code LIKE "signature%"':'') . (!empty($category_id)?' AND id_cat="' . intval($category_id) . '"':'') . (!empty($lang)?' AND (lang="' . vb($lang) . '" OR lang="")':'') . '
3714  ORDER BY technical_code, lang, name');
3715  while ($row_template = fetch_assoc($result)) {
3716  if ($option_id_nature == 'id') {
3717  $this_value = vn($row_template['id']);
3718  if (!empty($value_select)) {
3719  $this_select = frmvalide(vn($value_select) == $this_value, 'selected="selected"');
3720  }
3721  } elseif ($option_id_nature == 'technical_code') {
3722  $this_value = vb($row_template['technical_code']);
3723  if (!empty($value_select)) {
3724  $this_select = frmvalide(vb($value_select) == $this_value, 'selected="selected"');
3725  }
3726  }
3727  $output .= '
3728  <option value="' . $this_value . '" ' . (!empty($this_select)?$this_select:'') . '>' . get_site_info($row_template) . '[' . String::strtoupper(vb($row_template['lang'])) . '] - ' . String::str_form_value(vb($row_template['name'])) . '</option>';
3729  }
3730  return $output;
3731 }
3732 
3741 function get_site_id_select_options($selected_site_id = null, $selected_site_name = null, $display_first_option = null, $select_current_site_id_by_default = false) {
3742  if(!empty($GLOBALS['site_parameters']['multisite_disable'])) {
3743  // Désactivation du multisite : par défaut on prend site_id=1
3744  return '<input name="site_id" type="hidden" value="1" />';
3745  }
3746  // Création du template SMARTY
3747  $tpl = $GLOBALS['tplEngine']->createTemplate('select_options.tpl');
3748  $tpl_options = array();
3749  $all_sites_name_array = get_all_sites_name_array(true);
3750  if(is_array($selected_site_id) && count($selected_site_id) == 1) {
3751  $selected_site_id = current($selected_site_id);
3752  }
3753  if(empty($display_first_option)) {
3754  $display_first_option = (empty($_SESSION['session_utilisateur']['site_id']) && count($all_sites_name_array)>1?'STR_ADMIN_ALL_SITES':false);
3755  }
3756  if ($selected_site_id === '' || $selected_site_id === null) {
3757  // le site_id passé en paramètre est vide. Pour présélectioner la bonne option du select il faut utiliser soit le site séléctionné par l'admin, soit le site_id correspondant au site consulté.
3758  if($select_current_site_id_by_default && empty($_SESSION['session_admin_multisite'])) {
3759  // On ne souhaite pas avoir zéro sélectionné dans le select => On prend l'id du site par défaut (défini par le nom de domaine du site)
3760  $selected_site_id = $GLOBALS['site_id'];
3761  } elseif (isset($_SESSION['session_admin_multisite'])) {
3762  // On prend l'id de site de l'admin, il peut être égal à 0
3763  $selected_site_id = $_SESSION['session_admin_multisite'];
3764  }
3765  }
3766  if(!is_array($selected_site_name)) {
3767  $selected_site_name = explode(',', $selected_site_name);
3768  }
3769  if(!is_array($selected_site_id)) {
3770  $selected_site_id = explode(',', $selected_site_id);
3771  }
3772  if (!empty($display_first_option) && (String::substr($display_first_option, 0, 4) == 'STR_') && !empty($GLOBALS[$display_first_option])) {
3773  // Si l'admin peut administrer tous les sites, il faut mettre une option supplémentaire pour pouvoir accéder au contenu de tous les sites.
3774  if ($display_first_option == 'STR_ADMIN_ALL_SITES') {
3775  $value = 0;
3776  } else {
3777  $value = '';
3778  }
3779  // la première option est ajoutée au tableau $all_sites_name_array qui contient les sites configurés.
3780  $all_sites_name_array = array($value=>$GLOBALS[$display_first_option]) + $all_sites_name_array;
3781  }
3782  foreach($all_sites_name_array as $site_id=>$site_name) {
3783  // Récupération des infos qui seront utilisées par les options
3784  $site_selected = (($selected_site_name != array(null) && in_array($site_name, $selected_site_name)) || ($selected_site_id != array(null) && in_array($site_id, $selected_site_id)));
3785  $tpl_options[] = array(
3786  'value' => $site_id,
3787  'name' => $site_name,
3788  'issel' => $site_selected
3789  );
3790  }
3791  // La variable contient le tableau des données, un foreach dans select_options exploitera ces infos dans le fichier SMARTY
3792  $tpl->assign('options', $tpl_options);
3793 
3794  // Les options sont générées
3795  $output = $tpl->fetch();
3796 
3797  // Envoi des résultats
3798  return $output;
3799 }
3800 
3807  $result_array = get_all_sites_name_array();
3808  if($mode == 'id') {
3809  return implode(',', array_keys($result_array));
3810  } else {
3811  return implode(',', $result_array);
3812  }
3813 }
3814 
3822 }
3823 
3831  $site_id_array = array();
3832  $q = query('SELECT site_id, string
3833  FROM peel_configuration
3834  WHERE technical_code="wwwroot" AND ' . get_filter_site_cond('configuration', null, true) . '
3835  ORDER BY string ASC');
3836  while($result = fetch_assoc($q)) {
3837  $site_id_array[$result['site_id']] = $result['string'];
3838  }
3839  return $site_id_array;
3840 }
3841 
3849 function get_site_country_checkboxes($selected_site_country_array = null, $field_name = 'site_country') {
3850  if(empty($GLOBALS['site_parameters']['site_country_allowed_array'])) {
3851  return null;
3852  }
3853  // Création du template SMARTY
3854  $tpl = $GLOBALS['tplEngine']->createTemplate('checkboxes.tpl');
3855  $tpl_options = array();
3856  if ($selected_site_country_array === null) {
3857  $selected_site_country_array = $GLOBALS['site_parameters']['site_country_allowed_array'];
3858  }
3859  foreach($GLOBALS['site_parameters']['site_country_allowed_array'] as $site_country_id) {
3860  // Récupération des infos qui seront utilisée par les options
3861  $tpl_options[] = array(
3862  'name' => $field_name,
3863  'value' => $site_country_id,
3864  'text' => get_country_name($site_country_id),
3865  'issel' => in_array($site_country_id, $selected_site_country_array)
3866  );
3867  }
3868  // La variable contient le tableau des données, un foreach dans select_options exploitera ces infos dans le fichier SMARTY
3869  $tpl->assign('options', $tpl_options);
3870  // Les options sont générées
3871  $output = $tpl->fetch();
3872 
3873  // Envoi des résultats
3874  return $output;
3875 }
3876 
3884  if(!empty($GLOBALS['site_parameters']['field_auto_complete_with_main_content_lang']) && is_array($GLOBALS['site_parameters']['field_auto_complete_with_main_content_lang'])) {
3885  foreach ($GLOBALS['site_parameters']['field_auto_complete_with_main_content_lang'] as $this_field) {
3886  // Recherche du contenu principal
3887  if(!empty($frm[$this_field . '_' . $GLOBALS['site_parameters']['main_content_lang']])) {
3888  // La langue principale n'est pas vide
3889  $main_content = $GLOBALS['site_parameters']['main_content_lang'];
3890  }
3891  if (empty($main_content)) {
3892  // Recherche de contenu par langue, si la langue principale est vide
3893  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
3894  if(!empty($frm[$this_field . '_' . $lng])) {
3895  // un contenu dans une langue a été trouvé.
3896  $main_content = $lng;
3897  // on sort de la boucle
3898  break;
3899  }
3900  }
3901  }
3902  if (!empty($main_content)) {
3903  // On a un contenu principal, il faut compléter les champs vides avec
3904  foreach ($GLOBALS['admin_lang_codes'] as $lng) {
3905  if (empty($frm[$this_field . '_' . $lng])) {
3906  $frm[$this_field . '_' . $lng] = vb($frm[$this_field . '_' . $main_content]);
3907  }
3908  }
3909  }
3910  }
3911  }
3912  return $frm;
3913 }
3914 
3921 function get_delivery_status_options($selected_status_id = null)
3922 {
3923  $output = '';
3924  $sql_statut = "SELECT id, nom_" . $_SESSION['session_langue'] . ", site_id
3925  FROM peel_statut_livraison
3926  WHERE " . get_filter_site_cond('statut_livraison', null) . "
3927  ORDER BY position ASC, nom_" . $_SESSION['session_langue'] . " ASC";
3928  $res_statut = query($sql_statut);
3929 
3930  while ($s = fetch_assoc($res_statut)) {
3931  $output .= '<option value="' . intval($s['id']) . '" ' . frmvalide($s['id'] == $selected_status_id, ' selected="selected"') . '>' . String::html_entity_decode_if_needed(get_site_info($s).$s['nom_' . $_SESSION['session_langue']]) . '</option>';
3932  }
3933  return $output;
3934 }
3935 
3942 function get_payment_status_options($selected_status_id = null)
3943 {
3944  $output = '';
3945  $sql_statut = "SELECT id, nom_" . $_SESSION['session_langue'] . ", site_id
3946  FROM peel_statut_paiement
3947  WHERE " . get_filter_site_cond('statut_paiement', null) . "
3948  ORDER BY position ASC, nom_" . $_SESSION['session_langue'] . " ASC";
3949  $res_statut = query($sql_statut);
3950 
3951  $tpl = $GLOBALS['tplEngine']->createTemplate('payment_status_options.tpl');
3952  $tpl_options = array();
3953  while ($s = fetch_assoc($res_statut)) {
3954  $tpl_options[] = array(
3955  'value' => intval($s['id']),
3956  'name' => get_site_info($s).$s['nom_' . $_SESSION['session_langue']],
3957  'issel' => ($s['id'] == $selected_status_id)
3958  );
3959  }
3960  $tpl->assign('options', $tpl_options);
3961  $output .= $tpl->fetch();
3962  return $output;
3963 }
3964 
3972 function get_vat_select_options($selected_vat = null, $approximative_amount_selected = false)
3973 {
3974  $output = '';
3975  $sql_paiement = 'SELECT id, tva, site_id
3976  FROM peel_tva
3977  WHERE ' . get_filter_site_cond('tva'). '
3978  ORDER BY tva DESC';
3979  $res_paiement = query($sql_paiement);
3980 
3981  $tpl = $GLOBALS['tplEngine']->createTemplate('select_options.tpl');
3982  $tpl_options = array();
3983  while ($tab_paiement = fetch_assoc($res_paiement)) {
3984  if ($approximative_amount_selected) {
3985  // Pour éviter problèmes d'arrondis sur la TVA calculée à partir de la BDD, on regarde si elle vaut la valeur dans le select à 0,1% près
3986  $is_selected = (abs(floatval($selected_vat) - floatval($tab_paiement['tva'])) * 1000 <= abs($tab_paiement['tva']));
3987  } else {
3988  $is_selected = (floatval($selected_vat) == floatval($tab_paiement['tva']));
3989  }
3990 
3991  if($is_selected) {
3992  $selected_vat_found = true;
3993  }
3994  $tpl_options[] = array(
3995  'value' => $tab_paiement['tva'],
3996  'name' => get_site_info($tab_paiement).$tab_paiement['tva'],
3997  'issel' => $is_selected
3998  );
3999  }
4000  if(!empty($selected_vat) && empty($selected_vat_found)) {
4001  // Valeur cherchée non trouvée (par exemple valeur en base de données qui n'est plus disponible dans les choix de TVA autorisés) : on la rajoute à la liste du select
4002  $tpl_options[] = array(
4003  'value' => $selected_vat,
4004  'name' => $selected_vat . ' [' . $GLOBALS["STR_ADMIN_DEACTIVATED"] . ']',
4005