Passed
Push — master ( 2ecc51...c1b656 )
by Michael
04:26 queued 02:02
created

efqDataFieldManager::getFieldValue()   F

Complexity

Conditions 38
Paths 1555

Size

Total Lines 144
Code Lines 121

Duplication

Lines 39
Ratio 27.08 %

Importance

Changes 0
Metric Value
cc 38
eloc 121
nc 1555
nop 3
dl 39
loc 144
rs 2
c 0
b 0
f 0

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
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      efqdirectory
16
 * @since
17
 * @author       Martijn Hertog (aka wtravel)
18
 * @author       XOOPS Development Team,
19
 */
20
class efqDataFieldManager extends XoopsFormElement
0 ignored issues
show
Bug introduced by
The type XoopsFormElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
{
22
    public $_options  = array();
23
    public $_multiple = false;
24
    public $_size;
25
26
    public $_height;
27
    public $_width;
28
    public $_src;
29
    public $_value = array();
30
31
    /**
32
     * Constructor
33
     */
34
    public function __construct()
35
    {
36
    }
37
38
    public function createField($title = '', $name = '', $fieldtype = '', $ext = '', $options = '', $value = '', $custom = '0', $customtitle = null)
39
    {
40
        global $form, $myts, $moddir;
41
        if ($customtitle == null) {
42
            $customtitle = '';
43
        }
44
        $multiple = false;
45
        if ($ext != '') {
46
            $ext_arr = explode('[|]', $ext);
47
            foreach ($ext_arr as $ext_item) {
48
                $ext_item_arr   = explode('[=]', $ext_item);
49
                $ext_item_name  = $ext_item_arr[0];
50
                $ext_item_value = $ext_item_arr[1];
51
52
                switch ($ext_item_name) {
53
                    case 'cols':
54
                        $cols = $ext_item_value;
55
                        break;
56
                    case 'rows':
57
                        $rows = $ext_item_value;
58
                        break;
59
                    case 'size':
60
                        $size = $ext_item_value;
61
                        break;
62
                    case 'maxsize':
63
                        $maxsize = $ext_item_value;
64
                        break;
65
                    case 'multiple':
66
                        $multiple = true;
67
                        $size     = 5;
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
68
                    case 'value':
69
                        if ($ext_item_value != '' and $value == '') {
70
                            $value = $ext_item_value;
71
                        }
72
                        break;
73
                }
74
            }
75
        }
76
77
        switch ($fieldtype) {
78
            case 'textbox':
79
                if ($custom == '1') {
80
                    $form_text_tray = new XoopsFormElementTray($title, '', $name);
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
81
                    $form_text_tray->addElement(new XoopsFormLabel('', '<table><tr><td>'));
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
82
                    $form_text_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_TITLE . '</b></td><td>', 'custom' . $name, 50, 250, $customtitle));
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
83
                    $form_text_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>'));
84
                    $form_text_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_VALUE . '</b></td><td>', $name, $size, $maxsize, $value));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $size does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $maxsize does not seem to be defined for all execution paths leading up to this point.
Loading history...
85
                    $form_text_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
86
                    $form->addElement($form_text_tray);
87
                } else {
88
                    $form->addElement(new XoopsFormText($title, $name, 50, 250, $myts->htmlSpecialChars($value)));
89
                }
90
                break;
91 View Code Duplication
            case 'textarea':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
                if ($custom == '1') {
93
                    $form_textarea_tray = new XoopsFormElementTray($title, '', $name);
94
                    $form_textarea_tray->addElement(new XoopsFormLabel('', '<table><tr><td>'));
95
                    $form_textarea_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_TITLE . '</b></td><td>', 'custom' . $name, 50, 250, $customtitle));
96
                    $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>'));
97
                    $form_textarea_tray->addElement(new XoopsFormTextArea('<b>' . _MD_CUSTOM_VALUE . '</b></td><td>', $name, $value, $rows, $cols));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rows does not seem to be defined for all execution paths leading up to this point.
Loading history...
Bug introduced by
The type XoopsFormTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Comprehensibility Best Practice introduced by
The variable $cols does not seem to be defined for all execution paths leading up to this point.
Loading history...
98
                    $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
99
                    $form->addElement($form_textarea_tray);
100
                } else {
101
                    $form->addElement(new XoopsFormTextArea($title, $name, $value, $rows, $cols));
102
                }
103
                break;
104
            case 'yesno':
