Completed
Branch master (019813)
by Michael
03:23
created

confirmUpdateMimeValue()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 18
nc 12
nop 0
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 92 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Admin
16
 * @subpackage      Action
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
use Xmf\Request;
23
24
require_once __DIR__ . '/admin_header.php';
25
xoops_load('XoopsPagenav');
26
27
$start = Request::getInt('start', 0, 'GET');
28
$limit = Request::getInt('limit', Request::getInt('limit', 15, 'GET'), 'POST');
29
30
$aSortBy   = array(
31
    'mime_id'    => _AM_PUBLISHER_MIME_ID,
32
    'mime_name'  => _AM_PUBLISHER_MIME_NAME,
33
    'mime_ext'   => _AM_PUBLISHER_MIME_EXT,
34
    'mime_admin' => _AM_PUBLISHER_MIME_ADMIN,
35
    'mime_user'  => _AM_PUBLISHER_MIME_USER
36
);
37
$aOrderBy  = array('ASC' => _AM_PUBLISHER_TEXT_ASCENDING, 'DESC' => _AM_PUBLISHER_TEXT_DESCENDING);
38
$aLimitBy  = array('10' => 10, '15' => 15, '20' => 20, '25' => 25, '50' => 50, '100' => 100);
39
$aSearchBy = array('mime_id' => _AM_PUBLISHER_MIME_ID, 'mime_name' => _AM_PUBLISHER_MIME_NAME, 'mime_ext' => _AM_PUBLISHER_MIME_EXT);
40
41
$error = array();
42
43
$op = Request::getString('op', 'default', 'GET');
44
45
// all post requests should have a valid token
46
if ('POST' === Request::getMethod() && !$GLOBALS['xoopsSecurity']->check()) {
47
    redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage", 3, _CO_PUBLISHER_BAD_TOKEN);
48
}
49
50
switch ($op) {
51
    case 'add':
52
        PublisherMimetypesUtility::add();
53
        break;
54
55
    case 'delete':
56
        PublisherMimetypesUtility::delete();
57
        break;
58
59
    case 'edit':
60
        PublisherMimetypesUtility::edit();
61
        break;
62
63
    case 'search':
64
        PublisherMimetypesUtility::search();
65
        break;
66
67
    case 'updateMimeValue':
68
        PublisherMimetypesUtility::updateMimeValue();
69
        break;
70
71
    case 'confirmUpdateMimeValue':
72
        PublisherMimetypesUtility::confirmUpdateMimeValue();
73
        break;
74
75
    case 'clearAddSession':
76
        PublisherMimetypesUtility::clearAddSession();
77
        break;
78
79
    case 'clearEditSession':
80
        PublisherMimetypesUtility::clearEditSession();
81
        break;
82
83
    case 'manage':
84
    default:
85
        PublisherMimetypesUtility::manage();
86
        break;
87
}
88
89
/**
90
 * Class PublisherMimetypesUtility
91
 */
