code - Politics Forum.org | PoFo

Wandering the information superhighway, he came upon the last refuge of civilization, PoFo, the only forum on the internet ...

Co-ordination of all publishing projects.

Moderator: Administrators PoFo

User avatar
By dgun
#14188812
If a time comes when some may be interested in doing this, maybe the work Demo and I did a couple of years ago will be of help.

please excuse my "double posts".

This is a phpBB3 mod/addon. The phpBB3 system handles creating accounts, logging in, and so forth. The top part of each page has some standard code that has to go into each page of a mod. The good thing about this is that the standard security measures of phpBB3 are therefore incorporated into the mod.

IIRC by using request_var, phpBB3 checks the input.

This mod is not complete, but it was well on its way. The code is sloppy and all of the features are not implemented.

But the main features function. I'm guessing it's 2/3 complete.

First file is pfquiz.php

Code: Select all<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();

$testChoices = "<option value=\"Strongly Agree\">Strongly Agree</option>
<option value=\"Agree\">Agree</option>
<option value=\"No Opinion\" selected>No Opinion</option>
<option value=\"Disagree\">Disagree</option>
<option value=\"Strongly Disagree\">Strongly Disagree</option>\n";

$template->assign_var('TESTCHOICES', $testChoices);
$welcome_user_msg = "";
$questions_per_page = 10;

if(isset($_POST['quiz_part'])){
$quiz_part = request_var('quiz_part',0);
}
else $quiz_part = 0;

$template->assign_var("QUIZ_PART", $quiz_part);


function partOne(&$template,&$db,&$user,$qp){
if($user->data['user_id'] == ANONYMOUS){
$welcome_user_msg = "You are not logged in. You are welcome to take the quiz, but the results will not be saved. Otherwise, please login or register.";
}
else{
$welcome_user_msg = "Welcome " . $user->data['username'];
}

$template->assign_var("NEXT_QUIZ_PART", $qp + 1);
$template->assign_var("WELCOME_USER_MSG", $welcome_user_msg);

$sql = "SELECT compass FROM pfquiz_compass WHERE omit = 0";
$result = $db->sql_query($sql);

while($row = mysql_fetch_row($result)){
$template->assign_block_vars('compass', array(
'COMPASS_NAME' => $row[0]
));
}
}

function getSurveyQuestions(){

//this stuff will be moved to a table

$survey_questions[0] = "Following the test, would you say your results are:<br/>
<select name=\"survey[]\">
<option value=\"good\">Good</option>
<option value=\"ok\">Just OK</option>
<option value=\"bad\">Not Good</option>
</select><br/>";

$survey_questions[1] = "How can we improve the test?<br/>
<input name=\"survey[]\" type=\"text\" size=\"100\"><br/>";

$survey_questions[2] = "Will you recommend this test to others outside the Politics Forum?<br/>
<select name=\"survey[]\">
<option value=\"yes\">Yes</option>
<option value=\"no\">No</option>
</select><br/>";

return $survey_questions;
}

function getpoints($ans, $dir){
//echo "<h1>" . $ans . " - " . $dir . "</h1>\n";
switch($ans){
case 'Strongly Agree': return $dir * 2;
case 'Agree': return $dir * 1;
case 'No Opinion': return 0;
case 'Disagree': return $dir * -1;
case 'Strongly Disagree': return $dir * -2;
default: return 0;
}
}


//this function will have to change to be more general
function gradequiz(){
$answers = request_var('answers',array(''));
$scores = request_var('scores', array(''=> 0));

for($i = 0; $i < sizeof($answers); $i+=3){
$scores["'" . $answers[$i] . "'"] += getpoints($answers[$i + 2], $answers[$i + 1]);
}

return $scores;
}

function survey(){

return 1;
}

//this will have to be changed to something more general
//and make sure to exclude the demographics and survey axis
function getAxisNames(){
$axis_names[0] = 'Protectionist vs. Free Trader';
$axis_names[1] = 'Controlled Market vs. Liberal Market';
$axis_names[2] = 'Big Government vs. Small Government';
$axis_names[3] = 'Nationalist vs. Internationalist';
$axis_names[4] = 'Marxist vs. Non-Marxist';
$axis_names[5] = 'Individual vs. Social';
$axis_names[6] = 'Moral Absolutist vs. Non-absolutist';
$axis_names[7] = 'Theist vs. Materialist';
return $axis_names;

}

