|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Module: Equipment |
|
15
|
|
|
* |
|
16
|
|
|
* @category Module |
|
17
|
|
|
* @package equipment |
|
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <http://xoops.org> |
|
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
20
|
|
|
* @license GPL 2.0 or later |
|
21
|
|
|
* @link https://xoops.org/ |
|
22
|
|
|
* @since 1.0.0 |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
use Xmf\Request; |
|
26
|
|
|
|
|
27
|
|
|
require_once __DIR__ . '/../include/config.php'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Class EquipmentUtility |
|
31
|
|
|
*/ |
|
32
|
|
|
class EquipmentUtility |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @param $text |
|
36
|
|
|
* @param $form_sort |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function selectSorting($text, $form_sort) |
|
40
|
|
|
{ |
|
41
|
|
|
global $start, $order, $file_cat, $sort, $xoopsModule; |
|
42
|
|
|
|
|
43
|
|
|
$select_view = ''; |
|
|
|
|
|
|
44
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
45
|
|
|
|
|
46
|
|
|
if (false !== ($moduleHelper = Xmf\Module\Helper::getHelper($moduleDirName))) { |
|
|
|
|
|
|
47
|
|
|
} else { |
|
48
|
|
|
$moduleHelper = Xmf\Module\Helper::getHelper('system'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$pathModIcon16 = XOOPS_URL . '/modules/' . $moduleDirName . '/' . $moduleHelper->getModule()->getInfo('modicons16'); |
|
52
|
|
|
|
|
53
|
|
|
$select_view = '<form name="form_switch" id="form_switch" action="' . Request::getString('REQUEST_URI', '', 'SERVER') . '" method="post"><span style="font-weight: bold;">' . $text . '</span>'; |
|
54
|
|
|
//$sorts = $sort == 'asc' ? 'desc' : 'asc'; |
|
|
|
|
|
|
55
|
|
|
if ($form_sort == $sort) { |
|
56
|
|
|
$sel1 = $order === 'asc' ? 'selasc.png' : 'asc.png'; |
|
57
|
|
|
$sel2 = $order === 'desc' ? 'seldesc.png' : 'desc.png'; |
|
58
|
|
|
} else { |
|
59
|
|
|
$sel1 = 'asc.png'; |
|
60
|
|
|
$sel2 = 'desc.png'; |
|
61
|
|
|
} |
|
62
|
|
|
$select_view .= ' <a href="' . Request::getString('PHP_SELF', '', 'SERVER') . '?start=' . $start . '&sort=' . $form_sort . '&order=asc" /><img src="' . $pathModIcon16 . '/' . $sel1 . '" title="ASC" alt="ASC"></a>'; |
|
63
|
|
|
$select_view .= '<a href="' . Request::getString('PHP_SELF', '', 'SERVER') . '?start=' . $start . '&sort=' . $form_sort . '&order=desc" /><img src="' . $pathModIcon16 . '/' . $sel2 . '" title="DESC" alt="DESC"></a>'; |
|
64
|
|
|
$select_view .= '</form>'; |
|
65
|
|
|
|
|
66
|
|
|
return $select_view; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/***************Blocks***************/ |
|
72
|
|
|
/** |
|
73
|
|
|
* @param array $cats |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public static function block_addCatSelect($cats) |
|
77
|
|
|
{ |
|
78
|
|
|
$cat_sql = ''; |
|
79
|
|
|
if (is_array($cats)) { |
|
80
|
|
|
$cat_sql = '(' . current($cats); |
|
81
|
|
|
array_shift($cats); |
|
82
|
|
|
foreach ($cats as $cat) { |
|
83
|
|
|
$cat_sql .= ',' . $cat; |
|
84
|
|
|
} |
|
85
|
|
|
$cat_sql .= ')'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $cat_sql; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param $content |
|
93
|
|
|
*/ |
|
94
|
|
View Code Duplication |
public static function meta_keywords($content) |
|
|
|
|
|
|
95
|
|
|
{ |
|
96
|
|
|
global $xoopsTpl, $xoTheme; |
|
97
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
98
|
|
|
$content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
|
99
|
|
|
if (null !== $xoTheme && is_object($xoTheme)) { |
|
100
|
|
|
$xoTheme->addMeta('meta', 'keywords', strip_tags($content)); |
|
101
|
|
|
} else { // Compatibility for old Xoops versions |
|
102
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', strip_tags($content)); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @param $content |
|
108
|
|
|
*/ |
|
109
|
|
View Code Duplication |
public static function meta_description($content) |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
global $xoopsTpl, $xoTheme; |
|
112
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
113
|
|
|
$content = $myts->undoHtmlSpecialChars($myts->displayTarea($content)); |
|
114
|
|
|
if (null !== $xoTheme && is_object($xoTheme)) { |
|
115
|
|
|
$xoTheme->addMeta('meta', 'description', strip_tags($content)); |
|
116
|
|
|
} else { // Compatibility for old Xoops versions |
|
117
|
|
|
$xoopsTpl->assign('xoops_meta_description', strip_tags($content)); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param $tableName |
|
123
|
|
|
* @param $columnName |
|
124
|
|
|
* |
|
125
|
|
|
* @return array |
|
126
|
|
|
*/ |
|
127
|
|
|
public static function enumerate($tableName, $columnName) |
|
128
|
|
|
{ |
|
129
|
|
|
$table = $GLOBALS['xoopsDB']->prefix($tableName); |
|
130
|
|
|
|
|
131
|
|
|
// $result = $GLOBALS['xoopsDB']->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS |
|
132
|
|
|
// WHERE TABLE_NAME = '" . $table . "' AND COLUMN_NAME = '" . $columnName . "'") |
|
133
|
|
|
// || exit ($GLOBALS['xoopsDB']->error()); |
|
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
$sql = 'SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = "' . $table . '" AND COLUMN_NAME = "' . $columnName . '"'; |
|
136
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); |
|
137
|
|
|
if (!$result) { |
|
138
|
|
|
exit($GLOBALS['xoopsDB']->error()); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$row = $GLOBALS['xoopsDB']->fetchBoth($result); |
|
142
|
|
|
$enumList = explode(',', str_replace("'", '', substr($row['COLUMN_TYPE'], 5, strlen($row['COLUMN_TYPE']) - 6))); |
|
143
|
|
|
|
|
144
|
|
|
return $enumList; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param array|string $tableName |
|
149
|
|
|
* @param int $id_field |
|
150
|
|
|
* @param int $id |
|
151
|
|
|
* |
|
152
|
|
|
* @return mixed |
|
153
|
|
|
*/ |
|
154
|
|
|
public static function cloneRecord($tableName, $id_field, $id) |
|
155
|
|
|
{ |
|
156
|
|
|
$new_id = false; |
|
157
|
|
|
$table = $GLOBALS['xoopsDB']->prefix($tableName); |
|
158
|
|
|
// copy content of the record you wish to clone |
|
159
|
|
|
$tempTable = $GLOBALS['xoopsDB']->fetchArray($GLOBALS['xoopsDB']->query("SELECT * FROM $table WHERE $id_field='$id' "), MYSQLI_ASSOC) or exit('Could not select record'); |
|
160
|
|
|
// set the auto-incremented id's value to blank. |
|
161
|
|
|
unset($tempTable[$id_field]); |
|
162
|
|
|
// insert cloned copy of the original record |
|
163
|
|
|
$result = $GLOBALS['xoopsDB']->queryF("INSERT INTO $table (" . implode(', ', array_keys($tempTable)) . ") VALUES ('" . implode("', '", array_values($tempTable)) . "')") or exit($GLOBALS['xoopsDB']->error()); |
|
164
|
|
|
|
|
165
|
|
|
if ($result) { |
|
166
|
|
|
// Return the new id |
|
167
|
|
|
$new_id = $GLOBALS['xoopsDB']->getInsertId(); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
return $new_id; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $folder The full path of the directory to check |
|
177
|
|
|
* |
|
178
|
|
|
* @return void |
|
179
|
|
|
*/ |
|
180
|
|
|
public static function createFolder($folder) |
|
181
|
|
|
{ |
|
182
|
|
|
try { |
|
183
|
|
|
if (!file_exists($folder)) { |
|
184
|
|
|
if (!mkdir($folder) && !is_dir($folder)) { |
|
185
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
186
|
|
|
} |
|
187
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
catch (Exception $e) { |
|
191
|
|
|
echo 'Caught exception: ', $e->getMessage(), '', '<br>'; |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @param $file |
|
197
|
|
|
* @param $folder |
|
198
|
|
|
* @return bool |
|
199
|
|
|
*/ |
|
200
|
|
|
public static function copyFile($file, $folder) |
|
201
|
|
|
{ |
|
202
|
|
|
return copy($file, $folder); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param $src |
|
207
|
|
|
* @param $dst |
|
208
|
|
|
*/ |
|
209
|
|
|
public static function recurseCopy($src, $dst) |
|
210
|
|
|
{ |
|
211
|
|
|
$dir = opendir($src); |
|
212
|
|
|
// @mkdir($dst); |
|
213
|
|
|
while (false !== ($file = readdir($dir))) { |
|
214
|
|
|
if (($file !== '.') && ($file !== '..')) { |
|
215
|
|
|
if (is_dir($src . '/' . $file)) { |
|
216
|
|
|
static::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
217
|
|
|
} else { |
|
218
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
closedir($dir); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* |
|
227
|
|
|
* Verifies XOOPS version meets minimum requirements for this module |
|
228
|
|
|
* @static |
|
229
|
|
|
* @param XoopsModule $module |
|
230
|
|
|
* |
|
231
|
|
|
* @param null|string $requiredVer |
|
232
|
|
|
* @return bool true if meets requirements, false if not |
|
233
|
|
|
*/ |
|
234
|
|
|
public static function checkVerXoops(XoopsModule $module = null, $requiredVer = null) |
|
235
|
|
|
{ |
|
236
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
237
|
|
|
if (null === $module) { |
|
238
|
|
|
$module = XoopsModule::getByDirname($moduleDirName); |
|
239
|
|
|
} |
|
240
|
|
|
xoops_loadLanguage('admin', $moduleDirName); |
|
241
|
|
|
//check for minimum XOOPS version |
|
242
|
|
|
$currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
243
|
|
|
$currArray = explode('.', $currentVer); |
|
244
|
|
|
if (null === $requiredVer) { |
|
245
|
|
|
$requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
246
|
|
|
} |
|
247
|
|
|
$reqArray = explode('.', $requiredVer); |
|
248
|
|
|
$success = true; |
|
249
|
|
|
foreach ($reqArray as $k => $v) { |
|
250
|
|
|
if (isset($currArray[$k])) { |
|
251
|
|
|
if ($currArray[$k] > $v) { |
|
252
|
|
|
break; |
|
253
|
|
|
} elseif ($currArray[$k] == $v) { |
|
254
|
|
|
continue; |
|
255
|
|
|
} else { |
|
256
|
|
|
$success = false; |
|
257
|
|
|
break; |
|
258
|
|
|
} |
|
259
|
|
|
} else { |
|
260
|
|
|
if ((int)$v > 0) { // handles things like x.x.x.0_RC2 |
|
261
|
|
|
$success = false; |
|
262
|
|
|
break; |
|
263
|
|
|
} |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
if (!$success) { |
|
268
|
|
|
$module->setErrors(sprintf(AM_EQUIPMENT_ERROR_BAD_XOOPS, $requiredVer, $currentVer)); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
return $success; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* |
|
276
|
|
|
* Verifies PHP version meets minimum requirements for this module |
|
277
|
|
|
* @static |
|
278
|
|
|
* @param XoopsModule $module |
|
279
|
|
|
* |
|
280
|
|
|
* @return bool true if meets requirements, false if not |
|
281
|
|
|
*/ |
|
282
|
|
|
public static function checkVerPhp(XoopsModule $module) |
|
283
|
|
|
{ |
|
284
|
|
|
xoops_loadLanguage('admin', $module->dirname()); |
|
285
|
|
|
// check for minimum PHP version |
|
286
|
|
|
$success = true; |
|
287
|
|
|
$verNum = PHP_VERSION; |
|
288
|
|
|
$reqVer = $module->getInfo('min_php'); |
|
289
|
|
|
if (false !== $reqVer && '' !== $reqVer) { |
|
290
|
|
|
if (version_compare($verNum, $reqVer, '<')) { |
|
291
|
|
|
$module->setErrors(sprintf(AM_EQUIPMENT_ERROR_BAD_PHP, $reqVer, $verNum)); |
|
292
|
|
|
$success = false; |
|
293
|
|
|
} |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
return $success; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
public static function getQueryDataToJSON($sql) |
|
300
|
|
|
{ |
|
301
|
|
|
global $xoopsDB; |
|
302
|
|
|
$query = $xoopsDB->query($sql); |
|
303
|
|
|
$query_rows = []; |
|
304
|
|
|
|
|
305
|
|
|
if ($xoopsDB->getRowsNum($query) > 0) { |
|
306
|
|
|
while ($row = $xoopsDB->fetchArray($query)) { |
|
307
|
|
|
$query_rows[] = $row; |
|
308
|
|
|
} |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
return json_encode($query_rows); |
|
312
|
|
|
} |
|
313
|
|
|
} |
|
314
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.