tdmcreate_check_db()   F
last analyzed

Complexity

Conditions 21
Paths > 20000

Size

Total Lines 283
Code Lines 195

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 21
eloc 195
nc 59049
nop 1
dl 0
loc 283
rs 0
c 1
b 0
f 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
 * tdmcreate module.
15
 *
16
 * @copyright       XOOPS Project (https://xoops.org)
17
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
18
 *
19
 * @since           2.5.0
20
 *
21
 * @author          Txmod Xoops http://www.txmodxoops.org
22
 *
23
 * @param mixed      $module
24
 * @param null|mixed $prev_version
25
 */
26
27
/**
28
 * @param      $module
29
 * @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...
30
 *
31
 * @return bool|null
32
 */
33
function xoops_module_update_tdmcreate(&$module, $prev_version = null)
34
{
35
36
    $ret = null;
37
    if ($prev_version < 191) {
38
        update_tdmcreate_v191($module);
39
    }
40
41
	tdmcreate_check_db($module);
42
	
43
	//check upload directory
44
	include_once __DIR__ . '/install.php';
45
    xoops_module_install_tdmcreate($module);
46
	
47
    $errors = $module->getErrors();
48
    if (!empty($errors)) {
49
        print_r($errors);
50
    }
51
52
    return $ret;
53
54
}
55
56
// irmtfan bug fix: solve templates duplicate issue
57
/**
58
 * @param $module
59
 *
60
 * @return bool
61
 */
62
function update_tdmcreate_v191(&$module)
63
{
64
    global $xoopsDB;
65
    $result = $xoopsDB->query(
66
        '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'
67
    );
68
    $tplids = [];
69
    while (list($tplid) = $xoopsDB->fetchRow($result)) {
70
        $tplids[] = $tplid;
71
    }
72
    if (count($tplids) > 0) {
73
        $tplfileHandler  = xoops_getHandler('tplfile');
74
        $duplicate_files = $tplfileHandler->getObjects(
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

74
        /** @scrutinizer ignore-call */ 
75
        $duplicate_files = $tplfileHandler->getObjects(
Loading history...
75
            new \Criteria('tpl_id', '(' . implode(',', $tplids) . ')', 'IN')
76
        );
77
78
        if (count($duplicate_files) > 0) {
79
            foreach (array_keys($duplicate_files) as $i) {
80
                $tplfileHandler->delete($duplicate_files[$i]);
81
            }
82
        }
83
    }
84
    $sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'";
85
    if (!$result = $xoopsDB->queryF($sql)) {
86
        xoops_error($xoopsDB->error() . '<br />' . $sql);
87
88
        return false;
89
    }
90
    $ret = [];
91
    while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
92
        $ret[] = $myrow;
93
    }
94
    if (!empty($ret)) {
95
        $module->setErrors(
96
            "'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."
97
        );
98
99
        return true;
100
    }
101
    $sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )';
102
    if (!$result = $xoopsDB->queryF($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
103
        xoops_error($xoopsDB->error() . '<br />' . $sql);
104
        $module->setErrors(
105
            "'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."
106
        );
107
108
        return false;
109
    }
110
111
    return true;
112
}
113
// irmtfan bug fix: solve templates duplicate issue
114
115
/**
116
 * function to add code for db checking
117
 * @param $module
118
 *
119
 * @return bool
120
 */
121
function tdmcreate_check_db($module)
122
{
123
    $ret = true;
124
	//insert here code for database check
125
    global $xoopsDB;
126
127
    // new form field SelectStatus
128
    $fname  = 'SelectStatus';
129
    $fid    = 16;
130
    $fvalue = 'XoopsFormSelectStatus';
131
    $result = $xoopsDB->query(
132
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
133
    );
134
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
135
    if ($num_rows == 0) {
136
        $result = $xoopsDB->query(
137
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
138
        );
139
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
140
        if ($num_rows > 0) {
141
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
142
            //add existing element at end of table
143
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
144
            $result = $xoopsDB->query($sql);
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
145
            // update table fields to new id of previous 16
146
            $newId = $xoopsDB->getInsertId();
147
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
148
            $result = $xoopsDB->query($sql);
149
            // update 16 to new element
150
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
151
            $result = $xoopsDB->query($sql);
152
        } else {
153
            //add missing element
154
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
155
            $result = $xoopsDB->query($sql);
156
        }
157
    }
158
159
    // new form field Password
160
    $fname  = 'Password';
161
    $fid    = 17;
162
    $fvalue = 'XoopsFormPassword';
163
    $result = $xoopsDB->query(
164
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
165
    );
166
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
167
    if ($num_rows == 0) {
168
        $result = $xoopsDB->query(
169
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
170
        );
171
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
172
        if ($num_rows > 0) {
173
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
174
            //add existing element at end of table
175
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
176
            $result = $xoopsDB->query($sql);
177
            // update table fields to new id of previous 16
178
            $newId = $xoopsDB->getInsertId();
179
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
180
            $result = $xoopsDB->query($sql);
181
            // update 16 to new element
182
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
183
            $result = $xoopsDB->query($sql);
184
        } else {
185
            //add missing element
186
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
187
            $result = $xoopsDB->query($sql);
188
        }
189
    }
190
191
    // new form field SelectCountry
192
    $fname  = 'SelectCountry';
193
    $fid    = 18;
194
    $fvalue = 'XoopsFormSelectCountry';
195
    $result = $xoopsDB->query(
196
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
197
    );
198
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
199
    if ($num_rows == 0) {
200
        $result = $xoopsDB->query(
201
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
202
        );
203
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
204
        if ($num_rows > 0) {
205
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
206
            //add existing element at end of table
207
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
208
            $result = $xoopsDB->query($sql);
209
            // update table fields to new id of previous 16
210
            $newId = $xoopsDB->getInsertId();
211
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
212
            $result = $xoopsDB->query($sql);
213
            // update 16 to new element
214
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
215
            $result = $xoopsDB->query($sql);
216
        } else {
217
            //add missing element
218
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
219
            $result = $xoopsDB->query($sql);
220
        }
221
    }
222
223
    // new form field SelectLanguage
224
    $fname  = 'SelectLang';
225
    $fid    = 19;
226
    $fvalue = 'XoopsFormSelectLang';
227
    $result = $xoopsDB->query(
228
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
229
    );
230
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
231
    if ($num_rows == 0) {
232
        $result = $xoopsDB->query(
233
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
234
        );
235
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
236
        if ($num_rows > 0) {
237
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
238
            //add existing element at end of table
239
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
240
            $result = $xoopsDB->query($sql);
241
            // update table fields to new id of previous 16
242
            $newId = $xoopsDB->getInsertId();
243
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
244
            $result = $xoopsDB->query($sql);
245
            // update 16 to new element
246
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
247
            $result = $xoopsDB->query($sql);
248
        } else {
249
            //add missing element
250
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
251
            $result = $xoopsDB->query($sql);
252
        }
253
    }
254
255
    // new form field Radio
256
    $fname  = 'Radio';
257
    $fid    = 20;
258
    $fvalue = 'XoopsFormRadio';
259
    $result = $xoopsDB->query(
260
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
261
    );
262
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
263
    if ($num_rows == 0) {
264
        $result = $xoopsDB->query(
265
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
266
        );
267
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
268
        if ($num_rows > 0) {
269
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
270
            //add existing element at end of table
271
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
272
            $result = $xoopsDB->query($sql);
273
            // update table fields to new id of previous 16
274
            $newId = $xoopsDB->getInsertId();
275
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
276
            $result = $xoopsDB->query($sql);
277
            // update 16 to new element
278
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
279
            $result = $xoopsDB->query($sql);
280
        } else {
281
            //add missing element
282
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
283
            $result = $xoopsDB->query($sql);
284
        }
285
    }
286
287
    // new form field DateTime
288
    $fname  = 'DateTime';
289
    $fid    = 21;
290
    $fvalue = 'XoopsFormDateTime';
291
    $result = $xoopsDB->query(
292
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
293
    );
294
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
295
    if ($num_rows == 0) {
296
        $result = $xoopsDB->query(
297
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
298
        );
299
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
300
        if ($num_rows > 0) {
301
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
302
            //add existing element at end of table
303
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
304
            $result = $xoopsDB->query($sql);
305
            // update table fields to new id of previous 16
306
            $newId = $xoopsDB->getInsertId();
307
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
308
            $result = $xoopsDB->query($sql);
309
            // update 16 to new element
310
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
311
            $result = $xoopsDB->query($sql);
312
        } else {
313
            //add missing element
314
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
315
            $result = $xoopsDB->query($sql);
316
        }
317
    }
318
319
    // new form field DateTime
320
    $fname  = 'SelectCombo';
321
    $fid    = 22;
322
    $fvalue = 'XoopsFormSelectCombo';
323
    $result = $xoopsDB->query(
324
        'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_name = '{$fname}'"
325
    );
326
    $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
327
    if ($num_rows == 0) {
328
        $result = $xoopsDB->query(
329
            'SELECT * FROM ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " as fe WHERE fe.fieldelement_id ={$fid}"
330
        );
331
        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result);
332
        if ($num_rows > 0) {
333
            list($fe_id, $fe_mid, $fe_tid, $fe_name, $fe_value) = $xoopsDB->fetchRow($result);
334
            //add existing element at end of table
335
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '{$fe_mid}', '{$fe_tid}', '{$fe_name}', '{$fe_value}')";
336
            $result = $xoopsDB->query($sql);
337
            // update table fields to new id of previous 16
338
            $newId = $xoopsDB->getInsertId();
339
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fields') . "` SET `field_element` = '{$newId}' WHERE `" . $xoopsDB->prefix('tdmcreate_fields') . "`.`field_element` = '{$fid}';";
340
            $result = $xoopsDB->query($sql);
341
            // update 16 to new element
342
            $sql = 'UPDATE `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` SET `fieldelement_mid` = '0', `fieldelement_tid` = '0', `fieldelement_name` = '{$fname}', `fieldelement_value` = '{$fvalue}' WHERE `fieldelement_id` = {$fid};";
343
            $result = $xoopsDB->query($sql);
344
        } else {
345
            //add missing element
346
            $sql = 'INSERT INTO `' . $xoopsDB->prefix('tdmcreate_fieldelements') . "` (`fieldelement_id`, `fieldelement_mid`, `fieldelement_tid`, `fieldelement_name`, `fieldelement_value`) VALUES (NULL, '0', '0', '{$fname}', '{$fvalue}')";
347
            $result = $xoopsDB->query($sql);
348
        }
349
    }
