TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 196,004
  • Total Topics: 21,330
  • Online today: 136
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 108
  • Total: 108

TP Quiz Script (PHP Article)

Started by jacortina, October 30, 2007, 01:04:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jacortina

* * * Updated File Below * * *
See: http://www.tinyportal.net/index.php?topic=19688.msg160871#msg160871

All that was asked for was a simple script with just a couple of extra capabilities.

;D

Paste the contents of the attached "jquiz.php-article.txt" into a new PHP Article. There are only a few lines for configuration within the script:
$q_dir = 'quizfiles';                   // relative to forum base directory
$q_prefix = 'quiz';                     // filenames of XML quiz files must start with this (case-sensitive) string
$q_XML_help = 'Sources/JQuizXML.php';   // Location of XML Format 'help' file.

$q_admin_grps = array(2);               // Groups to admin quizzes (2-Global Moderators)
$q_mod_grps = array(2);                 // Groups to moderate/approve group changes
$q_mod_users = array();                 // Users allowed to moderate/approve group changes

$q_retake_pass = 'true';                // Can users re-take quizzes that they've passed?
        //      Can be overridden with per-quiz parameters.


It's set up to look for the XML Quiz files it uses in the directory 'quizfiles' and look for them as starting with the characters 'quiz' (put the files from the 'quizfiles.zip' into that directory; they're all the same three question quiz, but with different additional parameters).

Access to the Admin menu limited to forum admins and members of groups given in the array shown. Give a lot of information about the quizzes and is necessary for creation (or re-creation) of the DB table to keep scores. The other arrays are for those who can approve/dismiss pending membergroup changes which can be 'earned' by passing quizzes configure for that. Final config variable is for default behavior to handle passed test re-taking (can or cannot); this can be overridden by parameters in a quiz itself.

The last of the three files, 'JQuizXML.php', contains a single function to display instructions for the XML Quiz file itself. This script will handle the original format, but without any extra capabilities. The script is set up to look for it in the Sources directory. If it doesn't find it, the link for it won't show up so it IS optional.

Play with it. Beat on it. Complain about it.

I'm only about halfway through yanking the hard-coded text values and putting them in $txt strings for easier customization and translation.

I already see that this can be easily adapted to do surveys (saving answers) and Group Join Requests.

Here a couple of screenshots (Main Menu for all Users and Admin Menu)

tick

One word for ya.  OUTSTANDING!!!!

jacortina

Arrrggghhh! Last minute changes.

Use this one for the PHP Article.

Xarcell

#3
Ok, here's the first complaint lol...

When I try to create score table:

QuoteBLOB/TEXT column 'misc' can't have a default value
File: /home/.abigaildryer/xarcell/vestatt.org/Sources/Load.php(1735) : eval()'d code(305) : eval()'d code
Line: 425

:P

Thanks for working on this J.A.Cortina



EDIT:
Actually it also said I was running 1.1.3, was DB was 1.1.2. SO i upgraded to 1.1.4, then it still said my DB was 1.1.2. So then I run the upgrade.php and it fixed that part. However, the initial error still exists.

Xarcell

I tried using your updated j.quiz.php-article and got this error:

Quote
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/.abigaildryer/xarcell/vestatt.org/Sources/Load.php(1735) : eval()'d code(305) : eval()'d code on line 575

IchBin

Weird... Just tried it myself and didn't have any errors.

jacortina

Yes, I changed the (currently unused) misc field from a varchar to a text at the last minute after considering it's possible use to hold the (imploded) answers submitted and/or to allow for 'tell us a little about yourself' membergroup application data. It was one of the things addressed in the re-upload.

As with IchBin, I'm not experiencing that error and I can't find anything in the code.

Line 575 (in my editor) is the 2nd < tr > in this group:
echo '<table width="100%">';
echo '<tr><td width="20%" align="right"><b>Quiz Server Path:&nbsp;</b></td><td align="left">'.$boarddir.'/'.$q_dir.'/</td></tr>';
echo '<tr><td width="20%" align="right"><b>Quiz File Prefix:&nbsp;</b></td><td align="left">'.$q_prefix.' (above directory scanned for files named \''.$q_prefix.'*.xml\')</td></tr>';
echo '<tr><td width="20%" align="right"><b>Quiz Admin Groups:&nbsp;</b></td><td align="left">'.(count($q_admin_grps) ? implode(', ',$q_admin_grps) : 'None').'</td></tr>';
echo '<tr><td width="20%" align="right"><b>Quiz Mod Groups:&nbsp;</b></td><td align="left">'.(count($q_admin_grps) ? implode(', ',$q_mod_grps) : 'None').(count($q_mod_users) ? (' + Users '.implode(', ',$q_mod_users)) : '').'</td></tr>';
echo '<tr><td width="20%" align="right"><b>Can Retake Passed:&nbsp;</b></td><td align="left">'.(strtolower($q_retake_pass) == 'true' ? 'Yes' : 'No').' (board default - can be overridden in quiz parameters).</td></tr>';
echo '</table>';


Are you sure you got the full file when downloading? Should have 943 lines (it's a bit too big to include in a post, which is why I have to use an attachment).

Rus

This sounds great, definitely something to think about.

G6Cad

No errors for me, works wonders and thank you kindly for sharing it with us JA :)

Xarcell

I have 944 lines ???

Space after 943 :-\

I will attempt on a different site and report back.

This website is proudly hosted on Crocweb Cloud Website Hosting.