-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
190 lines (169 loc) · 6.33 KB
/
index.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
<?php
// File: welcome.php
// TODO: Start session tracking and redirect user back to the login form
// if user not in the session state.
$curYear = date('Y');
$projectStatus = '';
session_start();
//welcome message
$userName = $_SESSION['username'];
if (isset($userName)) {
$welcomeMessage = "<h2>   Welcome to your task list, $userName.</h2>";
//echo "<p>Welcome, $_SESSION[username]</p>";
}else {
header('Location: loginForm.php');
}
function getUserID(PDO $pdo, string $userName){
// Search for the current user and return its id if found,
// or 0 if not.
$sql = "
SELECT id
FROM users
WHERE username = '$userName'
";
$stm = $pdo->query($sql, PDO::FETCH_ASSOC);
if ($stm->rowCount() == 1) { return (int)$stm->fetch()['id']; }
else { return ''; }
}
function getProjectID(PDO $pdo, string $userName){
// Search for the instructor and return its id if found,
// or 0 if not.
$userID = getUserID($pdo, $userName);
$sql = "
SELECT id
FROM project
WHERE user\$id= '$userID'
";
$stm = $pdo->query($sql, PDO::FETCH_ASSOC);
if ($stm->rowCount() == 1) { return (int)$stm->fetch()['id']; }
else { return ''; }
}
function listProject(PDO $pdo, string $userName ){
$userID = getUserID($pdo, $userName);
$sql="
SELECT name, dueDate
FROM project
WHERE user\$id = '$userID'
ORDER BY id
;";
// Formats the table column headings
echo "</br><table border=1 cellspacing=0 cellpading=0><tr>
<td style='height:40px;width:160px;text-align:center'><font color= blue> Project Name </td>
<td style='height:40px;width:160px;text-align:center'><font color= red> Due Date </font></td></tr>";
// Fetch each record as an associative array (FETCH_ASSOC).
foreach($pdo->query($sql, PDO::FETCH_ASSOC) as $model) {
//echo "{$model['name']}, {$model['dueDate']}<br>";
echo "<td style='height:40px;width:160px;text-align:center'> {$model['name']} </td>
<td style='height:40px;width:160px;text-align:center'> {$model['dueDate']} </font></td></tr>";
}
}
function listTasks(PDO $pdo, string $userName) {
$projectID = getProjectID($pdo, $userName);
$sql="
SELECT name, status
FROM task
WHERE project\$id = '$projectID'
;";
// Display column names as headings.
//echo "Name | Status";
echo "<table border=1 cellspacing=0 cellpading=0><tr>
<td style='height:40px;width:160px;text-align:center'><font color= blue> Task </td>
<td style='height:40px;width:160px;text-align:center'><font color= #1b2631> Completed? (Y/N) </font></td></tr>";
// Fetch each record as an associative array (FETCH_ASSOC).
foreach($pdo->query($sql, PDO::FETCH_ASSOC) as $model) {
//echo "{$model['name']}, {$model['status']}<br>";
echo "<td style='height:40px;width:160px;text-align:center'> {$model['name']} </td>
<td style='height:40px;width:160px;text-align:center'> {$model['status']} </font></td></tr>";
}
}
try {
//use an external db_config.php file:
require_once 'inc.db.php';
$dsn = 'mysql:host=' . HOST . ';dbname=' . DB;
$pdo = new PDO($dsn, USER, PWD);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(getProjectID($pdo, $userName) == ''){
$projectStatus = "You currently have 0 projects due.";
}else{
echo "<div class='w3-panel' id=tables>";
echo "<h3 id=slide class='w3-center w3-animate-left' >Today's TODO: </h3><center>";
listProject($pdo, $userName);
listTasks($pdo, $userName);
echo "</center></div>";
}
} catch(PDOEXCEPTION $e) {
// For debugging purposes reveal the message.
die( $e->getMessage() );
}
$pdo = null;
?>
<!DOCTYPE html>
<html>
<head>
<title>Home - TaskList</title>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body id=body class="w3-container w3-margin-left">
<!--Welcome message-->
<div class="w3-panel">
<header id=header class="w3-container w3-center w3-text-gray">
<h2>
<?php
echo $welcomeMessage;
echo $projectStatus;
?>
</h2>
<h5>
<a href='addRecord.php'>Tambahkan Project</a> 
<a href='addTask.php'>Tambahkan Task</a> 
<a href='deleteRecord.php'>Menghapus Record</a> 
<a style='color:red' href='loginForm.php'>Keluar</a>
</h5>
</header>
</div>
</body>
<footer id=footer class="w3-container w3-center w3-text-gray">© <?php echo $curYear; ?> TaskList </footer>
<style>
footer{
position:absolute;
bottom:0;
left:0;
width:100%;
height:70px; /* Height of the footer */
background-color: #f9e79f;
font:#515a5a;
}
h2{
text-align:left;
padding:6px 0;
}
h5{
text-align:right;
padding:0px 0;
}
header{
display: block;
position:fixed;
top:0;
left:0;
width:100%;
height:100px;
background-color: #f9e79f;
}
body{
background-color: #fcf3cf;
}
#slide{
animation-duration: 2s;
}
#tables{
padding-top: 8rem;
}
content{
position:absolute;
bottom:40;
left:0;
}
</style>
</html>