[ Index ]

PHP Cross Reference of MyBB 1.8.32

title

Body

[close]

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

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  // Disallow direct access to this file for security reasons
  12  if(!defined("IN_MYBB"))
  13  {
  14      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15  }
  16  
  17  $page->add_breadcrumb_item($lang->security_questions, "index.php?module=config-questions");
  18  
  19  $plugins->run_hooks("admin_config_questions_begin");
  20  
  21  if($mybb->input['action'] == "add")
  22  {
  23      $plugins->run_hooks("admin_config_questions_add");
  24  
  25      if($mybb->request_method == "post")
  26      {
  27          if(!trim($mybb->input['question']))
  28          {
  29              $errors[] = $lang->error_missing_question;
  30          }
  31  
  32          if(!trim($mybb->input['answer']))
  33          {
  34              $errors[] = $lang->error_missing_answer;
  35          }
  36  
  37          if(!$errors)
  38          {
  39              if(!isset($mybb->input['preview']))
  40              {
  41                  $answer = preg_replace("#(\r\n|\r|\n)#s", "\n", trim($mybb->input['answer']));
  42  
  43                  $new_question = array(
  44                      "question" => $db->escape_string($mybb->input['question']),
  45                      "answer" => $db->escape_string($answer),
  46                      "active" => $mybb->get_input('active', MyBB::INPUT_INT)
  47                  );
  48                  $qid = $db->insert_query("questions", $new_question);
  49  
  50                  $plugins->run_hooks("admin_config_questions_add_commit");
  51  
  52                  // Log admin action
  53                  log_admin_action($qid, $mybb->input['question']);
  54  
  55                  flash_message($lang->success_question_created, 'success');
  56                  admin_redirect("index.php?module=config-questions");
  57              }
  58          }
  59      }
  60  
  61      $page->add_breadcrumb_item($lang->add_new_question);
  62      $page->output_header($lang->security_questions." - ".$lang->add_new_question);
  63  
  64      $sub_tabs['security_questions'] = array(
  65          'title' => $lang->security_questions,
  66          'link' => "index.php?module=config-questions"
  67      );
  68  
  69      $sub_tabs['add_new_question'] = array(
  70          'title' => $lang->add_new_question,
  71          'link' => "index.php?module=config-questions&amp;action=add",
  72          'description' => $lang->add_new_question_desc
  73      );
  74  
  75      $page->output_nav_tabs($sub_tabs, 'add_new_question');
  76      
  77      if(isset($mybb->input['preview']) && !$errors)
  78      {
  79          $table = new Table();
  80  
  81          require_once  MYBB_ROOT."inc/class_parser.php";
  82          $parser = new postParser;
  83  
  84          $parser_options = array(
  85              "allow_html" => 0,
  86              "allow_mycode" => 1,
  87              "allow_smilies" => 1,
  88              "allow_imgcode" => 1,
  89              "allow_videocode" => 1,
  90              "filter_badwords" => 1,
  91              "me_username" => 0,
  92              "shorten_urls" => 0,
  93              "highlight" => 0,
  94          );    
  95  
  96          $table->construct_cell($parser->parse_message($mybb->input['question'], $parser_options));
  97          $table->construct_row();
  98          $table->output($lang->preview_question);
  99      }
 100  
 101      $form = new Form("index.php?module=config-questions&amp;action=add", "post", "add");
 102  
 103      if($errors)
 104      {
 105          $page->output_inline_error($errors);
 106      }
 107      else
 108      {
 109          $mybb->input['active'] = '1';
 110      }
 111  
 112      $form_container = new FormContainer($lang->add_new_question);
 113      $form_container->output_row($lang->question." <em>*</em>", $lang->question_desc, $form->generate_text_area('question', $mybb->get_input('question'), array('id' => 'question')), 'question');
 114      $form_container->output_row($lang->answers." <em>*</em>", $lang->answers_desc, $form->generate_text_area('answer', $mybb->get_input('answer'), array('id' => 'answer')), 'answer');
 115      $form_container->output_row($lang->active." <em>*</em>", "", $form->generate_yes_no_radio('active', $mybb->input['active']));
 116      $form_container->end();
 117  
 118      $buttons[] = $form->generate_submit_button($lang->save_question);
 119      $buttons[] = $form->generate_submit_button($lang->preview_question, array('name' => 'preview'));
 120  
 121      $form->output_submit_wrapper($buttons);
 122      $form->end();
 123  
 124      $page->output_footer();
 125  }
 126  
 127  if($mybb->input['action'] == "edit")
 128  {
 129      $query = $db->simple_select("questions", "*", "qid='".$mybb->get_input('qid', MyBB::INPUT_INT)."'");
 130      $question = $db->fetch_array($query);
 131  
 132      if(!$question['qid'])
 133      {
 134          flash_message($lang->error_invalid_question, 'error');
 135          admin_redirect("index.php?module=config-questions");
 136      }
 137  
 138      $plugins->run_hooks("admin_config_questions_edit");
 139  
 140      if($mybb->request_method == "post")
 141      {
 142          if(!trim($mybb->input['question']))
 143          {
 144              $errors[] = $lang->error_missing_question;
 145          }
 146  
 147          if(!trim($mybb->input['answer']))
 148          {
 149              $errors[] = $lang->error_missing_answer;
 150          }
 151  
 152          if(!$errors)
 153          {
 154              if(!isset($mybb->input['preview']))
 155              {
 156                  $answer = preg_replace("#(\r\n|\r|\n)#s", "\n", trim($mybb->input['answer']));
 157  
 158                  $updated_question = array(
 159                      "question" => $db->escape_string($mybb->input['question']),
 160                      "answer" => $db->escape_string($answer),
 161                      "active" => $mybb->get_input('active', MyBB::INPUT_INT)
 162                  );
 163  
 164                  $plugins->run_hooks("admin_config_questions_edit_commit");
 165  
 166                  $db->update_query("questions", $updated_question, "qid='{$question['qid']}'");
 167  
 168                  // Log admin action
 169                  log_admin_action($question['qid'], $mybb->input['question']);
 170  
 171                  flash_message($lang->success_question_updated, 'success');
 172                  admin_redirect("index.php?module=config-questions");
 173              }
 174          }
 175      }
 176  
 177      $page->add_breadcrumb_item($lang->edit_question);
 178      $page->output_header($lang->security_questions." - ".$lang->edit_question);
 179      
 180      $sub_tabs['edit_question'] = array(
 181          'title' => $lang->edit_question,
 182          'link' => "index.php?module=config-questions&amp;action=edit&amp;qid={$question['qid']}",
 183          'description' => $lang->edit_question_desc
 184      );
 185  
 186      $page->output_nav_tabs($sub_tabs, 'edit_question');
 187      
 188      $form = new Form("index.php?module=config-questions&amp;action=edit&amp;qid={$question['qid']}", "post", "add");
 189  
 190      $show_preview = false;
 191      if(isset($mybb->input['preview_list']))
 192      {
 193          $show_preview = true;
 194      }
 195      
 196      if($errors)
 197      {
 198          $page->output_inline_error($errors);
 199      }
 200      else
 201      {
 202          if(!isset($mybb->input['preview']))
 203          {
 204              $mybb->input = $question;
 205          }
 206      }
 207      
 208      if((isset($mybb->input['preview']) || $show_preview === true) && !$errors)
 209      {
 210          $table = new Table();
 211  
 212          require_once  MYBB_ROOT."inc/class_parser.php";
 213          $parser = new postParser;
 214  
 215          $parser_options = array(
 216              "allow_html" => 0,
 217              "allow_mycode" => 1,
 218              "allow_smilies" => 1,
 219              "allow_imgcode" => 1,
 220              "allow_videocode" => 1,
 221              "filter_badwords" => 1,
 222              "me_username" => 0,
 223              "shorten_urls" => 0,
 224              "highlight" => 0,
 225          );    
 226  
 227          $table->construct_cell($parser->parse_message($mybb->input['question'], $parser_options));
 228          $table->construct_row();
 229          $table->output($lang->preview_question);
 230      }
 231      
 232      $form_container = new FormContainer($lang->edit_question);
 233      $form_container->output_row($lang->question." <em>*</em>", $lang->question_desc, $form->generate_text_area('question', $mybb->input['question'], array('id' => 'question')), 'question');
 234      $form_container->output_row($lang->answers." <em>*</em>", $lang->answers_desc, $form->generate_text_area('answer', $mybb->input['answer'], array('id' => 'answer')), 'answer');
 235      $form_container->output_row($lang->active." <em>*</em>", "", $form->generate_yes_no_radio('active', $mybb->input['active']));
 236      $form_container->end();
 237  
 238      $buttons[] = $form->generate_submit_button($lang->save_question);
 239      $buttons[] = $form->generate_submit_button($lang->preview_question, array('name' => 'preview'));
 240  
 241      $form->output_submit_wrapper($buttons);
 242      $form->end();
 243  
 244      $page->output_footer();
 245  }
 246  
 247  
 248  if($mybb->input['action'] == "delete")
 249  {
 250      if($mybb->get_input('no'))
 251      {
 252          admin_redirect("index.php?module=config-questions");
 253      }
 254  
 255      $query = $db->simple_select("questions", "*", "qid='".$mybb->get_input('qid', MyBB::INPUT_INT)."'");
 256      $question = $db->fetch_array($query);
 257  
 258      if(!$question['qid'])
 259      {
 260          flash_message($lang->error_invalid_question, 'error');
 261          admin_redirect("index.php?module=config-questions");
 262      }
 263  
 264      $plugins->run_hooks("admin_config_questions_delete");
 265  
 266      if($mybb->request_method == "post")
 267      {
 268          $db->delete_query("questions", "qid='{$question['qid']}'");
 269          $db->delete_query("questionsessions", "qid='{$question['qid']}'");
 270  
 271          $plugins->run_hooks("admin_config_questions_delete_commit");
 272  
 273          // Log admin action
 274          log_admin_action($question['qid'], $question['question']);
 275  
 276          flash_message($lang->success_question_deleted, 'success');
 277          admin_redirect("index.php?module=config-questions");
 278      }
 279      else
 280      {
 281          $page->output_confirm_action("index.php?module=config-questions&amp;action=delete&amp;qid={$question['qid']}", $lang->confirm_question_deletion);
 282      }
 283  }
 284  
 285  if($mybb->input['action'] == "disable")
 286  {
 287      $query = $db->simple_select("questions", "*", "qid='".$mybb->get_input('qid', MyBB::INPUT_INT)."'");
 288      $question = $db->fetch_array($query);
 289  
 290      if(!$question['qid'])
 291      {
 292          flash_message($lang->error_invalid_question, 'error');
 293          admin_redirect("index.php?module=config-questions");
 294      }
 295  
 296      $plugins->run_hooks("admin_config_questions_disable");
 297  
 298      $update_question = array(
 299          "active" => 0
 300      );
 301  
 302      $plugins->run_hooks("admin_config_questions_disable_commit");
 303  
 304      $db->update_query("questions", $update_question, "qid = '{$question['qid']}'");
 305  
 306      // Log admin action
 307      log_admin_action($question['qid'], $question['question']);
 308  
 309      flash_message($lang->success_question_disabled, 'success');
 310      admin_redirect("index.php?module=config-questions");
 311  }
 312  
 313  if($mybb->input['action'] == "enable")
 314  {
 315      $query = $db->simple_select("questions", "*", "qid='".$mybb->get_input('qid', MyBB::INPUT_INT)."'");
 316      $question = $db->fetch_array($query);
 317  
 318      if(!$question['qid'])
 319      {
 320          flash_message($lang->error_invalid_question, 'error');
 321          admin_redirect("index.php?module=config-questions");
 322      }
 323  
 324      $plugins->run_hooks("admin_config_questions_enable");
 325  
 326      $update_question = array(
 327          "active" => 1
 328      );
 329  
 330      $plugins->run_hooks("admin_config_questions_enable_commit");
 331  
 332      $db->update_query("questions", $update_question, "qid = '{$question['qid']}'");
 333  
 334      // Log admin action
 335      log_admin_action($question['qid'], $question['question']);
 336  
 337      flash_message($lang->success_question_enabled, 'success');
 338      admin_redirect("index.php?module=config-questions");
 339  }
 340  
 341  if(!$mybb->input['action'])
 342  {
 343      $plugins->run_hooks("admin_config_questions_start");
 344  
 345      $page->output_header($lang->security_questions);
 346  
 347      $sub_tabs['security_questions'] = array(
 348          'title' => $lang->security_questions,
 349          'link' => "index.php?module=config-questions",
 350          'description' => $lang->security_questions_desc
 351      );
 352      $sub_tabs['add_new_question'] = array(
 353          'title' => $lang->add_new_question,
 354          'link' => "index.php?module=config-questions&amp;action=add",
 355      );
 356  
 357      $page->output_nav_tabs($sub_tabs, 'security_questions');
 358  
 359      $query = $db->simple_select("questions", "COUNT(qid) AS questions");
 360      $total_rows = $db->fetch_field($query, "questions");
 361  
 362      $pagenum = $mybb->get_input('page', MyBB::INPUT_INT);
 363      if($pagenum)
 364      {
 365          $start = ($pagenum - 1) * 20;
 366          $pages = ceil($total_rows / 20);
 367          if($pagenum > $pages)
 368          {
 369              $start = 0;
 370              $pagenum = 1;
 371          }
 372      }
 373      else
 374      {
 375          $start = 0;
 376          $pagenum = 1;
 377      }
 378  
 379      $table = new Table;
 380      $table->construct_header($lang->question);
 381      $table->construct_header($lang->answers, array("width" => "35%"));
 382      $table->construct_header($lang->shown, array("width" => "5%", "class" => "align_center"));
 383      $table->construct_header($lang->correct, array("width" => "5%", "class" => "align_center"));
 384      $table->construct_header($lang->incorrect, array("width" => "5%", "class" => "align_center"));
 385      $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150));
 386  
 387      $query = $db->simple_select("questions", "*", "", array('limit_start' => $start, 'limit' => 20, 'order_by' => 'question'));
 388      while($questions = $db->fetch_array($query))
 389      {
 390          $questions['question'] = htmlspecialchars_uni($questions['question']);
 391          $questions['answer'] = htmlspecialchars_uni($questions['answer']);
 392          $questions['answer'] = preg_replace("#(\n)#s", "<br />", trim($questions['answer']));
 393          $questions['shown'] = my_number_format($questions['shown']);
 394          $questions['correct'] = my_number_format($questions['correct']);
 395          $questions['incorrect'] = my_number_format($questions['incorrect']);
 396  
 397          if($questions['active'] == 1)
 398          {
 399              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.png\" alt=\"({$lang->alt_enabled})\" title=\"{$lang->alt_enabled}\"  style=\"vertical-align: middle;\" /> ";
 400          }
 401          else
 402          {
 403              $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.png\" alt=\"({$lang->alt_disabled})\" title=\"{$lang->alt_disabled}\"  style=\"vertical-align: middle;\" /> ";
 404          }
 405  
 406          $table->construct_cell("<div>{$icon}{$questions['question']}</div>");
 407          $table->construct_cell($questions['answer']);
 408          $table->construct_cell($questions['shown'], array("class" => "align_center"));
 409          $table->construct_cell($questions['correct'], array("class" => "align_center"));
 410          $table->construct_cell($questions['incorrect'], array("class" => "align_center"));
 411          $popup = new PopupMenu("questions_{$questions['qid']}", $lang->options);
 412          $popup->add_item($lang->edit_question, "index.php?module=config-questions&amp;action=edit&amp;qid={$questions['qid']}");
 413          $popup->add_item($lang->preview_question, "index.php?module=config-questions&amp;action=edit&amp;qid={$questions['qid']}&amp;preview_list");
 414          if($questions['active'] == 1)
 415          {
 416              $popup->add_item($lang->disable_question, "index.php?module=config-questions&amp;action=disable&amp;qid={$questions['qid']}&amp;my_post_key={$mybb->post_code}");
 417          }
 418          else
 419          {
 420              $popup->add_item($lang->enable_question, "index.php?module=config-questions&amp;action=enable&amp;qid={$questions['qid']}&amp;my_post_key={$mybb->post_code}");
 421          }
 422          $popup->add_item($lang->delete_question, "index.php?module=config-questions&amp;action=delete&amp;qid={$questions['qid']}&amp;my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_question_deletion}')");
 423          $table->construct_cell($popup->fetch(), array("class" => "align_center"));
 424          $table->construct_row();
 425      }
 426  
 427      if($table->num_rows() == 0)
 428      {
 429          $table->construct_cell($lang->no_security_questions, array('colspan' => 6));
 430          $table->construct_row();
 431      }
 432  
 433      $table->output($lang->security_questions);
 434  
 435      echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-questions&amp;page={page}");
 436  
 437      $page->output_footer();
 438  }
 439  


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref