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:

Okay, try this and let me know how it goes.

OPEN quiz.php

FIND

Code: Select all

	// Let's check the stats, if the admin wants users to be able to play each quiz, once only.
	if( quiz_check_moderative_status($userdata['user_id'], $quiz_id) != ON &&

BEFORE ADD

Code: Select all

	// 06-11-08 quiz_play_once_addition
	$qpo_sql = $db->sql_query("SELECT quiz_user_list FROM " . QUIZ_GENERAL_TABLE . " WHERE quiz_id = $quiz_id");
	$qpo_row = $db->sql_fetchrow($qpo_sql);

	$qpo_user_plays = explode(',', $qpo_row['quiz_user_list']);

		for( $exp = 0; $exp < count($qpo_user_plays); $exp++ )
		{
			if( is_numeric($qpo_user_plays[$exp]) && $qpo_user_plays[$exp] == $userdata['user_id'] )
			{
			message_die(GENERAL_MESSAGE, 'You have already attempted to play this quiz');
			}
		}

	$qpo_addition_list = $qpo_row['quiz_user_list'] . ',' . $userdata['user_id'];

	$db->sql_query("UPDATE " . QUIZ_GENERAL_TABLE . " SET quiz_user_list = '" . $qpo_addition_list . "' WHERE quiz_id = $quiz_id");

	// -- end qpo addition
Try playing a quiz through to completion as well, I just want to make sure that you are able to see the results alright without it saying you've already played the quiz. Hopefully there are no silly parse errors from a missing semi colon, I double checked and it looked okay, but sometimes they have a habit of sneaking in there =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

Inserted your code and received no errors. Below is a report:

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

During a quiz:

a) If you refresh browser while timer is counting down you get the message: You have already attempted to play this quiz

b) If you click "back" in browser then select the same Quiz, again you get the You have already attempted to play this quiz

Time up!:

a) If the timer runs out, you get the usual js pop-up window telling you that "timer has expired!". Closing this and then clicking on "SUBMIT" results in the message: You have exceeded the time limit!. No answers are shown even though the ACP option: Do you wish for answers to be shown after the quiz is played? is set to YES.


Everything is working as it should (no room for cheats now!) except being able to see the answers. Is this right? Did you mean all the answers to show if ACP option is set to YES? Or UQM statistics?
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:

If you exceed the time limit the answers won't be shown to you, that was always an intended feature.

I just wanted to make sure it was displaying the answers correctly providing it was completed in the correct timeframe.

Would you like it to display the correct answers though, even if you don't complete it in the required time?
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

The way I see it, if a member runs out of time (and I'm still working out a "generous" time factor per question LOL), then there is no point in answers being shown heh heh (be like "rubbing it in" for losing LOL). This, I believe, combined with the new code (and all other parts, etc) you've provided to stop "cheaters" (for want of better description!) just makes UQM even more special and a definate must-have phpBB add-on!

There is one small thing I will point out is that if you set Should the quiz author be able to play their own quizzes? to YES, quiz authors (and administrators) can not replay a Quiz. In my own honest opinion though, I can't see why it should be necessary to replay a Quiz more than once any way. It'll just mean that members will try and achieve 100% and that'll take the fun out of it. Honesty is the best policy I say. ;)

Can not thank you enough for all your patience and time!

I also look forward to helping you any way I can with phpBB3 UQM as well: testing, bug reporting, feedback, etc. Let me know when the new thread is up!

Thanks! :D =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:

If you want to let admins and authors play more than once, try this:

Replace

Code: Select all

$qpo_sql = $db->sql_query("SELECT quiz_user_list FROM " . QUIZ_GENERAL_TABLE . " WHERE quiz_id = $quiz_id");
With

Code: Select all

$qpo_sql = $db->sql_query("SELECT quiz_author, quiz_user_list FROM " . QUIZ_GENERAL_TABLE . " WHERE quiz_id = $quiz_id");
FIND

Code: Select all

	$qpo_user_plays = explode(',', $qpo_row['quiz_user_list']);
BEFORE ADD

Code: Select all

	if( $qpo_row['quiz_author'] != $userdata['user_id'] || $userdata['user_level'] != ADMIN )
     {
FIND

Code: Select all

	// -- end qpo addition
BEFORE ADD

Code: Select all

      }
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

Your recommendations also inserted and works perfectly! :D

I noticed that there is a thread over at phpBB.com for UQM on phpBB3 (with posts from "cheeky" members who fail to realise that coders like you also have a life which comes first). Will you be starting a thread here when you are ready? I have some ideas... (as well as being willing to help test it, give feedback, etc, etc as I mentioned somewhere in a post above).

Back on original subject of this thread: With all your invaluable help, we now have a fully functioning countdown timer along with prevention of possible cheating. UQM will be installed on my "live" forum very soon! Thank you battye! :cheers: :prayer:
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:

quahappy wrote:Your recommendations also inserted and works perfectly! :D

I noticed that there is a thread over at phpBB.com for UQM on phpBB3 (with posts from "cheeky" members who fail to realise that coders like you also have a life which comes first). Will you be starting a thread here when you are ready? I have some ideas... (as well as being willing to help test it, give feedback, etc, etc as I mentioned somewhere in a post above).

Back on original subject of this thread: With all your invaluable help, we now have a fully functioning countdown timer along with prevention of possible cheating. UQM will be installed on my "live" forum very soon! Thank you battye! :cheers: :prayer:
Not a problem! :D

Yes I will start a thread here :)
In all likelihood it will be within the next week. There are a few maintenance things I need to get to first (like adding quick reply and a new theme here at CMX) but that won't take too long :)

