UQM 2.0 - Predictions Extensions

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

Post Reply
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Not as yet, didnt want to try and confuse different issues, and at the moment my hosts phpMyAdmin interface seems to be down
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Alright. Here is the new file, this has the statistics SQL query in it (so you should get the stats visible on the stats page now).

Code: Select all

<?php
// subvertbeats_quiz.php

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);

	if( !$auth->acl_get('a_') )
	{
		die('No access');
	}

	else
	{
		if( $_GET['mode'] == 'deactivate' )
		{
			$deactivate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 1
					WHERE quiz_id = $deactivate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $deactivate_id . ' has been deactivated');
		}

		if( $_GET['mode'] == 'activate' )
		{
			$activate_id = (int) $_GET['id'];

			$sql = "UPDATE " . QUIZ_TABLE . " SET quiz_deactivate = 0
					WHERE quiz_id = $activate_id";
			$db->sql_query($sql);
			die('Quiz id ' . $activate_id . ' has been activated');
		}

		if( $_GET['mode'] == 'enter_answers' )
		{
			if( $_GET['a'] == 'submit' )
			{
				$question_id_hidden = $_POST['questions'];
				$question_id_set = explode(',', $question_id_hidden);
				$question_id_set_count = sizeof($question_id_set) - 1;

				$users = array();
				$users_information = array();
				$users_names = array();

				for($i = 0; $i < $question_id_set_count; $i++ )
				{
					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i];
					$result = $db->sql_query($sql);
					while( $row = $db->sql_fetchrow($result) )
					{
						$users[$i] = $row['quiz_player'];

						$user_sql = 'SELECT username FROM ' . USERS_TABLE . '
									 WHERE user_id = ' . $row['quiz_player'];
						$user_result = $db->sql_query($user_sql);
						$user_name_fetch = $db->sql_fetchfield('username');
						$db->sql_freeresult($user_result);

						$users_names[$row['quiz_player']] = $user_name_fetch;

						$is_correct = 0;
						$is_incorrect = 0;

						if( $row['quiz_answer'] == $_POST['question' . $question_id_set[$i]] )
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> CORRECTLY<br />';
			
							$users_information[$row['quiz_player']]['quiz_correct']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' correct';
						}

						else
						{
							echo 'User <strong>' . $user_name_fetch . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.<br />';

							$users_information[$row['quiz_player']]['quiz_incorrect']++;
							$users_information[$row['quiz_player']]['quiz_id'] = $row['quiz_id'];
							$users_information[$row['quiz_player']]['info'] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
						}
					}
				}

				/* for( $j = 0, $j_count = sizeof($users); $j < $j_count; $j++ )
				{
					echo 'Username: ' . $users_names[$users[$j]] . '<br />';
					echo '-- Correct: ' .  $users_information[$users[$j]]['quiz_correct'] . '<br />';
					echo '-- Incorrect: ' .  $users_information[$users[$j]]['quiz_incorrect'] . '<br />';
					echo '-- Quiz ID: ' .  $users_information[$users[$j]]['quiz_id'] . '<br />';
				} */

				foreach($users_names as $key => $val)
				{
					// $key is the user_id, $val is the username
					$correct_answers = ($users_information[$key]['quiz_correct']) ? $users_information[$key]['quiz_correct'] : 0;
					$incorrect_answers = ($users_information[$key]['quiz_incorrect']) ? $users_information[$key]['quiz_incorrect'] : 0;
					$quiz_id_key = $users_information[$key]['quiz_id'];

					echo 'Info for ' . $val . ';<br />';
					echo '-- Correct: ' .  $correct_answers . '<br />';
					echo '-- Incorrect: ' .  $incorrect_answers . '<br />';
					echo '-- Quiz ID: ' . $quiz_id_key . '<br />';

					$statistical_overview_setup[] = array(
						'quiz_id'			=> (int) $quiz_id_key,
  						'quiz_correct'		=> (int) $correct_answers,
  						'quiz_incorrect'	=> (int) $incorrect_answers,
 						'user_id'			=> (int) $key,
 						'quiz_time'			=> (int) 0,
					);
				}

				$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $sql_ary);

				echo 'SQL Query entered';

				die();
			}

			$quiz_id = (int) $_GET['id'];
			$sql = 'SELECT * FROM ' . QUIZ_QUESTIONS_TABLE . '
					WHERE quiz_related_id = ' . $quiz_id;
			$result = $db->sql_query($sql);
			echo '<form action="subvertbeats_quiz.php?mode=enter_answers&id=' . $quiz_id . '&a=submit" method="post">';
			$question_id_hidden = '';
			while( $row = $db->sql_fetchrow($result) )
			{	
				$question_id_hidden .= $row['quiz_question_id'] . ',';
				echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
				// echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
				echo 'Correct answer:';

				$ans = 'SELECT quiz_answer FROM ' . QUIZ_DATA_TABLE . '
						WHERE quiz_question_id = ' . $row['quiz_question_id'];
				$ans_res = $db->sql_query($ans);
				while( $ans_row = $db->sql_fetchrow($ans_res) )
				{
					echo '<input type="radio" value="' . $ans_row['quiz_answer'] . '" name="question' . $row['quiz_question_id'] . '" /> ' . $ans_row['quiz_answer'] . '&nbsp;&nbsp;&nbsp;';
				} 

				echo '<br /><br />';
			}
			echo '<input type="hidden" value="' . $question_id_hidden . '" name="questions" />';
			echo '<input type="submit" value="Submit" name="submit" />';
			echo '</form>';

			die(); // new
		}

		else
		{
			echo 'Mode types:<br />
				<strong>subvertbeats_quiz.php?mode=deactivate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=activate&id=XXX</strong><br />
				<strong>subvertbeats_quiz.php?mode=enter_answers&id=XXX</strong>';
			die();
		}
	}
