checkout.php ➔ listCart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
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
 * Entering Customer Data + display information entered for validation with redirection to Paypal
28
 */
29
include __DIR__ . '/header.php';
30
$GLOBALS['current_category']  = -1;
31
$xoopsOption['template_main'] = 'bookshop_command.tpl';
32
include_once XOOPS_ROOT_PATH . '/header.php';
33
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
34
include_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
35
include_once BOOKSHOP_PATH . 'class/bookshop_paypal.php';
36
37
$op = 'default';
38
if (isset($_POST['op'])) {
39
    $op = $_POST['op'];
40
}
41
42
$xoopsTpl->assign('op', $op);
43
$cartForTemplate      = array();
44
$emptyCart            = false;
45
$shippingAmount       = $commandAmount = $vatAmount = $commandAmountTTC = 0;
46
$goOn                 = '';
47
$discountsDescription = array();
48
49
function listCart()
50
{
51
    global $h_bookshop_caddy, $cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription;
52
    $h_bookshop_caddy->computeCart($cartForTemplate, $emptyCart, $shippingAmount, $commandAmount, $vatAmount, $goOn, $commandAmountTTC, $discountsDescription);
53
    $dec              = bookshop_getmoduleoption('decimals_count');
54
    $shippingAmount   = sprintf('%0.' . $dec . 'f', $shippingAmount);        // Amount of postage
55
    $commandAmount    = sprintf('%0.' . $dec . 'f', $commandAmount);        // Amount HT command
56
    $vatAmount        = sprintf('%0.' . $dec . 'f', $vatAmount);                // Amount of VAT
57
    $commandAmountTTC = sprintf('%0.' . $dec . 'f', $commandAmountTTC);    // Amount TTC of the order (shipping included)
58
}
59
60
$tbl_country = XoopsLists::getCountryList();
61
if (is_object($xoopsUser)) {
62
    $uid = $xoopsUser->getVar('uid');
63
} else {
64
    $uid = 0;
65
}
66
67
switch ($op) {
68
    // ****************************************************************************************************************
69
    case 'default': // Submitting Forms
70
        // ****************************************************************************************************************
71
        if ($h_bookshop_caddy->isCartEmpty()) {
72
            bookshop_redirect(_BOOKSHOP_CART_IS_EMPTY, BOOKSHOP_URL, 4);
73
        }
74
        listCart();
75
        $notFound = true;
76
77
        if ($uid > 0) {    // Si c'est un utlisateur enregistr�, on recherche dans les anciennes commandes pour pr� remplir les champs
78
            $tblCommand  = array();
79
            $critereUser = new Criteria('cmd_uid', $uid, '=');
80
            $critereUser->setSort('cmd_date');
81
            $critereUser->setOrder('DESC');
82
            $critereUser->setLimit(1);
83
            $tblCommand = $h_bookshop_commands->getObjects($critereUser, false);
84
            if (count($tblCommand) > 0) {
85
                $notFound = false;
86
                $commande = $tblCommand[0];
87
            }
88
        }
89
90
        if ($notFound) {
91
            $commande = $h_bookshop_commands->create(true);
92
        }
93
94
        $sform = new XoopsThemeForm(_BOOKSHOP_PLEASE_ENTER, 'informationfrm', BOOKSHOP_URL . 'checkout.php', 'post');
95
        $sform->addElement(new XoopsFormHidden('op', 'paypal'));
96
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_TOTAL, $commandAmountTTC . ' ' . bookshop_getmoduleoption('money_full')));
97
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_SHIPPING_PRICE, $shippingAmount . ' ' . bookshop_getmoduleoption('money_full')));
98
        $sform->addElement(new XoopsFormText(_BOOKSHOP_LASTNAME, 'cmd_lastname', 50, 255, $commande->getVar('cmd_lastname')), true);
99
        $sform->addElement(new XoopsFormText(_BOOKSHOP_FIRSTNAME, 'cmd_firstname', 50, 255, $commande->getVar('cmd_firstname')), false);
100
        $sform->addElement(new XoopsFormTextArea(_BOOKSHOP_STREET, 'cmd_adress', $commande->getVar('cmd_adress'), 3, 50), true);
101
        $sform->addElement(new XoopsFormText(_BOOKSHOP_CP, 'cmd_zip', 5, 30, $commande->getVar('cmd_zip')), true);
102
        $sform->addElement(new XoopsFormText(_BOOKSHOP_CITY, 'cmd_town', 40, 255, $commande->getVar('cmd_town')), true);
103
        $sform->addElement(new XoopsFormSelectCountry(_BOOKSHOP_COUNTRY, 'cmd_country', $commande->getVar('cmd_country')), true);
