-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanageList.php
216 lines (177 loc) · 7.58 KB
/
manageList.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
<?php
session_start();
require_once 'connect.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<title>ToDoList</title>
</head>
<body>
<!-- Navbar starts here -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#" style="cursor: auto">Manage List Page</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.php">Manage Tasks</a>
</li>
<?php
//Query to get the lists from the database
$sql2 = "SELECT * FROM ToDoList.list";
//Execute the query
$result2 = mysqli_query($conn2, $sql2);
//Check whether the query executed or not
if ($result2 == true) {
//Display the list in menu
while ($row2 = mysqli_fetch_assoc($result2)) {
$list_id = $row2['list_id'];
$list_name = $row2['list_name'];
?>
<li class="nav-item ">
<a class="nav-link" href="listTask.php?list_id=<?php echo $list_id; ?>"><?php echo $list_name ?></a>
</li>
<?php
}
}
?>
</ul>
</div>
</nav>
<!-- Navbar ends here -->
<h1>ToDoList</h1>
<?php
//Checks whether the session is created or not
if (isset($_SESSION['add'])) {
?>
<div class="success">
<strong>Success!</strong>
<p><?php echo $_SESSION['add']; ?></p>
</div>
<?php
unset($_SESSION['add']);
}
//Checks whether the session is created or not
if (isset($_SESSION['add_fail'])) {
?>
<div class="danger">
<strong>Success!</strong>
<p><?php echo $_SESSION['add_fail']; ?></p>
</div>
<?php
unset($_SESSION['add_fail']);
}
//Check whether the session is deleted or not
if (isset($_SESSION['delete'])) {
//Displays session message
?>
<div class="success">
<strong>Success!</strong>
<p><?php echo ($_SESSION['delete']); ?>
</div>
<?php
//Removes the message after displaying once
unset($_SESSION['delete']);
}
if (isset($_SESSION['delete_fail'])) {
//Displays session message
?>
<div class="danger">
<strong>Error!</strong>
<p><?php echo ($_SESSION['delete_fail']); ?></p>
</div><?php
//Removes the message after displaying once
unset($_SESSION['delete_fail']);
}
if (isset($_SESSION['update'])) {
//Displays session message
?>
<div class="success">
<strong>Success!</strong>
<p> <?php echo ($_SESSION['update']); ?></p>
</div><?php
//Removes the message after displaying once
unset($_SESSION['update']);
}
if (isset($_SESSION['update_fail'])) {
//Displays session message
?>
<div class="danger">
<strong>Nope!</strong>
<p> <?php echo ($_SESSION['update_fail']); ?></p>
</div><?php
//Removes the message after displaying once
unset($_SESSION['update_fail']);
}
?>
<!--Table to display lists starts here-->
<div class="all-lists">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th scope="row">ID</th>
<th>List Name</th>
<th>Actions</th>
</tr>
</thead>
<?php
//Select all from list
$sql = "SELECT * FROM ToDoList.list";
//Execute The Query
$result = mysqli_query($conn, $sql);
//Checks whether the query is executed successfully or not
if ($result == true) {
//Count rows of data in database
$count_rows = mysqli_num_rows($result);
$id = 1;
//Check whether there is data in database or not
if ($count_rows > 0) {
//If There is data in the database. Display in table
//$row is an array. The data will be stored as an array in $row
while ($row = mysqli_fetch_assoc($result)) {
$list_id = $row['list_id'];
$list_name = $row['list_name'];
?>
<tbody>
<!-- Row -->
<tr>
<!-- Used ID++ because else when I delete a task/list, it will not count from the last existing ID -->
<th scope="row"><?php echo $id++ ?></th>
<td><?php echo $list_name ?></td>
<td>
<a href="CRUD_list/updateList.php?list_id=<?php echo $list_id; ?>">Update</a>
<a href="CRUD_list/deleteList.php?list_id=<?php echo $list_id; ?>">Delete</a>
</td>
</tr>
<?php
}
} else {
//Else Show a Message, That There Is No Data In The Database
?>
<!-- Makes 1 column out of different columns -->
<tr>
<td colspan="3">No List Added Yet.</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<a class="btn btn-primary" href="CRUD_list/addList.php">Add List</a>
</div>
</div>
</body>
</html>