//$quiz_over value used to stop duplicate quiz submimssions
//it will expire in an hour or when the user starts over at step 0
$quiz_over = request_var('QUIZ_OVER', '', false, true);
if($quiz_over == "TRUE" && $quiz_part == 0){
setcookie("QUIZ_OVER", "", time() - 3600);
}

//need to rethink the "logic" of this switch
switch($quiz_part){

case 0: $template->assign_var("NEXT_QUIZ_PART", $quiz_part + 1);
break;

case 1: partOne($template,$db,$user, $quiz_part);
//I put this section in a function in case it had to be called again in the next case.
break;
case 2: $tested_parts = request_var('compass', array(''));

if(sizeof($tested_parts) == 0){
//the user did not select the parts of the quiz he/she wanted to take
$template->assign_var("QUIZ_PART", $quiz_part - 1);
$template->assign_var("NEXT_QUIZ_PART", $quiz_part);
partOne($template,$db,$user,$quiz_part);
}
else{
$template->assign_var('PARTS_TAKEN', implode(",",$tested_parts));
$template->assign_var("NEXT_QUIZ_PART", $quiz_part + 1);

if($user->data['user_id'] != ANONYMOUS){
$sql = "SELECT * FROM pfquiz_tester WHERE name ='" . $db->sql_escape($user->data['username']) . "'";
$result = $db->sql_query($sql);
//obtain stored demographic information if in the DB,
//there can only be 1 or zero rows
if(mysql_num_rows($result) == 1){
$row = mysql_fetch_array($result, MYSQL_NUM);
$template->assign_vars(array(
'QLOCATION' => $row[1],
'BIRTH_YEAR' => $row[2],
'SEX' => $row[3],
'EDUCATION' => $row[4],
'IDEOLOGY' => $row[5]
));
}
else{
$template->assign_vars(array(
'QLOCATION' => "",
'NEW_TESTER' => "NEW_TESTER",
'SEX' => "Choose one",
'EDUCATION' => "Choose one",
'IDEOLOGY' => "Choose one"
));
}

}

else{
$template->assign_var('NO_DEMO_INFO', "TRUE");
}


}
break;
case 3: if(isset($_POST['new_tester'])){
//first time user has taken test
//if user is anonymous new_tester will not be set
$sql = "INSERT INTO pfquiz_tester (name, location, birth_year, sex, education, ideology) VALUES (";
$sql .= "'" . $db->sql_escape($user->data['username']) . "',";
$sql .= "'" . $db->sql_escape(request_var('qlocation', '')) . "',";
$sql .= "'" . $db->sql_escape(request_var('birth_year', 0)) . "',";
$sql .= "'" . $db->sql_escape(request_var('sex', '')) . "',";
$sql .= "'" . $db->sql_escape(request_var('education', '')) . "',";
$sql .= "'" . $db->sql_escape(request_var('ideology', '')) . "')";
$result = $db->sql_query($sql);

}
elseif(isset($_POST['update_demo'])){
//user has taken the test before but wishes to update demographic information
$sql = "UPDATE pfquiz_tester SET ";
$sql .= "location = '" . $db->sql_escape(request_var('qlocation', '')) . "',";
$sql .= "birth_year = '" . $db->sql_escape(request_var('birth_year', 0)) . "',";
$sql .= "sex = '" . $db->sql_escape(request_var('sex', '')) . "',";
$sql .= "education = '" . $db->sql_escape(request_var('education', '')) . "',";
$sql .= "ideology = '" . $db->sql_escape(request_var('ideology', '')) . "'";
$result = $db->sql_query($sql);
}

//figure out how many pages are on the quiz
//and how far along we are
//total_quiz_questions not set, so quiz has not beeb set up yet
if(!isset($_POST['total_quiz_questions'])){

//Have to know all the axis columns in order to constrcut the next query.
//need regex here and can avoid loop
$compass = explode(",", request_var('compass', ''));

$sql = "SELECT axis FROM pfquiz_axis WHERE compass IN (";
$numcompass = sizeof($compass);

for($i=0;$i<$numcompass;$i++){
if($i+1 == $numcompass){$sql .= "'" . $db->sql_escape($compass[$i]) . "')";}
else $sql .= "'" . $db->sql_escape($compass[$i]) . "',";
}

$result = $db->sql_query($sql);
$num_results = mysql_num_rows($result);
$sql ="";

for($i = 0; $i < $num_results; $i++){
$row = mysql_fetch_row($result);
//will need axis names later
$axis_names[$i] = $row[0];
if(($i + 1) == $num_results){
$sql .= "(SELECT id FROM pfquiz_questions WHERE axis = '" . $db->sql_escape($row[0]) . "' ORDER BY RAND() LIMIT 10) ORDER BY RAND()";
}
else{
$sql .= "(SELECT id FROM pfquiz_questions WHERE axis = '" . $db->sql_escape($row[0]) . "' ORDER BY RAND() LIMIT 10) UNION ";
}
}

//this query should take 10 randomnly from each axis and order all the questions randomnly
//and should look something like this if printed out
/**********************************************************************************************************
(SELECT id FROM pfquiz_questions WHERE axis ="Protectionist vs. Free Trader" ORDER BY RAND() LIMIT 10)
UNION
(SELECT id FROM pfquiz_questions WHERE axis ="Controlled Market vs. Liberal Market" ORDER BY RAND() LIMIT 10)
ORDER BY RAND()
************************************************************************************************************/

$result = $db->sql_query($sql);

$num_rows = mysql_num_rows($result);
$total_quiz_questions = $num_rows;
//integer division
$num_quiz_pages = $total_quiz_questions/$questions_per_page;


/***** check math here *****************/
if($total_quiz_questions % $questions_per_page > 0) $num_quiz_pages++;
$current_quiz_page = 1;

for($i = 0; $i < $num_rows ; $i++){
$row = mysql_fetch_row($result);
if($i + 1 == $num_rows) $question_nums .= $row[0];
else $question_nums .= $row[0] . ",";
}


//first time through
//echo "axis names size " . sizeof($axis_names);
for($i = 0; $i < sizeof($axis_names); $i++){
$template->assign_block_vars('scores', array(
'AXIS_NAMES' => "'" . $axis_names[$i] . "'",
'VALUE' => 0
));
}

mysql_free_result($result);
}
else{
$total_quiz_questions = request_var('total_quiz_questions',0);
$num_quiz_pages = request_var('num_quiz_pages',0);
$current_quiz_page = request_var('current_quiz_page',0) + 1;
$question_nums = request_var('question_nums',"");
$scores = gradequiz();

foreach($scores as $key => $value){
$template->assign_block_vars('scores', array(
'AXIS_NAMES' => $key,
'VALUE' => $value
));

}

}

$sql = "SELECT * FROM pfquiz_questions WHERE (";
//question_nums contains the id nums we want for our next query
//we need a certain number at a time
$qz_nums = explode(",", $question_nums);
if(sizeof($qz_nums) >= $questions_per_page){
for($i = 0; $i < $questions_per_page; $i++){
if($i + 1 == $questions_per_page) $sql .= "id = '" . $db->sql_escape($qz_nums[$i]) . "')";
else $sql .= "id = '" . $db->sql_escape($qz_nums[$i]) . "' OR ";
unset($qz_nums[$i]);
}
}
else{
for($i = 0, $length = sizeof($qz_nums); $i < $length; $i++){
if($i + 1 == $length) $sql .= "id = '" . $db->sql_escape($qz_nums[$i]) . "')";
else $sql .= "id = '" . $db->sql_escape($qz_nums[$i]) . "' OR ";
unset($qz_nums[$i]);
}
//also, we know this is the last page
}

$question_nums = implode(",",$qz_nums);

$result = $db->sql_query($sql);
$num = ($current_quiz_page - 1) * $questions_per_page;
while ($row = mysql_fetch_array($result, MYSQL_NUM)){
$num++;
$template->assign_block_vars('qloop', array(
'QUESTIONS' => $row[1],
'TYPE' => $row[3],
'NUMBER' => $row[0],
'ORDER' => $num,
'WEIGHT' => $row[2]
));
}

if($current_quiz_page >= $num_quiz_pages){
$template->assign_var("NEXT_QUIZ_PART", 4);
}
else $template->assign_var("NEXT_QUIZ_PART", 3);

$template->assign_var("QUESTION_NUMS", $question_nums);
$template->assign_var("TOTAL_QUIZ_QUESTIONS", $total_quiz_questions);
$template->assign_var("NUM_QUIZ_PAGES", $num_quiz_pages);
$template->assign_var("CURRENT_QUIZ_PAGE", $current_quiz_page);
$template->assign_var("FIRST_QUESTION", ($current_quiz_page * $questions_per_page) - ($questions_per_page - 1));

if($current_quiz_page * $questions_per_page <= $total_quiz_questions){
$template->assign_var("LAST_QUESTION", ($current_quiz_page * $questions_per_page));
}
else{
$template->assign_var("LAST_QUESTION", ((($current_quiz_page - 1) * $questions_per_page) + ($total_quiz_questions % $questions_per_page)));
}
break;

case 4: $scores = gradequiz();
$template->assign_var("NEXT_QUIZ_PART", 5);
$tv = "1.0.0"; //test version, this will have to be moved to a table

foreach($scores as $key => $value){
$sql = "INSERT INTO pfquiz_results (name, score, test_stamp,test_ver, axis) VALUES (";
$sql .= "'" . $db->sql_escape($user->data['username']) . "',";
$sql .= "'" . $db->sql_escape($value) . "',";
$sql .= "NOW(),";
$sql .= "'" . $db->sql_escape($tv) . "',";
$sql .= "'" . $db->sql_escape($key) . "')";
$template -> assign_block_vars('final_score', array(
'AXIS_NAME' => $key,
'SCORE' => $value
));

if($user->data['user_id'] != ANONYMOUS && $quiz_over != "TRUE"){
$result = $db->sql_query($sql);
}

}
setcookie("QUIZ_OVER", "TRUE", time() + 3600);

$s_q = getSurveyQuestions();
for($i = 0; $i < sizeof($s_q); $i++){
$template->assign_block_vars('survey_questions', array(
'S_Q' => $s_q[$i]
));
}
break;

case 5: $tv = "1.0.0"; //test version, this will have to be moved to a table
$sql = "INSERT INTO pfquiz_survey (test_ver, time_stamp, qanda) ";

// In the pfquiz_survey table, I'm just going to splice together
// the survey questions and answers and stick them in the qanda field.
// I'm doing this because the survey questions may change over time and
// attempting to handle it in other ways adds a good bit of complexity.

//these two arrays will always be of the same length
$s_a = request_var('survey', array(0)); //get the answers from the survey
$s_q = getSurveyQuestions();

$qanda = "";

for($i = 0; $i < sizeof($s_q); $i++){
$qanda .= $s_q[$i] . " ANSWER = " . $db->sql_escape($s_a[$i]) . "<br/>";
}

$sql .= "VALUES ('" . $tv . "',NOW(),'" . $qanda . "')";

$result = $db->sql_query($sql);
meta_refresh("3", $phpbb_root_path . "pfquiz.php");
break;
}


