diff --git a/crud.php b/crud.php
index 4531ab8..dd787e8 100644
--- a/crud.php
+++ b/crud.php
@@ -8,11 +8,11 @@
}
elseif ($type == "archive")
{
- $sql = 'SELECT * FROM article ORDER BY id DESC';
+ $sql = 'SELECT * FROM archive ORDER BY id DESC';
}
elseif ($type == "article")
{
- $sql = 'SELECT * FROM archive ORDER BY id DESC';
+ $sql = 'SELECT * FROM article ORDER BY id DESC';
}
?>
@@ -39,7 +39,7 @@
query($sql)))
{
?>
diff --git a/dbBackup/conspirator.sql b/dbBackup/conspirator.sql
index f70a02b..a3dc50d 100644
--- a/dbBackup/conspirator.sql
+++ b/dbBackup/conspirator.sql
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
--- Generation Time: Nov 19, 2014 at 09:17 AM
+-- Generation Time: Nov 29, 2014 at 09:23 AM
-- Server version: 5.6.16
-- PHP Version: 5.5.11
@@ -23,15 +23,20 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
--- Table structure for table `archive_facts`
+-- Table structure for table `archive`
--
-CREATE TABLE IF NOT EXISTS `archive_facts` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `archive_id` int(11) NOT NULL,
- `content` text NOT NULL,
+CREATE TABLE IF NOT EXISTS `archive` (
+ `id` int(11) NOT NULL DEFAULT '0',
+ `archive_name` varchar(30) NOT NULL,
+ `image` varchar(50) NOT NULL,
+ `content` mediumtext NOT NULL,
+ `date_created` date NOT NULL,
+ `author_id` int(11) NOT NULL,
+ `category` varchar(35) NOT NULL,
+ `quick_facts` text NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -46,38 +51,12 @@ CREATE TABLE IF NOT EXISTS `article` (
`content` mediumtext NOT NULL,
`date_created` date NOT NULL,
`author_id` int(11) NOT NULL,
- `category_id` int(11) NOT NULL,
- `is_archive` tinyint(1) NOT NULL,
+ `category` varchar(35) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
---
--- Table structure for table `category`
---
-
-CREATE TABLE IF NOT EXISTS `category` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `cat_name` varchar(25) NOT NULL,
- `css_link` varchar(50) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
-
---
--- Dumping data for table `category`
---
-
-INSERT INTO `category` (`id`, `cat_name`, `css_link`) VALUES
-(1, 'history', 'styles/history.css'),
-(2, 'evilCorps', 'styles/evilcorps.css'),
-(3, 'aliens', 'styles/aliens.css'),
-(4, 'exoticCreatures', 'styles/exotic.css'),
-(5, 'urbanLegends', 'styles/urbanleg.css'),
-(6, 'endOfDays', 'styles/endofdays.css');
-
--- --------------------------------------------------------
-
--
-- Table structure for table `comment`
--
diff --git a/delete.php b/delete.php
index 7a762b2..7aa5431 100644
--- a/delete.php
+++ b/delete.php
@@ -1,7 +1,9 @@
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "DELETE FROM customers WHERE id = ?";
+ $sql = "DELETE FROM article WHERE id = ?";
$q = $pdo->prepare($sql);
$q->execute(array($id));
Database::disconnect();
- header("Location: index.php");
-
- }
+ header("Location: index.php?page=crud&type=article");
+ }
+
+ elseif($type == 'archive')
+ {
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "DELETE FROM archive WHERE id = ?";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($id));
+ Database::disconnect();
+ header("Location: index.php?page=crud&type=archive");
+ }
+ }
?>
-
-
+
\ No newline at end of file
diff --git a/imageupload.php b/imageupload.php
new file mode 100644
index 0000000..d3085af
--- /dev/null
+++ b/imageupload.php
@@ -0,0 +1,85 @@
+ 1000000)
+ {
+ $imageError = 'Sorry, your file is too large'
+ $uploadOk = 0;
+ }
+
+ // Check file format
+
+ if($imageFileType != "gif" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "jpg")
+ {
+ $imageError = 'Sorry, only JPG, JPEG, PNG and GIF files are allowed';
+ $uploadOk = 0;
+ }
+
+ // Check if $uploadOk is true try to upload image and set path as DB value
+
+ if ($uploadOk == 1)
+ {
+ if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile))
+ {
+ $image = $targetFile;
+ }
+ else
+ {
+ $imageError = 'Sorry, there was an error uploading your file';
+ }
+ }
+
+
+?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 57e5212..5852424 100644
--- a/index.php
+++ b/index.php
@@ -14,9 +14,30 @@
-
-
-
-
-
Write an Archive
-
-
-
+ }
+ else
+ {
+ header("Location: index.php");
+ }
+
+ $valid = true;
-
-
-
Write an Article
-
-
- ';
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Back';?>
-
-
-
-
-
+ $quickFactsError = null;
+ $quickFacts = $_POST['quickFacts'];
+ }
-
-
I'm not sure you're meant to be here! Please return to the homepage here
-
+ // keep track post values
+ $name = $_POST['name'];
+ $content = $_POST['content'];
+ $category = $_POST['category'];
-
-
-
-
-
\ No newline at end of file
+
+ if (empty($image)) {
+ //$imageError = 'Please upload a feature image';
+ $valid = false;
+ $errors[] = $imageError;
+ }
+
+
+ //need to set up image errors
+
+ if (empty($content)) {
+ $contentError = 'Please enter some content';
+ $valid = false;
+ $errors[] = $contentError;
+ }
+
+ if (empty($category)) {
+ $categoryError = 'Please choose a category';
+ $valid = false;
+ $errors[] = $categoryError;
+ }
+
+ if ($type == 'archive')
+ {
+ if (empty($quickFacts)) {
+ $quickFactsError = 'Please enter the archive\'s quick facts';
+ $valid = false;
+ $errors[] = $quickFactsError;
+ }
+ }
+
+ // insert data
+ if ($valid == true) {
+ //setting non-user input vars
+ $date = date("Y/m/d");
+ $author = $userId;
+ echo ($date);
+ echo($author);
+ if ($type == 'archive')
+ {
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "INSERT INTO archive (archive_name,image,content,date_created,author_id,category,quick_facts) values(?, ?, ?, ?, ?, ?, ?)";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($name,$image,$content,$date,$author,$category,$quickFacts));
+ Database::disconnect();
+ header("Location: index.php?page=crud&type=article");
+ }
+ elseif ($type == 'article')
+ {
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "INSERT INTO article (article_name,image,content,date_created,author_id,category) values(?, ?, ?, ?, ?, ?)";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($name,$image,$content,$date,$author,$category));
+ Database::disconnect();
+ header("Location: index.php?page=crud&type=article");
+ }
+ else
+ {
+ header("Location: index.php");
+ }
+ }
+ }
+ }
+?>
\ No newline at end of file
diff --git a/createform.php b/createform.php
new file mode 100644
index 0000000..8913196
--- /dev/null
+++ b/createform.php
@@ -0,0 +1,217 @@
+
+
+
+ $error");
+ }
+ echo("
");
+ }
+ ?>
+
+
Create a User
+
+ ';
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back';?>
+
+
+
+
+
+
+
+ $error");
+ }
+ ?>
+
+
+
+ Write an Archive');
+ }
+ else
+ {
+ echo('
Write an Article
');
+ }
+
+ ?>
+
+ ';
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back';?>
+
+
+
+
+
+
+
+
I'm not sure you're meant to be here! Please return to the homepage here
+
+
+
\ No newline at end of file
diff --git a/dbBackup/createbackup.php b/dbBackup/createbackup.php
new file mode 100644
index 0000000..d2892ba
--- /dev/null
+++ b/dbBackup/createbackup.php
@@ -0,0 +1,636 @@
+setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "SELECT permissions FROM user WHERE id = ?";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($userId));
+ $f = $q->fetch(PDO::FETCH_ASSOC);
+ $permissions = $f['permissions'];
+ Database::disconnect();
+
+ if($permissions != 3)
+ {
+ header("Location: index.php");
+ }
+ }
+ else
+ {
+ header("Location: index.php");
+ }
+
+
+ $email = null;
+ $password = null;
+ $firstName = null;
+ $lastName = null;
+ $dateJoined = null;
+ $permissions = null;
+ $avatar = null;
+ $bio = null;
+
+
+
+ if (!empty($_POST)) {
+ // keep track validation errors
+ $emailError = null;
+ $passwordError = null;
+ $firstNameError = null;
+ $lastNameError = null;
+ $permissionsError = null;
+ $avatarError = null;
+ $bioError = null;
+
+ // keep track post values
+ $email = $_POST['email'];
+ $password = $_POST['password'];
+ $firstName = $_POST['firstName'];
+ $lastName = $_POST['lastName'];
+ $permissions = $_POST['permissions'];
+ $avatar = $_POST['avatar'];
+ $bio = $_POST['bio'];
+
+
+ // validate input
+ $valid = true;
+
+ # Validate and Sanitize all user input #
+
+
+ if (!empty($email))
+ {
+ $email = filter_var($email, FILTER_SANITIZE_EMAIL);
+ $email = filter_var($email, FILTER_VALIDATE_EMAIL);
+ if(empty($email))
+ {
+ $valid = false;
+ $emailError = 'Email invalid, please try again.';
+ $errors[] = $emailError;
+ }
+ else
+ {
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "SELECT email FROM user";
+ foreach ($pdo->query($sql) as $row)
+ {
+ if($row['email'] == $email)
+ {
+ $valid = false;
+ $emailError = 'Email address is already in use, please try a different one.';
+ $errors[] = $emailError;
+ }
+ }
+ Database::disconnect();
+ }
+ }
+ else
+ {
+ $valid = false;
+ $emailError = 'Please enter an email address.';
+ $errors[] = $emailError;
+ }
+
+ if (!empty($password))
+ {
+ $password = filter_var($password, FILTER_SANITIZE_STRING);
+ if (ctype_alnum($password) && strlen($password) > 7)
+ {
+ $password = password_hash($password, PASSWORD_DEFAULT);
+ $errors[] = $passwordError;
+ }
+ else
+ {
+ $valid = false;
+ $passwordError = 'Password is invalid, please review the guidelines and try again.';
+ $errors[] = $passwordError;
+ }
+ }
+ else
+ {
+ $valid = false;
+ $passwordError = 'Please enter a password.';
+ $errors[] = $passwordError;
+ }
+
+ if(!empty($firstName))
+ {
+ $firstName = filter_var($firstName, FILTER_SANITIZE_STRING);
+ if(!preg_match('^[a-zA-Z]{1,25}$', $firstName))
+ {
+ $valid = false;
+ $firstNameError = 'First name input is invalid, please review the guidelines and try again.';
+ $errors[] = $firstNameError;
+ }
+ }
+ else
+ {
+ $valid = false;
+ $firstNameError = 'Please enter your first name.';
+ $errors[] = $firstNameError;
+ }
+
+ if(!empty($lastName))
+ {
+ $lastName = filter_var($lastName, FILTER_SANITIZE_STRING);
+ if(!preg_match('^[a-zA-Z]{1,25}$', $lastName))
+ {
+ $valid = false;
+ $lastNameError = 'Last name input is invalid, please review the guidelines and try again.';
+ $errors[] = $lastNameError;
+ }
+ }
+ else
+ {
+ $valid = false;
+ $lastNameError = 'Please enter your last name.';
+ $errors[] = $lastNameError;
+ }
+
+ //Sets avatar image and string
+ if(!empty($avatar))
+ {
+ require 'imageupload.php';
+ if($uploadOk != 1)
+ {
+ $valid = false;
+ $errors[] = $imageError;
+ }
+ }
+ else
+ {
+ $image = 'default.jpg';
+ }
+
+ if(!empty($bio))
+ {
+ $bio = filter_var($bio, FILTER_SANITIZE_STRING);
+ if(strlen($password) > 512)
+ {
+ $valid = false;
+ $bioError = 'Your bio is too long, please reduce to 512 characters and resubmit.';
+ $errors[] = $bioError;
+ }
+ }
+ else
+ {
+ $valid = false;
+ $bioError = 'Please enter a short personal bio.';
+ $errors[] = $bioError;
+ }
+
+ if(!empty($permissions))
+ {
+ $permissions = filter_var($permissions, FILTER_SANITIZE_NUMBER_INT);
+ if($permissions < 1 && $permissions > 3)
+ {
+ $permissionsError = 'Set permissions are invalid, please revise.';
+ $valid = false;
+ $errors[] = $permissonsError;
+ }
+ }
+ else
+ {
+ $permissionsError = 'User permissions need to be set, please try again.';
+ $valid = false;
+ $errors[] = $permissonsError;
+ }
+
+ # Functions to be run if all input is valid #
+ if ($valid == true)
+ {
+ //Set non-user input variables
+ $dateJoined = date("Y/m/d");
+
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+ //Write to database table user
+ $sql = "INSERT INTO user (email,password,first_name,last_name,date_joined,permissions,avatar,bio) values(?, ?, ?, ?, ?, ?, ?, ?)";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($email,$password,$firstName,$lastName,$dateJoined,$permissions,$avatar,$bio));
+
+ Database::disconnect();
+ }
+ }
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $error");
+ }
+ ?>
+
+
+
+
+
+
Create a User
+
+ ';
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back';?>
+
+
+
+
+
+
+setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "SELECT permissions FROM user WHERE id = ?";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($userId));
+ $f = $q->fetch(PDO::FETCH_ASSOC);
+ $permissions = $f['permissions'];
+ Database::disconnect();
+
+ if($permissions < 2 || $permissions > 3)
+ {
+ header("Location: index.php");
+ }
+ }
+ else
+ {
+ header("Location: index.php");
+ }
+
+ $valid = true;
+
+ $name = null;
+ $image = null;
+ $content = null;
+ $date = null;
+ $author = null;
+ $category = null;
+
+ if (!empty($_POST)) {
+ // keep track validation errors
+ $nameError = null;
+ $imageError = null;
+ $contentError = null;
+ $categoryError = null;
+
+
+ //including image upload scripts
+ require 'imageupload.php';
+
+ echo($valid);
+
+
+ //adding in quickfacts vars in case of archive
+ if ($type == 'archive')
+ {
+ $quickFactsError = null;
+ $quickFacts = $_POST['quickFacts'];
+ }
+
+ // keep track post values
+ $name = $_POST['name'];
+ $content = $_POST['content'];
+ $category = $_POST['category'];
+
+ // validate input
+ $valid = true;
+ if (empty($name)) {
+ $nameError = 'Please enter the '.$type.'\'s name';
+ $valid = false;
+ $errors[] = $nameError;
+ }
+
+ if (empty($image)) {
+ //$imageError = 'Please upload a feature image';
+ $valid = false;
+ $errors[] = $imageError;
+ }
+
+
+ //need to set up image errors
+
+ if (empty($content)) {
+ $contentError = 'Please enter some content';
+ $valid = false;
+ $errors[] = $contentError;
+ }
+
+ if (empty($category)) {
+ $categoryError = 'Please choose a category';
+ $valid = false;
+ $errors[] = $categoryError;
+ }
+
+ if ($type == 'archive')
+ {
+ if (empty($quickFacts)) {
+ $quickFactsError = 'Please enter the archive\'s quick facts';
+ $valid = false;
+ $errors[] = $quickFactsError;
+ }
+ }
+
+ // insert data
+ if ($valid == true) {
+ //setting non-user input vars
+ $date = date("Y/m/d");
+ $author = $userId;
+ echo ($date);
+ echo($author);
+ if ($type == 'archive')
+ {
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "INSERT INTO archive (archive_name,image,content,date_created,author_id,category,quick_facts) values(?, ?, ?, ?, ?, ?, ?)";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($name,$image,$content,$date,$author,$category,$quickFacts));
+ Database::disconnect();
+ header("Location: index.php?page=crud&type=article");
+ }
+ elseif ($type == 'article')
+ {
+ $pdo = Database::connect();
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $sql = "INSERT INTO article (article_name,image,content,date_created,author_id,category) values(?, ?, ?, ?, ?, ?)";
+ $q = $pdo->prepare($sql);
+ $q->execute(array($name,$image,$content,$date,$author,$category));
+ Database::disconnect();
+ header("Location: index.php?page=crud&type=article");
+ }
+ else
+ {
+ header("Location: index.php");
+ }
+ }
+ }
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $error");
+ }
+ ?>
+
+
+
+
+
+ Write an Archive');
+ }
+ else
+ {
+ echo('
Write an Article
');
+ }
+
+ ?>
+
+
+
+
+ ';
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Back';?>
+
+
+
+
+
+
+
+
I'm not sure you're meant to be here! Please return to the homepage here
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/images/Aliens1.png b/images/Aliens1.png
new file mode 100644
index 0000000000000000000000000000000000000000..427b0cb497573e923e196b2ede30c394217987e6
GIT binary patch
literal 122948
zcmZU(V{|4!vo4y6CQc@{ZEIrNHs08_C&|RN%{R7f+qP|-`S#xToW0iVwOUp6RCU#_
z>go