Location: PHPKode > projects > Standardized Test Practice Engine > stpe/admin/deletequestions.php
<?php
/*
Copyright 2004 by Jonathan Bell and Daniel Perelman
This file is part of STPE - the Standardized Test Practice Engine.

    STPE 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.

    STPE is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
include_once("../globals.inc.php");
?>
<?php
include("login.inc.php");
if(!(
     (isset($_GET['top']) && isset($_GET['sub']))
     ||
     (isset($_POST['top']) && isset($_POST['sub']))
    )
  )
{
        header("Location: deletequestionswhich.php");
        exit;
}
$wantedtopic = $_GET['top'];
$wantedsection = $_GET['sub'];
require_once("../dbinit.inc.php");
$sql = "SELECT * FROM `users` WHERE topicnum=$wantedtopic && sectionnum=$wantedsection";
$total_result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
$total_found = @mysql_num_rows($total_result);

while ($row = mysql_fetch_array($total_result)) {
	$groupid=$row['group_id'];
    $topicnum=$row['topicnum'];
    $topicdesc=$row['topicdesc'];
    $sectionnum=$row['sectionnum'];
    $sectiondesc=$row['sectiondesc'];
    $names=$row['names'];
    $code=$row['code'];
	$x++;
}

$sql = "SELECT * FROM `questions` where group_id = $groupid ORDER by id";
$total_result = @mysql_query($sql, $connection) or die("Error #". mysql_errno() . ": " . mysql_error());
$total_found = @mysql_num_rows($total_result);
if($total_found >1){
$x=0;
while ($row = mysql_fetch_array($total_result)) {
    $id[$x]=$row['id'];
    $question[$x]=$row['question'];
    $answers[$x]=$row['answers'];
    $type[$x]=$row['type'];
    $x++;
}
}
//get the number of matching questions
$numberofmatch=0;
foreach($type as $x){
	if($x==2){
	$numberofmatch++;
	}
}
$numberoftype2=0;
$numberoftype3=0;

foreach($type as $sd){
if($sd==2){
$numberoftype2++;
}
if($sd==3){
$numberoftype3++;
}
}
if($numberoftype2>0){
$numberoftype2--;
}
//come up wtih the order for the matchign questions
// set some globals
$s = array();
$n = $numberoftype2; // the range you require

function set_num() {
  global $s, $n;
  $add = "yes";
  $ran = rand(0, $n);
  if(count($s) >= 0) {
   foreach($s as $sh) {
     if($ran == $sh) {
       $add = "no";
     }
   }
  }
  if($add == "yes") {
   $s[] = $ran;
  } else {
   set_num();
  }
}
// call the function as needed
while(count($s) <= $n) {
  set_num();
 }
$qseed=$s;

function fix_img($text)
{
        return str_replace("<img src = \"reviewpix", "<img src = \"../reviewpix", $text);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><?php echo $site_name; ?> Test: <?php
echo $topicdesc." : ".$sectiondesc;
?></title>

<link rel="stylesheet" type="text/css" href="../style.css" />
</head>
<body>
<?php include("../header.inc.php"); ?>
	<table>
		<tr valign="top">
			<?php include("../nav.inc.php"); ?>
			<td class="maincontent">
				<p>Now viewing the test for the subject:
				<?php
					echo $topicdesc." : ".$sectiondesc;
				?><br />
				Please note: There MUST be at LEAST ONE question remaining. If you wish to completely 
				delete all questions and the review, then please use "Delete Review".
								</p>
				<form action="deletequestionssubmit.php" method="post">
				<p><input type="hidden" name="top" value="<?php echo $wantedtopic; ?>" />
				<input type="hidden" name="sub" value="<?php echo $wantedsection; ?>" />
				<?php
					$count=1;
					$timesrun=0;
					$SCORE=0;
					foreach($question as $key => $thisquestion){
						$question[$key] = fix_img($question[$key]);
                                                $thisquestion = fix_img($thisquestion);
                                                $answers[$key] = fix_img($answers[$key]);
					
						if($type[$key]=="0"){
							echo "<p>\r\n";
							echo $count.": ".$thisquestion."<br />";
							$theanswers = explode("\n",$answers[$key]);
							foreach($theanswers as $key2 => $answer){
								echo "<input type=\"radio\" name=\"$id[$key]\" value=\"$key2\" />\r\n";
								echo $answer;
								echo "<br />";
							}
							echo "</p>\r\n";
						}
						if($type[$key]=="1"){
							echo "\r\n";

							foreach(explode("\n",$thisquestion) as $key2 => $questiontoask){
								if($key2 != "0"){
									echo "<li>";
								}
								$questiontoask = str_replace("&","&amp;",$questiontoask);
								echo "<p>";
								if($key2==0){
								echo $count.": ";
								}
								echo $questiontoask."</p>\r\n";
								if($key2 == "0"){
									echo "<ol style=\"list-style-type: upper-roman;\">";
								}
								else{
									echo "</li>";
								}
							}
							echo "</ol>";
							foreach(explode("\n",$answers[$key]) as $key3 => $answer){
								$answer = str_replace("&","&amp;",$answer);
								echo "<p><input type=\"radio\" name=\"$id[$key]\" value=\"$key3\" />\r\n";
								echo $answer;
								echo "<br /></p>\r\n";
							}
							echo "\r\n";
						}
						if($type[$key]=="2"){
							if($timesrun==0){
								echo "<table>";
								echo "<tr><th>Column one</th><th>Column two</th></tr>";
								//$leftselect="<select name=\"$id[$key]T2P1\">";
								//$rightselect="<select name=\"$id[$key]T2P2\">";
							}
							$thisq=$qseed[$timesrun];
							$thisa=$aseed[$timesrun];
							$timesrun2 = $timesrun + 1;
							//$leftselect = $leftselect."$question[$key]\r\n";
							$rightselect = $rightselect."<option value=\"$answers[$thisq]\">$answers[$thisq]</option>\r\n";
							$timesrun++;
							if($timesrun==$numberofmatch){

								for($x=0;$x<$numberofmatch;$x++){
								$y=$x+1;
								$thisquestion = $id[$key] - $numberofmatch + $x +1;
								echo "<tr><td>$y: $question[$x]</td><td><select name=\"$thisquestion\">$rightselect</select></td></tr>\r\n";
								}
								echo "</table>";
							}
						}
						if($type[$key]=="3"){
							if($SCORE == 0){
								echo "<table><tr><th>I</th><th></th><th>II</th></tr>";
							}
							$questionstoask=explode("\n",$thisquestion);
							echo "<tr><td>$count: $questionstoask[0]</td><td><b>Because</b></td><td>$questionstoask[1]</td></tr>\r\n";
							echo "<tr><td>T<input type=\"radio\" name=\"$id[$key]I\" value=\"T\" />F<input type=\"radio\" name=\"$id[$key]I\" value=\"F\" /></td>\r\n
							<td></td><td>T<input type=\"radio\" name=\"$id[$key]II\" value=\"T\" />F<input type=\"radio\" name=\"$id[$key]II\" value=\"F\" />\r\n
							CE<input type=\"checkbox\" name=\"$id[$key]\" value=\"CE\" /></td>";
							echo("<td><input type = \"submit\" name = \"$id[$key]\" value = \"Delete Previous Question\" /></td></tr>\r\n");
							
							$SCORE++;
							if($numberoftype3 == $SCORE){
								echo "</table>";
							}
						}
						$count++;
						if($type[$key]!="3") 
							echo("<input type = \"submit\" name = \"$id[$key]\" value = \"Delete Previous Question\" />");
					}
				?>
				</form>
				<p>This test was created by: <?php echo $names; ?></p>
			</td>
		</tr>
	</table>
<?php include("../footer.inc.php");?>
</body>
</html>
Return current item: Standardized Test Practice Engine