Quizcreator - Quiz creator.php

From Meta, a Wikimedia project coordination wiki
Jump to navigation Jump to search
Blue Glass Arrow.svg MediaWiki logo.png
This page should be moved to MediaWiki.org.
Please do not move the page by hand. It will be imported by a MediaWiki.org administrator with the full edit history. In the meantime, you may continue to edit the page as normal.
<?php

#apd_set_pprof_trace();
# Main wiki script; see design.doc
#

$wgRequestTime = microtime();

//unset( $IP );
@ini_set( 'allow_url_fopen', 0 ); # For security...
if( !file_exists( '../LocalSettings.php' ) ) {
  if ( file_exists( '../config/LocalSettings.php' ) ) {
    die( "To complete the installation, move <tt>config/LocalSettings.php</tt> to the parent directory.\n" );
  } else {
    die( "You'll have to <a href='config/index.php'>set the wiki up</a> first!" );
  }
}

# Valid web server entry point, enable includes.
# Please don't move this line to includes/Defines.php. This line essentially defines
# a valid entry point. If you put it in includes/Defines.php, then any script that includes
# it becomes an entry point, thereby defeating its purpose.
define( 'MEDIAWIKI', true );

require_once( '../includes/Defines.php' );
require_once( '../LocalSettings.php' );
require_once( '../includes/Setup.php' );

wfProfileIn( 'main-misc-setup' );
OutputPage::setEncodings(); # Not really used yet

# Debug statement for user levels
# print_r($wgUser);

# If the user is not logged in, the Namespace:title of the article must be in
# the Read array in order for the user to see it. (We have to check here to
# catch special pages etc. We check again in Article::view())
if ( !is_null( $wgTitle ) && !$wgTitle->userCanRead() ) {
$wgOut->loginToUse();
$wgOut->output();
exit;
}

