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

admin/actions/manufacturers.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 fabricants (dans l'administration)
22
 */
23
if (!defined('OLEDRION_ADMIN')) {
24
    exit();
25
}
26
switch ($action) {
27
    // ****************************************************************************************************************
28
    case 'default': // Liste des fabricants
29
        // ****************************************************************************************************************
30
        xoops_cp_header();
31
        $adminObject = \Xmf\Module\Admin::getInstance();
32
        $adminObject->displayNavigation('index.php?op=manufacturers');
33
34
        $vats = array();
35
        $form = "<form method='post' action='$baseurl' name='frmaddmanufacturer' id='frmaddmanufacturer'><input type='hidden' name='op' id='op' value='manufacturers'><input type='hidden' name='action' id='action' value='add'><input type='submit' name='btngo' id='btngo' value='"
36
                . _AM_OLEDRION_ADD_ITEM
37
                . "'></form>";
38
        echo $form;
39
        //        OledrionUtility::htitle(_MI_OLEDRION_ADMENU3, 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...
40
41
        $start    = isset($_GET['start']) ? (int)$_GET['start'] : 0;
42
        $criteria = new CriteriaCompo();
43
        $criteria->add(new Criteria('manu_id', 0, '<>'));
44
45
        $itemsCount = $h_oledrion_manufacturer->getCount($criteria); // Recherche du nombre total de fabricants
46
        if ($itemsCount > $limit) {
47
            $pagenav = new XoopsPageNav($itemsCount, $limit, $start, 'start', 'op=manufacturers');
48
        }
49
50
        $criteria->setLimit($limit);
51
        $criteria->setStart($start);
52
        $criteria->setSort('manu_name, manu_commercialname');
53
54
        $manufacturers = $h_oledrion_manufacturer->getObjects($criteria);
55
        $class         = '';
56
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
57
        if (isset($pagenav) && is_object($pagenav)) {
58
            echo "<tr><td colspan='2' align='left'>" . $pagenav->renderNav() . "</td><td align='right' colspan='3'>&nbsp;</td></tr>\n";
59
        }
60
        echo "<tr><th align='center'>" . _OLEDRION_LASTNAME . "</th><th align='center'>" . _OLEDRION_COMM_NAME . "</th><th align='center'>" . _OLEDRION_EMAIL . "</th><th align='center'>" . _AM_OLEDRION_ACTION . '</th></tr>';
61
        foreach ($manufacturers as $item) {
62
            $class     = ($class === 'even') ? 'odd' : 'even';
63
            $id        = $item->getVar('manu_id');
64
            $actions   = array();
65
            $actions[] = "<a href='$baseurl?op=manufacturers&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icones['edit'] . '</a>';
66
            $actions[] = "<a href='$baseurl?op=manufacturers&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>';
67
            echo "<tr class='" . $class . "'>\n";
68
            echo "<td><a href='" . $item->getLink() . "'>" . $item->getVar('manu_name') . "</a></td><td align='left'>" . $item->getVar('manu_commercialname') . "</td><td align='center'>" . $item->getVar('manu_email') . "</td><td align='center'>" . implode(' ', $actions) . "</td>\n";
69
            echo "<tr>\n";
70
        }
71
        $class = ($class === 'even') ? 'odd' : 'even';
72
        echo "<tr class='" . $class . "'>\n";
73
        echo "<td colspan='4' align='center'>" . $form . "</td>\n";
74
        echo "</tr>\n";
75
        echo '</table>';
76
        if (isset($pagenav) && is_object($pagenav)) {
77
            echo "<div align='right'>" . $pagenav->renderNav() . '</div>';
78
        }
79
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
80
        break;
81
82
    // ****************************************************************************************************************
83
    case 'add': // Ajout d'un fabricant
84
    case 'edit': // Edition d'un fabricant
85
        // ****************************************************************************************************************
86
        xoops_cp_header();
87 View Code Duplication
        if ($action === 'edit') {
88
            $title = _AM_OLEDRION_EDIT_MANUFACTURER;
89
            $id    = isset($_GET['id']) ? (int)$_GET['id'] : 0;
90
            if (empty($id)) {
91
                OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
92
            }
93
            // Item exits ?
94
            $item = null;
95
            $item = $h_oledrion_manufacturer->get($id);
96
            if (!is_object($item)) {
97
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
98
            }
99
            $edit         = true;
100
            $label_submit = _AM_OLEDRION_MODIFY;
101
        } else {
102
            $title        = _AM_OLEDRION_ADD_MANUFACTURER;
103
            $item         = $h_oledrion_manufacturer->create(true);
104
            $label_submit = _AM_OLEDRION_ADD;
105
            $edit         = false;
106
        }
107
108
        $sform = new XoopsThemeForm($title, 'frmmanufacturer', $baseurl);
109
        $sform->setExtra('enctype="multipart/form-data"');
110
        $sform->addElement(new XoopsFormHidden('op', 'manufacturers'));
111
        $sform->addElement(new XoopsFormHidden('action', 'saveedit'));
112
        $sform->addElement(new XoopsFormHidden('manu_id', $item->getVar('manu_id')));
113
        $sform->addElement(new XoopsFormText(_OLEDRION_LASTNAME, 'manu_name', 50, 255, $item->getVar('manu_name', 'e')), true);
114
        $sform->addElement(new XoopsFormText(_OLEDRION_COMM_NAME, 'manu_commercialname', 50, 255, $item->getVar('manu_commercialname', 'e')), false);
115
        $sform->addElement(new XoopsFormText(_OLEDRION_EMAIL, 'manu_email', 50, 255, $item->getVar('manu_email', 'e')), false);
116
        $sform->addElement(new XoopsFormText(_OLEDRION_SITEURL, 'manu_url', 50, 255, $item->getVar('manu_url', 'e')), false);
117
118
        $editor = OledrionUtility::getWysiwygForm(_OLEDRION_MANUFACTURER_INF, 'manu_bio', $item->getVar('manu_bio', 'e'), 15, 60, 'bio_hidden');
119
        if ($editor) {
120
            $sform->addElement($editor, false);
121
        }
122
        // Les 5 images
123
        for ($i = 1; $i <= 5; ++$i) {
124
            if ($action === 'edit' && $item->pictureExists($i)) {
125
                $pictureTray = new XoopsFormElementTray(_AM_OLEDRION_CURRENT_PICTURE, '<br>');
126
                $pictureTray->addElement(new XoopsFormLabel('', "<img src='" . $item->getPictureUrl($i) . "' alt='' border='0'>"));
127
                $deleteCheckbox = new XoopsFormCheckBox('', 'delpicture' . $i);
128
                $deleteCheckbox->addOption(1, _DELETE);
129
                $pictureTray->addElement($deleteCheckbox);
130
                $sform->addElement($pictureTray);
131
                unset($pictureTray, $deleteCheckbox);
132
            }
133
            $sform->addElement(new XoopsFormFile(_AM_OLEDRION_PICTURE . ' ' . $i, 'attachedfile' . $i, OledrionUtility::getModuleOption('maxuploadsize')), false);
134
        }
135
136
        $button_tray = new XoopsFormElementTray('', '');
137
        $submit_btn  = new XoopsFormButton('', 'post', $label_submit, 'submit');
138
        $button_tray->addElement($submit_btn);
139
        $sform->addElement($button_tray);
140
141
        $sform =& OledrionUtility::formMarkRequiredFields($sform);
142
        $sform->display();
143
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
144
        break;
145
146
    // ****************************************************************************************************************
147
    case 'saveedit': // Sauvegarde d'un fabricant
148
        // ****************************************************************************************************************
149
        xoops_cp_header();
150
        $id = isset($_POST['manu_id']) ? (int)$_POST['manu_id'] : 0;
151
        if (!empty($id)) {
152
            $edit = true;
153
            $item = $h_oledrion_manufacturer->get($id);
154
            if (!is_object($item)) {
155
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
156
            }
157
            $item->unsetNew();
158
        } else {
159
            $item = $h_oledrion_manufacturer->create(true);
160
        }
161
        $opRedirect = 'manufacturers';
162
        $item->setVars($_POST);
163
        for ($i = 1; $i <= 5; ++$i) {
164
            if (isset($_POST['delpicture' . $i]) && (int)$_POST['delpicture' . $i] == 1) {
165
                $item->deletePicture($i);
166
            }
167
        }
168
169
        // Upload des fichiers
170
        for ($i = 1; $i <= 5; ++$i) {
171
            $res1 = OledrionUtility::uploadFile($i - 1, OLEDRION_PICTURES_PATH);
172 View Code Duplication
            if ($res1 === true) {
173
                if (OledrionUtility::getModuleOption('resize_others')) { // Eventuellement on redimensionne l'image
174
                    OledrionUtility::resizePicture(OLEDRION_PICTURES_PATH . '/' . $destname, OLEDRION_PICTURES_PATH . 'l' . $destname, OledrionUtility::getModuleOption('images_width'), OledrionUtility::getModuleOption('images_height'), true);
175
                }
176
                $item->setVar('manu_photo' . $i, basename($destname));
177
            } else {
178
                if ($res1 !== false) {
179
                    echo $res1;
180
                }
181
            }
182
        }
183
184
        $res = $h_oledrion_manufacturer->insert($item);
185
        if ($res) {
186
            OledrionUtility::updateCache();
187
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
188
        } else {
189
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
190
        }
191
        break;
192
193
    // ****************************************************************************************************************
194 View Code Duplication
    case 'delete': // Suppression d'un fabricant
195
        // ****************************************************************************************************************
196
        xoops_cp_header();
197
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
198
        if (empty($id)) {
199
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
200
        }
201
        $opRedirect = 'manufacturers';
202
        // On vérifie que ce fabriquant n'est pas relié à des produits
203
        $cnt = $h_oledrion_manufacturer->getManufacturerProductsCount($id);
204
        if ($cnt == 0) {
205
            $item = null;
206
            $item = $h_oledrion_manufacturer->get($id);
207
            if (is_object($item)) {
208
                $res = $h_oledrion_manufacturer->deleteManufacturer($item);
209
                if ($res) {
210
                    OledrionUtility::updateCache();
211
                    OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
212
                } else {
213
                    OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
214
                }
215
            } else {
216
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
217
            }
218
        } else {
219
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_5, $baseurl . '?op=' . $opRedirect, 5);
220
        }
221
        break;
222
}
223