105
                $form->addElement(new XoopsFormRadioyn($title, $name, $value, _YES, _NO));
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The type XoopsFormRadioyn was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
106
                break;
107 View Code Duplication
            case 'radio':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
                $options_arr = explode('[|]', $options);
109
                $form_radio  = new XoopsFormRadio($title, $name, $value, 1);
0 ignored issues
show
Bug introduced by
The type XoopsFormRadio was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
110
                foreach ($options_arr as $option) {
111
                    $form_radio->addOption($option, $option);
112
                }
113
                $form->addElement($form_radio);
114
                break;
115 View Code Duplication
            case 'checkbox':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
                $options_arr   = explode('[|]', $options);
117
                $form_checkbox = new XoopsFormCheckbox($title, $name, $value, 1);
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckbox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
118
                foreach ($options_arr as $option) {
119
                    $form_checkbox->addOption($option, $option);
120
                }
121
                $form->addElement($form_checkbox);
122
                break;
123
            case 'select':
124
                $options_arr = explode('[|]', $options);
125
                $value_arr   = explode('[|]', $value);
126
                $form_select = new XoopsFormSelect($title, $name, $value, $size, $multiple);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
127
                $form_select->addOption('-', '----');
128
                $form_select->setValue($value_arr);
129
                foreach ($options_arr as $key => $option) {
130
                    $form_select->addOption($option, $option);
131
                }
132
                $form->addElement($form_select);
133
                break;
134 View Code Duplication
            case 'dhtml':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
135
                if ($custom == '1') {
136
                    $form_dhtmlarea_tray = new XoopsFormElementTray($title, '', $name);
137
                    $form_dhtmlarea_tray->addElement(new XoopsFormLabel('', '<table><tr><td>'));
138
                    $form_dhtmlarea_tray->addElement(new XoopsFormText('<b>' . _MD_CUSTOM_TITLE . '</b></td><td>', 'custom' . $name, 50, 250, $customtitle));
139
                    $form_dhtmlarea_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>'));
140
                    $form_dhtmlarea_tray->addElement(new XoopsFormDhtmlTextArea('<b>' . _MD_CUSTOM_VALUE . '</b></td><td>', $name, $value, $rows, $cols));
0 ignored issues
show
Bug introduced by
The type XoopsFormDhtmlTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
141
                    $form_dhtmlarea_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
142
                    $form->addElement($form_dhtmlarea_tray);
143
                } else {
144
                    $form->addElement(new XoopsFormDhtmlTextArea($title, $name, $value, $rows, $cols));
145
                }
146
                break;
147
            case 'address':
148
                //Query all address fields associated with the address type that belongs to the locid.
149
                $addressfields = getAddressFields('0');
150
                $addressvalues = getAddressValues($value);
151
                $form->addElement(new XoopsFormLabel('', '<strong>' . $title . '</strong>'));
152
                $fieldtitles = array(
153
                    'address'  => _MD_DF_ADDRESS,
154
                    'address2' => _MD_DF_ADDRESS2,
155
                    'zip'      => _MD_DF_ZIP,
156
                    'postcode' => _MD_DF_POSTCODE,
157
                    'lat'      => _MD_DF_LAT,
158
                    'lon'      => _MD_DF_LON,
159
                    'phone'    => _MD_DF_PHONE,
160
                    'fax'      => _MD_DF_FAX,
161
                    'mobile'   => _MD_DF_MOBILE,
162
                    'city'     => _MD_DF_CITY,
163
                    'country'  => _MD_DF_COUNTRY,
164
                    'typename' => _MD_DF_TYPENAME,
165
                    'uselocyn' => _MD_DF_USELOCYN
166
                );
167
                foreach ($addressfields['addressfields'] as $field => $fieldvalue) {
168
                    $storedvalue = $addressvalues["$field"];
169
                    if ($fieldvalue == 1) {
170
                        $title = $fieldtitles["$field"];
171
                        $form->addElement(new XoopsFormText($title, $name . $field, 50, 250, $myts->htmlSpecialChars($storedvalue)));
172
                    }
173
                }
