<?php

/****************************************************
* Grade Point Average Calculator (GPAC) 
*
* GPAC is a convenient grade point average calculator, based on a typical high school system.
*
* Licensed under the GNU General Public License
*
* This program 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.
* 
* This program 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.
*
* Last Modified: February 13, 2006
*
* Copyright � 2006 GPAC Development Team
****************************************************/

//system variables
$GPACFileName = "index.php"; //The name of the file should go here.  NOTE: For GPAC to run correctly, THIS IS THE ONLY LINE YOU SHOULD MODIFY!!! 

//version variables - for debugging purposes, PLEASE DO NOT MODIFY!
$GPACVersionNumber = "v0.2.8a";
$GPACVersionStatus = "alpha";
$GPACCopyrightYear = 2006;

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

if($_GET['source']) { //display source if requested
	$file = file_get_contents($GPACFileName);
	header("Content-Type: text/plain");
	echo $file;
	exit(); //stop script execution
}

//execute commands (available for user after gpa calculation)
if ($_POST['reset']) { header ("Location: $GPACFileName"); }
if ($_POST['save']) { setcookie ("gpa", $_POST['gpa'], time()+60*60*24*365); }
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--
/****************************************************
* Grade Point Average Calculator (GPAC) 
*
* Licensed under the GNU General Public License
*
* Copyright � <?php echo $GPACCopyrightYear; ?> GPAC Development Team
****************************************************/
-->

<?php
if($_POST['print']) { //display and print gpa in a printer-friendly format
?>
<head><title>Grade Point Average Calculator</title></head>
<body onLoad="window.print();">
<h1>Grade Point Average Calculator</h1>
<p><b>High School Edition</b></p>
<hr />
<div align='center'>
<h2>Your Grade Point Average is <?php echo $_POST['gpa']; ?>!</h2>
<?php
if ($_POST['gpa']>=3.5) { 
	echo "<p><b>Congratulations! You've achieved the Honor Roll!</b></p>"; 
}
?>
</div>
<hr />
<p align="right">GPAC <?php echo $GPACVersionNumber; ?>
<br />Copyright &copy; <?php echo $GPACCopyrightYear; ?> GPAC Development Team</p>
</body>
</html>
<?php
exit();
} // /print
?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="A convenient grade point average calculator, based on a typical high school system." />
<meta name="keywords" content="education, school, grades, grade, gpa, grade point average, calculator, free, open-source, open source" />
<meta name="author" content="GPAC Development Team" />
<link rel="shortcut icon" href="favicon.ico" />
<title>Grade Point Average Calculator</title>

<script type="text/javascript" language="javascript">
function moreInfo() {
	proceed = confirm("Grade Point Average Calculator (GPAC)\n-<?php echo $GPACVersionNumber; ?> (<?php echo $GPACVersionStatus; ?>)-\n----------\n(For more information, click \'Cancel\')\n----------\nCopyright � <?php echo $GPACCopyrightYear; ?> GPAC Development Team");
	
	if(proceed==false) {
		window.open('<?php echo $GPACFileName; ?>?info=true','info','status=yes,scrollbars=yes,resizable=yes,width=675,height=620');
	}
}
</script>

<style type="text/css">
<!--
body,td,th {
	font-family: Arial;
	color: #FFCC00;
}
body {
	background-color: #000000;
}
a:link {
	color: #CC9900;
}
a:visited {
	color: #CC6600;
}
.subtitle { 
	color: #FFFF00;
	font-weight: bold;
	font-size: medium;
}
.small {
	font-size: small;
}
.results {
	font-size: x-large;
	color: #CC3300;
	font-weight: bold;
}
acronym:hover {
    cursor: help;
}
-->
</style>

</head>

