Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
acp_profile.php
0001 <?php
0002 /**
0003 *
0004 * This file is part of the phpBB Forum Software package.
0005 *
0006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
0007 * @license GNU General Public License, version 2 (GPL-2.0)
0008 *
0009 * For full copyright and license information, please see
0010 * the docs/CREDITS.txt file.
0011 *
0012 */
0013
0014 /**
0015 * @ignore
0016 */
0017 if (!defined('IN_PHPBB'))
0018 {
0019 exit;
0020 }
0021
0022 class acp_profile
0023 {
0024 var $u_action;
0025
0026 var $edit_lang_id;
0027 var $lang_defs;
0028
0029 /**
0030 * @var \phpbb\di\service_collection
0031 */
0032 protected $type_collection;
0033
0034 function main($id, $mode)
0035 {
0036 global $config, $db, $user, $template;
0037 global $phpbb_root_path, $phpEx;
0038 global $request, $phpbb_container, $phpbb_log, $phpbb_dispatcher;
0039
0040 if (!function_exists('generate_smilies'))
0041 {
0042 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
0043 }
0044
0045 if (!function_exists('user_get_id_name'))
0046 {
0047 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
0048 }
0049
0050 $user->add_lang(array('ucp', 'acp/profile'));
0051 $this->tpl_name = 'acp_profile';
0052 $this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS';
0053
0054 $field_id = $request->variable('field_id', 0);
0055 $action = (isset($_POST['create'])) ? 'create' : $request->variable('action', '');
0056
0057 $error = array();
0058
0059 $form_key = 'acp_profile';
0060 add_form_key($form_key);
0061
0062 if (!$field_id && in_array($action, array('delete','activate', 'deactivate', 'move_up', 'move_down', 'edit')))
0063 {
0064 trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
0065 }
0066
0067 /* @var $cp \phpbb\profilefields\manager */
0068 $cp = $phpbb_container->get('profilefields.manager');
0069 $this->type_collection = $phpbb_container->get('profilefields.type_collection');
0070
0071 // Build Language array
0072 // Based on this, we decide which elements need to be edited later and which language items are missing
0073 $this->lang_defs = array();
0074
0075 $sql = 'SELECT lang_id, lang_iso
0076 FROM ' . LANG_TABLE . '
0077 ORDER BY lang_english_name';
0078 $result = $db->sql_query($sql);
0079
0080 while ($row = $db->sql_fetchrow($result))
0081 {
0082 // Make some arrays with all available languages
0083 $this->lang_defs['id'][$row['lang_id']] = $row['lang_iso'];
0084 $this->lang_defs['iso'][$row['lang_iso']] = $row['lang_id'];
0085 }
0086 $db->sql_freeresult($result);
0087
0088 $sql = 'SELECT field_id, lang_id
0089 FROM ' . PROFILE_LANG_TABLE . '
0090 ORDER BY lang_id';
0091 $result = $db->sql_query($sql);
0092
0093 while ($row = $db->sql_fetchrow($result))
0094 {
0095 // Which languages are available for each item
0096 $this->lang_defs['entry'][$row['field_id']][] = $row['lang_id'];
0097 }
0098 $db->sql_freeresult($result);
0099
0100 // Have some fields been defined?
0101 if (isset($this->lang_defs['entry']))
0102 {
0103 foreach ($this->lang_defs['entry'] as $field_ident => $field_ary)
0104 {
0105 // Fill an array with the languages that are missing for each field
0106 $this->lang_defs['diff'][$field_ident] = array_diff(array_values($this->lang_defs['iso']), $field_ary);
0107 }
0108 }
0109
0110 switch ($action)
0111 {
0112 case 'delete':
0113
0114 if (confirm_box(true))
0115 {
0116 $sql = 'SELECT field_ident
0117 FROM ' . PROFILE_FIELDS_TABLE . "
0118 WHERE field_id = $field_id";
0119 $result = $db->sql_query($sql);
0120 $field_ident = (string) $db->sql_fetchfield('field_ident');
0121 $db->sql_freeresult($result);
0122
0123 $db->sql_transaction('begin');
0124
0125 $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_TABLE . " WHERE field_id = $field_id");
0126 $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id");
0127 $db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id");
0128
0129 /* @var $db_tools \phpbb\db\tools\tools_interface */
0130 $db_tools = $phpbb_container->get('dbal.tools');
0131 $db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_' . $field_ident);
0132
0133 $order = 0;
0134
0135 $sql = 'SELECT *
0136 FROM ' . PROFILE_FIELDS_TABLE . '
0137 ORDER BY field_order';
0138 $result = $db->sql_query($sql);
0139
0140 while ($row = $db->sql_fetchrow($result))
0141 {
0142 $order++;
0143 if ($row['field_order'] != $order)
0144 {
0145 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
0146 SET field_order = $order
0147 WHERE field_id = {$row['field_id']}";
0148 $db->sql_query($sql);
0149 }
0150 }
0151 $db->sql_freeresult($result);
0152
0153 $db->sql_transaction('commit');
0154
0155 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_REMOVED', false, array($field_ident));
0156 trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action));
0157 }
0158 else
0159 {
0160 confirm_box(false, 'DELETE_PROFILE_FIELD', build_hidden_fields(array(
0161 'i' => $id,
0162 'mode' => $mode,
0163 'action' => $action,
0164 'field_id' => $field_id,
0165 )));
0166 }
0167
0168 break;
0169
0170 case 'activate':
0171
0172 if (!check_link_hash($request->variable('hash', ''), 'acp_profile'))
0173 {
0174 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
0175 }
0176
0177 $sql = 'SELECT lang_id
0178 FROM ' . LANG_TABLE . "
0179 WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'";
0180 $result = $db->sql_query($sql);
0181 $default_lang_id = (int) $db->sql_fetchfield('lang_id');
0182 $db->sql_freeresult($result);
0183
0184 if (!in_array($default_lang_id, $this->lang_defs['entry'][$field_id]))
0185 {
0186 trigger_error($user->lang['DEFAULT_LANGUAGE_NOT_FILLED'] . adm_back_link($this->u_action), E_USER_WARNING);
0187 }
0188
0189 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
0190 SET field_active = 1
0191 WHERE field_id = $field_id";
0192 $db->sql_query($sql);
0193
0194 $sql = 'SELECT field_ident
0195 FROM ' . PROFILE_FIELDS_TABLE . "
0196 WHERE field_id = $field_id";
0197 $result = $db->sql_query($sql);
0198 $field_ident = (string) $db->sql_fetchfield('field_ident');
0199 $db->sql_freeresult($result);
0200
0201 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_ACTIVATE', false, array($field_ident));
0202
0203 if ($request->is_ajax())
0204 {
0205 $json_response = new \phpbb\json_response();
0206 $json_response->send(array(
0207 'text' => $user->lang('DEACTIVATE'),
0208 ));
0209 }
0210
0211 trigger_error($user->lang['PROFILE_FIELD_ACTIVATED'] . adm_back_link($this->u_action));
0212
0213 break;
0214
0215 case 'deactivate':
0216
0217 if (!check_link_hash($request->variable('hash', ''), 'acp_profile'))
0218 {
0219 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
0220 }
0221
0222 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
0223 SET field_active = 0
0224 WHERE field_id = $field_id";
0225 $db->sql_query($sql);
0226
0227 $sql = 'SELECT field_ident
0228 FROM ' . PROFILE_FIELDS_TABLE . "
0229 WHERE field_id = $field_id";
0230 $result = $db->sql_query($sql);
0231 $field_ident = (string) $db->sql_fetchfield('field_ident');
0232 $db->sql_freeresult($result);
0233
0234 if ($request->is_ajax())
0235 {
0236 $json_response = new \phpbb\json_response();
0237 $json_response->send(array(
0238 'text' => $user->lang('ACTIVATE'),
0239 ));
0240 }
0241
0242 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_DEACTIVATE', false, array($field_ident));
0243
0244 trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action));
0245
0246 break;
0247
0248 case 'move_up':
0249 case 'move_down':
0250
0251 if (!check_link_hash($request->variable('hash', ''), 'acp_profile'))
0252 {
0253 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
0254 }
0255
0256 $sql = 'SELECT field_order
0257 FROM ' . PROFILE_FIELDS_TABLE . "
0258 WHERE field_id = $field_id";
0259 $result = $db->sql_query($sql);
0260 $field_order = $db->sql_fetchfield('field_order');
0261 $db->sql_freeresult($result);
0262
0263 if ($field_order === false || ($field_order == 0 && $action == 'move_up'))
0264 {
0265 break;
0266 }
0267 $field_order = (int) $field_order;
0268 $order_total = $field_order * 2 + (($action == 'move_up') ? -1 : 1);
0269
0270 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . "
0271 SET field_order = $order_total - field_order
0272 WHERE field_order IN ($field_order, " . (($action == 'move_up') ? $field_order - 1 : $field_order + 1) . ')';
0273 $db->sql_query($sql);
0274
0275 if ($request->is_ajax())
0276 {
0277 $json_response = new \phpbb\json_response;
0278 $json_response->send(array(
0279 'success' => (bool) $db->sql_affectedrows(),
0280 ));
0281 }
0282
0283 break;
0284
0285 case 'create':
0286 case 'edit':
0287
0288 $step = $request->variable('step', 1);
0289
0290 $submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false;
0291 $save = (isset($_REQUEST['save'])) ? true : false;
0292
0293 // The language id of default language
0294 $this->edit_lang_id = $this->lang_defs['iso'][$config['default_lang']];
0295
0296 // We are editing... we need to grab basic things
0297 if ($action == 'edit')
0298 {
0299 $sql = 'SELECT l.*, f.*
0300 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
0301 WHERE l.lang_id = ' . $this->edit_lang_id . "
0302 AND f.field_id = $field_id
0303 AND l.field_id = f.field_id";
0304 $result = $db->sql_query($sql);
0305 $field_row = $db->sql_fetchrow($result);
0306 $db->sql_freeresult($result);
0307
0308 if (!$field_row)
0309 {
0310 // Some admin changed the default language?
0311 $sql = 'SELECT l.*, f.*
0312 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f
0313 WHERE l.lang_id <> ' . $this->edit_lang_id . "
0314 AND f.field_id = $field_id
0315 AND l.field_id = f.field_id";
0316 $result = $db->sql_query($sql);
0317 $field_row = $db->sql_fetchrow($result);
0318 $db->sql_freeresult($result);
0319
0320 if (!$field_row)
0321 {
0322 trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
0323 }
0324
0325 $this->edit_lang_id = $field_row['lang_id'];
0326 }
0327 $field_type = $field_row['field_type'];
0328 $profile_field = $this->type_collection[$field_type];
0329
0330 // Get language entries
0331 $sql = 'SELECT *
0332 FROM ' . PROFILE_FIELDS_LANG_TABLE . '
0333 WHERE lang_id = ' . $this->edit_lang_id . "
0334 AND field_id = $field_id
0335 ORDER BY option_id ASC";
0336 $result = $db->sql_query($sql);
0337
0338 $lang_options = array();
0339 while ($row = $db->sql_fetchrow($result))
0340 {
0341 $lang_options[$row['option_id']] = $row['lang_value'];
0342 }
0343 $db->sql_freeresult($result);
0344
0345 $s_hidden_fields = '<input type="hidden" name="field_id" value="' . $field_id . '" />';
0346 }
0347 else
0348 {
0349 // We are adding a new field, define basic params
0350 $lang_options = $field_row = array();
0351
0352 $field_type = $request->variable('field_type', '');
0353
0354 if (!isset($this->type_collection[$field_type]))
0355 {
0356 trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
0357 }
0358
0359 $profile_field = $this->type_collection[$field_type];
0360 $field_row = array_merge($profile_field->get_default_option_values(), array(
0361 'field_ident' => str_replace(' ', '_', utf8_clean_string($request->variable('field_ident', '', true))),
0362 'field_required' => 0,
0363 'field_show_novalue'=> 0,
0364 'field_hide' => 0,
0365 'field_show_profile'=> 0,
0366 'field_no_view' => 0,
0367 'field_show_on_reg' => 0,
0368 'field_show_on_pm' => 0,
0369 'field_show_on_vt' => 0,
0370 'field_show_on_ml' => 0,
0371 'field_is_contact' => 0,
0372 'field_contact_desc'=> '',
0373 'field_contact_url' => '',
0374 'lang_name' => $request->variable('field_ident', '', true),
0375 'lang_explain' => '',
0376 'lang_default_value'=> '')
0377 );
0378
0379 $s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />';
0380 }
0381
0382 // $exclude contains the data we gather in each step
0383 $exclude = array(
0384 1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_pm', 'field_show_on_vt', 'field_show_on_ml', 'field_required', 'field_show_novalue', 'field_hide', 'field_show_profile', 'field_no_view', 'field_is_contact', 'field_contact_desc', 'field_contact_url'),
0385 2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
0386 3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
0387 );
0388
0389 // Visibility Options...
0390 $visibility_ary = array(
0391 'field_required',
0392 'field_show_novalue',
0393 'field_show_on_reg',
0394 'field_show_on_pm',
0395 'field_show_on_vt',
0396 'field_show_on_ml',
0397 'field_show_profile',
0398 'field_hide',
0399 'field_is_contact',
0400 );
0401
0402 /**
0403 * Event to add initialization for new profile field table fields
0404 *
0405 * @event core.acp_profile_create_edit_init
0406 * @var string action create|edit
0407 * @var int step Configuration step (1|2|3)
0408 * @var bool submit Form has been submitted
0409 * @var bool save Configuration should be saved
0410 * @var string field_type Type of the field we are dealing with
0411 * @var array field_row Array of data about the field
0412 * @var array exclude Array of excluded fields by step
0413 * @var array visibility_ary Array of fields that are visibility related
0414 * @since 3.1.6-RC1
0415 */
0416 $vars = array(
0417 'action',
0418 'step',
0419 'submit',
0420 'save',
0421 'field_type',
0422 'field_row',
0423 'exclude',
0424 'visibility_ary',
0425 );
0426 extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_init', compact($vars)));
0427
0428 $options = $profile_field->prepare_options_form($exclude, $visibility_ary);
0429
0430 $cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string($request->variable('field_ident', $field_row['field_ident'], true)) : $request->variable('field_ident', $field_row['field_ident']);
0431 $cp->vars['lang_name'] = $request->variable('lang_name', $field_row['lang_name'], true);
0432 $cp->vars['lang_explain'] = $request->variable('lang_explain', $field_row['lang_explain'], true);
0433 $cp->vars['lang_default_value'] = $request->variable('lang_default_value', $field_row['lang_default_value'], true);
0434 $cp->vars['field_contact_desc'] = $request->variable('field_contact_desc', $field_row['field_contact_desc'], true);
0435 $cp->vars['field_contact_url'] = $request->variable('field_contact_url', $field_row['field_contact_url'], true);
0436
0437 foreach ($visibility_ary as $val)
0438 {
0439 $cp->vars[$val] = ($submit || $save) ? $request->variable($val, 0) : $field_row[$val];
0440 }
0441
0442 $cp->vars['field_no_view'] = $request->variable('field_no_view', (int) $field_row['field_no_view']);
0443
0444 // If the user has submitted a form with options (i.e. dropdown field)
0445 if ($options)
0446 {
0447 $exploded_options = (is_array($options)) ? $options : explode("\n", $options);
0448
0449 if (count($exploded_options) == count($lang_options) || $action == 'create')
0450 {
0451 // The number of options in the field is equal to the number of options already in the database
0452 // Or we are creating a new dropdown list.
0453 $cp->vars['lang_options'] = $exploded_options;
0454 }
0455 else if ($action == 'edit')
0456 {
0457 // Changing the number of options? (We remove and re-create the option fields)
0458 $cp->vars['lang_options'] = $exploded_options;
0459 }
0460 }
0461 else
0462 {
0463 $cp->vars['lang_options'] = $lang_options;
0464 }
0465
0466 // step 2
0467 foreach ($exclude[2] as $key)
0468 {
0469 $var = $request->variable($key, $field_row[$key], true);
0470
0471 $field_data = $cp->vars;
0472 $var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 2);
0473 $cp->vars = $field_data;
0474
0475 $cp->vars[$key] = $var;
0476 }
0477
0478 // step 3 - all arrays
0479 if ($action == 'edit')
0480 {
0481 // Get language entries
0482 $sql = 'SELECT *
0483 FROM ' . PROFILE_FIELDS_LANG_TABLE . '
0484 WHERE lang_id <> ' . $this->edit_lang_id . "
0485 AND field_id = $field_id
0486 ORDER BY option_id ASC";
0487 $result = $db->sql_query($sql);
0488
0489 $l_lang_options = array();
0490 while ($row = $db->sql_fetchrow($result))
0491 {
0492 $l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value'];
0493 }
0494 $db->sql_freeresult($result);
0495
0496 $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value
0497 FROM ' . PROFILE_LANG_TABLE . '
0498 WHERE lang_id <> ' . $this->edit_lang_id . "
0499 AND field_id = $field_id
0500 ORDER BY lang_id ASC";
0501 $result = $db->sql_query($sql);
0502
0503 $l_lang_name = $l_lang_explain = $l_lang_default_value = array();
0504 while ($row = $db->sql_fetchrow($result))
0505 {
0506 $l_lang_name[$row['lang_id']] = $row['lang_name'];
0507 $l_lang_explain[$row['lang_id']] = $row['lang_explain'];
0508 $l_lang_default_value[$row['lang_id']] = $row['lang_default_value'];
0509 }
0510 $db->sql_freeresult($result);
0511 }
0512
0513 foreach ($exclude[3] as $key)
0514 {
0515 $cp->vars[$key] = $request->variable($key, array(0 => ''), true);
0516
0517 if (!$cp->vars[$key] && $action == 'edit')
0518 {
0519 $cp->vars[$key] = ${$key};
0520 }
0521
0522 $field_data = $cp->vars;
0523 $var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 3);
0524 $cp->vars = $field_data;
0525 }
0526
0527 // Check for general issues in every step
0528 if ($submit) // && $step == 1
0529 {
0530 // Check values for step 1
0531 if ($cp->vars['field_ident'] == '')
0532 {
0533 $error[] = $user->lang['EMPTY_FIELD_IDENT'];
0534 }
0535
0536 if (!preg_match('/^[a-z_]+$/', $cp->vars['field_ident']))
0537 {
0538 $error[] = $user->lang['INVALID_CHARS_FIELD_IDENT'];
0539 }
0540
0541 if (strlen($cp->vars['field_ident']) > 17)
0542 {
0543 $error[] = $user->lang['INVALID_FIELD_IDENT_LEN'];
0544 }
0545
0546 if ($cp->vars['lang_name'] == '')
0547 {
0548 $error[] = $user->lang['EMPTY_USER_FIELD_NAME'];
0549 }
0550
0551 $error = $profile_field->validate_options_on_submit($error, $cp->vars);
0552
0553 // Check for already existing field ident
0554 if ($action != 'edit')
0555 {
0556 $sql = 'SELECT field_ident
0557 FROM ' . PROFILE_FIELDS_TABLE . "
0558 WHERE field_ident = '" . $db->sql_escape($cp->vars['field_ident']) . "'";
0559 $result = $db->sql_query($sql);
0560 $row = $db->sql_fetchrow($result);
0561 $db->sql_freeresult($result);
0562
0563 if ($row)
0564 {
0565 $error[] = $user->lang['FIELD_IDENT_ALREADY_EXIST'];
0566 }
0567 }
0568 }
0569
0570 if (count($error))
0571 {
0572 $submit = false;
0573 }
0574 else
0575 {
0576 $step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step);
0577 }
0578
0579 // Build up the specific hidden fields
0580 foreach ($exclude as $num => $key_ary)
0581 {
0582 if ($num == $step)
0583 {
0584 continue;
0585 }
0586
0587 $_new_key_ary = array();
0588
0589 $field_data = $cp->vars;
0590 foreach ($key_ary as $key)
0591 {
0592 $var = $profile_field->prepare_hidden_fields($step, $key, $action, $field_data);
0593 if ($var !== null)
0594 {
0595 $_new_key_ary[$key] = $var;
0596 }
0597 }
0598 $cp->vars = $field_data;
0599
0600 $s_hidden_fields .= build_hidden_fields($_new_key_ary);
0601 }
0602
0603 if (!count($error))
0604 {
0605 if (($step == 3 && (count($this->lang_defs['iso']) == 1 || $save)) || ($action == 'edit' && $save))
0606 {
0607 if (!check_form_key($form_key))
0608 {
0609 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
0610 }
0611
0612 $this->save_profile_field($cp, $field_type, $action);
0613 }
0614 }
0615
0616 $template->assign_vars(array(
0617 'S_EDIT' => true,
0618 'S_EDIT_MODE' => ($action == 'edit') ? true : false,
0619 'ERROR_MSG' => (count($error)) ? implode('<br />', $error) : '',
0620
0621 'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)],
0622 'L_EXPLAIN' => $user->lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($action)],
0623
0624 'U_ACTION' => $this->u_action . "&action=$action&step=$step",
0625 'U_BACK' => $this->u_action)
0626 );
0627
0628 // Now go through the steps
0629 switch ($step)
0630 {
0631 // Create basic options - only small differences between field types
0632 case 1:
0633 $template_vars = array(
0634 'S_STEP_ONE' => true,
0635 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
0636 'S_FIELD_SHOW_NOVALUE'=> ($cp->vars['field_show_novalue']) ? true : false,
0637 'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
0638 'S_SHOW_ON_PM' => ($cp->vars['field_show_on_pm']) ? true : false,
0639 'S_SHOW_ON_VT' => ($cp->vars['field_show_on_vt']) ? true : false,
0640 'S_SHOW_ON_MEMBERLIST'=> ($cp->vars['field_show_on_ml']) ? true : false,
0641 'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
0642 'S_SHOW_PROFILE' => ($cp->vars['field_show_profile']) ? true : false,
0643 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false,
0644 'S_FIELD_CONTACT' => $cp->vars['field_is_contact'],
0645 'FIELD_CONTACT_DESC'=> $cp->vars['field_contact_desc'],
0646 'FIELD_CONTACT_URL' => $cp->vars['field_contact_url'],
0647
0648 'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
0649 'FIELD_TYPE' => $profile_field->get_name(),
0650 'FIELD_IDENT' => $cp->vars['field_ident'],
0651 'LANG_NAME' => $cp->vars['lang_name'],
0652 'LANG_EXPLAIN' => $cp->vars['lang_explain'],
0653 );
0654
0655 $field_data = $cp->vars;
0656 $profile_field->display_options($template_vars, $field_data);
0657 $cp->vars = $field_data;
0658
0659 // Build common create options
0660 $template->assign_vars($template_vars);
0661 break;
0662
0663 case 2:
0664
0665 $template->assign_vars(array(
0666 'S_STEP_TWO' => true,
0667 'L_NEXT_STEP' => (count($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS'])
0668 );
0669
0670 // Build options based on profile type
0671 $options = $profile_field->get_options($this->lang_defs['iso'][$config['default_lang']], $cp->vars);
0672
0673 foreach ($options as $num => $option_ary)
0674 {
0675 $template->assign_block_vars('option', $option_ary);
0676 }
0677
0678 break;
0679
0680 // Define remaining language variables
0681 case 3:
0682
0683 $template->assign_var('S_STEP_THREE', true);
0684 $options = $this->build_language_options($cp, $field_type, $action);
0685
0686 foreach ($options as $lang_id => $lang_ary)
0687 {
0688 $template->assign_block_vars('options', array(
0689 'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso']))
0690 );
0691
0692 foreach ($lang_ary['fields'] as $field_ident => $field_ary)
0693 {
0694 $template->assign_block_vars('options.field', array(
0695 'L_TITLE' => $field_ary['TITLE'],
0696 'L_EXPLAIN' => (isset($field_ary['EXPLAIN'])) ? $field_ary['EXPLAIN'] : '',
0697 'FIELD' => $field_ary['FIELD'])
0698 );
0699 }
0700 }
0701
0702 break;
0703 }
0704
0705 $field_data = $cp->vars;
0706 /**
0707 * Event to add template variables for new profile field table fields
0708 *
0709 * @event core.acp_profile_create_edit_after
0710 * @var string action create|edit
0711 * @var int step Configuration step (1|2|3)
0712 * @var bool submit Form has been submitted
0713 * @var bool save Configuration should be saved
0714 * @var string field_type Type of the field we are dealing with
0715 * @var array field_data Array of data about the field
0716 * @var array s_hidden_fields Array of hidden fields in case this needs modification
0717 * @var array options Array of options specific to this step
0718 * @since 3.1.6-RC1
0719 */
0720 $vars = array(
0721 'action',
0722 'step',
0723 'submit',
0724 'save',
0725 'field_type',
0726 'field_data',
0727 's_hidden_fields',
0728 'options',
0729 );
0730 extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_after', compact($vars)));
0731
0732 $template->assign_vars(array(
0733 'S_HIDDEN_FIELDS' => $s_hidden_fields)
0734 );
0735
0736 return;
0737
0738 break;
0739 }
0740
0741 $tpl_name = $this->tpl_name;
0742 $page_title = $this->page_title;
0743 $u_action = $this->u_action;
0744
0745 /**
0746 * Event to handle actions on the ACP profile fields page
0747 *
0748 * @event core.acp_profile_action
0749 * @var string action Action that is being performed
0750 * @var string tpl_name Template file to load
0751 * @var string page_title Page title
0752 * @var string u_action The URL we are at, read only
0753 * @since 3.2.2-RC1
0754 */
0755 $vars = array(
0756 'action',
0757 'tpl_name',
0758 'page_title',
0759 'u_action',
0760 );
0761 extract($phpbb_dispatcher->trigger_event('core.acp_profile_action', compact($vars)));
0762
0763 $this->tpl_name = $tpl_name;
0764 $this->page_title = $page_title;
0765 unset($u_action);
0766
0767 $sql = 'SELECT *
0768 FROM ' . PROFILE_FIELDS_TABLE . '
0769 ORDER BY field_order';
0770 $result = $db->sql_query($sql);
0771
0772 $s_one_need_edit = false;
0773 while ($row = $db->sql_fetchrow($result))
0774 {
0775 $active_lang = (!$row['field_active']) ? 'ACTIVATE' : 'DEACTIVATE';
0776 $active_value = (!$row['field_active']) ? 'activate' : 'deactivate';
0777 $id = $row['field_id'];
0778
0779 $s_need_edit = (count($this->lang_defs['diff'][$row['field_id']])) ? true : false;
0780
0781 if ($s_need_edit)
0782 {
0783 $s_one_need_edit = true;
0784 }
0785
0786 if (!isset($this->type_collection[$row['field_type']]))
0787 {
0788 continue;
0789 }
0790 $profile_field = $this->type_collection[$row['field_type']];
0791
0792 $field_block = array(
0793 'FIELD_IDENT' => $row['field_ident'],
0794 'FIELD_TYPE' => $profile_field->get_name(),
0795
0796 'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang],
0797 'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'),
0798 'U_EDIT' => $this->u_action . "&action=edit&field_id=$id",
0799 'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3",
0800 'U_DELETE' => $this->u_action . "&action=delete&field_id=$id",
0801 'U_MOVE_UP' => $this->u_action . "&action=move_up&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'),
0802 'U_MOVE_DOWN' => $this->u_action . "&action=move_down&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'),
0803
0804 'S_NEED_EDIT' => $s_need_edit,
0805 );
0806
0807 /**
0808 * Event to modify profile field data before it is assigned to the template
0809 *
0810 * @event core.acp_profile_modify_profile_row
0811 * @var array row Array with data for the current profile field
0812 * @var array field_block Template data that is being assigned to the 'fields' block
0813 * @var object profile_field A profile field instance, implements \phpbb\profilefields\type\type_base
0814 * @since 3.2.2-RC1
0815 */
0816 $vars = array(
0817 'row',
0818 'field_block',
0819 'profile_field',
0820 );
0821 extract($phpbb_dispatcher->trigger_event('core.acp_profile_modify_profile_row', compact($vars)));
0822
0823 $template->assign_block_vars('fields', $field_block);
0824 }
0825 $db->sql_freeresult($result);
0826
0827 // At least one option field needs editing?
0828 if ($s_one_need_edit)
0829 {
0830 $template->assign_var('S_NEED_EDIT', true);
0831 }
0832
0833 $s_select_type = '';
0834 foreach ($this->type_collection as $key => $profile_field)
0835 {
0836 $s_select_type .= '<option value="' . $key . '">' . $profile_field->get_name() . '</option>';
0837 }
0838
0839 $template->assign_vars(array(
0840 'U_ACTION' => $this->u_action,
0841 'S_TYPE_OPTIONS' => $s_select_type,
0842 ));
0843 }
0844
0845 /**
0846 * Build all Language specific options
0847 */
0848 function build_language_options($cp, $field_type, $action = 'create')
0849 {
0850 global $user, $config, $db, $request;
0851
0852 $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
0853
0854 $sql = 'SELECT lang_id, lang_iso
0855 FROM ' . LANG_TABLE . '
0856 WHERE lang_id <> ' . (int) $default_lang_id . '
0857 ORDER BY lang_english_name';
0858 $result = $db->sql_query($sql);
0859
0860 $languages = array();
0861 while ($row = $db->sql_fetchrow($result))
0862 {
0863 $languages[$row['lang_id']] = $row['lang_iso'];
0864 }
0865 $db->sql_freeresult($result);
0866
0867 $profile_field = $this->type_collection[$field_type];
0868 $options = $profile_field->get_language_options($cp->vars);
0869
0870 $lang_options = array();
0871
0872 foreach ($options as $field => $field_type)
0873 {
0874 $lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id];
0875 $lang_options[1]['fields'][$field] = array(
0876 'TITLE' => $user->lang['CP_' . strtoupper($field)],
0877 'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . '</dd>'
0878 );
0879
0880 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
0881 {
0882 $lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
0883 }
0884 }
0885
0886 foreach ($languages as $lang_id => $lang_iso)
0887 {
0888 $lang_options[$lang_id]['lang_iso'] = $lang_iso;
0889 foreach ($options as $field => $field_type)
0890 {
0891 $value = ($action == 'create') ? $request->variable('l_' . $field, array(0 => ''), true) : $cp->vars['l_' . $field];
0892 if ($field == 'lang_options')
0893 {
0894 $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];
0895
0896 switch ($field_type)
0897 {
0898 case 'two_options':
0899
0900 $lang_options[$lang_id]['fields'][$field] = array(
0901 'TITLE' => $user->lang['CP_' . strtoupper($field)],
0902 'FIELD' => '
0903 <dd><input class="medium" name="l_' . $field . '[' . $lang_id . '][]" value="' . ((isset($value[$lang_id][0])) ? $value[$lang_id][0] : $var[0]) . '" /> ' . $user->lang['FIRST_OPTION'] . '</dd>
0904 <dd><input class="medium" name="l_' . $field . '[' . $lang_id . '][]" value="' . ((isset($value[$lang_id][1])) ? $value[$lang_id][1] : $var[1]) . '" /> ' . $user->lang['SECOND_OPTION'] . '</dd>'
0905 );
0906 break;
0907
0908 case 'optionfield':
0909 $value = ((isset($value[$lang_id])) ? ((is_array($value[$lang_id])) ? implode("\n", $value[$lang_id]) : $value[$lang_id]) : implode("\n", $var));
0910 $lang_options[$lang_id]['fields'][$field] = array(
0911 'TITLE' => $user->lang['CP_' . strtoupper($field)],
0912 'FIELD' => '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="7" cols="80">' . $value . '</textarea></dd>'
0913 );
0914 break;
0915 }
0916
0917 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
0918 {
0919 $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
0920 }
0921 }
0922 else
0923 {
0924 $var = ($action == 'create' || !is_array($cp->vars[$field])) ? $cp->vars[$field] : $cp->vars[$field][$lang_id];
0925
0926 $lang_options[$lang_id]['fields'][$field] = array(
0927 'TITLE' => $user->lang['CP_' . strtoupper($field)],
0928 'FIELD' => ($field_type == 'string') ? '<dd><input class="medium" type="text" name="l_' . $field . '[' . $lang_id . ']" value="' . ((isset($value[$lang_id])) ? $value[$lang_id] : $var) . '" /></dd>' : '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="3" cols="80">' . ((isset($value[$lang_id])) ? $value[$lang_id] : $var) . '</textarea></dd>'
0929 );
0930
0931 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN']))
0932 {
0933 $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN'];
0934 }
0935 }
0936 }
0937 }
0938
0939 return $lang_options;
0940 }
0941
0942 /**
0943 * Save Profile Field
0944 */
0945 function save_profile_field($cp, $field_type, $action = 'create')
0946 {
0947 global $db, $config, $user, $phpbb_container, $phpbb_log, $request, $phpbb_dispatcher;
0948
0949 $field_id = $request->variable('field_id', 0);
0950
0951 // Collect all information, if something is going wrong, abort the operation
0952 $profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array();
0953
0954 $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']];
0955
0956 if ($action == 'create')
0957 {
0958 $sql = 'SELECT MAX(field_order) as max_field_order
0959 FROM ' . PROFILE_FIELDS_TABLE;
0960 $result = $db->sql_query($sql);
0961 $new_field_order = (int) $db->sql_fetchfield('max_field_order');
0962 $db->sql_freeresult($result);
0963
0964 $field_ident = $cp->vars['field_ident'];
0965 }
0966
0967 // Save the field
0968 $profile_fields = array(
0969 'field_length' => $cp->vars['field_length'],
0970 'field_minlen' => $cp->vars['field_minlen'],
0971 'field_maxlen' => $cp->vars['field_maxlen'],
0972 'field_novalue' => $cp->vars['field_novalue'],
0973 'field_default_value' => $cp->vars['field_default_value'],
0974 'field_validation' => $cp->vars['field_validation'],
0975 'field_required' => $cp->vars['field_required'],
0976 'field_show_novalue' => $cp->vars['field_show_novalue'],
0977 'field_show_on_reg' => $cp->vars['field_show_on_reg'],
0978 'field_show_on_pm' => $cp->vars['field_show_on_pm'],
0979 'field_show_on_vt' => $cp->vars['field_show_on_vt'],
0980 'field_show_on_ml' => $cp->vars['field_show_on_ml'],
0981 'field_hide' => $cp->vars['field_hide'],
0982 'field_show_profile' => $cp->vars['field_show_profile'],
0983 'field_no_view' => $cp->vars['field_no_view'],
0984 'field_is_contact' => $cp->vars['field_is_contact'],
0985 'field_contact_desc' => $cp->vars['field_contact_desc'],
0986 'field_contact_url' => $cp->vars['field_contact_url'],
0987 );
0988
0989 $field_data = $cp->vars;
0990 /**
0991 * Event to modify profile field configuration data before saving to database
0992 *
0993 * @event core.acp_profile_create_edit_save_before
0994 * @var string action create|edit
0995 * @var string field_type Type of the field we are dealing with
0996 * @var array field_data Array of data about the field
0997 * @var array profile_fields Array of fields to be sent to the database
0998 * @since 3.1.6-RC1
0999 */
1000 $vars = array(
1001 'action',
1002 'field_type',
1003 'field_data',
1004 'profile_fields',
1005 );
1006 extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_save_before', compact($vars)));
1007
1008 if ($action == 'create')
1009 {
1010 $profile_fields += array(
1011 'field_type' => $field_type,
1012 'field_ident' => $field_ident,
1013 'field_name' => $field_ident,
1014 'field_order' => $new_field_order + 1,
1015 'field_active' => 1
1016 );
1017
1018 $sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields);
1019 $db->sql_query($sql);
1020
1021 $field_id = $db->sql_nextid();
1022 }
1023 else
1024 {
1025 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . '
1026 SET ' . $db->sql_build_array('UPDATE', $profile_fields) . "
1027 WHERE field_id = $field_id";
1028 $db->sql_query($sql);
1029 }
1030
1031 $profile_field = $this->type_collection[$field_type];
1032
1033 if ($action == 'create')
1034 {
1035 $field_ident = 'pf_' . $field_ident;
1036 /* @var $db_tools \phpbb\db\tools\tools_interface */
1037 $db_tools = $phpbb_container->get('dbal.tools');
1038 $db_tools->sql_column_add(PROFILE_FIELDS_DATA_TABLE, $field_ident, array($profile_field->get_database_column_type(), null));
1039 }
1040
1041 $sql_ary = array(
1042 'lang_name' => $cp->vars['lang_name'],
1043 'lang_explain' => $cp->vars['lang_explain'],
1044 'lang_default_value' => $cp->vars['lang_default_value']
1045 );
1046
1047 if ($action == 'create')
1048 {
1049 $sql_ary['field_id'] = $field_id;
1050 $sql_ary['lang_id'] = $default_lang_id;
1051
1052 $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1053 }
1054 else
1055 {
1056 $this->update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id));
1057 }
1058
1059 if (is_array($cp->vars['l_lang_name']) && count($cp->vars['l_lang_name']))
1060 {
1061 foreach ($cp->vars['l_lang_name'] as $lang_id => $data)
1062 {
1063 if (($cp->vars['lang_name'] != '' && $cp->vars['l_lang_name'][$lang_id] == '')
1064 || ($cp->vars['lang_explain'] != '' && $cp->vars['l_lang_explain'][$lang_id] == '')
1065 || ($cp->vars['lang_default_value'] != '' && $cp->vars['l_lang_default_value'][$lang_id] == ''))
1066 {
1067 $empty_lang[$lang_id] = true;
1068 break;
1069 }
1070
1071 if (!isset($empty_lang[$lang_id]))
1072 {
1073 $profile_lang[] = array(
1074 'field_id' => $field_id,
1075 'lang_id' => $lang_id,
1076 'lang_name' => $cp->vars['l_lang_name'][$lang_id],
1077 'lang_explain' => (isset($cp->vars['l_lang_explain'][$lang_id])) ? $cp->vars['l_lang_explain'][$lang_id] : '',
1078 'lang_default_value' => (isset($cp->vars['l_lang_default_value'][$lang_id])) ? $cp->vars['l_lang_default_value'][$lang_id] : ''
1079 );
1080 }
1081 }
1082
1083 foreach ($empty_lang as $lang_id => $NULL)
1084 {
1085 $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . "
1086 WHERE field_id = $field_id
1087 AND lang_id = " . (int) $lang_id;
1088 $db->sql_query($sql);
1089 }
1090 }
1091
1092 $cp->vars = $profile_field->get_language_options_input($cp->vars);
1093
1094 if ($cp->vars['lang_options'])
1095 {
1096 if (!is_array($cp->vars['lang_options']))
1097 {
1098 $cp->vars['lang_options'] = explode("\n", $cp->vars['lang_options']);
1099 }
1100
1101 if ($action != 'create')
1102 {
1103 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1104 WHERE field_id = $field_id
1105 AND lang_id = " . (int) $default_lang_id;
1106 $db->sql_query($sql);
1107 }
1108
1109 foreach ($cp->vars['lang_options'] as $option_id => $value)
1110 {
1111 $sql_ary = array(
1112 'field_type' => $field_type,
1113 'lang_value' => $value
1114 );
1115
1116 if ($action == 'create')
1117 {
1118 $sql_ary['field_id'] = $field_id;
1119 $sql_ary['lang_id'] = $default_lang_id;
1120 $sql_ary['option_id'] = (int) $option_id;
1121
1122 $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
1123 }
1124 else
1125 {
1126 $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array(
1127 'field_id' => $field_id,
1128 'lang_id' => (int) $default_lang_id,
1129 'option_id' => (int) $option_id)
1130 );
1131 }
1132 }
1133 }
1134
1135 if (is_array($cp->vars['l_lang_options']) && count($cp->vars['l_lang_options']))
1136 {
1137 $empty_lang = array();
1138
1139 foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary)
1140 {
1141 if (!is_array($lang_ary))
1142 {
1143 $lang_ary = explode("\n", $lang_ary);
1144 }
1145
1146 if (count($lang_ary) != count($cp->vars['lang_options']))
1147 {
1148 $empty_lang[$lang_id] = true;
1149 }
1150
1151 if (!isset($empty_lang[$lang_id]))
1152 {
1153 if ($action != 'create')
1154 {
1155 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1156 WHERE field_id = $field_id
1157 AND lang_id = " . (int) $lang_id;
1158 $db->sql_query($sql);
1159 }
1160
1161 foreach ($lang_ary as $option_id => $value)
1162 {
1163 $profile_lang_fields[] = array(
1164 'field_id' => (int) $field_id,
1165 'lang_id' => (int) $lang_id,
1166 'option_id' => (int) $option_id,
1167 'field_type' => $field_type,
1168 'lang_value' => $value
1169 );
1170 }
1171 }
1172 }
1173
1174 foreach ($empty_lang as $lang_id => $NULL)
1175 {
1176 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . "
1177 WHERE field_id = $field_id
1178 AND lang_id = " . (int) $lang_id;
1179 $db->sql_query($sql);
1180 }
1181 }
1182
1183 foreach ($profile_lang as $sql)
1184 {
1185 if ($action == 'create')
1186 {
1187 $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1188 }
1189 else
1190 {
1191 $lang_id = $sql['lang_id'];
1192 unset($sql['lang_id'], $sql['field_id']);
1193
1194 $this->update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id));
1195 }
1196 }
1197
1198 if (count($profile_lang_fields))
1199 {
1200 foreach ($profile_lang_fields as $sql)
1201 {
1202 if ($action == 'create')
1203 {
1204 $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql);
1205 }
1206 else
1207 {
1208 $lang_id = $sql['lang_id'];
1209 $option_id = $sql['option_id'];
1210 unset($sql['lang_id'], $sql['field_id'], $sql['option_id']);
1211
1212 $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array(
1213 'lang_id' => $lang_id,
1214 'field_id' => $field_id,
1215 'option_id' => $option_id)
1216 );
1217 }
1218 }
1219 }
1220
1221 $db->sql_transaction('begin');
1222
1223 if ($action == 'create')
1224 {
1225 foreach ($profile_sql as $sql)
1226 {
1227 $db->sql_query($sql);
1228 }
1229 }
1230
1231 $db->sql_transaction('commit');
1232
1233 if ($action == 'edit')
1234 {
1235 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_EDIT', false, array($cp->vars['field_ident'] . ':' . $cp->vars['lang_name']));
1236 trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1237 }
1238 else
1239 {
1240 $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PROFILE_FIELD_CREATE', false, array(substr($field_ident, 3) . ':' . $cp->vars['lang_name']));
1241 trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action));
1242 }
1243 }
1244
1245 /**
1246 * Update, then insert if not successfull
1247 */
1248 function update_insert($table, $sql_ary, $where_fields)
1249 {
1250 global $db;
1251
1252 $where_sql = array();
1253 $check_key = '';
1254
1255 foreach ($where_fields as $key => $value)
1256 {
1257 $check_key = (!$check_key) ? $key : $check_key;
1258 $where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : (int) $value);
1259 }
1260
1261 if (!count($where_sql))
1262 {
1263 return;
1264 }
1265
1266 $sql = "SELECT $check_key
1267 FROM $table
1268 WHERE " . implode(' AND ', $where_sql);
1269 $result = $db->sql_query($sql);
1270 $row = $db->sql_fetchrow($result);
1271 $db->sql_freeresult($result);
1272
1273 if (!$row)
1274 {
1275 $sql_ary = array_merge($where_fields, $sql_ary);
1276
1277 if (count($sql_ary))
1278 {
1279 $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary));
1280 }
1281 }
1282 else
1283 {
1284 if (count($sql_ary))
1285 {
1286 $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . '
1287 WHERE ' . implode(' AND ', $where_sql);
1288 $db->sql_query($sql);
1289 }
1290 }
1291 }
1292 }
1293