-
Notifications
You must be signed in to change notification settings - Fork 1
/
answer_faq.php
95 lines (82 loc) · 2.67 KB
/
answer_faq.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
<?php
require_once __DIR__ . "/database.php";
require_once __DIR__ . "/configVars.php";
$db = new Database(...$DB_CONFIG);
$message = "";
$data;
function dataFetch()
{
global $data;
global $db;
$data = array();
$rs = $db->fullFetch("SELECT * FROM faq");
if (!$rs) {
$data = array();
} else {
foreach ($rs as $obj) {
$obj["submitName"] = $obj["answer"] ? "Save Changes" : "Submit Answer";
$obj["answer"] = $obj["answer"] ?? "";
$data[] = $obj;
}
}
}
dataFetch();
if (isset($_POST["answerSubmit"])) {
unset($_POST["answerSubmit"]);
$question = trim($_POST["question"]);
$answer = trim($_POST["answer"]);
$data;
if (strlen($question) == 0 || strlen($answer) == 0) {
$message = "Unable to add Empty Answer";
} else {
$rs = $db->fullExecute("UPDATE faq SET answer='$answer' WHERE question='$question'");
if (!$rs) {
$message = "Unable to POST Answer";
} else {
$message = "Answer Successfully Updated";
}
dataFetch();
}
} else if (isset($_POST["delQuestion"])) {
unset($_POST["delQuestion"]);
$question = trim($_POST["question"]);
$rs = $db->fullExecute("DELETE FROM faq WHERE question='$question'");
if (!$rs) {
$message = "Unable to POST Answer";
} else {
$message = "Question Successfully Deleted";
}
dataFetch();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Answer FAQs</title>
<link rel="stylesheet" type="text/css" href="./public/css/answer_faq.css" />
</head>
<body>
<?php if (count($data) == 0) {echo "<h3>" . "NO QUESTIONS TO BE ANSWERED" . "</h3>";}?>
<?php if (count($data) > 0) {
echo "<ol>";
foreach ($data as $obj) {
echo "<li>" . $obj["question"] . "</li>";
echo "<br />";
echo "<form method='POST'>";
echo "<input type='hidden' name='question' value='" . htmlentities($obj['question']) . "' />";
echo "<input type='text' name='answer' value='" . htmlentities($obj['answer']) . "'><br />";
echo "<input type='submit' name='answerSubmit' value='" . $obj["submitName"] . "' />";
echo "</form>";
echo "<form method='POST'>";
echo "<input type='hidden' name='question' value='" . $obj["question"] . "' />";
echo "<input type='submit' name='delQuestion' value='Delete This Question' />";
echo "</form>";
echo '<br />';
}
echo "</ol>";
}?>
<span class="message"><?=htmlentities($message)?></span>
</body>
</html>