Completed
Pull Request — master (#489)
by Richard
10:59
created

item.php ➔ publisher_editItem()   F

Complexity

Conditions 17
Paths 232

Size

Total Lines 135
Code Lines 86

Duplication

Lines 8
Ratio 5.93 %
Metric Value
cc 17
eloc 86
nc 232
nop 3
dl 8
loc 135
rs 3.9953

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\Request;
13
use Xoops\Core\XoopsTpl;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsTpl.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
15
/**
16
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
17
 * @license         GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
18
 * @package         Publisher
19
 * @since           1.0
20
 * @author          trabis <[email protected]>
21
 * @author          The SmartFactory <www.smartfactory.ca>
22
 */
23
24
include_once __DIR__ . '/admin_header.php';
25
26
$xoops = Xoops::getInstance();
27
28
$itemid = Request::getInt('itemid');
29
$op = ($itemid > 0 || isset($_POST['editor'])) ? 'mod' : '';
30
$op = Request::getCmd('op', $op);
31
32 View Code Duplication
if (isset($_POST['additem'])) {
33
    $op = 'additem';
34
} else {
35
    if (isset($_POST['del'])) {
36
        $op = 'del';
37
    }
38
}
39
40
// Where shall we start ?
41
$submittedstartitem = Request::getInt('submittedstartitem');
42
$publishedstartitem = Request::getInt('publishedstartitem');
43
$offlinestartitem = Request::getInt('offlinestartitem');
44
$rejectedstartitem = Request::getInt('rejectedstartitem');
45
46
switch ($op) {
47 View Code Duplication
    case "clone":
48
        if ($itemid == 0) {
49
            $totalcategories = $publisher->getCategoryHandler()->getCategoriesCount(-1);
50
            if ($totalcategories == 0) {
51
                $xoops->redirect("category.php?op=mod", 3, _AM_PUBLISHER_NEED_CATEGORY_ITEM);
52
53
            }
54
        }
55
        PublisherUtils::cpHeader();
56
        publisher_editItem(true, $itemid, true);
57
        break;
58
59 View Code Duplication
    case "mod":
60
        if ($itemid == 0) {
61
            $totalcategories = $publisher->getCategoryHandler()->getCategoriesCount(-1);
62
            if ($totalcategories == 0) {
63
                $xoops->redirect("category.php?op=mod", 3, _AM_PUBLISHER_NEED_CATEGORY_ITEM);
64
                exit();
65
            }
66
        }
67
68
        PublisherUtils::cpHeader();
69
        publisher_editItem(true, $itemid);
70
        break;
71
72
    case "additem":
73
        // Creating the item object
74
        /* @var $itemObj PublisherItem */
75
        if ($itemid != 0) {
76
            $itemObj = $publisher->getItemHandler()->get($itemid);
77
        } else {
78
            $itemObj = $publisher->getItemHandler()->create();
79
        }
80
81
        $itemObj->setVarsFromRequest();
82
83
        $old_status = $itemObj->getVar('status');
84
        $new_status = \Xmf\Request::getInt('status', _PUBLISHER_STATUS_PUBLISHED); //_PUBLISHER_STATUS_NOTSET;
85
86
        $error_msg = '';
87
        $redirect_msg = '';
88
        switch ($new_status) {
89 View Code Duplication
            case _PUBLISHER_STATUS_SUBMITTED:
90
                if (($old_status == _PUBLISHER_STATUS_NOTSET)) {
91
                    $error_msg = _AM_PUBLISHER_ITEMNOTUPDATED;
92
                } else {
93
                    $error_msg = _AM_PUBLISHER_ITEMNOTCREATED;
94
                }
95
                $redirect_msg = _AM_PUBLISHER_ITEM_RECEIVED_NEED_APPROVAL;
96
                break;
97
98
            case _PUBLISHER_STATUS_PUBLISHED:
99
                if (($old_status == _PUBLISHER_STATUS_NOTSET) || ($old_status == _PUBLISHER_STATUS_SUBMITTED)) {
100
                    $redirect_msg = _AM_PUBLISHER_SUBMITTED_APPROVE_SUCCESS;
101
                    $notifToDo = array(_PUBLISHER_NOT_ITEM_PUBLISHED);
102
                } else {
103
                    $redirect_msg = _AM_PUBLISHER_PUBLISHED_MOD_SUCCESS;
104
                }
105
                $error_msg = _AM_PUBLISHER_ITEMNOTUPDATED;
106
                break;
107
108
            case _PUBLISHER_STATUS_OFFLINE:
109
                if ($old_status == _PUBLISHER_STATUS_NOTSET) {
110
                    $redirect_msg = _AM_PUBLISHER_OFFLINE_CREATED_SUCCESS;
111
                } else {
112
                    $redirect_msg = _AM_PUBLISHER_OFFLINE_MOD_SUCCESS;
113
                }
114
                $error_msg = _AM_PUBLISHER_ITEMNOTUPDATED;
115
                break;
116
117 View Code Duplication
            case _PUBLISHER_STATUS_REJECTED:
118
                if ($old_status == _PUBLISHER_STATUS_NOTSET) {
119
                    $error_msg = _AM_PUBLISHER_ITEMNOTUPDATED;
120
                } else {
121
                    $error_msg = _AM_PUBLISHER_ITEMNOTCREATED;
122
                }
123
                $redirect_msg = _AM_PUBLISHER_ITEM_REJECTED;
124
                break;
125
        }
126
        $itemObj->setVar('status', $new_status);
127
128
        // Storing the item
129
        if (!$itemObj->store()) {
130
            $xoops->redirect("javascript:history.go(-1)", 3, $error_msg . PublisherUtils::formatErrors($itemObj->getErrors()));
131
        }
132
133
        // attach file if any
134
        if (isset($_FILES['item_upload_file']) && $_FILES['item_upload_file']['name'] != "") {
135
            $file_upload_result = PublisherUtils::uploadFile(false, false, $itemObj);
136
            if ($file_upload_result !== true) {
137
                $xoops->redirect("javascript:history.go(-1)", 3, $file_upload_result);
0 ignored issues
show
Bug introduced by
It seems like $file_upload_result defined by \PublisherUtils::uploadF...false, false, $itemObj) on line 135 can also be of type boolean; however, Xoops::redirect() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
138
                exit;
139
            }
140
        }
141
142
        // Send notifications
143
        if (!empty($notifToDo)) {
144
            $itemObj->sendNotifications($notifToDo);
145
        }
146
        $xoops->redirect("item.php", 2, $redirect_msg);
147
        break;
148
149
    case "del":
150
        /* @var $itemObj PublisherItem */
151
        $itemObj = $publisher->getItemHandler()->get($itemid);
152
        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
153
154 View Code Duplication
        if ($confirm) {
155
            if (!$publisher->getItemHandler()->delete($itemObj)) {
156
                $xoops->redirect("item.php", 2, _AM_PUBLISHER_ITEM_DELETE_ERROR . PublisherUtils::formatErrors($itemObj->getErrors()));
157
                exit();
158
            }
159
            $xoops->redirect("item.php", 2, sprintf(_AM_PUBLISHER_ITEMISDELETED, $itemObj->title()));
160
        } else {
161
            $xoops->header();
162
            echo $xoops->confirm(array(
163
                'op' => 'del', 'itemid' => $itemObj->getVar('itemid'), 'confirm' => 1, 'name' => $itemObj->title()
164
            ), 'item.php', _AM_PUBLISHER_DELETETHISITEM . " <br />'" . $itemObj->title() . "'. <br /> <br />", _AM_PUBLISHER_DELETE);
165
            $xoops->footer();
166
        }
167
        exit();
168
        break;
169
170
    case "default":
171
    default:
172
        PublisherUtils::cpHeader();
173
        //publisher_adminMenu(2, _AM_PUBLISHER_ITEMS);
174
175
        echo "<br />\n";
176
        echo "<form><div style=\"margin-bottom: 12px;\">";
177
        echo "<input type='button' name='button' onclick=\"location='item.php?op=mod'\" value='" . _AM_PUBLISHER_CREATEITEM . "'>&nbsp;&nbsp;";
178
        echo "</div></form>";
179
180
        $orderBy = 'datesub';
181
        $ascOrDesc = 'DESC';
182
183
        // Display Submited articles
184
        PublisherUtils::openCollapsableBar('submiteditemstable', 'submiteditemsicon', _AM_PUBLISHER_SUBMISSIONSMNGMT, _AM_PUBLISHER_SUBMITTED_EXP);
185
186
        // Get the total number of submitted ITEM
187
        $totalitems = $publisher->getItemHandler()->getItemsCount(-1, array(_PUBLISHER_STATUS_SUBMITTED));
188
189
        $itemsObj = $publisher->getItemHandler()
190
                ->getAllSubmitted($publisher->getConfig('idxcat_perpage'), $submittedstartitem, -1, $orderBy, $ascOrDesc);
191
192
        $totalItemsOnPage = count($itemsObj);
193
194
        echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
195
        echo "<tr>";
196
        echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . "</strong></td>";
197
        echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCATEGORYNAME . "</strong></td>";
198
        echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_TITLE . "</strong></td>";
199
        echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . "</strong></td>";
200
        echo "<td width='80' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
201
        echo "</tr>";
202
        if ($totalitems > 0) {
203
            for ($i = 0; $i < $totalItemsOnPage; ++$i) {
204
                $categoryObj = $itemsObj[$i]->category();
205
206
                $approve = "<a href='item.php?op=mod&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/approve.gif' title='" . _AM_PUBLISHER_SUBMISSION_MODERATE . "' alt='" . _AM_PUBLISHER_SUBMISSION_MODERATE . "' /></a>&nbsp;";
207
                $clone = '';
208
                $delete = "<a href='item.php?op=del&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "' /></a>";
209
                $modify = "";
210
211
                echo "<tr>";
212
                echo "<td class='head' align='center'>" . $itemsObj[$i]->getVar('itemid') . "</td>";
213
                echo "<td class='even' align='left'>" . $categoryObj->getCategoryLink() . "</td>";
214
                echo "<td class='even' align='left'><a href='" . PUBLISHER_URL . "/item.php?itemid=" . $itemsObj[$i]->getVar('itemid') . "'>" . $itemsObj[$i]->title() . "</a></td>";
215
                echo "<td class='even' align='center'>" . $itemsObj[$i]->datesub() . "</td>";
216
                echo "<td class='even' align='center'> $approve $clone $modify $delete </td>";
217
                echo "</tr>";
218
            }
219
        } else {
220
            $itemid = 0;
221
            echo "<tr>";
222
            echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS_SUBMITTED . "</td>";
223
            echo "</tr>";
224
        }
225
        echo "</table>\n";
226
        echo "<br />\n";
227
228
        $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $submittedstartitem, 'submittedstartitem');
