Completed
Push — master ( aef742...00e474 )
by Michael
05:09
created

checkout.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 73 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   The XOOPS Project http://sourceforge.net/projects/xoops/
16
 * @license     http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 * @version     $Id$
19
 */
20
21
/**
22
 * Saisie des données du client + affichage des informations saisies pour validation avec redirection vers la passerelle de paiement
23
 */
24
require 'header.php';
25
$GLOBALS['current_category'] = -1;
26
$xoopsOption['template_main'] = 'oledrion_command.tpl';
27
require_once XOOPS_ROOT_PATH . '/header.php';
28
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
29
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
30
require_once XOOPS_ROOT_PATH . '/class/tree.php';
31
require_once OLEDRION_PATH . 'class/registryfile.php';
32
33
// Get user id
34
$uid = oledrion_utils::getCurrentUserID();
35
// Get checkout level
36
$checkout_level = oledrion_utils::getModuleOption('checkout_level');
37
// Passage de commandes réservé aux utilisateurs enregistrés
38
if (oledrion_utils::getModuleOption('restrict_orders', false) == 1 && $uid == 0) {
39
    $registry = new oledrion_registryfile();
40
    $text = $registry -> getfile(OLEDRION_TEXTFILE5);
41
    oledrion_utils::redirect(xoops_trim($text), 'index.php', 5);
42
}
43
// Get option
44
$op = 'default';
45 View Code Duplication
if (isset($_POST['op'])) {
46
    $op = $_POST['op'];
47
} elseif (isset($_GET['op'])) {
48
    $op = $_GET['op'];
49
}
50
// Get action
51
$action = 'default';
52 View Code Duplication
if (isset($_POST['action'])) {
53
    $action = $_POST['action'];
54
} elseif (isset($_GET['action'])) {
55
    $action = $_GET['action'];
56
}
57
// Get commend id
58
$commend_id = 0;
59 View Code Duplication
if (isset($_POST['commend_id'])) {
60
    $commend_id = intval($_POST['commend_id']);
61
} elseif (isset($_GET['commend_id'])) {
62
    $commend_id = intval($_GET['commend_id']);
63
}
64
65
$xoopsTpl -> assign('op', $op);
66
$xoopsTpl -> assign('mod_pref', $mod_pref);
67
$cartForTemplate = array();
68
$emptyCart = false;
69
$shippingAmount = $commandAmount = $vatAmount = $commandAmountTTC = $discountsCount = $commandAmountVAT = 0;
70
$goOn = '';
71
$discountsDescription = array();
72
73
function listCart() {
0 ignored issues
show
The function listCart() has been defined more than once; this definition is ignored, only the first definition in caddy.php (L68-98) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
74
    global $cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription;
75
    $reductions = new oledrion_reductions();
76
    $reductions -> computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $discountsCount);
77
}
78
79
$oledrion_Currency = oledrion_Currency::getInstance();
80
$countries = oledrion_utils::getCountriesList();
81
82
switch ($op) {
83
    case 'save' :
84
        if (empty($_POST)) {
85
            oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
86
        }
87
        if ($h_oledrion_caddy -> isCartEmpty()) {
88
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
89
        }
90
        listCart();
91
92
        switch ($action) {
93
            case 'make' :
94
                $commandAmountTTC = $commandAmountTTC + $commandAmountVAT;
95
                $password = md5(xoops_makepass());
96
                $passwordCancel = md5(xoops_makepass());
97
                $commande = $h_oledrion_commands -> create(true);
98
                $commande -> setVars($_POST);
99
                $commande -> setVar('cmd_uid', $uid);
100
                $commande -> setVar('cmd_date', date("Y-m-d"));
101
                $commande -> setVar('cmd_create', time());
102
                $commande -> setVar('cmd_state', OLEDRION_STATE_NOINFORMATION);
103
                $commande -> setVar('cmd_ip', oledrion_utils::IP());
104
                $commande -> setVar('cmd_articles_count', count($cartForTemplate));
105
                $commande -> setVar('cmd_total', oledrion_utils::formatFloatForDB($commandAmountTTC));
106
                $commande -> setVar('cmd_shipping', oledrion_utils::formatFloatForDB($shippingAmount));
107
                $commande -> setVar('cmd_password', $password);
108
                $commande -> setVar('cmd_cancel', $passwordCancel);
109
                $commande -> setVar('cmd_text', implode("\n", $discountsDescription));
110
                $commande -> setVar('cmd_status', 2);
111
                $res = $h_oledrion_commands -> insert($commande, true);
112
                if (!$res) {
113
                    oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
114
                }
115
                // Check checkout level
116
                if ($checkout_level == 1) {
117
                    oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commande -> getVar('cmd_id'), 1);
118
                } elseif ($checkout_level == 2) {
119
                    oledrion_utils::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commande -> getVar('cmd_id'), 1);
120
                } else {
121
                    oledrion_utils::redirect(_OLEDRION_SELECT_PACKING, OLEDRION_URL . 'checkout.php?op=packing&commend_id=' . $commande -> getVar('cmd_id'), 1);
122
                }
