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