92
class PublisherMimetypesUtility
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
93
{
94
    public static function add()
0 ignored issues
show
Coding Style introduced by
add uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
95
    {
96
        $publisher = PublisherPublisher::getInstance();
97
        global $limit, $start;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
98
        $error = array();
99
        if (!Request::getString('add_mime', '', 'POST')) {
100
            PublisherUtility::cpHeader();
101
            //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
102
103
            PublisherUtility::openCollapsableBar('mimemaddtable', 'mimeaddicon', _AM_PUBLISHER_MIME_ADD_TITLE);
104
105
            $session    = PublisherSession::getInstance();
106
            $mimeType   = $session->get('publisher_addMime');
107
            $mimeErrors = $session->get('publisher_addMimeErr');
108
109
            //Display any form errors
110 View Code Duplication
            if (!$mimeErrors === false) {
0 ignored issues
show
Duplication introduced by
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...
111
                PublisherUtility::renderErrors($mimeErrors, PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'clearAddSession')));
112
            }
113
114
            if ($mimeType === false) {
115
                $mimeExt   = '';
116
                $mimeName  = '';
117
                $mimeTypes = '';
118
                $mimeAdmin = 1;
119
                $mimeUser  = 1;
120 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
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...
121
                $mimeExt   = $mimeType['mime_ext'];
122
                $mimeName  = $mimeType['mime_name'];
123
                $mimeTypes = $mimeType['mime_types'];
124
                $mimeAdmin = $mimeType['mime_admin'];
125
                $mimeUser  = $mimeType['mime_user'];
126
            }
127
128
            // Display add form
129
            echo "<form action='mimetypes.php?op=add' method='post'>";
130
            echo $GLOBALS['xoopsSecurity']->getTokenHTML();
131
            echo "<table width='100%' cellspacing='1' class='outer'>";
132
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_CREATEF . '</th></tr>';
133
            echo "<tr valign='top'>
134
        <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td>
135
        <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mimeExt' size='5' /></td>
136
        </tr>";
137
            echo "<tr valign='top'>
138
        <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td>
139
        <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mimeName' /></td>
140
        </tr>";
141
            echo "<tr valign='top'>
142
        <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td>
143
        <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mimeTypes</textarea></td>
144
        </tr>";
145
            echo "<tr valign='top'>
146
        <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td>
147
        <td class='even'>";
148
            echo "<input type='radio' name='mime_admin' value='1' " . ($mimeAdmin == 1 ? 'checked' : '') . ' />' . _YES;
149
            echo "<input type='radio' name='mime_admin' value='0' " . ($mimeAdmin == 0 ? 'checked' : '') . ' />' . _NO . '
150
        </td>
151
        </tr>';
152
            echo "<tr valign='top'>
153
        <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td>
154
        <td class='even'>";
155
            echo "<input type='radio' name='mime_user' value='1'" . ($mimeUser == 1 ? 'checked' : '') . ' />' . _YES;
156
            echo "<input type='radio' name='mime_user' value='0'" . ($mimeUser == 0 ? 'checked' : '') . '/>' . _NO . '
157
        </td>
158
        </tr>';
159
            echo "<tr valign='top'>
160
        <td class='head'>" . _AM_PUBLISHER_MIME_MANDATORY_FIELD . "</td>
161
        <td class='even'>
162
        <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' class='formButton' />
163
        <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton' />
164
        </td>
165
        </tr>";
166
            echo '</table></form>';
167
            // end of add form
168
169
            // Find new mimetypes table
170
            echo "<form action='http://www.filext.com' method='post'>";
171
            echo "<table width='100%' cellspacing='1' class='outer'>";
172
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . '</th></tr>';
173
174
            echo "<tr class='foot'>
175
        <td colspan='2'><input type='submit' name='find_mime' id='find_mime' value='" . _AM_PUBLISHER_MIME_FINDIT . "' class='formButton' /></td>
176
        </tr>";
177
178
            echo '</table></form>';
179
180
            PublisherUtility::closeCollapsableBar('mimeaddtable', 'mimeaddicon');
181
182
            xoops_cp_footer();
183
        } else {
184
            $hasErrors = false;
185
            $mimeExt   = Request::getString('mime_ext', '', 'POST');
186
            $mimeName  = Request::getString('mime_name', '', 'POST');
187
            $mimeTypes = Request::getText('mime_types', '', 'POST');
188
            $mimeAdmin = Request::getInt('mime_admin', 0, 'POST');
189
            $mimeUser  = Request::getInt('mime_user', 0, 'POST');
190
191
            //Validate Mimetype entry
192
            if ('' === trim($mimeExt)) {
193
                $hasErrors           = true;
194
                $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT;
195
            }
196
197
            if ('' === trim($mimeName)) {
198
                $hasErrors            = true;
199
                $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME;
200
            }
201
202
            if ('' === trim($mimeTypes)) {
203
                $hasErrors             = true;
204
                $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES;
205
            }
206
207
            if ($hasErrors) {
208
                $session            = PublisherSession::getInstance();
209
                $mime               = array();
210
                $mime['mime_ext']   = $mimeExt;
211
                $mime['mime_name']  = $mimeName;
212
                $mime['mime_types'] = $mimeTypes;
213
                $mime['mime_admin'] = $mimeAdmin;
214
                $mime['mime_user']  = $mimeUser;
215
                $session->set('publisher_addMime', $mime);
216
                $session->set('publisher_addMimeErr', $error);
217
                header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'add'), false));
218
            }
219
220
            $mimeType = $publisher->getHandler('mimetype')->create();
221
            $mimeType->setVar('mime_ext', $mimeExt);
222
            $mimeType->setVar('mime_name', $mimeName);
223
            $mimeType->setVar('mime_types', $mimeTypes);
224
            $mimeType->setVar('mime_admin', $mimeAdmin);
225
            $mimeType->setVar('mime_user', $mimeUser);
226
227 View Code Duplication
            if (!$publisher->getHandler('mimetype')->insert($mimeType)) {
0 ignored issues
show
Duplication introduced by
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...
228
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_ADD_MIME_ERROR);
229
            } else {
230
                self::clearAddSessionVars();
231
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
232
            }
233
        }
234
    }
235
236
    public static function delete()
237
    {
238
        $publisher = PublisherPublisher::getInstance();
239
        global $start, $limit;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
240
        $mimeId = 0;
241 View Code Duplication
        if (0 == Request::getInt('id', 0, 'GET')) {
0 ignored issues
show
Duplication introduced by
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...
242
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
243
        } else {
244
            $mimeId = Request::getInt('id', 0, 'GET');
245
        }
246
        $mimeType = $publisher->getHandler('mimetype')->get($mimeId); // Retrieve mimetype object
247 View Code Duplication
        if (!$publisher->getHandler('mimetype')->delete($mimeType, true)) {
0 ignored issues
show
Duplication introduced by
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...
248
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&id=$mimeId&limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
249
        } else {
250
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
251
        }
252
    }
253
254
    public static function edit()
0 ignored issues
show
Coding Style introduced by
edit uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
255
    {
256
        $publisher = PublisherPublisher::getInstance();
257
        global $start, $limit;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
258
        $mimeId    = 0;
259
        $error     = array();
260
        $hasErrors = false;
261 View Code Duplication
        if (0 == Request::getInt('id', 0, 'GET')) {
0 ignored issues
show
Duplication introduced by
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...
262
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
263
        } else {
264
            $mimeId = Request::getInt('id', 0, 'GET');
265
        }
266
        $mimeTypeObj = $publisher->getHandler('mimetype')->get($mimeId); // Retrieve mimetype object
267
268
        if (!Request::getString('edit_mime', '', 'POST')) {
269
            $session    = PublisherSession::getInstance();
270
            $mimeType   = $session->get('publisher_editMime_' . $mimeId);
271
            $mimeErrors = $session->get('publisher_editMimeErr_' . $mimeId);
272
273
            // Display header
274
            PublisherUtility::cpHeader();
275
            //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_EDIT);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
276
277
            PublisherUtility::openCollapsableBar('mimemedittable', 'mimeediticon', _AM_PUBLISHER_MIME_EDIT_TITLE);
278
279
            //Display any form errors
280 View Code Duplication
            if (!$mimeErrors === false) {
0 ignored issues
show
Duplication introduced by
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...
281
                PublisherUtility::renderErrors($mimeErrors, PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'clearEditSession', 'id' => $mimeId)));
282
            }