229
        echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
230
231
        PublisherUtils::closeCollapsableBar('submiteditemstable', 'submiteditemsicon');
232
233
        // Display Published articles
234
        PublisherUtils::openCollapsableBar('item_publisheditemstable', 'item_publisheditemsicon', _AM_PUBLISHER_PUBLISHEDITEMS, _AM_PUBLISHER_PUBLISHED_DSC);
235
236
        // Get the total number of published ITEM
237
        $totalitems = $publisher->getItemHandler()->getItemsCount(-1, array(_PUBLISHER_STATUS_PUBLISHED));
238
239
        $itemsObj = $publisher->getItemHandler()
240
                ->getAllPublished($publisher->getConfig('idxcat_perpage'), $publishedstartitem, -1, $orderBy, $ascOrDesc);
241
242
        $totalItemsOnPage = count($itemsObj);
243
244
        echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
245
        echo "<tr>";
246
        echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . "</strong></td>";
247
        echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCATEGORYNAME . "</strong></td>";
248
        echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_TITLE . "</strong></td>";
249
        echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . "</strong></td>";
250
        echo "<td width='80' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
251
        echo "</tr>";
252 View Code Duplication
        if ($totalitems > 0) {
253
            for ($i = 0; $i < $totalItemsOnPage; ++$i) {
254
                $categoryObj = $itemsObj[$i]->category();
255
256
                $modify = "<a href='item.php?op=mod&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITITEM . "' alt='" . _AM_PUBLISHER_EDITITEM . "' /></a>";
257
                $delete = "<a href='item.php?op=del&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "'/></a>";
258
                $clone = "<a href='item.php?op=clone&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/clone.gif' title='" . _AM_PUBLISHER_CLONE_ITEM . "' alt='" . _AM_PUBLISHER_CLONE_ITEM . "' /></a>";
259
260
                echo "<tr>";
261
                echo "<td class='head' align='center'>" . $itemsObj[$i]->getVar('itemid') . "</td>";
262
                echo "<td class='even' align='left'>" . $categoryObj->getCategoryLink() . "</td>";
263
                echo "<td class='even' align='left'>" . $itemsObj[$i]->getItemLink() . "</td>";
264
                echo "<td class='even' align='center'>" . $itemsObj[$i]->datesub() . "</td>";
265
                echo "<td class='even' align='center'> $clone $modify $delete </td>";
266
                echo "</tr>";
267
            }
268
        } else {
269
            $itemid = 0;
270
            echo "<tr>";
271
            echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS . "</td>";
272
            echo "</tr>";
273
        }