350
351
    // update table 'tdmcreate_fieldelements'
352
    $table   = $GLOBALS['xoopsDB']->prefix('tdmcreate_fieldelements');
353
    $field   = 'fieldelement_sort';
354
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
355
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
356
    if (!$numRows) {
357
        $sql = "ALTER TABLE `$table` ADD `$field` INT(8) NOT NULL DEFAULT '0' AFTER `fieldelement_value`;";
358
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
359
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
360
            $module->setErrors("Error when adding '$field' to table '$table'.");
361
            $ret = false;
362
        }
363
    }
364
365
    // update table 'tdmcreate_fieldelements'
366
    $table   = $GLOBALS['xoopsDB']->prefix('tdmcreate_fieldelements');
367
    $field   = 'fieldelement_deftype';
368
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
369
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
370
    if (!$numRows) {
371
        $sql = "ALTER TABLE `$table` ADD `$field` INT(10) NOT NULL DEFAULT '0' AFTER `fieldelement_sort`;";
372
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
373
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
374
            $module->setErrors("Error when adding '$field' to table '$table'.");
375
            $ret = false;
376
        }
377
    }
378
379
    // update table 'tdmcreate_fieldelements'
380
    $table   = $GLOBALS['xoopsDB']->prefix('tdmcreate_fieldelements');
