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
|
|
|
* Alumni module for Xoops |
14
|
|
|
* |
15
|
|
|
* @copyright XOOPS Project https://xoops.org/ |
16
|
|
|
* @license GPL 2.0 or later |
17
|
|
|
* @package alumni |
18
|
|
|
* @since 2.6.x |
19
|
|
|
* @author John Mordo (jlm69) |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use Xoops\Core\Request; |
23
|
|
|
|
24
|
|
|
include __DIR__ . '/admin_header.php'; |
25
|
|
|
$xoops = Xoops::getInstance(); |
26
|
|
|
$xoops->header(); |
27
|
|
|
|
28
|
|
|
$op = Request::getCmd('op', 'list'); |
29
|
|
|
$categoriesHandler = $xoops->getModuleHandler('category', 'alumni'); |
30
|
|
|
switch ($op) { |
31
|
|
|
case 'list': |
32
|
|
|
default: |
33
|
|
|
$categoriesHandler = $xoops->getModuleHandler('category', 'alumni'); |
34
|
|
|
$adminObject = new \Xoops\Module\Admin(); |
35
|
|
|
echo $adminObject->displayNavigation('category.php'); |
36
|
|
|
$adminObject->addItemButton(AlumniLocale::ADD_CAT, 'category.php?op=new_category', 'add'); |
37
|
|
|
echo $adminObject->renderButton('left', ''); |
38
|
|
|
|
39
|
|
|
$limit = Request::getInt('limit', 10); |
40
|
|
|
$start = Request::getInt('start', 0); |
41
|
|
|
$order = $xoops->getModuleConfig('alumni_csortorder'); |
42
|
|
|
$catCriteria = new CriteriaCompo(); |
43
|
|
|
$catCriteria->setSort('cid'); |
44
|
|
|
$catCriteria->setOrder($order); |
45
|
|
|
$catCriteria->setStart($start); |
46
|
|
|
$catCriteria->setLimit($limit); |
47
|
|
|
$numrows = $categoriesHandler->getCount(); |
48
|
|
|
$categoryArray = $categoriesHandler->getAll($catCriteria); |
49
|
|
|
|
50
|
|
|
//Function that allows display child categories |
51
|
|
|
/** |
52
|
|
|
* @param int $cid |
53
|
|
|
* @param $categoryArray |
54
|
|
|
* @param string $prefix |
55
|
|
|
* @param string $order |
56
|
|
|
* @param $class |
57
|
|
|
*/ |
58
|
|
|
function alumniCategoryDisplayChildren($cid = 0, $categoryArray, $prefix = '', $order = '', &$class) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$xoops = Xoops::getInstance(); |
61
|
|
|
|
62
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
63
|
|
|
$prefix = $prefix . '<img src=\'' . XOOPS_URL . "/modules/{$moduleDirName}/assets/images/arrow.gif'>"; |
64
|
|
|
foreach (array_keys($categoryArray) as $i) { |
65
|
|
|
$cid = $categoryArray[$i]->getVar('cid'); |
66
|
|
|
$pid = $categoryArray[$i]->getVar('pid'); |
|
|
|
|
67
|
|
|
$title = $categoryArray[$i]->getVar('title'); |
|
|
|
|
68
|
|
|
$img = $categoryArray[$i]->getVar('img'); |
|
|
|
|
69
|
|
|
$order = $categoryArray[$i]->getVar('ordre'); |
70
|
|
|
|
71
|
|
|
echo '<tr class="' . $class . '">'; |
72
|
|
|
echo '<td align="left">' . $prefix . ' ' . $categoryArray[$i]->getVar('title') . '</td>'; |
73
|
|
|
echo '<td align="center"><img src="' . XOOPS_URL . "/modules/{$moduleDirName}/assets/images/cat/" . $categoryArray[$i]->getVar('img') . '" height="16px" title="img" alt="img"></td>'; |
74
|
|
|
echo '<td align="center">' . $categoryArray[$i]->getVar('ordre') . '</td>'; |
75
|
|
|
echo "<td align='center' width='10%'> |
76
|
|
|
<a href='category.php?op=edit_category&cid=" . $categoryArray[$i]->getVar('cid') . "'><img src='../images/edit.gif' alt='" . XoopsLocale::A_EDIT . "' title='" . XoopsLocale::A_EDIT . "'></a> |
77
|
|
|
<a href='category.php?op=delete_category&cid=" . $categoryArray[$i]->getVar('cid') . "'><img src='../images/dele.gif' alt='" . XoopsLocale::A_DELETE . "' title='" . XoopsLocale::A_DELETE . "'></a></td></tr>"; |
78
|
|
|
$class = ('even' === $class) ? 'odd' : 'even'; |
79
|
|
|
|
80
|
|
|
$categoriesHandler = $xoops->getModuleHandler('category', 'alumni'); |
81
|
|
|
$criteria2 = new CriteriaCompo(); |
82
|
|
|
$criteria2->add(new Criteria('pid', $categoryArray[$i]->getVar('cid'))); |
83
|
|
|
$criteria2->setSort('title'); |
84
|
|
|
$criteria2->setOrder('ASC'); |
85
|
|
|
$cat_pid = $categoriesHandler->getAll($criteria2); |
|
|
|
|
86
|
|
|
$num_pid = $categoriesHandler->getCount(); |
|
|
|
|
87
|
|
|
if (0 != $num_pid) { |
|
|
|
|
88
|
|
|
alumniCategoryDisplayChildren($cid, $cat_pid, $prefix, $order, $class); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ($numrows > 0) { |
94
|
|
|
if ($numrows > 1) { |
95
|
|
|
if ($numrows > $limit) { |
96
|
|
|
$cat_url[] = 'limit=' . $limit; |
|
|
|
|
97
|
|
|
$cat_url[] = 'orderby=' . $order; |
|
|
|
|
98
|
|
|
if (isset($cat_url)) { |
|
|
|
|
99
|
|
|
$args = implode('&', $cat_url); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
$nav = new XoopsPageNav($numrows, $limit, $start, 'start', $args); |
102
|
|
|
echo '' . $nav->renderNav(5, '', 'center') . ''; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
echo "<table width='100%' cellspacing='1' class='outer'> |
107
|
|
|
<tr> |
108
|
|
|
<th align=\"center\">" . AlumniLocale::CATEGORY_TITLE . '</th> |
109
|
|
|
<th align="center">' . AlumniLocale::IMGCAT . '</th> |
110
|
|
|
<th align="center">' . XoopsLocale::ORDER . "</th> |
111
|
|
|
<th align='center' width='10%'>" . XoopsLocale::ACTIONS . '</th></tr>'; |
112
|
|
|
$class = 'odd'; |
113
|
|
|
$prefix = "<img src='" . XOOPS_URL . "/modules/{$moduleDirName}/assets/images/arrow.gif'>"; |
114
|
|
|
|
115
|
|
|
$categoryArray2 = $categoriesHandler->getAll($catCriteria); |
116
|
|
|
|
117
|
|
|
foreach (array_keys($categoryArray2) as $i) { |
118
|
|
|
if (0 == $categoryArray2[$i]->getVar('pid')) { |
119
|
|
|
$cid = $categoryArray2[$i]->getVar('cid'); |
120
|
|
|
$img = $categoryArray2[$i]->getVar('img'); |
121
|
|
|
$title = $categoryArray2[$i]->getVar('title'); |
122
|
|
|
$order = $categoryArray2[$i]->getVar('ordre'); |
123
|
|
|
echo "<tr class='" . $class . "'>"; |
124
|
|
|
echo '<td align="left">' . $prefix . ' ' . $categoryArray2[$i]->getVar('title') . '</td>'; |
125
|
|
|
echo '<td align="center"><img src="' . XOOPS_URL . "/modules/{$moduleDirName}/assets/images/cat/" . $categoryArray2[$i]->getVar('img') . '" height="16px" title="img" alt="img"></td>'; |
126
|
|
|
echo '<td align="center">' . $categoryArray2[$i]->getVar('ordre') . '</td>'; |
127
|
|
|
echo "<td align='center' width='10%'> |
128
|
|
|
<a href='category.php?op=edit_category&cid=" . $categoryArray2[$i]->getVar('cid') . "'><img src='../images/edit.gif' alt='" . XoopsLocale::A_EDIT . "' title='" . XoopsLocale::A_EDIT . "'></a> |
129
|
|
|
<a href='category.php?op=delete_category&cid=" . $categoryArray2[$i]->getVar('cid') . "'><img src='../images/dele.gif' alt='" . XoopsLocale::A_DELETE . "' title='" . XoopsLocale::A_DELETE . "'></a></td></tr>"; |
130
|
|
|
$class = ('even' === $class) ? 'odd' : 'even'; |
131
|
|
|
$criteria3 = new CriteriaCompo(); |
132
|
|
|
$criteria3->add(new Criteria('pid', $cid)); |
133
|
|
|
$criteria3->setSort('title'); |
134
|
|
|
$criteria3->setOrder('ASC'); |
135
|
|
|
$pid = $categoriesHandler->getAll($criteria3); |
136
|
|
|
$num_pid = $categoriesHandler->getCount(); |
|
|
|
|
137
|
|
|
|
138
|
|
|
if (0 != $pid) { |
139
|
|
|
alumniCategoryDisplayChildren($cid, $pid, $prefix, 'title', $class); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
echo '</table><br><br>'; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
break; |
147
|
|
|
|
148
|
|
View Code Duplication |
case 'new_category': |
|
|
|
|
149
|
|
|
$xoops->header(); |
150
|
|
|
$adminObject = new \Xoops\Module\Admin(); |
151
|
|
|
$adminObject->displayNavigation('category.php'); |
152
|
|
|
$adminObject->addItemButton(AlumniLocale::LIST_CATS, 'category.php'); |
153
|
|
|
echo $adminObject->renderButton('left', ''); |
154
|
|
|
$categoriesHandler = $xoops->getModuleHandler('category', 'alumni'); |
155
|
|
|
$obj = $categoriesHandler->create(); |
156
|
|
|
$form = $xoops->getModuleForm($obj, 'category'); |
157
|
|
|
$form->display(); |
158
|
|
|
break; |
159
|
|
|
|
160
|
|
|
case 'save_category': |
161
|
|
|
if (!$xoops->security()->check()) { |
162
|
|
|
$xoops->redirect('category.php', 3, implode(',', $xoops->security()->getErrors())); |
163
|
|
|
} |
164
|
|
|
$cid = Request::getInt('cid', 0); |
165
|
|
|
$categoriesHandler = $xoops->getModuleHandler('category', 'alumni'); |
166
|
|
|
if (isset($cid)) { |
167
|
|
|
$obj = $categoriesHandler->get(Request::getInt('cid')); |
168
|
|
|
} else { |
169
|
|
|
$obj = $categoriesHandler->create(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$photo_old = Request::getString('photo_old', ''); |
|
|
|
|
173
|
|
|
$destination = XOOPS_ROOT_PATH . "/uploads/{$moduleDirName}/photos/school_photos"; |
174
|
|
|
$del_photo = Request::getInt('del_photo', 0); |
|
|
|
|
175
|
|
View Code Duplication |
if (isset($del_photo)) { |
|
|
|
|
176
|
|
|
if ('1' == $del_photo) { |
|
|
|
|
177
|
|
|
if (@file_exists('' . $destination . '/' . $photo_old) . '') { |
|
|
|
|
178
|
|
|
unlink('' . $destination . '/' . $photo_old . ''); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
$obj->setVar('scphoto', ''); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
$obj->setVar('pid', Request::getInt('pid')); |
185
|
|
|
$obj->setVar('title', Request::getString('title')); |
186
|
|
|
|
187
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
188
|
|
|
$uploaddir = XOOPS_ROOT_PATH . '/modules/alumni/images/cat/'; |
189
|
|
|
$photomax = $xoops->getModuleConfig('alumni_photomax'); |
190
|
|
|
$maxwide = $xoops->getModuleConfig('alumni_maxwide'); |
191
|
|
|
$maxhigh = $xoops->getModuleConfig('alumni_maxhigh'); |
192
|
|
|
$allowedMimetypes = ['image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png']; |
193
|
|
|
$uploader = new XoopsMediaUploader($uploaddir, $allowedMimetypes, $photomax, $maxwide, $maxhigh); |
194
|
|
|
if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
195
|
|
|
$uploader->setPrefix('category_img_'); |
196
|
|
|
$uploader->fetchMedia($_POST['xoops_upload_file'][0]); |
197
|
|
|
if (!$uploader->upload()) { |
198
|
|
|
$errors = $uploader->getErrors(); |
199
|
|
|
$xoops->redirect('javascript:history.go(-1)', 3, $errors); |
200
|
|
|
} else { |
201
|
|
|
$obj->setVar('img', $uploader->getSavedFileName()); |
202
|
|
|
} |
203
|
|
|
} else { |
204
|
|
|
$obj->setVar('img', Request::getString('img')); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$obj->setVar('ordre', Request::getInt('ordre')); |
208
|
|
|
$obj->setVar('scaddress', Request::getString('scaddress')); |
209
|
|
|
$obj->setVar('scaddress2', Request::getString('scaddress2')); |
210
|
|
|
$obj->setVar('sccity', Request::getString('sccity')); |
211
|
|
|
$obj->setVar('scstate', Request::getString('scstate')); |
212
|
|
|
$obj->setVar('sczip', Request::getString('sczip')); |
213
|
|
|
$obj->setVar('scphone', Request::getString('scphone')); |
214
|
|
|
$obj->setVar('scfax', Request::getString('scfax')); |
215
|
|
|
$obj->setVar('scmotto', Request::getString('scmotto')); |
216
|
|
|
$obj->setVar('scurl', Request::getString('scurl')); |
217
|
|
|
|
218
|
|
|
$date = time(); |
219
|
|
View Code Duplication |
if (!empty($_FILES['scphoto']['name'])) { |
|
|
|
|
220
|
|
|
include_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
221
|
|
|
$uploaddir = XOOPS_ROOT_PATH . "/uploads/{$moduleDirName}/photos/school_photos"; |
222
|
|
|
$photomax = $xoops->getModuleConfig('alumni_photomax'); |
223
|
|
|
$maxwide = $xoops->getModuleConfig('alumni_maxwide'); |
224
|
|
|
$maxhigh = $xoops->getModuleConfig('alumni_maxhigh'); |
225
|
|
|
$allowedMimetypes = ['image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png']; |
226
|
|
|
$uploader = new XoopsMediaUploader($uploaddir, $allowedMimetypes, $photomax, $maxwide, $maxhigh); |
227
|
|
|
if ($uploader->fetchMedia($_POST['xoops_upload_file'][1])) { |
228
|
|
|
$uploader->setTargetFileName($date . '_' . $_FILES['scphoto']['name']); |
229
|
|
|
$uploader->fetchMedia($_POST['xoops_upload_file'][1]); |
230
|
|
|
if (!$uploader->upload()) { |
231
|
|
|
$errors = $uploader->getErrors(); |
232
|
|
|
$xoops->redirect('javascript:history.go(-1)', 3, $errors); |
233
|
|
|
} else { |
234
|
|
|
$obj->setVar('scphoto', $uploader->getSavedFileName()); |
235
|
|
|
} |
236
|
|
|
} else { |
237
|
|
|
$obj->setVar('scphoto', Request::getString('scphoto')); |
238
|
|
|
} |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
if ($categoriesHandler->insert($obj)) { |
242
|
|
|
$xoops->redirect('category.php', 3, AlumniLocale::FORMOK); |
243
|
|
|
} |
244
|
|
|
echo $obj->getHtmlErrors(); |
245
|
|
|
$form = $xoops->getModuleForm($obj, 'category'); |
246
|
|
|
$form->display(); |
247
|
|
|
break; |
248
|
|
|
|
249
|
|
View Code Duplication |
case 'edit_category': |
|
|
|
|
250
|
|
|
|
251
|
|
|
$cid = Request::getInt('cid', 0); |
252
|
|
|
$xoops = Xoops::getInstance(); |
253
|
|
|
$xoops->header(); |
254
|
|
|
$adminObject = new \Xoops\Module\Admin(); |
255
|
|
|
$adminObject->displayNavigation('category.php'); |
256
|
|
|
$adminObject->addItemButton(AlumniLocale::LIST_CATS, 'alumni.php', 'list'); |
257
|
|
|
$adminObject->renderButton('left', ''); |
258
|
|
|
$obj = $categoriesHandler->get($cid); |
259
|
|
|
$form = $xoops->getModuleForm($obj, 'category'); |
260
|
|
|
$form->display(); |
261
|
|
|
break; |
262
|
|
|
|
263
|
|
View Code Duplication |
case 'delete_category': |
|
|
|
|
264
|
|
|
$xoops = Xoops::getInstance(); |
265
|
|
|
$xoops->header(); |
266
|
|
|
$cid = Request::getInt('cid', 0); |
267
|
|
|
$ok = Request::getInt('ok', 0); |
268
|
|
|
$obj = $categoriesHandler->get($cid); |
269
|
|
|
if (isset($ok) && 1 == $ok) { |
270
|
|
|
if (!$xoops->security()->check()) { |
271
|
|
|
$xoops->redirect('category.php', 3, implode(',', $xoops->security()->getErrors())); |
272
|
|
|
} |
273
|
|
|
if ($categoriesHandler->delete($obj)) { |
274
|
|
|
$xoops->redirect('category.php', 3, AlumniLocale::FORMDELOK); |
275
|
|
|
} else { |
276
|
|
|
echo $obj->getHtmlErrors(); |
277
|
|
|
} |
278
|
|
|
} else { |
279
|
|
|
echo $xoops->confirm(['ok' => 1, 'cid' => $cid, 'op' => 'delete_category'], 'category.php', XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM . '<br><span class="red">' . $obj->getVar('title') . '<span>'); |
280
|
|
|
} |
281
|
|
|
break; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
$xoops->footer(); |
285
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.