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

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 68 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: caddy.php 12290 2014-02-07 11:05:17Z beckmi $
19
 */
20
21
/**
22
 * Affichage et gestion du caddy
23
 */
24
require 'header.php';
25
$GLOBALS['current_category'] = -1;
26
$xoopsOption['template_main'] = 'oledrion_caddy.tpl';
27
require_once XOOPS_ROOT_PATH . '/header.php';
28
require_once OLEDRION_PATH . 'class/registryfile.php';
29
30
$xoopsTpl->assign('mod_pref', $mod_pref); // Préférences du module
31
32
if (oledrion_utils::getModuleOption('restrict_orders', false)) {
33
    $registry = new oledrion_registryfile();
34
    $text = $registry->getfile(OLEDRION_TEXTFILE5);
35
    $xoopsTpl->assign('restrict_orders_text', xoops_trim($text));
36
} else {
37
    $xoopsTpl->assign('restrict_orders_text', '');
38
}
39
40
$op = 'default';
41 View Code Duplication
if (isset($_POST['op'])) {
42
    $op = $_POST['op'];
43
} elseif (isset($_GET['op'])) {
44
    $op = $_GET['op'];
45
}
46
47
$productId = 0;
48 View Code Duplication
if (isset($_POST['product_id'])) {
49
    $productId = intval($_POST['product_id']);
50
} elseif (isset($_GET['product_id'])) {
51
    $productId = intval($_GET['product_id']);
52
}
53
54
$xoopsTpl->assign('op', $op);
55
$xoopsTpl->assign('confEmpty', oledrion_utils::javascriptLinkConfirm(_OLEDRION_EMPTY_CART_SURE, true));
56
$xoopsTpl->assign('confirm_delete_item', oledrion_utils::javascriptLinkConfirm(_OLEDRION_EMPTY_ITEM_SURE, false));
57
58
$uid = oledrion_utils::getCurrentUserID();
59
if ($uid > 0) {
60
    $xoopsTpl->assign('isCartExists', $h_oledrion_persistent_cart->isCartExists());
61
} else {
62
    $xoopsTpl->assign('isCartExists', false);
63
}
64
65
// ********************************************************************************************************************
66
// Liste le contenu du caddy
67
// ********************************************************************************************************************
68
function listCart()
69
{
70
    global $xoopsTpl, $uid;
71
    $cartForTemplate = $discountsDescription = array();
72
    $emptyCart = false;
73
    $shippingAmount = $commandAmount = $vatAmount = $commandAmountTTC = $discountsCount = $ecotaxeAmount = $discountAmount = $totalSavings = 0;
74
    $goOn = '';
75
    $reductions = new oledrion_reductions();
76
    $reductions->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription, $discountsCount, $ecotaxeAmount, $discountAmount, $totalSavings );
77
    $oledrion_Currency = & oledrion_Currency::getInstance();
78
    $xoopsTpl->assign('emptyCart', $emptyCart);                                            // Caddy Vide ?
79
    $xoopsTpl->assign('caddieProducts', $cartForTemplate);                                // Produits dans le caddy
80
    $xoopsTpl->assign('shippingAmount', $oledrion_Currency->amountForDisplay($shippingAmount));        // Montant des frais de port
81
    $xoopsTpl->assign('ecotaxeAmount', $oledrion_Currency->amountForDisplay($ecotaxeAmount));        // Montant des frais de port
82
    $xoopsTpl->assign('commandAmount', $oledrion_Currency->amountForDisplay($commandAmount));        // Montant HT de la commande
83
    $xoopsTpl->assign('discountAmount', $oledrion_Currency->amountForDisplay($discountAmount));        // Total Discount
84
    $xoopsTpl->assign('totalSavings', $oledrion_Currency->amountForDisplay($totalSavings));        // Total Savings
85
    $xoopsTpl->assign('vatAmount', $oledrion_Currency->amountForDisplay($vatAmount));                // Montant de la TVA
86
    $xoopsTpl->assign('discountsCount', $discountsCount);                                // Nombre de réductions appliquées
87
    $xoopsTpl->assign('goOn', $goOn);                                                    // Adresse à utiliser pour continuer ses achats
88
    $xoopsTpl->assign('commandAmountTTC', $oledrion_Currency->amountForDisplay($commandAmountTTC, 'l'));    // Montant TTC de la commande
89
    $xoopsTpl->assign('discountsDescription', $discountsDescription);                    // Liste des réductions accordées
90
    $showOrderButton = true;
91
    $showRegistredOnly = false;
92
    if (oledrion_utils::getModuleOption('restrict_orders', false) && $uid == 0) {
93
        $showRegistredOnly = true;
94
        $showOrderButton = false;
95
    }
96
    $xoopsTpl->assign('showRegistredOnly', $showRegistredOnly);
97
    $xoopsTpl->assign('showOrderButton', $showOrderButton);
