-
Notifications
You must be signed in to change notification settings - Fork 2
/
answerquestions.php
163 lines (120 loc) · 4.19 KB
/
answerquestions.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
<?php
require('app.php');
if(!PupilAuth::isLoggedIn()) {
header( 'Location: index.php' ) ;
exit;
}
require('templates/header.php');
if($_POST['update'] == "true") {
$User->updateQuestions($_POST['first-question'], $_POST['first-answer'], $_POST['second-question'], $_POST['second-answer'], $_POST['year-joined']);
?>
<div class="ui green inverted segment">Questions updated successfully</div>
<?php
}
?>
<div class="ui red segment">
<h1>Answer two questions about yourself</h1>
</div>
<div class="ui segment">
<form class="ui form" method="post">
<div class="field">
<label>First question...</label>
<select class="ui dropdown" name="first-question">
<option value="">Question</option>
<?php
$questions = DB::query("SELECT * FROM pupil_questions");
foreach($questions as $question) {
if($User->firstquestion == $question['id']) {
?>
<option value="<?=$question['id']?>" selected><?=$question['question']?>...</option>
<?php
}else {
?>
<option value="<?=$question['id']?>"><?=$question['question']?>...</option>
<?php
}
}
?>
</select>
</div>
<div class="field">
<label>Answer</label>
<input type="text" name="first-answer" placeholder="Answer" value="<?=$User->firstanswer?>" id="firstanswer">
<p>Characters remaining: <span id="firstlimit"></span></p>
</div>
<div class="field">
<label>Second question...</label>
<select class="ui dropdown" name="second-question">
<option value="">Question</option>
<?php
$questions = DB::query("SELECT * FROM pupil_questions");
foreach($questions as $question) {
if($User->secondquestion == $question['id']) {
?>
<option value="<?=$question['id']?>" selected><?=$question['question']?>...</option>
<?php
}else {
?>
<option value="<?=$question['id']?>"><?=$question['question']?>...</option>
<?php
}
}
?>
</select>
</div>
<div class="field">
<label>Answer</label>
<input type="text" name="second-answer" placeholder="Answer" value="<?=$User->secondanswer?>" id="secondanswer">
<p>Characters remaining: <span id="secondlimit"></span></p>
</div>
<div class="field">
<label>Year Joined (Year 0 is reception)</label>
<select class="ui dropdown" name="year-joined">
<option value="">Choose your starting year...</option>
<?php
for($x = 0; $x <= 12; $x++) {
if($x == $User->yearjoined) {
?>
<option value="<?=$x?>" selected>Year <?=$x?></option>
<?php
}else {
?>
<option value="<?=$x?>">Year <?=$x?></option>
<?php
}
}
?>
</select>
</div>
<input type="hidden" name="update" value="true"/>
<button class="ui positive button" type="submit">Save</button>
</form>
</div>
<script>
(function($) {
$.fn.extend( {
limiter: function(limit, elem) {
$(this).on("keyup focus", function() {
setCount(this, elem);
});
function setCount(src, elem) {
var chars = src.value.length;
if (chars > limit) {
src.value = src.value.substr(0, limit);
chars = limit;
}
elem.html( limit - chars );
}
setCount($(this)[0], elem);
}
});
})(jQuery);
$('select.dropdown')
.dropdown()
;
$("#firstanswer").limiter(70, $("#firstlimit"));
$("#secondanswer").limiter(70, $("#secondlimit"));
</script>
<?php
require('templates/footer.php');
?>