Jump to content

Recommended Posts

Hi

 

I've been through this code over and over but cannot find why I'm getting an unexpected T_ELSE on line 481.

 

Any ideas?  Sorry about the length of code, but this is a last resort to find the error.

 

<?php
$today=getdate();
$today=$today[0];
$quizname="Fleet";
$region=$_POST['region'];
$User_region=$_POST['user_region'];
$quizid=$_POST['quizid'];
//$quizname=$_POST['quizname'];
$UserID=$_POST['userid'];
$admin=$_POST['admin'];
$counter=$_POST['counter'];
$admin_report=$_POST['admin_report'];
$reset=$_POST['reset'];
$course = 236;
if(isset($reset)){
unset($UserID, $region, $User_region, $admin, $admin_report, $reset);
}

error_reporting(E_ALL);
//added extra brace to prevent report working whilst user auth is added
require_once(dirname(__FILE__) . '/../config.php');
require_once(dirname(__FILE__) . '/functions.php');
//require_once(dirname(__FILE__) . '/index2.php');
$USERID=$USER->id;






?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> POST Course Evaluation Results </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Stu Watson" CONTENT="">
  <META http-equiv="Content-Style-Type" content="text/css">
  <META NAME="Description" CONTENT="">

  <!--Styles for report-->
  <style>
  td {font-size:75%; text-align:center}
  .outer{border:2px solid black;border-collapse:collapse; padding:5px; }
  .inner{border:1px solid gray;border-collapse:collapse;}
  tr.base{background-color:yellow;border-top-style:hidden;border-collapse:collapse;}
  tr.internal{border-bottom-style:hidden;border-collapse:collapse;}
  .over{background-color:green; font-weight:bold;}
  .under{background-color:red; font-weight:bold;}
.alone{border:2px solid black;border-collapse:collapse; padding:5px; background-color:yellow; }

  </style>
</HEAD>
<?php

