1
|
|
|
<?php declare(strict_types=1); |
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
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
15
|
|
|
* @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
16
|
|
|
* @author Brian Wahoff <[email protected]> |
17
|
|
|
* @author Eric Juden <[email protected]> |
18
|
|
|
* @author XOOPS Development Team |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Xmf\Request; |
22
|
|
|
use XoopsModules\Xhelp; |
23
|
|
|
|
24
|
|
|
/** @var Xhelp\Helper $helper */ |
25
|
|
|
require_once __DIR__ . '/header.php'; |
26
|
|
|
|
27
|
|
|
require_once \dirname(__DIR__, 2) . '/mainfile.php'; |
28
|
|
|
if (!defined('XHELP_CONSTANTS_INCLUDED')) { |
29
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/xhelp/include/constants.php'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
//require_once XHELP_BASE_PATH . '/functions.php'; |
33
|
|
|
$helper->loadLanguage('modinfo'); |
34
|
|
|
$helper->loadLanguage('main'); |
35
|
|
|
|
36
|
|
|
$op = ''; |
37
|
|
|
|
38
|
|
|
if (Request::hasVar('op', 'GET')) { |
39
|
|
|
$op = $_GET['op']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
switch ($op) { |
43
|
|
|
case 'updateTopics': |
44
|
|
|
global $xoopsModule; |
45
|
|
|
$myTopics = updateTopics(); |
46
|
|
|
break; |
47
|
|
|
case 'updateDepts': |
48
|
|
|
global $xoopsModule; |
49
|
|
|
$myDepts = updateDepts(); |
50
|
|
|
break; |
51
|
|
|
default: |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
function updateDepts(): bool |
59
|
|
|
{ |
60
|
|
|
global $xoopsDB; |
61
|
|
|
$helper = Xhelp\Helper::getInstance(); |
62
|
|
|
|
63
|
|
|
echo "<link rel='stylesheet' type='text/css' media'screen' href='" . XOOPS_URL . "/xoops.css'> |
64
|
|
|
<link rel='stylesheet' type='text/css' media='screen' href='" . xoops_getcss() . "'> |
65
|
|
|
<link rel='stylesheet' type='text/css' media='screen' href='../system/style.css'>"; |
66
|
|
|
echo "<table width='100%' border='1' cellpadding='0' cellspacing='2' class='formButton'>"; |
67
|
|
|
echo '<tr><th>' . _MI_XHELP_DEFAULT_DEPT . '</th></tr>'; |
68
|
|
|
echo "<tr class='head'><td>" . _XHELP_TEXT_DEPTS_ADDED . '</td></tr>'; |
69
|
|
|
|
70
|
|
|
if (!$xhelp_config = removeDepts()) { |
71
|
|
|
return false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//Retrieve list of departments |
75
|
|
|
/** @var \XoopsModules\Xhelp\DepartmentHandler $departmentHandler */ |
76
|
|
|
$departmentHandler = $helper->getHandler('Department'); |
77
|
|
|
$depts = $departmentHandler->getObjects(); |
78
|
|
|
|
79
|
|
|
$class = 'odd'; |
80
|
|
|
foreach ($depts as $dept) { |
81
|
|
|
$deptid = $dept->getVar('id'); |
82
|
|
|
$deptname = $dept->getVar('department'); |
83
|
|
|
|
84
|
|
|
/** @var \XoopsModules\Xhelp\ConfigOptionHandler $configOptionHandler */ |
85
|
|
|
$configOptionHandler = $helper->getHandler('ConfigOption'); |
86
|
|
|
$newOption = $configOptionHandler->create(); |
87
|
|
|
$newOption->setVar('confop_name', $deptname); |
88
|
|
|
$newOption->setVar('confop_value', $deptid); |
89
|
|
|
$newOption->setVar('conf_id', $xhelp_config); |
90
|
|
|
|
91
|
|
|
if (!$configOptionHandler->insert($newOption, true)) { |
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
echo "<tr class='" . $class . "'><td>" . $dept->getVar('department') . '</td></tr>'; |
96
|
|
|
$class = ('odd' === $class) ? 'even' : 'odd'; |
97
|
|
|
} |
98
|
|
|
echo "<tr class='foot'><td>" . _XHELP_TEXT_UPDATE_COMP . "<br><br><input type='button' name='closeWindow' value='" . _XHELP_TEXT_CLOSE_WINDOW . "' class='formButton' onClick=\"window.opener.location=window.opener.location;window.close();\"></td></tr>"; |
99
|
|
|
echo '</table>'; |
100
|
|
|
|
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return bool |
106
|
|
|
*/ |
107
|
|
|
function removeDepts(): bool |
108
|
|
|
{ |
109
|
|
|
global $xoopsDB; |
110
|
|
|
$helper = Xhelp\Helper::getInstance(); |
111
|
|
|
|
112
|
|
|
//Needs force on delete |
113
|
|
|
/** @var \XoopsConfigHandler $configHandler */ |
114
|
|
|
$configHandler = xoops_getHandler('config'); |
115
|
|
|
|
116
|
|
|
// Select the config from the xoops_config table |
117
|
|
|
$criteria = new \Criteria('conf_name', 'xhelp_defaultDept'); |
118
|
|
|
$config = $configHandler->getConfigs($criteria); |
119
|
|
|
|
120
|
|
|
if (count($config) > 0) { |
121
|
|
|
$xhelp_config = $config[0]->getVar('conf_id'); |
122
|
|
|
} else { |
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// Remove the config options |
127
|
|
|
/** @var \XoopsModules\Xhelp\ConfigOptionHandler $configOptionHandler */ |
128
|
|
|
$configOptionHandler = $helper->getHandler('ConfigOption'); |
129
|
|
|
$criteria = new \Criteria('conf_id', $xhelp_config); |
130
|
|
|
$configOptions = $configOptionHandler->getObjects($criteria); |
131
|
|
|
|
132
|
|
|
if (count($configOptions) > 0) { |
133
|
|
|
foreach ($configOptions as $option) { |
134
|
|
|
if (!$configOptionHandler->deleteAll($option, true)) { // Remove each config option |
135
|
|
|
return false; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
} else { // If no config options were found |
139
|
|
|
return $xhelp_config; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $xhelp_config; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param bool $onInstall |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
|
|
function updateTopics(bool $onInstall = false): bool |
150
|
|
|
{ |
151
|
|
|
if (!$onInstall) { // Don't need to display anything if installing |
152
|
|
|
echo "<link rel='stylesheet' type='text/css' media='screen' href='" . XOOPS_URL . "/xoops.css'> |
153
|
|
|
<link rel='stylesheet' type='text/css' media='screen' href='" . xoops_getcss() . "'> |
154
|
|
|
<link rel='stylesheet' type='text/css' media='screen' href='../system/style.css'>"; |
155
|
|
|
echo "<table width='100%' border='1' cellpadding='0' cellspacing='2' class='formButton'>"; |
156
|
|
|
echo '<tr><th>' . _MI_XHELP_ANNOUNCEMENTS . '</th></tr>'; |
157
|
|
|
echo "<tr class='head'><td>" . _XHELP_TEXT_TOPICS_ADDED . '</td></tr>'; |
158
|
|
|
} |
159
|
|
|
if (!$xhelp_config = removeTopics()) { |
160
|
|
|
return false; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
//Retrieve list of topics from DB |
164
|
|
|
global $xoopsDB; |
165
|
|
|
$ret = $xoopsDB->query('SELECT topic_id, topic_title FROM ' . $xoopsDB->prefix('topics')); |
166
|
|
|
$myTopics = []; |
167
|
|
|
$myTopics[_MI_XHELP_ANNOUNCEMENTS_NONE] = 0; |
168
|
|
|
while (false !== ($arr = $xoopsDB->fetchArray($ret))) { |
169
|
|
|
$myTopics[$arr['topic_title']] = $arr['topic_id']; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
$class = 'odd'; |
173
|
|
|
foreach ($myTopics as $topic => $value) { |
174
|
|
|
$xhelp_id = $xoopsDB->genId($xoopsDB->prefix('configoption') . '_uid_seq'); |
175
|
|
|
$sql = sprintf('INSERT INTO `%s` (confop_id, confop_name, confop_value, conf_id) VALUES (%u, %s, %s, %u)', $xoopsDB->prefix('configoption'), $xhelp_id, $xoopsDB->quoteString($topic), $xoopsDB->quoteString($value), $xhelp_config); |
|
|
|
|
176
|
|
|
|
177
|
|
|
if (!$result = $xoopsDB->queryF($sql)) { |
|
|
|
|
178
|
|
|
return false; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
if (empty($xhelp_id)) { |
182
|
|
|
$xhelp_id = $xoopsDB->getInsertId(); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
if (!$onInstall) { // Don't need to display anything if installing |
185
|
|
|
echo "<tr class='" . $class . "'><td>" . $topic . '</td></tr>'; |
186
|
|
|
$class = ('odd' === $class) ? 'even' : 'odd'; |
187
|
|
|
} |
188
|
|
|
} |
189
|
|
|
if (!$onInstall) { // Don't need to display anything if installing |
190
|
|
|
echo "<tr class='foot'><td>" . _XHELP_TEXT_UPDATE_COMP . "<br><br><input type='button' name='closeWindow' value='" . _XHELP_TEXT_CLOSE_WINDOW . "' class='formButton' onClick=\"javascript:window.opener.location=window.opener.location;window.close();\"></td></tr>"; |
191
|
|
|
echo '</table>'; |
192
|
|
|
} |
193
|
|
|
return true; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* @return bool|string |
198
|
|
|
*/ |
199
|
|
|
function removeTopics() |
200
|
|
|
{ |
201
|
|
|
global $xoopsDB; |
202
|
|
|
// Select the config from the xoops_config table |
203
|
|
|
$sql = sprintf('SELECT * FROM `%s` WHERE conf_name = %s', $xoopsDB->prefix('config'), "'xhelp_announcements'"); |
204
|
|
|
if (!$ret = $xoopsDB->query($sql)) { |
205
|
|
|
return false; |
206
|
|
|
} |
207
|
|
|
$xhelp_config = false; |
|
|
|
|
208
|
|
|
$arr = $xoopsDB->fetchArray($ret); |
209
|
|
|
$xhelp_config = $arr['conf_id']; |
210
|
|
|
|
211
|
|
|
// Remove the config options |
212
|
|
|
$sql = sprintf('DELETE FROM `%s` WHERE conf_id = %s', $xoopsDB->prefix('configoption'), $xhelp_config); |
213
|
|
|
if (!$ret = $xoopsDB->queryF($sql)) { |
|
|
|
|
214
|
|
|
return false; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
return $xhelp_config; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* |
222
|
|
|
* @param \XoopsModule $module |
223
|
|
|
* @return bool |
224
|
|
|
*/ |
225
|
|
|
function xoops_module_install_xhelp(\XoopsModule $module): bool |
|
|
|
|
226
|
|
|
{ |
227
|
|
|
$myTopics = updateTopics(true); |
|
|
|
|
228
|
|
|
$hasRoles = Xhelp\Utility::createRoles(); |
|
|
|
|
229
|
|
|
$hasStatuses = Xhelp\Utility::createStatuses(); |
|
|
|
|
230
|
|
|
$hasNotifications = Xhelp\Utility::createNotifications(); |
|
|
|
|
231
|
|
|
$hasTicketLists = Xhelp\Utility::createDefaultTicketLists(); |
|
|
|
|
232
|
|
|
|
233
|
|
|
return true; |
234
|
|
|
} |
235
|
|
|
|