174
                $form->addElement(new XoopsFormHidden('submitaddress', '1'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
175
                $form->addElement(new XoopsFormHidden($name, $value));
176
                $form->addElement(new XoopsFormHidden('addrid', $value));
177
                break;
178
            case 'rating':
179
                $rating_options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
180
                $form_rating    = new XoopsFormSelect($title, $name, $value, 1);
181
                $form_rating->addOption('0', '----');
182
                foreach ($rating_options as $option) {
183
                    $form_rating->addOption($option, $option);
184
                }
185
                $form->addElement($form_rating);
186
                break;
187
            case 'date':
188
                $form->addElement(new XoopsFormText($title, $name, 10, 10, $value));
189
                break;
190
            case 'url':
191
                if ($value != '') {
192
                    $link = explode('|', $value);
193
                } else {
194
                    $link    = array();
195
                    $link[0] = '';
196
                    $link[1] = '';
197
                }
198
                $form_textarea_tray = new XoopsFormElementTray($title, '', $name);
199
                $form_textarea_tray->addElement(new XoopsFormLabel('', '<table><tr><td>'));
200
                $form_textarea_tray->addElement(new XoopsFormText('<b>' . _MD_FIELDNAMES_URL_TITLE . '</b></td><td>', 'url_title' . $name, 50, 250, $link[1]));
201
                $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr><tr><td>'));
202
                $form_textarea_tray->addElement(new XoopsFormText('<b>' . _MD_FIELDNAMES_URL_LINK . '</b></td><td>', 'url_link' . $name, 50, 250, $link[0]));
203
                $form_textarea_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
204
                $form->addElement($form_textarea_tray);
205
                break;
206
            default:
207
                echo $fieldtype . ' is an unknown field type.';
208
                break;
209
        }
210
    }
211
212
    public function getFieldValue($fieldtype = '', $options = '', $value = 0)
213
    {
214
        global $form, $myts, $moddir;
215
        switch ($fieldtype) {
216
            case 'textbox':
217
                return $myts->htmlSpecialChars($value);
218
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
219
            case 'yesno':
220
                if ($value == '1') {
221
                    return _YES;
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
222
                } else {
223
                    return _NO;
0 ignored issues
show
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
224
                }
225
                break;
226
            case 'radio':
227
                return $myts->htmlSpecialChars($value);
228
                break;
229
            case 'select':
230
                return $myts->htmlSpecialChars($value);
231
            case 'dhtml':
232
                return $myts->displayTarea($value);
233 View Code Duplication
            case 'rating':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
234
                $xoops_url = XOOPS_URL;
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
235
                switch ($value) {
236
                    case 1:
237
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_1.gif";
238
                        break;
239
                    case 2:
240
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_2.gif";
241
                        break;
242
                    case 3:
243
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_3.gif";
244
                        break;
245
                    case 4:
246
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_4.gif";
247
                        break;
248
                    case 5:
249
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_5.gif";
250
                        break;
251
                    case 6:
252
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_6.gif";
253
                        break;
254
                    case 7:
255
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_7.gif";
256
                        break;
257
                    case 8:
258
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_8.gif";
259
                        break;
260
                    case 9:
261
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_9.gif";
262
                        break;
263
                    case 10:
264
                        $src = "$xoops_url/modules/$moddir/assets/images/rating_10.gif";
265
                        break;
266
                    default:
267
                        $src = '';
268
                }
269
                $rating = "<img src=\"$src\">";
270
271
                return $rating;
272
            case 'address':
273
                $fieldtitles   = array(
274
                    'address'  => _MD_DF_ADDRESS,
275
                    'address2' => _MD_DF_ADDRESS2,
276
                    'zip'      => _MD_DF_ZIP,
277
                    'postcode' => _MD_DF_POSTCODE,
278
                    'lat'      => _MD_DF_LAT,
279
                    'lon'      => _MD_DF_LON,
280
                    'phone'    => _MD_DF_PHONE,
281
                    'fax'      => _MD_DF_FAX,
282
                    'mobile'   => _MD_DF_MOBILE,
283
                    'city'     => _MD_DF_CITY,
284
                    'country'  => _MD_DF_COUNTRY
285
                );
286
                $addressfields = getAddressFields('0');
287
                $addressvalues = getAddressValues($value);
288
                $address       = '';
289
290
                foreach ($addressfields['addressfields'] as $field => $fieldvalue) {
291
                    $storedvalue = $addressvalues["$field"];
292
                    if ($fieldvalue == '1' && $storedvalue != '') {
293
                        $title = $fieldtitles["$field"];
0 ignored issues
show
Unused Code introduced by
The assignment to $title is dead and can be removed.
Loading history...
294
295
                        switch ($field) {
296
                            case 'address':
297
                                $street = $myts->htmlSpecialChars($storedvalue);
298
                                break;
299
                            case 'city':
300
                                $city = $myts->htmlSpecialChars($storedvalue);
301
                                break;
302
                            case 'zip':
303
                                $zip = $myts->htmlSpecialChars($storedvalue);
304
                                break;
305
                            case 'state':
306
                                $state = $myts->htmlSpecialChars($storedvalue);
307
                                break;
308
                            case 'country':
309
                                $country = $myts->htmlSpecialChars($storedvalue);
310
                                break;
311
                            default:
312
                                break;
313
                        }
314
                        $address .= $myts->htmlSpecialChars($storedvalue) . '<br>';
315
                    }
316
                }
317
                if (!isset($street)) {
318
                    $street = '';
319
                }
320
                if (!isset($city)) {
321
                    $city = '';
322
                }
323
                if (!isset($zip)) {
324
                    $zip = '';
325
                }
326
                if (!isset($state)) {
327
                    $state = '';
328
                }
329
                if (!isset($country)) {
330
                    $country = '';
331
                }
332
                if ($country == 'United States') {
333
                    $countrycode = 'us';
334
                } elseif ($country == 'Canada') {
335
                    $countrycode = 'ca';
336
                }
337
                if (isset($countrycode) && isset($city) && isset($street)) {
338
                    $address .= '<form name=mapForm2 action="http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps" target="_new" method=get>
339
                    <input type="hidden" name="addr" value="' . $street . '">
340
                    <input type="hidden" name="csz" value="' . $city . ', ' . $state . ' ' . $zip . '">
341
                    <input type="hidden" name="country" value="' . $countrycode . '">
342
                    <input type=hidden name=srchtype value=a>
343
                    <input type=submit name="getmap" value="Yahoo Map">
344
                    </form>';
345
                }
346
347
                return $address;
348
            case 'url':
349
                $link = explode('|', $value);
350
351
                return '<a href="' . $myts->htmlSpecialChars($link[0]) . '" title="' . $myts->htmlSpecialChars($link[1]) . '">' . $myts->htmlSpecialChars($link[0]) . '</a>';
352
                break;
353
            default:
354
                return $myts->htmlSpecialChars($value);
355
                break;
356
        }
357
    }
