-
Notifications
You must be signed in to change notification settings - Fork 2
/
voteawards.php
127 lines (96 loc) · 4 KB
/
voteawards.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
<?php
require('app.php');
if(!PupilAuth::isLoggedIn()) {
header( 'Location: index.php' ) ;
exit;
}
require('templates/header.php');
?>
<div class="ui active dimmer">
<div class="ui loader"></div>
</div>
<div class="ui red segment">
<h1>Vote for awards</h1>
<p>Nominate one pupil for each award. At the end, a winner will be announced for each award along with two runners up. You're allowed to nominate yourself.</p>
</div>
<table class="ui celled striped table awards_table">
<thead>
<tr>
<th class="ten wide">Awards</th>
<th class="six wide">Nominations</th>
</tr>
</thead>
<?php
$awards = DB::query("SELECT * FROM awards");
$votes = DB::query("SELECT * FROM award_votes WHERE rollnumber = %i", $User->rollnumber);
foreach($awards as $award) {
?>
<tr award_id="<?=$award["id"]?>">
<td class="dy_award_name"><?=$award['award']?></td>
<td class="dy_award_value negative">
<div class="ui small search" style="float: left;"><div class="ui icon input"><input class="prompt" type="text" placeholder="Search students..."><i class="search icon"></i></div></div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<div class="ui segment">
<div class="ui labeled button" tabindex="0">
<a href="/" class="ui green button">
<i class="arrow left icon"></i> back
</a>
<a class="ui basic green left pointing label">
Autosaved
</a>
</div>
</div>
<script>
//Load awards pupil has voted on and update table
$.getJSON( "/getcompletedawards.php", function( data ) {
$('.dimmer').remove();
$.each( data, function( key, val ) {
$('tr[award_id="' + key + '"]').find("td.dy_award_value").removeClass("negative").addClass("positive").html('<p>' + val + ' <a href="javascript:editAward(' + key + ')">edit</a></p>');
});
});
function updateAward(awardid, value) {
$.get( "updateaward.php", { awardid: awardid, value: value} )
.done(function( data ) {
if(data != "success") {
alert("Error updating award, please refresh the page and try again");
}
$('tr[award_id="' + awardid + '"]').find('td.dy_award_value').html("<p>" + value + ' <a href="javascript:editAward(' + awardid + ')">edit</a></p>').removeClass("negative").addClass("positive");
});
}
function editAward(awardid) {
$('tr[award_id="' + awardid + '"]').find('td.dy_award_value').find('a').remove();
$('tr[award_id="' + awardid + '"]').find('td.dy_award_value').html('<div class="ui small search" style="float: left;"><div class="ui icon input"><input class="prompt" type="text" placeholder="Search students..." value="' + $('tr[award_id="' + awardid + '"]').find('td.dy_award_value').text().slice(0,-1) + '"><i class="search icon"></i></div></div>').removeClass("positive").addClass("negative");
$('.ui.search')
.search({
source: pupils,
onSelect: function(response) {
updateAward($(this).parent().parent().attr('award_id'), response.title);
}
})
;
}
var pupils = [
<?php
foreach(Pupil::getAllPupilNames() as $pupil) {
echo "{ title: '" . str_replace("'", "\\'", htmlspecialchars($pupil)) . "' },\n";
}
?>
];
$('.ui.search')
.search({
source: pupils,
onSelect: function(response) {
updateAward($(this).parent().parent().attr('award_id'), response.title);
}
})
;
</script>
<?php
require('templates/footer.php');
?>