Location: PHPKode > projects > EdLite-light-weight web classrooms > edlite/templates/student_template/grades.php
This file is part of EdLite.
Copyright (C) 2005 Philip Spears and Philip Allen

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

Edlite is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with EdLite; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Version: 2005081900 


$student_name = str_replace(dirname(getcwd())."/", "", getcwd());
$course_name = str_replace(dirname(dirname(getcwd()))."/", "", dirname(getcwd()));
$current_date  = date("m.d.Y");
$title = basename($HTTP_SERVER_VARS[PHP_SELF], ".php");
if (file_exists("./header.html")) { include ("./header.html"); }
if ($HTTP_POST_VARS['post'] == "true") {
	$grade		=stripslashes($HTTP_POST_VARS['grade']);
	$assignment	=$HTTP_POST_VARS['assignment'];
	$date		=$HTTP_POST_VARS['date'];
	$file = "./grades.txt";
/* merge post data into string.. tab deliminated with cr (\n) and lf \r */
	$grades_entry = $date."\t".$assignment."\t".$grade."\r";
	if (!file_exists($file)) { touch($file); }
	if (is_writable($file)) {
		// making entry_read here!!
		if (!$entry_read = fopen($file, "r")) {
			echo "cannot read text file";
		// make $content here!
		if (filesize($file) == "0") {
			$content = "";
		} else {
			$content = fread($entry_read, filesize($file));
		//this $towrite = $jentry . $content; // is the same as one line below
		$towrite = $grades_entry.$content;
		//make $entry1 here!
		if (!$entry = fopen($file, "w+")) {
			echo "cannot open test.txt";
		//or die("Could not create file.");
		//writes the input jentry to string entry1;
		if (fwrite ($entry, $towrite) === FALSE) {
			echo "cannot write to grades.txt";
		printf ("<div class=\"box_red\" style=\"text-align: center;\">Grade Posted<br /></div>");
		//prints link to jentry web output
		//printf ("<a href=\"assignments.php\">Read Assignments</a>");
		//closes entry one
		} else { // else if file is writable.
			printf ("<div class=\"box_red\" style=\"text-align: center;\">unable to write to ($file)<br /></div>");
		} // end if writable.
}//end if post == true
<div class="box_noborder">
	<?php printf($student_name); ?>'s <?php printf($course_name); ?> Grades Entries
	<br />
	<a href="#NewEntry">Create a new Entry</a>
<br />
<div class="box">
$file = "./grades.txt";
if (file_exists($file) && filesize($file) != "0") {
<pre style="padding-left:10px; padding-right:10px;" wrap="on"><?php include ($file); ?></pre>
} else {
	printf ("<br /><center>No grades posted.</center><br />");
<br /><br /><br /><br /><br /><br />
<div class="box">
	&nbsp;&nbsp;<a name="NewEntry">Grades Entry Form</a><br />
	<form action="grades.php" method=post>
		&nbsp;&nbsp;&nbsp;Date : <input name="date" size="10" type="text" value="<?php printf($current_date); ?>">
		&nbsp;&nbsp;Assignment Number : <input name="assignment" size="2" type="text" value="">
		&nbsp;&nbsp;Grade : <input name="grade" size="1"type="text" value=""><br />
		<input name="post" type="hidden" value="true">
		&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Add Entry"><br />
if (file_exists("./footer.html")) { include ("./footer.html"); }
Return current item: EdLite-light-weight web classrooms