- <?php
- $results = 5; //How many news articles per page?
- $newspass = "12292"; //The password for the news editing/deleting/adding
- if ($_COOKIE['news'] == $newspass) {setcookie("news", $newspass, time()+3600);}
- //What is displayed if an ID is not defined
- if (!$_GET['do']) {
- include("db_connect.php"); //Initiate a connection to the database
- $result = mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT $results"); //The query
- include ('./fix.php');
- //Split up the result into rows
- while ($row = mysql_fetch_array($result)) {
- echo "<a href='index.php?do=article&id=" . $row['id'] . "'><h1><font color='#009900'>" . $row['subject'] . "</font> </h1></a>";
- echo "<center><h3><b><font color='#666666'> Posted by " . $row['author'] . " on " . date("D jS F Y", $row['time']) . " </font></b></h3></center>";
- if ($_COOKIE['news'] == $newspass) {echo ("<p>(<a href='index.php?do=edit&id=" . $row['id'] . "'>edit</a>)(<a href='index.php?do=delete&id=" . $row['id'] . "'>delete</a>) ");}
- echo "<table style='border-style: none;'><tr><td><div style='padding-left: 3em'><p>" . $row['body'] . "</p></div></td></tr></table>";
- echo "<hr><br />";
- }
- }
- //Shows the page for a particular news article
- elseif ($_GET['do'] == "article") {
- include ('./fix.php');
- $id = $_GET['id'];
- include("db_connect.php"); //Initiate a connection to the database
- $article = mysql_query("SELECT * FROM news WHERE id LIKE $id"); //The query for the article
- $comments = mysql_query("SELECT * FROM comments WHERE article_id LIKE $id ORDER BY id"); //The query for the comments
- while ($row = mysql_fetch_array($article)) {
- echo "<a href='index.php?do=article&id=" . $row['id'] . "'><h1><font color='#009900'>" . $row['subject'] . "</font> </h1></a>";
- echo "<center><h3><b><font color='#666666'> Posted by " . $row['author'] . " on " . date("D jS F Y", $row['time']) . " </font></b></h3></center>"; if ($_COOKIE['news'] == $newspass) {echo ("<p>(<a href='index.php?do=edit&id=" . $row['id'] . "'>edit</a>)(<a href='index.php?do=delete&id=" . $row['id'] . "'>delete</a>) ");}
- echo "<table style='border-style: none;'><tr><td><div style='padding-left: 3em'><p>" . $row['body'] . "</p></div></td></tr></table>";
- echo "<hr><br /><h2>Comments.</h2>";
- }
- while ($row = mysql_fetch_array($comments)) {
- echo "<strong><h2><a href='" . $row['subject'] . "'/>" . $row['author'] . "</a></h2></strong>";
- if ($_COOKIE['news'] == $newspass) {echo ("<p>(<a href='index.php?do=deletereply&id=" . $row['id'] . "'>delete</a>) ");}
- echo "<p>" . $row['body'] . "</p>";
- echo "<p>" . date("D jS F Y", $row['time']) . "</p>";
- echo "<br />";
- }
- if (mysql_num_rows($article)>0) {
- echo ("<form action='index.php?do=reply&id=$id' method='post'><br /><input type='text' name='subject' value='http://' /> Your website.<br /><br />
- <input type='text' name='author' value='' /> Name (required)<br /><br />
- <textarea class='body1' name='body' rows='4' cols='20'></textarea><br /><br />");
- require_once('recaptchalib.php');
- $publickey = "6Lc45ggAAAAAAG_5x1oikf1m8Akfq5Vv57TCaU2C"; // you got this from the signup page
- echo recaptcha_get_html($publickey);
- echo ("<input type='submit' value='Reply' />");
- }
- else {
- echo "There is no article with the ID $id, sorry.";
- }
- }
- //Handles posting POST NEWS
- elseif ($_GET['do'] == "post") {
- include ('./fix.php');
- echo (' Notes: <br /> Newline <b> <br /> </b> <br /> Paragraph <b> <p> text </p> </b> <br /> Image <b> <img src="www.linktotheimage.com/thepic.png" /> </b> <br /> Bold <b> <b>This text is entirely BOLD!</b> </b> <br /> Italics <b> <i>Sean is awesome</i> </b> <br /> Underlined <b> I want<u> this </u> word to be underlined! </b> <br /> Hyperlink <b> <a href="http://www.website.com" />Click here to go to website.com</a> ');
- if ($_COOKIE['news'] == $newspass) {
- if (!($_POST['author'] == "") && !($_POST['subject'] == "") && !($_POST['body'] == "")) {
- $author = $_POST['author'];
- $subject = $_POST['subject'];
- $body = $_POST['body'];
- $time = time();
- include("db_connect.php"); //Initiate a connection to the database
- mysql_query("INSERT INTO news (`author`, `subject`, `body`, `time`) VALUES ('$author', '$subject', '$body', '$time')") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
- echo ("<h1>POSTED!! :D</h1><br /><a href='index.php'>News</a>");
- }
- else {
- echo ("<form action='index.php?do=post' method='post'><input type='text' name='subject' value='subject' /><br />
- <textarea class='body' name='body' rows='4' cols='20'></textarea> <br />
- <input type='text' name='author' value='author' /><br />
- <input type='submit' value='Submit' />");
- }
- }
- else {
- echo ("<h1>YOU ARE NOT LOGGED IN OMG</h1>");
- echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");
- }
- }
- //Handles commenting an article
- elseif ($_GET['do'] == "reply") {
- if (!$_POST['author'] or !$_POST['subject'] or !$_POST['body']) {
- $id = $_GET['id'];
- echo ("<form action='index.php?do=reply&id=$id' method='post'><input type='text' name='subject' value='title' /><br />
- <input type='text' name='author' value='author' /><br />
- <input type='text' name='body' value='body' /><br />
- <input type='submit' value='Submit' />");
- }
- else {
- include("db_connect.php"); //Initiate a connection to the database
- //$result = mysql_query("SELECT * FROM news WHERE
- $author = htmlspecialchars($_POST['author']);
- $subject = htmlspecialchars($_POST['subject']);
- $body = htmlspecialchars($_POST['body']);
- $time = time();
- $id = $_GET['id'];
- require_once('recaptchalib.php');
- $privatekey = "6Lc45ggAAAAAAPZBWVMBpxK_XdGhAIm1TnToh9V5";
- $resp = recaptcha_check_answer ($privatekey,
- $_SERVER["REMOTE_ADDR"],
- $_POST["recaptcha_challenge_field"],
- $_POST["recaptcha_response_field"]);
- if (!$resp->is_valid) {
- die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
- "(reCAPTCHA said: " . $resp->error . ")");
- }
- mysql_query("INSERT INTO comments (`author`, `subject`, `body`, `time`, `article_id`) VALUES ('$author', '$subject', '$body', '$time', '$id')") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
- echo ("<h1>Comment posted.</h1><br /><a href='index.php?do=article&id=$id'>Back to article</a>");
- }
- }
- //Handles editing article
- elseif ($_GET['do'] == "edit") {
- include ('./fix.php');
- if ($_COOKIE['news'] == $newspass) {
- if (!$_POST['author']) {
- $id = $_GET['id'];
- include("db_connect.php"); //Initiate a connection to the database
- $article = mysql_query("SELECT * FROM news WHERE id LIKE $id"); //The query for the article
- while ($row = mysql_fetch_array($article)) {
- echo ("<form action='index.php?do=edit&id=" . $row['id'] . "' method='post'><input type='text' name='subject' value='" . $row['subject'] . "' /><br />
- <textarea class='body' name='body' rows='4' cols='20'>" . $row['body'] . "</textarea> <br />
- <input type='text' name='author' value='" . $row['author'] . "' /><br />
- <input type='submit' value='Submit' />");
- }
- }
- else {
- $author = $_POST['author'];
- $subject = $_POST['subject'];
- $body = $_POST['body'];
- $time = time();
- $id = $_GET['id'];
- include("db_connect.php"); //Initiate a connection to the database
- mysql_query("UPDATE news SET author='$author', subject='$subject', body='$body', time='$time' WHERE id LIKE $id") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
- echo ("<h2>Article sucessfully edited.</h2><br /><a href='index.php'>Back to News</a>");
- }
- }
- else {
- echo ("<h1>Please Login.</h1>");
- echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");
- }
- }
- //Handles deleting article
- elseif ($_GET['do'] == "delete") {
- include ('./fix.php');
- if ($_COOKIE['news'] == $newspass) {
- if (!$_GET['sure']) {
- $id = $_GET['id'];
- echo ("<h1>Are you sure you want to DELETE post ID $id</h1>");
- echo ("<h1>This action CANNOT be undone.</h1>");
- echo ("<a href='index.php?do=delete&id=$id&sure=yes'><h1>Yes</h1></a><a href='index.php'><h1>No</h1></a>");
- }
- else {
- if ($_GET['sure'] == "yes") {
- $id = $_GET['id'];
- include("db_connect.php"); //Initiate a connection to the database
- mysql_query("DELETE FROM news WHERE id LIKE $id") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
- echo ("<h1>Artcle Deleted</h1><br /><a href='index.php'>News</a>");
- }
- }
- }
- else {
- echo ("<h1>Please Login.</h1>");
- echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");
- }
- }
- //Handles deleting comments
- elseif ($_GET['do'] == "deletereply") {
- include ('./fix.php');
- if ($_COOKIE['news'] == $newspass) {
- if (!$_GET['sure']) {
- $id = $_GET['id'];
- echo ("<h1>Are you sure you want to DELETE reply ID $id</h1>");
- echo ("<h1>This action CANNOT be undone.</h1>");
- echo ("<a href='index.php?do=deletereply&id=$id&sure=yes'><h1>Yes</h1></a><a href='index.php'><h1>No</h1></a>");
- }
- else {
- if ($_GET['sure'] == "yes") {
- $id = $_GET['id'];
- include("db_connect.php"); //Initiate a connection to the database
- mysql_query("DELETE FROM comments WHERE id LIKE $id") or die("Sorry! It failed! Please try again.<br />" . mysql_error()); //The query for the article
- echo ("<h1>Reply Deleted</h1><br /><a href='index.php'>News</a>");
- }
- }
- }
- else {
- echo ("<h1>Please Login.</h1>");
- echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");
- }
- }
- //Log in
- elseif ($_GET['do'] == "login") {
- if (!$_POST['pass']) {
- echo ("<center><h1>Admin Login</h1>");
- echo ("<form action='index.php?do=login' method='post'><input type='password' name='pass' /><input type='submit' value='Submit' />");
- }
- else {
- if ($_COOKIE['news'] == $newspass) {
- echo ("<h1>Sorry But You Are Already Logged In.</h1><br /><a href='index.php'>News</a>");
- }
- else {
- if ($_POST['pass'] == $newspass) {
- setcookie("news", $newspass, time()+3600);
- echo ("<h1>Thank You For Logging In, You Will Automatically Logged Out After 1 Hour Of Inactivity.</h1><br /><a href='index.php'>News</a>");
- }
- else {
- echo ("<h1>Incorrect PASSWORD.</h1><br /><a href='index.php'>News</a></center>");
- }
- }
- }
- }
- elseif ($_GET['do'] == "logout") {
- if ($_COOKIE['news'] == $newspass) {
- setcookie("news", $newspass, time());
- echo ("<h1>Thank You, You Are Now Logged Out.</h1><br /><a href='index.php'>News</a>");
- }
- else {
- echo ("<h1>You aren't Logged In to Logout...</h1><br /><a href='index.php'>News</a>");
- }
- }
- ?>
- </div>
- </div>
- </body>
- </center>
- </html>
