Code: Select all
utf8_normalize_nfc(request_var('message', '', true))
Code: Select all
<?php
/**
*
* @package phpBB3
* @version $Id: quiz.php
* @copyright (c) 2008, 2009 battye, CricketMX.com
* Ultimate Quiz MOD v2.0.0
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_quiz.' . $phpEx);
include($phpbb_root_path . 'includes/quiz_stats_class.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/quiz');
// Grab data
$mode = request_var('mode', '');
$action = request_var('action', '');
$category = request_var('category', 0);
if( !$user->data['is_registered'] )
{
trigger_error('QUIZ_MUST_BE_LOGGED_IN');
}
// Find which mode is set
if ($mode == 'submit')
{
// submit quiz
// Sort bbCode
$uid = $bitfield = $options = '';
$allow_bbcode = $allow_urls = $allow_smilies = true;
// uid - $uid, bitfield - $bitfield, options - $options
page_header($user->lang['SUBMIT_QUIZ']);
if( $action == 'submit' ) // The actual submission to the database stage
{
$data_array = array();
$full_correct_array = array();
$full_correct_array_count = 0;
$number_of_questions = request_var('number_of_questions', 0);
$this_quiz_id = quiz_latest_id() + 1;
if (!($number_of_questions > 0))
{
trigger_error($user->lang['NUMBER_QUESTIONS_UNDEFINED']);
}
for ($e = 1; $e <= $number_of_questions; $e++) // Just a trial run to make sure all questions are submitted
{
if (!request_var('question_name_' . $e, ''))
{
trigger_error($user->lang['EMPTY_QUESTION']);
}
}
for ($i = 1; $i <= $number_of_questions; $i++)
{
$question_name = utf8_normalize_nfc(request_var('question_name_' . $i, '', true));
if (request_var('answers_' . $i, '', true)) // input answer or multiple choice
{
$correct_answer = utf8_normalize_nfc(request_var('mc_' . $i, '', true));
$multiple_answers = utf8_normalize_nfc(request_var('answers_' . $i, '', true));
$multiple_answers_array = explode("\n", $multiple_answers);
}
else if (request_var('tf_' . $i, 0) != 0) // true/false
{
$correct_answer = (request_var('tf_' . $i, 0) == 1) ? $user->lang['TRUE_FALSE_TRUE'] : $user->lang['TRUE_FALSE_FALSE'];
$multiple_answers_array = array($user->lang['TRUE_FALSE_TRUE'], $user->lang['TRUE_FALSE_FALSE']);
}
// Update questions table
generate_text_for_storage($question_name, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$question_array = array(
'quiz_question' => utf8_normalize_nfc($question_name),
'quiz_related_id' => $this_quiz_id,
'quiz_uid' => $uid,
'quiz_bitfield' => $bitfield,
'quiz_options' => $options
);
$question_sql = 'INSERT INTO ' . QUIZ_QUESTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $question_array);
$db->sql_query($question_sql);
//$that_question_id = $db->sql_nextid() - 1; // This is the ID of the question submitted now.
$that_question_id = $db->sql_nextid();
// Now the actual data
$multiple_answers_array_number = sizeof($multiple_answers_array);
// For those people who submit too many choices
$key = 0;
if( $multiple_answers_array_number > $config['quiz_submit_max_multiple_choice'] )
{
$key = array_search($correct_answer, $multiple_answers_array);
$key++;
$how_many_further = $multiple_answers_array_number - $config['quiz_submit_max_multiple_choice'];
}
$stop_further_checks = 0;
for ($k = 0; $k < $multiple_answers_array_number; $k++)
{
// If key is set, we need to remove one of the incorrect answers
if ($key > 0 && $stop_further_checks != 1)
{
if ( ($key-1) != $k ) // If it is not the correct answer then we remove this one
{
$remove_question = 1; // yes
$how_many_further = $how_many_further - 1;
if ($how_many_further == 0)
{
$stop_further_checks = 1; // don't check any more
}
else
{
$stop_further_checks = 0; // keep going
}
}
else
{
$remove_question = 0;
$stop_further_checks = 0;
}
}
if ( $remove_question != 1 )
{
$correct_true_input_question_answer = ($multiple_answers_array[$k] == $correct_answer) ? true : false;
generate_text_for_storage($multiple_answers_array[$k], $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$data_array[] = array(
'quiz_question_id' => $that_question_id,
'quiz_answer' => utf8_normalize_nfc($multiple_answers_array[$k]),
'quiz_correct' => $correct_true_input_question_answer,
'quiz_uid' => $uid,
'quiz_bitfield' => $bitfield,
'quiz_options' => $options,
);
}
$remove_question = 0;
}
// End the looping of the separate questions
}
$db->sql_multi_insert(QUIZ_DATA_TABLE, $data_array);
// Insert into main quiz table.
$quiz_category = request_var('select_category', 0);
$quiz_name = utf8_normalize_nfc(request_var('quiz_name', '', true));
$quiz_array = array(
'quiz_author' => $user->data['user_id'],
'quiz_category' => $quiz_category,
'quiz_name' => $quiz_name,
'quiz_date' => time(),
'quiz_number_of_questions' => $number_of_questions,
'quiz_views' => 0
);
$quiz_sql = 'INSERT INTO ' . QUIZ_TABLE . ' ' . $db->sql_build_array('INSERT', $quiz_array);
$db->sql_query($quiz_sql);
trigger_error(sprintf($user->lang['QUIZ_SUBMISSION_SUCCESSFUL'], '<a href="' . append_sid('quiz.'.$phpEx) . '">', '</a>')); // The quiz was successfully entered into the database
}
if( $action == 'verify' )
{
$number_of_questions = request_var('number_of_questions', 0);
$true_false_questions = '';
if (!($number_of_questions > 0))
{
trigger_error($user->lang['NUMBER_QUESTIONS_UNDEFINED']);
}
// ready to submit?
if( request_var('final_verification', 0) )
{
$readiness_fv = 1; // true by default
if( !request_var('quiz_name', '') || !request_var('select_category', '') )
{
// We are not ready
$readiness_fv = 0;
}
else // check the questions that answers have been selected
{
for ($r = 1; $r <= $number_of_questions; $r++)
{
if( !request_var('tf_' . $r, 0) && !utf8_normalize_nfc(request_var('mc_' . $r, '', true)) )
{
// Not ready here either
$readiness_fv = 0;
}
}
}
if( $readiness_fv )
{
for ($r = 1; $r <= $number_of_questions; $r++)
{
// Define the quiz type
$reveal_multiples_row = '';
if( request_var('tf_' . $r, 0) )
{
$reveal_quiz_type = $user->lang['IS_TRUE_FALSE'];
}
else if ( strpos(request_var('answers_' . $r, ''), "\n") )
{
$multi_list = explode("\n", utf8_normalize_nfc(request_var('answers_' . $r, '', true)));
$alternates_list = '';
for ($b = 0; $b < sizeof($multi_list); $b++)
{
$multi_list[$b] = ($multi_list[$b] == utf8_normalize_nfc(request_var('mc_' . $r, '', true))) ? '' : $multi_list[$b];
$alternates_list .= ($multi_list[$b] != '') ? ', ' . $multi_list[$b] : '';
}
$alternates_list[0] = '';
$alternates_list[1] = '';
$uid = $bitfield = $options = '';
$allow_bbcode = $allow_urls = $allow_smilies = true;
generate_text_for_storage($alternates_list, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$alternates_list = generate_text_for_display($alternates_list, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$reveal_quiz_type = $user->lang['MULTIPLE_CHOICE_QUESTION'];
$reveal_multiples_row .= $alternates_list;
}
else
{
$reveal_quiz_type = $user->lang['INPUT_ANSWER_QUESTION'];
}
// Create bbCode for question
$reveal_name_of_quiz = utf8_normalize_nfc(request_var('question_name_' . $r, '', true));
$uid = $bitfield = $options = '';
$allow_bbcode = $allow_urls = $allow_smilies = true;
generate_text_for_storage($reveal_name_of_quiz, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$reveal_name_of_quiz = generate_text_for_display($reveal_name_of_quiz, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
// Create bbCode for correct answer
$reveal_correct_answer_for_question = request_var('mc_' . $r, '', true);
$uid = $bitfield = $options = '';
$allow_bbcode = $allow_urls = $allow_smilies = true;
generate_text_for_storage($reveal_correct_answer_for_question, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$reveal_correct_answer_for_question = generate_text_for_display($reveal_correct_answer_for_question, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
$template->assign_block_vars('question_row', array(
'QUESTION_ID' => $r,
'QUIZ_TYPE' => $reveal_quiz_type,
'QUESTION_NAME_REVEAL' => $reveal_name_of_quiz,
'QUESTION_NAME_HIDDEN' => '<input type="hidden" name="question_name_' . $r . '" value="' . utf8_normalize_nfc(request_var('question_name_' . $r, '', true)) . '" />',
'QUESTION_ANSWER_REVEAL' => (request_var('tf_' . $r, 0) != 0) ? ((request_var('tf_' . $r, 0) == 1) ? $user->lang['TRUE_FALSE_TRUE'] : $user->lang['TRUE_FALSE_FALSE']) : $reveal_correct_answer_for_question,
'MULTIPLES_REVEAL' => $reveal_multiples_row,
'QUESTION_ANSWER_HIDDEN' => (request_var('tf_' . $r, 0) != 0) ? '<input type="hidden" name="tf_' . $r . '" value="' . request_var('tf_' . $r, '') . '" />' : '<input type="hidden" name="answers_' . $r . '" value="' . utf8_normalize_nfc(request_var('answers_' . $r, '', true)) . '" /><input type="hidden" name="mc_' . $r . '" value="' . utf8_normalize_nfc(request_var('mc_' . $r, '', true)) . '" />',
));
}
$s_hidden_fields = build_hidden_fields(array(
'number_of_questions' => $number_of_questions,
));
$template->assign_vars( array(
'S_SUBMIT_QUIZ_ACTION' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=submit&action=submit'),
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'L_SUBMIT_INFORMATION' => $user->lang['FINAL_VERIFY_SUBMIT'],
'U_STEP_SUBMIT_QUIZ' => $user->lang['SUBMIT_STEP_3'],
'U_CHECK_INITIAL' => false,
'U_VERIFY_ANSWERS' => false,
'U_FINAL_VERIFY' => true,
'U_QUIZ_NAME' => utf8_normalize_nfc(request_var('quiz_name', '', true)),
'U_SELECT_A_CATEGORY' => quiz_category_list(request_var('select_category', 0)),
));
$template->set_filenames(array(
'body' => 'quiz_submit_body.html')
);
page_footer();
}
}
if( !$readiness_fv && !request_var('final_verification', 0) )
{
// let's check to make sure all of the questions have been filled out. Also that multiple choice is correct
for ($q = 1; $q <= $number_of_questions; $q++)
{
// is the question/answer actually filled out for all questions?
$verify_ok = ( utf8_normalize_nfc(request_var('question_name_' . $q, '', true)) != '' && ( utf8_normalize_nfc(request_var('answers_' . $q, '', true)) != '' || request_var('is_true_false_' . $q, 0) == 1 ) ) ? 1 : 0; // 0 represents something is empty
$multiple_choices = ( utf8_normalize_nfc(request_var('answers_' . $q, '', true)) ) ? explode("\n", utf8_normalize_nfc(request_var('answers_' . $q, '', true))) : '';
$number_of_multiple_choices = sizeof($multiple_choices);
$mc_alert = ($number_of_multiple_choices > $config['quiz_submit_max_multiple_choice']) ? sprintf($user->lang['TOO_MANY_CHOICES'], $config['quiz_submit_max_multiple_choice']) : '';
if ($verify_ok == 0 || $number_of_multiple_choices > $config['quiz_submit_max_multiple_choice'])
{
break;
}
}
}
if ((!$readiness_fv && !request_var('final_verification', 0)) && (!$verify_ok || $number_of_multiple_choices > $config['quiz_submit_max_multiple_choice']))
{
$submit_quiz_action_figure = "verify";
$final_quiz_verification = false;
for ($i = 1; $i <= $number_of_questions; $i++)
{
$template->assign_block_vars('question_row', array(
'S_HIDDEN_ANSWERS' => $hidden_field,
'QUESTION_ID' => $i,
'QUESTION_NAME' => utf8_normalize_nfc(request_var('question_name_' . $i, '', true)),
'QUESTION_TF_CHECK' => (request_var('is_true_false_' . $i, 0) == 1) ? 'checked="checked"' : false, // Display true or false option
'QUESTION_ANSWER' => request_var('answers_' . $i, '', true),
));
}
// Deciding the error message
$ef_error_msg = ( !$verify_ok ) ? $user->lang['EMPTY_QUIZ_FIELDS'] : $mc_alert;
$verify_ok = false; // Just in case it was the multiple choice that caused this, to be used later on
$template->assign_vars( array(
'U_EMPTY_FIELDS' => true,
'U_EMPTY_FIELDS_MSG' => $ef_error_msg,
'L_SUBMIT_INFORMATION' => sprintf( $user->lang['SUBMIT_INFORMATION'], $number_of_questions, $config['quiz_submit_max_multiple_choice'] ),
));
}
else
{
$submit_quiz_action_figure = "verify";
$final_quiz_verification = true;
// If we are on Step 2 "retry", ie. referred back to this page, we need to check for the existance of true/false questions
$tf_questions_expl = explode(',', request_var('true_false_questions', '', true));
for ($i = 1; $i <= $number_of_questions; $i++)
{
if ( utf8_normalize_nfc(request_var('question_name_' . $i, '', true)) || utf8_normalize_nfc(request_var('answers_' . $i, '', true)) && ( !request_var('final_verification', 0) && (request_var('is_true_false_' . $i, 0) == 1) ))
{
if (request_var('is_true_false_' . $i, 0) == 1)
{
$true_false_questions .= $i . ',';
}
else
{
$hidden_field = '<input type="hidden" name="answers_' . $i . '" value="' . utf8_normalize_nfc(request_var('answers_' . $i, '', true)) . '" />';
$multiple_choices = ( request_var('answers_' . $i, '', true) ) ? explode("\n", utf8_normalize_nfc(request_var('answers_' . $i, '', true))) : '';
$number_of_multiple_choices = sizeof($multiple_choices);
//$mc_alert = ($number_of_multiple_choices > $config['quiz_submit_max_multiple_choice']) ? sprintf($user->lang['TOO_MANY_CHOICES'], $config['quiz_submit_max_multiple_choice']) : '';
if ($number_of_multiple_choices == 1) // If the quiz is input answer, this will apply
{
$multiple_choice_lineup = $multiple_choices[0] . '<input type="hidden" name="mc_'.$i.'" value="' . $multiple_choices[0] . '" />';
}
else // for deciding multiple choice options
{
$multiple_choice_lineup = '';
for ($x = 0; $x < $number_of_multiple_choices; $x++)
{
$multiple_choice_lineup .= '<input type="radio" name="mc_'.$i.'" value="' . $multiple_choices[$x] . '" /> ' . $multiple_choices[$x] . '<br />';
}
}
}
if ( !$true_false_questions && request_var('true_false_questions', '') )
{
$true_false_questions = request_var('true_false_questions', '');
}
$question_tf_vp = false;
// is_numeric must be used in case it is the 0th item in the array
if( request_var('is_true_false_' . $i, 0) == 1 || (!((!$readiness_fv && !request_var('final_verification', 0))) && is_numeric(array_search(($i), $tf_questions_expl))) )
{
$question_tf_vp = true;
}
$template->assign_block_vars('question_row', array(
'S_HIDDEN_ANSWERS' => $hidden_field,
'QUESTION_ID' => $i,
'QUESTION_NAME' => utf8_normalize_nfc(request_var('question_name_' . $i, '', true)),
'QUESTION_TF' => $question_tf_vp, // Display true or false option
'QUESTION_MC' => $multiple_choice_lineup, // Display a list of multiple choices or the input answer
// 'QUESTION_MC_ALERT' => $mc_alert,
));
}
}
}
$s_hidden_fields = build_hidden_fields(array(
'number_of_questions' => $number_of_questions,
'true_false_questions' => $true_false_questions,
'final_verification' => $final_quiz_verification,
));
$template->assign_vars( array(
'S_SUBMIT_QUIZ_ACTION' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=submit&action=' . $submit_quiz_action_figure),
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'U_STEP_SUBMIT_QUIZ' => $user->lang['SUBMIT_STEP_2'],
'U_EMPTY_FIELDS' => ((!$readiness_fv && !request_var('final_verification', 0))) ? false : true,
'U_EMPTY_FIELDS_MSG' => $user->lang['EMPTY_RADIO_BOX'],
'U_CHECK_INITIAL' => false,
'U_VERIFY_ANSWERS' => ((!$readiness_fv && !request_var('final_verification', 0))) ? $verify_ok : true,
'U_QUIZ_NAME' => utf8_normalize_nfc(request_var('quiz_name', '', true)),
'U_SELECT_A_CATEGORY' => quiz_category_list(request_var('select_category', 0)),
));
}
else
{
if (!request_var('number_of_questions', 0))
{
// initial "choose number of questions screen"
// quahappy's suggestion to use a drop down box
$num_drop = '<select name="number_of_questions">';
for ($d = $config['quiz_submit_min']; $d <= $config['quiz_submit_max']; $d++)
{
$num_drop .= ' <option value="' . $d . '">' . $d . '</option>';
}
$num_drop .= '</select>';
$template->assign_vars( array(
'L_SELECT_NUMBER_EXPLAIN' => sprintf($user->lang['SELECT_NUMBER_EXPLAIN'], $config['quiz_submit_min'], $config['quiz_submit_max']),
'S_SUBMIT_QUIZ_ACTION' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=submit'),
'U_STEP_SUBMIT_QUIZ' => $user->lang['SUBMIT_QUIZ'],
'U_CHECK_INITIAL' => true,
'U_NUM_DROP' => $num_drop,
));
}
else
{
// actual adding questions and answers screen
// check to make sure it is within required parameters
$number_of_questions = request_var('number_of_questions', 0);
if (!request_var('number_of_questions', 0) || $number_of_questions < $config['quiz_submit_min'] || $number_of_questions > $config['quiz_submit_max'])
{
trigger_error( sprintf($user->lang['OUTSIDE_QUESTION_PARAM'], $config['quiz_submit_min'], $config['quiz_submit_max']) );
}
for ($i = 0; $i < $number_of_questions; $i++)
{
$template->assign_block_vars('question_row', array(
'QUESTION_ID' => $i + 1,
));
}
$s_hidden_fields = build_hidden_fields(array(
'number_of_questions' => $number_of_questions,
));
$template->assign_vars( array(
'S_SUBMIT_QUIZ_ACTION' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=submit&action=verify'),
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'L_SUBMIT_INFORMATION' => sprintf( $user->lang['SUBMIT_INFORMATION'], $number_of_questions, $config['quiz_submit_max_multiple_choice'] ),
'U_STEP_SUBMIT_QUIZ' => $user->lang['SUBMIT_STEP_1'],
'U_CHECK_INITIAL' => false,
'U_SELECT_A_CATEGORY' => quiz_category_list(''),
'U_MAX_MULTIPLE_CHOICE' => $config['quiz_submit_max_multiple_choice'],
));
}
}
$template->set_filenames(array(
'body' => 'quiz_submit_body.html')
);
}
if ($mode == 'play')
{
if ($action == 'submit')
{
// The save type - "save" or "submit".
$save_type = request_var('submit', '');
$quiz_id = request_var('quiz_id', 0);
$current_quiz_in_progress_check = find_current_live_progress_id($quiz_id, 1);
if (!$current_quiz_in_progress_check)
{
trigger_error($user->lang['MULTIPLE_SUBMISSION']);
}
$find_number_of_questions_in_quiz = find_number_of_questions_in_quiz($quiz_id);
$quiz_start_time = find_current_live_progress_id($quiz_id, 2); // When "2", the unix timestamp of the start time is given
$time_taken_to_do_quiz = time() - $quiz_start_time + find_current_live_progress_id($quiz_id, 3);
if ($config['quiz_save_enabled'] == '1' && $save_type == $user->lang['QUIZ_SAVE'])
{
if ($config['quiz_time_limit_per_question'] != '0')
{
if ($time_taken_to_do_quiz > ($config['quiz_time_limit_per_question'] * $find_number_of_questions_in_quiz))
{
$db->sql_query("UPDATE " . QUIZ_PROGRESSIVE_TABLE . " SET quiz_in_progress = 0 WHERE quiz_progress_id = " . $current_quiz_in_progress_check);
trigger_error(sprintf($user->lang['QUIZ_TIME_EXCEEDED'], $time_taken_to_do_quiz));
}
}
$saved_input = '';
// Essentially a rehash of what is below, but saved.
$sql = "SELECT quiz_question_id
FROM " . QUIZ_QUESTIONS_TABLE . "
WHERE quiz_related_id = " . $quiz_id;
$result = $db->sql_query($sql);
while ($question_id_array = $db->sql_fetchrow($result))
{
$give_question_id = $question_id_array['quiz_question_id'];
$given_user_input = utf8_normalize_nfc(request_var('question' . $give_question_id, ''));
$user_given_answer = (!is_numeric($given_user_input)) ? $given_user_input : correct_answer_for_id($given_user_input, 2);
$saved_input .= $give_question_id . ':/\:/\:/\:' . $user_given_answer . ';/\;/\;/\;';
}
$sql = "UPDATE " . QUIZ_PROGRESSIVE_TABLE . "
SET quiz_progress_saved = '" . $db->sql_escape($saved_input) . "',
quiz_progress_stop_time = " . time() . "
WHERE quiz_progress_id = " . find_current_live_progress_id($quiz_id, 1);
$db->sql_query($sql);
trigger_error($user->lang['QUIZ_PROGRESS_SAVED']);
}
else if ($save_type == $user->lang['SUBMIT'])
{
page_header($user->lang['QUIZ_RESULTS']);
$time_results_summary = sprintf($user->lang['TIME_SUMMARY'], $time_taken_to_do_quiz);
$submit_quiz_progressive_id = find_current_live_progress_id($quiz_id, 1);
// Before we do anything, let's see if the time limits stuff is alright
if ($config['quiz_time_limit_per_question'] != '0')
{
if ($time_taken_to_do_quiz > (($config['quiz_time_limit_per_question'] * $find_number_of_questions_in_quiz) - find_current_live_progress_id($quiz_id, 3)))
{
$db->sql_query("UPDATE " . QUIZ_PROGRESSIVE_TABLE . " SET quiz_in_progress = 0 WHERE quiz_progress_id = " . $submit_quiz_progressive_id);
trigger_error(sprintf($user->lang['QUIZ_TIME_EXCEEDED'], $time_taken_to_do_quiz));
}
}
$number_of_correct_answers = 0;
$number_of_incorrect_answers = 0;
$show_answers = array();
$statistical_sql = array();
$sql = "SELECT quiz_question_id
FROM " . QUIZ_QUESTIONS_TABLE . "
WHERE quiz_related_id = " . $quiz_id;
$result = $db->sql_query($sql);
while ($question_id_array = $db->sql_fetchrow($result))
{
$give_question_id = $question_id_array['quiz_question_id'];
$given_user_input = request_var('question' . $give_question_id, ''); // raw input
$user_given_answer = (!is_numeric($given_user_input)) ? $given_user_input : correct_answer_for_id($given_user_input, 2); // the answer the user chose or gave
$actual_correct_answer = correct_answer_for_id($give_question_id, 1); // the correct (database) answer
if (utf8_case_fold_nfc($user_given_answer) == utf8_case_fold_nfc($actual_correct_answer))
{
if ($config['quiz_show_answers'] != '0') // Should we show the answers to the user? Err...
{
$show_answers[($number_of_correct_answers + $number_of_incorrect_answers)] = sprintf($user->lang['SHOW_RESULTS_CORRECT'], $user_given_answer);
}
$statistical_array = array(
'quiz_question_id' => (int) $give_question_id,
'quiz_id' => (int) $quiz_id,
'quiz_correct' => 1,
'quiz_answer' => $user_given_answer,
'quiz_player' => (int) $user->data['user_id'],
);
$number_of_correct_answers++;
}
else
{
if ($config['quiz_show_answers'] != '0') // Should we show the answers to the user? Err...
{
$show_answers[($number_of_correct_answers + $number_of_incorrect_answers)] = sprintf($user->lang['SHOW_RESULTS_INCORRECT'], $user_given_answer, $actual_correct_answer);
}
$statistical_array = array(
'quiz_question_id' => (int) $give_question_id,
'quiz_id' => (int) $quiz_id,
'quiz_correct' => 0,
'quiz_answer' => $user_given_answer,
'quiz_player' => (int) $user->data['user_id'],
);
$number_of_incorrect_answers++;
}
$statistical_sql[] = 'INSERT INTO ' . QUIZ_STATISTICS_TABLE . '
' . $db->sql_build_array('INSERT', $statistical_array);
}
$db->sql_freeresult($result);
// the basic stats (right/wrong in a quiz for quick reference)
$statistical_overview_setup = array(
'quiz_id' => (int) $quiz_id,
'quiz_correct' => (int) $number_of_correct_answers,
'quiz_incorrect' => (int) $number_of_incorrect_answers,
'user_id' => (int) $user->data['user_id'],
'quiz_time' => (int) $time_taken_to_do_quiz,
);
$statistical_sql[] = 'INSERT INTO ' . QUIZ_STATISTICS_OVERVIEW_TABLE . '
' . $db->sql_build_array('INSERT', $statistical_overview_setup);
$results_summary = sprintf($user->lang['RESULTS_SUMMARY'], $number_of_correct_answers, $number_of_incorrect_answers);
if ($config['quiz_show_answers'] != '0') // Ctrl+V. I mean, " // Should we show the answers to the user? Err..."
{
$sql = "SELECT * FROM " . QUIZ_QUESTIONS_TABLE . "
WHERE quiz_related_id = $quiz_id
ORDER BY quiz_question_id ASC";
$result = $db->sql_query($sql);
// Loops the questions, so we can display the answer
$n = 0;
while ($row = $db->sql_fetchrow($result))
{
$question_formatted = generate_text_for_display($row['quiz_question'], $row['quiz_uid'], $row['quiz_bitfield'], $row['quiz_options']); // does this look familiar? lets format the question
$user_result = $show_answers[$n];
$template->assign_block_vars('results_row', array(
'QUESTION' => $question_formatted,
'RESULT' => $user_result,
));
$n++;
}
}
$template->assign_vars( array(
'SHOW_ANSWERS' => ($config['quiz_show_answers'] != '0') ? true : false,
'TIME_SUMMARY' => $time_results_summary,
'RESULTS_SUMMARY' => $results_summary,
));
$template->set_filenames(array(
'body' => 'quiz_results_body.html')
);
// Delete all temporary/progressive data and update the view count of the quiz
// We'll use the stats array as it looks nicer, and loosely related anyway
$statistical_sql[] = "DELETE FROM " . QUIZ_PROGRESSIVE_TABLE . " WHERE quiz_progress_id = $submit_quiz_progressive_id";
$statistical_sql[] = "UPDATE " . QUIZ_TABLE . " SET quiz_views = quiz_views + 1 WHERE quiz_id = $quiz_id";
// Insert statistics
$size_statistical_sql = sizeof($statistical_sql);
for ($u = 0; $u < $size_statistical_sql; $u++)
{
$db->sql_query($statistical_sql[$u]);
}
page_footer();
}
else
{
trigger_error($user->lang['QUIZ_NO_TYPE_SUBMIT']);
}
}
$quiz_id = request_var('q', 0); // get the ID for this quiz being played
page_header(get_quiz_title($quiz_id));
$current_progressive = find_current_live_progress_id($quiz_id, 1);
if ($current_progressive > 0)
{
$sql = "SELECT quiz_progress_saved, quiz_progress_time, quiz_progress_stop_time
FROM " . QUIZ_PROGRESSIVE_TABLE . "
WHERE quiz_progress_id = $current_progressive";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$progress_saved = $row['quiz_progress_saved'];
if ($config['quiz_time_limit_per_question'] != '0' && ($row['quiz_progress_time'] + (find_number_of_questions_in_quiz($quiz_id) * $config['quiz_time_limit_per_question'])) < time())
{
trigger_error($user->lang['CHEATING_ATTEMPT']);
}
$progress_time_used = $row['quiz_progress_stop_time'] - $row['quiz_progress_time'];
if ($progress_time_used < 0)
{
$progress_time_used = 0;
}
$questions_saved = explode(';/\;/\;/\;', $progress_saved);
$questions_saved_size = sizeof($questions_saved);
$saved_information = array();
for ($w = 0; $w < $questions_saved_size; $w++)
{
$question_given_answer = explode(':/\:/\:/\:', $questions_saved[$w]);
$saved_information[$w]['question_number'] = intval($question_given_answer[0]);
$saved_information[$w]['given_answer'] = ($question_given_answer[1]) ? $question_given_answer[1] : '';
}
}
else
{
$progress_array = array(
'quiz_player_id' => $user->data['user_id'],
'quiz_progress_time' => time(),
'quiz_id' => $quiz_id,
'quiz_progress_saved' => '',
'quiz_in_progress' => 1,
);
// Enter the data into the progressive data, important to know later on if a user has paused
// a quiz and wants to resume. Also helpful for admins with time limits enabled.
$progress_sql = 'INSERT INTO ' . QUIZ_PROGRESSIVE_TABLE . '
' . $db->sql_build_array('INSERT', $progress_array);
$db->sql_query($progress_sql);
}
// Get the questions and loop the loop
$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
WHERE quiz_related_id = ' . $quiz_id;
$result = $db->sql_query($sql);
$quiz_answers_list = array();
$quiz_answer_row_id = array();
$question_count = 0;
while ($row = $db->sql_fetchrow($result))
{
$question_formatted = ''; // reset values to avoid a continual build-up of options
$answer_select_output = '';
$quiz_question_id = $row['quiz_question_id']; // This is needed to match to results from the data table
$question_formatted = generate_text_for_display($row['quiz_question'], $row['quiz_uid'], $row['quiz_bitfield'], $row['quiz_options']);
$answer_sql = 'SELECT * FROM ' . QUIZ_DATA_TABLE . '
WHERE quiz_question_id = ' . $quiz_question_id;
$mc_answer_result = $db->sql_query($answer_sql);
$a = 0;
while ($answer_row = $db->sql_fetchrow($mc_answer_result))
{
$answer_formatted = generate_text_for_display($answer_row['quiz_answer'], $answer_row['quiz_uid'], $answer_row['quiz_bitfield'], $answer_row['quiz_options']);
$quiz_answers_list[$quiz_question_id][$a] = $answer_formatted;
$quiz_answer_row_id[$quiz_question_id][$a] = $answer_row['quiz_data_id'];
$a++;
}
$sizeof_mc_array = sizeof($quiz_answer_row_id[$quiz_question_id]);
if ($sizeof_mc_array > 1)
{
$answer_select_output = ''; // The input fields that are shown to the user
for ($i = 0; $i < $sizeof_mc_array; $i++)
{
$checked_input = '';
// If we are grabbing saved answers
if ($current_progressive > 0)
{
if (is_numeric($saved_information[$question_count]['given_answer']))
{
$checked_input = (intval($saved_information[$question_count]['given_answer']) == intval($quiz_answers_list[$quiz_question_id][$i])) ? 'checked="checked"' : '';
}
else
{
$checked_input = (utf8_case_fold_nfc($saved_information[$question_count]['given_answer']) == utf8_case_fold_nfc($quiz_answers_list[$quiz_question_id][$i])) ? 'checked="checked"' : '';
}
}
$answer_select_output .= '<input type="radio" name="question' . $quiz_question_id . '" value="' . $quiz_answer_row_id[$quiz_question_id][$i] . '" ' . $checked_input . ' /> ' . $quiz_answers_list[$quiz_question_id][$i] . '<br />';
}
}
else
{
$value_input = '';
// If we are grabbing saved answers
if ($current_progressive > 0)
{
$value_input = $saved_information[$question_count]['given_answer'];
}
$answer_select_output .= '<input type="text" name="question' . $quiz_question_id . '" value="' . $value_input . '" /> ' . $quiz_answers_list[$quiz_question_id][$i] . '<br />';
}
$template->assign_block_vars('play_row', array(
'QUESTION' => $question_formatted,
'ANSWER' => $answer_select_output,
));
$question_count++;
}
$db->sql_freeresult($result);
// Time limits stuff
// Javascript from http://www.java-scripts.net/javascripts/Countdown-Timer.phtml (thanks to author Thomas).
if ($config['quiz_time_limit_per_question'] > 0)
{
if ($progress_time_used && $progress_saved)
{
// Reset the start time - we have already noted the time already used
$db->sql_query("UPDATE " . QUIZ_PROGRESSIVE_TABLE . "
SET quiz_time_used = " . $progress_time_used . ",
quiz_progress_time = " . time() . ",
quiz_progress_stop_time = 0
WHERE quiz_progress_id = " . $current_progressive);
}
$total_time_allowed = ($progress_time_used) ? (($config['quiz_time_limit_per_question'] * $question_count) - $progress_time_used) : $config['quiz_time_limit_per_question'] * $question_count; // time (seconds) allowed to complete the entire quiz
}
$s_hidden_fields = build_hidden_fields(array(
'quiz_id' => $quiz_id,
));
$template->assign_vars( array(
'S_HIDDEN_FIELDS' => $s_hidden_fields,
'S_SUBMIT_QUIZ_ACTION' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=play&action=submit'),
'TIME_LIMITS_ENABLED' => ($total_time_allowed) ? true : false,
'TIME_ALLOWED' => $total_time_allowed,
'SAVE_ENABLED' => ($config['quiz_save_enabled'] == '1') ? true : false,
));
$template->set_filenames(array(
'body' => 'quiz_play_body.html')
);
}
if ($mode == 'stats')
{
page_header($user->lang['QUIZ_STATISTICS']);
// view statistics
$stats = new quiz_stats;
$stats->best_results();
$stats->most_played();
$stats->most_correct_answers();
// $stats->high_percentage_correct_answers();
$template->set_filenames(array(
'body' => 'quiz_statistics_body.html')
);
page_footer();
}
else if (!$mode)
{
// index and categories
if( $category )
{
// list quizzes in a certain category
$category_title = get_category_name($category);
page_header($category_title);
$sql = "SELECT * FROM " . QUIZ_TABLE . " WHERE quiz_category = $category";
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$user_info = "SELECT username, user_colour
FROM " . USERS_TABLE . "
WHERE user_id = " . $row['quiz_author'];
$user_info_result = $db->sql_query($user_info);
$user_info_row = $db->sql_fetchrow($user_info_result);
$db->sql_freeresult($user_info_result);
$template->assign_block_vars('quiz_row', array(
'QUIZ_LINK' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=play&q=' . $row['quiz_id']),
'QUIZ_NAME' => $row['quiz_name'],
'QUIZ_AUTHOR' => get_username_string('full', $row['quiz_author'], $user_info_row['username'], $user_info_row['user_colour']),
'QUIZ_DATE' => $user->format_date($row['quiz_date']),
'QUIZ_VIEWS' => ($row['quiz_views'] == 1) ? sprintf($user->lang['NUMBER_OF_QUIZ_VIEWS_SINGLE'], $row['quiz_views']) : sprintf($user->lang['NUMBER_OF_QUIZ_VIEWS_PLURAL'], $row['quiz_views']),
));
}
$template->assign_vars( array(
'CATEGORY_VIEW' => true,
'CATEGORY_VIEW_NAME' => $category_title,
));
$template->set_filenames(array(
'body' => 'quiz_body.html')
);
page_footer();
}
else
{
page_header($user->lang['QUIZ']);
$sql = "SELECT * FROM " . QUIZ_CATEGORY_TABLE . "
ORDER BY quiz_category_name ASC";
$result = $db->sql_query($sql);
while( $row = $db->sql_fetchrow($result) )
{
$quiz_category_id = $row['quiz_category_id'];
$quiz_category_name = $row['quiz_category_name'];
$quiz_category_desc = $row['quiz_category_description'];
$quiz_category_password = ($row['quiz_category_password']) ? $user->lang['QUIZ_PASSWORD_PROTECTED_CAT'] : false;
$quiz_category_link = append_sid("{$phpbb_root_path}quiz.$phpEx", 'category='.$quiz_category_id);
$quiz_count_quiz_num = find_number_of_quiz_in_category($quiz_category_id);
$template->assign_block_vars('category_row', array(
'CAT_LINK' => $quiz_category_link,
'CAT_NAME' => $quiz_category_name,
'CAT_DESC' => $quiz_category_desc,
'CAT_PSWD' => $quiz_category_password,
'CAT_NUMBER_QUIZZES' => ($quiz_count_quiz_num == 1) ? sprintf($user->lang['NUMBER_OF_QUIZ_INDEX_SINGLE'], $quiz_count_quiz_num) : sprintf($user->lang['NUMBER_OF_QUIZ_INDEX_PLURAL'], $quiz_count_quiz_num),
));
}
$template->assign_vars( array(
'U_NEW_QUIZ' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=submit'),
'U_STATS' => append_sid("{$phpbb_root_path}quiz.$phpEx", 'mode=stats'),
'U_CP' => append_sid("{$phpbb_root_path}quiz_cp.$phpEx"),
'CAN_ACCESS_CP' => ((intval($config['quiz_user_edit_own_quiz']) == 1) || $auth->acl_get('a_')) ? true : false,
));
$template->set_filenames(array(
'body' => 'quiz_body.html')
);
page_footer();
}
}
page_footer();
?>
Code: Select all
Step 2 of 3 - Enter the answers!
[phpBB Debug] PHP Notice: in file /quiz.php on line 324: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 343: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 351: Undefined variable: hidden_field
[phpBB Debug] PHP Notice: in file /quiz.php on line 351: Undefined variable: hidden_field
[phpBB Debug] PHP Notice: in file /quiz.php on line 351: Undefined variable: hidden_field
[phpBB Debug] PHP Notice: in file /quiz.php on line 351: Undefined variable: hidden_field
[phpBB Debug] PHP Notice: in file /quiz.php on line 447: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 450: Undefined variable: readiness_fv
After entering some answers
Step 2 of 3 - Enter the answers!
[phpBB Debug] PHP Notice: in file /quiz.php on line 324: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 343: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 420: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 447: Undefined variable: readiness_fv
[phpBB Debug] PHP Notice: in file /quiz.php on line 450: Undefined variable: readiness_fv
Step 3 of 3 - Check all is correct!
No PHP notice - error
At last
Your quiz was successfully entered into the database.
Return to the quiz index page.
[phpBB Debug] PHP Notice: in file /quiz.php on line 151: Undefined variable: remove_question
Trying to take the test:
[phpBB Debug] PHP Notice: in file /quiz.php on line 862: Undefined variable: i
[phpBB Debug] PHP Notice: in file /quiz.php on line 862: Undefined index:
[phpBB Debug] PHP Notice: in file /quiz.php on line 879: Undefined variable: progress_time_used
[phpBB Debug] PHP Notice: in file /quiz.php on line 889: Undefined variable: progress_time_used
At last, quizz halted when I tried to submit twice due to error.
You are seeing this error because one of several events might have occurred:
- A cheating attempt may have been detected. You cannot leave a quiz and later re-enter it without going through the save process.
- You have tried to resubmit a quiz that you have exceeded the time limit on
- You have already played this quiz, and the admin does not allow multiple attempts.
Code: Select all
[phpBB Debug] PHP Notice: in file /includes/quiz_stats_class.php on line 96: Division by zero
My mistake, repackaging now...mtrs wrote:Beta 2 mod package misses .xls file and some folders contains mac .DS_Store files.