page_header("Politics Forum Quiz");

$template->set_filenames(array(
'body' => 'quiz_tmpl.html')
);

page_footer();

?>


quizadmin.php

Code: Select all<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();

/*******

Check all inputs

****************/

function query_info($sql, $msg){
return $msg . " " . $sql . "<br/>" . mysql_info() . mysql_error() . "<br/>";
}

include("quiz_moderator.php");
$template->assign_var('QUIZ_ADMIN_NAME', $quiz_admin_name);

if($user->data['username'] != $quiz_admin_name){
//then we don't do anything
//no reason to do any of the queries if the user is not the quiz admin

}

else{
//we do stuff
$sql = "SELECT COUNT(*) from pfquiz_questions";
$result = $db->sql_query($sql);
$count = mysql_result($result, 0);
$numupdated = 0;
$updated ="";

if(isset($_POST["update_questions"])){
$ckbxs = request_var('qzck', array(0));
for($i=0;$i<sizeof($ckbxs);$i++){
$qzq = request_var('q' . $ckbxs[$i], array(""));
$sql = "UPDATE pfquiz_questions SET question = '" . $db->sql_escape($qzq[2]) . "', axis = '" . $db->sql_escape($qzq[0]) . "', weight = '" . $db->sql_escape($qzq[1]) . "' WHERE id = '" . $ckbxs[$i] . "'";
$result = $db->sql_query($sql);
$updated .= query_info($sql, "");
}
$template->assign_var('UPDATED', $updated);
}

elseif(isset($_POST["delete_questions"])){
$ckbxs = request_var('qzck', array(0));
for($i=0;$i<sizeof($ckbxs);$i++){
$sql = "DELETE from pfquiz_questions WHERE id = '" . $db->sql_escape($ckbxs[$i]) . "'";
$result = $db->sql_query($sql);
$updated .= query_info($sql, "");
}
$template->assign_var('UPDATED', $updated);
}

elseif(isset($_POST["add_question"])){
$addq = request_var('addq', array(""));
if($addq[0] == "" || $addq[1] == "" || $addq[2] == ""){
$updated .= query_info("", "Need values for question, axis, and weight");
}
else{
$sql = "INSERT INTO pfquiz_questions (axis, weight, question) VALUES('". $db->sql_escape($addq[0]) . "','" . $db->sql_escape($addq[1]) . "','" . $db->sql_escape($addq[2]) . "')";
$result = $db->sql_query($sql);
if($result){$updated .= query_info($sql, "");}
}
$template->assign_var('UPDATED', $updated);
}

elseif(isset($_POST["add_compass"])){
$addC = request_var('addC','');
if($addC == ''){
$updated .= query_info("", "Please enter a compass name in the text box to create a new compass");
}
else{
$sql = "INSERT INTO pfquiz_compass (compass, omit) VALUES ('" . $db->sql_escape($addC) . "', 0)";
$result = $db->sql_query($sql);
$updated .= query_info($sql,"");
}
$template->assign_var('UPDATED', $updated);
}
elseif(isset($_POST["add_axis"])){
$addX = request_var('addX', array(""));
if($addX[0] == "" || $addX[1] == ""){
$updated .= query_info("", "Enter a value for the new axis and select a compass from the drop down box.");
}
else{
$sql = "INSERT INTO pfquiz_axis (axis, compass) VALUES ('" . $db->sql_escape($addX[0]) . "','" . $db->sql_escape($addX[1]) . "')";
$result = $db->sql_query($sql);
$updated .= query_info($sql, "");
}
$template->assign_var('UPDATED', $updated);
}

$sql = "SELECT * from pfquiz_questions ORDER BY axis";
$result = $db->sql_query($sql);
$temp = '';
while ($row = mysql_fetch_array($result, MYSQL_NUM)){

switch($temp){
case '': $divstart = TRUE;
$divend = FALSE;
$temp = $row[3];
break;
case $row[3]: $divstart = FALSE;
$divend = FALSE;
break;
default: $divend = TRUE;
$divstart = TRUE;
$temp = $row[3];
}

$template->assign_block_vars('qloop', array(
'QUESTIONS' => $row[1],
'TYPE' => $row[3],
'NUMBER' => $row[0],
'DIVSTART' => $divstart,
'DIVEND' => $divend,
'WEIGHT' => $row[2]
));
}

$sql = "SELECT DISTINCT axis from pfquiz_axis";
$result = $db->sql_query($sql);

while ($row = mysql_fetch_array($result, MYSQL_NUM)){
$template->assign_block_vars('axis_choices', array(
'AXIS' => $row[0]
));
}

$sql = "SELECT DISTINCT compass from pfquiz_compass";
$result = $db->sql_query($sql);

while ($row = mysql_fetch_array($result, MYSQL_NUM)){
$template->assign_block_vars('compass_choices', array(
'COMPASS' => $row[0]
));
}

} //end of doing stuff

