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

admin/actions/packing.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      Hossein Azizabadi ([email protected])
18
 */
19
20
/**
21
 * Check is admin
22
 */
23
if (!defined('OLEDRION_ADMIN')) {
24
    exit();
25
}
26
27
switch ($action) {
28
    case 'default':
29
        xoops_cp_header();
30
        $adminObject = \Xmf\Module\Admin::getInstance();
31
        $adminObject->displayNavigation('index.php?op=packing');
32
33
        $start   = isset($_GET['start']) ? (int)$_GET['start'] : 0;
34
        $packing = array();
35
        $form    = "<form method='post' action='$baseurl' name='frmaddpacking' id='frmaddpacking'><input type='hidden' name='op' id='op' value='packing'><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_ADMENU18, 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
        $packing = $h_oledrion_packing->getAllPacking(new Oledrion_parameters(array(
41
                                                                                  'start' => $start,
42
                                                                                  'limit' => $limit
43
                                                                              )));
44
45
        $class = '';
46
        echo "<table width='100%' cellspacing='1' cellpadding='3' border='0' class='outer'>";
47
        echo "<tr><th align='center'>" . _AM_OLEDRION_ID . "</th><th align='center'>" . _AM_OLEDRION_PACKING_TITLE . "</th><th align='center'>" . _OLEDRION_PRICE . "</th><th align='center'>" . _OLEDRION_ONLINE . "</th><th align='center'>" . _AM_OLEDRION_ACTION . '</th></tr>';
48
        foreach ($packing as $item) {
49
            $id        = $item->getVar('packing_id');
50
            $class     = ($class === 'even') ? 'odd' : 'even';
51
            $actions   = array();
52
            $actions[] = "<a href='$baseurl?op=packing&action=edit&id=" . $id . "' title='" . _OLEDRION_EDIT . "'>" . $icones['edit'] . '</a>';
53
            $actions[] = "<a href='$baseurl?op=packing&action=delete&id=" . $id . "' title='" . _OLEDRION_DELETE . "'" . $conf_msg . '>' . $icones['delete'] . '</a>';
54
            $online    = $item->getVar('packing_online') == 1 ? _YES : _NO;
55
            echo "<tr class='" . $class . "'>\n";
56
            echo "<td align='center'>" . $id . "</td><td align='center'>" . $item->getVar('packing_title') . "</td><td align='center'>" . $item->getVar('packing_price') . "</td><td align='center'>" . $online . "</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='5' align='center'>" . $form . "</td>\n";
62
        echo "</tr>\n";
63
        echo '</table>';
64
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
65
        break;
66
67
    case 'add':
68
    case 'edit':
69
        xoops_cp_header();
70 View Code Duplication
        if ($action === 'edit') {
71
            $title = _AM_OLEDRION_PACKING_EDIT;
72
            $id    = isset($_GET['id']) ? (int)$_GET['id'] : 0;
73
            if (empty($id)) {
74
                OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
75
            }
76
            // Item exits ?
77
            $item = null;
78
            $item = $h_oledrion_packing->get($id);
79
            if (!is_object($item)) {
80
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
81
            }
82
            $edit         = true;
83
            $label_submit = _AM_OLEDRION_MODIFY;
84
        } else {
85
            $title        = _AM_OLEDRION_PACKING_ADD;
86
            $item         = $h_oledrion_packing->create(true);
87
            $label_submit = _AM_OLEDRION_ADD;
88
            $edit         = false;
89
        }
90
        $sform = new XoopsThemeForm($title, 'frmaddpacking', $baseurl);
91
        $sform->addElement(new XoopsFormHidden('op', 'packing'));
92
        $sform->addElement(new XoopsFormHidden('action', 'save'));
93
        $sform->addElement(new XoopsFormHidden('packing_id', $item->getVar('packing_id')));
94
        $sform->addElement(new XoopsFormText(_AM_OLEDRION_PACKING_TITLE, 'packing_title', 50, 150, $item->getVar('packing_title', 'e')), true);
95
        $sform->addElement(new XoopsFormText(_AM_OLEDRION_PACKING_WIDTH, 'packing_width', 20, 20, $item->getVar('packing_width', 'e')), false);
96
        $sform->addElement(new XoopsFormText(_AM_OLEDRION_PACKING_LENGTH, 'packing_length', 20, 20, $item->getVar('packing_length', 'e')), false);
97
        $sform->addElement(new XoopsFormText(_AM_OLEDRION_PACKING_WEIGHT, 'packing_weight', 20, 20, $item->getVar('packing_weight', 'e')), false);
98 View Code Duplication
        if ($action === 'edit' && $item->pictureExists()) {
99
            $pictureTray = new XoopsFormElementTray(_AM_OLEDRION_CURRENT_PICTURE, '<br>');
100
            $pictureTray->addElement(new XoopsFormLabel('', "<img src='" . $item->getPictureUrl() . "' alt='' border='0'>"));
101
            $deleteCheckbox = new XoopsFormCheckBox('', 'delpicture');
102
            $deleteCheckbox->addOption(1, _DELETE);
103
            $pictureTray->addElement($deleteCheckbox);
104
            $sform->addElement($pictureTray);
105
            unset($pictureTray, $deleteCheckbox);
106
        }
107
        $sform->addElement(new XoopsFormFile(_AM_OLEDRION_PICTURE, 'attachedfile', OledrionUtility::getModuleOption('maxuploadsize')), false);
108
        $editor = OledrionUtility::getWysiwygForm(_AM_OLEDRION_DESCRIPTION, 'packing_description', $item->getVar('packing_description', 'e'), 15, 60, 'description_hidden');
109
        if ($editor) {
110
            $sform->addElement($editor, false);
111
        }
112
        $sform->addElement(new XoopsFormText(_AM_OLEDRION_PACKING_PRICE, 'packing_price', 20, 20, $item->getVar('packing_price', 'e')), false);
113
        $sform->addElement(new XoopsFormRadioYN(_OLEDRION_ONLINE_HLP, 'packing_online', $item->getVar('packing_online')), true);
114
        $button_tray = new XoopsFormElementTray('', '');
115
        $submit_btn  = new XoopsFormButton('', 'post', $label_submit, 'submit');
116
        $button_tray->addElement($submit_btn);
117
        $sform->addElement($button_tray);
118
        $sform =& OledrionUtility::formMarkRequiredFields($sform);
119
        $sform->display();
120
        require_once OLEDRION_ADMIN_PATH . 'admin_footer.php';
121
        break;
122
123
    case 'save':
124
        xoops_cp_header();
125
        $id = isset($_POST['packing_id']) ? (int)$_POST['packing_id'] : 0;
126
        if (!empty($id)) {
127
            $edit = true;
128
            $item = $h_oledrion_packing->get($id);
129
            if (!is_object($item)) {
130
                OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl, 5);
131
            }
132
            $item->unsetNew();
133
        } else {
134
            $item = $h_oledrion_packing->create(true);
135
        }
136
        $opRedirect = 'packing';
137
        $item->setVars($_POST);
138
139
        if (isset($_POST['delpicture']) && (int)$_POST['delpicture'] == 1) {
140
            $item->deletePicture();
141
        }
142
        $destname = '';
143
        $res1     = OledrionUtility::uploadFile(0, OLEDRION_PICTURES_PATH);
144 View Code Duplication
        if ($res1) {
145
            if (OledrionUtility::getModuleOption('resize_others')) { // Eventuellement on redimensionne l'image
146
                OledrionUtility::resizePicture(OLEDRION_PICTURES_PATH . '/' . $destname, OLEDRION_PICTURES_PATH . '/' . $destname, OledrionUtility::getModuleOption('images_width'), OledrionUtility::getModuleOption('images_height'), true);
147
            }
148
            $item->setVar('packing_image', basename($destname));
149
        } else {
150
            if ($res1 !== false) {
151
                echo $res1;
152
            }
153
        }
154
        $res = $h_oledrion_packing->insert($item);
155
        if ($res) {
156
            OledrionUtility::updateCache();
157
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
158
        } else {
159
            OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
160
        }
161
        break;
162
163 View Code Duplication
    case 'delete':
164
        xoops_cp_header();
165
        $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
166
        if ($id == 0) {
167
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
168
        }
169
        $packing = null;
170
        $packing = $h_oledrion_packing->get($id);
171
        if (!is_object($packing)) {
172
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_10, $baseurl, 5);
173
        }
174
        $msg = sprintf(_AM_OLEDRION_CONF_DEL_ITEM, $packing->getVar('packing_title'));
175
        xoops_confirm(array('op' => 'packing', 'action' => 'confdelete', 'id' => $id), 'index.php', $msg);
176
177
        break;
178
179 View Code Duplication
    case 'confdelete':
180
181
        xoops_cp_header();
182
        $id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
183
        if (empty($id)) {
184
            OledrionUtility::redirect(_AM_OLEDRION_ERROR_1, $baseurl, 5);
185
        }
186
        $opRedirect = 'packing';
187
188
        $item = null;
189
        $item = $h_oledrion_packing->get($id);
190
        if (is_object($item)) {
191
            $res = $h_oledrion_packing->delete($item);
192
            if ($res) {
193
                OledrionUtility::updateCache();
194
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_OK, $baseurl . '?op=' . $opRedirect, 2);
195
            } else {
196
                OledrionUtility::redirect(_AM_OLEDRION_SAVE_PB, $baseurl . '?op=' . $opRedirect, 5);
197
            }
198
        } else {
199
            OledrionUtility::redirect(_AM_OLEDRION_NOT_FOUND, $baseurl . '?op=' . $opRedirect, 5);
200
        }
201
        break;
202
}
203