[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/admin/modules/config/ -> profile_fields.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  // Disallow direct access to this file for security reasons
  13  if(!defined("IN_MYBB"))
  14  {
  15      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  16  }
  17  
  18  $page->add_breadcrumb_item($lang->custom_profile_fields, "index.php?module=config-profile_fields");
  19  
  20  $plugins->run_hooks("admin_config_profile_fields_begin");
  21  
  22  if($mybb->input['action'] == "add")
  23  {
  24      $plugins->run_hooks("admin_config_profile_fields_add");
  25      
  26      if($mybb->request_method == "post")
  27      {
  28          if(!trim($mybb->input['name']))
  29          {
  30              $errors[] = $lang->error_missing_name;
  31          }
  32  
  33          if(!trim($mybb->input['description']))
  34          {
  35              $errors[] = $lang->error_missing_description;
  36          }
  37  
  38          if(!trim($mybb->input['fieldtype']))
  39          {
  40              $errors[] = $lang->error_missing_fieldtype;
  41          }
  42          
  43          if(!$errors)
  44          {
  45              $type = $mybb->input['fieldtype'];
  46              $options = preg_replace("#(\r\n|\r|\n)#s", "\n", trim($mybb->input['options']));
  47              if($type != "text" && $type != "textarea")
  48              {
  49                  $thing = "$type\n$options";
  50              }
  51              else
  52              {
  53                  $thing = $type;
  54              }
  55      
  56              $new_profile_field = array(
  57                  "name" => $db->escape_string($mybb->input['name']),
  58                  "description" => $db->escape_string($mybb->input['description']),
  59                  "disporder" => intval($mybb->input['disporder']),
  60                  "type" => $db->escape_string($thing),
  61                  "length" => intval($mybb->input['length']),
  62                  "maxlength" => intval($mybb->input['maxlength']),
  63                  "required" => $db->escape_string($mybb->input['required']),
  64                  "editable" => $db->escape_string($mybb->input['editable']),
  65                  "hidden" => $db->escape_string($mybb->input['hidden']),
  66                  "postnum" => intval($mybb->input['postnum'])
  67              );
  68              
  69              $fid = $db->insert_query("profilefields", $new_profile_field);
  70              
  71              $db->write_query("ALTER TABLE ".TABLE_PREFIX."userfields ADD fid{$fid} TEXT");
  72              
  73              $plugins->run_hooks("admin_config_profile_fields_add_commit");
  74  
  75              // Log admin action
  76              log_admin_action($fid, $mybb->input['name']);
  77                      
  78              flash_message($lang->success_profile_field_added, 'success');
  79              admin_redirect("index.php?module=config-profile_fields");
  80          }
  81      }
  82      
  83      $page->add_breadcrumb_item($lang->add_new_profile_field);
  84      $page->output_header($lang->custom_profile_fields." - ".$lang->add_new_profile_field);
  85      
  86      $sub_tabs['custom_profile_fields'] = array(
  87          'title' => $lang->custom_profile_fields,
  88          'link' => "index.php?module=config-profile_fields"
  89      );
  90      
  91      $sub_tabs['add_profile_field'] = array(
  92          'title' => $lang->add_new_profile_field,
  93          'link' => "index.php?module=config-profile_fields&amp;action=add",
  94          'description' => $lang->add_new_profile_field_desc
  95      );
  96      
  97      $page->output_nav_tabs($sub_tabs, 'add_profile_field');
  98      $form = new Form("index.php?module=config-profile_fields&amp;action=add", "post", "add");
  99      
 100      if($errors)
 101      {
 102          $page->output_inline_error($errors);
 103      }
 104      else
 105      {
 106          $mybb->input['fieldtype'] = 'textbox';
 107          $mybb->input['required'] = 0;
 108          $mybb->input['editable'] = 1;
 109          $mybb->input['hidden'] = 0;
 110      }
 111      
 112      $form_container = new FormContainer($lang->add_new_profile_field);
 113      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name');
 114      $form_container->output_row($lang->short_description." <em>*</em>", "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 115      $select_list = array(
 116          "text" => $lang->text,
 117          "textarea" => $lang->textarea,
 118          "select" => $lang->select,
 119          "multiselect" => $lang->multiselect,
 120          "radio" => $lang->radio,
 121          "checkbox" => $lang->checkbox
 122      );
 123      $form_container->output_row($lang->field_type." <em>*</em>", $lang->field_type_desc, $form->generate_select_box('fieldtype', $select_list, $mybb->input['fieldtype'], array('id' => 'fieldtype')), 'fieldtype');
 124      $form_container->output_row($lang->maximum_length, $lang->maximum_length_desc, $form->generate_text_box('maxlength', $mybb->input['maxlength'], array('id' => 'maxlength')), 'maxlength', array(), array('id' => 'row_maxlength'));
 125      $form_container->output_row($lang->field_length, $lang->field_length_desc, $form->generate_text_box('length', $mybb->input['length'], array('id' => 'length')), 'length', array(), array('id' => 'row_fieldlength'));
 126      $form_container->output_row($lang->selectable_options, $lang->selectable_options_desc, $form->generate_text_area('options', $mybb->input['options'], array('id' => 'options')), 'options', array(), array('id' => 'row_options'));
 127      $form_container->output_row($lang->display_order." <em>*</em>", $lang->display_order_desc, $form->generate_text_box('disporder', $mybb->input['disporder'], array('id' => 'disporder')), 'disporder');
 128      $form_container->output_row($lang->required." <em>*</em>", $lang->required_desc, $form->generate_yes_no_radio('required', $mybb->input['required']));
 129      $form_container->output_row($lang->editable_by_user." <em>*</em>", $lang->editable_by_user_desc, $form->generate_yes_no_radio('editable', $mybb->input['editable']));
 130      $form_container->output_row($lang->hide_on_profile." <em>*</em>", $lang->hide_on_profile_desc, $form->generate_yes_no_radio('hidden', $mybb->input['hidden']));
 131      $form_container->output_row($lang->min_posts_enabled, $lang->min_posts_enabled_desc, $form->generate_text_box('postnum', $mybb->input['postnum'], array('id' => 'postnum')), 'postnum');
 132      $form_container->end();
 133  
 134      $buttons[] = $form->generate_submit_button($lang->save_profile_field);
 135  
 136      $form->output_submit_wrapper($buttons);
 137      $form->end();
 138  
 139      echo '<script type="text/javascript" src="./jscripts/peeker.js"></script>
 140      <script type="text/javascript">
 141          Event.observe(window, "load", function() {
 142                  var maxlength_peeker = new Peeker($("fieldtype"), $("row_maxlength"), /text|textarea/, false);
 143                  var fieldlength_peeker = new Peeker($("fieldtype"), $("row_fieldlength"), /select|multiselect/, false);
 144                  var options_peeker = new Peeker($("fieldtype"), $("row_options"), /select|radio|checkbox/, false);
 145                  // Add a star to the extra row since the "extra" is required if the box is shown
 146                  add_star("row_maxlength");
 147                  add_star("row_fieldlength");
 148                  add_star("row_options");
 149          });
 150      </script>';
 151      
 152      $page->output_footer();
 153  }
 154  
 155  if($mybb->input['action'] == "edit")
 156  {
 157      $plugins->run_hooks("admin_config_profile_fields_edit");
 158      
 159      $query = $db->simple_select("profilefields", "*", "fid = '".intval($mybb->input['fid'])."'");
 160      $profile_field = $db->fetch_array($query);
 161      
 162      if(!$profile_field['fid'])
 163      {
 164          flash_message($lang->error_invalid_fid, 'error');
 165          admin_redirect("index.php?module=config-profile_fields");
 166      }
 167          
 168      if($mybb->request_method == "post")
 169      {
 170          if(!trim($mybb->input['name']))
 171          {
 172              $errors[] = $lang->error_missing_name;
 173          }
 174  
 175          if(!trim($mybb->input['description']))
 176          {
 177              $errors[] = $lang->error_missing_description;
 178          }
 179  
 180          if(!trim($mybb->input['fieldtype']))
 181          {
 182              $errors[] = $lang->error_missing_fieldtype;
 183          }
 184          
 185          $type = $mybb->input['fieldtype'];
 186          $options = preg_replace("#(\r\n|\r|\n)#s", "\n", trim($mybb->input['options']));
 187          if($type != "text" && $type != "textarea")
 188          {
 189              $type = "$type\n$options";
 190          }
 191          
 192          if(!$errors)
 193          {
 194              $updated_profile_field = array(
 195                  "name" => $db->escape_string($mybb->input['name']),
 196                  "description" => $db->escape_string($mybb->input['description']),
 197                  "disporder" => intval($mybb->input['disporder']),
 198                  "type" => $db->escape_string($type),
 199                  "length" => intval($mybb->input['length']),
 200                  "maxlength" => intval($mybb->input['maxlength']),
 201                  "required" => $db->escape_string($mybb->input['required']),
 202                  "editable" => $db->escape_string($mybb->input['editable']),
 203                  "hidden" => $db->escape_string($mybb->input['hidden']),
 204                  "postnum" => intval($mybb->input['postnum'])
 205              );
 206              
 207              $db->update_query("profilefields", $updated_profile_field, "fid = '".intval($mybb->input['fid'])."'");
 208              
 209              $plugins->run_hooks("admin_config_profile_fields_edit_commit");
 210              
 211              // Log admin action
 212              log_admin_action($profile_field['fid'], $mybb->input['name']);
 213  
 214              flash_message($lang->success_profile_field_saved, 'success');
 215              admin_redirect("index.php?module=config-profile_fields");
 216          }
 217      }
 218      
 219      $page->add_breadcrumb_item($lang->edit_profile_field);
 220      $page->output_header($lang->custom_profile_fields." - ".$lang->edit_profile_field);
 221      
 222      $sub_tabs['edit_profile_field'] = array(
 223          'title' => $lang->edit_profile_field,
 224          'link' => "index.php?module=config-profile_fields&amp;action=edit&amp;fid=".intval($mybb->input['fid']),
 225          'description' => $lang->edit_profile_field_desc
 226      );
 227      
 228      $page->output_nav_tabs($sub_tabs, 'edit_profile_field');
 229      $form = new Form("index.php?module=config-profile_fields&amp;action=edit", "post", "edit");
 230      
 231      
 232      echo $form->generate_hidden_field("fid", $profile_field['fid']);
 233      
 234      if($errors)
 235      {
 236          $page->output_inline_error($errors);
 237      }
 238      else
 239      {
 240          $type = explode("\n", $profile_field['type'], "2");
 241      
 242          $mybb->input = $profile_field;
 243          $mybb->input['fieldtype'] = $type[0];
 244          $mybb->input['options'] = $type[1];
 245      }
 246      
 247      $form_container = new FormContainer($lang->edit_profile_field);
 248      $form_container->output_row($lang->title." <em>*</em>", "", $form->generate_text_box('name', $mybb->input['name'], array('id' => 'name')), 'name');
 249      $form_container->output_row($lang->short_description." <em>*</em>", "", $form->generate_text_box('description', $mybb->input['description'], array('id' => 'description')), 'description');
 250      $select_list = array(
 251          "text" => $lang->text,
 252          "textarea" => $lang->textarea,
 253          "select" => $lang->select,
 254          "multiselect" => $lang->multiselect,
 255          "radio" => $lang->radio,
 256          "checkbox" => $lang->checkbox
 257      );
 258      $form_container->output_row($lang->field_type." <em>*</em>", $lang->field_type_desc, $form->generate_select_box('fieldtype', $select_list, $mybb->input['fieldtype'], array('id' => 'fieldtype')), 'fieldtype');
 259      $form_container->output_row($lang->maximum_length, $lang->maximum_length_desc, $form->generate_text_box('maxlength', $mybb->input['maxlength'], array('id' => 'maxlength')), 'maxlength', array(), array('id' => 'row_maxlength'));
 260      $form_container->output_row($lang->field_length, $lang->field_length_desc, $form->generate_text_box('length', $mybb->input['length'], array('id' => 'length')), 'length', array(), array('id' => 'row_fieldlength'));
 261      $form_container->output_row($lang->selectable_options, $lang->selectable_options_desc, $form->generate_text_area('options', $mybb->input['options'], array('id' => 'options')), 'options', array(), array('id' => 'row_options'));
 262      $form_container->output_row($lang->display_order." <em>*</em>", $lang->display_order_desc, $form->generate_text_box('disporder', $mybb->input['disporder'], array('id' => 'disporder')), 'disporder');
 263      $form_container->output_row($lang->required." <em>*</em>", $lang->required_desc, $form->generate_yes_no_radio('required', $mybb->input['required']));
 264      $form_container->output_row($lang->editable_by_user." <em>*</em>", $lang->editable_by_user_desc, $form->generate_yes_no_radio('editable', $mybb->input['editable']));
 265      $form_container->output_row($lang->hide_on_profile." <em>*</em>", $lang->hide_on_profile_desc, $form->generate_yes_no_radio('hidden', $mybb->input['hidden']));
 266      $form_container->output_row($lang->min_posts_enabled, $lang->min_posts_enabled_desc, $form->generate_text_box('postnum', $mybb->input['postnum'], array('id' => 'postnum')), 'postnum');
 267      $form_container->end();
 268  
 269      $buttons[] = $form->generate_submit_button($lang->save_profile_field);
 270  
 271      $form->output_submit_wrapper($buttons);
 272      $form->end();
 273  
 274      echo '<script type="text/javascript" src="./jscripts/peeker.js"></script>
 275      <script type="text/javascript">
 276          Event.observe(window, "load", function() {
 277                  var maxlength_peeker = new Peeker("fieldtype", "row_maxlength", /text|textarea/);
 278                  var fieldlength_peeker = new Peeker("fieldtype", "row_fieldlength", /select|multiselect/);
 279                  var options_peeker = new Peeker("fieldtype", "row_options", /select|radio|checkbox/);
 280                  // Add a star to the extra row since the "extra" is required if the box is shown
 281                  add_star("row_maxlength");
 282                  add_star("row_fieldlength");
 283                  add_star("row_options");
 284          });
 285      </script>';
 286      
 287      $page->output_footer();
 288  }
 289  
 290  if($mybb->input['action'] == "delete")
 291  {
 292      $plugins->run_hooks("admin_config_profile_fields_delete");
 293      
 294      $query = $db->simple_select("profilefields", "*", "fid='".intval($mybb->input['fid'])."'");
 295      $profile_field = $db->fetch_array($query);
 296      
 297      // Does the profile field not exist?
 298      if(!$profile_field['fid'])
 299      {
 300          flash_message($lang->error_invalid_fid, 'error');
 301          admin_redirect("index.php?module=config-profile_fields");
 302      }
 303  
 304      // User clicked no
 305      if($mybb->input['no'])
 306      {
 307          admin_redirect("index.php?module=config-profile_fields");
 308      }
 309  
 310      if($mybb->request_method == "post")
 311      {
 312          // Delete the profile field
 313          $db->delete_query("profilefields", "fid='{$profile_field['fid']}'");
 314          $db->write_query("ALTER TABLE ".TABLE_PREFIX."userfields DROP fid{$profile_field['fid']}");
 315          
 316          $plugins->run_hooks("admin_config_profile_fields_delete_commit");
 317  
 318          // Log admin action
 319          log_admin_action($profile_field['fid'], $profile_field['name']);
 320  
 321          flash_message($lang->success_profile_field_deleted, 'success');
 322          admin_redirect("index.php?module=config-profile_fields");
 323      }
 324      else
 325      {
 326          $page->output_confirm_action("index.php?module=config-profile_fields&amp;action=delete&amp;fid={$profile_field['fid']}", $lang->confirm_profile_field_deletion);
 327      }
 328  }
 329  
 330  if(!$mybb->input['action'])
 331  {
 332      $plugins->run_hooks("admin_config_profile_fields_start");
 333      
 334      $page->output_header($lang->custom_profile_fields);
 335  
 336      $sub_tabs['custom_profile_fields'] = array(
 337          'title' => $lang->custom_profile_fields,
 338          'link' => "index.php?module=config-profile_fields",
 339          'description' => $lang->custom_profile_fields_desc
 340      );
 341      
 342      $sub_tabs['add_profile_field'] = array(
 343          'title' => $lang->add_new_profile_field,
 344          'link' => "index.php?module=config-profile_fields&amp;action=add",
 345      );
 346  
 347      
 348      $page->output_nav_tabs($sub_tabs, 'custom_profile_fields');
 349      
 350      $table = new Table;
 351      $table->construct_header($lang->name);
 352      $table->construct_header($lang->id, array("class" => "align_center"));
 353      $table->construct_header($lang->required, array("class" => "align_center"));
 354      $table->construct_header($lang->editable, array("class" => "align_center"));
 355      $table->construct_header($lang->hidden, array("class" => "align_center"));
 356      $table->construct_header($lang->controls, array("class" => "align_center"));
 357      
 358      $query = $db->simple_select("profilefields", "*", "", array('order_by' => 'disporder'));
 359      while($field = $db->fetch_array($query))
 360      {
 361          if($field['required'])
 362          {
 363              $required = $lang->yes;
 364          }
 365          else
 366          {
 367              $required = $lang->no;
 368          }
 369  
 370          if($field['editable'])
 371          {
 372              $editable = $lang->yes;
 373          }
 374          else
 375          {
 376              $editable = $lang->no;
 377          }
 378  
 379          if($field['hidden'])
 380          {
 381              $hidden = $lang->yes;
 382          }
 383          else
 384          {
 385              $hidden = $lang->no;
 386          }
 387  
 388          $table->construct_cell("<strong><a href=\"index.php?module=config-profile_fields&amp;action=edit&amp;fid={$field['fid']}\">".htmlspecialchars_uni($field['name'])."</a></strong><br /><small>".htmlspecialchars_uni($field['description'])."</small>", array('width' => '45%'));
 389          $table->construct_cell($field['fid'], array("class" => "align_center", 'width' => '5%'));
 390          $table->construct_cell($required, array("class" => "align_center", 'width' => '10%'));
 391          $table->construct_cell($editable, array("class" => "align_center", 'width' => '10%'));        
 392          $table->construct_cell($hidden, array("class" => "align_center", 'width' => '10%'));
 393          
 394          $popup = new PopupMenu("field_{$field['fid']}", $lang->options);
 395          $popup->add_item($lang->edit_field, "index.php?module=config-profile_fields&amp;action=edit&amp;fid={$field['fid']}");
 396          $popup->add_item($lang->delete_field, "index.php?module=config-profile_fields&amp;action=delete&amp;fid={$field['fid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_profile_field_deletion}')");
 397          $table->construct_cell($popup->fetch(), array("class" => "align_center", 'width' => '20%'));
 398          $table->construct_row();
 399      }
 400      
 401      if($table->num_rows() == 0)
 402      {
 403          $table->construct_cell($lang->no_profile_fields, array('colspan' => 6));
 404          $table->construct_row();
 405      }
 406      
 407      $table->output($lang->custom_profile_fields);
 408      
 409      $page->output_footer();
 410  }
 411  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1