Dynamic timer

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:

Sorry, I haven't been able to get on for a couple of days :(

Yes it is feasible. Hopefully easy since it is back on my own home turf - PHP 8)

Try this, replace all instances of:

Code: Select all

	<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
	ActivateCountDown("CountDownPanel", 100);
}
</script>
With (the only change is on the 4th line):

Code: Select all

	<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
	ActivateCountDown("CountDownPanel", {COUNTDOWN_TIMER_IN_SECONDS_UQM});
}
</script>
For the life of me I can't find the database field which defines the number of second allowed for each question. If you are able to copy and paste in your next reply the 20 or so lines that precede the section below in your copy of quiz_install.php (the ones that say INSERT INTO " . CONFIG_TABLE . " ) I can give you the correct code - at the moment it is just working on the basis of 10 seconds per question (as represented by the "10" in the $timer_in_seconds above.... sorry if that was confusing :cry:

20 lines preceding this:

Code: Select all

		for ($i = 0; $i < count($sql); $i++) 
		{
			if(!$result = $db->sql_query($sql[$i]))

Anyway, in quiz.php FIND

Code: Select all

		if($quiz_type == MULTIPLE_CHOICE)
		{
After add:

Code: Select all

		$timer_in_seconds = (10*number_of_questions($quiz_id, QUIZ_MULTIPLE_CHOICE_TABLE));
FIND

Code: Select all

				$template->assign_vars( array(
				 "U_QUIZ_NAME" => $quiz_name,
AFTER ADD

Code: Select all

"COUNTDOWN_TIMER_IN_SECONDS_UQM" => $timer_in_seconds,
Then after:

Code: Select all

		if($quiz_type == INPUT_ANSWER)
		{
ADD:

Code: Select all

		$timer_in_seconds = (10*number_of_questions($quiz_id, QUIZ_INPUT_TABLE));
And again find (this is the second instance of it)

Code: Select all

				$template->assign_vars( array(
				 "U_QUIZ_NAME" => $quiz_name,
AFTER ADD

Code: Select all

"COUNTDOWN_TIMER_IN_SECONDS_UQM" => $timer_in_seconds,
And for (find):

Code: Select all

		if($quiz_type == TRUE_FALSE)
		{
After add:

Code: Select all

		$timer_in_seconds = (10*number_of_questions($quiz_id, QUIZ_TRUE_FALSE_TABLE));
And again find: (third instance)

Code: Select all

				$template->assign_vars( array(
				 "U_QUIZ_NAME" => $quiz_name,
AFTER ADD

Code: Select all

"COUNTDOWN_TIMER_IN_SECONDS_UQM" => $timer_in_seconds,



Fingers crossed it works :o
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

battye...... it WORKED!!! Can't even begin to tell you how elated I am!!

Nope - everything you typed made perfect sense. I've installed so many MOD's since my site went live 2 years ago that I am beginning to understand how things work (I've tweaked some things myself - only cosmetic stuff). I was going to learn javascript at one time but settled for HTML (the basics off) just to set-up a couple of sites for friends. ;)

One more thing to solve now then - the SQL to link the timer set in UQM. Here's the quiz_install.php section you requested:

Code: Select all

	$sql[] = "ALTER TABLE " . SESSIONS_TABLE . " ADD `session_quiz_categories` VARCHAR( 255 ) NOT NULL;";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_show_answers', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Register_Play', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Post_Count_Play', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Post_Requirement', '1')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Play_Once', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Author_Play', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Min_Max_Questions', '5,10')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Author_Mod', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Banned', '')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Moderators', '')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Stats_Display', '10')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Mod_Submit', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Cash_Currency', 'user_points')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Cash_Incorrect', '1')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Cash_Correct', '1')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_Cash_Tax', '2')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_CashMOD_On', '" . ON . "')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_packs_category', '1')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_packs_bot', 'Quartz')";
	$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value) VALUES ('Quiz_timeout', '10')";
At a guess I'd say it's Quiz_timeout ? lol. Of course, I wouldn't then know how to call the quiz timeout from SQL so I eagerly await your code!

Thank you so much for ALL your help. We are getting there. Such a shame that we now have phpBB3 although I will be making the switch early next year no doubt but I understand UQM is also in progress for phpBB3 too and that is great (hope it's got all that you've done for me)
If you don't ask...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Okay, hopefully this one will be easy as well :)

Find all places where you have:

Code: Select all

 $timer_in_seconds = (10*number_of_questions ...
Replace the 10 each time with:

Code: Select all

$board_config['Quiz_timeout']
So it says:

Code: Select all

 $timer_in_seconds = ($board_config['Quiz_timeout']*number_of_questions ...
I will start UQM development again in December, and there will be a lot of community input! :D
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

Absolutely brilliant! All works perfectly. Thank you SO much!

There is just one more question which "should" be in a new thread and I think I may know how to figure it out. Members at my site have to make so many post per month before they get (or retain) access to key features like the Arcade Room, Hangman, and soon, UQM! If members meet the criteria, they are entered into a Usergroup called "Access All Areas". I noticed that in UQM admin controls there is no option to select a Usergroup.

Is coding for this easy enough to do?
If you don't ask...
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

quahappy wrote:Absolutely brilliant! All works perfectly. Thank you SO much!

There is just one more question which "should" be in a new thread and I think I may know how to figure it out. Members at my site have to make so many post per month before they get (or retain) access to key features like the Arcade Room, Hangman, and soon, UQM! If members meet the criteria, they are entered into a Usergroup called "Access All Areas". I noticed that in UQM admin controls there is no option to select a Usergroup.

Is coding for this easy enough to do?
It is! battye has kindly started a new thread which can be found here.

battye... I think I've found a "flaw" which I'm not 100% sure could be related to having to insert the js call function at the beginning of the quiz_play... files because it refused to work if the code was inserted before </head> in overall_header.tpl:

Code: Select all

<script type="text/javascript">
window.onload=WindowLoad;
function WindowLoad(event) {
   ActivateCountDown("CountDownPanel", {COUNTDOWN_TIMER_IN_SECONDS_UQM});
}
</script>
If you refresh the page before timer runs out (or even when it has run out!), the timer starts again, meaning that it gives would-be "'net searchers" more time to get all questions right. :(

I've just tried again to remove ALL of the above code from quiz_play... files and insert it back into overall_header.tpl and nope, the timer doesn't show. And yes the below is also inserted:

Code: Select all

<script type="text/javascript" src="CountDown.js"></script>
I'm guessing that when refresh is clicked on, it's the actual quiz_play.. file that is refreshed before of the js script in each one. Am I right in saying that if the CountDown.js script in overall_header.tpl DID work, refreshing any one of the quiz_play files (while playing) wouldn't reset the timer? Or have I got that wrong?

Sorry to be an utter pain battye. Bet you'll be glad to see back of me! lol. One compensation though, I'm more than happy to test your phpBB3 version of this for feedback, bug reporting etc, as I will be installing a hidden test of phpBB3 on my site soon. ;)
If you don't ask...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

It's been a while, so I might be wrong, but if you set it in the ACP so users can only play quizzes once, does that fix this problem?

I can't remember whether I made it update the database the moment a user clicks a quiz, or only once they have clicked submit. If it is the former, this will stop people from refreshing the page.

Try it out and let me know what the results are :)
Sorry to be an utter pain battye. Bet you'll be glad to see back of me!
Not at all! There hasn't been a UQM question posted here for quite a while, so I was glad to see it :) Looking at the code again makes me want to get cracking on a phpBB3 version of this MOD... I'm glad to hear you will be sticking around to help out with testing the new version :D

My intention was to start work on it in mid-December, but time permitting I might instead try and make a start in the coming weeks :)
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

Only be too glad to help in any way I can with phpBB3 UQM. To say you've been a great help to me is an understatement. Thank you! :D

In phpBB2 UQM ACP: Should users only be able to play each quiz once? Set to YES

a) Refreshing the page at any time during countdown timer restarts the timer

b) When "Your timer has expired" window pops up and you close it, refreshing also restarts the countdown timer.

c) Clicking on SUBMIT after timer has run out gives "You have exceeded the time limit!" information box. At this stage, clicking on either Refresh (shortcut key is F5) or "back a page" (in browser) still gives you the aforementioned information box. ;)

So basically, when the quiz questions are displayed, it is possible to restart the same quiz at anytime simply by refreshing the page regardless of wether the time has run out or not. ONLY when submit option has been selected can that quiz no longer be played.

As you mentioned, it looks like the database updates only once they have clicked submit?

Hope my information helps. ;)
If you don't ask...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