358
359
    public function createSearchField($title = '', $name = '', $fieldtype = '', $ext = '', $options = '', $value = '', $custom = '0', $customtitle = null)
360
    {
361
        global $form, $myts;
362
363
        switch ($fieldtype) {
364
            case 'textbox':
365
                $this->createSearchField_text($title, $name, $value, $options);
366
                break;
367
            case 'textarea':
368
                $this->createSearchField_text($title, $value, $options);
369
                break;
370
            case 'yesno':
371
                $form->addElement(new XoopsFormRadioyn($title, $name, '', _YES, _NO));
0 ignored issues
show
Bug introduced by
The constant _YES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _NO was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
372
                break;
373
            case 'radio':
374
                $this->createSearchField_select($title, $name, $value, $options);
375
                break;
376
            case 'checkbox':
377
                $this->createSearchField_checkbox($title, $name, $value, $options);
378
                break;
379
            case 'select':
380
                $this->createSearchField_checkbox($title, $name, $value, $options);
381
                break;
382
            case 'dhtml':
383
                $this->createSearchField_text($title, $name, $value, $options);
384
                break;
385
            case 'address':
386
                //Query all address fields associated with the address type that belongs to the locid.
387
                /* $addressfields = getAddressFields('0');
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
388
                $fieldtitles = array('address' => _MD_DF_ADDRESS, 'address2' => _MD_DF_ADDRESS2, 'zip' => _MD_DF_ZIP, 'postcode' => _MD_DF_POSTCODE, 'lat' => _MD_DF_LAT, 'lon' => _MD_DF_LON, 'phone' => _MD_DF_PHONE, 'fax' => _MD_DF_FAX, 'mobile' => _MD_DF_MOBILE, 'city' => _MD_DF_CITY, 'country' => _MD_DF_COUNTRY, 'typename' => _MD_DF_TYPENAME);
389
                $form->addElement(new XoopsFormLabel("", "<strong>".$title."</strong>"));
390
                foreach ($addressfields['addressfields'] as $field => $fieldvalue) {
391
                if ($fieldvalue == 1) {
392
                $title = $fieldtitles["$field"];
393
                $form->addElement(new XoopsFormText($title, $name.$field, 50, 250, ""));
394
                }
395
                }
396
                $form->addElement(new XoopsFormHidden("submitaddress","1"));
397
                $form->addElement(new XoopsFormHidden($name, $value));
398
                $form->addElement(new XoopsFormHidden("addrid", $value)); */
399
                break;
400
            case 'rating':
401
                $this->createSearchField_rating($title, $name, $value, $options);
402
                break;
403
            case 'date':
404
                $this->createSearchField_text($title, $name, $value, $options);
405
                break;
406
            case 'url':
407
                $this->createSearchField_text($title, $name, $value, $options);
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment if this fall-through is intended.
Loading history...
408
            default:
409
                echo $fieldtype . ' geen bekend veldtype ';
410
                break;
411
        }
412
    }