page_header("Quiz Admin");

$template->set_filenames(array(
'body' => 'quiz_admin_tmpl.html')
);

page_footer();


?>
Last edited by dgun on 08 Mar 2013 04:26, edited 4 times in total.
User avatar
By dgun
#14188814
quiz_tmpl.html

Code: Select all<!-- INCLUDE overall_header.html -->

<div class="quiz">
<h3>Politics Forum Quiz (Beta)</h3>

<form method="post" action="pfquiz.php">

<!-- IF QUIZ_PART == 0 -->
<input type="hidden" value="{NEXT_QUIZ_PART}" name="quiz_part"/>

<p>This is the prototype of what will become the quiz for PoliticsForum.org. The quiz attempts to plot on a graph
testers by personal beliefs in regard to various subjects, such as politics, morality, and religion.</p>

<p>Testers are presented with a number of multiple choice questions and move up and down along a range of scores as the test progresses.
At the end of the test, the scores will be calculated and a 3d axis will be presented for each subject. At the moment, only the scores are
printed.</p>

<p>Although we can't claim that the methodology is scientific, the real value of the quiz will be that it allows testers to compare themselves to others from around the world.</p>

<p>Please keep in mind that this is still an early prototype. All suggestions and comments are welcome.</p>

<input type="submit" name="next_qpage" value="Start Quiz" />