104
        $sform->addElement(new XoopsFormText(_BOOKSHOP_PHONE, 'cmd_telephone', 15, 50, $commande->getVar('cmd_telephone')), false);
105
        if ($uid > 0) {
106
            $sform->addElement(new XoopsFormText(_BOOKSHOP_EMAIL, 'cmd_email', 50, 255, $xoopsUser->getVar('email')), true);
107
        } else {
108
            $sform->addElement(new XoopsFormText(_BOOKSHOP_EMAIL, 'cmd_email', 50, 255, ''), true);
109
        }
110
        $sform->addElement(new XoopsFormRadioYN(_BOOKSHOP_INVOICE, 'cmd_bill', 0), true);
111
112
        $button_tray = new XoopsFormElementTray('', '');
113
        $submit_btn  = new XoopsFormButton('', 'post', _BOOKSHOP_SAVE, 'submit');
114
        $button_tray->addElement($submit_btn);
115
        $sform->addElement($button_tray);
116
117
        $sform = bookshop_formMarkRequiredFields($sform);
118
        $xoopsTpl->assign('form', $sform->render());
119
        break;
120
121
    // ****************************************************************************************************************
122
    case 'paypal':    // Validation finale avant envoi sur Paypal
123
        // ****************************************************************************************************************
124
        if ($h_bookshop_caddy->isCartEmpty()) {
125
            bookshop_redirect(_BOOKSHOP_CART_IS_EMPTY, BOOKSHOP_URL, 4);
126
        }
127
        listCart();
128
129
        $password       = md5(xoops_makepass());
130
        $passwordCancel = md5(xoops_makepass());
131
        $paypal         = new bookshop_paypal(bookshop_getmoduleoption('paypal_test'), bookshop_getmoduleoption('paypal_email'), bookshop_getmoduleoption('paypal_money'), true, $passwordCancel);
132
133
        $commande = $h_bookshop_commands->create(true);
134
        $commande->setVars($_POST);
135
        $commande->setVar('cmd_uid', $uid);
136
        $commande->setVar('cmd_date', date('Y-m-d'));
137
        $commande->setVar('cmd_state', COMMAND_STATE_NOINFORMATION);
138
        $commande->setVar('cmd_ip', bookshop_IP());
139
        $commande->setVar('cmd_articles_count', count($cartForTemplate));
140
        $commande->setVar('cmd_total', $commandAmountTTC);
141
        $commande->setVar('cmd_shipping', $shippingAmount);
142
        $commande->setVar('cmd_password', $password);
143
        $commande->setVar('cmd_cancel', $passwordCancel);
144
        $commande->setVar('cmd_text', implode("\n", $discountsDescription));
145
        $res = $h_bookshop_commands->insert($commande, true);
146
        if (!$res) {    // Si la sauvegarde n'a pas fonctionn�
147
            bookshop_redirect(_BOOKSHOP_ERROR10, BOOKSHOP_URL, 6);
148
        }
149
150
        // Enregistrement du panier
151
        $msgCommande = '';
152
        foreach ($cartForTemplate as $line) {
153
            $panier = $h_bookshop_caddy->create(true);
154
            $panier->setVar('caddy_book_id', $line['book_id']);
155
            $panier->setVar('caddy_qte', $line['book_qty']);
156
            $panier->setVar('caddy_price', $line['book_price_ttc']);    // Attention, prix TTC
157
            $panier->setVar('caddy_cmd_id', $commande->getVar('cmd_id'));
158
            $panier->setVar('caddy_shipping', $line['book_shipping_amount']);
159
            $msgCommande .= str_pad(wordwrap($line['book_title'], 60), 60, ' ') . ' ' . str_pad($line['book_qty'] . ' ' . _BOOKSHOP_COPY_COUNT, 8, ' ', STR_PAD_LEFT) . ' ' . str_pad($line['book_price_ttc'] . ' ' . bookshop_getmoduleoption('money_short'), 10, ' ', STR_PAD_LEFT) . ' '
160
                            . str_pad($line['book_shipping_amount'] . ' ' . bookshop_getmoduleoption('money_short'), 10, ' ', STR_PAD_LEFT) . "\n";
161
            $res = $h_bookshop_caddy->insert($panier, true);
162
        }
163
        $msgCommande .= "\n\n" . _BOOKSHOP_SHIPPING_PRICE . ' ' . $shippingAmount . ' ' . bookshop_getmoduleoption('money_full') . "\n";
164
        $msgCommande .= _BOOKSHOP_TOTAL . ' ' . $commandAmountTTC . ' ' . bookshop_getmoduleoption('money_full') . "\n";