381
    $field   = 'fieldelement_defvalue';
382
    $check   = $GLOBALS['xoopsDB']->queryF('SHOW COLUMNS FROM `' . $table . "` LIKE '" . $field . "'");
383
    $numRows = $GLOBALS['xoopsDB']->getRowsNum($check);
384
    if (!$numRows) {
385
        $sql = "ALTER TABLE `$table` ADD `$field` int(10) NULL DEFAULT '0' AFTER `fieldelement_deftype`;";
386
        if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) {
387
            xoops_error($GLOBALS['xoopsDB']->error() . '<br>' . $sql);
388
            $module->setErrors("Error when adding '$field' to table '$table'.");
389
            $ret = false;
390
        }
391
    }
392
393
    // set default values for form elements
394
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '255' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in(2, 10, 11, 12, 13, 14, 17)");
395
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 15, `fieldelement_defvalue` = '0' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in (3, 4)");
396
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 2, `fieldelement_defvalue` = '10' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in(5, 7, 8, 15, 20, 21, 22)");
397
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 2, `fieldelement_defvalue` = '1' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in(6, 16)");
398
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '7' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in(9)");
399
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '3' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in(18)");
400
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 14, `fieldelement_defvalue` = '100' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_id` in(19)");
401
    $result = $xoopsDB->query('UPDATE ' . $xoopsDB->prefix('tdmcreate_fieldelements') . " SET `fieldelement_deftype` = 2, `fieldelement_defvalue` = '10' WHERE `xc_tdmcreate_fieldelements`.`fieldelement_mid` > 0");
402
403
    return $ret;
404
}
405