<!-- ELSEIF QUIZ_PART == 1 -->
<p>{WELCOME_USER_MSG}</p>
<input type="hidden" value="{NEXT_QUIZ_PART}" name="quiz_part"/>

<p>Select the parts of the test you wish to take.</p>

<table>
<!-- BEGIN compass -->
<tr>
<td><label for="{compass.COMPASS_NAME}">{compass.COMPASS_NAME}</label></td><td><input type="checkbox" name="compass[]" value="{compass.COMPASS_NAME}" id="{compass.COMPASS_NAME}" /></td>
</tr>
<!-- END compass -->
</table>

<input type="submit" name="next_qpage" value="Next" />

<!-- ELSEIF QUIZ_PART == 2 -->
<fieldset>

<!-- IF NO_DEMO_INFO == "TRUE" -->

<p>ANONYMOUS user, please skip this page for now by clicking next. (This issue will be corrected later.)</p>

<!-- ELSE -->
<legend>Demographic Information</legend>

Select the area on the map that best describes the region you most closely identify with politically, whether you were born or raised there?<br/>
<input type="text" name="location" value="{LOCATION}" /><br/>

What year were you born?<br/>
<input type="text" name="birth_year" value="{BIRTH_YEAR}" /><br/>

What is your sex?<br/>
<select name="sex">
<option value="{SEX}" selected="selected">{SEX}</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select><br/>