As you mentioned, it looks like the database updates only once they have clicked submit?
Yes, from your information (thanks, that was exactly what I needed to know) it shows the database is updated after clicking submit.

Just to clarify, would you like me to provide some code so that users can only play the quiz in the X seconds after they have actually clicked the link?


These are obviously issues that will need to be addressed in a more permanent way in the phpBB3 version of UQM. This is not to do with the countdown javascript (incidentally), it's a way of people getting around the time limits that are in place in the PHP code. I guess it was an oversight when I originally implemented the time limits feature :(
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

battye wrote:Just to clarify, would you like me to provide some code so that users can only play the quiz in the X seconds after they have actually clicked the link?
Yes please. But only if it isn't too much trouble and this will also help with the phpBB3 UQM version. ;)
battye wrote:These are obviously issues that will need to be addressed in a more permanent way in the phpBB3 version of UQM. This is not to do with the countdown javascript (incidentally), it's a way of people getting around the time limits that are in place in the PHP code. I guess it was an oversight when I originally implemented the time limits feature :(
I think UQM is brilliant and you've done a grand job. I believe, like all MOD's (especially "entertainment" add-ons), you think the program is "all there" and then members start requesting or recommending new features (bit like me oops lol). Which in itself is a good thing because it shows the amount of interest and popularity which is all positive.