123
                break;
124
125
            case 'find' :
126
                if ($commend_id == 0) {
127
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
128
                }
129
                $commandAmountTTC = $commandAmountTTC + $commandAmountVAT;
130
                $commande = $h_oledrion_commands -> get($commend_id);
131
                $commande -> setVars($_POST);
132
                $commande -> setVar('cmd_state', OLEDRION_STATE_NOINFORMATION);
133
                $commande -> setVar('cmd_ip', oledrion_utils::IP());
134
                $commande -> setVar('cmd_articles_count', count($cartForTemplate));
135
                $commande -> setVar('cmd_total', oledrion_utils::formatFloatForDB($commandAmountTTC));
136
                $commande -> setVar('cmd_shipping', oledrion_utils::formatFloatForDB($shippingAmount));
137
                $commande -> setVar('cmd_text', implode("\n", $discountsDescription));
138
                $commande -> setVar('cmd_status', 2);
139
                $res = $h_oledrion_commands -> insert($commande, true);
140
                if (!$res) {
141
                    oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
142
                }
143
                oledrion_utils::redirect(_OLEDRION_SELECT_PACKING, OLEDRION_URL . 'checkout.php?op=packing&commend_id=' . $commande -> getVar('cmd_id'), 1);
144
                break;
145
146
            case 'packing' :
147
                $packing_id = 0;
148
                if (isset($_POST['packing_id'])) {
149
                    $packing_id = intval($_POST['packing_id']);
150
                }
151
                if ($packing_id == 0) {
152
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
153
                }
154
                if ($commend_id == 0) {
155
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
156
                }
157
                // Check checkout level
158 View Code Duplication
                if ($checkout_level == 1) {
159
                    oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
160
                } elseif ($checkout_level == 2) {
161
                    oledrion_utils::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commend_id, 1);
162
                }
163
164
                $packing = $h_oledrion_packing -> get($packing_id);
165
                if (!$packing -> getVar('packing_id')) {
166
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
167
                }
168
                $commande = $h_oledrion_commands -> get($commend_id);
169
                $commande -> setVar('cmd_packing', $packing -> getVar('packing_title'));
170
                $commande -> setVar('cmd_packing_id', $packing -> getVar('packing_id'));
171
                $commande -> setVar('cmd_packing_price', $packing -> getVar('packing_price'));
172
                $res = $h_oledrion_commands -> insert($commande, true);
173
                if (!$res) {
174
                    oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
175
                }
176
                oledrion_utils::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commande -> getVar('cmd_id'), 1);
177
                break;
178
179
            case 'location' :
180
                $location_id = 0;
181
                if (isset($_POST['location_id'])) {
182
                    $location_id = intval($_POST['location_id']);
183
                }
184
                if ($location_id == 0) {
185
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
186
                }
187
                if ($commend_id == 0) {
188
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
189
                }
190
                // Check checkout level
191
                if ($checkout_level == 1) {
192
                    oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
193
                }
194
                $location = $h_oledrion_location -> get($location_id);
195
                $commande = $h_oledrion_commands -> get($commend_id);
196
                $commande -> setVar('cmd_location', $location -> getVar('location_title'));
197
                $commande -> setVar('cmd_location_id', $location -> getVar('location_id'));
198
                $res = $h_oledrion_commands -> insert($commande, true);
199
                if (!$res) {
200
                    oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
201
                }
202
203
                if ($h_oledrion_location -> haveChild($location -> getVar('location_id'))) {
204
                    oledrion_utils::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&action=select&commend_id=' . $commande -> getVar('cmd_id'), 1);
205
                } else {
206
                    oledrion_utils::redirect(_OLEDRION_SELECT_DELIVERY, OLEDRION_URL . 'checkout.php?op=delivery&commend_id=' . $commande -> getVar('cmd_id'), 1);
207
                }
208
                break;
209
210
            case 'delivery' :
211
                $delivery_id = 0;
212
                if (isset($_POST['delivery_id'])) {
213
                    $delivery_id = intval($_POST['delivery_id']);
214
                }
215
                if ($delivery_id == 0) {
216
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
217
                }
218
                if ($commend_id == 0) {
219
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
220
                }
221
                // Check checkout level
222
                if ($checkout_level == 1) {
223
                    oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
224
                }
225
                $commande = $h_oledrion_commands -> get($commend_id);
226
                $delivery = $h_oledrion_delivery -> getThisLocationThisDelivery($delivery_id, $commande -> getVar('cmd_location_id'));
227
228
                $shipping_price = '';
229
                $shipping_price_op = oledrion_utils::getModuleOption('checkout_shipping', false);
230
                switch ($shipping_price_op) {
231
                    case 1 :
232
                        $shipping_price = $shippingAmount + $delivery['delivery_price'];
233
                        break;
234
235
                    case 2 :
236
                        $shipping_price = $shippingAmount;
237
                        break;
238
239
                    case 3 :
240
                        $shipping_price = $delivery['delivery_price'];
241
                        break;
242
243
                    case 4 :
244
                        $shipping_price = 0;
245
                        break;
246
                }
