phpBB2 UQM - No Quiz Authors ACP

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

User avatar
quahappy
Happy, not Quappy
Happy, not Quappy
Posts: 2266
Joined: Fri Oct 10, 2008 8:56 pm
Location: South Yorkshire, UK

Back again for one final time and this topic can be resolved. ;)

I've modified quiz_play_once_addition code to quiz.php as the additional AFTER, ADD below:

FIND

Code: Select all

                 if( is_numeric($qpo_user_plays[$exp]) && $qpo_user_plays[$exp] == $userdata['user_id'] )
                 {
AFTER, ADD

Code: Select all

             if( quiz_check_moderative_status($userdata['user_id'], $quiz_id) == ON )
             {
             $message_ctl = sprintf($lang['Quiz_author_cannot_play_give_edit_options'], '<a href="' . append_sid("quiz_cp.$phpEx?mode=edit&q=$quiz_id") . '">', '</a>', '<a href="' . append_sid("quiz_cp.$phpEx?mode=delete&q=$quiz_id") . '">', '</a>', '<a href="' . append_sid("quiz_cp.$phpEx?mode=move&q=$quiz_id") . '">', '</a>');
              }
.... allowed countdown timer to be restarted if browser page was refreshed or browser back selected instead of the "You have already attempted to play this Quiz" message. Basically I've moved the quiz_check_moderative_status function to before $qpo_sql = $db->sql_query("SELECT quiz_user_list....

Anyhow, to save confusion, here's the modified code. Slightly messy but it works. ;)

Code: Select all

       // 06-11-08 quiz_play_once_addition

         $message = 'You have already attempted to play this Quiz'  . '<br /><br />' . sprintf($lang['Quiz_click_return_quiz'], '<a href="' . append_sid("quiz.$phpEx") . '">', '</a>');

         if( quiz_check_moderative_status($userdata['user_id'], $quiz_id) == ON )
         {
         $message_ctl =  '<br /><br />' . sprintf($lang['Quiz_author_cannot_play_give_edit_options'], '<a href="' . append_sid("quiz_cp.$phpEx?mode=edit&q=$quiz_id") . '">', '</a>', '<a href="' . append_sid("quiz_cp.$phpEx?mode=delete&q=$quiz_id") . '">', '</a>', '<a href="' . append_sid("quiz_cp.$phpEx?mode=move&q=$quiz_id") . '">', '</a>');
          }

       $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, $message . $message_ctl);
             }
          }

       $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
The above also includes option (link) for the user to return to Quiz Index page.

Also, in an ideal situation, the You have already attempted to play this Quiz shouldn't be true if it's a quiz created by the quiz author as on first "play" the You cannot play quizzes which you have submitted! is correctly displayed (along with moderator controls). Of course, thereafter, the quiz_user_list gets updated meaning that subsequent selection of a Quiz created by the Quiz Author results in You have already attempted to play this Quiz (again, with Moderator controls).

Like I've said elsewhere, I'm not an expert on php and still getting to grips with it so forgive me if it's not quite the right way to do what I've done.
: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

EDIT: I wasn't going to be beaten with Information messages (see "ideal situation..." above) so here's the code again that displays all correct Information messages according to moderator status, quiz already played, etc:

Code: Select all

       // 06-11-08 quiz_play_once_addition

         $message = 'You have already attempted to play this Quiz' .'<br />';

         if( quiz_check_moderative_status($userdata['user_id'], $quiz_id) == ON )
         {
         $message = $lang['Quiz_author_cannot_play'] .'<br />' . sprintf($lang['Quiz_author_cannot_play_give_edit_options'], '<a href="' . append_sid("quiz_cp.$phpEx?mode=edit&q=$quiz_id") . '">', '</a>', '<a href="' . append_sid("quiz_cp.$phpEx?mode=delete&q=$quiz_id") . '">', '</a>', '<a href="' . append_sid("quiz_cp.$phpEx?mode=move&q=$quiz_id") . '">', '</a>') .'<br />';
          }

       $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, $message . '<br />' . sprintf($lang['Quiz_click_return_quiz'], '<a href="' . append_sid("quiz.$phpEx") . '">', '</a>'));
             }
          }

       $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
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

Darn it! Well it worked so far and then, although a Quiz Author had the Moderator Control options (only for OWN quizzes they created), clicking on any one of them (EDIT, DELETE, MOVE) resulted in a "You are not a Quiz Moderator!" message! On checking quiz_cp.php there is no checking for a quiz author (unless I overlooked something) so done this:

OPEN quiz_cp.php
FIND

Code: Select all

$users = explode(',', $board_config['Quiz_Moderators']);

	for( $o = 0; $o < count($users); $o++ )
	{
		if( $userdata['user_id'] == intval($users[$o]) )
		{
			$quiz_moderator = ON;
		}
	}
AFTER, ADD

Code: Select all

// Does Quiz Author have permission to Moderate own Quiz?
	if( $board_config['Quiz_Author_Mod'] == ON )
	{
		$sql = "SELECT quiz_author FROM " . QUIZ_GENERAL_TABLE . " WHERE quiz_id = '$quiz_id'";
		
		if(!$result = $db->sql_query($sql))
		{
			message_die(GENERAL_ERROR, '', 'Could not obtain the user id', __LINE__, __FILE__, $sql);
		}
		
		$row = $db->sql_fetchrow($result);

		if( $row['quiz_id'] == intval($user_id) )
		{
			$quiz_moderator = ON;
		}
	}
// End Quiz Author check
And in includes/functions_quiz.php:

FIND

Code: Select all

        if( $row['user_id'] == intval($user_id) )
REPLACE WITH

Code: Select all

	 if( $row['quiz_id'] == intval($user_id) )
Got there in the end. :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

Pleased to say that this MOD (phpBB2) went "live" on 1st January at my site. I have altered quite a bit in terms of style layout, links, etc. Thanks battye for all your help. :D
If you don't ask...
Post Reply