Passed
Push — master ( b6c858...3ff449 )
by Michael
61:14 queued 25:43
created

search()   F

Complexity

Conditions 18
Paths 15

Size

Total Lines 168
Code Lines 111

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 111
nc 15
nop 0
dl 0
loc 168
rs 3.8933
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
use Xmf\Module\Helper\Session;
13
use XoopsModules\Publisher;
14
use XoopsModules\Publisher\Helper;
15
16
/**
17
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
18
 * @license         GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
19
 * @package         Admin
20
 * @subpackage      Action
21
 * @since           1.0
22
 * @author          trabis <[email protected]>
23
 * @author          The SmartFactory <www.smartfactory.ca>
24
 * @version         $Id$
25
 */
26
require_once __DIR__ . '/admin_header.php';
27
28
$start = $limit = 0;
29
if (isset($_REQUEST['limit'])) {
30
    $limit = (int)$_REQUEST['limit'];
31
} else {
32
    $limit = 15;
33
}
34
if (isset($_REQUEST['start'])) {
35
    $start = (int)$_REQUEST['start'];
36
}
37
38
$aSortBy = [
39
    'mime_id' => _AM_PUBLISHER_MIME_ID,
40
    'mime_name' => _AM_PUBLISHER_MIME_NAME,
41
    'mime_ext' => _AM_PUBLISHER_MIME_EXT,
42
    'mime_admin' => _AM_PUBLISHER_MIME_ADMIN,
43
    'mime_user' => _AM_PUBLISHER_MIME_USER,
44
];
45
$aOrderBy = ['ASC' => _AM_PUBLISHER_TEXT_ASCENDING, 'DESC' => _AM_PUBLISHER_TEXT_DESCENDING];
46
$aLimitBy = ['10' => 10, '15' => 15, '20' => 20, '25' => 25, '50' => 50, '100' => 100];
47
$aSearchBy = ['mime_id' => _AM_PUBLISHER_MIME_ID, 'mime_name' => _AM_PUBLISHER_MIME_NAME, 'mime_ext' => _AM_PUBLISHER_MIME_EXT];
48
49
$op = $_REQUEST['op'] ?? 'default';
50
51
switch ($op) {
52
    case 'add':
53
        add();
54
        break;
55
    case 'delete':
56
        delete();
57
        break;
58
    case 'edit':
59
        edit();
60
        break;
61
    case 'search':
62
        search();
63
        break;
64
    case 'updateMimeValue':
65
        updateMimeValue();
66
        break;
67
    case 'clearAddSession':
68
        clearAddSession();
69
        break;
70
    case 'clearEditSession':
71
        clearEditSession();
72
        break;
73
    case 'manage':
74
    default:
75
        manage();
76
        break;
77
}
78
79
function add()
80
{
81
    $helper = Helper::getInstance();
82
    $xoops = Xoops::getInstance();
83
84
    global $limit, $start;
85
86
    if (!isset($_POST['add_mime'])) {
87
        Publisher\Utils::cpHeader();
88
89
        Publisher\Utils::openCollapsableBar('mimemaddtable', 'mimeaddicon', _AM_PUBLISHER_MIME_ADD_TITLE);
90
91
        $session = new Session();
92
        $mime_type = $session->get('publisher_addMime');
93
        $mime_errors = $session->get('publisher_addMimeErr');
94
95
        //Display any form errors
96
        if (false === !$mime_errors) {
97
            Publisher\Utils::renderErrors($mime_errors, Publisher\Utils::makeURI(PUBLISHER_ADMIN_URL . 'mimetypes.php', ['op' => 'clearAddSession']));
98
        }
99
100
        if (false === $mime_type) {
101
            $mime_ext = '';
102
            $mime_name = '';
103
            $mime_types = '';
104
            $mime_admin = 1;
105
            $mime_user = 1;
106
        } else {
107
            $mime_ext = $mime_type['mime_ext'];
108
            $mime_name = $mime_type['mime_name'];
109
            $mime_types = $mime_type['mime_types'];
110
            $mime_admin = $mime_type['mime_admin'];
111
            $mime_user = $mime_type['mime_user'];
112
        }
113
114
        // Display add form
115
        echo "<form action='mimetypes.php?op=add' method='post'>";
116
        echo "<table width='100%' cellspacing='1' class='outer'>";
117
        echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_CREATEF . '</th></tr>';
118
        echo "<tr valign='top'>
119
        <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td>
120
        <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mime_ext' size='5'></td>
121
        </tr>";
122
        echo "<tr valign='top'>
123
        <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td>
124
        <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mime_name'></td>
125
        </tr>";
126
        echo "<tr valign='top'>
127
        <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td>
128
        <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mime_types</textarea></td>
129
        </tr>";
130
        echo "<tr valign='top'>
131
        <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td>
132
        <td class='even'>";
133
        echo "<input type='radio' name='mime_admin' value='1' " . (1 == $mime_admin ? "checked" : '') . '>' . XoopsLocale::YES;
134
        echo "<input type='radio' name='mime_admin' value='0' " . (0 == $mime_admin ? "checked" : '') . '>' . XoopsLocale::NO . '
135
        </td>
136
        </tr>';
137
        echo "<tr valign='top'>
138
        <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td>
139
        <td class='even'>";
140
        echo "<input type='radio' name='mime_user' value='1'" . (1 == $mime_user ? "checked" : '') . '>' . XoopsLocale::YES;
141
        echo "<input type='radio' name='mime_user' value='0'" . (0 == $mime_user ? "checked" : '') . '>' . XoopsLocale::NO . '
142
        </td>
143
        </tr>';
144
        echo "<tr valign='top'>
145
        <td class='head'></td>
146
        <td class='even'>
147
        <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' class='formButton'>
148
        <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton'>
149
        </td>
150
        </tr>";
151
        echo '</table></form>';
152
        // end of add form
153
154
        // Find new mimetypes table
155
        echo "<form action='http://www.filext.com' method='post'>";
156
        echo "<table width='100%' cellspacing='1' class='outer'>";
157
        echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . '</th></tr>';
158
159
        echo "<tr class='foot'>
160
        <td colspan='2'><input type='submit' name='find_mime' id='find_mime' value='" . _AM_PUBLISHER_MIME_FINDIT . "' class='formButton'></td>
161
        </tr>";
162
163
        echo '</table></form>';
164
165
        Publisher\Utils::closeCollapsableBar('mimeaddtable', 'mimeaddicon');
166
167
        $xoops->footer();
168
    } else {
169
        $has_errors = false;
170
        $error = [];
171
        $mime_ext = $_POST['mime_ext'];
172
        $mime_name = $_POST['mime_name'];
173
        $mime_types = $_POST['mime_types'];
174
        $mime_admin = (int)$_POST['mime_admin'];
175
        $mime_user = (int)$_POST['mime_user'];
176
177
        //Validate Mimetype entry
178
        if ('' === trim($mime_ext)) {
179
            $has_errors = true;
180
            $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT;
0 ignored issues
show
Bug introduced by
The constant _AM_PUBLISHER_VALID_ERR_MIME_EXT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
181
        }
182
183
        if ('' === trim($mime_name)) {
184
            $has_errors = true;
185
            $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME;
0 ignored issues
show
Bug introduced by
The constant _AM_PUBLISHER_VALID_ERR_MIME_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
186
        }
187
188
        if ('' === trim($mime_types)) {
189
            $has_errors = true;
190
            $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES;
0 ignored issues
show
Bug introduced by
The constant _AM_PUBLISHER_VALID_ERR_MIME_TYPES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
191
        }
192
193
        if ($has_errors) {
194
            $session = new Session();
195
            $mime = [];
196
            $mime['mime_ext'] = $mime_ext;
197
            $mime['mime_name'] = $mime_name;
198
            $mime['mime_types'] = $mime_types;
199
            $mime['mime_admin'] = $mime_admin;
200
            $mime['mime_user'] = $mime_user;
201
            $session->set('publisher_addMime', $mime);
202
            $session->set('publisher_addMimeErr', $error);
203
            header('Location: ' . Publisher\Utils::makeURI(PUBLISHER_ADMIN_URL . 'mimetypes.php', ['op' => 'add'], false));
204
        }
205
206
        $mimetype = $helper->getMimetypeHandler()->create();
207
        $mimetype->setVar('mime_ext', $mime_ext);
208
        $mimetype->setVar('mime_name', $mime_name);
209
        $mimetype->setVar('mime_types', $mime_types);
210
        $mimetype->setVar('mime_admin', $mime_admin);
211
        $mimetype->setVar('mime_user', $mime_user);
212
213
        if (!$helper->getMimetypeHandler()->insert($mimetype)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $helper->getMimetypeHandler()->insert($mimetype) of type false|integer is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
214
            $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_ADD_MIME_ERROR);
215
        } else {
216
            _clearAddSessionVars();
217
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
218
        }
219
    }