274
        echo "</table>\n";
275
        echo "<br />\n";
276
277
        $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $publishedstartitem, 'publishedstartitem');
278
        echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
279
280
        PublisherUtils::closeCollapsableBar('item_publisheditemstable', 'item_publisheditemsicon');
281
282
        // Display Offline articles
283
        PublisherUtils::openCollapsableBar('offlineitemstable', 'offlineitemsicon', _AM_PUBLISHER_ITEMS . " " . _CO_PUBLISHER_OFFLINE, _AM_PUBLISHER_OFFLINE_EXP);
284
285
        $totalitems = $publisher->getItemHandler()->getItemsCount(-1, array(_PUBLISHER_STATUS_OFFLINE));
286
287
        $itemsObj = $publisher->getItemHandler()
288
                ->getAllOffline($publisher->getConfig('idxcat_perpage'), $offlinestartitem, -1, $orderBy, $ascOrDesc);
289
290
        $totalItemsOnPage = count($itemsObj);
291
292
        echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
293
        echo "<tr>";
294
        echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . "</strong></td>";
295
        echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCATEGORYNAME . "</strong></td>";
296
        echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_TITLE . "</strong></td>";
297
        echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . "</strong></td>";
298
        echo "<td width='80' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
299
        echo "</tr>";