98
}
99
100
// ********************************************************************************************************************
101
// ********************************************************************************************************************
102
// ********************************************************************************************************************
103
switch ($op) {
104
    // ****************************************************************************************************************
105
    case 'update': // Recalcul des quantités
106
        // ****************************************************************************************************************
107
        $h_oledrion_caddy->updateQuantites();
108
        listCart();
109
        break;
110
111
    // ****************************************************************************************************************
112
    case 'reload': // Chargement du dernier panier enregistré
113
        // ****************************************************************************************************************
114
        $h_oledrion_caddy->reloadPersistentCart();
115
        listCart();
116
        break;
117
118
    // ****************************************************************************************************************
119
    case 'delete': // Suppression d'un élément
120
        // ****************************************************************************************************************
121
        $productId--;
122
        $h_oledrion_caddy->deleteProduct($productId);
123
        listCart();
124
        break;
125
126
    // ****************************************************************************************************************
127
    case 'addproduct': // Ajout d'un produit
128
        // ****************************************************************************************************************
129
        if ($productId == 0) {
130
            oledrion_utils::redirect(_OLEDRION_ERROR9, 'index.php', 4);
131
        }
132
        $product = null;
133
        $product = $h_oledrion_products->get($productId);
134
        if (!is_object($product)) {
135
            oledrion_utils::redirect(_OLEDRION_ERROR9, 'index.php', 4);
136
        }
137
        if ($product->getVar('product_online') == 0) {
138
            oledrion_utils::redirect(_OLEDRION_ERROR2, 'index.php', 4);
139
        }
140
141
        if ($product->getVar('product_stock') - 1 >= 0) {
142
            // Options
143
            $userAttributes = array();
144
            if ($product->productAttributesCount() > 0) { // Si le produit a des attributs
145
                $productAttributes = array();
146
                // On commence par vérifier que les attributs obligatoires sont renseignés
147
                // It starts by checking if mandatory attributes are filled
148
                if ($product->getProductMandatoryAttributesCount()) {
149
                    $mandatoryFieldsList = array();
150
                    $mandatoryFieldsList = $product->getProductMandatoryFieldsList();
151
                    if (count($mandatoryFieldsList) > 0) {
152
                        $productUrl = $product->getLink();
153
                        foreach ($mandatoryFieldsList as $mandatoryField) {
154
                            $mandatoryFieldKey = $mandatoryField->getAttributeNameInForm();
155
                            $mandatoryFieldText = $mandatoryField->getVar('attribute_title');
156
                            if (!isset($_POST[$mandatoryFieldKey]) && !$mandatoryField->hasDefaultValue()) {
157
                                oledrion_utils::redirect(sprintf(_OLEDRION_MANDATORY_MISSED, $mandatoryFieldText), $productUrl, 4);
158
                            }
159
                        }
160
                    }
161
                }
162
                // Toujours là c'est que le produit a des attributs et qu'ils sont renseignés
163
                //Checks if the product has more options and if they are set
164
                $productAttributes = $product->getProductsAttributesList();
165
                foreach ($productAttributes as $attribute) {
166
                    $nameInForm = $attribute->getAttributeNameInForm();
167
                    if (isset($_POST[$nameInForm])) {
168
                        $userAttributes[$attribute->attribute_id] = $_POST[$nameInForm];
169
                    } else { // On va chercher sa valeur par défaut
170
                        if ($attribute->hasDefaultValue()) {
171
                            $userAttributes[$attribute->attribute_id] = $attribute->getAttributeDefaultValue();
172
                        }
173
                    }
174
                }
175
            }
176
            $h_oledrion_caddy->addProduct($productId, 1, $userAttributes);
177
            $url = OLEDRION_URL . 'caddy.php';
178
            if (!OLEDRION_CART_BUG) {
179
                header("Location: $url");
180
            } else {
181
                listCart();
182
            }
183
        } else {
184
            oledrion_utils::redirect(_OLEDRION_PROBLEM_QTY, 'index.php', 5); // Plus de stock !
185
        }
186
        listCart();
187
        break;
188
189
    // ****************************************************************************************************************
190
    case 'empty': // Suppression du contenu du caddy
191
        // ****************************************************************************************************************
192
        $h_oledrion_caddy->emptyCart();
193
        listCart();
194
        break;
195
196
    // ****************************************************************************************************************
197
    case 'default': // Action par défaut
198
        // ****************************************************************************************************************
199
        listCart();
200
        break;
201
}
202
203
// Image icons
204 View Code Duplication
if (file_exists(OLEDRION_PATH . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . 'step1.png')) {
205
    $step1 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step1.png';
206
    $step2 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step2.png';
207
    $step3 = OLEDRION_URL . 'language/' . $xoopsConfig['language'] . '/image/step3.png';
208
} else { // Fallback
209
    $step1 = OLEDRION_URL . 'language/english/image/step1.png';
210
    $step2 = OLEDRION_URL . 'language/english/image/step2.png';
211
    $step3 = OLEDRION_URL . 'language/english/image/step3.png';
212
}
213
$xoopsTpl->assign('step1', $step1);
214
$xoopsTpl->assign('step2', $step2);
215
$xoopsTpl->assign('step3', $step3);
216
217
oledrion_utils::setCSS();
218
oledrion_utils::setLocalCSS($xoopsConfig['language']);
219
oledrion_utils::loadLanguageFile('modinfo.php');
220
221
$xoopsTpl->assign('breadcrumb', oledrion_utils::breadcrumb(array(OLEDRION_URL . basename(__FILE__) => _MI_OLEDRION_SMNAME1)));
222
223
$title = _MI_OLEDRION_SMNAME1 . ' - ' . oledrion_utils::getModuleName();
224
oledrion_utils::setMetas($title, $title);
225
require_once XOOPS_ROOT_PATH . '/footer.php';
226