1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* **************************************************************************** |
4
|
|
|
* - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
5
|
|
|
* **************************************************************************** |
6
|
|
|
* XNEWSLETTER - MODULE FOR XOOPS |
7
|
|
|
* Copyright (c) 2007 - 2012 |
8
|
|
|
* Goffy ( wedega.com ) |
9
|
|
|
* |
10
|
|
|
* You may not change or alter any portion of this comment or credits |
11
|
|
|
* of supporting developers from this source code or any supporting |
12
|
|
|
* source code which is considered copyrighted (c) material of the |
13
|
|
|
* original comment or credit authors. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU General Public License for more details. |
19
|
|
|
* --------------------------------------------------------------------------- |
20
|
|
|
* @copyright Goffy ( wedega.com ) |
21
|
|
|
* @license GNU General Public License 2.0 |
22
|
|
|
* @package xnewsletter |
23
|
|
|
* @author Goffy ( [email protected] ) |
24
|
|
|
* |
25
|
|
|
* **************************************************************************** |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
use Xmf\Request; |
29
|
|
|
|
30
|
|
|
$currentFile = basename(__FILE__); |
31
|
|
|
require_once __DIR__ . '/admin_header.php'; |
32
|
|
|
xoops_cp_header(); |
33
|
|
|
|
34
|
|
|
// set template |
35
|
|
|
$templateMain = 'xnewsletter_admin_attachments.tpl'; |
36
|
|
|
|
37
|
|
|
// We recovered the value of the argument op in the URL$ |
38
|
|
|
$op = Request::getString('op', 'list'); |
39
|
|
|
$attachment_id = Request::getInt('attachment_id', 0); |
40
|
|
|
|
41
|
|
|
$GLOBALS['xoopsTpl']->assign('xnewsletter_url', XNEWSLETTER_URL); |
42
|
|
|
$GLOBALS['xoopsTpl']->assign('xnewsletter_icons_url', XNEWSLETTER_ICONS_URL); |
43
|
|
|
|
44
|
|
|
switch ($op) { |
45
|
|
|
case 'list': |
46
|
|
|
default: |
47
|
|
|
$adminObject->displayNavigation($currentFile); |
48
|
|
|
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->renderButton('left')); |
49
|
|
|
|
50
|
|
|
$limit = $helper->getConfig('adminperpage'); |
51
|
|
|
$attachmentCriteria = new \CriteriaCompo(); |
52
|
|
|
$attachmentCriteria->setSort('attachment_letter_id DESC, attachment_id'); |
53
|
|
|
$attachmentCriteria->setOrder('DESC'); |
54
|
|
|
$attachmentCount = $helper->getHandler('Attachment')->getCount(); |
55
|
|
|
$start = Request::getInt('start', 0); |
56
|
|
|
$attachmentCriteria->setStart($start); |
57
|
|
|
$attachmentCriteria->setLimit($limit); |
58
|
|
|
$attachmentsAll = $helper->getHandler('Attachment')->getAll($attachmentCriteria); |
59
|
|
View Code Duplication |
if ($attachmentCount > $limit) { |
60
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
61
|
|
|
$pagenav = new \XoopsPageNav($attachmentCount, $limit, $start, 'start', 'op=list'); |
62
|
|
|
$GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav(4)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($attachmentCount > 0) { |
66
|
|
|
$GLOBALS['xoopsTpl']->assign('attachmentCount', $attachmentCount); |
67
|
|
|
$class = 'odd'; |
68
|
|
|
foreach ($attachmentsAll as $attachment_id => $attachmentObj) { |
69
|
|
|
$attachment = $attachmentObj->getValuesAttachment(); |
70
|
|
|
$letterObj = $helper->getHandler('Letter')->get($attachmentObj->getVar('attachment_letter_id')); |
71
|
|
|
$attachment['letter_title'] = $letterObj->getVar('letter_title'); |
72
|
|
|
|
73
|
|
|
$attachment['attsize'] = xnewsletter_bytesToSize1024($attachmentObj->getVar('attachment_size')); |
74
|
|
|
$GLOBALS['xoopsTpl']->append('attachments_list', $attachment); |
75
|
|
|
unset($attachment); |
76
|
|
|
} |
77
|
|
|
} else { |
78
|
|
|
$GLOBALS['xoopsTpl']->assign('error', _AM_XNEWSLETTER_THEREARENT_ATTACHMENT); |
79
|
|
|
} |
80
|
|
|
break; |
81
|
|
|
case 'edit_attachment': |
82
|
|
|
$adminObject->displayNavigation($currentFile); |
83
|
|
|
$adminObject->addItemButton(_AM_XNEWSLETTER_ATTACHMENTLIST, '?op=list', 'list'); |
84
|
|
|
$GLOBALS['xoopsTpl']->assign('buttons', $adminObject->renderButton('left')); |
85
|
|
|
|
86
|
|
|
$attachmentObj = $helper->getHandler('Attachment')->get($attachment_id); |
87
|
|
|
$form = $attachmentObj->getForm(); |
88
|
|
|
$GLOBALS['xoopsTpl']->assign('form', $form->render()); |
89
|
|
|
break; |
90
|
|
|
case 'save_attachment': |
91
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
92
|
|
|
redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$attachmentObj = $helper->getHandler('Attachment')->get($attachment_id); |
96
|
|
|
$attachmentObj->setVar('attachment_mode', Request::getInt('attachment_mode', _XNEWSLETTER_ATTACHMENTS_MODE_ASATTACHMENT)); |
97
|
|
|
|
98
|
|
|
if ($helper->getHandler('Attachment')->insert($attachmentObj)) { |
99
|
|
|
redirect_header('?op=list', 3, _AM_XNEWSLETTER_FORMOK); |
100
|
|
|
} else { |
101
|
|
|
$GLOBALS['xoopsTpl']->assign('error', $attachmentObj->getHtmlErrors()); |
102
|
|
|
$form = $attachmentObj->getForm(); |
103
|
|
|
$GLOBALS['xoopsTpl']->assign('form', $form->render()); |
104
|
|
|
} |
105
|
|
|
break; |
106
|
|
View Code Duplication |
case 'delete_attachment': |
|
|
|
|
107
|
|
|
$attachmentObj = $helper->getHandler('Attachment')->get($attachment_id); |
108
|
|
|
if (true === Request::getBool('ok', false, 'POST')) { |
109
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
110
|
|
|
redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
111
|
|
|
} |
112
|
|
|
if ($helper->getHandler('Attachment')->delete($attachmentObj)) { |
113
|
|
|
redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELOK); |
114
|
|
|
} else { |
115
|
|
|
$GLOBALS['xoopsTpl']->assign('error', $attachmentObj->getHtmlErrors()); |
116
|
|
|
} |
117
|
|
|
} else { |
118
|
|
|
xoops_confirm(['ok' => true, 'attachment_id' => $attachment_id, 'op' => 'delete_attachment'], $_SERVER['REQUEST_URI'], sprintf(_AM_XNEWSLETTER_FORMSUREDEL, $attachmentObj->getVar('attachment_name'))); |
119
|
|
|
} |
120
|
|
|
break; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
124
|
|
|
|
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.