247
                $commande -> setVar('cmd_delivery', $delivery['delivery_title']);
248
                $commande -> setVar('cmd_delivery_id', $delivery['delivery_id']);
249
                $commande -> setVar('cmd_shipping', $shipping_price);
250
                $res = $h_oledrion_commands -> insert($commande, true);
251
                if (!$res) {
252
                    oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
253
                }
254
                oledrion_utils::redirect(_OLEDRION_SELECT_PAYMENT, OLEDRION_URL . 'checkout.php?op=payment&commend_id=' . $commande -> getVar('cmd_id'), 1);
255
                break;
256
257
            case 'payment' :
258
                $payment_id = 0;
259
                if (isset($_POST['payment_id'])) {
260
                    $payment_id = intval($_POST['payment_id']);
261
                }
262
                if ($payment_id == 0) {
263
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
264
                }
265
                if ($commend_id == 0) {
266
                    oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
267
                }
268
                // Check checkout level
269
                if ($checkout_level == 1) {
270
                    oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
271
                }
272
                $payment = $h_oledrion_payment -> get($payment_id);
273
                $commande = $h_oledrion_commands -> get($commend_id);
274
                $commande -> setVar('cmd_payment', $payment -> getVar('payment_title'));
275
                $commande -> setVar('cmd_payment_id', $payment -> getVar('payment_id'));
276
                $res = $h_oledrion_commands -> insert($commande, true);
277
                if (!$res) {
278
                    oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
279
                }
280
                oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commande -> getVar('cmd_id'), 1);
281
                break;
282
        }
283
284
        break;
285
286
    // ****************************************************************************************************************
287
    case 'default' :
288
        // Présentation du formulaire
289
        // ****************************************************************************************************************
290
        if ($h_oledrion_caddy -> isCartEmpty()) {
291
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
292
        }
293
        listCart();
294
        $notFound = true;
295
296
        if ($uid > 0) {// Si c'est un utlisateur enregistré, on recherche dans les anciennes commandes pour pré-remplir les champs
297
            $commande = null;
298
            $commande = $h_oledrion_commands -> getLastUserOrder($uid);
299
            if (is_object($commande)) {
300
                $notFound = false;
301
            }
302
        }
303
304
        if ($notFound) {
305
            $commande = $h_oledrion_commands -> create(true);
306
            $commande -> setVar('cmd_country', OLEDRION_DEFAULT_COUNTRY);
307
        }
308
309
        // texte à afficher
310
        $registry = new oledrion_registryfile();
311
        $text = $registry -> getfile(OLEDRION_TEXTFILE6);
312
        $xoopsTpl -> assign('text', xoops_trim($text));
313
314
        $sform = new XoopsThemeForm(_OLEDRION_PLEASE_ENTER, "informationfrm", OLEDRION_URL . 'checkout.php', 'post');
315
        $sform -> addElement(new XoopsFormHidden('op', 'save'));
316
        if ($commande -> getVar('cmd_id') && $commande -> getVar('cmd_id') > 0) {
317
            $sform -> addElement(new XoopsFormHidden('action', 'find'));
318
            $sform -> addElement(new XoopsFormHidden('commend_id', $commande -> getVar('cmd_id')));
319
        } else {
320
            $sform -> addElement(new XoopsFormHidden('action', 'make'));
321
        }
322
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_TOTAL, $oledrion_Currency -> amountForDisplay($commandAmountTTC)));
323
        // By voltan
324
        if (in_array(oledrion_utils::getModuleOption('checkout_shipping'), array(1, 2)) && $shippingAmount > 0) {
325
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_SHIPPING_PRICE, $oledrion_Currency -> amountForDisplay($shippingAmount)));
326
        }
327
        $sform -> addElement(new XoopsFormText(_OLEDRION_LASTNAME, 'cmd_lastname', 50, 255, $commande -> getVar('cmd_lastname', 'e')), true);
328
        $sform -> addElement(new XoopsFormText(_OLEDRION_FIRSTNAME, 'cmd_firstname', 50, 255, $commande -> getVar('cmd_firstname', 'e')), false);
329
        if ($uid > 0) {
330
            $sform -> addElement(new XoopsFormText(_OLEDRION_EMAIL, 'cmd_email', 50, 255, $xoopsUser -> getVar('email', 'e')), true);
331
        } else {
332
            $sform -> addElement(new XoopsFormText(_OLEDRION_EMAIL, 'cmd_email', 50, 255, ''), true);
333
        }
334
        $sform -> addElement(new XoopsFormText(_OLEDRION_CITY, 'cmd_town', 50, 255, $commande -> getVar('cmd_town', 'e')), true);
335
        // By voltan
336 View Code Duplication
        if (oledrion_utils::getModuleOption('checkout_country')) {
337
            $countriesList = new XoopsFormSelect(_OLEDRION_COUNTRY, 'cmd_country', $commande -> getVar('cmd_country', ' e'));
338
            $countriesList -> addOptionArray($countries);
339
            $sform -> addElement($countriesList, true);
340
        } else {
341
            $sform -> addElement(new XoopsFormHidden('cmd_country', OLEDRION_DEFAULT_COUNTRY));
342
        }