300 View Code Duplication
        if ($totalitems > 0) {
301
            for ($i = 0; $i < $totalItemsOnPage; ++$i) {
302
                $categoryObj = $itemsObj[$i]->category();
303
304
                $modify = "<a href='item.php?op=mod&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITITEM . "' alt='" . _AM_PUBLISHER_EDITITEM . "' /></a>";
305
                $delete = "<a href='item.php?op=del&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "'/></a>";
306
                $clone = "<a href='item.php?op=clone&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/clone.gif' title='" . _AM_PUBLISHER_CLONE_ITEM . "' alt='" . _AM_PUBLISHER_CLONE_ITEM . "' /></a>";
307
308
                echo "<tr>";
309
                echo "<td class='head' align='center'>" . $itemsObj[$i]->getVar('itemid') . "</td>";
310
                echo "<td class='even' align='left'>" . $categoryObj->getCategoryLink() . "</td>";
311
                echo "<td class='even' align='left'>" . $itemsObj[$i]->getItemLink() . "</td>";
312
                echo "<td class='even' align='center'>" . $itemsObj[$i]->datesub() . "</td>";
313
                echo "<td class='even' align='center'> $clone $modify $delete </td>";
314
                echo "</tr>";
315
            }
316
        } else {
317
            $itemid = 0;
318
            echo "<tr>";
319
            echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS_OFFLINE . "</td>";
320
            echo "</tr>";
321
        }
322
        echo "</table>\n";
323
        echo "<br />\n";
324
325
        $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $offlinestartitem, 'offlinestartitem');
326
        echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
327
328
        PublisherUtils::closeCollapsableBar('offlineitemstable', 'offlineitemsicon');
329
330
        // Display Rejected articles
331
        PublisherUtils::openCollapsableBar('Rejecteditemstable', 'rejecteditemsicon', _AM_PUBLISHER_REJECTED_ITEM, _AM_PUBLISHER_REJECTED_ITEM_EXP, _AM_PUBLISHER_SUBMITTED_EXP);
332
333
        // Get the total number of Rejected ITEM
334
        $totalitems = $publisher->getItemHandler()->getItemsCount(-1, array(_PUBLISHER_STATUS_REJECTED));
335
336
        $itemsObj = $publisher->getItemHandler()
337
                ->getAllRejected($publisher->getConfig('idxcat_perpage'), $rejectedstartitem, -1, $orderBy, $ascOrDesc);
338
339
        $totalItemsOnPage = count($itemsObj);
340
341
        echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>";
342
        echo "<tr>";
343
        echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . "</strong></td>";
344
        echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCATEGORYNAME . "</strong></td>";
345
        echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_TITLE . "</strong></td>";
346
        echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . "</strong></td>";
347
        echo "<td width='80' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . "</strong></td>";
348
        echo "</tr>";
