-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_appt.php
217 lines (190 loc) · 5.82 KB
/
edit_appt.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
217
<?php
ob_start(); // Output buffering - allows header rewrites to happen at anytime before flushing the buffer
session_start();
require_once("incdir.php.inc");
require_once("config.php");
include_php_dir("includes");
mysql_init();
document_header();
echo include_javascript_dir("js",$debug);
echo include_stylesheet_dir("stylesheets",$debug);
//stupid datepicker
echo '<script src="http://eternicode.github.io/bootstrap-datepicker/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>';
check_validated();
//Any pre-page logic should go here!
if (isset($_POST['updateAppt-submit'])) {
$_POST['quest_id'] = $_GET['quest_id'];
appt_edit($_POST);
}
if (isset($_POST['delete_appt-submit'])) {
appt_delete($_GET['quest_id']);
echo "<script>window.close();</script>";
}
if (isset($_GET['quest_id']))
$apptinfo = get_appt_info($_GET['quest_id']);
draw_page($apptinfo);
close_page();
ob_end_flush(); // Flush the buffer out to client
document_footer(); mysql_end();
function draw_page($apptinfo)
{
?>
<div class="container">
<div class="col-xs-12">
<h3>
Edit Appointment
<div class="pull-right">
<button class="btn btn-danger btn-sm" data-toggle="modal" data-target="#delete">Delete</button>
</div>
</h3>
</div>
<?php
draw_appt_edit_form($apptinfo);
draw_delete_appt_modal();
?>
</div>
<?php
}
function draw_appt_edit_form($apptinfo) {
global $appt_types,$buildings;
$date=date('Y-m-d', strtotime($apptinfo['datetime']));
$time=date('H:00:00', strtotime($apptinfo['datetime']));
?>
<form action='' method='post' role="form">
<div class="form-group col-xs-6">
<label for="date">Date</label>
<div class="input-group date">
<input type="text" class="form-control" name="date" value=<?php echo '"'.$date.'"'; ?>><span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
<div class="form-group col-xs-6">
<label for="time">Time</label>
<select class="form-control" name="time">
<?php
for ($i=10;$i<=18;$i++) {
if ($i>12) {
$j = $i-12;
$ampm = 'pm';
}
else {
$j = $i;
$ampm = 'am';
}
echo '<option value="'.$i.'">'.$j.':00 '.$ampm.'</option>';
}
?>
</select>
</div>
<div class="form-group col-xs-6">
<label for="type">Type</label>
<select class="form-control" name="type">
<?php
for ($i=0;$i<count($appt_types);$i++) {
echo '<option value='.$i;
if ($apptinfo['type']==$i)
echo ' selected="true"';
echo '>'.ucfirst(appt_type_to_string($i)).'</option>';
}
?>
</select>
</div>
<div class="form-group col-xs-6">
<label for="tt">Trouble Ticket</label>
<input type="text" class="form-control" name="tt" value=<?php echo $apptinfo['tt']; ?>>
</div>
<div class="form-group col-xs-6">
<label for="building">Building</label>
<select class="form-control" name="building">
<?php
foreach ($buildings as $building) {
echo '<option value="'.strtolower(str_replace(' ', '_', $building)).'"';
if (strtolower(str_replace(' ','_',$building))==$apptinfo['building'])
echo ' selected="true"';
echo '>'.$building.'</option>';
}
?>
</select>
</div>
<div class="form-group col-xs-6">
<label for="room">Room</label>
<input type="text" class="form-control" name="room" value="<?php echo $apptinfo['room']; ?>">
</div>
<div class="form-group col-xs-6">
<label for="tech_id">Technician</label>
<select class="form-control" name="tech_id">
<?php
$users = get_users();
while ($user = $users->fetch_array()) {
echo '<option value='.$user['user_id'];
if ($user['user_id']==$apptinfo['tech_id'])
echo ' selected="true"';
echo '>'.$user['fname'].' '.$user['lname'].'</option>';
}
?>
</select>
</div>
<div class="col-xs-6">
<input type="hidden" name="updateAppt-submit" value="true">
<button type="submit" class="btn btn-default pull-right">Update</button>
</div>
</form>
<?php
}
function draw_delete_appt_modal() {
?>
<form role="form" action="" method="post">
<div class="modal fade" id="delete">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>Really Delete?</p>
</div>
<div class="modal-footer">
<input type="hidden" name="delete_appt-submit" value="true">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Yes, Really Delete</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</form>
<?
}
?>
<!-- Closes the window on esc keypress. -->
<script>
$(document).keydown(function(e) {
// ESCAPE key pressed
if (e.keyCode == 27) {
window.close();
}
});
window.opener.location.reload(false);
</script>
<!-- Datepicker today set here -->
<script>
var today = new Date('<?php echo $apptinfo['datetime']; ?>');
var dd = today.getTime();
var mm = today.getMonth()+1; //Jan is 0!
var yyyy = today.getFullYear();
if (dd<10) {
dd='0'+dd
}
if (mm<10) {
mm='0'+mm
}
today=yyyy+'-'+mm+'-'+dd;
endyear = yyyy+2;
enddate =endyear+'-'+mm+'-'+dd;
$('.input-group.date').datepicker({
format: "yyyy-mm-dd",
endDate: enddate,
todayBtn: "linked",
autoclose: true,
todayHighlight: true
});
</script>