Skip to content

Commit

Permalink
Insert, Update and Delete posts, links and users.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantschultz committed Feb 18, 2014
1 parent 47de1ca commit 6767e50
Show file tree
Hide file tree
Showing 32 changed files with 1,571 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ErrorDocument 400 /400.php
ErrorDocument 401 /401.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
8 changes: 8 additions & 0 deletions 400.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">400 Error:</h1>
<h1 id="welcome">Bad request</h1>

8 changes: 8 additions & 0 deletions 400.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">400 Error:</h1>
<h1 id="welcome">Bad request</h1>

7 changes: 7 additions & 0 deletions 401.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">401 Error:</h1>
<h1 id="welcome">Authorization required</h1>
7 changes: 7 additions & 0 deletions 401.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">401 Error:</h1>
<h1 id="welcome">Authorization required</h1>
7 changes: 7 additions & 0 deletions 403.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">403 Error:</h1>
<h1 id="welcome">Forbidden</h1>
7 changes: 7 additions & 0 deletions 403.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">403 Error:</h1>
<h1 id="welcome">Forbidden</h1>
7 changes: 7 additions & 0 deletions 404.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">404 Error:</h1>
<h1 id="welcome">Page not found</h1>
7 changes: 7 additions & 0 deletions 404.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">404 Error:</h1>
<h1 id="welcome">Page not found</h1>
7 changes: 7 additions & 0 deletions 500.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">500 Error:</h1>
<h1 id="welcome">Internal server error</h1>
7 changes: 7 additions & 0 deletions 500.shtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">500 Error:</h1>
<h1 id="welcome">Internal server error</h1>
5 changes: 1 addition & 4 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ a:active { /* selected link */
#c1 {
background: url(/images/home.jpeg) fixed no-repeat;
background-size: cover;
font-size: 6em;
}

.content p {
Expand All @@ -89,7 +90,3 @@ img {
height: auto;
box-shadow: 5px 5px 25px black;
}

#welcome{
font-size: 6em;
}
6 changes: 6 additions & 0 deletions error_page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
// Display Header
include $_SERVER['DOCUMENT_ROOT'] . '/view/header.php';
?>

<h1 id="welcome">404 Error: Page not found</h1>
92 changes: 88 additions & 4 deletions helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

function hashPassword($password) {
$crypt = crypt($password, 'Ns');
return $crypt;
}


//functions to sanitize and validate user input

function cleanString ($string){
Expand All @@ -12,7 +18,7 @@ function cleanString ($string){

function cleanEmail ($email){
$email = trim($email);
$string = removeTags ($string);
$email = removeTags($email);
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
return $email;
Expand All @@ -32,6 +38,74 @@ function encodeTags ($string){

//BUILD FUNCTIONS

function createLink($id){

$link = "index.php?action=content&amp;page_id=" . $id;
return $link;
}

function buildListOfContent(){

$headers = array();
$headers = getLinks();



if(is_array($headers)){
$navigation = "<ul>";
foreach ($headers as $head){
$navigation .= "<li><h1><a href='http://cs313.nathantschultz.com/?action=content&amp;page_id=" . $head['post_id'] . "'>". $head['title'] . "</a></h1> <a href='http://cs313.nathantschultz.com/index.php?action=edit_content&amp;page_id=". $head['post_id'] ."'>Edit</a> <a href='http://cs313.nathantschultz.com/index.php?action=confirm_delete_content&amp;page_id=". $head['post_id'] ."'>Delete</a></li>";
}
$navigation .= "</ul>";

} else {
$navigation = 'Sorry, a critical error occurred.';
}
return $navigation;


}

function buildUserProfile($id){
$people = getPeople();
$content = null;
$admin = null;

foreach ($people as $person){
if ($person['user_id'] == $id){
if($person['admin']){
$admin = "YES";
} else {
$admin = "NO";
}
$content .= "<h1>".$person['name']."</h1><ul><li>EMAIL: ". $person['email']."</li><li>PASSWORD: ***********</li><li>ADMIN: ".$admin."</li><li><a href='http://cs313.nathantschultz.com/index.php?action=edit_user&amp;page_id=".$person['user_id']."'>edit</a> <a href='http://cs313.nathantschultz.com/index.php?action=confirm_delete_user&amp;page_id=".$person['user_id']."'>delete</a></li></ul>";
}
}

return $content;
}

function buildAdminProfile(){


//display content list link

//display list of users with editing abilitiy for each part
$people = getPeople();
$content = "<h1><a href='http://cs313.nathantschultz.com/index.php?action=list_content'>EDIT CONTENT</a></h1><h1>USERS:</h1><ul>";
$admin = null;

foreach ($people as $person){
if ($person['admin']) {
$admin = "YES";
} else {
$admin = "NO";
}
$content .= "<li><h1>".$person['name']."</h1><ul><li>EMAIL: ". $person['email']."</li><li>PASSWORD: ***********</li><li>ADMIN: ".$admin."</li><li><a href='http://cs313.nathantschultz.com/index.php?action=edit_user&amp;page_id=".$person['user_id']."'>edit</a> <a href='http://cs313.nathantschultz.com/index.php?action=confirm_delete_user&amp;page_id=".$person['user_id']."'>delete</a></li></ul></li>";
}
return $content;
}



function buildNav(){
Expand All @@ -41,7 +115,7 @@ function buildNav(){
$nav = "";

foreach ($links as $link){
$nav .= "<li><a href='http://cs313.nathantschultz.com/?action=content&page_id=" . $link['post_id'] . "'>". $link['title'] . "</a>";
$nav .= "<li><a href='http://cs313.nathantschultz.com/?action=content&amp;page_id=" . $link['post_id'] . "'>". $link['title'] . "</a>";
}

} else {
Expand Down Expand Up @@ -75,11 +149,21 @@ function buildContent($page_id){
//echo $alerts;
//$alerts = "";

echo "<div class='content' id='c$page_id'>";
echo "<section class='content' id='c$page_id'>";

if(!isset($_SESSION['$alerts'])){
$_SESSION['$alerts'] = false;
}

if($_SESSION['$alerts']){
echo $_SESSION['$alerts'] . "<br />";
$_SESSION['$alerts'] = "";
}


//display content and footer
echo $page;
echo "</div></body></html>";
echo "</section></body></html>";

}

Expand Down
Loading

0 comments on commit 6767e50

Please sign in to comment.