5
* @version $Id: acp_profile.php,v 1.61 2007/11/15 19:54:37 kellanved Exp $
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' => utf8_clean_string(request_var('field_ident', '', true)),
367
'field_required' => 0,
369
'field_no_view' => 0,
370
'field_show_on_reg' => 0,
371
'lang_name' => utf8_normalize_nfc(request_var('field_ident', '', true)),
372
'lang_explain' => '',
373
'lang_default_value'=> '')
376
$s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
379
// $exclude contains the data we gather in each step
381
1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option', 'field_no_view'),
382
2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
383
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
386
// Text-based fields require the lang_default_value to be excluded
387
if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
389
$exclude[1][] = 'lang_default_value';
392
// option-specific fields require lang_options to be excluded
393
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
395
$exclude[1][] = 'lang_options';
398
$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']);
399
$cp->vars['lang_name'] = utf8_normalize_nfc(request_var('lang_name', $field_row['lang_name'], true));
400
$cp->vars['lang_explain'] = utf8_normalize_nfc(request_var('lang_explain', $field_row['lang_explain'], true));
401
$cp->vars['lang_default_value'] = utf8_normalize_nfc(request_var('lang_default_value', $field_row['lang_default_value'], true));
404
if (isset($_REQUEST['field_option']))
406
$field_option = request_var('field_option', '');
408
$cp->vars['field_required'] = ($field_option == 'field_required') ? 1 : 0;
409
$cp->vars['field_show_on_reg'] = ($field_option == 'field_show_on_reg') ? 1 : 0;
410
$cp->vars['field_hide'] = ($field_option == 'field_hide') ? 1 : 0;
414
$cp->vars['field_required'] = $field_row['field_required'];
415
$cp->vars['field_show_on_reg'] = $field_row['field_show_on_reg'];
416
$cp->vars['field_hide'] = $field_row['field_hide'];
418
$field_option = ($field_row['field_required']) ? 'field_required' : (($field_row['field_show_on_reg']) ? 'field_show_on_reg' : (($field_row['field_hide']) ? 'field_hide' : ''));
421
$cp->vars['field_no_view'] = request_var('field_no_view', $field_row['field_no_view']);
423
// A boolean field expects an array as the lang options
424
if ($field_type == FIELD_BOOL)
426
$options = utf8_normalize_nfc(request_var('lang_options', array(''), true));
430
$options = utf8_normalize_nfc(request_var('lang_options', '', true));
433
// If the user has submitted a form with options (i.e. dropdown field)
436
$exploded_options = (is_array($options)) ? $options : explode("\n", $options);
438
if (sizeof($exploded_options) == sizeof($lang_options) || $action == 'create')
440
// The number of options in the field is equal to the number of options already in the database
441
// Or we are creating a new dropdown list.
442
$cp->vars['lang_options'] = $exploded_options;
444
else if ($action == 'edit')
446
// Changing the number of options? (We remove and re-create the option fields)
447
$cp->vars['lang_options'] = $exploded_options;
452
$cp->vars['lang_options'] = $lang_options;
456
foreach ($exclude[2] as $key)
458
$var = utf8_normalize_nfc(request_var($key, $field_row[$key], true));
460
// Manipulate the intended variables a little bit if needed
461
if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen')
463
// Get the number of options if this key is 'field_maxlen'
464
$var = sizeof(explode("\n", utf8_normalize_nfc(request_var('lang_options', '', true))));
466
else if ($field_type == FIELD_TEXT && $key == 'field_length')
468
if (isset($_REQUEST['rows']))
470
$cp->vars['rows'] = request_var('rows', 0);
471
$cp->vars['columns'] = request_var('columns', 0);
472
$var = $cp->vars['rows'] . '|' . $cp->vars['columns'];
476
$row_col = explode('|', $var);
477
$cp->vars['rows'] = $row_col[0];
478
$cp->vars['columns'] = $row_col[1];
481
else if ($field_type == FIELD_DATE && $key == 'field_default_value')
483
$always_now = request_var('always_now', -1);
485
if ($always_now == 1 || ($always_now === -1 && $var == 'now'))
489
$cp->vars['field_default_value_day'] = $now['mday'];
490
$cp->vars['field_default_value_month'] = $now['mon'];
491
$cp->vars['field_default_value_year'] = $now['year'];
492
$var = $_POST['field_default_value'] = 'now';
496
if (isset($_REQUEST['field_default_value_day']))
498
$cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
499
$cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
500
$cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
501
$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']);
505
list($cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']) = explode('-', $var);
509
/* else if ($field_type == FIELD_BOOL && $key == 'field_default_value')
511
// Get the number of options if this key is 'field_maxlen'
512
$var = request_var('field_default_value', 0);
515
$cp->vars[$key] = $var;
518
// step 3 - all arrays
519
if ($action == 'edit')
521
// Get language entries
523
FROM ' . PROFILE_FIELDS_LANG_TABLE . '
524
WHERE lang_id <> ' . $this->edit_lang_id . "
525
AND field_id = $field_id
526
ORDER BY option_id ASC";
527
$result = $db->sql_query($sql);
529
$l_lang_options = array();
530
while ($row = $db->sql_fetchrow($result))
532
$l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value'];
534
$db->sql_freeresult($result);
537
$sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value
538
FROM ' . PROFILE_LANG_TABLE . '
539
WHERE lang_id <> ' . $this->edit_lang_id . "
540
AND field_id = $field_id
541
ORDER BY lang_id ASC";
542
$result = $db->sql_query($sql);
544
$l_lang_name = $l_lang_explain = $l_lang_default_value = array();
545
while ($row = $db->sql_fetchrow($result))
547
$l_lang_name[$row['lang_id']] = $row['lang_name'];
548
$l_lang_explain[$row['lang_id']] = $row['lang_explain'];
549
$l_lang_default_value[$row['lang_id']] = $row['lang_default_value'];
551
$db->sql_freeresult($result);
554
foreach ($exclude[3] as $key)
556
$cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => ''), true));
558
if (!$cp->vars[$key] && $action == 'edit')
560
$cp->vars[$key] = $$key;
562
else if ($key == 'l_lang_options' && $field_type == FIELD_BOOL)
564
$cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => array('')), true));
566
else if ($key == 'l_lang_options' && is_array($cp->vars[$key]))
568
foreach ($cp->vars[$key] as $lang_id => $options)
570
$cp->vars[$key][$lang_id] = explode("\n", $options);
576
// Check for general issues in every step
577
if ($submit) // && $step == 1
579
// Check values for step 1
580
if ($cp->vars['field_ident'] == '')
582
$error[] = $user->lang['EMPTY_FIELD_IDENT'];
585
if (!preg_match('/^[a-z_]+$/', $cp->vars['field_ident']))
587
$error[] = $user->lang['INVALID_CHARS_FIELD_IDENT'];
590
if (strlen($cp->vars['field_ident']) > 17)
592
$error[] = $user->lang['INVALID_FIELD_IDENT_LEN'];
595
if ($cp->vars['lang_name'] == '')
597
$error[] = $user->lang['EMPTY_USER_FIELD_NAME'];
600
if ($field_type == FIELD_DROPDOWN && !sizeof($cp->vars['lang_options']))
602
$error[] = $user->lang['NO_FIELD_ENTRIES'];
605
if ($field_type == FIELD_BOOL && (empty($cp->vars['lang_options'][0]) || empty($cp->vars['lang_options'][1])))
607
$error[] = $user->lang['NO_FIELD_ENTRIES'];
610
// Check for already existing field ident
611
if ($action != 'edit')
613
$sql = 'SELECT field_ident
614
FROM ' . PROFILE_FIELDS_TABLE . "
615
WHERE field_ident = '" . $db->sql_escape($cp->vars['field_ident']) . "'";
616
$result = $db->sql_query($sql);
617
$row = $db->sql_fetchrow($result);
618
$db->sql_freeresult($result);
622
$error[] = $user->lang['FIELD_IDENT_ALREADY_EXIST'];
627
$step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);
635
// Build up the specific hidden fields
636
foreach ($exclude as $num => $key_ary)
643
$_new_key_ary = array();
645
foreach ($key_ary as $key)
647
if ($field_type == FIELD_TEXT && $key == 'field_length' && isset($_REQUEST['rows']))
649
$cp->vars['rows'] = request_var('rows', 0);
650
$cp->vars['columns'] = request_var('columns', 0);
651
$_new_key_ary[$key] = $cp->vars['rows'] . '|' . $cp->vars['columns'];
653
else if ($field_type == FIELD_DATE && $key == 'field_default_value')
655
$always_now = request_var('always_now', 0);
659
$_new_key_ary[$key] = 'now';
661
else if (isset($_REQUEST['field_default_value_day']))
663
$cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
664
$cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
665
$cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
666
$_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']);
669
else if ($field_type == FIELD_BOOL && $key == 'l_lang_options' && isset($_REQUEST['l_lang_options']))
671
$_new_key_ary[$key] = utf8_normalize_nfc(request_var($key, array(array('')), true));
675
if (!isset($_REQUEST[$key]))
679
else if ($key == 'field_ident' && isset($cp->vars[$key]))
681
$_new_key_ary[$key]= $cp->vars[$key];
685
$_new_key_ary[$key] = (is_array($_REQUEST[$key])) ? utf8_normalize_nfc(request_var($key, array(''), true)) : utf8_normalize_nfc(request_var($key, '', true));
690
$s_hidden_fields .= build_hidden_fields($_new_key_ary);
695
if ($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save))
697
$this->save_profile_field($cp, $field_type, $action);
699
else if ($action == 'edit' && $save)
701
$this->save_profile_field($cp, $field_type, $action);
705
$template->assign_vars(array(
707
'S_EDIT_MODE' => ($action == 'edit') ? true : false,
708
'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
710
'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)],
711
'L_EXPLAIN' => $user->lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($action)],
713
'U_ACTION' => $this->u_action . "&action=$action&step=$step",
714
'U_BACK' => $this->u_action)
717
// Now go through the steps
720
// Create basic options - only small differences between field types
723
// Build common create options
724
$template->assign_vars(array(
725
'S_STEP_ONE' => true,
726
'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
727
'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
728
'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
729
'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
731
'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
732
'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])],
733
'FIELD_IDENT' => $cp->vars['field_ident'],
734
'LANG_NAME' => $cp->vars['lang_name'],
735
'LANG_EXPLAIN' => $cp->vars['lang_explain'])
738
// String and Text needs to set default values here...
739
if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
741
$template->assign_vars(array(
742
'S_TEXT' => ($field_type == FIELD_TEXT) ? true : false,
743
'S_STRING' => ($field_type == FIELD_STRING) ? true : false,
745
'L_DEFAULT_VALUE_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_DEFAULT_VALUE_EXPLAIN'],
746
'LANG_DEFAULT_VALUE' => $cp->vars['lang_default_value'])
750
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
752
// Initialize these array elements if we are creating a new field
753
if (!sizeof($cp->vars['lang_options']))
755
if ($field_type == FIELD_BOOL)
757
// No options have been defined for a boolean field.
758
$cp->vars['lang_options'][0] = '';
759
$cp->vars['lang_options'][1] = '';
763
// No options have been defined for the dropdown menu
764
$cp->vars['lang_options'] = array();
768
$template->assign_vars(array(
769
'S_BOOL' => ($field_type == FIELD_BOOL) ? true : false,
770
'S_DROPDOWN' => ($field_type == FIELD_DROPDOWN) ? true : false,
772
'L_LANG_OPTIONS_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_ENTRIES_EXPLAIN'],
773
'LANG_OPTIONS' => ($field_type == FIELD_DROPDOWN) ? implode("\n", $cp->vars['lang_options']) : '',
774
'FIRST_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][0] : '',
775
'SECOND_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][1] : '')
783
$template->assign_vars(array(
784
'S_STEP_TWO' => true,
785
'L_NEXT_STEP' => (sizeof($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS'])
788
// Build options based on profile type
789
$function = 'get_' . $cp->profile_types[$field_type] . '_options';
790
$options = $cp->$function();
792
foreach ($options as $num => $option_ary)
794
$template->assign_block_vars('option', $option_ary);
799
// Define remaining language variables
802
$template->assign_var('S_STEP_THREE', true);
803
$options = $this->build_language_options($cp, $field_type, $action);
805
foreach ($options as $lang_id => $lang_ary)
807
$template->assign_block_vars('options', array(
808
'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso']))
811
foreach ($lang_ary['fields'] as $field_ident => $field_ary)
813
$template->assign_block_vars('options.field', array(
814
'L_TITLE' => $field_ary['TITLE'],
815
'L_EXPLAIN' => (isset($field_ary['EXPLAIN'])) ? $field_ary['EXPLAIN'] : '',
816
'FIELD' => $field_ary['FIELD'])
824
$template->assign_vars(array(
825
'S_HIDDEN_FIELDS' => $s_hidden_fields)
834
FROM ' . PROFILE_FIELDS_TABLE . '
835
ORDER BY field_order';
836
$result = $db->sql_query($sql);
838
$s_one_need_edit = false;
839
while ($row = $db->sql_fetchrow($result))
841
$active_lang = (!$row['field_active']) ? 'ACTIVATE' : 'DEACTIVATE';
842
$active_value = (!$row['field_active']) ? 'activate' : 'deactivate';
843
$id = $row['field_id'];
845
$s_need_edit = (sizeof($this->lang_defs['diff'][$row['field_id']])) ? true : false;
849
$s_one_need_edit = true;
852
$template->assign_block_vars('fields', array(
853
'FIELD_IDENT' => $row['field_ident'],
854
'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])],
856
'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],
857
'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id",
858
'U_EDIT' => $this->u_action . "&action=edit&field_id=$id",
859
'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
860
'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",
861
'U_MOVE_UP' => $this->u_action . "&action=move_up&order={$row['field_order']}",
862
'U_MOVE_DOWN' => $this->u_action . "&action=move_down&order={$row['field_order']}",
864
'S_NEED_EDIT' => $s_need_edit)
867
$db->sql_freeresult($result);
869
// At least one option field needs editing?
870
if ($s_one_need_edit)
872
$template->assign_var('S_NEED_EDIT', true);
876
foreach ($cp->profile_types as $key => $value)
878
$s_select_type .= '<option value="' . $key . '">' . $user->lang['FIELD_' . strtoupper($value)] . '</option>';
881
$template->assign_vars(array(
882
'U_ACTION' => $this->u_action,
883
'S_TYPE_OPTIONS' => $s_select_type)
888
* Build all Language specific options
890
function build_language_options(&$cp, $field_type, $action = 'create')
892
global $user, $config, $db;
894
$default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
896
$sql = 'SELECT lang_id, lang_iso
897
FROM ' . LANG_TABLE . '
898
WHERE lang_id <> ' . (int) $default_lang_id . '
899
ORDER BY lang_english_name';
900
$result = $db->sql_query($sql);
902
$languages = array();
903
while ($row = $db->sql_fetchrow($result))
905
$languages[$row['lang_id']] = $row['lang_iso'];
907
$db->sql_freeresult($result);
910
$options['lang_name'] = 'string';
911
if ($cp->vars['lang_explain'])
913
$options['lang_explain'] = 'text';
919
$options['lang_options'] = 'two_options';
923
$options['lang_options'] = 'optionfield';
928
if ($cp->vars['lang_default_value'])
930
$options['lang_default_value'] = ($field_type == FIELD_STRING) ? 'string' : 'text';
935
$lang_options = array();
937
foreach ($options as $field => $field_type)
939
$lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id];
940
$lang_options[1]['fields'][$field] = array(
941
'TITLE' => $user->lang['CP_' . strtoupper($field)],
942
'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . '</dd>'
945
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
947
$lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
951
foreach ($languages as $lang_id => $lang_iso)
953
$lang_options[$lang_id]['lang_iso'] = $lang_iso;
954
foreach ($options as $field => $field_type)
956
$value = ($action == 'create') ? utf8_normalize_nfc(request_var('l_' . $field, array(0 => ''), true)) : $cp->vars['l_' . $field];
957
if ($field == 'lang_options')
959
$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];
965
$lang_options[$lang_id]['fields'][$field] = array(
966
'TITLE' => $user->lang['CP_' . strtoupper($field)],
968
<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>
969
<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>'
974
$value = ((isset($value[$lang_id])) ? ((is_array($value[$lang_id])) ? implode("\n", $value[$lang_id]) : $value[$lang_id]) : implode("\n", $var));
975
$lang_options[$lang_id]['fields'][$field] = array(
976
'TITLE' => $user->lang['CP_' . strtoupper($field)],
977
'FIELD' => '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="7" cols="80">' . $value . '</textarea></dd>'
982
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
984
$lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
989
$var = ($action == 'create' || !is_array($cp->vars[$field])) ? $cp->vars[$field] : $cp->vars[$field][$lang_id];
991
$lang_options[$lang_id]['fields'][$field] = array(
992
'TITLE' => $user->lang['CP_' . strtoupper($field)],
993
'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>'
996
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
998
$lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
1004
return $lang_options;
1008
* Save Profile Field
1010
function save_profile_field(&$cp, $field_type, $action = 'create')
1012
global $db, $config, $user;
1014
$field_id = request_var('field_id', 0);
1016
// Collect all information, if something is going wrong, abort the operation
1017
$profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();
1019
$default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
1021
if ($action == 'create')
1023
$sql = 'SELECT MAX(field_order) as max_field_order
1024
FROM ' . PROFILE_FIELDS_TABLE;
1025
$result = $db->sql_query($sql);
1026
$new_field_order = (int) $db->sql_fetchfield('max_field_order');
1027
$db->sql_freeresult($result);
1029
$field_ident = $cp->vars['field_ident'];
1033
$profile_fields = array(
1034
'field_length' => $cp->vars['field_length'],
1035
'field_minlen' => $cp->vars['field_minlen'],
1036
'field_maxlen' => $cp->vars['field_maxlen'],
1037
'field_novalue' => $cp->vars['field_novalue'],
1038
'field_default_value' => $cp->vars['field_default_value'],
1039
'field_validation' => $cp->vars['field_validation'],
1040
'field_required' => $cp->vars['field_required'],
1041
'field_show_on_reg' => $cp->vars['field_show_on_reg'],
1042
'field_hide' => $cp->vars['field_hide'],
1043
'field_no_view' => $cp->vars['field_no_view']
1046
if ($action == 'create')
1048
$profile_fields += array(
1049
'field_type' => $field_type,
1050
'field_ident' => $field_ident,
1051
'field_name' => $field_ident,
1052
'field_order' => $new_field_order + 1,
1056
$sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields);
1057
$db->sql_query($sql);
1059
$field_id = $db->sql_nextid();
1063
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
1064
SET ' . $db->sql_build_array('UPDATE', $profile_fields) . "
1065
WHERE field_id = $field_id";
1066
$db->sql_query($sql);
1069
if ($action == 'create')
1071
$field_ident = 'pf_' . $field_ident;
1072
$profile_sql[] = $this->add_field_ident($field_ident, $field_type);
1076
'lang_name' => $cp->vars['lang_name'],
1077
'lang_explain' => $cp->vars['lang_explain'],
1078
'lang_default_value' => $cp->vars['lang_default_value']
1081
if ($action == 'create')
1083
$sql_ary['field_id'] = $field_id;
1084
$sql_ary['lang_id'] = $default_lang_id;
1086
$profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1090
$this->update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id));
1093
if (is_array($cp->vars['l_lang_name']) && sizeof($cp->vars['l_lang_name']))
1095
foreach ($cp->vars['l_lang_name'] as $lang_id => $data)
1097
if (($cp->vars['lang_name'] != '' && $cp->vars['l_lang_name'][$lang_id] == '')
1098
|| ($cp->vars['lang_explain'] != '' && $cp->vars['l_lang_explain'][$lang_id] == '')
1099
|| ($cp->vars['lang_default_value'] != '' && $cp->vars['l_lang_default_value'][$lang_id] == ''))
1101
$empty_lang[$lang_id] = true;
1105
if (!isset($empty_lang[$lang_id]))
1107
$profile_lang[] = array(
1108
'field_id' => $field_id,
1109
'lang_id' => $lang_id,
1110
'lang_name' => $cp->vars['l_lang_name'][$lang_id],
1111
'lang_explain' => (isset($cp->vars['l_lang_explain'][$lang_id])) ? $cp->vars['l_lang_explain'][$lang_id] : '',
1112
'lang_default_value' => (isset($cp->vars['l_lang_default_value'][$lang_id])) ? $cp->vars['l_lang_default_value'][$lang_id] : ''
1117
foreach ($empty_lang as $lang_id => $NULL)
1119
$sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . "
1120
WHERE field_id = $field_id
1121
AND lang_id = " . (int) $lang_id;
1122
$db->sql_query($sql);
1126
// These are always arrays because the key is the language id...
1127
$cp->vars['l_lang_name'] = utf8_normalize_nfc(request_var('l_lang_name', array(0 => ''), true));
1128
$cp->vars['l_lang_explain'] = utf8_normalize_nfc(request_var('l_lang_explain', array(0 => ''), true));
1129
$cp->vars['l_lang_default_value'] = utf8_normalize_nfc(request_var('l_lang_default_value', array(0 => ''), true));
1131
if ($field_type != FIELD_BOOL)
1133
$cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => ''), true));
1138
* @todo check if this line is correct...
1139
$cp->vars['l_lang_default_value'] = request_var('l_lang_default_value', array(0 => array('')), true);
1141
$cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => array('')), true));
1144
if ($cp->vars['lang_options'])
1146
if (!is_array($cp->vars['lang_options']))
1148
$cp->vars['lang_options'] = explode("\n", $cp->vars['lang_options']);
1151
if ($action != 'create')
1153
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1154
WHERE field_id = $field_id
1155
AND lang_id = " . (int) $default_lang_id;
1156
$db->sql_query($sql);
1159
foreach ($cp->vars['lang_options'] as $option_id => $value)
1162
'field_type' => (int) $field_type,
1163
'lang_value' => $value
1166
if ($action == 'create')
1168
$sql_ary['field_id'] = $field_id;
1169
$sql_ary['lang_id'] = $default_lang_id;
1170
$sql_ary['option_id'] = (int) $option_id;
1172
$profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1176
$this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array(
1177
'field_id' => $field_id,
1178
'lang_id' => (int) $default_lang_id,
1179
'option_id' => (int) $option_id)
1185
if (is_array($cp->vars['l_lang_options']) && sizeof($cp->vars['l_lang_options']))
1187
$empty_lang = array();
1189
foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary)
1191
if (!is_array($lang_ary))
1193
$lang_ary = explode("\n", $lang_ary);
1196
if (sizeof($lang_ary) != sizeof($cp->vars['lang_options']))
1198
$empty_lang[$lang_id] = true;
1201
if (!isset($empty_lang[$lang_id]))
1203
if ($action != 'create')
1205
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1206
WHERE field_id = $field_id
1207
AND lang_id = " . (int) $lang_id;
1208
$db->sql_query($sql);
1211
foreach ($lang_ary as $option_id => $value)
1213
$profile_lang_fields[] = array(
1214
'field_id' => (int) $field_id,
1215
'lang_id' => (int) $lang_id,
1216
'option_id' => (int) $option_id,
1217
'field_type' => (int) $field_type,
1218
'lang_value' => $value
1224
foreach ($empty_lang as $lang_id => $NULL)
1226
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1227
WHERE field_id = $field_id
1228
AND lang_id = " . (int) $lang_id;
1229
$db->sql_query($sql);
1233
foreach ($profile_lang as $sql)
1235
if ($action == 'create')
1237
$profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1241
$lang_id = $sql['lang_id'];
1242
unset($sql['lang_id'], $sql['field_id']);
1244
$this->update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id));
1248
if (sizeof($profile_lang_fields))
1250
foreach ($profile_lang_fields as $sql)
1252
if ($action == 'create')
1254
$profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1258
$lang_id = $sql['lang_id'];
1259
$option_id = $sql['option_id'];
1260
unset($sql['lang_id'], $sql['field_id'], $sql['option_id']);
1262
$this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array(
1263
'lang_id' => $lang_id,
1264
'field_id' => $field_id,
1265
'option_id' => $option_id)
1272
$db->sql_transaction('begin');
1274
if ($action == 'create')
1276
foreach ($profile_sql as $sql)
1278
$db->sql_query($sql);
1282
$db->sql_transaction('commit');
1284
if ($action == 'edit')
1286
add_log('admin', 'LOG_PROFILE_FIELD_EDIT', $cp->vars['field_ident'] . ':' . $cp->vars['lang_name']);
1287
trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1291
add_log('admin', 'LOG_PROFILE_FIELD_CREATE', substr($field_ident, 3) . ':' . $cp->vars['lang_name']);
1292
trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1297
* Update, then insert if not successfull
1299
function update_insert($table, $sql_ary, $where_fields)
1303
$where_sql = array();
1306
foreach ($where_fields as $key => $value)
1308
$check_key = (!$check_key) ? $key : $check_key;
1309
$where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : (int) $value);
1312
if (!sizeof($where_sql))
1317
$sql = "SELECT $check_key
1319
WHERE " . implode(' AND ', $where_sql);
1320
$result = $db->sql_query($sql);
1321
$row = $db->sql_fetchrow($result);
1322
$db->sql_freeresult($result);
1326
$sql_ary = array_merge($where_fields, $sql_ary);
1328
if (sizeof($sql_ary))
1330
$db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary));
1335
if (sizeof($sql_ary))
1337
$sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . '
1338
WHERE ' . implode(' AND ', $where_sql);
1339
$db->sql_query($sql);
1345
* Return sql statement for adding a new field ident (profile field) to the profile fields data table
1347
function add_field_ident($field_ident, $field_type)
1351
switch ($db->sql_layer)
1357
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1358
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` ";
1360
switch ($field_type)
1363
$sql .= ' VARCHAR(255) ';
1367
$sql .= 'VARCHAR(10) ';
1372
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1373
// ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
1377
$sql .= 'TINYINT(2) ';
1380
case FIELD_DROPDOWN:
1381
$sql .= 'MEDIUMINT(8) ';
1385
$sql .= 'BIGINT(20) ';
1393
switch ($field_type)
1396
$type = ' VARCHAR(255) ';
1400
$type = 'VARCHAR(10) ';
1404
$type = "TEXT(65535)";
1405
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1406
// ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
1410
$type = 'TINYINT(2) ';
1413
case FIELD_DROPDOWN:
1414
$type = 'MEDIUMINT(8) ';
1418
$type = 'BIGINT(20) ';
1422
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1423
if (version_compare(sqlite_libversion(), '3.0') == -1)
1427
WHERE type = 'table'
1428
AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
1429
ORDER BY type DESC, name;";
1430
$result = $db->sql_query($sql);
1431
$row = $db->sql_fetchrow($result);
1432
$db->sql_freeresult($result);
1434
// Create a temp table and populate it, destroy the existing one
1435
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
1436
$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
1437
$db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
1439
preg_match('#\((.*)\)#s', $row['sql'], $matches);
1441
$new_table_cols = trim($matches[1]);
1442
$old_table_cols = explode(',', $new_table_cols);
1443
$column_list = array();
1445
foreach ($old_table_cols as $declaration)
1447
$entities = preg_split('#\s+#', trim($declaration));
1448
if ($entities[0] == 'PRIMARY')
1452
$column_list[] = $entities[0];
1455
$columns = implode(',', $column_list);
1457
$new_table_cols = $field_ident . ' ' . $type . ',' . $new_table_cols;
1459
// create a new table and fill it up. destroy the temp one
1460
$db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
1461
$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
1462
$db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
1466
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident [$type]";
1474
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1475
$sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] ";
1477
switch ($field_type)
1480
$sql .= ' [VARCHAR] (255) ';
1484
$sql .= '[VARCHAR] (10) ';
1489
// ADD {$field_ident}_bbcode_uid [VARCHAR] (5) NOT NULL,
1490
// ADD {$field_ident}_bbcode_bitfield [INT] UNSIGNED";
1494
case FIELD_DROPDOWN:
1507
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1508
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD COLUMN \"$field_ident\" ";
1510
switch ($field_type)
1513
$sql .= ' VARCHAR(255) ';
1517
$sql .= 'VARCHAR(10) ';
1522
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1523
// ADD {$field_ident}_bbcode_bitfield INT4 UNSIGNED";
1530
case FIELD_DROPDOWN:
1543
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1544
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD \"$field_ident\" ";
1546
switch ($field_type)
1549
$sql .= ' VARCHAR(255) ';
1553
$sql .= 'VARCHAR(10) ';
1557
$sql .= "BLOB SUB_TYPE TEXT";
1558
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1559
// ADD {$field_ident}_bbcode_bitfield INTEGER UNSIGNED";
1563
case FIELD_DROPDOWN:
1568
$sql .= 'DOUBLE PRECISION ';
1576
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1577
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident ";
1579
switch ($field_type)
1582
$sql .= ' VARCHAR2(255) ';
1586
$sql .= 'VARCHAR2(10) ';
1591
// ADD {$field_ident}_bbcode_uid VARCHAR2(5) NOT NULL,
1592
// ADD {$field_ident}_bbcode_bitfield NUMBER(11) UNSIGNED";
1596
$sql .= 'NUMBER(2) ';
1599
case FIELD_DROPDOWN:
1600
$sql .= 'NUMBER(8) ';
1604
$sql .= 'NUMBER(20) ';
b'\\ No newline at end of file'