diff --git a/coursework-blog/step-1/admin.php b/coursework-blog/step-1/admin.php deleted file mode 100644 index f20b87a9cc4b66b450a8e70609ecc85981bf54b8..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include '../../../config.php'; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-1/controllers/admin/editor.php b/coursework-blog/step-1/controllers/admin/editor.php deleted file mode 100644 index a4eb8bf5696308ad16e010c8b5e64af3140fe6fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/controllers/admin/editor.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //was "save" button clicked - $insertNewEntry = ( $buttonClicked === 'save' ); - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } -} - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-1/controllers/admin/entries.php b/coursework-blog/step-1/controllers/admin/entries.php deleted file mode 100644 index 969eed60a018897d9183d8e80d85439138beeec4..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/controllers/admin/entries.php +++ /dev/null @@ -1,5 +0,0 @@ -<? - -echo "here's the entries!"; - -?> diff --git a/coursework-blog/step-1/coursework-blog.sql b/coursework-blog/step-1/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-1/css/blog.css b/coursework-blog/step-1/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-1/models/Blog_Entry_Table.class.php b/coursework-blog/step-1/models/Blog_Entry_Table.class.php deleted file mode 100644 index 0cabf4b37d577eddc0e721fe2d195137e265ec3f..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - -} diff --git a/coursework-blog/step-1/views/admin/admin-navigation.php b/coursework-blog/step-1/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-1/views/admin/editor-html.php b/coursework-blog/step-1/views/admin/editor-html.php deleted file mode 100644 index 71476759c7e9d090983c3fa57665586fecca05bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/views/admin/editor-html.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' /> - - <label>Entry</label> - <textarea name='entry'></textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-1/views/admin/entries-html.php b/coursework-blog/step-1/views/admin/entries-html.php deleted file mode 100644 index 681402413fa04860c8f8e76845f91a70d05e563a..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/views/admin/entries-html.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-1/views/footer.php b/coursework-blog/step-1/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-1/views/header.php b/coursework-blog/step-1/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-1/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-10/admin.php b/coursework-blog/step-10/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-10/controllers/admin/editor.php b/coursework-blog/step-10/controllers/admin/editor.php deleted file mode 100644 index bb87c09f4d1097e94677207ef423d14c82243b41..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/controllers/admin/editor.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -include_once "models/Table.class.php"; -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - $id = $_POST['id']; - $save = ($buttonClicked === 'save'); - $insertNewEntry = ( $save and $id === '0' ); - $updateEntry = ( $save and $insertNewEntry === false ); - $deleteEntry = ($buttonClicked === 'delete'); - - $title = $_POST['title']; - $entry = $_POST['entry']; - - if ( $insertNewEntry ) { - $savedEntryId = $entryTable->saveEntry( $title, $entry ); - } else if ( $updateEntry ){ - $entryTable->updateEntry( $id, $title, $entry ); - $savedEntryId = $id; - } else if ( $deleteEntry ) { - $entryTable->deleteEntry( $id ); - } -} - -$entryRequested = isset( $_GET['id'] ); -$entrySaved = isset( $savedEntryId ); - -if ( $entryRequested ) { - $id = $_GET['id']; - $entryData = $entryTable->getEntry( $id ); - $entryData->entry_id = $id; - $entryData->message = ""; -} else if ( $entrySaved ) { - $entryData = $entryTable->getEntry( $savedEntryId ); - $entryData->message = "Entry was saved"; -} else { - $entryData = new StdClass(); - $entryData->entry_id = 0; - $entryData->title = ""; - $entryData->entry_text = ""; - $entryData->message = ""; -} - - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-10/controllers/admin/entries.php b/coursework-blog/step-10/controllers/admin/entries.php deleted file mode 100644 index 921d4945477d1b8f9120593603abbb64a9dd19a5..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/controllers/admin/entries.php +++ /dev/null @@ -1,11 +0,0 @@ -<? - -include_once "models/Table.class.php"; -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-10/controllers/admin/users.php b/coursework-blog/step-10/controllers/admin/users.php deleted file mode 100644 index 29516cf1844145610a682e807488ac0b969148a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/controllers/admin/users.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -include_once "models/Table.class.php"; -include_once "models/Admin_Table.class.php"; - -$createNewAdmin = isset( $_POST['new-admin'] ); - -if( $createNewAdmin ) { - - $newEmail = $_POST['email']; - $newPassword = $_POST['password']; - $adminTable = new Admin_Table($db); - - try { - $adminTable->create( $newEmail, $newPassword ); - $adminFormMessage = "New user created"; - } catch ( Exception $e ) { - $adminFormMessage = $e->getMessage(); - } -} - -include_once "views/admin/new-admin-form-html.php"; diff --git a/coursework-blog/step-10/controllers/blog.php b/coursework-blog/step-10/controllers/blog.php deleted file mode 100644 index c675c8fc0f6da2223d57892b16396ae05a5001cd..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/controllers/blog.php +++ /dev/null @@ -1,17 +0,0 @@ -<? -include_once "models/Table.class.php"; -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-10/coursework-blog.sql b/coursework-blog/step-10/coursework-blog.sql deleted file mode 100644 index d9006b2c318c93f769f3be69fa408e58f73731f7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/coursework-blog.sql +++ /dev/null @@ -1,16 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) - --- this will create a table for admin users -CREATE TABLE admin ( - admin_id INT NOT NULL AUTO_INCREMENT, - email TEXT, - password VARCHAR( 32 ), - PRIMARY KEY ( admin_id ) -) diff --git a/coursework-blog/step-10/css/blog.css b/coursework-blog/step-10/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-10/index.php b/coursework-blog/step-10/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-10/models/Admin_Table.class.php b/coursework-blog/step-10/models/Admin_Table.class.php deleted file mode 100644 index dd52931c75a0a78e24a4825f9eed59bd35884511..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/models/Admin_Table.class.php +++ /dev/null @@ -1,25 +0,0 @@ -<? - -class Admin_Table extends Table { - - public function create ( $email, $password ) { - //check if e-mail is available - $this->checkEmail( $email ); - //encrypt password with MD5 - $sql = "INSERT INTO admin ( email, password ) - VALUES( ?, SHA1(?) )"; - $data= array( $email, $password ); - $this->makeStatement( $sql, $data ); - } - - private function checkEmail ($email) { - $sql = "SELECT email FROM admin WHERE email = ?"; - $data = array( $email ); - $this->makeStatement( $sql, $data ); - $statement = $this->makeStatement( $sql, $data ); - if ( $statement->rowCount() === 1 ) { - $e = new Exception("Error: '$email' already used!"); - throw $e; - } - } -} diff --git a/coursework-blog/step-10/models/Blog_Entry_Table.class.php b/coursework-blog/step-10/models/Blog_Entry_Table.class.php deleted file mode 100644 index 9a6c81a1ecb26e5d5f7e420233735eea307fd271..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php -class Blog_Entry_Table extends Table { - - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) VALUES ( ?, ?)"; - $formData = array( $title, $entry ); - $entryStatement = $this->makeStatement( $entrySQL, $formData ); - return $this->db->lastInsertId(); - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function updateEntry ( $id, $title, $entry) { - $sql = "UPDATE blog_entry - SET title = ?, - entry_text = ? - WHERE entry_id = ?"; - $data = array( $title, $entry, $id ); - $statement = $this->makeStatement( $sql, $data) ; - return $statement; - } - - public function deleteEntry ( $id ) { - $sql = "DELETE FROM blog_entry WHERE entry_id = ?"; - $data = array( $id ); - $statement = $this->makeStatement( $sql, $data ); - } - -} - -?> diff --git a/coursework-blog/step-10/models/Table.class.php b/coursework-blog/step-10/models/Table.class.php deleted file mode 100644 index 0f5eaf1cd18b5e778762ae34c234a716c7f5f0b4..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/models/Table.class.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -class Table { - protected $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} diff --git a/coursework-blog/step-10/views/admin/admin-navigation.php b/coursework-blog/step-10/views/admin/admin-navigation.php deleted file mode 100644 index 05a639ed7217f7d8aff2dd315526441cc5f180fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/admin/admin-navigation.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> - <a href='admin.php?page=users'>Create admin user</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-10/views/admin/editor-html.php b/coursework-blog/step-10/views/admin/editor-html.php deleted file mode 100644 index e614941c7cfbf37d4cf009076dcf31cc2c3eaffb..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/admin/editor-html.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <input type='hidden' name='id' value='$entryData->entry_id' /> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' value='$entryData->title' required /> - - <label>Entry</label> - <textarea name='entry'>$entryData->entry_text</textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='delete' /> - <input type='submit' name='action' value='save' /> - <p id='editor-message'>$entryData->message</p> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-10/views/admin/entries-html.php b/coursework-blog/step-10/views/admin/entries-html.php deleted file mode 100644 index 2097a76b3afa1ec464ca5dccfc984d5ad63cfafe..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/admin/entries-html.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -if ( isset( $allEntries ) === false ) { -trigger_error('views/admin/entries-html.php needs $allEntries'); -} - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-10/views/admin/new-admin-form-html.php b/coursework-blog/step-10/views/admin/new-admin-form-html.php deleted file mode 100644 index 71cb6f288d9a00a702bde0fba7363da96d5efecb..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/admin/new-admin-form-html.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -//complete code for views/admin/new-admin-form-html.php -if( isset($adminFormMessage) === false ) { - $adminFormMessage = ""; -} - -$out = "<form method='post' action='admin.php?page=users'> - <fieldset> - <legend>Create new admin user</legend> - <label>e-mail</label> - <input type='text' name='email' required/> - <label>password</label> - <input type='password' name='password' required/> - <input type='submit' value='create user' name='new-admin'/> - </fieldset> - <p id='admin-form-message'>$adminFormMessage</p> -</form>"; - -echo $out; - - diff --git a/coursework-blog/step-10/views/entry-html.php b/coursework-blog/step-10/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-10/views/footer.php b/coursework-blog/step-10/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-10/views/header.php b/coursework-blog/step-10/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-10/views/list-entries-html.php b/coursework-blog/step-10/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-10/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-11/admin.php b/coursework-blog/step-11/admin.php deleted file mode 100644 index f538ad87186f155960d55a7b5332ea92aa405978..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/admin.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; - -include_once "models/Table.class.php"; -include_once "models/Admin_User.class.php"; -$admin = new Admin_User(); - -include_once "controllers/admin/login.php"; - -if( $admin->isLoggedIn() ) { - include_once "views/admin/admin-navigation.php"; - - $navigation = isset( $_GET['page'] ); - if ( $navigation ) { - $contrl = $_GET['page']; - } else { - $contrl = "entries"; - } - include_once "controllers/admin/$contrl.php"; - include_once "views/admin/logout-form-html.php"; -} -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-11/controllers/admin/editor.php b/coursework-blog/step-11/controllers/admin/editor.php deleted file mode 100644 index bb87c09f4d1097e94677207ef423d14c82243b41..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/controllers/admin/editor.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -include_once "models/Table.class.php"; -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - $id = $_POST['id']; - $save = ($buttonClicked === 'save'); - $insertNewEntry = ( $save and $id === '0' ); - $updateEntry = ( $save and $insertNewEntry === false ); - $deleteEntry = ($buttonClicked === 'delete'); - - $title = $_POST['title']; - $entry = $_POST['entry']; - - if ( $insertNewEntry ) { - $savedEntryId = $entryTable->saveEntry( $title, $entry ); - } else if ( $updateEntry ){ - $entryTable->updateEntry( $id, $title, $entry ); - $savedEntryId = $id; - } else if ( $deleteEntry ) { - $entryTable->deleteEntry( $id ); - } -} - -$entryRequested = isset( $_GET['id'] ); -$entrySaved = isset( $savedEntryId ); - -if ( $entryRequested ) { - $id = $_GET['id']; - $entryData = $entryTable->getEntry( $id ); - $entryData->entry_id = $id; - $entryData->message = ""; -} else if ( $entrySaved ) { - $entryData = $entryTable->getEntry( $savedEntryId ); - $entryData->message = "Entry was saved"; -} else { - $entryData = new StdClass(); - $entryData->entry_id = 0; - $entryData->title = ""; - $entryData->entry_text = ""; - $entryData->message = ""; -} - - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-11/controllers/admin/entries.php b/coursework-blog/step-11/controllers/admin/entries.php deleted file mode 100644 index 921d4945477d1b8f9120593603abbb64a9dd19a5..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/controllers/admin/entries.php +++ /dev/null @@ -1,11 +0,0 @@ -<? - -include_once "models/Table.class.php"; -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-11/controllers/admin/login.php b/coursework-blog/step-11/controllers/admin/login.php deleted file mode 100644 index 83a7aba705c5e1ba0ba0f8b5e70c2826574a21d1..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/controllers/admin/login.php +++ /dev/null @@ -1,26 +0,0 @@ -<? -include_once "models/Admin_Table.class.php"; - -$loginFormSubmitted = isset( $_POST['log-in'] ); -if( $loginFormSubmitted ) { - $email = $_POST['email']; - $password = $_POST['password']; - - $adminTable = new Admin_Table( $db ); - try { - $adminTable->checkCredentials( $email, $password ); - $admin->login(); - } catch ( Exception $e ) { - echo $e->getMessage(); - } - -} - -$loggingOut = isset ( $_POST['logout'] ); -if ( $loggingOut ){ - $admin->logout(); -} - -if (!$admin->isLoggedIn() ) { - include_once "views/admin/login-form-html.php"; -} diff --git a/coursework-blog/step-11/controllers/admin/users.php b/coursework-blog/step-11/controllers/admin/users.php deleted file mode 100644 index 29516cf1844145610a682e807488ac0b969148a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/controllers/admin/users.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php -include_once "models/Table.class.php"; -include_once "models/Admin_Table.class.php"; - -$createNewAdmin = isset( $_POST['new-admin'] ); - -if( $createNewAdmin ) { - - $newEmail = $_POST['email']; - $newPassword = $_POST['password']; - $adminTable = new Admin_Table($db); - - try { - $adminTable->create( $newEmail, $newPassword ); - $adminFormMessage = "New user created"; - } catch ( Exception $e ) { - $adminFormMessage = $e->getMessage(); - } -} - -include_once "views/admin/new-admin-form-html.php"; diff --git a/coursework-blog/step-11/controllers/blog.php b/coursework-blog/step-11/controllers/blog.php deleted file mode 100644 index c675c8fc0f6da2223d57892b16396ae05a5001cd..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/controllers/blog.php +++ /dev/null @@ -1,17 +0,0 @@ -<? -include_once "models/Table.class.php"; -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-11/coursework-blog.sql b/coursework-blog/step-11/coursework-blog.sql deleted file mode 100644 index d9006b2c318c93f769f3be69fa408e58f73731f7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/coursework-blog.sql +++ /dev/null @@ -1,16 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) - --- this will create a table for admin users -CREATE TABLE admin ( - admin_id INT NOT NULL AUTO_INCREMENT, - email TEXT, - password VARCHAR( 32 ), - PRIMARY KEY ( admin_id ) -) diff --git a/coursework-blog/step-11/css/blog.css b/coursework-blog/step-11/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-11/index.php b/coursework-blog/step-11/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-11/models/Admin_Table.class.php b/coursework-blog/step-11/models/Admin_Table.class.php deleted file mode 100644 index 7c873c4f4c9deb9064b64c320c8c690505b64d7b..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/models/Admin_Table.class.php +++ /dev/null @@ -1,39 +0,0 @@ -<? - -class Admin_Table extends Table { - - public function create ( $email, $password ) { - $this->checkEmail( $email ); - $sql = "INSERT INTO admin ( email, password ) - VALUES( ?, SHA1(?) )"; - $data= array( $email, $password ); - $this->makeStatement( $sql, $data ); - } - - private function checkEmail ($email) { - $sql = "SELECT email FROM admin WHERE email = ?"; - $data = array( $email ); - $this->makeStatement( $sql, $data ); - $statement = $this->makeStatement( $sql, $data ); - if ( $statement->rowCount() === 1 ) { - $e = new Exception("Error: '$email' already used!"); - throw $e; - } - } - - public function checkCredentials ( $email, $password ){ - $sql = "SELECT email FROM admin - WHERE email = ? AND password = SHA1(?)"; - $data = array($email, $password); - $statement = $this->makeStatement( $sql, $data ); - if ( $statement->rowCount() === 1 ) { - $out = true; - } else { - $loginProblem = new Exception( "login failed!" ); - throw $loginProblem; - } - return $out; - } - - -} diff --git a/coursework-blog/step-11/models/Admin_User.class.php b/coursework-blog/step-11/models/Admin_User.class.php deleted file mode 100644 index a6c2ba8958d64f452360e2c34601240f9fce1978..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/models/Admin_User.class.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -class Admin_User { - public function __construct(){ - session_start(); - } - - public function isLoggedIn(){ - $sessionIsSet = isset( $_SESSION['logged_in'] ); - if ( $sessionIsSet ) { - $out = $_SESSION['logged_in']; - } else { - $out = false; - } - return $out; - } - - public function login () { - $_SESSION['logged_in'] = true; - } - - public function logout () { - $_SESSION['logged_in'] = false; - } - -} diff --git a/coursework-blog/step-11/models/Blog_Entry_Table.class.php b/coursework-blog/step-11/models/Blog_Entry_Table.class.php deleted file mode 100644 index 9a6c81a1ecb26e5d5f7e420233735eea307fd271..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php -class Blog_Entry_Table extends Table { - - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) VALUES ( ?, ?)"; - $formData = array( $title, $entry ); - $entryStatement = $this->makeStatement( $entrySQL, $formData ); - return $this->db->lastInsertId(); - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function updateEntry ( $id, $title, $entry) { - $sql = "UPDATE blog_entry - SET title = ?, - entry_text = ? - WHERE entry_id = ?"; - $data = array( $title, $entry, $id ); - $statement = $this->makeStatement( $sql, $data) ; - return $statement; - } - - public function deleteEntry ( $id ) { - $sql = "DELETE FROM blog_entry WHERE entry_id = ?"; - $data = array( $id ); - $statement = $this->makeStatement( $sql, $data ); - } - -} - -?> diff --git a/coursework-blog/step-11/models/Table.class.php b/coursework-blog/step-11/models/Table.class.php deleted file mode 100644 index 0f5eaf1cd18b5e778762ae34c234a716c7f5f0b4..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/models/Table.class.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php -class Table { - protected $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} diff --git a/coursework-blog/step-11/views/admin/admin-navigation.php b/coursework-blog/step-11/views/admin/admin-navigation.php deleted file mode 100644 index 05a639ed7217f7d8aff2dd315526441cc5f180fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/admin/admin-navigation.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> - <a href='admin.php?page=users'>Create admin user</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-11/views/admin/editor-html.php b/coursework-blog/step-11/views/admin/editor-html.php deleted file mode 100644 index e614941c7cfbf37d4cf009076dcf31cc2c3eaffb..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/admin/editor-html.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <input type='hidden' name='id' value='$entryData->entry_id' /> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' value='$entryData->title' required /> - - <label>Entry</label> - <textarea name='entry'>$entryData->entry_text</textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='delete' /> - <input type='submit' name='action' value='save' /> - <p id='editor-message'>$entryData->message</p> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-11/views/admin/entries-html.php b/coursework-blog/step-11/views/admin/entries-html.php deleted file mode 100644 index 2097a76b3afa1ec464ca5dccfc984d5ad63cfafe..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/admin/entries-html.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -if ( isset( $allEntries ) === false ) { -trigger_error('views/admin/entries-html.php needs $allEntries'); -} - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-11/views/admin/login-form-html.php b/coursework-blog/step-11/views/admin/login-form-html.php deleted file mode 100644 index 72af92a4f87a0824bddd2d048673ff0babc973a9..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/admin/login-form-html.php +++ /dev/null @@ -1,10 +0,0 @@ -<? -$out = " <form method='post' action='admin.php'> - <p>Login to access admin area</p> - <label>e-mail</label><input type='email' name='email' required /> - <label>password</label> - <input type='password' name='password' required /> - <input type='submit' value='login' name='log-in' /> -</form>"; - -echo $out; diff --git a/coursework-blog/step-11/views/admin/logout-form-html.php b/coursework-blog/step-11/views/admin/logout-form-html.php deleted file mode 100644 index 92192f1781ce25735855b375f9021c168105f2ed..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/admin/logout-form-html.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -<form method='post' action='admin.php'> - <label>logged in as administrator</label> - <input type='submit' value='log out' name='logout' /> -</form>"; - -echo $out; diff --git a/coursework-blog/step-11/views/admin/new-admin-form-html.php b/coursework-blog/step-11/views/admin/new-admin-form-html.php deleted file mode 100644 index ca35f9f29e2bce62c2b965d123bc0cb545e7836e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/admin/new-admin-form-html.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php -if( isset($adminFormMessage) === false ) { - $adminFormMessage = ""; -} - -$out = "<form method='post' action='admin.php?page=users'> - <fieldset> - <legend>Create new admin user</legend> - <label>e-mail</label> - <input type='email' name='email' required/> - <label>password</label> - <input type='password' name='password' required/> - <input type='submit' value='create user' name='new-admin'/> - </fieldset> - <p id='admin-form-message'>$adminFormMessage</p> -</form>"; - -echo $out; - - diff --git a/coursework-blog/step-11/views/entry-html.php b/coursework-blog/step-11/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-11/views/footer.php b/coursework-blog/step-11/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-11/views/header.php b/coursework-blog/step-11/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-11/views/list-entries-html.php b/coursework-blog/step-11/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-11/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-2/admin.php b/coursework-blog/step-2/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-2/controllers/admin/editor.php b/coursework-blog/step-2/controllers/admin/editor.php deleted file mode 100644 index a4eb8bf5696308ad16e010c8b5e64af3140fe6fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/controllers/admin/editor.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //was "save" button clicked - $insertNewEntry = ( $buttonClicked === 'save' ); - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } -} - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-2/controllers/admin/entries.php b/coursework-blog/step-2/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-2/coursework-blog.sql b/coursework-blog/step-2/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-2/css/blog.css b/coursework-blog/step-2/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-2/models/Blog_Entry_Table.class.php b/coursework-blog/step-2/models/Blog_Entry_Table.class.php deleted file mode 100644 index 6467c9fc8c80b6f8f643ff16186585a1ece0d7be..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - - public function getAllEntries () { - $entrySQL = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->db->prepare( $entrySQL ); - try{ - $statement->execute(); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - return $statement; - } - - -} diff --git a/coursework-blog/step-2/views/admin/admin-navigation.php b/coursework-blog/step-2/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-2/views/admin/editor-html.php b/coursework-blog/step-2/views/admin/editor-html.php deleted file mode 100644 index 71476759c7e9d090983c3fa57665586fecca05bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/views/admin/editor-html.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' /> - - <label>Entry</label> - <textarea name='entry'></textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-2/views/admin/entries-html.php b/coursework-blog/step-2/views/admin/entries-html.php deleted file mode 100644 index 681402413fa04860c8f8e76845f91a70d05e563a..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/views/admin/entries-html.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-2/views/footer.php b/coursework-blog/step-2/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-2/views/header.php b/coursework-blog/step-2/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-2/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-3/admin.php b/coursework-blog/step-3/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-3/controllers/admin/editor.php b/coursework-blog/step-3/controllers/admin/editor.php deleted file mode 100644 index a4eb8bf5696308ad16e010c8b5e64af3140fe6fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/controllers/admin/editor.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //was "save" button clicked - $insertNewEntry = ( $buttonClicked === 'save' ); - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } -} - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-3/controllers/admin/entries.php b/coursework-blog/step-3/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-3/controllers/blog.php b/coursework-blog/step-3/controllers/blog.php deleted file mode 100644 index 94444e527f0192328b7d11ad0de9309cbe54f3a3..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/controllers/blog.php +++ /dev/null @@ -1,8 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; - -?> diff --git a/coursework-blog/step-3/coursework-blog.sql b/coursework-blog/step-3/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-3/css/blog.css b/coursework-blog/step-3/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-3/index.php b/coursework-blog/step-3/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-3/models/Blog_Entry_Table.class.php b/coursework-blog/step-3/models/Blog_Entry_Table.class.php deleted file mode 100644 index 4d652710d319f9d151efa0242d9432022ba9ad3f..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - - public function getAllEntries () { - $entrySQL = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->db->prepare( $entrySQL ); - try{ - $statement->execute(); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - return $statement; - } - - -} - -?> diff --git a/coursework-blog/step-3/views/admin/admin-navigation.php b/coursework-blog/step-3/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-3/views/admin/editor-html.php b/coursework-blog/step-3/views/admin/editor-html.php deleted file mode 100644 index 71476759c7e9d090983c3fa57665586fecca05bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/views/admin/editor-html.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' /> - - <label>Entry</label> - <textarea name='entry'></textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-3/views/admin/entries-html.php b/coursework-blog/step-3/views/admin/entries-html.php deleted file mode 100644 index 681402413fa04860c8f8e76845f91a70d05e563a..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/views/admin/entries-html.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-3/views/footer.php b/coursework-blog/step-3/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-3/views/header.php b/coursework-blog/step-3/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-3/views/list-entries-html.php b/coursework-blog/step-3/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-3/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-4/admin.php b/coursework-blog/step-4/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-4/controllers/admin/editor.php b/coursework-blog/step-4/controllers/admin/editor.php deleted file mode 100644 index a4eb8bf5696308ad16e010c8b5e64af3140fe6fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/controllers/admin/editor.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //was "save" button clicked - $insertNewEntry = ( $buttonClicked === 'save' ); - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } -} - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-4/controllers/admin/entries.php b/coursework-blog/step-4/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-4/controllers/blog.php b/coursework-blog/step-4/controllers/blog.php deleted file mode 100644 index 51823f9e6dc517223b0deb9cc598e62909aa7dcf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/controllers/blog.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-4/coursework-blog.sql b/coursework-blog/step-4/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-4/css/blog.css b/coursework-blog/step-4/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-4/index.php b/coursework-blog/step-4/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-4/models/.Blog_Entry_Table.class.php.swp b/coursework-blog/step-4/models/.Blog_Entry_Table.class.php.swp deleted file mode 100644 index 5d46d90df3e083cf31a60b9e27ef2c81df6e8976..0000000000000000000000000000000000000000 Binary files a/coursework-blog/step-4/models/.Blog_Entry_Table.class.php.swp and /dev/null differ diff --git a/coursework-blog/step-4/models/Blog_Entry_Table.class.php b/coursework-blog/step-4/models/Blog_Entry_Table.class.php deleted file mode 100644 index 51229d1972d0f30eaeaf88486bfa8606ff68bbf0..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,56 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - - public function getAllEntries () { - $entrySQL = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->db->prepare( $entrySQL ); - try{ - $statement->execute(); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $statement = $this->db->prepare( $sql ); - $data = array($id); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - $model = $statement->fetchObject(); - return $model; - } - - -} - -?> diff --git a/coursework-blog/step-4/views/admin/admin-navigation.php b/coursework-blog/step-4/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-4/views/admin/editor-html.php b/coursework-blog/step-4/views/admin/editor-html.php deleted file mode 100644 index 71476759c7e9d090983c3fa57665586fecca05bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/admin/editor-html.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' /> - - <label>Entry</label> - <textarea name='entry'></textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-4/views/admin/entries-html.php b/coursework-blog/step-4/views/admin/entries-html.php deleted file mode 100644 index 681402413fa04860c8f8e76845f91a70d05e563a..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/admin/entries-html.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-4/views/entry-html.php b/coursework-blog/step-4/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-4/views/footer.php b/coursework-blog/step-4/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-4/views/header.php b/coursework-blog/step-4/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-4/views/list-entries-html.php b/coursework-blog/step-4/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-4/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-5/admin.php b/coursework-blog/step-5/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-5/controllers/admin/editor.php b/coursework-blog/step-5/controllers/admin/editor.php deleted file mode 100644 index a4eb8bf5696308ad16e010c8b5e64af3140fe6fa..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/controllers/admin/editor.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //was "save" button clicked - $insertNewEntry = ( $buttonClicked === 'save' ); - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } -} - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-5/controllers/admin/entries.php b/coursework-blog/step-5/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-5/controllers/blog.php b/coursework-blog/step-5/controllers/blog.php deleted file mode 100644 index 51823f9e6dc517223b0deb9cc598e62909aa7dcf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/controllers/blog.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-5/coursework-blog.sql b/coursework-blog/step-5/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-5/css/blog.css b/coursework-blog/step-5/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-5/index.php b/coursework-blog/step-5/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-5/models/Blog_Entry_Table.class.php b/coursework-blog/step-5/models/Blog_Entry_Table.class.php deleted file mode 100644 index 2063813168d498ca4037f4ad16ad0ffa1aafc8d5..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} - -?> diff --git a/coursework-blog/step-5/views/admin/admin-navigation.php b/coursework-blog/step-5/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-5/views/admin/editor-html.php b/coursework-blog/step-5/views/admin/editor-html.php deleted file mode 100644 index 71476759c7e9d090983c3fa57665586fecca05bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/admin/editor-html.php +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' /> - - <label>Entry</label> - <textarea name='entry'></textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-5/views/admin/entries-html.php b/coursework-blog/step-5/views/admin/entries-html.php deleted file mode 100644 index 681402413fa04860c8f8e76845f91a70d05e563a..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/admin/entries-html.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-5/views/entry-html.php b/coursework-blog/step-5/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-5/views/footer.php b/coursework-blog/step-5/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-5/views/header.php b/coursework-blog/step-5/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-5/views/list-entries-html.php b/coursework-blog/step-5/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-5/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-6/admin.php b/coursework-blog/step-6/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-6/controllers/admin/editor.php b/coursework-blog/step-6/controllers/admin/editor.php deleted file mode 100644 index 4effa65124082aece3b8bc1b4b4f3111052195ab..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/controllers/admin/editor.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //was "save" button clicked - $insertNewEntry = ( $buttonClicked === 'save' ); - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } -} - -$entryRequested = isset( $_GET['id'] ); -if ( $entryRequested ) { - $id = $_GET['id']; - $entryData = $entryTable->getEntry( $id ); - $entryData->entry_id = $id; -// $entryData->message = ""; -} else { - $entryData = new StdClass(); - $entryData->entry_id = 0; - $entryData->title = ""; - $entryData->entry_text = ""; -// $entryData->message = ""; -} - - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-6/controllers/admin/entries.php b/coursework-blog/step-6/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-6/controllers/blog.php b/coursework-blog/step-6/controllers/blog.php deleted file mode 100644 index 51823f9e6dc517223b0deb9cc598e62909aa7dcf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/controllers/blog.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-6/coursework-blog.sql b/coursework-blog/step-6/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-6/css/blog.css b/coursework-blog/step-6/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-6/index.php b/coursework-blog/step-6/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-6/models/Blog_Entry_Table.class.php b/coursework-blog/step-6/models/Blog_Entry_Table.class.php deleted file mode 100644 index 2063813168d498ca4037f4ad16ad0ffa1aafc8d5..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} - -?> diff --git a/coursework-blog/step-6/views/admin/admin-navigation.php b/coursework-blog/step-6/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-6/views/admin/editor-html.php b/coursework-blog/step-6/views/admin/editor-html.php deleted file mode 100644 index bf86ba2747d1df2ea2e63ef21412315e0f2d8a2a..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/admin/editor-html.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <input type='hidden' name='id' value='$entryData->entry_id' /> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' value='$entryData->title' required /> - - <label>Entry</label> - <textarea name='entry'>$entryData->entry_text</textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-6/views/admin/entries-html.php b/coursework-blog/step-6/views/admin/entries-html.php deleted file mode 100644 index 2097a76b3afa1ec464ca5dccfc984d5ad63cfafe..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/admin/entries-html.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -if ( isset( $allEntries ) === false ) { -trigger_error('views/admin/entries-html.php needs $allEntries'); -} - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-6/views/entry-html.php b/coursework-blog/step-6/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-6/views/footer.php b/coursework-blog/step-6/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-6/views/header.php b/coursework-blog/step-6/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-6/views/list-entries-html.php b/coursework-blog/step-6/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-6/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-7/admin.php b/coursework-blog/step-7/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-7/controllers/admin/editor.php b/coursework-blog/step-7/controllers/admin/editor.php deleted file mode 100644 index 7040909507ed50e23a3d502a8dd86c16abb75b2c..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/controllers/admin/editor.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - //which button was clicked? - $insertNewEntry = ( $buttonClicked === 'save' ); - $deleteEntry = ($buttonClicked === 'delete'); - $id = $_POST['id']; - - if ( $insertNewEntry ) { - $title = $_POST['title']; - $entry = $_POST['entry']; - //save the new entry - $entryTable->saveEntry( $title, $entry ); - } else if ( $deleteEntry ) { - $entryTable->deleteEntry( $id ); - } -} - -$entryRequested = isset( $_GET['id'] ); -if ( $entryRequested ) { - $id = $_GET['id']; - $entryData = $entryTable->getEntry( $id ); - $entryData->entry_id = $id; -// $entryData->message = ""; -} else { - $entryData = new StdClass(); - $entryData->entry_id = 0; - $entryData->title = ""; - $entryData->entry_text = ""; -// $entryData->message = ""; -} - - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-7/controllers/admin/entries.php b/coursework-blog/step-7/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-7/controllers/blog.php b/coursework-blog/step-7/controllers/blog.php deleted file mode 100644 index 51823f9e6dc517223b0deb9cc598e62909aa7dcf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/controllers/blog.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-7/coursework-blog.sql b/coursework-blog/step-7/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-7/css/blog.css b/coursework-blog/step-7/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-7/index.php b/coursework-blog/step-7/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-7/models/Blog_Entry_Table.class.php b/coursework-blog/step-7/models/Blog_Entry_Table.class.php deleted file mode 100644 index d301843aa8f058233a889d1281795610db649b3c..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,59 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) - VALUES ( ?, ?)"; - $entryStatement = $this->db->prepare( $entrySQL ); - $formData = array( $title, $entry ); - try{ - $entryStatement->execute( $formData ); - } catch (Exception $e){ - $msg = "<p>You tried to run this sql: $entrySQL<p> - <p>Exception: $e</p>"; - trigger_error($msg); - } - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function deleteEntry ( $id ) { - $sql = "DELETE FROM blog_entry WHERE entry_id = ?"; - $data = array( $id ); - $statement = $this->makeStatement( $sql, $data ); - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} - -?> diff --git a/coursework-blog/step-7/views/admin/admin-navigation.php b/coursework-blog/step-7/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-7/views/admin/editor-html.php b/coursework-blog/step-7/views/admin/editor-html.php deleted file mode 100644 index bf7c29569670b85da7ce8d0a491aa3fcc611e216..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/admin/editor-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <input type='hidden' name='id' value='$entryData->entry_id' /> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' value='$entryData->title' required /> - - <label>Entry</label> - <textarea name='entry'>$entryData->entry_text</textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='delete' /> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-7/views/admin/entries-html.php b/coursework-blog/step-7/views/admin/entries-html.php deleted file mode 100644 index 2097a76b3afa1ec464ca5dccfc984d5ad63cfafe..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/admin/entries-html.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -if ( isset( $allEntries ) === false ) { -trigger_error('views/admin/entries-html.php needs $allEntries'); -} - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-7/views/entry-html.php b/coursework-blog/step-7/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-7/views/footer.php b/coursework-blog/step-7/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-7/views/header.php b/coursework-blog/step-7/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-7/views/list-entries-html.php b/coursework-blog/step-7/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-7/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-8/admin.php b/coursework-blog/step-8/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-8/controllers/admin/editor.php b/coursework-blog/step-8/controllers/admin/editor.php deleted file mode 100644 index c2ebc128c09896adc198982f426a3cdb9a1d24a6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/controllers/admin/editor.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - $id = $_POST['id']; - $save = ($buttonClicked === 'save'); - $insertNewEntry = ( $save and $id === '0' ); - $updateEntry = ( $save and $insertNewEntry === false ); - $deleteEntry = ($buttonClicked === 'delete'); - - $title = $_POST['title']; - $entry = $_POST['entry']; - - if ( $insertNewEntry ) { - $entryTable->saveEntry( $title, $entry ); - } else if ( $updateEntry ){ - $entryTable->updateEntry( $id, $title, $entry ); - $savedEntryId = $id; - } else if ( $deleteEntry ) { - $entryTable->deleteEntry( $id ); - } -} - -$entryRequested = isset( $_GET['id'] ); -if ( $entryRequested ) { - $id = $_GET['id']; - $entryData = $entryTable->getEntry( $id ); - $entryData->entry_id = $id; -// $entryData->message = ""; -} else { - $entryData = new StdClass(); - $entryData->entry_id = 0; - $entryData->title = ""; - $entryData->entry_text = ""; -// $entryData->message = ""; -} - - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-8/controllers/admin/entries.php b/coursework-blog/step-8/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-8/controllers/blog.php b/coursework-blog/step-8/controllers/blog.php deleted file mode 100644 index 51823f9e6dc517223b0deb9cc598e62909aa7dcf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/controllers/blog.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-8/coursework-blog.sql b/coursework-blog/step-8/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-8/css/blog.css b/coursework-blog/step-8/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-8/index.php b/coursework-blog/step-8/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-8/models/Blog_Entry_Table.class.php b/coursework-blog/step-8/models/Blog_Entry_Table.class.php deleted file mode 100644 index d5bfccef26f5cf4d16f311f15bf1e37a0d1fbd48..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) VALUES ( ?, ?)"; - $formData = array( $title, $entry ); - $entryStatement = $this->makeStatement( $entrySQL, $formData ); - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function updateEntry ( $id, $title, $entry) { - $sql = "UPDATE blog_entry - SET title = ?, - entry_text = ? - WHERE entry_id = ?"; - $data = array( $title, $entry, $id ); - $statement = $this->makeStatement( $sql, $data) ; - return $statement; - } - - public function deleteEntry ( $id ) { - $sql = "DELETE FROM blog_entry WHERE entry_id = ?"; - $data = array( $id ); - $statement = $this->makeStatement( $sql, $data ); - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} - -?> diff --git a/coursework-blog/step-8/views/admin/admin-navigation.php b/coursework-blog/step-8/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-8/views/admin/editor-html.php b/coursework-blog/step-8/views/admin/editor-html.php deleted file mode 100644 index bf7c29569670b85da7ce8d0a491aa3fcc611e216..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/admin/editor-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <input type='hidden' name='id' value='$entryData->entry_id' /> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' value='$entryData->title' required /> - - <label>Entry</label> - <textarea name='entry'>$entryData->entry_text</textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='delete' /> - <input type='submit' name='action' value='save' /> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-8/views/admin/entries-html.php b/coursework-blog/step-8/views/admin/entries-html.php deleted file mode 100644 index 2097a76b3afa1ec464ca5dccfc984d5ad63cfafe..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/admin/entries-html.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -if ( isset( $allEntries ) === false ) { -trigger_error('views/admin/entries-html.php needs $allEntries'); -} - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-8/views/entry-html.php b/coursework-blog/step-8/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-8/views/footer.php b/coursework-blog/step-8/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-8/views/header.php b/coursework-blog/step-8/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-8/views/list-entries-html.php b/coursework-blog/step-8/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-8/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/coursework-blog/step-9/admin.php b/coursework-blog/step-9/admin.php deleted file mode 100644 index 91f6afddc026b5755a13e17b0c75368c563d23bf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/admin.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; - -include_once "views/header.php"; -include_once "views/admin/admin-navigation.php"; - -$navigation = isset( $_GET['page'] ); -if ( $navigation ) { - //prepare to load corresponding controller - $contrl = $_GET['page']; -} else { - //or prepare to load default controller - $contrl = "entries"; -} -//load the controller -include_once "controllers/admin/$contrl.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-9/controllers/admin/editor.php b/coursework-blog/step-9/controllers/admin/editor.php deleted file mode 100644 index 92618e601d940e31ea4dad6cbbcf5a174f1dbb43..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/controllers/admin/editor.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - -//was editor form submitted? -$editorSubmitted = isset( $_POST['action'] ); -if ( $editorSubmitted ) { - $buttonClicked = $_POST['action']; - $id = $_POST['id']; - $save = ($buttonClicked === 'save'); - $insertNewEntry = ( $save and $id === '0' ); - $updateEntry = ( $save and $insertNewEntry === false ); - $deleteEntry = ($buttonClicked === 'delete'); - - $title = $_POST['title']; - $entry = $_POST['entry']; - - if ( $insertNewEntry ) { - $savedEntryId = $entryTable->saveEntry( $title, $entry ); - } else if ( $updateEntry ){ - $entryTable->updateEntry( $id, $title, $entry ); - $savedEntryId = $id; - } else if ( $deleteEntry ) { - $entryTable->deleteEntry( $id ); - } -} - -$entryRequested = isset( $_GET['id'] ); -$entrySaved = isset( $savedEntryId ); - -if ( $entryRequested ) { - $id = $_GET['id']; - $entryData = $entryTable->getEntry( $id ); - $entryData->entry_id = $id; - $entryData->message = ""; -} else if ( $entrySaved ) { - $entryData = $entryTable->getEntry( $savedEntryId ); - $entryData->message = "Entry was saved"; -} else { - $entryData = new StdClass(); - $entryData->entry_id = 0; - $entryData->title = ""; - $entryData->entry_text = ""; - $entryData->message = ""; -} - - -include_once "views/admin/editor-html.php"; - -?> diff --git a/coursework-blog/step-9/controllers/admin/entries.php b/coursework-blog/step-9/controllers/admin/entries.php deleted file mode 100644 index adf710348c5a3e9b33b3ec2a9a8bb193c7e9fad6..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/controllers/admin/entries.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); -$allEntries = $entryTable->getAllEntries(); - -include_once "views/admin/entries-html.php"; - - -?> diff --git a/coursework-blog/step-9/controllers/blog.php b/coursework-blog/step-9/controllers/blog.php deleted file mode 100644 index 51823f9e6dc517223b0deb9cc598e62909aa7dcf..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/controllers/blog.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -include_once "models/Blog_Entry_Table.class.php"; -$entryTable = new Blog_Entry_Table( $db ); - - -$entryClicked = isset( $_GET['id'] ); -if ($entryClicked ) { - $entryId = $_GET['id']; - $entryData = $entryTable->getEntry( $entryId ); -// print_r($entryData); - include_once "views/entry-html.php"; -} else { - $entries = $entryTable->getallentries(); - include_once "views/list-entries-html.php"; -} -?> diff --git a/coursework-blog/step-9/coursework-blog.sql b/coursework-blog/step-9/coursework-blog.sql deleted file mode 100644 index 61ba3ff71306180219cf21698d4129ce56252898..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/coursework-blog.sql +++ /dev/null @@ -1,8 +0,0 @@ --- this will create a table for blog entries -CREATE TABLE blog_entry ( - entry_id INT NOT NULL AUTO_INCREMENT, - title VARCHAR( 150 ), - entry_text TEXT, - date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY ( entry_id ) -) diff --git a/coursework-blog/step-9/css/blog.css b/coursework-blog/step-9/css/blog.css deleted file mode 100644 index c1b6d0670a8fd4ef1d0b8d9b856a04639d5d583e..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/css/blog.css +++ /dev/null @@ -1,24 +0,0 @@ -/* code listing for blog/css/blog.css */ -form#editor{ - width: 300px; - margin:0px; - padding:0px; -} - -form#editor label, form#editor input[type='text']{ - display:block; -} - -form#editor #editor-buttons{ - border:none; - text-align:right; -} - -form#editor textarea, form#editor input[type='text']{ - width:90%; - margin-bottom:2em; -} - -form#editor textarea{ - height:10em; -} diff --git a/coursework-blog/step-9/index.php b/coursework-blog/step-9/index.php deleted file mode 100644 index d15e46128c23bde74a1f5f5130449f4f805659a7..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -include_once "../../../coursework_blog_config.php"; -$db = new PDO( $dbInfo, $dbUser, $dbPassword ); -$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); - -$title = "PHP/MySQL blog demo"; -$css="css/blog.css"; -$embeddedStyle = ""; -include_once "views/header.php"; - -include_once "controllers/blog.php"; - -include_once "views/footer.php"; - -?> - diff --git a/coursework-blog/step-9/models/Blog_Entry_Table.class.php b/coursework-blog/step-9/models/Blog_Entry_Table.class.php deleted file mode 100644 index 8da1860a2b6930ea30d59e4f142d2f2ecd192849..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/models/Blog_Entry_Table.class.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -class Blog_Entry_Table { - private $db; - - - public function __construct ( $db ) { - $this->db = $db; - } - - public function saveEntry ( $title, $entry ) { - $entrySQL = "INSERT INTO blog_entry ( title, entry_text ) VALUES ( ?, ?)"; - $formData = array( $title, $entry ); - $entryStatement = $this->makeStatement( $entrySQL, $formData ); - return $this->db->lastInsertId(); - } - - public function getAllEntries () { - $sql = "SELECT entry_id, title, SUBSTRING(entry_text, 1, 150) AS intro FROM blog_entry"; - $statement = $this->makeStatement($sql); - return $statement; - } - - - public function getEntry( $id ){ - $sql = "SELECT entry_id, title, entry_text, date_created FROM blog_entry WHERE entry_id = ?"; - $data = array($id); - $statement = $this->makeStatement( $sql, $data); - $model = $statement->fetchObject(); - return $model; - } - - public function updateEntry ( $id, $title, $entry) { - $sql = "UPDATE blog_entry - SET title = ?, - entry_text = ? - WHERE entry_id = ?"; - $data = array( $title, $entry, $id ); - $statement = $this->makeStatement( $sql, $data) ; - return $statement; - } - - public function deleteEntry ( $id ) { - $sql = "DELETE FROM blog_entry WHERE entry_id = ?"; - $data = array( $id ); - $statement = $this->makeStatement( $sql, $data ); - } - - public function makeStatement( $sql, $data = NULL) { - $statement = $this->db->prepare( $sql ); - try{ - $statement->execute( $data ); - } catch (Exception $e) { - $exceptionMessage = "<p>You tried to run this sql: $sql <p> - <p>Exception: $e</p>"; - trigger_error($exceptionMessage); - } - return $statement; - } - -} - -?> diff --git a/coursework-blog/step-9/views/admin/admin-navigation.php b/coursework-blog/step-9/views/admin/admin-navigation.php deleted file mode 100644 index c58b361f5687bc015c0bb084ec1adcfdf87c0c23..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/admin/admin-navigation.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -$out = " -<nav id='admin-navigation'> - <a href='admin.php?page=entries'>All entries</a> - <a href='admin.php?page=editor'>Editor</a> -</nav>"; - -echo $out; - -?> diff --git a/coursework-blog/step-9/views/admin/editor-html.php b/coursework-blog/step-9/views/admin/editor-html.php deleted file mode 100644 index e614941c7cfbf37d4cf009076dcf31cc2c3eaffb..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/admin/editor-html.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -$out = " -<form method='post' action='admin.php?page=editor' id='editor'> - <input type='hidden' name='id' value='$entryData->entry_id' /> - <fieldset> - <legend>New Entry Submission</legend> - <label>Title</label> - <input type='text' name='title' maxlength='150' value='$entryData->title' required /> - - <label>Entry</label> - <textarea name='entry'>$entryData->entry_text</textarea> - - <fieldset id='editor-buttons'> - <input type='submit' name='action' value='delete' /> - <input type='submit' name='action' value='save' /> - <p id='editor-message'>$entryData->message</p> - </fieldset> - </fieldset> -</form> -"; - -echo $out; - -?> diff --git a/coursework-blog/step-9/views/admin/entries-html.php b/coursework-blog/step-9/views/admin/entries-html.php deleted file mode 100644 index 2097a76b3afa1ec464ca5dccfc984d5ad63cfafe..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/admin/entries-html.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -if ( isset( $allEntries ) === false ) { -trigger_error('views/admin/entries-html.php needs $allEntries'); -} - -$entriesAsHTML = "<ul>"; -while ( $entry = $allEntries->fetchObject() ) { - $href = "admin.php?page=editor&id=$entry->entry_id"; - $entriesAsHTML .= "<li><a href='$href'>$entry->title</a></li>"; -} - -$entriesAsHTML .= "</ul>"; -echo $entriesAsHTML; - -?> diff --git a/coursework-blog/step-9/views/entry-html.php b/coursework-blog/step-9/views/entry-html.php deleted file mode 100644 index 44c629f34b48ce2b432a58a5fe9c6b0fd8c83e80..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/entry-html.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php - -//check if required data is available -$entryDataFound = isset( $entryData ); -if ( $entryDataFound === false ) { - trigger_error('views/entry-html.php needs an $entryData object'); -} -//properties available in $entry: entry_id, title, entry_text, date_created - -echo "<article> - <h1>$entryData->title</h1> - <div class='date'>$entryData->date_created</div> - $entryData->entry_text -</article>"; diff --git a/coursework-blog/step-9/views/footer.php b/coursework-blog/step-9/views/footer.php deleted file mode 100644 index e7373f51428a6aa5ef1ffa5d974b7d30d633c526..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/footer.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -$out = " -</body> -</html> -"; - -echo $out; -?> diff --git a/coursework-blog/step-9/views/header.php b/coursework-blog/step-9/views/header.php deleted file mode 100644 index 4c5a94f334184fa5e665e83abf16d0407fc05c98..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/header.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -$out = "<!DOCTYPE html> -<html> - <head> - <title>$title</title> - <meta http-equiv='Content-Type' content='text/html;charset=utf-8' /> - <link rel='stylesheet' type='text/css' href='$css'> - <link rel='stylesheet' type='text/css' href='$embeddedStyle'> - </head>"; - -echo $out; -?> diff --git a/coursework-blog/step-9/views/list-entries-html.php b/coursework-blog/step-9/views/list-entries-html.php deleted file mode 100644 index f568bc89d29cae908caedf77b8d659b17599da94..0000000000000000000000000000000000000000 --- a/coursework-blog/step-9/views/list-entries-html.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -$entriesFound = isset( $entries ); -if ( $entriesFound === false ) { - trigger_error( 'views/list-entries-html.php needs $entries' ); -} - -$entriesHTML = "<ul id='blog-entries'>"; - -while ( $entry = $entries->fetchObject() ) { - $href = "index.php?page=blog&id=$entry->entry_id"; - //create an <li> for each of the entries - $entriesHTML .= "<li> - <h2>$entry->title</h2> - <div>$entry->intro - <p><a href='$href'>Read more</a></p> - </div> - </li>"; -} -$entriesHTML .= "</ul>"; - -echo $entriesHTML; - -?> diff --git a/week-1/test_app/README.txt b/week-1/test_app/README.txt deleted file mode 100644 index f3d37bc56ae68fe15f94b988ddc56315a15dac70..0000000000000000000000000000000000000000 --- a/week-1/test_app/README.txt +++ /dev/null @@ -1,21 +0,0 @@ -********************************* -* A TEST APPLICATION * -********************************* - -Description ------------ -This is a test PHP application. You can upload use it to test your LAMP stack. You can also browse the directory structure to get an idea of how PHP web applications are commonly structured. You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -Upload the application to your web root folder. No further actions needed! - -Configuration Instructions --------------------------- -There is nothing to configure. - - diff --git a/week-1/test_app/includes/functions.php b/week-1/test_app/includes/functions.php deleted file mode 100644 index 74d6c1c1e57be31a318503e9d19160133bab3762..0000000000000000000000000000000000000000 --- a/week-1/test_app/includes/functions.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -# Write some functions here... - -?> - diff --git a/week-1/test_app/index.php b/week-1/test_app/index.php deleted file mode 100755 index 6eada61e92cfa36565a0c88b5d651a5bd1940b67..0000000000000000000000000000000000000000 --- a/week-1/test_app/index.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -// Code to detect whether index.php has been requested without query string -// If no page parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -$content = ''; - -// Switch statement to decide content of page will go here. -// Regardless of which "view" is displayed, the variable $content will -switch ($id) { - case 'home' : - include 'views/home.php'; - break; - case 'menu' : - include 'views/page_2.php'; - break; - default : - include 'views/404.php'; -} -?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <head> - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> - <title>Test Application</title> - </head> - <body> - <ul> - <li><a href="index.php">Home</a></li> - <li><a href="index.php?page=page_2">Page 2</a></li> - </ul> - - <?php - // Display content for requested view. - echo $content; - ?> - - </body> -</html> diff --git a/week-1/test_app/views/404.php b/week-1/test_app/views/404.php deleted file mode 100755 index e6d29ffac0b321b5d7157f42db60a20320ae8713..0000000000000000000000000000000000000000 --- a/week-1/test_app/views/404.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php -$content .= '<h1>Sorry, page can not be found</h1>'; -?> - diff --git a/week-1/test_app/views/home.php b/week-1/test_app/views/home.php deleted file mode 100644 index f811619f4b955f740a2ca1f3843fe5600a4b8de2..0000000000000000000000000000000000000000 --- a/week-1/test_app/views/home.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php -$content .= '<h1>Hello world!</h1>'; -$content .= '<p>If you\'re reading this, it means you have successfully launched the <b>test app</b>.</p>'; -?> \ No newline at end of file diff --git a/week-1/test_app/views/page_2.php b/week-1/test_app/views/page_2.php deleted file mode 100755 index 6a9716b57b102b2e1c3780def4915d838fd37d03..0000000000000000000000000000000000000000 --- a/week-1/test_app/views/page_2.php +++ /dev/null @@ -1,4 +0,0 @@ -<?php -$content = '<h1>Welcome to page 2!</h1>'; -?> - diff --git a/week-12/README.txt b/week-12/README.txt deleted file mode 100644 index db41256a3e53b0db799dee85b6c26f21bf524809..0000000000000000000000000000000000000000 --- a/week-12/README.txt +++ /dev/null @@ -1,27 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -Description ------------ -This is a demo record store application. You can use it to help you complete lab 8. It is You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -+ Check you have a LAMP stack installed with PHP>5 and MySQL>5 -+ Upload the application to your web root folder. -+ Run the record-store.sql file on your database. -+ Run the dummy_data.sql file to insert some data. - -Configuration Instructions --------------------------- -Modify the includes/db_connect.php script with your MySQL database credentials. - -Live Demo ---------- -A demo version of this app is deployed at the following URL: -http://doc.gold.ac.uk/~sharr003/data-network-web/lab-exercises/week-8/record-store-app/ diff --git a/week-12/includes/db_connect.php b/week-12/includes/db_connect.php deleted file mode 100644 index 53c5fb94ab76b4ae3840501948dfe079b2f35296..0000000000000000000000000000000000000000 --- a/week-12/includes/db_connect.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* Open a new connection to the MySQL server */ - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'recordstoreuser', - 'recordstorepwd', - 'recordstore' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); -} - -?> diff --git a/week-12/index.php b/week-12/index.php deleted file mode 100644 index 153d06ccfb08cca252df1515fe72430772d309fa..0000000000000000000000000000000000000000 --- a/week-12/index.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -// connect to the database -require('includes/db_connect.php'); - -// define a function to sanitise user input (this would ideally be in includes folder) -function clean_input($data) { - $data = trim($data); // strips unnecessary characters from beginning/end - $data = stripslashes($data); // remove backslashes - $data = htmlspecialchars($data); // replace special characters with HTML entities - return $data; -} - -// include the header HTML -include('templates/header.html'); - -// include the navigation HTML -include('templates/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -case 'orders' : - include 'views/orders.php'; - break; -case 'order' : - include 'views/order.php'; - break; -case 'add-record' : - include 'views/add-record.php'; - break; -case 'search' : - include 'views/search.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('templates/footer.html'); - -?> diff --git a/week-12/sql/dummy_data.sql b/week-12/sql/dummy_data.sql deleted file mode 100644 index 7d0580104297aa0ad65f6d70c33601e128b685d4..0000000000000000000000000000000000000000 --- a/week-12/sql/dummy_data.sql +++ /dev/null @@ -1,67 +0,0 @@ -/* Note that, because foreign key values are being -inserted manually, tables must be recreated before running -this code in order to reset AUTO_INCREMENT */ - -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs'), -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (ean, title, artist_id, genre, year, price) -VALUES -('00562056', 'Soul Rebel', 1, 'Reggae', 1970, 25.99 ), -('50264967', 'Catch A Fire', 1, 'Reggae', 1973, 25.99 ), -('00748396', 'Natty Dread', 1, 'Reggae', 1974, 20.99 ), -('00495739', 'Babylon By Bus', 1, 'Reggae', 1978, 24.99 ), -('00738432', 'Legalize It', 2, 'Reggae', 1976, 22.99 ), -('50847583', 'Bush Doctor', 2, 'Reggae', 1978, 20.99 ), -('30748743', 'Marcus Garvey', 3, 'Reggae', 1975, 24.99 ), -('50856384', 'Night Nurse', 5, 'Reggae', 1982, 17.99 ), -('50264972', 'Mr Issacs', 5, 'Reggae', 1982, 9.99 ), -('00649573', 'Black and Dekker', 6, 'Reggae', 1980, 19.99 ), -('00625485', 'Sunday Coming', 4, 'Reggae', 1970, 15.99 ); - -INSERT INTO customer (id, first_name, last_name, email_address, address_1, address_2, postcode) -VALUES -(NULL, 'John', 'Smith', 'john@smith.com', '1 Fake Street', 'London', 'SE3 5RD'), -(NULL, 'Sukie', 'Bapswent', 's.baps@gmail.com', '64 The Terrace', 'Whitby', 'YO65 3TR'), -(NULL, 'John', 'Thumb', 'jthumb@gmail.com', '25 Fantasy Grove', 'Brighton', 'BR2 6LV'); - -INSERT INTO transaction (id, customer_id, delivery_method, dt_date) -VALUES -(NULL, 1, 2, '2015-07-01 14:34:58'), -(NULL, 1, 2, '2015-04-01 11:22:35'), -(NULL, 3, 1, '2015-04-01 19:47:03'), -(NULL, 2, 1, '2015-05-11 22:01:19'); - -INSERT INTO orderline (id, transaction_id, record_ean, quantity) -VALUES -(NULL, 1, '00562056', 1), -(NULL, 1, '00495739', 1), -(NULL, 2, '00649573', 2), -(NULL, 2, '00495739', 1), -(NULL, 3, '00738432', 2), -(NULL, 3, '00562056', 1), -(NULL, 3, '50856384', 3), -(NULL, 3, '00495739', 1), -(NULL, 4, '00625485', 1), -(NULL, 4, '00562056', 2); - -INSERT INTO inventory (stock, record_ean) -VALUES -(25, '00562056'), -(18, '50264967'), -(15, '00748396'), -(20, '00495739'), -(10, '00738432'), -(7, '50847583'), -(3, '30748743'), -(34, '50856384'), -(22, '50264972'), -(15, '00649573'), -(12, '00625485'); diff --git a/week-12/sql/practice_queries.sql b/week-12/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-12/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-12/sql/record-store.sql b/week-12/sql/record-store.sql deleted file mode 100644 index 971708804df2996481388ffecf24895dd9047bb8..0000000000000000000000000000000000000000 --- a/week-12/sql/record-store.sql +++ /dev/null @@ -1,71 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS inventory, orderline, transaction, customer, record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -) ENGINE=InnoDB; - -/* Define table for storing records (products) */ -CREATE TABLE record ( - ean CHAR(8) NOT NULL, - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price DECIMAL(10, 2) unsigned NOT NULL, - PRIMARY KEY (ean), - FOREIGN KEY (artist_id) - REFERENCES artist (id) - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address_1 VARCHAR(50) NOT NULL, - address_2 VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - dt_date DATETIME, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -) ENGINE=InnoDB; - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - record_ean CHAR(8), - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (record_ean) - REFERENCES record(ean) - ON UPDATE CASCADE - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for inventory */ -CREATE TABLE inventory ( - stock INT unsigned DEFAULT 0, - record_ean CHAR(8), - PRIMARY KEY (stock, record_ean), - FOREIGN KEY (record_ean) - REFERENCES record (ean) -) ENGINE=InnoDB; diff --git a/week-12/sql/recordstore-dump.sql b/week-12/sql/recordstore-dump.sql deleted file mode 100644 index f9dc7c87b19c8a9d855abce62050f3091f0d5ee5..0000000000000000000000000000000000000000 --- a/week-12/sql/recordstore-dump.sql +++ /dev/null @@ -1,196 +0,0 @@ --- MySQL dump 10.13 Distrib 5.6.26, for Linux (x86_64) --- --- Host: localhost Database: recordstore --- ------------------------------------------------------ --- Server version 5.6.26 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `artist` --- - -DROP TABLE IF EXISTS `artist`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `artist` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) DEFAULT NULL, - `last_name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `artist` --- - -LOCK TABLES `artist` WRITE; -/*!40000 ALTER TABLE `artist` DISABLE KEYS */; -INSERT INTO `artist` VALUES (1,'Bob','Marley'),(2,'Peter','Tosh'),(3,'Burning','Spear'),(4,'Alton','Ellis'),(5,'Gregory','Issacs'),(6,'Desmond','Dekker'); -/*!40000 ALTER TABLE `artist` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customer` --- - -DROP TABLE IF EXISTS `customer`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `customer` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) NOT NULL, - `last_name` varchar(50) NOT NULL, - `email_address` varchar(50) NOT NULL, - `address_1` varchar(50) NOT NULL, - `address_2` varchar(50) DEFAULT NULL, - `postcode` varchar(10) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customer` --- - -LOCK TABLES `customer` WRITE; -/*!40000 ALTER TABLE `customer` DISABLE KEYS */; -INSERT INTO `customer` VALUES (1,'John','Smith','john@smith.com','1 Fake Street','London','SE3 5RD'),(2,'Sukie','Bapswent','s.baps@gmail.com','64 The Terrace','Whitby','YO65 3TR'),(3,'John','Thumb','jthumb@gmail.com','25 Fantasy Grove','Brighton','BR2 6LV'); -/*!40000 ALTER TABLE `customer` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `inventory` --- - -DROP TABLE IF EXISTS `inventory`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `inventory` ( - `stock` int(10) unsigned NOT NULL DEFAULT '0', - `record_ean` char(8) NOT NULL DEFAULT '', - PRIMARY KEY (`stock`,`record_ean`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `inventory` --- - -LOCK TABLES `inventory` WRITE; -/*!40000 ALTER TABLE `inventory` DISABLE KEYS */; -INSERT INTO `inventory` VALUES (20,'00495739'),(25,'00562056'),(12,'00625485'),(15,'00649573'),(10,'00738432'),(15,'00748396'),(1,'1010010'),(5,'12121212'),(2,'131313'),(3,'30748743'),(18,'50264967'),(22,'50264972'),(7,'50847583'),(34,'50856384'); -/*!40000 ALTER TABLE `inventory` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `orderline` --- - -DROP TABLE IF EXISTS `orderline`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderline` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `transaction_id` int(11) DEFAULT NULL, - `record_ean` char(8) DEFAULT NULL, - `quantity` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `transaction_id` (`transaction_id`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `orderline_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `transaction` (`id`), - CONSTRAINT `orderline_ibfk_2` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `orderline` --- - -LOCK TABLES `orderline` WRITE; -/*!40000 ALTER TABLE `orderline` DISABLE KEYS */; -INSERT INTO `orderline` VALUES (1,1,'00562056',1),(2,1,'00495739',1),(3,2,'00649573',2),(4,2,'00495739',1),(5,3,'00738432',2),(6,3,'00562056',1),(7,3,'50856384',3),(8,3,'00495739',1),(9,4,'00625485',1),(10,4,'00562056',2); -/*!40000 ALTER TABLE `orderline` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `record` --- - -DROP TABLE IF EXISTS `record`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `record` ( - `ean` char(8) NOT NULL, - `title` varchar(50) NOT NULL, - `artist_id` int(11) DEFAULT NULL, - `genre` varchar(50) DEFAULT NULL, - `year` year(4) DEFAULT NULL, - `price` decimal(10,2) unsigned NOT NULL, - `image` varchar(64) DEFAULT NULL, - PRIMARY KEY (`ean`), - KEY `artist_id` (`artist_id`), - CONSTRAINT `record_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `record` --- - -LOCK TABLES `record` WRITE; -/*!40000 ALTER TABLE `record` DISABLE KEYS */; -INSERT INTO `record` VALUES ('00495739','Babylon By Bus',1,'Reggae',1978,24.99,NULL),('00562056','Soul Rebel',1,'Reggae',1970,25.99,NULL),('00625485','Sunday Coming',4,'Reggae',1970,15.99,NULL),('00649573','Black and Dekker',6,'Reggae',1980,19.99,NULL),('00738432','Legalize It',2,'Reggae',1976,22.99,NULL),('00748396','Natty Dread',1,'Reggae',1974,20.99,NULL),('1010010','A test',6,'testy',2000,20.00,'uploads/2009-a32-08-05-adorno-b.jpg'),('12121212','Dek Stop',6,'2 tone',1978,10.99,NULL),('131313','blahblah',4,'hip hop',2011,9.99,NULL),('30748743','Marcus Garvey',3,'Reggae',1975,24.99,NULL),('50264967','Catch A Fire',1,'Reggae',1973,25.99,NULL),('50264972','Mr Issacs',5,'Reggae',1982,9.99,NULL),('50847583','Bush Doctor',2,'Reggae',1978,20.99,NULL),('50856384','Night Nurse',5,'Reggae',1982,17.99,NULL); -/*!40000 ALTER TABLE `record` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `transaction` --- - -DROP TABLE IF EXISTS `transaction`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transaction` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `customer_id` int(11) NOT NULL, - `delivery_method` int(11) DEFAULT NULL, - `dt_date` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `customer_id` (`customer_id`), - CONSTRAINT `transaction_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `transaction` --- - -LOCK TABLES `transaction` WRITE; -/*!40000 ALTER TABLE `transaction` DISABLE KEYS */; -INSERT INTO `transaction` VALUES (1,1,2,'2015-07-01 14:34:58'),(2,1,2,'2015-04-01 11:22:35'),(3,3,1,'2015-04-01 19:47:03'),(4,2,1,'2015-05-11 22:01:19'); -/*!40000 ALTER TABLE `transaction` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2016-01-19 18:54:19 diff --git a/week-12/templates/footer.html b/week-12/templates/footer.html deleted file mode 100644 index 2ab5c0d1fc7b0e6c12fb00bf177037f64450298c..0000000000000000000000000000000000000000 --- a/week-12/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - </body> -</html> diff --git a/week-12/templates/header.html b/week-12/templates/header.html deleted file mode 100644 index 373b26f6655d85da48d4aa6febcbb98372f0d451..0000000000000000000000000000000000000000 --- a/week-12/templates/header.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Record Store</title> - </head> - <body> \ No newline at end of file diff --git a/week-12/templates/navigation.html b/week-12/templates/navigation.html deleted file mode 100644 index 61de71417efcda78ca52a94fb1ccfa8a47982ded..0000000000000000000000000000000000000000 --- a/week-12/templates/navigation.html +++ /dev/null @@ -1,9 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=orders" title="orders">Orders</a></li> - <li><a href="?page=add-record" title="add record">Add record</a></li> - <li><a href="?page=search" title="search">Search</a></li> - </ul> -</nav> diff --git a/week-12/uploads/2009-a32-08-05-adorno-b.jpg b/week-12/uploads/2009-a32-08-05-adorno-b.jpg deleted file mode 100644 index 4e896284f0a353698a1567dbd60fe9084352102b..0000000000000000000000000000000000000000 Binary files a/week-12/uploads/2009-a32-08-05-adorno-b.jpg and /dev/null differ diff --git a/week-12/uploads/avatar 1.jpg b/week-12/uploads/avatar 1.jpg deleted file mode 100644 index 0f72ed7d3df1b440ca9e8128ce3bf9b495fac37e..0000000000000000000000000000000000000000 Binary files a/week-12/uploads/avatar 1.jpg and /dev/null differ diff --git a/week-12/uploads/avatar 2 06_mask-2 square.jpg b/week-12/uploads/avatar 2 06_mask-2 square.jpg deleted file mode 100644 index b0046e2dc12b34a2a3bc046d4726b2a26602c5bd..0000000000000000000000000000000000000000 Binary files a/week-12/uploads/avatar 2 06_mask-2 square.jpg and /dev/null differ diff --git a/week-12/uploads/je-participe.gif b/week-12/uploads/je-participe.gif deleted file mode 100644 index 91e7b890942debafe2718187d3f0f785b09d25ea..0000000000000000000000000000000000000000 Binary files a/week-12/uploads/je-participe.gif and /dev/null differ diff --git a/week-12/uploads/think of this as a window.jpg b/week-12/uploads/think of this as a window.jpg deleted file mode 100644 index 6974a3771579395769a65c117e46e5887a83f285..0000000000000000000000000000000000000000 Binary files a/week-12/uploads/think of this as a window.jpg and /dev/null differ diff --git a/week-12/views/404.php b/week-12/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-12/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-12/views/add-record-insecure.php b/week-12/views/add-record-insecure.php deleted file mode 100644 index 841a5078b968ebf2b18cb97286ab6e8f9d03bbfc..0000000000000000000000000000000000000000 --- a/week-12/views/add-record-insecure.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -$action = $_SERVER["PHP_SELF"]."?page=add-record"; - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = $_POST["ean"]; - $title = $_POST["title"]; - $artist_id = $_POST["artist_id"]; - $genre = $_POST["genre"]; - $year = $_POST["year"]; - $price = $_POST["price"]; - - // define the insertion query - $sql = "INSERT INTO record (ean, title, artist_id, genre, year, price) - VALUES ('$ean', '$title', '$artist_id', '$genre', '$year', '$price')"; - - // run the query to insert the data - $result = mysqli_query($link, $sql); - - // check if the query went ok - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "Record successfully added to database."; - } -} - -// ------- END form processing code... ------- - -// output the html -echo($content); - -?> diff --git a/week-12/views/add-record.php b/week-12/views/add-record.php deleted file mode 100644 index bf9bf31267211830991b850f197942dd3c317c6c..0000000000000000000000000000000000000000 --- a/week-12/views/add-record.php +++ /dev/null @@ -1,175 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -// -> htmlspecialchars() is used to replace special characters with HTML entities */ -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=add-record"); - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' enctype='multipart/form-data' method='POST'> -<input type='hidden' name='MAX_FILE_SIZE' value='1000000' /> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <fieldset> - <label for='price'>Stock:</label> - <input type='text' name='stock' placeholder='0' /> - </fieldset> -<label>image <input type='file' id='image' name='image' /></label><br /> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = $stock = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = mysqli_real_escape_string($link, clean_input($_POST["ean"])); - $title = mysqli_real_escape_string($link, clean_input($_POST["title"])); - $artist_id = mysqli_real_escape_string($link, clean_input($_POST["artist_id"])); - $genre = mysqli_real_escape_string($link, clean_input($_POST["genre"])); - $year = mysqli_real_escape_string($link, clean_input($_POST["year"])); - $price = mysqli_real_escape_string($link, clean_input($_POST["price"])); - $stock = mysqli_real_escape_string($link, clean_input($_POST["stock"])); - - // handle the image upload - $uploadOk = 1; - - $target_dir = "uploads/"; - - // Check if image file is a actual image or fake image - $check = getimagesize($_FILES["image"]["tmp_name"]); - if($check !== false) { - $uploadOk = 1; - } else { - echo "File is not an image."; - $uploadOk = 0; - } - - // Check file size - if ($_FILES["image"]["size"] > 1000000) { - echo "Sorry, your file is too large."; - $uploadOk = 0; - } - - $target_file = $target_dir . basename($_FILES["image"]["name"]); - $image = $target_file; - - // Check if file already exists - if (file_exists($target_file)) { - echo "Sorry, file already exists."; - $uploadOk = 0; - } - - $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); - - // Allow certain file formats - if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" - && $imageFileType != "gif" ) { - echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; - $uploadOk = 0; - } - - // Check if $uploadOk is set to 0 by an error - if ($uploadOk == 0) { - echo "Sorry, your file was not uploaded."; - - // if everything is ok, try to upload file - } else { - if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { - echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded."; - - - // turn autocommit off - mysqli_autocommit($link, FALSE); - - // start a transaction - mysqli_query($link, 'START TRANSACTION'); - - // define the insertion query to add a new record in record table - $query1 = sprintf("INSERT INTO record (ean, title, artist_id, genre, year, price, image) - VALUES ('%s', '%s', %d, '%s', %d, %f, '%s')", $ean, $title, $artist_id, $genre, $year, $price, $image); - - // define the insertion query to add a new record in inventory table - $query2 = sprintf("INSERT INTO inventory (stock, record_ean) - VALUES (%d, '%s')", $stock, $ean); - - // check if either of the queries failed (returned false) - if (!mysqli_query($link, $query1) or !mysqli_query($link, $query2)) { - echo mysqli_error($link); - mysqli_rollback($link); // if so, rollback transaction - } else { - mysqli_commit($link); // else, commit transaction -// $content .= "Record successfully added to database."; - } - - - } else { - echo "Sorry, there was an error uploading your file."; - } - } - // end of image upload - - - - } - - // ------- END form processing code... ------- - - // output the html - echo($content); - -?> diff --git a/week-12/views/artist.php b/week-12/views/artist.php deleted file mode 100644 index ea371d7e2a7a6057ea88edcd8afe2edd4020a582..0000000000000000000000000000000000000000 --- a/week-12/views/artist.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -// check if id parameter was not set in query string -if (!isset($_GET['id'])) { - - // define $content with suitable message - $content = "<h1>I don't know which artist you're looking for...</h1>"; - -} else { // id was set, so carry on... - - // define $artist_id variable and assign value of id parameter - $artist_id = $_GET['id']; - - // fetch record titles for artist with id matching $artist_id - $sql = "SELECT r.title, r.year, r.price, a.first_name, a.last_name - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - WHERE a.id=".$artist_id." - ORDER BY year ASC"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // define a row counter - $i = 0; - - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - - // do this if we are on first row - if ($i == 0) { - - // initialise $content string, assigning it a page header - $content = "<h1>".$row['first_name']." ".$row['last_name']." Records</h1>"; - // append $content string with table definition - $content .= "<table border='1'><tbody>"; - - } - - // append table rows to $content string - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['year']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "</tr>"; - - // increment the row counter - $i++; - - } - - // append $content string with closing table tags - $content .= "</tbody></table>"; - - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-12/views/home.php b/week-12/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-12/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-12/views/order.php b/week-12/views/order.php deleted file mode 100644 index 0f81c631d898204086a592a060e6341c59a16f20..0000000000000000000000000000000000000000 --- a/week-12/views/order.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price - FROM record r - INNER JOIN orderline ol - ON ol.record_ean=r.ean - WHERE ol.transaction_id=".$order_id; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = $row['quantity'] * $row['price']; - $total = $total + $subtotal; - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-12/views/orders.php b/week-12/views/orders.php deleted file mode 100644 index d1228914e88edccc204d29b7380dabe43fd36aa7..0000000000000000000000000000000000000000 --- a/week-12/views/orders.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "SELECT id, customer_id FROM transaction - ORDER BY customer_id"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) -{ - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>"; - $content .= "<td>".$row['customer_id']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-12/views/record.php b/week-12/views/record.php deleted file mode 100644 index 06ffa5efc4b771330005e5732cf3e63a37b77419..0000000000000000000000000000000000000000 --- a/week-12/views/record.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; -$content .= "<p>You are now viewing all records in the database.</p>"; - -// fetch records as a result set -$sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, r.image, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - ORDER BY r.title, r.price DESC"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "<td><img src='".$row['image']."' style='height: 100px;' /></td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-12/views/search.php b/week-12/views/search.php deleted file mode 100644 index 3f78082fb762e7e6fa725d2cadd58f960a232a1b..0000000000000000000000000000000000000000 --- a/week-12/views/search.php +++ /dev/null @@ -1,90 +0,0 @@ -<? -$content = "<h1>Search</h1>"; - -// define a variable with path to this script which will process form -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=search"); - -// define the search form -$form_html = "<form method='post' action='". $action ."'> - <label for='usersearch'>search the record store</label><br /> - <input type='text' id='usersearch' name='usersearch' /><br /> - <input type='submit' name='submit' value='Submit' /> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - -// $sort = clean_input($_GET['sort']); - $user_search = clean_input($_POST['usersearch']); - $clean_search = str_replace(',',' ',$user_search); - $search_words = explode(' ',$clean_search); - $final_search_words = array(); - if (count($search_words > 0)){ - foreach ($search_words as $word) { - if (!empty($word)) { - $final_search_words[] = $word; - } - } - } - foreach ($final_search_words as $word) { - $where_list[] = "r.title like '%$word%'"; - } - $where_clause = implode(' OR ', $where_list); - -echo "where clause = " . $where_clause."<br />"; - - // Query to get the results - $sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, r.image, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - WHERE $where_clause - ORDER BY r.title, r.price DESC"; -//echo $sql."<br />"; - - // Start generating the table of results - echo '<table border="0" cellpadding="2">'; - - // Generate the search result headings - echo '<tr class="heading">'; - echo '<td>Job Title</td><td>Description</td><td>State</td><td>Date Posted</td>'; - echo '</tr>'; - - -$result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "<td><img src='".$row['image']."' style='height: 100px;' /></td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/README.txt b/week-13/README.txt deleted file mode 100644 index 3ec4f7e04e250189518ef35eb7d907808868ecb0..0000000000000000000000000000000000000000 --- a/week-13/README.txt +++ /dev/null @@ -1,29 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -## this recordstore has been hacked for term 2 - -Description ------------ -This is a demo record store application. You can use it to help you complete lab 8. It is You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -+ Check you have a LAMP stack installed with PHP>5 and MySQL>5 -+ Upload the application to your web root folder. -+ Run the record-store.sql file on your database. -+ Run the dummy_data.sql file to insert some data. - -Configuration Instructions --------------------------- -Modify the includes/db_connect.php script with your MySQL database credentials. - -Live Demo ---------- -A demo version of this app is deployed at the following URL: -http://doc.gold.ac.uk/~sharr003/data-network-web/lab-exercises/week-8/record-store-app/ diff --git a/week-13/admin/index.php b/week-13/admin/index.php deleted file mode 100644 index 4b5707c19c18855d5214132b5d6f434ce53e3845..0000000000000000000000000000000000000000 --- a/week-13/admin/index.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php - -// connect to the database -require('../includes/db_connect.php'); -require('../includes/functions.php'); - -session_start(); -if (!is_logged_in()) { - header('Location: http://localhost/term2labs-dan/week-13/admin/views/login.php'); -} - -// define a function to sanitise user input (this would ideally be in includes folder) -function clean_input($data) { - $data = trim($data); // strips unnecessary characters from beginning/end - $data = stripslashes($data); // remove backslashes - $data = htmlspecialchars($data); // replace special characters with HTML entities - return $data; -} - -// include the header HTML -include('../templates/header.html'); - -// include the navigation HTML -include('views/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -case 'orders' : - include 'views/orders.php'; - break; -case 'order' : - include 'views/order.php'; - break; -case 'add-record' : - include 'views/add-record.php'; - break; -case 'search' : - include 'views/search.php'; - break; -case 'logout' : - include 'views/logout.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('../templates/footer.html'); - -?> diff --git a/week-13/admin/views/404.php b/week-13/admin/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-13/admin/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-13/admin/views/add-record.php b/week-13/admin/views/add-record.php deleted file mode 100644 index 8ba12cf18a76d7695e7f8194a6622d04ff37ec49..0000000000000000000000000000000000000000 --- a/week-13/admin/views/add-record.php +++ /dev/null @@ -1,175 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -// -> htmlspecialchars() is used to replace special characters with HTML entities */ -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=add-record"); - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' enctype='multipart/form-data' method='POST'> -<input type='hidden' name='MAX_FILE_SIZE' value='1000000' /> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <fieldset> - <label for='price'>Stock:</label> - <input type='text' name='stock' placeholder='0' /> - </fieldset> -<label>image <input type='file' id='image' name='image' /></label><br /> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = $stock = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = mysqli_real_escape_string($link, clean_input($_POST["ean"])); - $title = mysqli_real_escape_string($link, clean_input($_POST["title"])); - $artist_id = mysqli_real_escape_string($link, clean_input($_POST["artist_id"])); - $genre = mysqli_real_escape_string($link, clean_input($_POST["genre"])); - $year = mysqli_real_escape_string($link, clean_input($_POST["year"])); - $price = mysqli_real_escape_string($link, clean_input($_POST["price"])); - $stock = mysqli_real_escape_string($link, clean_input($_POST["stock"])); - - // handle the image upload - $uploadOk = 1; - - $target_dir = "../uploads/"; - $image_dir = "uploads/"; - - // Check if image file is a actual image or fake image - $check = getimagesize($_FILES["image"]["tmp_name"]); - if($check !== false) { - // echo "File is an image - " . $check["mime"] . "."; - $uploadOk = 1; - } else { - echo "File is not an image."; - $uploadOk = 0; - } - - // Check file size - if ($_FILES["image"]["size"] > 1000000) { - echo "Sorry, your file is too large."; - $uploadOk = 0; - } - - $target_file = $target_dir . basename($_FILES["image"]["name"]); - $image = $image_dir . basename($_FILES["image"]["name"]); - - // Check if file already exists - if (file_exists($target_file)) { - echo "Sorry, file already exists."; - $uploadOk = 0; - } - - $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); - - // Allow certain file formats - if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" - && $imageFileType != "gif" ) { - echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; - $uploadOk = 0; - } - - // Check if $uploadOk is set to 0 by an error - if ($uploadOk == 0) { - echo "Sorry, your file was not uploaded."; - - // if everything is ok, try to upload file - } else { - if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { - echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded."; - } else { - echo "Sorry, there was an error uploading your file."; - } - } - // end of image upload - - // turn autocommit off - mysqli_autocommit($link, FALSE); - - // start a transaction - mysqli_query($link, 'START TRANSACTION'); - - // define the insertion query to add a new record in record table - $query1 = sprintf("INSERT INTO record (ean, title, artist_id, genre, year, price, image) - VALUES ('%s', '%s', %d, '%s', %d, %f, '%s')", $ean, $title, $artist_id, $genre, $year, $price, $image); - - // define the insertion query to add a new record in inventory table - $query2 = sprintf("INSERT INTO inventory (stock, record_ean) - VALUES (%d, '%s')", $stock, $ean); - - // check if either of the queries failed (returned false) - if (!mysqli_query($link, $query1) or !mysqli_query($link, $query2)) { - echo mysqli_error($link); - mysqli_rollback($link); // if so, rollback transaction - } else { - mysqli_commit($link); // else, commit transaction - $content .= "Record successfully added to database."; - } - - - - } - - // ------- END form processing code... ------- - - // output the html - echo($content); - -?> diff --git a/week-13/admin/views/artist.php b/week-13/admin/views/artist.php deleted file mode 100644 index ea371d7e2a7a6057ea88edcd8afe2edd4020a582..0000000000000000000000000000000000000000 --- a/week-13/admin/views/artist.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -// check if id parameter was not set in query string -if (!isset($_GET['id'])) { - - // define $content with suitable message - $content = "<h1>I don't know which artist you're looking for...</h1>"; - -} else { // id was set, so carry on... - - // define $artist_id variable and assign value of id parameter - $artist_id = $_GET['id']; - - // fetch record titles for artist with id matching $artist_id - $sql = "SELECT r.title, r.year, r.price, a.first_name, a.last_name - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - WHERE a.id=".$artist_id." - ORDER BY year ASC"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // define a row counter - $i = 0; - - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - - // do this if we are on first row - if ($i == 0) { - - // initialise $content string, assigning it a page header - $content = "<h1>".$row['first_name']." ".$row['last_name']." Records</h1>"; - // append $content string with table definition - $content .= "<table border='1'><tbody>"; - - } - - // append table rows to $content string - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['year']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "</tr>"; - - // increment the row counter - $i++; - - } - - // append $content string with closing table tags - $content .= "</tbody></table>"; - - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/admin/views/home.php b/week-13/admin/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-13/admin/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-13/admin/views/login.php b/week-13/admin/views/login.php deleted file mode 100644 index f1cd3e33dda00301c6ec8757d98b55321df5ebb5..0000000000000000000000000000000000000000 --- a/week-13/admin/views/login.php +++ /dev/null @@ -1,51 +0,0 @@ -<? -session_start(); -require_once '../../includes/db_connect.php'; -function printform(){ - print "<form action='login.php' method='POST'> - <p><label>username <input type='text' name='username'></label><p> - <p><label>password <input type='password' name='password'></label><p> - <p><input type='submit' name='submit' value='login'><p>"; -} - -$message=""; - -if ($_SERVER['REQUEST_METHOD'] == 'POST'){ - - $username = mysqli_real_escape_string($link, trim(strip_tags($_POST['username']))); - $password = mysqli_real_escape_string($link, trim(strip_tags($_POST['password']))); - - - if ((!empty($username)) && (!empty($password))){ - - $q = "select * from users where name ='$username' and password = SHA('$password')"; - $r = mysqli_query($link, $q); - if (mysqli_affected_rows($link) == 1){ - $row = mysqli_fetch_array($r); - $_SESSION['username'] = $username; - $_SESSION['user_id'] = $row['user_id']; - header('Location: http://localhost/term2labs-dan/week-13/admin/index.php'); - } else { - $message = $message."Login unsuccessful: please try again </br>"; - } - } - if (empty($username)) { - $message = $message."Please include a username </br>"; - } - if (empty($password)) { - $message = $message."Please include a password </br>"; - } - -} - -require_once '../../templates/header.html'; - -//if (!empty($message)){ - print "<p class='error'>".$message."</p>"; -//} -printform(); - - - -require_once '../../templates/footer.html'; -?> diff --git a/week-13/admin/views/logout.php b/week-13/admin/views/logout.php deleted file mode 100644 index d606c375ebb0ad9837ff3ced2ba581befc57dcb6..0000000000000000000000000000000000000000 --- a/week-13/admin/views/logout.php +++ /dev/null @@ -1,7 +0,0 @@ -<? -session_start(); - -session_destroy(); -header('Location: http://localhost/term2labs-dan/week-13/index.php'); -?> - diff --git a/week-13/admin/views/navigation.html b/week-13/admin/views/navigation.html deleted file mode 100644 index 2990306c990239618e2c0f40c07a06a67ebd03df..0000000000000000000000000000000000000000 --- a/week-13/admin/views/navigation.html +++ /dev/null @@ -1,10 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=search" title="search">Search</a></li> - <li><a href="?page=orders" title="orders">Orders</a></li> - <li><a href="?page=add-record" title="add record">Add record</a></li> - <li><a href="?page=logout" title="logout">Logout</a></li> - </ul> -</nav> diff --git a/week-13/admin/views/order.php b/week-13/admin/views/order.php deleted file mode 100644 index 0f81c631d898204086a592a060e6341c59a16f20..0000000000000000000000000000000000000000 --- a/week-13/admin/views/order.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price - FROM record r - INNER JOIN orderline ol - ON ol.record_ean=r.ean - WHERE ol.transaction_id=".$order_id; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = $row['quantity'] * $row['price']; - $total = $total + $subtotal; - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/admin/views/orders.php b/week-13/admin/views/orders.php deleted file mode 100644 index d1228914e88edccc204d29b7380dabe43fd36aa7..0000000000000000000000000000000000000000 --- a/week-13/admin/views/orders.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "SELECT id, customer_id FROM transaction - ORDER BY customer_id"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) -{ - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>"; - $content .= "<td>".$row['customer_id']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/admin/views/record.php b/week-13/admin/views/record.php deleted file mode 100644 index cdeaff20279d9d18e0f21feb8264051800449340..0000000000000000000000000000000000000000 --- a/week-13/admin/views/record.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; -$content .= "<p>You are now viewing all records in the database.</p>"; - -// fetch records as a result set -$sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, r.image, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - ORDER BY r.title, r.price DESC"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "<td><img src='../".$row['image']."' style='height: 100px;' /></td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/admin/views/search.php b/week-13/admin/views/search.php deleted file mode 100644 index 942e783b49072659b6fceeeadb7c6f25e457f984..0000000000000000000000000000000000000000 --- a/week-13/admin/views/search.php +++ /dev/null @@ -1,90 +0,0 @@ -<? -$content = "<h1>Search</h1>"; - -// define a variable with path to this script which will process form -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=search"); - -// define the search form -$form_html = "<form method='post' action='". $action ."'> - <label for='usersearch'>search the record store</label><br /> - <input type='text' id='usersearch' name='usersearch' /><br /> - <input type='submit' name='submit' value='Submit' /> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - -// $sort = clean_input($_GET['sort']); - $user_search = clean_input($_POST['usersearch']); - $clean_search = str_replace(',',' ',$user_search); - $search_words = explode(' ',$clean_search); - $final_search_words = array(); - if (count($search_words > 0)){ - foreach ($search_words as $word) { - if (!empty($word)) { - $final_search_words[] = $word; - } - } - } - foreach ($final_search_words as $word) { - $where_list[] = "r.title like '%$word%'"; - } - $where_clause = implode(' OR ', $where_list); - -echo "where clause = " . $where_clause."<br />"; - - // Query to get the results - $sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, r.image, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - WHERE $where_clause - ORDER BY r.title, r.price DESC"; -//echo $sql."<br />"; - - // Start generating the table of results - echo '<table border="0" cellpadding="2">'; - - // Generate the search result headings - echo '<tr class="heading">'; - echo '<td>Job Title</td><td>Description</td><td>State</td><td>Date Posted</td>'; - echo '</tr>'; - - -$result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "<td><img src='../".$row['image']."' style='height: 100px;' /></td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/includes/db_connect.php b/week-13/includes/db_connect.php deleted file mode 100644 index 53c5fb94ab76b4ae3840501948dfe079b2f35296..0000000000000000000000000000000000000000 --- a/week-13/includes/db_connect.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* Open a new connection to the MySQL server */ - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'recordstoreuser', - 'recordstorepwd', - 'recordstore' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); -} - -?> diff --git a/week-13/includes/functions.php b/week-13/includes/functions.php deleted file mode 100644 index 9a4c18ec2c4c693cbbe246e9d97121b19bf39cd9..0000000000000000000000000000000000000000 --- a/week-13/includes/functions.php +++ /dev/null @@ -1,60 +0,0 @@ -<? - -function is_logged_in(){ - if (isset($_SESSION['username'])){ -// print session_name()."<br />"; -// print $_COOKIE[session_name()]; - return true; - } -/* } else { - return false; - } -*/ -} - - -function build_query ($user_search, $sort) { - $clean_search = str_replace(',',' ',$user_search); - $search_words = explode(' ',$clean_search); - $final_search_words = array(); - if (count($search_words > 0)){ - foreach ($search_words as $word) { - if (!empty($word)) { - $final_search_words[] = $word; - } - } - } - $where_list = array(); - foreach ($final_search_words as $word) { - $where_list[] = "r.title like '%$word%'"; - $where_list[] = "a.first_name like '%$word%'"; - $where_list[] = "a.last_name like '%$word%'"; - } - $where_clause = implode(' OR ', $where_list); - -//echo "where clause = " . $where_clause."<br />"; - - // Query to get the results - $sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, r.image, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - WHERE $where_clause"; - -//add the sort to the search, if set - switch ($sort) { - case 1: - $sql .= " ORDER BY r.title"; - break; - case 2: - $sql .= " ORDER BY a.last_name"; - break; - default: - } - - return $sql; -} - -?> diff --git a/week-13/index.php b/week-13/index.php deleted file mode 100644 index baae4a2cc2ed867817a28ee0449a870793466335..0000000000000000000000000000000000000000 --- a/week-13/index.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -//error_reporting(0); -error_reporting (E_ALL | E_STRICT); // Show all possible problems! - -// connect to the database -require('includes/db_connect.php'); -require('includes/functions.php'); - -// define a function to sanitise user input (this would ideally be in includes folder) -function clean_input($data) { - $data = trim($data); // strips unnecessary characters from beginning/end - $data = stripslashes($data); // remove backslashes - $data = htmlspecialchars($data); // replace special characters with HTML entities - return $data; -} - -// include the header HTML -include('templates/header.html'); - -// include the navigation HTML -include('templates/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -case 'orders' : - include 'views/orders.php'; - break; -case 'order' : - include 'views/order.php'; - break; -case 'add-record' : - include 'views/add-record.php'; - break; -case 'search' : - include 'views/search.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('templates/footer.html'); - -?> diff --git a/week-13/sql/dummy_data.sql b/week-13/sql/dummy_data.sql deleted file mode 100644 index 7d0580104297aa0ad65f6d70c33601e128b685d4..0000000000000000000000000000000000000000 --- a/week-13/sql/dummy_data.sql +++ /dev/null @@ -1,67 +0,0 @@ -/* Note that, because foreign key values are being -inserted manually, tables must be recreated before running -this code in order to reset AUTO_INCREMENT */ - -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs'), -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (ean, title, artist_id, genre, year, price) -VALUES -('00562056', 'Soul Rebel', 1, 'Reggae', 1970, 25.99 ), -('50264967', 'Catch A Fire', 1, 'Reggae', 1973, 25.99 ), -('00748396', 'Natty Dread', 1, 'Reggae', 1974, 20.99 ), -('00495739', 'Babylon By Bus', 1, 'Reggae', 1978, 24.99 ), -('00738432', 'Legalize It', 2, 'Reggae', 1976, 22.99 ), -('50847583', 'Bush Doctor', 2, 'Reggae', 1978, 20.99 ), -('30748743', 'Marcus Garvey', 3, 'Reggae', 1975, 24.99 ), -('50856384', 'Night Nurse', 5, 'Reggae', 1982, 17.99 ), -('50264972', 'Mr Issacs', 5, 'Reggae', 1982, 9.99 ), -('00649573', 'Black and Dekker', 6, 'Reggae', 1980, 19.99 ), -('00625485', 'Sunday Coming', 4, 'Reggae', 1970, 15.99 ); - -INSERT INTO customer (id, first_name, last_name, email_address, address_1, address_2, postcode) -VALUES -(NULL, 'John', 'Smith', 'john@smith.com', '1 Fake Street', 'London', 'SE3 5RD'), -(NULL, 'Sukie', 'Bapswent', 's.baps@gmail.com', '64 The Terrace', 'Whitby', 'YO65 3TR'), -(NULL, 'John', 'Thumb', 'jthumb@gmail.com', '25 Fantasy Grove', 'Brighton', 'BR2 6LV'); - -INSERT INTO transaction (id, customer_id, delivery_method, dt_date) -VALUES -(NULL, 1, 2, '2015-07-01 14:34:58'), -(NULL, 1, 2, '2015-04-01 11:22:35'), -(NULL, 3, 1, '2015-04-01 19:47:03'), -(NULL, 2, 1, '2015-05-11 22:01:19'); - -INSERT INTO orderline (id, transaction_id, record_ean, quantity) -VALUES -(NULL, 1, '00562056', 1), -(NULL, 1, '00495739', 1), -(NULL, 2, '00649573', 2), -(NULL, 2, '00495739', 1), -(NULL, 3, '00738432', 2), -(NULL, 3, '00562056', 1), -(NULL, 3, '50856384', 3), -(NULL, 3, '00495739', 1), -(NULL, 4, '00625485', 1), -(NULL, 4, '00562056', 2); - -INSERT INTO inventory (stock, record_ean) -VALUES -(25, '00562056'), -(18, '50264967'), -(15, '00748396'), -(20, '00495739'), -(10, '00738432'), -(7, '50847583'), -(3, '30748743'), -(34, '50856384'), -(22, '50264972'), -(15, '00649573'), -(12, '00625485'); diff --git a/week-13/sql/practice_queries.sql b/week-13/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-13/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-13/sql/record-store.sql b/week-13/sql/record-store.sql deleted file mode 100644 index 971708804df2996481388ffecf24895dd9047bb8..0000000000000000000000000000000000000000 --- a/week-13/sql/record-store.sql +++ /dev/null @@ -1,71 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS inventory, orderline, transaction, customer, record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -) ENGINE=InnoDB; - -/* Define table for storing records (products) */ -CREATE TABLE record ( - ean CHAR(8) NOT NULL, - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price DECIMAL(10, 2) unsigned NOT NULL, - PRIMARY KEY (ean), - FOREIGN KEY (artist_id) - REFERENCES artist (id) - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address_1 VARCHAR(50) NOT NULL, - address_2 VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - dt_date DATETIME, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -) ENGINE=InnoDB; - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - record_ean CHAR(8), - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (record_ean) - REFERENCES record(ean) - ON UPDATE CASCADE - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for inventory */ -CREATE TABLE inventory ( - stock INT unsigned DEFAULT 0, - record_ean CHAR(8), - PRIMARY KEY (stock, record_ean), - FOREIGN KEY (record_ean) - REFERENCES record (ean) -) ENGINE=InnoDB; diff --git a/week-13/sql/recordstore-dump.sql b/week-13/sql/recordstore-dump.sql deleted file mode 100644 index f9dc7c87b19c8a9d855abce62050f3091f0d5ee5..0000000000000000000000000000000000000000 --- a/week-13/sql/recordstore-dump.sql +++ /dev/null @@ -1,196 +0,0 @@ --- MySQL dump 10.13 Distrib 5.6.26, for Linux (x86_64) --- --- Host: localhost Database: recordstore --- ------------------------------------------------------ --- Server version 5.6.26 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `artist` --- - -DROP TABLE IF EXISTS `artist`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `artist` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) DEFAULT NULL, - `last_name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `artist` --- - -LOCK TABLES `artist` WRITE; -/*!40000 ALTER TABLE `artist` DISABLE KEYS */; -INSERT INTO `artist` VALUES (1,'Bob','Marley'),(2,'Peter','Tosh'),(3,'Burning','Spear'),(4,'Alton','Ellis'),(5,'Gregory','Issacs'),(6,'Desmond','Dekker'); -/*!40000 ALTER TABLE `artist` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customer` --- - -DROP TABLE IF EXISTS `customer`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `customer` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) NOT NULL, - `last_name` varchar(50) NOT NULL, - `email_address` varchar(50) NOT NULL, - `address_1` varchar(50) NOT NULL, - `address_2` varchar(50) DEFAULT NULL, - `postcode` varchar(10) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customer` --- - -LOCK TABLES `customer` WRITE; -/*!40000 ALTER TABLE `customer` DISABLE KEYS */; -INSERT INTO `customer` VALUES (1,'John','Smith','john@smith.com','1 Fake Street','London','SE3 5RD'),(2,'Sukie','Bapswent','s.baps@gmail.com','64 The Terrace','Whitby','YO65 3TR'),(3,'John','Thumb','jthumb@gmail.com','25 Fantasy Grove','Brighton','BR2 6LV'); -/*!40000 ALTER TABLE `customer` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `inventory` --- - -DROP TABLE IF EXISTS `inventory`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `inventory` ( - `stock` int(10) unsigned NOT NULL DEFAULT '0', - `record_ean` char(8) NOT NULL DEFAULT '', - PRIMARY KEY (`stock`,`record_ean`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `inventory` --- - -LOCK TABLES `inventory` WRITE; -/*!40000 ALTER TABLE `inventory` DISABLE KEYS */; -INSERT INTO `inventory` VALUES (20,'00495739'),(25,'00562056'),(12,'00625485'),(15,'00649573'),(10,'00738432'),(15,'00748396'),(1,'1010010'),(5,'12121212'),(2,'131313'),(3,'30748743'),(18,'50264967'),(22,'50264972'),(7,'50847583'),(34,'50856384'); -/*!40000 ALTER TABLE `inventory` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `orderline` --- - -DROP TABLE IF EXISTS `orderline`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderline` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `transaction_id` int(11) DEFAULT NULL, - `record_ean` char(8) DEFAULT NULL, - `quantity` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `transaction_id` (`transaction_id`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `orderline_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `transaction` (`id`), - CONSTRAINT `orderline_ibfk_2` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `orderline` --- - -LOCK TABLES `orderline` WRITE; -/*!40000 ALTER TABLE `orderline` DISABLE KEYS */; -INSERT INTO `orderline` VALUES (1,1,'00562056',1),(2,1,'00495739',1),(3,2,'00649573',2),(4,2,'00495739',1),(5,3,'00738432',2),(6,3,'00562056',1),(7,3,'50856384',3),(8,3,'00495739',1),(9,4,'00625485',1),(10,4,'00562056',2); -/*!40000 ALTER TABLE `orderline` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `record` --- - -DROP TABLE IF EXISTS `record`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `record` ( - `ean` char(8) NOT NULL, - `title` varchar(50) NOT NULL, - `artist_id` int(11) DEFAULT NULL, - `genre` varchar(50) DEFAULT NULL, - `year` year(4) DEFAULT NULL, - `price` decimal(10,2) unsigned NOT NULL, - `image` varchar(64) DEFAULT NULL, - PRIMARY KEY (`ean`), - KEY `artist_id` (`artist_id`), - CONSTRAINT `record_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `record` --- - -LOCK TABLES `record` WRITE; -/*!40000 ALTER TABLE `record` DISABLE KEYS */; -INSERT INTO `record` VALUES ('00495739','Babylon By Bus',1,'Reggae',1978,24.99,NULL),('00562056','Soul Rebel',1,'Reggae',1970,25.99,NULL),('00625485','Sunday Coming',4,'Reggae',1970,15.99,NULL),('00649573','Black and Dekker',6,'Reggae',1980,19.99,NULL),('00738432','Legalize It',2,'Reggae',1976,22.99,NULL),('00748396','Natty Dread',1,'Reggae',1974,20.99,NULL),('1010010','A test',6,'testy',2000,20.00,'uploads/2009-a32-08-05-adorno-b.jpg'),('12121212','Dek Stop',6,'2 tone',1978,10.99,NULL),('131313','blahblah',4,'hip hop',2011,9.99,NULL),('30748743','Marcus Garvey',3,'Reggae',1975,24.99,NULL),('50264967','Catch A Fire',1,'Reggae',1973,25.99,NULL),('50264972','Mr Issacs',5,'Reggae',1982,9.99,NULL),('50847583','Bush Doctor',2,'Reggae',1978,20.99,NULL),('50856384','Night Nurse',5,'Reggae',1982,17.99,NULL); -/*!40000 ALTER TABLE `record` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `transaction` --- - -DROP TABLE IF EXISTS `transaction`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transaction` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `customer_id` int(11) NOT NULL, - `delivery_method` int(11) DEFAULT NULL, - `dt_date` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `customer_id` (`customer_id`), - CONSTRAINT `transaction_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `transaction` --- - -LOCK TABLES `transaction` WRITE; -/*!40000 ALTER TABLE `transaction` DISABLE KEYS */; -INSERT INTO `transaction` VALUES (1,1,2,'2015-07-01 14:34:58'),(2,1,2,'2015-04-01 11:22:35'),(3,3,1,'2015-04-01 19:47:03'),(4,2,1,'2015-05-11 22:01:19'); -/*!40000 ALTER TABLE `transaction` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2016-01-19 18:54:19 diff --git a/week-13/sql/recordstore-dump2.sql b/week-13/sql/recordstore-dump2.sql deleted file mode 100644 index f46498bb1e7c4897a468112326a0b7475b7c3ac9..0000000000000000000000000000000000000000 --- a/week-13/sql/recordstore-dump2.sql +++ /dev/null @@ -1,196 +0,0 @@ --- MySQL dump 10.13 Distrib 5.6.26, for Linux (x86_64) --- --- Host: localhost Database: recordstore --- ------------------------------------------------------ --- Server version 5.6.26 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `artist` --- - -DROP TABLE IF EXISTS `artist`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `artist` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) DEFAULT NULL, - `last_name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `artist` --- - -LOCK TABLES `artist` WRITE; -/*!40000 ALTER TABLE `artist` DISABLE KEYS */; -INSERT INTO `artist` VALUES (1,'Bob','Marley'),(2,'Peter','Tosh'),(3,'Burning','Spear'),(4,'Alton','Ellis'),(5,'Gregory','Issacs'),(6,'Desmond','Dekker'); -/*!40000 ALTER TABLE `artist` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customer` --- - -DROP TABLE IF EXISTS `customer`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `customer` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) NOT NULL, - `last_name` varchar(50) NOT NULL, - `email_address` varchar(50) NOT NULL, - `address_1` varchar(50) NOT NULL, - `address_2` varchar(50) DEFAULT NULL, - `postcode` varchar(10) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customer` --- - -LOCK TABLES `customer` WRITE; -/*!40000 ALTER TABLE `customer` DISABLE KEYS */; -INSERT INTO `customer` VALUES (1,'John','Smith','john@smith.com','1 Fake Street','London','SE3 5RD'),(2,'Sukie','Bapswent','s.baps@gmail.com','64 The Terrace','Whitby','YO65 3TR'),(3,'John','Thumb','jthumb@gmail.com','25 Fantasy Grove','Brighton','BR2 6LV'); -/*!40000 ALTER TABLE `customer` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `inventory` --- - -DROP TABLE IF EXISTS `inventory`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `inventory` ( - `stock` int(10) unsigned NOT NULL DEFAULT '0', - `record_ean` char(8) NOT NULL DEFAULT '', - PRIMARY KEY (`stock`,`record_ean`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `inventory` --- - -LOCK TABLES `inventory` WRITE; -/*!40000 ALTER TABLE `inventory` DISABLE KEYS */; -INSERT INTO `inventory` VALUES (20,'00495739'),(25,'00562056'),(12,'00625485'),(15,'00649573'),(10,'00738432'),(15,'00748396'),(1,'1000000'),(1,'1010010'),(5,'12121212'),(2,'131313'),(3,'30748743'),(18,'50264967'),(22,'50264972'),(7,'50847583'),(34,'50856384'),(2,'985'); -/*!40000 ALTER TABLE `inventory` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `orderline` --- - -DROP TABLE IF EXISTS `orderline`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderline` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `transaction_id` int(11) DEFAULT NULL, - `record_ean` char(8) DEFAULT NULL, - `quantity` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `transaction_id` (`transaction_id`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `orderline_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `transaction` (`id`), - CONSTRAINT `orderline_ibfk_2` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `orderline` --- - -LOCK TABLES `orderline` WRITE; -/*!40000 ALTER TABLE `orderline` DISABLE KEYS */; -INSERT INTO `orderline` VALUES (1,1,'00562056',1),(2,1,'00495739',1),(3,2,'00649573',2),(4,2,'00495739',1),(5,3,'00738432',2),(6,3,'00562056',1),(7,3,'50856384',3),(8,3,'00495739',1),(9,4,'00625485',1),(10,4,'00562056',2); -/*!40000 ALTER TABLE `orderline` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `record` --- - -DROP TABLE IF EXISTS `record`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `record` ( - `ean` char(8) NOT NULL, - `title` varchar(50) NOT NULL, - `artist_id` int(11) DEFAULT NULL, - `genre` varchar(50) DEFAULT NULL, - `year` year(4) DEFAULT NULL, - `price` decimal(10,2) unsigned NOT NULL, - `image` varchar(64) DEFAULT NULL, - PRIMARY KEY (`ean`), - KEY `artist_id` (`artist_id`), - CONSTRAINT `record_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `record` --- - -LOCK TABLES `record` WRITE; -/*!40000 ALTER TABLE `record` DISABLE KEYS */; -INSERT INTO `record` VALUES ('00495739','Babylon By Bus',1,'Reggae',1978,24.99,NULL),('00562056','Soul Rebel',1,'Reggae',1970,25.99,NULL),('00625485','Sunday Coming',4,'Reggae',1970,15.99,NULL),('00649573','Black and Dekker',6,'Reggae',1980,19.99,NULL),('00738432','Legalize It',2,'Reggae',1976,22.99,NULL),('00748396','Natty Dread',1,'Reggae',1974,20.99,NULL),('1000000','B test',5,'funk',2016,26.00,'uploads/avatar 1.jpg'),('1010010','A test',6,'testy',2000,20.00,'uploads/2009-a32-08-05-adorno-b.jpg'),('12121212','Dek Stop',6,'2 tone',1978,10.99,NULL),('131313','blahblah',4,'hip hop',2011,9.99,NULL),('30748743','Marcus Garvey',3,'Reggae',1975,24.99,NULL),('50264967','Catch A Fire',1,'Reggae',1973,25.99,NULL),('50264972','Mr Issacs',5,'Reggae',1982,9.99,NULL),('50847583','Bush Doctor',2,'Reggae',1978,20.99,NULL),('50856384','Night Nurse',5,'Reggae',1982,17.99,NULL),('985','test',6,'test',0000,22.00,'uploads/think of this as a window.jpg'); -/*!40000 ALTER TABLE `record` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `transaction` --- - -DROP TABLE IF EXISTS `transaction`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transaction` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `customer_id` int(11) NOT NULL, - `delivery_method` int(11) DEFAULT NULL, - `dt_date` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `customer_id` (`customer_id`), - CONSTRAINT `transaction_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `transaction` --- - -LOCK TABLES `transaction` WRITE; -/*!40000 ALTER TABLE `transaction` DISABLE KEYS */; -INSERT INTO `transaction` VALUES (1,1,2,'2015-07-01 14:34:58'),(2,1,2,'2015-04-01 11:22:35'),(3,3,1,'2015-04-01 19:47:03'),(4,2,1,'2015-05-11 22:01:19'); -/*!40000 ALTER TABLE `transaction` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2016-01-26 16:55:43 diff --git a/week-13/sql/user-table.sql b/week-13/sql/user-table.sql deleted file mode 100644 index d0a426b347739d9e806f843213c5bdfa672b9838..0000000000000000000000000000000000000000 --- a/week-13/sql/user-table.sql +++ /dev/null @@ -1,25 +0,0 @@ --- --- Table structure for table `users` --- - -DROP TABLE IF EXISTS `users`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `users` ( - `user_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(50) DEFAULT NULL, - `password` varchar(50) DEFAULT NULL, - PRIMARY KEY (`user_id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `users` --- - -LOCK TABLES `users` WRITE; -/*!40000 ALTER TABLE `users` DISABLE KEYS */; -INSERT INTO `users` VALUES (1,'alice','5f55cff83a8f2f274947745629d3ede299a05bfd'),(2,'bob','b639bbe4c65ae9ea79b4268701e8656a80c95b14'),(3,'cliff','0c0b7dce234a29cf42d72db5420d708ac9251a82'),(4,'dan','4376fd0454dbaf40ba385212c04c0d18319c572b'),(5,'eric','9b2b6e9f988f06e7807694b7903cd7832e154975'),(6,'fabio','782a7facdc65b96b3896f40e43f5b5ec04393b3e'); -/*!40000 ALTER TABLE `users` ENABLE KEYS */; -UNLOCK TABLES; - diff --git a/week-13/templates/footer.html b/week-13/templates/footer.html deleted file mode 100644 index 2ab5c0d1fc7b0e6c12fb00bf177037f64450298c..0000000000000000000000000000000000000000 --- a/week-13/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - </body> -</html> diff --git a/week-13/templates/header.html b/week-13/templates/header.html deleted file mode 100644 index fc565541741ccc043bfeb2c6d3f7a39640740dd9..0000000000000000000000000000000000000000 --- a/week-13/templates/header.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Record Store</title> - </head> - <body> diff --git a/week-13/templates/navigation.html b/week-13/templates/navigation.html deleted file mode 100644 index 9f895997e38d4c0abe5b44ef8352910f14f9e8dc..0000000000000000000000000000000000000000 --- a/week-13/templates/navigation.html +++ /dev/null @@ -1,7 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=search" title="search">Search</a></li> - </ul> -</nav> diff --git a/week-13/uploads/2009-a32-08-05-adorno-b.jpg b/week-13/uploads/2009-a32-08-05-adorno-b.jpg deleted file mode 100644 index 4e896284f0a353698a1567dbd60fe9084352102b..0000000000000000000000000000000000000000 Binary files a/week-13/uploads/2009-a32-08-05-adorno-b.jpg and /dev/null differ diff --git a/week-13/uploads/avatar 1.jpg b/week-13/uploads/avatar 1.jpg deleted file mode 100644 index 0f72ed7d3df1b440ca9e8128ce3bf9b495fac37e..0000000000000000000000000000000000000000 Binary files a/week-13/uploads/avatar 1.jpg and /dev/null differ diff --git a/week-13/uploads/je-participe.gif b/week-13/uploads/je-participe.gif deleted file mode 100644 index 91e7b890942debafe2718187d3f0f785b09d25ea..0000000000000000000000000000000000000000 Binary files a/week-13/uploads/je-participe.gif and /dev/null differ diff --git a/week-13/uploads/man-ray-iron-A.gif b/week-13/uploads/man-ray-iron-A.gif deleted file mode 100644 index 127305ad2f453616c0858c28a09f65dc7a57afcf..0000000000000000000000000000000000000000 Binary files a/week-13/uploads/man-ray-iron-A.gif and /dev/null differ diff --git a/week-13/uploads/think of this as a window.jpg b/week-13/uploads/think of this as a window.jpg deleted file mode 100644 index 6974a3771579395769a65c117e46e5887a83f285..0000000000000000000000000000000000000000 Binary files a/week-13/uploads/think of this as a window.jpg and /dev/null differ diff --git a/week-13/views/404.php b/week-13/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-13/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-13/views/add-record-insecure.php b/week-13/views/add-record-insecure.php deleted file mode 100644 index 841a5078b968ebf2b18cb97286ab6e8f9d03bbfc..0000000000000000000000000000000000000000 --- a/week-13/views/add-record-insecure.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -$action = $_SERVER["PHP_SELF"]."?page=add-record"; - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = $_POST["ean"]; - $title = $_POST["title"]; - $artist_id = $_POST["artist_id"]; - $genre = $_POST["genre"]; - $year = $_POST["year"]; - $price = $_POST["price"]; - - // define the insertion query - $sql = "INSERT INTO record (ean, title, artist_id, genre, year, price) - VALUES ('$ean', '$title', '$artist_id', '$genre', '$year', '$price')"; - - // run the query to insert the data - $result = mysqli_query($link, $sql); - - // check if the query went ok - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "Record successfully added to database."; - } -} - -// ------- END form processing code... ------- - -// output the html -echo($content); - -?> diff --git a/week-13/views/add-record.php b/week-13/views/add-record.php deleted file mode 100644 index b8d556e457bd6c5211695b034c7295984a870291..0000000000000000000000000000000000000000 --- a/week-13/views/add-record.php +++ /dev/null @@ -1,174 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -// -> htmlspecialchars() is used to replace special characters with HTML entities */ -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=add-record"); - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' enctype='multipart/form-data' method='POST'> -<input type='hidden' name='MAX_FILE_SIZE' value='1000000' /> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <fieldset> - <label for='price'>Stock:</label> - <input type='text' name='stock' placeholder='0' /> - </fieldset> -<label>image <input type='file' id='image' name='image' /></label><br /> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = $stock = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = mysqli_real_escape_string($link, clean_input($_POST["ean"])); - $title = mysqli_real_escape_string($link, clean_input($_POST["title"])); - $artist_id = mysqli_real_escape_string($link, clean_input($_POST["artist_id"])); - $genre = mysqli_real_escape_string($link, clean_input($_POST["genre"])); - $year = mysqli_real_escape_string($link, clean_input($_POST["year"])); - $price = mysqli_real_escape_string($link, clean_input($_POST["price"])); - $stock = mysqli_real_escape_string($link, clean_input($_POST["stock"])); - - // handle the image upload - $uploadOk = 1; - - $target_dir = "uploads/"; - - // Check if image file is a actual image or fake image - $check = getimagesize($_FILES["image"]["tmp_name"]); - if($check !== false) { - // echo "File is an image - " . $check["mime"] . "."; - $uploadOk = 1; - } else { - echo "File is not an image."; - $uploadOk = 0; - } - - // Check file size - if ($_FILES["image"]["size"] > 1000000) { - echo "Sorry, your file is too large."; - $uploadOk = 0; - } - - $target_file = $target_dir . basename($_FILES["image"]["name"]); - $image = $target_file; - - // Check if file already exists - if (file_exists($target_file)) { - echo "Sorry, file already exists."; - $uploadOk = 0; - } - - $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); - - // Allow certain file formats - if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" - && $imageFileType != "gif" ) { - echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; - $uploadOk = 0; - } - - // Check if $uploadOk is set to 0 by an error - if ($uploadOk == 0) { - echo "Sorry, your file was not uploaded."; - - // if everything is ok, try to upload file - } else { - if (move_uploaded_file($_FILES["image"]["tmp_name"], $target_file)) { - echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded."; - } else { - echo "Sorry, there was an error uploading your file."; - } - } - // end of image upload - - // turn autocommit off - mysqli_autocommit($link, FALSE); - - // start a transaction - mysqli_query($link, 'START TRANSACTION'); - - // define the insertion query to add a new record in record table - $query1 = sprintf("INSERT INTO record (ean, title, artist_id, genre, year, price, image) - VALUES ('%s', '%s', %d, '%s', %d, %f, '%s')", $ean, $title, $artist_id, $genre, $year, $price, $image); - - // define the insertion query to add a new record in inventory table - $query2 = sprintf("INSERT INTO inventory (stock, record_ean) - VALUES (%d, '%s')", $stock, $ean); - - // check if either of the queries failed (returned false) - if (!mysqli_query($link, $query1) or !mysqli_query($link, $query2)) { - echo mysqli_error($link); - mysqli_rollback($link); // if so, rollback transaction - } else { - mysqli_commit($link); // else, commit transaction - $content .= "Record successfully added to database."; - } - - - - } - - // ------- END form processing code... ------- - - // output the html - echo($content); - -?> diff --git a/week-13/views/artist.php b/week-13/views/artist.php deleted file mode 100644 index ea371d7e2a7a6057ea88edcd8afe2edd4020a582..0000000000000000000000000000000000000000 --- a/week-13/views/artist.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -// check if id parameter was not set in query string -if (!isset($_GET['id'])) { - - // define $content with suitable message - $content = "<h1>I don't know which artist you're looking for...</h1>"; - -} else { // id was set, so carry on... - - // define $artist_id variable and assign value of id parameter - $artist_id = $_GET['id']; - - // fetch record titles for artist with id matching $artist_id - $sql = "SELECT r.title, r.year, r.price, a.first_name, a.last_name - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - WHERE a.id=".$artist_id." - ORDER BY year ASC"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // define a row counter - $i = 0; - - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - - // do this if we are on first row - if ($i == 0) { - - // initialise $content string, assigning it a page header - $content = "<h1>".$row['first_name']." ".$row['last_name']." Records</h1>"; - // append $content string with table definition - $content .= "<table border='1'><tbody>"; - - } - - // append table rows to $content string - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['year']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "</tr>"; - - // increment the row counter - $i++; - - } - - // append $content string with closing table tags - $content .= "</tbody></table>"; - - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/views/home.php b/week-13/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-13/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-13/views/order.php b/week-13/views/order.php deleted file mode 100644 index 0f81c631d898204086a592a060e6341c59a16f20..0000000000000000000000000000000000000000 --- a/week-13/views/order.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price - FROM record r - INNER JOIN orderline ol - ON ol.record_ean=r.ean - WHERE ol.transaction_id=".$order_id; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = $row['quantity'] * $row['price']; - $total = $total + $subtotal; - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/views/orders.php b/week-13/views/orders.php deleted file mode 100644 index d1228914e88edccc204d29b7380dabe43fd36aa7..0000000000000000000000000000000000000000 --- a/week-13/views/orders.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "SELECT id, customer_id FROM transaction - ORDER BY customer_id"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) -{ - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>"; - $content .= "<td>".$row['customer_id']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/views/record.php b/week-13/views/record.php deleted file mode 100644 index 06ffa5efc4b771330005e5732cf3e63a37b77419..0000000000000000000000000000000000000000 --- a/week-13/views/record.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; -$content .= "<p>You are now viewing all records in the database.</p>"; - -// fetch records as a result set -$sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, r.image, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - ORDER BY r.title, r.price DESC"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "<td><img src='".$row['image']."' style='height: 100px;' /></td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-13/views/search.php b/week-13/views/search.php deleted file mode 100644 index 8e9482d5df3d96f82499726fff3789c46a17ff59..0000000000000000000000000000000000000000 --- a/week-13/views/search.php +++ /dev/null @@ -1,131 +0,0 @@ -<? -$content = "<h1>Search</h1>"; - -// define a variable with path to this script which will process form -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=search"); - -// define the search form -// note: need ?page=search for index to route here -// note: a form wihout an action will submit to the document's address -$form_html = "<form method='get'> - <label for='usersearch'>search the record store</label><br /> - <input type='text' id='usersearch' name='usersearch' /><br /> - <input type='submit' name='page' value='search' /> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// check if there was a POST request -//if ($_SERVER["REQUEST_METHOD"] == "POST") { -if (!empty($_GET['usersearch'])) { - $sort =""; - -// make a build_query function for the search - $user_search = $_GET['usersearch']; - $user_search = clean_input($user_search); - if (!empty($_GET['sort'])) { - $sort = $_GET['sort']; - $sort = clean_input($sort); - } - $sql = build_query($user_search, $sort); - - //sort pagination - $cur_page = isset($_GET['pagenumber']) ? $_GET['pagenumber'] : 1 ; - $results_per_page = 3; - $skip = (($cur_page - 1) * $results_per_page); - - // Start generating the table of results - echo '<table border="0" cellpadding="2">'; - - // Generate the search result headings - echo '<tr class="heading">'; - echo '<td>Job Title</td><td>Description</td><td>State</td><td>Date Posted</td>'; - echo '</tr>'; - - -$result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // info needed for pagination - $total = mysqli_num_rows($result); - $num_pages = ceil($total / $results_per_page); - - // query again to get subset of results per page - $sql = $sql .= " LIMIT $skip, $results_per_page"; - $result = mysqli_query($link, $sql); - - $content .= "<table border='1'>"; - $content .= "<thead><tr><th><a href='?page=search&usersearch=$user_search&sort=1'>Title</a></th>"; - $content .= "<th><a href='?page=search&usersearch=$user_search&sort=2'>Artist</a></th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "<td><img src='".$row['image']."' style='height: 100px;' /></td>"; - $content .= "</tr>"; - - } - $content .= "</tbody></table>"; - - // This function builds navigational page links based on the current page and the number of pages - function generate_page_links($user_search, $sort, $cur_page, $num_pages) { - $page_links = ''; -/* - // If this page is not the first page, generate the "previous" link - if ($cur_page > 1) { - $page_links .= '<a href="' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=' . $sort . '&page=' . ($cur_page - 1) . '"><-</a> '; - } - else { - $page_links .= '<- '; - } -*/ - // Loop through the pages generating the page number links - for ($i = 1; $i <= $num_pages; $i++) { - if ($cur_page == $i) { - $page_links .= ' ' . $i; - } - else { - $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=search&usersearch=' . $user_search . '&sort=' . $sort . '&pagenumber=' . $i . '"> ' . $i . '</a>'; - } - } -/* - // If this page is not the last page, generate the "next" link - if ($cur_page < $num_pages) { - $page_links .= ' <a href="' . $_SERVER['PHP_SELF'] . '?usersearch=' . $user_search . '&sort=' . $sort . '&page=' . ($cur_page + 1) . '">-></a>'; - } - else { - $page_links .= ' ->'; - } -*/ - return $page_links; - } - - - // Generate navigational page links if we have more than one page - if ($num_pages > 1) { - echo generate_page_links($user_search, $sort, $cur_page, $num_pages); - } - - - - // free result set - mysqli_free_result($result); - } - -} -// output the content HTML -echo $content; - -?> diff --git a/week-15/database-class/config.php b/week-15/database-class/config.php deleted file mode 100644 index 48e9bd42763f50fc43aadb00399925713b2a5e6e..0000000000000000000000000000000000000000 --- a/week-15/database-class/config.php +++ /dev/null @@ -1,10 +0,0 @@ -<? - -// define constants for database conncetion -define('DATABASE_HOST', 'localhost'); -define('DATABASE_NAME', 'recordstore'); -define('DATABASE_USER', 'recordstoreuser'); -define('DATABASE_PASSWORD', 'recordstorepwd'); - - -?> diff --git a/week-15/database-class/database.class.php b/week-15/database-class/database.class.php deleted file mode 100644 index 8d96806cdf73ecfdfc919361a82ec753fb2f29cc..0000000000000000000000000000000000000000 --- a/week-15/database-class/database.class.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -class Database -{ - private $connection; - private $hostname; - private $username; - private $password; - private $database; - - public function __construct() - { - $this->hostname = DATABASE_HOST; - $this->username = DATABASE_USER; - $this->password = DATABASE_PASSWORD; - $this->database = DATABASE_NAME; - } - - public function openConnection() - { - // Open database connection - $this->connection = mysqli_connect($this->hostname, $this->username, $this->password, $this->database) - or die(mysqli_error()); - - } - - public function closeConnection() - { - if (isset($this->connection)) { - // Close database connection - mysql_close($this->connection) - or die(mysql_error()); - } - } - - public function executeStatement($statement) - { - - // Execute database statement - $result = mysqli_query($this->connection, $statement) - or die(mysql_error()); - - - // Return result - return $result; - } - - public function executeSql($sql) - { - // Execute database statement - $result = $this->executeStatement($sql); - - // Check number of rows returned - if(mysqli_num_rows($result) == 1) - { - // Fetch one row from the result - $dataset = mysqli_fetch_object($result); - } - else - { - // Fetch multiple rows from the result - $dataset = array(); - while ($row = mysqli_fetch_object($result)) { - $dataset[] = $row; - } - } - - // Close database cursor - mysqli_free_result($result); - - // Return dataset - return $dataset; - } - - public function executeDml($dml) - { - // Execute database statement - $this->executeStatement($dml); - - // Return number of affected rows - return mysqli_affected_rows($this->connection); - } - - public function sanitizeInput($value) - { - // more here... - } -} diff --git a/week-15/database-class/index.php b/week-15/database-class/index.php deleted file mode 100644 index 2c2c09ae222745b2d540dff86329a65373869e0b..0000000000000000000000000000000000000000 --- a/week-15/database-class/index.php +++ /dev/null @@ -1,19 +0,0 @@ -<? - -include 'config.php'; - -include 'database.class.php'; - -$db = new Database; -$db->openConnection(); - -$sql = 'select * from record'; -$rows = $db->executeSQL($sql); - -foreach($rows as $row) { - print $row->title; - print "<br />"; -} - - -?> diff --git a/week-15/image-upload/classes/Uploader.class.php b/week-15/image-upload/classes/Uploader.class.php deleted file mode 100644 index 8ffa7dd6fa1400ab4c9cdfcb96055b3925b170f2..0000000000000000000000000000000000000000 --- a/week-15/image-upload/classes/Uploader.class.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php -class Uploader { - private $filename; - private $fileData; - private $destination; - - - public function __construct( $key ) { - $this->filename = $_FILES[$key]['name']; - $this->fileData = $_FILES[$key]['tmp_name']; - } - - public function saveIn( $folder ) { - $this->destination = $folder; - } - - public function save(){ - $folderIsWritAble = is_writable( $this->destination ); - if( $folderIsWritAble ){ - $name = "$this->destination/$this->filename"; - $success = move_uploaded_file( $this->fileData, $name ); - } else { - trigger_error("cannot write to $this->destination"); - $success = false; - } - return $success; - } - -} diff --git a/week-15/image-upload/css/layout.css b/week-15/image-upload/css/layout.css deleted file mode 100644 index 3868846b891e8a2c8cb030b4b9fc333e907b1e2d..0000000000000000000000000000000000000000 --- a/week-15/image-upload/css/layout.css +++ /dev/null @@ -1,4 +0,0 @@ -/* code listing for css/layout.css */ -h1{color:red;} - - diff --git a/week-15/image-upload/css/navigation.css b/week-15/image-upload/css/navigation.css deleted file mode 100644 index f1a7798ce40a48990bb2bae510826c8e881457e4..0000000000000000000000000000000000000000 --- a/week-15/image-upload/css/navigation.css +++ /dev/null @@ -1,15 +0,0 @@ -/* code listing for css/navigation.css*/ - -nav { -background-color: #CCCCDE; -padding-top: 10px; -} -nav a{ -display:inline-block; -text-decoration:none; -color: #000; -margin-left: 10px; -} -nav a:hover{text-decoration: underline;} - - diff --git a/week-15/image-upload/img/2009-a32-08-05-adorno-b.jpg b/week-15/image-upload/img/2009-a32-08-05-adorno-b.jpg deleted file mode 100644 index 4e896284f0a353698a1567dbd60fe9084352102b..0000000000000000000000000000000000000000 Binary files a/week-15/image-upload/img/2009-a32-08-05-adorno-b.jpg and /dev/null differ diff --git a/week-15/image-upload/index.php b/week-15/image-upload/index.php deleted file mode 100644 index b4ade3275eb5b04b19da78bc6e4715da5a592c11..0000000000000000000000000000000000000000 --- a/week-15/image-upload/index.php +++ /dev/null @@ -1,21 +0,0 @@ -<? - -error_reporting( E_ALL ); -ini_set( "display_errors", 1 ); - -$title = "oo image upload"; - -include 'templates/header.php'; -include 'views/navigation.php'; - -$userClicked = isset($_GET['page']); -if ( $userClicked ) { - $fileToLoad = $_GET['page']; -} else { - $fileToLoad = "gallery"; -} - -include_once "views/$fileToLoad.php"; - -include "templates/footer.php"; -?> diff --git a/week-15/image-upload/templates/footer.php b/week-15/image-upload/templates/footer.php deleted file mode 100644 index c7daecf98a9a2e125f67b2c906f17d67354852c7..0000000000000000000000000000000000000000 --- a/week-15/image-upload/templates/footer.php +++ /dev/null @@ -1,9 +0,0 @@ -<? - -$out = " -</body> -</html>"; - -echo $out; - -?> diff --git a/week-15/image-upload/templates/header.php b/week-15/image-upload/templates/header.php deleted file mode 100644 index 390cd9f8c6886f5b5a02e65580e8f30a4ee543f3..0000000000000000000000000000000000000000 --- a/week-15/image-upload/templates/header.php +++ /dev/null @@ -1,14 +0,0 @@ -<? - -$out = "<!DOCTYPE html> -<html> -<head> -<title>$title</title> -<link href='css/layout.css' rel='stylesheet' /> -<link href='css/navigation.css' rel='stylesheet' /> -</head> -<body>"; - -echo $out; - -?> diff --git a/week-15/image-upload/views/gallery.php b/week-15/image-upload/views/gallery.php deleted file mode 100644 index 5468198f78357f64b54dc460b0fe5386c8314952..0000000000000000000000000000000000000000 --- a/week-15/image-upload/views/gallery.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -return showImages(); - -function showImages(){ - $out = "<h1>Image Gallery</h1>"; - $out .= "<ul id='images'>"; - $folder = "img"; - $filesInFolder = new DirectoryIterator( $folder); - while ( $filesInFolder->valid() ) { - $file = $filesInFolder->current(); - $filename = $file->getFilename(); - $src = "$folder/$filename"; - $fileInfo = new Finfo( FILEINFO_MIME_TYPE ); - $mimeType = $fileInfo->file( $src ); - - if ( $mimeType === 'image/jpeg' ) { - $out .= "<li><img src='$src' /></li>"; - } - $filesInFolder->next(); - } - $out .= "</ul>"; - echo $out; - -} - -?> diff --git a/week-15/image-upload/views/navigation.php b/week-15/image-upload/views/navigation.php deleted file mode 100644 index 179b23e149073a22ef1abd4de79f93117f6e1ae0..0000000000000000000000000000000000000000 --- a/week-15/image-upload/views/navigation.php +++ /dev/null @@ -1,4 +0,0 @@ -<nav> - <a href='index.php?page=gallery'>Gallery</a> - <a href='index.php?page=upload'>Upload new image</a> -</nav> diff --git a/week-15/image-upload/views/upload.php b/week-15/image-upload/views/upload.php deleted file mode 100644 index ce9a840c9a885eed3d6219f0a3765736d4b3e173..0000000000000000000000000000000000000000 --- a/week-15/image-upload/views/upload.php +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -include_once "classes/Uploader.class.php"; -$content = ""; - -//$newImageSubmitted is TRUE if form was submitted, otherwise FALSE -$newImageSubmitted = isset( $_POST['new-image'] ); -if ( $newImageSubmitted ) { - $uploader = new Uploader( "image-data" ); - $uploader->saveIn("img"); - $fileUploaded = $uploader->save(); - if ( $fileUploaded ) { - $content .= "new file uploaded"; - } else { - $content .= "something went wrong"; - } -} - -$content .= "<h1>Upload new jpg images</h1> -<form method='post' action='index.php?page=upload' enctype='multipart/form-data' > - <label>Find a jpg image to upload</label> - <input type='file' name='image-data' accept='image/jpeg'/> - <input type='submit' value='upload' name='new-image' /> - </form>"; - -echo $content; - -?> - diff --git a/week-15/simple-classes/Rectangle.php b/week-15/simple-classes/Rectangle.php deleted file mode 100644 index ceee0837649f407e0032df06a04e703f4d1a9256..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/Rectangle.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php # Script 4.5 - Rectangle.php -/* This page defines the Rectangle class. - * The class contains two attributes: width and height. - * The class contains five methods: - * - __construct() - * - setSize() - * - getArea() - * - getPermeter() - * - isSquare() - */ - -class Rectangle { - - // Declare the attributes: - public $width = 0; - public $height = 0; - - // Constructor: - function __construct($w = 0, $h = 0) { - $this->width = $w; - $this->height = $h; - } - - // Method to set the dimensions: - function setSize($w = 0, $h = 0) { - $this->width = $w; - $this->height = $h; - } - - // Method to calculate and return the area: - function getArea() { - return ($this->width * $this->height); - } - - // Method to calculate and return the perimeter: - function getPerimeter() { - return ( ($this->width + $this->height) * 2 ); - } - - // Method to determine if the rectange - // is also a square. - function isSquare() { - if ($this->width == $this->height) { - return true; // Square - } else { - return false; // Not a square - } - - } - -} // End of Rectangle class. \ No newline at end of file diff --git a/week-15/simple-classes/Rectangle1.php b/week-15/simple-classes/Rectangle1.php deleted file mode 100644 index 57b2e4e304b88447e57c849a1493523b1d709b5a..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/Rectangle1.php +++ /dev/null @@ -1,36 +0,0 @@ -<? - -class Rectangle { - - // Declare the attributes: - public $width = 0; - public $height = 0; - - // Method to set the dimensions: - function setSize($w = 0, $h = 0) { - $this->width = $w; - $this->height = $h; - } - - // Method to calculate and return the area: - function getArea() { - return ($this->width * $this->height); - } - - // Method to calculate and return the perimeter: - function getPerimeter() { - return ( ($this->width + $this->height) * 2 ); - } - - // Method to determine if the rectange - // is also a square. - function isSquare() { - if ($this->width == $this->height) { - return true; // Square - } else { - return false; // Not a square - } - - } - -} // End of Rectangle class. diff --git a/week-15/simple-classes/Rectangle2.php b/week-15/simple-classes/Rectangle2.php deleted file mode 100644 index 1cc3b26212b51be9331c2418ccb7c66b2e1d5be4..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/Rectangle2.php +++ /dev/null @@ -1,42 +0,0 @@ -<? - -class Rectangle { - - // Declare the attributes: - public $width = 0; - public $height = 0; - - // Constructor: - function __construct($w = 0, $h = 0) { - $this->width = $w; - $this->height = $h; - } - - // Method to set the dimensions: - function setSize($w = 0, $h = 0) { - $this->width = $w; - $this->height = $h; - } - - // Method to calculate and return the area: - function getArea() { - return ($this->width * $this->height); - } - - // Method to calculate and return the perimeter: - function getPerimeter() { - return ( ($this->width + $this->height) * 2 ); - } - - // Method to determine if the rectange - // is also a square. - function isSquare() { - if ($this->width == $this->height) { - return true; // Square - } else { - return false; // Not a square - } - - } - -} // End of Rectangle class. diff --git a/week-15/simple-classes/cat.class.php b/week-15/simple-classes/cat.class.php deleted file mode 100644 index b848d2c84a9e375161d259b7632aba6c371fb610..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/cat.class.php +++ /dev/null @@ -1,16 +0,0 @@ -<? -/* Cat class extends Pet. - * Cat overrides play(). - */ -class Cat extends Pet { - function play() { - - // Call the Pet::play() method: - parent::play(); - - echo "<p>$this->name is climbing.</p>"; - } -} // End of Cat class. - - -?> diff --git a/week-15/simple-classes/dog.class.php b/week-15/simple-classes/dog.class.php deleted file mode 100644 index 3cd9b0951fef758b24e947f0f20cc8009d742dfd..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/dog.class.php +++ /dev/null @@ -1,17 +0,0 @@ -<? -/* Dog class extends Pet. - * Dog overrides play(). - */ -class Dog extends Pet { - function play() { - - // Call the Pet::play() method: - parent::play(); - - echo "<p>$this->name is fetching.</p>"; - } -} // End of Dog class. - - - -?> diff --git a/week-15/simple-classes/pet.class.php b/week-15/simple-classes/pet.class.php deleted file mode 100644 index 055c4be72ad4c7bac8ac6bb8c634e9bed9a7cf7b..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/pet.class.php +++ /dev/null @@ -1,19 +0,0 @@ -<? -class Pet { - public $name; - function __construct($pet_name) { - $this->name = $pet_name; - self::sleep(); - } - function eat() { - echo "<p>$this->name is eating.</p>"; - } - function sleep() { - echo "<p>$this->name is sleeping.</p>"; - } - function play() { - echo "<p>$this->name is playing.</p>"; - } -} // End of Pet class. -?> - diff --git a/week-15/simple-classes/pets1.php b/week-15/simple-classes/pets1.php deleted file mode 100644 index 97391f084dc158c269213d25a7cb509bf5d2520b..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/pets1.php +++ /dev/null @@ -1,65 +0,0 @@ -<? -class Pet { - - // Declare the attributes: - public $name; - - // Constructor assigns the pet's name: - function __construct($pet_name) { - $this->name = $pet_name; - } - - // Pets can eat: - function eat() { - echo "<p>$this->name is eating.</p>"; - } - - // Pets can sleep: - function sleep() { - echo "<p>$this->name is sleeping.</p>"; - } - -} // End of Pet class. - -/* Cat class extends Pet. - * Cat has additional method: climb(). - */ -class Cat extends Pet { - function climb() { - echo "<p>$this->name is climbing.</p>"; - } -} // End of Cat class. - -/* Dog class extends Pet. - * Dog has additional method: fetch(). - */ -class Dog extends Pet { - function fetch() { - echo "<p>$this->name is fetching.</p>"; - } -} // End of Dog class. - -# ***** END OF CLASSES ***** # - -// Create a dog: -$dog = new Dog('Rover'); - -// Create a cat: -$cat = new Cat('Whiskers'); - -// Feed them: -$dog->eat(); -$cat->eat(); - -// Nap time: -$dog->sleep(); -$cat->sleep(); - -// Do animal-specific thing: -$dog->fetch(); -$cat->climb(); - -// Delete the objects: -unset($dog, $cat); - -?> diff --git a/week-15/simple-classes/pets2.php b/week-15/simple-classes/pets2.php deleted file mode 100644 index 99157e6c83419851263eee63228f88bd2f19ddea..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/pets2.php +++ /dev/null @@ -1,68 +0,0 @@ -<? -class Pet { - public $name; - function __construct($pet_name) { - $this->name = $pet_name; - } - function eat() { - echo "<p>$this->name is eating.</p>"; - } - function sleep() { - echo "<p>$this->name is sleeping.</p>"; - } - - // Pets can play: - function play() { - echo "<p>$this->name is playing.</p>"; - } - -} // End of Pet class. - -/* Cat class extends Pet. - * Cat overrides play(). - */ -class Cat extends Pet { - function play() { - echo "<p>$this->name is climbing.</p>"; - } -} // End of Cat class. - -/* Dog class extends Pet. - * Dog overrides play(). - */ -class Dog extends Pet { - function play() { - echo "<p>$this->name is fetching.</p>"; - } -} // End of Dog class. - -# ***** END OF CLASSES ***** # - -// Create a dog: -$dog = new Dog('Rover'); - -// Create a cat: -$cat = new Cat('Whiskers'); - -// Create an unknown type of pet: -$pet = new Pet('Rob'); - -// Feed them: -$dog->eat(); -$cat->eat(); -$pet->eat(); - -// Nap time: -$dog->sleep(); -$cat->sleep(); -$pet->sleep(); - -// Have them play: -$dog->play(); -$cat->play(); -$pet->play(); - -// Delete the objects: -unset($dog, $cat, $pet); - -?> diff --git a/week-15/simple-classes/pets3.php b/week-15/simple-classes/pets3.php deleted file mode 100644 index a00574b2e91bd88df1b4d94e46d59b11a45a2377..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/pets3.php +++ /dev/null @@ -1,96 +0,0 @@ -<!doctype html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <title>Pets</title> - <link rel="stylesheet" href="style.css"> -</head> -<body> -<?php # Script 5.5 - pets3.php -// This page defines and uses the Pet, Cat, and Dog classes. - -# ***** CLASSES ***** # - -/* Class Pet. - * The class contains one attribute: name. - * The class contains four methods: - * - __construct() - * - eat() - * - sleep() - * - play() - */ -class Pet { - public $name; - function __construct($pet_name) { - $this->name = $pet_name; - self::sleep(); - } - function eat() { - echo "<p>$this->name is eating.</p>"; - } - function sleep() { - echo "<p>$this->name is sleeping.</p>"; - } - function play() { - echo "<p>$this->name is playing.</p>"; - } -} // End of Pet class. - -/* Cat class extends Pet. - * Cat overrides play(). - */ -class Cat extends Pet { - function play() { - - // Call the Pet::play() method: - parent::play(); - - echo "<p>$this->name is climbing.</p>"; - } -} // End of Cat class. - -/* Dog class extends Pet. - * Dog overrides play(). - */ -class Dog extends Pet { - function play() { - - // Call the Pet::play() method: - parent::play(); - - echo "<p>$this->name is fetching.</p>"; - } -} // End of Dog class. - -# ***** END OF CLASSES ***** # - -// Create a dog: -$dog = new Dog('Satchel'); - -// Create a cat: -$cat = new Cat('Bucky'); - -// Create an unknown type of pet: -$pet = new Pet('Rob'); - -// Feed them: -$dog->eat(); -$cat->eat(); -$pet->eat(); - -// Nap time: -$dog->sleep(); -$cat->sleep(); -$pet->sleep(); - -// Have them play: -$dog->play(); -$cat->play(); -$pet->play(); - -// Delete the objects: -unset($dog, $cat, $pet); - -?> -</body> -</html> \ No newline at end of file diff --git a/week-15/simple-classes/pets4.php b/week-15/simple-classes/pets4.php deleted file mode 100644 index 9731d24f952d3d7d41d6783a27ebf828740687a8..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/pets4.php +++ /dev/null @@ -1,47 +0,0 @@ -<!doctype html> -<html lang="en"> -<head> - <meta charset="utf-8"> - <title>Pets</title> - <link rel="stylesheet" href="style.css"> -</head> -<body> -<?php # Script 5.5 - pets3.php -// This page defines and uses the Pet, Cat, and Dog classes. - -spl_autoload_register(function ($class_name) { - $class_name = strtolower($class_name); - include $class_name . '.class.php'; -}); - - -// Create a dog: -$dog = new Dog('Satchel'); - -// Create a cat: -$cat = new Cat('Bucky'); - -// Create an unknown type of pet: -$pet = new Pet('Rob'); - -// Feed them: -$dog->eat(); -$cat->eat(); -$pet->eat(); - -// Nap time: -$dog->sleep(); -$cat->sleep(); -$pet->sleep(); - -// Have them play: -$dog->play(); -$cat->play(); -$pet->play(); - -// Delete the objects: -unset($dog, $cat, $pet); - -?> -</body> -</html> diff --git a/week-15/simple-classes/rectangle1.php b/week-15/simple-classes/rectangle1.php deleted file mode 100644 index b72ba69f1c660de63a541cc2f3b8e2a4d45363b6..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/rectangle1.php +++ /dev/null @@ -1,37 +0,0 @@ -<? - -// Include the class definition: -require('Rectangle1.php'); - -// Define the necessary variables: -$width = 42; -$height = 7; - -// Print a little introduction: -echo "<h2>With a width of $width and a height of $height...</h2>"; - -// Create a new object: -$r = new Rectangle(); - -// Assign the rectangle dimensions: -$r->setSize($width, $height); - -// Print the area: -echo '<p>The area of the rectangle is ' . $r->getArea() . '</p>'; - -// Print the perimeter: -echo '<p>The perimeter of the rectangle is ' . $r->getPerimeter() . '</p>'; - -// Is this a square? -echo '<p>This rectangle is '; -if ($r->isSquare()) { - echo 'also'; -} else { - echo 'not'; -} -echo ' a square.</p>'; - -// Delete the object: -unset($r); - -?> diff --git a/week-15/simple-classes/rectangle2.php b/week-15/simple-classes/rectangle2.php deleted file mode 100644 index 90bab3187916da219930c2e78317f58918652d9e..0000000000000000000000000000000000000000 --- a/week-15/simple-classes/rectangle2.php +++ /dev/null @@ -1,35 +0,0 @@ -<? - -// Include the class definition: -require('Rectangle2.php'); - -// Define the necessary variables: -$width = 160; -$height = 75; - -// Print a little introduction: -echo "<h2>With a width of $width and a height of $height...</h2>"; - -// Create a new object: -$r = new Rectangle($width, $height); - -// Print the area. -echo '<p>The area of the rectangle is ' . $r->getArea() . '</p>'; - -// Print the perimeter. -echo '<p>The perimeter of the rectangle is ' . $r->getPerimeter() . '</p>'; - -// Is this a square? -echo '<p>This rectangle is '; -if ($r->isSquare()) { - echo 'also'; -} else { - echo 'not'; -} -echo ' a square.</p>'; - -// Delete the object: -unset($r); - -?> - diff --git a/week-2/record-store-app/sql/dummy_data.sql b/week-2/record-store-app/sql/dummy_data.sql deleted file mode 100644 index 3db28062e748efc9d7b047191be44ca7d802bcef..0000000000000000000000000000000000000000 --- a/week-2/record-store-app/sql/dummy_data.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs') -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (id, title, artist_id, genre, year, price) -VALUES -(NULL, 'Catch A Fire', NULL, 'Reggae', 1973, 20.99 ), -(NULL, 'Sunday Coming', NULL, 'Reggae', 1970, 15.99 ); diff --git a/week-2/record-store-app/sql/practice_queries.sql b/week-2/record-store-app/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-2/record-store-app/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-2/record-store-app/sql/record-store.sql b/week-2/record-store-app/sql/record-store.sql deleted file mode 100644 index 670b774261b12ce491f60063c110feb151eb39e0..0000000000000000000000000000000000000000 --- a/week-2/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -); - -/* Define table for storing records (products) */ -CREATE TABLE record ( - id INT AUTO_INCREMENT, - title VARCHAR(50), - artist_id INT, - genre TINYTEXT, - year YEAR(4), - price DECIMAL(10, 2) unsigned, - PRIMARY KEY (id), - FOREIGN KEY (artist_id) - REFERENCES artist (id) -); diff --git a/week-3/record-store-app/artist.php b/week-3/record-store-app/artist.php deleted file mode 100644 index f50a022e9deabe0593846f1d65dfaafd19368140..0000000000000000000000000000000000000000 --- a/week-3/record-store-app/artist.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'YOUR_USERNAME', - 'YOUR_PASSWORD', - 'YOUR_DB_NAME' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - exit(mysqli_connect_error()); -} - -/* fetch a result set */ -$sql = "SELECT first_name, last_name FROM artist"; -$result = mysqli_query($link, $sql); - -/* check query returned a result */ -if ($result === false) { - echo mysqli_error($link); -} else { - /* fetch associative array */ - while ($row = mysqli_fetch_assoc($result)) { - echo($row['first_name']." (".$row['last_name'].") "); - } - /* free result set */ - mysqli_free_result($result); -} - -/* close the connection to the database */ -mysqli_close($link) - -?> \ No newline at end of file diff --git a/week-3/record-store-app/index.php b/week-3/record-store-app/index.php deleted file mode 100644 index 6ef98ce6dc6a4d7bc970e3b56e411b7279a11c52..0000000000000000000000000000000000000000 --- a/week-3/record-store-app/index.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'YOUR_USERNAME', - 'YOUR_PASSWORD', - 'YOUR_DB_NAME' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - exit(mysqli_connect_error()); -} - -/* fetch a result set */ -$sql = "SELECT title, genre FROM record"; -$result = mysqli_query($link, $sql); - -/* check query returned a result */ -if ($result === false) { - echo mysqli_error($link); -} else { - // $row_cnt = mysqli_num_rows($result); - // echo $row_cnt - /* fetch associative array */ - while ($row = mysqli_fetch_assoc($result)) { - echo($row['title']." (".$row['genre'].") "); - } - /* free result set */ - mysqli_free_result($result); -} - -/* close the connection to the database */ -mysqli_close($link) - -?> \ No newline at end of file diff --git a/week-3/record-store-app/sql/dummy_data.sql b/week-3/record-store-app/sql/dummy_data.sql deleted file mode 100644 index 3db28062e748efc9d7b047191be44ca7d802bcef..0000000000000000000000000000000000000000 --- a/week-3/record-store-app/sql/dummy_data.sql +++ /dev/null @@ -1,14 +0,0 @@ -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs') -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (id, title, artist_id, genre, year, price) -VALUES -(NULL, 'Catch A Fire', NULL, 'Reggae', 1973, 20.99 ), -(NULL, 'Sunday Coming', NULL, 'Reggae', 1970, 15.99 ); diff --git a/week-3/record-store-app/sql/practice_queries.sql b/week-3/record-store-app/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-3/record-store-app/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-3/record-store-app/sql/record-store.sql b/week-3/record-store-app/sql/record-store.sql deleted file mode 100644 index 670b774261b12ce491f60063c110feb151eb39e0..0000000000000000000000000000000000000000 --- a/week-3/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -); - -/* Define table for storing records (products) */ -CREATE TABLE record ( - id INT AUTO_INCREMENT, - title VARCHAR(50), - artist_id INT, - genre TINYTEXT, - year YEAR(4), - price DECIMAL(10, 2) unsigned, - PRIMARY KEY (id), - FOREIGN KEY (artist_id) - REFERENCES artist (id) -); diff --git a/week-4/record-store-app/README.txt b/week-4/record-store-app/README.txt deleted file mode 100644 index eec341ca6d1cbe903247007832458bfa6cc8acef..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/README.txt +++ /dev/null @@ -1,24 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -Description ------------ -This is a demo record store application. You can use it to help you complete lab 4. It is You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -+ Check you have a LAMP stack installed with PHP>5 and MySQL>5 -+ Upload the application to your web root folder. -+ Run the record-store.sql file on your database. -+ Run the dummy_data.sql file to insert some data. - -Configuration Instructions --------------------------- -Modify the includes/db_connect.php script with your MySQL database credentials. - - diff --git a/week-4/record-store-app/includes/db_connect.php b/week-4/record-store-app/includes/db_connect.php deleted file mode 100644 index 8787faffe2d71c2d84ecf636ca17892334d3bf90..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/includes/db_connect.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* Open a new connection to the MySQL server */ - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'YOUR_USERNAME', - 'YOUR_PASSWORD', - 'YOUR_DB_NAME' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); -} - -?> \ No newline at end of file diff --git a/week-4/record-store-app/index.php b/week-4/record-store-app/index.php deleted file mode 100644 index 6245c3483057fa8f9716e7da79f5094473668dc1..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/index.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -// connect to the database -require('includes/db_connect.php'); - -// include the header HTML -include('templates/header.html'); - -// include the navigation HTML -include('templates/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('templates/footer.html'); - -?> diff --git a/week-4/record-store-app/sql/dummy_data.sql b/week-4/record-store-app/sql/dummy_data.sql deleted file mode 100644 index 8b8d90f92c62e19736c9cdf8daab56bb2da72981..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/sql/dummy_data.sql +++ /dev/null @@ -1,25 +0,0 @@ -/* Drop all existing records from these tables */ -DELETE FROM artist; -DELETE FROM record; - -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs'), -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (id, title, artist_id, genre, year, price) -VALUES -(NULL, 'Soul Rebel', NULL, 'Reggae', 1970, 25.99 ), -(NULL, 'Catch A Fire', NULL, 'Reggae', 1973, 25.99 ), -(NULL, 'Natty Dread', NULL, 'Reggae', 1974, 20.99 ), -(NULL, 'Babylon By Bus', NULL, 'Reggae', 1978, 24.99 ), -(NULL, 'Night Nurse', NULL, 'Reggae', 1982, 17.99 ), -(NULL, 'Mr Issacs', NULL, 'Reggae', 1982, 9.99 ), -(NULL, 'Black and Dekker', NULL, 'Reggae', 1980, 19.99 ), -(NULL, 'Sunday Coming', NULL, 'Reggae', 1970, 15.99 ); - diff --git a/week-4/record-store-app/sql/practice_queries.sql b/week-4/record-store-app/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-4/record-store-app/sql/record-store.sql b/week-4/record-store-app/sql/record-store.sql deleted file mode 100644 index c96ba60dd73b98134d9363da180b5aa5c34f8211..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,58 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS record, artist, customer, transaction, orderline; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -); - -/* Define table for storing records (products) */ -CREATE TABLE record ( - id INT AUTO_INCREMENT, - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price DECIMAL(10, 2) unsigned NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (artist_id) - REFERENCES artist (id) -); - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address_1 VARCHAR(50) NOT NULL, - address_2 VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - PRIMARY KEY (id) -); - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -); - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - product_id INT, - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (product_id) - REFERENCES record(id) -); diff --git a/week-4/record-store-app/templates/footer.html b/week-4/record-store-app/templates/footer.html deleted file mode 100644 index 2ab5c0d1fc7b0e6c12fb00bf177037f64450298c..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - </body> -</html> diff --git a/week-4/record-store-app/templates/header.html b/week-4/record-store-app/templates/header.html deleted file mode 100644 index 373b26f6655d85da48d4aa6febcbb98372f0d451..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/templates/header.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Record Store</title> - </head> - <body> \ No newline at end of file diff --git a/week-4/record-store-app/templates/navigation.html b/week-4/record-store-app/templates/navigation.html deleted file mode 100644 index 1f88a9ef2560ca8b89c6727cd796a5f5001777f7..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/templates/navigation.html +++ /dev/null @@ -1,7 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=artist" title="artists">Artists</a></li> - </ul> -</nav> diff --git a/week-4/record-store-app/views/404.php b/week-4/record-store-app/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-4/record-store-app/views/artist.php b/week-4/record-store-app/views/artist.php deleted file mode 100644 index 73697e6cbc47c4b3d239241336bb0b03c25a9e7d..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/views/artist.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Artists</h1>"; - -// fetch records as a result set -$sql = "SELECT first_name, last_name FROM artist"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'><tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['first_name']."</td>"; - $content .= "<td>".$row['last_name']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-4/record-store-app/views/home.php b/week-4/record-store-app/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-4/record-store-app/views/record.php b/week-4/record-store-app/views/record.php deleted file mode 100644 index e4ea6a3dd8eaaa1f2901455927d808c0fd75d01f..0000000000000000000000000000000000000000 --- a/week-4/record-store-app/views/record.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; - -// fetch records as a result set -$sql = "SELECT title, genre, price FROM record"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'><tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/README.txt b/week-5/record-store-app/README.txt deleted file mode 100644 index b685e0dbc6dc34d976593f51e27965437a9f274c..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -Description ------------ -This is a demo record store application. You can use it to help you complete lab 5. It is You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -+ Check you have a LAMP stack installed with PHP>5 and MySQL>5 -+ Upload the application to your web root folder. -+ Run the record-store.sql file on your database. -+ Run the dummy_data.sql file to insert some data. - -Configuration Instructions --------------------------- -Modify the includes/db_connect.php script with your MySQL database credentials. \ No newline at end of file diff --git a/week-5/record-store-app/includes/db_connect.php b/week-5/record-store-app/includes/db_connect.php deleted file mode 100644 index 8787faffe2d71c2d84ecf636ca17892334d3bf90..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/includes/db_connect.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* Open a new connection to the MySQL server */ - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'YOUR_USERNAME', - 'YOUR_PASSWORD', - 'YOUR_DB_NAME' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); -} - -?> \ No newline at end of file diff --git a/week-5/record-store-app/index.php b/week-5/record-store-app/index.php deleted file mode 100644 index 904628711e62c0371f6fd6c9c2b283b4844fb77f..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/index.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -// connect to the database -require('includes/db_connect.php'); - -// include the header HTML -include('templates/header.html'); - -// include the navigation HTML -include('templates/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -case 'orders' : - include 'views/orders.php'; - break; -case 'order' : - include 'views/order.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('templates/footer.html'); - -?> diff --git a/week-5/record-store-app/sql/dummy_data.sql b/week-5/record-store-app/sql/dummy_data.sql deleted file mode 100644 index 9a8c9eab7481a0d2ed4eb3c7657c6961190f4d8b..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/sql/dummy_data.sql +++ /dev/null @@ -1,51 +0,0 @@ -/* Note that, because foreign key values are being -inserted manually, tables must be recreated before running -this code in order to reset AUTO_INCREMENT */ - -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs'), -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (ean, title, artist_id, genre, year, price) -VALUES -('00562056', 'Soul Rebel', 1, 'Reggae', 1970, 25.99 ), -('50264967', 'Catch A Fire', 1, 'Reggae', 1973, 25.99 ), -('00748396', 'Natty Dread', 1, 'Reggae', 1974, 20.99 ), -('00495739', 'Babylon By Bus', 1, 'Reggae', 1978, 24.99 ), -('00738432', 'Legalize It', 2, 'Reggae', 1976, 22.99 ), -('50847583', 'Bush Doctor', 2, 'Reggae', 1978, 20.99 ), -('30748743', 'Marcus Garvey', 3, 'Reggae', 1975, 24.99 ), -('50856384', 'Night Nurse', 5, 'Reggae', 1982, 17.99 ), -('50264972', 'Mr Issacs', 5, 'Reggae', 1982, 9.99 ), -('00649573', 'Black and Dekker', 6, 'Reggae', 1980, 19.99 ), -('00625485', 'Sunday Coming', 4, 'Reggae', 1970, 15.99 ); - -INSERT INTO customer (id, first_name, last_name, email_address, address_1, address_2, postcode) -VALUES -(NULL, 'John', 'Smith', 'john@smith.com', '1 Fake Street', 'London', 'SE3 5RD'), -(NULL, 'Sukie', 'Bapswent', 's.baps@gmail.com', '64 The Terrace', 'Whitby', 'YO65 3TR'), -(NULL, 'John', 'Thumb', 'jthumb@gmail.com', '25 Fantasy Grove', 'Brighton', 'BR2 6LV'); - -INSERT INTO transaction (id, customer_id, delivery_method, dt_date) -VALUES -(NULL, 1, 2, '2015-07-01 14:34:58'), -(NULL, 1, 2, '2015-04-01 11:22:35'), -(NULL, 3, 1, '2015-04-01 19:47:03'), -(NULL, 2, 1, '2015-05-11 22:01:19'); - -INSERT INTO orderline (id, transaction_id, record_ean, quantity) -VALUES -(NULL, 1, '00562056', 1), -(NULL, 1, '00495739', 1), -(NULL, 2, '00649573', 2), -(NULL, 2, '00495739', 1), -(NULL, 3, '00738432', 2), -(NULL, 3, '00562056', 1), -(NULL, 3, '00625485', 1), -(NULL, 4, '00562056', 2); diff --git a/week-5/record-store-app/sql/practice_queries.sql b/week-5/record-store-app/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-5/record-store-app/sql/record-store.sql b/week-5/record-store-app/sql/record-store.sql deleted file mode 100644 index 4017cc24509bcd61c384e7e2a47742240813b00c..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,62 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS orderline, transaction, customer, record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -) ENGINE=InnoDB; - -/* Define table for storing records (products) */ -CREATE TABLE record ( - ean VARCHAR(8), - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price DECIMAL(10, 2) unsigned NOT NULL, - PRIMARY KEY (ean), - FOREIGN KEY (artist_id) - REFERENCES artist (id) - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address_1 VARCHAR(50) NOT NULL, - address_2 VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - dt_date DATETIME, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -) ENGINE=InnoDB; - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - record_ean VARCHAR(8), - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (record_ean) - REFERENCES record(ean) - ON UPDATE CASCADE - ON DELETE CASCADE -) ENGINE=InnoDB; diff --git a/week-5/record-store-app/templates/footer.html b/week-5/record-store-app/templates/footer.html deleted file mode 100644 index 2ab5c0d1fc7b0e6c12fb00bf177037f64450298c..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - </body> -</html> diff --git a/week-5/record-store-app/templates/header.html b/week-5/record-store-app/templates/header.html deleted file mode 100644 index 373b26f6655d85da48d4aa6febcbb98372f0d451..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/templates/header.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Record Store</title> - </head> - <body> \ No newline at end of file diff --git a/week-5/record-store-app/templates/navigation.html b/week-5/record-store-app/templates/navigation.html deleted file mode 100644 index aadcc9683a7940b42de50a6dc07aa124ece476dc..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/templates/navigation.html +++ /dev/null @@ -1,7 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=orders" title="orders">Orders</a></li> - </ul> -</nav> diff --git a/week-5/record-store-app/views/404.php b/week-5/record-store-app/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/artist.php b/week-5/record-store-app/views/artist.php deleted file mode 100644 index ea371d7e2a7a6057ea88edcd8afe2edd4020a582..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/artist.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -// check if id parameter was not set in query string -if (!isset($_GET['id'])) { - - // define $content with suitable message - $content = "<h1>I don't know which artist you're looking for...</h1>"; - -} else { // id was set, so carry on... - - // define $artist_id variable and assign value of id parameter - $artist_id = $_GET['id']; - - // fetch record titles for artist with id matching $artist_id - $sql = "SELECT r.title, r.year, r.price, a.first_name, a.last_name - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - WHERE a.id=".$artist_id." - ORDER BY year ASC"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // define a row counter - $i = 0; - - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - - // do this if we are on first row - if ($i == 0) { - - // initialise $content string, assigning it a page header - $content = "<h1>".$row['first_name']." ".$row['last_name']." Records</h1>"; - // append $content string with table definition - $content .= "<table border='1'><tbody>"; - - } - - // append table rows to $content string - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['year']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "</tr>"; - - // increment the row counter - $i++; - - } - - // append $content string with closing table tags - $content .= "</tbody></table>"; - - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/home.php b/week-5/record-store-app/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/order.php b/week-5/record-store-app/views/order.php deleted file mode 100644 index a1af92d0b34bcaaf9bee4a5676ae3c8e58b27034..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/order.php +++ /dev/null @@ -1,72 +0,0 @@ -<?php -/* ************************************************************** -* TASK 2: Create a view which: * -* - outputs the order details for an order based * -* on the value of the order_id parameter * -* - for each item in the order, the following * -* details should be displayed: * -* | EAN | TITLE | QUANTITY | PRICE | SUBTOTAL | * -* - the order total should also be displayed. * -****************************************************************/ - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "INSERT YOUR SQL QUERY HERE!"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = 0.00; // <-- CALCULATE SUBTOTAL! - $total = 0.00; // <-- KEEP RUNNING ORDER TOTAL! - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/order_example.php b/week-5/record-store-app/views/order_example.php deleted file mode 100644 index 0f81c631d898204086a592a060e6341c59a16f20..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/order_example.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price - FROM record r - INNER JOIN orderline ol - ON ol.record_ean=r.ean - WHERE ol.transaction_id=".$order_id; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = $row['quantity'] * $row['price']; - $total = $total + $subtotal; - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/orders.php b/week-5/record-store-app/views/orders.php deleted file mode 100644 index 5dd6ca5fd302753a7eec2e4aadc85931ad58097c..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/orders.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -/* ************************************************************** -* TASK 1: Create a view which: * -* - outputs a list of all transactions (orders) * -* - the orders should be grouped by customer ID * -* - each transaction links to an `order' view, setting a * -* parameter `order_id' in the URL query string * -****************************************************************/ - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "INSERT YOUR SQL STATEMENT HERE!"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/orders_example.php b/week-5/record-store-app/views/orders_example.php deleted file mode 100644 index d1228914e88edccc204d29b7380dabe43fd36aa7..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/orders_example.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "SELECT id, customer_id FROM transaction - ORDER BY customer_id"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) -{ - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>"; - $content .= "<td>".$row['customer_id']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-5/record-store-app/views/record.php b/week-5/record-store-app/views/record.php deleted file mode 100644 index 6c2c4f18a6fcca940c7e854893d4b9235e987abf..0000000000000000000000000000000000000000 --- a/week-5/record-store-app/views/record.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; - -// fetch records as a result set -$sql = "SELECT r.title, a.first_name, a.last_name, r.genre, r.price, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - ORDER BY r.title, r.price DESC"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'><tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-6/record-store-app/README.txt b/week-6/record-store-app/README.txt deleted file mode 100644 index b685e0dbc6dc34d976593f51e27965437a9f274c..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/README.txt +++ /dev/null @@ -1,22 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -Description ------------ -This is a demo record store application. You can use it to help you complete lab 5. It is You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -+ Check you have a LAMP stack installed with PHP>5 and MySQL>5 -+ Upload the application to your web root folder. -+ Run the record-store.sql file on your database. -+ Run the dummy_data.sql file to insert some data. - -Configuration Instructions --------------------------- -Modify the includes/db_connect.php script with your MySQL database credentials. \ No newline at end of file diff --git a/week-6/record-store-app/includes/db_connect.php b/week-6/record-store-app/includes/db_connect.php deleted file mode 100644 index 8787faffe2d71c2d84ecf636ca17892334d3bf90..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/includes/db_connect.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* Open a new connection to the MySQL server */ - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'YOUR_USERNAME', - 'YOUR_PASSWORD', - 'YOUR_DB_NAME' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); -} - -?> \ No newline at end of file diff --git a/week-6/record-store-app/index.php b/week-6/record-store-app/index.php deleted file mode 100644 index 2995f49f0512f6201fbb09d743f8a2e2a80704d7..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/index.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -// connect to the database -require('includes/db_connect.php'); - -// include the header HTML -include('templates/header.html'); - -// include the navigation HTML -include('templates/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -case 'orders' : - include 'views/orders.php'; - break; -case 'order' : - include 'views/order.php'; - break; -case 'add-record' : - include 'views/add-record.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('templates/footer.html'); - -?> \ No newline at end of file diff --git a/week-6/record-store-app/sql/dummy_data.sql b/week-6/record-store-app/sql/dummy_data.sql deleted file mode 100644 index 9a8c9eab7481a0d2ed4eb3c7657c6961190f4d8b..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/sql/dummy_data.sql +++ /dev/null @@ -1,51 +0,0 @@ -/* Note that, because foreign key values are being -inserted manually, tables must be recreated before running -this code in order to reset AUTO_INCREMENT */ - -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs'), -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (ean, title, artist_id, genre, year, price) -VALUES -('00562056', 'Soul Rebel', 1, 'Reggae', 1970, 25.99 ), -('50264967', 'Catch A Fire', 1, 'Reggae', 1973, 25.99 ), -('00748396', 'Natty Dread', 1, 'Reggae', 1974, 20.99 ), -('00495739', 'Babylon By Bus', 1, 'Reggae', 1978, 24.99 ), -('00738432', 'Legalize It', 2, 'Reggae', 1976, 22.99 ), -('50847583', 'Bush Doctor', 2, 'Reggae', 1978, 20.99 ), -('30748743', 'Marcus Garvey', 3, 'Reggae', 1975, 24.99 ), -('50856384', 'Night Nurse', 5, 'Reggae', 1982, 17.99 ), -('50264972', 'Mr Issacs', 5, 'Reggae', 1982, 9.99 ), -('00649573', 'Black and Dekker', 6, 'Reggae', 1980, 19.99 ), -('00625485', 'Sunday Coming', 4, 'Reggae', 1970, 15.99 ); - -INSERT INTO customer (id, first_name, last_name, email_address, address_1, address_2, postcode) -VALUES -(NULL, 'John', 'Smith', 'john@smith.com', '1 Fake Street', 'London', 'SE3 5RD'), -(NULL, 'Sukie', 'Bapswent', 's.baps@gmail.com', '64 The Terrace', 'Whitby', 'YO65 3TR'), -(NULL, 'John', 'Thumb', 'jthumb@gmail.com', '25 Fantasy Grove', 'Brighton', 'BR2 6LV'); - -INSERT INTO transaction (id, customer_id, delivery_method, dt_date) -VALUES -(NULL, 1, 2, '2015-07-01 14:34:58'), -(NULL, 1, 2, '2015-04-01 11:22:35'), -(NULL, 3, 1, '2015-04-01 19:47:03'), -(NULL, 2, 1, '2015-05-11 22:01:19'); - -INSERT INTO orderline (id, transaction_id, record_ean, quantity) -VALUES -(NULL, 1, '00562056', 1), -(NULL, 1, '00495739', 1), -(NULL, 2, '00649573', 2), -(NULL, 2, '00495739', 1), -(NULL, 3, '00738432', 2), -(NULL, 3, '00562056', 1), -(NULL, 3, '00625485', 1), -(NULL, 4, '00562056', 2); diff --git a/week-6/record-store-app/sql/practice_queries.sql b/week-6/record-store-app/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-6/record-store-app/sql/record-store.sql b/week-6/record-store-app/sql/record-store.sql deleted file mode 100644 index 7256dafc37c21d819b4822d6489e4d2c4b89505a..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,62 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS orderline, transaction, customer, record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -) ENGINE=InnoDB; - -/* Define table for storing records (products) */ -CREATE TABLE record ( - ean CHAR(8) NOT NULL, - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price DECIMAL(10, 2) unsigned NOT NULL, - PRIMARY KEY (ean), - FOREIGN KEY (artist_id) - REFERENCES artist (id) - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address_1 VARCHAR(50) NOT NULL, - address_2 VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - dt_date DATETIME, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -) ENGINE=InnoDB; - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - record_ean CHAR(8), - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (record_ean) - REFERENCES record(ean) - ON UPDATE CASCADE - ON DELETE CASCADE -) ENGINE=InnoDB; diff --git a/week-6/record-store-app/templates/footer.html b/week-6/record-store-app/templates/footer.html deleted file mode 100644 index 2ab5c0d1fc7b0e6c12fb00bf177037f64450298c..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - </body> -</html> diff --git a/week-6/record-store-app/templates/header.html b/week-6/record-store-app/templates/header.html deleted file mode 100644 index 373b26f6655d85da48d4aa6febcbb98372f0d451..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/templates/header.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Record Store</title> - </head> - <body> \ No newline at end of file diff --git a/week-6/record-store-app/templates/navigation.html b/week-6/record-store-app/templates/navigation.html deleted file mode 100644 index bf4662e22bc2e6ec6da0e51e4b4a36b00d810db4..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/templates/navigation.html +++ /dev/null @@ -1,8 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=orders" title="orders">Orders</a></li> - <li><a href="?page=add-record" title="add record">Add record</a></li> - </ul> -</nav> diff --git a/week-6/record-store-app/views/404.php b/week-6/record-store-app/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-6/record-store-app/views/add-record-insecure.php b/week-6/record-store-app/views/add-record-insecure.php deleted file mode 100644 index 841a5078b968ebf2b18cb97286ab6e8f9d03bbfc..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/add-record-insecure.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -$action = $_SERVER["PHP_SELF"]."?page=add-record"; - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = $_POST["ean"]; - $title = $_POST["title"]; - $artist_id = $_POST["artist_id"]; - $genre = $_POST["genre"]; - $year = $_POST["year"]; - $price = $_POST["price"]; - - // define the insertion query - $sql = "INSERT INTO record (ean, title, artist_id, genre, year, price) - VALUES ('$ean', '$title', '$artist_id', '$genre', '$year', '$price')"; - - // run the query to insert the data - $result = mysqli_query($link, $sql); - - // check if the query went ok - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "Record successfully added to database."; - } -} - -// ------- END form processing code... ------- - -// output the html -echo($content); - -?> diff --git a/week-6/record-store-app/views/add-record.php b/week-6/record-store-app/views/add-record.php deleted file mode 100644 index 12325406ed0e1a1e8fcdd6ab48e789897436031f..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/add-record.php +++ /dev/null @@ -1,111 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -// -> htmlspecialchars() is used to replace special characters with HTML entities */ -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=add-record"); - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define a function to sanitise user input (this would ideally be in includes folder) -// helps protect against XSS -function clean_input($data) { - $data = trim($data); // strips unnecessary characters from beginning/end - $data = stripslashes($data); // remove backslashes - $data = htmlspecialchars($data); // replace special characters with HTML entities - return $data; -} - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = mysqli_real_escape_string($link, clean_input($_POST["ean"])); - $title = mysqli_real_escape_string($link, clean_input($_POST["title"])); - $artist_id = mysqli_real_escape_string($link, clean_input($_POST["artist_id"]); - $genre = mysqli_real_escape_string($link, clean_input($_POST["genre"])); - $year = mysqli_real_escape_string($link, clean_input($_POST["year"])); - $price = mysqli_real_escape_string($link, clean_input($_POST["price"])); - - // define the insertion query - $sql = sprintf("INSERT INTO record (ean, title, artist_id, genre, year, price) - VALUES ('%s', '%s', %d, '%s', %d, %f)", $ean, $title, $artist_id, $genre, $year, $price); - - // run the query to insert the data - $result = mysqli_query($link, $sql); - - // check if the query went ok - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "Record successfully added to database."; - } - - } - - // ------- END form processing code... ------- - - // output the html - echo($content); - -?> diff --git a/week-6/record-store-app/views/artist.php b/week-6/record-store-app/views/artist.php deleted file mode 100644 index ea371d7e2a7a6057ea88edcd8afe2edd4020a582..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/artist.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -// check if id parameter was not set in query string -if (!isset($_GET['id'])) { - - // define $content with suitable message - $content = "<h1>I don't know which artist you're looking for...</h1>"; - -} else { // id was set, so carry on... - - // define $artist_id variable and assign value of id parameter - $artist_id = $_GET['id']; - - // fetch record titles for artist with id matching $artist_id - $sql = "SELECT r.title, r.year, r.price, a.first_name, a.last_name - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - WHERE a.id=".$artist_id." - ORDER BY year ASC"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // define a row counter - $i = 0; - - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - - // do this if we are on first row - if ($i == 0) { - - // initialise $content string, assigning it a page header - $content = "<h1>".$row['first_name']." ".$row['last_name']." Records</h1>"; - // append $content string with table definition - $content .= "<table border='1'><tbody>"; - - } - - // append table rows to $content string - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['year']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "</tr>"; - - // increment the row counter - $i++; - - } - - // append $content string with closing table tags - $content .= "</tbody></table>"; - - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-6/record-store-app/views/edit-record.php b/week-6/record-store-app/views/edit-record.php deleted file mode 100644 index ed8644a23faa764d0b4ee33a2d5d8c1111230e6a..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/edit-record.php +++ /dev/null @@ -1,147 +0,0 @@ -<?php -/* - -IGNORE THIS SCRIPT AS IT IS INCOMPLETE - -*/ - -// check if id parameter was not set in query string -if (isset($_GET['id'])) { - - $content = "<h1>Edit record</h1>"; - - // define $ean variable and assign value of id parameter - $ean = $_GET['id']; - - // define query to fetch record details - $sql = sprintf("SELECT title, artist_id, genre, year, price - FROM record - WHERE ean=%d",$ean); - - $result = mysqli_query($link, $sql); - $title = $artist_id = $genre = $year = $price = ""; - - if ($result === false) { - echo mysqli_error($link); - } else { - $row = mysqli_fetch_assoc($result); - - $title = $row['title']; - $artist_id = $row['artist_id']; - $genre = $row['genre']; - $year = $row['year']; - $price = $row['price']; - unset($result); - } - - // define a variable with path to the script which will process form - $action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=edit-record"); - - // fetch the artists so that we have access to their names and IDs - $sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - // if the id matches current artist_id, show option as selected - if ($row['id'] == $artist_id) { - $options .= "<option value='".$row['id']."' selected>"; - } else { - $options .= "<option value='".$row['id']."'>"; - } - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } - unset($result); - } - - // define the form HTML (would ideally be in a template) - $form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean' value='".$ean."'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' value='".$title."' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' value='".$genre."' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' value='".$year."' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' value='".$price."' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - - // append form HTML to content string - $content .= $form_html; - - // ------- START form processing code... ------- - - // define a function to sanitise user input (this would ideally be in includes folder) - // helps protect against XSS - function clean_input($data) { - $data = trim($data); // strips unnecessary characters from beginning/end - $data = stripslashes($data); // remove backslashes - $data = htmlspecialchars($data); // replace special characters with HTML entities - return $data; - } - - // check if there was a POST request - if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = mysqli_real_escape_string($link, clean_input($_POST["ean"])); - $title = mysqli_real_escape_string($link, clean_input($_POST["title"])); - $artist_id = mysqli_real_escape_string($link, clean_input($_POST["artist_id"])); - $genre = mysqli_real_escape_string($link, clean_input($_POST["genre"])); - $year = mysqli_real_escape_string($link, clean_input($_POST["year"])); - $price = mysqli_real_escape_string($link, clean_input($_POST["price"])); -} - - // define the insertion query - $sql = sprintf("UPDATE record - SET ean=%d, title=%d, artist_id=%d, genre=%d, year=%d, price=%d - WHERE ean=%d", $ean, $title, $artist_id, $genre, $year, $price, $ean); - - // run the query to update the data - $result = mysqli_query($link, $sql); - - // check if the query went ok - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "Record updated successfully."; - } -} else { - $content = "Not sure what you want to edit."; -} - -// ------- END form processing code... ------- - -// output the html -echo($content); - -?> \ No newline at end of file diff --git a/week-6/record-store-app/views/home.php b/week-6/record-store-app/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-6/record-store-app/views/order.php b/week-6/record-store-app/views/order.php deleted file mode 100644 index 0f81c631d898204086a592a060e6341c59a16f20..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/order.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price - FROM record r - INNER JOIN orderline ol - ON ol.record_ean=r.ean - WHERE ol.transaction_id=".$order_id; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = $row['quantity'] * $row['price']; - $total = $total + $subtotal; - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-6/record-store-app/views/orders.php b/week-6/record-store-app/views/orders.php deleted file mode 100644 index d1228914e88edccc204d29b7380dabe43fd36aa7..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/orders.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "SELECT id, customer_id FROM transaction - ORDER BY customer_id"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) -{ - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>"; - $content .= "<td>".$row['customer_id']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-6/record-store-app/views/record.php b/week-6/record-store-app/views/record.php deleted file mode 100644 index 051ed1e2a812e163b87b1305db5e5224ff7fe9ba..0000000000000000000000000000000000000000 --- a/week-6/record-store-app/views/record.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; -$content .= "<p>You are now viewing all records in the database.</p>"; - -// fetch records as a result set -$sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - ORDER BY r.title, r.price DESC"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-7/record-store-app/README.txt b/week-7/record-store-app/README.txt deleted file mode 100644 index e1b81286b37bafe40724172f4a7cbb3344cab519..0000000000000000000000000000000000000000 --- a/week-7/record-store-app/README.txt +++ /dev/null @@ -1,12 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -Description ------------ -This folder contains the sql file you will need to complete lab 7. - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - diff --git a/week-7/record-store-app/sql/record-store.sql b/week-7/record-store-app/sql/record-store.sql deleted file mode 100644 index e50d2d0ac093c0ffe779366e37b7f45e53b8e2ae..0000000000000000000000000000000000000000 --- a/week-7/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,66 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS orderline, transaction, customer, record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -) ENGINE=InnoDB; - -/* Define table for storing records (products) */ -CREATE TABLE record ( - ean CHAR(8) NOT NULL, - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price_gbp DECIMAL(10, 2) unsigned NOT NULL, - price_eu DECIMAL(10, 2) unsigned NOT NULL, - avg_rating DECIMAL(10, 1) unsigned, - PRIMARY KEY (ean), - FOREIGN KEY (artist_id) - REFERENCES artist (id) - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address VARCHAR(50) NOT NULL, - city VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - wishlist TEXT, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - dt_date DATETIME, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -) ENGINE=InnoDB; - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - record_ean CHAR(8), - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (record_ean) - REFERENCES record(ean) - ON UPDATE CASCADE - ON DELETE CASCADE -) ENGINE=InnoDB; - diff --git a/week-8/record-store-app/README.txt b/week-8/record-store-app/README.txt deleted file mode 100644 index db41256a3e53b0db799dee85b6c26f21bf524809..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/README.txt +++ /dev/null @@ -1,27 +0,0 @@ -********************************* -* RECORD STORE APPLICATION * -********************************* - -Description ------------ -This is a demo record store application. You can use it to help you complete lab 8. It is You can also read this README file to find out the sorts of things that should be included in a README file! - -Author & Contact ----------------- -Sorrel Harriet s.harriet@gold.ac.uk - -Installation Instructions -------------------------- -+ Check you have a LAMP stack installed with PHP>5 and MySQL>5 -+ Upload the application to your web root folder. -+ Run the record-store.sql file on your database. -+ Run the dummy_data.sql file to insert some data. - -Configuration Instructions --------------------------- -Modify the includes/db_connect.php script with your MySQL database credentials. - -Live Demo ---------- -A demo version of this app is deployed at the following URL: -http://doc.gold.ac.uk/~sharr003/data-network-web/lab-exercises/week-8/record-store-app/ diff --git a/week-8/record-store-app/includes/db_connect.php b/week-8/record-store-app/includes/db_connect.php deleted file mode 100644 index 8787faffe2d71c2d84ecf636ca17892334d3bf90..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/includes/db_connect.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* Open a new connection to the MySQL server */ - -/* connect to the database */ -$link = mysqli_connect( - 'localhost', - 'YOUR_USERNAME', - 'YOUR_PASSWORD', - 'YOUR_DB_NAME' -); - -/* check connection succeeded */ -if (mysqli_connect_errno()) { - echo "Failed to connect to MySQL: " . mysqli_connect_error(); -} - -?> \ No newline at end of file diff --git a/week-8/record-store-app/index.php b/week-8/record-store-app/index.php deleted file mode 100644 index 2995f49f0512f6201fbb09d743f8a2e2a80704d7..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/index.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -// connect to the database -require('includes/db_connect.php'); - -// include the header HTML -include('templates/header.html'); - -// include the navigation HTML -include('templates/navigation.html'); - -// get the page id from the URL -// if no parameter detected... -if (!isset($_GET['page'])) { - $id = 'home'; // display home page -} else { - $id = $_GET['page']; // else requested page -} - -// use switch to determine which view to serve based on $id -switch ($id) { -case 'home' : - include 'views/home.php'; - break; -case 'record' : - include 'views/record.php'; - break; -case 'artist' : - include 'views/artist.php'; - break; -case 'orders' : - include 'views/orders.php'; - break; -case 'order' : - include 'views/order.php'; - break; -case 'add-record' : - include 'views/add-record.php'; - break; -default : - include 'views/404.php'; -} - -// close the connection to the database -mysqli_close($link); - -// include the footer HTML -include('templates/footer.html'); - -?> \ No newline at end of file diff --git a/week-8/record-store-app/sql/dummy_data.sql b/week-8/record-store-app/sql/dummy_data.sql deleted file mode 100644 index 7d0580104297aa0ad65f6d70c33601e128b685d4..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/sql/dummy_data.sql +++ /dev/null @@ -1,67 +0,0 @@ -/* Note that, because foreign key values are being -inserted manually, tables must be recreated before running -this code in order to reset AUTO_INCREMENT */ - -/* Statement to insert some records in the artist table */ -INSERT INTO artist (id, first_name, last_name) -VALUES -(NULL, 'Bob', 'Marley'), -(NULL, 'Peter', 'Tosh'), -(NULL, 'Burning', 'Spear'), -(NULL, 'Alton', 'Ellis'), -(NULL, 'Gregory', 'Issacs'), -(NULL, 'Desmond', 'Dekker'); - -INSERT INTO record (ean, title, artist_id, genre, year, price) -VALUES -('00562056', 'Soul Rebel', 1, 'Reggae', 1970, 25.99 ), -('50264967', 'Catch A Fire', 1, 'Reggae', 1973, 25.99 ), -('00748396', 'Natty Dread', 1, 'Reggae', 1974, 20.99 ), -('00495739', 'Babylon By Bus', 1, 'Reggae', 1978, 24.99 ), -('00738432', 'Legalize It', 2, 'Reggae', 1976, 22.99 ), -('50847583', 'Bush Doctor', 2, 'Reggae', 1978, 20.99 ), -('30748743', 'Marcus Garvey', 3, 'Reggae', 1975, 24.99 ), -('50856384', 'Night Nurse', 5, 'Reggae', 1982, 17.99 ), -('50264972', 'Mr Issacs', 5, 'Reggae', 1982, 9.99 ), -('00649573', 'Black and Dekker', 6, 'Reggae', 1980, 19.99 ), -('00625485', 'Sunday Coming', 4, 'Reggae', 1970, 15.99 ); - -INSERT INTO customer (id, first_name, last_name, email_address, address_1, address_2, postcode) -VALUES -(NULL, 'John', 'Smith', 'john@smith.com', '1 Fake Street', 'London', 'SE3 5RD'), -(NULL, 'Sukie', 'Bapswent', 's.baps@gmail.com', '64 The Terrace', 'Whitby', 'YO65 3TR'), -(NULL, 'John', 'Thumb', 'jthumb@gmail.com', '25 Fantasy Grove', 'Brighton', 'BR2 6LV'); - -INSERT INTO transaction (id, customer_id, delivery_method, dt_date) -VALUES -(NULL, 1, 2, '2015-07-01 14:34:58'), -(NULL, 1, 2, '2015-04-01 11:22:35'), -(NULL, 3, 1, '2015-04-01 19:47:03'), -(NULL, 2, 1, '2015-05-11 22:01:19'); - -INSERT INTO orderline (id, transaction_id, record_ean, quantity) -VALUES -(NULL, 1, '00562056', 1), -(NULL, 1, '00495739', 1), -(NULL, 2, '00649573', 2), -(NULL, 2, '00495739', 1), -(NULL, 3, '00738432', 2), -(NULL, 3, '00562056', 1), -(NULL, 3, '50856384', 3), -(NULL, 3, '00495739', 1), -(NULL, 4, '00625485', 1), -(NULL, 4, '00562056', 2); - -INSERT INTO inventory (stock, record_ean) -VALUES -(25, '00562056'), -(18, '50264967'), -(15, '00748396'), -(20, '00495739'), -(10, '00738432'), -(7, '50847583'), -(3, '30748743'), -(34, '50856384'), -(22, '50264972'), -(15, '00649573'), -(12, '00625485'); diff --git a/week-8/record-store-app/sql/practice_queries.sql b/week-8/record-store-app/sql/practice_queries.sql deleted file mode 100644 index ebb0dffa0b828a6072ed93cdede777c89ddd168f..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/sql/practice_queries.sql +++ /dev/null @@ -1,9 +0,0 @@ -/* Simple query -Fetch first_name and last_name columns from artist table */ -SELECT first_name, last_name FROM artist; - -/* Query with filters -Fetches titles from record table where year is 1973 and genre is Reggae */ -SELECT title FROM record -WHERE year = 1973 -AND genre = "Reggae"; \ No newline at end of file diff --git a/week-8/record-store-app/sql/record-store.sql b/week-8/record-store-app/sql/record-store.sql deleted file mode 100644 index 971708804df2996481388ffecf24895dd9047bb8..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/sql/record-store.sql +++ /dev/null @@ -1,71 +0,0 @@ -/* Make sure tables don't exist before creation */ -DROP TABLE IF EXISTS inventory, orderline, transaction, customer, record, artist; - -/* Define table for storing artists */ -CREATE TABLE artist ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50), - last_name VARCHAR(50), - PRIMARY KEY(id) -) ENGINE=InnoDB; - -/* Define table for storing records (products) */ -CREATE TABLE record ( - ean CHAR(8) NOT NULL, - title VARCHAR(50) NOT NULL, - artist_id INT, - genre VARCHAR(50), - year YEAR(4), - price DECIMAL(10, 2) unsigned NOT NULL, - PRIMARY KEY (ean), - FOREIGN KEY (artist_id) - REFERENCES artist (id) - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for storing customers */ -CREATE TABLE customer ( - id INT AUTO_INCREMENT, - first_name VARCHAR(50) NOT NULL, - last_name VARCHAR(50) NOT NULL, - email_address VARCHAR(50) NOT NULL, - address_1 VARCHAR(50) NOT NULL, - address_2 VARCHAR(50), - postcode VARCHAR(10) NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB; - -/* Define table for storing orders */ -CREATE TABLE transaction ( - id INT AUTO_INCREMENT, - customer_id INT NOT NULL, - delivery_method INT, - dt_date DATETIME, - PRIMARY KEY (id), - FOREIGN KEY (customer_id) - REFERENCES customer(id) -) ENGINE=InnoDB; - -/* Define table for storing orderlines */ -CREATE TABLE orderline ( - id INT AUTO_INCREMENT, - transaction_id INT, - record_ean CHAR(8), - quantity INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (transaction_id) - REFERENCES transaction(id), - FOREIGN KEY (record_ean) - REFERENCES record(ean) - ON UPDATE CASCADE - ON DELETE CASCADE -) ENGINE=InnoDB; - -/* Define table for inventory */ -CREATE TABLE inventory ( - stock INT unsigned DEFAULT 0, - record_ean CHAR(8), - PRIMARY KEY (stock, record_ean), - FOREIGN KEY (record_ean) - REFERENCES record (ean) -) ENGINE=InnoDB; diff --git a/week-8/record-store-app/templates/footer.html b/week-8/record-store-app/templates/footer.html deleted file mode 100644 index 2ab5c0d1fc7b0e6c12fb00bf177037f64450298c..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/templates/footer.html +++ /dev/null @@ -1,2 +0,0 @@ - </body> -</html> diff --git a/week-8/record-store-app/templates/header.html b/week-8/record-store-app/templates/header.html deleted file mode 100644 index 373b26f6655d85da48d4aa6febcbb98372f0d451..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/templates/header.html +++ /dev/null @@ -1,7 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <meta charset="UTF-8"> - <title>Record Store</title> - </head> - <body> \ No newline at end of file diff --git a/week-8/record-store-app/templates/navigation.html b/week-8/record-store-app/templates/navigation.html deleted file mode 100644 index bf4662e22bc2e6ec6da0e51e4b4a36b00d810db4..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/templates/navigation.html +++ /dev/null @@ -1,8 +0,0 @@ -<nav> - <ul> - <li><a href="?page=home" title="home">Home</a></li> - <li><a href="?page=record" title="records">Records</a></li> - <li><a href="?page=orders" title="orders">Orders</a></li> - <li><a href="?page=add-record" title="add record">Add record</a></li> - </ul> -</nav> diff --git a/week-8/record-store-app/views/404.php b/week-8/record-store-app/views/404.php deleted file mode 100644 index 7ae2fe7434a65afd31bee52d9ef7edb42d0ee2f1..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/404.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Page not found</h1>"; -$content .= "<p>Sorry, the page you requested could not be found.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-8/record-store-app/views/add-record-insecure.php b/week-8/record-store-app/views/add-record-insecure.php deleted file mode 100644 index 841a5078b968ebf2b18cb97286ab6e8f9d03bbfc..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/add-record-insecure.php +++ /dev/null @@ -1,100 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -$action = $_SERVER["PHP_SELF"]."?page=add-record"; - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = $_POST["ean"]; - $title = $_POST["title"]; - $artist_id = $_POST["artist_id"]; - $genre = $_POST["genre"]; - $year = $_POST["year"]; - $price = $_POST["price"]; - - // define the insertion query - $sql = "INSERT INTO record (ean, title, artist_id, genre, year, price) - VALUES ('$ean', '$title', '$artist_id', '$genre', '$year', '$price')"; - - // run the query to insert the data - $result = mysqli_query($link, $sql); - - // check if the query went ok - if ($result === false) { - echo mysqli_error($link); - } else { - $content .= "Record successfully added to database."; - } -} - -// ------- END form processing code... ------- - -// output the html -echo($content); - -?> diff --git a/week-8/record-store-app/views/add-record.php b/week-8/record-store-app/views/add-record.php deleted file mode 100644 index b1fe79def093be79a175f423c1517391444a046e..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/add-record.php +++ /dev/null @@ -1,125 +0,0 @@ -<?php - -$content = "<h1>Add a record</h1>"; - -// define a variable with path to the script which will process form -// -> $_SERVER["PHP_SELF"] is a path to the current script (index.php) -// -> htmlspecialchars() is used to replace special characters with HTML entities */ -$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=add-record"); - -// fetch the artists so that we have access to their names and IDs -$sql = "SELECT id, first_name, last_name - FROM artist - ORDER BY last_name"; - -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $options = ""; - // create an option for each artist - while ($row = mysqli_fetch_assoc($result)) { - $options .= "<option value='".$row['id']."'>"; - $options .= $row['first_name']." ".$row['last_name']; - $options .= "</option>"; - } -} - -// define the form HTML (would ideally be in a template) -$form_html = "<form action='".$action."' method='POST'> - <fieldset> - <label for='ean'>EAN (required):</label> - <input type='text' name='ean'/> - </fieldset> - <fieldset> - <label for='title'>Title:</label> - <input type='text' name='title' /> - </fieldset> - <fieldset> - <label for='artist_id'>Artist:</label> - <select name='artist_id'> - - ".$options." - <option value='NULL'>Not listed</option> - </select> - </fieldset> - <fieldset> - <label for='genre'>Genre</label> - <input type='text' name='genre' /> - </fieldset> - <fieldset> - <label for='year'>Year:</label> - <input type='text' name='year' size='5' placeholder='YYYY' /> - </fieldset> - <fieldset> - <label for='price'>Price (£):</label> - <input type='text' name='price' placeholder='00.00' /> - </fieldset> - <fieldset> - <label for='price'>Stock:</label> - <input type='text' name='stock' placeholder='0' /> - </fieldset> - <button type='submit'>Submit</button> - </form>"; - -// append form HTML to content string -$content .= $form_html; - -// ------- START form processing code... ------- - -// define a function to sanitise user input (this would ideally be in includes folder) -// helps protect against XSS -function clean_input($data) { - $data = trim($data); // strips unnecessary characters from beginning/end - $data = stripslashes($data); // remove backslashes - $data = htmlspecialchars($data); // replace special characters with HTML entities - return $data; -} - -// define variables and set to empty values -$title = $artist_id = $price = $year = $genre = $stock = ""; - -// check if there was a POST request -if ($_SERVER["REQUEST_METHOD"] == "POST") { - // validate the form data - $ean = mysqli_real_escape_string($link, clean_input($_POST["ean"])); - $title = mysqli_real_escape_string($link, clean_input($_POST["title"])); - $artist_id = mysqli_real_escape_string($link, clean_input($_POST["artist_id"])); - $genre = mysqli_real_escape_string($link, clean_input($_POST["genre"])); - $year = mysqli_real_escape_string($link, clean_input($_POST["year"])); - $price = mysqli_real_escape_string($link, clean_input($_POST["price"])); - $stock = mysqli_real_escape_string($link, clean_input($_POST["stock"])); - - // turn autocommit off - mysqli_autocommit($link, FALSE); - - // start a transaction - mysqli_query($link, 'START TRANSACTION'); - - // define the insertion query to add a new record in record table - $query1 = sprintf("INSERT INTO record (ean, title, artist_id, genre, year, price) - VALUES ('%s', '%s', %d, '%s', %d, %f)", $ean, $title, $artist_id, $genre, $year, $price); - - // define the insertion query to add a new record in inventory table - $query2 = sprintf("INSERT INTO inventory (stock, record_ean) - VALUES (%d, '%s')", $stock, $ean); - - // check if either of the queries failed (returned false) - if (!mysqli_query($link, $query1) or !mysqli_query($link, $query2)) { - echo mysqli_error($link); - mysqli_rollback($link); // if so, rollback transaction - } else { - mysqli_commit($link); // else, commit transaction - $content .= "Record successfully added to database."; - } - - } - - // ------- END form processing code... ------- - - // output the html - echo($content); - -?> diff --git a/week-8/record-store-app/views/artist.php b/week-8/record-store-app/views/artist.php deleted file mode 100644 index ea371d7e2a7a6057ea88edcd8afe2edd4020a582..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/artist.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php - -// check if id parameter was not set in query string -if (!isset($_GET['id'])) { - - // define $content with suitable message - $content = "<h1>I don't know which artist you're looking for...</h1>"; - -} else { // id was set, so carry on... - - // define $artist_id variable and assign value of id parameter - $artist_id = $_GET['id']; - - // fetch record titles for artist with id matching $artist_id - $sql = "SELECT r.title, r.year, r.price, a.first_name, a.last_name - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - WHERE a.id=".$artist_id." - ORDER BY year ASC"; - - $result = mysqli_query($link, $sql); - - // check query returned a result - if ($result === false) { - echo mysqli_error($link); - } else { - - // define a row counter - $i = 0; - - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - - // do this if we are on first row - if ($i == 0) { - - // initialise $content string, assigning it a page header - $content = "<h1>".$row['first_name']." ".$row['last_name']." Records</h1>"; - // append $content string with table definition - $content .= "<table border='1'><tbody>"; - - } - - // append table rows to $content string - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['year']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "</tr>"; - - // increment the row counter - $i++; - - } - - // append $content string with closing table tags - $content .= "</tbody></table>"; - - // free result set - mysqli_free_result($result); - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-8/record-store-app/views/home.php b/week-8/record-store-app/views/home.php deleted file mode 100644 index dc1ed44ecb479e1c621c9798b39d42e025002d21..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/home.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Welcome to Goldsmith's Record Store</h1>"; -$content .= "<p>Follow the links above to browse the store.</p>"; - -// output the content HTML -echo $content; - -?> diff --git a/week-8/record-store-app/views/order.php b/week-8/record-store-app/views/order.php deleted file mode 100644 index 0f81c631d898204086a592a060e6341c59a16f20..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/order.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -// check the order_id parameter has been set in the URL -if (isset($_GET['order_id'])) -{ - $order_id = $_GET['order_id']; -} else { - $order_id = -1; // if not, set to an implausible value -} - -// fetch order details associated with current order id -$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price - FROM record r - INNER JOIN orderline ol - ON ol.record_ean=r.ean - WHERE ol.transaction_id=".$order_id; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - - // Find the number of rows returned - $num_rows = mysqli_num_rows($result); - - // Check it's not 0 - if ($num_rows == 0) { - $content = "<h1>Order not found</h1>"; - } else { - // create variable for content HTML - $content = "<h1>Order ".$order_id."</h1>"; - $content .= "<table border='1'>"; - $content .= "<thead><tr> - <th>EAN</th> - <th>Title</th> - <th>Quantity</th> - <th>Price</th> - <th>Total</th> - </tr></thead>"; - $content .= "<tbody>"; - // initialise total order price to 0 - $total = 0.00; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $subtotal = $row['quantity'] * $row['price']; - $total = $total + $subtotal; - $content .= "<tr>"; - $content .= "<td>".$row['ean']."</td>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td>".$row['quantity']."</td>"; - $content .= "<td>£".$row['price']."</td>"; - $content .= "<td>£".$subtotal."</td>"; - $content .= "</tr>"; - } - $content .= "<tr><td colspan=4><b>TOTAL</b><td><b>£".$total."</b></td></tr>"; - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); - - } -} - -// output the content HTML -echo $content; - -?> diff --git a/week-8/record-store-app/views/orders.php b/week-8/record-store-app/views/orders.php deleted file mode 100644 index d1228914e88edccc204d29b7380dabe43fd36aa7..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/orders.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -// initialise string variable for content HTML -$content = "<h1>Orders</h1>"; - -// fetch all transactions (orders) and group by customer id -$sql = "SELECT id, customer_id FROM transaction - ORDER BY customer_id"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) -{ - echo mysqli_error($link); -} else { - $num_rows = mysqli_num_rows($result); - if ($num_rows > 0) - { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>"; - $content .= "<tbody>"; - // fetch each row in result set as an associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>"; - $content .= "<td>".$row['customer_id']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - } else { - $content .= "<p>There are no orders to display.</p>"; - } - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-8/record-store-app/views/record.php b/week-8/record-store-app/views/record.php deleted file mode 100644 index 17c5201f4aedf1b82efac301d3c257a3f4ad9d60..0000000000000000000000000000000000000000 --- a/week-8/record-store-app/views/record.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -// create variable for content HTML -$content = "<h1>Records</h1>"; -$content .= "<p>You are now viewing all records in the database.</p>"; - -// fetch records as a result set -$sql = "SELECT r.title, r.ean, a.first_name, a.last_name, r.genre, r.price, i.stock, a.id - FROM record r - INNER JOIN artist a - ON r.artist_id=a.id - INNER JOIN inventory i - ON r.ean=i.record_ean - ORDER BY r.title, r.price DESC"; -$result = mysqli_query($link, $sql); - -// check query returned a result -if ($result === false) { - echo mysqli_error($link); -} else { - $content .= "<table border='1'>"; - $content .= "<thead><tr><th>Title</th><th>Artist</th><th>Genre</th><th>Price</th><th>Stock</th></tr></thead>"; - $content .= "<tbody>"; - // fetch associative array - while ($row = mysqli_fetch_assoc($result)) { - $content .= "<tr>"; - $content .= "<td>".$row['title']."</td>"; - $content .= "<td><a href='?page=artist&id=".$row['id']."'>".$row['first_name']." ".$row['last_name']."</a></td>"; - $content .= "<td>".$row['genre']."</td>"; - $content .= "<td>".$row['price']."</td>"; - $content .= "<td>".$row['stock']."</td>"; - $content .= "</tr>"; - } - $content .= "</tbody></table>"; - // free result set - mysqli_free_result($result); -} - -// output the content HTML -echo $content; - -?> diff --git a/week-9/sharr003_dump.sql b/week-9/sharr003_dump.sql deleted file mode 100644 index b4dfbf8743a32e64cd7b56ef765bf0e6fd3ef7b3..0000000000000000000000000000000000000000 --- a/week-9/sharr003_dump.sql +++ /dev/null @@ -1,203 +0,0 @@ --- MySQL dump 10.13 Distrib 5.5.41, for Linux (x86_64) --- --- Host: localhost Database: sharr003_recordstore --- ------------------------------------------------------ --- Server version 5.5.41 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Current Database: `sharr003_recordstore` --- - -CREATE DATABASE /*!32312 IF NOT EXISTS*/ `sharr003_recordstore` /*!40100 DEFAULT CHARACTER SET latin1 */; - -USE `sharr003_recordstore`; - --- --- Table structure for table `artist` --- - -DROP TABLE IF EXISTS `artist`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `artist` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) DEFAULT NULL, - `last_name` varchar(50) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `artist` --- - -LOCK TABLES `artist` WRITE; -/*!40000 ALTER TABLE `artist` DISABLE KEYS */; -INSERT INTO `artist` VALUES (1,'Bob','Marley'),(2,'Peter','Tosh'),(3,'Burning','Spear'),(4,'Alton','Ellis'),(5,'Gregory','Issacs'),(6,'Desmond','Dekker'); -/*!40000 ALTER TABLE `artist` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `customer` --- - -DROP TABLE IF EXISTS `customer`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `customer` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `first_name` varchar(50) NOT NULL, - `last_name` varchar(50) NOT NULL, - `email_address` varchar(50) NOT NULL, - `address_1` varchar(50) NOT NULL, - `address_2` varchar(50) DEFAULT NULL, - `postcode` varchar(10) NOT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `customer` --- - -LOCK TABLES `customer` WRITE; -/*!40000 ALTER TABLE `customer` DISABLE KEYS */; -INSERT INTO `customer` VALUES (1,'John','Smith','john@smith.com','1 Fake Street','London','SE3 5RD'),(2,'Sukie','Bapswent','s.baps@gmail.com','64 The Terrace','Whitby','YO65 3TR'),(3,'John','Thumb','jthumb@gmail.com','25 Fantasy Grove','Brighton','BR2 6LV'); -/*!40000 ALTER TABLE `customer` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `inventory` --- - -DROP TABLE IF EXISTS `inventory`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `inventory` ( - `stock` int(10) unsigned NOT NULL DEFAULT '0', - `record_ean` char(8) NOT NULL DEFAULT '', - PRIMARY KEY (`stock`,`record_ean`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `inventory_ibfk_1` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `inventory` --- - -LOCK TABLES `inventory` WRITE; -/*!40000 ALTER TABLE `inventory` DISABLE KEYS */; -INSERT INTO `inventory` VALUES (0,''),(20,'00495739'),(25,'00562056'),(12,'00625485'),(15,'00649573'),(10,'00738432'),(15,'00748396'),(3,'00873645'),(0,'01459284'),(1,'1'),(130,'12341234'),(12,'1234312'),(43,'2382398'),(280,'26542543'),(3,'30748743'),(23,'45545453'),(18,'50264967'),(22,'50264972'),(7,'50847583'),(34,'50856384'),(92429482,'fdgfd'),(0,'q5 5hh5'); -/*!40000 ALTER TABLE `inventory` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `orderline` --- - -DROP TABLE IF EXISTS `orderline`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderline` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `transaction_id` int(11) DEFAULT NULL, - `record_ean` char(8) DEFAULT NULL, - `quantity` int(11) NOT NULL, - PRIMARY KEY (`id`), - KEY `transaction_id` (`transaction_id`), - KEY `record_ean` (`record_ean`), - CONSTRAINT `orderline_ibfk_1` FOREIGN KEY (`transaction_id`) REFERENCES `transaction` (`id`), - CONSTRAINT `orderline_ibfk_2` FOREIGN KEY (`record_ean`) REFERENCES `record` (`ean`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `orderline` --- - -LOCK TABLES `orderline` WRITE; -/*!40000 ALTER TABLE `orderline` DISABLE KEYS */; -INSERT INTO `orderline` VALUES (1,1,'00562056',1),(2,1,'00495739',1),(3,2,'00649573',2),(4,2,'00495739',1),(5,3,'00738432',2),(6,3,'00562056',1),(7,3,'50856384',3),(8,3,'00495739',1),(9,4,'00625485',1),(10,4,'00562056',2); -/*!40000 ALTER TABLE `orderline` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `record` --- - -DROP TABLE IF EXISTS `record`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `record` ( - `ean` char(8) NOT NULL, - `title` varchar(50) NOT NULL, - `artist_id` int(11) DEFAULT NULL, - `genre` varchar(50) DEFAULT NULL, - `year` year(4) DEFAULT NULL, - `price` decimal(10,2) unsigned NOT NULL, - PRIMARY KEY (`ean`), - KEY `artist_id` (`artist_id`), - CONSTRAINT `record_ibfk_1` FOREIGN KEY (`artist_id`) REFERENCES `artist` (`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `record` --- - -LOCK TABLES `record` WRITE; -/*!40000 ALTER TABLE `record` DISABLE KEYS */; -INSERT INTO `record` VALUES ('','',6,'',0000,0.00),('00495739','Babylon By Bus',1,'Reggae',1978,24.99),('00562056','Soul Rebel',1,'Reggae',1970,25.99),('00625485','Sunday Coming',4,'Reggae',1970,15.99),('00649573','Black and Dekker',6,'Reggae',1980,19.99),('00738432','Legalize It',2,'Reggae',1976,22.99),('00748396','Natty Dread',1,'Reggae',1974,20.99),('00873645','Another Record',1,'Reggae',1985,10.00),('01459284','Yet another record',3,'Pop',1925,12.50),('1','2',4,'d',2002,2.00),('12341234','Pray for Paris',6,'xxxxx',2015,0.00),('1234312','John SMith the Mac Daddy',2,'Asdf',0000,423.00),('2382398','Arrow',1,'You have failed this city',2011,1000.00),('26542543','Never give up!!!',6,'We can do this people :)',2017,270000.00),('30748743','Marcus Garvey',3,'Reggae',1975,24.99),('45545453','The drop out',1,'rap',1987,12.75),('50264967','Catch A Fire',1,'Reggae',1973,25.99),('50264972','Mr Issacs',5,'Reggae',1982,9.99),('50847583','Bush Doctor',2,'Reggae',1978,20.99),('50856384','Night Nurse',5,'Reggae',1982,17.99),('fdgfd','gffdg',6,'fgfdgg',0000,23323.00),('q5 5hh5','w46h w46h',6,'w64h w46h',0000,6.00); -/*!40000 ALTER TABLE `record` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `transaction` --- - -DROP TABLE IF EXISTS `transaction`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transaction` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `customer_id` int(11) NOT NULL, - `delivery_method` int(11) DEFAULT NULL, - `dt_date` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `customer_id` (`customer_id`), - CONSTRAINT `transaction_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `transaction` --- - -LOCK TABLES `transaction` WRITE; -/*!40000 ALTER TABLE `transaction` DISABLE KEYS */; -INSERT INTO `transaction` VALUES (1,1,2,'2015-07-01 14:34:58'),(2,1,2,'2015-04-01 11:22:35'),(3,3,1,'2015-04-01 19:47:03'),(4,2,1,'2015-05-11 22:01:19'); -/*!40000 ALTER TABLE `transaction` ENABLE KEYS */; -UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2015-11-27 10:34:44