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