Issues (314)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

include/update.php (2 issues)

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
 * modulebuilder module.
15
 *
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.0
20
 *
21
 * @author          Txmod Xoops https://xoops.org 
22
 *                  Goffy https://myxoops.org
23
 *
24
 * @param mixed      $module
25
 * @param null|mixed $prev_version
26
 */
27
28
/**
29
 * @param      $module
30
 * @param null $prev_version
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $prev_version is correct as it would always require null to be passed?
Loading history...
31
 *
32
 * @return bool|null
33
 */
34
function xoops_module_update_modulebuilder(&$module, $prev_version = null)
35
{
36
37
    $ret = null;
38
    if ($prev_version < 191) {
39
        update_modulebuilder_v191($module);
40
    }
41
42
	if (!modulebuilder_check_db($module)) {
43
        print_r($module->getErrors());
44
    }
45
46
    if (!clean_index_files()) {
47
        print_r($module->getErrors());
48
    }
49
	
50
	//check upload directory
51
	require_once __DIR__ . '/install.php';
52
    xoops_module_install_modulebuilder($module);
53
	
54
    $errors = $module->getErrors();
55
    if (!empty($errors)) {
56
        print_r($errors);
57
    }
58
59
    return $ret;
60
61
}
62
63
// irmtfan bug fix: solve templates duplicate issue
64
/**
65
 * @param $module
66
 *
67
 * @return bool
68
 */
69
function update_modulebuilder_v191(&$module)
70
{
71
    global $xoopsDB;
72
    $result = $xoopsDB->query(
73
        'SELECT t1.tpl_id FROM ' . $xoopsDB->prefix('tplfile') . ' t1, ' . $xoopsDB->prefix('tplfile') . ' t2 WHERE t1.tpl_refid = t2.tpl_refid AND t1.tpl_module = t2.tpl_module AND t1.tpl_tplset=t2.tpl_tplset AND t1.tpl_file = t2.tpl_file AND t1.tpl_type = t2.tpl_type AND t1.tpl_id > t2.tpl_id'
74
    );
75
    $tplids = [];
76
    while (list($tplid) = $xoopsDB->fetchRow($result)) {
77
        $tplids[] = $tplid;
78
    }
79
    if (\count($tplids) > 0) {
80
        $tplfileHandler  = \xoops_getHandler('tplfile');
81
        $duplicate_files = $tplfileHandler->getObjects(
82
            new \Criteria('tpl_id', '(' . \implode(',', $tplids) . ')', 'IN')
83
        );
84
85
        if (\count($duplicate_files) > 0) {
86
            foreach (\array_keys($duplicate_files) as $i) {
87
                $tplfileHandler->delete($duplicate_files[$i]);
88
            }
89
        }
90
    }
91
    $sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'";
92
    if (!$result = $xoopsDB->queryF($sql)) {
93
        xoops_error($xoopsDB->error() . '<br />' . $sql);
94
95
        return false;
96
    }
97
    $ret = [];
98
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
99
        $ret[] = $myrow;
100
    }
101
    if (!empty($ret)) {
102
        $module->setErrors(
103
            "'tpl_refid_module_set_file_type' unique index is exist. Note: check 'tplfile' table to be sure this index is UNIQUE because XOOPS CORE need it."
104
        );
105
106
        return true;
107
    }
108
    $sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )';
109
    if (!$result = $xoopsDB->queryF($sql)) {
0 ignored issues
show
The assignment to $result is dead and can be removed.
Loading history...
110
        xoops_error($xoopsDB->error() . '<br />' . $sql);
111
        $module->setErrors(
112
            "'tpl_refid_module_set_file_type' unique index is not added to 'tplfile' table. Warning: do not use XOOPS until you add this unique index."
113
        );
114
115
        return false;
116
    }
117
118
    return true;
119
}
120
// irmtfan bug fix: solve templates duplicate issue
121
122
/**
123
 * function to add code for db checking
124
 * @param $module
125
 *
126
 * @return bool
127
 */
