Form::radio()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 4
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Smallworld;
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * SmallWorld
17
 *
18
 * @package      \XoopsModules\Smallworld
19
 * @license      GNU GPL (https://www.gnu.org/licenses/gpl-2.0.html/)
20
 * @copyright    The XOOPS Project (https://xoops.org)
21
 * @copyright    2011 Culex
22
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
23
 * @link         https://github.com/XoopsModules25x/smallworld
24
 * @since        1.0
25
 */
26
27
 /**
28
 * Form Class
29
 *
30
 * creates HTML entities to display in forms
31
 *
32
 */
33
class Form
34
{
35
    /**
36
     * Create a dropdown select
37
     *
38
     * @param string $name
39
     * @param array  $options
40
     * @param string $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
41
     * @param string $sep (optional)
42
     * @return string
43
     */
44
    public function dropdown($name, array $options, $selected = null, $sep = '<br>')
45
    {
46
        $dropdown = "<select name='{$name}' id='{$name}'>\n";
47
        foreach ($options as $key => $option) {
48
            $select    = $selected == $key ? ' selected' : '';
0 ignored issues
show
Unused Code introduced by
$select is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
            $dropdown .= "<option value='{$key}'{$selected}>{$option}</option>\n";
50
        }
51
        $dropdown .= "</select>{$sep}";
52
53
        return $dropdown;
54
    }
55
56
    /**
57
     * Create a radio select
58
	 *
59
     * @param string $name
60
     * @param array  $options
61
     * @param string $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
62
     * @param string $sep (optional)
63
     * @return string
64
     */
65
    public function radio($name, array $options, $selected = null, $sep = '<br>')
66
    {
67
        $selected = $selected;
0 ignored issues
show
Bug introduced by
Why assign $selected to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
68
        $form     = '';
69
        $i = 0;
70
        foreach ($options as $value => $option) {
71
            $select = $selected == $value ? ' checked' : '';
72
            $form   .= "<label for='{$name}-{$i}'><input type='radio' name='{$name}[]' id='{$name}-{$i}' value='{$value}'{$select}> "
73
            . "{$option}</label>{$sep}\n";
74
//            $form   .= "<input type='checkbox' name='{$name}[]' id='{$name}-{$i}' value='{$value}'{$select}> "
75
//            . "<label for='{$name}-{$i}'>{$option}</label>{$sep}\n";
76
            $i++;
77
        }
78
79
        return $form;
80
    }
81
82
    /**
83
	 * Create a HTML checkbox element
84
	 *
85
     * @param string $name
86
     * @param array  $options
87
     * @param array  $valuearray
88
     * @param string $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
89
     * @param string $sep (optional)
90
     * @return string
91
     */
92
    public function retrieveRadio($name, $options, $valuearray, $selected = null, $sep = '<br>')
0 ignored issues
show
Unused Code introduced by
The parameter $selected is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        $form = '';
95
        $a    = count($options) - 1;
96
        for ($i = 0; $i <= $a; ++$i) {
97
            if (in_array($i, $valuearray)) {
98
                $form .= "<input type='checkbox' id='{$name}-{$i}' name='{$name}[]' value='{$i}' checked> "
99
                . "<label for='{$name}-{$i}'>{$options[$i]}</label>{$sep}";
100
            } else {
101
                $form .= "<input type='checkbox' id='{$name}-{$i}' name='{$name}[]' value='{$i}'> "
102
                . "<label for='{$name}-{$i}'>{$options[$i]}</label>{$sep}";
103
            }
104
        }
105
106
        return $form;
107
    }
108
109
    /**
110
	 * Create a HTML text input element
111
	 *
112
     * @param string $name
113
     * @param string $id
114
     * @param string $class
115
     * @param int    $size   (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $size not be integer|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
116
     * @param string $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
117
     * @return string
118
     */
119 View Code Duplication
    public function input($name, $id, $class, $size = null, $preset = null)
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...
120
    {
121
        $s    = $size ?: '50px';
122
        $data = "<input type='text' size='" . $s . "' name='" . $name . "' id='" . $id . "' class='" . $class . "' value='" . $preset . "'>";
123
124
        return $data;
125
    }
126
127
    /**
128
	 * Create a HTML hidden element
129
	 *
130
     * @param string $name
131
     * @param string $id
132
     * @param string $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
133
     * @return string
134
     */
135
    public function hidden($name, $id, $preset = null)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
136
    {
137
        $data = "<input type='hidden' name='" . $name . "' value='" . $preset . "' >";
138
139
        return $data;
140
    }
141
142
    /**
143
	 * Returns simple text string
144
	 *
145
     * @param string $value
146
     * @return string
147
     */
148
    public function simpleText($value)
149
    {
150
        $data = $value;
151
152
        return $data;
153
    }
154
155
    /**
156
	 * Create a HTML select (dropdown) element
157
	 *
158
     * @param string  $class
159
     * @param string  $name
160
     * @param         $name2
161
     * @param string  $rel
162
     * @param array   $options
163
     * @param string  $textmore
164
     * @param string  $selected (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
165
     * @param string  $preset   (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
166
     * @return string
167
     */
168
    public function dropdown_add($class, $name, $name2, $rel, array $options, $textmore, $selected = null, $preset = null)
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
169
    {
170
        $dropdown = '<span id="' . $name . '"><input type="text" name="' . $name2 . '[]" value="' . $preset . '">';
171
        $dropdown .= '<select class="smallworld_select" name="' . $name . '[]" id="' . $name . '">' . '<br>';
172 View Code Duplication
        foreach ($options as $key => $option) {
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...
173
            $select   = $selected == $key ? ' selected' : null;
174
            $dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
175
        }
176
        $dropdown .= '</select></span>';
177
178
        return $dropdown;
179
    }
180
181
    /**
182
     * @param string  $class
183
     * @param string  $name
184
     * @param         $name2
185
     * @param string  $rel
186
     * @param int     $size
187
     * @param string  $textmore
188
     * @param string  $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
189
     * @param string  $id     (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $id not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
190
     * @return string
191
     */
192 View Code Duplication
    public function input_add($class, $name, $name2, $rel, $size, $textmore, $preset = null, $id = null)
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...
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
193
    {
194
        $s    = $size ?: '50px';
195
        $i    = $id ?: '';
196
        $data = "<span id='" . $name . "'><input type='text' size='" . $s . "' name='" . $name2 . "[]' value='" . $preset . "' id='" . $i . "'></span>";
197
198
        return $data;
199
    }
200
201
    /**
202
     * @param string $name
203
     * @param string $id
204
     * @param string $title
205
     * @param string $rows
206
     * @param string $cols
207
     * @param string $class
208
     * @param string $preset (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
209
     * @return string
210
     * @return string
211
     */
212
    public function textarea($name, $id, $title, $rows, $cols, $class, $preset = null)
213
    {
214
        return "<textarea name='" . $name . "' id='" . $id . "'  title='" . $title . "' rows='" . $rows . "' cols='" . $cols . "' class='" . $class . "'>" . $preset . '</textarea>';
215
    }
216
217
    /**
218
     * @param string $class
219
     * @param string $name
220
     * @param string $name2
221
     * @param string $rel
222
     * @param array  $options
223
     * @param string $textmore
224
     * @param string $selected      (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selected not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
225
     * @param string $preset        (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $preset not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
226
     * @param string $selectedstart (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstart not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
227
     * @param string $selectedstop  (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstop not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
228
     * @return string
229
     */
230
    public function school_add(
231
        $class,
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
232
        $name,
233
        $name2,
234
        $rel,
0 ignored issues
show
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
235
        array $options,
236
        $textmore,
0 ignored issues
show
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
237
        $selected = null,
238
        $preset = null,
239
        $selectedstart = null,
240
        $selectedstop = null
241
    ) {
242
        $dropdown = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_SCHOOLNAME . '<input class="school" type="text" value="' . $preset . '" name="' . $name2 . '[]">'
243
                  . '<br><br>' . _SMALLWORLD_SCHOOLTYPE . '<select class="school" name="' . $name . '[]" id="' . $name . '"">' . '<br>';
244 View Code Duplication
        foreach ($options as $key => $option) {
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...
245
            $select   = $selected == $key ? ' selected="selected"' : null;
246
            $dropdown .= '<option  class="school" value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>';
247
        }
248
        $dropdown .= '</select>'
249
                   . '<br><br>'
250
                   . _SMALLWORLD_START . '<select class="schooltime" name="schoolstart[]" id="schoolstart">';
251
        $array    = SmallworldGetTimestampsToForm();
252 View Code Duplication
        foreach ($array as $key => $option) {
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...
253
            $selectstart = $selectedstart == $key ? ' selected="selected"' : null;
254
            $dropdown    .= '<option value="' . $key . '"' . $selectstart . '>' . $option . '</option>' . '<br>';
255
        }
256
        $dropdown .= '</select>'
257
                   . '<br><br>'
258
                   . _SMALLWORLD_STOP . '<select class="schooltime" name="schoolstop[]" id="schoolstop">';
259
        $array    = SmallworldGetTimestampsToForm();
260 View Code Duplication
        foreach ($array as $key => $option) {
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...
261
            $selectstop = $selectedstop == $key ? ' selected="selected"' : null;
262
            $dropdown   .= '<option value="' . $key . '"' . $selectstop . '>' . $option . '</option>' . '<br>';
263
        }
264
        $dropdown .= '</select><br></p></div>';
265
266
        return $dropdown;
267
    }
268
269
    /**
270
     * Create HTML form elements for Job fields
271
     *
272
     * @param string  $class - not used
273
     * @param string  $name
274
     * @param string  $name2 - not used
275
     * @param string  $rel   - not used
276
     * @param string  $textmore - not used
277
     * @param string  $employer      (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $employer not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
278
     * @param string  $position      (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $position not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
279
     * @param string  $selectedstart (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstart not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
280
     * @param string  $selectedstop  (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $selectedstop not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
281
     * @param string  $description   (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $description not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
282
     * @return string
283
     */
284
    public function job(
285
        $class,
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
286
        $name,
287
        $name2,
0 ignored issues
show
Unused Code introduced by
The parameter $name2 is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
288
        $rel,
0 ignored issues
show
Unused Code introduced by
The parameter $rel is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
289
        $textmore,
0 ignored issues
show
Unused Code introduced by
The parameter $textmore is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
290
        $employer = null,
291
        $position = null,
292
        $selectedstart = null,
293
        $selectedstop = null,
294
        $description = null
295
    ) {
296
        $text = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_EMPLOYER . '<input class="job" id="job" value="' . $employer . '" type="text" name="employer[]">'
297
              . '<br><br>' . _SMALLWORLD_POSITION . '<input class="job" type="text" value="' . $position . '" name="position[]">'
298
              . '<br><br>' . _SMALLWORLD_JOBSTART . '<input class="jobstart" type="text" value="' . $selectedstart . '" name="jobstart[]">'
299
              . '<br><br>' . _SMALLWORLD_JOBSTOP . '<input class="jobstop" value="' . $selectedstop . '" type="text" name="jobstop[]">'
300
              . '<br><br><span class="jobdescText">' . _SMALLWORLD_DESCRIPTION . '</span><textarea class="jobdesc" name="description[]" rows="20" cols="20">' . $description . '</textarea><br></p></div>'
301
              . '' . '<br>';
302
303
        return $text;
304
    }
305
306
    /**
307
     * Create a HTML upload form
308
     *
309
     * @param int $userID - not used
310
     * @return string
311
     */
312
    public function uploadform($userID)
0 ignored issues
show
Unused Code introduced by
The parameter $userID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
313
    {
314
        $text = '<form action="' . Helper::getInstance()->url('imgupload.php') . '" method="POST" enctype="multipart/form-data">'
315
              . '<input type="file" name="file[]" multiple>'
316
              . '<button type="submit">' . _SMALLWORLD_UPLOADTEXT . '</button>'
317
              . '<span class="file_upload_label">' . _SMALLWORLD_UPLOADFILESTEXT . '</span>'
318
              . '</form>';
319
320
        return $text;
321
    }
322
323
    /**
324
     * @param int    $userID - not used
325
     * @param string $imgurl
326
     * @param string $imgdesc
327
     * @param string $id
328
     * @return string
329
     */
330
    public function edit_images($userID, $imgurl, $imgdesc, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $userID is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
331
    {
332
        $text = '<p class="smallworld_clonebreaker"><br>'
333
              . '<table class="smallworld_table" border="0" cellspacing="0" cellpadding="0">'
334
              . '<tr>'
335
              . '<td><img class="smallworld_edit_image" src="' . $imgurl . '" height="100px" width="80px;"></td>'
336
              . '<td><span class="smallworld_editTextSpan">' . _SMALLWORLD_UPLOADDESC . '</span><br><br><textarea class="smallworld_edit_desc" name="imgdesc[]" rows="1" cols="1">' . stripslashes($imgdesc) . '</textarea><br><br></td>'
337
              . '<input value="' . $id . '" type="hidden" name="id[]">'
338
              . '</tr></table></p>';
339
340
        return $text;
341
    }
342
343
    /**
344
     * Create HTML radio selects for user settings
345
     *
346
     * @param int $userid
347
     * @return string
348
     */
349
    public function usersettings($userid)
350
    {
351
        $form = "<div style='display:none'><div class='smallworld_usersetings'>";
352
        $form .= '<fieldset><legend>' . _SMALLWORLD_SHOWIFPUBLICORPRIVATE . '</legend>';
353
        $form .= "<form id='perset'>";
354
        if ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser'] instanceof \XoopsUser) {
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
355
            $sql    = 'SELECT value FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$userid;
356
            $result = $GLOBALS['xoopsDB']->queryF($sql);
357
            $i      = $GLOBALS['xoopsDB']->getRowsNum($result);
358
            $v      = [];
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
359
            if ($i >= 1) {
360
                while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) {
361
                    $v    = unserialize(stripslashes($row['value']));
362
                    $pv   = ('1' == $v['posts']) ? ' checked' : '';
363
                    $cv   = ('1' == $v['comments']) ? ' checked' : '';
364
                    $nv   = ('1' == $v['notify']) ? ' checked' : '';
365
                    $form .= '<input type="checkbox" name="usersettings[]" id="posts" value="' . $v['posts'] . '" ' . $pv . '> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>';
366
                    $form .= '<input type="checkbox" name="usersettings[]" id="comments" value="' . $v['comments'] . '" ' . $cv . '> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>';
367
                    $form .= '<input type="checkbox" name="usersettings[]" id="notify" value="' . $v['notify'] . '" ' . $nv . '> ' . _SMALLWORLD_NOTIFYME . '<br>';
368
                }
369
            } else {
370
                $form .= '<input type="checkbox" name="usersettings[]" id="posts" value="0"> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>';
371
                $form .= '<input type="checkbox" name="usersettings[]" id="comments" value="0"> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>';
372
                $form .= '<input type="checkbox" name="usersettings[]" id="notify" value="0"> ' . _SMALLWORLD_NOTIFYME . '<br>';
373
            }
374
        }
375
        $form .= "<br><input type='submit' id='smallworld_privsave' value='" . _SMALLWORLD_SUBMIT . "' class='smallworld_finish'>";
376
        $form .= '</form></fieldset></div></div>';
377
378
        return $form;
379
    }
380
}
381