if($USERID !== 0) {
//Check whether user is logged in and if they have the correct role assignment to report.

if(user_has_role_assignment($USER->id, 1) || user_has_role_assignment($USER->id, 36)) {
	if(user_has_role_assignment($USER->id, 1)){
		echo'<form method="POST" action=""><input type="hidden" name="admin" value="admin"><input type="submit" value="Admin Info"></form>';
		if(!table_exists("qreports")){
			$sql="CREATE TABLE qreports (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, userid INT NOT NULL, username VARCHAR(255), date VARCHAR(255), quizid INT NOT NULL)";
			mysql_query($sql) or die ('Invalid query: ' . mysql_error());
		}
	}else{

		// set variable for admin report of users accessing site
		$counter++;
	}
?>
<BODY>
<p><h3><center>Post Course Evaluation Results</center></h3>

<!-- Reset Button-->
<form method="POST" action="">
<input type="hidden" name="counter" value="<?php echo $counter; ?>">
<input type="submit" name="reset" value="Return to front page">
</form></p>
<?php


// if admin report has been selected then get infor from table and report.
if(isset($admin)){
echo"<h3><center>Users viewing reports</center></h3>";
?>
<form method="POST" action="">
<p>Please choose the assessment to view users utilising reports</p>
	<?php
$sql="SELECT quizid FROM qreports";
$sql=mysql_query($sql) or die ('Invalid query: ' . mysql_error());
while($row=mysql_fetch_array($sql)){
	$admin_quiz[]=$row['quizid'];
	}
echo'<select name="admin_report">';
$admin_quiz=array_unique($admin_quiz);
foreach($admin_quiz as $value){
	$admin_name=Get_Quiz($value);
	echo'<option value="' . $value . '">' . $admin_name . '</option>';
}
echo"</select>";
echo'<input type="submit">';
echo"</form>";
unset($admin);
}elseif(isset($admin_report)){
$sql="SELECT * FROM qreports WHERE quizid = " . $admin_report;
$sql=mysql_query($sql);
while($row=mysql_fetch_array($sql)){
	$admin_output[$row['id']][$row['username']]=$row['date'];
}?>
<table class="outer">
<tr>
<td class="outer">User</td><td class="outer">Date of Access</td>
</tr>
<?php
foreach($admin_output as $value){
	while(list($name,$date)=each($value)){
	echo '<tr><td class="outer">' . $name . '</td><td class="outer">' . $date . '</td></tr>';
	}
}
?>
</table>
<?php
	unset ($admin, $admin_report);
}else{


//User Selects quiz title from dropdown to report on.
		if(!isset($quizid)){
			echo '<form method="POST" action=""><p>Please select the assessment you which to report from</p><select name="quizid">';
			$sql="SELECT id, name FROM mdl_quiz WHERE course = 236";
			$sql=mysql_query($sql);
			while($row=mysql_fetch_array($sql)){
				$quiz_id[$row['id']]=$row['name'];
			}
			while(list($id, $name)=each($quiz_id)){
				echo'<option value="' . $id . '">' . $name . "</option>";
			}
			echo'</select><input type="submit"></form>';

		}else{
?>
<!--Heading-->
<p>
Following on from the <?php echo Get_Quiz($quizid); ?> training we have created an assessment to establish the knowledge and understanding of relevant scenarios within the business.</p>
<p>
ALL the results have now been published here.</p>
<p>
Please select which report you would like to see from the drop-down below.<br>
The Regional and ALL UK reports will show the breakdown question by question, which should help establish where specific training requirements are needed across the UK.<br>
The overview option provides a comparisson against the average score for the UK and the facility to see scores on a delegate by delegate basis.</p>




<?php
//add to table to track user viewing reports
$names = Get_Names($USERID);
$today=nicedatetime($today);
if ($counter==1){
if(table_exists("qreports")){
	$sql="INSERT INTO qreports (userid, username, date, quizid) VALUES ('" . $USERID . "',' " . $names . "',' " . $today . "', ' " . $quizid . "')";
	mysql_query ($sql) or die ('Invalid query: ' . mysql_error());
}
else{
	$sql="CREATE TABLE qreports (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, userid INT NOT NULL, username VARCHAR(255), date VARCHAR(255), quizid INT NOT NULL)";
	mysql_query($sql) or die ('Invalid query: ' . mysql_error());

	$sql="INSERT INTO qreports (userid, username, date, quizid) VALUES ('" . $USERID . "',' " . $names . "',' " . $today . "', ' " . $quizid . "')";
	mysql_query ($sql) or die ('Invalid query: ' . mysql_error());

}

}

		}	

//has user selected individual user?  if so, produce their quiz breakdown

if(isset($UserID)){
//if (isset($export_user)){
	//echo $UserID;
$output_name=Get_Names($UserID);
$output_score=Get_Score($UserID, $quizid);
include("get_info.php");
$sql="SELECT uniqueid FROM mdl_quiz_attempts WHERE quiz = " . $quizid . " AND preview = 0 AND timefinish != 0 and userid=" . $UserID;
$sql=mysql_query($sql);
while($row=mysql_fetch_array($sql)){
	$User_completed=$row['uniqueid'];
}

$sql="SELECT answer FROM mdl_question_states WHERE attempt = " . $User_completed . " and seq_number = 1";
$sql=mysql_query($sql);
while($row=mysql_fetch_array($sql)){
	$array=explode(":",$row['answer']);
		$answers_given[]=$array[1];
}

$count_answers = array_count_values($answers_given);
echo"<h3><center><u>User Responses for " .  ucwords($output_name) . ".<br>Total Score= $output_score / 30</u></center></h3>";
echo '<table class="outer"><tr><td><table class="outer" width="100%"><tr><td class="outer" width="40%">Question Text</td><td class="outer" width="30%">Possible Answers</td><td class="outer" width="10%">Correct/Incorrect</td><td class="outer" width="10%">User Response</td></tr></table></td></tr>';
while(list($qref,$aref_arr)=each($ref_array)){
echo'<tr class="internal"><td class="outer"><table class"inner" width="100%"><tr></tr><tr><td width="40%">' . $questiontext[$qref] . "</td>";
while(list($aref,$mark)=each($aref_arr)){
	if (!isset($count_answers[$aref])){
		$count_answers[$aref]=0;
	}
	if($count_answers[$aref]==0){
		$response="";
	}elseif($count_answers[$aref]==1){
		$response='<h5><span style="font-family: wingdings; font-size: 200%;">&#252;</span></h5>';
	}
	echo'<td class="inner" width="30%">' . $answertext[$aref] . '</td>' . $mark . '</style></td><td class="inner" width="10%">' . $response . '</td></tr><tr><td></td>';
}echo'</table></td></tr><tr class="base"><td>&nbsp</td></tr><tr></tr>';
}
echo "</tr></table>";
unset($UserID);
}
//}









//Does user require export of users for specific region?

elseif(isset($User_region)){
$SQL="SELECT userid, sumgrades FROM mdl_quiz_attempts WHERE quiz = " . $quizid . " AND preview = 0 AND timefinish != 0";
$SQL=mysql_query($SQL) or die;
while($ROW = mysql_fetch_array($SQL)){
	if($User_region!="No Region Set"){
		$sql="SELECT data FROM mdl_user_info_data where userid = " . $ROW['userid'];
		$sql=mysql_query($sql);
		while($row=mysql_fetch_array($sql)){
			if ($row['data']==$User_region){
				$moresql="SELECT firstname, lastname FROM mdl_user where id = " . $ROW['userid'];
				$moresql=mysql_query($moresql);
				while($last=mysql_fetch_array($moresql)){
					$last['firstname']=ucwords($last['firstname']);
					$last['lastname']=ucwords($last['lastname']);
					$gradout[$ROW['userid']] = $ROW['sumgrades'];;
				}
			}
		}
	}else{
		$sql='SELECT data FROM mdl_user_info_data WHERE userid = ' . $ROW['userid'];
		$sql=mysql_query($sql);
		$return=mysql_num_rows($sql);
		if($return==0){
			$moresql="SELECT firstname, lastname FROM mdl_user where id = " . $ROW['userid'];
			$moresql=mysql_query($moresql);
			while($last=mysql_fetch_array($moresql)){
				$last['firstname']=ucwords($last['firstname']);
				$last['lastname']=ucwords($last['lastname']);
				$gradout[$ROW['userid']] = $ROW['sumgrades'];;
			}
		}
		while($row=mysql_fetch_array($sql)){
			if (strlen($row['data'])<1){
				$moresql="SELECT firstname, lastname FROM mdl_user where id = " . $ROW['userid'];
				$moresql=mysql_query($moresql);
				while($last=mysql_fetch_array($moresql)){
					$last['firstname']=ucwords($last['firstname']);
					$last['lastname']=ucwords($last['lastname']);
					$gradout[$ROW['userid']] = $ROW['sumgrades'];
				}
			}
		}
	}		
}
arsort($gradout);?>
<form method="POST" Action="">
<p><h3>Individual scores for the <?php echo"$User_region"; ?> Region</h3></p>
<p>The current UK average score for this assessment is <span class="alone"><b><u><?php echo $_SESSION['UK_AVE']; ?></b></u></span></p><p><table ><td><table class="outer"><tr><td class="inner">Name</td><td class="inner">Score out<br>of 30</td><td class="inner">Select to view<br>individual results</td></tr>
<?php
	while(list($Userid,$score)=each($gradout)){
		if($score>=$_SESSION['UK_AVE']){
			$format='class="over"';
		}else{
			$format='class="under"';}
			$VALUE = Get_Names($Userid);
		echo '<tr ' . $format . '><td class="inner">' . ucwords($VALUE) . '</td><td class="inner">' . $score . '</td><td class="inner">'?>
		<input type="radio" name="userid" value="<?php echo $Userid; ?>"></td></tr><?php
	}
	echo'</table></td><td valign=top><input type="submit" value="Retrieve User Information"></td></table>';
	echo'<input type="hidden" name="region" value="' . $region . '"><input type="hidden" name="user_region" value="' . $User_region . '"><input type="hidden" name="quizid" value="' . $quizid . '"><input type="hidden" name="counter" value="' . $counter . '"><input type="hidden" name="quizname" value="' . $quizname . '"></form></p>';
	unset($User_region);
}


//Has Region been selected?
elseif (!isset($region) and isset($quizid)){

//POST regions available from DB
$sql="SELECT param1 FROM mdl_user_info_field WHERE id = 1";
$sql=mysql_query($sql);
while ($row=mysql_fetch_array($sql)){
	$regionlist=explode("\n",$row['param1']);
}?>

<form method="POST" action="">
<select name="region">
<option value="overview">Overview</option>
<?php foreach($regionlist as $value){?>	
<option value="<?php echo $value; ?>"><?php echo $value; ?></option>
<?php } ?>
<option value="all">All UK Regions</option>
</select>
<?php echo'<input type="hidden" name="counter" value="' . $counter . '"><input type="hidden" name="quizid" value="' . $quizid . '">';?>
<input type="submit">
<?php



}elseif(isset($region)){ 
include("get_info.php");



if ($region!="overview"){

//POST all users for specified region then check if 'ALL' have been selected

if ($region!="all"){
$sql='SELECT userid FROM mdl_user_info_data WHERE data = "' . $region . '"';
$sql=mysql_query($sql);
while($row=mysql_fetch_array($sql)){
	$SQL="SELECT uniqueid FROM mdl_quiz_attempts WHERE quiz = " . $quizid . " AND userid = " . $row['userid'] . " AND preview = 0 AND timefinish != 0";
	$SQL=mysql_query($SQL);
	while($ROW=mysql_fetch_array($SQL)){
		$Users_completed[$row['userid']]=$ROW['uniqueid'];
		$regcount++;
	}
}
}else{
$sql="SELECT userid, uniqueid FROM mdl_quiz_attempts WHERE quiz = " . $quizid . " AND preview = 0 AND timefinish != 0";
$sql=mysql_query($sql);
while($row=mysql_fetch_array($sql)){
	$Users_completed[$row['userid']]=$row['uniqueid'];
}
}


//POST all answers given for all users given

foreach ($Users_completed as $value){
//echo "$value <br>";
$sql="SELECT answer FROM mdl_question_states WHERE attempt = " . $value . " and seq_number = 1";
$sql=mysql_query($sql);
while($row=mysql_fetch_array($sql)){
	$array=explode(":",$row['answer']);
		$answers_given[]=$array[1];
}
}


//find out how many are right and how many are wrong

$count_answers = array_count_values($answers_given);

//count total number of people completing the module

$total = count($Users_completed);

//echo out questions, answers and correct or not

?>

<p><h3><center>For the <?php echo "$region Region, $total"; ?> Users have completed the Fleet Assessment.</center></h3></p>
<p>There are 30 questions, each with 4 possible answers.  The following gives a breakdown of how many selected each option and whether the responses given were correct or incorrect.</p>
<?php
echo '<table class="outer"><tr><td><table class="outer" width="100%"><tr><td class="outer" width="40%">Question Text</td><td class="outer" width="30%">Possible Answers</td><td class="outer" width="10%">Correct/Incorrect</td><td class="outer" width="10%">Users Responding</td></tr></table></td></tr>';
while(list($qref,$aref_arr)=each($ref_array)){
echo'<tr class="internal"><td class="outer"><table class"inner" width="100%"><tr></tr><tr><td width="40%">' . $questiontext[$qref] . "</td>";
while(list($aref,$mark)=each($aref_arr)){
	if (!isset($count_answers[$aref])){
		$count_answers[$aref]=0;
	}
	echo'<td class="inner" width="30%">' . $answertext[$aref] . '</td>' . $mark . '</style></td><td class="inner" width="10%">' . $count_answers[$aref] . '</td></tr><tr><td></td>';
}echo'</table></td></tr><tr class="base"><td>&nbsp</td></tr><tr></tr>';
}
echo "</tr></table>";
}
else{
//POST all users completing quiz and their scores
$SQL="SELECT userid, sumgrades FROM mdl_quiz_attempts WHERE quiz = " . $quizid . " AND preview = 0 AND timefinish != 0";
$SQL=mysql_query($SQL) or die;
while($ROW = mysql_fetch_array($SQL)){
	$sql="SELECT data FROM mdl_user_info_data where userid = " . $ROW['userid'];
	$sql=mysql_query($sql);
	$return = mysql_num_rows($sql);
	if($return==0){
		$grade['No Region Set'][$ROW['userid']] = $ROW['sumgrades'];
		$ave_grade['No Region Set'][$ROW['userid']] = $ROW['sumgrades'];
	}else{
		while($row=mysql_fetch_array($sql)){
			$length=strlen($row['data']);
			if ($length == 0){
				$grade['No Region Set'][$ROW['userid']] = $ROW['sumgrades'];
				$ave_grade['No Region Set'][$ROW['userid']] = $ROW['sumgrades'];
			}else{
				$ave_grade[$row['data']][$ROW['userid']] = $ROW['sumgrades'];
				$grade[$row['data']][$ROW['userid']] = $ROW['sumgrades'];
			}
		}
	}
}

//count for each region
while(list($location, $number)=each($ave_grade)){
$total=count($number);

	ksort($number);
	unset($total_grade);
	while(list($Userid, $result)=each($number)){
		$uk_total+=$result;
		$total_grade+=$result;
		$COUNT++;
			}
	$_SESSION['UK_AVE'] = round(($uk_total/$COUNT),2);
}
?>
<form method="POST" action=""><table><tr><td><h4>Regions Ranked by Average Score</h4><td></td><td><h4>Regions Ranked by Users Completed</h4></td></tr><tr><td><table border=1><tr><td>Region</td><td>Users<br> Complete</td><td>Average<br>Score</td><td>Select to<br>export users</td></tr>
<?php
while(list($location, $number)=each($grade)){
$total=count($number);

	ksort($number);
	unset($total_grade);
	while(list($Userid, $result)=each($number)){
		$uk_total+=$result;
		$total_grade+=$result;


	}
	$score=round(($total_grade/$total),2);

	$scoreout[$score][$location]=$total;
	$Userout[$total][$location]=$score;


	}
	krsort($scoreout);
	while(list($scores, $value)=each($scoreout)){
		while(list($place,$Users)=each($value)){
			if($scores>=$_SESSION['UK_AVE']){
				$format=' class="over"';
			}else{
				$format=' class="under"';
			}
			echo"<tr><td $format>$place</td><td$format> $Users</td><td $format>$scores</td><td>"?><input type="radio" name="user_region" value="<?php echo $place; ?>"></td></tr><?php;
		}
	}
echo"<tr><td>UK Average</td><td>$COUNT</td><td>" . $_SESSION['UK_AVE'] . "</td><td>"?><input type="submit"></tr></table></td><td width=20%>&nbsp</td><td width="40%"><table border=1><tr><td>Region</td><td>Users<br> Complete</td><td>Average<br>Score</td><td>Select to<br>export users</td></tr>
<?php
krsort($Userout);
	while(list($Users, $value)=each($Userout)){
		while(list($place,$scores)=each($value)){
			if($scores>=$_SESSION['UK_AVE']){
				$format=' class="over"';
			}else{
				$format=' class="under"';
			}
			echo"<tr><td $format>$place</td><td$format> $Users</td><td $format>$scores</td><td>"?><input type="radio" name="user_region" value="<?php echo $place; ?>"></tr><?php;
		}
	}
echo"<tr><td>UK Average</td><td>$COUNT</td><td>" . $_SESSION['UK_AVE'] . "</td><td>"?><input type="hidden" name="region" value="<?php echo $region; ?> "><input type="submit"><?php echo '<input type="hidden" name="quizid" value="' . $quizid . '"><input type="hidden" name="counter" value="' . $counter . '"><input type="hidden" name="quizname" value="' . $quizname . '">';?>

</td></tr></form></table></td></table>

<?php
}
}
}
}else{?>
<h3><center>You must be a Territory Manager or Regional Director to view these reports<br>
<form method="POST" action="/../">
<input type="submit" value="Go to SKooch">
</form>
</center></h3>
<?php }

}else{?>
<h3><center>You must be logged into SKooch to view this page<br>
<form method="POST" action="/../">
<input type="submit" value="Go to SKooch">
</form>
</center></h3>
<?php }




