[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 /** 15 * @ignore 16 */ 17 if (!defined('IN_PHPBB')) 18 { 19 exit; 20 } 21 22 class acp_profile 23 { 24 var $u_action; 25 26 var $edit_lang_id; 27 var $lang_defs; 28 protected $type_collection; 29 30 function main($id, $mode) 31 { 32 global $config, $db, $user, $auth, $template, $cache; 33 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; 34 global $request, $phpbb_container, $phpbb_dispatcher; 35 36 if (!function_exists('generate_smilies')) 37 { 38 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx); 39 } 40 41 if (!function_exists('user_get_id_name')) 42 { 43 include($phpbb_root_path . 'includes/functions_user.' . $phpEx); 44 } 45 46 $user->add_lang(array('ucp', 'acp/profile')); 47 $this->tpl_name = 'acp_profile'; 48 $this->page_title = 'ACP_CUSTOM_PROFILE_FIELDS'; 49 50 $field_id = $request->variable('field_id', 0); 51 $action = (isset($_POST['create'])) ? 'create' : request_var('action', ''); 52 53 $error = array(); 54 $s_hidden_fields = ''; 55 56 $form_key = 'acp_profile'; 57 add_form_key($form_key); 58 59 if (!$field_id && in_array($action, array('delete','activate', 'deactivate', 'move_up', 'move_down', 'edit'))) 60 { 61 trigger_error($user->lang['NO_FIELD_ID'] . adm_back_link($this->u_action), E_USER_WARNING); 62 } 63 64 $cp = $phpbb_container->get('profilefields.manager'); 65 $this->type_collection = $phpbb_container->get('profilefields.type_collection'); 66 67 // Build Language array 68 // Based on this, we decide which elements need to be edited later and which language items are missing 69 $this->lang_defs = array(); 70 71 $sql = 'SELECT lang_id, lang_iso 72 FROM ' . LANG_TABLE . ' 73 ORDER BY lang_english_name'; 74 $result = $db->sql_query($sql); 75 76 while ($row = $db->sql_fetchrow($result)) 77 { 78 // Make some arrays with all available languages 79 $this->lang_defs['id'][$row['lang_id']] = $row['lang_iso']; 80 $this->lang_defs['iso'][$row['lang_iso']] = $row['lang_id']; 81 } 82 $db->sql_freeresult($result); 83 84 $sql = 'SELECT field_id, lang_id 85 FROM ' . PROFILE_LANG_TABLE . ' 86 ORDER BY lang_id'; 87 $result = $db->sql_query($sql); 88 89 while ($row = $db->sql_fetchrow($result)) 90 { 91 // Which languages are available for each item 92 $this->lang_defs['entry'][$row['field_id']][] = $row['lang_id']; 93 } 94 $db->sql_freeresult($result); 95 96 // Have some fields been defined? 97 if (isset($this->lang_defs['entry'])) 98 { 99 foreach ($this->lang_defs['entry'] as $field_ident => $field_ary) 100 { 101 // Fill an array with the languages that are missing for each field 102 $this->lang_defs['diff'][$field_ident] = array_diff(array_values($this->lang_defs['iso']), $field_ary); 103 } 104 } 105 106 switch ($action) 107 { 108 case 'delete': 109 110 if (confirm_box(true)) 111 { 112 $sql = 'SELECT field_ident 113 FROM ' . PROFILE_FIELDS_TABLE . " 114 WHERE field_id = $field_id"; 115 $result = $db->sql_query($sql); 116 $field_ident = (string) $db->sql_fetchfield('field_ident'); 117 $db->sql_freeresult($result); 118 119 $db->sql_transaction('begin'); 120 121 $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_TABLE . " WHERE field_id = $field_id"); 122 $db->sql_query('DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " WHERE field_id = $field_id"); 123 $db->sql_query('DELETE FROM ' . PROFILE_LANG_TABLE . " WHERE field_id = $field_id"); 124 125 $db_tools = $phpbb_container->get('dbal.tools'); 126 $db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_' . $field_ident); 127 128 $order = 0; 129 130 $sql = 'SELECT * 131 FROM ' . PROFILE_FIELDS_TABLE . ' 132 ORDER BY field_order'; 133 $result = $db->sql_query($sql); 134 135 while ($row = $db->sql_fetchrow($result)) 136 { 137 $order++; 138 if ($row['field_order'] != $order) 139 { 140 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . " 141 SET field_order = $order 142 WHERE field_id = {$row['field_id']}"; 143 $db->sql_query($sql); 144 } 145 } 146 $db->sql_freeresult($result); 147 148 $db->sql_transaction('commit'); 149 150 add_log('admin', 'LOG_PROFILE_FIELD_REMOVED', $field_ident); 151 trigger_error($user->lang['REMOVED_PROFILE_FIELD'] . adm_back_link($this->u_action)); 152 } 153 else 154 { 155 confirm_box(false, 'DELETE_PROFILE_FIELD', build_hidden_fields(array( 156 'i' => $id, 157 'mode' => $mode, 158 'action' => $action, 159 'field_id' => $field_id, 160 ))); 161 } 162 163 break; 164 165 case 'activate': 166 167 if (!check_link_hash($request->variable('hash', ''), 'acp_profile')) 168 { 169 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 170 } 171 172 $sql = 'SELECT lang_id 173 FROM ' . LANG_TABLE . " 174 WHERE lang_iso = '" . $db->sql_escape($config['default_lang']) . "'"; 175 $result = $db->sql_query($sql); 176 $default_lang_id = (int) $db->sql_fetchfield('lang_id'); 177 $db->sql_freeresult($result); 178 179 if (!in_array($default_lang_id, $this->lang_defs['entry'][$field_id])) 180 { 181 trigger_error($user->lang['DEFAULT_LANGUAGE_NOT_FILLED'] . adm_back_link($this->u_action), E_USER_WARNING); 182 } 183 184 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . " 185 SET field_active = 1 186 WHERE field_id = $field_id"; 187 $db->sql_query($sql); 188 189 $sql = 'SELECT field_ident 190 FROM ' . PROFILE_FIELDS_TABLE . " 191 WHERE field_id = $field_id"; 192 $result = $db->sql_query($sql); 193 $field_ident = (string) $db->sql_fetchfield('field_ident'); 194 $db->sql_freeresult($result); 195 196 add_log('admin', 'LOG_PROFILE_FIELD_ACTIVATE', $field_ident); 197 198 if ($request->is_ajax()) 199 { 200 $json_response = new \phpbb\json_response(); 201 $json_response->send(array( 202 'text' => $user->lang('DEACTIVATE'), 203 )); 204 } 205 206 trigger_error($user->lang['PROFILE_FIELD_ACTIVATED'] . adm_back_link($this->u_action)); 207 208 break; 209 210 case 'deactivate': 211 212 if (!check_link_hash($request->variable('hash', ''), 'acp_profile')) 213 { 214 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 215 } 216 217 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . " 218 SET field_active = 0 219 WHERE field_id = $field_id"; 220 $db->sql_query($sql); 221 222 $sql = 'SELECT field_ident 223 FROM ' . PROFILE_FIELDS_TABLE . " 224 WHERE field_id = $field_id"; 225 $result = $db->sql_query($sql); 226 $field_ident = (string) $db->sql_fetchfield('field_ident'); 227 $db->sql_freeresult($result); 228 229 if ($request->is_ajax()) 230 { 231 $json_response = new \phpbb\json_response(); 232 $json_response->send(array( 233 'text' => $user->lang('ACTIVATE'), 234 )); 235 } 236 237 add_log('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', $field_ident); 238 239 trigger_error($user->lang['PROFILE_FIELD_DEACTIVATED'] . adm_back_link($this->u_action)); 240 241 break; 242 243 case 'move_up': 244 case 'move_down': 245 246 if (!check_link_hash($request->variable('hash', ''), 'acp_profile')) 247 { 248 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 249 } 250 251 $sql = 'SELECT field_order 252 FROM ' . PROFILE_FIELDS_TABLE . " 253 WHERE field_id = $field_id"; 254 $result = $db->sql_query($sql); 255 $field_order = $db->sql_fetchfield('field_order'); 256 $db->sql_freeresult($result); 257 258 if ($field_order === false || ($field_order == 0 && $action == 'move_up')) 259 { 260 break; 261 } 262 $field_order = (int) $field_order; 263 $order_total = $field_order * 2 + (($action == 'move_up') ? -1 : 1); 264 265 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . " 266 SET field_order = $order_total - field_order 267 WHERE field_order IN ($field_order, " . (($action == 'move_up') ? $field_order - 1 : $field_order + 1) . ')'; 268 $db->sql_query($sql); 269 270 if ($request->is_ajax()) 271 { 272 $json_response = new \phpbb\json_response; 273 $json_response->send(array( 274 'success' => (bool) $db->sql_affectedrows(), 275 )); 276 } 277 278 break; 279 280 case 'create': 281 case 'edit': 282 283 $step = request_var('step', 1); 284 285 $submit = (isset($_REQUEST['next']) || isset($_REQUEST['prev'])) ? true : false; 286 $save = (isset($_REQUEST['save'])) ? true : false; 287 288 // The language id of default language 289 $this->edit_lang_id = $this->lang_defs['iso'][$config['default_lang']]; 290 291 // We are editing... we need to grab basic things 292 if ($action == 'edit') 293 { 294 $sql = 'SELECT l.*, f.* 295 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f 296 WHERE l.lang_id = ' . $this->edit_lang_id . " 297 AND f.field_id = $field_id 298 AND l.field_id = f.field_id"; 299 $result = $db->sql_query($sql); 300 $field_row = $db->sql_fetchrow($result); 301 $db->sql_freeresult($result); 302 303 if (!$field_row) 304 { 305 // Some admin changed the default language? 306 $sql = 'SELECT l.*, f.* 307 FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f 308 WHERE l.lang_id <> ' . $this->edit_lang_id . " 309 AND f.field_id = $field_id 310 AND l.field_id = f.field_id"; 311 $result = $db->sql_query($sql); 312 $field_row = $db->sql_fetchrow($result); 313 $db->sql_freeresult($result); 314 315 if (!$field_row) 316 { 317 trigger_error($user->lang['FIELD_NOT_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); 318 } 319 320 $this->edit_lang_id = $field_row['lang_id']; 321 } 322 $field_type = $field_row['field_type']; 323 $profile_field = $this->type_collection[$field_type]; 324 325 // Get language entries 326 $sql = 'SELECT * 327 FROM ' . PROFILE_FIELDS_LANG_TABLE . ' 328 WHERE lang_id = ' . $this->edit_lang_id . " 329 AND field_id = $field_id 330 ORDER BY option_id ASC"; 331 $result = $db->sql_query($sql); 332 333 $lang_options = array(); 334 while ($row = $db->sql_fetchrow($result)) 335 { 336 $lang_options[$row['option_id']] = $row['lang_value']; 337 } 338 $db->sql_freeresult($result); 339 340 $s_hidden_fields = '<input type="hidden" name="field_id" value="' . $field_id . '" />'; 341 } 342 else 343 { 344 // We are adding a new field, define basic params 345 $lang_options = $field_row = array(); 346 347 $field_type = request_var('field_type', ''); 348 349 if (!isset($this->type_collection[$field_type])) 350 { 351 trigger_error($user->lang['NO_FIELD_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); 352 } 353 354 $profile_field = $this->type_collection[$field_type]; 355 $field_row = array_merge($profile_field->get_default_option_values(), array( 356 'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))), 357 'field_required' => 0, 358 'field_show_novalue'=> 0, 359 'field_hide' => 0, 360 'field_show_profile'=> 0, 361 'field_no_view' => 0, 362 'field_show_on_reg' => 0, 363 'field_show_on_pm' => 0, 364 'field_show_on_vt' => 0, 365 'field_show_on_ml' => 0, 366 'field_is_contact' => 0, 367 'field_contact_desc'=> '', 368 'field_contact_url' => '', 369 'lang_name' => utf8_normalize_nfc(request_var('field_ident', '', true)), 370 'lang_explain' => '', 371 'lang_default_value'=> '') 372 ); 373 374 $s_hidden_fields = '<input type="hidden" name="field_type" value="' . $field_type . '" />'; 375 } 376 377 // $exclude contains the data we gather in each step 378 $exclude = array( 379 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'), 380 2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'), 381 3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options') 382 ); 383 384 // Visibility Options... 385 $visibility_ary = array( 386 'field_required', 387 'field_show_novalue', 388 'field_show_on_reg', 389 'field_show_on_pm', 390 'field_show_on_vt', 391 'field_show_on_ml', 392 'field_show_profile', 393 'field_hide', 394 'field_is_contact', 395 ); 396 397 /** 398 * Event to add initialization for new profile field table fields 399 * 400 * @event core.acp_profile_create_edit_init 401 * @var string action create|edit 402 * @var int step Configuration step (1|2|3) 403 * @var bool submit Form has been submitted 404 * @var bool save Configuration should be saved 405 * @var string field_type Type of the field we are dealing with 406 * @var array field_row Array of data about the field 407 * @var array exclude Array of excluded fields by step 408 * @var array visibility_ary Array of fields that are visibility related 409 * @since 3.1.6-RC1 410 */ 411 $vars = array( 412 'action', 413 'step', 414 'submit', 415 'save', 416 'field_type', 417 'field_row', 418 'exclude', 419 'visibility_ary', 420 ); 421 extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_init', compact($vars))); 422 423 $options = $profile_field->prepare_options_form($exclude, $visibility_ary); 424 425 $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']); 426 $cp->vars['lang_name'] = $request->variable('lang_name', $field_row['lang_name'], true); 427 $cp->vars['lang_explain'] = $request->variable('lang_explain', $field_row['lang_explain'], true); 428 $cp->vars['lang_default_value'] = $request->variable('lang_default_value', $field_row['lang_default_value'], true); 429 $cp->vars['field_contact_desc'] = $request->variable('field_contact_desc', $field_row['field_contact_desc'], true); 430 $cp->vars['field_contact_url'] = $request->variable('field_contact_url', $field_row['field_contact_url'], true); 431 432 foreach ($visibility_ary as $val) 433 { 434 $cp->vars[$val] = ($submit || $save) ? $request->variable($val, 0) : $field_row[$val]; 435 } 436 437 $cp->vars['field_no_view'] = $request->variable('field_no_view', (int) $field_row['field_no_view']); 438 439 // If the user has submitted a form with options (i.e. dropdown field) 440 if ($options) 441 { 442 $exploded_options = (is_array($options)) ? $options : explode("\n", $options); 443 444 if (sizeof($exploded_options) == sizeof($lang_options) || $action == 'create') 445 { 446 // The number of options in the field is equal to the number of options already in the database 447 // Or we are creating a new dropdown list. 448 $cp->vars['lang_options'] = $exploded_options; 449 } 450 else if ($action == 'edit') 451 { 452 // Changing the number of options? (We remove and re-create the option fields) 453 $cp->vars['lang_options'] = $exploded_options; 454 } 455 } 456 else 457 { 458 $cp->vars['lang_options'] = $lang_options; 459 } 460 461 // step 2 462 foreach ($exclude[2] as $key) 463 { 464 $var = utf8_normalize_nfc(request_var($key, $field_row[$key], true)); 465 466 $field_data = $cp->vars; 467 $var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 2); 468 $cp->vars = $field_data; 469 470 $cp->vars[$key] = $var; 471 } 472 473 // step 3 - all arrays 474 if ($action == 'edit') 475 { 476 // Get language entries 477 $sql = 'SELECT * 478 FROM ' . PROFILE_FIELDS_LANG_TABLE . ' 479 WHERE lang_id <> ' . $this->edit_lang_id . " 480 AND field_id = $field_id 481 ORDER BY option_id ASC"; 482 $result = $db->sql_query($sql); 483 484 $l_lang_options = array(); 485 while ($row = $db->sql_fetchrow($result)) 486 { 487 $l_lang_options[$row['lang_id']][$row['option_id']] = $row['lang_value']; 488 } 489 $db->sql_freeresult($result); 490 491 $sql = 'SELECT lang_id, lang_name, lang_explain, lang_default_value 492 FROM ' . PROFILE_LANG_TABLE . ' 493 WHERE lang_id <> ' . $this->edit_lang_id . " 494 AND field_id = $field_id 495 ORDER BY lang_id ASC"; 496 $result = $db->sql_query($sql); 497 498 $l_lang_name = $l_lang_explain = $l_lang_default_value = array(); 499 while ($row = $db->sql_fetchrow($result)) 500 { 501 $l_lang_name[$row['lang_id']] = $row['lang_name']; 502 $l_lang_explain[$row['lang_id']] = $row['lang_explain']; 503 $l_lang_default_value[$row['lang_id']] = $row['lang_default_value']; 504 } 505 $db->sql_freeresult($result); 506 } 507 508 foreach ($exclude[3] as $key) 509 { 510 $cp->vars[$key] = utf8_normalize_nfc(request_var($key, array(0 => ''), true)); 511 512 if (!$cp->vars[$key] && $action == 'edit') 513 { 514 $cp->vars[$key] = ${$key}; 515 } 516 517 $field_data = $cp->vars; 518 $var = $profile_field->get_excluded_options($key, $action, $var, $field_data, 3); 519 $cp->vars = $field_data; 520 } 521 522 // Check for general issues in every step 523 if ($submit) // && $step == 1 524 { 525 // Check values for step 1 526 if ($cp->vars['field_ident'] == '') 527 { 528 $error[] = $user->lang['EMPTY_FIELD_IDENT']; 529 } 530 531 if (!preg_match('/^[a-z_]+$/', $cp->vars['field_ident'])) 532 { 533 $error[] = $user->lang['INVALID_CHARS_FIELD_IDENT']; 534 } 535 536 if (strlen($cp->vars['field_ident']) > 17) 537 { 538 $error[] = $user->lang['INVALID_FIELD_IDENT_LEN']; 539 } 540 541 if ($cp->vars['lang_name'] == '') 542 { 543 $error[] = $user->lang['EMPTY_USER_FIELD_NAME']; 544 } 545 546 $error = $profile_field->validate_options_on_submit($error, $cp->vars); 547 548 // Check for already existing field ident 549 if ($action != 'edit') 550 { 551 $sql = 'SELECT field_ident 552 FROM ' . PROFILE_FIELDS_TABLE . " 553 WHERE field_ident = '" . $db->sql_escape($cp->vars['field_ident']) . "'"; 554 $result = $db->sql_query($sql); 555 $row = $db->sql_fetchrow($result); 556 $db->sql_freeresult($result); 557 558 if ($row) 559 { 560 $error[] = $user->lang['FIELD_IDENT_ALREADY_EXIST']; 561 } 562 } 563 } 564 565 if (sizeof($error)) 566 { 567 $submit = false; 568 } 569 else 570 { 571 $step = (isset($_REQUEST['next'])) ? $step + 1 : ((isset($_REQUEST['prev'])) ? $step - 1 : $step); 572 } 573 574 // Build up the specific hidden fields 575 foreach ($exclude as $num => $key_ary) 576 { 577 if ($num == $step) 578 { 579 continue; 580 } 581 582 $_new_key_ary = array(); 583 584 $field_data = $cp->vars; 585 foreach ($key_ary as $key) 586 { 587 $var = $profile_field->prepare_hidden_fields($step, $key, $action, $field_data); 588 if ($var !== null) 589 { 590 $_new_key_ary[$key] = $var; 591 } 592 } 593 $cp->vars = $field_data; 594 595 $s_hidden_fields .= build_hidden_fields($_new_key_ary); 596 } 597 598 if (!sizeof($error)) 599 { 600 if (($step == 3 && (sizeof($this->lang_defs['iso']) == 1 || $save)) || ($action == 'edit' && $save)) 601 { 602 if (!check_form_key($form_key)) 603 { 604 trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); 605 } 606 607 $this->save_profile_field($cp, $field_type, $action); 608 } 609 } 610 611 $template->assign_vars(array( 612 'S_EDIT' => true, 613 'S_EDIT_MODE' => ($action == 'edit') ? true : false, 614 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '', 615 616 'L_TITLE' => $user->lang['STEP_' . $step . '_TITLE_' . strtoupper($action)], 617 'L_EXPLAIN' => $user->lang['STEP_' . $step . '_EXPLAIN_' . strtoupper($action)], 618 619 'U_ACTION' => $this->u_action . "&action=$action&step=$step", 620 'U_BACK' => $this->u_action) 621 ); 622 623 // Now go through the steps 624 switch ($step) 625 { 626 // Create basic options - only small differences between field types 627 case 1: 628 $template_vars = array( 629 'S_STEP_ONE' => true, 630 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false, 631 'S_FIELD_SHOW_NOVALUE'=> ($cp->vars['field_show_novalue']) ? true : false, 632 'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false, 633 'S_SHOW_ON_PM' => ($cp->vars['field_show_on_pm']) ? true : false, 634 'S_SHOW_ON_VT' => ($cp->vars['field_show_on_vt']) ? true : false, 635 'S_SHOW_ON_MEMBERLIST'=> ($cp->vars['field_show_on_ml']) ? true : false, 636 'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false, 637 'S_SHOW_PROFILE' => ($cp->vars['field_show_profile']) ? true : false, 638 'S_FIELD_NO_VIEW' => ($cp->vars['field_no_view']) ? true : false, 639 'S_FIELD_CONTACT' => $cp->vars['field_is_contact'], 640 'FIELD_CONTACT_DESC'=> $cp->vars['field_contact_desc'], 641 'FIELD_CONTACT_URL' => $cp->vars['field_contact_url'], 642 643 'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']), 644 'FIELD_TYPE' => $profile_field->get_name(), 645 'FIELD_IDENT' => $cp->vars['field_ident'], 646 'LANG_NAME' => $cp->vars['lang_name'], 647 'LANG_EXPLAIN' => $cp->vars['lang_explain'], 648 ); 649 650 $field_data = $cp->vars; 651 $profile_field->display_options($template_vars, $field_data); 652 $cp->vars = $field_data; 653 654 // Build common create options 655 $template->assign_vars($template_vars); 656 break; 657 658 case 2: 659 660 $template->assign_vars(array( 661 'S_STEP_TWO' => true, 662 'L_NEXT_STEP' => (sizeof($this->lang_defs['iso']) == 1) ? $user->lang['SAVE'] : $user->lang['PROFILE_LANG_OPTIONS']) 663 ); 664 665 // Build options based on profile type 666 $options = $profile_field->get_options($this->lang_defs['iso'][$config['default_lang']], $cp->vars); 667 668 foreach ($options as $num => $option_ary) 669 { 670 $template->assign_block_vars('option', $option_ary); 671 } 672 673 break; 674 675 // Define remaining language variables 676 case 3: 677 678 $template->assign_var('S_STEP_THREE', true); 679 $options = $this->build_language_options($cp, $field_type, $action); 680 681 foreach ($options as $lang_id => $lang_ary) 682 { 683 $template->assign_block_vars('options', array( 684 'LANGUAGE' => sprintf($user->lang[(($lang_id == $this->edit_lang_id) ? 'DEFAULT_' : '') . 'ISO_LANGUAGE'], $lang_ary['lang_iso'])) 685 ); 686 687 foreach ($lang_ary['fields'] as $field_ident => $field_ary) 688 { 689 $template->assign_block_vars('options.field', array( 690 'L_TITLE' => $field_ary['TITLE'], 691 'L_EXPLAIN' => (isset($field_ary['EXPLAIN'])) ? $field_ary['EXPLAIN'] : '', 692 'FIELD' => $field_ary['FIELD']) 693 ); 694 } 695 } 696 697 break; 698 } 699 700 $field_data = $cp->vars; 701 /** 702 * Event to add template variables for new profile field table fields 703 * 704 * @event core.acp_profile_create_edit_after 705 * @var string action create|edit 706 * @var int step Configuration step (1|2|3) 707 * @var bool submit Form has been submitted 708 * @var bool save Configuration should be saved 709 * @var string field_type Type of the field we are dealing with 710 * @var array field_data Array of data about the field 711 * @var array s_hidden_fields Array of hidden fields in case this needs modification 712 * @var array options Array of options specific to this step 713 * @since 3.1.6-RC1 714 */ 715 $vars = array( 716 'action', 717 'step', 718 'submit', 719 'save', 720 'field_type', 721 'field_data', 722 's_hidden_fields', 723 'options', 724 ); 725 extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_after', compact($vars))); 726 727 $template->assign_vars(array( 728 'S_HIDDEN_FIELDS' => $s_hidden_fields) 729 ); 730 731 return; 732 733 break; 734 } 735 736 $sql = 'SELECT * 737 FROM ' . PROFILE_FIELDS_TABLE . ' 738 ORDER BY field_order'; 739 $result = $db->sql_query($sql); 740 741 $s_one_need_edit = false; 742 while ($row = $db->sql_fetchrow($result)) 743 { 744 $active_lang = (!$row['field_active']) ? 'ACTIVATE' : 'DEACTIVATE'; 745 $active_value = (!$row['field_active']) ? 'activate' : 'deactivate'; 746 $id = $row['field_id']; 747 748 $s_need_edit = (sizeof($this->lang_defs['diff'][$row['field_id']])) ? true : false; 749 750 if ($s_need_edit) 751 { 752 $s_one_need_edit = true; 753 } 754 755 if (!isset($this->type_collection[$row['field_type']])) 756 { 757 continue; 758 } 759 $profile_field = $this->type_collection[$row['field_type']]; 760 $template->assign_block_vars('fields', array( 761 'FIELD_IDENT' => $row['field_ident'], 762 'FIELD_TYPE' => $profile_field->get_name(), 763 764 'L_ACTIVATE_DEACTIVATE' => $user->lang[$active_lang], 765 'U_ACTIVATE_DEACTIVATE' => $this->u_action . "&action=$active_value&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'), 766 'U_EDIT' => $this->u_action . "&action=edit&field_id=$id", 767 'U_TRANSLATE' => $this->u_action . "&action=edit&field_id=$id&step=3", 768 'U_DELETE' => $this->u_action . "&action=delete&field_id=$id", 769 'U_MOVE_UP' => $this->u_action . "&action=move_up&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'), 770 'U_MOVE_DOWN' => $this->u_action . "&action=move_down&field_id=$id" . '&hash=' . generate_link_hash('acp_profile'), 771 772 'S_NEED_EDIT' => $s_need_edit) 773 ); 774 } 775 $db->sql_freeresult($result); 776 777 // At least one option field needs editing? 778 if ($s_one_need_edit) 779 { 780 $template->assign_var('S_NEED_EDIT', true); 781 } 782 783 $s_select_type = ''; 784 foreach ($this->type_collection as $key => $profile_field) 785 { 786 $s_select_type .= '<option value="' . $key . '">' . $profile_field->get_name() . '</option>'; 787 } 788 789 $template->assign_vars(array( 790 'U_ACTION' => $this->u_action, 791 'S_TYPE_OPTIONS' => $s_select_type, 792 )); 793 } 794 795 /** 796 * Build all Language specific options 797 */ 798 function build_language_options(&$cp, $field_type, $action = 'create') 799 { 800 global $user, $config, $db, $phpbb_container; 801 802 $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']]; 803 804 $sql = 'SELECT lang_id, lang_iso 805 FROM ' . LANG_TABLE . ' 806 WHERE lang_id <> ' . (int) $default_lang_id . ' 807 ORDER BY lang_english_name'; 808 $result = $db->sql_query($sql); 809 810 $languages = array(); 811 while ($row = $db->sql_fetchrow($result)) 812 { 813 $languages[$row['lang_id']] = $row['lang_iso']; 814 } 815 $db->sql_freeresult($result); 816 817 $profile_field = $this->type_collection[$field_type]; 818 $options = $profile_field->get_language_options($cp->vars); 819 820 $lang_options = array(); 821 822 foreach ($options as $field => $field_type) 823 { 824 $lang_options[1]['lang_iso'] = $this->lang_defs['id'][$default_lang_id]; 825 $lang_options[1]['fields'][$field] = array( 826 'TITLE' => $user->lang['CP_' . strtoupper($field)], 827 'FIELD' => '<dd>' . ((is_array($cp->vars[$field])) ? implode('<br />', $cp->vars[$field]) : bbcode_nl2br($cp->vars[$field])) . '</dd>' 828 ); 829 830 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN'])) 831 { 832 $lang_options[1]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN']; 833 } 834 } 835 836 foreach ($languages as $lang_id => $lang_iso) 837 { 838 $lang_options[$lang_id]['lang_iso'] = $lang_iso; 839 foreach ($options as $field => $field_type) 840 { 841 $value = ($action == 'create') ? utf8_normalize_nfc(request_var('l_' . $field, array(0 => ''), true)) : $cp->vars['l_' . $field]; 842 if ($field == 'lang_options') 843 { 844 $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]; 845 846 switch ($field_type) 847 { 848 case 'two_options': 849 850 $lang_options[$lang_id]['fields'][$field] = array( 851 'TITLE' => $user->lang['CP_' . strtoupper($field)], 852 'FIELD' => ' 853 <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> 854 <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>' 855 ); 856 break; 857 858 case 'optionfield': 859 $value = ((isset($value[$lang_id])) ? ((is_array($value[$lang_id])) ? implode("\n", $value[$lang_id]) : $value[$lang_id]) : implode("\n", $var)); 860 $lang_options[$lang_id]['fields'][$field] = array( 861 'TITLE' => $user->lang['CP_' . strtoupper($field)], 862 'FIELD' => '<dd><textarea name="l_' . $field . '[' . $lang_id . ']" rows="7" cols="80">' . $value . '</textarea></dd>' 863 ); 864 break; 865 } 866 867 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN'])) 868 { 869 $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN']; 870 } 871 } 872 else 873 { 874 $var = ($action == 'create' || !is_array($cp->vars[$field])) ? $cp->vars[$field] : $cp->vars[$field][$lang_id]; 875 876 $lang_options[$lang_id]['fields'][$field] = array( 877 'TITLE' => $user->lang['CP_' . strtoupper($field)], 878 '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>' 879 ); 880 881 if (isset($user->lang['CP_' . strtoupper($field) . '_EXPLAIN'])) 882 { 883 $lang_options[$lang_id]['fields'][$field]['EXPLAIN'] = $user->lang['CP_' . strtoupper($field) . '_EXPLAIN']; 884 } 885 } 886 } 887 } 888 889 return $lang_options; 890 } 891 892 /** 893 * Save Profile Field 894 */ 895 function save_profile_field(&$cp, $field_type, $action = 'create') 896 { 897 global $db, $config, $user, $phpbb_container, $phpbb_dispatcher; 898 899 $field_id = request_var('field_id', 0); 900 901 // Collect all information, if something is going wrong, abort the operation 902 $profile_sql = $profile_lang = $empty_lang = $profile_lang_fields = array(); 903 904 $default_lang_id = (!empty($this->edit_lang_id)) ? $this->edit_lang_id : $this->lang_defs['iso'][$config['default_lang']]; 905 906 if ($action == 'create') 907 { 908 $sql = 'SELECT MAX(field_order) as max_field_order 909 FROM ' . PROFILE_FIELDS_TABLE; 910 $result = $db->sql_query($sql); 911 $new_field_order = (int) $db->sql_fetchfield('max_field_order'); 912 $db->sql_freeresult($result); 913 914 $field_ident = $cp->vars['field_ident']; 915 } 916 917 // Save the field 918 $profile_fields = array( 919 'field_length' => $cp->vars['field_length'], 920 'field_minlen' => $cp->vars['field_minlen'], 921 'field_maxlen' => $cp->vars['field_maxlen'], 922 'field_novalue' => $cp->vars['field_novalue'], 923 'field_default_value' => $cp->vars['field_default_value'], 924 'field_validation' => $cp->vars['field_validation'], 925 'field_required' => $cp->vars['field_required'], 926 'field_show_novalue' => $cp->vars['field_show_novalue'], 927 'field_show_on_reg' => $cp->vars['field_show_on_reg'], 928 'field_show_on_pm' => $cp->vars['field_show_on_pm'], 929 'field_show_on_vt' => $cp->vars['field_show_on_vt'], 930 'field_show_on_ml' => $cp->vars['field_show_on_ml'], 931 'field_hide' => $cp->vars['field_hide'], 932 'field_show_profile' => $cp->vars['field_show_profile'], 933 'field_no_view' => $cp->vars['field_no_view'], 934 'field_is_contact' => $cp->vars['field_is_contact'], 935 'field_contact_desc' => $cp->vars['field_contact_desc'], 936 'field_contact_url' => $cp->vars['field_contact_url'], 937 ); 938 939 $field_data = $cp->vars; 940 /** 941 * Event to modify profile field configuration data before saving to database 942 * 943 * @event core.acp_profile_create_edit_save_before 944 * @var string action create|edit 945 * @var string field_type Type of the field we are dealing with 946 * @var array field_data Array of data about the field 947 * @var array profile_fields Array of fields to be sent to the database 948 * @since 3.1.6-RC1 949 */ 950 $vars = array( 951 'action', 952 'field_type', 953 'field_data', 954 'profile_fields', 955 ); 956 extract($phpbb_dispatcher->trigger_event('core.acp_profile_create_edit_save_before', compact($vars))); 957 958 if ($action == 'create') 959 { 960 $profile_fields += array( 961 'field_type' => $field_type, 962 'field_ident' => $field_ident, 963 'field_name' => $field_ident, 964 'field_order' => $new_field_order + 1, 965 'field_active' => 1 966 ); 967 968 $sql = 'INSERT INTO ' . PROFILE_FIELDS_TABLE . ' ' . $db->sql_build_array('INSERT', $profile_fields); 969 $db->sql_query($sql); 970 971 $field_id = $db->sql_nextid(); 972 } 973 else 974 { 975 $sql = 'UPDATE ' . PROFILE_FIELDS_TABLE . ' 976 SET ' . $db->sql_build_array('UPDATE', $profile_fields) . " 977 WHERE field_id = $field_id"; 978 $db->sql_query($sql); 979 } 980 981 $profile_field = $this->type_collection[$field_type]; 982 983 if ($action == 'create') 984 { 985 $field_ident = 'pf_' . $field_ident; 986 987 $db_tools = $phpbb_container->get('dbal.tools'); 988 $db_tools->sql_column_add(PROFILE_FIELDS_DATA_TABLE, $field_ident, array($profile_field->get_database_column_type(), null)); 989 } 990 991 $sql_ary = array( 992 'lang_name' => $cp->vars['lang_name'], 993 'lang_explain' => $cp->vars['lang_explain'], 994 'lang_default_value' => $cp->vars['lang_default_value'] 995 ); 996 997 if ($action == 'create') 998 { 999 $sql_ary['field_id'] = $field_id; 1000 $sql_ary['lang_id'] = $default_lang_id; 1001 1002 $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); 1003 } 1004 else 1005 { 1006 $this->update_insert(PROFILE_LANG_TABLE, $sql_ary, array('field_id' => $field_id, 'lang_id' => $default_lang_id)); 1007 } 1008 1009 if (is_array($cp->vars['l_lang_name']) && sizeof($cp->vars['l_lang_name'])) 1010 { 1011 foreach ($cp->vars['l_lang_name'] as $lang_id => $data) 1012 { 1013 if (($cp->vars['lang_name'] != '' && $cp->vars['l_lang_name'][$lang_id] == '') 1014 || ($cp->vars['lang_explain'] != '' && $cp->vars['l_lang_explain'][$lang_id] == '') 1015 || ($cp->vars['lang_default_value'] != '' && $cp->vars['l_lang_default_value'][$lang_id] == '')) 1016 { 1017 $empty_lang[$lang_id] = true; 1018 break; 1019 } 1020 1021 if (!isset($empty_lang[$lang_id])) 1022 { 1023 $profile_lang[] = array( 1024 'field_id' => $field_id, 1025 'lang_id' => $lang_id, 1026 'lang_name' => $cp->vars['l_lang_name'][$lang_id], 1027 'lang_explain' => (isset($cp->vars['l_lang_explain'][$lang_id])) ? $cp->vars['l_lang_explain'][$lang_id] : '', 1028 'lang_default_value' => (isset($cp->vars['l_lang_default_value'][$lang_id])) ? $cp->vars['l_lang_default_value'][$lang_id] : '' 1029 ); 1030 } 1031 } 1032 1033 foreach ($empty_lang as $lang_id => $NULL) 1034 { 1035 $sql = 'DELETE FROM ' . PROFILE_LANG_TABLE . " 1036 WHERE field_id = $field_id 1037 AND lang_id = " . (int) $lang_id; 1038 $db->sql_query($sql); 1039 } 1040 } 1041 1042 $cp->vars = $profile_field->get_language_options_input($cp->vars); 1043 1044 if ($cp->vars['lang_options']) 1045 { 1046 if (!is_array($cp->vars['lang_options'])) 1047 { 1048 $cp->vars['lang_options'] = explode("\n", $cp->vars['lang_options']); 1049 } 1050 1051 if ($action != 'create') 1052 { 1053 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " 1054 WHERE field_id = $field_id 1055 AND lang_id = " . (int) $default_lang_id; 1056 $db->sql_query($sql); 1057 } 1058 1059 foreach ($cp->vars['lang_options'] as $option_id => $value) 1060 { 1061 $sql_ary = array( 1062 'field_type' => $field_type, 1063 'lang_value' => $value 1064 ); 1065 1066 if ($action == 'create') 1067 { 1068 $sql_ary['field_id'] = $field_id; 1069 $sql_ary['lang_id'] = $default_lang_id; 1070 $sql_ary['option_id'] = (int) $option_id; 1071 1072 $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); 1073 } 1074 else 1075 { 1076 $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql_ary, array( 1077 'field_id' => $field_id, 1078 'lang_id' => (int) $default_lang_id, 1079 'option_id' => (int) $option_id) 1080 ); 1081 } 1082 } 1083 } 1084 1085 if (is_array($cp->vars['l_lang_options']) && sizeof($cp->vars['l_lang_options'])) 1086 { 1087 $empty_lang = array(); 1088 1089 foreach ($cp->vars['l_lang_options'] as $lang_id => $lang_ary) 1090 { 1091 if (!is_array($lang_ary)) 1092 { 1093 $lang_ary = explode("\n", $lang_ary); 1094 } 1095 1096 if (sizeof($lang_ary) != sizeof($cp->vars['lang_options'])) 1097 { 1098 $empty_lang[$lang_id] = true; 1099 } 1100 1101 if (!isset($empty_lang[$lang_id])) 1102 { 1103 if ($action != 'create') 1104 { 1105 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " 1106 WHERE field_id = $field_id 1107 AND lang_id = " . (int) $lang_id; 1108 $db->sql_query($sql); 1109 } 1110 1111 foreach ($lang_ary as $option_id => $value) 1112 { 1113 $profile_lang_fields[] = array( 1114 'field_id' => (int) $field_id, 1115 'lang_id' => (int) $lang_id, 1116 'option_id' => (int) $option_id, 1117 'field_type' => $field_type, 1118 'lang_value' => $value 1119 ); 1120 } 1121 } 1122 } 1123 1124 foreach ($empty_lang as $lang_id => $NULL) 1125 { 1126 $sql = 'DELETE FROM ' . PROFILE_FIELDS_LANG_TABLE . " 1127 WHERE field_id = $field_id 1128 AND lang_id = " . (int) $lang_id; 1129 $db->sql_query($sql); 1130 } 1131 } 1132 1133 foreach ($profile_lang as $sql) 1134 { 1135 if ($action == 'create') 1136 { 1137 $profile_sql[] = 'INSERT INTO ' . PROFILE_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql); 1138 } 1139 else 1140 { 1141 $lang_id = $sql['lang_id']; 1142 unset($sql['lang_id'], $sql['field_id']); 1143 1144 $this->update_insert(PROFILE_LANG_TABLE, $sql, array('lang_id' => (int) $lang_id, 'field_id' => $field_id)); 1145 } 1146 } 1147 1148 if (sizeof($profile_lang_fields)) 1149 { 1150 foreach ($profile_lang_fields as $sql) 1151 { 1152 if ($action == 'create') 1153 { 1154 $profile_sql[] = 'INSERT INTO ' . PROFILE_FIELDS_LANG_TABLE . ' ' . $db->sql_build_array('INSERT', $sql); 1155 } 1156 else 1157 { 1158 $lang_id = $sql['lang_id']; 1159 $option_id = $sql['option_id']; 1160 unset($sql['lang_id'], $sql['field_id'], $sql['option_id']); 1161 1162 $this->update_insert(PROFILE_FIELDS_LANG_TABLE, $sql, array( 1163 'lang_id' => $lang_id, 1164 'field_id' => $field_id, 1165 'option_id' => $option_id) 1166 ); 1167 } 1168 } 1169 } 1170 1171 $db->sql_transaction('begin'); 1172 1173 if ($action == 'create') 1174 { 1175 foreach ($profile_sql as $sql) 1176 { 1177 $db->sql_query($sql); 1178 } 1179 } 1180 1181 $db->sql_transaction('commit'); 1182 1183 if ($action == 'edit') 1184 { 1185 add_log('admin', 'LOG_PROFILE_FIELD_EDIT', $cp->vars['field_ident'] . ':' . $cp->vars['lang_name']); 1186 trigger_error($user->lang['CHANGED_PROFILE_FIELD'] . adm_back_link($this->u_action)); 1187 } 1188 else 1189 { 1190 add_log('admin', 'LOG_PROFILE_FIELD_CREATE', substr($field_ident, 3) . ':' . $cp->vars['lang_name']); 1191 trigger_error($user->lang['ADDED_PROFILE_FIELD'] . adm_back_link($this->u_action)); 1192 } 1193 } 1194 1195 /** 1196 * Update, then insert if not successfull 1197 */ 1198 function update_insert($table, $sql_ary, $where_fields) 1199 { 1200 global $db; 1201 1202 $where_sql = array(); 1203 $check_key = ''; 1204 1205 foreach ($where_fields as $key => $value) 1206 { 1207 $check_key = (!$check_key) ? $key : $check_key; 1208 $where_sql[] = $key . ' = ' . ((is_string($value)) ? "'" . $db->sql_escape($value) . "'" : (int) $value); 1209 } 1210 1211 if (!sizeof($where_sql)) 1212 { 1213 return; 1214 } 1215 1216 $sql = "SELECT $check_key 1217 FROM $table 1218 WHERE " . implode(' AND ', $where_sql); 1219 $result = $db->sql_query($sql); 1220 $row = $db->sql_fetchrow($result); 1221 $db->sql_freeresult($result); 1222 1223 if (!$row) 1224 { 1225 $sql_ary = array_merge($where_fields, $sql_ary); 1226 1227 if (sizeof($sql_ary)) 1228 { 1229 $db->sql_query("INSERT INTO $table " . $db->sql_build_array('INSERT', $sql_ary)); 1230 } 1231 } 1232 else 1233 { 1234 if (sizeof($sql_ary)) 1235 { 1236 $sql = "UPDATE $table SET " . $db->sql_build_array('UPDATE', $sql_ary) . ' 1237 WHERE ' . implode(' AND ', $where_sql); 1238 $db->sql_query($sql); 1239 } 1240 } 1241 } 1242 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |