caddy.php ➔ listCaddie()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
1
<?php
2
//  ------------------------------------------------------------------------ //
3
//                      BOOKSHOP - MODULE FOR XOOPS 2                        //
4
//                  Copyright (c) 2007, 2008 Instant Zero                    //
5
//                     <http://www.instant-zero.com/>                        //
6
// ------------------------------------------------------------------------- //
7
//  This program is free software; you can redistribute it and/or modify     //
8
//  it under the terms of the GNU General Public License as published by     //
9
//  the Free Software Foundation; either version 2 of the License, or        //
10
//  (at your option) any later version.                                      //
11
//                                                                           //
12
//  You may not change or alter any portion of this comment or credits       //
13
//  of supporting developers from this source code or any supporting         //
14
//  source code which is considered copyrighted (c) material of the          //
15
//  original comment or credit authors.                                      //
16
//                                                                           //
17
//  This program is distributed in the hope that it will be useful,          //
18
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
//  GNU General Public License for more details.                             //
21
//                                                                           //
22
//  You should have received a copy of the GNU General Public License        //
23
//  along with this program; if not, write to the Free Software              //
24
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
//  ------------------------------------------------------------------------ //
26
/**
27
 * Affichage et gestion du caddy
28
 */
29
include __DIR__ . '/header.php';
30
$GLOBALS['current_category']  = -1;
31
$xoopsOption['template_main'] = 'bookshop_caddy.tpl';
32
include_once XOOPS_ROOT_PATH . '/header.php';
33
34
$xoopsTpl->assign('mod_pref', $mod_pref);    // Module Preferences
35
36
$op = 'default';
37 View Code Duplication
if (isset($_POST['op'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    $op = $_POST['op'];
39
} elseif (isset($_GET['op'])) {
40
    $op = $_GET['op'];
41
}
42
43
$book_id = 0;
44
if (isset($_POST['book_id'])) {
45
    $book_id = $_POST['book_id'];
46
} elseif (isset($_GET['book_id'])) {
47
    $book_id = $_GET['book_id'];
48
}
49
50
$xoopsTpl->assign('op', $op);
51
$xoopsTpl->assign('confEmpty', bookshop_JavascriptLinkConfirm(_BOOKSHOP_EMPTY_CART_SURE, true));
52
$xoopsTpl->assign('confirm_delete_book', bookshop_JavascriptLinkConfirm(_BOOKSHOP_EMPTY_ITEM_SURE, false));
53
54
// ********************************************************************************************************************
55
// Liste le contenu du caddy
56
// ********************************************************************************************************************
57
function listCaddie()
58
{
59
    global $xoopsTpl, $h_bookshop_caddy;
60
    $cartForTemplate      = array();
61
    $emptyCart            = false;
62
    $shippingAmount       = 0;
63
    $commandAmount        = 0;
64
    $vatAmount            = 0;
65
    $goOn                 = '';
66
    $commandAmountTTC     = 0;
67
    $discountsDescription = array();
68
69
    $h_bookshop_caddy->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription);
70
    $dec = bookshop_getmoduleoption('decimals_count');
71
72
    $xoopsTpl->assign('emptyCart', $emptyCart);                                            // Empty shopping cart??
73
    $xoopsTpl->assign('caddieProducts', $cartForTemplate);                                //  Products in the cart
74
    $xoopsTpl->assign('shippingAmount', sprintf('%0.' . $dec . 'f', $shippingAmount));        // Shipping Cost
75
    $xoopsTpl->assign('commandAmount', sprintf('%0.' . $dec . 'f', $commandAmount));        // Net amount of the order
76
    $xoopsTpl->assign('vatAmount', sprintf('%0.' . $dec . 'f', $vatAmount));                // Amount of VAT
77
    $xoopsTpl->assign('goOn', $goOn);                                                    // Address use to continue its purchases
78
    $xoopsTpl->assign('commandAmountTTC', sprintf('%0.' . $dec . 'f', $commandAmountTTC));    // Amount of tax control
79
    $xoopsTpl->assign('discountsDescription', $discountsDescription);                    // List of discounts granted
80
}
81
82
// ********************************************************************************************************************
83
// ********************************************************************************************************************
84
// ********************************************************************************************************************
85
switch ($op) {
86
    // ****************************************************************************************************************
87
    case 'update':    // Update quantities
88
        // ****************************************************************************************************************
89
        $h_bookshop_caddy->updateQuantites();
90
        listCaddie();
91
        break;
92
93
    // ****************************************************************************************************************
94
    case 'delete':    // Delete an item
95
        // ****************************************************************************************************************
96
        $book_id--;
97
        $h_bookshop_caddy->deleteProduct($book_id);
98
        listCaddie();
99
        break;
100
101
    // ****************************************************************************************************************
102
    case 'addbook':    // Add  a book
103
        // ****************************************************************************************************************
104
        if ($book_id == 0) {
105
            bookshop_redirect(_BOOKSHOP_ERROR9, 'index.php', 4);
106
        }
107
108
        $book = null;
109
        $book = $h_bookshop_books->get($book_id);
110
        if (!is_object($book)) {
111
            bookshop_redirect(_BOOKSHOP_ERROR9, 'index.php', 4);
112
        }
113
        if ($book->getVar('book_online') == 0) {
114
            bookshop_redirect(_BOOKSHOP_ERROR2, 'index.php', 4);
115
        }
116
117
        if ($book->getVar('book_stock') - 1 >= 0) {
118
            $h_bookshop_caddy->addProduct($book_id, 1);
119
            $url = BOOKSHOP_URL . 'caddy.php';
120
            header("Location: $url");
121
        } else {
122
            bookshop_redirect(_BOOKSHOP_PROBLEM_QTY, 'index.php', 5);    // Plus de stock !
123
        }
124
        listCaddie();
125
        break;
126
127
    // ****************************************************************************************************************
128
    case 'empty':    // Empty content of the shopping cart
129
        // ****************************************************************************************************************
130
        $h_bookshop_caddy->emptyCart();
131
        listCaddie();
132
        break;
133
134
    // ****************************************************************************************************************
135
    case 'default':    // Default Action
136
        // ****************************************************************************************************************
137
        listCaddie();
138
        break;
139
}
140
141
bookshop_setCSS();
142 View Code Duplication
if (file_exists(BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/modinfo.php')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
    include_once BOOKSHOP_PATH . 'language/' . $xoopsConfig['language'] . '/modinfo.php';
144
} else {
145
    include_once BOOKSHOP_PATH . 'language/english/modinfo.php';
146
}
147
148
$title = _MI_BOOKSHOP_SMNAME1 . ' - ' . bookshop_get_module_name();
149
bookshop_set_metas($title, $title);
150
include_once XOOPS_ROOT_PATH . '/footer.php';
151