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
|
|
|
* SmallWorld |
14
|
|
|
* |
15
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
16
|
|
|
* @copyright 2011 Culex |
17
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
18
|
|
|
* @package SmallWorld |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class SmallWorldForm |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @create a dropdown select |
26
|
|
|
* @param string $name |
27
|
|
|
* @param array $options |
28
|
|
|
* @param string $selected (optional) |
|
|
|
|
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function dropdown($name, array $options, $selected = null) |
32
|
|
|
{ |
33
|
|
|
$dropdown = '<select name="' . $name . '" id="' . $name . '">' . '<br>'; |
34
|
|
|
$selected = $selected; |
|
|
|
|
35
|
|
|
foreach ($options as $key => $option) { |
36
|
|
|
$select = $selected == $key ? ' selected="yes"' : ''; |
37
|
|
|
$dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>'; |
38
|
|
|
} |
39
|
|
|
$dropdown .= '</select>' . '<br>'; |
40
|
|
|
return $dropdown; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @create a radio select |
45
|
|
|
* @param string $name |
46
|
|
|
* @param array $options |
47
|
|
|
* @param string $selected (optional) |
|
|
|
|
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
public function radio($name, array $options, $selected = null) |
51
|
|
|
{ |
52
|
|
|
$selected = $selected; |
|
|
|
|
53
|
|
|
$form = ''; |
54
|
|
|
foreach ($options as $value => $option) { |
55
|
|
|
$select = $selected == $value ? ' checked' : ' checked="unchecked"'; |
56
|
|
|
$form .= '<input type="checkbox" name="' . $name . '[]" id="' . $name . '" value="' . $value . '" ' . $select . '> ' . $option . '<br>'; |
57
|
|
|
} |
58
|
|
|
return $form; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $name |
63
|
|
|
* @param array $options |
64
|
|
|
* @param array $valuearray |
65
|
|
|
* @param string $selected (optional) |
|
|
|
|
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function RetrieveRadio($name, $options, $valuearray, $selected = null) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$form = ''; |
71
|
|
|
$a = count($options) - 1; |
72
|
|
|
for ($i = 0; $i <= $a; ++$i) { |
73
|
|
|
if (in_array($i, $valuearray)) { |
74
|
|
|
$form .= '<input type="checkbox" id="' . $name . '-' . $i . '" name="' . $name . '[]" value="' . $i . '" checked>' . $options[$i] . '<br>'; |
75
|
|
|
} else { |
76
|
|
|
$form .= '<input type="checkbox" id="' . $name . '-' . $i . '" name="' . $name . '[]" value="' . $i . '" >' . $options[$i] . '<br>'; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
return $form; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $name |
84
|
|
|
* @param string $id |
85
|
|
|
* @param string $class |
86
|
|
|
* @param int $size (optional) |
|
|
|
|
87
|
|
|
* @param string $preset (optional) |
|
|
|
|
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function input($name, $id, $class, $size = null, $preset = null) |
91
|
|
|
{ |
92
|
|
|
$s = $size ?: '50px'; |
93
|
|
|
$data = "<input type='text' size='" . $s . "' name='" . $name . "' id='" . $id . "' class='" . $class . "' value='" . $preset . "' autocomplete='off'>"; |
94
|
|
|
return $data; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $name |
99
|
|
|
* @param string $id |
100
|
|
|
* @param string $preset (optional) |
|
|
|
|
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function hidden($name, $id, $preset = null) |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
$data = "<input type='hidden' name='" . $name . "' value='" . $preset . "' >"; |
106
|
|
|
return $data; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param string $value |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function simpleText($value) |
114
|
|
|
{ |
115
|
|
|
$data = $value; |
116
|
|
|
return $data; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* |
121
|
|
|
* @param string $class |
122
|
|
|
* @param string $name |
123
|
|
|
* @param $name2 |
124
|
|
|
* @param string $rel |
125
|
|
|
* @param array $options |
126
|
|
|
* @param string $textmore |
127
|
|
|
* @param string $selected (optional) |
|
|
|
|
128
|
|
|
* @param string $preset (optional) |
|
|
|
|
129
|
|
|
* @return as|string |
130
|
|
|
*/ |
131
|
|
|
public function dropdown_add($class, $name, $name2, $rel, array $options, $textmore, $selected = null, $preset = null) |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
$dropdown = '<span id="' . $name . '"><input type="text" name="' . $name2 . '[]" value="' . $preset . '">'; |
134
|
|
|
$dropdown .= '<select class="smallworld_select" name="' . $name . '[]" id="' . $name . '"></p>' . '<br>'; |
135
|
|
|
foreach ($options as $key => $option) { |
136
|
|
|
$select = $selected == $key ? ' selected' : null; |
137
|
|
|
$dropdown .= '<option value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>'; |
138
|
|
|
} |
139
|
|
|
$dropdown .= '</select></span>'; |
140
|
|
|
return $dropdown; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* |
145
|
|
|
* @param string $class |
146
|
|
|
* @param string $name |
147
|
|
|
* @param $name2 |
148
|
|
|
* @param string $rel |
149
|
|
|
* @param int $size |
150
|
|
|
* @param string $textmore |
151
|
|
|
* @param string $preset (optional) |
|
|
|
|
152
|
|
|
* @param string $id (optional) |
|
|
|
|
153
|
|
|
* @return dynamic|string |
154
|
|
|
*/ |
155
|
|
|
public function input_add($class, $name, $name2, $rel, $size, $textmore, $preset = null, $id = null) |
|
|
|
|
156
|
|
|
{ |
157
|
|
|
$s = $size ?: '50px'; |
158
|
|
|
$i = $id ?: ''; |
159
|
|
|
$data = "<span id='" . $name . "'><input type='text' size='" . $s . "' name='" . $name2 . "[]' value='" . $preset . "' id='" . $i . "'></span>"; |
160
|
|
|
return $data; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return string|textarea |
165
|
|
|
* @param string $name |
166
|
|
|
* @param string $id |
167
|
|
|
* @param string $title |
168
|
|
|
* @param string $rows |
169
|
|
|
* @param string $cols |
170
|
|
|
* @param string $class |
171
|
|
|
* @param string $preset (optional) |
|
|
|
|
172
|
|
|
* @return string |
173
|
|
|
*/ |
174
|
|
|
public function textarea($name, $id, $title, $rows, $cols, $class, $preset = null) |
175
|
|
|
{ |
176
|
|
|
return "<textarea name='" . $name . "' id='" . $id . "' title='" . $title . "' rows='" . $rows . "' cols='" . $cols . "' class='" . $class . "'>" . $preset . '</textarea>'; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return dynamic|string |
181
|
|
|
* @param string $class |
182
|
|
|
* @param string $name |
183
|
|
|
* @param string $name2 |
184
|
|
|
* @param string $rel |
185
|
|
|
* @param array $options |
186
|
|
|
* @param string $textmore |
187
|
|
|
* @param string $selected (optional) |
|
|
|
|
188
|
|
|
* @param string $preset (optional) |
|
|
|
|
189
|
|
|
* @param string $selectedstart (optional) |
|
|
|
|
190
|
|
|
* @param string $selectedstop (optional) |
|
|
|
|
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
public function school_add( |
194
|
|
|
$class, |
|
|
|
|
195
|
|
|
$name, |
196
|
|
|
$name2, |
197
|
|
|
$rel, |
|
|
|
|
198
|
|
|
array $options, |
199
|
|
|
$textmore, |
|
|
|
|
200
|
|
|
$selected = null, |
201
|
|
|
$preset = null, |
202
|
|
|
$selectedstart = null, |
203
|
|
|
$selectedstop = null |
204
|
|
|
) { |
205
|
|
|
$dropdown = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_SCHOOLNAME . '<input class="school" type="text" value="' . $preset . '" name="' . $name2 . '[]">'; |
206
|
|
|
$dropdown .= '<br><br>' . _SMALLWORLD_SCHOOLTYPE . '<select class="school" name="' . $name . '[]" id="' . $name . '"">' . '<br>'; |
207
|
|
|
foreach ($options as $key => $option) { |
208
|
|
|
$select = $selected == $key ? ' selected="selected"' : null; |
209
|
|
|
$dropdown .= '<option class="school" value="' . $key . '"' . $select . '>' . $option . '</option>' . '<br>'; |
210
|
|
|
} |
211
|
|
|
$dropdown .= '</select>'; |
212
|
|
|
$dropdown .= '<br><br>'; |
213
|
|
|
$dropdown .= _SMALLWORLD_START . '<select class="schooltime" name="schoolstart[]" id="schoolstart">'; |
214
|
|
|
$array = SmallworldGetTimestampsToForm(); |
215
|
|
|
foreach ($array as $key => $option) { |
216
|
|
|
$selectstart = $selectedstart == $key ? ' selected="selected"' : null; |
217
|
|
|
$dropdown .= '<option value="' . $key . '"' . $selectstart . '>' . $option . '</option>' . '<br>'; |
218
|
|
|
} |
219
|
|
|
$dropdown .= '</select>'; |
220
|
|
|
$dropdown .= '<br><br>'; |
221
|
|
|
$dropdown .= _SMALLWORLD_STOP . '<select class="schooltime" name="schoolstop[]" id="schoolstop">'; |
222
|
|
|
$array = SmallworldGetTimestampsToForm(); |
223
|
|
|
foreach ($array as $key => $option) { |
224
|
|
|
$selectstop = $selectedstop == $key ? ' selected="selected"' : null; |
225
|
|
|
$dropdown .= '<option value="' . $key . '"' . $selectstop . '>' . $option . '</option>' . '<br>'; |
226
|
|
|
} |
227
|
|
|
$dropdown .= '</select><br></p></div>'; |
228
|
|
|
return $dropdown; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* |
233
|
|
|
* @param string $class |
234
|
|
|
* @param string $name |
235
|
|
|
* @param $name2 |
236
|
|
|
* @param string $rel |
237
|
|
|
* @param string $textmore |
238
|
|
|
* @param string $employer (optional) |
|
|
|
|
239
|
|
|
* @param string $position (optional) |
|
|
|
|
240
|
|
|
* @param string $selectedstart (optional) |
|
|
|
|
241
|
|
|
* @param string $selectedstop (optional) |
|
|
|
|
242
|
|
|
* @param string $description (optional) |
|
|
|
|
243
|
|
|
* @return dynamic|string |
244
|
|
|
*/ |
245
|
|
|
public function job( |
246
|
|
|
$class, |
|
|
|
|
247
|
|
|
$name, |
248
|
|
|
$name2, |
|
|
|
|
249
|
|
|
$rel, |
|
|
|
|
250
|
|
|
$textmore, |
|
|
|
|
251
|
|
|
$employer = null, |
252
|
|
|
$position = null, |
253
|
|
|
$selectedstart = null, |
254
|
|
|
$selectedstop = null, |
255
|
|
|
$description = null |
256
|
|
|
) { |
257
|
|
|
$text = '<div id="' . $name . '"><p class="smallworld_clonebreaker">' . _SMALLWORLD_EMPLOYER . '<input class="job" id="job" value="' . $employer . '" type="text" name="employer[]">'; |
258
|
|
|
$text .= '<br><br>' . _SMALLWORLD_POSITION . '<input class="job" type="text" value="' . $position . '" name="position[]">'; |
259
|
|
|
$text .= '<br><br>' . _SMALLWORLD_JOBSTART . '<input class="jobstart" type="text" value="' . $selectedstart . '" name="jobstart[]">'; |
260
|
|
|
$text .= '<br><br>' . _SMALLWORLD_JOBSTOP . '<input class="jobstop" value="' . $selectedstop . '" type="text" name="jobstop[]">'; |
261
|
|
|
$text .= '<br><br><span class="jobdescText">' . _SMALLWORLD_DESCRIPTION . '</span><textarea class="jobdesc" name="description[]" rows="20" cols="20">' . $description . '</textarea><br></p></div>'; |
262
|
|
|
$text .= '' . '<br>'; |
263
|
|
|
return $text; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return file|string |
268
|
|
|
* @param int $userID |
269
|
|
|
* @return string |
270
|
|
|
*/ |
271
|
|
|
public function uploadform($userID) |
|
|
|
|
272
|
|
|
{ |
273
|
|
|
$text = '<form action="imgupload.php" method="POST" enctype="multipart/form-data">'; |
274
|
|
|
$text .= '<input type="file" name="file[]" multiple>'; |
275
|
|
|
$text .= '<button type="submit">' . _SMALLWORLD_UPLOADTEXT . '</button>'; |
276
|
|
|
$text .= '<span class="file_upload_label">' . _SMALLWORLD_UPLOADFILESTEXT . '</span>'; |
277
|
|
|
$text .= '</form>'; |
278
|
|
|
return $text; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @return dynamic|string |
283
|
|
|
* @param int $userID |
284
|
|
|
* @param string $imgurl |
285
|
|
|
* @param string $imgdesc |
286
|
|
|
* @param string $id |
287
|
|
|
* @return string |
288
|
|
|
*/ |
289
|
|
|
public function edit_images($userID, $imgurl, $imgdesc, $id) |
|
|
|
|
290
|
|
|
{ |
291
|
|
|
global $xoopsUser; |
292
|
|
|
$text = '<p class="smallworld_clonebreaker"><br>'; |
293
|
|
|
$text .= '<table class="smallworld_table" border="0" cellspacing="0" cellpadding="0">'; |
294
|
|
|
$text .= '<tr>'; |
295
|
|
|
$text .= '<td><img class="smallworld_edit_image" src="' . $imgurl . '" height="100px" width="80px;"></td>'; |
296
|
|
|
$text .= '<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>'; |
297
|
|
|
$text .= '<input value="' . $id . '" type="hidden" name="id[]"></p>'; |
298
|
|
|
$text .= '</tr></table>'; |
299
|
|
|
return $text; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* @create a radio select |
304
|
|
|
* @param $userid |
305
|
|
|
* @return string |
306
|
|
|
*/ |
307
|
|
|
public function usersettings($userid) |
308
|
|
|
{ |
309
|
|
|
global $xoopsUser, $xoopsDB; |
310
|
|
|
|
311
|
|
|
$form = "<div style='display:none'><div class='smallworld_usersetings'>"; |
312
|
|
|
$form .= '<fieldset><legend>' . _SMALLWORLD_SHOWIFPUBLICORPRIVATE . '</legend>'; |
313
|
|
|
$form .= "<form id='perset'>"; |
314
|
|
|
if ($xoopsUser) { |
315
|
|
|
$sql = 'SELECT value FROM ' . $xoopsDB->prefix('smallworld_settings') . ' WHERE userid = ' . (int)$userid; |
316
|
|
|
$result = $xoopsDB->queryF($sql); |
317
|
|
|
$i = $xoopsDB->getRowsNum($result); |
318
|
|
|
$v = []; |
|
|
|
|
319
|
|
|
if ($i >= 1) { |
320
|
|
|
while ($row = $xoopsDB->fetchArray($result)) { |
321
|
|
|
$v = unserialize(stripslashes($row['value'])); |
322
|
|
|
$pv = ('1' == $v['posts']) ? ' checked' : ''; |
323
|
|
|
$cv = ('1' == $v['comments']) ? ' checked' : ''; |
324
|
|
|
$nv = ('1' == $v['notify']) ? ' checked' : ''; |
325
|
|
|
$form .= '<input type="checkbox" name="usersettings[]" id="posts" value="' . $v['posts'] . '" ' . $pv . '> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>'; |
326
|
|
|
$form .= '<input type="checkbox" name="usersettings[]" id="comments" value="' . $v['comments'] . '" ' . $cv . '> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>'; |
327
|
|
|
$form .= '<input type="checkbox" name="usersettings[]" id="notify" value="' . $v['notify'] . '" ' . $nv . '> ' . _SMALLWORLD_NOTIFYME . '<br>'; |
328
|
|
|
} |
329
|
|
|
} else { |
330
|
|
|
$form .= '<input type="checkbox" name="usersettings[]" id="posts" value="0"> ' . _SMALLWORLD_SHOWMYPOSTS . '<br>'; |
331
|
|
|
$form .= '<input type="checkbox" name="usersettings[]" id="comments" value="0"> ' . _SMALLWORLD_SHOWMYCOMMENTS . '<br>'; |
332
|
|
|
$form .= '<input type="checkbox" name="usersettings[]" id="notify" value="0"> ' . _SMALLWORLD_NOTIFYME . '<br>'; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
$form .= "<br><input type='submit' id='smallworld_privsave' value='" . _SMALLWORLD_SUBMIT . "' class='smallworld_finish'>"; |
336
|
|
|
$form .= '</form></fieldset></div></div>'; |
337
|
|
|
return $form; |
338
|
|
|
} |
339
|
|
|
} |
340
|
|
|
|
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.