165
        if (count($discountsDescription) > 0) {
166
            $msgCommande .= "\n\n" . _BOOKSHOP_CART4 . "\n";
167
            $msgCommande .= implode("\n", $discountsDescription);
168
            $msgCommande .= "\n";
169
        }
170
        $msg                 = array();
171
        $msg['COMMANDE']     = $msgCommande;
172
        $msg['NUM_COMMANDE'] = $commande->getVar('cmd_id');
173
        $msg['NOM']          = $commande->getVar('cmd_lastname');
174
        $msg['PRENOM']       = $commande->getVar('cmd_firstname');
175
        $msg['ADRESSE']      = $commande->getVar('cmd_adress');
176
        $msg['CP']           = $commande->getVar('cmd_zip');
177
        $msg['VILLE']        = $commande->getVar('cmd_town');
178
        $msg['PAYS']         = $tbl_country[$commande->getVar('cmd_country')];
179
        $msg['TELEPHONE']    = $commande->getVar('cmd_telephone');
180
        $msg['EMAIL']        = $commande->getVar('cmd_email');
181
        $msg['URL_BILL']     = BOOKSHOP_URL . 'invoice.php?command=' . $commande->getVar('cmd_id') . '&pass=' . $password;
182
        $msg['IP']           = bookshop_IP();
183
        if ($commande->getVar('cmd_bill') == 1) {
184
            $msg['FACTURE'] = _YES;
185
        } else {
186
            $msg['FACTURE'] = _NO;
187
        }
188
        // Envoi du mail au client
189
        bookshop_send_email_from_tpl('command_client.tpl', $commande->getVar('cmd_email'), sprintf(_BOOKSHOP_THANKYOU_CMD, $xoopsConfig['sitename']), $msg);
190
        // Envoi du mail au groupe de personne devant recevoir le mail
191
        bookshop_send_email_from_tpl('command_shop.tpl', bookshop_getEmailsFromGroup(bookshop_getmoduleoption('grp_sold')), _BOOKSHOP_NEW_COMMAND, $msg);
0 ignored issues
show
Documentation introduced by
bookshop_getmoduleoption('grp_sold') is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
192
193
        // Presentation of the form to send to Paypal
194
        $payURL = $paypal->getURL();
195
196
        // Final presentation with hidden variables basket  ******************************
197
        $sform    = new XoopsThemeForm(_BOOKSHOP_PAY_PAYPAL, 'payform', $payURL, 'post');
198
        $elements = array();
199
        $elements = $paypal->getFormContent($commande->getVar('cmd_id'), $commandAmountTTC, $commande->getVar('cmd_email'));
200
        foreach ($elements as $key => $value) {
201
            $sform->addElement(new XoopsFormHidden($key, $value));
202
        }
203
204
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_TOTAL, $commandAmountTTC . ' ' . bookshop_getmoduleoption('money_full')));
205
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_SHIPPING_PRICE, $shippingAmount . ' ' . bookshop_getmoduleoption('money_full')));
206
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_LASTNAME, $commande->getVar('cmd_lastname')));
207
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_FIRSTNAME, $commande->getVar('cmd_firstname')));
208
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_STREET, $commande->getVar('cmd_adress')));
209
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_CP, $commande->getVar('cmd_zip')));
210
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_CITY, $commande->getVar('cmd_town')));
211
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_COUNTRY, $tbl_country[$commande->getVar('cmd_country')]));
212
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_PHONE, $commande->getVar('cmd_telephone')));
213
        $sform->addElement(new XoopsFormLabel(_BOOKSHOP_EMAIL, $commande->getVar('cmd_email')));
214
215
        if ($commande->getVar('cmd_bill') == 0) {
216
            $sform->addElement(new XoopsFormLabel(_BOOKSHOP_INVOICE, _NO));
217
        } else {
218
            $sform->addElement(new XoopsFormLabel(_BOOKSHOP_INVOICE, _YES));
219
        }
220
        $button_tray = new XoopsFormElementTray('', '');
221
        $submit_btn  = new XoopsFormButton('', 'post', _BOOKSHOP_PAY_PAYPAL, 'submit');
222
        $button_tray->addElement($submit_btn);
223
        $sform->addElement($button_tray);
224
        $xoopsTpl->assign('form', $sform->render());
225
        break;
226
}
227
$title = _BOOKSHOP_VALIDATE_CMD . ' - ' . bookshop_get_module_name();
228
bookshop_set_metas($title, $title);
229
bookshop_setCSS();
230
include_once(XOOPS_ROOT_PATH . '/footer.php');
231