-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.php
188 lines (174 loc) · 7.14 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* xmnews module
*
* @copyright XOOPS Project (https://xoops.org)
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
* @author Mage Gregory (AKA Mage)
*/
use \Xmf\Request;
include_once __DIR__ . '/header.php';
$GLOBALS['xoopsOption']['template_main'] = 'xmnews_action.tpl';
include_once XOOPS_ROOT_PATH . '/header.php';
$xoTheme->addStylesheet(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/assets/css/styles.css', null);
$op = Request::getCmd('op', '');
// Get start pager
$start = Request::getInt('start', 0);
$xoopsTpl->assign('index_module', $helper->getModule()->getVar('name'));
if ($op == 'clone' || $op == 'edit' || $op == 'del' || $op == 'add' || $op == 'loadnews' || $op == 'save') {
switch ($op) {
// Add
case 'add':
// Get Permission to submit
$submitPermissionCat = XmnewsUtility::getPermissionCat('xmnews_submit');
if (empty($submitPermissionCat)){
redirect_header('index.php', 2, _NOPERM);
}
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('category_status', 1));
$criteria->setSort('category_weight ASC, category_name');
$criteria->setStart($start);
$criteria->setLimit($nb_limit);
$criteria->setOrder('ASC');
$criteria->add(new Criteria('category_id', '(' . implode(',', $submitPermissionCat) . ')','IN'));
$category_arr = $categoryHandler->getall($criteria);
$category_count = $categoryHandler->getCount($criteria);
$xoopsTpl->assign('category_count', $category_count);
if ($category_count > 0) {
foreach (array_keys($category_arr) as $i) {
$category_id = $category_arr[$i]->getVar('category_id');
$category['id'] = $category_id;
$category['name'] = $category_arr[$i]->getVar('category_name');
$category['description'] = $category_arr[$i]->getVar('category_description', 'show');
$category_img = $category_arr[$i]->getVar('category_logo');
if ($category_img == ''){
$category['logo'] = '';
} else {
$category['logo'] = $url_logo . $category_img;
}
$color = $category_arr[$i]->getVar('category_color');
if ($color == '#ffffff'){
$category['color'] = false;
} else {
$category['color'] = $color;
}
$xoopsTpl->appendByRef('categories', $category);
unset($category);
}
// Display Page Navigation
if ($category_count > $nb_limit) {
$nav = new XoopsPageNav($category_count, $nb_limit, $start, 'start', 'op=add');
$xoopsTpl->assign('nav_menu', $nav->renderNav(4));
}
} else {
$xoopsTpl->assign('error_message', _MA_XMNEWS_ERROR_NOCATEGORY);
}
break;
// Loadtype
case 'loadnews':
$category_id = Request::getInt('category_id', 0);
if ($category_id == 0) {
$xoopsTpl->assign('error_message', _MA_XMNEWS_ERROR_NOCATEGORY);
} else {
// Get Permission to submit in category
$permHelper->checkPermissionRedirect('xmnews_submit', $category_id, 'action.php?op=add', 2, _NOPERM);
$obj = $newsHandler->create();
$form = $obj->getForm($category_id);
$xoopsTpl->assign('form', $form->render());
}
break;
// Edit
case 'edit':
$news_id = Request::getInt('news_id', 0);
if ($news_id == 0) {
$xoopsTpl->assign('error_message', _MA_XMNEWS_ERROR_NONEWS);
} else {
$obj = $newsHandler->get($news_id);
if (empty($obj)) {
$xoopsTpl->assign('error_message', _MA_XMNEWS_ERROR_NONEWS);
} else {
// Get Permission to edit in category
$permHelper->checkPermissionRedirect('xmnews_editapprove', $obj->getVar('news_cid'), 'index.php', 2, _NOPERM);
$form = $obj->getForm();
$xoopsTpl->assign('form', $form->render());
}
}
break;
// Clone
case 'clone':
$news_id = Request::getInt('news_id', 0);
if ($news_id == 0) {
$xoopsTpl->assign('error_message', _MA_XMNEWS_ERROR_NONEWS);
} else {
$cloneobj = XmnewsUtility::cloneNews($news_id);
// Get Permission to edit in category
$permHelper->checkPermissionRedirect('xmnews_editapprove', $cloneobj->getVar('news_cid'), 'index.php', 2, _NOPERM);
$form = $cloneobj->getForm($cloneobj->getVar('news_cid'), 'action.php', true);
$xoopsTpl->assign('form', $form->render());
}
break;
// Save
case 'save':
$news_cid = Request::getInt('news_cid', 0);
// Get Permission to submit in category
$permHelper->checkPermissionRedirect('xmnews_submit', $news_cid, 'index.php', 2, _NOPERM);
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('index.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
}
$news_id = Request::getInt('news_id', 0);
if ($news_id == 0) {
$obj = $newsHandler->create();
} else {
$obj = $newsHandler->get($news_id);
}
$error_message = $obj->saveNews($newsHandler, 'article.php');
if ($error_message != '') {
$xoopsTpl->assign('error_message', $error_message);
$news_cid = Request::getInt('news_cid', 0);
$form = $obj->getForm($news_cid);
$xoopsTpl->assign('form', $form->render());
}
break;
// del
case 'del':
$news_id = Request::getInt('news_id', 0);
if ($news_id == 0) {
$xoopsTpl->assign('error_message', _MA_XMNEWS_ERROR_NONEWS);
} else {
$surdel = Request::getBool('surdel', false);
$obj = $newsHandler->get($news_id);
// Get Permission to delete in category
$permHelper->checkPermissionRedirect('xmnews_delete', $obj->getVar('news_cid'), 'index.php', 2, _NOPERM);
if ($surdel === true) {
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header('index.php', 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
}
$error_message = $obj->delNews($newsHandler, $news_id, 'index.php');
if ($error_message != ''){
$xoopsTpl->assign('error_message', $error_message);
}
} else {
$news_img = $obj->getVar('news_logo');
if ($news_img == '' || $news_img == 'CAT'){
$img = '';
} else {
$img = '<img src="' . $url_logo . $news_img . '" title="' . $obj->getVar('news_name') . '" style="max-width:100px"><br>';
}
xoops_confirm(['surdel' => true, 'news_id' => $news_id, 'op' => 'del'], $_SERVER['REQUEST_URI'],
sprintf(_MA_XMNEWS_NEWS_SUREDEL, $obj->getVar('news_title')) . '<br>' . $img);
}
}
break;
}
} else {
redirect_header('index.php', 2, _NOPERM);
}
include XOOPS_ROOT_PATH . '/footer.php';