What is your highest level of formal education?<br/>
<select name="education">
<option value="{EDUCATION}" selected="selected">{EDUCATION}</option>
<option value="Less">Less than high school</option>
<option value="High school">High School diploma</option>
<option value="Some college">Some College</option>
<option value="Technical">Technical School degree/Associate's Degree</option>
<option value="Bachelor">Bachelor's Degree</option>
<option value="Masters">Master's Degree</option>
<option value="Doctorate">Doctorate</option>
</select><br/>

Prior to the test, how would you describe yourself politically? (Please choose most accurate):<br/>
<select name="ideology">
<option value="{IDEOLOGY}" selected="selected">{IDEOLOGY}</option>
<option value="Conservative">Conservative (American/Dutch)</option>
<option value="Right Libertarian">Right Libertarian</option>
<option value="Fascist">Fasciest</option>
<option value="Liberal">Liberal (American)</option>
<option value="Democrat">Liberal Democrat</option>
<option value="Progressive">Progressive</option>
<option value="Social Democrat">Social Democrat</option>
<option value="Trotsky">Marxist, Trotsky</option>
<option value="Left Libertarian">Left Libertarian</option>
<option value="Anarchist">Anarchist</option>
<option value="Non">Non-ideological</option>
<option value="Other">Other</option>
<option value="dont know">I didn't know</option>
</select><br/>

<!-- IF NEW_TESTER != NULL -->
<input type="hidden" value="{NEW_TESTER}" name="new_tester"/>
<!-- ELSE -->
<input type="submit" name="update_demo" value="Update Demographic Info" /> OR
<!-- ENDIF -->

<!-- ENDIF -->

<input type="hidden" value="{NEXT_QUIZ_PART}" name="quiz_part"/>
<input type="hidden" name="compass" value="{PARTS_TAKEN}" />


<input type="submit" name="next_qpage" value="Next" />

</fieldset>

<!-- ELSEIF QUIZ_PART == 3 -->
<label>Questions {FIRST_QUESTION} - {LAST_QUESTION} of {TOTAL_QUIZ_QUESTIONS}</label>
<fieldset>
<!-- BEGIN qloop -->
{qloop.ORDER}. {qloop.QUESTIONS}<br/>
<input type="hidden" name="answers[]" value="{qloop.TYPE}" />
<input type="hidden" name="answers[]" value="{qloop.WEIGHT}" />
<select name="answers[]" value="">

{TESTCHOICES}
</select><br/>
<!-- END qloop -->
<input type="hidden" value="{NEXT_QUIZ_PART}" name="quiz_part"/>
<input type="hidden" value="{CURRENT_QUIZ_PAGE}" name="current_quiz_page"/>
<input type="hidden" value="{NUM_QUIZ_PAGES}" name="num_quiz_pages"/>
<input type="hidden" value="{TOTAL_QUIZ_QUESTIONS}" name="total_quiz_questions"/>
<input type="hidden" value="{QUESTION_NUMS}" name="question_nums"/>


