-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.php
167 lines (153 loc) · 4.87 KB
/
manage.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
/* MedLog MANAGE Module ~~~~~ Add, Delete and Edit MedLog edits.
Check login firstly... */
require_once("./include/usercontrol.php");
require_once("./include/entries.php");
require_once("./include/static.php");
$u = new UserControl();
$dry = new DRYHelper();
if (!$u->CheckLogin())
{
// Not logged-in, redirect to index
header("Location: index.php");
die();
}
// Now we assume we're logged in! Get the username.
$sess_user = $_SESSION[$u->GetLoginSessionVar()];
$op = $_GET["op"];
// Start the HTML love
$dry->build_header("Manage");
?>
<h1>MedLog MANAGE</h1>
<div id="content">
<?php
// Let's try and find out what we're trying to do.
if ($op == "add")
{
/* Add a new entry to the journal */
?>
<h2>Add new entry</h2>
<div id="content">
<!-- File-specific script -->
<script>
// Main function
$(document).ready(function() {
// Validate the form
mjm.setForm("#addentry");
mjm.watchForm();
});
</script>
<form id="addentry">
<fieldset>
<label for="drug">Drug name: </label>
<input type="text" name="drug" required />
<br />
<label for="dose">Dose: </label>
<input type="text" size="5" name="dose" required />
<input type="radio" name="dose_unit" value="mg" checked> mg
<input type="radio" name="dose_unit" value="g"> g
<input type="radio" name="dose_unit" value="oz."> oz
<br />
<label for="datetime">Date and time: </label>
<input type="datetime-local" name="datetime" required value="<?php echo date("Y-m-d\TH:i"); ?>" />
<br />
<label for="comment">Comments: </label>
<input type="text" name="comment" value=" " />
<br />
<input type="hidden" name="op" value="add" />
<input type="submit" value="Submit" />
</fieldset>
</form>
<?php
} else if ($op == "rem")
{
?>
<h2>Remove an entry</h2>
<script>
// Main function
$(document).ready(function() {
// Validate the form
mjm.setForm("#rem-entry");
mjm.watchForm();
});
</script>
<p class="warning">To find the ID of the entry you want to remove, check in your MedLog.</p>
<form id="rem-entry">
<fieldset>
<label for="id">Entry ID: </label>
<input type="text" size=3 name="id" required/>
<input type="hidden" name="op" value="rem" />
<input type="submit" value="Submit" />
</fieldset>
</form>
<?php
} else if ($op == "edit")
{
?>
<h2>Edit an entry</h2>
<script>
// Main function
$(document).ready(function() {
// Validate the form
mjm.setForm("#edit-entry");
mjm.fetch("#edit-entry-values", sendEditForm);
// Second form now
function sendEditForm() {
mjm.setForm("#edit-entry-values");
mjm.watchForm();
}
});
</script>
<p class="warning">To find the ID of the entry you want to edit, check in your MedLog.</p>
<form id="edit-entry">
<fieldset>
<label for="id">Entry ID: </label>
<input type="text" size=3 name="id" required />
<input type="hidden" name="op" value="fetch" />
<input type="submit" value="Submit" />
</fieldset>
</form>
<form id="edit-entry-values" style="display: none;">
<fieldset>
<label for="drug">Drug name: </label>
<input type="text" name="drug" value=""/ required>
<br />
<label for="dose">Dose: </label>
<input type="text" size="5" name="dose" value="" required/>
<input type="radio" name="dose_unit" id="mg" value="mg"> mg
<input type="radio" name="dose_unit" id="g" value="g"> g
<input type="radio" name="dose_unit" id="oz." value="oz."> oz
<br />
<label for="datetime">Date and time: </label>
<input type="datetime-local" name="datetime" required value="" />
<br />
<label for="comment">Comments: </label>
<input type="text" name="comment" value=""/>
<br />
<input type="hidden" name="op" value="edit" />
<input type="hidden" name="id" value="" />
<input type="submit" value="Submit" />
</fieldset>
</form>
<?php
} else if ($op == "trip")
{
?>
<h2>Generate a trip report</h2>
<p class="warning">To generate a trip report, specify the trip's date and then select all the entries
to be included in the report.</p>
<form id="gen-trip" action="trip.php" method="POST" data-parsley-validate>
<fieldset>
<label for="date">Trip date: </label>
<input type="date" name="date" required/>
<input type="hidden" name="done" value="no" />
<input type="submit" value="Submit" />
</fieldset>
</form>
<?php
}
echo "<div id='incoming'></div>";
echo "</div>";
$dry->build_links();
$dry->build_footer();
?>