|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
*
|
|
|
ef5584 |
* @package acp
|
|
|
ef5584 |
* @version $Id: acp_profile.php 9127 2008-11-26 19:58:35Z acydburn $
|
|
|
ef5584 |
* @copyright (c) 2005 phpBB Group
|
|
|
ef5584 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
ef5584 |
*
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* @ignore
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
if (!defined('IN_PHPBB'))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
exit;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* @package acp
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
class acp_profile
|
|
|
ef5584 |
{
|
|
|
ef5584 |
var $u_action;
|
|
|
ef5584 |
|
|
|
ef5584 |
var $edit_lang_id;
|
|
|
ef5584 |
var $lang_defs;
|
|
|
ef5584 |
|
|
|
ef5584 |
function main($id, $mode)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $config, $db, $user, $auth, $template, $cache;
|
|
|
ef5584 |
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
|
|
|
ef5584 |
|
|
|
ef5584 |
include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
|
|
ef5584 |
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
|
|
ef5584 |
include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
|
|
|
ef5584 |
|
|
|
ef5584 |
$user->add_lang(array('ucp', 'acp/profile'));
|
|
|
ef5584 |
$this->tpl_name = 'acp_profile';
|
|
|
ef5584 |
$this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';
|
|
|
ef5584 |
|
|
|
ef5584 |
$action = (isset($_POST['create'])) ? 'create' : request_var('action', '');
|
|
|
ef5584 |
|
|
|
ef5584 |
$error = array();
|
|
|
ef5584 |
$s_hidden_fields = '';
|
|
|
ef5584 |
|
|
|
ef5584 |
// Define some default values for each field type
|
|
|
ef5584 |
$default_values = array(
|
|
|
ef5584 |
FIELD_STRING => array('field_length' => 10, 'field_minlen' => 0, 'field_maxlen' => 20, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
|
|
|
ef5584 |
FIELD_TEXT => array('field_length' => '5|80', 'field_minlen' => 0, 'field_maxlen' => 1000, 'field_validation' => '.*', 'field_novalue' => '', 'field_default_value' => ''),
|
|
|
ef5584 |
FIELD_INT => array('field_length' => 5, 'field_minlen' => 0, 'field_maxlen' => 100, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
|
|
|
ef5584 |
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'),
|
|
|
ef5584 |
FIELD_BOOL => array('field_length' => 1, 'field_minlen' => 0, 'field_maxlen' => 0, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
|
|
|
ef5584 |
FIELD_DROPDOWN => array('field_length' => 0, 'field_minlen' => 0, 'field_maxlen' => 5, 'field_validation' => '', 'field_novalue' => 0, 'field_default_value' => 0),
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
$cp = new custom_profile_admin();
|
|
|
ef5584 |
|
|
|
ef5584 |
// Build Language array
|
|
|
ef5584 |
// Based on this, we decide which elements need to be edited later and which language items are missing
|
|
|
ef5584 |
$this->lang_defs = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT lang_id, lang_iso
|
|
|
ef5584 |
FROM ' . LANG_TABLE . '
|
|
|
ef5584 |
ORDER BY lang_english_name';
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Make some arrays with all available languages
|
|
|
ef5584 |
$this->lang_defs['id'][$row['lang_id']] = $row['lang_iso'];
|
|
|
ef5584 |
$this->lang_defs['iso'][$row['lang_iso']] = $row['lang_id'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT field_id, lang_id
|
|
|
ef5584 |
FROM ' . PROFILE_LANG_TABLE . '
|
|
|
ef5584 |
ORDER BY lang_id';
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Which languages are available for each item
|
|
|
ef5584 |
$this->lang_defs['entry'][$row['field_id']][] = $row['lang_id'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Have some fields been defined?
|
|
|
ef5584 |
if (isset($this->lang_defs['entry']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($this->lang_defs['entry'] as $field_id => $field_ary)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Fill an array with the languages that are missing for each field
|
|
|
ef5584 |
$this->lang_defs['diff'][$field_id] = array_diff(array_values($this->lang_defs['iso']), $field_ary);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($action)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case 'delete':
|
|
|
ef5584 |
$field_id = request_var('field_id', 0);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$field_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (confirm_box(true))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'SELECT field_ident
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$field_ident = (string) $db->sql_fetchfield('field_ident');
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
$db->sql_transaction('begin');
|
|
|
ef5584 |
|
|
|
ef5584 |
$db->sql_query('DELETE FROM ' . PROFILE_FIELDS_TABLE . " WHERE field_id = $field_id");
|
|
|
ef5584 |
$db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
|
|
|
ef5584 |
$db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($db->sql_layer)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case 'sqlite':
|
|
|
ef5584 |
$sql = "SELECT sql
|
|
|
ef5584 |
FROM sqlite_master
|
|
|
ef5584 |
WHERE type = 'table'
|
|
|
ef5584 |
AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
|
|
|
ef5584 |
ORDER BY type DESC, name;";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$row = $db->sql_fetchrow($result);
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Create a temp table and populate it, destroy the existing one
|
|
|
ef5584 |
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
|
|
|
ef5584 |
$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
|
|
|
ef5584 |
$db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
|
|
|
ef5584 |
|
|
|
ef5584 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
ef5584 |
|
|
|
ef5584 |
$new_table_cols = trim($matches[1]);
|
|
|
ef5584 |
$old_table_cols = preg_split('/,(?=[\\sa-z])/im', $new_table_cols);
|
|
|
ef5584 |
$column_list = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($old_table_cols as $declaration)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($entities[0] == 'PRIMARY')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
continue;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($entities[0] !== 'pf_' . $field_ident)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$column_list[] = $entities[0];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$columns = implode(',', $column_list);
|
|
|
ef5584 |
|
|
|
ef5584 |
$new_table_cols = preg_replace('/' . 'pf_' . $field_ident . '[^,]+,/', '', $new_table_cols);
|
|
|
ef5584 |
|
|
|
ef5584 |
// create a new table and fill it up. destroy the temp one
|
|
|
ef5584 |
$db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
|
|
|
ef5584 |
$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
|
|
|
ef5584 |
$db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
default:
|
|
|
ef5584 |
$db->sql_query('ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " DROP COLUMN pf_$field_ident");
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$order = 0;
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT *
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE . '
|
|
|
ef5584 |
ORDER BY field_order';
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$order++;
|
|
|
ef5584 |
if ($row['field_order'] != $order)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
SET field_order = $order
|
|
|
ef5584 |
WHERE field_id = {$row['field_id']}";
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
$db->sql_transaction('commit');
|
|
|
ef5584 |
|
|
|
ef5584 |
add_log('admin', 'LOG_PROFILE_FIELD_REMOVED', $field_ident);
|
|
|
ef5584 |
trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
confirm_box(false, 'DELETE_PROFILE_FIELD', build_hidden_fields(array(
|
|
|
ef5584 |
'i' => $id,
|
|
|
ef5584 |
'mode' => $mode,
|
|
|
ef5584 |
'action' => $action,
|
|
|
ef5584 |
'field_id' => $field_id,
|
|
|
ef5584 |
)));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'activate':
|
|
|
ef5584 |
$field_id = request_var('field_id', 0);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$field_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT lang_id
|
|
|
ef5584 |
FROM ' . LANG_TABLE . "
|
|
|
ef5584 |
WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$default_lang_id = (int) $db->sql_fetchfield('lang_id');
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!in_array($default_lang_id, $this->lang_defs['entry'][$field_id]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['DEFAULT_LANGUAGE_NOT_FILLED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
SET field_active = 1
|
|
|
ef5584 |
WHERE field_id = $field_id";
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT field_ident
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$field_ident = (string) $db->sql_fetchfield('field_ident');
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
add_log('admin', 'LOG_PROFILE_FIELD_ACTIVATE', $field_ident);
|
|
|
ef5584 |
trigger_error($user->lang['PROFILE_FIELD_ACTIVATED'] . adm_back_link($this->u_action));
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'deactivate':
|
|
|
ef5584 |
$field_id = request_var('field_id', 0);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$field_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
SET field_active = 0
|
|
|
ef5584 |
WHERE field_id = $field_id";
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT field_ident
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$field_ident = (string) $db->sql_fetchfield('field_ident');
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
add_log('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', $field_ident);
|
|
|
ef5584 |
trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action));
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'move_up':
|
|
|
ef5584 |
case 'move_down':
|
|
|
ef5584 |
$field_order = request_var('order', 0);
|
|
|
ef5584 |
$order_total = $field_order * 2 + (($action == 'move_up') ? -1 : 1);
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
SET field_order = $order_total - field_order
|
|
|
ef5584 |
WHERE field_order IN ($field_order, " . (($action == 'move_up') ? $field_order - 1 : $field_order + 1) . ')';
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'create':
|
|
|
ef5584 |
case 'edit':
|
|
|
ef5584 |
|
|
|
ef5584 |
$field_id = request_var('field_id', 0);
|
|
|
ef5584 |
$step = request_var('step', 1);
|
|
|
ef5584 |
|
|
|
ef5584 |
$submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
|
|
|
ef5584 |
$save = (isset($_REQUEST['save'])) ? true : false;
|
|
|
ef5584 |
|
|
|
ef5584 |
// The language id of default language
|
|
|
ef5584 |
$this->edit_lang_id = $this->lang_defs['iso'][$config['default_lang']];
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are editing... we need to grab basic things
|
|
|
ef5584 |
if ($action == 'edit')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (!$field_id)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT l.*, f.*
|
|
|
ef5584 |
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
|
|
|
ef5584 |
WHERE l.lang_id = ' . $this->edit_lang_id . "
|
|
|
ef5584 |
AND f.field_id = $field_id
|
|
|
ef5584 |
AND l.field_id = f.field_id";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$field_row = $db->sql_fetchrow($result);
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$field_row)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Some admin changed the default language?
|
|
|
ef5584 |
$sql = 'SELECT l.*, f.*
|
|
|
ef5584 |
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
|
|
|
ef5584 |
WHERE l.lang_id <> ' . $this->edit_lang_id . "
|
|
|
ef5584 |
AND f.field_id = $field_id
|
|
|
ef5584 |
AND l.field_id = f.field_id";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$field_row = $db->sql_fetchrow($result);
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$field_row)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$this->edit_lang_id = $field_row['lang_id'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$field_type = $field_row['field_type'];
|
|
|
ef5584 |
|
|
|
ef5584 |
// Get language entries
|
|
|
ef5584 |
$sql = 'SELECT *
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_LANG_TABLE . '
|
|
|
ef5584 |
WHERE lang_id = ' . $this->edit_lang_id . "
|
|
|
ef5584 |
AND field_id = $field_id
|
|
|
ef5584 |
ORDER BY option_id ASC";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$lang_options = array();
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_options[$row['option_id']] = $row['lang_value'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
$s_hidden_fields = '<input type="hidden" name="field_id" value="' . $field_id . '" />';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// We are adding a new field, define basic params
|
|
|
ef5584 |
$lang_options = $field_row = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
$field_type = request_var('field_type', 0);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$field_row = array_merge($default_values[$field_type], array(
|
|
|
ef5584 |
'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),
|
|
|
ef5584 |
'field_required' => 0,
|
|
|
ef5584 |
'field_hide' => 0,
|
|
|
ef5584 |
'field_show_profile'=> 0,
|
|
|
ef5584 |
'field_no_view' => 0,
|
|
|
ef5584 |
'field_show_on_reg' => 0,
|
|
|
ef5584 |
'lang_name' => utf8_normalize_nfc(request_var('field_ident', '', true)),
|
|
|
ef5584 |
'lang_explain' => '',
|
|
|
ef5584 |
'lang_default_value'=> '')
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
$s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// $exclude contains the data we gather in each step
|
|
|
ef5584 |
$exclude = array(
|
|
|
ef5584 |
1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_required', 'field_hide', 'field_show_profile', 'field_no_view'),
|
|
|
ef5584 |
2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
|
|
|
ef5584 |
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Text-based fields require the lang_default_value to be excluded
|
|
|
ef5584 |
if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$exclude[1][] = 'lang_default_value';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// option-specific fields require lang_options to be excluded
|
|
|
ef5584 |
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$exclude[1][] = 'lang_options';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$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']);
|
|
|
ef5584 |
$cp->vars['lang_name'] = utf8_normalize_nfc(request_var('lang_name', $field_row['lang_name'], true));
|
|
|
ef5584 |
$cp->vars['lang_explain'] = utf8_normalize_nfc(request_var('lang_explain', $field_row['lang_explain'], true));
|
|
|
ef5584 |
$cp->vars['lang_default_value'] = utf8_normalize_nfc(request_var('lang_default_value', $field_row['lang_default_value'], true));
|
|
|
ef5584 |
|
|
|
ef5584 |
// Visibility Options...
|
|
|
ef5584 |
$visibility_ary = array(
|
|
|
ef5584 |
'field_required',
|
|
|
ef5584 |
'field_show_on_reg',
|
|
|
ef5584 |
'field_show_profile',
|
|
|
ef5584 |
'field_hide',
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($visibility_ary as $val)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars[$val] = ($submit || $save) ? request_var($val, 0) : $field_row[$val];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$cp->vars['field_no_view'] = request_var('field_no_view', (int) $field_row['field_no_view']);
|
|
|
ef5584 |
|
|
|
ef5584 |
// A boolean field expects an array as the lang options
|
|
|
ef5584 |
if ($field_type == FIELD_BOOL)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$options = utf8_normalize_nfc(request_var('lang_options', array(''), true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$options = utf8_normalize_nfc(request_var('lang_options', '', true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// If the user has submitted a form with options (i.e. dropdown field)
|
|
|
ef5584 |
if ($options)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$exploded_options = (is_array($options)) ? $options : explode("\n", $options);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($exploded_options) == sizeof($lang_options) || $action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// The number of options in the field is equal to the number of options already in the database
|
|
|
ef5584 |
// Or we are creating a new dropdown list.
|
|
|
ef5584 |
$cp->vars['lang_options'] = $exploded_options;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($action == 'edit')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Changing the number of options? (We remove and re-create the option fields)
|
|
|
ef5584 |
$cp->vars['lang_options'] = $exploded_options;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['lang_options'] = $lang_options;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// step 2
|
|
|
ef5584 |
foreach ($exclude[2] as $key)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$var = utf8_normalize_nfc(request_var($key, $field_row[$key], true));
|
|
|
ef5584 |
|
|
|
ef5584 |
// Manipulate the intended variables a little bit if needed
|
|
|
ef5584 |
if ($field_type == FIELD_DROPDOWN && $key == 'field_maxlen')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Get the number of options if this key is 'field_maxlen'
|
|
|
ef5584 |
$var = sizeof(explode("\n", utf8_normalize_nfc(request_var('lang_options', '', true))));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($field_type == FIELD_TEXT && $key == 'field_length')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (isset($_REQUEST['rows']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['rows'] = request_var('rows', 0);
|
|
|
ef5584 |
$cp->vars['columns'] = request_var('columns', 0);
|
|
|
ef5584 |
$var = $cp->vars['rows'] . '|' . $cp->vars['columns'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$row_col = explode('|', $var);
|
|
|
ef5584 |
$cp->vars['rows'] = $row_col[0];
|
|
|
ef5584 |
$cp->vars['columns'] = $row_col[1];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($field_type == FIELD_DATE && $key == 'field_default_value')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$always_now = request_var('always_now', -1);
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($always_now == 1 || ($always_now === -1 && $var == 'now'))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$now = getdate();
|
|
|
ef5584 |
|
|
|
ef5584 |
$cp->vars['field_default_value_day'] = $now['mday'];
|
|
|
ef5584 |
$cp->vars['field_default_value_month'] = $now['mon'];
|
|
|
ef5584 |
$cp->vars['field_default_value_year'] = $now['year'];
|
|
|
ef5584 |
$var = $_POST['field_default_value'] = 'now';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (isset($_REQUEST['field_default_value_day']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
|
|
|
ef5584 |
$cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
|
|
|
ef5584 |
$cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
|
|
|
ef5584 |
$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']);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
list($cp->vars['field_default_value_day'], $cp->vars['field_default_value_month'], $cp->vars['field_default_value_year']) = explode('-', $var);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
/* else if ($field_type == FIELD_BOOL && $key == 'field_default_value')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Get the number of options if this key is 'field_maxlen'
|
|
|
ef5584 |
$var = request_var('field_default_value', 0);
|
|
|
ef5584 |
}*/
|
|
|
ef5584 |
|
|
|
ef5584 |
$cp->vars[$key] = $var;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// step 3 - all arrays
|
|
|
ef5584 |
if ($action == 'edit')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Get language entries
|
|
|
ef5584 |
$sql = 'SELECT *
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_LANG_TABLE . '
|
|
|
ef5584 |
WHERE lang_id <> ' . $this->edit_lang_id . "
|
|
|
ef5584 |
AND field_id = $field_id
|
|
|
ef5584 |
ORDER BY option_id ASC";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$l_lang_options = array();
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value
|
|
|
ef5584 |
FROM ' . PROFILE_LANG_TABLE . '
|
|
|
ef5584 |
WHERE lang_id <> ' . $this->edit_lang_id . "
|
|
|
ef5584 |
AND field_id = $field_id
|
|
|
ef5584 |
ORDER BY lang_id ASC";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$l_lang_name = $l_lang_explain = $l_lang_default_value = array();
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$l_lang_name[$row['lang_id']] = $row['lang_name'];
|
|
|
ef5584 |
$l_lang_explain[$row['lang_id']] = $row['lang_explain'];
|
|
|
ef5584 |
$l_lang_default_value[$row['lang_id']] = $row['lang_default_value'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($exclude[3] as $key)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => ''), true));
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$cp->vars[$key] && $action == 'edit')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars[$key] = $$key;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($key == 'l_lang_options' && $field_type == FIELD_BOOL)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => array('')), true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($key == 'l_lang_options' && is_array($cp->vars[$key]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($cp->vars[$key] as $lang_id => $options)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars[$key][$lang_id] = explode("\n", $options);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Check for general issues in every step
|
|
|
ef5584 |
if ($submit) // && $step == 1
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Check values for step 1
|
|
|
ef5584 |
if ($cp->vars['field_ident'] == '')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['EMPTY_FIELD_IDENT'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!preg_match('/^[a-z_]+$/', $cp->vars['field_ident']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['INVALID_CHARS_FIELD_IDENT'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (strlen($cp->vars['field_ident']) > 17)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['INVALID_FIELD_IDENT_LEN'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($cp->vars['lang_name'] == '')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['EMPTY_USER_FIELD_NAME'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($field_type == FIELD_DROPDOWN && !sizeof($cp->vars['lang_options']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['NO_FIELD_ENTRIES'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($field_type == FIELD_BOOL && (empty($cp->vars['lang_options'][0]) || empty($cp->vars['lang_options'][1])))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['NO_FIELD_ENTRIES'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Check for already existing field ident
|
|
|
ef5584 |
if ($action != 'edit')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'SELECT field_ident
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE . "
|
|
|
ef5584 |
WHERE field_ident = '" . $db->sql_escape($cp->vars['field_ident']) . "'";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$row = $db->sql_fetchrow($result);
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($row)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$error[] = $user->lang['FIELD_IDENT_ALREADY_EXIST'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($error))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$step--;
|
|
|
ef5584 |
$submit = false;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Build up the specific hidden fields
|
|
|
ef5584 |
foreach ($exclude as $num => $key_ary)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($num == $step)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
continue;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$_new_key_ary = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($key_ary as $key)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($field_type == FIELD_TEXT && $key == 'field_length' && isset($_REQUEST['rows']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['rows'] = request_var('rows', 0);
|
|
|
ef5584 |
$cp->vars['columns'] = request_var('columns', 0);
|
|
|
ef5584 |
$_new_key_ary[$key] = $cp->vars['rows'] . '|' . $cp->vars['columns'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($field_type == FIELD_DATE && $key == 'field_default_value')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$always_now = request_var('always_now', 0);
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($always_now)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$_new_key_ary[$key] = 'now';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if (isset($_REQUEST['field_default_value_day']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['field_default_value_day'] = request_var('field_default_value_day', 0);
|
|
|
ef5584 |
$cp->vars['field_default_value_month'] = request_var('field_default_value_month', 0);
|
|
|
ef5584 |
$cp->vars['field_default_value_year'] = request_var('field_default_value_year', 0);
|
|
|
ef5584 |
$_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']);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($field_type == FIELD_BOOL && $key == 'l_lang_options' && isset($_REQUEST['l_lang_options']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$_new_key_ary[$key] = utf8_normalize_nfc(request_var($key, array(array('')), true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (!isset($_REQUEST[$key]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$var = false;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($key == 'field_ident' && isset($cp->vars[$key]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$_new_key_ary[$key]= $cp->vars[$key];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$_new_key_ary[$key] = (is_array($_REQUEST[$key])) ? utf8_normalize_nfc(request_var($key, array(''), true)) : utf8_normalize_nfc(request_var($key, '', true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$s_hidden_fields .= build_hidden_fields($_new_key_ary);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!sizeof($error))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->save_profile_field($cp, $field_type, $action);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else if ($action == 'edit' && $save)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->save_profile_field($cp, $field_type, $action);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'S_EDIT' => true,
|
|
|
ef5584 |
'S_EDIT_MODE' => ($action == 'edit') ? true : false,
|
|
|
ef5584 |
'ERROR_MSG' => (sizeof($error)) ? implode(' ', $error) : '',
|
|
|
ef5584 |
|
|
|
ef5584 |
'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)],
|
|
|
ef5584 |
'L_EXPLAIN' => $user->lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($action)],
|
|
|
ef5584 |
|
|
|
ef5584 |
'U_ACTION' => $this->u_action . "&action=$action&step=$step",
|
|
|
ef5584 |
'U_BACK' => $this->u_action)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Now go through the steps
|
|
|
ef5584 |
switch ($step)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Create basic options - only small differences between field types
|
|
|
ef5584 |
case 1:
|
|
|
ef5584 |
|
|
|
ef5584 |
// Build common create options
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'S_STEP_ONE' => true,
|
|
|
ef5584 |
'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
|
|
|
ef5584 |
'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
|
|
|
ef5584 |
'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
|
|
|
ef5584 |
'S_SHOW_PROFILE' => ($cp->vars['field_show_profile']) ? true : false,
|
|
|
ef5584 |
'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
|
|
|
ef5584 |
|
|
|
ef5584 |
'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
|
|
|
ef5584 |
'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$field_type])],
|
|
|
ef5584 |
'FIELD_IDENT' => $cp->vars['field_ident'],
|
|
|
ef5584 |
'LANG_NAME' => $cp->vars['lang_name'],
|
|
|
ef5584 |
'LANG_EXPLAIN' => $cp->vars['lang_explain'])
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
// String and Text needs to set default values here...
|
|
|
ef5584 |
if ($field_type == FIELD_STRING || $field_type == FIELD_TEXT)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'S_TEXT' => ($field_type == FIELD_TEXT) ? true : false,
|
|
|
ef5584 |
'S_STRING' => ($field_type == FIELD_STRING) ? true : false,
|
|
|
ef5584 |
|
|
|
ef5584 |
'L_DEFAULT_VALUE_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_DEFAULT_VALUE_EXPLAIN'],
|
|
|
ef5584 |
'LANG_DEFAULT_VALUE' => $cp->vars['lang_default_value'])
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($field_type == FIELD_BOOL || $field_type == FIELD_DROPDOWN)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// Initialize these array elements if we are creating a new field
|
|
|
ef5584 |
if (!sizeof($cp->vars['lang_options']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($field_type == FIELD_BOOL)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// No options have been defined for a boolean field.
|
|
|
ef5584 |
$cp->vars['lang_options'][0] = '';
|
|
|
ef5584 |
$cp->vars['lang_options'][1] = '';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
// No options have been defined for the dropdown menu
|
|
|
ef5584 |
$cp->vars['lang_options'] = array();
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'S_BOOL' => ($field_type == FIELD_BOOL) ? true : false,
|
|
|
ef5584 |
'S_DROPDOWN' => ($field_type == FIELD_DROPDOWN) ? true : false,
|
|
|
ef5584 |
|
|
|
ef5584 |
'L_LANG_OPTIONS_EXPLAIN' => $user->lang[strtoupper($cp->profile_types[$field_type]) . '_ENTRIES_EXPLAIN'],
|
|
|
ef5584 |
'LANG_OPTIONS' => ($field_type == FIELD_DROPDOWN) ? implode("\n", $cp->vars['lang_options']) : '',
|
|
|
ef5584 |
'FIRST_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][0] : '',
|
|
|
ef5584 |
'SECOND_LANG_OPTION' => ($field_type == FIELD_BOOL) ? $cp->vars['lang_options'][1] : '')
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 2:
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'S_STEP_TWO' => true,
|
|
|
ef5584 |
'L_NEXT_STEP' => (sizeof($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS'])
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Build options based on profile type
|
|
|
ef5584 |
$function = 'get_' . $cp->profile_types[$field_type] . '_options';
|
|
|
ef5584 |
$options = $cp->$function();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($options as $num => $option_ary)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$template->assign_block_vars('option', $option_ary);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
// Define remaining language variables
|
|
|
ef5584 |
case 3:
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_var('S_STEP_THREE', true);
|
|
|
ef5584 |
$options = $this->build_language_options($cp, $field_type, $action);
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($options as $lang_id => $lang_ary)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$template->assign_block_vars('options', array(
|
|
|
ef5584 |
'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso']))
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($lang_ary['fields'] as $field_ident => $field_ary)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$template->assign_block_vars('options.field', array(
|
|
|
ef5584 |
'L_TITLE' => $field_ary['TITLE'],
|
|
|
ef5584 |
'L_EXPLAIN' => (isset($field_ary['EXPLAIN'])) ? $field_ary['EXPLAIN'] : '',
|
|
|
ef5584 |
'FIELD' => $field_ary['FIELD'])
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'S_HIDDEN_FIELDS' => $s_hidden_fields)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
return;
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT *
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE . '
|
|
|
ef5584 |
ORDER BY field_order';
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$s_one_need_edit = false;
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$active_lang = (!$row['field_active']) ? 'ACTIVATE' : 'DEACTIVATE';
|
|
|
ef5584 |
$active_value = (!$row['field_active']) ? 'activate' : 'deactivate';
|
|
|
ef5584 |
$id = $row['field_id'];
|
|
|
ef5584 |
|
|
|
ef5584 |
$s_need_edit = (sizeof($this->lang_defs['diff'][$row['field_id']])) ? true : false;
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($s_need_edit)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$s_one_need_edit = true;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_block_vars('fields', array(
|
|
|
ef5584 |
'FIELD_IDENT' => $row['field_ident'],
|
|
|
ef5584 |
'FIELD_TYPE' => $user->lang['FIELD_' . strtoupper($cp->profile_types[$row['field_type']])],
|
|
|
ef5584 |
|
|
|
ef5584 |
'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],
|
|
|
ef5584 |
'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id",
|
|
|
ef5584 |
'U_EDIT' => $this->u_action . "&action=edit&field_id=$id",
|
|
|
ef5584 |
'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
|
|
|
ef5584 |
'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",
|
|
|
ef5584 |
'U_MOVE_UP' => $this->u_action . "&action=move_up&order={$row['field_order']}",
|
|
|
ef5584 |
'U_MOVE_DOWN' => $this->u_action . "&action=move_down&order={$row['field_order']}",
|
|
|
ef5584 |
|
|
|
ef5584 |
'S_NEED_EDIT' => $s_need_edit)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
// At least one option field needs editing?
|
|
|
ef5584 |
if ($s_one_need_edit)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$template->assign_var('S_NEED_EDIT', true);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$s_select_type = '';
|
|
|
ef5584 |
foreach ($cp->profile_types as $key => $value)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$s_select_type .= '<option value="' . $key . '">' . $user->lang['FIELD_' . strtoupper($value)] . '</option>';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$template->assign_vars(array(
|
|
|
ef5584 |
'U_ACTION' => $this->u_action,
|
|
|
ef5584 |
'S_TYPE_OPTIONS' => $s_select_type)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Build all Language specific options
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function build_language_options(&$cp, $field_type, $action = 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $user, $config, $db;
|
|
|
ef5584 |
|
|
|
ef5584 |
$default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'SELECT lang_id, lang_iso
|
|
|
ef5584 |
FROM ' . LANG_TABLE . '
|
|
|
ef5584 |
WHERE lang_id <> ' . (int) $default_lang_id . '
|
|
|
ef5584 |
ORDER BY lang_english_name';
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$languages = array();
|
|
|
ef5584 |
while ($row = $db->sql_fetchrow($result))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$languages[$row['lang_id']] = $row['lang_iso'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
$options = array();
|
|
|
ef5584 |
$options['lang_name'] = 'string';
|
|
|
ef5584 |
if ($cp->vars['lang_explain'])
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$options['lang_explain'] = 'text';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
$options['lang_options'] = 'two_options';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$options['lang_options'] = 'optionfield';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
if ($cp->vars['lang_default_value'])
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$options['lang_default_value'] = ($field_type == FIELD_STRING) ? 'string' : 'text';
|
|
|
ef5584 |
}
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$lang_options = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($options as $field => $field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id];
|
|
|
ef5584 |
$lang_options[1]['fields'][$field] = array(
|
|
|
ef5584 |
'TITLE' => $user->lang['CP_' . strtoupper($field)],
|
|
|
ef5584 |
'FIELD' => '' . ((is_array($cp->vars[$field])) ? implode(' ', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . ''
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($languages as $lang_id => $lang_iso)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_options[$lang_id]['lang_iso'] = $lang_iso;
|
|
|
ef5584 |
foreach ($options as $field => $field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$value = ($action == 'create') ? utf8_normalize_nfc(request_var('l_' . $field, array(0 => ''), true)) : $cp->vars['l_' . $field];
|
|
|
ef5584 |
if ($field == 'lang_options')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$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];
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case 'two_options':
|
|
|
ef5584 |
|
|
|
ef5584 |
$lang_options[$lang_id]['fields'][$field] = array(
|
|
|
ef5584 |
'TITLE' => $user->lang['CP_' . strtoupper($field)],
|
|
|
ef5584 |
'FIELD' => '
|
|
|
ef5584 |
<input class="medium" name="l_' . $field . '[' . $lang_id . '][]" value="' . ((isset($value[$lang_id][0])) ? $value[$lang_id][0] : $var[0]) . '" /> ' . $user->lang['FIRST_OPTION'] . '
|
|
|
ef5584 |
<input class="medium" name="l_' . $field . '[' . $lang_id . '][]" value="' . ((isset($value[$lang_id][1])) ? $value[$lang_id][1] : $var[1]) . '" /> ' . $user->lang['SECOND_OPTION'] . ''
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'optionfield':
|
|
|
ef5584 |
$value = ((isset($value[$lang_id])) ? ((is_array($value[$lang_id])) ? implode("\n", $value[$lang_id]) : $value[$lang_id]) : implode("\n", $var));
|
|
|
ef5584 |
$lang_options[$lang_id]['fields'][$field] = array(
|
|
|
ef5584 |
'TITLE' => $user->lang['CP_' . strtoupper($field)],
|
|
|
ef5584 |
'FIELD' => '<textarea name="l_' . $field . '[' . $lang_id . ']" rows="7" cols="80">' . $value . '</textarea>'
|
|
|
ef5584 |
);
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$var = ($action == 'create' || !is_array($cp->vars[$field])) ? $cp->vars[$field] : $cp->vars[$field][$lang_id];
|
|
|
ef5584 |
|
|
|
ef5584 |
$lang_options[$lang_id]['fields'][$field] = array(
|
|
|
ef5584 |
'TITLE' => $user->lang['CP_' . strtoupper($field)],
|
|
|
ef5584 |
'FIELD' => ($field_type == 'string') ? '<input class="medium" type="text" name="l_' . $field . '[' . $lang_id . ']" value="' . ((isset($value[$lang_id])) ? $value[$lang_id] : $var) . '" />' : '<textarea name="l_' . $field . '[' . $lang_id . ']" rows="3" cols="80">' . ((isset($value[$lang_id])) ? $value[$lang_id] : $var) . '</textarea>'
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
return $lang_options;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Save Profile Field
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function save_profile_field(&$cp, $field_type, $action = 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $db, $config, $user;
|
|
|
ef5584 |
|
|
|
ef5584 |
$field_id = request_var('field_id', 0);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Collect all information, if something is going wrong, abort the operation
|
|
|
ef5584 |
$profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
$default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'SELECT MAX(field_order) as max_field_order
|
|
|
ef5584 |
FROM ' . PROFILE_FIELDS_TABLE;
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$new_field_order = (int) $db->sql_fetchfield('max_field_order');
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
$field_ident = $cp->vars['field_ident'];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// Save the field
|
|
|
ef5584 |
$profile_fields = array(
|
|
|
ef5584 |
'field_length' => $cp->vars['field_length'],
|
|
|
ef5584 |
'field_minlen' => $cp->vars['field_minlen'],
|
|
|
ef5584 |
'field_maxlen' => $cp->vars['field_maxlen'],
|
|
|
ef5584 |
'field_novalue' => $cp->vars['field_novalue'],
|
|
|
ef5584 |
'field_default_value' => $cp->vars['field_default_value'],
|
|
|
ef5584 |
'field_validation' => $cp->vars['field_validation'],
|
|
|
ef5584 |
'field_required' => $cp->vars['field_required'],
|
|
|
ef5584 |
'field_show_on_reg' => $cp->vars['field_show_on_reg'],
|
|
|
ef5584 |
'field_hide' => $cp->vars['field_hide'],
|
|
|
ef5584 |
'field_show_profile' => $cp->vars['field_show_profile'],
|
|
|
ef5584 |
'field_no_view' => $cp->vars['field_no_view']
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$profile_fields += array(
|
|
|
ef5584 |
'field_type' => $field_type,
|
|
|
ef5584 |
'field_ident' => $field_ident,
|
|
|
ef5584 |
'field_name' => $field_ident,
|
|
|
ef5584 |
'field_order' => $new_field_order + 1,
|
|
|
ef5584 |
'field_active' => 1
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields);
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
|
|
|
ef5584 |
$field_id = $db->sql_nextid();
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
|
|
|
ef5584 |
SET ' . $db->sql_build_array('UPDATE', $profile_fields) . "
|
|
|
ef5584 |
WHERE field_id = $field_id";
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$field_ident = 'pf_' . $field_ident;
|
|
|
ef5584 |
$profile_sql[] = $this->add_field_ident($field_ident, $field_type);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql_ary = array(
|
|
|
ef5584 |
'lang_name' => $cp->vars['lang_name'],
|
|
|
ef5584 |
'lang_explain' => $cp->vars['lang_explain'],
|
|
|
ef5584 |
'lang_default_value' => $cp->vars['lang_default_value']
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql_ary['field_id'] = $field_id;
|
|
|
ef5584 |
$sql_ary['lang_id'] = $default_lang_id;
|
|
|
ef5584 |
|
|
|
ef5584 |
$profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (is_array($cp->vars['l_lang_name']) && sizeof($cp->vars['l_lang_name']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($cp->vars['l_lang_name'] as $lang_id => $data)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (($cp->vars['lang_name'] != '' && $cp->vars['l_lang_name'][$lang_id] == '')
|
|
|
ef5584 |
|| ($cp->vars['lang_explain'] != '' && $cp->vars['l_lang_explain'][$lang_id] == '')
|
|
|
ef5584 |
|| ($cp->vars['lang_default_value'] != '' && $cp->vars['l_lang_default_value'][$lang_id] == ''))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$empty_lang[$lang_id] = true;
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!isset($empty_lang[$lang_id]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$profile_lang[] = array(
|
|
|
ef5584 |
'field_id' => $field_id,
|
|
|
ef5584 |
'lang_id' => $lang_id,
|
|
|
ef5584 |
'lang_name' => $cp->vars['l_lang_name'][$lang_id],
|
|
|
ef5584 |
'lang_explain' => (isset($cp->vars['l_lang_explain'][$lang_id])) ? $cp->vars['l_lang_explain'][$lang_id] : '',
|
|
|
ef5584 |
'lang_default_value' => (isset($cp->vars['l_lang_default_value'][$lang_id])) ? $cp->vars['l_lang_default_value'][$lang_id] : ''
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($empty_lang as $lang_id => $NULL)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id
|
|
|
ef5584 |
AND lang_id = " . (int) $lang_id;
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// These are always arrays because the key is the language id...
|
|
|
ef5584 |
$cp->vars['l_lang_name'] = utf8_normalize_nfc(request_var('l_lang_name', array(0 => ''), true));
|
|
|
ef5584 |
$cp->vars['l_lang_explain'] = utf8_normalize_nfc(request_var('l_lang_explain', array(0 => ''), true));
|
|
|
ef5584 |
$cp->vars['l_lang_default_value'] = utf8_normalize_nfc(request_var('l_lang_default_value', array(0 => ''), true));
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($field_type != FIELD_BOOL)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => ''), true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* @todo check if this line is correct...
|
|
|
ef5584 |
$cp->vars['l_lang_default_value'] = request_var('l_lang_default_value', array(0 => array('')), true);
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
$cp->vars['l_lang_options'] = utf8_normalize_nfc(request_var('l_lang_options', array(0 => array('')), true));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($cp->vars['lang_options'])
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (!is_array($cp->vars['lang_options']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$cp->vars['lang_options'] = explode("\n", $cp->vars['lang_options']);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action != 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id
|
|
|
ef5584 |
AND lang_id = " . (int) $default_lang_id;
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($cp->vars['lang_options'] as $option_id => $value)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql_ary = array(
|
|
|
ef5584 |
'field_type' => (int) $field_type,
|
|
|
ef5584 |
'lang_value' => $value
|
|
|
ef5584 |
);
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql_ary['field_id'] = $field_id;
|
|
|
ef5584 |
$sql_ary['lang_id'] = $default_lang_id;
|
|
|
ef5584 |
$sql_ary['option_id'] = (int) $option_id;
|
|
|
ef5584 |
|
|
|
ef5584 |
$profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array(
|
|
|
ef5584 |
'field_id' => $field_id,
|
|
|
ef5584 |
'lang_id' => (int) $default_lang_id,
|
|
|
ef5584 |
'option_id' => (int) $option_id)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (is_array($cp->vars['l_lang_options']) && sizeof($cp->vars['l_lang_options']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$empty_lang = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (!is_array($lang_ary))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_ary = explode("\n", $lang_ary);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($lang_ary) != sizeof($cp->vars['lang_options']))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$empty_lang[$lang_id] = true;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!isset($empty_lang[$lang_id]))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($action != 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id
|
|
|
ef5584 |
AND lang_id = " . (int) $lang_id;
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($lang_ary as $option_id => $value)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$profile_lang_fields[] = array(
|
|
|
ef5584 |
'field_id' => (int) $field_id,
|
|
|
ef5584 |
'lang_id' => (int) $lang_id,
|
|
|
ef5584 |
'option_id' => (int) $option_id,
|
|
|
ef5584 |
'field_type' => (int) $field_type,
|
|
|
ef5584 |
'lang_value' => $value
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($empty_lang as $lang_id => $NULL)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
|
|
|
ef5584 |
WHERE field_id = $field_id
|
|
|
ef5584 |
AND lang_id = " . (int) $lang_id;
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($profile_lang as $sql)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_id = $sql['lang_id'];
|
|
|
ef5584 |
unset($sql['lang_id'], $sql['field_id']);
|
|
|
ef5584 |
|
|
|
ef5584 |
$this->update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($profile_lang_fields))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($profile_lang_fields as $sql)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$lang_id = $sql['lang_id'];
|
|
|
ef5584 |
$option_id = $sql['option_id'];
|
|
|
ef5584 |
unset($sql['lang_id'], $sql['field_id'], $sql['option_id']);
|
|
|
ef5584 |
|
|
|
ef5584 |
$this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array(
|
|
|
ef5584 |
'lang_id' => $lang_id,
|
|
|
ef5584 |
'field_id' => $field_id,
|
|
|
ef5584 |
'option_id' => $option_id)
|
|
|
ef5584 |
);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
|
|
|
ef5584 |
$db->sql_transaction('begin');
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'create')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
foreach ($profile_sql as $sql)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$db->sql_transaction('commit');
|
|
|
ef5584 |
|
|
|
ef5584 |
if ($action == 'edit')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
add_log('admin', 'LOG_PROFILE_FIELD_EDIT', $cp->vars['field_ident'] . ':' . $cp->vars['lang_name']);
|
|
|
ef5584 |
trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
add_log('admin', 'LOG_PROFILE_FIELD_CREATE', substr($field_ident, 3) . ':' . $cp->vars['lang_name']);
|
|
|
ef5584 |
trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Update, then insert if not successfull
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function update_insert($table, $sql_ary, $where_fields)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $db;
|
|
|
ef5584 |
|
|
|
ef5584 |
$where_sql = array();
|
|
|
ef5584 |
$check_key = '';
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($where_fields as $key => $value)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$check_key = (!$check_key) ? $key : $check_key;
|
|
|
ef5584 |
$where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : (int) $value);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!sizeof($where_sql))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
return;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$sql = "SELECT $check_key
|
|
|
ef5584 |
FROM $table
|
|
|
ef5584 |
WHERE " . implode(' AND ', $where_sql);
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$row = $db->sql_fetchrow($result);
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (!$row)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql_ary = array_merge($where_fields, $sql_ary);
|
|
|
ef5584 |
|
|
|
ef5584 |
if (sizeof($sql_ary))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary));
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
if (sizeof($sql_ary))
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . '
|
|
|
ef5584 |
WHERE ' . implode(' AND ', $where_sql);
|
|
|
ef5584 |
$db->sql_query($sql);
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
/**
|
|
|
ef5584 |
* Return sql statement for adding a new field ident (profile field) to the profile fields data table
|
|
|
ef5584 |
*/
|
|
|
ef5584 |
function add_field_ident($field_ident, $field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
global $db;
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($db->sql_layer)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case 'mysql':
|
|
|
ef5584 |
case 'mysql4':
|
|
|
ef5584 |
case 'mysqli':
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
|
|
|
ef5584 |
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD `$field_ident` ";
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
$sql .= ' VARCHAR(255) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DATE:
|
|
|
ef5584 |
$sql .= 'VARCHAR(10) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
$sql .= "TEXT";
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
$sql .= 'TINYINT(2) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$sql .= 'MEDIUMINT(8) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_INT:
|
|
|
ef5584 |
$sql .= 'BIGINT(20) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'sqlite':
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
$type = ' VARCHAR(255) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DATE:
|
|
|
ef5584 |
$type = 'VARCHAR(10) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
$type = "TEXT(65535)";
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_bitfield INT(11) UNSIGNED";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
$type = 'TINYINT(2) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$type = 'MEDIUMINT(8) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_INT:
|
|
|
ef5584 |
$type = 'BIGINT(20) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
|
|
|
ef5584 |
if (version_compare(sqlite_libversion(), '3.0') == -1)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = "SELECT sql
|
|
|
ef5584 |
FROM sqlite_master
|
|
|
ef5584 |
WHERE type = 'table'
|
|
|
ef5584 |
AND name = '" . PROFILE_FIELDS_DATA_TABLE . "'
|
|
|
ef5584 |
ORDER BY type DESC, name;";
|
|
|
ef5584 |
$result = $db->sql_query($sql);
|
|
|
ef5584 |
$row = $db->sql_fetchrow($result);
|
|
|
ef5584 |
$db->sql_freeresult($result);
|
|
|
ef5584 |
|
|
|
ef5584 |
// Create a temp table and populate it, destroy the existing one
|
|
|
ef5584 |
$db->sql_query(preg_replace('#CREATE\s+TABLE\s+"?' . PROFILE_FIELDS_DATA_TABLE . '"?#i', 'CREATE TEMPORARY TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp', $row['sql']));
|
|
|
ef5584 |
$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . '_temp SELECT * FROM ' . PROFILE_FIELDS_DATA_TABLE);
|
|
|
ef5584 |
$db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE);
|
|
|
ef5584 |
|
|
|
ef5584 |
preg_match('#\((.*)\)#s', $row['sql'], $matches);
|
|
|
ef5584 |
|
|
|
ef5584 |
$new_table_cols = trim($matches[1]);
|
|
|
ef5584 |
$old_table_cols = explode(',', $new_table_cols);
|
|
|
ef5584 |
$column_list = array();
|
|
|
ef5584 |
|
|
|
ef5584 |
foreach ($old_table_cols as $declaration)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$entities = preg_split('#\s+#', trim($declaration));
|
|
|
ef5584 |
if ($entities[0] == 'PRIMARY')
|
|
|
ef5584 |
{
|
|
|
ef5584 |
continue;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
$column_list[] = $entities[0];
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
$columns = implode(',', $column_list);
|
|
|
ef5584 |
|
|
|
ef5584 |
$new_table_cols = $field_ident . ' ' . $type . ',' . $new_table_cols;
|
|
|
ef5584 |
|
|
|
ef5584 |
// create a new table and fill it up. destroy the temp one
|
|
|
ef5584 |
$db->sql_query('CREATE TABLE ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $new_table_cols . ');');
|
|
|
ef5584 |
$db->sql_query('INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' (' . $columns . ') SELECT ' . $columns . ' FROM ' . PROFILE_FIELDS_DATA_TABLE . '_temp;');
|
|
|
ef5584 |
$db->sql_query('DROP TABLE ' . PROFILE_FIELDS_DATA_TABLE . '_temp');
|
|
|
ef5584 |
}
|
|
|
ef5584 |
else
|
|
|
ef5584 |
{
|
|
|
ef5584 |
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident [$type]";
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'mssql':
|
|
|
ef5584 |
case 'mssql_odbc':
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
|
|
|
ef5584 |
$sql = 'ALTER TABLE [' . PROFILE_FIELDS_DATA_TABLE . "] ADD [$field_ident] ";
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
$sql .= ' [VARCHAR] (255) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DATE:
|
|
|
ef5584 |
$sql .= '[VARCHAR] (10) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
$sql .= "[TEXT]";
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_uid [VARCHAR] (5) NOT NULL,
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_bitfield [INT] UNSIGNED";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$sql .= '[INT] ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_INT:
|
|
|
ef5584 |
$sql .= '[FLOAT] ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'postgres':
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
|
|
|
ef5584 |
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD COLUMN \"$field_ident\" ";
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
$sql .= ' VARCHAR(255) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DATE:
|
|
|
ef5584 |
$sql .= 'VARCHAR(10) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
$sql .= "TEXT";
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_bitfield INT4 UNSIGNED";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
$sql .= 'INT2 ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$sql .= 'INT4 ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_INT:
|
|
|
ef5584 |
$sql .= 'INT8 ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'firebird':
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
|
|
|
ef5584 |
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD \"$field_ident\" ";
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
$sql .= ' VARCHAR(255) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DATE:
|
|
|
ef5584 |
$sql .= 'VARCHAR(10) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
$sql .= "BLOB SUB_TYPE TEXT";
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_uid VARCHAR(5) NOT NULL,
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_bitfield INTEGER UNSIGNED";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$sql .= 'INTEGER ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_INT:
|
|
|
ef5584 |
$sql .= 'DOUBLE PRECISION ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case 'oracle':
|
|
|
ef5584 |
|
|
|
ef5584 |
// We are defining the biggest common value, because of the possibility to edit the min/max values of each field.
|
|
|
ef5584 |
$sql = 'ALTER TABLE ' . PROFILE_FIELDS_DATA_TABLE . " ADD $field_ident ";
|
|
|
ef5584 |
|
|
|
ef5584 |
switch ($field_type)
|
|
|
ef5584 |
{
|
|
|
ef5584 |
case FIELD_STRING:
|
|
|
ef5584 |
$sql .= ' VARCHAR2(255) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DATE:
|
|
|
ef5584 |
$sql .= 'VARCHAR2(10) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_TEXT:
|
|
|
ef5584 |
$sql .= "CLOB";
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_uid VARCHAR2(5) NOT NULL,
|
|
|
ef5584 |
// ADD {$field_ident}_bbcode_bitfield NUMBER(11) UNSIGNED";
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_BOOL:
|
|
|
ef5584 |
$sql .= 'NUMBER(2) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_DROPDOWN:
|
|
|
ef5584 |
$sql .= 'NUMBER(8) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
|
|
|
ef5584 |
case FIELD_INT:
|
|
|
ef5584 |
$sql .= 'NUMBER(20) ';
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
break;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
return $sql;
|
|
|
ef5584 |
}
|
|
|
ef5584 |
}
|
|
|
ef5584 |
|
|
|
ef5584 |
?>
|