<!-- BEGIN scores -->
<input type="hidden" name="scores[{scores.AXIS_NAMES}]" value="{scores.VALUE}" />
<!-- END scores -->


<input type="submit" name="next_qpage" value="Next" />
</fieldset>

<!-- ELSEIF QUIZ_PART == 4 -->
<h3>The axis scores are:</h3>
<!-- BEGIN final_score -->
{final_score.AXIS_NAME} = {final_score.SCORE}<br/>
<!-- END final_score -->
<hr/>

<!-- BEGIN survey_questions -->
{survey_questions.S_Q}
<!-- END survey_questions -->

<input type="hidden" value="{NEXT_QUIZ_PART}" name="quiz_part"/>
<input type="submit" name="next_qpage" value="Next" />

<!-- ELSE -->
<p>Thanks for the feedback.</p>

<!-- ENDIF -->
</form>
<h3><a href="quiz_admin.php">Go to quiz admin</a></h3>
</div>

<!-- INCLUDE overall_footer.html -->


grade_quiz.php --- this is just a stub and I don't recall whether or not I decided I needed this...

Code: Select all<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>

<html>
<head>
<link type="text/css" rel="stylesheet" href="pfstyle.css" />
</head>


<body>
<h3>
<?php

echo "This is the form that will grade the quiz.";

?>
</h3>

</body>

</html>


Here are the styles I added to the style sheet. I think these are the only ones. The others are standard for the standard phpbb3 style:

Code: Select all.quiz{
background-image: url("/images/0/123.gif");
//float: right;
//height: 250px;
margin: 10px;
width: 600px;
font-size: 1.2em;
}

.quiz li{clear:both}
.quiz select{float:left; margin:10px}
.quiz textarea{float:left; margin:10px}
.quiz hr{margin:10px; height:5px;clear:both}
User avatar
By dgun
#14188823
In order for some of this to make sense, you have to study the phpbb3 mod manuals available on their website. They have basically what amounts to an API.

The templates can be confusing. They are very similar to cake.php.

Also, you need to know a little about google maps API.

The core functionality works. A user can take a quiz. The admin can alter the quiz.

If I recall the quiz is graded as it goes. This probably needs to be changed.

I haven't done anything to this in 2 years, so I'm a little sketchy on the details.

the following are notes from the test forum:

1st raw form:

The quiz does not do anything as of yet. I converted the questions from BB code to HTML then I moved the questions into a database table.

Right now, I have one page that shows all the questions.

pfquiz.php

The quiz will be randomized later. Clicking the grade me button at the bottom takes you to a stub that will be used to grade the quiz.

I have an admin page that does no do anything at the moment but load all the fields from the question table and into a form that can be edited.

Like I said, at the moment nothing can be done to the form that's why I haven't bothered to block access to it, but soon it will check to see if you're an admin and if so you can edit the questions if you need to.

quiz_admin.php

I'm not sure if the 'weight' field is needed, but I put it there in case. It can be removed or altered later if need be.

A map will be added using Google's Map API once the form is functional.

I may not be able to do anything else until this weekend. But I plan to:

1) finish the admin page so the questions can be edited if need be
2) start on the grading of the quiz stub.
3) check if users are logged in to phpBB
4) initial logic for location selector (Google map API)

After that: a table for the results of the quiz, submitting the results to the DB, randomizing the questions, displaying results to the user.


I have the pagination correct.

The admin page will update.


The admin page has all but a couple of features and seems to be working rather well.

I do need to implement delete capabilities for compass and axis.

The quiz is doing mostly everything it should with the exception of two big things:

1) A map to select location for demographic information
and
2) Calculating the compass grades (it is tracking and then displaying each axis grade at the moment) and plotting it on as yet to be determined graph.

Other things to do:

A front page for the quiz
Clean up the code
Deal with browsing backwards in the quiz.
Help files for user and admin
Some pretty graphics of some sort, like maybe icons for each compass.
User avatar
By dgun
#14188830
Here are the sql dumps for the tables, which are in addition to the standard phpBB3 tables. This is only the structure of the tables, no data.

pfquiz_axis

