-
Notifications
You must be signed in to change notification settings - Fork 0
/
listview.php
167 lines (146 loc) · 5.82 KB
/
listview.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
<?php
include_once "./DBSetup/db.php";
session_start();
extract($_POST);
$id=$_SESSION["id"];
$usertype=$_SESSION["usertype"];
if (isset($_SESSION['start']) && (time() - $_SESSION['start'] > (5*60))) {//30 min session
session_unset();
session_destroy();
header("Location:./Login-Register-Logout/login.php");
}
if(isset($action)){
if(ctype_space($title) == false && $title != null){
$sql = "insert into list (userid,title) values(?,?)";
$stmt = $db->prepare($sql);
$stmt->execute([$id,$title]);
}
}
if(isset($_GET["listId"])){
$listid = $_GET["listId"];
$sql = "delete from list where id=?";
$stmt = $db->prepare($sql);
$stmt->execute([$listid]);
}
//If the user is the admin then admin can view every item on the list
if(isset($id)){
if($usertype==0){
$sql = "select * from list";
$rs=$db->query($sql);
$lists = $rs->fetchAll(PDO::FETCH_ASSOC);
}else{
$sql = "select * from list where userid=?";
$stmt=$db->prepare($sql);
$stmt->execute([$id]);
$lists = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./style/listview.css" media="screen" />
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
<div class="wrapper" id="box">
<header>Welcome,
<?php
//Username will be shown in this php code
if(isset($_SESSION["name"])){
echo $_SESSION["name"];
}
?>
</header>
<div class="inputField">
<form action="" method="post" autocomplete="off" style="display: flex">
<input type="text" style="width: auto" name="title" placeholder="New List">
<button class="fa fa-plus" style = "color:aliceblue" name="action" type='submit'></button>
</form>
</div>
<!-- create a foreach loop for the lists-->
<ul class="todoList" >
<?php
foreach( $lists as $list) : ?>
<li>
<a class='title' href='todoview.php?listId=<?=$list["id"]?>'> <?=$list["title"]?> </a>
<?php
if($usertype!=0){
?>
<a class='fa fa-edit' style="font-size:18px;margin-left:15px;color:green;" type='button' href='listDetail.php?listId=<?= $list["id"] ?>' ></a>
<a class='fa fa-trash-o' style="font-size:18px;margin-left:15px;color:red;" name='deleteList' type='button ' href='?listId=<?=$list["id"] ?>'></a>
<?php
}
?>
</li>
<?php endforeach?>
</ul>
<form action="Login-Register-Logout/logout.php" method="post">
<button type="submit" name="logout" class="btn btn-primary btn-lg btn-block" style='background-color:red; width:100px; margin-left:120px;'>Logout</button>
</form>
<!-- MODALS FOR CONFIRMATION AND FORMS ETC -->
<!-- update modal -->
<div class="modal fade" id="updateListModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="name">Name: </label>
<input type="text" autocomplete="off" id="editname" name="name"><br><br>
</div>
<input type="hidden" id="id" name="id">
<div class="modal-footer">
<button type="button" class="btn btn-secondary" id="update-listitem-form"
data-bs-dismiss="updateListModal">Close</button>
<button type="button" class="btn btn-primary">Update</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- delete modal -->
<div class="modal fade" id="deleteListModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Delete Item</h3>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h4>Are you sure you want to delete this item?</h4>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" id="delete-listitem-form" >Cancel</button>
<button type="button" class="btn btn-red">Delete</button>
</div>
</div>
</div>
</div>
</div>
<!-- <script src="script.js"></script> -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<script type="text/javascript"></script>
</body>
</html>