UQM 2.0 - Predictions Extensions

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

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

subvertbeats, I obviously can't go too far with this as I am writing this add-on as a kind gesture. It is unfair to all of the other UQM users if I start spending more time on this than the actual MOD - I hope you understand where I am coming from. I am happy to write the script and tell you which minor changes to make to the quiz code, but if I start making major changes to the quiz code it will just take up too much of my time. So I can't add in a "closing date" function, what you will need to do is set the quiz to "allow play once" and get the results in as soon as possible after the match.
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

battye wrote:subvertbeats, I obviously can't go too far with this as I am writing this add-on as a kind gesture. It is unfair to all of the other UQM users if I start spending more time on this than the actual MOD - I hope you understand where I am coming from. I am happy to write the script and tell you which minor changes to make to the quiz code, but if I start making major changes to the quiz code it will just take up too much of my time. So I can't add in a "closing date" function, what you will need to do is set the quiz to "allow play once" and get the results in as soon as possible after the match.
Hi battye

Completely understand, and I thank you again for all your help. In fact before reading this I just sent you a PM with a note of thanks.

If you dont view the capability to toggle a quiz as active (able to enter) or closed (no more entries possible) as a valid enhancement for UQM core, perhaps you could be so kind as to offer some pointers as to what Id need to do.

Cheers

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

I'll have a think about that, I might be able to incorporate a way for you to turn a quiz off into the script. That wouldn't be too difficult (adding a closing date as you can imagine would require some heavy changes :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

battye wrote:I'll have a think about that, I might be able to incorporate a way for you to turn a quiz off into the script. That wouldn't be too difficult (adding a closing date as you can imagine would require some heavy changes :wink:)
yep, a simple toggle would be fine - but if its not what you want to do with UQM, im fine trying to work it out here, though I may need some pointers :)
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Okay, here is the first part done. Toggling a quiz to be active or not isn't too hard at all:

Firstly, add a new column to the phpbb_quiz table in phpMyAdmin. Call the column "quiz_deactivate" and set it as an int. If you prefer using the SQL, the relevant query is:

Code: Select all

ALTER TABLE phpbb_quiz ADD quiz_deactivate INT;

Okay, next; save this file as subvertbeats_quiz.php and upload to your forum (in the same folder as index.php, viewtopic.php, quiz.php, etc). All it does right now is allow you to activate and deactivate quizzes... entering answers will come soon.

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' )
		{
			$quiz_id = (int) $_GET['id'];
			// $sql = 'SELECT
			// not complete
		}

		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();
		}
	}
?>
Now, open quiz.php and FIND:

Code: Select all

		if( $config['quiz_play_own_quiz'] == 0 )
		{
			if( get_author_of_quiz(request_var('q', 0)) == $user->data['user_id'] || get_author_of_quiz(request_var('quiz_id', 0)) == $user->data['user_id'] )
			{
				trigger_error($user->lang['QUIZ_USER_CANNOT_PLAY_OWN']);
			}
		}
AFTER ADD:

Code: Select all

// active check
$act_sql = 'SELECT quiz_deactivate FROM ' . QUIZ_TABLE . ' WHERE quiz_id = ' . request_var('q', 0);
$act_res = $db->sql_query($act_sql);
$act_check_look = $db->sql_fetchfield('quiz_deactivate');
if( $act_check_look > 0 )
{
trigger_error("This quiz has been deactivated");
} 

Try it out and let me know. Go to ./subvertbeats_quiz.php?mode=deactivate&id=XXX (making XXX the quiz id) to deactivate or turn off a quiz. If you make a mistake, you can go to ./subvertbeats_quiz.php?mode=activate&id=XXX to turn it back on (re-activate).
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

battye - amazing thanks!

I'll try this asap and post back here
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I'm actually making this for you right now, so if you can stay online we might be able to finish this in real-time.

Finish trying the above code first, and when you have done that (presuming it works) try this:

OPEN subvertbeats_quiz.php

FIND

Code: Select all

      if( $_GET['mode'] == 'enter_answers' )
      {
         $quiz_id = (int) $_GET['id'];
         // $sql = 'SELECT
         // not complete
      }
REPLACE WITH

Code: Select all

		if( $_GET['mode'] == 'enter_answers' )
		{
			$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">';
			while( $row = $db->sql_fetchrow($result) )
			{	
				echo '<strong>Question: ' . $row['quiz_question'] . '</strong><br />';
				echo 'Correct answer: <input type="text" name="question' . $row['quiz_question_id'] . '" />';
				echo '<br /><br />';
			}
			echo '<input type="submit" value="Submit" name="submit" />';
			echo '</form>';
		}
What the above does, will allow you to enter a quiz id into ./subvertbeats_quiz.php?mode=enter_answers&id=XXX and you should get a page listing the questions and a box for you to enter the real answer.
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

thanks battye

Ive made the changes locally, but my host seems to be down at the moment, so Im unable to validate. Hopefully will be back up soon.
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

edit.....still testing
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I tested the code above, I can't reproduce the tpl error. It displays fine for me.
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

Right, finally the host is back up and Ive been able to test this out.

Its all looking great, apart from one thing:

The questions in the quizzes we do are all multiple choice, yet the ?mode=enter_answers&id=XXX parameter returns a page that gives a text box for answers instead of the radio buttons.

Any ideas?
subvertbeats
Know-It-All
Know-It-All
Posts: 113
Joined: Thu Jan 14, 2010 6:07 pm

battye wrote:I tested the code above, I can't reproduce the tpl error. It displays fine for me.
Yes, that was my usage error, sorry....tried to edit the post before you saw it but you were too quick :)

See post above for my results
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

subvertbeats wrote:Right, finally the host is back up and Ive been able to test this out.

Its all looking great, apart from one thing:

The questions in the quizzes we do are all multiple choice, yet the ?mode=enter_answers&id=XXX parameter returns a page that gives a text box for answers instead of the radio buttons.

Any ideas?
Can't you just type in the answer? :)
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

I can, but im a little concerned since often the names are obscure, and contain non english characters

Such characters seem to be displayed ok in the actual quiz, but not in the page to enter the answers

eg for one name i get:

Marius Žaromskis

Hence Im not actually sure what to type in the correct answer box...a mistake here will of course affect the results
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Alright, maybe tomorrow I will bring up some multiple choice options (how about if it simply shows the options, and you can copy and paste the correct one in? That would be less hassle than getting radio boxes and the like working). Try and be online about 12 hours from now, or if not then about 18 hours from now... because this time for me is very late and I am logging off now :)

Anyway, this is what else I had done - you can play around with this. In fact, please do - I'm hoping it will give a read out of the right/wrong answers... please let me know the results so I know what to fix/improve/change.

subvertsbeats_quiz.php

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_set = explode(',', $question_id_hidden);
				$question_id_set_count = sizeof($question_id_set);

				$users = array();
				$users_information = 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'];

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

						else
						{
							echo 'User <strong>' . $row['quiz_player'] . '</strong> answered question <strong>' . $question_id_set[$i] . '</strong> INCORRECTLY. They entered the answer <strong>' . $row['quiz_answer'] . '</strong>.';
							$users_information[$row['quiz_player']][] = 'Question ' . $question_id_set[$i] . ' incorrect (' . $row['quiz_answer'] . ')';
						}
					}
				}

				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 '<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)
Post Reply