343
        $sform -> addElement(new XoopsFormText(_OLEDRION_CP, 'cmd_zip', 15, 30, $commande -> getVar('cmd_zip', 'e')), true);
344
        $sform -> addElement(new XoopsFormText(_OLEDRION_MOBILE, 'cmd_mobile', 15, 50, $commande -> getVar('cmd_mobile', 'e')), true);
345
        $sform -> addElement(new XoopsFormText(_OLEDRION_PHONE, 'cmd_telephone', 15, 50, $commande -> getVar('cmd_telephone', 'e')), true);
346
        if (oledrion_utils::getModuleOption('ask_vatnumber')) {
347
            $sform -> addElement(new XoopsFormText(_OLEDRION_VAT_NUMBER, 'cmd_vat_number', 50, 255, $commande -> getVar('cmd_vat_number', 'e')), false);
348
        }
349
        if (oledrion_utils::getModuleOption('ask_bill')) {
350
            $sform -> addElement(new XoopsFormRadioYN(_OLEDRION_INVOICE, 'cmd_bill', 0), true);
351
        }
352
        $sform -> addElement(new XoopsFormTextArea(_OLEDRION_STREET, 'cmd_adress', $commande -> getVar('cmd_adress', 'e'), 3, 50), true);
353
        $sform -> addElement(new XoopsFormText(_OLEDRION_GIFT, 'cmd_gift', 15, 30, $commande -> getVar('cmd_gift', 'e')), false);
354
        $button_tray = new XoopsFormElementTray('', '');
355
        $submit_btn = new XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit');
356
        $button_tray -> addElement($submit_btn);
357
        $sform -> addElement($button_tray);
358
        $sform = oledrion_utils::formMarkRequiredFields($sform);
359
        $xoopsTpl -> assign('form', $sform -> render());
360
        break;
361
362
    case 'packing' :
363
        if ($h_oledrion_caddy -> isCartEmpty()) {
364
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
365
        }
366
        if ($commend_id == 0) {
367
            oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
368
        }
369
        // Check checkout level
370 View Code Duplication
        if ($checkout_level == 1) {
371
            oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
372
        } elseif ($checkout_level == 2) {
373
            oledrion_utils::redirect(_OLEDRION_SELECT_LOCATION, OLEDRION_URL . 'checkout.php?op=location&commend_id=' . $commend_id, 1);
374
        }
375
        listCart();
376
        $packings = $h_oledrion_packing -> getPacking();
377
378
        $sform = new XoopsThemeForm(_OLEDRION_PACKING_FORM, "informationfrm", OLEDRION_URL . 'checkout.php', 'post');
379
        $sform -> addElement(new XoopsFormHidden('op', 'save'));
380
        $sform -> addElement(new XoopsFormHidden('action', 'packing'));
381
        $sform -> addElement(new XoopsFormHidden('commend_id', $commend_id));
382
        $packingSelect = new XoopsFormRadio(_OLEDRION_SELECT_PACKING, 'packing_id', '');
383
        foreach ($packings as $packing) {
384
            $packingSelect -> addOption($packing['packing_id'], oledrion_utils::packingHtmlSelect($packing));
385
        }
386
        $sform -> addElement($packingSelect, true);
