Shopadmin::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
    HCSF - A multilingual CMS and Shopsystem
5
    Copyright (C) 2014  Marcus Haase - [email protected]
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 3 of the License, or
10
    (at your option) any later version.
11
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16
17
    You should have received a copy of the GNU General Public License
18
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
namespace HaaseIT\HCSF\Controller\Admin\Shop;
22
23
24
use HaaseIT\Toolbox\Tools;
25
use Zend\ServiceManager\ServiceManager;
26
27
/**
28
 * Class Shopadmin
29
 * @package HaaseIT\HCSF\Controller\Admin\Shop
30
 */
31
class Shopadmin extends Base
32
{
33
    /**
34
     * @var \Doctrine\DBAL\Connection
35
     */
36
    protected $dbal;
37
38
    /**
39
     * @var \HaaseIT\HCSF\HardcodedText
40
     */
41
    private $hardcodedtextcats;
42
43
    /**
44
     * Shopadmin constructor.
45
     * @param ServiceManager $serviceManager
46
     */
47
    public function __construct(ServiceManager $serviceManager)
48
    {
49
        parent::__construct($serviceManager);
50
        $this->dbal = $serviceManager->get('dbal');
51
        $this->hardcodedtextcats = $serviceManager->get('hardcodedtextcats');
52
    }
53
54
    /**
55
     *
56
     */
57
    public function preparePage()
58
    {
59
        $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager, [], 'admin/base.twig');
60
        $this->P->cb_pagetype = 'content';
61
        $this->P->cb_subnav = 'admin';
62
63
        $this->P->cb_customcontenttemplate = 'shop/shopadmin';
64
65
        if (filter_input(INPUT_POST, 'change') !== null) {
66
            $iID = filter_var(trim(Tools::getFormfield('id')), FILTER_SANITIZE_NUMBER_INT);
67
            $serverauthuser = filter_input(INPUT_SERVER, 'PHP_AUTH_USER', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
68
69
            $querybuilder = $this->dbal->createQueryBuilder();
70
            $querybuilder
71
                ->update('orders')
72
                ->set('o_lastedit_timestamp', ':o_lastedit_timestamp')
73
                ->set('o_remarks_internal', ':o_remarks_internal')
74
                ->set('o_transaction_no', ':o_transaction_no')
75
                ->set('o_paymentcompleted', ':o_paymentcompleted')
76
                ->set('o_ordercompleted', ':o_ordercompleted')
77
                ->set('o_lastedit_user', ':o_lastedit_user')
78
                ->set('o_shipping_service', ':o_shipping_service')
79
                ->set('o_shipping_trackingno', ':o_shipping_trackingno')
80
                ->where('o_id = :o_id')
81
                ->setParameter(':o_lastedit_timestamp', time())
82
                ->setParameter(':o_remarks_internal', filter_var(trim(Tools::getFormfield('remarks_internal')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
83
                ->setParameter(':o_transaction_no', filter_var(trim(Tools::getFormfield('transaction_no')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
84
                ->setParameter(':o_paymentcompleted', filter_var(trim(Tools::getFormfield('order_paymentcompleted')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
85
                ->setParameter(':o_ordercompleted', filter_var(trim(Tools::getFormfield('order_completed')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
86
                ->setParameter(':o_lastedit_user', !empty($serverauthuser) ? $serverauthuser : '')
87
                ->setParameter(':o_shipping_service', filter_var(trim(Tools::getFormfield('order_shipping_service')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
88
                ->setParameter(':o_shipping_trackingno', filter_var(trim(Tools::getFormfield('order_shipping_trackingno')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW))
89
                ->setParameter(':o_id', $iID)
90
            ;
91
            $querybuilder->execute();
92
            $this->helper->redirectToPage('/_admin/shopadmin.html?action=edit&id='.$iID);
93
        }
94
95
        $aPData = [
96
            'searchform_type' => Tools::getFormfield('type', 'openinwork'),
97
            'searchform_fromday' => Tools::getFormfield('fromday', '01'),
98
            'searchform_frommonth' => Tools::getFormfield('frommonth', '01'),
99
            'searchform_fromyear' => Tools::getFormfield('fromyear', '2014'),
100
            'searchform_today' => Tools::getFormfield('today', date('d')),
101
            'searchform_tomonth' => Tools::getFormfield('tomonth', date('m')),
102
            'searchform_toyear' => Tools::getFormfield('toyear', date('Y')),
103
        ];
104
105
        $CSA = [
106
            'list_orders' => [
107
                ['title' => '', 'key' => 'o_id', 'width' => 30, 'linked' => false, 'callback' => 'shopadminMakeCheckbox'],
108
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_orderid'), 'key' => 'o_id', 'width' => 30, 'linked' => false,],
109
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_customer'), 'key' => 'o_cust', 'width' => 280, 'linked' => false,],
110
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_sumnettoall'), 'key' => 'o_sumnettoall', 'width' => 75, 'linked' => false,],
111
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_orderstatus'), 'key' => 'o_order_status', 'width' => 80, 'linked' => false,],
112
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_ordertimenumber'), 'key' => 'o_ordertime_number', 'width' => 100, 'linked' => false,],
113
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_hostpayment'), 'key' => 'o_order_host_payment', 'width' => 140, 'linked' => false,],
114
                [
115
                    'title' => $this->hardcodedtextcats->get('shopadmin_list_edit'),
116
                    'key' => 'o_id',
117
                    'width' => 45,
118
                    'linked' => true,
119
                    'ltarget' => '/_admin/shopadmin.html',
120
                    'lkeyname' => 'id',
121
                    'lgetvars' => [
122
                        'action' => 'edit',
123
                    ],
124
                ],
125
            ],
126
            'list_orderitems' => [
127
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_itemno'), 'key' => 'oi_itemno', 'width' => 95, 'linked' => false,],
128
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_itemname'), 'key' => 'oi_itemname', 'width' => 350, 'linked' => false,],
129
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_itemamount'), 'key' => 'oi_amount', 'width' => 50, 'linked' => false, 'style-data' => 'text-align: center;',],
130
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_itemnetto'), 'key' => 'oi_price_netto', 'width' => 70, 'linked' => false,],
131
                ['title' => $this->hardcodedtextcats->get('shopadmin_list_itemsumnetto'), 'key' => 'ges_netto', 'width' => 75, 'linked' => false,],
132
            ],
133
        ];
134
135
        $aShopadmin = $this->handleShopAdmin($CSA);
136
137
        $this->P->cb_customdata = array_merge($aPData, $aShopadmin);
138
    }
139
140
    /**
141
     * @param $CSA
142
     * @return array
143
     */
144
    private function handleShopAdmin($CSA)
145
    {
146
        $aSData = [];
147
        $aData = [];
148
        $getaction = filter_input(INPUT_GET, 'action');
149
        if ($getaction === null) {
150
            $bIgnoreStorno = false;
151
152
            $querybuilder = $this->dbal->createQueryBuilder();
153
            $querybuilder
154
                ->select('*')
155
                ->from('orders')
156
                ->orderBy('o_ordertimestamp', 'DESC')
157
            ;
158
159
            $posttype = filter_input(INPUT_POST, 'type');
160
            $querybuilder->where('o_ordercompleted = ?');
161
            if ($posttype !== null) {
162
                switch ($posttype) {
163
                    case 'closed':
164
                        $querybuilder->setParameter(0, 'y');
165
                        break;
166
                    case 'open':
167
                        $querybuilder->setParameter(0, 'n');
168
                        break;
169
                    case 'inwork':
170
                        $querybuilder->setParameter(0, 'i');
171
                        break;
172
                    case 'storno':
173
                        $querybuilder->setParameter(0, 's');
174
                        break;
175
                    case 'deleted':
176
                        $querybuilder->setParameter(0, 'd');
177
                        break;
178
                    case 'all':
179
                        $querybuilder
180
                            ->where('o_ordercompleted != ?')
181
                            ->setParameter(0, 'd')
182
                        ;
183
                        $bIgnoreStorno = true;
184
                        break;
185
                    case 'openinwork':
186
                    default:
187
                    $querybuilder
188
                        ->where('o_ordercompleted = ? OR o_ordercompleted = ?')
189
                        ->setParameter(0, 'n')
190
                        ->setParameter(1, 'i')
191
                    ;
192
                }
193
            } else {
194
                $querybuilder
195
                    ->where('o_ordercompleted = ? OR o_ordercompleted = ?')
196
                    ->setParameter(0, 'n')
197
                    ->setParameter(1, 'i')
198
                ;
199
            }
200
201
            $sFrom = null;
0 ignored issues
show
Unused Code introduced by
$sFrom is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
202
            $sTo = null;
0 ignored issues
show
Unused Code introduced by
$sTo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
203
            if ($posttype === 'deleted' || $posttype === 'all' || $posttype === 'closed') {
204
                $sFrom = filter_input(INPUT_POST, 'fromyear', FILTER_SANITIZE_NUMBER_INT).'-'
205
                    .Tools::dateAddLeadingZero(filter_input(INPUT_POST, 'frommonth', FILTER_SANITIZE_NUMBER_INT)).'-'
206
                    .Tools::dateAddLeadingZero(filter_input(INPUT_POST, 'fromday', FILTER_SANITIZE_NUMBER_INT))
207
                ;
208
                $sTo = filter_input(INPUT_POST, 'toyear', FILTER_SANITIZE_NUMBER_INT).'-'
209
                    .Tools::dateAddLeadingZero(filter_input(INPUT_POST, 'tomonth', FILTER_SANITIZE_NUMBER_INT)).'-'
210
                    .Tools::dateAddLeadingZero(filter_input(INPUT_POST, 'today', FILTER_SANITIZE_NUMBER_INT));
211
212
                $querybuilder
213
                    ->andWhere('o_orderdate >= :from AND o_orderdate <= :to')
214
                    ->setParameter(':from', $sFrom)
215
                    ->setParameter(':to', $sTo)
216
                ;
217
            }
218
            $stmt = $querybuilder->execute();
219
220
            if ($stmt->rowCount() !== 0) {
221
                $i = 0;
222
                $j = 0;
223
                $k = 0;
224
                $fGesamtnetto = 0.0;
225
                while ($aRow = $stmt->fetch()) {
226
                    switch ($aRow['o_ordercompleted']) {
227
                        case 'y':
228
                            $sStatus = '<span style="color: green; font-weight: bold;">'.$this->hardcodedtextcats->get('shopadmin_orderstatus_completed').'</span>';
229
                            break;
230
                        case 'n':
231
                            $sStatus = '<span style="color: orange; font-weight: bold;">'.$this->hardcodedtextcats->get('shopadmin_orderstatus_open').'</span>';
232
                            break;
233
                        case 'i':
234
                            $sStatus = '<span style="color: orange;">'.$this->hardcodedtextcats->get('shopadmin_orderstatus_inwork').'</span>';
235
                            break;
236
                        case 's':
237
                            $sStatus = '<span style="color: red; font-weight: bold;">'.$this->hardcodedtextcats->get('shopadmin_orderstatus_canceled').'</span>';
238
                            break;
239
                        case 'd':
240
                            $sStatus = $this->hardcodedtextcats->get('shopadmin_orderstatus_deleted');
241
                            break;
242
                        default:
243
                            $sStatus = '';
244
                    }
245
246
                    if ($aRow['o_paymentcompleted'] === 'y') {
247
                        $sZahlungsmethode = '<span style="color: green;">';
248
                    } else {
249
                        $sZahlungsmethode = '<span style="color: red;">';
250
                    }
251
                    $mZahlungsmethode = $this->serviceManager->get('textcats')->T('order_paymentmethod_' .$aRow['o_paymentmethod'], true);
252
                    if ($mZahlungsmethode ) {
253
                        $sZahlungsmethode .= $mZahlungsmethode;
254
                    } else {
255
                        $sZahlungsmethode .= ucwords($aRow['o_paymentmethod']);
256
                    }
257
                    $sZahlungsmethode .= '</span>';
258
259
                    if (trim($aRow['o_corpname']) === '') {
260
                        $sName = $aRow['o_name'];
261
                    } else {
262
                        $sName = $aRow['o_corpname'];
263
                    }
264
265
                    $aData[] = [
266
                        'o_id' => $aRow['o_id'],
267
                        'o_account_no' => $aRow['o_custno'],
268
                        'o_email' => $aRow['o_email'],
269
                        'o_cust' => $sName.'<br>'.$aRow['o_zip'].' '.$aRow['o_town'],
270
                        'o_authed' => $aRow['o_authed'],
271
                        'o_sumnettoall' => number_format(
272
                                $aRow['o_sumnettoall'],
273
                                $this->config->getCore('numberformat_decimals'),
274
                                $this->config->getCore('numberformat_decimal_point'),
275
                                $this->config->getCore('numberformat_thousands_seperator')
276
                            )
277
                            .' '.$this->config->getShop('waehrungssymbol')
278
                            .(
279
                                ($aRow['o_mindermenge'] != 0 && $aRow['o_mindermenge'] !== '')
280
                                    ? '<br>+'.number_format(
281
                                        $aRow['o_mindermenge'],
282
                                        $this->config->getCore('numberformat_decimals'),
283
                                        $this->config->getCore('numberformat_decimal_point'),
284
                                        $this->config->getCore('numberformat_thousands_seperator')
285
                                    ).' '.$this->config->getShop('waehrungssymbol') : ''),
286
                        'o_order_status' => $sStatus.((trim($aRow['o_lastedit_user']) !== '') ? '<br>'.$aRow['o_lastedit_user'] : ''),
287
                        'o_ordertime_number' => date(
288
                            $this->config->getCore('locale_format_date_time'),
289
                                $aRow['o_ordertimestamp']
290
                            )
291
                            .((trim($aRow['o_transaction_no']) !== '') ? '<br>'.$aRow['o_transaction_no'] : ''),
292
                        'o_order_host_payment' => $sZahlungsmethode.'<br>'.$aRow['o_srv_hostname'],
293
                    ];
294
                    if (!($bIgnoreStorno && $aRow['o_ordercompleted'] === 's')) {
295
                        $fGesamtnetto += $aRow['o_sumnettoall'];
296
                        $j ++;
297
                    } else {
298
                        $k++;
299
                    }
300
                    $i++;
301
                }
302
                $aSData['listtable_orders'] = Tools::makeListtable($CSA['list_orders'], $aData, $this->serviceManager->get('twig'));
303
                $aSData['listtable_i'] = $i;
304
                $aSData['listtable_j'] = $j;
305
                $aSData['listtable_k'] = $k;
306
                $aSData['listtable_gesamtnetto'] = $fGesamtnetto;
307
            } else {
308
                $aSData['nomatchingordersfound'] = true;
309
            }
310
        } elseif ($getaction === 'edit') {
311
            $iId = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
312
            $querybuilder = $this->dbal->createQueryBuilder();
313
            $querybuilder
314
                ->select('*')
315
                ->from('orders')
316
                ->where('o_id = ?')
317
                ->setParameter(0, $iId)
318
            ;
319
            $stmt = $querybuilder->execute();
320
            if ($stmt->rowCount() === 1) {
321
                $aSData['orderdata'] = $stmt->fetch();
322
323
                $querybuilder = $this->dbal->createQueryBuilder();
324
                $querybuilder
325
                    ->select('*')
326
                    ->from('orders_items')
327
                    ->where('oi_o_id = ?')
328
                    ->setParameter(0, $iId)
329
                ;
330
                $stmt = $querybuilder->execute();
331
                $aItems = $stmt->fetchAll();
332
333
                $aUserdata = [
334
                    'cust_no' => $aSData['orderdata']['o_custno'],
335
                    'cust_email' => $aSData['orderdata']['o_email'],
336
                    'cust_corp' => $aSData['orderdata']['o_corpname'],
337
                    'cust_name' => $aSData['orderdata']['o_name'],
338
                    'cust_street' => $aSData['orderdata']['o_street'],
339
                    'cust_zip' => $aSData['orderdata']['o_zip'],
340
                    'cust_town' => $aSData['orderdata']['o_town'],
341
                    'cust_phone' => $aSData['orderdata']['o_phone'],
342
                    'cust_cellphone' => $aSData['orderdata']['o_cellphone'],
343
                    'cust_fax' => $aSData['orderdata']['o_fax'],
344
                    'cust_country' => $aSData['orderdata']['o_country'],
345
                    'cust_group' => $aSData['orderdata']['o_group'],
346
                ];
347
                $aSData['customerform'] = $this->helperCustomer->buildCustomerForm(
348
                    $this->config->getLang(),
349
                    'shopadmin',
350
                    [],
351
                    $aUserdata
0 ignored issues
show
Documentation introduced by
$aUserdata is of type array<string,?,{"cust_no...:"?","cust_group":"?"}>, but the function expects a boolean.

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...
352
                );
353
354
                $aSData['orderdata']['options_shippingservices'] = [''];
355
                foreach ($this->config->getShop('shipping_services') as $sValue) {
356
                    $aSData['orderdata']['options_shippingservices'][] = $sValue;
357
                }
358
359
                $aItemsCarttable = [];
360
                foreach ($aItems as $aValue) {
361
                    $aPrice = [
362
                        'netto_list' => $aValue['oi_price_netto_list'],
363
                        'netto_sale' => $aValue['oi_price_netto_sale'],
364
                        'netto_rebated' => $aValue['oi_price_netto_rebated'],
365
                        'netto_use' => $aValue['oi_price_netto_use'],
366
                        'brutto_use' => $aValue['oi_price_brutto_use'],
367
                    ];
368
369
                    $aItemsCarttable[$aValue['oi_cartkey']] = [
370
                        'amount' => $aValue['oi_amount'],
371
                        'price' => $aPrice,
372
                        'vat' => $aValue['oi_vat'],
373
                        'rg' => $aValue['oi_rg'],
374
                        'rg_rebate' => $aValue['oi_rg_rebate'],
375
                        'name' => $aValue['oi_itemname'],
376
                        'img' => $aValue['oi_img'],
377
                    ];
378
                }
379
380
                $aSData = array_merge(
381
                    $this->helperShop->buildShoppingCartTable(
382
                        $aItemsCarttable,
383
                        true,
384
                        $aSData['orderdata']['o_group'],
385
                        [],
386
                        $aSData['orderdata']['o_vatfull'],
387
                        $aSData['orderdata']['o_vatreduced']
388
                    ),
389
                    $aSData);
390
            } else {
391
                $aSData['ordernotfound'] = true;
392
            }
393
        }
394
395
        return $aSData;
396
    }
397
}
398