<?php
function htmlHeader() //HTML Headers
{
$strHead.= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
$strHead.= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
$strHead.= "<head>\n";
$strHead.= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=iso-8859-1\" />\n";
$strHead.= "<meta http-equiv=\"Content-Language\" content=\"en-us\" />\n";
$strHead.= "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">";
$strHead.= "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\"/>\n";
$strHead.= "<title>Tom Sinclair - Guestbook</title>\n";
$strHead.= "</head>\n";
$strHead.= "<body>\n";
//$strHead.="<div id=\"Wrapper\">";
return $strHead;
}
// GET FORM POST or GET
function GetPost($get_string) {
If (isset($_POST[$get_string])) {
return $_POST[$get_string];
} elseif (isset($_GET[$get_string])) {
return $_GET[$get_string];
} else {
return "";
}
}
function displaycomment($strfilename, $intComment, $strfile)
{
$handle = fopen($strfilename, "r") or exit("Error opening file"); //Opens file, read only, if it can't then creates an error
While(!feof($handle)) //Goes through file line by line until eof(end of file)
{
//Set variable to blanks
$strline = "";
$strdata = "";
$intComments = 0;
$strSwitch = "";
$strline = fgets($handle); //Gets line, stores it in a variable
If (strlen($strline) > 0)
{
Switch (substr($strline, 0, 1) ) //Gets 1st Chr, determines if it's a comment or a reply, outputs HTML accordingly
{
case "~":
$strdata = explode("|", $strline); //Exploded data array
echo "<div class=\"comment\">";
echo "<div class=\"name\"><a href=\"mailto:".$strdata[3]."\">".$strdata[2]."</a></div>";
echo "<div class=\"info\">".$strdata[1]."</div>";
echo $strdata[4];
echo "<div class=\"comReply\"><A href=\"index.php?p=reply&file=".substr($strfile, 0, strlen($strfile) - 4)."\">Reply</a></div>";
if ($_SESSION['allowed'] == "TRUE")
{
echo "<div class=\"comDelete\"><A href=\"index.php?p=delete&file=".substr($strfile, 0, strlen($strfile) - 4)."\">Delete</a></div>";
//index.php?p=delete&file=".substr($strfile, 0, strlen($strfile) - 4)."
}
echo "<div class=\"comNumber\">#".($intComment+1)."</div>";
echo "</div>";
break;
case "#":
$strdata = explode("|", $strline);
echo "<div class=\"reply\">";
echo "<div class=\"name\"><a href=\"mailto:".$strdata[3]."\">".$strdata[2]."</a></div>";
echo "<div class=\"info\">".$strdata[1]."</div>";
echo $strdata[4];
echo "</div>";
break;
}
}
}
fclose($handle);
}
function writeReply($strReplyFile, $strName, $strEmail, $strReply)
{
If ($strReplyFile != "" && $strName != "" && $strEmail != "" && $strReply != "")
{
$strReplyfilename = getcwd()."/data/".$strReplyFile.".txt";
$handle = fopen($strReplyfilename, "a") or exit("Error opening file"); //Opens file Write pointer at end of file, if it can't then creates an error
$strReplyContent = "\r\n#|".Date("m/d/y")." - ".Date("H:i:s")."|".$strName."|".$strEmail."|".$strReply; //To be writen to textfile
if (fwrite($handle, $strReplyContent) === FALSE)
{
return FALSE;
} else {
return TRUE;
}
fclose($handle);
} else {
return FALSE;
}
}
function writeComment($strName, $strEmail, $strComment)
{
If ($strName != "" && $strEmail != "" && $strComment != "")
{
$strdirectory = getcwd()."/data/"; //Gets current working directory, adds the directory data to it
// Get comment files in comment (data) directory
$strFiles = array();
$handle = opendir($strdirectory) or die("Directory not found!"); //Opens directory
while($entry = readdir($handle)) //Scans through, uses an array to sort out files and subdirs
{
if(!is_dir($entry) && $entry != ".." && $entry != ".")
{
$strFiles[] = $entry;
}
}
closedir($handle); //Close handle for directory
sort($strFiles); //Sorts files/directory
$intComCount = count($strFiles); //number of comments (actually files)
$strLastFile = $strFiles[$intComCount - 1]; // Last filename in comment data dir
$intNewFile = intval(substr($strLastFile, 0, strlen($strLastFile) - 4)) + 1; //Strips off the .txt, converts string to integer, adds 1
$strNewFile = $intNewFile.".txt"; //new string for file creation
$strCommentContent = "~|".Date("m/d/y")." - ".Date("H:i:s")."|".$strName."|".$strEmail."|".$strComment; //to be written to textfile
$handle = fopen($strdirectory.$strNewFile, "w");
if (fwrite($handle, $strCommentContent) === FALSE)
{
return FALSE;
} else {
return TRUE;
}
fclose($handle);
} else {
return FALSE;
}
}
?>