6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
29 function main($id, $mode)
31 global $config, $db, $user, $auth, $template, $cache;
32 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
34 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
35 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
36 include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
38 $user->add_lang(array('ucp', 'acp/profile'));
39 $this->tpl_name = 'acp_profile';
40 $this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';
42 $action = (isset($_POST['create'])) ? 'create' : request_var('action', '');
45 $s_hidden_fields = '';
47 // Define some default values for each field type
48 $default_values = array(
49 FIELD_STRING => array('field_length' => 10, 'field_minlen' => 0, 'field_maxlen' => 20, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
50 FIELD_TEXT => array('field_length' => '5|80', 'field_minlen' => 0, 'field_maxlen' => 1000, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
51 FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
52 FIELD_DATE => array('field_length' => 10, 'field_minlen' => 10, 'field_maxlen' => 10, 'field_validation' => '', 'field_novalue' => ' 0- 0- 0', 'field_default_value' => ' 0- 0- 0'),
53 FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
54 FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
57 $cp = new custom_profile_admin();
59 // Build Language array
60 // Based on this, we decide which elements need to be edited later and which language items are missing
61 $this->lang_defs = array();
63 $sql = 'SELECT lang_id, lang_iso
64 FROM ' . LANG_TABLE . '
65 ORDER BY lang_english_name';
66 $result = $db->sql_query($sql);
68 while ($row = $db->sql_fetchrow($result))
70 // Make some arrays with all available languages
71 $this->lang_defs['id'][$row['lang_id']] = $row['lang_iso'];
72 $this->lang_defs['iso'][$row['lang_iso']] = $row['lang_id'];
74 $db->sql_freeresult($result);
76 $sql = 'SELECT field_id, lang_id
77 FROM ' . PROFILE_LANG_TABLE . '
79 $result = $db->sql_query($sql);
81 while ($row = $db->sql_fetchrow($result))
83 // Which languages are available for each item
84 $this->lang_defs['entry'][$row['field_id']][] = $row['lang_id'];
86 $db->sql_freeresult($result);
88 // Have some fields been defined?
89 if (isset($this->lang_defs['entry']))
91 foreach ($this->lang_defs['entry'] as $field_id => $field_ary)
93 // Fill an array with the languages that are missing for each field
94 $this->lang_defs['diff'][$field_id] = array_diff(array_values($this->lang_defs['iso']), $field_ary);
101 $field_id = request_var('field_id', 0);
105 trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
108 if (confirm_box(true))
110 $sql = 'SELECT field_ident
111 FROM ' . PROFILE_FIELDS_TABLE . "
112 WHERE field_id = $field_id";
113 $result = $db->sql_query($sql);
114 $field_ident = (string) $db->sql_fetchfield('field_ident');
115 $db->sql_freeresult($result);
117 $db->sql_transaction('begin');
119 $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_TABLE . " WHERE field_id = $field_id");
120 $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
121 $db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");
123 switch ($db->sql_layer)
129 AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
130 ORDER BY type DESC, name;";
131 $result = $db->sql_query($sql);
132 $row = $db->sql_fetchrow($result);
133 $db->sql_freeresult($result);
135 // Create a temp table and populate it, destroy the existing one
136 $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
137 $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
138 $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
140 preg_match('#\((.*)\)#s', $row['sql'], $matches);
142 $new_table_cols = trim($matches[1]);
143 $old_table_cols = preg_split('/,(?=[\\sa-z])/im', $new_table_cols);
144 $column_list = array();
146 foreach ($old_table_cols as $declaration)
148 $entities = preg_split('#\s+#', trim($declaration));
150 if ($entities[0] == 'PRIMARY')
155 if ($entities[0] !== 'pf_' . $field_ident)
157 $column_list[] = $entities[0];
161 $columns = implode(',', $column_list);
163 $new_table_cols = preg_replace('/' . 'pf_' . $field_ident . '[^,]+,/', '', $new_table_cols);
165 // create a new table and fill it up. destroy the temp one
166 $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
167 $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
168 $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
172 $db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident");
178 FROM ' . PROFILE_FIELDS_TABLE . '
179 ORDER BY field_order';
180 $result = $db->sql_query($sql);
182 while ($row = $db->sql_fetchrow($result))
185 if ($row['field_order'] != $order)
187 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
188 SET field_order = $order
189 WHERE field_id = {$row['field_id']}";
190 $db->sql_query($sql);
193 $db->sql_freeresult($result);
195 $db->sql_transaction('commit');
197 add_log('admin', 'LOG_PROFILE_FIELD_REMOVED', $field_ident);
198 trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action));
202 confirm_box(false, 'DELETE_PROFILE_FIELD', build_hidden_fields(array(
206 'field_id' => $field_id,
213 $field_id = request_var('field_id', 0);
217 trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
220 $sql = 'SELECT lang_id
221 FROM ' . LANG_TABLE . "
222 WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
223 $result = $db->sql_query($sql);
224 $default_lang_id = (int) $db->sql_fetchfield('lang_id');
225 $db->sql_freeresult($result);
227 if (!in_array($default_lang_id, $this->lang_defs['entry'][$field_id]))
229 trigger_error($user->lang['DEFAULT_LANGUAGE_NOT_FILLED'] . adm_back_link($this->u_action), E_USER_WARNING);
232 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
234 WHERE field_id = $field_id";
235 $db->sql_query($sql);
237 $sql = 'SELECT field_ident
238 FROM ' . PROFILE_FIELDS_TABLE . "
239 WHERE field_id = $field_id";
240 $result = $db->sql_query($sql);
241 $field_ident = (string) $db->sql_fetchfield('field_ident');
242 $db->sql_freeresult($result);
244 add_log('admin', 'LOG_PROFILE_FIELD_ACTIVATE', $field_ident);
245 trigger_error($user->lang['PROFILE_FIELD_ACTIVATED'] . adm_back_link($this->u_action));
250 $field_id = request_var('field_id', 0);
254 trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
257 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
259 WHERE field_id = $field_id";
260 $db->sql_query($sql);
262 $sql = 'SELECT field_ident
263 FROM ' . PROFILE_FIELDS_TABLE . "
264 WHERE field_id = $field_id";
265 $result = $db->sql_query($sql);
266 $field_ident = (string) $db->sql_fetchfield('field_ident');
267 $db->sql_freeresult($result);
269 add_log('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', $field_ident);
270 trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action));
276 $field_order = request_var('order', 0);
277 $order_total = $field_order * 2 + (($action == 'move_up') ? -1 : 1);
279 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
280 SET field_order = $order_total - field_order
281 WHERE field_order IN ($field_order, " . (($action == 'move_up') ? $field_order - 1 : $field_order + 1) . ')';
282 $db->sql_query($sql);
289 $field_id = request_var('field_id', 0);
290 $step = request_var('step', 1);
292 $submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
293 $save = (isset($_REQUEST['save'])) ? true : false;
295 // The language id of default language
296 $this->edit_lang_id = $this->lang_defs['iso'][$config['default_lang']];
298 // We are editing... we need to grab basic things
299 if ($action == 'edit')
303 trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
306 $sql = 'SELECT l.*, f.*
307 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
308 WHERE l.lang_id = ' . $this->edit_lang_id . "
309 AND f.field_id = $field_id
310 AND l.field_id = f.field_id";
311 $result = $db->sql_query($sql);
312 $field_row = $db->sql_fetchrow($result);
313 $db->sql_freeresult($result);
317 // Some admin changed the default language?
318 $sql = 'SELECT l.*, f.*
319 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
320 WHERE l.lang_id <> ' . $this->edit_lang_id . "
321 AND f.field_id = $field_id
322 AND l.field_id = f.field_id";
323 $result = $db->sql_query($sql);
324 $field_row = $db->sql_fetchrow($result);
325 $db->sql_freeresult($result);
329 trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
332 $this->edit_lang_id = $field_row['lang_id'];
334 $field_type = $field_row['field_type'];
336 // Get language entries
338 FROM ' . PROFILE_FIELDS_LANG_TABLE . '
339 WHERE lang_id = ' . $this->edit_lang_id . "
340 AND field_id = $field_id
341 ORDER BY option_id ASC";
342 $result = $db->sql_query($sql);
344 $lang_options = array();
345 while ($row = $db->sql_fetchrow($result))
347 $lang_options[$row['option_id']] = $row['lang_value'];
349 $db->sql_freeresult($result);
351 $s_hidden_fields = '<input type="hidden" name="field_id" value="' . $field_id . '" />';
355 // We are adding a new field, define basic params
356 $lang_options = $field_row = array();
358 $field_type = request_var('field_type', 0);
362 trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
365 $field_row = array_merge($default_values[$field_type], array(
366 'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),
367 'field_required' => 0,
369 'field_show_profile'=> 0,
370 'field_no_view' => 0,
371 'field_show_on_reg' => 0,
372 'field_show_on_vt' => 0,
373 'lang_name' => utf8_normalize_nfc(request_var('field_ident', '', true)),
374 'lang_explain' => '',
375 'lang_default_value'=> '')
378 $s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
381 // $exclude contains the data we gather in each step
383 1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_vt', 'field_required', 'field_hide', 'field_show_profile', 'field_no_view'),
384 2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
385 3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
388 // Text-based fields require the lang_default_value to be excluded
389 if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
391 $exclude[1][] = 'lang_default_value';
394 // option-specific fields require lang_options to be excluded
395 if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
397 $exclude[1][] = 'lang_options';
400 $cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string(request_var('field_ident', $field_row['field_ident'], true)) : request_var('field_ident', $field_row['field_ident']);
401 $cp->vars['lang_name'] = utf8_normalize_nfc(request_var('lang_name', $field_row['lang_name'], true));
402 $cp->vars['lang_explain'] = utf8_normalize_nfc(request_var('lang_explain', $field_row['lang_explain'], true));
403 $cp->vars['lang_default_value'] = utf8_normalize_nfc(request_var('lang_default_value', $field_row['lang_default_value'], true));
405 // Visibility Options...
406 $visibility_ary = array(
410 'field_show_profile',
414 foreach ($visibility_ary as $val)
416 $cp->vars[$val] = ($submit || $save) ? request_var($val, 0) : $field_row[$val];
419 $cp->vars['field_no_view'] = request_var('field_no_view', (int) $field_row['field_no_view']);
421 // A boolean field expects an array as the lang options
422 if ($field_type == FIELD_BOOL)
424 $options = utf8_normalize_nfc(request_var('lang_options', array(''), true));
428 $options = utf8_normalize_nfc(request_var('lang_options', '', true));
431 // If the user has submitted a form with options (i.e. dropdown field)
434 $exploded_options = (is_array($options)) ? $options : explode("\n", $options);
436 if (sizeof($exploded_options) == sizeof($lang_options) || $action == 'create')
438 // The number of options in the field is equal to the number of options already in the database
439 // Or we are creating a new dropdown list.
440 $cp->vars['lang_options'] = $exploded_options;
442 else if ($action == 'edit')
444 // Changing the number of options? (We remove and re-create the option fields)
445 $cp->vars['lang_options'] = $exploded_options;
450 $cp->vars['lang_options'] = $lang_options;
454 foreach ($exclude[2] as $key)
456 $var = utf8_normalize_nfc(request_var($key, $field_row[$key], true));
458 // Manipulate the intended variables a little bit if needed
459 if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen')
461 // Get the number of options if this key is 'field_maxlen'
462 $var = sizeof(explode("\n", utf8_normalize_nfc(request_var('lang_options', '', true))));
464 else if ($field_type == FIELD_TEXT && $key == 'field_length')
466 if (isset($_REQUEST['rows']))
468 $cp->vars['rows'] = request_var('rows', 0);
469 $cp->vars['columns'] = request_var('columns', 0);
470 $var = $cp->vars['rows'] . '|' . $cp->vars['columns'];
474 $row_col = explode('|', $var);
475 $cp->vars['rows'] = $row_col[0];
476 $cp->vars['columns'] = $row_col[1];
479 else if ($field_type == FIELD_DATE && $key == 'field_default_value')
481 $always_now = request_var('always_now', -1);
483 if ($always_now == 1 || ($always_now === -1 && $var == 'now'))
487 $cp->vars['field_default_value_day'] = $now['mday'];
488 $cp->vars['field_default_value_month'] = $now['mon'];
489 $cp->vars['field_default_value_year'] = $now['year'];
490 $var = $_POST['field_default_value'] = 'now';
494 if (isset($_REQUEST['field_default_value_day']))
496 $cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
497 $cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
498 $cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
499 $var = $_POST['field_default_value'] = sprintf('%2d-%2d-%4d', $cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']);
503 list($cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']) = explode('-', $var);
507 /* else if ($field_type == FIELD_BOOL && $key == 'field_default_value')
509 // Get the number of options if this key is 'field_maxlen'
510 $var = request_var('field_default_value', 0);
512 else if ($field_type == FIELD_INT && $key == 'field_default_value')
514 // Permit an empty string
515 if ($action == 'create' && request_var('field_default_value', '') === '')
521 $cp->vars[$key] = $var;
524 // step 3 - all arrays
525 if ($action == 'edit')
527 // Get language entries
529 FROM ' . PROFILE_FIELDS_LANG_TABLE . '
530 WHERE lang_id <> ' . $this->edit_lang_id . "
531 AND field_id = $field_id
532 ORDER BY option_id ASC";
533 $result = $db->sql_query($sql);
535 $l_lang_options = array();
536 while ($row = $db->sql_fetchrow($result))
538 $l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value'];
540 $db->sql_freeresult($result);
543 $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value
544 FROM ' . PROFILE_LANG_TABLE . '
545 WHERE lang_id <> ' . $this->edit_lang_id . "
546 AND field_id = $field_id
547 ORDER BY lang_id ASC";
548 $result = $db->sql_query($sql);
550 $l_lang_name = $l_lang_explain = $l_lang_default_value = array();
551 while ($row = $db->sql_fetchrow($result))
553 $l_lang_name[$row['lang_id']] = $row['lang_name'];
554 $l_lang_explain[$row['lang_id']] = $row['lang_explain'];
555 $l_lang_default_value[$row['lang_id']] = $row['lang_default_value'];
557 $db->sql_freeresult($result);
560 foreach ($exclude[3] as $key)
562 $cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => ''), true));
564 if (!$cp->vars[$key] && $action == 'edit')
566 $cp->vars[$key] = $$key;
568 else if ($key == 'l_lang_options' && $field_type == FIELD_BOOL)
570 $cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => array('')), true));
572 else if ($key == 'l_lang_options' && is_array($cp->vars[$key]))
574 foreach ($cp->vars[$key] as $lang_id => $options)
576 $cp->vars[$key][$lang_id] = explode("\n", $options);
582 // Check for general issues in every step
583 if ($submit) // && $step == 1
585 // Check values for step 1
586 if ($cp->vars['field_ident'] == '')
588 $error[] = $user->lang['EMPTY_FIELD_IDENT'];
591 if (!preg_match('/^[a-z_]+$/', $cp->vars['field_ident']))
593 $error[] = $user->lang['INVALID_CHARS_FIELD_IDENT'];
596 if (strlen($cp->vars['field_ident']) > 17)
598 $error[] = $user->lang['INVALID_FIELD_IDENT_LEN'];
601 if ($cp->vars['lang_name'] == '')
603 $error[] = $user->lang['EMPTY_USER_FIELD_NAME'];
606 if ($field_type == FIELD_DROPDOWN && !sizeof($cp->vars['lang_options']))
608 $error[] = $user->lang['NO_FIELD_ENTRIES'];
611 if ($field_type == FIELD_BOOL && (empty($cp->vars['lang_options'][0]) || empty($cp->vars['lang_options'][1])))
613 $error[] = $user->lang['NO_FIELD_ENTRIES'];
616 // Check for already existing field ident
617 if ($action != 'edit')
619 $sql = 'SELECT field_ident
620 FROM ' . PROFILE_FIELDS_TABLE . "
621 WHERE field_ident = '" . $db->sql_escape($cp->vars['field_ident']) . "'";
622 $result = $db->sql_query($sql);
623 $row = $db->sql_fetchrow($result);
624 $db->sql_freeresult($result);
628 $error[] = $user->lang['FIELD_IDENT_ALREADY_EXIST'];
633 $step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);
641 // Build up the specific hidden fields
642 foreach ($exclude as $num => $key_ary)
649 $_new_key_ary = array();
651 foreach ($key_ary as $key)
653 if ($field_type == FIELD_TEXT && $key == 'field_length' && isset($_REQUEST['rows']))
655 $cp->vars['rows'] = request_var('rows', 0);
656 $cp->vars['columns'] = request_var('columns', 0);
657 $_new_key_ary[$key] = $cp->vars['rows'] . '|' . $cp->vars['columns'];
659 else if ($field_type == FIELD_DATE && $key == 'field_default_value')
661 $always_now = request_var('always_now', 0);
665 $_new_key_ary[$key] = 'now';
667 else if (isset($_REQUEST['field_default_value_day']))
669 $cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
670 $cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
671 $cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
672 $_new_key_ary[$key] = sprintf('%2d-%2d-%4d', $cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']);
675 else if ($field_type == FIELD_BOOL && $key == 'l_lang_options' && isset($_REQUEST['l_lang_options']))
677 $_new_key_ary[$key] = utf8_normalize_nfc(request_var($key, array(array('')), true));
681 if (!isset($_REQUEST[$key]))
685 else if ($key == 'field_ident' && isset($cp->vars[$key]))
687 $_new_key_ary[$key]= $cp->vars[$key];
691 $_new_key_ary[$key] = (is_array($_REQUEST[$key])) ? utf8_normalize_nfc(request_var($key, array(''), true)) : utf8_normalize_nfc(request_var($key, '', true));
696 $s_hidden_fields .= build_hidden_fields($_new_key_ary);
701 if ($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save))
703 $this->save_profile_field($cp, $field_type, $action);
705 else if ($action == 'edit' && $save)
707 $this->save_profile_field($cp, $field_type, $action);
711 $template->assign_vars(array(
713 'S_EDIT_MODE' => ($action == 'edit') ? true : false,
714 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
716 'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)],
717 'L_EXPLAIN' => $user->lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($action)],
719 'U_ACTION' => $this->u_action . "&action=$action&step=$step",
720 'U_BACK' => $this->u_action)
723 // Now go through the steps
726 // Create basic options - only small differences between field types
729 // Build common create options
730 $template->assign_vars(array(
731 'S_STEP_ONE' => true,
732 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
733 'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
734 'S_SHOW_ON_VT' => ($cp->vars['field_show_on_vt']) ? true : false,
735 'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
736 'S_SHOW_PROFILE' => ($cp->vars['field_show_profile']) ? true : false,
737 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
739 'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
740 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])],
741 'FIELD_IDENT' => $cp->vars['field_ident'],
742 'LANG_NAME' => $cp->vars['lang_name'],
743 'LANG_EXPLAIN' => $cp->vars['lang_explain'])
746 // String and Text needs to set default values here...
747 if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
749 $template->assign_vars(array(
750 'S_TEXT' => ($field_type == FIELD_TEXT) ? true : false,
751 'S_STRING' => ($field_type == FIELD_STRING) ? true : false,
753 'L_DEFAULT_VALUE_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_DEFAULT_VALUE_EXPLAIN'],
754 'LANG_DEFAULT_VALUE' => $cp->vars['lang_default_value'])
758 if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
760 // Initialize these array elements if we are creating a new field
761 if (!sizeof($cp->vars['lang_options']))
763 if ($field_type == FIELD_BOOL)
765 // No options have been defined for a boolean field.
766 $cp->vars['lang_options'][0] = '';
767 $cp->vars['lang_options'][1] = '';
771 // No options have been defined for the dropdown menu
772 $cp->vars['lang_options'] = array();
776 $template->assign_vars(array(
777 'S_BOOL' => ($field_type == FIELD_BOOL) ? true : false,
778 'S_DROPDOWN' => ($field_type == FIELD_DROPDOWN) ? true : false,
780 'L_LANG_OPTIONS_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_ENTRIES_EXPLAIN'],
781 'LANG_OPTIONS' => ($field_type == FIELD_DROPDOWN) ? implode("\n", $cp->vars['lang_options']) : '',
782 'FIRST_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][0] : '',
783 'SECOND_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][1] : '')
791 $template->assign_vars(array(
792 'S_STEP_TWO' => true,
793 'L_NEXT_STEP' => (sizeof($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS'])
796 // Build options based on profile type
797 $function = 'get_' . $cp->profile_types[$field_type] . '_options';
798 $options = $cp->$function();
800 foreach ($options as $num => $option_ary)
802 $template->assign_block_vars('option', $option_ary);
807 // Define remaining language variables
810 $template->assign_var('S_STEP_THREE', true);
811 $options = $this->build_language_options($cp, $field_type, $action);
813 foreach ($options as $lang_id => $lang_ary)
815 $template->assign_block_vars('options', array(
816 'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso']))
819 foreach ($lang_ary['fields'] as $field_ident => $field_ary)
821 $template->assign_block_vars('options.field', array(
822 'L_TITLE' => $field_ary['TITLE'],
823 'L_EXPLAIN' => (isset($field_ary['EXPLAIN'])) ? $field_ary['EXPLAIN'] : '',
824 'FIELD' => $field_ary['FIELD'])
832 $template->assign_vars(array(
833 'S_HIDDEN_FIELDS' => $s_hidden_fields)
842 FROM ' . PROFILE_FIELDS_TABLE . '
843 ORDER BY field_order';
844 $result = $db->sql_query($sql);
846 $s_one_need_edit = false;
847 while ($row = $db->sql_fetchrow($result))
849 $active_lang = (!$row['field_active']) ? 'ACTIVATE' : 'DEACTIVATE';
850 $active_value = (!$row['field_active']) ? 'activate' : 'deactivate';
851 $id = $row['field_id'];
853 $s_need_edit = (sizeof($this->lang_defs['diff'][$row['field_id']])) ? true : false;
857 $s_one_need_edit = true;
860 $template->assign_block_vars('fields', array(
861 'FIELD_IDENT' => $row['field_ident'],
862 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])],
864 'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],
865 'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id",
866 'U_EDIT' => $this->u_action . "&action=edit&field_id=$id",
867 'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
868 'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",
869 'U_MOVE_UP' => $this->u_action . "&action=move_up&order={$row['field_order']}",
870 'U_MOVE_DOWN' => $this->u_action . "&action=move_down&order={$row['field_order']}",
872 'S_NEED_EDIT' => $s_need_edit)
875 $db->sql_freeresult($result);
877 // At least one option field needs editing?
878 if ($s_one_need_edit)
880 $template->assign_var('S_NEED_EDIT', true);
884 foreach ($cp->profile_types as $key => $value)
886 $s_select_type .= '<option value="' . $key . '">' . $user->lang['FIELD_' . strtoupper($value)] . '</option>';
889 $template->assign_vars(array(
890 'U_ACTION' => $this->u_action,
891 'S_TYPE_OPTIONS' => $s_select_type)
896 * Build all Language specific options
898 function build_language_options(&$cp, $field_type, $action = 'create')
900 global $user, $config, $db;
902 $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
904 $sql = 'SELECT lang_id, lang_iso
905 FROM ' . LANG_TABLE . '
906 WHERE lang_id <> ' . (int) $default_lang_id . '
907 ORDER BY lang_english_name';
908 $result = $db->sql_query($sql);
910 $languages = array();
911 while ($row = $db->sql_fetchrow($result))
913 $languages[$row['lang_id']] = $row['lang_iso'];
915 $db->sql_freeresult($result);
918 $options['lang_name'] = 'string';
919 if ($cp->vars['lang_explain'])
921 $options['lang_explain'] = 'text';
927 $options['lang_options'] = 'two_options';
931 $options['lang_options'] = 'optionfield';
936 if (strlen($cp->vars['lang_default_value']))
938 $options['lang_default_value'] = ($field_type == FIELD_STRING) ? 'string' : 'text';
943 $lang_options = array();
945 foreach ($options as $field => $field_type)
947 $lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id];
948 $lang_options[1]['fields'][$field] = array(
949 'TITLE' => $user->lang['CP_' . strtoupper($field)],
950 'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . '</dd>'
953 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
955 $lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
959 foreach ($languages as $lang_id => $lang_iso)
961 $lang_options[$lang_id]['lang_iso'] = $lang_iso;
962 foreach ($options as $field => $field_type)
964 $value = ($action == 'create') ? utf8_normalize_nfc(request_var('l_' . $field, array(0 => ''), true)) : $cp->vars['l_' . $field];
965 if ($field == 'lang_options')
967 $var = (!isset($cp->vars['l_lang_options'][$lang_id]) || !is_array($cp->vars['l_lang_options'][$lang_id])) ? $cp->vars['lang_options'] : $cp->vars['l_lang_options'][$lang_id];
973 $lang_options[$lang_id]['fields'][$field] = array(
974 'TITLE' => $user->lang['CP_' . strtoupper($field)],
976 <dd><input class="medium" name="l_' . $field . '[' . $lang_id . '][]" value="' . ((isset($value[$lang_id][0])) ? $value[$lang_id][0] : $var[0]) . '" /> ' . $user->lang['FIRST_OPTION'] . '</dd>
977 <dd><input class="medium" name="l_' . $field . '[' . $lang_id . '][]" value="' . ((isset($value[$lang_id][1])) ? $value[$lang_id][1] : $var[1]) . '" /> ' . $user->lang['SECOND_OPTION'] . '</dd>'
982 $value = ((isset($value[$lang_id])) ? ((is_array($value[$lang_id])) ? implode("\n", $value[$lang_id]) : $value[$lang_id]) : implode("\n", $var));
983 $lang_options[$lang_id]['fields'][$field] = array(
984 'TITLE' => $user->lang['CP_' . strtoupper($field)],
985 'FIELD' => '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="7" cols="80">' . $value . '</textarea></dd>'
990 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
992 $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
997 $var = ($action == 'create' || !is_array($cp->vars[$field])) ? $cp->vars[$field] : $cp->vars[$field][$lang_id];
999 $lang_options[$lang_id]['fields'][$field] = array(
1000 'TITLE' => $user->lang['CP_' . strtoupper($field)],
1001 'FIELD' => ($field_type == 'string') ? '<dd><input class="medium" type="text" name="l_' . $field . '[' . $lang_id . ']" value="' . ((isset($value[$lang_id])) ? $value[$lang_id] : $var) . '" /></dd>' : '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="3" cols="80">' . ((isset($value[$lang_id])) ? $value[$lang_id] : $var) . '</textarea></dd>'
1004 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
1006 $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
1012 return $lang_options;
1016 * Save Profile Field
1018 function save_profile_field(&$cp, $field_type, $action = 'create')
1020 global $db, $config, $user;
1022 $field_id = request_var('field_id', 0);
1024 // Collect all information, if something is going wrong, abort the operation
1025 $profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();
1027 $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
1029 if ($action == 'create')
1031 $sql = 'SELECT MAX(field_order) as max_field_order
1032 FROM ' . PROFILE_FIELDS_TABLE;
1033 $result = $db->sql_query($sql);
1034 $new_field_order = (int) $db->sql_fetchfield('max_field_order');
1035 $db->sql_freeresult($result);
1037 $field_ident = $cp->vars['field_ident'];
1041 $profile_fields = array(
1042 'field_length' => $cp->vars['field_length'],
1043 'field_minlen' => $cp->vars['field_minlen'],
1044 'field_maxlen' => $cp->vars['field_maxlen'],
1045 'field_novalue' => $cp->vars['field_novalue'],
1046 'field_default_value' => $cp->vars['field_default_value'],
1047 'field_validation' => $cp->vars['field_validation'],
1048 'field_required' => $cp->vars['field_required'],
1049 'field_show_on_reg' => $cp->vars['field_show_on_reg'],
1050 'field_show_on_vt' => $cp->vars['field_show_on_vt'],
1051 'field_hide' => $cp->vars['field_hide'],
1052 'field_show_profile' => $cp->vars['field_show_profile'],
1053 'field_no_view' => $cp->vars['field_no_view']
1056 if ($action == 'create')
1058 $profile_fields += array(
1059 'field_type' => $field_type,
1060 'field_ident' => $field_ident,
1061 'field_name' => $field_ident,
1062 'field_order' => $new_field_order + 1,
1066 $sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields);
1067 $db->sql_query($sql);
1069 $field_id = $db->sql_nextid();
1073 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
1074 SET ' . $db->sql_build_array('UPDATE', $profile_fields) . "
1075 WHERE field_id = $field_id";
1076 $db->sql_query($sql);
1079 if ($action == 'create')
1081 $field_ident = 'pf_' . $field_ident;
1082 $profile_sql[] = $this->add_field_ident($field_ident, $field_type);
1086 'lang_name' => $cp->vars['lang_name'],
1087 'lang_explain' => $cp->vars['lang_explain'],
1088 'lang_default_value' => $cp->vars['lang_default_value']
1091 if ($action == 'create')
1093 $sql_ary['field_id'] = $field_id;
1094 $sql_ary['lang_id'] = $default_lang_id;
1096 $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1100 $this->update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id));
1103 if (is_array($cp->vars['l_lang_name']) && sizeof($cp->vars['l_lang_name']))
1105 foreach ($cp->vars['l_lang_name'] as $lang_id => $data)
1107 if (($cp->vars['lang_name'] != '' && $cp->vars['l_lang_name'][$lang_id] == '')
1108 || ($cp->vars['lang_explain'] != '' && $cp->vars['l_lang_explain'][$lang_id] == '')
1109 || ($cp->vars['lang_default_value'] != '' && $cp->vars['l_lang_default_value'][$lang_id] == ''))
1111 $empty_lang[$lang_id] = true;
1115 if (!isset($empty_lang[$lang_id]))
1117 $profile_lang[] = array(
1118 'field_id' => $field_id,
1119 'lang_id' => $lang_id,
1120 'lang_name' => $cp->vars['l_lang_name'][$lang_id],
1121 'lang_explain' => (isset($cp->vars['l_lang_explain'][$lang_id])) ? $cp->vars['l_lang_explain'][$lang_id] : '',
1122 'lang_default_value' => (isset($cp->vars['l_lang_default_value'][$lang_id])) ? $cp->vars['l_lang_default_value'][$lang_id] : ''
1127 foreach ($empty_lang as $lang_id => $NULL)
1129 $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . "
1130 WHERE field_id = $field_id
1131 AND lang_id = " . (int) $lang_id;
1132 $db->sql_query($sql);
1136 // These are always arrays because the key is the language id...
1137 $cp->vars['l_lang_name'] = utf8_normalize_nfc(request_var('l_lang_name', array(0 => ''), true));
1138 $cp->vars['l_lang_explain'] = utf8_normalize_nfc(request_var('l_lang_explain', array(0 => ''), true));
1139 $cp->vars['l_lang_default_value'] = utf8_normalize_nfc(request_var('l_lang_default_value', array(0 => ''), true));
1141 if ($field_type != FIELD_BOOL)
1143 $cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => ''), true));
1148 * @todo check if this line is correct...
1149 $cp->vars['l_lang_default_value'] = request_var('l_lang_default_value', array(0 => array('')), true);
1151 $cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => array('')), true));
1154 if ($cp->vars['lang_options'])
1156 if (!is_array($cp->vars['lang_options']))
1158 $cp->vars['lang_options'] = explode("\n", $cp->vars['lang_options']);
1161 if ($action != 'create')
1163 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1164 WHERE field_id = $field_id
1165 AND lang_id = " . (int) $default_lang_id;
1166 $db->sql_query($sql);
1169 foreach ($cp->vars['lang_options'] as $option_id => $value)
1172 'field_type' => (int) $field_type,
1173 'lang_value' => $value
1176 if ($action == 'create')
1178 $sql_ary['field_id'] = $field_id;
1179 $sql_ary['lang_id'] = $default_lang_id;
1180 $sql_ary['option_id'] = (int) $option_id;
1182 $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1186 $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array(
1187 'field_id' => $field_id,
1188 'lang_id' => (int) $default_lang_id,
1189 'option_id' => (int) $option_id)
1195 if (is_array($cp->vars['l_lang_options']) && sizeof($cp->vars['l_lang_options']))
1197 $empty_lang = array();
1199 foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary)
1201 if (!is_array($lang_ary))
1203 $lang_ary = explode("\n", $lang_ary);
1206 if (sizeof($lang_ary) != sizeof($cp->vars['lang_options']))
1208 $empty_lang[$lang_id] = true;
1211 if (!isset($empty_lang[$lang_id]))
1213 if ($action != 'create')
1215 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1216 WHERE field_id = $field_id
1217 AND lang_id = " . (int) $lang_id;
1218 $db->sql_query($sql);
1221 foreach ($lang_ary as $option_id => $value)
1223 $profile_lang_fields[] = array(
1224 'field_id' => (int) $field_id,
1225 'lang_id' => (int) $lang_id,
1226 'option_id' => (int) $option_id,
1227 'field_type' => (int) $field_type,
1228 'lang_value' => $value
1234 foreach ($empty_lang as $lang_id => $NULL)
1236 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1237 WHERE field_id = $field_id
1238 AND lang_id = " . (int) $lang_id;
1239 $db->sql_query($sql);
1243 foreach ($profile_lang as $sql)
1245 if ($action == 'create')
1247 $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1251 $lang_id = $sql['lang_id'];
1252 unset($sql['lang_id'], $sql['field_id']);
1254 $this->update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id));
1258 if (sizeof($profile_lang_fields))
1260 foreach ($profile_lang_fields as $sql)
1262 if ($action == 'create')
1264 $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1268 $lang_id = $sql['lang_id'];
1269 $option_id = $sql['option_id'];
1270 unset($sql['lang_id'], $sql['field_id'], $sql['option_id']);
1272 $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array(
1273 'lang_id' => $lang_id,
1274 'field_id' => $field_id,
1275 'option_id' => $option_id)
1282 $db->sql_transaction('begin');
1284 if ($action == 'create')
1286 foreach ($profile_sql as $sql)
1288 $db->sql_query($sql);
1292 $db->sql_transaction('commit');
1294 if ($action == 'edit')
1296 add_log('admin', 'LOG_PROFILE_FIELD_EDIT', $cp->vars['field_ident'] . ':' . $cp->vars['lang_name']);
1297 trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1301 add_log('admin', 'LOG_PROFILE_FIELD_CREATE', substr($field_ident, 3) . ':' . $cp->vars['lang_name']);
1302 trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1307 * Update, then insert if not successfull
1309 function update_insert($table, $sql_ary, $where_fields)
1313 $where_sql = array();
1316 foreach ($where_fields as $key => $value)
1318 $check_key = (!$check_key) ? $key : $check_key;
1319 $where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : (int) $value);
1322 if (!sizeof($where_sql))
1327 $sql = "SELECT $check_key
1329 WHERE " . implode(' AND ', $where_sql);
1330 $result = $db->sql_query($sql);
1331 $row = $db->sql_fetchrow($result);
1332 $db->sql_freeresult($result);
1336 $sql_ary = array_merge($where_fields, $sql_ary);
1338 if (sizeof($sql_ary))
1340 $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary));
1345 if (sizeof($sql_ary))
1347 $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . '
1348 WHERE ' . implode(' AND ', $where_sql);
1349 $db->sql_query($sql);
1355 * Return sql statement for adding a new field ident (profile field) to the profile fields data table
1357 function add_field_ident($field_ident, $field_type)
1361 switch ($db->sql_layer)
1367 // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1368 $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` ";
1370 switch ($field_type)
1373 $sql .= ' VARCHAR(255) ';
1377 $sql .= 'VARCHAR(10) ';
1382 // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1383 // ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
1387 $sql .= 'TINYINT(2) ';
1390 case FIELD_DROPDOWN:
1391 $sql .= 'MEDIUMINT(8) ';
1395 $sql .= 'BIGINT(20) ';
1403 switch ($field_type)
1406 $type = ' VARCHAR(255) ';
1410 $type = 'VARCHAR(10) ';
1414 $type = "TEXT(65535)";
1415 // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1416 // ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
1420 $type = 'TINYINT(2) ';
1423 case FIELD_DROPDOWN:
1424 $type = 'MEDIUMINT(8) ';
1428 $type = 'BIGINT(20) ';
1432 // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1433 if (version_compare(sqlite_libversion(), '3.0') == -1)
1437 WHERE type = 'table'
1438 AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
1439 ORDER BY type DESC, name;";
1440 $result = $db->sql_query($sql);
1441 $row = $db->sql_fetchrow($result);
1442 $db->sql_freeresult($result);
1444 // Create a temp table and populate it, destroy the existing one
1445 $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
1446 $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
1447 $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
1449 preg_match('#\((.*)\)#s', $row['sql'], $matches);
1451 $new_table_cols = trim($matches[1]);
1452 $old_table_cols = explode(',', $new_table_cols);
1453 $column_list = array();
1455 foreach ($old_table_cols as $declaration)
1457 $entities = preg_split('#\s+#', trim($declaration));
1458 if ($entities[0] == 'PRIMARY')
1462 $column_list[] = $entities[0];
1465 $columns = implode(',', $column_list);
1467 $new_table_cols = $field_ident . ' ' . $type . ',' . $new_table_cols;
1469 // create a new table and fill it up. destroy the temp one
1470 $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
1471 $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
1472 $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
1476 $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident [$type]";
1485 // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1486 $sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] ";
1488 switch ($field_type)
1491 $sql .= ' [VARCHAR] (255) ';
1495 $sql .= '[VARCHAR] (10) ';
1500 // ADD {$field_ident}_bbcode_uid [VARCHAR] (5) NOT NULL,
1501 // ADD {$field_ident}_bbcode_bitfield [INT] UNSIGNED";
1505 case FIELD_DROPDOWN:
1518 // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1519 $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD COLUMN \"$field_ident\" ";
1521 switch ($field_type)
1524 $sql .= ' VARCHAR(255) ';
1528 $sql .= 'VARCHAR(10) ';
1533 // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1534 // ADD {$field_ident}_bbcode_bitfield INT4 UNSIGNED";
1541 case FIELD_DROPDOWN:
1554 // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1555 $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' ADD "' . strtoupper($field_ident) . '" ';
1557 switch ($field_type)
1560 $sql .= ' VARCHAR(255) ';
1564 $sql .= 'VARCHAR(10) ';
1568 $sql .= "BLOB SUB_TYPE TEXT";
1569 // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1570 // ADD {$field_ident}_bbcode_bitfield INTEGER UNSIGNED";
1574 case FIELD_DROPDOWN:
1579 $sql .= 'DOUBLE PRECISION ';
1587 // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1588 $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident ";
1590 switch ($field_type)
1593 $sql .= ' VARCHAR2(255) ';
1597 $sql .= 'VARCHAR2(10) ';
1602 // ADD {$field_ident}_bbcode_uid VARCHAR2(5) NOT NULL,
1603 // ADD {$field_ident}_bbcode_bitfield NUMBER(11) UNSIGNED";
1607 $sql .= 'NUMBER(2) ';
1610 case FIELD_DROPDOWN:
1611 $sql .= 'NUMBER(8) ';
1615 $sql .= 'NUMBER(20) ';