0) { $id = max($ids) + 1; } else { $id = 1; } return $id; } function dateSort($entries, $descending) { if ($descending) { array_multisort(array_column($entries, 'date'), SORT_DESC, $entries); } else { array_multisort(array_column($entries, 'date'), SORT_ASC, $entries); } return $entries; } function showPages($page, $total_pages) { if ($total_pages > 0) { ?> )/i", $text))) { return false; } return true; } function validateComment($name, $url, $security, $correct, $comment) { if (checkName($name) == false) { $error .= "The name you provided isn't valid - it should only consist of letters. "; } if (checkUrl($url) == false) { $error .= "The URL you provided isn't valid. "; } if (checkSecurity($security, $correct) == false) { $error .= "Wrong security question answer! "; } if (checkComment($comment) == false) { $error .= "No bots or HTML! "; } if (substr_count($comment, 'http://') > 0) { $error .= "Please only include URLs in the website field."; } return $error; } function addComment($filepath, $name, $url, $date, $comment, $reply) { try { $id = getID($filepath); $newentry = array($id, $name, $url, $date, $comment, $reply); $file = fopen($filepath,"a"); fputcsv($file, $newentry); fclose($file); return true; } catch (Exception $ex) { echo $ex->getMessage(); return false; } } function deleteComment($id, $filepath, $headers) { try { $entries = toArray($filepath); $key = array_search($id, array_column($entries, 'id')); if ($key !== false) { unset($entries[$key]); $file = fopen($filepath,"w"); fputcsv($file, $headers); foreach ($entries as $entry) { fputcsv($file, $entry); } fclose($file); return true; } else { echo "The entry you're trying to delete doesn't exist!"; return false; } } catch (Exception $ex) { echo $ex->getMessage(); return false; } } function updateComment($key, $id, $name, $url, $date, $comment, $reply, $headers) { try { if ($key !== false) { $entries = toArray("entries.csv"); $entries[$key] = array($id, $name, $url, $date, $comment, $reply); $file = fopen("entries.csv","w"); fputcsv($file, $headers); foreach ($entries as $entry) { fputcsv($file, $entry); } fclose($file); return true; } else { echo "The entry you're trying to update doesn't exist!"; return false; } } catch (Exception $ex) { echo $ex->getMessage(); return false; } } function showEntries($entries, $status) { ?>
Name URL Date Comment Reply Edit
Edit