-
Notifications
You must be signed in to change notification settings - Fork 1
/
addtask.php
236 lines (195 loc) · 10.3 KB
/
addtask.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
@ob_start();
session_start();
date_default_timezone_set('Asia/Singapore');
if (!isset( $_SESSION['NUSEmail'] ) ) {
// Redirect them to the login page
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
header("Location: http://localhost/orbital/signup.php");
}
else{
header("Location: http://localhost:8080/orbital/signup.php");
}
}
?>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="img\studylah_logo.jpg" type="image/jpg">
<link rel="stylesheet" href="css\addtask.css">
<link rel="stylesheet" href="css\navbar.css">
<title>StudyLah</title>
</head>
<body>
<!--navbar-->
<?php include('header.php');?>
<div class="checklist">
<div class="heading">
<div class="add"><button class="open-button"name="add" id="add" onclick="openForm()"><img src=img\add.png width="40" height="40"></button></div>
<div class="naming"><img src=img\notes.png width="30" height="30">To-Do-List</div>
</div>
<div class="form-popup" id="myForm">
<form method="post" enctype="multipart/form-data" class="form-container">
<h2>Add A New Task</h2>
<label>Module</label><br>
<input type="text" name="Module" placeholder="Write Assignment's Module" class="input-field" required>
<label>Task</label><br>
<textarea name="Tasks" cols="60" rows="3" id="textareabox" placeholder="Description" class="input-field" required></textarea>
<br>
<br>
<label>Deadline</label><br>
<input type="date" name="DueDate" required>
<input type="time" name="DueTime" required>
<br>
<br>
<button type="submit" class="submit-btn" name="addtaskbtn" id="addtaskbtn">Add</button>
<button type="button" class="btn cancel" onclick="closeForm()">Close</button>
<?php
if (isset($_POST['addtaskbtn'])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "orbital";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$useremail=$_SESSION['NUSEmail'];
$sqlgetuser="SELECT * FROM users WHERE NUSEmail='$useremail'";
$resultgetuser=mysqli_query($conn,$sqlgetuser);
if(mysqli_num_rows($resultgetuser) > 0){//valid
while($rowgetuser=mysqli_fetch_array($resultgetuser)){
$id=$rowgetuser['UserID'];
}
}
$taskname=$_POST['Tasks'];
$module=$_POST['Module'];
$duedate=$_POST['DueDate'];
$duetime=$_POST['DueTime'];
//sanitize
$taskname = mysqli_real_escape_string($conn, $taskname);//sanitize
$module = mysqli_real_escape_string($conn, $module);//sanitize
$taskname = filter_var($taskname, FILTER_SANITIZE_STRING);
$module = filter_var($module, FILTER_SANITIZE_STRING);
//insert into checklist
$sqlinsert1="INSERT INTO tasklist (UserID,Tasks,Modules,DueDate,DueTime) VALUES ('$id','$taskname','$module', '$duedate', '$duetime');";
$result1=mysqli_query($conn,$sqlinsert1);
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
$url="http://localhost/orbital/addtask.php";
header('Location:' . $url);
}
else{
$url="http://localhost:8080/orbital/addtask.php";
header('Location:' . $url);
}
}
?>
</form>
</div>
<div class="table">
<table id="checklist">
<tr>
<th>No.</th>
<th>Task</th>
<th>Module</th>
<th>Due Date</th>
<th>Deadline</th>
<th>Complete Status</th>
</tr>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "orbital";
$mysqli = new mysqli($servername, $username, $password, $dbname);
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
$useremail=$_SESSION['NUSEmail'];
$sqlgetuser="SELECT * FROM users WHERE NUSEmail='$useremail'";
$resultgetuser=mysqli_query($mysqli,$sqlgetuser);
if(mysqli_num_rows($resultgetuser) > 0){//valid
while($rowgetuser=mysqli_fetch_array($resultgetuser)){
$id=$rowgetuser['UserID'];
}
}
$query = "SELECT * FROM tasklist WHERE UserID='$id'";
if ($result = $mysqli->query($query)) {
$number = 1;
while ($row = $result->fetch_assoc()) {
$tasks = $row["Tasks"];
$module = $row["Modules"];
$duedate = $row["DueDate"];
$duetime = $row["DueTime"];
$completion = $row["Completion"];
$taskid = $row["TaskID"];
echo '<form method = "post">
<tr>
<td>'.$number.'</td>
<td name="task">'.$tasks.'</td>
<td name="module">'.$module.'</td>
<td name="duedate">'.$duedate.'</td>
<td name="duetime">'.$duetime.'</td>
<td>
<input name = "delete" type = "submit" id="delete" value = "Complete" onclick="return clicked();">
</td>
<td hidden ><input type="hidden" name="taskid" value='.$taskid.'></td>
</tr>
</form>';
$number += 1;
}
$result->free();
}
?>
<?php
if(isset($_POST['delete'])) {
$taskidno=$_POST['taskid'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "orbital";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to delete a record
$sql = "DELETE FROM tasklist WHERE TaskID=$taskidno";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
if ($_SERVER['SERVER_PORT'] == '80' || $_SERVER['SERVER_PORT'] =='443'){
$url="http://localhost/orbital/addtask.php";
header('Location:' . $url);
}
else{
$url="http://localhost:8080/orbital/addtask.php";
header('Location:' . $url);
}
}
?>
</table>
</div>
</div>
<div class="end">
<button class="nav_contact" >Contact Us</button>
</div>
<script>
function clicked(){
return confirm('Are you sure you have completed the task and finish submission?');
}
function openForm() {
document.getElementById("myForm").style.display = "block";
}
function closeForm() {
document.getElementById("myForm").style.display = "none";
}
</script>
</body>
</html>