Completed
Push — master ( 9d3fbd...af269e )
by Michael
09:48
created

admin/actions/lowstock.php (1 issue)

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
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   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
/**
21
 * Gestion des stocks bas (dans l'administration)
22
 */
23
if (!defined('OLEDRION_ADMIN')) {
24
    exit();
25
}
26
switch ($action) {
27
    // ****************************************************************************************************************
28
    case 'default': // Stock bas
29
        // ****************************************************************************************************************
30
        xoops_cp_header();
31
        $adminObject = \Xmf\Module\Admin::getInstance();
32
        $adminObject->displayNavigation('index.php?op=lowstock');
33
34
        //        OledrionUtility::htitle(_MI_OLEDRION_ADMENU9, 4);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
35
        $start    = isset($_GET['start']) ? (int)$_GET['start'] : 0;
36
        $criteria = new CriteriaCompo();
37
        // Recherche des produits dont la quantité en stock est inférieure ou égale à la quantité d'alerte et ou la quantité d'alerte est supérieure à 0
38
        $itemsCount = $h_oledrion_products->getLowStocksCount();
39
        if ($itemsCount > $limit) {
40
            $pagenav = new XoopsPageNav($itemsCount, $limit, $start, 'start', 'op=lowstock');
41
        }
42
        $products = $h_oledrion_products->getLowStocks($start, $limit);
43
        $class    = $name = '';
44
        $names    = array();
45
        echo "<form name='frmupdatequant' id='frmupdatequant' method='post' action='$baseurl'><input type='hidden' name='op' id='op' value='lowstock'><input type='hidden' name='action' id='action' value='updatequantities'>";
46
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
47
        echo "<tr><th align='center'>" . _OLEDRION_TITLE . "</th><th align='center'>" . _OLEDRION_STOCK_QUANTITY . "</th><th align='center'>" . _OLEDRION_STOCK_ALERT . "</th><th align='center'>" . _AM_OLEDRION_NEW_QUANTITY . '</th></tr>';
48
        foreach ($products as $item) {
49
            $id    = $item->getVar('product_id');
50
            $class = ($class === 'even') ? 'odd' : 'even';
51
            $link  = "<a href='" . $item->getLink() . "'>" . $item->getVar('product_title') . '</a>';
52
            echo "<tr class='" . $class . "'>\n";
53
            $name    = 'qty_' . $id;
54
            $names[] = $id;
55
            echo '<td>' . $link . "</td><td align='center'>" . $item->getVar('product_stock') . "</td><td align='center'>" . $item->getVar('product_alert_stock') . "</td><td align='center'><input type='text' name='$name' id='$name' size='3' maxlength='5' value=''></td>\n";
56
            echo "<tr>\n";
57
        }
58
        $class = ($class === 'even') ? 'odd' : 'even';
59
        if (count($names) > 0) {
60
            echo "<tr class='$class'><td colspan='3' align='center'>&nbsp;</td><td align='center'><input type='hidden' name='names' id='names' value='" . implode('|', $names) . "'><input type='submit' name='btngo' id='btngo' value='" . _AM_OLEDRION_UPDATE_QUANTITIES . "'></td></tr>";
61
        }
62
        echo '</table></form>';
63
        if (isset($pagenav) && is_object($pagenav)) {
64
            echo "<div align='right'>" . $pagenav->renderNav() . '</div>';
65
        }
66
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
67
        break;
68
69
    // ****************************************************************************************************************
70
    case 'updatequantities': // Mise à jour des quantités des produits
71
        // ****************************************************************************************************************
72
        $names = array();
73
        if (isset($_POST['names'])) {
74
            $names = explode('|', $_POST['names']);
75
            foreach ($names as $item) {
76
                $name = 'qty_' . $item;
77
                if (isset($_POST[$name]) && xoops_trim($_POST[$name]) != '') {
78
                    $quantity   = (int)$_POST[$name];
79
                    $product_id = (int)$item;
80
                    $product    = null;
81
                    $product    = $h_oledrion_products->get($product_id);
82
                    if (is_object($product)) {
83
                        $h_oledrion_products->updateAll('product_stock', $quantity, new Criteria('product_id', $product_id, '='), true);
84
                    }
85
                }
86
            }
87
        }
88
        OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=lowstock', 2);
89
        break;
90
91
}
92