387
        $sform -> addElement(new XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit'));
388
        $sform = oledrion_utils::formMarkRequiredFields($sform);
389
        $xoopsTpl -> assign('form', $sform -> render());
390
391
        // texte à afficher
392
        $registry = new oledrion_registryfile();
393
        $text = $registry -> getfile(OLEDRION_TEXTFILE6);
394
        $xoopsTpl -> assign('text', xoops_trim($text));
395
        break;
396
397
    case 'location' :
398
        if ($h_oledrion_caddy -> isCartEmpty()) {
399
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
400
        }
401
        if ($commend_id == 0) {
402
            oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
403
        }
404
        // Check checkout level
405
        if ($checkout_level == 1) {
406
            oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
407
        }
408
        listCart();
409
        switch ($action) {
410
            case 'default' :
411
                $sform = new XoopsThemeForm(_OLEDRION_LOCATION_FORM, "informationfrm", OLEDRION_URL . 'checkout.php', 'post');
412
                $sform -> addElement(new XoopsFormHidden('op', 'save'));
413
                $sform -> addElement(new XoopsFormHidden('action', 'location'));
414
                $sform -> addElement(new XoopsFormHidden('commend_id', $commend_id));
415
                $pids = $h_oledrion_location -> getAllPid(new oledrion_parameters());
416
                $location_pid = new XoopsFormRadio(_OLEDRION_SELECT_LOCATION, 'location_id');
417
                foreach ($pids as $pid) {
418
                    $location_pid -> addOption($pid -> getVar('location_id'), $pid -> getVar('location_title'));
419
                }
420
                $sform -> addElement($location_pid, true);
421
                $sform -> addElement(new XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit'));
422
                $sform = oledrion_utils::formMarkRequiredFields($sform);
423
                $xoopsTpl -> assign('form', $sform -> render());
424
                break;
425
426
            case 'select' :
427
                $commande = $h_oledrion_commands -> get($commend_id);
428
                $sform = new XoopsThemeForm(_OLEDRION_LOCATION_FORM, "informationfrm", OLEDRION_URL . 'checkout.php', 'post');
429
                $sform -> addElement(new XoopsFormHidden('op', 'save'));
430
                $sform -> addElement(new XoopsFormHidden('action', 'location'));
431
                $sform -> addElement(new XoopsFormHidden('commend_id', $commend_id));
432
                $locations = $h_oledrion_location -> getLocation($commande -> getVar('cmd_location_id'));
433
                $location_select = new XoopsFormSelect(_OLEDRION_SELECT_LOCATION, 'location_id', '');
434
                foreach ($locations as $location) {
435
                    $location_select -> addOption($location -> getVar('location_id'), $location -> getVar('location_title'));
436
                }
437
                $sform -> addElement($location_select, true);
438
                $sform -> addElement(new XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit'));
439
                $sform = oledrion_utils::formMarkRequiredFields($sform);
440
                $xoopsTpl -> assign('form', $sform -> render());
441
                break;
442
        }
443
444
        // texte à afficher
445
        $registry = new oledrion_registryfile();
446
        $text = $registry -> getfile(OLEDRION_TEXTFILE6);
447
        $xoopsTpl -> assign('text', xoops_trim($text));
448
        break;
449
450 View Code Duplication
    case 'delivery' :
451
        if ($h_oledrion_caddy -> isCartEmpty()) {
452
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
453
        }
454
        if ($commend_id == 0) {
455
            oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
456
        }
457
        // Check checkout level
458
        if ($checkout_level == 1) {
459
            oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
460
        }
461
        listCart();
462
        $commande = $h_oledrion_commands -> get($commend_id);
463
        $location_id = $commande -> getVar('cmd_location_id');
464
        $deliveres = $h_oledrion_delivery -> getThisLocationDelivery($location_id);
465
466
        $sform = new XoopsThemeForm(_OLEDRION_DELIVERY_FORM, "informationfrm", OLEDRION_URL . 'checkout.php', 'post');
467
        $sform -> addElement(new XoopsFormHidden('op', 'save'));
468
        $sform -> addElement(new XoopsFormHidden('action', 'delivery'));
469
        $sform -> addElement(new XoopsFormHidden('commend_id', $commend_id));
470
        $delivery_options = new XoopsFormRadio(_OLEDRION_SELECT_DELIVERY, 'delivery_id');
471
        foreach ($deliveres as $delivery) {
472
            $delivery_options -> addOption($delivery['delivery_id'], oledrion_utils::deliveryHtmlSelect($delivery));
473
        }
474
        $sform -> addElement($delivery_options, true);
475
        $sform -> addElement(new XoopsFormButton('', 'post', _OLEDRION_SAVE_NEXT, 'submit'));
476
        $sform = oledrion_utils::formMarkRequiredFields($sform);
477
        $xoopsTpl -> assign('form', $sform -> render());
478
479
        // texte à afficher
480
        $registry = new oledrion_registryfile();
481
        $text = $registry -> getfile(OLEDRION_TEXTFILE6);
482
        $xoopsTpl -> assign('text', xoops_trim($text));
483
        break;
484
485 View Code Duplication
    case 'payment' :
486
        if ($h_oledrion_caddy -> isCartEmpty()) {
487
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
488
        }
489
        if ($commend_id == 0) {
490
            oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
491
        }
492
        // Check checkout level
493
        if ($checkout_level == 1) {
494
            oledrion_utils::redirect(_OLEDRION_FINAL_CHECKOUT, OLEDRION_URL . 'checkout.php?op=confirm&commend_id=' . $commend_id, 1);
495
        }
496
        listCart();
497
        $commande = $h_oledrion_commands -> get($commend_id);
498
        $delivery_id = $commande -> getVar('cmd_delivery_id');
499
        $payments = $h_oledrion_payment -> getThisDeliveryPayment($delivery_id);
500
501
        $sform = new XoopsThemeForm(_OLEDRION_PAYMENT_FORM, "informationfrm", OLEDRION_URL . 'checkout.php', 'post');
502
        $sform -> addElement(new XoopsFormHidden('op', 'save'));
503
        $sform -> addElement(new XoopsFormHidden('action', 'payment'));
504
        $sform -> addElement(new XoopsFormHidden('commend_id', $commend_id));
505
        $payment_options = new XoopsFormRadio(_OLEDRION_SELECT_PAYMENT, 'payment_id');
506
        foreach ($payments as $payment) {
507
            $payment_options -> addOption($payment['payment_id'], oledrion_utils::paymentHtmlSelect($payment));
508
        }
509
        $sform -> addElement($payment_options, true);
510
        $sform -> addElement(new XoopsFormButton('', 'post', _OLEDRION_SAVE_CONFIRM, 'submit'));
511
        $sform = oledrion_utils::formMarkRequiredFields($sform);
512
        $xoopsTpl -> assign('form', $sform -> render());
513
514
        // texte à afficher
515
        $registry = new oledrion_registryfile();
516
        $text = $registry -> getfile(OLEDRION_TEXTFILE6);
517
        $xoopsTpl -> assign('text', xoops_trim($text));
518
        break;
519
520
    // ****************************************************************************************************************
521
    case 'confirm' :
522
        // Validation finale avant envoi sur la passerelle de paiement (ou arrêt)
523
        // ****************************************************************************************************************
524
        if ($h_oledrion_caddy -> isCartEmpty()) {
525
            oledrion_utils::redirect(_OLEDRION_CART_IS_EMPTY, OLEDRION_URL, 4);
526
        }
527
        if ($commend_id == 0) {
528
            oledrion_utils::redirect(_OLEDRION_ERROR20, OLEDRION_URL, 4);
529
        }
530
        listCart();
531
532
        $commandAmountTTC = $commandAmountTTC + $commandAmountVAT;
533
534
        $commande = $h_oledrion_commands -> get($commend_id);
535
        if ($commande -> getVar('cmd_status') == 1) {
536
            oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL . 'invoice.php?id=' . $commande -> getVar('cmd_id') . '&pass=' . $commande -> getVar('cmd_password'), 6);
537
        }
538
        $commande -> setVar('cmd_create', time());
539
        $commande -> setVar('cmd_date', date("Y-m-d"));
540
        $commande -> setVar('cmd_state', OLEDRION_STATE_NOINFORMATION);
541
        $commande -> setVar('cmd_ip', oledrion_utils::IP());
542
        $commande -> setVar('cmd_status', 1);
543
        $res = $h_oledrion_commands -> insert($commande, true);
544
        if (!$res) {
545
            oledrion_utils::redirect(_OLEDRION_ERROR10, OLEDRION_URL, 6);
546
        }
547
548
        // Save command and empty cart
549
        $h_oledrion_caddy -> emptyCart();
550
551
        // Enregistrement du panier
552
        $msgCommande = '';
553
        $handlers = oledrion_handler::getInstance();
554
        foreach ($cartForTemplate as $line) {
555
            $panier = $h_oledrion_caddy -> create(true);
556
            $panier -> setVar('caddy_product_id', $line['product_id']);
557
            $panier -> setVar('caddy_qte', $line['product_qty']);
558
            $panier -> setVar('caddy_price', oledrion_utils::formatFloatForDB($line['totalPrice']));
559
            // Attention, prix TTC avec frais de port
560
            $panier -> setVar('caddy_cmd_id', $commande -> getVar('cmd_id'));
561
            $panier -> setVar('caddy_shipping', oledrion_utils::formatFloatForDB($line['discountedShipping']));
562
            $panier -> setVar('caddy_pass', md5(xoops_makepass()));
563
            // Pour le téléchargement
564
            $res = $h_oledrion_caddy -> insert($panier, true);
565
            // Make msg
566
            $cat = $h_oledrion_cat -> get($line['product_cid']) -> toArray();
567
            $msgCommande .= str_pad($line['product_id'], 5, ' ') . ' ';
568
            $msgCommande .= str_pad($cat['cat_title'], 10, ' ', STR_PAD_LEFT) . ' ';
569
            $msgCommande .= str_pad($line['product_title'], 19, ' ', STR_PAD_LEFT) . ' ';
570
            $msgCommande .= str_pad($line['product_qty'], 8, ' ', STR_PAD_LEFT) . ' ';
571
            $msgCommande .= str_pad($oledrion_Currency -> amountForDisplay($line['product_price']), 15, ' ', STR_PAD_LEFT) . ' ';
572
            //$msgCommande .= str_pad($line['totalPriceFormated'],10,' ', STR_PAD_LEFT) . ' ';
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
573
            $msgCommande .= "\n";
574
            // Attributs
575
            if ($res && is_array($line['attributes']) && count($line['attributes']) > 0) {
576
                // Enregistrement des attributs pour ce produit
577
                foreach ($line['attributes'] as $attributeId => $attributeInformation) {
578
                    $caddyAttribute = $handlers -> h_oledrion_caddy_attributes -> create(true);
579
                    $caddyAttribute -> setVar('ca_cmd_id', $commande -> getVar('cmd_id'));
580
                    $caddyAttribute -> setVar('ca_caddy_id', $panier -> getVar('caddy_id'));
581
                    $caddyAttribute -> setVar('ca_attribute_id', $attributeId);
582
                    $selectedOptions = $attributeInformation['attribute_options'];
583
                    $msgCommande .= '- ' . $attributeInformation['attribute_title'] . "\n";
584
                    foreach ($selectedOptions as $selectedOption) {
585
                        $caddyAttribute -> addOption($selectedOption['option_name'], $selectedOption['option_value'], $selectedOption['option_price']);
586
                        $msgCommande .= '    ' . $selectedOption['option_name'] . ' : ' . $selectedOption['option_ttc_formated'] . "\n";
587
                    }
588
                    $handlers -> h_oledrion_caddy_attributes -> insert($caddyAttribute, true);
589
                }
590
            }
591
        }
592
593
        // Totaux généraux
594
        //$msgCommande .= "\n\n"._OLEDRION_SHIPPING_PRICE.' '.$oledrion_Currency->amountForDisplay($shippingAmount)."\n";
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
595
        $msgCommande .= "\n\n" . _OLEDRION_TOTAL . " " . $oledrion_Currency -> amountForDisplay($commandAmountTTC) . "\n";
596
        if (count($discountsDescription) > 0) {
597
            $msgCommande .= "\n\n" . _OLEDRION_CART4 . "\n";
598
            $msgCommande .= implode("\n", $discountsDescription);
599
            $msgCommande .= "\n";
600
        }
601
602
        $msg = array();
603
        $msg['COMMANDE'] = $msgCommande;
604
        $msg['NUM_COMMANDE'] = $commande -> getVar('cmd_id');
605
        $msg['NOM'] = $commande -> getVar('cmd_lastname');
606
        $msg['PRENOM'] = $commande -> getVar('cmd_firstname');
607
        $msg['ADRESSE'] = $commande -> getVar('cmd_adress', 'n');
608
        $msg['CP'] = $commande -> getVar('cmd_zip');
609
        $msg['VILLE'] = $commande -> getVar('cmd_town');
610
        $msg['PAYS'] = $countries[$commande -> getVar('cmd_country')];
611
        $msg['TELEPHONE'] = $commande -> getVar('cmd_telephone');
612
        $msg['EMAIL'] = $commande -> getVar('cmd_email');
613
        $msg['URL_BILL'] = OLEDRION_URL . 'invoice.php?id=' . $commande -> getVar('cmd_id') . '&pass=' . $commande -> getVar('cmd_password');
614
        $msg['IP'] = oledrion_utils::IP();
615
        if ($commande -> getVar('cmd_bill') == 1) {
616
            $msg['FACTURE'] = _YES;
617
        } else {
618
            $msg['FACTURE'] = _NO;
619
        }
620
        // Send mail to client
621
        oledrion_utils::sendEmailFromTpl('command_client.tpl', $commande -> getVar('cmd_email'), sprintf(_OLEDRION_THANKYOU_CMD, $xoopsConfig['sitename']), $msg);
622
        // Send mail to admin
623
        oledrion_utils::sendEmailFromTpl('command_shop.tpl', oledrion_utils::getEmailsFromGroup(oledrion_utils::getModuleOption('grp_sold')), _OLEDRION_NEW_COMMAND, $msg);
624
625
        // Présentation du formulaire pour envoi à la passerelle de paiement
626
        // Présentation finale avec panier en variables cachées ******************************
627
        $registry = new oledrion_registryfile();
628
        $text = $registry -> getfile(OLEDRION_TEXTFILE7);
629
        $xoopsTpl -> assign('text', xoops_trim($text));
630
631
        if ($checkout_level == 1) {
632
            $text = $registry -> getfile(OLEDRION_TEXTFILE4);
633
            $xoopsTpl -> append('text', "<br />" . xoops_trim($text));
634
            $payURL = OLEDRION_URL . 'invoice.php?id=' . $commande -> getVar('cmd_id') . '&pass=' . $commande -> getVar('cmd_password');
635
            $sform = new XoopsThemeForm(_OLEDRION_FINISH, 'payform', $payURL, 'post');
636
        } else {
637
            if (!isset($payment) || $payment['payment_type'] == 'offline' || $commandAmountTTC == 0) {
638
                $text = $registry -> getfile(OLEDRION_TEXTFILE4);
639
                $xoopsTpl -> append('text', "<br />" . xoops_trim($text));
640
                $payURL = OLEDRION_URL . 'invoice.php?id=' . $commande -> getVar('cmd_id') . '&pass=' . $commande -> getVar('cmd_password');
641
                $sform = new XoopsThemeForm(_OLEDRION_FINISH, 'payform', $payURL, 'post');
642
            } else {
643
                // Set gateway
644
                $gateway = oledrion_gateways::getGatewayObject($payment['payment_gateway']);
645
                if (!is_object($gateway)) {
646
                    die(_OLEDRION_ERROR20);
647
                }
648
                if (is_object($gateway)) {
649
                    $payURL = $gateway -> getRedirectURL($commande -> getVar('cmd_total'), $commande -> getVar('cmd_id'));
650
                } else {
651
                    $payURL = OLEDRION_URL . 'invoice.php?id=' . $commande -> getVar('cmd_id') . '&pass=' . $commande -> getVar('cmd_password');
652
                }
653
                $sform = new XoopsThemeForm(_OLEDRION_PAY_GATEWAY, 'payform', $payURL, 'post');
654
                $elements = array();
655
                if (is_object($gateway)) {
656
                    $elements = $gateway -> getCheckoutFormContent($commande);
657
                }
658
                foreach ($elements as $key => $value) {
659
                    $sform -> addElement(new XoopsFormHidden($key, $value));
660
                }
661
            }
662
        }
663
664
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_AMOUNT_PRICE, $oledrion_Currency -> amountForDisplay($commandAmountTTC)));
665 View Code Duplication
        if ($commande -> getVar('cmd_shipping') > 0) {
666
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_SHIPPING_PRICE, $oledrion_Currency -> amountForDisplay($commande -> getVar('cmd_shipping'))));
667
        }