413
414
    public function createSearchField_text($title = '', $name = '', $value = '', $options = '')
415
    {
416
        global $form, $myts;
417
        $options_arr_constr = array(
418
            'equal'      => _MD_EQUAL_TO,
419
            'notequal'   => _MD_NOT_EQUAL_TO,
420
            'contains'   => _MD_CONTAINS,
421
            'begins'     => _MD_BEGINSWITH,
422
            'ends'       => _MD_ENDSWITH,
423
            'notcontain' => _MD_NOTCONTAIN
424
        );
425
        $form_tray          = new XoopsFormElementTray($title, '', $name);
426
        $form_tray->addElement(new XoopsFormLabel('', '<table><tr><td width="150">'));
427
        $form_select_constr = new XoopsFormSelect('', $name . 'constr', $value, 1);
428
        //$form_select->addOption('0', '----');
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
429
        foreach ($options_arr_constr as $optionname => $option) {
430
            $form_select_constr->addOption($optionname, $option);
431
        }
432
        $form_tray->addElement($form_select_constr);
433
        $form_tray->addElement(new XoopsFormLabel('', '</td><td>'));
434
        $form_tray->addElement(new XoopsFormText('', $name, 50, 250, ''));
435
        $form_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
436
        $form->addElement($form_tray);
437
    }
438
439
    public function createSearchField_checkbox($title = '', $name = '', $value = '', $options = '')
440
    {
441
        global $form, $myts;
442
        $options_arr   = explode('[|]', $options);
443
        $countoptions  = count($options_arr) + 1;
0 ignored issues
show
Unused Code introduced by
The assignment to $countoptions is dead and can be removed.
Loading history...
444
        $form_checkbox = new XoopsFormCheckBox($title, $name, $value);
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
445
        foreach ($options_arr as $optionname) {
446
            $form_checkbox->addOption($optionname, $optionname);
447
        }
448
        $form->addElement($form_checkbox);
449
    }
450
451
    public function createSearchField_select($title = '', $name = '', $value = '', $options = '')
452
    {
453
        global $form, $myts;
454
        $options_arr        = explode('[|]', $options);
455
        $options_arr_constr = array('equal' => _MD_EQUAL_TO, 'notequal' => _MD_NOT_EQUAL_TO);
456
        $form_tray          = new XoopsFormElementTray($title, '', $name);
457
        $form_tray->addElement(new XoopsFormLabel('', '<table><tr><td width="150">'));
458
        $form_select_constr = new XoopsFormSelect('', $name, $value, 1);
459
        foreach ($options_arr_constr as $option) {
460
            $form_select_constr->addOption($option, $option);
461
        }
462
        $form_tray->addElement($form_select_constr);
463
        $form_tray->addElement(new XoopsFormLabel('', '</td><td>'));
464
        $countoptions = count($options_arr) + 1;
465
        if ($countoptions >= 5) {
466
            $selectformsize = 5;
467
        } else {
468
            $selectformsize = $countoptions;
469
        }
470
        $form_select = new XoopsFormSelect('', $name, $value, $selectformsize);
471
        $form_select->setExtra(" multiple='multiple'");
472
        $form_select->addOption('0', '----');
473
        foreach ($options_arr as $option) {
474
            $form_select->addOption($option, $option);
475
        }
476
        $form_tray->addElement($form_select);
477
        $form_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
478
        $form->addElement($form_tray);
479
    }
480
481
    public function createSearchField_rating2($title = '', $name = '', $value = '', $options = '')
482
    {
483
        global $form, $myts;
484
        $options_arr    = explode('[|]', $options);
0 ignored issues
show
Unused Code introduced by
The assignment to $options_arr is dead and can be removed.
Loading history...
485
        $rating_options = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
486
        $form_rating    = new XoopsFormSelect($title, $name, $value, 1);
487
        $form_rating->addOption('0', '----');
488
        foreach ($rating_options as $option) {
489
            $form_rating->addOption($option, $option);
490
        }
491
        $form->addElement($form_rating);
492
    }
