-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.php
More file actions
128 lines (104 loc) · 5.85 KB
/
dashboard.php
File metadata and controls
128 lines (104 loc) · 5.85 KB
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
<!DOCTYPE html>
<html lang="en-UK">
<head>
<?php include_once("./includes/headTags.php"); ?>
<link rel="stylesheet" href="./css/dashboard.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,0,0" />
<script src="./js/dashboard.js"></script>
</head>
<body>
<!-- Header Section -->
<?php include_once("./includes/header.php"); ?>
<?php
// check if user is logged in
if (!isset($_SESSION["user"])) {
header("Location: ./signup.php");
}
?>
<!-- Main Content -->
<main>
<h1>Dashboard</h1>
<br>
<div id="create-survey-button-container">
<a href="./createSurvey.php"><p><span class="material-symbols-outlined">add</span>Create New Survey</p></a>
</div>
<br>
<ul class="survey-item-container">
<h2>Active Surveys</h2>
<hr>
<?php
// Database connection
include_once("./php/dbConnection.php");
// Get user id
$userID = $_SESSION["user"]->user_ID;
// Get all user created surveys that are active
$getAllUserSurveysSQL = "SELECT s.* FROM surveys AS s INNER JOIN survey_owner AS so ON s.survey_ID=so.survey_ID AND so.user_ID='$userID' AND s.status='1'";
$surveys = $db->query($getAllUserSurveysSQL);
// Print each survey as a list item
if ($surveys->rowCount() > 0) {
$surveys = $surveys->fetchAll();
foreach($surveys as $survey) {
// Get total response count
$surveyID = $survey["survey_ID"];
$totalParticipants = $db->query(
"SELECT survey_ID, count(*) as 'count' FROM survey_response WHERE survey_ID='$surveyID'"
);
$totalParticipants = $totalParticipants->fetchObject();
$totalParticipants = $totalParticipants->count;
$codeString = "'" . $survey['code'] . "'";
?>
<li class="survey-item">
<div id="left-container" onclick="openSurveyResults(<?php echo($codeString); ?>)">
<p id="survey-item-title"><?php echo($survey["name"]. " | Code: " . $survey["code"]); ?></p>
<p id="survey-item-questions"><?php echo($survey["number_of_questions"] . " Questions"); ?></p>
<p id="survey-item-participants"><?php echo($totalParticipants . " Participants"); ?></p>
</div>
<div id="right-container" onclick="copyLink(<?php echo($codeString); ?>)">
<a id="survey-item-copy-link-button"><p><span class="material-symbols-outlined">content_copy</span>Copy Survey Link</p></a>
</div>
</li>
<?php
}
}
?>
</ul>
<ul class="survey-item-container">
<h2>Closed Surveys</h2>
<hr>
<?php
// Get all user created surveys that are not active
$getAllUserSurveysSQL = "SELECT s.* FROM surveys AS s INNER JOIN survey_owner AS so ON s.survey_ID=so.survey_ID AND so.user_ID='$userID' AND s.status='0'";
$surveys = $db->query($getAllUserSurveysSQL);
// Print each survey as a list item
if ($surveys->rowCount() > 0) {
$surveys = $surveys->fetchAll();
foreach($surveys as $survey) {
// Get total response count
$surveyID = $survey["survey_ID"];
$totalParticipants = $db->query(
"SELECT survey_ID, count(*) as 'count' FROM survey_response WHERE survey_ID='$surveyID'"
);
$totalParticipants = $totalParticipants->fetchObject();
$totalParticipants = $totalParticipants->count;
$codeString = "'" . $survey['code'] . "'";
?>
<li class="survey-item">
<div id="left-container" onclick="openSurveyResults(<?php echo($codeString); ?>)">
<p id="survey-item-title"><?php echo($survey["name"]. " | Code: " . $survey["code"]); ?></p>
<p id="survey-item-questions"><?php echo($survey["number_of_questions"] . " Questions"); ?></p>
<p id="survey-item-participants"><?php echo($totalParticipants . " Participants"); ?></p>
</div>
<div id="right-container" onclick="copyLink(<?php echo($codeString); ?>)">
<a id="survey-item-copy-link-button"><p><span class="material-symbols-outlined">content_copy</span>Copy Survey Link</p></a>
</div>
</li>
<?php
}
}
?>
</ul>
</main>
<!-- Footer Section -->
<?php include_once("./includes/footer.php"); ?>
</body>
</html>