?>
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Looks good.

I was having a hard time working out the stats properly, so I just deleted all the existing quizzes and created a new one.

When I enter it I see no questions. I think I remember seeing this issue in the main UQM thread so going to have a look there now
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

subvertbeats wrote:Looks good.

I was having a hard time working out the stats properly, so I just deleted all the existing quizzes and created a new one.

When I enter it I see no questions. I think I remember seeing this issue in the main UQM thread so going to have a look there now
I think you are looking for this: http://www.phpbb.com/community/viewtopi ... #p11802285
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Hmmm yes, thanks....though Ive made thouse changes and still have the same issue....

edit - might well be the value of config_value - just checking now...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

subvertbeats wrote:Hmmm yes, thanks....though Ive made thouse changes and still have the same issue....

edit - might well be the value of config_value - just checking now...
Yeah, this is explained at http://www.phpbb.com/community/viewtopi ... #p11813005
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Yep its fixed now....I can play the quizzes....

Ok.....heres whats Ive noticed

- Created quiz
- Entered myself
- Got 2 others to enter
- Deactivated quiz
- Entered answers for quiz

On the Enter answers page, the order of questions was mixed up somehow - The first question in the quiz (out of 3 total questions) appeared second in the list in this page

- Viewed statistics

Statistics are blank apart from it showing that this quiz was viewed 3 times.
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Have you regained access to phpMyAdmin?

I'd like to know if phpbb_quiz_statistics_overview is empty or if there is data in it. Thanks.
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Hey battye....It looks empty
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Argh! It was a typo :(

FIND

Code: Select all

				$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $sql_ary);
REPLACE WITH

Code: Select all

				$db->sql_multi_insert(QUIZ_STATISTICS_OVERVIEW_TABLE, $statistical_overview_setup);
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Hey battye

Good find!

Ok, so, statistics look correct, apart from the Most correct answers table seems to be out of whack....
Best results
Competition name Competition player Correct Incorrect Percentage
Heres my test comp subvertbeats 2 1 67%
Heres my test comp Dent 2 1 67%

Most played
Competition name Author Submission date Views
Heres my test comp subvertbeats Fri Jan 22, 2010 2:57 pm 2

Most correct answers
Competition player Correct Incorrect Percentage
subvertbeats 4 2 67%


This time on the answer entry page, the order of Qs was completely reversed:

Q3
Q2
Q1
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

To fix the question order, find:

Code: Select all

					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i];
REPLACE WITH

Code: Select all

					$sql = 'SELECT * FROM ' . QUIZ_STATISTICS_TABLE . '
							WHERE quiz_question_id = ' . $question_id_set[$i] . '
							ORDER BY quiz_question_id ASC';


If you empty (EMPTY in phpMyAdmin) the phpbb_quiz_statistics_overview table (only that table) and re-run the script... do the statistics appear okay then?
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

table emptied ans scripe re-ran (assume you menat to re-enter and submit the answers)
Competition name Competition player Correct Incorrect Percentage
Heres my test comp Dent 2 1 67%
Heres my test comp subvertbeats 2 1 67%

Most played
Competition name Author Submission date Views
Heres my test comp subvertbeats Fri Jan 22, 2010 2:57 pm 2

Most correct answers
Competition player Correct Incorrect Percentage
Dent 4 2 67%
As you can see that Most Correct answers table is still incorrect, but different to how it was before (user Dent vs subvertbeats)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I think we can put it down to a bug in UQM v2.0.0 beta 3... see, my stats at http://forums.cricketmx.com/quiz.php?mode=stats don't look right for "most correct answers" either. For some reason I appear three times. So there is probably something wrong with the SQL query.

So for this script, that is all that needs doing? Are you satisfied with the output screens or would you prefer it in a different format? (this is fairly easy to do, as long as you don't ask for tables or css or anything :wink:)
CricketMX.com in 2022: Still the home of bat's, rat's and other farmyard animals!

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

Id like tables, with css :)

Being serious for a moment, I feel most indebted to you for all of your kind help, THANK YOU!

If we could comment out the parts of the code that shows each users answers for each question (else this screen will have lots of data) that would be good.

In terms of format - the primary requirement is a list of users (ordered - ascending on number of incorrect answers)

eg:
QUIZ ID: 8 QUIZ NAME: XXXXXXXXXXXXXXX
dent (correct: 5, incorrect 0)
subvertbeats (correct 5, incorrect 0)
jodie (correct 4, incorrect 1)
pete (correct 3, incorrect 2)
dave (correct 3, incorrect 2)
donald (correct 2, incorrect 3)
duck (correct 1, incorrect 4)
terriblepicker (correct 0, incorrect 5)

Is that something easily achievable ?

When thats done, I think we can go live!

=D>
Last edited by subvertbeats on Fri Jan 22, 2010 3:29 pm, edited 2 times in total.
Post Reply