Oversight? Blimey. I'm more than aware that new and existing MOD's are all done voluntarily (and unpaid) in your own time outside of day-to-day stuff. I'm also part of a beta testing group (for another MOD which will be the final for phpBB2) elsewhere and get slightly peeved when pressure is put on developers for release dates, etc. from members. Think some forget that we all have lives lol. (I don't know where I find time myself with five kids but I like to keep busy heh heh).

Put simply, if you had said to me I am not supporting phpBB2 UQM any more because of phpBB3 UQM WIP, I would had accepted your answer without hesitation. 8)
If you don't ask...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Do you have access to phpMyAdmin?
If you have cPanel, there should be a link in there somewhere amongst the database settings.

This change will need an addition to the database, so we need to add a new column to the quiz table.
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

battye wrote:Do you have access to phpMyAdmin?
If you have cPanel, there should be a link in there somewhere amongst the database settings.
Yes to both questions. ;)
battye wrote:This change will need an addition to the database, so we need to add a new column to the quiz table.
Okies. Ready when you are and thanks again. :D
If you don't ask...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

Okay, here is the database change you need to make:

1. Go to phpMyAdmin
2. Go to the _quiz table (phpbb_quiz, or forum_quiz... it depends on your table prefix)
3. Click "Structure" - a top tab at the top
4. Then click "Go" at the bottom where it says "Add 1 new row at the end of the table"
5. Where it says "Field", give it the name "quiz_user_list" (without the quotations)
6. For "Type" give it "Text" from the drop down list.
7. The rest can remain untouched, and just click "Save"

After doing this you should see a new column quiz_user_list in the _quiz table. Let me know when this bit is done and I will organise the PHP code to go with it :)
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

Cheers battye!

Column quiz_user_list created. (table prefix at my site is phpbb_ so column added to phpbb_quiz). ;)
If you don't ask...
User avatar
battye
Site Admin
Site Admin
Posts: 14391
Joined: Sun Jan 11, 2004 8:26 am
Location: Australia
Contact:

I will post the code by this time tomorrow (I don't have enough time tonight I'm afraid) :)
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)
User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

No worries! I'm working on fixing a bug in Christmas style I'm trying to get up and running. (Forum text for new posts not showing up in red :( ) As I said before, I hope all the help you are giving me contributes in some way to your phpBB3 UQM. ;)
If you don't ask...
Post Reply