493
494
    public function createSearchField_rating($title = '', $name = '', $value = '', $options = '')
495
    {
496
        global $form, $myts;
497
        $options_arr        = explode('[|]', $options);
0 ignored issues
show
Unused Code introduced by
The assignment to $options_arr is dead and can be removed.
Loading history...
498
        $rating_options     = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
499
        $options_arr_constr = array(
500
            'equal'    => _MD_EQUAL_TO,
501
            'notequal' => _MD_NOT_EQUAL_TO,
502
            'smaller'  => _MD_SMALLER_THAN,
503
            'bigger'   => _MD_GREATER_THAN
504
        );
505
        $form_tray          = new XoopsFormElementTray($title, '', $name);
506
        $form_tray->addElement(new XoopsFormLabel('', '<table><tr><td width="150">'));
507
        $form_select_constr = new XoopsFormSelect('', $name . 'constr', $value, 1);
508
        foreach ($options_arr_constr as $optionname => $option) {
509
            $form_select_constr->addOption($optionname, $option);
510
        }
511
        $form_tray->addElement($form_select_constr);
512
        $form_tray->addElement(new XoopsFormLabel('', '</td><td>'));
513
        $countoptions = count($rating_options) + 1;
514
        if ($countoptions >= 5) {
515
            $selectformsize = 5;
516
        } else {
517
            $selectformsize = $rating_options;
518
        }
519
        $form_select = new XoopsFormSelect('', $name, $value, $selectformsize);
520
        //$form_select->setExtra(" multiple='multiple'");
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
521
        $form_select->addOption('0', '----');
522
        foreach ($rating_options as $option) {
523
            $form_select->addOption($option, $option);
524
        }
525
        $form_tray->addElement($form_select);
526
        $form_tray->addElement(new XoopsFormLabel('', '</td></tr></table>'));
527
        $form->addElement($form_tray);
528
    }
529
530
    public function getWidth()
531
    {
532
        return $this->_width;
533
    }
534
535
    public function getHeight()
536
    {
537
        return $this->_height;
538
    }
539
540
    public function getSrc()
541
    {
542
        return $this->_src;
543
    }
544
545
    /*
546
    * Are multiple selections allowed?
547
    *
548
    * @return bool
549
    */
550
    public function isMultiple()
551
    {
552
        return $this->_multiple;
553
    }
554
555
    /**
556
     * Get the size
557
     *
558
     * @return int
559
     */
560
    public function getSize()
561
    {
562
        return $this->_size;
563
    }
564
565
    /**
566
     * Get an array of pre-selected values
567
     *
568
     * @return array
569
     */
570
    public function getValue()
571
    {
572
        return $this->_value;
573
    }
574
575
    /**
576
     * Set pre-selected values
577
     *
578
     * @param $value mixed
579
     */
580 View Code Duplication
    public function setValue($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
581
    {
582
        if (is_array($value)) {
583
            foreach ($value as $v) {
584
                $this->_value[] = $v;
585
            }
586
        } else {
587
            $this->_value[] = $value;
588
        }
589
    }
590
591
    /**
592
     * Add an option
593
     *
594
     * @param string $value "value" attribute
595
     * @param string $name  "name" attribute
596
     */
597 View Code Duplication
    public function addOption($value, $name = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
598
    {
599
        if ($name != '') {
600
            $this->_options[$value] = $name;
601
        } else {
602
            $this->_options[$value] = $value;
603
        }
604
    }
605
606
    /**
607
     * Add multiple options
608
     *
609
     * @param array $options Associative array of value->name pairs
610
     */
611
    public function addOptionArray($options)
612
    {
613
        if (is_array($options)) {
614
            foreach ($options as $k => $v) {
615
                $this->addOption($k, $v);
616
            }
617
        }
618
    }
619
620
    /**
621
     * Get all options
622
     *
623
     * @return array   Associative array of value->name pairs
624
     */
625
    public function getOptions()
626
    {
627
        return $this->_options;
628
    }
629
630
    /**
631
     * Prepare HTML for output
632
     *
633
     * @return string  HTML
634
     */
635
    public function render()
636
    {
637
        $ret = "<img src='" . $this->getSrc() . '\' width=\'' . $this->getWidth() . '\'  height=\'' . $this->getHeight() . '\'';
638
        $ret .= '>';
639
640
        return $ret;
641
    }
642
}
643