668 View Code Duplication
        if ($commande -> getVar('cmd_packing_price') > 0) {
669
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_PACKING_PRICE, $oledrion_Currency -> amountForDisplay($commande -> getVar('cmd_packing_price'))));
670
        }
671
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_TOTAL, $oledrion_Currency -> amountForDisplay($commandAmountTTC + $commande -> getVar('cmd_shipping') + $commande -> getVar('cmd_packing_price'))));
672
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_LASTNAME, $commande -> getVar('cmd_lastname')));
673
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_FIRSTNAME, $commande -> getVar('cmd_firstname')));
674
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_STREET, $commande -> getVar('cmd_adress')));
675
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_CP, $commande -> getVar('cmd_zip')));
676
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_CITY, $commande -> getVar('cmd_town')));
677
        if (oledrion_utils::getModuleOption('checkout_country')) {
678
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_COUNTRY, $countries[$commande -> getVar('cmd_country')]));
679
        }
680
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_PHONE, $commande -> getVar('cmd_telephone')));
681
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_MOBILE, $commande -> getVar('cmd_mobile')));
682
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_EMAIL, $commande -> getVar('cmd_email')));
683
        $sform -> addElement(new XoopsFormLabel(_OLEDRION_GIFT, $commande -> getVar('cmd_gift')));
