-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.php
86 lines (77 loc) · 2 KB
/
admin.php
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
<?php //admin.php
require ('login.php');
include_once ('functions.php');
echo "
<!DOCTYPE html>
<html>
<head>
<title>Create New Post | JeremyKao.com</title>
</head>
<body>
<form method=\"post\">
<label for=\"titleIn\">Title: </label>
<input type=\"text\" name=\"title\" id=\"titleIn\" />
<br />
<label for=\"contentIn\">Content: </label>
<br />
<textarea rows=\"12\" cols=\"100\" name=\"content\" id=\"contentIn\"></textarea>
<br />
<br />
<input type=\"submit\" value=\"Create a Post\" />
</form>
<form method=\"post\">
<input type=\"submit\" name=\"deletePost\" value=\"Delete a Post\" />
</form>
</body>
</html>";
/*** DELETE POSTS ***/
if ($_POST['deletePost']) displayDelete($db_database);
if ($_POST['deletePosts'])
{
$postsToDelete = $_POST['toBeDeleted'];
for ($num = 0; $num < sizeof($postsToDelete); $num++)
{
$postTitle = substr($postsToDelete[$num], 8);
$postYear = substr($postsToDelete[$num], 0, 8);
deleteFromDatabase($postTitle, $postYear);
}
}
/***END DELETE POSTS ***/
if ($_POST['title'])
{
//set Variables
$title = $_POST['title'];
$year = substr($dateYear,4,4);
$content = $_POST['content'];
//Check to see if necessary to create tables
$showTablesQ = mysql_query("SHOW TABLES FROM $db_database");
$numTables = mysql_num_rows($showTablesQ);
//echo "$title, $date, $content, $numTables $dateYear, $dateDate, $dateMonth";
if ($numTables == 0)
{
createTable($dateYear);
//echo 'im in';
}
else
{
$count = 0;
for ($i = 0; $i < $numTables; $i++)
{
$row = mysql_fetch_row($showTablesQ);
//echo '<br><br>INSIDE THE FOR LOOP!!!!';
if ($dateYear == $row[0])
{
$count++;
//echo '<br><br>created tables!!!!';
}
}
if ($count == 0)
{
createTable($dateYear);
}
}
$db_table = $dateYear;
//insert post into correct table
insertPost($db_table, $dateMonth, (Integer) $dateDate, $title, $year, $content);
}
?>