-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_poll_detailed.php
132 lines (98 loc) · 3.65 KB
/
view_poll_detailed.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
<?php
include_once('database/connection.php');
include_once('database/polls.php');
include_once('database/poll_answers.php');
include_once('database/answers.php');
include_once('database/questions.php');
include('lock.php');
include('templates/header.php');
include('templates/navbar.php');
$poll_id = $_GET['id'];
$filter = $_GET['filter'];
include_once('templates/validation/view_poll_detailed_validation.php');
$params = array('db' => $db, 'poll_id' => $poll_id, 'id' => $poll_id, 'user_id' => $_SESSION['myid']);
$errors = validateDetailedView($params);
if(sizeof($errors) > 0) {
$_SESSION['message'] = "Access denied.";
header("location: user.php");
}
?>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawPoll);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawPoll() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
$.ajax({
type : "GET",
url : "templates/details.php",
data : "id=" + <?=$poll_id?>,
success: function (response) {
var pollData = jQuery.parseJSON(response);
$(".panel-title").html("" + pollData['poll']['description']);
var detailsBody = $(".panel-body").get(0);
$(detailsBody).html('');
// Each Question
$.each(pollData['questions'], function(index, question) {
var panelDiv = document.createElement('div');
panelDiv.className = 'panel panel-primary';
var questionHeading = document.createElement('div');
questionHeading.className = 'panel-heading';
var questionTitle = document.createElement('div');
questionTitle.className = 'panel-title';
questionTitle.innerHTML = question['description'];
questionHeading.appendChild(questionTitle);
panelDiv.appendChild(questionHeading);
var answersBody = document.createElement('div');
answersBody.className = 'panel-body';
if(pollData['answers'][question['id']].length > 0) {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Answer');
data.addColumn('number', 'Number');
// Each answer within each question
$.each(pollData['answers'][question['id']], function(questionIndex, answer) {
var answerDescr = answer['description'];
var numAnswers = pollData['poll_answers'][question['id']][answer['id']];
data.addRows([[answerDescr, numAnswers]]);
});
// Set chart options
var options = {'width':250,
'height':200};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(answersBody);
chart.draw(data, options);
panelDiv.appendChild(answersBody);
}
detailsBody.appendChild(panelDiv);
});
}
});
}
</script>
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-title"></div>
</div>
<div class="panel-body">
</div>
<div class="panel-footer">
<a href="user.php?filter=<?=$filter?>"><button class="btn btn-primary">Back</button></a>
</div>
</div>