These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 GPL 2.0 |
||
22 | * @package xnewsletter |
||
23 | * @author Goffy ( [email protected] ) |
||
24 | * |
||
25 | * **************************************************************************** |
||
26 | */ |
||
27 | |||
28 | $currentFile = basename(__FILE__); |
||
29 | include_once __DIR__ . '/header.php'; |
||
30 | |||
31 | $uid = (is_object($xoopsUser) && isset($xoopsUser)) ? $xoopsUser->uid() : 0; |
||
32 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : [0 => XOOPS_GROUP_ANONYMOUS]; |
||
33 | |||
34 | $op = XoopsRequest::getString('op', 'list_letters'); |
||
35 | $letter_id = XoopsRequest::getInt('letter_id', 0); |
||
36 | $cat_id = XoopsRequest::getInt('cat_id', 0); |
||
37 | |||
38 | //check the rights of current user first |
||
39 | if (!xnewsletter_userAllowedCreateCat()) redirect_header('index.php', 3, _NOPERM); |
||
40 | |||
41 | $delete_att_1 = XoopsRequest::getString('delete_attachment_1', 'none'); |
||
42 | $delete_att_2 = XoopsRequest::getString('delete_attachment_2', 'none'); |
||
43 | $delete_att_3 = XoopsRequest::getString('delete_attachment_3', 'none'); |
||
44 | $delete_att_4 = XoopsRequest::getString('delete_attachment_4', 'none'); |
||
45 | $delete_att_5 = XoopsRequest::getString('delete_attachment_5', 'none'); |
||
46 | |||
47 | View Code Duplication | if ($delete_att_1 !== 'none') { |
|
0 ignored issues
–
show
|
|||
48 | $op = 'delete_attachment'; |
||
49 | $id_del = 1; |
||
50 | } elseif ($delete_att_2 !== 'none') { |
||
51 | $op = 'delete_attachment'; |
||
52 | $id_del = 2; |
||
53 | } elseif ($delete_att_3 !== 'none') { |
||
54 | $op = 'delete_attachment'; |
||
55 | $id_del = 3; |
||
56 | } elseif ($delete_att_4 !== 'none') { |
||
57 | $op = 'delete_attachment'; |
||
58 | $id_del = 4; |
||
59 | } elseif ($delete_att_5 !== 'none') { |
||
60 | $op = 'delete_attachment'; |
||
61 | $id_del = 5; |
||
62 | } else { |
||
63 | $id_del = 0; |
||
64 | } |
||
65 | |||
66 | switch ($op) { |
||
67 | case 'list_subscrs' : |
||
68 | $xoopsOption['template_main'] = 'xnewsletter_letter_list_subscrs.tpl'; |
||
69 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
70 | |||
71 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
72 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
73 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
74 | |||
75 | // Breadcrumb |
||
76 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
77 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
78 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST_SUBSCR, ''); |
||
79 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
80 | |||
81 | // check right to edit/delete subscription of other persons |
||
82 | $permissionChangeOthersSubscriptions = false; |
||
83 | foreach ($groups as $group) { |
||
84 | if (in_array($group, $xnewsletter->getConfig('xn_groups_change_other')) || XOOPS_GROUP_ADMIN == $group) { |
||
85 | $permissionChangeOthersSubscriptions = true; |
||
86 | break; |
||
87 | } |
||
88 | } |
||
89 | $xoopsTpl->assign('permissionChangeOthersSubscriptions', $permissionChangeOthersSubscriptions); |
||
90 | // get search subscriber form |
||
91 | if ($permissionChangeOthersSubscriptions) { |
||
92 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
93 | $form = new XoopsThemeForm(_AM_XNEWSLETTER_FORMSEARCH_SUBSCR_EXIST, 'form_search', 'subscription.php', 'post', true); |
||
94 | $form->setExtra('enctype="multipart/form-data"'); |
||
95 | $form->addElement(new XoopsFormText(_AM_XNEWSLETTER_SUBSCR_EMAIL, 'subscr_email', 60, 255, '', true)); |
||
96 | $form->addElement(new XoopsFormButton('', 'submit', _AM_XNEWSLETTER_SEARCH, 'submit')); |
||
97 | $xoopsTpl->assign('searchSubscriberForm', $form->render()); |
||
98 | } else { |
||
99 | $xoopsTpl->assign('searchSubscriberForm', ''); |
||
100 | } |
||
101 | // get cat objects |
||
102 | $catCriteria = new CriteriaCompo(); |
||
103 | $catCriteria->setSort('cat_id'); |
||
104 | $catCriteria->setOrder('ASC'); |
||
105 | $catObjs = $xnewsletter->getHandler('cat')->getAll($catCriteria, null, true, true); |
||
106 | // cats table |
||
107 | foreach ($catObjs as $cat_id => $catObj) { |
||
108 | $permissionShowCats[$cat_id] = $gperm_handler->checkRight('newsletter_list_cat', $cat_id, $groups, $xnewsletter->getModule()->mid()); |
||
109 | if ($permissionShowCats[$cat_id] == true) { |
||
110 | $cat_array = $catObj->toArray(); |
||
111 | $catsubscrCriteria = new CriteriaCompo(); |
||
112 | $catsubscrCriteria->add(new Criteria('catsubscr_catid', $cat_id)); |
||
113 | $cat_array['catsubscrCount'] = $xnewsletter->getHandler('catsubscr')->getCount($catsubscrCriteria); |
||
114 | $xoopsTpl->append('cats', $cat_array); |
||
115 | } |
||
116 | } |
||
117 | // get cat_id |
||
118 | $cat_id = XoopsRequest::getInt('cat_id', 0); |
||
119 | $xoopsTpl->assign('cat_id', $cat_id); |
||
120 | if ($cat_id > 0) { |
||
121 | $catObj = $xnewsletter->getHandler('cat')->get($cat_id); |
||
122 | // subscrs table |
||
123 | if ($permissionShowCats[$cat_id] == true) { |
||
124 | $counter = 1; |
||
125 | $sql = 'SELECT `subscr_sex`, `subscr_lastname`, `subscr_firstname`, `subscr_email`, `subscr_id`'; |
||
126 | $sql.= " FROM {$xoopsDB->prefix('xnewsletter_subscr')} INNER JOIN {$xoopsDB->prefix('xnewsletter_catsubscr')} ON `subscr_id` = `catsubscr_subscrid`"; |
||
127 | $sql.= " WHERE (((`catsubscr_catid`)={$cat_id}) AND ((`catsubscr_quited`)=0)) ORDER BY `subscr_lastname`, `subscr_email`;"; |
||
128 | if(!$subscrs = $xoopsDB->query($sql)) die ('MySQL-Error: ' . $xoopsDB->error()); |
||
129 | while ($subscr_array = $xoopsDB->fetchArray($subscrs)) { |
||
130 | $subscr_array['counter'] = ++$counter; |
||
131 | $xoopsTpl->append('subscrs', $subscr_array); |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | break; |
||
136 | |||
137 | case 'delete_attachment' : |
||
138 | //$xoopsOption['template_main'] = 'xnewsletter_letter.tpl'; // IN PROGRESS |
||
139 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
140 | |||
141 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
142 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
143 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
144 | |||
145 | // Breadcrumb |
||
146 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
147 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
148 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
149 | |||
150 | // IN PROGRESS FROM HERE |
||
151 | // get attachment |
||
152 | $attachment_id = XoopsRequest::getString("attachment_{$id_del}", 'none'); |
||
153 | if ($attachment_id === 'none') { |
||
154 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_LETTER_ERROR_INVALID_ATT_ID); |
||
155 | } |
||
156 | $attachmentObj = $xnewsletter->getHandler('attachment')->get($attachment_id); |
||
157 | $attachment_name = $attachmentObj->getVar('attachment_name'); |
||
158 | // delete attachment |
||
159 | if ($xnewsletter->getHandler('attachment')->delete($attachmentObj, true)) { |
||
160 | // delete file |
||
161 | $uploadDir = XOOPS_UPLOAD_PATH . $xnewsletter->getConfig('xn_attachment_path') . $letter_id; |
||
162 | if (file_exists($uploadDir . '/' . $attachment_name)) { |
||
163 | unlink($uploadDir . '/' . $attachment_name); |
||
164 | } |
||
165 | // get letter |
||
166 | $letterObj = $xnewsletter->getHandler('letter')->get($letter_id); |
||
167 | $letterObj->setVar('letter_title', $_REQUEST['letter_title']); |
||
168 | $letterObj->setVar('letter_content', $_REQUEST['letter_content']); |
||
169 | $letterObj->setVar('letter_template', $_REQUEST['letter_template']); |
||
170 | // IN PROGRESS |
||
171 | // IN PROGRESS |
||
172 | // IN PROGRESS |
||
173 | //Form letter_cats |
||
174 | $letter_cats = ''; |
||
175 | //$cat_arr = isset($_REQUEST["letter_cats"]) ? $_REQUEST["letter_cats"] : ""; |
||
176 | $cats_arr = XoopsRequest::getArray('letter_cats', []); |
||
177 | View Code Duplication | if (count($cats_arr) > 0) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
178 | foreach ($cats_arr as $cat) { |
||
179 | $letter_cats .= $cat . '|'; |
||
180 | } |
||
181 | $letter_cats = substr($letter_cats, 0, -1); |
||
182 | } else { |
||
183 | $letter_cats = $cats_arr; |
||
184 | } |
||
185 | //no cat |
||
186 | View Code Duplication | if ($letter_cats == false) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
187 | $form = $letterObj->getForm(); |
||
188 | $content = $form->render(); |
||
189 | $xoopsTpl->assign('content', $content); |
||
190 | break; |
||
191 | } |
||
192 | $letterObj->setVar('letter_cats', $letter_cats); |
||
193 | // IN PROGRESS |
||
194 | // IN PROGRESS |
||
195 | // IN PROGRESS |
||
196 | $letterObj->setVar('letter_account', $_REQUEST['letter_account']); |
||
197 | $letterObj->setVar('letter_email_test', $_REQUEST['letter_email_test']); |
||
198 | // get letter form |
||
199 | $form = $letterObj->getForm(false, true); |
||
200 | $form->display(); |
||
201 | } else { |
||
202 | echo $attachmentObj->getHtmlErrors(); |
||
203 | } |
||
204 | break; |
||
205 | |||
206 | case 'show_preview' : |
||
207 | case 'show_letter_preview' : |
||
208 | $xoopsOption['template_main'] = 'xnewsletter_letter_preview.tpl'; |
||
209 | include XOOPS_ROOT_PATH . '/header.php'; |
||
210 | |||
211 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
212 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
213 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
214 | |||
215 | // Breadcrumb |
||
216 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
217 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
218 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST, XNEWSLETTER_URL . '/letter.php?op=list_letters'); |
||
219 | $breadcrumb->addLink(_MD_XNEWSLETTER_LETTER_PREVIEW, ''); |
||
220 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
221 | |||
222 | // get letter_id |
||
223 | $letter_id = XoopsRequest::getInt('letter_id', 0); |
||
224 | // get letter object |
||
225 | $letterObj = $xnewsletter->getHandler('letter')->get($letter_id); |
||
226 | // subscr data |
||
227 | $xoopsTpl->assign('sex', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW); |
||
228 | $xoopsTpl->assign('salutation', _AM_XNEWSLETTER_SUBSCR_SEX_PREVIEW); // new from v1.3 |
||
229 | $xoopsTpl->assign('firstname', _AM_XNEWSLETTER_SUBSCR_FIRSTNAME_PREVIEW); |
||
230 | $xoopsTpl->assign('lastname', _AM_XNEWSLETTER_SUBSCR_LASTNAME_PREVIEW); |
||
231 | $xoopsTpl->assign('subscr_email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW); |
||
232 | $xoopsTpl->assign('email', _AM_XNEWSLETTER_SUBSCR_EMAIL_PREVIEW); // new from v1.3 |
||
233 | // letter data |
||
234 | $xoopsTpl->assign('title', $letterObj->getVar('letter_title', 'n')); // new from v1.3 |
||
235 | $xoopsTpl->assign('content', $letterObj->getVar('letter_content', 'n')); |
||
236 | // extra data |
||
237 | $xoopsTpl->assign('date', time()); // new from v1.3 |
||
238 | $xoopsTpl->assign('unsubscribe_url', XOOPS_URL . '/modules/xnewsletter/'); |
||
239 | $xoopsTpl->assign('catsubscr_id', '0'); |
||
240 | |||
241 | $letter_array = $letterObj->toArray(); |
||
242 | |||
243 | preg_match('/db:([0-9]*)/', $letterObj->getVar('letter_template'), $matches); |
||
244 | View Code Duplication | if(isset($matches[1]) && ($templateObj = $xnewsletter->getHandler('template')->get((int)$matches[1]))) { |
|
245 | // get template from database |
||
246 | $htmlBody = $xoopsTpl->fetchFromData($templateObj->getVar('template_content', 'n')); |
||
247 | } else { |
||
248 | // get template from filesystem |
||
249 | $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/' . $GLOBALS['xoopsConfig']['language'] . '/templates/'; |
||
250 | if (!is_dir($template_path)) $template_path = XOOPS_ROOT_PATH . '/modules/xnewsletter/language/english/templates/'; |
||
251 | $template = $template_path . $letterObj->getVar('letter_template') . '.tpl'; |
||
252 | $htmlBody = $xoopsTpl->fetch($template); |
||
253 | } |
||
254 | $textBody = xnewsletter_html2text($htmlBody); // new from v1.3 |
||
255 | |||
256 | $letter_array['letter_content_templated'] = $htmlBody; |
||
257 | $letter_array['letter_content_templated_html'] = $htmlBody; |
||
258 | $letter_array['letter_content_templated_text'] = $textBody; // new from v1.3 |
||
259 | $letter_array['letter_created_timestamp'] = formatTimestamp($letterObj->getVar('letter_created'), $xnewsletter->getConfig('dateformat')); |
||
260 | $letter_array['letter_submitter_name'] = XoopsUserUtility::getUnameFromId($letterObj->getVar('letter_submitter')); |
||
261 | $xoopsTpl->assign('letter', $letter_array); |
||
262 | break; |
||
263 | |||
264 | case 'list' : |
||
265 | exit('IN_PROGRESS: use op=list_letters instead of op=list'); |
||
266 | break; |
||
267 | case 'list_letters' : |
||
268 | default : |
||
269 | $xoopsOption['template_main'] = 'xnewsletter_letter_list_letters.tpl'; |
||
270 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
271 | |||
272 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
273 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
274 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
275 | |||
276 | // Breadcrumb |
||
277 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
278 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
279 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST, ''); |
||
280 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
281 | |||
282 | // get letters array |
||
283 | $letterCriteria = new CriteriaCompo(); |
||
284 | $letterCriteria->setSort('letter_id'); |
||
285 | $letterCriteria->setOrder('DESC'); |
||
286 | $letterCount = $xnewsletter->getHandler('letter')->getCount(); |
||
287 | $start = XoopsRequest::getInt('start', 0); |
||
288 | $limit = $xnewsletter->getConfig('adminperpage'); |
||
289 | $letterCriteria->setStart($start); |
||
290 | $letterCriteria->setLimit($limit); |
||
291 | View Code Duplication | if ($letterCount > $limit) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
292 | include_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
293 | $pagenav = new XoopsPageNav($letterCount, $limit, $start, 'start', "op={$op}"); |
||
294 | $pagenav = $pagenav->renderNav(4); |
||
295 | } else { |
||
296 | $pagenav = ''; |
||
297 | } |
||
298 | $xoopsTpl->assign('pagenav', $pagenav); |
||
299 | $letterObjs = $xnewsletter->getHandler('letter')->getAll($letterCriteria, null, true, true); |
||
300 | // letters table |
||
301 | if ($letterCount> 0) { |
||
302 | foreach ($letterObjs as $letter_id => $letterObj) { |
||
303 | $userPermissions = []; |
||
304 | $userPermissions = xnewsletter_getUserPermissionsByLetter($letter_id); |
||
305 | if ($userPermissions['read']) { |
||
306 | $letter_array = $letterObj->toArray(); |
||
307 | $letter_array['letter_created_timestamp'] = formatTimestamp($letterObj->getVar('letter_created'), $xnewsletter->getConfig('dateformat')); |
||
308 | $letter_array['letter_submitter_name'] = XoopsUserUtility::getUnameFromId($letterObj->getVar('letter_submitter')); |
||
309 | // get categories |
||
310 | $catsAvailableCount = 0; |
||
311 | $cats_string = ''; |
||
312 | $cat_ids = explode('|' , $letterObj->getVar('letter_cats')); |
||
313 | unset($letter_array['letter_cats']); // IN PROGRESS |
||
314 | View Code Duplication | foreach ($cat_ids as $cat_id) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
315 | $catObj = $xnewsletter->getHandler('cat')->get($cat_id); |
||
316 | if ($gperm_handler->checkRight('newsletter_read_cat', $catObj->getVar('cat_id'), $groups, $xnewsletter->getModule()->mid())) { |
||
317 | ++$catsAvailableCount; |
||
318 | $letter_array['letter_cats'][] = $catObj->toArray(); |
||
319 | } |
||
320 | unset($catObj); |
||
321 | } |
||
322 | if ($catsAvailableCount > 0) { |
||
323 | $letters_array[] = $letter_array; |
||
324 | } |
||
325 | // count letter attachements |
||
326 | $attachmentCriteria = new CriteriaCompo(); |
||
327 | $attachmentCriteria->add(new Criteria('attachment_letter_id', $letterObj->getVar('letter_id'))); |
||
328 | $letter_array['attachmentCount'] = $xnewsletter->getHandler('attachment')->getCount($attachmentCriteria); |
||
329 | // get protocols |
||
330 | if ($userPermissions['edit']) { |
||
331 | // take last item protocol_subscriber_id=0 from table protocol as actual status |
||
332 | $protocolCriteria = new CriteriaCompo(); |
||
333 | $protocolCriteria->add(new Criteria('protocol_letter_id', $letterObj->getVar('letter_id'))); |
||
334 | //$criteria->add(new Criteria('protocol_subscriber_id', '0')); |
||
335 | $protocolCriteria->setSort('protocol_id'); |
||
336 | $protocolCriteria->setOrder('DESC'); |
||
337 | $protocolCriteria->setLimit(1); |
||
338 | $protocolObjs = $xnewsletter->getHandler('protocol')->getAll($protocolCriteria); |
||
339 | $protocol_status = ''; |
||
340 | $protocol_letter_id = 0; |
||
341 | foreach ($protocolObjs as $protocolObj) { |
||
342 | $letter_array['protocols'][] = [ |
||
343 | 'protocol_status' => $protocolObj->getVar('protocol_status'), |
||
344 | 'protocol_letter_id' => $protocolObj->getVar('protocol_letter_id') |
||
345 | ]; |
||
346 | } |
||
347 | } |
||
348 | |||
349 | $letter_array['userPermissions'] = $userPermissions; |
||
350 | $xoopsTpl->append('letters', $letter_array); |
||
351 | } |
||
352 | } |
||
353 | } else { |
||
354 | // NOP |
||
355 | } |
||
356 | break; |
||
357 | |||
358 | case 'new_letter' : |
||
359 | $xoopsOption['template_main'] = 'xnewsletter_letter.tpl'; // IN PROGRESS |
||
360 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
361 | |||
362 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
363 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
364 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
365 | |||
366 | // Breadcrumb |
||
367 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
368 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
369 | $breadcrumb->addLink(_MD_XNEWSLETTER_LETTER_CREATE, ''); |
||
370 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
371 | |||
372 | // IN PROGRESS FROM HERE |
||
373 | $letterObj = $xnewsletter->getHandler('letter')->create(); |
||
374 | $form = $letterObj->getForm(); |
||
375 | $content = $form->render(); |
||
376 | $xoopsTpl->assign('content', $content); |
||
377 | break; |
||
378 | |||
379 | case 'copy_letter': |
||
380 | case 'clone_letter': |
||
381 | $xoopsOption['template_main'] = 'xnewsletter_letter.tpl'; // IN PROGRESS |
||
382 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
383 | |||
384 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
385 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
386 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
387 | |||
388 | // Breadcrumb |
||
389 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
390 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
391 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST, XNEWSLETTER_URL . '/letter.php?op=list_letters'); |
||
392 | $breadcrumb->addLink(_MD_XNEWSLETTER_LETTER_COPY, ''); |
||
393 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
394 | |||
395 | // IN PROGRESS FROM HERE |
||
396 | |||
397 | $letterObj_old = $xnewsletter->getHandler('letter')->get($letter_id); |
||
398 | $letterObj_new = $xnewsletter->getHandler('letter')->create(); |
||
399 | |||
400 | $letterObj_new->setVar('letter_title', $letterObj_old->getVar('letter_title')); |
||
401 | $letterObj_new->setVar('letter_content', $letterObj_old->getVar('letter_content', 'n')); |
||
402 | $letterObj_new->setVar('letter_template', $letterObj_old->getVar('letter_template')); |
||
403 | $letterObj_new->setVar('letter_cats', $letterObj_old->getVar('letter_cats')); |
||
404 | $letterObj_new->setVar('letter_account', $letterObj_old->getVar('letter_account')); |
||
405 | $letterObj_new->setVar('letter_email_test', $letterObj_old->getVar('letter_email_test')); |
||
406 | unset($letterObj_old); |
||
407 | $action = XOOPS_URL . "/modules/xnewsletter/{$currentFile}?op=copy_letter"; |
||
408 | $form = $letterObj_new->getForm($action); |
||
409 | $content = $form->render(); |
||
410 | $xoopsTpl->assign('content', $content); |
||
411 | break; |
||
412 | |||
413 | case 'save_letter' : |
||
414 | $xoopsOption['template_main'] = 'xnewsletter_letter.tpl'; // IN PROGRESS |
||
415 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
416 | |||
417 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
418 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
419 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
420 | |||
421 | // Breadcrumb |
||
422 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
423 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
424 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
425 | |||
426 | // IN PROGRESS FROM HERE |
||
427 | |||
428 | if ( !$GLOBALS['xoopsSecurity']->check() ) { |
||
429 | redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
430 | } |
||
431 | $letterObj = $xnewsletter->getHandler('letter')->get($letter_id); |
||
432 | |||
433 | //Form letter_title |
||
434 | $letterObj->setVar('letter_title', $_REQUEST['letter_title']); |
||
435 | //Form letter_content |
||
436 | $letterObj->setVar('letter_content', $_REQUEST['letter_content']); |
||
437 | //Form letter_template |
||
438 | $letterObj->setVar('letter_template', $_REQUEST['letter_template']); |
||
439 | //Form letter_cats |
||
440 | $letter_cats = ''; |
||
441 | //$cat_arr = isset($_REQUEST["letter_cats"]) ? $_REQUEST["letter_cats"] : ""; |
||
442 | $cat_arr = XoopsRequest::getArray('letter_cats', []); |
||
443 | View Code Duplication | if (count($cat_arr) > 0) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
444 | foreach ($cat_arr as $cat) { |
||
445 | $letter_cats .= $cat . '|'; |
||
446 | } |
||
447 | $letter_cats = substr($letter_cats, 0, -1); |
||
448 | } else { |
||
449 | $letter_cats = $cat_arr; |
||
450 | } |
||
451 | //no cat |
||
452 | View Code Duplication | if ($letter_cats == false) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
453 | $form = $letterObj->getForm(); |
||
454 | $content = $form->render(); |
||
455 | $xoopsTpl->assign('content', $content); |
||
456 | break; |
||
457 | } |
||
458 | |||
459 | $letterObj->setVar('letter_cats', $letter_cats); |
||
460 | |||
461 | // Form letter_account |
||
462 | $letterObj->setVar('letter_account', $_REQUEST['letter_account']); |
||
463 | // Form letter_email_test |
||
464 | $letterObj->setVar('letter_email_test', $_REQUEST['letter_email_test']); |
||
465 | // Form letter_submitter |
||
466 | $letterObj->setVar('letter_submitter', XoopsRequest::getInt('letter_submitter', 0)); |
||
467 | // Form letter_created |
||
468 | $letterObj->setVar('letter_created', XoopsRequest::getInt('letter_created', 0)); |
||
469 | if ($xnewsletter->getHandler('letter')->insert($letterObj)) { |
||
470 | $letter_id = $letterObj->getVar('letter_id'); |
||
471 | |||
472 | //upload attachments |
||
473 | $uploaded_files = []; |
||
474 | include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
475 | $uploaddir = XOOPS_UPLOAD_PATH . $xnewsletter->getConfig('xn_attachment_path') . $letter_id . '/'; |
||
476 | View Code Duplication | if (!is_dir($uploaddir)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
477 | $indexFile = XOOPS_UPLOAD_PATH . '/index.html'; |
||
478 | mkdir($uploaddir, 0777); |
||
479 | chmod($uploaddir, 0777); |
||
480 | copy($indexFile, $uploaddir . 'index.html'); |
||
481 | } |
||
482 | $uploader = new XoopsMediaUploader($uploaddir, $xnewsletter->getConfig('xn_mimetypes'), $xnewsletter->getConfig('xn_maxsize'), null, null); |
||
483 | for ($upl = 0 ;$upl < 5; ++$upl) { |
||
484 | View Code Duplication | if ($uploader->fetchMedia($_POST['xoops_upload_file'][$upl])) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
485 | //$uploader->setPrefix("xn_") ; keep original name |
||
486 | $uploader->fetchMedia($_POST['xoops_upload_file'][$upl]); |
||
487 | if (!$uploader->upload()) { |
||
488 | $errors = $uploader->getErrors(); |
||
489 | redirect_header('javascript:history.go(-1)', 3, $errors); |
||
490 | } else { |
||
491 | $uploaded_files[] = ['name' => $uploader->getSavedFileName(), 'origname' => $uploader->getMediaType()]; |
||
492 | } |
||
493 | } |
||
494 | } |
||
495 | |||
496 | // create items in attachments |
||
497 | View Code Duplication | foreach ($uploaded_files as $file) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
498 | $attachmentObj = $xnewsletter->getHandler('attachment')->create(); |
||
499 | //Form attachment_letter_id |
||
500 | $attachmentObj->setVar('attachment_letter_id', $letter_id); |
||
501 | //Form attachment_name |
||
502 | $attachmentObj->setVar('attachment_name', $file['name']); |
||
503 | //Form attachment_type |
||
504 | $attachmentObj->setVar('attachment_type', $file['origname']); |
||
505 | //Form attachment_submitter |
||
506 | $attachmentObj->setVar('attachment_submitter', $xoopsUser->uid()); |
||
507 | //Form attachment_created |
||
508 | $attachmentObj->setVar('attachment_created', time()); |
||
509 | $xnewsletter->getHandler('attachment')->insert($attachmentObj); |
||
510 | } |
||
511 | //create item in protocol |
||
512 | $protocolObj = $xnewsletter->getHandler('protocol')->create(); |
||
513 | $protocolObj->setVar('protocol_letter_id', $letter_id); |
||
514 | $protocolObj->setVar('protocol_subscriber_id', '0'); |
||
515 | $protocolObj->setVar('protocol_success', '1'); |
||
516 | $action = ''; |
||
517 | //$action = isset($_REQUEST["letter_action"]) ? $_REQUEST["letter_action"] : 0; |
||
518 | $action = XoopsRequest::getInt('letter_action', 0); |
||
519 | switch ($action) { |
||
520 | case _AM_XNEWSLETTER_LETTER_ACTION_VAL_PREVIEW : |
||
521 | $url = "{$currentFile}?op=show_preview&letter_id={$letter_id}"; |
||
522 | break; |
||
523 | case _AM_XNEWSLETTER_LETTER_ACTION_VAL_SEND : |
||
524 | $url = "sendletter.php?op=send_letter&letter_id={$letter_id}"; |
||
525 | break; |
||
526 | case _AM_XNEWSLETTER_LETTER_ACTION_VAL_SENDTEST : |
||
527 | $url = "sendletter.php?op=send_test&letter_id={$letter_id}"; |
||
528 | break; |
||
529 | default: |
||
530 | $url = "{$currentFile}?op=list_letters"; |
||
531 | break; |
||
532 | } |
||
533 | $protocolObj->setVar('protocol_status', _AM_XNEWSLETTER_LETTER_ACTION_SAVED); |
||
534 | $protocolObj->setVar('protocol_submitter', $xoopsUser->uid()); |
||
535 | $protocolObj->setVar('protocol_created', time()); |
||
536 | |||
537 | if ($xnewsletter->getHandler('protocol')->insert($protocolObj)) { |
||
538 | // create protocol is ok |
||
539 | redirect_header($url, 3, _AM_XNEWSLETTER_FORMOK); |
||
540 | } |
||
541 | } else { |
||
542 | echo 'Error create protocol: ' . $protocolObj->getHtmlErrors(); |
||
543 | } |
||
544 | break; |
||
545 | |||
546 | case 'edit_letter' : |
||
547 | $xoopsOption['template_main'] = 'xnewsletter_letter.tpl'; // IN PROGRESS |
||
548 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
549 | |||
550 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
551 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
552 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
553 | |||
554 | // Breadcrumb |
||
555 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
556 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
557 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST, XNEWSLETTER_URL . '/letter.php?op=list_letters'); |
||
558 | $breadcrumb->addLink(_MD_XNEWSLETTER_LETTER_EDIT, ''); |
||
559 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
560 | |||
561 | // IN PROGRESS FROM HERE |
||
562 | |||
563 | $letterObj = $xnewsletter->getHandler('letter')->get($letter_id); |
||
564 | $form = $letterObj->getForm(); |
||
565 | $content = $form->render(); |
||
566 | $xoopsTpl->assign('content', $content); |
||
567 | break; |
||
568 | |||
569 | case 'delete_letter': |
||
570 | $xoopsOption['template_main'] = 'xnewsletter_letter.tpl'; // IN PROGRESS |
||
571 | include_once XOOPS_ROOT_PATH . '/header.php'; |
||
572 | |||
573 | $xoTheme->addStylesheet(XNEWSLETTER_URL . '/assets/css/module.css'); |
||
574 | $xoTheme->addMeta('meta', 'keywords', $xnewsletter->getConfig('keywords')); // keywords only for index page |
||
575 | $xoTheme->addMeta('meta', 'description', strip_tags(_MA_XNEWSLETTER_DESC)); // description |
||
576 | |||
577 | // Breadcrumb |
||
578 | $breadcrumb = new XnewsletterBreadcrumb(); |
||
579 | $breadcrumb->addLink($xnewsletter->getModule()->getVar('name'), XNEWSLETTER_URL); |
||
580 | $breadcrumb->addLink(_MD_XNEWSLETTER_LIST, XNEWSLETTER_URL . '/letter.php?op=list_letters'); |
||
581 | $breadcrumb->addLink(_MD_XNEWSLETTER_LETTER_DELETE, ''); |
||
582 | $xoopsTpl->assign('xnewsletter_breadcrumb', $breadcrumb->render()); |
||
583 | |||
584 | // IN PROGRESS FROM HERE |
||
585 | |||
586 | $letterObj = $xnewsletter->getHandler('letter')->get($letter_id); |
||
587 | if (isset($_REQUEST['ok']) && $_REQUEST['ok'] == 1) { |
||
588 | if ( !$GLOBALS['xoopsSecurity']->check() ) { |
||
589 | redirect_header($currentFile, 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
590 | } |
||
591 | |||
592 | if ($xnewsletter->getHandler('letter')->delete($letterObj)) { |
||
593 | // delete protocol |
||
594 | $sql = "DELETE FROM `{$xoopsDB->prefix('xnewsletter_protocol')}`"; |
||
595 | $sql.= " WHERE `protocol_letter_id`={$letter_id}"; |
||
596 | if(!$result = $xoopsDB->query($sql)) die('MySQL-Error: ' . $xoopsDB->error()); |
||
597 | |||
598 | // delete attachments |
||
599 | $attachmentCriteria = new CriteriaCompo(); |
||
600 | $attachmentCriteria->add(new Criteria('attachment_letter_id', $letter_id)); |
||
601 | $attachmentObjs = $xnewsletter->getHandler('attachment')->getAll($attachmentCriteria); |
||
602 | View Code Duplication | foreach (array_keys($attachmentObjs) as $attachment_id) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
603 | $attachmentObj = $xnewsletter->getHandler('attachment')->get($attachment_id); |
||
604 | $attachment_name = $attachmentObj->getVar('attachment_name'); |
||
605 | $xnewsletter->getHandler('attachment')->delete($attachmentObj, true); |
||
606 | // delete file |
||
607 | $uploaddir = XOOPS_UPLOAD_PATH . $xnewsletter->getConfig('xn_attachment_path') . $letter_id . '/'; |
||
608 | unlink($uploaddir . $attachment_name); |
||
609 | } |
||
610 | redirect_header($currentFile, 3, _AM_XNEWSLETTER_FORMDELOK); |
||
611 | } else { |
||
612 | echo $letterObj->getHtmlErrors(); |
||
613 | } |
||
614 | View Code Duplication | } else { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
615 | xoops_confirm(['ok' => 1, 'letter_id' => $letter_id, 'op' => 'delete_letter'], $_SERVER['REQUEST_URI'], sprintf(_AM_XNEWSLETTER_FORMSUREDEL, $letterObj->getVar('letter_title'))); |
||
616 | } |
||
617 | break; |
||
618 | } |
||
619 | |||
620 | include __DIR__ . '/footer.php'; |
||
621 |
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.