-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaq-actions.php
159 lines (146 loc) · 10.8 KB
/
faq-actions.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
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
<?php
//
// TorrentTrader v2.x
// $LastChangedDate: 2011-11-13 22:38:48 +0000 (Sun, 13 Nov 2011) $
// $LastChangedBy: dj-howarth1 $
//
// http://www.torrenttrader.org
//
//
require_once("backend/functions.php");
dbconn(false);
loggedinonly();
if (!$CURUSER || $CURUSER["control_panel"]!="yes"){
show_error_msg(T_("ERROR"), T_("SORRY_NO_RIGHTS_TO_ACCESS"), 1);
}
// ACTION: reorder - reorder sections and items
if ($_GET[action] == "reorder") {
foreach($_POST[order] as $id => $position) SQL_Query_exec("UPDATE `faq` SET `order`='$position' WHERE id='$id'");
header("Refresh: 0; url=faq-manage.php");
}
// ACTION: edit - edit a section or item
elseif ($_GET[action] == "edit" && is_valid_id($_GET[id])) {
stdhead(T_("FAQ_MANAGEMENT"));
begin_frame();
print("<h1 align=\"center\">Edit Section or Item</h1>");
$res = SQL_Query_exec("SELECT * FROM `faq` WHERE `id`='$_GET[id]' LIMIT 1");
while ($arr = mysql_fetch_array($res, MYSQL_BOTH)) {
$arr[question] = stripslashes(htmlspecialchars($arr[question]));
$arr[answer] = stripslashes(htmlspecialchars($arr[answer]));
if ($arr[type] == "item") {
print("<form method=\"post\" action=\"faq-actions.php?action=edititem\">");
print("<table border=\"0\" class=\"table_table\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\">\n");
print("<tr><td class='table_col1'>ID:</td><td class='table_col1'>$arr[id] <input type=\"hidden\" name=\"id\" value=\"$arr[id]\" /></td></tr>\n");
print("<tr><td class='table_col2'>Question:</td><td class='table_col2'><input style=\"width: 300px;\" type=\"text\" name=\"question\" value=\"$arr[question]\" /></td></tr>\n");
print("<tr><td class='table_col1' style=\"vertical-align: top;\">Answer:</td><td class='table_col1'><textarea rows='3' cols='35' name=\"answer\">$arr[answer]</textarea></td></tr>\n");
if ($arr[flag] == "0") print("<tr><td class='table_col2'>Status:</td><td class='table_col2'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\" selected=\"selected\">Hidden</option><option value=\"1\" style=\"color: #000000;\">Normal</option><option value=\"2\" style=\"color: #0000FF;\">Updated</option><option value=\"3\" style=\"color: #008000;\">New</option></select></td></tr>");
elseif ($arr[flag] == "2") print("<tr><td class='table_col2'>Status:</td><td class='table_col2'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\">Hidden</option><option value=\"1\" style=\"color: #000000;\">Normal</option><option value=\"2\" style=\"color: #0000FF;\" selected=\"selected\">Updated</option><option value=\"3\" style=\"color: #008000;\">New</option></select></td></tr>");
elseif ($arr[flag] == "3") print("<tr><td class='table_col2'>Status:</td><td class='table_col2'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\">Hidden</option><option value=\"1\" style=\"color: #000000;\">Normal</option><option value=\"2\" style=\"color: #0000FF;\">Updated</option><option value=\"3\" style=\"color: #008000;\" selected=\"selected\">New</option></select></td></tr>");
else print("<tr><td class='table_col2'>Status:</td><td class='table_col2'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\">Hidden</option><option value=\"1\" style=\"color: #000000;\" selected=\"selected\">Normal</option><option value=\"2\" style=\"color: #0000FF;\">Updated</option><option value=\"3\" style=\"color: #008000;\">New</option></select></td></tr>");
print("<tr><td class='table_col1'>Category:</td><td class='table_col1'><select style=\"width: 300px;\" name=\"categ\">");
$res2 = SQL_Query_exec("SELECT `id`, `question` FROM `faq` WHERE `type`='categ' ORDER BY `order` ASC");
while ($arr2 = mysql_fetch_array($res2, MYSQL_BOTH)) {
$selected = ($arr2[id] == $arr[categ]) ? " selected=\"selected\"" : "";
print("<option value=\"$arr2[id]\"". $selected .">$arr2[question]</option>");
}
print("</select></td></tr>\n");
print("<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"edit\" value=\"Edit\" style=\"width: 60px;\" /></td></tr>\n");
print("</table></form>");
}
elseif ($arr[type] == "categ") {
print("<form method=\"post\" action=\"faq-actions.php?action=editsect\">");
print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\">\n");
print("<tr><td class='table_col1'>ID:</td><td class='table_col1'>$arr[id] <input type=\"hidden\" name=\"id\" value=\"$arr[id]\" /></td></tr>\n");
print("<tr><td class='table_col2'>Title:</td><td class='table_col2'><input style=\"width: 300px;\" type=\"text\" name=\"title\" value=\"$arr[question]\" /></td></tr>\n");
if ($arr[flag] == "0") print("<tr><td class='table_col1'>Status:</td><td class='table_col1'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\" selected=\"selected\">Hidden</option><option value=\"1\" style=\"color: #000000;\">Normal</option></select></td></tr>");
else print("<tr><td class='table_col1'>Status:</td><td class='table_col1'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\">Hidden</option><option value=\"1\" style=\"color: #000000;\" selected=\"selected\">Normal</option></select></td></tr>");
print("<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"edit\" value=\"Edit\" style=\"width: 60px;\" /></td></tr>\n");
print("</table></form>");
}
}
end_frame();
stdfoot();
}
// subACTION: edititem - edit an item
elseif ($_GET[action] == "edititem" && is_valid_id($_POST[id]) && $_POST[question] != NULL && $_POST[answer] != NULL && is_valid_int($_POST[flag]) && is_valid_id($_POST[categ])) {
$question = sqlesc($_POST[question]);
$answer = sqlesc($_POST[answer]);
SQL_Query_exec("UPDATE `faq` SET `question`=$question, `answer`=$answer, `flag`='$_POST[flag]', `categ`='$_POST[categ]' WHERE id='$_POST[id]'");
header("Refresh: 0; url=faq-manage.php");
}
// subACTION: editsect - edit a section
elseif ($_GET[action] == "editsect" && is_valid_id($_POST[id]) && $_POST[title] != NULL && is_valid_int($_POST[flag])) {
$title = sqlesc($_POST[title]);
SQL_Query_exec("UPDATE `faq` SET `question`=$title, `answer`='', `flag`='$_POST[flag]', `categ`='0' WHERE id='$_POST[id]'");
header("Refresh: 0; url=faq-manage.php");
}
// ACTION: delete - delete a section or item
elseif ($_GET[action] == "delete" && isset($_GET[id])) {
if ($_GET[confirm] == "yes") {
SQL_Query_exec("DELETE FROM `faq` WHERE `id`='$_GET[id]' LIMIT 1");
header("Refresh: 0; url=faq-manage.php");
}
else {
stdhead(T_("FAQ_MANAGEMENT"));
begin_frame();
print("<h1 align=\"center\">Confirmation required</h1>");
print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" align=\"center\" width=\"95%\">\n<tr><td align=\"center\">Please click <a href=\"faq-actions.php?action=delete&id=$_GET[id]&confirm=yes\">here</a> to confirm.</td></tr>\n</table>\n");
end_frame();
stdfoot();
}
}
// ACTION: additem - add a new item
elseif ($_GET[action] == "additem" && $_GET[inid]) {
stdhead(T_("FAQ_MANAGEMENT"));
begin_frame();
print("<h1 align=\"center\">Add Item</h1>");
print("<form method=\"post\" action=\"faq-actions.php?action=addnewitem\">");
print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\">\n");
print("<tr><td class='table_col1'>Question:</td><td class='table_col1'><input style=\"width: 300px;\" type=\"text\" name=\"question\" value=\"\" /></td></tr>\n");
print("<tr><td class='table_col2' style=\"vertical-align: top;\">Answer:</td><td class='table_col2'><textarea rows='3' cols='35' name=\"answer\"></textarea></td></tr>\n");
print("<tr><td class='table_col1'>Status:</td><td class='table_col1'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\">Hidden</option><option value=\"1\" style=\"color: #000000;\">Normal</option><option value=\"2\" style=\"color: #0000FF;\">Updated</option><option value=\"3\" style=\"color: #008000;\" selected=\"selected\">New</option></select></td></tr>");
print("<tr><td class='table_col2'>Category:</td><td class='table_col2'><select style=\"width: 300px;\" name=\"categ\">");
$res = SQL_Query_exec("SELECT `id`, `question` FROM `faq` WHERE `type`='categ' ORDER BY `order` ASC");
while ($arr = mysql_fetch_array($res, MYSQL_BOTH)) {
$selected = ($arr[id] == $_GET[inid]) ? " selected=\"selected\"" : "";
print("<option value=\"$arr[id]\"". $selected .">$arr[question]</option>");
}
print("</select></td></tr>\n");
print("<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"edit\" value=\"Add\" style=\"width: 60px;\" /></td></tr>\n");
print("</table></form>");
end_frame();
stdfoot();
}
// ACTION: addsection - add a new section
elseif ($_GET[action] == "addsection") {
stdhead(T_("FAQ_MANAGEMENT"));
begin_frame();
print("<h1 align=\"center\">Add Section</h1>");
print("<form method=\"post\" action=\"faq-actions.php?action=addnewsect\">");
print("<table border=\"0\" class=\"table_table\" cellspacing=\"0\" cellpadding=\"10\" align=\"center\">\n");
print("<tr><td class='table_col1'>Title:</td><td class='table_col1'><input style=\"width: 300px;\" type=\"text\" name=\"title\" value=\"\" /></td></tr>\n");
print("<tr><td class='table_col2'>Status:</td><td class='table_col2'><select name=\"flag\" style=\"width: 110px;\"><option value=\"0\" style=\"color: #ff0000;\">Hidden</option><option value=\"1\" style=\"color: #000000;\" selected=\"selected\">Normal</option></select></td></tr>");
print("<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"edit\" value=\"Add\" style=\"width: 60px;\" /></td></tr>\n");
print("</table></form>");
end_frame();
stdfoot();
}
// subACTION: addnewitem - add a new item to the db
elseif ($_GET[action] == "addnewitem" && $_POST[question] != NULL && $_POST[answer] != NULL && is_valid_int($_POST[flag]) && is_valid_int($_POST[categ])) {
$question = sqlesc($_POST[question]);
$answer = sqlesc($_POST[answer]);
$res = SQL_Query_exec("SELECT MAX(`order`) FROM `faq` WHERE `type`='item' AND `categ`='$_POST[categ]'");
while ($arr = mysql_fetch_array($res, MYSQL_BOTH)) $order = $arr[0] + 1;
SQL_Query_exec("INSERT INTO `faq` (`type`, `question`, `answer`, `flag`, `categ`, `order`) VALUES ('item', $question, $answer, '$_POST[flag]', '$_POST[categ]', '$order')");
header("Refresh: 0; url=faq-manage.php");
}
// subACTION: addnewsect - add a new section to the db
elseif ($_GET[action] == "addnewsect" && $_POST[title] != NULL && is_valid_int($_POST[flag])) {
$title = sqlesc($_POST[title]);
$res = SQL_Query_exec("SELECT MAX(`order`) FROM `faq` WHERE `type`='categ'");
while ($arr = mysql_fetch_array($res, MYSQL_BOTH)) $order = $arr[0] + 1;
SQL_Query_exec("INSERT INTO `faq` (`type`, `question`, `answer`, `flag`, `categ`, `order`) VALUES ('categ', $title, '', '$_POST[flag]', '0', '$order')");
header("Refresh: 0; url=faq-manage.php");
}
else header("Refresh: 0; url=faq-manage.php");
?>