220
}
221
222
function delete()
223
{
224
    $helper = Helper::getInstance();
225
    $xoops = Xoops::getInstance();
226
    global $start, $limit;
227
    if (!isset($_REQUEST['id'])) {
228
        $xoops->redirect(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
229
    }
230
    $mime_id = (int)$_REQUEST['id'];
231
232
    $mimetype = $helper->getMimetypeHandler()->get($mime_id); // Retrieve mimetype object
233
    if (!$helper->getMimetypeHandler()->delete($mimetype, true)) {
0 ignored issues
show
Bug introduced by
It seems like $mimetype can also be of type null; however, parameter $object of Xoops\Core\Kernel\XoopsP...ObjectHandler::delete() does only seem to accept Xoops\Core\Kernel\XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

233
    if (!$helper->getMimetypeHandler()->delete(/** @scrutinizer ignore-type */ $mimetype, true)) {
Loading history...
234
        $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&id=$mime_id&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
235
    } else {
236
        $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start", 3, 'Deleted');
237
    }
238
}
239
240
function edit()
241
{
242
    $helper = Helper::getInstance();
243
    $xoops = Xoops::getInstance();
244
    global $start, $limit, $oAdminButton;
245
246
    if (!isset($_REQUEST['id'])) {
247
        $xoops->redirect(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
248
    }
249
    $mime_id = (int)$_REQUEST['id'];
250
251
    $mimetype = $helper->getMimetypeHandler()->get($mime_id); // Retrieve mimetype object
252
253
    if (!isset($_POST['edit_mime'])) {
254
        $session = new Session();
255
        $mime_type = $session->get("publisher_editMime_$mime_id");
256
        $mime_errors = $session->get("publisher_editMimeErr_$mime_id");
257
258
        // Display header
259
        Publisher\Utils::cpHeader();
260
        //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_EDIT);
261
262
        Publisher\Utils::openCollapsableBar('mimemedittable', 'mimeediticon', _AM_PUBLISHER_MIME_EDIT_TITLE);
263
264
        //Display any form errors
265
        if (false === !$mime_errors) {
266
            Publisher\Utils::renderErrors($mime_errors, Publisher\Utils::makeURI(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'clearEditSession', 'id' => $mime_id]));
267
        }
268
269
        if (false === $mime_type) {
270
            $mime_ext = $mimetype->getVar('mime_ext');
271
            $mime_name = $mimetype->getVar('mime_name', 'e');
272
            $mime_types = $mimetype->getVar('mime_types', 'e');
273
            $mime_admin = $mimetype->getVar('mime_admin');
274
            $mime_user = $mimetype->getVar('mime_user');
275
        } else {
276
            $mime_ext = $mime_type['mime_ext'];
277
            $mime_name = $mime_type['mime_name'];
278
            $mime_types = $mime_type['mime_types'];
279
            $mime_admin = $mime_type['mime_admin'];
280
            $mime_user = $mime_type['mime_user'];
281
        }
282
283
        // Display edit form
284
        echo "<form action='mimetypes.php?op=edit&amp;id=" . $mime_id . "' method='post'>";
285
        echo "<input type='hidden' name='limit' value='" . $limit . "'>";
286
        echo "<input type='hidden' name='start' value='" . $start . "'>";
287
        echo "<table width='100%' cellspacing='1' class='outer'>";
288
        echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_MODIFYF . '</th></tr>';
289
        echo "<tr valign='top'>
290
        <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td>
291
        <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mime_ext' size='5'></td>
292
        </tr>";
293
        echo "<tr valign='top'>
294
        <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td>
295
        <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mime_name'></td>
296
        </tr>";
297
        echo "<tr valign='top'>
298
        <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td>
299
        <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mime_types</textarea></td>
300
        </tr>";
301
        echo "<tr valign='top'>
302
        <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td>
303
        <td class='even'>
304
        <input type='radio' name='mime_admin' value='1' " . (1 == $mime_admin ? "checked" : '') . '>' . XoopsLocale::YES . "
305
        <input type='radio' name='mime_admin' value='0' " . (0 == $mime_admin ? "checked" : '') . '>' . XoopsLocale::NO . '
306
        </td>
307
        </tr>';
308
        echo "<tr valign='top'>
309
        <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td>
310
        <td class='even'>
311
        <input type='radio' name='mime_user' value='1' " . (1 == $mime_user ? "checked" : '') . '>' . XoopsLocale::YES . "
312
        <input type='radio' name='mime_user' value='0' " . (0 == $mime_user ? "checked" : '') . '>' . XoopsLocale::NO . '
313
        </td>
314
        </tr>';
315
        echo "<tr valign='top'>
316
        <td class='head'></td>
317
        <td class='even'>
318
        <input type='submit' name='edit_mime' id='edit_mime' value='" . _AM_PUBLISHER_BUTTON_UPDATE . "' class='formButton'>
319
        <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton'>
320
        </td>
321
        </tr>";
322
        echo '</table></form>';
323
        // end of edit form
324
        Publisher\Utils::closeCollapsableBar('mimeedittable', 'mimeediticon');
325
        $xoops->footer();
326
    } else {
327
        $mime_admin = 0;
328
        $mime_user = 0;
329
        $has_errors = false;
330
        $error = [];
331
        if (isset($_POST['mime_admin']) && 1 == $_POST['mime_admin']) {
332
            $mime_admin = 1;
333
        }
334
        if (isset($_POST['mime_user']) && 1 == $_POST['mime_user']) {
335
            $mime_user = 1;
336
        }
337
338
        //Validate Mimetype entry
339
        if ('' === trim($_POST['mime_ext'])) {
340
            $has_errors = true;
341
            $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT;
0 ignored issues
show
Bug introduced by
The constant _AM_PUBLISHER_VALID_ERR_MIME_EXT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
342
        }
343
344
        if ('' === trim($_POST['mime_name'])) {
345
            $has_errors = true;
346
            $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME;
0 ignored issues
show
Bug introduced by
The constant _AM_PUBLISHER_VALID_ERR_MIME_NAME was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
347
        }
348
349
        if ('' === trim($_POST['mime_types'])) {
350
            $has_errors = true;
351
            $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES;
0 ignored issues
show
Bug introduced by
The constant _AM_PUBLISHER_VALID_ERR_MIME_TYPES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
352
        }
353
354
        if ($has_errors) {
355
            $session = new Session();
356
            $mime = [];
357
            $mime['mime_ext'] = $_POST['mime_ext'];
358
            $mime['mime_name'] = $_POST['mime_name'];
359
            $mime['mime_types'] = $_POST['mime_types'];
360
            $mime['mime_admin'] = $mime_admin;
361
            $mime['mime_user'] = $mime_user;
362
            $session->set('publisher_editMime_' . $mime_id, $mime);
363
            $session->set('publisher_editMimeErr_' . $mime_id, $error);
364
            header('Location: ' . Publisher\Utils::makeURI(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'edit', 'id' => $mime_id], false));
365
        }
366
367
        $mimetype->setVar('mime_ext', $_POST['mime_ext']);
368
        $mimetype->setVar('mime_name', $_POST['mime_name']);
369
        $mimetype->setVar('mime_types', $_POST['mime_types']);
370
        $mimetype->setVar('mime_admin', $mime_admin);
371
        $mimetype->setVar('mime_user', $mime_user);
372
373
        if (!$helper->getMimetypeHandler()->insert($mimetype, true)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $helper->getMimetypeHand...insert($mimetype, true) of type false|integer is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
Bug introduced by
It seems like $mimetype can also be of type null; however, parameter $object of Xoops\Core\Kernel\XoopsP...ObjectHandler::insert() does only seem to accept Xoops\Core\Kernel\XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

373
        if (!$helper->getMimetypeHandler()->insert(/** @scrutinizer ignore-type */ $mimetype, true)) {
Loading history...
374
            $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=edit&id=$mime_id", 3, _AM_PUBLISHER_MESSAGE_EDIT_MIME_ERROR);
375
        } else {
376
            _clearEditSessionVars($mime_id);
377
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
378
        }
379
    }
380
}
381
382
function manage()
383
{
384
    $xoops = Xoops::getInstance();
385
    $helper = Helper::getInstance();
386
387
    $imagearray = [
388
        'editimg' => "<img src='" . $helper->url('images/button_edit.png') . "' alt='" . _AM_PUBLISHER_ICO_EDIT . "' align='middle'>",
389
        'deleteimg' => "<img src='" . $helper->url('images/button_delete.png') . "' alt='" . _AM_PUBLISHER_ICO_DELETE . "' align='middle'>",
390
        'online' => "<img src='" . $helper->url('images/on.png') . "' alt='" . _AM_PUBLISHER_ICO_ONLINE . "' align='middle'>",
391
        'offline' => "<img src='" . $helper->url('images/off.png') . "' alt='" . _AM_PUBLISHER_ICO_OFFLINE . "' align='middle'>",
392
    ];
393
    global $start, $limit, $aSortBy, $aOrderBy, $aLimitBy, $aSearchBy;
394
395
    if (isset($_POST['deleteMimes'])) {
396
        $aMimes = $_POST['mimes'];
397
398
        $crit = new Criteria('mime_id', '(' . implode(',', $aMimes) . ')', 'IN');
399
400
        if ($helper->getMimetypeHandler()->deleteAll($crit)) {
401
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
402
        } else {
403
            $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
404
        }
405
    }
406
    if (isset($_POST['add_mime'])) {
407
        header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
408
        exit();
409
    }
410
    if (isset($_POST['mime_search'])) {
411
        header('Location: ' . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=search');
412
        exit();
413
    }
414
415
    Publisher\Utils::cpHeader();
416
    ////publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES);
417
    Publisher\Utils::openCollapsableBar('mimemanagetable', 'mimemanageicon', _AM_PUBLISHER_MIME_MANAGE_TITLE, _AM_PUBLISHER_MIME_INFOTEXT);
418
    $crit = new CriteriaCompo();
419
    $order = $_REQUEST['order'] ?? 'ASC';
420
    $sort = $_REQUEST['sort'] ?? 'mime_ext';
421
    $crit->setOrder($order);
422
    $crit->setStart($start);
423
    $crit->setLimit($limit);
424
    $crit->setSort($sort);
425
    $mimetypes = $helper->getMimetypeHandler()->getObjects($crit); // Retrieve a list of all mimetypes
426
    $mime_count = $helper->getMimetypeHandler()->getCount();
427
    $nav = new XoopsPageNav($mime_count, $limit, $start, 'start', "op=manage&amp;limit=$limit");
428
429
    echo "<table width='100%' cellspacing='1' class='outer'>";
430
    echo "<tr><td colspan='6' align='right'>";
431
    echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
432
    echo '<table>';
433
    echo '<tr>';
434
    echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
435
    echo "<td align='left'><select name='search_by'>";
436
    foreach ($aSearchBy as $value => $text) {
437
        ($sort == $value) ? $selected = "selected='selected'" : $selected = '';
438
        echo "<option value='$value' $selected>$text</option>";
439
    }
440
    echo '</select></td>';
441
    echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
442
    echo "<td align='left'><input type='text' name='search_text' id='search_text' value=''></td>";
443
    echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "'></td>";
444
    echo '</tr></table></form></td></tr>';
445
446
    echo "<tr><td colspan='6'>";
447
    echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage' style='margin:0; padding:0;' method='post'>";
448
    echo "<table width='100%'>";
449
    echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
450
    <select name='sort'>";
451
    foreach ($aSortBy as $value => $text) {
452
        ($sort == $value) ? $selected = "selected='selected'" : $selected = '';
453
        echo "<option value='$value' $selected>$text</option>";
454
    }
455
    echo '</select>
456
    &nbsp;&nbsp;&nbsp;
457
    ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
458
    <select name='order'>";
459
    foreach ($aOrderBy as $value => $text) {
460
        ($order == $value) ? $selected = "selected='selected'" : $selected = '';
461
        echo "<option value='$value' $selected>$text</option>";
462
    }
463
    echo '</select>
464
    &nbsp;&nbsp;&nbsp;
465
    ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . "
466
    <select name='limit'>";
467
    foreach ($aLimitBy as $value => $text) {
468
        ($limit == $value) ? $selected = "selected='selected'" : $selected = '';
469
        echo "<option value='$value' $selected>$text</option>";
470
    }
471
    echo "</select>
472
    <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "'>
473
    </td>
474
    </tr>";
475
    echo '</table>';
476
    echo '</td></tr>';
477
    echo "<tr><th colspan='6'>" . _AM_PUBLISHER_MIME_MANAGE_TITLE . '</th></tr>';
478
    echo "<tr class='head'>
479
    <td>" . _AM_PUBLISHER_MIME_ID . '</td>
480
    <td>' . _AM_PUBLISHER_MIME_NAME . '</td>
481
    <td>' . _AM_PUBLISHER_MIME_EXT . '</td>
482
    <td>' . _AM_PUBLISHER_MIME_ADMIN . '</td>
483
    <td>' . _AM_PUBLISHER_MIME_USER . '</td>
484
    <td>' . _AM_PUBLISHER_MINDEX_ACTION . '</td>
485
    </tr>';
486
    foreach ($mimetypes as $mime) {
487
        echo "<tr class='even'>
488
        <td><input type='checkbox' name='mimes[]' value='" . $mime->getVar('mime_id') . "'>" . $mime->getVar('mime_id') . '</td>
489
        <td>' . $mime->getVar('mime_name') . '</td>
490
        <td>' . $mime->getVar('mime_ext') . "</td>
491
        <td>
492
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_admin=' . $mime->getVar('mime_admin') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>
493
        " . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline']) . "</a>
494
        </td>
495
        <td>
496
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_user=' . $mime->getVar('mime_user') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>
497
        " . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline']) . "</a>
498
        </td>
499
        <td>
500
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=edit&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['editimg'] . "</a>
501
        <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=delete&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['deleteimg'] . '</a>
502
        </td>
503
        </tr>';
504
    }
505
    echo "<tr class='foot'>
506
    <td colspan='6' valign='top'>
507
    <a href='http://www.filext.com' style='float: right' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
508
    <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);'>
509
    <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "'>
510
    <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton'>
511
    </td>
512
    </tr>";
513
    echo '</table>';
514
    echo "<div id='staff_nav'>" . $nav->renderNav() . '</div>';
515
516
    Publisher\Utils::closeCollapsableBar('mimemanagetable', 'mimemanageicon');
517
518
    $xoops->footer();
519
}
520
521
function search()
522
{
523
    $helper = Helper::getInstance();
524
    $xoops = Xoops::getInstance();
525
526
    global $limit, $start, $imagearray, $aSearchBy, $aOrderBy, $aLimitBy, $aSortBy;
527
528
    if (isset($_POST['deleteMimes'])) {
529
        $aMimes = $_POST['mimes'];
530
531
        $crit = new Criteria('mime_id', '(' . implode(',', $aMimes) . ')', 'IN');
532
533
        if ($helper->getMimetypeHandler()->deleteAll($crit)) {
534
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
535
        } else {
536
            $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
537
        }
538
    }
539
    if (isset($_POST['add_mime'])) {
540
        header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
541
        exit();
542
    }
543
    $order = $_REQUEST['order'] ?? 'ASC';
544
    $sort = $_REQUEST['sort'] ?? 'mime_name';
545
546
    Publisher\Utils::cpHeader();
547
    //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_SEARCH);
548
549
    Publisher\Utils::openCollapsableBar('mimemsearchtable', 'mimesearchicon', _AM_PUBLISHER_MIME_SEARCH);
550
551
    if (!isset($_REQUEST['mime_search'])) {
552
        echo "<form action='mimetypes.php?op=search' method='post'>";
553
        echo "<table width='100%' cellspacing='1' class='outer'>";
554
        echo "<tr><th colspan='2'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
555
        echo "<tr><td class='head' width='20%'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . "</td>
556
        <td class='even'>
557
        <select name='search_by'>";
558
        foreach ($aSortBy as $value => $text) {
559
            echo "<option value='$value'>$text</option>";
560
        }
561
        echo '</select>
562
        </td>
563
        </tr>';
564
        echo "<tr><td class='head'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . "</td>
565
        <td class='even'>
566
        <input type='text' name='search_text' id='search_text' value=''>
567
        </td>
568
        </tr>";
569
        echo "<tr class='foot'>
570
        <td colspan='2'>
571
        <input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "'>
572
        </td>
573
        </tr>";
574
        echo '</table></form>';
575
    } else {
576
        $search_field = $_REQUEST['search_by'];
577
        $search_text = $_REQUEST['search_text'];
578
579
        $crit = new Criteria($search_field, "%$search_text%", 'LIKE');
580
        $crit->setSort($sort);
581
        $crit->setOrder($order);
582
        $crit->setLimit($limit);
583
        $crit->setStart($start);
584
        $mime_count = $helper->getMimetypeHandler()->getCount($crit);
585
        $mimetypes = $helper->getMimetypeHandler()->getObjects($crit);
586
        $nav = new XoopsPageNav($mime_count, $limit, $start, 'start', "op=search&amp;limit=$limit&amp;order=$order&amp;sort=$sort&amp;mime_search=1&amp;search_by=$search_field&amp;search_text=$search_text");
587
        // Display results
588
        echo '<script type="text/javascript" src="' . PUBLISHER_URL . '/include/functions.js"></script>';
589
590
        echo "<table width='100%' cellspacing='1' class='outer'>";
591
        echo "<tr><td colspan='6' align='right'>";
592
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
593
        echo '<table>';
594
        echo '<tr>';
595
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
596
        echo "<td align='left'><select name='search_by'>";
597
        foreach ($aSearchBy as $value => $text) {
598
            ($search_field == $value) ? $selected = "selected='selected'" : $selected = '';
599
            echo "<option value='$value' $selected>$text</option>";
600
        }
601
        echo '</select></td>';
602
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
603
        echo "<td align='left'><input type='text' name='search_text' id='search_text' value='$search_text'></td>";
604
        echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "'></td>";
605
        echo '</tr></table></form></td></tr>';
606
607
        echo "<tr><td colspan='6'>";
608
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
609
        echo "<table width='100%'>";
610
        echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
611
        <select name='sort'>";
612
        foreach ($aSortBy as $value => $text) {
613
            ($sort == $value) ? $selected = "selected='selected'" : $selected = '';
614
            echo "<option value='$value' $selected>$text</option>";
615
        }
616
        echo '</select>
617
        &nbsp;&nbsp;&nbsp;
618
        ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
619
        <select name='order'>";
620
        foreach ($aOrderBy as $value => $text) {
621
            ($order == $value) ? $selected = "selected='selected'" : $selected = '';
622
            echo "<option value='$value' $selected>$text</option>";
623
        }
624
        echo '</select>
625
        &nbsp;&nbsp;&nbsp;
626
        ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . "
627
        <select name='limit'>";
628
        foreach ($aLimitBy as $value => $text) {
629
            ($limit == $value) ? $selected = "selected='selected'" : $selected = '';
630
            echo "<option value='$value' $selected>$text</option>";
631
        }
632
        echo "</select>
633
        <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "'>
634
        <input type='hidden' name='mime_search' id='mime_search' value='1'>
635
        <input type='hidden' name='search_by' id='search_by' value='$search_field'>
636
        <input type='hidden' name='search_text' id='search_text' value='$search_text'>
637
        </td>
638
        </tr>";
639
        echo '</table>';
640
        echo '</td></tr>';
641
        if (count($mimetypes) > 0) {
642
            echo "<tr><th colspan='6'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
643
            echo "<tr class='head'>
644
            <td>" . _AM_PUBLISHER_MIME_ID . '</td>
645
            <td>' . _AM_PUBLISHER_MIME_NAME . '</td>
646
            <td>' . _AM_PUBLISHER_MIME_EXT . '</td>
647
            <td>' . _AM_PUBLISHER_MIME_ADMIN . '</td>
648
            <td>' . _AM_PUBLISHER_MIME_USER . '</td>
649
            <td>' . _AM_PUBLISHER_MINDEX_ACTION . '</td>
650
            </tr>';
651
            foreach ($mimetypes as $mime) {
652
                echo "<tr class='even'>
653
                <td><input type='checkbox' name='mimes[]' value='" . $mime->getVar('mime_id') . "'>" . $mime->getVar('mime_id') . '</td>
654
                <td>' . $mime->getVar('mime_name') . '</td>
655
                <td>' . $mime->getVar('mime_ext') . "</td>
656
                <td>
657
                <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_admin=' . $mime->getVar('mime_admin') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>
658
                " . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline']) . "</a>
659
                </td>
660
                <td>
661
                <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=updateMimeValue&amp;id=' . $mime->getVar('mime_id') . '&amp;mime_user=' . $mime->getVar('mime_user') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>
662
                " . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline']) . "</a>
663
                </td>
664
                <td>
665
                <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=edit&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['editimg'] . "</a>
666
                <a href='" . PUBLISHER_ADMIN_URL . '/mimetypes.php?op=delete&amp;id=' . $mime->getVar('mime_id') . '&amp;limit=' . $limit . '&amp;start=' . $start . "'>" . $imagearray['deleteimg'] . '</a>
667
                </td>
668
                </tr>';
669
            }
670
            echo "<tr class='foot'>
671
            <td colspan='6' valign='top'>
672
            <a href='http://www.filext.com' style='float: right' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
673
            <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);'>
674
            <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "'>
675
            <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton'>
676
            </td>
677
            </tr>";
678
        } else {
679
            echo '<tr><th>' . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
680
            echo "<tr class='even'>
681
            <td>" . _AM_PUBLISHER_TEXT_NO_RECORDS . '</td>
682
            </tr>';
683
        }
684
        echo '</table>';
685
        echo "<div id='pagenav'>" . $nav->renderNav() . '</div>';
686
    }
687
    Publisher\Utils::closeCollapsableBar('mimesearchtable', 'mimesearchicon');
688
    $xoops->footer();
689
}
690
691
function updateMimeValue()
692
{
693
    $xoops = Xoops::getInstance();
694
    $helper = Helper::getInstance();
695
    $start = $limit = 0;
696
697
    if (isset($_GET['limit'])) {
698
        $limit = (int)$_GET['limit'];
699
    }
700
    if (isset($_GET['start'])) {
701
        $start = (int)$_GET['start'];
702
    }
703
704
    if (!isset($_REQUEST['id'])) {
705
        $xoops->redirect(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
706
    }
707
    $mime_id = (int)$_REQUEST['id'];
708
709
    $mimetype = $helper->getMimetypeHandler()->get($mime_id);
710
711
    if (isset($_REQUEST['mime_admin'])) {
712
        $mime_admin = (int)$_REQUEST['mime_admin'];
713
        $mime_admin = _changeMimeValue($mime_admin);
714
        $mimetype->setVar('mime_admin', $mime_admin);
715
    }
716
    if (isset($_REQUEST['mime_user'])) {
717
        $mime_user = (int)$_REQUEST['mime_user'];
718
        $mime_user = _changeMimeValue($mime_user);
719
        $mimetype->setVar('mime_user', $mime_user);
720
    }
721
    if ($helper->getMimetypeHandler()->insert($mimetype, true)) {
0 ignored issues
show
Bug introduced by
It seems like $mimetype can also be of type null; however, parameter $object of Xoops\Core\Kernel\XoopsP...ObjectHandler::insert() does only seem to accept Xoops\Core\Kernel\XoopsObject, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

721
    if ($helper->getMimetypeHandler()->insert(/** @scrutinizer ignore-type */ $mimetype, true)) {
Loading history...
Bug Best Practice introduced by
The expression $helper->getMimetypeHand...insert($mimetype, true) of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
722
        header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
723
    } else {
724
        $xoops->redirect(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3);
725
    }
726
}
727
728
/**
729
 * @param $mime_value
730
 * @return int
731
 */
732
/**
733
 * @param $mime_value
734
 * @return int
735
 */
736
function _changeMimeValue($mime_value)
737
{
738
    if (1 == $mime_value) {
739
        $mime_value = 0;
740
    } else {
741
        $mime_value = 1;
742
    }
743
744
    return $mime_value;
745
}
746
747
function _clearAddSessionVars()
748
{
749
    $session = new Session();
750
    $session->del('publisher_addMime');
751
    $session->del('publisher_addMimeErr');
752
}
753
754
function clearAddSession()
755
{
756
    _clearAddSessionVars();
757
    header('Location: ' . Publisher\Utils::makeURI(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'add'], false));
758
}
759
760
/**
761
 * @param $id
762
 */
763
/**
764
 * @param $id
765
 */
766
function _clearEditSessionVars($id)
767
{
768
    $id = (int)$id;
769
    $session = new Session();
770
    $session->del("publisher_editMime_$id");
771
    $session->del("publisher_editMimeErr_$id");
772
}
773
774
function clearEditSession()
775
{
776
    $mimeid = $_REQUEST['id'];
777
    _clearEditSessionVars($mimeid);
778
    header('Location: ' . Publisher\Utils::makeURI(PUBLISHER_ADMIN_URL . '/mimetypes.php', ['op' => 'edit', 'id' => $mimeid], false));
779
}
780