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

admin/actions/vendors.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
 * Actions relatives aux vendeurs (affichage, édition, suppression)
22
 */
23
if (!defined('OLEDRION_ADMIN')) {
24
    exit();
25
}
26
switch ($action) {
27
    // ****************************************************************************************************************
28
    case 'default': // Gestion des vendeurs
29
        // ****************************************************************************************************************
30
        xoops_cp_header();
31
        $adminObject = \Xmf\Module\Admin::getInstance();
32
        $adminObject->displayNavigation('index.php?op=vendors');
33
34
        $start   = isset($_GET['start']) ? (int)$_GET['start'] : 0;
35
        $vendors = array();
36
        $form    = "<form method='post' action='$baseurl' name='frmaddvendor' id='frmaddvendor'><input type='hidden' name='op' id='op' value='vendors'><input type='hidden' name='action' id='action' value='add'><input type='submit' name='btngo' id='btngo' value='"
37
                   . _AM_OLEDRION_ADD_ITEM
38
                   . "'></form>";
39
        echo $form;
40
        //        OledrionUtility::htitle(_MI_OLEDRION_ADMENU0, 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...
41
42
        $vendors = $h_oledrion_vendors->getAllVendors(new Oledrion_parameters(array(
43
                                                                                  'start' => $start,
44
                                                                                  'limit' => $limit
45
                                                                              )));
46
        $class   = '';
47
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
48
        echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _OLEDRION_VENDOR . "</th><th align='center'>" . _AM_OLEDRION_ACTION . '</th></tr>';
49
        foreach ($vendors as $item) {
50
            $id        = $item->getVar('vendor_id');
51
            $class     = ($class === 'even') ? 'odd' : 'even';
52
            $actions   = array();
53
            $actions[] = "<a href='$baseurl?op=vendors&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icones['edit'] . '</a>';
54
            $actions[] = "<a href='$baseurl?op=vendors&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>';
55
            echo "<tr class='" . $class . "'>\n";
56
            echo "<td align='center'>" . $id . "</td><td align='center'>" . $item->getVar('vendor_name') . "</td><td align='center'>" . implode(' ', $actions) . "</td>\n";
57
            echo "<tr>\n";
58
        }
59
        $class = ($class === 'even') ? 'odd' : 'even';
60
        echo "<tr class='" . $class . "'>\n";
61
        echo "<td colspan='3' align='center'>" . $form . "</td>\n";
62
        echo "</tr>\n";
63
        echo '</table>';
64
65
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
66
        break;
67
68
    // ****************************************************************************************************************
69
    case 'add': // Ajout d'un vendeur
70
    case 'edit': // Edition d'un vendeur
71
        // ****************************************************************************************************************
72
        xoops_cp_header();
73 View Code Duplication
        if ($action === 'edit') {
74
            $title = _AM_OLEDRION_EDIT_VENDOR;
75
            $id    = isset($_GET['id']) ? (int)$_GET['id'] : 0;
76
            if (empty($id)) {
77
                OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
78
            }
79
            // Item exits ?
80
            $item = null;
81
            $item = $h_oledrion_vendors->get($id);
82
            if (!is_object($item)) {
83
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
84
            }
85
            $edit         = true;
86
            $label_submit = _AM_OLEDRION_MODIFY;
87
        } else {
88
            $title        = _AM_OLEDRION_ADD_VENDOR;
89
            $item         = $h_oledrion_vendors->create(true);
90
            $label_submit = _AM_OLEDRION_ADD;
91
            $edit         = false;
92
        }
93
        $sform = new XoopsThemeForm($title, 'frmaddvendor', $baseurl);
94
        $sform->addElement(new XoopsFormHidden('op', 'vendors'));
95
        $sform->addElement(new XoopsFormHidden('action', 'saveedit'));
96
        $sform->addElement(new XoopsFormHidden('vendor_id', $item->getVar('vendor_id')));
97
        $sform->addElement(new XoopsFormText(_OLEDRION_VENDOR, 'vendor_name', 50, 150, $item->getVar('vendor_name', 'e')), true);
98
99
        $button_tray = new XoopsFormElementTray('', '');
100
        $submit_btn  = new XoopsFormButton('', 'post', $label_submit, 'submit');
101
        $button_tray->addElement($submit_btn);
102
        $sform->addElement($button_tray);
103
        $sform =& OledrionUtility::formMarkRequiredFields($sform);
104
        $sform->display();
105
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
106
        break;
107
108
    // ****************************************************************************************************************
109 View Code Duplication
    case 'saveedit': // Sauvegarde d'un vendeur (édition et ajout)
110
        // ****************************************************************************************************************
111
        xoops_cp_header();
112
        $id = isset($_POST['vendor_id']) ? (int)$_POST['vendor_id'] : 0;
113
        if (!empty($id)) {
114
            $edit = true;
115
            $item = $h_oledrion_vendors->get($id);
116
            if (!is_object($item)) {
117
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
118
            }
119
            $item->unsetNew();
120
        } else {
121
            $item = $h_oledrion_vendors->create(true);
122
        }
123
        $opRedirect = 'vendors';
124
        $item->setVars($_POST);
125
        $res = $h_oledrion_vendors->insert($item);
126
        if ($res) {
127
            OledrionUtility::updateCache();
128
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
129
        } else {
130
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
131
        }
132
        break;
133
134
    // ****************************************************************************************************************
135 View Code Duplication
    case 'delete': // Suppression d'un vendeur
136
        // ****************************************************************************************************************
137
        xoops_cp_header();
138
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
139
        if (empty($id)) {
140
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
141
        }
142
        $opRedirect = 'vendors';
143
        // On vérifie que ce vendeur n'est pas rattaché à des produits
144
        $cnt = $h_oledrion_vendors->getVendorProductsCount($id);
145
        if ($cnt == 0) {
146
            $item = null;
147
            $item = $h_oledrion_vendors->get($id);
148
            if (is_object($item)) {
149
                $res = $h_oledrion_vendors->deleteVendor($item);
150
                if ($res) {
151
                    OledrionUtility::updateCache();
152
                    OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
153
                } else {
154
                    OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
155
                }
156
            } else {
157
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
158
            }
159
        } else {
160
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_6, $baseurl . '?op=' . $opRedirect, 5);
161
        }
162
        break;
163
}
164