128
function modulebuilder_check_db($module)
129
{
130
    $ret = true;
131
	//insert here code for database check
132
    global $xoopsDB;
133
134
    // new form field SelectStatus
135
    $fname  = 'SelectStatus';
136
    $fid    = 16;
137
    $fvalue = 'XoopsFormSelectStatus';
138
    $result = $xoopsDB->query(
139
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
140
    );
141
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
142
    if ($num_rows == 0) {
143
        $result = $xoopsDB->query(
144
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
145
        );
146
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
147
        if ($num_rows > 0) {
148
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
149
            //add existing element at end of table
150
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
151
            $result = $xoopsDB->query($sql);
152
            // update table fields to new id of previous 16
153
            $newId = $xoopsDB->getInsertId();
154
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
155
            $result = $xoopsDB->query($sql);
156
            // update 16 to new element
157
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
158
            $result = $xoopsDB->query($sql);
159
        } else {
160
            //add missing element
161
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
162
            $result = $xoopsDB->query($sql);
163
        }
164
    }
165
166
    // new form field Password
167
    $fname  = 'Password';
168
    $fid    = 17;
169
    $fvalue = 'XoopsFormPassword';
170
    $result = $xoopsDB->query(
171
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
172
    );
173
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
174
    if ($num_rows == 0) {
175
        $result = $xoopsDB->query(
176
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
177
        );
178
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
179
        if ($num_rows > 0) {
180
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
181
            //add existing element at end of table
182
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
183
            $result = $xoopsDB->query($sql);
184
            // update table fields to new id of previous 17
185
            $newId = $xoopsDB->getInsertId();
186
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
187
            $result = $xoopsDB->query($sql);
188
            // update 17 to new element
189
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
190
            $result = $xoopsDB->query($sql);
191
        } else {
192
            //add missing element
193
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
194
            $result = $xoopsDB->query($sql);
195
        }
196
    }
197
198
    // new form field SelectCountry
199
    $fname  = 'SelectCountry';
200
    $fid    = 18;
201
    $fvalue = 'XoopsFormSelectCountry';
202
    $result = $xoopsDB->query(
203
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
204
    );
205
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
206
    if ($num_rows == 0) {
207
        $result = $xoopsDB->query(
208
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
209
        );
210
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
211
        if ($num_rows > 0) {
212
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
213
            //add existing element at end of table
214
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
215
            $result = $xoopsDB->query($sql);
216
            // update table fields to new id of previous 18
217
            $newId = $xoopsDB->getInsertId();
218
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
219
            $result = $xoopsDB->query($sql);
220
            // update 18 to new element
221
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
222
            $result = $xoopsDB->query($sql);
223
        } else {
224
            //add missing element
225
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
226
            $result = $xoopsDB->query($sql);
227
        }
228
    }
229
230
    // new form field SelectLanguage
231
    $fname  = 'SelectLang';
232
    $fid    = 19;
233
    $fvalue = 'XoopsFormSelectLang';
234
    $result = $xoopsDB->query(
235
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
236
    );
237
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
238
    if ($num_rows == 0) {
239
        $result = $xoopsDB->query(
240
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
241
        );
242
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
243
        if ($num_rows > 0) {
244
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
245
            //add existing element at end of table
246
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
247
            $result = $xoopsDB->query($sql);
248
            // update table fields to new id of previous 19
249
            $newId = $xoopsDB->getInsertId();
250
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
251
            $result = $xoopsDB->query($sql);
252
            // update 19 to new element
253
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
254
            $result = $xoopsDB->query($sql);
255
        } else {
256
            //add missing element
257
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
258
            $result = $xoopsDB->query($sql);
259
        }
260
    }
261
262
    // new form field Radio
263
    $fname  = 'Radio';
264
    $fid    = 20;
265
    $fvalue = 'XoopsFormRadio';
266
    $result = $xoopsDB->query(
267
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
268
    );
269
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
270
    if ($num_rows == 0) {
271
        $result = $xoopsDB->query(
272
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
273
        );
274
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
275
        if ($num_rows > 0) {
276
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
277
            //add existing element at end of table
278
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
279
            $result = $xoopsDB->query($sql);
280
            // update table fields to new id of previous 20
281
            $newId = $xoopsDB->getInsertId();
282
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
283
            $result = $xoopsDB->query($sql);
284
            // update 20 to new element
285
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
286
            $result = $xoopsDB->query($sql);
287
        } else {
288
            //add missing element
289
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
290
            $result = $xoopsDB->query($sql);
291
        }
292
    }
293
294
    // new form field DateTime
295
    $fname  = 'DateTime';
296
    $fid    = 21;
297
    $fvalue = 'XoopsFormDateTime';
298
    $result = $xoopsDB->query(
299
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
300
    );
301
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
302
    if ($num_rows == 0) {
303
        $result = $xoopsDB->query(
304
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
305
        );
306
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
307
        if ($num_rows > 0) {
308
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
309
            //add existing element at end of table
310
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
311
            $result = $xoopsDB->query($sql);
312
            // update table fields to new id of previous 21
313
            $newId = $xoopsDB->getInsertId();
314
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
315
            $result = $xoopsDB->query($sql);
316
            // update 21 to new element
317
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
318
            $result = $xoopsDB->query($sql);
319
        } else {
320
            //add missing element
321
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
322
            $result = $xoopsDB->query($sql);
323
        }
324
    }
325
326
    // new form field DateTime
327
    $fname  = 'SelectCombo';
328
    $fid    = 22;
329
    $fvalue = 'XoopsFormSelectCombo';
330
    $result = $xoopsDB->query(
331
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
332
    );
333
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
334
    if ($num_rows == 0) {
335
        $result = $xoopsDB->query(
336
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
337
        );
338
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
339
        if ($num_rows > 0) {
340
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
341
            //add existing element at end of table
342
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
343
            $result = $xoopsDB->query($sql);
344
            // update table fields to new id of previous 22
345
            $newId = $xoopsDB->getInsertId();
346
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
347
            $result = $xoopsDB->query($sql);
348
            // update 22 to new element
349
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
350
            $result = $xoopsDB->query($sql);
351
        } else {
352
            //add missing element
353
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
354
            $result = $xoopsDB->query($sql);
355
        }
356
    }
357
358
    // update table 'modulebuilder_fieldelements'
359
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fieldelements');
360
    $field   = 'fieldelement_sort';
361
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
362
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
363
    if (!$numRows) {
364
        $sql = "ALTER TABLE `$table` ADD `$field` INT(8) NOT NULL DEFAULT '0' AFTER `fieldelement_value`;";
365
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
366
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
367
            $module->setErrors("Error when adding '$field' to table '$table'.");
368
            $ret = false;
369
        }
370
    }
