forked from awhigginbotham/Commentz
/
index.php
172 lines (159 loc) · 5.78 KB
/
index.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
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
// index.php
// Main screen of application. Allows users to enter
// comments about other students. Shows the questions for
// the currently active form.
//
require_once 'includes/global.inc.php';
require_once 'classes/Answer.class.php';
require_once 'classes/AnswerTools.class.php';
//check to see if they're logged in
if(!isset($_SESSION['logged_in'])) {
header("Location: login.php");
}
$aTool = new AnswerTools();
$uTool = new UserTools();
//get the user object from the session
$userID = $_SESSION["userID"];
if ($userID == "") {
echo "Lost userID SESSION variable...<br>";
$uTool->logout();
header("Location: login.php");
}
$user = $uTool->get($userID);
$toID = "";
$toUser = null;
//
// See who is selected from the user popup menu. This is
// who we want to send comments to.
//
if (isset($_POST['toID'])) {
$toID = $_POST['toID'];
}
else { // If no one is selected, select the first one in the menu.
$db = new DB();
$rows = $db->select2("id","users","userPriv='S'","lastName");
$toID = $rows[0]["id"];
}
$toUser = $uTool->get($toID);
// If the user submitted their answers, save them.
//
if (isset($_POST['modify-submit'])) {
$rows = $db->select2("questionID","formQuestions");
foreach($rows as $row) {
$data['questionID'] = $row["questionID"];
$questionID = $data['questionID'];
$data['text'] = $_POST['question'.$questionID];
$data['fromID'] = $userID;
$data['toID'] = $toID;
$answer = new Answer($data);
$answer->modify();
}
$error = "Answers modified.";
}
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="User login." content="">
<meta name="Dr. Brown" content="">
<link rel="shortcut icon" href="images/favicon.png">
<title>Commentz To:</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="../../assets/js/html5shiv.js"></script>
<script src="../../assets/js/respond.min.js"></script>
<![endif]-->
<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script>
$(function() {
$("#userPopup").change(function() {
$("#toID").val(this.value);
$("#answerForm").submit();
});
})
</script>
</head>
<body>
<?php
showNavbar($user,"To");
?>
<div class="container">
<h2>Commentz To:</h2>
<form id="answerForm" class="form-horizontal" action="index.php" method="post">
<?php
// Show a popup with the users to send comments to.
//
$uTools = new UserTools();
$uTools->showUserPopup($toID);
// Hidden field containing the id of the person that the comments are intended for.
echo '<input id="toID" name="toID" type="hidden" value="' . $toID . '">';
// Show selected user site link.
echo '<br><br><label for="link">Site Link:</label>' . "\n";
$link = $toUser->link;
if ($link == null)
echo "No link defined yet for this user.\n";
else
echo '<a id="link" href="' . $link . '" target="_BLANK">' . $link . '</a>' . "\n";
// Show selected user blog link.
echo '<br><br><label for="link">Blog Link:</label>' . "\n";
$blog = $toUser->blog;
if ($blog == null)
echo "No blog link yet for this user.\n";
else
echo '<a id="link" href="' . $blog . '" target="_BLANK">' . $blog . '</a>' . "\n";
echo "<br><br>\n";
//
// Get and then show the questions and leave spaces to write the answers.
//
$rows = $db->select2("questionID, question.title, text, type","form, formQuestions, question", "form.title='Exam 2' and formID=form.ID and questionID=question.ID");
if ($db->numRows == 0)
echo "";
elseif ($db->numRows == 1) {
echo '<label for="question' . $rows["questionID"]. '">' . $rows["text"] . "</label>\n";
}
else {
//
// Show the questions and answer spaces.
//
foreach($rows as $row) {
echo '<label for="question' . $row["questionID"]. '">' . $row["text"] . "</label>\n";
$whereClause = "questionID=" . $row['questionID'] . " and fromID='" . $userID . "' and toID='" . $toID . "'";
$results = $db->select2("text","answer",$whereClause);
if ($db->numRows == 0)
$text = "";
else
$text = $results["text"];
// Handle "rating" questions by showing a popup.
if ($row["type"] == 'R') {
echo '<select name="question' . $row["questionID"] . '" id="question' . $row["questionID"] . '"class="form-control" >' . "\n";
for($i = 1; $i <= 10; $i++) {
if ($text == (string)$i)
echo ' <option selected value="' . $i . '">' . $i . '</option>' . "\n";
else
echo ' <option value="' . $i . '">' . $i . '</option>' . "\n";
}
echo '</select><br>' . "\n";
}
// Handle regular text questions.
else {
echo '<textarea name="question' . $row["questionID"] . '" id="question' . $row["questionID"] . '" class="form-control well-lg" rows="5" placeholder="' . $row["title"] . '" name="answer">' . $text . '</textarea></br>' . "\n";
}
}
}
echo '<button type="submit" class="btn btn-lg btn-primary btn-block" name="modify-submit" value="' . $toID . '">Modify</button>' . "\n";
?>
</form>
</div>
<?php
echo $error;
?>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/bootstrap.js"></script>
</body>
</html>