283
284
            if ($mimeType === false) {
285
                $mimeExt   = $mimeTypeObj->getVar('mime_ext');
286
                $mimeName  = $mimeTypeObj->getVar('mime_name', 'e');
287
                $mimeTypes = $mimeTypeObj->getVar('mime_types', 'e');
288
                $mimeAdmin = $mimeTypeObj->getVar('mime_admin');
289
                $mimeUser  = $mimeTypeObj->getVar('mime_user');
290 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
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...
291
                $mimeExt   = $mimeType['mime_ext'];
292
                $mimeName  = $mimeType['mime_name'];
293
                $mimeTypes = $mimeType['mime_types'];
294
                $mimeAdmin = $mimeType['mime_admin'];
295
                $mimeUser  = $mimeType['mime_user'];
296
            }
297
298
            // Display edit form
299
            echo "<form action='mimetypes.php?op=edit&amp;id=" . $mimeId . "' method='post'>";
300
            echo $GLOBALS['xoopsSecurity']->getTokenHTML();
301
            echo "<input type='hidden' name='limit' value='" . $limit . "' />";
302
            echo "<input type='hidden' name='start' value='" . $start . "' />";
303
            echo "<table width='100%' cellspacing='1' class='outer'>";
304
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_MIME_MODIFYF . '</th></tr>';
305
            echo "<tr valign='top'>
306
        <td class='head'>" . _AM_PUBLISHER_MIME_EXTF . "</td>
307
        <td class='even'><input type='text' name='mime_ext' id='mime_ext' value='$mimeExt' size='5' /></td>
308
        </tr>";
309
            echo "<tr valign='top'>
310
        <td class='head'>" . _AM_PUBLISHER_MIME_NAMEF . "</td>
311
        <td class='even'><input type='text' name='mime_name' id='mime_name' value='$mimeName' /></td>
312
        </tr>";
313
            echo "<tr valign='top'>
314
        <td class='head'>" . _AM_PUBLISHER_MIME_TYPEF . "</td>
315
        <td class='even'><textarea name='mime_types' id='mime_types' cols='60' rows='5'>$mimeTypes</textarea></td>
316
        </tr>";
317
            echo "<tr valign='top'>
318
        <td class='head'>" . _AM_PUBLISHER_MIME_ADMINF . "</td>
319
        <td class='even'>
320
        <input type='radio' name='mime_admin' value='1' " . ($mimeAdmin == 1 ? 'checked' : '') . ' />' . _YES . "
321
        <input type='radio' name='mime_admin' value='0' " . ($mimeAdmin == 0 ? 'checked' : '') . ' />' . _NO . '
322
        </td>
323
        </tr>';
324
            echo "<tr valign='top'>
325
        <td class='head'>" . _AM_PUBLISHER_MIME_USERF . "</td>
326
        <td class='even'>
327
        <input type='radio' name='mime_user' value='1' " . ($mimeUser == 1 ? 'checked' : '') . ' />' . _YES . "
328
        <input type='radio' name='mime_user' value='0' " . ($mimeUser == 0 ? 'checked' : '') . ' />' . _NO . '
329
        </td>
330
        </tr>';
331
            echo "<tr valign='top'>
332
        <td class='head'></td>
333
        <td class='even'>
334
        <input type='submit' name='edit_mime' id='edit_mime' value='" . _AM_PUBLISHER_BUTTON_UPDATE . "' class='formButton' />
335
        <input type='button' name='cancel' value='" . _AM_PUBLISHER_BUTTON_CANCEL . "' onclick='history.go(-1)' class='formButton' />
336
        </td>
337
        </tr>";
338
            echo '</table></form>';
339
            // end of edit form
340
            PublisherUtility::closeCollapsableBar('mimeedittable', 'mimeediticon');
341
            //            xoops_cp_footer();
342
            require_once __DIR__ . '/admin_footer.php';