371
372
    // update table 'modulebuilder_fieldelements'
373
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fieldelements');
374
    $field   = 'fieldelement_deftype';
375
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
376
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
377
    if (!$numRows) {
378
        $sql = "ALTER TABLE `$table` ADD `$field` INT(10) NOT NULL DEFAULT '0' AFTER `fieldelement_sort`;";
379
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
380
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
381
            $module->setErrors("Error when adding '$field' to table '$table'.");
382
            $ret = false;
383
        }
384
    }
385
386
    // update table 'modulebuilder_fieldelements'
387
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fieldelements');
388
    $field   = 'fieldelement_defvalue';
389
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
390
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
391
    if (!$numRows) {
392
        $sql = "ALTER TABLE `$table` ADD `$field` int(10) NULL DEFAULT '0' AFTER `fieldelement_deftype`;";
393
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
394
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
395
            $module->setErrors("Error when adding '$field' to table '$table'.");
396
            $ret = false;
397
        }
398
    }
399
400
    // set default values for form elements
401
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '255' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in(2, 10, 11, 12, 13, 14, 17)");
402
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 15, `fieldelement_defvalue` = '0' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in (3, 4)");
403
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 2, `fieldelement_defvalue` = '10' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in(5, 7, 8, 15, 20, 21, 22)");
404
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 2, `fieldelement_defvalue` = '1' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in(6, 16)");
405
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '7' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in(9)");
406
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '3' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in(18)");
407
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '100' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_id` in(19)");
408
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " SET `fieldelement_deftype` = 2, `fieldelement_defvalue` = '10' WHERE `xc_modulebuilder_fieldelements`.`fieldelement_mid` > 0");
409
410
    // update table 'modulebuilder_fields'
411
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fields');
412
    $field   = 'field_ifoot';
413
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
414
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
415
    if (!$numRows) {
416
        $sql = "ALTER TABLE `$table` ADD `$field` INT(8) NOT NULL DEFAULT '0' AFTER `field_user`;";
417
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
418
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
419
            $module->setErrors("Error when adding '$field' to table '$table'.");
420
            $ret = false;
421
        }
422
    }
423
    // update table 'modulebuilder_fields'
424
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fields');
425
    $field   = 'field_ibody';
426
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
427
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
428
    if (!$numRows) {
429
        $sql = "ALTER TABLE `$table` ADD `$field` INT(8) NOT NULL DEFAULT '0' AFTER `field_user`;";
430
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
431
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
432
            $module->setErrors("Error when adding '$field' to table '$table'.");
433
            $ret = false;
434
        }
435
    }
436
    // update table 'modulebuilder_fields'
437
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fields');
438
    $field   = 'field_ihead';
439
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
440
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
441
    if (!$numRows) {
442
        $sql = "ALTER TABLE `$table` ADD `$field` INT(8) NOT NULL DEFAULT '0' AFTER `field_user`;";
443
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
444
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
445
            $module->setErrors("Error when adding '$field' to table '$table'.");
446
            $ret = false;
447
        }
448
    }
449
450
    // update table 'modulebuilder_morefiles'
451
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_morefiles');
452
    $field   = 'file_type';
453
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
454
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
455
    if (!$numRows) {
456
        $sql = "ALTER TABLE `$table` ADD `$field` INT(8) NOT NULL DEFAULT '0' AFTER `file_mid`;";
457
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
458
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
459
            $module->setErrors("Error when adding '$field' to table '$table'.");
460
            $ret = false;
461
        }
462
    }
463
464
    // update table 'modulebuilder_morefiles'
465
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_morefiles');
466
    $field   = 'file_upload';
467
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
468
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
469
    if (!$numRows) {
470
        $sql = "ALTER TABLE `$table` ADD `$field` varchar(255) NOT NULL DEFAULT '' AFTER `file_extension`;";
471
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
472
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
473
            $module->setErrors("Error when adding '$field' to table '$table'.");
474
            $ret = false;
475
        }
476
    }
477
478
    // new form field text UUID
479
    $fname     = 'TextUuid';
480
    $fid       = 23;
481
    $fvalue    = 'XoopsFormTextUuid';
482
    $fsort     = 22;
483
    $fdeftype  = 14;
484
    $fdefvalue = 45;
485
    $result = $xoopsDB->query(
486
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
487
    );
488
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
489
    if ($num_rows == 0) {
490
        $result = $xoopsDB->query(
491
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
492
        );
493
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
494
        if ($num_rows > 0) {
495
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value, $fe_sort, $fe_deftype, $fe_defvalue) = $xoopsDB->fetchRow($result);
496
            //add existing element at end of table
497
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}', '{$fe_sort}', '{$fe_deftype}', '{$fe_defvalue}')";
498
            $result = $xoopsDB->query($sql);
499
            // update table fields to new id of previous 23
500
            $newId = $xoopsDB->getInsertId();
501
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
502
            $result = $xoopsDB->query($sql);
503
            // update 23 to new element
504
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}', `fieldelement_sort` = '{$fsort}', `fieldelement_deftype` = '{$fdeftype}', `fieldelement_defvalue` = '{$fdefvalue}' WHERE `fieldelement_id` = {$fid};";
505
            $result = $xoopsDB->query($sql);
506
        } else {
507
            //add missing element
508
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}', '{$fsort}', '{$fdeftype}', '{$fdefvalue}')";
509
            $result = $xoopsDB->query($sql);
510
        }
511
    }
512
513
    // new form field text IP
514
    $fname     = 'TextIp';
515
    $fid       = 24;
516
    $fvalue    = 'XoopsFormTextIp';
517
    $fsort     = 23;
518
    $fdeftype  = 14;
519
    $fdefvalue = 16;
520
    $result = $xoopsDB->query(
521
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
522
    );
523
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
524
    if ($num_rows == 0) {
525
        $result = $xoopsDB->query(
526
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
527
        );
528
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
529
        if ($num_rows > 0) {
530
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value, $fe_sort, $fe_deftype, $fe_defvalue) = $xoopsDB->fetchRow($result);
531
            //add existing element at end of table
532
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}', '{$fe_sort}', '{$fe_deftype}', '{$fe_defvalue}')";
533
            $result = $xoopsDB->query($sql);
534
            // update table fields to new id of previous 23
535
            $newId = $xoopsDB->getInsertId();
536
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
537
            $result = $xoopsDB->query($sql);
538
            // update 23 to new element
539
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}', `fieldelement_sort` = '{$fsort}', `fieldelement_deftype` = '{$fdeftype}', `fieldelement_defvalue` = '{$fdefvalue}' WHERE `fieldelement_id` = {$fid};";
540
            $result = $xoopsDB->query($sql);
541
        } else {
542
            //add missing element
543
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}', '{$fsort}', '{$fdeftype}', '{$fdefvalue}')";
544
            $result = $xoopsDB->query($sql);
545
        }
546
    }
547
548
    // update table 'modulebuilder_fieldelements'
549
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_fieldelements');
550
    $field   = 'fieldelement_defvalue';
551
    $sql = "ALTER TABLE `$table` CHANGE `$field` `$field` varchar(5) NULL DEFAULT NULL;";
552
    if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
553
        xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
554
        $module->setErrors("Error when changing '$field' in table '$table'.");
555
        $ret = false;
556
    }
557
558
    // new form field text comments
559
    $fname     = 'TextComments';
560
    $fid       = 25;
561
    $fvalue    = 'XoopsFormTextComments';
562
    $fsort     = 24;
563
    $fdeftype  = 2;
564
    $fdefvalue = 10;
565
    $result = $xoopsDB->query(
566
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
567
    );
568
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
569
    if ($num_rows == 0) {
570
        $result = $xoopsDB->query(
571
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
572
        );
573
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
574
        if ($num_rows > 0) {
575
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value, $fe_sort, $fe_deftype, $fe_defvalue) = $xoopsDB->fetchRow($result);
576
            //add existing element at end of table
577
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}', '{$fe_sort}', '{$fe_deftype}', '{$fe_defvalue}')";
578
            $result = $xoopsDB->query($sql);
579
            // update table fields to new id of previous 25
580
            $newId = $xoopsDB->getInsertId();
581
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
582
            $result = $xoopsDB->query($sql);
583
            // update 25 to new element
584
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}', `fieldelement_sort` = '{$fsort}', `fieldelement_deftype` = '{$fdeftype}', `fieldelement_defvalue` = '{$fdefvalue}' WHERE `fieldelement_id` = {$fid};";
585
            $result = $xoopsDB->query($sql);
586
        } else {
587
            //add missing element
588
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}', '{$fsort}', '{$fdeftype}', '{$fdefvalue}')";
589
            $result = $xoopsDB->query($sql);
590
        }
591
    }
592
    // new form field text ratings
593
    $fname     = 'TextRatings';
594
    $fid       = 26;
595
    $fvalue    = 'XoopsFormTextRatings';
596
    $fsort     = 25;
597
    $fdeftype  = 7;
598
    $fdefvalue = '10, 2';
599
    $result = $xoopsDB->query(
600
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
601
    );
602
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
603
    if ($num_rows == 0) {
604
        $result = $xoopsDB->query(
605
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
606
        );
607
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
608
        if ($num_rows > 0) {
609
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value, $fe_sort, $fe_deftype, $fe_defvalue) = $xoopsDB->fetchRow($result);
610
            //add existing element at end of table
611
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}', '{$fe_sort}', '{$fe_deftype}', '{$fe_defvalue}')";
612
            $result = $xoopsDB->query($sql);
613
            // update table fields to new id of previous 26
614
            $newId = $xoopsDB->getInsertId();
615
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
616
            $result = $xoopsDB->query($sql);
617
            // update 26 to new element
618
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}', `fieldelement_sort` = '{$fsort}', `fieldelement_deftype` = '{$fdeftype}', `fieldelement_defvalue` = '{$fdefvalue}' WHERE `fieldelement_id` = {$fid};";
619
            $result = $xoopsDB->query($sql);
620
        } else {
621
            //add missing element
622
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}', '{$fsort}', '{$fdeftype}', '{$fdefvalue}')";
623
            $result = $xoopsDB->query($sql);
624
        }
625
    }
626
    // new form field text votes
627
    $fname     = 'TextVotes';
628
    $fid       = 27;
629
    $fvalue    = 'XoopsFormTextVotes';
630
    $fsort     = 26;
631
    $fdeftype  = 2;
632
    $fdefvalue = 10;
633
    $result = $xoopsDB->query(
634
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
635
    );
636
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
637
    if ($num_rows == 0) {
638
        $result = $xoopsDB->query(
639
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
640
        );
641
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
642
        if ($num_rows > 0) {
643
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value, $fe_sort, $fe_deftype, $fe_defvalue) = $xoopsDB->fetchRow($result);
644
            //add existing element at end of table
645
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}', '{$fe_sort}', '{$fe_deftype}', '{$fe_defvalue}')";
646
            $result = $xoopsDB->query($sql);
647
            // update table fields to new id of previous 27
648
            $newId = $xoopsDB->getInsertId();
649
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
650
            $result = $xoopsDB->query($sql);
651
            // update 27 to new element
652
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}', `fieldelement_sort` = '{$fsort}', `fieldelement_deftype` = '{$fdeftype}', `fieldelement_defvalue` = '{$fdefvalue}' WHERE `fieldelement_id` = {$fid};";
653
            $result = $xoopsDB->query($sql);
654
        } else {
655
            //add missing element
656
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}', '{$fsort}', '{$fdeftype}', '{$fdefvalue}')";
657
            $result = $xoopsDB->query($sql);
658
        }
659
    }
660
    // new form field text votes
661
    $fname     = 'TextReads';
662
    $fid       = 28;
663
    $fvalue    = 'XoopsFormTextReads';
664
    $fsort     = 27;
665
    $fdeftype  = 2;
666
    $fdefvalue = 10;
667
    $result = $xoopsDB->query(
668
        'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
669
    );
670
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
671
    if ($num_rows == 0) {
672
        $result = $xoopsDB->query(
673
            'SELECT * FROM ' . $xoopsDB->prefix('modulebuilder_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
674
        );
675
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
676
        if ($num_rows > 0) {
677
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value, $fe_sort, $fe_deftype, $fe_defvalue) = $xoopsDB->fetchRow($result);
678
            //add existing element at end of table
679
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}', '{$fe_sort}', '{$fe_deftype}', '{$fe_defvalue}')";
680
            $result = $xoopsDB->query($sql);
681
            // update table fields to new id of previous 28
682
            $newId = $xoopsDB->getInsertId();
683
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('modulebuilder_fields') . "`.`field_element` = '{$fid}';";
684
            $result = $xoopsDB->query($sql);
