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
|
|
|
/** |
13
|
|
|
* userlog module |
14
|
|
|
* |
15
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
17
|
|
|
* @package userlog admin |
18
|
|
|
* @since 1 |
19
|
|
|
* @author irmtfan ([email protected]) |
20
|
|
|
* @author XOOPS Project <www.xoops.org> <www.xoops.ir> |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use Xmf\Request; |
24
|
|
|
|
25
|
|
|
require_once __DIR__ . '/admin_header.php'; |
26
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
27
|
|
|
xoops_cp_header(); |
28
|
|
|
$userlog = Userlog::getInstance(); |
29
|
|
|
$loglogObj = UserlogLog::getInstance(); |
30
|
|
|
|
31
|
|
|
$adminObject = \Xmf\Module\Admin::getInstance(); |
32
|
|
|
|
33
|
|
|
// Where do we start ? |
34
|
|
|
$opentry = Request::getString('op', ''); |
35
|
|
|
$file = Request::getArray('file', !empty($opentry) ? '' : $userlog->getConfig('file')); |
36
|
|
|
$filename = Request::getString('filename', ''); |
37
|
|
|
$confirm = Request::getString('confirm', 0, 'post'); |
38
|
|
|
$file = $loglogObj->parseFiles($file); |
39
|
|
|
$totalFiles = count($file); |
40
|
|
|
if (!empty($opentry) && (0 == $confirm || 0 == $totalFiles)) { |
41
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, '')); |
42
|
|
|
} |
43
|
|
|
switch ($opentry) { |
44
|
|
View Code Duplication |
case 'del': |
|
|
|
|
45
|
|
|
if ($deleteFiles = $loglogObj->deleteFiles($file)) { |
46
|
|
|
$msgDel = sprintf(_AM_USERLOG_FILE_DELETE_SUCCESS, $deleteFiles) . "<br\>" . implode("<br\>", $loglogObj->getErrors()); |
47
|
|
|
redirect_header('file.php', 5, $msgDel); |
48
|
|
|
} |
49
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, implode("<br\>", $loglogObj->getErrors()))); |
50
|
|
|
break; |
51
|
|
View Code Duplication |
case 'rename': |
|
|
|
|
52
|
|
|
// only one file. 0 file or more than one file => error |
53
|
|
|
if (1 != $totalFiles) { |
54
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, _AM_USERLOG_FILE_SELECT_ONE)); |
55
|
|
|
} |
56
|
|
|
if ($newFile = $loglogObj->renameFile($file[0], $filename)) { |
57
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_FILE_RENAME_SUCCESS, $file[0], $newFile)); |
58
|
|
|
} |
59
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, implode("<br\>", $loglogObj->getErrors()))); |
60
|
|
|
break; |
61
|
|
View Code Duplication |
case 'copy': |
|
|
|
|
62
|
|
|
// only one file. 0 file or more than one file => error |
63
|
|
|
if (1 != $totalFiles) { |
64
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, _AM_USERLOG_FILE_SELECT_ONE)); |
65
|
|
|
} |
66
|
|
|
if ($newFile = $loglogObj->copyFile($file[0], $filename)) { |
67
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_FILE_COPY_SUCCESS, $file[0], $newFile)); |
68
|
|
|
} |
69
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, implode("<br\>", $loglogObj->getErrors()))); |
70
|
|
|
break; |
71
|
|
|
case 'merge': |
72
|
|
|
if ($mergeFile = $loglogObj->mergeFiles($file, $filename)) { |
73
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_FILE_MERGE_SUCCESS, $totalFiles, $mergeFile)); |
74
|
|
|
} |
75
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, implode("<br\>", $loglogObj->getErrors()))); |
76
|
|
|
break; |
77
|
|
View Code Duplication |
case 'zip': |
|
|
|
|
78
|
|
|
if ($zipFile = $loglogObj->zipFiles($file, $filename)) { |
79
|
|
|
$msgZip = sprintf(_AM_USERLOG_FILE_ZIP_SUCCESS, $totalFiles, $zipFile) . "<br\>" . implode("<br\>", $loglogObj->getErrors()); |
80
|
|
|
redirect_header('file.php', 5, $msgZip); |
81
|
|
|
} |
82
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, implode("<br\>", $loglogObj->getErrors()))); |
83
|
|
|
break; |
84
|
|
|
case 'export-csv': |
85
|
|
|
$logsetObj = UserlogSetting::getInstance(); |
86
|
|
|
$headers = $logsetObj->getOptions('', 'title'); |
87
|
|
|
unset($headers['store_db'], $headers['store_file'], $headers['views']); |
88
|
|
|
if ($csvFile = $loglogObj->exportFilesToCsv($file, $headers, $filename, ';')) { |
89
|
|
|
$msgCsv = sprintf(_AM_USERLOG_FILE_EXOPORT_SUCCESS, $totalFiles, $csvFile); |
90
|
|
|
redirect_header('file.php', 5, $msgCsv); |
91
|
|
|
} |
92
|
|
|
redirect_header('file.php', 5, sprintf(_AM_USERLOG_ERROR, implode("<br\>", $loglogObj->getErrors()))); |
93
|
|
|
break; |
94
|
|
|
} |
95
|
|
|
$form = new XoopsThemeForm(_AM_USERLOG_ADMENU_FILE, 'filemanager', 'file.php', 'post', true); |
96
|
|
|
$fileEl = $loglogObj->buildFileSelectEle($file, true, 10);// multiselect = true, size=10 |
97
|
|
|
$form->addElement($fileEl); |
98
|
|
|
$actionEl = new XoopsFormSelect(_AM_USERLOG_FILE_ACTION, 'op', $opentry); |
99
|
|
|
$actions = [ |
100
|
|
|
'zip' => _AM_USERLOG_FILE_ZIP, |
101
|
|
|
'del' => _DELETE, |
102
|
|
|
'rename' => _AM_USERLOG_FILE_RENAME, |
103
|
|
|
'copy' => _AM_USERLOG_FILE_COPY, |
104
|
|
|
'merge' => _AM_USERLOG_FILE_MERGE, |
105
|
|
|
'export-csv' => _AM_USERLOG_FILE_EXPORT_CSV |
106
|
|
|
]; |
107
|
|
|
$actionEl->addOptionArray($actions); |
108
|
|
|
$actionEl->setExtra("onchange=\"var el = document.forms.filemanager.filename.parentElement.parentElement; el.className = ''; if (this.value == 'del') { el.className = 'hidden'}\""); |
109
|
|
|
$form->addElement($actionEl); |
110
|
|
|
$filenameEl = new XoopsFormText(_AM_USERLOG_FILE_FILENAME, 'filename', 50, 255, ''); |
111
|
|
|
$filenameEl->setDescription(_AM_USERLOG_FILE_FILENAME_DSC); |
112
|
|
|
$form->addElement($filenameEl); |
113
|
|
|
$submitEl = new XoopsFormButton(_SUBMIT, 'submitfilemanager', _SUBMIT, 'submit'); |
114
|
|
|
$form->addElement($submitEl); |
115
|
|
|
$confirmEl = new XoopsFormHidden('confirm', 0); |
116
|
|
|
$confirmEl->customValidationCode[] = "if (confirm('" . _AM_USERLOG_FILE_CONFIRM . " ' + myform.op.options[myform.op.selectedIndex].innerHTML + '\\n " . _AM_USERLOG_FILE . ": ' + myform.file.value)) {myform.confirm.value = 1;} else {return false;};"; |
117
|
|
|
$form->addElement($confirmEl); |
118
|
|
|
$GLOBALS['xoopsTpl']->assign('form', $form->render()); |
119
|
|
|
$GLOBALS['xoopsTpl']->assign('logo', $adminObject->displayNavigation(basename(__FILE__))); |
120
|
|
|
// template |
121
|
|
|
$template_main = USERLOG_DIRNAME . '_admin_file.tpl'; |
122
|
|
|
if (!empty($template_main)) { |
123
|
|
|
$GLOBALS['xoopsTpl']->display("db:{$template_main}"); |
124
|
|
|
} |
125
|
|
|
xoops_cp_footer(); |
126
|
|
|
|
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.