343
        } else {
344
            $mimeAdmin = 0;
345
            $mimeUser  = 0;
346
            if (1 == Request::getInt('mime_admin', 0, 'POST')) {
347
                $mimeAdmin = 1;
348
            }
349
            if (1 == Request::getInt('mime_user', 0, 'POST')) {
350
                $mimeUser = 1;
351
            }
352
353
            //Validate Mimetype entry
354
            if ('' === Request::getString('mime_ext', '', 'POST')) {
355
                $hasErrors           = true;
356
                $error['mime_ext'][] = _AM_PUBLISHER_VALID_ERR_MIME_EXT;
357
            }
358
359
            if ('' === Request::getString('mime_name', '', 'POST')) {
360
                $hasErrors            = true;
361
                $error['mime_name'][] = _AM_PUBLISHER_VALID_ERR_MIME_NAME;
362
            }
363
364
            if ('' === Request::getString('mime_types', '', 'POST')) {
365
                $hasErrors             = true;
366
                $error['mime_types'][] = _AM_PUBLISHER_VALID_ERR_MIME_TYPES;
367
            }
368
369
            if ($hasErrors) {
370
                $session            = PublisherSession::getInstance();
371
                $mime               = array();
372
                $mime['mime_ext']   = Request::getString('mime_ext', '', 'POST');
373
                $mime['mime_name']  = Request::getString('mime_name', '', 'POST');
374
                $mime['mime_types'] = Request::getText('mime_types', '', 'POST');
375
                $mime['mime_admin'] = $mimeAdmin;
376
                $mime['mime_user']  = $mimeUser;
377
                $session->set('publisher_editMime_' . $mimeId, $mime);
378
                $session->set('publisher_editMimeErr_' . $mimeId, $error);
379
                header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'edit', 'id' => $mimeId), false));
380
            }
381
382
            $mimeTypeObj->setVar('mime_ext', Request::getString('mime_ext', '', 'POST'));
383
            $mimeTypeObj->setVar('mime_name', Request::getString('mime_name', '', 'POST'));
384
            $mimeTypeObj->setVar('mime_types', Request::getText('mime_types', '', 'POST'));
385
            $mimeTypeObj->setVar('mime_admin', $mimeAdmin);
386
            $mimeTypeObj->setVar('mime_user', $mimeUser);
387
388 View Code Duplication
            if (!$publisher->getHandler('mimetype')->insert($mimeTypeObj, true)) {
0 ignored issues
show
Duplication introduced by
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...
389
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=edit&id=$mimeId", 3, _AM_PUBLISHER_MESSAGE_EDIT_MIME_ERROR);
390
            } else {
391
                self::clearEditSessionVars($mimeId);
392
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage&limit=$limit&start=$start");
393
            }
394
        }
395
    }
396
397
    public static function manage()