685
            // update 28 to new element
686
            $sql = 'UPDATE `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}', `fieldelement_sort` = '{$fsort}', `fieldelement_deftype` = '{$fdeftype}', `fieldelement_defvalue` = '{$fdefvalue}' WHERE `fieldelement_id` = {$fid};";
687
            $result = $xoopsDB->query($sql);
688
        } else {
689
            //add missing element
690
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('modulebuilder_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`, `fieldelement_sort`, `fieldelement_deftype`, `fieldelement_defvalue`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}', '{$fsort}', '{$fdeftype}', '{$fdefvalue}')";
691
            $result = $xoopsDB->query($sql);
692
        }
693
    }
694
695
    // update table 'modulebuilder_tables'
696
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_tables');
697
    $field   = 'table_reads';
698
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
699
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
700
    if (!$numRows) {
701
        $sql = "ALTER TABLE `$table` ADD `$field` TINYINT(1) NOT NULL DEFAULT '0' AFTER `table_rss`;";
702
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
703
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
704
            $module->setErrors("Error when adding '$field' to table '$table'.");
705
            $ret = false;
706
        }
707
    }
708
709
    // update table 'modulebuilder_settings'
710
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_settings');
711
    $field   = 'set_min_xoops';
712
    $sql = "ALTER TABLE `$table` CHANGE `$field` `$field` varchar(15) NOT NULL DEFAULT '1.0';";
