Location: PHPKode > projects > PHP Grade Book > phpGradeBook/index.php
<?php
global $strings, $UsePasswords;
//error_reporting (E_ALL);
//error_reporting (0);
include ('admin/GBsql.inc.php');
include('config.inc.php');
include($LangFile);

if($_POST['action'] == $strings[l_ViewStudGrades] && $UsePasswords==1 && $_POST[LoginNow]!="") {
        setcookie ("StudID", $_POST['StudID']);
        setcookie ("StudPass", md5($_POST['StudPass']));
        $_COOKIE['StudID'] = $_POST['StudID'];
        $_COOKIE['StudPass'] = md5($_POST['StudPass']);
}
if($_GET[LogOut]==1) {
        setcookie ("StudID", "");
        setcookie ("StudPass", "");
        $_COOKIE['StudID'] = $_POST['StudID'];
        $_COOKIE['StudPass'] = md5($_POST['StudPass']);
}
//echo md5($_POST['StudPass'])." ".$_COOKIE['StudPass'];


if ($_POST[action] == "ChangePassword") { ChangePass("$_POST[StudID]","$_POST[UseTerm]"); }
include($top_part);

//if ($_GET['LogOut']==1) {session_start(); $_SESSION[password]="";; echo "OUT";}

if (!isset($_POST['action'])) {
	//Default Home Page

	if($ShowClassGrades == 1) {
		echo ("<br><fieldset class='introfieldsets'><legend><b>$strings[l_ViewGradeByClass]</b></legend>
		<form action='index.php' method=post>");
		SelectTerm();
		echo ("<br>$strings[l_Class]: ");

		if($ShowAllClass == 1) {
			ClassCombo();
			}else { echo ("<input type=text name=class class='InputField'>"); }
		echo ("<br><input type=submit name=action value='$strings[l_ViewClassGrades]' class='button'>");
		echo ("</form></fieldset><br>");
	}

	if($ShowIDGrades == 1) {
		echo ("<fieldset class='introfieldsets'><legend><b>$strings[l_ViewGradeByStudent]</b></legend>
		<form action='index.php' method=post>");
		SelectTerm();	
		echo("<br>$strings[l_StudentID]: <input type=text name=StudID class='InputField'>");
		if($UsePasswords==1) {
			echo("<br>$strings[l_Password]: <input type=password name=StudPass class='InputField'>");
			echo "<input type=hidden name=LoginNow value=yes>";
		}
		echo ("<br><input type=submit name=action value='$strings[l_ViewStudGrades]' class='button'>
		</form></fieldset>");
	}
}

if ($_POST[action] == $strings["l_ViewClassGrades"]) { ViewGrades("$_POST[class]"); }
if ($_POST[action] == "$strings[l_ViewStudGrades]") { ViewStudGrades("$_POST[StudID]"); }
function HtmlLocation($Class, $Location) {
	global $dbprefix;
	$query="SELECT $Location FROM ".$dbprefix."EditBox WHERE Class='$Class' AND Term='".$_POST[UseTerm]."'";
	$result = QueryMysql($query);
	$row = mysql_fetch_row($result);
	return $row[0];

}

function HtmlBox($Class) {
	global $dbprefix, $strings, $TableHeadColor, $TableRowColor1;
	$query="SELECT * FROM ".$dbprefix."EditBox WHERE Class='$Class' AND Term='".$_POST[UseTerm]."'";
	$result = QueryMysql($query);
	$row = mysql_fetch_row($result);
	echo "<table width=100% class=border border=1 cellpadding=5 cellspacing=0><tr><td bgcolor='$TableHeadColor' class='titlebar'><center> $row[4]<center></td></tr><tr><td>$row[5]</td></tr></table>";

}

function ViewGrades($class) {
	global $dbprefix, $strings, $TableHeadColor, $TableRowColor1, $TableRowColor2, $RowColor, $ExcuseCode;
	$location = HtmlLocation($class, "CLocation");
	if ($location==1) { HtmlBox($class); echo "<br>";}	

	$TeacherClass = FindLink($class);
	$ClassArray=ClassArray($TeacherClass);

	echo "<table width=100% class=border border=1 cellpadding=0 cellspacing=0><tr><td bgcolor='$TableHeadColor' class='titlebar'><center>$class $strings[l_Grades]<center></td></tr><tr><td><table border=1 cellspacing=0 cellpadding=3><tr><td bgcolor='$TableRowColor1'>$strings[l_Student]</td>";

	$Cols= AssignCount($TeacherClass);
		for ($i=1; $i<$Cols; $i++) { echo "<td bgcolor='$TableRowColor1'>$i</td>"; }
	echo "<td bgcolor='$TableRowColor1'>$strings[l_Total]</td><td bgcolor='$TableRowColor1'>$strings[l_Percent]</td></tr>";

	$RowColor = $TableRowColor1;

	$TotalPoints = TeacherRow($TeacherClass);
	$query = "SELECT * from ".$dbprefix."Users".$_POST[UseTerm]." WHERE Class='$class' ORDER by StudID asc";
	$result = QueryMysql($query);
              while ($row = mysql_fetch_row($result))
              {
				echo "<tr><td bgcolor='$RowColor'>".$row[2]."</td>";
				$ExcusedPoints=0;
				$TotalCorrect = 0;
				$Colum=0;
				$query2 = "SELECT * from ".$dbprefix."Grade_".$row[0].$_POST[UseTerm];
				$result2 = QueryMysql($query2);
				$AssignNum=0;

                while ($graderow = mysql_fetch_row($result2))
				{
					$GradeWeight=GetWeight($graderow[1]);
					//Total Excused Points
					if($graderow[2]==$ExcuseCode){
						//$ExcusedPoints=$ExcusedPoints+$ClassArray[$AssignNum];
						$ExcusedPoints=$ExcusedPoints+($ClassArray[$AssignNum]*$GradeWeight);
					}
				echo "<td bgcolor='$RowColor'>".$graderow[2]."</td>";
				//$TotalCorrect = $graderow[2] + $TotalCorrect;
				$TotalCorrect = ($graderow[2]*$GradeWeight) + $TotalCorrect;
				$AssignNum=$AssignNum+1;
				$Colum++;
			}
		$MyTotalPoints=$TotalPoints-$ExcusedPoints;

		AddEmptyCols($Cols-$Colum);
		//@$MyPercent = round(($TotalCorrect/$MyTotalPoints) * 100);
		@$MyPercent = number_format((($TotalCorrect/$MyTotalPoints) * 100),"1",".",",");
		echo "<td bgcolor='$RowColor'>$TotalCorrect</td><td align=right bgcolor='$RowColor'>".$MyPercent."%";
		$Letter=GetGrade($class, $MyPercent);
		if($Letter!="") { echo " - $Letter"; } 
		echo "</td></tr>";
		if ($RowColor==$TableRowColor1) {$RowColor = $TableRowColor2;}else{$RowColor = $TableRowColor1;}
		}
	echo "</table></td></tr></table>";
	ShowKey($TeacherClass);

	if ($location==2) { echo "<br>"; HtmlBox($class); }	

	echo ("<a href='JavaScript:window.print();'>
	<img src='images/print.gif' border=0 alt='$strings[l_PrintPage]' align='middle'>$strings[l_PrintPage]</a>");

}


function AssignCount($class) {
	global $dbprefix, $strings;
	$ClassCount=0;
	$query2 = "SELECT * from ".$dbprefix."Teacher".$_POST[UseTerm]." WHERE Class='$class'";
		
	$result2 = QueryMysql($query2);
                while ($graderow = mysql_fetch_row($result2))
		{
		$ClassCount++;
		}
	
	return $ClassCount+1;
}

function ClassArray($class) {
	global $dbprefix;
	$ClassArray=array();
	$query = "SELECT * from ".$dbprefix."Teacher".$_POST[UseTerm]." WHERE Class='$class' ORDER by ID asc";
	$result = QueryMysql($query);
		while ($graderow = mysql_fetch_row($result))
		{
			//$TotalCorrect = $graderow[2] + $TotalCorrect;
			array_push($ClassArray, "$graderow[2]");
		}
	return $ClassArray;
}


function TeacherRow($class) {
	global $dbprefix, $strings, $TableRowColor2;
		echo "<td bgcolor='$TableRowColor2'>$strings[l_Total]</td>";
		$query = "SELECT * from ".$dbprefix."Teacher".$_POST[UseTerm]." WHERE Class='$class' ORDER by ID asc";
		
		$result = QueryMysql($query);
                while ($graderow = mysql_fetch_row($result))
			{
			echo "<td bgcolor='$TableRowColor2'>".$graderow[2]."</td>";
			//$TotalCorrect = $graderow[2] + @$TotalCorrect;
			$TotalCorrect = ($graderow[2]*$graderow[6]) + $TotalCorrect;
			}
		if (!isset($TotalCorrect)) {$TotalCorrect="N/A";}	
		echo "<td bgcolor='$TableRowColor2'>$TotalCorrect</td><td bgcolor='$TableRowColor2'></td></tr>";
		return $TotalCorrect;
}

function TeacherRowStudent($class, $AssignNum) {
	global $dbprefix, $strings, $TableRowColor2;
		$query = "SELECT * from ".$dbprefix."Teacher".$_POST[UseTerm]." WHERE Class='$class' ORDER by ID asc";
		$ThisNum=1;
		$result = QueryMysql($query);
                while ($graderow = mysql_fetch_row($result))
			{
			if($ThisNum==$AssignNum) {
				return "<b>$graderow[1]</b><br>$strings[l_OutOf] $graderow[2]";			
			}
			//echo "<td bgcolor='$TableRowColor2'>".$graderow[2]."</td>";
			//$TotalCorrect = $graderow[2] + @$TotalCorrect;
			$TotalCorrect = ($graderow[2]*$graderow[6]) + $TotalCorrect;
			$ThisNum++;
			}
		if (!isset($TotalCorrect)) {$TotalCorrect="N/A";}	
		return $TotalCorrect;
}


function AddEmptyCols($AddAmount) {global $RowColor; for ($i=1; $i<$AddAmount; $i++) { echo "<td bgcolor='$RowColor'></td>"; }}


function ShowKey($class) {
	global $dbprefix, $strings;
	echo ("<fieldset class='key'><legend><b>$strings[l_Key]</b></legend><table><tr><td>$strings[l_AssignmentNumber]</td><td>$strings[l_Separator]</td><td>$strings[l_AssignmentName]</td></tr>");
	$query = "SELECT AssignName from ".$dbprefix."Teacher".$_POST[UseTerm]." WHERE Class='$class' ORDER by ID asc";
        $result = QueryMysql($query);
		$AssignNum = 1;
		while ($graderow = mysql_fetch_row($result)) {
		echo "<tr><td align=right>$AssignNum</td><td>$strings[l_Separator]</td><td>$graderow[0]</td></tr>";
		$AssignNum++;
		}
	echo ("</td></tr></table></fieldset>");
}


function CheckLogin() {
	global $strings, $dbprefix, $UsePasswords;
	$query = "SELECT UserPass FROM ".$dbprefix."Login WHERE UserID='$_COOKIE[StudID]'";
	$password=$_COOKIE[StudPass];
	//echo "$password ".$_COOKIE[StudID];
        $result = QueryMysql($query); $row = mysql_fetch_row($result);
	if($row[0]!=$password || $password=="") {
		echo ("$strings[l_LogIn]<fieldset class='introfieldsets'><legend><b>$strings[l_ViewGradeByStudent]</b></legend>
		<form action='index.php' method=post>");
		SelectTerm();	
		echo("<br>$strings[l_StudentID]: <input type=text name=StudID class='InputField'>");
		if($UsePasswords==1) {
			echo("<br>$strings[l_Password]: <input type=password name=StudPass class='InputField'>");
			echo "<input type=hidden name=LoginNow value=yes>";
		}
		echo ("<br><input type=submit name=action value='$strings[l_ViewStudGrades]' class='button'>
		</form></fieldset>");
		return false;
	}
return true;
}


function ViewStudGrades($StudID) {
	global $dbprefix, $strings, $TableHeadColor, $TableRowColor1, $TableRowColor2, $UsePasswords, $ExcuseCode, $PublishStats;
	if($UsePasswords==1) {
		$LoggedIn = CheckLogin();
		if ($LoggedIn==false) { echo "$strings[l_LoginIncorrect]";  ShowFoot(); exit; }
	}
	echo "<table><tr><td><table><tr><td><form action=index.php method=POST>";
	echo "<input type=hidden name=StudID value='$StudID'>";
	echo "<input type=hidden name=UseTerm value='$_POST[UseTerm]'>";
	echo "<input type=hidden name=action value='$strings[l_ViewStudGrades]'>$strings[l_Class]:";
	echo("<Select name=Class class='InputField'>");
       	$query = "SELECT DISTINCT Class from ".$dbprefix."Users".$_POST[UseTerm]." WHERE StudID='$StudID'";
	$result = QueryMysql($query);
	if("$_POST[Class]"=="") { 
		echo ("<option value=''>$strings[l_PickAClass]</option>");	
	}else{
		echo ("<option value='$_POST[Class]'>$_POST[Class]</option>"); 
	}
	while ($row = mysql_fetch_row($result)) {
		if("$_POST[Class]" != "$row[0]") { 
			echo ("<option value='$row[0]'>$row[0]</option>");
		}
		$ClassCount=$ClassCount+1; $OneClass=$row[0];
	}
	echo ("</select>");
	echo ("<input type=submit value='$strings[l_Select]' class='button'></form>");

	if($UsePasswords==1) {
		echo ("</td><td><form action=index.php method=POST>");
		echo "<input type=hidden name=StudID value='$StudID'>";
		echo "<input type=hidden name=UseTerm value='$_POST[UseTerm]'>";
		echo "<input type=hidden name=action value='ChangePassword'>";
		echo ("<input type=submit value='$strings[l_ChangePassword]' class='button'></form>");
	}

	echo "</td></tr></table>";


	if($ClassCount==1) {$_POST['Class']=$OneClass;}
	$class=$_POST['Class'];
	$location = HtmlLocation("$class", "SLocation");
	if(!$_POST['Class']=="") {
		echo "<table><tr><td nowrap valign=top><table class=border border=1 cellspacing=0 cellpadding=0><tr><td bgcolor='$TableHeadColor' class='titlebar'><center>$strings[l_GradesFor] $StudID, $strings[l_Class] $_POST[Class]<center></td></tr><tr><td><table border=1 width=100% cellspacing=0 cellpadding=3>";
		$query = "SELECT * from ".$dbprefix."Users".$_POST[UseTerm]." WHERE StudID='$StudID' AND Class='$_POST[Class]'";
		$result = QueryMysql($query);
		$row = mysql_fetch_row($result);
		$TeacherClass = FindLink($row[3]);
		$ClassArray=ClassArray($TeacherClass);

		$TotalPoints = TeacherRowStudent($TeacherClass,0);
		$class = $row[3];
		$query = "SELECT * from ".$dbprefix."Users".$_POST[UseTerm]." WHERE StudID='$StudID' AND Class='$_POST[Class]'";
		$result = QueryMysql($query);
                	while ($row = mysql_fetch_row($result))
	                {
			$TotalCorrect = 0;
			$query2 = "SELECT * from ".$dbprefix."Grade_".$row[0].$_POST[UseTerm];
			$StudentsID=$row[0];
			$AssignNum=1;
			$result2 = QueryMysql($query2);
			$RowColor=$TableRowColor1;
        	        while ($graderow = mysql_fetch_row($result2))
				{
					$GradeWeight=GetWeight($graderow[1]);
					//Total Excused Points
					if($graderow[2]=="$ExcuseCode"){
						$AssignNumA=$AssignNum-1;
						//$ExcusedPoints=$ExcusedPoints+$ClassArray[$AssignNumA];
						$ExcusedPoints=$ExcusedPoints+($ClassArray[$AssignNum]*$GradeWeight);
					}
					if($graderow[2]==$ExcuseCode) {
					$graderow[2]="$strings[l_Excused]";
				}
				echo "<tr bgcolor=$RowColor><td><center>"; echo TeacherRowStudent($TeacherClass,$AssignNum);  echo"</center></td><td><center>".$graderow[2]."</center></td></tr>";
				//$TotalCorrect = $graderow[2] + $TotalCorrect;
				$TotalCorrect = ($graderow[2]*$GradeWeight) + $TotalCorrect;
				$AssignNum++; if ($RowColor==$TableRowColor1) {$RowColor=$TableRowColor2;}else{$RowColor=$TableRowColor1;}
				}
			$TotalPoints=$TotalPoints-$ExcusedPoints;
			if($ExcusedPoints>0) {
				$ExcusedMsg= "<br>($ExcusedPoints $strings[l_Excused])";
			}else{ $ExcusedMsg=""; }
			@$MyPercent = round(($TotalCorrect/$TotalPoints) * 100);
			echo "<tr bgcolor=$RowColor><td><center><b>$strings[l_Total]</b> $strings[l_OutOf] $TotalPoints $ExcusedMsg</center></td><td>$TotalCorrect -".$MyPercent."%";
			$Letter=GetGrade($class, $MyPercent);
        	        if($Letter!="") { echo " - $Letter"; }
			echo "</td></tr>";
			}
		echo "</table></td></tr></table>";
		echo "</td><td valign=top>";
		if ($location==3) { HtmlBox($class); echo "<br>";}
		if ($GLOBALS[PublishAttendance]==1) {
			echo ("<table class=border border=1 cellspacing=0 cellpadding=4 width=200><tr><td bgcolor='$TableHeadColor' colspan=6 class='titlebar'><center>$strings[l_Attendance]</center></td></tr>");
			StudAttendance($StudentsID);
			echo "</table><br>";
		}
		if ($location==4) { HtmlBox($class); echo "<br>";}
		if($PublishStats) { ClassStats($TotalPoints,$class); }
		if ($location==5) { echo "<br>"; HtmlBox($class); }

		if ($location==2) { echo "</td><td valign=top>"; HtmlBox($class); }	
		echo "</td></tr></table>";
		if ($location==1) { HtmlBox($class); }
		echo "</td></tr></table>";	

		echo ("<a href='JavaScript:window.print();'>
		<img src='images/print.gif' border=0 alt='$strings[l_PrintPage]' align='middle'>$strings[l_PrintPage]</a>");
		if($UsePasswords==1) {
			//echo (" | <a href=index.php?action=ChangePass&StudID=".$_COOKIE['StudID']." border=0>$strings[l_ChangePassword]</a>");
			echo (" | <a href=index.php?LogOut=1 border=0>$strings[l_LogOut]</a>");
		}
	}
}


function ClassStats($TotalPoints,$class) {
	global $dbprefix, $strings, $TableHeadColor, $TableRowColor1, $TableRowColor2;
	echo ("<table class=border border=1 width=200 cellspacing=0><tr><td bgcolor=$TableHeadColor class='titlebar'><center>$strings[l_Class] $strings[l_Stats]</center></td></tr><tr><td><table width=100%>");
	$query = "SELECT AdminID FROM ".$dbprefix."Teacher".$_POST[UseTerm]." WHERE Class = '$class'";
	$result = QueryMysql($query); $row = mysql_fetch_row($result);
	$query= "SELECT RealName FROM ".$dbprefix."admin WHERE ID = '$row[0]'";
	$result = QueryMysql($query); $row = mysql_fetch_row($result);
	echo "<tr><td>$strings[l_Teacher]:</td><td>$row[0]</td></tr>";
	
	$query = "SELECT count(*) FROM ".$dbprefix."Users".$_POST[UseTerm]." WHERE Class = '$class'";
	$result = QueryMysql($query); $row = mysql_fetch_row($result);
	echo "<tr><td>$strings[l_Students]:</td><td>$row[0]</td></tr>";


	$Totals = array();
	$query = "SELECT ID FROM ".$dbprefix."Users".$_POST[UseTerm]." WHERE Class = '$class'";
	$result = QueryMysql($query); while ($row = mysql_fetch_row($result)) {
		$query="SELECT sum(CorrectPoint) FROM ".$dbprefix."Grade_$row[0]".$_POST[UseTerm];
		$result2 = QueryMysql($query); $row2 = mysql_fetch_row($result2);	
		if ($row2[0]=="") {$row2[0]='0';}
		array_push($Totals,$row2[0]);
	}

	@$MinPercent = round((min($Totals)/$TotalPoints) * 100);
	@$MaxPercent = round((max($Totals)/$TotalPoints) * 100);
	@$AvgPoints = round(array_sum($Totals) / count($Totals));
	@$AvgPercent = round(($AvgPoints/$TotalPoints) * 100);
	echo "<tr><td>$strings[l_Max]:</td><td>".max($Totals)." - ".GetGrade($class, $MaxPercent)."</td></tr>";
	echo "<tr><td>$strings[l_Avg]:</td><td>".$AvgPoints." - ".GetGrade($class, $AvgPercent)."</td></tr>";
	echo "<tr><td>$strings[l_Min]:</td><td>".min($Totals)." - ".GetGrade($class, $MinPercent)."</td></tr>";

	echo "</table></td></tr></table>";
}

function ClassCombo() {
	global $dbprefix, $strings;
	echo("<Select name=class class='InputField'>");
        $query = "SELECT DISTINCT Class from ".$dbprefix."Classes";

//Stick into array then use $array =array_unique($array)
	
        $result = QueryMysql($query);
                while ($row = mysql_fetch_row($result)) {
		echo ("<option value='$row[0]'>$row[0]</option>");
		}
	echo ("</select>");
}
function FindLink($class) {
	include ('admin/GBsql.inc.php');
	$query = "SELECT * FROM ".$dbprefix."GradeLinks".$_POST[UseTerm]." WHERE Class1 = '$class'";
	$result = QueryMysql($query);
	while ($row = mysql_fetch_row($result))
	{
		$UseClass = $row[2];
	}
	if (isset($UseClass)) { return $UseClass; } else { return $class; }
}


//function LastPostFix() {
////Get last PostFix
//        include('admin/GBsql.inc.php');
//        $query = "SELECT PostFix FROM ".$dbprefix."Terms ORDER by ID asc";
//        $result = QueryMysql($query);
//        while ($row = mysql_fetch_row($result)) {
//                $LastPostFix = $row[0];
//        }
//        if($LastPostFix=="default") {$LastPostFix="";}
//	return $LastPostFix;
//}
function SelectTerm() {
        global $strings;
        include('admin/GBsql.inc.php');

        $query = "SELECT * FROM ".$dbprefix."Terms ORDER by ID desc";
        $result = QueryMysql($query);
        if($result) {
		echo ("$strings[l_Term]: <select name=UseTerm>");
                while($row = mysql_fetch_row($result)) {
			if($row[2]=="default") {$row[2]="";}
			  echo ("<option value='$row[2]'>$row[1]</option>");
                }
                echo "</select>";
        }
}


function GetGrade($class, $percent) {
	include ('admin/GBsql.inc.php');
	$query = "SELECT Gradescale FROM ".$dbprefix."Classes WHERE Class='$class'";
	$result = QueryMysql($query);
	$ClassData = mysql_fetch_row($result);
	$Gradescale = $ClassData[0];
	$GradeArray = split(";", $Gradescale);
	for($i=0;$i<sizeof($GradeArray); $i++) {
		$GSplit = split(":", $GradeArray[$i]);
		$P1=$GSplit[0];
		$L1=$GSplit[1];
		if($percent>=$P1) {
			return $L1;
		}
	}
}

function StudAttendance($StudID) {
        global $strings, $dbprefix, $TableHeadColor, $TableRowColor1, $TableRowColor2, $CatagorizeAttendance;
        if ($_POST[UseTerm]=="default") { $_POST[UseTerm] = ""; }
        $RowColor=$TableRowColor1;
        $query = "SELECT * FROM ".$dbprefix."Attendance".$_POST[UseTerm]." WHERE StudentID='$StudID' ORDER by ID asc";
        $result = QueryMysql($query);
//        echo ("<tr>");
//	if($CatagorizeAttendance==1) {
//		echo ("<td>$strings[l_Excused] $strings[l_Absent]</td>
//		<td>$strings[l_Unexcused] $strings[l_Absent]</td>
//		<td>$strings[l_Excused] $strings[l_Tardy]</td><td>$strings[l_Unexcused] $strings[l_Tardy]</td>");
//	}
//	echo ("<td>$strings[l_Total] $strings[l_Absent]</td><td>$strings[l_Total] $strings[l_Tardy] ");
        while ($row = mysql_fetch_row($result))
                {
                //if($row[2]=="1") { $Type="$strings[l_Absent]"; } else {$Type="$strings[l_Tardy]";}
                //if($row[3]=="1") { $Excused="$strings[l_Excused]"; }else if($row[3]===0){$Excused="$strings[l_Unexcused]"; }
		if($row[2]=="1") {$Absent=$Absent+1; if ($row[3]=="1") { $ExAbsent=$ExAbsent+1; } else { $UnAbsent=$UnAbsent+1; } }
		if($row[2]=="0") {$Tardy=$Tardy+1; if ($row[3]=="1") { $ExTardy=$ExTardy+1; } else { $UnTardy=$UnTardy+1; } }
                }
//	echo "<tr>";
	if ($ExAbsent=="") {$ExAbsent=0;} if ($UnAbsent=="") {$UnAbsent=0;} if ($ExTardy=="") {$ExTardy=0;}
	if ($UnTardy=="") {$UnTardy=0;} if ($Absent=="") {$Absent=0;} if ($Tardy=="") {$Tardy=0;}
//	if($CatagorizeAttendance==1) {
//		echo ("<td>$ExAbsent</td><td>$UnAbsent</td><td>$ExTardy</td><td>$UnTardy</td>");
//	}
//	echo ("<td>$Absent</td><td>$Tardy</td></tr>");
 
	if($CatagorizeAttendance==1) {
		echo ("<tr><td>$strings[l_Excused] $strings[l_Absent]</td><td>$ExAbsent</td></tr>
		<tr><td>$strings[l_Unexcused] $strings[l_Absent]</td><td>$UnAbsent</td></tr>
		<tr><td>$strings[l_Excused] $strings[l_Tardy]</td><td>$ExTardy</td></tr>
		<tr><td>$strings[l_Unexcused] $strings[l_Tardy]</td><td>$UnTardy</td></tr>
		");
	}
	echo ("<tr><td>$strings[l_Total] $strings[l_Absent]</td><td>$Absent</td></tr>");
	echo ("<tr><td>$strings[l_Total] $strings[l_Tardy]</td><td>$Tardy</td></tr>");
}

function StudAttendanceDates($StudID) {
        global $strings, $dbprefix, $TableHeadColor, $TableRowColor1, $TableRowColor2;
        if ($_POST[UseTerm]=="default") { $_POST[UseTerm] = ""; }
        $RowColor=$TableRowColor1;
        $query = "SELECT * FROM ".$dbprefix."Attendance".$_POST[UseTerm]." WHERE StudentID='$StudID' ORDER by ID asc";
        $result = QueryMysql($query);
        echo "<table border=1 cellspacing=0 cellpadding=3>";
        while ($row = mysql_fetch_row($result))
                {
                if($row[2]=="1") { $Type="$strings[l_Absent]"; } else {$Type="$strings[l_Tardy]";}
                if($row[3]=="1") { $Excused="$strings[l_Excused]"; }else if($row[3]=="0"){$Excused="$strings[l_Unexcused]"; }
                $Date=$row[1];
                echo ("<tr bgcolor='$RowColor'><td>$Excused $Type</td><td>$Date</td></td>");
                if($RowColor==$TableRowColor1) {$RowColor=$TableRowColor2;}else{$RowColor=$TableRowColor1;}
                }
        
}

function ChangePass($StudID,$UseTerm) {
	global $strings, $dbprefix, $top_part;
	if($_POST[ChangeNow]==1) {
		$query = "SELECT * FROM ".$dbprefix."Login WHERE UserID='$StudID'";
		$result=QueryMysql($query);
		$row = mysql_fetch_row($result);
		if(md5($_POST[OldPass])==$row[2]) {
			if($_POST[NewPass]==$_POST[NewPass2] && $_POST[NewPass]!="") {
				$query = "UPDATE ".$dbprefix."Login SET  UserPass='".md5($_POST[NewPass])."' WHERE UserID='$StudID'";
				$result=QueryMysql($query);
				setcookie ("StudPass", md5($_POST['NewPass']));
		        	$_COOKIE['StudPass'] = md5($_POST['NewPass']);
			echo "$strings[l_PasswordChanged]";
			}else{ echo "$strings[l_PasswordNotMatched]"; }
		}else{ echo "$strings[l_CurrentPasswordIncorrect]"; }
	}
	include($top_part);
	echo ("<form action=index.php method=POST><table>
	<input type=hidden name=action value=ChangePassword>
	<input type=hidden name=StudID value=$StudID>
	<input type=hidden name=UseTerm value=$UseTerm>
	<input type=hidden name=ChangeNow value=1>
	<tr><td>$strings[l_CurrentPassword]:</td><td><input type=text name=OldPass></td></tr>
	<tr><td>$strings[l_New] $strings[l_Password]:</td><td><input type=text name=NewPass>  </td></tr>
	<tr><td>$strings[l_New] $strings[l_PasswordAgain]:</td><td><input type=text name=NewPass2>  </td></tr>
	<tr><td colspan=2><input type=submit class=button value=$strings[l_Change]></form></td></tr>
	</table>");

	echo "<form action=index.php method=POST>";
	echo "<input type=hidden name=StudID value='$StudID'>";
	echo "<input type=hidden name=UseTerm value='$UseTerm'>";
	echo "<input type=hidden name=action value='$strings[l_ViewStudGrades]'>";
	echo "<input type=submit class=button value='$strings[l_BackToGrades]'></form>";

	ShowFoot(); exit;
// echo "CHNAGE PASS FOR $StudID (back to $UseTerm)";
}



function ShowFoot() {
	global $version,$bottom_part; include($bottom_part);
}

function GetWeight($id) {
	if ($_COOKIE['term']=="default") { $_COOKIE['term'] = ""; }
	include ('admin/GBsql.inc.php');
    $connection = mysql_connect($host, $user, $pass) or die ("SQL server problem");
	$query = "SELECT * from ".$dbprefix."Teacher".$_COOKIE['term']." WHERE ID='$id'";
	$result = mysql_db_query($dbname, $query, $connection);
    $graderow = mysql_fetch_row($result);
	return $graderow[6];
}

function QueryMysql($query) {
	include ('admin/GBsql.inc.php');
        $connection = mysql_connect($host, $user, $pass) or die ("SQL server problem");
        mysql_select_db($dbname, $connection);
        $result = mysql_query($query);
//echo mysql_error();
	return $result;
}

ShowFoot();
?>
Return current item: PHP Grade Book