349 View Code Duplication
        if ($totalitems > 0) {
350
            for ($i = 0; $i < $totalItemsOnPage; ++$i) {
351
                $categoryObj = $itemsObj[$i]->category();
352
353
                $modify = "<a href='item.php?op=mod&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/edit.gif' title='" . _AM_PUBLISHER_EDITITEM . "' alt='" . _AM_PUBLISHER_EDITITEM . "' /></a>";
354
                $delete = "<a href='item.php?op=del&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/delete.png' title='" . _AM_PUBLISHER_DELETEITEM . "' alt='" . _AM_PUBLISHER_DELETEITEM . "'/></a>";
355
                $clone = "<a href='item.php?op=clone&itemid=" . $itemsObj[$i]->getVar('itemid') . "'><img src='" . PUBLISHER_URL . "/images/links/clone.gif' title='" . _AM_PUBLISHER_CLONE_ITEM . "' alt='" . _AM_PUBLISHER_CLONE_ITEM . "' /></a>";
356
357
                echo "<tr>";
358
                echo "<td class='head' align='center'>" . $itemsObj[$i]->getVar('itemid') . "</td>";
359
                echo "<td class='even' align='left'>" . $categoryObj->getCategoryLink() . "</td>";
360
                echo "<td class='even' align='left'>" . $itemsObj[$i]->getItemLink() . "</td>";
361
                echo "<td class='even' align='center'>" . $itemsObj[$i]->datesub() . "</td>";
362
                echo "<td class='even' align='center'> $clone $modify $delete </td>";
363
                echo "</tr>";
364
            }
365
        } else {
366
            $itemid = 0;
367
            echo "<tr>";
368
            echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS_REJECTED . "</td>";
369
            echo "</tr>";
370
        }
371
        echo "</table>\n";
372
        echo "<br />\n";
373
374
        $pagenav = new XoopsPageNav($totalitems, $publisher->getConfig('idxcat_perpage'), $rejectedstartitem, 'rejectedstartitem');
375
        echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>';
376
377
        PublisherUtils::closeCollapsableBar('Rejecteditemstable', 'rejecteditemsicon');
378
        break;
