-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransact-article.php
More file actions
132 lines (131 loc) · 3.63 KB
/
transact-article.php
File metadata and controls
132 lines (131 loc) · 3.63 KB
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
<?php //transact-article.php
session_start();
require_once "conn.php";
require_once "http.php";
require_once "error_handler.php";
if (isset($_REQUEST["action"]))
{
switch ($_REQUEST["action"])
{
case "Submit New Article":
if(isset($_POST["title"])
and isset($_POST["body"])
and isset($_SESSION["user_id"]))
{
$body = $_POST["body"];
$tags = array("<p>", "</p>");
$body = str_replace($tags, "", $body);
$sql = "INSERT INTO cms_articles " .
"(title,body,author_id,date_submitted) " .
"VALUES ('" . $_POST["title"] .
"','" . addslashes($body) .
"'," . $_SESSION["user_id"] . ",'" .
date("Y-m-d H:i:s", time()) . "')";
mysql_query($sql,$conn)
or die("Couldn't submit article: " . mysql_error());
}
redirect("index.php");
break;
case "Edit":
redirect("compose.php?a=edit&article=" . $_POST["article"]);
break;
case "Save Changes":
if(isset($_POST["title"])
and isset($_POST["body"])
and isset($_POST["article"]))
{
$body = $_POST["body"];
$tags = array("<p>", "</p>");
$body = str_replace($tags, "", $body);
$sql = "UPDATE cms_articles " .
"SET title='" . $_POST["title"] .
"', body='" . addslashes($body) .
"', date_submitted='" . date("Y-m-d H:i:s", time()) . "' " .
"WHERE article_id=" . $_POST["article"];
if(isset($_POST["authorid"]))
{
$sql .= " AND author_id=" . $_POST["authorid"];
}
mysql_query($sql, $conn)
or die("Couldn't update article: " . mysql_error());
}
if(isset($_POST["authorid"]))
{
redirect("cpanel.php");
}
else
{
redirect("pending.php");
}
break;
case "Publish":
if($_POST["article"])
{
$sql = "UPDATE cms_articles " .
"SET is_published = 1, date_published ='" .
date("Y-m-d H:i:s",time()) . "' " .
"WHERE article_id=" . $_POST["article"];
mysql_query($sql, $conn)
or die("Couldn't publish article: " . mysql_error());
}
redirect("pending.php");
break;
case "Retract":
if($_POST["article"])
{
$sql = "UPDATE cms_articles " .
"SET is_published = 0, date_published = ''" .
"WHERE article_id=" . $_POST["article"];
mysql_query($sql, $conn)
or die("Couldn't retract article: " . mysql_error());
}
redirect("pending.php");
break;
case "Delete":
if($_POST["article"])
{
$sql = "DELETE FROM cms_articles " .
"WHERE is_published=0 " .
"AND article_id=" . $_POST["article"];
mysql_query($sql, $conn)
or die("Couldn't delete article: " . mysql_error());
}
redirect("pending.php");
break;
case "Submit Comment":
if(isset($_POST["article"])
and $_POST["article"]
and isset($_POST["comment"])
and $_POST["comment"])
{
$sql = "INSERT INTO cms_comments " .
"(article_id,comment_date,comment_user,comment) " .
"VALUES (" . $_POST["article"] . ",'" .
date("Y-m-d H:i:s", time()) .
"'," . $_SESSION["user_id"] .
",'" .$_POST["comment"] . "')";
mysql_query($sql,$conn)
or die("Couldn't add comment: " . mysql_error());
}
redirect("viewarticle.php?article=" . $_POST["article"]);
break;
case "Remove":
if(isset($_GET["article"])
and isset($_SESSION["user_id"]))
{
$sql = "DELETE FROM cms_articles " .
"WHERE article_id=" . $_GET["article"] .
" AND author_id=" . $_SESSION["user_id"];
mysql_query($sql,$conn)
or die("Couldn't remove article: " . mysql_error());
}
redirect("cpanel.php");
break;
}
mysql_close($conn);
}
else
{
redirect("index.php");
}
?>