Passed
Branch master (026829)
by Michael
03:14
created

publisher_editFile()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 22
nc 6
nop 3
dl 0
loc 37
rs 9.568
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 You may not change or alter any portion of this comment or credits
6
 of supporting developers from this source code or any supporting source code
7
 which is considered copyrighted (c) material of the original comment or credit authors.
8
9
 This program is distributed in the hope that it will be useful,
10
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 */
13
14
/**
15
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
16
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          The SmartFactory <www.smartfactory.ca>
20
 */
21
22
use Xmf\Request;
23
use XoopsModules\Publisher\{File,
24
    Helper,
25
    Utility
26
};
27
28
require_once __DIR__ . '/admin_header.php';
29
30
$op = Request::getString('op');
31
32
//$itemObj = null;
33
/* -- Available operations -- */
34
switch ($op) {
35
    case 'uploadfile':
36
        Utility::uploadFile(false, true);
37
        exit;
38
    case 'uploadanother':
39
        Utility::uploadFile(true, true);
40
        exit;
41
    case 'mod':
42
        $fileid = Request::getInt('fileid', 0, 'GET');
43
        $itemId = Request::getInt('itemid', 0, 'GET');
44
        if ((0 == $fileid) && (0 == $itemId)) {
45
            redirect_header('<script>javascript:history.go(-1)</script>', 3, _AM_PUBLISHER_NOITEMSELECTED);
46
        }
47
48
        Utility::cpHeader();
49
        require_once $GLOBALS['xoops']->path('class/xoopsformloader.php');
50
51
        Utility::editFile(true, $fileid, $itemId);
52
        break;
53
    case 'modify':
54
        $fileid = Request::getInt('fileid', 0, 'POST');
55
56
        // Creating the file object
57
        if (0 != $fileid) {
58
            $fileObj = $helper->getHandler('File')->get($fileid);
59
        } else {
60
            $fileObj = $helper->getHandler('File')->create();
61
        }
62
63
        // Putting the values in the file object
64
        $fileObj->setVar('name', Request::getString('name', '', 'POST'));
65
        $fileObj->setVar('description', Request::getString('description', '', 'POST'));
66
        $fileObj->setVar('status', Request::getInt('status', 0, 'POST'));
67
68
        // Storing the file
69
        if (!$fileObj->store()) {
70
            redirect_header('item.php?op=mod&itemid=' . $fileObj->itemid() . '#tab_2', 3, _AM_PUBLISHER_FILE_EDITING_ERROR . Utility::formatErrors($fileObj->getErrors()));
71
        }
72
73
        redirect_header('item.php?op=mod&itemid=' . $fileObj->itemid() . '#tab_2', 2, _AM_PUBLISHER_FILE_EDITING_SUCCESS);
74
        break;
75
    case 'del':
76
        $fileid = Request::getInt('fileid', 0, 'POST');
77
        $fileid = Request::getInt('fileid', $fileid, 'GET');
78
79
        $fileObj = $helper->getHandler('File')->get($fileid);
80
81
        $confirm = Request::getInt('confirm', 0, 'POST');
82
        $title   = Request::getString('title', '', 'POST');
83
84
        if ($confirm) {
85
            if (!$helper->getHandler('File')->delete($fileObj)) {
86
                redirect_header('item.php?op=mod&itemid=' . $fileObj->itemid() . '#tab_2', 2, _AM_PUBLISHER_FILE_DELETE_ERROR);
87
            }
88
89
            redirect_header('item.php?op=mod&itemid=' . $fileObj->itemid() . '#tab_2', 2, sprintf(_AM_PUBLISHER_FILEISDELETED, $fileObj->name()));
90
        } else {
91
            // no confirm: show deletion condition
92
            $fileid = Request::getInt('fileid', 0, 'GET');
93
94
            Utility::cpHeader();
95
            xoops_confirm(['op' => 'del', 'fileid' => $fileObj->fileid(), 'confirm' => 1, 'name' => $fileObj->name()], 'file.php', _AM_PUBLISHER_DELETETHISFILE . ' <br>' . $fileObj->name() . ' <br> <br>', _AM_PUBLISHER_DELETE);
96
            xoops_cp_footer();
97
        }
98
99
        exit();
100
    case 'default':
101
    default:
102
        Utility::cpHeader();
103
        //publisher_adminMenu(2, _AM_PUBLISHER_ITEMS);
104
        break;
105
}
106
require_once __DIR__ . '/admin_footer.php';
107