| [ Index ] |
PHP Cross Reference of MyBB 1.8.40 |
[Summary view] [Print] [Text view]
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&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&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) 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&action=edit&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&action=edit&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) 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&action=delete&qid={$question['qid']}", $lang->confirm_question_deletion); 282 } 283 } 284 285 if($mybb->input['action'] == "disable") 286 { 287 if(!verify_post_check($mybb->get_input('my_post_key'))) 288 { 289 flash_message($lang->invalid_post_verify_key2, 'error'); 290 admin_redirect("index.php?module=config-questions"); 291 } 292 293 $query = $db->simple_select("questions", "*", "qid='".$mybb->get_input('qid', MyBB::INPUT_INT)."'"); 294 $question = $db->fetch_array($query); 295 296 if(!$question) 297 { 298 flash_message($lang->error_invalid_question, 'error'); 299 admin_redirect("index.php?module=config-questions"); 300 } 301 302 $plugins->run_hooks("admin_config_questions_disable"); 303 304 $update_question = array( 305 "active" => 0 306 ); 307 308 $plugins->run_hooks("admin_config_questions_disable_commit"); 309 310 $db->update_query("questions", $update_question, "qid = '{$question['qid']}'"); 311 312 // Log admin action 313 log_admin_action($question['qid'], $question['question']); 314 315 flash_message($lang->success_question_disabled, 'success'); 316 admin_redirect("index.php?module=config-questions"); 317 } 318 319 if($mybb->input['action'] == "enable") 320 { 321 if(!verify_post_check($mybb->get_input('my_post_key'))) 322 { 323 flash_message($lang->invalid_post_verify_key2, 'error'); 324 admin_redirect("index.php?module=config-questions"); 325 } 326 327 $query = $db->simple_select("questions", "*", "qid='".$mybb->get_input('qid', MyBB::INPUT_INT)."'"); 328 $question = $db->fetch_array($query); 329 330 if(!$question) 331 { 332 flash_message($lang->error_invalid_question, 'error'); 333 admin_redirect("index.php?module=config-questions"); 334 } 335 336 $plugins->run_hooks("admin_config_questions_enable"); 337 338 $update_question = array( 339 "active" => 1 340 ); 341 342 $plugins->run_hooks("admin_config_questions_enable_commit"); 343 344 $db->update_query("questions", $update_question, "qid = '{$question['qid']}'"); 345 346 // Log admin action 347 log_admin_action($question['qid'], $question['question']); 348 349 flash_message($lang->success_question_enabled, 'success'); 350 admin_redirect("index.php?module=config-questions"); 351 } 352 353 if(!$mybb->input['action']) 354 { 355 $plugins->run_hooks("admin_config_questions_start"); 356 357 $page->output_header($lang->security_questions); 358 359 $sub_tabs['security_questions'] = array( 360 'title' => $lang->security_questions, 361 'link' => "index.php?module=config-questions", 362 'description' => $lang->security_questions_desc 363 ); 364 $sub_tabs['add_new_question'] = array( 365 'title' => $lang->add_new_question, 366 'link' => "index.php?module=config-questions&action=add", 367 ); 368 369 $page->output_nav_tabs($sub_tabs, 'security_questions'); 370 371 $query = $db->simple_select("questions", "COUNT(qid) AS questions"); 372 $total_rows = $db->fetch_field($query, "questions"); 373 374 $pagenum = $mybb->get_input('page', MyBB::INPUT_INT); 375 if($pagenum) 376 { 377 $start = ($pagenum - 1) * 20; 378 $pages = ceil($total_rows / 20); 379 if($pagenum > $pages) 380 { 381 $start = 0; 382 $pagenum = 1; 383 } 384 } 385 else 386 { 387 $start = 0; 388 $pagenum = 1; 389 } 390 391 $table = new Table; 392 $table->construct_header($lang->question); 393 $table->construct_header($lang->answers, array("width" => "35%")); 394 $table->construct_header($lang->shown, array("width" => "5%", "class" => "align_center")); 395 $table->construct_header($lang->correct, array("width" => "5%", "class" => "align_center")); 396 $table->construct_header($lang->incorrect, array("width" => "5%", "class" => "align_center")); 397 $table->construct_header($lang->controls, array("class" => "align_center", "width" => 150)); 398 399 $query = $db->simple_select("questions", "*", "", array('limit_start' => $start, 'limit' => 20, 'order_by' => 'question')); 400 while($questions = $db->fetch_array($query)) 401 { 402 $questions['question'] = htmlspecialchars_uni($questions['question']); 403 $questions['answer'] = htmlspecialchars_uni($questions['answer']); 404 $questions['answer'] = preg_replace("#(\n)#s", "<br />", trim($questions['answer'])); 405 $questions['shown'] = my_number_format($questions['shown']); 406 $questions['correct'] = my_number_format($questions['correct']); 407 $questions['incorrect'] = my_number_format($questions['incorrect']); 408 409 if($questions['active'] == 1) 410 { 411 $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_on.png\" alt=\"({$lang->alt_enabled})\" title=\"{$lang->alt_enabled}\" style=\"vertical-align: middle;\" /> "; 412 } 413 else 414 { 415 $icon = "<img src=\"styles/{$page->style}/images/icons/bullet_off.png\" alt=\"({$lang->alt_disabled})\" title=\"{$lang->alt_disabled}\" style=\"vertical-align: middle;\" /> "; 416 } 417 418 $table->construct_cell("<div>{$icon}{$questions['question']}</div>"); 419 $table->construct_cell($questions['answer']); 420 $table->construct_cell($questions['shown'], array("class" => "align_center")); 421 $table->construct_cell($questions['correct'], array("class" => "align_center")); 422 $table->construct_cell($questions['incorrect'], array("class" => "align_center")); 423 $popup = new PopupMenu("questions_{$questions['qid']}", $lang->options); 424 $popup->add_item($lang->edit_question, "index.php?module=config-questions&action=edit&qid={$questions['qid']}"); 425 $popup->add_item($lang->preview_question, "index.php?module=config-questions&action=edit&qid={$questions['qid']}&preview_list"); 426 if($questions['active'] == 1) 427 { 428 $popup->add_item($lang->disable_question, "index.php?module=config-questions&action=disable&qid={$questions['qid']}&my_post_key={$mybb->post_code}"); 429 } 430 else 431 { 432 $popup->add_item($lang->enable_question, "index.php?module=config-questions&action=enable&qid={$questions['qid']}&my_post_key={$mybb->post_code}"); 433 } 434 $popup->add_item($lang->delete_question, "index.php?module=config-questions&action=delete&qid={$questions['qid']}&my_post_key={$mybb->post_code}", "return AdminCP.deleteConfirmation(this, '{$lang->confirm_question_deletion}')"); 435 $table->construct_cell($popup->fetch(), array("class" => "align_center")); 436 $table->construct_row(); 437 } 438 439 if($table->num_rows() == 0) 440 { 441 $table->construct_cell($lang->no_security_questions, array('colspan' => 6)); 442 $table->construct_row(); 443 } 444 445 $table->output($lang->security_questions); 446 447 echo "<br />".draw_admin_pagination($pagenum, "20", $total_rows, "index.php?module=config-questions&page={page}"); 448 449 $page->output_footer(); 450 } 451
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| 2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |