Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

admin/public-category.php (2 issues)

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
 * ExtGallery Admin settings
4
 * Manage admin pages
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   {@link https://xoops.org/ XOOPS Project}
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Zoullou (http://www.zoullou.net)
16
 * @package     ExtGallery
17
 */
18
19
require_once __DIR__ . '/admin_header.php';
20
21
if (isset($_GET['op'])) {
22
    $op = $_GET['op'];
23
} else {
24
    $op = 'default';
25
}
26
27
if (isset($_POST['step'])) {
28
    $step = $_POST['step'];
29
} else {
30
    $step = 'default';
31
}
32
33
switch ($op) {
34
35
    case 'create':
36
37
        switch ($step) {
38
39
            case 'enreg':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
40
41
                /** @var \ExtgalleryPublicCatHandler $catHandler */
42
                $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
43
                $data       = [
44
                    'cat_pid'    => $_POST['cat_pid'],
45
                    'cat_name'   => $_POST['cat_name'],
46
                    'cat_desc'   => $_POST['cat_desc'],
47
                    'cat_weight' => $_POST['cat_weight'],
48
                    'cat_date'   => time(),
49
                    'cat_imgurl' => $_POST['cat_imgurl']
50
                ];
51
                $catHandler->createCat($data);
52
53
                redirect_header('public-category.php', 3, _AM_EXTGALLERY_CAT_CREATED);
54
55
                break;
56
57
        }
58
59
        break;
60
61
    case 'modify':
62
63
        switch ($step) {
64
65
            case 'enreg':
66
67
                if (isset($_POST['submit'])) {
68
                    $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
69
                    $catHandler->modifyCat($_POST);
70
71
                    redirect_header('public-category.php', 3, _AM_EXTGALLERY_CAT_MODIFIED);
72
                } elseif ($_POST['delete']) {
73
                    xoops_cp_header();
74
75
                    xoops_confirm(['cat_id' => $_POST['cat_id'], 'step' => 'enreg'], 'public-category.php?op=delete', _AM_EXTGALLERY_DELETE_CAT_CONFIRM);
76
                    //                    xoops_cp_footer();
77
                    require_once __DIR__ . '/admin_footer.php';
78
                }
79
80
                break;
81
82
            case 'default':
83
            default:
84
85
                // Check if they are selected category
86
                if (!isset($_POST['cat_id'])) {
87
                    redirect_header('photo.php', 3, _AM_EXTGALLERY_NO_CATEGORY_SELECTED);
88
                }
89
90
                $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
91
                /** @var ExtgalleryPublicPhotoHandler $photoHandler */
92
                $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
93
94
                $cat       = $catHandler->getCat($_POST['cat_id']);
95
                $photosCat = $photoHandler->getCatPhoto($cat);
96
97
                xoops_cp_header();
98
99
                $selectedPhoto = '../assets/images/blank.gif';
100
                $photoArray    = [];
101
                foreach ($photosCat as $photo) {
102 View Code Duplication
                    if ('' != $photo->getVar('photo_serveur')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
                        $url = $photo->getVar('photo_serveur') . 'thumb_' . $photo->getVar('photo_name');
104
                    } else {
105
                        $url = XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name');
106
                    }
107
                    if ($photo->getVar('photo_id') == $cat->getVar('photo_id')) {
108
                        $selectedPhoto = $url;
109
                    }
110
                    $photoArray[$photo->getVar('photo_id')] = $url;
111
                }
112
113
                echo "<script type='text/JavaScript'>";
114
                echo 'function ChangeThumb() {
115
116
                            var formSelect;
117
                            var thumb = new Array();';
118
119
                echo "thumb[0] = '../assets/images/blank.gif';\n";
120
                foreach ($photoArray as $k => $v) {
121
                    echo 'thumb[' . $k . "] = '" . $v . "';\n";
122
                }
123
124
                echo "formSelect = document.getElementById('photo_id');
125
126
                            document.getElementById('thumb').src = thumb[formSelect.options[formSelect.selectedIndex].value];
127
                        }";
128
                echo '</script>';
129
130
                $photoSelect = "\n" . '<select size="1" name="photo_id" id="photo_id" onChange="ChangeThumb();" onkeydown="ChangeThumb();">' . "\n";
131
                $photoSelect .= '<option value="0">&nbsp;</option>' . "\n";
132
                foreach ($photosCat as $photo) {
133
                    if ($photo->getVar('photo_id') == $cat->getVar('photo_id')) {
134
                        $photoSelect .= '<option value="' . $photo->getVar('photo_id') . '" selected>' . $photo->getVar('photo_title') . ' (' . $photo->getVar('photo_name') . ')</option>' . "\n";
135
                    } else {
136
                        $photoSelect .= '<option value="' . $photo->getVar('photo_id') . '">' . $photo->getVar('photo_title') . ' (' . $photo->getVar('photo_name') . ')</option>' . "\n";
137
                    }
138
                }
139
                $photoSelect .= '</select>' . "\n";
140
141
                $form = new XoopsThemeForm(_AM_EXTGALLERY_MOD_PUBLIC_CAT, 'create_cat', 'public-category.php?op=modify', 'post', true);
142
                $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_PARENT_CAT, $catHandler->getSelect('cat_pid', 'leaf', true, $cat->getVar('cat_pid'))));
143
                $form->addElement(new XoopsFormText(_AM_EXTGALLERY_NAME, 'cat_name', '70', '255', $cat->getVar('cat_name', 'e')), false);
144
                $form->addElement(new XoopsFormText(_AM_EXTGALLERY_WEIGHT, 'cat_weight', '4', '4', $cat->getVar('cat_weight')), false);
145
                $form->addElement(new XoopsFormDhtmlTextArea(_AM_EXTGALLERY_DESC, 'cat_desc', $cat->getVar('cat_desc', 'e')), false);
146
                $elementTrayThumb = new XoopsFormElementTray(_AM_EXTGALLERY_THUMB);
147
                $elementTrayThumb->addElement(new XoopsFormLabel('', $photoSelect . "<img style=\"float:left; margin-top:5px;\" id=\"thumb\" src=\"$selectedPhoto\">"));
148
                $form->addElement(new XoopsFormText(_AM_EXTGALLERY_CAT_IMG, 'cat_imgurl', '70', '150', $cat->getVar('cat_imgurl', 'e')), false);
149
                $form->addElement($elementTrayThumb);
150
                $elementTrayButton = new XoopsFormElementTray('');
151
                $elementTrayButton->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
152
                $elementTrayButton->addElement(new XoopsFormButton('', 'delete', _DELETE, 'submit'));
153
                $form->addElement($elementTrayButton);
154
                $form->addElement(new XoopsFormHidden('cat_id', $_POST['cat_id']));
155
                $form->addElement(new XoopsFormHidden('step', 'enreg'));
156
                $xoopsTpl->assign('formmodifcat', $form->render());
157
158
                $xoopsTpl->display(XOOPS_ROOT_PATH . '/modules/extgallery/templates/admin/extgallery_admin_public_category.tpl');
159
160
                //                xoops_cp_footer();
161
                require_once __DIR__ . '/admin_footer.php';
162
163
                break;
164
165
        }
166
167
        break;
168
169
    case 'delete':
170
171
        switch ($step) {
172
173
            case 'enreg':
174
175
                $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
176
177
                $catHandler->deleteCat($_POST['cat_id']);
178
179
                redirect_header('public-category.php', 3, _AM_EXTGALLERY_CAT_DELETED);
180
181
                break;
182
183
        }
184
185
        break;
186
187
    case 'default':
188
    default:
189
190
        $catHandler = xoops_getModuleHandler('publiccat', 'extgallery');
191
192
        xoops_cp_header();
193
194
        $form = new XoopsThemeForm(_AM_EXTGALLERY_MODDELETE_PUBLICCAT, 'modify_cat', 'public-category.php?op=modify', 'post', true);
195
        $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_CATEGORY, $catHandler->getSelect('cat_id', false, false, 0, '', true)));
196
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
197
        $xoopsTpl->assign('formselectcat', $form->render());
198
199
        $form = new XoopsThemeForm(_AM_EXTGALLERY_ADD_PUBLIC_CAT, 'create_cat', 'public-category.php?op=create', 'post', true);
200
        $form->addElement(new XoopsFormLabel(_AM_EXTGALLERY_PARENT_CAT, $catHandler->getSelect('cat_pid', 'leaf', true)));
201
        $form->addElement(new XoopsFormText(_AM_EXTGALLERY_NAME, 'cat_name', '70', '255'), true);
202
        $form->addElement(new XoopsFormText(_AM_EXTGALLERY_WEIGHT, 'cat_weight', '4', '4'), false);
203
        $form->addElement(new XoopsFormDhtmlTextArea(_AM_EXTGALLERY_DESC, 'cat_desc', ''), false);
204
        $form->addElement(new XoopsFormText(_AM_EXTGALLERY_CAT_IMG, 'cat_imgurl', '70', '150'), false);
205
        $form->addElement(new XoopsFormHidden('step', 'enreg'));
206
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
207
        $xoopsTpl->assign('formcreatecat', $form->render());
208
209
        // Call template file
210
        $xoopsTpl->display(XOOPS_ROOT_PATH . '/modules/extgallery/templates/admin/extgallery_admin_public_category.tpl');
211
        //        xoops_cp_footer();
212
        require_once __DIR__ . '/admin_footer.php';
213
        break;
214
215
}
216