<?php
if($_GET['info']) {
?>
<body>
<h2>Grade Point Average Calculator</h2>

<p><b><?php echo $GPACVersionNumber; ?> (<?php echo $GPACVersionStatus; ?>)</b></p>

<p><i>GPAC is a convenient grade point average calculator, based on a typical high school system.</i></p>

<p>Licensed under the <a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License</a></p>
<blockquote>
  This program is free software; you can redistribute it and/or<br />
  modify it under the terms of the GNU General Public License<br />
  as published by the Free Software Foundation; either version 2<br />
  of the License, or (at your option) any later version.<br />
  <br />
  This program is distributed in the hope that it will be useful,<br />
  but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />
  GNU General Public License for more details.<br />
  <br />
  <i><a href="http://www.gnu.org/licenses/gpl.txt">View full text of license</a></i>
</blockquote>

<p>This script is <a href="http://www.opensource.org/docs/definition.php">open source</a>. The source code of the Grade Point Average Calculator is available <br />for download from the <a href="http://sourceforge.net/projects/gpa/" title="Project Homepage">project homepage</a>.</p>

<p>GPAC markup has been coded to be valid XHTML 1.0 Transitional. 
<br />The document's <acronym title="Cascading Style Sheets">CSS</acronym> also passes validation.</p>

<p>
<!--Sourceforge logo code-->
<a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=159462&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" longdesc="GPAC is hosted by Sourceforge.net" /></a>
<!--/Sourceforge logo code-->
&nbsp;|&nbsp;
<!-- GPL License (image via http://gtmcknight.com/buttons/)-->
<a href="http://www.gnu.org/copyleft/gpl.html">
<img src="http://gpa.sourceforge.net/gnugpl.png" alt="GNU General Public License" longdesc="GPAC is licensed under the GNU General Public License" border="0" height="15" width="80" />
</a>
<!-- /GPL License -->
&nbsp;|&nbsp;
<!--Valid XHTML-->
<a href="http://validator.w3.org/check?uri=referer">
<img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Transitional" height="31" width="88" border="0" />
</a>
<!--/Valid XHTML-->
&nbsp;|&nbsp;
<!--Valid CSS-->
<a href="http://jigsaw.w3.org/css-validator/check/referer">
<img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" border="0" />
</a>
<!--/Valid CSS-->
&nbsp;|&nbsp;
<!--Open Source-->
<a href="http://www.opensource.org/docs/definition.php"><img src="http://www.opensource.org/trademarks/opensource/web/opensource-55x48.png" alt="Open Source" longdesc="GPAC supports open-source standards." border="0" width="55" height="48" /></a>
<!--/Open Source-->
&nbsp;|&nbsp;
<a href="<?php echo $GPACFileName; ?>?source=true">View source code</a>
</p>

<p>Copyright &copy; <?php echo $GPACCopyrightYear; ?> <a href="http://nmalkin.net/contact/" title="Contact GPAC Development Team">GPAC Development Team</a></p>

</body>
</html>

<?php 
exit();
} // /info 

if ($_POST['save']) {
	echo "<body onLoad=\"alert('Your GPA was saved successfully!')\">";
} else { 
	echo "<body>"; } 
?>
<h1>Grade Point Average Calculator</h1>
<p class="subtitle">High School Edition</p>

<?php
$courses = $_POST['courses'];
if (isset($courses)) {

/*
For the following variables,
	$cc - current step
	$tc = total steps
	$nc = next step
*/
$cc = $_POST['cc'] + 1;
$tc = $courses + 1;
$nc = $cc + 1;

$grade_temp = $_POST['grade'];
$credits_temp = $_POST['credits'];
$course_temp = $_POST['course'];

$credits = $_POST['fcredits'];
$points = $_POST['fpoints'];

$credits = $credits + $credits_temp;
$points_temp = $grade_temp*$credits_temp*$course_temp;
$points = $points + $points_temp;

if ($cc==$tc) { $submit = "Calculate GPA!";} // ..=on the last step
else { $submit = "Proceed to Step $nc";}

if ($cc>$tc) { //means all steps have been completed
	$gpa = $points / $credits;
	echo "<hr /><div align='center'><p class='results'>Your Grade Point Average is $gpa!</p>";
	if ($gpa>=3.5) { 
		echo "<p><b>Congratulations! You've achieved the Honor Roll!</b></p>"; 
	}

	$old = $HTTP_COOKIE_VARS["gpa"];
	if (isset($old)) { //show change if gpa has been previously saved
		$diff = abs($gpa - $old);
		if ($gpa>$old) {
			echo "<p class='small'><b><i>Good job! This score is an improvement of $diff points compared to your older <acronym title='Grade Point Average'>GPA</acronym>.</i></b></p>";
		}
		if ($gpa<$old) {
			echo "<p class='small'><b><i>Your previous <acronym title='Grade Point Average'>GPA</acronym> was better by $diff points.</i></b></p>";
		}
	}

	echo "<p><form action='$GPACFileName' method='post' name='formInput' id='formInput'>
<input name='gpa' type='hidden' id='gpa' value='$gpa' />
<input type='submit' name='reset' value='Start Over' /> <input type='submit' name='print' value='Print GPA' /> <input type='submit' name='save' value='Save GPA' />
</form></p></div>";

} else { //steps 2 through last
	echo "<hr /><form action='$GPACFileName' method='post' name='formInput' id='formInput'>
	<input name='courses' type='hidden' id='courses' value='$courses' />
	<input name='cc' type='hidden' id='cc' value='$cc' />
	<input name='fcredits' type='hidden' id='fcredits' value='$credits' />
	<input name='fpoints' type='hidden' id='fpoints' value='$points' />
	<input type='submit' name='reset' value='Start Over' />
	<input type='submit' name='submit' value='$submit' />
	<h3>Step $cc/$tc:</h3>";
?>
<table border='0'><tr>
<td>Grade:</td>
<td><select name='grade' size='1' id='grade'>
<option value='4'>A+ (>98%)</option>
<option value='4'>A (93%-97%)</option>
<option value='3.7'>A- (90%-92%)</option>
<option value='3.5'>B+ (87%-89%)</option>
<option value='3.3'>B (83%-86%)</option>
<option value='3'>B- (80%-82%)</option>
<option value='2.5'>C+ (77%-79%)</option>
<option value='2.3' selected='selected'>C (73%-76%)</option>
<option value='2'>C- (70%-72%)</option>
<option value='1.5'>D+ (67%-69%)</option>
<option value='1.3'>D (64%-66%)</option>
<option value='1'>D- (60%-63%)</option>
<option value='0'>E (<60%)</option>
</select></td>

</tr><tr>

<td>Number of Credits: </td>
<td><select name='credits' size='1' id='credits'>
<option value='0.25'>0.25</option>
<option value='0.5' selected='selected'>0.5</option>
<option value='1'>1</option>
<option value='1.25'>1.25</option>
<option value='2'>2</option>
</select></td>

</tr></table>

<p>
<input name='course' type='radio' value='1' checked="checked" />Normal Course
<br /><input name='course' type='radio' value='1.1' />Honors Course
<br /><input name='course' type='radio' value='1.2' />Advanced Placement Course
<br /><input name='course' type='radio' value='1.2' />International Baccalaureate Course
</p>

<?php
echo "
<p>
<input type='submit' name='reset' value='Start Over' />
<input type='submit' name='submit' value='$submit' />
</p>
</form>";

} //end of steps 2-last

} else { 
	if ($_POST['save']) { //if saved, a page similar to results page is displayed
	$gpa = $_POST['gpa'];
	
	echo "<hr /><div align='center'><p class='results'>Your Grade Point Average is $gpa!</p>";
	if ($gpa>=3.5) { 
		echo "<p><b>Congratulations! You've achieved the Honor Roll!</b></p>"; 
	}

	echo "<p><form action='$GPACFileName' method='post' name='formInput' id='formInput'>
<input name='gpa' type='hidden' id='gpa' value='$gpa' />
<input type='submit' name='reset' value='Start Over' /> <input type='submit' name='print' value='Print GPA' /> <input type='submit' name='save' value='Save GPA' />
</form></p></div>";

} else { //if on step 1
?>
<hr />
<h3>Step 1:</h3>
<form action='<?php echo $GPACFileName; ?>' method='post' name='formCourseNumber' id='formCourseNumber'>
<input name='cc' type='hidden' id='cc' value='1' />
<p>How many courses do you want to include in calculating your <acronym title='Grade Point Average'>GPA</acronym>?</p>
<blockquote>
<select name='courses' size='1' id='courses'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7' selected='selected'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
</select>
&nbsp;Course(s)*</blockquote>
<input type='submit' name='proceed' value='Proceed to Step 2' />
</form>
<p><i>*A typical schedule allows for seven courses at a certain time, excluding any blocked classes and study halls.</i></p>

<?php 
} //end step 1
} //end if($courses)
?>

<!--footer-->
<hr />
<p>

<!--Sourceforge logo code-->
<a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=159462&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" longdesc="GPAC is hosted by Sourceforge.net" /></a>
<!--/Sourceforge logo code-->
&nbsp;|&nbsp;
<!--Open Source-->
<a href="http://www.opensource.org/docs/definition.php"><img src="http://opensource.org/trademarks/open_source_button.png" alt="Open Source" longdesc="GPAC supports open-source standards." border="0" width="88" height="31" /></a>
<!--/Open Source-->
&nbsp;|&nbsp;
<a href="http://sourceforge.net/projects/gpa/" title="Project Homepage">Project Homepage</a>

<noscript>
&nbsp;|&nbsp;
<a href="<?php echo $GPACFileName; ?>?info=true" title="More Info">About GPAC</a>
</noscript>

</p>

<div align="right">
<p><b><a href="javascript:moreInfo()">GPAC <?php echo $GPACVersionNumber; ?></a></b></p>
</div>

<!-- Start of StatCounter Code -->
<script type="text/javascript">
<!-- 
var sc_project=1265517; 
var sc_invisible=1; 
var sc_partition=11; 
var sc_security="9dd194db"; 
var sc_remove_link=1; 
//-->
</script>

<script type="text/javascript" src="http://www.statcounter.com/counter/counter_xhtml.js"></script>
<!-- End of StatCounter Code -->

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-242605-2";
urchinTracker();
</script>
</body>
</html>