Code: Select all-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 10.6.166.183
-- Generation Time: Mar 07, 2013 at 09:08 PM
-- Server version: 5.0.96
-- PHP Version: 5.3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `pol1113707384942`
--

-- --------------------------------------------------------

--
-- Table structure for table `pfquiz_axis`
--

CREATE TABLE `pfquiz_axis` (
  `axis` varchar(255) NOT NULL default 'other',
  `omit` tinyint(1) NOT NULL default '0',
  `compass` varchar(255) NOT NULL,
  PRIMARY KEY  (`axis`),
  KEY `FK_axis_compass` (`compass`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `pfquiz_axis`
--
ALTER TABLE `pfquiz_axis`
  ADD CONSTRAINT `FK_axis_compass` FOREIGN KEY (`compass`) REFERENCES `pfquiz_compass` (`compass`);


pfquiz_compass

Code: Select all-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 10.6.166.183
-- Generation Time: Mar 07, 2013 at 09:11 PM
-- Server version: 5.0.96
-- PHP Version: 5.3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `pol1113707384942`
--

-- --------------------------------------------------------

--
-- Table structure for table `pfquiz_compass`
--

CREATE TABLE `pfquiz_compass` (
  `compass` varchar(255) NOT NULL default 'Other',
  `omit` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`compass`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



pfquiz_questions

Code: Select all-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 10.6.166.183
-- Generation Time: Mar 07, 2013 at 09:11 PM
-- Server version: 5.0.96
-- PHP Version: 5.3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `pol1113707384942`
--

-- --------------------------------------------------------

--
-- Table structure for table `pfquiz_questions`
--

CREATE TABLE `pfquiz_questions` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `question` text NOT NULL,
  `weight` int(11) NOT NULL,
  `axis` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `FK_questions_axis` (`axis`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=97 ;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `pfquiz_questions`
--
ALTER TABLE `pfquiz_questions`
  ADD CONSTRAINT `FK_questions_axis` FOREIGN KEY (`axis`) REFERENCES `pfquiz_axis` (`axis`);


pfquiz_results

Code: Select all-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 10.6.166.183
-- Generation Time: Mar 07, 2013 at 09:12 PM
-- Server version: 5.0.96
-- PHP Version: 5.3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `pol1113707384942`
--

-- --------------------------------------------------------

--
-- Table structure for table `pfquiz_results`
--

CREATE TABLE `pfquiz_results` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL,
  `score` int(11) NOT NULL,
  `test_stamp` varchar(45) NOT NULL,
  `test_ver` varchar(45) NOT NULL,
  `axis` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `FK_results_tester` (`name`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `pfquiz_results`
--
ALTER TABLE `pfquiz_results`
  ADD CONSTRAINT `FK_results_tester` FOREIGN KEY (`name`) REFERENCES `pfquiz_tester` (`name`);


pfquiz_survey

Code: Select all-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 10.6.166.183
-- Generation Time: Mar 07, 2013 at 09:13 PM
-- Server version: 5.0.96
-- PHP Version: 5.3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `pol1113707384942`
--

-- --------------------------------------------------------

--
-- Table structure for table `pfquiz_survey`
--

CREATE TABLE `pfquiz_survey` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `test_ver` varchar(45) NOT NULL default '',
  `time_stamp` varchar(255) NOT NULL default '',
  `qanda` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;


pfquiz_tester

Code: Select all-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: 10.6.166.183
-- Generation Time: Mar 07, 2013 at 09:13 PM
-- Server version: 5.0.96
-- PHP Version: 5.3.4

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `pol1113707384942`
--

-- --------------------------------------------------------

--
-- Table structure for table `pfquiz_tester`
--

CREATE TABLE `pfquiz_tester` (
  `name` varchar(255) NOT NULL,
  `location` varchar(255) NOT NULL,
  `birth_year` int(10) unsigned NOT NULL,
  `sex` varchar(45) NOT NULL,
  `education` varchar(45) NOT NULL,
  `ideology` varchar(255) NOT NULL,
  PRIMARY KEY  (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
User avatar
By dgun
#14189056
You're welcome. I wish I could have finished it. When I changed jobs it made it difficult to do work on side projects.

There is no evidence whatsoever that the IDF and I[…]

Voting for this guy again would be a very banan[…]

The US government does not care about the ongoing […]

I would also say that the extreme Left can be j[…]