1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_profile.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1626 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* @package acp
1.24 +*/
1.25 +class acp_profile
1.26 +{
1.27 + var $u_action;
1.28 +
1.29 + var $edit_lang_id;
1.30 + var $lang_defs;
1.31 +
1.32 + function main($id, $mode)
1.33 + {
1.34 + global $config, $db, $user, $auth, $template, $cache;
1.35 + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
1.36 +
1.37 + include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1.38 + include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.39 + include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
1.40 +
1.41 + $user->add_lang(array('ucp', 'acp/profile'));
1.42 + $this->tpl_name = 'acp_profile';
1.43 + $this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';
1.44 +
1.45 + $action = (isset($_POST['create'])) ? 'create' : request_var('action', '');
1.46 +
1.47 + $error = array();
1.48 + $s_hidden_fields = '';
1.49 +
1.50 + // Define some default values for each field type
1.51 + $default_values = array(
1.52 + FIELD_STRING => array('field_length' => 10, 'field_minlen' => 0, 'field_maxlen' => 20, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
1.53 + FIELD_TEXT => array('field_length' => '5|80', 'field_minlen' => 0, 'field_maxlen' => 1000, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
1.54 + FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
1.55 + 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'),
1.56 + FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
1.57 + FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
1.58 + );
1.59 +
1.60 + $cp = new custom_profile_admin();
1.61 +
1.62 + // Build Language array
1.63 + // Based on this, we decide which elements need to be edited later and which language items are missing
1.64 + $this->lang_defs = array();
1.65 +
1.66 + $sql = 'SELECT lang_id, lang_iso
1.67 + FROM ' . LANG_TABLE . '
1.68 + ORDER BY lang_english_name';
1.69 + $result = $db->sql_query($sql);
1.70 +
1.71 + while ($row = $db->sql_fetchrow($result))
1.72 + {
1.73 + // Make some arrays with all available languages
1.74 + $this->lang_defs['id'][$row['lang_id']] = $row['lang_iso'];
1.75 + $this->lang_defs['iso'][$row['lang_iso']] = $row['lang_id'];
1.76 + }
1.77 + $db->sql_freeresult($result);
1.78 +
1.79 + $sql = 'SELECT field_id, lang_id
1.80 + FROM ' . PROFILE_LANG_TABLE . '
1.81 + ORDER BY lang_id';
1.82 + $result = $db->sql_query($sql);
1.83 +
1.84 + while ($row = $db->sql_fetchrow($result))
1.85 + {
1.86 + // Which languages are available for each item
1.87 + $this->lang_defs['entry'][$row['field_id']][] = $row['lang_id'];
1.88 + }
1.89 + $db->sql_freeresult($result);
1.90 +
1.91 + // Have some fields been defined?
1.92 + if (isset($this->lang_defs['entry']))
1.93 + {
1.94 + foreach ($this->lang_defs['entry'] as $field_id => $field_ary)
1.95 + {
1.96 + // Fill an array with the languages that are missing for each field
1.97 + $this->lang_defs['diff'][$field_id] = array_diff(array_values($this->lang_defs['iso']), $field_ary);
1.98 + }
1.99 + }
1.100 +
1.101 + switch ($action)
1.102 + {
1.103 + case 'delete':
1.104 + $field_id = request_var('field_id', 0);
1.105 +
1.106 + if (!$field_id)
1.107 + {
1.108 + trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.109 + }
1.110 +
1.111 + if (confirm_box(true))
1.112 + {
1.113 + $sql = 'SELECT field_ident
1.114 + FROM ' . PROFILE_FIELDS_TABLE . "
1.115 + WHERE field_id = $field_id";
1.116 + $result = $db->sql_query($sql);
1.117 + $field_ident = (string) $db->sql_fetchfield('field_ident');
1.118 + $db->sql_freeresult($result);
1.119 +
1.120 + $db->sql_transaction('begin');
1.121 +
1.122 + $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_TABLE . " WHERE field_id = $field_id");
1.123 + $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
1.124 + $db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");
1.125 +
1.126 + switch ($db->sql_layer)
1.127 + {
1.128 + case 'sqlite':
1.129 + $sql = "SELECT sql
1.130 + FROM sqlite_master
1.131 + WHERE type = 'table'
1.132 + AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
1.133 + ORDER BY type DESC, name;";
1.134 + $result = $db->sql_query($sql);
1.135 + $row = $db->sql_fetchrow($result);
1.136 + $db->sql_freeresult($result);
1.137 +
1.138 + // Create a temp table and populate it, destroy the existing one
1.139 + $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
1.140 + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
1.141 + $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
1.142 +
1.143 + preg_match('#\((.*)\)#s', $row['sql'], $matches);
1.144 +
1.145 + $new_table_cols = trim($matches[1]);
1.146 + $old_table_cols = preg_split('/,(?=[\\sa-z])/im', $new_table_cols);
1.147 + $column_list = array();
1.148 +
1.149 + foreach ($old_table_cols as $declaration)
1.150 + {
1.151 + $entities = preg_split('#\s+#', trim($declaration));
1.152 +
1.153 + if ($entities[0] == 'PRIMARY')
1.154 + {
1.155 + continue;
1.156 + }
1.157 +
1.158 + if ($entities[0] !== 'pf_' . $field_ident)
1.159 + {
1.160 + $column_list[] = $entities[0];
1.161 + }
1.162 + }
1.163 +
1.164 + $columns = implode(',', $column_list);
1.165 +
1.166 + $new_table_cols = preg_replace('/' . 'pf_' . $field_ident . '[^,]+,/', '', $new_table_cols);
1.167 +
1.168 + // create a new table and fill it up. destroy the temp one
1.169 + $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
1.170 + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
1.171 + $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
1.172 + break;
1.173 +
1.174 + default:
1.175 + $db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident");
1.176 + }
1.177 +
1.178 + $order = 0;
1.179 +
1.180 + $sql = 'SELECT *
1.181 + FROM ' . PROFILE_FIELDS_TABLE . '
1.182 + ORDER BY field_order';
1.183 + $result = $db->sql_query($sql);
1.184 +
1.185 + while ($row = $db->sql_fetchrow($result))
1.186 + {
1.187 + $order++;
1.188 + if ($row['field_order'] != $order)
1.189 + {
1.190 + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
1.191 + SET field_order = $order
1.192 + WHERE field_id = {$row['field_id']}";
1.193 + $db->sql_query($sql);
1.194 + }
1.195 + }
1.196 + $db->sql_freeresult($result);
1.197 +
1.198 + $db->sql_transaction('commit');
1.199 +
1.200 + add_log('admin', 'LOG_PROFILE_FIELD_REMOVED', $field_ident);
1.201 + trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1.202 + }
1.203 + else
1.204 + {
1.205 + confirm_box(false, 'DELETE_PROFILE_FIELD', build_hidden_fields(array(
1.206 + 'i' => $id,
1.207 + 'mode' => $mode,
1.208 + 'action' => $action,
1.209 + 'field_id' => $field_id,
1.210 + )));
1.211 + }
1.212 +
1.213 + break;
1.214 +
1.215 + case 'activate':
1.216 + $field_id = request_var('field_id', 0);
1.217 +
1.218 + if (!$field_id)
1.219 + {
1.220 + trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.221 + }
1.222 +
1.223 + $sql = 'SELECT lang_id
1.224 + FROM ' . LANG_TABLE . "
1.225 + WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
1.226 + $result = $db->sql_query($sql);
1.227 + $default_lang_id = (int) $db->sql_fetchfield('lang_id');
1.228 + $db->sql_freeresult($result);
1.229 +
1.230 + if (!in_array($default_lang_id, $this->lang_defs['entry'][$field_id]))
1.231 + {
1.232 + trigger_error($user->lang['DEFAULT_LANGUAGE_NOT_FILLED'] . adm_back_link($this->u_action), E_USER_WARNING);
1.233 + }
1.234 +
1.235 + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
1.236 + SET field_active = 1
1.237 + WHERE field_id = $field_id";
1.238 + $db->sql_query($sql);
1.239 +
1.240 + $sql = 'SELECT field_ident
1.241 + FROM ' . PROFILE_FIELDS_TABLE . "
1.242 + WHERE field_id = $field_id";
1.243 + $result = $db->sql_query($sql);
1.244 + $field_ident = (string) $db->sql_fetchfield('field_ident');
1.245 + $db->sql_freeresult($result);
1.246 +
1.247 + add_log('admin', 'LOG_PROFILE_FIELD_ACTIVATE', $field_ident);
1.248 + trigger_error($user->lang['PROFILE_FIELD_ACTIVATED'] . adm_back_link($this->u_action));
1.249 +
1.250 + break;
1.251 +
1.252 + case 'deactivate':
1.253 + $field_id = request_var('field_id', 0);
1.254 +
1.255 + if (!$field_id)
1.256 + {
1.257 + trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.258 + }
1.259 +
1.260 + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
1.261 + SET field_active = 0
1.262 + WHERE field_id = $field_id";
1.263 + $db->sql_query($sql);
1.264 +
1.265 + $sql = 'SELECT field_ident
1.266 + FROM ' . PROFILE_FIELDS_TABLE . "
1.267 + WHERE field_id = $field_id";
1.268 + $result = $db->sql_query($sql);
1.269 + $field_ident = (string) $db->sql_fetchfield('field_ident');
1.270 + $db->sql_freeresult($result);
1.271 +
1.272 + add_log('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', $field_ident);
1.273 + trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action));
1.274 +
1.275 + break;
1.276 +
1.277 + case 'move_up':
1.278 + case 'move_down':
1.279 + $field_order = request_var('order', 0);
1.280 + $order_total = $field_order * 2 + (($action == 'move_up') ? -1 : 1);
1.281 +
1.282 + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
1.283 + SET field_order = $order_total - field_order
1.284 + WHERE field_order IN ($field_order, " . (($action == 'move_up') ? $field_order - 1 : $field_order + 1) . ')';
1.285 + $db->sql_query($sql);
1.286 +
1.287 + break;
1.288 +
1.289 + case 'create':
1.290 + case 'edit':
1.291 +
1.292 + $field_id = request_var('field_id', 0);
1.293 + $step = request_var('step', 1);
1.294 +
1.295 + $submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
1.296 + $save = (isset($_REQUEST['save'])) ? true : false;
1.297 +
1.298 + // The language id of default language
1.299 + $this->edit_lang_id = $this->lang_defs['iso'][$config['default_lang']];
1.300 +
1.301 + // We are editing... we need to grab basic things
1.302 + if ($action == 'edit')
1.303 + {
1.304 + if (!$field_id)
1.305 + {
1.306 + trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.307 + }
1.308 +
1.309 + $sql = 'SELECT l.*, f.*
1.310 + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
1.311 + WHERE l.lang_id = ' . $this->edit_lang_id . "
1.312 + AND f.field_id = $field_id
1.313 + AND l.field_id = f.field_id";
1.314 + $result = $db->sql_query($sql);
1.315 + $field_row = $db->sql_fetchrow($result);
1.316 + $db->sql_freeresult($result);
1.317 +
1.318 + if (!$field_row)
1.319 + {
1.320 + // Some admin changed the default language?
1.321 + $sql = 'SELECT l.*, f.*
1.322 + FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
1.323 + WHERE l.lang_id <> ' . $this->edit_lang_id . "
1.324 + AND f.field_id = $field_id
1.325 + AND l.field_id = f.field_id";
1.326 + $result = $db->sql_query($sql);
1.327 + $field_row = $db->sql_fetchrow($result);
1.328 + $db->sql_freeresult($result);
1.329 +
1.330 + if (!$field_row)
1.331 + {
1.332 + trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
1.333 + }
1.334 +
1.335 + $this->edit_lang_id = $field_row['lang_id'];
1.336 + }
1.337 + $field_type = $field_row['field_type'];
1.338 +
1.339 + // Get language entries
1.340 + $sql = 'SELECT *
1.341 + FROM ' . PROFILE_FIELDS_LANG_TABLE . '
1.342 + WHERE lang_id = ' . $this->edit_lang_id . "
1.343 + AND field_id = $field_id
1.344 + ORDER BY option_id ASC";
1.345 + $result = $db->sql_query($sql);
1.346 +
1.347 + $lang_options = array();
1.348 + while ($row = $db->sql_fetchrow($result))
1.349 + {
1.350 + $lang_options[$row['option_id']] = $row['lang_value'];
1.351 + }
1.352 + $db->sql_freeresult($result);
1.353 +
1.354 + $s_hidden_fields = '<input type="hidden" name="field_id" value="' . $field_id . '" />';
1.355 + }
1.356 + else
1.357 + {
1.358 + // We are adding a new field, define basic params
1.359 + $lang_options = $field_row = array();
1.360 +
1.361 + $field_type = request_var('field_type', 0);
1.362 +
1.363 + if (!$field_type)
1.364 + {
1.365 + trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
1.366 + }
1.367 +
1.368 + $field_row = array_merge($default_values[$field_type], array(
1.369 + 'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),
1.370 + 'field_required' => 0,
1.371 + 'field_hide' => 0,
1.372 + 'field_show_profile'=> 0,
1.373 + 'field_no_view' => 0,
1.374 + 'field_show_on_reg' => 0,
1.375 + 'field_show_on_vt' => 0,
1.376 + 'lang_name' => utf8_normalize_nfc(request_var('field_ident', '', true)),
1.377 + 'lang_explain' => '',
1.378 + 'lang_default_value'=> '')
1.379 + );
1.380 +
1.381 + $s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
1.382 + }
1.383 +
1.384 + // $exclude contains the data we gather in each step
1.385 + $exclude = array(
1.386 + 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'),
1.387 + 2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
1.388 + 3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
1.389 + );
1.390 +
1.391 + // Text-based fields require the lang_default_value to be excluded
1.392 + if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
1.393 + {
1.394 + $exclude[1][] = 'lang_default_value';
1.395 + }
1.396 +
1.397 + // option-specific fields require lang_options to be excluded
1.398 + if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
1.399 + {
1.400 + $exclude[1][] = 'lang_options';
1.401 + }
1.402 +
1.403 + $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']);
1.404 + $cp->vars['lang_name'] = utf8_normalize_nfc(request_var('lang_name', $field_row['lang_name'], true));
1.405 + $cp->vars['lang_explain'] = utf8_normalize_nfc(request_var('lang_explain', $field_row['lang_explain'], true));
1.406 + $cp->vars['lang_default_value'] = utf8_normalize_nfc(request_var('lang_default_value', $field_row['lang_default_value'], true));
1.407 +
1.408 + // Visibility Options...
1.409 + $visibility_ary = array(
1.410 + 'field_required',
1.411 + 'field_show_on_reg',
1.412 + 'field_show_on_vt',
1.413 + 'field_show_profile',
1.414 + 'field_hide',
1.415 + );
1.416 +
1.417 + foreach ($visibility_ary as $val)
1.418 + {
1.419 + $cp->vars[$val] = ($submit || $save) ? request_var($val, 0) : $field_row[$val];
1.420 + }
1.421 +
1.422 + $cp->vars['field_no_view'] = request_var('field_no_view', (int) $field_row['field_no_view']);
1.423 +
1.424 + // A boolean field expects an array as the lang options
1.425 + if ($field_type == FIELD_BOOL)
1.426 + {
1.427 + $options = utf8_normalize_nfc(request_var('lang_options', array(''), true));
1.428 + }
1.429 + else
1.430 + {
1.431 + $options = utf8_normalize_nfc(request_var('lang_options', '', true));
1.432 + }
1.433 +
1.434 + // If the user has submitted a form with options (i.e. dropdown field)
1.435 + if ($options)
1.436 + {
1.437 + $exploded_options = (is_array($options)) ? $options : explode("\n", $options);
1.438 +
1.439 + if (sizeof($exploded_options) == sizeof($lang_options) || $action == 'create')
1.440 + {
1.441 + // The number of options in the field is equal to the number of options already in the database
1.442 + // Or we are creating a new dropdown list.
1.443 + $cp->vars['lang_options'] = $exploded_options;
1.444 + }
1.445 + else if ($action == 'edit')
1.446 + {
1.447 + // Changing the number of options? (We remove and re-create the option fields)
1.448 + $cp->vars['lang_options'] = $exploded_options;
1.449 + }
1.450 + }
1.451 + else
1.452 + {
1.453 + $cp->vars['lang_options'] = $lang_options;
1.454 + }
1.455 +
1.456 + // step 2
1.457 + foreach ($exclude[2] as $key)
1.458 + {
1.459 + $var = utf8_normalize_nfc(request_var($key, $field_row[$key], true));
1.460 +
1.461 + // Manipulate the intended variables a little bit if needed
1.462 + if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen')
1.463 + {
1.464 + // Get the number of options if this key is 'field_maxlen'
1.465 + $var = sizeof(explode("\n", utf8_normalize_nfc(request_var('lang_options', '', true))));
1.466 + }
1.467 + else if ($field_type == FIELD_TEXT && $key == 'field_length')
1.468 + {
1.469 + if (isset($_REQUEST['rows']))
1.470 + {
1.471 + $cp->vars['rows'] = request_var('rows', 0);
1.472 + $cp->vars['columns'] = request_var('columns', 0);
1.473 + $var = $cp->vars['rows'] . '|' . $cp->vars['columns'];
1.474 + }
1.475 + else
1.476 + {
1.477 + $row_col = explode('|', $var);
1.478 + $cp->vars['rows'] = $row_col[0];
1.479 + $cp->vars['columns'] = $row_col[1];
1.480 + }
1.481 + }
1.482 + else if ($field_type == FIELD_DATE && $key == 'field_default_value')
1.483 + {
1.484 + $always_now = request_var('always_now', -1);
1.485 +
1.486 + if ($always_now == 1 || ($always_now === -1 && $var == 'now'))
1.487 + {
1.488 + $now = getdate();
1.489 +
1.490 + $cp->vars['field_default_value_day'] = $now['mday'];
1.491 + $cp->vars['field_default_value_month'] = $now['mon'];
1.492 + $cp->vars['field_default_value_year'] = $now['year'];
1.493 + $var = $_POST['field_default_value'] = 'now';
1.494 + }
1.495 + else
1.496 + {
1.497 + if (isset($_REQUEST['field_default_value_day']))
1.498 + {
1.499 + $cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
1.500 + $cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
1.501 + $cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
1.502 + $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']);
1.503 + }
1.504 + else
1.505 + {
1.506 + list($cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']) = explode('-', $var);
1.507 + }
1.508 + }
1.509 + }
1.510 + /* else if ($field_type == FIELD_BOOL && $key == 'field_default_value')
1.511 + {
1.512 + // Get the number of options if this key is 'field_maxlen'
1.513 + $var = request_var('field_default_value', 0);
1.514 + }*/
1.515 + else if ($field_type == FIELD_INT && $key == 'field_default_value')
1.516 + {
1.517 + // Permit an empty string
1.518 + if ($action == 'create' && request_var('field_default_value', '') === '')
1.519 + {
1.520 + $var = '';
1.521 + }
1.522 + }
1.523 +
1.524 + $cp->vars[$key] = $var;
1.525 + }
1.526 +
1.527 + // step 3 - all arrays
1.528 + if ($action == 'edit')
1.529 + {
1.530 + // Get language entries
1.531 + $sql = 'SELECT *
1.532 + FROM ' . PROFILE_FIELDS_LANG_TABLE . '
1.533 + WHERE lang_id <> ' . $this->edit_lang_id . "
1.534 + AND field_id = $field_id
1.535 + ORDER BY option_id ASC";
1.536 + $result = $db->sql_query($sql);
1.537 +
1.538 + $l_lang_options = array();
1.539 + while ($row = $db->sql_fetchrow($result))
1.540 + {
1.541 + $l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value'];
1.542 + }
1.543 + $db->sql_freeresult($result);
1.544 +
1.545 +
1.546 + $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value
1.547 + FROM ' . PROFILE_LANG_TABLE . '
1.548 + WHERE lang_id <> ' . $this->edit_lang_id . "
1.549 + AND field_id = $field_id
1.550 + ORDER BY lang_id ASC";
1.551 + $result = $db->sql_query($sql);
1.552 +
1.553 + $l_lang_name = $l_lang_explain = $l_lang_default_value = array();
1.554 + while ($row = $db->sql_fetchrow($result))
1.555 + {
1.556 + $l_lang_name[$row['lang_id']] = $row['lang_name'];
1.557 + $l_lang_explain[$row['lang_id']] = $row['lang_explain'];
1.558 + $l_lang_default_value[$row['lang_id']] = $row['lang_default_value'];
1.559 + }
1.560 + $db->sql_freeresult($result);
1.561 + }
1.562 +
1.563 + foreach ($exclude[3] as $key)
1.564 + {
1.565 + $cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => ''), true));
1.566 +
1.567 + if (!$cp->vars[$key] && $action == 'edit')
1.568 + {
1.569 + $cp->vars[$key] = $$key;
1.570 + }
1.571 + else if ($key == 'l_lang_options' && $field_type == FIELD_BOOL)
1.572 + {
1.573 + $cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => array('')), true));
1.574 + }
1.575 + else if ($key == 'l_lang_options' && is_array($cp->vars[$key]))
1.576 + {
1.577 + foreach ($cp->vars[$key] as $lang_id => $options)
1.578 + {
1.579 + $cp->vars[$key][$lang_id] = explode("\n", $options);
1.580 + }
1.581 +
1.582 + }
1.583 + }
1.584 +
1.585 + // Check for general issues in every step
1.586 + if ($submit) // && $step == 1
1.587 + {
1.588 + // Check values for step 1
1.589 + if ($cp->vars['field_ident'] == '')
1.590 + {
1.591 + $error[] = $user->lang['EMPTY_FIELD_IDENT'];
1.592 + }
1.593 +
1.594 + if (!preg_match('/^[a-z_]+$/', $cp->vars['field_ident']))
1.595 + {
1.596 + $error[] = $user->lang['INVALID_CHARS_FIELD_IDENT'];
1.597 + }
1.598 +
1.599 + if (strlen($cp->vars['field_ident']) > 17)
1.600 + {
1.601 + $error[] = $user->lang['INVALID_FIELD_IDENT_LEN'];
1.602 + }
1.603 +
1.604 + if ($cp->vars['lang_name'] == '')
1.605 + {
1.606 + $error[] = $user->lang['EMPTY_USER_FIELD_NAME'];
1.607 + }
1.608 +
1.609 + if ($field_type == FIELD_DROPDOWN && !sizeof($cp->vars['lang_options']))
1.610 + {
1.611 + $error[] = $user->lang['NO_FIELD_ENTRIES'];
1.612 + }
1.613 +
1.614 + if ($field_type == FIELD_BOOL && (empty($cp->vars['lang_options'][0]) || empty($cp->vars['lang_options'][1])))
1.615 + {
1.616 + $error[] = $user->lang['NO_FIELD_ENTRIES'];
1.617 + }
1.618 +
1.619 + // Check for already existing field ident
1.620 + if ($action != 'edit')
1.621 + {
1.622 + $sql = 'SELECT field_ident
1.623 + FROM ' . PROFILE_FIELDS_TABLE . "
1.624 + WHERE field_ident = '" . $db->sql_escape($cp->vars['field_ident']) . "'";
1.625 + $result = $db->sql_query($sql);
1.626 + $row = $db->sql_fetchrow($result);
1.627 + $db->sql_freeresult($result);
1.628 +
1.629 + if ($row)
1.630 + {
1.631 + $error[] = $user->lang['FIELD_IDENT_ALREADY_EXIST'];
1.632 + }
1.633 + }
1.634 + }
1.635 +
1.636 + $step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);
1.637 +
1.638 + if (sizeof($error))
1.639 + {
1.640 + $step--;
1.641 + $submit = false;
1.642 + }
1.643 +
1.644 + // Build up the specific hidden fields
1.645 + foreach ($exclude as $num => $key_ary)
1.646 + {
1.647 + if ($num == $step)
1.648 + {
1.649 + continue;
1.650 + }
1.651 +
1.652 + $_new_key_ary = array();
1.653 +
1.654 + foreach ($key_ary as $key)
1.655 + {
1.656 + if ($field_type == FIELD_TEXT && $key == 'field_length' && isset($_REQUEST['rows']))
1.657 + {
1.658 + $cp->vars['rows'] = request_var('rows', 0);
1.659 + $cp->vars['columns'] = request_var('columns', 0);
1.660 + $_new_key_ary[$key] = $cp->vars['rows'] . '|' . $cp->vars['columns'];
1.661 + }
1.662 + else if ($field_type == FIELD_DATE && $key == 'field_default_value')
1.663 + {
1.664 + $always_now = request_var('always_now', 0);
1.665 +
1.666 + if ($always_now)
1.667 + {
1.668 + $_new_key_ary[$key] = 'now';
1.669 + }
1.670 + else if (isset($_REQUEST['field_default_value_day']))
1.671 + {
1.672 + $cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
1.673 + $cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
1.674 + $cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
1.675 + $_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']);
1.676 + }
1.677 + }
1.678 + else if ($field_type == FIELD_BOOL && $key == 'l_lang_options' && isset($_REQUEST['l_lang_options']))
1.679 + {
1.680 + $_new_key_ary[$key] = utf8_normalize_nfc(request_var($key, array(array('')), true));
1.681 + }
1.682 + else
1.683 + {
1.684 + if (!isset($_REQUEST[$key]))
1.685 + {
1.686 + $var = false;
1.687 + }
1.688 + else if ($key == 'field_ident' && isset($cp->vars[$key]))
1.689 + {
1.690 + $_new_key_ary[$key]= $cp->vars[$key];
1.691 + }
1.692 + else
1.693 + {
1.694 + $_new_key_ary[$key] = (is_array($_REQUEST[$key])) ? utf8_normalize_nfc(request_var($key, array(''), true)) : utf8_normalize_nfc(request_var($key, '', true));
1.695 + }
1.696 + }
1.697 + }
1.698 +
1.699 + $s_hidden_fields .= build_hidden_fields($_new_key_ary);
1.700 + }
1.701 +
1.702 + if (!sizeof($error))
1.703 + {
1.704 + if ($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save))
1.705 + {
1.706 + $this->save_profile_field($cp, $field_type, $action);
1.707 + }
1.708 + else if ($action == 'edit' && $save)
1.709 + {
1.710 + $this->save_profile_field($cp, $field_type, $action);
1.711 + }
1.712 + }
1.713 +
1.714 + $template->assign_vars(array(
1.715 + 'S_EDIT' => true,
1.716 + 'S_EDIT_MODE' => ($action == 'edit') ? true : false,
1.717 + 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
1.718 +
1.719 + 'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)],
1.720 + 'L_EXPLAIN' => $user->lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($action)],
1.721 +
1.722 + 'U_ACTION' => $this->u_action . "&action=$action&step=$step",
1.723 + 'U_BACK' => $this->u_action)
1.724 + );
1.725 +
1.726 + // Now go through the steps
1.727 + switch ($step)
1.728 + {
1.729 + // Create basic options - only small differences between field types
1.730 + case 1:
1.731 +
1.732 + // Build common create options
1.733 + $template->assign_vars(array(
1.734 + 'S_STEP_ONE' => true,
1.735 + 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
1.736 + 'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
1.737 + 'S_SHOW_ON_VT' => ($cp->vars['field_show_on_vt']) ? true : false,
1.738 + 'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
1.739 + 'S_SHOW_PROFILE' => ($cp->vars['field_show_profile']) ? true : false,
1.740 + 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
1.741 +
1.742 + 'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
1.743 + 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])],
1.744 + 'FIELD_IDENT' => $cp->vars['field_ident'],
1.745 + 'LANG_NAME' => $cp->vars['lang_name'],
1.746 + 'LANG_EXPLAIN' => $cp->vars['lang_explain'])
1.747 + );
1.748 +
1.749 + // String and Text needs to set default values here...
1.750 + if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
1.751 + {
1.752 + $template->assign_vars(array(
1.753 + 'S_TEXT' => ($field_type == FIELD_TEXT) ? true : false,
1.754 + 'S_STRING' => ($field_type == FIELD_STRING) ? true : false,
1.755 +
1.756 + 'L_DEFAULT_VALUE_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_DEFAULT_VALUE_EXPLAIN'],
1.757 + 'LANG_DEFAULT_VALUE' => $cp->vars['lang_default_value'])
1.758 + );
1.759 + }
1.760 +
1.761 + if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
1.762 + {
1.763 + // Initialize these array elements if we are creating a new field
1.764 + if (!sizeof($cp->vars['lang_options']))
1.765 + {
1.766 + if ($field_type == FIELD_BOOL)
1.767 + {
1.768 + // No options have been defined for a boolean field.
1.769 + $cp->vars['lang_options'][0] = '';
1.770 + $cp->vars['lang_options'][1] = '';
1.771 + }
1.772 + else
1.773 + {
1.774 + // No options have been defined for the dropdown menu
1.775 + $cp->vars['lang_options'] = array();
1.776 + }
1.777 + }
1.778 +
1.779 + $template->assign_vars(array(
1.780 + 'S_BOOL' => ($field_type == FIELD_BOOL) ? true : false,
1.781 + 'S_DROPDOWN' => ($field_type == FIELD_DROPDOWN) ? true : false,
1.782 +
1.783 + 'L_LANG_OPTIONS_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_ENTRIES_EXPLAIN'],
1.784 + 'LANG_OPTIONS' => ($field_type == FIELD_DROPDOWN) ? implode("\n", $cp->vars['lang_options']) : '',
1.785 + 'FIRST_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][0] : '',
1.786 + 'SECOND_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][1] : '')
1.787 + );
1.788 + }
1.789 +
1.790 + break;
1.791 +
1.792 + case 2:
1.793 +
1.794 + $template->assign_vars(array(
1.795 + 'S_STEP_TWO' => true,
1.796 + 'L_NEXT_STEP' => (sizeof($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS'])
1.797 + );
1.798 +
1.799 + // Build options based on profile type
1.800 + $function = 'get_' . $cp->profile_types[$field_type] . '_options';
1.801 + $options = $cp->$function();
1.802 +
1.803 + foreach ($options as $num => $option_ary)
1.804 + {
1.805 + $template->assign_block_vars('option', $option_ary);
1.806 + }
1.807 +
1.808 + break;
1.809 +
1.810 + // Define remaining language variables
1.811 + case 3:
1.812 +
1.813 + $template->assign_var('S_STEP_THREE', true);
1.814 + $options = $this->build_language_options($cp, $field_type, $action);
1.815 +
1.816 + foreach ($options as $lang_id => $lang_ary)
1.817 + {
1.818 + $template->assign_block_vars('options', array(
1.819 + 'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso']))
1.820 + );
1.821 +
1.822 + foreach ($lang_ary['fields'] as $field_ident => $field_ary)
1.823 + {
1.824 + $template->assign_block_vars('options.field', array(
1.825 + 'L_TITLE' => $field_ary['TITLE'],
1.826 + 'L_EXPLAIN' => (isset($field_ary['EXPLAIN'])) ? $field_ary['EXPLAIN'] : '',
1.827 + 'FIELD' => $field_ary['FIELD'])
1.828 + );
1.829 + }
1.830 + }
1.831 +
1.832 + break;
1.833 + }
1.834 +
1.835 + $template->assign_vars(array(
1.836 + 'S_HIDDEN_FIELDS' => $s_hidden_fields)
1.837 + );
1.838 +
1.839 + return;
1.840 +
1.841 + break;
1.842 + }
1.843 +
1.844 + $sql = 'SELECT *
1.845 + FROM ' . PROFILE_FIELDS_TABLE . '
1.846 + ORDER BY field_order';
1.847 + $result = $db->sql_query($sql);
1.848 +
1.849 + $s_one_need_edit = false;
1.850 + while ($row = $db->sql_fetchrow($result))
1.851 + {
1.852 + $active_lang = (!$row['field_active']) ? 'ACTIVATE' : 'DEACTIVATE';
1.853 + $active_value = (!$row['field_active']) ? 'activate' : 'deactivate';
1.854 + $id = $row['field_id'];
1.855 +
1.856 + $s_need_edit = (sizeof($this->lang_defs['diff'][$row['field_id']])) ? true : false;
1.857 +
1.858 + if ($s_need_edit)
1.859 + {
1.860 + $s_one_need_edit = true;
1.861 + }
1.862 +
1.863 + $template->assign_block_vars('fields', array(
1.864 + 'FIELD_IDENT' => $row['field_ident'],
1.865 + 'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])],
1.866 +
1.867 + 'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],
1.868 + 'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id",
1.869 + 'U_EDIT' => $this->u_action . "&action=edit&field_id=$id",
1.870 + 'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
1.871 + 'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",
1.872 + 'U_MOVE_UP' => $this->u_action . "&action=move_up&order={$row['field_order']}",
1.873 + 'U_MOVE_DOWN' => $this->u_action . "&action=move_down&order={$row['field_order']}",
1.874 +
1.875 + 'S_NEED_EDIT' => $s_need_edit)
1.876 + );
1.877 + }
1.878 + $db->sql_freeresult($result);
1.879 +
1.880 + // At least one option field needs editing?
1.881 + if ($s_one_need_edit)
1.882 + {
1.883 + $template->assign_var('S_NEED_EDIT', true);
1.884 + }
1.885 +
1.886 + $s_select_type = '';
1.887 + foreach ($cp->profile_types as $key => $value)
1.888 + {
1.889 + $s_select_type .= '<option value="' . $key . '">' . $user->lang['FIELD_' . strtoupper($value)] . '</option>';
1.890 + }
1.891 +
1.892 + $template->assign_vars(array(
1.893 + 'U_ACTION' => $this->u_action,
1.894 + 'S_TYPE_OPTIONS' => $s_select_type)
1.895 + );
1.896 + }
1.897 +
1.898 + /**
1.899 + * Build all Language specific options
1.900 + */
1.901 + function build_language_options(&$cp, $field_type, $action = 'create')
1.902 + {
1.903 + global $user, $config, $db;
1.904 +
1.905 + $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
1.906 +
1.907 + $sql = 'SELECT lang_id, lang_iso
1.908 + FROM ' . LANG_TABLE . '
1.909 + WHERE lang_id <> ' . (int) $default_lang_id . '
1.910 + ORDER BY lang_english_name';
1.911 + $result = $db->sql_query($sql);
1.912 +
1.913 + $languages = array();
1.914 + while ($row = $db->sql_fetchrow($result))
1.915 + {
1.916 + $languages[$row['lang_id']] = $row['lang_iso'];
1.917 + }
1.918 + $db->sql_freeresult($result);
1.919 +
1.920 + $options = array();
1.921 + $options['lang_name'] = 'string';
1.922 + if ($cp->vars['lang_explain'])
1.923 + {
1.924 + $options['lang_explain'] = 'text';
1.925 + }
1.926 +
1.927 + switch ($field_type)
1.928 + {
1.929 + case FIELD_BOOL:
1.930 + $options['lang_options'] = 'two_options';
1.931 + break;
1.932 +
1.933 + case FIELD_DROPDOWN:
1.934 + $options['lang_options'] = 'optionfield';
1.935 + break;
1.936 +
1.937 + case FIELD_TEXT:
1.938 + case FIELD_STRING:
1.939 + if (strlen($cp->vars['lang_default_value']))
1.940 + {
1.941 + $options['lang_default_value'] = ($field_type == FIELD_STRING) ? 'string' : 'text';
1.942 + }
1.943 + break;
1.944 + }
1.945 +
1.946 + $lang_options = array();
1.947 +
1.948 + foreach ($options as $field => $field_type)
1.949 + {
1.950 + $lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id];
1.951 + $lang_options[1]['fields'][$field] = array(
1.952 + 'TITLE' => $user->lang['CP_' . strtoupper($field)],
1.953 + 'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . '</dd>'
1.954 + );
1.955 +
1.956 + if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
1.957 + {
1.958 + $lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
1.959 + }
1.960 + }
1.961 +
1.962 + foreach ($languages as $lang_id => $lang_iso)
1.963 + {
1.964 + $lang_options[$lang_id]['lang_iso'] = $lang_iso;
1.965 + foreach ($options as $field => $field_type)
1.966 + {
1.967 + $value = ($action == 'create') ? utf8_normalize_nfc(request_var('l_' . $field, array(0 => ''), true)) : $cp->vars['l_' . $field];
1.968 + if ($field == 'lang_options')
1.969 + {
1.970 + $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];
1.971 +
1.972 + switch ($field_type)
1.973 + {
1.974 + case 'two_options':
1.975 +
1.976 + $lang_options[$lang_id]['fields'][$field] = array(
1.977 + 'TITLE' => $user->lang['CP_' . strtoupper($field)],
1.978 + 'FIELD' => '
1.979 + <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>
1.980 + <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>'
1.981 + );
1.982 + break;
1.983 +
1.984 + case 'optionfield':
1.985 + $value = ((isset($value[$lang_id])) ? ((is_array($value[$lang_id])) ? implode("\n", $value[$lang_id]) : $value[$lang_id]) : implode("\n", $var));
1.986 + $lang_options[$lang_id]['fields'][$field] = array(
1.987 + 'TITLE' => $user->lang['CP_' . strtoupper($field)],
1.988 + 'FIELD' => '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="7" cols="80">' . $value . '</textarea></dd>'
1.989 + );
1.990 + break;
1.991 + }
1.992 +
1.993 + if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
1.994 + {
1.995 + $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
1.996 + }
1.997 + }
1.998 + else
1.999 + {
1.1000 + $var = ($action == 'create' || !is_array($cp->vars[$field])) ? $cp->vars[$field] : $cp->vars[$field][$lang_id];
1.1001 +
1.1002 + $lang_options[$lang_id]['fields'][$field] = array(
1.1003 + 'TITLE' => $user->lang['CP_' . strtoupper($field)],
1.1004 + '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>'
1.1005 + );
1.1006 +
1.1007 + if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
1.1008 + {
1.1009 + $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
1.1010 + }
1.1011 + }
1.1012 + }
1.1013 + }
1.1014 +
1.1015 + return $lang_options;
1.1016 + }
1.1017 +
1.1018 + /**
1.1019 + * Save Profile Field
1.1020 + */
1.1021 + function save_profile_field(&$cp, $field_type, $action = 'create')
1.1022 + {
1.1023 + global $db, $config, $user;
1.1024 +
1.1025 + $field_id = request_var('field_id', 0);
1.1026 +
1.1027 + // Collect all information, if something is going wrong, abort the operation
1.1028 + $profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();
1.1029 +
1.1030 + $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
1.1031 +
1.1032 + if ($action == 'create')
1.1033 + {
1.1034 + $sql = 'SELECT MAX(field_order) as max_field_order
1.1035 + FROM ' . PROFILE_FIELDS_TABLE;
1.1036 + $result = $db->sql_query($sql);
1.1037 + $new_field_order = (int) $db->sql_fetchfield('max_field_order');
1.1038 + $db->sql_freeresult($result);
1.1039 +
1.1040 + $field_ident = $cp->vars['field_ident'];
1.1041 + }
1.1042 +
1.1043 + // Save the field
1.1044 + $profile_fields = array(
1.1045 + 'field_length' => $cp->vars['field_length'],
1.1046 + 'field_minlen' => $cp->vars['field_minlen'],
1.1047 + 'field_maxlen' => $cp->vars['field_maxlen'],
1.1048 + 'field_novalue' => $cp->vars['field_novalue'],
1.1049 + 'field_default_value' => $cp->vars['field_default_value'],
1.1050 + 'field_validation' => $cp->vars['field_validation'],
1.1051 + 'field_required' => $cp->vars['field_required'],
1.1052 + 'field_show_on_reg' => $cp->vars['field_show_on_reg'],
1.1053 + 'field_show_on_vt' => $cp->vars['field_show_on_vt'],
1.1054 + 'field_hide' => $cp->vars['field_hide'],
1.1055 + 'field_show_profile' => $cp->vars['field_show_profile'],
1.1056 + 'field_no_view' => $cp->vars['field_no_view']
1.1057 + );
1.1058 +
1.1059 + if ($action == 'create')
1.1060 + {
1.1061 + $profile_fields += array(
1.1062 + 'field_type' => $field_type,
1.1063 + 'field_ident' => $field_ident,
1.1064 + 'field_name' => $field_ident,
1.1065 + 'field_order' => $new_field_order + 1,
1.1066 + 'field_active' => 1
1.1067 + );
1.1068 +
1.1069 + $sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields);
1.1070 + $db->sql_query($sql);
1.1071 +
1.1072 + $field_id = $db->sql_nextid();
1.1073 + }
1.1074 + else
1.1075 + {
1.1076 + $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
1.1077 + SET ' . $db->sql_build_array('UPDATE', $profile_fields) . "
1.1078 + WHERE field_id = $field_id";
1.1079 + $db->sql_query($sql);
1.1080 + }
1.1081 +
1.1082 + if ($action == 'create')
1.1083 + {
1.1084 + $field_ident = 'pf_' . $field_ident;
1.1085 + $profile_sql[] = $this->add_field_ident($field_ident, $field_type);
1.1086 + }
1.1087 +
1.1088 + $sql_ary = array(
1.1089 + 'lang_name' => $cp->vars['lang_name'],
1.1090 + 'lang_explain' => $cp->vars['lang_explain'],
1.1091 + 'lang_default_value' => $cp->vars['lang_default_value']
1.1092 + );
1.1093 +
1.1094 + if ($action == 'create')
1.1095 + {
1.1096 + $sql_ary['field_id'] = $field_id;
1.1097 + $sql_ary['lang_id'] = $default_lang_id;
1.1098 +
1.1099 + $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1.1100 + }
1.1101 + else
1.1102 + {
1.1103 + $this->update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id));
1.1104 + }
1.1105 +
1.1106 + if (is_array($cp->vars['l_lang_name']) && sizeof($cp->vars['l_lang_name']))
1.1107 + {
1.1108 + foreach ($cp->vars['l_lang_name'] as $lang_id => $data)
1.1109 + {
1.1110 + if (($cp->vars['lang_name'] != '' && $cp->vars['l_lang_name'][$lang_id] == '')
1.1111 + || ($cp->vars['lang_explain'] != '' && $cp->vars['l_lang_explain'][$lang_id] == '')
1.1112 + || ($cp->vars['lang_default_value'] != '' && $cp->vars['l_lang_default_value'][$lang_id] == ''))
1.1113 + {
1.1114 + $empty_lang[$lang_id] = true;
1.1115 + break;
1.1116 + }
1.1117 +
1.1118 + if (!isset($empty_lang[$lang_id]))
1.1119 + {
1.1120 + $profile_lang[] = array(
1.1121 + 'field_id' => $field_id,
1.1122 + 'lang_id' => $lang_id,
1.1123 + 'lang_name' => $cp->vars['l_lang_name'][$lang_id],
1.1124 + 'lang_explain' => (isset($cp->vars['l_lang_explain'][$lang_id])) ? $cp->vars['l_lang_explain'][$lang_id] : '',
1.1125 + 'lang_default_value' => (isset($cp->vars['l_lang_default_value'][$lang_id])) ? $cp->vars['l_lang_default_value'][$lang_id] : ''
1.1126 + );
1.1127 + }
1.1128 + }
1.1129 +
1.1130 + foreach ($empty_lang as $lang_id => $NULL)
1.1131 + {
1.1132 + $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . "
1.1133 + WHERE field_id = $field_id
1.1134 + AND lang_id = " . (int) $lang_id;
1.1135 + $db->sql_query($sql);
1.1136 + }
1.1137 + }
1.1138 +
1.1139 + // These are always arrays because the key is the language id...
1.1140 + $cp->vars['l_lang_name'] = utf8_normalize_nfc(request_var('l_lang_name', array(0 => ''), true));
1.1141 + $cp->vars['l_lang_explain'] = utf8_normalize_nfc(request_var('l_lang_explain', array(0 => ''), true));
1.1142 + $cp->vars['l_lang_default_value'] = utf8_normalize_nfc(request_var('l_lang_default_value', array(0 => ''), true));
1.1143 +
1.1144 + if ($field_type != FIELD_BOOL)
1.1145 + {
1.1146 + $cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => ''), true));
1.1147 + }
1.1148 + else
1.1149 + {
1.1150 + /**
1.1151 + * @todo check if this line is correct...
1.1152 + $cp->vars['l_lang_default_value'] = request_var('l_lang_default_value', array(0 => array('')), true);
1.1153 + */
1.1154 + $cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => array('')), true));
1.1155 + }
1.1156 +
1.1157 + if ($cp->vars['lang_options'])
1.1158 + {
1.1159 + if (!is_array($cp->vars['lang_options']))
1.1160 + {
1.1161 + $cp->vars['lang_options'] = explode("\n", $cp->vars['lang_options']);
1.1162 + }
1.1163 +
1.1164 + if ($action != 'create')
1.1165 + {
1.1166 + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1.1167 + WHERE field_id = $field_id
1.1168 + AND lang_id = " . (int) $default_lang_id;
1.1169 + $db->sql_query($sql);
1.1170 + }
1.1171 +
1.1172 + foreach ($cp->vars['lang_options'] as $option_id => $value)
1.1173 + {
1.1174 + $sql_ary = array(
1.1175 + 'field_type' => (int) $field_type,
1.1176 + 'lang_value' => $value
1.1177 + );
1.1178 +
1.1179 + if ($action == 'create')
1.1180 + {
1.1181 + $sql_ary['field_id'] = $field_id;
1.1182 + $sql_ary['lang_id'] = $default_lang_id;
1.1183 + $sql_ary['option_id'] = (int) $option_id;
1.1184 +
1.1185 + $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1.1186 + }
1.1187 + else
1.1188 + {
1.1189 + $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array(
1.1190 + 'field_id' => $field_id,
1.1191 + 'lang_id' => (int) $default_lang_id,
1.1192 + 'option_id' => (int) $option_id)
1.1193 + );
1.1194 + }
1.1195 + }
1.1196 + }
1.1197 +
1.1198 + if (is_array($cp->vars['l_lang_options']) && sizeof($cp->vars['l_lang_options']))
1.1199 + {
1.1200 + $empty_lang = array();
1.1201 +
1.1202 + foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary)
1.1203 + {
1.1204 + if (!is_array($lang_ary))
1.1205 + {
1.1206 + $lang_ary = explode("\n", $lang_ary);
1.1207 + }
1.1208 +
1.1209 + if (sizeof($lang_ary) != sizeof($cp->vars['lang_options']))
1.1210 + {
1.1211 + $empty_lang[$lang_id] = true;
1.1212 + }
1.1213 +
1.1214 + if (!isset($empty_lang[$lang_id]))
1.1215 + {
1.1216 + if ($action != 'create')
1.1217 + {
1.1218 + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1.1219 + WHERE field_id = $field_id
1.1220 + AND lang_id = " . (int) $lang_id;
1.1221 + $db->sql_query($sql);
1.1222 + }
1.1223 +
1.1224 + foreach ($lang_ary as $option_id => $value)
1.1225 + {
1.1226 + $profile_lang_fields[] = array(
1.1227 + 'field_id' => (int) $field_id,
1.1228 + 'lang_id' => (int) $lang_id,
1.1229 + 'option_id' => (int) $option_id,
1.1230 + 'field_type' => (int) $field_type,
1.1231 + 'lang_value' => $value
1.1232 + );
1.1233 + }
1.1234 + }
1.1235 + }
1.1236 +
1.1237 + foreach ($empty_lang as $lang_id => $NULL)
1.1238 + {
1.1239 + $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1.1240 + WHERE field_id = $field_id
1.1241 + AND lang_id = " . (int) $lang_id;
1.1242 + $db->sql_query($sql);
1.1243 + }
1.1244 + }
1.1245 +
1.1246 + foreach ($profile_lang as $sql)
1.1247 + {
1.1248 + if ($action == 'create')
1.1249 + {
1.1250 + $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1.1251 + }
1.1252 + else
1.1253 + {
1.1254 + $lang_id = $sql['lang_id'];
1.1255 + unset($sql['lang_id'], $sql['field_id']);
1.1256 +
1.1257 + $this->update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id));
1.1258 + }
1.1259 + }
1.1260 +
1.1261 + if (sizeof($profile_lang_fields))
1.1262 + {
1.1263 + foreach ($profile_lang_fields as $sql)
1.1264 + {
1.1265 + if ($action == 'create')
1.1266 + {
1.1267 + $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1.1268 + }
1.1269 + else
1.1270 + {
1.1271 + $lang_id = $sql['lang_id'];
1.1272 + $option_id = $sql['option_id'];
1.1273 + unset($sql['lang_id'], $sql['field_id'], $sql['option_id']);
1.1274 +
1.1275 + $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array(
1.1276 + 'lang_id' => $lang_id,
1.1277 + 'field_id' => $field_id,
1.1278 + 'option_id' => $option_id)
1.1279 + );
1.1280 + }
1.1281 + }
1.1282 + }
1.1283 +
1.1284 +
1.1285 + $db->sql_transaction('begin');
1.1286 +
1.1287 + if ($action == 'create')
1.1288 + {
1.1289 + foreach ($profile_sql as $sql)
1.1290 + {
1.1291 + $db->sql_query($sql);
1.1292 + }
1.1293 + }
1.1294 +
1.1295 + $db->sql_transaction('commit');
1.1296 +
1.1297 + if ($action == 'edit')
1.1298 + {
1.1299 + add_log('admin', 'LOG_PROFILE_FIELD_EDIT', $cp->vars['field_ident'] . ':' . $cp->vars['lang_name']);
1.1300 + trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1.1301 + }
1.1302 + else
1.1303 + {
1.1304 + add_log('admin', 'LOG_PROFILE_FIELD_CREATE', substr($field_ident, 3) . ':' . $cp->vars['lang_name']);
1.1305 + trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1.1306 + }
1.1307 + }
1.1308 +
1.1309 + /**
1.1310 + * Update, then insert if not successfull
1.1311 + */
1.1312 + function update_insert($table, $sql_ary, $where_fields)
1.1313 + {
1.1314 + global $db;
1.1315 +
1.1316 + $where_sql = array();
1.1317 + $check_key = '';
1.1318 +
1.1319 + foreach ($where_fields as $key => $value)
1.1320 + {
1.1321 + $check_key = (!$check_key) ? $key : $check_key;
1.1322 + $where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : (int) $value);
1.1323 + }
1.1324 +
1.1325 + if (!sizeof($where_sql))
1.1326 + {
1.1327 + return;
1.1328 + }
1.1329 +
1.1330 + $sql = "SELECT $check_key
1.1331 + FROM $table
1.1332 + WHERE " . implode(' AND ', $where_sql);
1.1333 + $result = $db->sql_query($sql);
1.1334 + $row = $db->sql_fetchrow($result);
1.1335 + $db->sql_freeresult($result);
1.1336 +
1.1337 + if (!$row)
1.1338 + {
1.1339 + $sql_ary = array_merge($where_fields, $sql_ary);
1.1340 +
1.1341 + if (sizeof($sql_ary))
1.1342 + {
1.1343 + $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary));
1.1344 + }
1.1345 + }
1.1346 + else
1.1347 + {
1.1348 + if (sizeof($sql_ary))
1.1349 + {
1.1350 + $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . '
1.1351 + WHERE ' . implode(' AND ', $where_sql);
1.1352 + $db->sql_query($sql);
1.1353 + }
1.1354 + }
1.1355 + }
1.1356 +
1.1357 + /**
1.1358 + * Return sql statement for adding a new field ident (profile field) to the profile fields data table
1.1359 + */
1.1360 + function add_field_ident($field_ident, $field_type)
1.1361 + {
1.1362 + global $db;
1.1363 +
1.1364 + switch ($db->sql_layer)
1.1365 + {
1.1366 + case 'mysql':
1.1367 + case 'mysql4':
1.1368 + case 'mysqli':
1.1369 +
1.1370 + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1.1371 + $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` ";
1.1372 +
1.1373 + switch ($field_type)
1.1374 + {
1.1375 + case FIELD_STRING:
1.1376 + $sql .= ' VARCHAR(255) ';
1.1377 + break;
1.1378 +
1.1379 + case FIELD_DATE:
1.1380 + $sql .= 'VARCHAR(10) ';
1.1381 + break;
1.1382 +
1.1383 + case FIELD_TEXT:
1.1384 + $sql .= "TEXT";
1.1385 + // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1.1386 + // ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
1.1387 + break;
1.1388 +
1.1389 + case FIELD_BOOL:
1.1390 + $sql .= 'TINYINT(2) ';
1.1391 + break;
1.1392 +
1.1393 + case FIELD_DROPDOWN:
1.1394 + $sql .= 'MEDIUMINT(8) ';
1.1395 + break;
1.1396 +
1.1397 + case FIELD_INT:
1.1398 + $sql .= 'BIGINT(20) ';
1.1399 + break;
1.1400 + }
1.1401 +
1.1402 + break;
1.1403 +
1.1404 + case 'sqlite':
1.1405 +
1.1406 + switch ($field_type)
1.1407 + {
1.1408 + case FIELD_STRING:
1.1409 + $type = ' VARCHAR(255) ';
1.1410 + break;
1.1411 +
1.1412 + case FIELD_DATE:
1.1413 + $type = 'VARCHAR(10) ';
1.1414 + break;
1.1415 +
1.1416 + case FIELD_TEXT:
1.1417 + $type = "TEXT(65535)";
1.1418 + // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1.1419 + // ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
1.1420 + break;
1.1421 +
1.1422 + case FIELD_BOOL:
1.1423 + $type = 'TINYINT(2) ';
1.1424 + break;
1.1425 +
1.1426 + case FIELD_DROPDOWN:
1.1427 + $type = 'MEDIUMINT(8) ';
1.1428 + break;
1.1429 +
1.1430 + case FIELD_INT:
1.1431 + $type = 'BIGINT(20) ';
1.1432 + break;
1.1433 + }
1.1434 +
1.1435 + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1.1436 + if (version_compare(sqlite_libversion(), '3.0') == -1)
1.1437 + {
1.1438 + $sql = "SELECT sql
1.1439 + FROM sqlite_master
1.1440 + WHERE type = 'table'
1.1441 + AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
1.1442 + ORDER BY type DESC, name;";
1.1443 + $result = $db->sql_query($sql);
1.1444 + $row = $db->sql_fetchrow($result);
1.1445 + $db->sql_freeresult($result);
1.1446 +
1.1447 + // Create a temp table and populate it, destroy the existing one
1.1448 + $db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
1.1449 + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
1.1450 + $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
1.1451 +
1.1452 + preg_match('#\((.*)\)#s', $row['sql'], $matches);
1.1453 +
1.1454 + $new_table_cols = trim($matches[1]);
1.1455 + $old_table_cols = explode(',', $new_table_cols);
1.1456 + $column_list = array();
1.1457 +
1.1458 + foreach ($old_table_cols as $declaration)
1.1459 + {
1.1460 + $entities = preg_split('#\s+#', trim($declaration));
1.1461 + if ($entities[0] == 'PRIMARY')
1.1462 + {
1.1463 + continue;
1.1464 + }
1.1465 + $column_list[] = $entities[0];
1.1466 + }
1.1467 +
1.1468 + $columns = implode(',', $column_list);
1.1469 +
1.1470 + $new_table_cols = $field_ident . ' ' . $type . ',' . $new_table_cols;
1.1471 +
1.1472 + // create a new table and fill it up. destroy the temp one
1.1473 + $db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
1.1474 + $db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
1.1475 + $db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
1.1476 + }
1.1477 + else
1.1478 + {
1.1479 + $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident [$type]";
1.1480 + }
1.1481 +
1.1482 + break;
1.1483 +
1.1484 + case 'mssql':
1.1485 + case 'mssql_odbc':
1.1486 + case 'mssqlnative':
1.1487 +
1.1488 + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1.1489 + $sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] ";
1.1490 +
1.1491 + switch ($field_type)
1.1492 + {
1.1493 + case FIELD_STRING:
1.1494 + $sql .= ' [VARCHAR] (255) ';
1.1495 + break;
1.1496 +
1.1497 + case FIELD_DATE:
1.1498 + $sql .= '[VARCHAR] (10) ';
1.1499 + break;
1.1500 +
1.1501 + case FIELD_TEXT:
1.1502 + $sql .= "[TEXT]";
1.1503 + // ADD {$field_ident}_bbcode_uid [VARCHAR] (5) NOT NULL,
1.1504 + // ADD {$field_ident}_bbcode_bitfield [INT] UNSIGNED";
1.1505 + break;
1.1506 +
1.1507 + case FIELD_BOOL:
1.1508 + case FIELD_DROPDOWN:
1.1509 + $sql .= '[INT] ';
1.1510 + break;
1.1511 +
1.1512 + case FIELD_INT:
1.1513 + $sql .= '[FLOAT] ';
1.1514 + break;
1.1515 + }
1.1516 +
1.1517 + break;
1.1518 +
1.1519 + case 'postgres':
1.1520 +
1.1521 + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1.1522 + $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD COLUMN \"$field_ident\" ";
1.1523 +
1.1524 + switch ($field_type)
1.1525 + {
1.1526 + case FIELD_STRING:
1.1527 + $sql .= ' VARCHAR(255) ';
1.1528 + break;
1.1529 +
1.1530 + case FIELD_DATE:
1.1531 + $sql .= 'VARCHAR(10) ';
1.1532 + break;
1.1533 +
1.1534 + case FIELD_TEXT:
1.1535 + $sql .= "TEXT";
1.1536 + // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1.1537 + // ADD {$field_ident}_bbcode_bitfield INT4 UNSIGNED";
1.1538 + break;
1.1539 +
1.1540 + case FIELD_BOOL:
1.1541 + $sql .= 'INT2 ';
1.1542 + break;
1.1543 +
1.1544 + case FIELD_DROPDOWN:
1.1545 + $sql .= 'INT4 ';
1.1546 + break;
1.1547 +
1.1548 + case FIELD_INT:
1.1549 + $sql .= 'INT8 ';
1.1550 + break;
1.1551 + }
1.1552 +
1.1553 + break;
1.1554 +
1.1555 + case 'firebird':
1.1556 +
1.1557 + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1.1558 + $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' ADD "' . strtoupper($field_ident) . '" ';
1.1559 +
1.1560 + switch ($field_type)
1.1561 + {
1.1562 + case FIELD_STRING:
1.1563 + $sql .= ' VARCHAR(255) ';
1.1564 + break;
1.1565 +
1.1566 + case FIELD_DATE:
1.1567 + $sql .= 'VARCHAR(10) ';
1.1568 + break;
1.1569 +
1.1570 + case FIELD_TEXT:
1.1571 + $sql .= "BLOB SUB_TYPE TEXT";
1.1572 + // ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
1.1573 + // ADD {$field_ident}_bbcode_bitfield INTEGER UNSIGNED";
1.1574 + break;
1.1575 +
1.1576 + case FIELD_BOOL:
1.1577 + case FIELD_DROPDOWN:
1.1578 + $sql .= 'INTEGER ';
1.1579 + break;
1.1580 +
1.1581 + case FIELD_INT:
1.1582 + $sql .= 'DOUBLE PRECISION ';
1.1583 + break;
1.1584 + }
1.1585 +
1.1586 + break;
1.1587 +
1.1588 + case 'oracle':
1.1589 +
1.1590 + // We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
1.1591 + $sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident ";
1.1592 +
1.1593 + switch ($field_type)
1.1594 + {
1.1595 + case FIELD_STRING:
1.1596 + $sql .= ' VARCHAR2(255) ';
1.1597 + break;
1.1598 +
1.1599 + case FIELD_DATE:
1.1600 + $sql .= 'VARCHAR2(10) ';
1.1601 + break;
1.1602 +
1.1603 + case FIELD_TEXT:
1.1604 + $sql .= "CLOB";
1.1605 + // ADD {$field_ident}_bbcode_uid VARCHAR2(5) NOT NULL,
1.1606 + // ADD {$field_ident}_bbcode_bitfield NUMBER(11) UNSIGNED";
1.1607 + break;
1.1608 +
1.1609 + case FIELD_BOOL:
1.1610 + $sql .= 'NUMBER(2) ';
1.1611 + break;
1.1612 +
1.1613 + case FIELD_DROPDOWN:
1.1614 + $sql .= 'NUMBER(8) ';
1.1615 + break;
1.1616 +
1.1617 + case FIELD_INT:
1.1618 + $sql .= 'NUMBER(20) ';
1.1619 + break;
1.1620 + }
1.1621 +
1.1622 + break;
1.1623 + }
1.1624 +
1.1625 + return $sql;
1.1626 + }
1.1627 +}
1.1628 +
1.1629 +?>