Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
functions_profile_fields.php
0001 <?php
0002 /**
0003 *
0004 * @package phpBB3
0005 * @version $Id$
0006 * @copyright (c) 2005 phpBB Group
0007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008 *
0009 */
0010
0011 /**
0012 * @ignore
0013 */
0014 if (!defined('IN_PHPBB'))
0015 {
0016 exit;
0017 }
0018
0019 /**
0020 * Custom Profile Fields
0021 * @package phpBB3
0022 */
0023 class custom_profile
0024 {
0025 var $profile_types = array(FIELD_INT => 'int', FIELD_STRING => 'string', FIELD_TEXT => 'text', FIELD_BOOL => 'bool', FIELD_DROPDOWN => 'dropdown', FIELD_DATE => 'date');
0026 var $profile_cache = array();
0027 var $options_lang = array();
0028
0029 /**
0030 * Assign editable fields to template, mode can be profile (for profile change) or register (for registration)
0031 * Called by ucp_profile and ucp_register
0032 * @access public
0033 */
0034 function generate_profile_fields($mode, $lang_id)
0035 {
0036 global $db, $template, $auth;
0037
0038 $sql_where = '';
0039 switch ($mode)
0040 {
0041 case 'register':
0042 // If the field is required we show it on the registration page and do not show hidden fields
0043 $sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0';
0044 break;
0045
0046 case 'profile':
0047 // Show hidden fields to moderators/admins
0048 if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
0049 {
0050 $sql_where .= ' AND f.field_hide = 0';
0051 }
0052 break;
0053
0054 default:
0055 trigger_error('Wrong profile mode specified', E_USER_ERROR);
0056 break;
0057 }
0058
0059 $sql = 'SELECT l.*, f.*
0060 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
0061 WHERE f.field_active = 1
0062 $sql_where
0063 AND l.lang_id = $lang_id
0064 AND l.field_id = f.field_id
0065 ORDER BY f.field_order";
0066 $result = $db->sql_query($sql);
0067
0068 while ($row = $db->sql_fetchrow($result))
0069 {
0070 // Return templated field
0071 $tpl_snippet = $this->process_field_row('change', $row);
0072
0073 // Some types are multivalue, we can't give them a field_id as we would not know which to pick
0074 $type = (int) $row['field_type'];
0075
0076 $template->assign_block_vars('profile_fields', array(
0077 'LANG_NAME' => $row['lang_name'],
0078 'LANG_EXPLAIN' => $row['lang_explain'],
0079 'FIELD' => $tpl_snippet,
0080 'FIELD_ID' => ($type == FIELD_DATE || ($type == FIELD_BOOL && $row['field_length'] == '1')) ? '' : 'pf_' . $row['field_ident'],
0081 'S_REQUIRED' => ($row['field_required']) ? true : false)
0082 );
0083 }
0084 $db->sql_freeresult($result);
0085 }
0086
0087 /**
0088 * Validate entered profile field data
0089 * @access public
0090 */
0091 function validate_profile_field($field_type, &$field_value, $field_data)
0092 {
0093 switch ($field_type)
0094 {
0095 case FIELD_INT:
0096 case FIELD_DROPDOWN:
0097 $field_value = (int) $field_value;
0098 break;
0099
0100 case FIELD_BOOL:
0101 $field_value = (bool) $field_value;
0102 break;
0103 }
0104
0105 switch ($field_type)
0106 {
0107 case FIELD_DATE:
0108 $field_validate = explode('-', $field_value);
0109
0110 $day = (isset($field_validate[0])) ? (int) $field_validate[0] : 0;
0111 $month = (isset($field_validate[1])) ? (int) $field_validate[1] : 0;
0112 $year = (isset($field_validate[2])) ? (int) $field_validate[2] : 0;
0113
0114 if ((!$day || !$month || !$year) && !$field_data['field_required'])
0115 {
0116 return false;
0117 }
0118
0119 if ((!$day || !$month || !$year) && $field_data['field_required'])
0120 {
0121 return 'FIELD_REQUIRED';
0122 }
0123
0124 if ($day < 0 || $day > 31 || $month < 0 || $month > 12 || ($year < 1901 && $year > 0) || $year > gmdate('Y', time()) + 50)
0125 {
0126 return 'FIELD_INVALID_DATE';
0127 }
0128
0129 if (checkdate($month, $day, $year) === false)
0130 {
0131 return 'FIELD_INVALID_DATE';
0132 }
0133 break;
0134
0135 case FIELD_BOOL:
0136 if (!$field_value && $field_data['field_required'])
0137 {
0138 return 'FIELD_REQUIRED';
0139 }
0140 break;
0141
0142 case FIELD_INT:
0143 if (empty($field_value) && !$field_data['field_required'])
0144 {
0145 return false;
0146 }
0147
0148 if ($field_value < $field_data['field_minlen'])
0149 {
0150 return 'FIELD_TOO_SMALL';
0151 }
0152 else if ($field_value > $field_data['field_maxlen'])
0153 {
0154 return 'FIELD_TOO_LARGE';
0155 }
0156 break;
0157
0158 case FIELD_DROPDOWN:
0159 if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
0160 {
0161 return 'FIELD_REQUIRED';
0162 }
0163 break;
0164
0165 case FIELD_STRING:
0166 case FIELD_TEXT:
0167 if (empty($field_value) && !$field_data['field_required'])
0168 {
0169 return false;
0170 }
0171 else if (empty($field_value) && $field_data['field_required'])
0172 {
0173 return 'FIELD_REQUIRED';
0174 }
0175
0176 if ($field_data['field_minlen'] && utf8_strlen($field_value) < $field_data['field_minlen'])
0177 {
0178 return 'FIELD_TOO_SHORT';
0179 }
0180 else if ($field_data['field_maxlen'] && utf8_strlen($field_value) > $field_data['field_maxlen'])
0181 {
0182 return 'FIELD_TOO_LONG';
0183 }
0184
0185 if (!empty($field_data['field_validation']) && $field_data['field_validation'] != '.*')
0186 {
0187 $field_validate = ($field_type == FIELD_STRING) ? $field_value : bbcode_nl2br($field_value);
0188 if (!preg_match('#^' . str_replace('\\\\', '\\', $field_data['field_validation']) . '$#i', $field_validate))
0189 {
0190 return 'FIELD_INVALID_CHARS';
0191 }
0192 }
0193 break;
0194 }
0195
0196 return false;
0197 }
0198
0199 /**
0200 * Build profile cache, used for display
0201 * @access private
0202 */
0203 function build_cache()
0204 {
0205 global $db, $user, $auth;
0206
0207 $this->profile_cache = array();
0208
0209 // Display hidden/no_view fields for admin/moderator
0210 $sql = 'SELECT l.*, f.*
0211 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
0212 WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
0213 AND f.field_active = 1 ' .
0214 ((!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_')) ? ' AND f.field_hide = 0 ' : '') . '
0215 AND f.field_no_view = 0
0216 AND l.field_id = f.field_id
0217 ORDER BY f.field_order';
0218 $result = $db->sql_query($sql);
0219
0220 while ($row = $db->sql_fetchrow($result))
0221 {
0222 $this->profile_cache[$row['field_ident']] = $row;
0223 }
0224 $db->sql_freeresult($result);
0225 }
0226
0227 /**
0228 * Get language entries for options and store them here for later use
0229 */
0230 function get_option_lang($field_id, $lang_id, $field_type, $preview)
0231 {
0232 global $db;
0233
0234 if ($preview)
0235 {
0236 $lang_options = (!is_array($this->vars['lang_options'])) ? explode("\n", $this->vars['lang_options']) : $this->vars['lang_options'];
0237
0238 foreach ($lang_options as $num => $var)
0239 {
0240 $this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
0241 }
0242 }
0243 else
0244 {
0245 $sql = 'SELECT option_id, lang_value
0246 FROM ' . PROFILE_FIELDS_LANG_TABLE . "
0247 WHERE field_id = $field_id
0248 AND lang_id = $lang_id
0249 AND field_type = $field_type
0250 ORDER BY option_id";
0251 $result = $db->sql_query($sql);
0252
0253 while ($row = $db->sql_fetchrow($result))
0254 {
0255 $this->options_lang[$field_id][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
0256 }
0257 $db->sql_freeresult($result);
0258 }
0259 }
0260
0261 /**
0262 * Submit profile field
0263 * @access public
0264 */
0265 function submit_cp_field($mode, $lang_id, &$cp_data, &$cp_error)
0266 {
0267 global $auth, $db, $user;
0268
0269 $sql_where = '';
0270 switch ($mode)
0271 {
0272 case 'register':
0273 // If the field is required we show it on the registration page and do not show hidden fields
0274 $sql_where .= ' AND (f.field_show_on_reg = 1 OR f.field_required = 1) AND f.field_hide = 0';
0275 break;
0276
0277 case 'profile':
0278 // Show hidden fields to moderators/admins
0279 if (!$auth->acl_gets('a_', 'm_') && !$auth->acl_getf_global('m_'))
0280 {
0281 $sql_where .= ' AND f.field_hide = 0';
0282 }
0283 break;
0284
0285 default:
0286 trigger_error('Wrong profile mode specified', E_USER_ERROR);
0287 break;
0288 }
0289
0290 $sql = 'SELECT l.*, f.*
0291 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . " f
0292 WHERE l.lang_id = $lang_id
0293 AND f.field_active = 1
0294 $sql_where
0295 AND l.field_id = f.field_id
0296 ORDER BY f.field_order";
0297 $result = $db->sql_query($sql);
0298
0299 while ($row = $db->sql_fetchrow($result))
0300 {
0301 $cp_data['pf_' . $row['field_ident']] = $this->get_profile_field($row);
0302 $check_value = $cp_data['pf_' . $row['field_ident']];
0303
0304 if (($cp_result = $this->validate_profile_field($row['field_type'], $check_value, $row)) !== false)
0305 {
0306 // If not and only showing common error messages, use this one
0307 $error = '';
0308 switch ($cp_result)
0309 {
0310 case 'FIELD_INVALID_DATE':
0311 case 'FIELD_REQUIRED':
0312 $error = sprintf($user->lang[$cp_result], $row['lang_name']);
0313 break;
0314
0315 case 'FIELD_TOO_SHORT':
0316 case 'FIELD_TOO_SMALL':
0317 $error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_minlen']);
0318 break;
0319
0320 case 'FIELD_TOO_LONG':
0321 case 'FIELD_TOO_LARGE':
0322 $error = sprintf($user->lang[$cp_result], $row['lang_name'], $row['field_maxlen']);
0323 break;
0324
0325 case 'FIELD_INVALID_CHARS':
0326 switch ($row['field_validation'])
0327 {
0328 case '[0-9]+':
0329 $error = sprintf($user->lang[$cp_result . '_NUMBERS_ONLY'], $row['lang_name']);
0330 break;
0331
0332 case '[\w]+':
0333 $error = sprintf($user->lang[$cp_result . '_ALPHA_ONLY'], $row['lang_name']);
0334 break;
0335
0336 case '[\w_\+\. \-\[\]]+':
0337 $error = sprintf($user->lang[$cp_result . '_SPACERS_ONLY'], $row['lang_name']);
0338 break;
0339 }
0340 break;
0341 }
0342
0343 if ($error != '')
0344 {
0345 $cp_error[] = $error;
0346 }
0347 }
0348 }
0349 $db->sql_freeresult($result);
0350 }
0351
0352 /**
0353 * Assign fields to template, used for viewprofile, viewtopic and memberlist (if load setting is enabled)
0354 * This is directly connected to the user -> mode == grab is to grab the user specific fields, mode == show is for assigning the row to the template
0355 * @access public
0356 */
0357 function generate_profile_fields_template($mode, $user_id = 0, $profile_row = false)
0358 {
0359 global $db;
0360
0361 if ($mode == 'grab')
0362 {
0363 if (!is_array($user_id))
0364 {
0365 $user_id = array($user_id);
0366 }
0367
0368 if (!sizeof($this->profile_cache))
0369 {
0370 $this->build_cache();
0371 }
0372
0373 if (!sizeof($user_id))
0374 {
0375 return array();
0376 }
0377
0378 $sql = 'SELECT *
0379 FROM ' . PROFILE_FIELDS_DATA_TABLE . '
0380 WHERE ' . $db->sql_in_set('user_id', array_map('intval', $user_id));
0381 $result = $db->sql_query($sql);
0382
0383 $field_data = array();
0384 while ($row = $db->sql_fetchrow($result))
0385 {
0386 $field_data[$row['user_id']] = $row;
0387 }
0388 $db->sql_freeresult($result);
0389
0390 $user_fields = array();
0391
0392 // Go through the fields in correct order
0393 foreach (array_keys($this->profile_cache) as $used_ident)
0394 {
0395 foreach ($field_data as $user_id => $row)
0396 {
0397 $user_fields[$user_id][$used_ident]['value'] = $row['pf_' . $used_ident];
0398 $user_fields[$user_id][$used_ident]['data'] = $this->profile_cache[$used_ident];
0399 }
0400 }
0401
0402 return $user_fields;
0403 }
0404 else if ($mode == 'show')
0405 {
0406 // $profile_row == $user_fields[$row['user_id']];
0407 $tpl_fields = array();
0408 $tpl_fields['row'] = $tpl_fields['blockrow'] = array();
0409
0410 foreach ($profile_row as $ident => $ident_ary)
0411 {
0412 $value = $this->get_profile_value($ident_ary);
0413
0414 if ($value === NULL)
0415 {
0416 continue;
0417 }
0418
0419 $tpl_fields['row'] += array(
0420 'PROFILE_' . strtoupper($ident) . '_VALUE' => $value,
0421 'PROFILE_' . strtoupper($ident) . '_TYPE' => $ident_ary['data']['field_type'],
0422 'PROFILE_' . strtoupper($ident) . '_NAME' => $ident_ary['data']['lang_name'],
0423 'PROFILE_' . strtoupper($ident) . '_EXPLAIN'=> $ident_ary['data']['lang_explain'],
0424
0425 'S_PROFILE_' . strtoupper($ident) => true
0426 );
0427
0428 $tpl_fields['blockrow'][] = array(
0429 'PROFILE_FIELD_VALUE' => $value,
0430 'PROFILE_FIELD_TYPE' => $ident_ary['data']['field_type'],
0431 'PROFILE_FIELD_NAME' => $ident_ary['data']['lang_name'],
0432 'PROFILE_FIELD_EXPLAIN' => $ident_ary['data']['lang_explain'],
0433
0434 'S_PROFILE_' . strtoupper($ident) => true
0435 );
0436 }
0437
0438 return $tpl_fields;
0439 }
0440 else
0441 {
0442 trigger_error('Wrong mode for custom profile', E_USER_ERROR);
0443 }
0444 }
0445
0446 /**
0447 * Get Profile Value for display
0448 */
0449 function get_profile_value($ident_ary)
0450 {
0451 $value = $ident_ary['value'];
0452 $field_type = $ident_ary['data']['field_type'];
0453
0454 switch ($this->profile_types[$field_type])
0455 {
0456 case 'int':
0457 if ($value == '')
0458 {
0459 return NULL;
0460 }
0461 return (int) $value;
0462 break;
0463
0464 case 'string':
0465 case 'text':
0466 if (!$value)
0467 {
0468 return NULL;
0469 }
0470
0471 $value = make_clickable($value);
0472 $value = censor_text($value);
0473 $value = bbcode_nl2br($value);
0474 return $value;
0475 break;
0476
0477 // case 'datetime':
0478 case 'date':
0479 $date = explode('-', $value);
0480 $day = (isset($date[0])) ? (int) $date[0] : 0;
0481 $month = (isset($date[1])) ? (int) $date[1] : 0;
0482 $year = (isset($date[2])) ? (int) $date[2] : 0;
0483
0484 if (!$day && !$month && !$year)
0485 {
0486 return NULL;
0487 }
0488 else if ($day && $month && $year)
0489 {
0490 global $user;
0491 return $user->format_date(mktime(0, 0, 0, $month, $day, $year), $user->lang['DATE_FORMAT'], true);
0492 }
0493
0494 return $value;
0495 break;
0496
0497 case 'dropdown':
0498 $field_id = $ident_ary['data']['field_id'];
0499 $lang_id = $ident_ary['data']['lang_id'];
0500 if (!isset($this->options_lang[$field_id][$lang_id]))
0501 {
0502 $this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
0503 }
0504
0505 if ($value == $ident_ary['data']['field_novalue'])
0506 {
0507 return NULL;
0508 }
0509
0510 $value = (int) $value;
0511
0512 // User not having a value assigned
0513 if (!isset($this->options_lang[$field_id][$lang_id][$value]))
0514 {
0515 return NULL;
0516 }
0517
0518 return $this->options_lang[$field_id][$lang_id][$value];
0519 break;
0520
0521 case 'bool':
0522 $field_id = $ident_ary['data']['field_id'];
0523 $lang_id = $ident_ary['data']['lang_id'];
0524 if (!isset($this->options_lang[$field_id][$lang_id]))
0525 {
0526 $this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
0527 }
0528
0529 if ($ident_ary['data']['field_length'] == 1)
0530 {
0531 return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;
0532 }
0533 else if (!$value)
0534 {
0535 return NULL;
0536 }
0537 else
0538 {
0539 return $this->options_lang[$field_id][$lang_id][(int) ($value) + 1];
0540 }
0541 break;
0542
0543 default:
0544 trigger_error('Unknown profile type', E_USER_ERROR);
0545 break;
0546 }
0547 }
0548
0549 /**
0550 * Get field value for registration/profile
0551 * @access private
0552 */
0553 function get_var($field_validation, &$profile_row, $default_value, $preview)
0554 {
0555 global $user;
0556
0557 $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
0558 $user_ident = $profile_row['field_ident'];
0559 // checkbox - only testing for isset
0560 if ($profile_row['field_type'] == FIELD_BOOL && $profile_row['field_length'] == 2)
0561 {
0562 $value = (isset($_REQUEST[$profile_row['field_ident']])) ? true : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);
0563 }
0564 else if ($profile_row['field_type'] == FIELD_INT)
0565 {
0566 if (isset($_REQUEST[$profile_row['field_ident']]))
0567 {
0568 $value = ($_REQUEST[$profile_row['field_ident']] === '') ? NULL : request_var($profile_row['field_ident'], $default_value);
0569 }
0570 else
0571 {
0572 if (!$preview && isset($user->profile_fields[$user_ident]) && is_null($user->profile_fields[$user_ident]))
0573 {
0574 $value = NULL;
0575 }
0576 else if (!isset($user->profile_fields[$user_ident]) || $preview)
0577 {
0578 $value = $default_value;
0579 }
0580 else
0581 {
0582 $value = $user->profile_fields[$user_ident];
0583 }
0584 }
0585
0586 return (is_null($value)) ? '' : (int) $value;
0587 }
0588 else
0589 {
0590 $value = (isset($_REQUEST[$profile_row['field_ident']])) ? request_var($profile_row['field_ident'], $default_value, true) : ((!isset($user->profile_fields[$user_ident]) || $preview) ? $default_value : $user->profile_fields[$user_ident]);
0591
0592 if (gettype($value) == 'string')
0593 {
0594 $value = utf8_normalize_nfc($value);
0595 }
0596 }
0597
0598 switch ($field_validation)
0599 {
0600 case 'int':
0601 return (int) $value;
0602 break;
0603 }
0604
0605 return $value;
0606 }
0607
0608 /**
0609 * Process int-type
0610 * @access private
0611 */
0612 function generate_int($profile_row, $preview = false)
0613 {
0614 global $template;
0615
0616 $profile_row['field_value'] = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
0617 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
0618 }
0619
0620 /**
0621 * Process date-type
0622 * @access private
0623 */
0624 function generate_date($profile_row, $preview = false)
0625 {
0626 global $user, $template;
0627
0628 $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
0629 $user_ident = $profile_row['field_ident'];
0630
0631 $now = getdate();
0632
0633 if (!isset($_REQUEST[$profile_row['field_ident'] . '_day']))
0634 {
0635 if ($profile_row['field_default_value'] == 'now')
0636 {
0637 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
0638 }
0639 list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
0640 }
0641 else
0642 {
0643 if ($preview && $profile_row['field_default_value'] == 'now')
0644 {
0645 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
0646 list($day, $month, $year) = explode('-', ((!isset($user->profile_fields[$user_ident]) || $preview) ? $profile_row['field_default_value'] : $user->profile_fields[$user_ident]));
0647 }
0648 else
0649 {
0650 $day = request_var($profile_row['field_ident'] . '_day', 0);
0651 $month = request_var($profile_row['field_ident'] . '_month', 0);
0652 $year = request_var($profile_row['field_ident'] . '_year', 0);
0653 }
0654 }
0655
0656 $profile_row['s_day_options'] = '<option value="0"' . ((!$day) ? ' selected="selected"' : '') . '>--</option>';
0657 for ($i = 1; $i < 32; $i++)
0658 {
0659 $profile_row['s_day_options'] .= '<option value="' . $i . '"' . (($i == $day) ? ' selected="selected"' : '') . ">$i</option>";
0660 }
0661
0662 $profile_row['s_month_options'] = '<option value="0"' . ((!$month) ? ' selected="selected"' : '') . '>--</option>';
0663 for ($i = 1; $i < 13; $i++)
0664 {
0665 $profile_row['s_month_options'] .= '<option value="' . $i . '"' . (($i == $month) ? ' selected="selected"' : '') . ">$i</option>";
0666 }
0667
0668 $profile_row['s_year_options'] = '<option value="0"' . ((!$year) ? ' selected="selected"' : '') . '>--</option>';
0669 for ($i = $now['year'] - 100; $i <= $now['year']; $i++)
0670 {
0671 $profile_row['s_year_options'] .= '<option value="' . $i . '"' . (($i == $year) ? ' selected="selected"' : '') . ">$i</option>";
0672 }
0673 unset($now);
0674
0675 $profile_row['field_value'] = 0;
0676 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
0677 }
0678
0679 /**
0680 * Process bool-type
0681 * @access private
0682 */
0683 function generate_bool($profile_row, $preview = false)
0684 {
0685 global $template;
0686
0687 $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
0688
0689 $profile_row['field_value'] = $value;
0690 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
0691
0692 if ($profile_row['field_length'] == 1)
0693 {
0694 if (!isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]))
0695 {
0696 $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_BOOL, $preview);
0697 }
0698
0699 foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
0700 {
0701 $template->assign_block_vars('bool.options', array(
0702 'OPTION_ID' => $option_id,
0703 'CHECKED' => ($value == $option_id) ? ' checked="checked"' : '',
0704 'VALUE' => $option_value)
0705 );
0706 }
0707 }
0708 }
0709
0710 /**
0711 * Process string-type
0712 * @access private
0713 */
0714 function generate_string($profile_row, $preview = false)
0715 {
0716 global $template;
0717
0718 $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
0719 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
0720 }
0721
0722 /**
0723 * Process text-type
0724 * @access private
0725 */
0726 function generate_text($profile_row, $preview = false)
0727 {
0728 global $template;
0729 global $user, $phpEx, $phpbb_root_path;
0730
0731 $field_length = explode('|', $profile_row['field_length']);
0732 $profile_row['field_rows'] = $field_length[0];
0733 $profile_row['field_cols'] = $field_length[1];
0734
0735 $profile_row['field_value'] = $this->get_var('string', $profile_row, $profile_row['lang_default_value'], $preview);
0736 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
0737 }
0738
0739 /**
0740 * Process dropdown-type
0741 * @access private
0742 */
0743 function generate_dropdown($profile_row, $preview = false)
0744 {
0745 global $user, $template;
0746
0747 $value = $this->get_var('int', $profile_row, $profile_row['field_default_value'], $preview);
0748
0749 if (!isset($this->options_lang[$profile_row['field_id']]) || !isset($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]) || !sizeof($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']]))
0750 {
0751 $this->get_option_lang($profile_row['field_id'], $profile_row['lang_id'], FIELD_DROPDOWN, $preview);
0752 }
0753
0754 $profile_row['field_value'] = $value;
0755 $template->assign_block_vars($this->profile_types[$profile_row['field_type']], array_change_key_case($profile_row, CASE_UPPER));
0756
0757 foreach ($this->options_lang[$profile_row['field_id']][$profile_row['lang_id']] as $option_id => $option_value)
0758 {
0759 $template->assign_block_vars('dropdown.options', array(
0760 'OPTION_ID' => $option_id,
0761 'SELECTED' => ($value == $option_id) ? ' selected="selected"' : '',
0762 'VALUE' => $option_value)
0763 );
0764 }
0765 }
0766
0767 /**
0768 * Return Templated value/field. Possible values for $mode are:
0769 * change == user is able to set/enter profile values; preview == just show the value
0770 * @access private
0771 */
0772 function process_field_row($mode, $profile_row)
0773 {
0774 global $template;
0775
0776 $preview = ($mode == 'preview') ? true : false;
0777
0778 // set template filename
0779 $template->set_filenames(array(
0780 'cp_body' => 'custom_profile_fields.html')
0781 );
0782
0783 // empty previously filled blockvars
0784 foreach ($this->profile_types as $field_case => $field_type)
0785 {
0786 $template->destroy_block_vars($field_type);
0787 }
0788
0789 // Assign template variables
0790 $type_func = 'generate_' . $this->profile_types[$profile_row['field_type']];
0791 $this->$type_func($profile_row, $preview);
0792
0793 // Return templated data
0794 return $template->assign_display('cp_body');
0795 }
0796
0797 /**
0798 * Build Array for user insertion into custom profile fields table
0799 */
0800 function build_insert_sql_array($cp_data)
0801 {
0802 global $db, $user, $auth;
0803
0804 $sql_not_in = array();
0805 foreach ($cp_data as $key => $null)
0806 {
0807 $sql_not_in[] = (strncmp($key, 'pf_', 3) === 0) ? substr($key, 3) : $key;
0808 }
0809
0810 $sql = 'SELECT f.field_type, f.field_ident, f.field_default_value, l.lang_default_value
0811 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
0812 WHERE l.lang_id = ' . $user->get_iso_lang_id() . '
0813 ' . ((sizeof($sql_not_in)) ? ' AND ' . $db->sql_in_set('f.field_ident', $sql_not_in, true) : '') . '
0814 AND l.field_id = f.field_id';
0815 $result = $db->sql_query($sql);
0816
0817 while ($row = $db->sql_fetchrow($result))
0818 {
0819 if ($row['field_default_value'] == 'now' && $row['field_type'] == FIELD_DATE)
0820 {
0821 $now = getdate();
0822 $row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
0823 }
0824
0825 $cp_data['pf_' . $row['field_ident']] = (in_array($row['field_type'], array(FIELD_TEXT, FIELD_STRING))) ? $row['lang_default_value'] : $row['field_default_value'];
0826 }
0827 $db->sql_freeresult($result);
0828
0829 return $cp_data;
0830 }
0831
0832 /**
0833 * Get profile field value on submit
0834 * @access private
0835 */
0836 function get_profile_field($profile_row)
0837 {
0838 global $phpbb_root_path, $phpEx;
0839 global $config;
0840
0841 $var_name = 'pf_' . $profile_row['field_ident'];
0842
0843 switch ($profile_row['field_type'])
0844 {
0845 case FIELD_DATE:
0846
0847 if (!isset($_REQUEST[$var_name . '_day']))
0848 {
0849 if ($profile_row['field_default_value'] == 'now')
0850 {
0851 $now = getdate();
0852 $profile_row['field_default_value'] = sprintf('%2d-%2d-%4d', $now['mday'], $now['mon'], $now['year']);
0853 }
0854 list($day, $month, $year) = explode('-', $profile_row['field_default_value']);
0855 }
0856 else
0857 {
0858 $day = request_var($var_name . '_day', 0);
0859 $month = request_var($var_name . '_month', 0);
0860 $year = request_var($var_name . '_year', 0);
0861 }
0862
0863 $var = sprintf('%2d-%2d-%4d', $day, $month, $year);
0864 break;
0865
0866 case FIELD_BOOL:
0867 // Checkbox
0868 if ($profile_row['field_length'] == 2)
0869 {
0870 $var = (isset($_REQUEST[$var_name])) ? 1 : 0;
0871 }
0872 else
0873 {
0874 $var = request_var($var_name, $profile_row['field_default_value']);
0875 }
0876 break;
0877
0878 case FIELD_STRING:
0879 case FIELD_TEXT:
0880 $var = utf8_normalize_nfc(request_var($var_name, $profile_row['field_default_value'], true));
0881 break;
0882
0883 case FIELD_INT:
0884 if (isset($_REQUEST[$var_name]) && $_REQUEST[$var_name] === '')
0885 {
0886 $var = NULL;
0887 }
0888 else
0889 {
0890 $var = request_var($var_name, $profile_row['field_default_value']);
0891 }
0892 break;
0893
0894 default:
0895 $var = request_var($var_name, $profile_row['field_default_value']);
0896 break;
0897 }
0898
0899 return $var;
0900 }
0901 }
0902
0903 /**
0904 * Custom Profile Fields ACP
0905 * @package phpBB3
0906 */
0907 class custom_profile_admin extends custom_profile
0908 {
0909 var $vars = array();
0910
0911 /**
0912 * Return possible validation options
0913 */
0914 function validate_options()
0915 {
0916 global $user;
0917
0918 $validate_ary = array('CHARS_ANY' => '.*', 'NUMBERS_ONLY' => '[0-9]+', 'ALPHA_ONLY' => '[\w]+', 'ALPHA_SPACERS' => '[\w_\+\. \-\[\]]+');
0919
0920 $validate_options = '';
0921 foreach ($validate_ary as $lang => $value)
0922 {
0923 $selected = ($this->vars['field_validation'] == $value) ? ' selected="selected"' : '';
0924 $validate_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang[$lang] . '</option>';
0925 }
0926
0927 return $validate_options;
0928 }
0929
0930 /**
0931 * Get string options for second step in ACP
0932 */
0933 function get_string_options()
0934 {
0935 global $user;
0936
0937 $options = array(
0938 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
0939 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
0940 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
0941 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
0942 );
0943
0944 return $options;
0945 }
0946
0947 /**
0948 * Get text options for second step in ACP
0949 */
0950 function get_text_options()
0951 {
0952 global $user;
0953
0954 $options = array(
0955 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input name="rows" size="5" value="' . $this->vars['rows'] . '" /> ' . $user->lang['ROWS'] . '</dd><dd><input name="columns" size="5" value="' . $this->vars['columns'] . '" /> ' . $user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $this->vars['field_length'] . '" />'),
0956 1 => array('TITLE' => $user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_minlen" size="10" value="' . $this->vars['field_minlen'] . '" />'),
0957 2 => array('TITLE' => $user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="text" name="field_maxlen" size="10" value="' . $this->vars['field_maxlen'] . '" />'),
0958 3 => array('TITLE' => $user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options() . '</select>')
0959 );
0960
0961 return $options;
0962 }
0963
0964 /**
0965 * Get int options for second step in ACP
0966 */
0967 function get_int_options()
0968 {
0969 global $user;
0970
0971 $options = array(
0972 0 => array('TITLE' => $user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="text" name="field_length" size="5" value="' . $this->vars['field_length'] . '" />'),
0973 1 => array('TITLE' => $user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_minlen" size="5" value="' . $this->vars['field_minlen'] . '" />'),
0974 2 => array('TITLE' => $user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="text" name="field_maxlen" size="5" value="' . $this->vars['field_maxlen'] . '" />'),
0975 3 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="post" name="field_default_value" value="' . $this->vars['field_default_value'] . '" />')
0976 );
0977
0978 return $options;
0979 }
0980
0981 /**
0982 * Get bool options for second step in ACP
0983 */
0984 function get_bool_options()
0985 {
0986 global $user, $config, $lang_defs;
0987
0988 $default_lang_id = $lang_defs['iso'][$config['default_lang']];
0989
0990 $profile_row = array(
0991 'var_name' => 'field_default_value',
0992 'field_id' => 1,
0993 'lang_name' => $this->vars['lang_name'],
0994 'lang_explain' => $this->vars['lang_explain'],
0995 'lang_id' => $default_lang_id,
0996 'field_default_value' => $this->vars['field_default_value'],
0997 'field_ident' => 'field_default_value',
0998 'field_type' => FIELD_BOOL,
0999 'field_length' => $this->vars['field_length'],
1000 'lang_options' => $this->vars['lang_options']
1001 );
1002
1003 $options = array(
1004 0 => array('TITLE' => $user->lang['FIELD_TYPE'], 'EXPLAIN' => $user->lang['BOOL_TYPE_EXPLAIN'], 'FIELD' => '<label><input type="radio" class="radio" name="field_length" value="1"' . (($this->vars['field_length'] == 1) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['RADIO_BUTTONS'] . '</label><label><input type="radio" class="radio" name="field_length" value="2"' . (($this->vars['field_length'] == 2) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['CHECKBOX'] . '</label>'),
1005 1 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row))
1006 );
1007
1008 return $options;
1009 }
1010
1011 /**
1012 * Get dropdown options for second step in ACP
1013 */
1014 function get_dropdown_options()
1015 {
1016 global $user, $config, $lang_defs;
1017
1018 $default_lang_id = $lang_defs['iso'][$config['default_lang']];
1019
1020 $profile_row[0] = array(
1021 'var_name' => 'field_default_value',
1022 'field_id' => 1,
1023 'lang_name' => $this->vars['lang_name'],
1024 'lang_explain' => $this->vars['lang_explain'],
1025 'lang_id' => $default_lang_id,
1026 'field_default_value' => $this->vars['field_default_value'],
1027 'field_ident' => 'field_default_value',
1028 'field_type' => FIELD_DROPDOWN,
1029 'lang_options' => $this->vars['lang_options']
1030 );
1031
1032 $profile_row[1] = $profile_row[0];
1033 $profile_row[1]['var_name'] = 'field_novalue';
1034 $profile_row[1]['field_ident'] = 'field_novalue';
1035 $profile_row[1]['field_default_value'] = $this->vars['field_novalue'];
1036
1037 $options = array(
1038 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
1039 1 => array('TITLE' => $user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1]))
1040 );
1041
1042 return $options;
1043 }
1044
1045 /**
1046 * Get date options for second step in ACP
1047 */
1048 function get_date_options()
1049 {
1050 global $user, $config, $lang_defs;
1051
1052 $default_lang_id = $lang_defs['iso'][$config['default_lang']];
1053
1054 $profile_row = array(
1055 'var_name' => 'field_default_value',
1056 'lang_name' => $this->vars['lang_name'],
1057 'lang_explain' => $this->vars['lang_explain'],
1058 'lang_id' => $default_lang_id,
1059 'field_default_value' => $this->vars['field_default_value'],
1060 'field_ident' => 'field_default_value',
1061 'field_type' => FIELD_DATE,
1062 'field_length' => $this->vars['field_length']
1063 );
1064
1065 $always_now = request_var('always_now', -1);
1066 if ($always_now == -1)
1067 {
1068 $s_checked = ($this->vars['field_default_value'] == 'now') ? true : false;
1069 }
1070 else
1071 {
1072 $s_checked = ($always_now) ? true : false;
1073 }
1074
1075 $options = array(
1076 0 => array('TITLE' => $user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row)),
1077 1 => array('TITLE' => $user->lang['ALWAYS_TODAY'], 'FIELD' => '<label><input type="radio" class="radio" name="always_now" value="1"' . (($s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['YES'] . '</label><label><input type="radio" class="radio" name="always_now" value="0"' . ((!$s_checked) ? ' checked="checked"' : '') . ' onchange="document.getElementById(\'add_profile_field\').submit();" /> ' . $user->lang['NO'] . '</label>'),
1078 );
1079
1080 return $options;
1081 }
1082 }
1083
1084 ?>