Location: PHPKode > projects > EdLite-light-weight web classrooms > edlite/templates/student_template/journal.php
<?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
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 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") {
	$journal	=stripslashes($HTTP_POST_VARS['journal']);
	$date		=$HTTP_POST_VARS['date'];
	$author		=$HTTP_POST_VARS['author'];
	$file = "./journal.txt";
/* merge post data into string.. tab deliminated with cr (\n) and lf \r */
	$jentry = $author."\t".$date."\n\r".$journal."\n\r\n\r\n\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";
			exit;
		}
		// 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 = $jentry.$content;
		//make $entry1 here!
		if (!$entry = fopen($file, "w+")) {
			echo "cannot open test.txt";
			exit;
		}
		//or die("Could not create file.");
		//writes the input jentry to string entry1;
		if (fwrite ($entry, $towrite) === FALSE) {
			echo "cannot write to journal.txt";
			exit;
		}
		printf ("<div class=\"box_red\" style=\"text-align: center;\">Journal Posted<br /></div>");
		//prints link to jentry web output
		//printf ("<a href=\"assignments.php\">Read Assignments</a>");
		//closes entry one
		fclose($entry);
		} 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); ?> Journal Entries
	<br />
	<a href="#NewEntry">Create a new Entry</a>
</div>
<br />
<div class="box">
<?php
$file = "./journal.txt";
if (file_exists($file) && filesize($file) != "0") {
?>
<pre style="padding-left:10px; padding-right:10px;" wrap="on"><?php include ($file); ?></pre>
<?php
} else {
	printf ("<br /><center>No journal entries posted.</center><br />");
}
?>
</div>
<br /><br /><br /><br /><br /><br />
<div class="box">
	&nbsp;&nbsp;<a name="NewEntry">Journal Entry Form</a><br />
	<form action="journal.php" method=post>
		&nbsp;&nbsp;Date : <input name="date" type="text" value="<?php printf($current_date); ?>"><br />
		&nbsp;&nbsp;Author : <input name="author" type="text" value="<?php printf($student_name); ?>"><br />
		&nbsp;&nbsp;Journal Entry<br />
		&nbsp;&nbsp;<textarea  name="journal" rows="15" cols="60" wrap></textarea><br />
		<input name="post" type="hidden" value="true">
		&nbsp;&nbsp;<input type="submit" name="submit" value="Add Entry"><br />
	</form>
</div>
<?php
if (file_exists("./footer.html")) { include ("./footer.html"); }
?>
Return current item: EdLite-light-weight web classrooms