684
        if ($commande -> getVar('cmd_packing')) {
685
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_PACKING, $commande -> getVar('cmd_packing')));
686
        }
687
        if ($commande -> getVar('cmd_location')) {
688
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_LOCATION, $commande -> getVar('cmd_location')));
689
        }
690
        if ($commande -> getVar('cmd_delivery')) {
691
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_DELIVERY, $commande -> getVar('cmd_delivery')));
692
        }
693
        if ($commande -> getVar('cmd_payment')) {
694
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_PAYMENT, $commande -> getVar('cmd_payment')));
695
        }
696
        if (oledrion_utils::getModuleOption('ask_vatnumber')) {
697
            $sform -> addElement(new XoopsFormLabel(_OLEDRION_VAT_NUMBER, $commande -> getVar('cmd_vat_number')));
698
        }
699
        if (oledrion_utils::getModuleOption('ask_bill')) {
700
            if ($commande -> getVar('cmd_bill') == 0) {
701
                $sform -> addElement(new XoopsFormLabel(_OLEDRION_INVOICE, _NO));
702
            } else {
703
                $sform -> addElement(new XoopsFormLabel(_OLEDRION_INVOICE, _YES));
704
            }
705
        }
706
        $button_tray = new XoopsFormElementTray('', '');
707
        if (!isset($payment) || $payment['payment_type'] == 'offline' || $commandAmountTTC == 0 || $checkout_level == 1) {
708
            $submit_btn = new XoopsFormButton('', 'post', _OLEDRION_FINISH, 'submit');
709
        } else {
710
            $submit_btn = new XoopsFormButton('', 'post', _OLEDRION_PAY_GATEWAY, 'submit');
711
        }
