The following files exists in this folder. Click to view.
Foogler_blog/pages
PAuthor.php
PCommentProcess.php
PDeleteCommentProcess.php
PDeletePost.php
PDeletePostProcess.php
PEditPost.php
PEditPostProcess.php
PErDiagramme.php
PIndex.php
PInstall.php
PInstallProcess.php
PNewPost.php
PNewPostProcess.php
PRssFeed.php
PShowPost.php
PStatistics.php
PValidate.php
login/
<?php
// -------------------
// PInstallProcess.php
//
// Handles process for resetting database
//--------------------
if(!isset($_SESSION['accountUser'])) {
die("Sorry, you have to be logged in to do this.");
} else if($_SESSION['accountUser'] == "guest" ) {
die("Sorry, you don't have the priviliges for doing this...");
}
//---------------------------
//DB stuff
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); //Sets up DB
//Makes sure DB connection is OK
if (mysqli_connect_error()) {
echo "Connect failed: ".mysqli_connect_error()."<br>";
exit();
}
$mysqli->set_charset("utf8");
// -------------------------------------------------------------------------------------------
// Prepare SQL
$tableAuthor = DB_PREFIX . 'Author';
$tablePost = DB_PREFIX . 'Post';
$tableComment = DB_PREFIX . 'Comment';
$tableTag = DB_PREFIX . 'Tag';
$tablePostTag = DB_PREFIX . 'PostTag';
require_once('placeholder.php');
//----------------------
//SQL queries
$query = <<<END
DROP TABLE IF EXISTS {$tableAuthor};
DROP TABLE IF EXISTS {$tablePost};
DROP TABLE IF EXISTS {$tableComment};
DROP TABLE IF EXISTS {$tableTag};
DROP TABLE IF EXISTS {$tablePostTag};
--
-- Table for author
--
CREATE TABLE {$tableAuthor} (
-- Primary key(s)
idAuthor INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
-- Attributes
username CHAR(20) NOT NULL UNIQUE,
screenname CHAR(50) NOT NULL,
password CHAR(32) NOT NULL,
info TEXT NOT NULL
) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_swedish_ci;
--
-- Table for post
--
CREATE TABLE {$tablePost} (
-- Primary key(s)
idPost INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
-- Foreign key(s)
Post_idAuthor INT NOT NULL,
FOREIGN KEY (Post_idAuthor) REFERENCES {$tableAuthor}(idAuthor),
-- Attributes
postTitle CHAR(150) NOT NULL,
postText LONGTEXT NOT NULL,
postDate DATETIME NOT NULL
) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_swedish_ci;
--
-- Table for comment
--
CREATE TABLE {$tableComment} (
-- Primary key(s)
idComment INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
-- Foreign key(s)
Comment_idPost INT NOT NULL,
FOREIGN KEY (Comment_idPost) REFERENCES {$tablePost}(idPost),
-- Attributes
commTitle CHAR(150) NOT NULL,
commText TEXT NOT NULL,
commDate DATETIME NOT NULL,
commSignature CHAR(50) NOT NULL,
commEmail CHAR(50) NOT NULL
) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_swedish_ci;
--
-- Table for tag
--
CREATE TABLE {$tableTag} (
-- Primary key(s)
idTag INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
-- Attributes
tagName CHAR(50) NOT NULL UNIQUE
) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_swedish_ci;
--
-- Table for PostTag
--
CREATE TABLE {$tablePostTag} (
-- Primary key(s)
--
-- The PK is the combination of the two foreign keys, see below.
--
-- Foreign keys
PostTag_idPost INT NOT NULL,
PostTag_idTag INT NOT NULL,
FOREIGN KEY (PostTag_idPost) REFERENCES {$tablePost}(idPost),
FOREIGN KEY (PostTag_idTag) REFERENCES {$tableTag}(idTag),
PRIMARY KEY (PostTag_idPost, PostTag_idTag)
-- Attributes
) ENGINE = MYISAM CHARSET=utf8 COLLATE=utf8_swedish_ci;
--
-- Add default author(s)
--
INSERT INTO {$tableAuthor} (username, screenname, password, info)
VALUES ('admin', 'administrator', md5('secret'), 'Quite an ordinary fellow. Often seen around login pages.');
INSERT INTO {$tableAuthor} (username, screenname, password, info)
VALUES ('sparrowhawk', 'sparrowhawk', md5('earthsea'), 'Dragonlord, former archmage, and generally nice guy.');
INSERT INTO {$tableAuthor} (username, screenname, password, info)
VALUES ('guest', 'guest', md5('guest'), 'Reader of the blog, without administrative priviliges.');
--
-- Add default tag(s)
--
INSERT INTO {$tableTag} (tagName) VALUES ('apple');
INSERT INTO {$tableTag} (tagName) VALUES ('orange');
INSERT INTO {$tableTag} (tagName) VALUES ('pear');
INSERT INTO {$tableTag} (tagName) VALUES ('grape');
INSERT INTO {$tableTag} (tagName) VALUES ('banana');
INSERT INTO {$tableTag} (tagName) VALUES ('poltergeist');
--
-- Add default post(s)
--
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postOneTitle}', '{$postOne}', DATE_SUB(NOW(), INTERVAL 60 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'admin'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postTwoTitle}', '{$postTwo}', DATE_SUB(NOW(), INTERVAL 50 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'admin'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postThreeTitle}', '{$postThree}', DATE_SUB(NOW(), INTERVAL 40 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'sparrowhawk'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postFourTitle}', '{$postFour}', DATE_SUB(NOW(), INTERVAL 35 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'admin'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postFiveTitle}', '{$postFive}.', DATE_SUB(NOW(), INTERVAL 30 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'sparrowhawk'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postSixTitle}', '{$postSix}', DATE_SUB(NOW(), INTERVAL 2 WEEK), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'sparrowhawk'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postSevenTitle}', '{$postSeven}', DATE_SUB(NOW(), INTERVAL 8 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'sparrowhawk'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postEightTitle}', '{$postEight}', DATE_SUB(NOW(), INTERVAL 2 DAY), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'admin'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postNineTitle}', '{$postNine}', DATE_SUB(NOW(), INTERVAL 50 MINUTE), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'sparrowhawk'));
INSERT INTO {$tablePost} (postTitle, postText, postDate, Post_idAuthor)
VALUES ('{$postTenTitle}', '{$postTen}', NOW(), (SELECT idAuthor FROM {$tableAuthor} WHERE username = 'admin'));
--
-- Add default comment(s)
--
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentOneTitle}', '{$commentOne}', DATE_SUB(NOW(), INTERVAL 59 DAY), 'Jedd', 'hawk@sparrow.com', 1);
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentTwoTitle}', '{$commentTwo}', DATE_SUB(NOW(), INTERVAL 29 DAY), 'Gandalf', 'GaNdyBOy@magicWorld.com', 2);
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentThreeTitle}', '{$commentThree}', DATE_SUB(NOW(), INTERVAL 29 DAY), 'Old friend', 'old@friend.com', 2);
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentFourTitle}', '{$commentFour}', DATE_SUB(NOW(), INTERVAL 28 DAY), 'The Voice', 'sound@silence.com', 2);
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentFiveTitle}', '{$commentFive}', DATE_SUB(NOW(), INTERVAL 2 DAY), 'Dumby', 'headmaster@hogwarts.com', 8);
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentSixTitle}', '{$commentSix}', DATE_SUB(NOW(), INTERVAL 2 MINUTE), 'Gandalf', 'GaNdyBOy@magicWorld.com', 8);
INSERT INTO {$tableComment} (commTitle, commText, commDate, commSignature, commEmail, Comment_idPost)
VALUES ('{$commentSevenTitle}', '{$commentSeven}', DATE_SUB(NOW(), INTERVAL 2 MINUTE), 'anon', 'no@udidnt.com', 10);
--
-- Add default PostTag(s)
--
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (1, (SELECT idTag FROM {$tableTag} WHERE tagName = 'orange'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (1, (SELECT idTag FROM {$tableTag} WHERE tagName = 'apple'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (7, (SELECT idTag FROM {$tableTag} WHERE tagName = 'banana'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (8, (SELECT idTag FROM {$tableTag} WHERE tagName = 'grape'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (8, (SELECT idTag FROM {$tableTag} WHERE tagName = 'apple'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (10, (SELECT idTag FROM {$tableTag} WHERE tagName = 'pear'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (10, (SELECT idTag FROM {$tableTag} WHERE tagName = 'poltergeist'));
INSERT INTO {$tablePostTag} (PostTag_idPost, PostTag_idTag)
VALUES (10, (SELECT idTag FROM {$tableTag} WHERE tagName = 'banana'));
END;
//Performs queries
$res = $mysqli->multi_query($query) or die("Could not query database");
//Gets results from query
$statements = 0; //For counting statements
do{
$res = $mysqli->store_result();
$statements++;
}while($mysqli->more_results() && $mysqli->next_result());
$html = "";
//Checks if error
if ($mysqli->errno) {
$html .= "<p>Stopped receiving results: {$mysqli->errno} ({$mysqli->error})</p>";
} else {
$html .= "<p>The database has been successfully reset.</p>";
}
//HTML
$html .= "<p>Number of successful statements: {$statements}</p>";
$mysqli->close(); //Cloess DB connection
//-----------------------
//Prints HTML
require_once(TP_SOURCEPATH . 'CHTMLPage.php');
$page = new CHTMLPage();
$page->printHTMLHeader();
$page->printPageHeader();
$page->printPageBody($html);
//$page->printTagList();
$page->printRightColumn();