if ($wgUser->getID() != 0) {
$wgOut->setArticleFlag( false );

$wgTitle = Title::makeTitle( NS_SPECIAL, "Custom" );

$wgOut->setArticleRelated( false );
$wgOut->setRobotPolicy( "noindex,follow" );

require_once( '../quizzes/function.php' );

//if (!$_POST['quizname']&&!$_POST['question']) {
if (!file_exists("temp.txt")){

				 $wtext = "==Name of quiz==\n";
				 $text .= "Write the name of the quiz below, and click submit.<br><br>";
				 $text .= "If you need additional help using the quiz creator, click ";
				 $text .= "<a href=\"http://www.unitorganizer.com/mediawiki/index.php/Quiz_Creator\">here</a><br><br>";
				 
				 $text .= create_quiz_form ();
				 $text .= create_input_button ("quizname","text","");
				 $text .= create_submit_button ("submit_quizname","submit");				 
				 
				 if ($_POST['quizname']) {
 	 			     $quiz_name = $_POST['quizname'];
				     $quiz_file_name = "$quiz_name".".xml";
				     $stringAPP = "<?xml version=\"1.0\"?>\n"."<QUIZ>\n\n"."<TITLE>"."$quiz_name"."</TITLE>";
						 
						 // Open the file to write
				     $fh = fopen("$quiz_file_name", 'w') or die("can't create file");
				     // Add the strings in XML format
				     fwrite($fh, "$stringAPP");
				     fclose($fh);
						 
						 $fh = fopen("temp.txt", 'w') or die("can't create file");
				     // Add the strings in XML format
				     fwrite($fh, "$quiz_file_name");
				     fclose($fh);
						 
						 if (create_duplicate_quiz($quiz_name)){
						 } else {
						   echo "Can't create quiz file.  Check the permissions of your quiz folder";
						 }	 
						 

				 }
}
if (file_exists("temp.txt")) {
   $quiz_file_name = file_get_contents("temp.txt");
}

if (file_exists($quiz_file_name)) {
    
	 			 $wtext = "==Enter Questions==\n";
				 $text = "When you are done entering questions, click submit without.\n";
				 $text .= "entering anything into the textbook.  Below the question, enter\n";
				 $text .= "the choices for the question, and click on the one that is the answer.\n\n";

				 $text .= create_quiz_form ();
				 $text .= create_textarea ("question_textarea");
				 $text .= create_input_button ("question_choice1","text","");
				 $text .= create_input_button_radio ("question_radio","choice1");
				 $text .= create_input_button ("question_choice2","text","");
				 $text .= create_input_button_radio ("question_radio","choice2");
				 $text .= create_input_button ("question_choice3","text","");
				 $text .= create_input_button_radio ("question_radio","choice3");
				 $text .= create_input_button ("question_choice4","text","");
				 $text .= create_input_button_radio ("question_radio","choice4");
				 $text .= create_submit_button ("submit_questions","submit");				 
				 
				 if ($_POST['submit_questions']) {
				 
				    if ($_POST['question_textarea']){  
				       $choice = $_POST['question_radio'];
							 $choicetext = $choice;
							 $question = create_tex_tag ($_POST['question_textarea']);
							 $choice_1 = $_POST['question_choice1'];
							 $choice_2 = $_POST['question_choice2'];
							 $choice_3 = $_POST['question_choice3'];
							 $choice_4 = $_POST['question_choice4'];							 
							 
							 $text = "\n\n<QUESTION>\n"."<TEXT>"."$question"."</TEXT>\n";
							 $text .= "<CHOICES>"."$choice_1, "."$choice_2, "."$choice_3, "."$choice_4 "."</CHOICES>\n";
							 
							 if ($choice == "choice1"){
							     $answer = $_POST['question_choice1'];
									 $text .= "<ANSWER>"."$answer"."</ANSWER>\n";
							 }
							 if ($choice == "choice2"){
                   $answer = $_POST['question_choice2'];
									 $text .= "<ANSWER>"."$answer"."</ANSWER>\n";
							 }
							 if ($choice == "choice3"){
							     $answer = $_POST['question_choice3'];
									 $text .= "<ANSWER>"."$answer"."</ANSWER>\n";
							 }
							 if ($choice == "choice4"){
                   $answer = $_POST['question_choice4'];
									 $text .= "<ANSWER>"."$answer"."</ANSWER>\n";
               }
							 $text .= "</QUESTION>";
							 $quiz_file_name = file_get_contents("temp.txt");
							 
							 $stringAPP = $text;
				       $fh = fopen("$quiz_file_name", 'a') or die("can't create file");
				       // Add the strings in XML format
				       fwrite($fh, "$stringAPP");
				       fclose($fh);
							 
							 $_POST = array();
							 							 
							 include ("quiz_creator.php");
							 
						 }else {
						   
							 $main_page = "/mediawiki/index.php";
							 $wtext = "==Quiz saved successfully==";
							 //$text = "$choicetext";
							 $text = "<a href=\"$main_page\">Main Page</a>";
							 
							 $quiz_file_name = file_get_contents("temp.txt");
							 $stringAPP = "\n</QUIZ>";
				       $fh = fopen("$quiz_file_name", 'a') or die("can't create file");
				       // Add the strings in XML format
				       fwrite($fh, "$stringAPP");
				       fclose($fh);
							 
							 $_POST = array();
							 
							 if (unlink("temp.txt")){
							 } else {
							   echo "Delete of temp.txt failed!\n";
							 }
						 } 
				  }
		}
		$wgOut->setPageTitle($wTitle);

    $wgOut->addWikiText( "<br clear=all>\n" );
    $wgOut->addWikiText( $wtext );
    $wgOut->addWikiText( "<br clear=all>\n" );


    $wgOut->addHTML( $text );
    $wgOut->output();
    exit;
					
} else {

$wgOut->loginToUse();
$wgOut->output();
exit;
}