?>

</BODY>
</HTML>

Link to comment
https://forums.phpfreaks.com/topic/239648-unexpected-t_else/
Share on other sites

I'm not going to take the time to scan through all of those uncommented closing brackets right now...

 

However, this error is generally because you missed a semi-colon, or put a closing bracket somewhere you shouldn't have.

 

Match up all of your brackets to make sure they belong to the proper opening bracket. And in the future, when you have code like this it doesn't hurt to add a comment so you know which closing bracket goes to what opening bracket.

Link to comment
https://forums.phpfreaks.com/topic/239648-unexpected-t_else/#findComment-1231053
Share on other sites

I've been through and checked all my closing brackets and braces and these all seem correct, as do my semi-colons

 

As I said, this is purely a last resort to find the error as I'm baffled.  If it makes any difference, this worked until my server was upgraded to PHP 5.3?

Link to comment
https://forums.phpfreaks.com/topic/239648-unexpected-t_else/#findComment-1231058
Share on other sites

This may or may not be the cause of the problem. If you look at the color highlighting in the forum post, you will see two echo statements, staring in column 1, near the end of the code that are in black. The <?php tags that start each of those sections have semi-colons ; on the end of them.

 

Edit: You are also missing the closing quote " on the end of the first one of those echo statements. I think the language parser just got tired of all the opening and closing php tags.

 

Edit2: If you remove the semi-colons on the two <?php tags, the syntax error will go away.

Link to comment
https://forums.phpfreaks.com/topic/239648-unexpected-t_else/#findComment-1231063
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.