0 ignored issues
show
Coding Style introduced by
manage uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
398
    {
399
        $publisher = PublisherPublisher::getInstance();
400
        global $imagearray, $start, $limit, $aSortBy, $aOrderBy, $aLimitBy, $aSearchBy;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
401
402 View Code Duplication
        if (Request::getString('deleteMimes', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
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...
403
            $aMimes = Request::getArray('mimes', array(), 'POST');
404
405
            $crit = new Criteria('mime_id', '(' . implode($aMimes, ',') . ')', 'IN');
406
407
            if ($publisher->getHandler('mimetype')->deleteAll($crit)) {
408
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
409
            } else {
410
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
411
            }
412
        }
413 View Code Duplication
        if (Request::getString('add_mime', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
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...
414
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
415
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit", 3, _AM_PUBLISHER_MIME_CREATEF);
416
            //        exit();
417
        }
418
        if (Request::getString('mime_search', '', 'POST')) {
419
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search");
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
420
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php?op=search', 3, _AM_PUBLISHER_MIME_SEARCH);
421
            //        exit();
422
        }
423
424
        PublisherUtility::cpHeader();
425
        ////publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES);
426
        PublisherUtility::openCollapsableBar('mimemanagetable', 'mimemanageicon', _AM_PUBLISHER_MIME_MANAGE_TITLE, _AM_PUBLISHER_MIME_INFOTEXT);
427
        $crit  = new CriteriaCompo();
428
        $order = Request::getString('order', 'ASC', 'POST');
429
        $sort  = Request::getString('sort', 'mime_ext', 'POST');
430
431
        $crit->setOrder($order);
432
        $crit->setStart($start);
433
        $crit->setLimit($limit);
434
        $crit->setSort($sort);
435
        $mimetypes = $publisher->getHandler('mimetype')->getObjects($crit); // Retrieve a list of all mimetypes
436
        $mimeCount = $publisher->getHandler('mimetype')->getCount();
437
        $nav       = new XoopsPageNav($mimeCount, $limit, $start, 'start', "op=manage&amp;limit=$limit");
438
439
        echo "<table width='100%' cellspacing='1' class='outer'>";
440
        echo "<tr><td colspan='6' align='right'>";
441
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
442
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
443
        echo '<table>';
444
        echo '<tr>';
445
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
446
        echo "<td align='left'><select name='search_by'>";
447 View Code Duplication
        foreach ($aSearchBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
448
            ($sort == $value) ? $selected = 'selected' : $selected = '';
449
            echo "<option value='$value' $selected>$text</option>";
450
        }
451
        unset($value, $text);
452
        echo '</select></td>';
453
        echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
454
        echo "<td align='left'><input type='text' name='search_text' id='search_text' value='' /></td>";
455
        echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "' /></td>";
456
        echo '</tr></table></form></td></tr>';
457
458
        echo "<tr><td colspan='6'>";
459
        echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=manage' style='margin:0; padding:0;' method='post'>";
460
        echo $GLOBALS['xoopsSecurity']->getTokenHTML();
461
        echo "<table width='100%'>";
462
        echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
463
    <select name='sort'>";
464 View Code Duplication
        foreach ($aSortBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
465
            ($sort == $value) ? $selected = 'selected' : $selected = '';
466
            echo "<option value='$value' $selected>$text</option>";
467
        }
468
        unset($value, $text);
469
        echo '</select>
470
    &nbsp;&nbsp;&nbsp;
471
    ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
472
    <select name='order'>";
473 View Code Duplication
        foreach ($aOrderBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
474
            ($order == $value) ? $selected = 'selected' : $selected = '';
475
            echo "<option value='$value' $selected>$text</option>";
476
        }
477
        unset($value, $text);
478
        echo '</select>
479
    &nbsp;&nbsp;&nbsp;
480
    ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . "
481
    <select name='limit'>";
482 View Code Duplication
        foreach ($aLimitBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
483
            ($limit == $value) ? $selected = 'selected' : $selected = '';
484
            echo "<option value='$value' $selected>$text</option>";
485
        }
486
        unset($value, $text);
487
        echo "</select>
488
    <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' />
489
    </td>
490
    </tr>";
491
        echo '</table>';
492
        echo '</td></tr>';
493
        echo "<tr><th colspan='6'>" . _AM_PUBLISHER_MIME_MANAGE_TITLE . '</th></tr>';
494
        echo "<tr class='head'>
495
    <td>" . _AM_PUBLISHER_MIME_ID . '</td>
496
    <td>' . _AM_PUBLISHER_MIME_NAME . "</td>
497
    <td align='center'>" . _AM_PUBLISHER_MIME_EXT . "</td>
498
    <td align='center'>" . _AM_PUBLISHER_MIME_ADMIN . "</td>
499
    <td align='center'>" . _AM_PUBLISHER_MIME_USER . "</td>
500
    <td align='center'>" . _AM_PUBLISHER_MINDEX_ACTION . '</td>
501
    </tr>';
502 View Code Duplication
        foreach ($mimetypes as $mime) {
0 ignored issues
show
Duplication introduced by
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...
503
            echo "<tr class='even'>
504
        <td><input type='checkbox' name='mimes[]' value='"
505
                 . $mime->getVar('mime_id')
506
                 . "' />"
507
                 . $mime->getVar('mime_id')
508
                 . '</td>
509
        <td>'
510
                 . $mime->getVar('mime_name')
511
                 . "</td>
512
        <td align='center'>"
513
                 . $mime->getVar('mime_ext')
514
                 . "</td>
515
        <td align='center'>
516
        <a href='"
517
                 . PUBLISHER_ADMIN_URL
518
                 . '/mimetypes.php?op=updateMimeValue&amp;id='
519
                 . $mime->getVar('mime_id')
520
                 . '&amp;mime_admin='
521
                 . $mime->getVar('mime_admin')
522
                 . '&amp;limit='
523
                 . $limit
524
                 . '&amp;start='
525
                 . $start
526
                 . "'>
527
        "
528
                 . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline'])
529
                 . "</a>
530
        </td>
531
        <td align='center'>
532
        <a href='"
533
                 . PUBLISHER_ADMIN_URL
534
                 . '/mimetypes.php?op=updateMimeValue&amp;id='
535
                 . $mime->getVar('mime_id')
536
                 . '&amp;mime_user='
537
                 . $mime->getVar('mime_user')
538
                 . '&amp;limit='
539
                 . $limit
540
                 . '&amp;start='
541
                 . $start
542
                 . "'>
543
        "
544
                 . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline'])
545
                 . "</a>
546
        </td>
547
        <td align='center'>
548
        <a href='"
549
                 . PUBLISHER_ADMIN_URL
550
                 . '/mimetypes.php?op=edit&amp;id='
551
                 . $mime->getVar('mime_id')
552
                 . '&amp;limit='
553
                 . $limit
554
                 . '&amp;start='
555
                 . $start
556
                 . "'>"
557
                 . $imagearray['editimg']
558
                 . "</a>
559
        <a href='"
560
                 . PUBLISHER_ADMIN_URL
561
                 . '/mimetypes.php?op=delete&amp;id='
562
                 . $mime->getVar('mime_id')
563
                 . '&amp;limit='
564
                 . $limit
565
                 . '&amp;start='
566
                 . $start
567
                 . "'>"
568
                 . $imagearray['deleteimg']
569
                 . '</a>
570
        </td>
571
        </tr>';
572
        }
573
        //        unset($mime);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
574
        echo "<tr class='foot'>
575
    <td colspan='6' valign='top'>
576
    <a href='http://www.filext.com' style='float: right;' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
577
    <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);' />
578
    <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "' />
579
    <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton' />
580
    </td>
581
    </tr>";
582
        echo '</table>';
583
        echo "<div id='staff_nav'>" . $nav->renderNav() . '</div><br>';
584
585
        PublisherUtility::closeCollapsableBar('mimemanagetable', 'mimemanageicon');
586
587
        //        xoops_cp_footer();
588
        require_once __DIR__ . '/admin_footer.php';
589
    }
590
591
    public static function search()
0 ignored issues
show
Coding Style introduced by
search uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
592
    {
593
        $publisher = PublisherPublisher::getInstance();
594
        global $limit, $start, $imagearray, $aSearchBy, $aOrderBy, $aLimitBy, $aSortBy;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
595
596 View Code Duplication
        if (Request::getString('deleteMimes', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
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...
597
            $aMimes = Request::getArray('mimes', array(), 'POST');
598
599
            $crit = new Criteria('mime_id', '(' . implode($aMimes, ',') . ')', 'IN');
600
601
            if ($publisher->getHandler('mimetype')->deleteAll($crit)) {
602
                header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
603
            } else {
604
                redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3, _AM_PUBLISHER_MESSAGE_DELETE_MIME_ERROR);
605
            }
606
        }
607 View Code Duplication
        if (Request::getString('add_mime', '', 'POST')) {
0 ignored issues
show
Duplication introduced by
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...
608
            //        header("Location: " . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit");
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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...
609
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?op=add&start=$start&limit=$limit", 3, _AM_PUBLISHER_MIME_CREATEF);
610
            //        exit();
611
        }
612
613
        $order = Request::getString('order', 'ASC');
614
        $sort  = Request::getString('sort', 'mime_name');
615
616
        PublisherUtility::cpHeader();
617
        //publisher_adminMenu(4, _AM_PUBLISHER_MIMETYPES . " > " . _AM_PUBLISHER_BUTTON_SEARCH);
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
618
619
        PublisherUtility::openCollapsableBar('mimemsearchtable', 'mimesearchicon', _AM_PUBLISHER_MIME_SEARCH);
620
621
        if (!Request::hasVar('mime_search')) {
622
            echo "<form action='mimetypes.php?op=search' method='post'>";
623
            echo $GLOBALS['xoopsSecurity']->getTokenHTML();
624
            echo "<table width='100%' cellspacing='1' class='outer'>";
625
            echo "<tr><th colspan='2'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
626
            echo "<tr><td class='head' width='20%'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . "</td>
627
        <td class='even'>
628
        <select name='search_by'>";
629
            foreach ($aSortBy as $value => $text) {
630
                echo "<option value='$value'>$text</option>";
631
            }
632
            unset($value, $text);
633
            echo '</select>
634
        </td>
635
        </tr>';
636
            echo "<tr><td class='head'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . "</td>
637
        <td class='even'>
638
        <input type='text' name='search_text' id='search_text' value='' />
639
        </td>
640
        </tr>";
641
            echo "<tr class='foot'>
642
        <td colspan='2'>
643
        <input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "' />
644
        </td>
645
        </tr>";
646
            echo '</table></form>';
647
        } else {
648
            $searchField = Request::getString('search_by', '');
649
            $searchField = isset($aSearchBy[$searchField]) ? $searchField : 'mime_ext' ;
650
            $searchText  = Request::getString('search_text', '');
651
652
            $crit = new Criteria($searchField, '%' . $GLOBALS['xoopsDB']->escape($searchText) . '%', 'LIKE');
653
            $crit->setSort($sort);
654
            $crit->setOrder($order);
655
            $crit->setLimit($limit);
656
            $crit->setStart($start);
657
            $mimeCount = $publisher->getHandler('mimetype')->getCount($crit);
658
            $mimetypes = $publisher->getHandler('mimetype')->getObjects($crit);
659
            $nav       = new XoopsPageNav($mimeCount, $limit, $start, 'start',
660
                "op=search&amp;limit=$limit&amp;order=$order&amp;sort=$sort&amp;mime_search=1&amp;search_by=$searchField&amp;search_text="
661
                . htmlentities($searchText, ENT_QUOTES));
662
            // Display results
663
            echo '<script type="text/javascript" src="' . PUBLISHER_URL . '/include/functions.js"></script>';
664
665
            echo "<table width='100%' cellspacing='1' class='outer'>";
666
            echo "<tr><td colspan='6' align='right'>";
667
            echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
668
            echo $GLOBALS['xoopsSecurity']->getTokenHTML();
669
            echo '<table>';
670
            echo '<tr>';
671
            echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_BY . '</td>';
672
            echo "<td align='left'><select name='search_by'>";
673 View Code Duplication
            foreach ($aSearchBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
674
                ($searchField == $value) ? $selected = 'selected' : $selected = '';
675
                echo "<option value='$value' $selected>$text</option>";
676
            }
677
            unset($value, $text);
678
            echo '</select></td>';
679
            echo "<td align='right'>" . _AM_PUBLISHER_TEXT_SEARCH_TEXT . '</td>';
680
            echo "<td align='left'><input type='text' name='search_text' id='search_text' value='" .htmlentities($searchText, ENT_QUOTES). "' /></td>";
681
            echo "<td><input type='submit' name='mime_search' id='mime_search' value='" . _AM_PUBLISHER_BUTTON_SEARCH . "' /></td>";
682
            echo '</tr></table></form></td></tr>';
683
684
            echo "<tr><td colspan='6'>";
685
            echo "<form action='" . PUBLISHER_ADMIN_URL . "/mimetypes.php?op=search' style='margin:0; padding:0;' method='post'>";
686
            echo $GLOBALS['xoopsSecurity']->getTokenHTML();
687
            echo "<table width='100%'>";
688
            echo "<tr><td align='right'>" . _AM_PUBLISHER_TEXT_SORT_BY . "
689
        <select name='sort'>";
690 View Code Duplication
            foreach ($aSortBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
691
                ($sort == $value) ? $selected = 'selected' : $selected = '';
692
                echo "<option value='$value' $selected>$text</option>";
693
            }
694
            unset($value, $text);
695
            echo '</select>
696
        &nbsp;&nbsp;&nbsp;
697
        ' . _AM_PUBLISHER_TEXT_ORDER_BY . "
698
        <select name='order'>";
699 View Code Duplication
            foreach ($aOrderBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
700
                ($order == $value) ? $selected = 'selected' : $selected = '';
701
                echo "<option value='$value' $selected>$text</option>";
702
            }
703
            unset($value, $text);
704
            echo '</select>
705
        &nbsp;&nbsp;&nbsp;
706
        ' . _AM_PUBLISHER_TEXT_NUMBER_PER_PAGE . "
707
        <select name='limit'>";
708 View Code Duplication
            foreach ($aLimitBy as $value => $text) {
0 ignored issues
show
Duplication introduced by
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...
709
                ($limit == $value) ? $selected = 'selected' : $selected = '';
710
                echo "<option value='$value' $selected>$text</option>";
711
            }
712
            unset($value, $text);
713
            echo "</select>
714
        <input type='submit' name='mime_sort' id='mime_sort' value='" . _AM_PUBLISHER_BUTTON_SUBMIT . "' />
715
        <input type='hidden' name='mime_search' id='mime_search' value='1' />
716
        <input type='hidden' name='search_by' id='search_by' value='$searchField' />
717
        <input type='hidden' name='search_text' id='search_text' value='" .htmlentities($searchText, ENT_QUOTES) . "' />
718
        </td>
719
        </tr>";
720
            echo '</table>';
721
            echo '</td></tr>';
722
            if (count($mimetypes) > 0) {
723
                echo "<tr><th colspan='6'>" . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
724
                echo "<tr class='head'>
725
            <td>" . _AM_PUBLISHER_MIME_ID . '</td>
726
            <td>' . _AM_PUBLISHER_MIME_NAME . "</td>
727
            <td align='center'>" . _AM_PUBLISHER_MIME_EXT . "</td>
728
            <td align='center'>" . _AM_PUBLISHER_MIME_ADMIN . "</td>
729
            <td align='center'>" . _AM_PUBLISHER_MIME_USER . "</td>
730
            <td align='center'>" . _AM_PUBLISHER_MINDEX_ACTION . '</td>
731
            </tr>';
732 View Code Duplication
                foreach ($mimetypes as $mime) {
0 ignored issues
show
Duplication introduced by
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...
733
                    echo "<tr class='even'>
734
                <td><input type='checkbox' name='mimes[]' value='"
735
                         . $mime->getVar('mime_id')
736
                         . "' />"
737
                         . $mime->getVar('mime_id')
738
                         . '</td>
739
                <td>'
740
                         . $mime->getVar('mime_name')
741
                         . "</td>
742
                <td align='center'>"
743
                         . $mime->getVar('mime_ext')
744
                         . "</td>
745
                <td align='center'>
746
                <a href='"
747
                         . PUBLISHER_ADMIN_URL
748
                         . '/mimetypes.php?op=updateMimeValue&amp;id='
749
                         . $mime->getVar('mime_id')
750
                         . '&amp;mime_admin='
751
                         . $mime->getVar('mime_admin')
752
                         . '&amp;limit='
753
                         . $limit
754
                         . '&amp;start='
755
                         . $start
756
                         . "'>
757
                "
758
                         . ($mime->getVar('mime_admin') ? $imagearray['online'] : $imagearray['offline'])
759
                         . "</a>
760
                </td>
761
                <td align='center'>
762
                <a href='"
763
                         . PUBLISHER_ADMIN_URL
764
                         . '/mimetypes.php?op=updateMimeValue&amp;id='
765
                         . $mime->getVar('mime_id')
766
                         . '&amp;mime_user='
767
                         . $mime->getVar('mime_user')
768
                         . '&amp;limit='
769
                         . $limit
770
                         . '&amp;start='
771
                         . $start
772
                         . "'>
773
                "
774
                         . ($mime->getVar('mime_user') ? $imagearray['online'] : $imagearray['offline'])
775
                         . "</a>
776
                </td>
777
                <td align='center'>
778
                <a href='"
779
                         . PUBLISHER_ADMIN_URL
780
                         . '/mimetypes.php?op=edit&amp;id='
781
                         . $mime->getVar('mime_id')
782
                         . '&amp;limit='
783
                         . $limit
784
                         . '&amp;start='
785
                         . $start
786
                         . "'>"
787
                         . $imagearray['editimg']
788
                         . "</a>
789
                <a href='"
790
                         . PUBLISHER_ADMIN_URL
791
                         . '/mimetypes.php?op=delete&amp;id='
792
                         . $mime->getVar('mime_id')
793
                         . '&amp;limit='
794
                         . $limit
795
                         . '&amp;start='
796
                         . $start
797
                         . "'>"
798
                         . $imagearray['deleteimg']
799
                         . '</a>
800
                </td>
801
                </tr>';
802
                }
803
                //                unset($mime);
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
804
                echo "<tr class='foot'>
805
            <td colspan='6' valign='top'>
806
            <a href='http://www.filext.com' style='float: right;' target='_blank'>" . _AM_PUBLISHER_MIME_FINDMIMETYPE . "</a>
807
            <input type='checkbox' name='checkAllMimes' value='0' onclick='selectAll(this.form,\"mimes[]\",this.checked);' />
808
            <input type='submit' name='deleteMimes' id='deleteMimes' value='" . _AM_PUBLISHER_BUTTON_DELETE . "' />
809
            <input type='submit' name='add_mime' id='add_mime' value='" . _AM_PUBLISHER_MIME_CREATEF . "' class='formButton' />
810
            </td>
811
            </tr>";
812
            } else {
813
                echo '<tr><th>' . _AM_PUBLISHER_TEXT_SEARCH_MIME . '</th></tr>';
814
                echo "<tr class='even'>
815
            <td>" . _AM_PUBLISHER_TEXT_NO_RECORDS . '</td>
816
            </tr>';
817
            }
818
            echo '</table>';
819
            echo "<div id='pagenav'>" . $nav->renderNav() . '</div>';
820
        }
821
        PublisherUtility::closeCollapsableBar('mimesearchtable', 'mimesearchicon');
822
        //        require_once __DIR__ . '/admin_footer.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
823
        xoops_cp_footer();
824
    }
825
826
    /**
827
     * confirm update to mime access, resubmit as POST, including TOKEN
828
     */
829
    public static function updateMimeValue()
830
    {
831
        // op=updateMimeValue&id=65&mime_admin=0&limit=15&start=0
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% 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...
832
        PublisherUtility::cpHeader();
833
        $hiddens = array(
834
            'id'    => Request::getInt('id', 0, 'GET'),
835
            'start' =>  Request::getInt('start', 0, 'GET'),
836
            'limit' =>  Request::getInt('limit', 15, 'GET'),
837
        );
838
839
        $publisher = PublisherPublisher::getInstance();
840
        $mimeTypeObj = $publisher->getHandler('mimetype')->get($hiddens['id']);
841
        if (Request::hasVar('mime_admin')) {
842
            $hiddens['mime_admin'] = Request::getInt('mime_admin', 0, 'GET');
843
            $msg = sprintf(_AM_PUBLISHER_MIME_ACCESS_CONFIRM_ADMIN, $mimeTypeObj->getVar('mime_name'));
844
        } else {
845
            $hiddens['mime_user'] = Request::getInt('mime_user', 0, 'GET');
846
            $msg = sprintf(_AM_PUBLISHER_MIME_ACCESS_CONFIRM_USER, $mimeTypeObj->getVar('mime_name'));
847
        }
848
849
        $action = PUBLISHER_ADMIN_URL . '/mimetypes.php?op=confirmUpdateMimeValue';
850
        $submit = _AM_PUBLISHER_MIME_ACCESS_CONFIRM;
851
852
        xoops_confirm($hiddens, $action, $msg, $submit, true);
853
        xoops_cp_footer();
854
    }
855
856
    public static function confirmUpdateMimeValue()
857
    {
858
        $publisher = PublisherPublisher::getInstance();
859
860
        $limit = Request::getInt('limit', 0, 'POST');
861
        $start = Request::getInt('start', 0, 'POST');
862
        $mimeId = Request::getInt('id', 0, 'POST');
863
        if (0 === $mimeId) {
864
            redirect_header(PUBLISHER_ADMIN_URL . '/mimetypes.php', 3, _AM_PUBLISHER_MESSAGE_NO_ID);
865
        }
866
867
        $mimeTypeObj = $publisher->getHandler('mimetype')->get($mimeId);
868
869
        if (-1 !== ($mimeAdmin = Request::getInt('mime_admin', -1, 'POST'))) {
870
            $mimeAdmin = self::changeMimeValue($mimeAdmin);
871
            $mimeTypeObj->setVar('mime_admin', $mimeAdmin);
872
        } elseif (-1 !== ($mimeUser = Request::getInt('mime_user', -1, 'POST'))) {
873
            $mimeUser = self::changeMimeValue($mimeUser);
874
            $mimeTypeObj->setVar('mime_user', $mimeUser);
875
        }
876
        if ($publisher->getHandler('mimetype')->insert($mimeTypeObj, true)) {
877
            header('Location: ' . PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start");
878
        } else {
879
            redirect_header(PUBLISHER_ADMIN_URL . "/mimetypes.php?limit=$limit&start=$start", 3);
880
        }
881
    }
882
883
    /**
884
     * @param $mimeValue
885
     *
886
     * @return int
887
     */
888
    protected static function changeMimeValue($mimeValue)
889
    {
890
        if ((int)$mimeValue === 1) {
891
            $mimeValue = 0;
892
        } else {
893
            $mimeValue = 1;
894
        }
895
896
        return $mimeValue;
897
    }
898
899
    protected static function clearAddSessionVars()
900
    {
901
        $session = PublisherSession::getInstance();
902
        $session->del('publisher_addMime');
903
        $session->del('publisher_addMimeErr');
904
    }
905
906
    public static function clearAddSession()
907
    {
908
        self::clearAddSessionVars();
909
        header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'add'), false));
910
    }
911
912
    /**
913
     * @param $id
914
     */
915
    public static function clearEditSessionVars($id)
916
    {
917
        $id      = (int)$id;
918
        $session = PublisherSession::getInstance();
919
        $session->del("publisher_editMime_$id");
920
        $session->del("publisher_editMimeErr_$id");
921
    }
922
923
    public static function clearEditSession()
924
    {
925
        $mimeid = Request::getInt('id', '', 'GET');
926
        self::clearEditSessionVars($mimeid);
927
        header('Location: ' . PublisherUtility::makeUri(PUBLISHER_ADMIN_URL . '/mimetypes.php', array('op' => 'edit', 'id' => $mimeid), false));
928
    }
929
}
930