713
    if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
714
        xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
715
        $module->setErrors("Error when changing '$field' in table '$table'.");
716
        $ret = false;
717
    }
718
719
    // update table 'modulebuilder_modules'
720
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_modules');
721
    $field   = 'mod_min_xoops';
722
    $sql = "ALTER TABLE `$table` CHANGE `$field` `$field` varchar(15) NOT NULL DEFAULT '1.0';";
723
    if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
724
        xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
725
        $module->setErrors("Error when changing '$field' in table '$table'.");
726
        $ret = false;
727
    }
728
729
    // update table 'modulebuilder_modules'
730
    $table   = $GLOBALS['xoopsDB']->prefix('modulebuilder_modules');
731
    $field   = 'mod_since';
732
    $sql = "ALTER TABLE `$table` CHANGE `$field` `$field` varchar(10) NOT NULL DEFAULT '1.0';";
733
    if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
734
        xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
735
        $module->setErrors("Error when changing '$field' in table '$table'.");
736
        $ret = false;
737
    }
738
739
    return $ret;
740
}
741
742
/**
743
 * function remove unnecessary index.php from files folder
744
 * which could be added by index_scan module
745
 *
746
 * @return bool
747
 */
748
function clean_index_files()
749
{
750
    $files = [];
751
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/commonfiles/admin/index.php';
752
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/commonfiles/assets/index.php';
753
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/commonfiles/class/index.php';
754
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/commonfiles/include/index.php';
755
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/commonfiles/language/index.php';
756
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/commonfiles/preloads/index.php';
757
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/ratingfiles/assets/index.php';
758
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/ratingfiles/class/index.php';
759
    $files[] = \XOOPS_ROOT_PATH . '/modules/modulebuilder/files/ratingfiles/templates/index.php';
760
761
    foreach($files as $file) {
762
        if (\file_exists($file)) {
763
            \unlink($file);
764
        }
765
    }
766
767
    return true;
768
}
769