Please go back. and try again."); if ( !isset($date) ) die("$msgError: Date field was not received!\n"); $fp = fopen($gbFile, "r") or die("$msgError: Data file not found! (01)
"); fseek($fp, 0); $content = fread($fp, filesize($gbFile)); fclose($fp); $text = explode("\n", $content); //$text = file($gbFile); $lines = count($text) - 1; # Improved security. # It helps when two or more people have access to deleting # entries, if id number has changed: if someone deleted an entry # and someone else is trying to delete another one at the same # moment, line number could have changed. So we check whether # the date is the same to the one we wanted to delete. If not, # we don't delete anything, it's better than deleting something # you don't want to :). # It won't happen if only one person has access to the admin # system (or if onlye one person is accessing it at a time). $entry = explode("|", $text[$id]); if ( $date != $entry[1] ) { echo "date: $date
date: $entry[1] - $entry[0]
"; die("$msgError: date does not match.
\n"); } if ($id > $lines - 1) die("$msgError: Entry with id = $id does not exist anymore.
\n Someone else should have deleted a previous entry\n while you were trying to delete this one.
\n Go back to guestbook and try again."); # Move all entries after $id one place up # ($id becomes $id's next) for ($i = $id; $i < $lines - 1; $i++) { $text[$i] = $text[$i + 1]; } # Save the new entries array. $fp = fopen($gbFile, "w") or die("$msgError: Data file not found! (02)"); for ($i = 0; $i < $lines - 1; $i++) fputs($fp, "$text[$i]\n"); fclose($fp); echo "Message deleted succesfully!
\nGo back to book."; break; } case "modify": { # Exit if id is not set. if ( !isset($id) ) die("$msgError: Nothing to modify!
Please go back. and try again."); $fp = fopen($gbFile, "r") or die("$msgError: Data file not found! (03)
"); fseek($fp, 0); $content = fread($fp, filesize($gbFile)); fclose($fp); $text = explode("\n", $content); $contents = readTemplate("temp_modify.html"); list($name, $date, $email, $url, $message) = explode("|", $text[$_POST["id"]]); $message = str_replace("
", "\n", $message); $contents = swapEntryTags($contents, $id, $name, $date, $email, $url, $message); $contents = swapGlobalTags($contents); echo $contents; break; } case "update": { # Exit if id is not set. if ( !isset($id) ) die("$msgError: Nothing to modify!
Please go back. and try again."); $fp = fopen($gbFile, "r") or die("$msgError: Data file not found! (04)"); fseek($fp, 0); $content = fread($fp, filesize($gbFile)); fclose($fp); $text = explode("\n", $content); $lines = count($text); if ( !empty($_POST) ) { if ( isset($_POST["name"]) ) $name = $_POST["name"]; if ( isset($_POST["email"]) ) $email = $_POST["email"]; if ( isset($_POST["url"]) ) $url = $_POST["url"]; if ( isset($_POST["message"]) ) $message = $_POST["message"]; } else if ( !empty($HTTP_POST_VARS) ) { if ( isset($HTTP_POST_VARS["name"]) ) $name = $HTTP_POST_VARS["name"]; if ( isset($HTTP_POST_VARS["email"]) ) $email = $HTTP_POST_VARS["email"]; if ( isset($HTTP_POST_VARS["url"]) ) $url = $HTTP_POST_VARS["url"]; if ( isset($HTTP_POST_VARS["message"]) ) $message = $HTTP_POST_VARS["message"]; } $name = cleanField($name); $email = cleanField($email); $url = cleanField($url); $message = cleanMessage($message); $modEntry = $name."|".$date."|".$email."|".$url."|".$message."|[end]"; $text[$id] = $modEntry; $fp = fopen($gbFile, "w") or die("$msgDataFileNotFound"); for ($i = 0; $i < $lines - 1; $i++) fputs($fp, "$text[$i]\n"); fclose($fp); echo "Message with id = $id was updated succesfully!.
\nGo back to book\n"; break; } default: { die("$msgError: Unknown action!
Go back to book"); } } } # Action is not set, show the modify/delete selection page. else { # If id is not set, we can not show anything, so exit. if ( !isset($id) ) die("$msgError: No entry was selected!
Please go back. and try again."); $text = file($gbFile); list($name, $date, $email, $url, $message) = explode("|", $text[$id]); $adminContent = readTemplate("temp_admin.html"); $adminContent = swapEntryTags($adminContent, $id, $name, $date, $email, $url, $message); $adminContent = swapGlobalTags($adminContent); echo $adminContent; } ?>