712
        $button_tray -> addElement($submit_btn);
713
        $sform -> addElement($button_tray);
714
        $xoopsTpl -> assign('form', $sform -> render());
715
716
        // Send sms
717
        if (oledrion_utils::getModuleOption('sms_checkout')) {
718
            $information['to'] = ltrim($commande -> getVar('cmd_mobile'), 0);
719
            $information['text'] = oledrion_utils::getModuleOption('sms_checkout_text');
720
            $sms = oledrion_sms::sendSms($information);
721
        }
722
        break;
723
}
724
725
$xoopsTpl -> assign('breadcrumb', oledrion_utils::breadcrumb(array(OLEDRION_URL . basename(__FILE__) => _OLEDRION_VALIDATE_CMD)));
726
727
// Image icons
728 View Code Duplication
if (file_exists(OLEDRION_PATH . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'step1.png')) {
729
    $step1 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step1.png';
730
    $step2 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step2.png';
731
    $step3 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step3.png';
732
} else {// Fallback
733
    $step1 = OLEDRION_URL . 'language/english/image/step1.png';
734
    $step2 = OLEDRION_URL . 'language/english/image/step2.png';
735
    $step3 = OLEDRION_URL . 'language/english/image/step3.png';
736
}
737
$xoopsTpl -> assign('step1', $step1);
738
$xoopsTpl -> assign('step2', $step2);
739
$xoopsTpl -> assign('step3', $step3);
740
741
$title = _OLEDRION_VALIDATE_CMD . ' - ' . oledrion_utils::getModuleName();
742
oledrion_utils::setMetas($title, $title);
743
oledrion_utils::setCSS();
744
oledrion_utils::setLocalCSS($xoopsConfig['language']);
745
require_once (XOOPS_ROOT_PATH . '/footer.php');
746