1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Extended User Profile |
4
|
|
|
* |
5
|
|
|
* You may not change or alter any portion of this comment or credits |
6
|
|
|
* of supporting developers from this source code or any supporting source code |
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
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
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
13
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14
|
|
|
* @package profile |
15
|
|
|
* @since 2.3.0 |
16
|
|
|
* @author Jan Pedersen |
17
|
|
|
* @author Taiwen Jiang <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
// defined('XOOPS_ROOT_PATH') || exit("XOOPS root path not defined"); |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @package kernel |
24
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
25
|
|
|
*/ |
26
|
|
|
class ProfileField extends XoopsObject |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
public function __construct() |
32
|
|
|
{ |
33
|
|
|
$this->initVar('field_id', XOBJ_DTYPE_INT, null); |
34
|
|
|
$this->initVar('cat_id', XOBJ_DTYPE_INT, null, true); |
35
|
|
|
$this->initVar('field_type', XOBJ_DTYPE_TXTBOX); |
36
|
|
|
$this->initVar('field_valuetype', XOBJ_DTYPE_INT, null, true); |
37
|
|
|
$this->initVar('field_name', XOBJ_DTYPE_TXTBOX, null, true); |
38
|
|
|
$this->initVar('field_title', XOBJ_DTYPE_TXTBOX); |
39
|
|
|
$this->initVar('field_description', XOBJ_DTYPE_TXTAREA); |
40
|
|
|
$this->initVar('field_required', XOBJ_DTYPE_INT, 0); //0 = no, 1 = yes |
41
|
|
|
$this->initVar('field_maxlength', XOBJ_DTYPE_INT, 0); |
42
|
|
|
$this->initVar('field_weight', XOBJ_DTYPE_INT, 0); |
43
|
|
|
$this->initVar('field_default', XOBJ_DTYPE_TXTAREA, ''); |
44
|
|
|
$this->initVar('field_notnull', XOBJ_DTYPE_INT, 1); |
45
|
|
|
$this->initVar('field_edit', XOBJ_DTYPE_INT, 0); |
46
|
|
|
$this->initVar('field_show', XOBJ_DTYPE_INT, 0); |
47
|
|
|
$this->initVar('field_config', XOBJ_DTYPE_INT, 0); |
48
|
|
|
$this->initVar('field_options', XOBJ_DTYPE_ARRAY, array()); |
49
|
|
|
$this->initVar('step_id', XOBJ_DTYPE_INT, 0); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Extra treatment dealing with non latin encoding |
54
|
|
|
* Tricky solution |
55
|
|
|
* @param string $key |
56
|
|
|
* @param mixed $value |
57
|
|
|
* @param bool $not_gpc |
58
|
|
|
*/ |
59
|
|
|
public function setVar($key, $value, $not_gpc = false) |
60
|
|
|
{ |
61
|
|
|
if ($key === 'field_options' && is_array($value)) { |
62
|
|
|
foreach (array_keys($value) as $idx) { |
63
|
|
|
$value[$idx] = base64_encode($value[$idx]); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
parent::setVar($key, $value, $not_gpc); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $key |
71
|
|
|
* @param string $format |
72
|
|
|
* |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
|
|
public function getVar($key, $format = 's') |
76
|
|
|
{ |
77
|
|
|
$value = parent::getVar($key, $format); |
78
|
|
|
if ($key === 'field_options' && !empty($value)) { |
79
|
|
|
foreach (array_keys($value) as $idx) { |
|
|
|
|
80
|
|
|
$value[$idx] = base64_decode($value[$idx]); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $value; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns a {@link XoopsFormElement} for editing the value of this field |
89
|
|
|
* |
90
|
|
|
* @param XoopsUser $user {@link XoopsUser} object to edit the value of |
91
|
|
|
* @param ProfileProfile $profile {@link ProfileProfile} object to edit the value of |
92
|
|
|
* |
93
|
|
|
* @return XoopsFormElement |
94
|
|
|
**/ |
95
|
|
|
public function getEditElement($user, $profile) |
96
|
|
|
{ |
97
|
|
|
$value = in_array($this->getVar('field_name'), $this->getUserVars()) ? $user->getVar($this->getVar('field_name'), 'e') : $profile->getVar($this->getVar('field_name'), 'e'); |
98
|
|
|
|
99
|
|
|
$caption = $this->getVar('field_title'); |
100
|
|
|
$caption = defined($caption) ? constant($caption) : $caption; |
101
|
|
|
$name = $this->getVar('field_name', 'e'); |
102
|
|
|
$options = $this->getVar('field_options'); |
103
|
|
|
if (is_array($options)) { |
104
|
|
|
//asort($options); |
105
|
|
|
|
106
|
|
|
foreach (array_keys($options) as $key) { |
107
|
|
|
$optval = defined($options[$key]) ? constant($options[$key]) : $options[$key]; |
108
|
|
|
$optkey = defined($key) ? constant($key) : $key; |
109
|
|
|
unset($options[$key]); |
110
|
|
|
$options[$optkey] = $optval; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
114
|
|
|
switch ($this->getVar('field_type')) { |
115
|
|
|
default: |
116
|
|
|
case 'autotext': |
117
|
|
|
//autotext is not for editing |
118
|
|
|
$element = new XoopsFormLabel($caption, $this->getOutputValue($user, $profile)); |
|
|
|
|
119
|
|
|
break; |
120
|
|
|
|
121
|
|
|
case 'textbox': |
122
|
|
|
$element = new XoopsFormText($caption, $name, 35, $this->getVar('field_maxlength'), $value); |
|
|
|
|
123
|
|
|
break; |
124
|
|
|
|
125
|
|
|
case 'textarea': |
126
|
|
|
$element = new XoopsFormTextArea($caption, $name, $value, 4, 30); |
|
|
|
|
127
|
|
|
break; |
128
|
|
|
|
129
|
|
|
case 'dhtml': |
130
|
|
|
$element = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 30); |
|
|
|
|
131
|
|
|
break; |
132
|
|
|
|
133
|
|
|
case 'select': |
134
|
|
|
$element = new XoopsFormSelect($caption, $name, $value); |
135
|
|
|
// If options do not include an empty element, then add a blank option to prevent any default selection |
136
|
|
|
// if (!in_array('', array_keys($options))) { |
137
|
|
|
if (!array_key_exists('', $options)) { |
138
|
|
|
$element->addOption('', _NONE); |
139
|
|
|
|
140
|
|
|
$eltmsg = empty($caption) ? sprintf(_FORM_ENTER, $name) : sprintf(_FORM_ENTER, $caption); |
141
|
|
|
$eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
142
|
|
|
$element->customValidationCode[] = "\nvar hasSelected = false; var selectBox = myform.{$name};" . "for (i = 0; i < selectBox.options.length; i++) { if (selectBox.options[i].selected == true && selectBox.options[i].value != '') { hasSelected = true; break; } }" . "if (!hasSelected) { window.alert(\"{$eltmsg}\"); selectBox.focus(); return false; }"; |
143
|
|
|
} |
144
|
|
|
$element->addOptionArray($options); |
145
|
|
|
break; |
146
|
|
|
|
147
|
|
|
case 'select_multi': |
148
|
|
|
$element = new XoopsFormSelect($caption, $name, $value, 5, true); |
149
|
|
|
$element->addOptionArray($options); |
150
|
|
|
break; |
151
|
|
|
|
152
|
|
|
case 'radio': |
153
|
|
|
$element = new XoopsFormRadio($caption, $name, $value); |
|
|
|
|
154
|
|
|
$element->addOptionArray($options); |
155
|
|
|
break; |
156
|
|
|
|
157
|
|
|
case 'checkbox': |
158
|
|
|
$element = new XoopsFormCheckBox($caption, $name, $value); |
159
|
|
|
$element->addOptionArray($options); |
160
|
|
|
break; |
161
|
|
|
|
162
|
|
|
case 'yesno': |
163
|
|
|
$element = new XoopsFormRadioYN($caption, $name, $value); |
|
|
|
|
164
|
|
|
break; |
165
|
|
|
|
166
|
|
|
case 'group': |
167
|
|
|
$element = new XoopsFormSelectGroup($caption, $name, true, $value); |
168
|
|
|
break; |
169
|
|
|
|
170
|
|
|
case 'group_multi': |
171
|
|
|
$element = new XoopsFormSelectGroup($caption, $name, true, $value, 5, true); |
172
|
|
|
break; |
173
|
|
|
|
174
|
|
|
case 'language': |
175
|
|
|
$element = new XoopsFormSelectLang($caption, $name, $value); |
176
|
|
|
break; |
177
|
|
|
|
178
|
|
|
case 'date': |
179
|
|
|
$element = new XoopsFormTextDateSelect($caption, $name, 15, $value); |
180
|
|
|
break; |
181
|
|
|
|
182
|
|
|
case 'longdate': |
183
|
|
|
$element = new XoopsFormTextDateSelect($caption, $name, 15, str_replace('-', '/', $value)); |
184
|
|
|
break; |
185
|
|
|
|
186
|
|
|
case 'datetime': |
187
|
|
|
$element = new XoopsFormDatetime($caption, $name, 15, $value); |
188
|
|
|
break; |
189
|
|
|
|
190
|
|
|
case 'timezone': |
191
|
|
|
$element = new XoopsFormSelectTimezone($caption, $name, $value); |
192
|
|
|
$element->setExtra("style='width: 280px;'"); |
193
|
|
|
break; |
194
|
|
|
|
195
|
|
|
case 'rank': |
196
|
|
|
$element = new XoopsFormSelect($caption, $name, $value); |
197
|
|
|
|
198
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopslists.php'); |
199
|
|
|
$ranks = XoopsLists::getUserRankList(); |
200
|
|
|
$element->addOption(0, '--------------'); |
201
|
|
|
$element->addOptionArray($ranks); |
202
|
|
|
break; |
203
|
|
|
|
204
|
|
|
case 'theme': |
205
|
|
|
$element = new XoopsFormSelectTheme($caption, $name, $value, 1, true); |
206
|
|
|
break; |
207
|
|
|
} |
208
|
|
|
if ($this->getVar('field_description') != '') { |
209
|
|
|
$element->setDescription($this->getVar('field_description')); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return $element; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Returns a value for output of this field |
217
|
|
|
* |
218
|
|
|
* @param XoopsUser $user {@link XoopsUser} object to get the value of |
219
|
|
|
* @param profileProfile $profile object to get the value of |
220
|
|
|
* |
221
|
|
|
* @return mixed |
222
|
|
|
**/ |
223
|
|
|
public function getOutputValue(&$user, $profile) |
224
|
|
|
{ |
225
|
|
|
xoops_loadLanguage('modinfo', 'profile'); |
226
|
|
|
|
227
|
|
|
$value = in_array($this->getVar('field_name'), $this->getUserVars()) ? $user->getVar($this->getVar('field_name')) : $profile->getVar($this->getVar('field_name')); |
228
|
|
|
|
229
|
|
|
switch ($this->getVar('field_type')) { |
230
|
|
|
default: |
231
|
|
|
case 'textbox': |
232
|
|
|
$value = is_array($value) ? $value[0] : $value; |
233
|
|
|
if ($this->getVar('field_name') === 'url' && $value !== '') { |
234
|
|
|
return '<a href="' . formatURL($value) . '" rel="external">' . $value . '</a>'; |
235
|
|
|
} else { |
236
|
|
|
return $value; |
237
|
|
|
} |
238
|
|
|
break; |
239
|
|
|
case 'textarea': |
240
|
|
|
case 'dhtml': |
241
|
|
|
case 'theme': |
242
|
|
|
case 'language': |
243
|
|
|
return $value; |
244
|
|
|
break; |
|
|
|
|
245
|
|
|
|
246
|
|
|
case 'select': |
247
|
|
|
case 'radio': |
248
|
|
|
$value = is_array($value) ? $value[0] : $value; |
249
|
|
|
$options = $this->getVar('field_options'); |
250
|
|
|
if (isset($options[$value])) { |
251
|
|
|
$value = htmlspecialchars(defined($options[$value]) ? constant($options[$value]) : $options[$value]); |
252
|
|
|
} else { |
253
|
|
|
$value = ''; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
return $value; |
257
|
|
|
break; |
258
|
|
|
|
259
|
|
|
case 'select_multi': |
260
|
|
|
case 'checkbox': |
261
|
|
|
$options = $this->getVar('field_options'); |
262
|
|
|
$ret = array(); |
263
|
|
|
if (count($options) > 0) { |
264
|
|
|
foreach (array_keys($options) as $key) { |
265
|
|
|
if (in_array($key, $value)) { |
|
|
|
|
266
|
|
|
$ret[$key] = htmlspecialchars(defined($options[$key]) ? constant($options[$key]) : $options[$key]); |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
return $ret; |
272
|
|
|
break; |
273
|
|
|
|
274
|
|
|
case 'group': |
275
|
|
|
/* @var XoopsMemberHandler $member_handler */ |
276
|
|
|
$member_handler = xoops_getHandler('member'); |
277
|
|
|
$options = $member_handler->getGroupList(); |
278
|
|
|
$ret = isset($options[$value]) ? $options[$value] : ''; |
279
|
|
|
|
280
|
|
|
return $ret; |
281
|
|
|
break; |
282
|
|
|
|
283
|
|
|
case 'group_multi': |
284
|
|
|
/* @var XoopsMemberHandler $member_handler */ |
285
|
|
|
$member_handler = xoops_getHandler('member'); |
286
|
|
|
$options = $member_handler->getGroupList(); |
287
|
|
|
$ret = array(); |
288
|
|
|
foreach (array_keys($options) as $key) { |
289
|
|
|
if (in_array($key, $value)) { |
290
|
|
|
$ret[$key] = htmlspecialchars($options[$key]); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
return $ret; |
295
|
|
|
break; |
296
|
|
|
|
297
|
|
|
case 'longdate': |
298
|
|
|
//return YYYY/MM/DD format - not optimal as it is not using local date format, but how do we do that |
299
|
|
|
//when we cannot convert it to a UNIX timestamp? |
300
|
|
|
return str_replace('-', '/', $value); |
301
|
|
|
|
302
|
|
|
case 'date': |
303
|
|
|
return formatTimestamp($value, 's'); |
304
|
|
|
break; |
305
|
|
|
|
306
|
|
|
case 'datetime': |
307
|
|
|
if (!empty($value)) { |
308
|
|
|
return formatTimestamp($value, 'm'); |
309
|
|
|
} else { |
310
|
|
|
return $value = _PROFILE_MI_NEVER_LOGGED_IN; |
|
|
|
|
311
|
|
|
} |
312
|
|
|
break; |
313
|
|
|
|
314
|
|
|
case 'autotext': |
315
|
|
|
$value = $user->getVar($this->getVar('field_name'), 'n'); //autotext can have HTML in it |
316
|
|
|
$value = str_replace('{X_UID}', $user->getVar('uid'), $value); |
317
|
|
|
$value = str_replace('{X_URL}', XOOPS_URL, $value); |
318
|
|
|
$value = str_replace('{X_UNAME}', $user->getVar('uname'), $value); |
319
|
|
|
|
320
|
|
|
return $value; |
321
|
|
|
break; |
322
|
|
|
|
323
|
|
|
case 'rank': |
324
|
|
|
$userrank = $user->rank(); |
325
|
|
|
$user_rankimage = ''; |
326
|
|
|
if (isset($userrank['image']) && $userrank['image'] !== '') { |
327
|
|
|
$user_rankimage = '<img src="' . XOOPS_UPLOAD_URL . '/' . $userrank['image'] . '" alt="' . $userrank['title'] . '" /><br>'; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
return $user_rankimage . $userrank['title']; |
331
|
|
|
break; |
332
|
|
|
|
333
|
|
|
case 'yesno': |
334
|
|
|
return $value ? _YES : _NO; |
335
|
|
|
break; |
336
|
|
|
|
337
|
|
|
case 'timezone': |
338
|
|
|
include_once $GLOBALS['xoops']->path('class/xoopslists.php'); |
339
|
|
|
$timezones = XoopsLists::getTimeZoneList(); |
340
|
|
|
$value = empty($value) ? '0' : (string)$value; |
341
|
|
|
|
342
|
|
|
return $timezones[str_replace('.0', '', $value)]; |
343
|
|
|
break; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Returns a value ready to be saved in the database |
349
|
|
|
* |
350
|
|
|
* @param mixed $value Value to format |
351
|
|
|
* |
352
|
|
|
* @return mixed |
353
|
|
|
*/ |
354
|
|
|
public function getValueForSave($value) |
355
|
|
|
{ |
356
|
|
|
switch ($this->getVar('field_type')) { |
357
|
|
|
default: |
358
|
|
|
case 'textbox': |
359
|
|
|
case 'textarea': |
360
|
|
|
case 'dhtml': |
361
|
|
|
case 'yesno': |
362
|
|
|
case 'timezone': |
363
|
|
|
case 'theme': |
364
|
|
|
case 'language': |
365
|
|
|
case 'select': |
366
|
|
|
case 'radio': |
367
|
|
|
case 'select_multi': |
368
|
|
|
case 'group': |
369
|
|
|
case 'group_multi': |
370
|
|
|
case 'longdate': |
371
|
|
|
return $value; |
372
|
|
|
|
373
|
|
|
case 'checkbox': |
374
|
|
|
return (array)$value; |
375
|
|
|
|
376
|
|
|
case 'date': |
377
|
|
|
if ($value !== '') { |
378
|
|
|
return strtotime($value); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
return $value; |
382
|
|
|
break; |
|
|
|
|
383
|
|
|
|
384
|
|
|
case 'datetime': |
385
|
|
|
if (!empty($value)) { |
386
|
|
|
return strtotime($value['date']) + (int)$value['time']; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
return $value; |
390
|
|
|
break; |
391
|
|
|
} |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Get names of user variables |
396
|
|
|
* |
397
|
|
|
* @return array |
398
|
|
|
*/ |
399
|
|
|
public function getUserVars() |
400
|
|
|
{ |
401
|
|
|
/* @var ProfileProfileHandler $profile_handler */ |
402
|
|
|
$profile_handler = xoops_getModuleHandler('profile', 'profile'); |
403
|
|
|
|
404
|
|
|
return $profile_handler->getUserVars(); |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
/** |
409
|
|
|
* @package kernel |
410
|
|
|
* @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
411
|
|
|
*/ |
412
|
|
|
class ProfileFieldHandler extends XoopsPersistableObjectHandler |
413
|
|
|
{ |
414
|
|
|
/** |
415
|
|
|
* @param null|XoopsDatabase $db |
416
|
|
|
*/ |
417
|
|
|
public function __construct(XoopsDatabase $db) |
418
|
|
|
{ |
419
|
|
|
parent::__construct($db, 'profile_field', 'profilefield', 'field_id', 'field_title'); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Read field information from cached storage |
424
|
|
|
* |
425
|
|
|
* @param bool $force_update read fields from database and not cached storage |
426
|
|
|
* |
427
|
|
|
* @return array |
428
|
|
|
*/ |
429
|
|
|
public function loadFields($force_update = false) |
430
|
|
|
{ |
431
|
|
|
static $fields = array(); |
432
|
|
|
if (!empty($force_update) || count($fields) == 0) { |
433
|
|
|
$this->table_link = $this->db->prefix('profile_category'); |
|
|
|
|
434
|
|
|
$criteria = new Criteria('o.field_id', 0, '!='); |
435
|
|
|
$criteria->setSort('l.cat_weight ASC, o.field_weight'); |
436
|
|
|
$field_objs =& $this->getByLink($criteria, array('o.*'), true, 'cat_id', 'cat_id'); |
437
|
|
|
foreach (array_keys($field_objs) as $i) { |
438
|
|
|
$fields[$field_objs[$i]->getVar('field_name')] = $field_objs[$i]; |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
return $fields; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* save a profile field in the database |
447
|
|
|
* |
448
|
|
|
* @param XoopsObject|ProfileField $obj reference to the object |
449
|
|
|
* @param bool $force whether to force the query execution despite security settings |
450
|
|
|
* |
451
|
|
|
* @internal param bool $checkObject check if the object is dirty and clean the attributes |
452
|
|
|
* @return bool FALSE if failed, TRUE if already present and unchanged or successful |
453
|
|
|
*/ |
454
|
|
|
public function insert(XoopsObject $obj, $force = false) |
455
|
|
|
{ |
456
|
|
|
if (!($obj instanceof $this->className)) { |
457
|
|
|
return false; |
458
|
|
|
} |
459
|
|
|
/* @var ProfileProfileHandler $profile_handler */ |
460
|
|
|
$profile_handler = xoops_getModuleHandler('profile', 'profile'); |
461
|
|
|
$obj->setVar('field_name', str_replace(' ', '_', $obj->getVar('field_name'))); |
462
|
|
|
$obj->cleanVars(); |
463
|
|
|
$defaultstring = ''; |
|
|
|
|
464
|
|
|
switch ($obj->getVar('field_type')) { |
465
|
|
|
case 'datetime': |
466
|
|
|
case 'date': |
467
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_INT); |
468
|
|
|
$obj->setVar('field_maxlength', 10); |
469
|
|
|
break; |
470
|
|
|
|
471
|
|
|
case 'longdate': |
472
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_MTIME); |
473
|
|
|
break; |
474
|
|
|
|
475
|
|
|
case 'yesno': |
476
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_INT); |
477
|
|
|
$obj->setVar('field_maxlength', 1); |
478
|
|
|
break; |
479
|
|
|
|
480
|
|
|
case 'textbox': |
481
|
|
|
if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) { |
482
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX); |
483
|
|
|
} |
484
|
|
|
break; |
485
|
|
|
|
486
|
|
|
case 'autotext': |
487
|
|
|
if ($obj->getVar('field_valuetype') != XOBJ_DTYPE_INT) { |
488
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA); |
489
|
|
|
} |
490
|
|
|
break; |
491
|
|
|
|
492
|
|
|
case 'group_multi': |
493
|
|
|
case 'select_multi': |
494
|
|
|
case 'checkbox': |
495
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_ARRAY); |
496
|
|
|
break; |
497
|
|
|
|
498
|
|
|
case 'language': |
499
|
|
|
case 'timezone': |
500
|
|
|
case 'theme': |
501
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX); |
502
|
|
|
break; |
503
|
|
|
|
504
|
|
|
case 'dhtml': |
505
|
|
|
case 'textarea': |
506
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_TXTAREA); |
507
|
|
|
break; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
if ($obj->getVar('field_valuetype') === '') { |
511
|
|
|
$obj->setVar('field_valuetype', XOBJ_DTYPE_TXTBOX); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
if ((!in_array($obj->getVar('field_name'), $this->getUserVars())) && isset($_REQUEST['field_required'])) { |
515
|
|
|
if ($obj->isNew()) { |
516
|
|
|
//add column to table |
517
|
|
|
$changetype = 'ADD'; |
518
|
|
|
} else { |
519
|
|
|
//update column information |
520
|
|
|
$changetype = 'MODIFY COLUMN'; |
521
|
|
|
} |
522
|
|
|
$maxlengthstring = $obj->getVar('field_maxlength') > 0 ? '(' . $obj->getVar('field_maxlength') . ')' : ''; |
523
|
|
|
|
524
|
|
|
//set type |
525
|
|
|
switch ($obj->getVar('field_valuetype')) { |
526
|
|
|
default: |
527
|
|
|
case XOBJ_DTYPE_ARRAY: |
528
|
|
|
case XOBJ_DTYPE_UNICODE_ARRAY: |
529
|
|
|
$type = 'mediumtext'; |
530
|
|
|
$maxlengthstring = ''; |
531
|
|
|
break; |
532
|
|
|
case XOBJ_DTYPE_UNICODE_EMAIL: |
533
|
|
|
case XOBJ_DTYPE_UNICODE_TXTBOX: |
534
|
|
|
case XOBJ_DTYPE_UNICODE_URL: |
535
|
|
|
case XOBJ_DTYPE_EMAIL: |
536
|
|
|
case XOBJ_DTYPE_TXTBOX: |
537
|
|
|
case XOBJ_DTYPE_URL: |
538
|
|
|
$type = 'varchar'; |
539
|
|
|
// varchars must have a maxlength |
540
|
|
|
if (!$maxlengthstring) { |
541
|
|
|
//so set it to max if maxlength is not set - or should it fail? |
542
|
|
|
$maxlengthstring = '(255)'; |
543
|
|
|
$obj->setVar('field_maxlength', 255); |
544
|
|
|
} |
545
|
|
|
break; |
546
|
|
|
|
547
|
|
|
case XOBJ_DTYPE_INT: |
548
|
|
|
$type = 'int'; |
549
|
|
|
break; |
550
|
|
|
|
551
|
|
|
case XOBJ_DTYPE_DECIMAL: |
552
|
|
|
$type = 'decimal(14,6)'; |
553
|
|
|
break; |
554
|
|
|
|
555
|
|
|
case XOBJ_DTYPE_FLOAT: |
556
|
|
|
$type = 'float(15,9)'; |
557
|
|
|
break; |
558
|
|
|
|
559
|
|
|
case XOBJ_DTYPE_OTHER: |
560
|
|
|
case XOBJ_DTYPE_UNICODE_TXTAREA: |
561
|
|
|
case XOBJ_DTYPE_TXTAREA: |
562
|
|
|
$type = 'text'; |
563
|
|
|
$maxlengthstring = ''; |
564
|
|
|
break; |
565
|
|
|
|
566
|
|
|
case XOBJ_DTYPE_MTIME: |
567
|
|
|
$type = 'date'; |
568
|
|
|
$maxlengthstring = ''; |
569
|
|
|
break; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
$sql = 'ALTER TABLE `' . $profile_handler->table . '` ' . $changetype . ' `' . $obj->cleanVars['field_name'] . '` ' . $type . $maxlengthstring . ' NULL'; |
573
|
|
|
$result = $force ? $this->db->queryF($sql) : $this->db->query($sql); |
|
|
|
|
574
|
|
|
if (!$result) { |
575
|
|
|
$obj->setErrors($this->db->error()); |
|
|
|
|
576
|
|
|
return false; |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
//change this to also update the cached field information storage |
581
|
|
|
$obj->setDirty(); |
582
|
|
|
if (!parent::insert($obj, $force)) { |
583
|
|
|
return false; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
return $obj->getVar('field_id'); |
|
|
|
|
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* delete a profile field from the database |
591
|
|
|
* |
592
|
|
|
* @param XoopsObject|ProfileField $obj reference to the object to delete |
593
|
|
|
* @param bool $force |
594
|
|
|
* @return bool FALSE if failed. |
595
|
|
|
**/ |
596
|
|
|
public function delete(XoopsObject $obj, $force = false) |
597
|
|
|
{ |
598
|
|
|
if (!($obj instanceof $this->className)) { |
599
|
|
|
return false; |
600
|
|
|
} |
601
|
|
|
/* @var ProfileProfileHandler $profile_handler */ |
602
|
|
|
$profile_handler = xoops_getModuleHandler('profile', 'profile'); |
603
|
|
|
// remove column from table |
604
|
|
|
$sql = 'ALTER TABLE ' . $profile_handler->table . ' DROP `' . $obj->getVar('field_name', 'n') . '`'; |
605
|
|
|
if ($this->db->query($sql)) { |
606
|
|
|
//change this to update the cached field information storage |
607
|
|
|
if (!parent::delete($obj, $force)) { |
608
|
|
|
return false; |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
if ($obj->getVar('field_show') || $obj->getVar('field_edit')) { |
612
|
|
|
/* @var XoopsModuleHandler $module_handler */ |
613
|
|
|
$module_handler = xoops_getHandler('module'); |
614
|
|
|
$profile_module = $module_handler->getByDirname('profile'); |
615
|
|
|
if (is_object($profile_module)) { |
616
|
|
|
// Remove group permissions |
617
|
|
|
/* @var XoopsGroupPermHandler $groupperm_handler */ |
618
|
|
|
$groupperm_handler = xoops_getHandler('groupperm'); |
619
|
|
|
$criteria = new CriteriaCompo(new Criteria('gperm_modid', $profile_module->getVar('mid'))); |
|
|
|
|
620
|
|
|
$criteria->add(new Criteria('gperm_itemid', $obj->getVar('field_id'))); |
621
|
|
|
|
622
|
|
|
return $groupperm_handler->deleteAll($criteria); |
623
|
|
|
} |
624
|
|
|
} |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
return false; |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
/** |
631
|
|
|
* Get array of standard variable names (user table) |
632
|
|
|
* |
633
|
|
|
* @return array |
634
|
|
|
*/ |
635
|
|
|
public function getUserVars() |
636
|
|
|
{ |
637
|
|
|
return array( |
638
|
|
|
'uid', |
639
|
|
|
'uname', |
640
|
|
|
'name', |
641
|
|
|
'email', |
642
|
|
|
'url', |
643
|
|
|
'user_avatar', |
644
|
|
|
'user_regdate', |
645
|
|
|
'user_icq', |
646
|
|
|
'user_from', |
647
|
|
|
'user_sig', |
648
|
|
|
'user_viewemail', |
649
|
|
|
'actkey', |
650
|
|
|
'user_aim', |
651
|
|
|
'user_yim', |
652
|
|
|
'user_msnm', |
653
|
|
|
'pass', |
654
|
|
|
'posts', |
655
|
|
|
'attachsig', |
656
|
|
|
'rank', |
657
|
|
|
'level', |
658
|
|
|
'theme', |
659
|
|
|
'timezone_offset', |
660
|
|
|
'last_login', |
661
|
|
|
'umode', |
662
|
|
|
'uorder', |
663
|
|
|
'notify_method', |
664
|
|
|
'notify_mode', |
665
|
|
|
'user_occ', |
666
|
|
|
'bio', |
667
|
|
|
'user_intrest', |
668
|
|
|
'user_mailok'); |
669
|
|
|
} |
670
|
|
|
} |
671
|
|
|
|