379
}
380
$xoops->footer();
381
382
function publisher_editItem($showmenu = false, $itemid = 0, $clone = false)
0 ignored issues
show
Unused Code introduced by
The parameter $showmenu is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
publisher_editItem uses the super-global variable $_GET 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...
383
{
384
    $xoops = Xoops::getInstance();
385
    $publisher = Publisher::getInstance();
386
    global $publisher_current_page;
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...
387
388
    $formTpl = new XoopsTpl();
389
    //publisher_submit.html
390
391
    // if there is a parameter, and the id exists, retrieve data: we're editing a item
392
393
    if ($itemid != 0) {
394
395
        // Creating the ITEM object
396
        /* @var $itemObj PublisherItem */
397
        $itemObj = $publisher->getItemHandler()->get($itemid);
398
399
        if (!$itemObj) {
400
            $xoops->redirect("item.php", 1, _AM_PUBLISHER_NOITEMSELECTED);
401
        }
402
403
        if ($clone) {
404
            $itemObj->setNew();
405
            $itemObj->setVar('itemid', 0);
406
            $itemObj->setVar('status', _PUBLISHER_STATUS_NOTSET);
407
            $itemObj->setVar('datesub', time());
408
        }
409
410
        switch ($itemObj->getVar('status')) {
411
412
            case _PUBLISHER_STATUS_SUBMITTED:
413
                $page_title = _AM_PUBLISHER_SUBMITTED_TITLE;
414
                $page_info = _AM_PUBLISHER_SUBMITTED_INFO;
415
                break;
416
417
            case _PUBLISHER_STATUS_PUBLISHED:
418
                $page_title = _AM_PUBLISHER_PUBLISHEDEDITING;
419
                $page_info = _AM_PUBLISHER_PUBLISHEDEDITING_INFO;
420
                break;
421
422
            case _PUBLISHER_STATUS_OFFLINE:
423
                $page_title = _AM_PUBLISHER_OFFLINEEDITING;
424
                $page_info = _AM_PUBLISHER_OFFLINEEDITING_INFO;
425
                break;
426
427
            case _PUBLISHER_STATUS_REJECTED:
428
                $page_title = _AM_PUBLISHER_REJECTED_EDIT;
429
                $page_info = _AM_PUBLISHER_REJECTED_EDIT_INFO;
430
                break;
431
432
            case _PUBLISHER_STATUS_NOTSET: // Then it's a clone...
433
                $page_title = _AM_PUBLISHER_ITEM_DUPLICATING;
434
                $page_info = _AM_PUBLISHER_ITEM_DUPLICATING_DSC;
435
                break;
436
437
            case "default":
438
            default:
439
                $page_title = _AM_PUBLISHER_PUBLISHEDEDITING;
440
                $page_info = _AM_PUBLISHER_PUBLISHEDEDITING_INFO;
441
                break;
442
        }
443
444
        echo "<br />\n";
445
        PublisherUtils::openCollapsableBar('edititemtable', 'edititemicon', $page_title, $page_info);
446
447
        if (!$clone) {
448
            echo "<form><div style=\"margin-bottom: 10px;\">";
449
            echo "<input type='button' name='button' onclick=\"location='item.php?op=clone&itemid=" . $itemObj->getVar('itemid') . "'\" value='" . _AM_PUBLISHER_CLONE_ITEM . "'>&nbsp;&nbsp;";
450
            echo "</div></form>";
451
        }
452
    } else {
453
        // there's no parameter, so we're adding an item
454
455
        /* @var $itemObj PublisherItem */
456
        $itemObj = $publisher->getItemHandler()->create();
457
        $itemObj->setVarsFromRequest();
458
459
        $categoryObj = $publisher->getCategoryHandler()->create();
460
        $sel_categoryid = isset($_GET['categoryid']) ? $_GET['categoryid'] : 0;
461
        $categoryObj->setVar('categoryid', $sel_categoryid);
462
463
        PublisherUtils::openCollapsableBar('createitemtable', 'createitemicon', _AM_PUBLISHER_ITEM_CREATING, _AM_PUBLISHER_ITEM_CREATING_DSC);
464
    }
465
466
    /* @var $sform PublisherItemForm */
467
    $sform = $publisher->getForm($itemObj, 'item');
468
    $sform->setTitle(_AM_PUBLISHER_ITEMS);
469
    $sform->assign($formTpl);
470
    $formTpl->display('module:publisher/publisher_submit.tpl');
471
472
    PublisherUtils::closeCollapsableBar('edititemtable', 'edititemicon');
473
474
    PublisherUtils::openCollapsableBar('pagewraptable', 'pagewrapicon', _AM_PUBLISHER_PAGEWRAP, _AM_PUBLISHER_PAGEWRAPDSC);
475
476
    $dir = PublisherUtils::getUploadDir(true, 'content');
477
478 View Code Duplication
    if (!preg_match('/777/i', decoct(fileperms($dir)))) {
479
        echo "<font color='FF0000'><h4>" . _AM_PUBLISHER_PERMERROR . "</h4></font>";
480
    }
481
482
    // Upload File
483
    echo "<form name='form_name2' id='form_name2' action='pw_upload_file.php' method='post' enctype='multipart/form-data'>";
484
    echo "<table cellspacing='1' width='100%' class='outer'>";
485
    echo "<tr><th colspan='2'>" . _AM_PUBLISHER_UPLOAD_FILE . "</th></tr>";
486
    echo "<tr valign='top' align='left'><td class='head'>" . _AM_PUBLISHER_SEARCH_PW . "</td><td class='even'><input type='file' name='fileupload' id='fileupload' size='30' /></td></tr>";
487
    echo "<tr valign='top' align='left'><td class='head'><input type='hidden' name='MAX_FILE_SIZE' id='op' value='500000' /></td><td class='even'><input type='submit' name='submit' value='" . _AM_PUBLISHER_UPLOAD . "' /></td></tr>";
488
    echo "<input type='hidden' name='backto' value='$publisher_current_page'/>";
489
    echo "</table>";
490
    echo "</form>";
491
492
    // Delete File
493
    $form = new Xoops\Form\ThemeForm(_CO_PUBLISHER_DELETEFILE, "form_name", "pw_delete_file.php");
494
495
    $pWrap_select = new Xoops\Form\Select(PublisherUtils::getUploadDir(true, 'content'), "address");
496
    $folder = dir($dir);
497
    if (is_object($folder)) {
498 View Code Duplication
        while ($file = $folder->read()) {
499
            if ($file !== "." && $file !== "..") {
500
                $pWrap_select->addOption($file, $file);
501
            }
502
        }
503
        $folder->close();
504
        $form->addElement($pWrap_select);
505
    }
506
507
    $delfile = "delfile";
508
    $form->addElement(new Xoops\Form\Hidden('op', $delfile));
509
    $submit = new Xoops\Form\Button("", "submit", _AM_PUBLISHER_BUTTON_DELETE, "submit");
510
    $form->addElement($submit);
511
512
    $form->addElement(new Xoops\Form\Hidden('backto', $publisher_current_page));
513
    $form->display();
514
515
    PublisherUtils::closeCollapsableBar('pagewraptable', 'pagewrapicon');
516
}
517