Show sourcecode

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/

PInstallProcess.php

252 lines ASCII Windows (CRLF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<?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_HOSTDB_USERDB_PASSWORDDB_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();