You are sitting on 98 posts, well done =D> =D> :D Next milestone is "Know-It-All" at 100 :P

I have also added a link to this thread in the sticky in case other people are looking for the solution to the countdown timer. :)
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

Great! :D

I have another question which may warrant a new thread but here goes lol:

As you know, I've been doing all the code changes (thanks to you!), etc at my test site and will soon be adding it to my live forum. One thing I've never done within Quiz ACP is clear all the Statistics before all code changes were made (including the new SQL entry). I've cleared all the Statistics (basically to check all is in order) and whilst they have been cleared, I was unable to replay a Quiz that I've already done before statistics were cleared. Is this right?

I thought (dangerous I know!) that on clearing the statistics it would "empty" the SQL tables for all members statistcs meaning that they have the ability to play the quizzes again. The only reason why I've thought about this is that I was toying with the idea of "clearing" the statistics, say, once a year (or every six months) so that all members get another opportunity to play quizzes they've only been able to play once.

Other words, once statistics are cleared (or SQL tables truncated EXCEPT the actual quizzes?), stats are reset and all members can play a quiz again (only once) until the next time they are cleared a year later? Or is it just a case of "resetting" phpbb_quiz quiz_user_list SQL entry?

Hope that makes sense and I'm not setting out to make more work honest! Just a thought or something I may had overlooked. :)

admin/admin_quiz.tpl:

Code: Select all

   if( $HTTP_GET_VARS['mode'] == "clear_quiz_statistics" )
   {
		if( intval($HTTP_GET_VARS['confirm']) == 0 || !isset($HTTP_GET_VARS['confirm'])) // Give the user a chance to espape the deletion, or a second chance if they somehow got to this page without the confirm var. set.
		{
			message_die(GENERAL_MESSAGE, sprintf($lang['Quiz_admin_stats_clear_all_stats_do_confirm'], "<a href='" . append_sid('admin_quiz.'.$phpEx.'?mode=clear_quiz_statistics&confirm=1') . "'>", "</a>"));
		}
		
		else if( intval($HTTP_GET_VARS['confirm']) == 1 )
		{
		$sql = "TRUNCATE TABLE " . QUIZ_STATISTICS_TABLE;
			
			if( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Unable to truncate statistics table (' . QUIZ_STATISTICS_TABLE . ')', '', __LINE__, __FILE__, $sql);
			}
			
		message_die(GENERAL_MESSAGE, $lang['Quiz_admin_stats_clear_all_stats_do_deleted']);
		}
   }
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:

Yes, you have to reset quiz_user_list as well. Ordinarily clearing the stats table should be enough, but in your case you need to also clear this column.

FIND

Code: Select all

    $sql = "TRUNCATE TABLE " . QUIZ_STATISTICS_TABLE;
AFTER ADD

Code: Select all

$db->sql_query("UPDATE " . QUIZ_GENERAL_TABLE . " SET quiz_user_list = ''");
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 once again battye. Greatly appreciated! :D
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

Not important this but thought it would be a nice touch. I tried duplicating the countdown timer code so it appears at top of quiz questions (as it already does) and, at the end of quiz questions. Thinking that members won't lose track of how much time they have remaning because to check this, they have to scroll to top of quiz page, then back down to current question they are answering, etc.

I copied:

Code: Select all

          <tr>
             <td class="row1" width="100%" align="center" valign="middle" height="100%" colspan="2">
                
                  Time remaining: <span id="CountDownPanel"></span>
               
             </td>
          </tr>
AFTER, ADD ABOVE:

Code: Select all

	<!-- END quiz_row -->
Shows "Time remaining:" text but no timer. Does this mean it's not possible to show the timer more than once within a .tpl file?

Sorry to be a pain... again lol,
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:

Maybe if you try below, instead of above <!-- END quiz_row --> ?
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

Same result - just the text and no timer.

As I've said though, it's not that important, just thought of it as a continuity for members to see countdown timer at start of quiz questions and at bottom of quiz questions before they click on Submit. ;)
If you don't ask...
Post Reply