Page 2 of 2

Re: Looking for Additions

Posted: Tue May 20, 2008 7:58 am
by battye
DakotaSurfer wrote:I have another option for you... what if someone make a valid mistake and hit "Enter" before they were done with a quiz. Now I know he quiz gets assigned a number. If I wanted to delete quiz #4 or q=4 for user# 738 or $q_user_id = 738, could that be put in that SQL deletion routine so I can only delete the info for one quiz on a specific member using a php file? (here's hoping)
My only concern about this, as that this query will remove all q=4 played by user_id 738. There is no way of limiting it to just the one he made a mistake on. Having said that, if the user has only played the quiz in question (excuse the pun :P ) once, then it is not a problem:

Here is the code:

Code: Select all

<?php
/***************************************************************************
 *                               db_update.php
 *                            -------------------
 *
 *   copyright            : ©2003 Freakin' Booty ;-P & Antony Bailey
 *   project              : http://sourceforge.net/projects/dbgenerator
 *   Website              : http://freakingbooty.no-ip.com/ & http://www.rapiddr3am.net
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

// Edit these
$q_user_id = 738;
$q_quiz_del_id = 4;
$q_quiz_table = 'phpbb_quiz_statistics';

if( !$userdata['session_logged_in'] )
{
    $header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
    header($header_location . append_sid("login.$phpEx?redirect=db_update.$phpEx", true));
    exit;
}

if( $userdata['user_level'] != ADMIN )
{
    message_die(GENERAL_MESSAGE, 'You are not authorised to access this page');
}


$page_title = 'Updating the database';
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

echo '<table width="100%" cellspacing="1" cellpadding="2" border="0" class="forumline">';
echo '<tr><th>Updating the database</th></tr><tr><td><span class="genmed"><ul type="circle">';


$sql = array();
$sql[] = "DELETE FROM $q_quiz_table WHERE user_id = $q_user_id AND quiz_id = $q_quiz_del_id";

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

        echo '<li>' . $sql[$i] . '<br /> +++ <font color="#FF0000"><b>Error:</b></font> ' . $error['message'] . '</li><br />';
    }
    else
    {
        echo '<li>' . $sql[$i] . '<br /> +++ <font color="#00AA00"><b>Successful</b></font></li><br />';
    }
}


echo '</ul></span></td></tr><tr><td class="catBottom" height="28">&nbsp;</td></tr>';

echo '<tr><th>Installation Complete</th></tr><tr><td><span class="genmed">Please be sure to delete this file now.<br /></span></td></tr>';
echo '<tr><td class="catBottom" height="28" align="center"><span class="genmed"><a href="' . append_sid("index.$phpEx") . '">Go back to your index page</a>.</span></td></table>';

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

?>

The new additions are:

// Edit these
$q_user_id = 738;
$q_quiz_del_id = 4;
$q_quiz_table = 'phpbb_quiz_statistics';

and

$sql[] = "DELETE FROM $q_quiz_table WHERE user_id = $q_user_id AND quiz_id = $q_quiz_del_id";



Like all database deletions, back up your database before running it, just to be on the safe side.

Re: Looking for Additions

Posted: Wed May 28, 2008 9:57 pm
by DakotaSurfer
Thanks for the fix... I've been gone because I was sick and then I had to go out-of-town for a few days on John Wayne business.

That looks like exactly what I need and since I have it set so they can only play a quiz once, multiple plays of the same quiz is not a problem. Thanks again for your time and expertise. Duke fans thank you everywhere.

Re: Looking for Additions

Posted: Mon Jun 09, 2008 3:28 am
by DakotaSurfer
I've tried your latest addition to my request and it worked great. Specific member and specific quiz deleted just fine. Others may be able to use this as well. Thanks again for all your help.

Re: Looking for Additions

Posted: Tue Jun 10, 2008 11:44 am
by battye
DakotaSurfer wrote:I've tried your latest addition to my request and it worked great. Specific member and specific quiz deleted just fine. Others may be able to use this as well. Thanks again for all your help.
That is fantastic news, I'm glad it worked. If you have any other requests like this please don't hesitate to ask, I will do my best to help :)

Re: Looking for Additions

Posted: Sat Aug 02, 2008 5:26 pm
by DakotaSurfer
The quiz contest worked out fine and now I want to open up the quizzes for everyone to play as they like but I would like a couple Modifications if you have the time.

First there is a section at the bottom of the stats page that shows the names of all the quizzes and how many times they have been played. "Most Played Quizzes" Basically I want to get rid of this list. I'd rather have the room so show more quiz results.

Second under the ACP Quiz Configuration section I would like to limit the number of times a member can play the quizzes. I want them to be able to play more than once but not more than 3 - 5 times. Maybe an option to set the max. plays per quiz per member.

Hate to bother you again but I'm in sort of a unique situation with our members and our benefactor. Thanks for any help you can give.