-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
87 lines (82 loc) · 2.59 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
<?php
/* Main page of MedLog. Displays the brief site details,
login form and last entries of the user */
require_once("./include/usercontrol.php");
require_once("./include/entries.php");
require_once("./include/static.php");
$u = new UserControl();
$dry = new DRYHelper();
// Check login before sending headers
$checklogin = $u->CheckLogin();
$dry->build_header();
if (!empty($_GET["message"])) {
?>
<div id="message"><?php echo $_GET["message"]; ?></div>
<?php
}
?>
<h1>MedLog</h1>
<div id="site-info">
<p>MedLog provides an easy-to-use medication/drug log for our users. Log every drug you take!
MedLog also analyses your logged data to create powerful statistics regarding your drug use.</p>
</div>
<div id="content">
<?php
/* Check if the user has already logged in */
if (!$checklogin) {
/* Log-in form */
?>
<div id="login-area">
<p>Please, log in to use our web logging service.</p>
<form id="login" action="login.php" method="POST" data-parsley-validate>
<fieldset>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<label for="username">Username: </label>
<input type="text" name="username" id="username" required/>
<label for="password">Password: </label>
<input type="password" name="password" id="password" required/>
<input type="submit" name="Submit" value="Submit" />
</fieldset>
</form>
<p>If you don't own an account yet, <a href="register.php">register now!</a></p>
</div>
<?php
}
else {
$sess_user = $_SESSION[$u->GetLoginSessionVar()];
/* Content to be displayed if the user is logged in */
?>
<!-- START LOGGED IN HTML -->
<p id="welcome-user">Welcome <?php echo $sess_user; ?>, you've been successfully logged in!
Your last 5 entries are shown below.</p>
<?php
/* Get all the FIRST FIVE entries by this user */
$ent = new EntriesController($sess_user);
$res = $ent->FindEntries();
if ($res != false) {
$dry->build_table_header();
//$rows = []; Holds the 5 last rows of the user
$count = 0;
while (($row = $res->fetch_assoc()) && ($count < 5))
{
//array_push($rows, $row);
$dry->build_table_row($row);
$count++;
}
echo "</table>";
// Reverse the rows from newer to older
// $rows = array_reverse($rows);
// Iterate over those rows
// $dry->build_table_rows($rows);
}
?>
<!-- End dynamic PHP content -->
<!-- Manage your MedLog -->
<?php $dry->build_links(); ?>
<!-- END LOGGED IN HTML -->
<?php
}
?>
</div>
<script>
<?php $dry->build_footer(); ?>