-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookingedit.php
540 lines (506 loc) · 21.2 KB
/
bookingedit.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
<?php require("verify.php");
#### User has logged in and been verified ####
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Expires: 0");?>
<HTML>
<head>
<TITLE>ThreeD - Manage Assets</TITLE>
<LINK REL="StyleSheet" HREF="style.css" TYPE="text/css">
<META HTTP-EQUIV="Expires" CONTENT="Fri, Jun 12 1981 08:20:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
</head>
<BODY onload="document.forms[0].xtext.focus()">
<?php
$q = "'";
$bquery = "SELECT * FROM bookingthing WHERE active = 't' ORDER by id;";
$bresult = pg_query($db, $bquery);
$bnum = pg_num_rows($bresult);
for ($i=0;$i<$bnum;$i++) {
$br = pg_Fetch_array($bresult, $i, PGSQL_ASSOC);
$bthingname[$i] = $br['name'];
$bthingid[$i] = $br['id'];
}
if (!$xb) { $xb = $bthingid[0]; }
$gquery = "SELECT * FROM bookingthing ORDER by id;";
$gresult = pg_query($db, $gquery);
$gnum = pg_num_rows($gresult);
for ($i=0;$i<$gnum;$i++) {
$gr = pg_Fetch_array($gresult, $i, PGSQL_ASSOC);
$bthing[$gr[id]] = $gr['name'];
}
$todayN = mktime (0,0,0,date("m"),date("d"),date("Y"));
$today = date ("Y-m-d", $todayN);
if(isset($_POST['xdateid']))
{
settype ($xeditdate, integer);
$xeditdate = htmlspecialchars($_POST['xdateid']);
#echo "<font color=green>POSTED xeditdate= :$xeditdate:</font><br><p>";
}
$command = "newdate"; ##
if ($xeditdate) { $command = "editid"; }
if ($xdodelete) { $command = "delete"; } ##
if ($xdoupdate) { $command = "update"; } ##
if ($xdonew) { $command = "create"; } ##
if ($xdocreate) { $command = "create"; } ##
#echo "<font color=red><p><b>command= :$command:</b><p></font>";
#echo "xdodelete= :$xdodelete:<br>";
#echo "xdoupdate= :$xdoupdate:<br>";
#echo "xdonew= :$xdonew:<br>";
#echo "xdocreate= :$xdocreate:<br>";
#echo "xeditdate= :$xeditdate:<br>";
if ($command == "newdate") {
$todayN = mktime (0,0,0,date("m"),date("d"),date("Y"));
$thedayN = strtotime($xnewdate);
if (!$xnewdate || $thedayN == -1) { $thedayN = $todayN; }
$thedayN = mktime (0,0,0,date("m", $thedayN),date("d", $thedayN),date("Y", $thedayN));
$ydate = date ("Y-m-d", $thedayN);
$xdate = date ("d/m/Y", $thedayN);
if (!$admin && !$adminbook && $ydate < $today) { $dateerr = 1; }
$xdateid = "";
$xtext = "";
$xwhoid = $cid;
$xwho = $name[$cid];
#echo "<p>thedayN= :$thedayN:<p>ydate= :$ydate:<p>xdate= :$xdate:";
echo "<p><b>ENTER EVENT DETAILS</b>";
}
if ($command == "create") {
echo "<p><b>ENTER EVENT DETAILS</b>";
$err = "";
$tdate = $xdate;
if (preg_match("|(.*)/(.*)/(.*)|", $xdate, $matches)) { $xdate = $matches[2]."/".$matches[1]."/".$matches[3]; }
$thedayN = strtotime($xdate);
if (!$xdate || $thedayN == -1) {
$err = 1;
$dateerr = 1;
$xdate = $tdate;
}
else {
$todayN = mktime (0,0,0,date("m"),date("d"),date("Y"));
$today = date ("Y-m-d", $todayN);
$thedayN = mktime (0,0,0,date("m", $thedayN),date("d", $thedayN),date("Y", $thedayN));
$ydate = date ("Y-m-d", $thedayN);
$xdate = date ("d/m/Y", $thedayN);
if (!$admin && !$adminbook && $ydate < $today) { $err = 1; $dateerr = 1; }
}
$xtext = trim($xtext);
if (!$xtext) {
#echo "<p><b>NO EVENT TEXT</b>";
$err = 1;
$texterr = 1;
}
settype ($xwhoid, integer);
if (!$admin && !$adminbook) { $xwhoid = $cid; }
if (!$name[$xwhoid]) {
$err = 1;
$whoerr = 1;
}
$starttime = preg_replace ("/ +/", "", trim($xstarttime));
$starthour = "-1"; $startmin = "-1"; $startpm = 0; $startam = 0;
if (preg_match("|^([0-9:.]*)([Pp][Mm])$|", $starttime, $matches)) { $startpm = 1; $starttime = $matches[1]; }
if (preg_match("|^([0-9:.]*)([Aa][Mm])$|", $starttime, $matches)) { $startam = 1; $starttime = $matches[1]; }
if (preg_match("|^([0-9]+)[:.]+([0-9][0-9])$|", $starttime, $matches)) { $starthour = $matches[1]; $startmin = $matches[2]; }
if (preg_match("|^([0-9])$|", $starttime, $matches)) { $starthour = $matches[1]; $startmin = "0"; }
if (preg_match("|^([0-9])([0-9])$|", $starttime, $matches)) { $starthour = $matches[1].$matches[2]; $startmin = "0"; }
if (preg_match("|^([0-9])([0-9])([0-9])$|", $starttime, $matches)) { $starthour = $matches[1]; $startmin = $matches[2].$matches[3]; }
if (preg_match("|^([0-9])([0-9])([0-9])([0-9])$|", $starttime, $matches)) { $starthour = $matches[1].$matches[2]; $startmin = $matches[3].$matches[4]; }
if ($startpm && $starthour < 12) { $starthour += 12; }
if ($startam && $starthour == 12) { $starthour = 0; }
if (!$startmin) { $startmin = "00"; }
if ($startmin >= 0 && $startmin <=59 && $starthour >= 0 && $starthour <= 23) { $xstarttime = sprintf("%02.0f", $starthour) . ":" . sprintf("%02.0f", $startmin); }
else { $starterr = 1; $err = 1;}
$endtime = preg_replace ("/ +/", "", trim($xendtime));
$endhour = "-1"; $endmin = "-1"; $endpm = 0; $endam = 0;
if (preg_match("|^([0-9:.]*)([Pp][Mm])$|", $endtime, $matches)) { $endpm = 1; $endtime = $matches[1]; }
if (preg_match("|^([0-9:.]*)([Aa][Mm])$|", $endtime, $matches)) { $endam = 1; $endtime = $matches[1]; }
if (preg_match("|^([0-9]+)[:.]+([0-9][0-9])$|", $endtime, $matches)) { $endhour = $matches[1]; $endmin = $matches[2]; }
if (preg_match("|^([0-9])$|", $endtime, $matches)) { $endhour = $matches[1]; $endmin = "0"; }
if (preg_match("|^([0-9])([0-9])$|", $endtime, $matches)) { $endhour = $matches[1].$matches[2]; $endmin = "0"; }
if (preg_match("|^([0-9])([0-9])([0-9])$|", $endtime, $matches)) { $endhour = $matches[1]; $endmin = $matches[2].$matches[3]; }
if (preg_match("|^([0-9])([0-9])([0-9])([0-9])$|", $endtime, $matches)) { $endhour = $matches[1].$matches[2]; $endmin = $matches[3].$matches[4]; }
if ($endpm && $endhour < 12) { $endhour += 12; }
if ($endam && $endhour == 12) { $endhour = 0; }
if (!$endmin) { $endmin = 0; }
if ($endhour == 0 && $endmin == 0) { $endhour = 24; }
if ($endmin >= 0 && $endmin <=59 && (($endhour >= 0 && $endhour <= 23) || ($endhour == 24 && $endmin == 0))) {
$xendtime = sprintf("%02.0f", $endhour) . ":" . sprintf("%02.0f", $endmin);
if ($xendtime < $xstarttime && !$starterr) { $enderr = 1; $err = 1;}
}
else { $enderr = 1; $err = 1;}
if (!$err) {
$timenow = time();
$uquery = "INSERT INTO booking (createwho, createwhen, modifywho, modifywhen, bookedthing, text, date, starttime, endtime, active, parent) VALUES (";
$uquery = $uquery . "$q$xwhoid$q, $q$timenow$q, $q$cid$q, $q$timenow$q, $q$xb$q, $q$xtext$q, $q$ydate$q, $q$xstarttime$q, $q$xendtime$q, 'y', '0');";
$result = pg_query($db, $uquery);
echo "<p><b>EVENT HAS BEEN ADDED - ";
echo "<a href=bookings.php?xb=$xb&xdate=$xdate>Return to Bookings</b></a>\n";
header("Location: https://".$_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']) ."/bookings.php?xdate=".$xdate.'&xb='.$xb);
}
}
if ($command == "editid") {
$todayN = mktime (0,0,0,date("m"),date("d"),date("Y"));
$today = date ("Y-m-d", $todayN);
$xdateid = $xeditdate;
#echo "<b>editid function</b><p>";
#echo "<br>xeditdate_2:$xeditdate:<br>xdateid:$xdateid:<p>";
settype ($xdateid, integer);
#echo "<br>xeditdate_3:$xeditdate:<p>";
$yquery = "SELECT * FROM booking WHERE id = $q$xdateid$q;";
$yresult = pg_query($db, $yquery);
$ynum = pg_num_rows($yresult);
if ($ynum != 1) {
echo "<font color=red><b>That event does not exist.</b></font>";
echo "<br>$yquery<br>$yresult</body></html>";
exit;
}
$yr = pg_Fetch_array($yresult, 0, PGSQL_ASSOC);
$query = "SELECT * FROM booking WHERE id = $q$xdateid$q;";
#echo "<p>query= :$query:<p>";
$result = pg_query($db, $query);
$num = pg_num_rows($result);
if ($num) {
$r = pg_Fetch_array($result, 0, PGSQL_ASSOC);
$xdate = htmlentities($r[date]);
$thedayN = strtotime($xdate);
$thedayN = mktime (0,0,0,date("m", $thedayN),date("d", $thedayN),date("Y", $thedayN));
$xdate = date ("d/m/Y", $thedayN);
$xtext = addslashes($r[text]);
$xbookedthing = addslashes($r[bookedthing]);
$xb = $r[bookedthing];
$xstarttime = htmlentities($r[starttime]);
$xendtime = htmlentities($r[endtime]);
$xwhoid = $r[createwho];
$xwho = $name[$xwhoid];
}
else {
echo "<font color=red><b>That event does not exist..</b></font>";
echo "<br>$yquery<br>$yresult</body></html>";
exit;
}
if ($xwhoid != $cid && !$admin && !$adminbook) {
echo "<font color=red><b>You cannot edit other peoples events</b></font>";
echo "</body></html>";
exit;
}
if ($r[date] < $today && !$admin && !$adminbook) {
echo "<font color=red><b>You cannot edit a booking in the past</b></font>";
echo "</body></html>";
exit;
}
echo "<p><b>EDIT THIS EVENT</b>";
}
if ($command == "update") {
$todayN = mktime (0,0,0,date("m"),date("d"),date("Y"));
$today = date ("Y-m-d", $todayN);
echo "<p><font color=red><b>UPDATE</b></font><p>";
settype ($xdateid, integer);
$xdateid = $xeditdate;
#echo "xeditdate_4 :$xeditdate:<br><br>";
#echo "xdateid :$xdateid:<br>";
$yquery = "SELECT * FROM booking WHERE id = $q$xdateid$q;";
#echo "<br>yquery= :$yquery:<br>";
$yresult = pg_query($db, $yquery);
#echo "<p>yresult :$yresult:<p>";
$ynum = pg_num_rows($yresult);
if ($ynum != 1) {
echo "<font color=red><b>That event does not exist</b></font>";
echo "<br>1:<br>todayN:$todayN:<br>today:$today:<br>yquery:$yquery:<br>yresult:$yresult:<br>ynum:$ynum:<br>xdateid:$xdateid:</body></html>";
exit;
}
$yr = pg_Fetch_array($yresult, 0, PGSQL_ASSOC);
$theid = $yr[id];
if ($yr[parent]) { $theid = $yr[parent]; }
$thestatus = $yr[active];
$query = "SELECT * FROM booking WHERE id = $q$theid$q OR parent = $q$theid$q ORDER BY id DESC;";
#echo "<p>query= :$query:<p>";
$result = pg_query($db, $query);
$num = pg_num_rows($result);
if ($num) {
$r = pg_Fetch_array($result, 0, PGSQL_ASSOC);
$theid = $r[id];
#$thestatus = $r[active];
if ($r[createwho] != $cid && !$admin && !$adminbook) {
echo "<font color=red><b>You cannot update another persons record</b></font>";
echo "</body></html>";
exit;
}
if ($r[date] < $today && !$admin && !$adminbook) {
echo "<font color=red><b>You cannot change a booking in the past</b></font>";
echo "</body></html>";
exit;
}
}
else {
echo "<font color=red><b>That event does not exist</b></font>";
#echo "<br>$yquery<br>$yresult</body></html>";
exit;
}
echo "<p><b>EDIT THIS EVENT</b>"; $err = "";
$tdate = $xdate;
if (preg_match("|(.*)/(.*)/(.*)|", $xdate, $matches)) { $xdate = $matches[2]."/".$matches[1]."/".$matches[3]; }
$thedayN = strtotime($xdate);
if (!$xdate || $thedayN == -1) {
$err = 1;
$dateerr = 1;
$xdate = $tdate;
}
else {
$thedayN = mktime (0,0,0,date("m", $thedayN),date("d", $thedayN),date("Y", $thedayN));
$ydate = date ("Y-m-d", $thedayN);
$xdate = date ("d/m/Y", $thedayN);
if (!$admin && !$adminbook && $ydate < $today) { $err = 1; $dateerr = 1; }
}
$xtext = trim($xtext);
if (!$xtext) {
$err = 1;
$texterr = 1;
}
settype ($xwhoid, integer);
if (!$admin && !$adminbook) { $xwhoid = $cid; }
if (!$name[$xwhoid]) {
$err = 1;
$whoerr = 1;
}
$starttime = preg_replace ("/ +/", "", trim($xstarttime));
$starthour = "-1"; $startmin = "-1"; $startpm = 0; $startam = 0;
if (preg_match("|^([0-9:.]*)([Pp][Mm])$|", $starttime, $matches)) { $startpm = 1; $starttime = $matches[1]; }
if (preg_match("|^([0-9:.]*)([Aa][Mm])$|", $starttime, $matches)) { $startam = 1; $starttime = $matches[1]; }
if (preg_match("|^([0-9]+)[:.]+([0-9][0-9])$|", $starttime, $matches)) { $starthour = $matches[1]; $startmin = $matches[2]; }
if (preg_match("|^([0-9])$|", $starttime, $matches)) { $starthour = $matches[1]; $startmin = "0"; }
if (preg_match("|^([0-9])([0-9])$|", $starttime, $matches)) { $starthour = $matches[1].$matches[2]; $startmin = "0"; }
if (preg_match("|^([0-9])([0-9])([0-9])$|", $starttime, $matches)) { $starthour = $matches[1]; $startmin = $matches[2].$matches[3]; }
if (preg_match("|^([0-9])([0-9])([0-9])([0-9])$|", $starttime, $matches)) { $starthour = $matches[1].$matches[2]; $startmin = $matches[3].$matches[4]; }
if ($startpm && $starthour < 12) { $starthour += 12; }
if ($startam && $starthour == 12) { $starthour = 0; }
if (!$startmin) { $startmin = "00"; }
if ($startmin >= 0 && $startmin <=59 && $starthour >= 0 && $starthour <= 23) { $xstarttime = sprintf("%02.0f", $starthour) . ":" . sprintf("%02.0f", $startmin); }
else { $starterr = 1; $err = 1;}
$endtime = preg_replace ("/ +/", "", trim($xendtime));
$endhour = "-1"; $endmin = "-1"; $endpm = 0; $endam = 0;
if (preg_match("|^([0-9:.]*)([Pp][Mm])$|", $endtime, $matches)) { $endpm = 1; $endtime = $matches[1]; }
if (preg_match("|^([0-9:.]*)([Aa][Mm])$|", $endtime, $matches)) { $endam = 1; $endtime = $matches[1]; }
if (preg_match("|^([0-9]+)[:.]+([0-9][0-9])$|", $endtime, $matches)) { $endhour = $matches[1]; $endmin = $matches[2]; }
if (preg_match("|^([0-9])$|", $endtime, $matches)) { $endhour = $matches[1]; $endmin = "0"; }
if (preg_match("|^([0-9])([0-9])$|", $endtime, $matches)) { $endhour = $matches[1].$matches[2]; $endmin = "0"; }
if (preg_match("|^([0-9])([0-9])([0-9])$|", $endtime, $matches)) { $endhour = $matches[1]; $endmin = $matches[2].$matches[3]; }
if (preg_match("|^([0-9])([0-9])([0-9])([0-9])$|", $endtime, $matches)) { $endhour = $matches[1].$matches[2]; $endmin = $matches[3].$matches[4]; }
if ($endpm && $endhour < 12) { $endhour += 12; }
if ($endam && $endhour == 12) { $endhour = 0; }
if (!$endmin) { $endmin = 0; }
if ($endhour == 0 && $endmin == 0) { $endhour = 24; }
if ($endmin >= 0 && $endmin <=59 && (($endhour >= 0 && $endhour <= 23) || ($endhour == 24 && $endmin == 0))) {
$xendtime = sprintf("%02.0f", $endhour) . ":" . sprintf("%02.0f", $endmin);
if ($xendtime < $xstarttime && !$starterr) { $enderr = 1; $err = 1;}
}
else { $enderr = 1; $err = 1;}
if (!$err) {
$timenow = time();
if ($thestatus != 'x') {
$uquery = "UPDATE booking SET active = 'u' WHERE id=$q$theid$q;";
#echo "<p>uquery :$uquery:<p>";
$uresult = pg_query($db, $uquery);
}
$parent = $r[id];
if ($r[parent]) { $parent = $r[parent]; }
$uquery = "INSERT INTO booking (createwho, createwhen, modifywho, modifywhen, bookedthing, text, date, starttime, endtime, active, parent) VALUES (";
$uquery = $uquery . "$q$xwhoid$q, $q$r[createwhen]$q, $q$cid$q, $q$timenow$q, $q$xb$q, $q$xtext$q, $q$ydate$q, $q$xstarttime$q, $q$xendtime$q, 'y', $q$parent$q);";
#echo "<p>uquery :$uquery:<p>";
$uresult = pg_query($db, $uquery);
echo "<p><b>EVENT HAS BEEN UPDATED - ";
echo "<a href=bookings.php?xid=$xid&xdate=$xdate>Return to Bookings</b></a>\n";
header("Location: https://".$_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']) ."/bookings.php?xdate=".$xdate."&xb=$xb");
}
else { $r[active] = $thestatus; }
}
if ($command == "delete") {
echo "<p><font color=red><b>DELETE</b></font><p>";
$todayN = mktime (0,0,0,date("m"),date("d"),date("Y"));
$today = date ("Y-m-d", $todayN);
$err = "";
settype ($xdateid, integer);
$query = "SELECT * FROM booking WHERE id = $q$xdateid$q;";
#echo "<br>xdateid :$xdateid:<br>queryi :$query:<br>";
$result = pg_query($db, $query);
$num = pg_num_rows($result);
if ($num) {
$r = pg_Fetch_array($result, 0, PGSQL_ASSOC);
$xdateid = $r[id];
$thestatus = $r[active];
if ($r[createwho] != $cid && !$admin && !$adminbook) {
echo "<font color=red><b>You cannot delete another persons record</b></font>";
echo "</body></html>";
exit;
}
if ($r[date] < $today && !$admin && !$adminbook) {
echo "<font color=red><b>You cannot delete a booking in the past</b></font>";
echo "</body></html>";
exit;
}
if ($r[active] != 'y') {
echo "<font color=red><b>Cannot delete a non active entry</b></font>";
echo "</body></html>";
exit;
}
}
else {
echo "<font color=red><b>That event does not exist</b></font>";
#echo "<br>xdateid:$xdateid:<br>yquery:$yquery:<br>yresult:$yresult:";
echo "</body></html>";
exit;
}
if (!$err) {
$timenow = time();
if ($thestatus != 'x') {
$uquery = "UPDATE booking SET active = 'd' WHERE id=$q$xdateid$q;";
$uresult = pg_query($db, $uquery);
}
$parent = $r[id];
if ($r[parent]) { $parent = $r[parent]; }
$uquery = "INSERT INTO booking (createwho, createwhen, modifywho, modifywhen, bookedthing, text, date, starttime, endtime, active, parent) VALUES (";
$uquery = $uquery . "$q$r[createwho]$q, $q$r[createwhen]$q, $q$cid$q, $q$timenow$q, $q$r[bookedthing]$q, $q$r[text]$q, $q$r[date]$q, $q$r[starttime]$q, $q$r[endtime]$q, 'x', $q$parent$q);";
#echo "uquery= :$uquery:<br>";
$uresult = pg_query($db, $uquery);
#echo "uresult= :$uresult:<br>";
echo "<p><b>EVENT HAS BEEN DELETED - ";
echo "<a href=bookings.php?xid=$xid&xdate=$xdate>Return to Bookings</b></a>\n";
header("Location: https://".$_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']) ."/bookings.php?xdate=".$xdate."&xb=$xb");
}
}
$fdateid = htmlentities(stripslashes(trim($xdateid)));
#echo "<p>fdateid :$fdateid:<p>";
$fdate = htmlentities(stripslashes(trim($xdate)));
$ftext = htmlentities(stripslashes(trim($xtext)));
$fstarttime = htmlentities(stripslashes(trim($xstarttime)));
$fendtime = htmlentities(stripslashes(trim($xendtime)));
if ($xwhoid) { $xwho = $name[$xwhoid]; } else { $xwho = "UNKNOWN"; }
#echo "xwhoid:$xwhoid:";
?>
<form action=bookingedit.php method=post name=myform>
<?php
echo "<input type=hidden name=xdateid value=$fdateid>";
echo "<input type=hidden name=xb value=$xb>";
?>
<table border=0 cellspacing=0 cellpadding=8>
<?php
echo "<tr bgcolor=#CCCCFF>";
echo "<td><b>Resource</b></td>";
echo '<td><select name=xb>';
for ($i=0;$i<$bnum;$i++) {
$j = '<option value=' . $bthingid[$i];
if ($bthingid[$i] == $xb) { $j = $j . " selected"; }
$j = $j . ">" . $bthingname[$i] . "</option>";
echo "$j";
}
echo '</select></td></tr>';
if ($admin || $adminbook) {
echo '<tr bgcolor=#CCCCFF>';
echo '<td><b>';
if ($whoerr) { echo "<font color=red>"; }
echo 'Who For';
if ($whoerr) { echo "</font>"; }
echo '</b></td>';
echo "<td colspan=3><input type=text name=xwho value=\"$xwho\" size=30 maxlength=50 disabled>";
echo "<input type=hidden name=xwhoid value=\"$xwhoid\">";
echo '<SCRIPT LANGUAGE="JavaScript">';
echo 'function popUp(URL) {';
echo 'day = new Date();';
echo 'id = day.getTime();';
echo 'eval("page" + id + " = window.open(URL, \'" + id + "\', \'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=600,left=400,top=40\');");';
echo '}';
echo '</script>';
echo '<input type=button value="Lookup User" onClick="javascript:popUp(\'userlookup.php\')">';
echo '</td>';
echo '</tr>';
}
?>
<tr bgcolor="#CCCCFF">
<td><b>
<?php if ($dateerr) { echo "<font color=red>"; } ?>
Date
<?php if ($dateerr) { echo "</font>"; } ?>
</b></td>
<td colspan=3><input type=text name=xdate value="<?php $a=htmlentities(stripslashes($fdate)); echo "$a"; ?>" size=30 maxlength=50></td>
</tr>
<tr bgcolor="#CCCCFF">
<td><b>
<?php if ($starterr) { echo "<font color=red>"; } ?>
Start Time
<?php if ($starterr) { echo "</font>"; } ?>
</b></td>
<td colspan=3><input type=text name=xstarttime value="<?php $a=htmlentities(stripslashes($fstarttime)); echo "$a"; ?>" size=30 maxlength=50>
<INPUT TYPE=button VALUE="All Day"
ONCLICK="document.myform.xstarttime.value='00:00';document.myform.xendtime.value='24:00';">
</td>
</tr>
<tr bgcolor="#CCCCFF">
<td><b>
<?php if ($enderr) { echo "<font color=red>"; } ?>
End Time
<?php if ($enderr) { echo "</font>"; } ?>
</b></td>
<td colspan=3><input type=text name=xendtime value="<?php $a=htmlentities(stripslashes($fendtime)); echo "$a"; ?>" size=30 maxlength=50></td>
</tr>
<tr bgcolor="#CCCCFF">
<td><b>
<?php if ($texterr) { echo "<font color=red>"; } ?>
Text
<?php if ($texterr) { echo "</font>"; } ?>
</b></td>
<td colspan=3><input type=text name=xtext value="<?php $a=htmlentities(stripslashes($ftext)); echo "$a"; ?>" size=50 maxlength=100></td>
</tr>
</table>
<?php
if ($fdateid) {
echo '<p><input type=submit name=xdoupdate value=Update> ';
echo "<input type=submit name=xdonew value=Duplicate> ";
if ( $r[active] == 'y') {
echo "<input type=submit name=xdodelete value=Delete>";
}
}
else {
echo '<p><input type="submit" name="xdocreate" value="New">';
}
echo "</form>";
if ($admin || $adminbook) {
if ($xdateid) {
#echo "<br>xeditdate_3:$xeditdate:<br>xdateid:$xdateid:";
#settype ($xeditdate, integer);
$theid = $r[id];
if ($r[parent]) { $theid = $r[parent]; }
$wquery = "SELECT * FROM booking WHERE id = $q$theid$q
OR parent = $theid ORDER by id;";
$wresult = pg_query($db, $wquery);
$wnum = pg_num_rows($wresult);
echo "<p><table border=0 cellspacing=2 cellpadding=2 bgcolor=white>";
echo "<tr bgcolor=lightgrey>";
echo "<th align=left>Action</th>";
echo "<th align=left>Who did it</th>";
echo "<th align=left>When it was done</th>";
echo "<th align=left>Resource</th>";
echo "<th align=left>Who For</th>";
echo "<th align=left>Date</th>";
echo "<th align=left>Start Time</th>";
echo "<th align=left>End Time</th>";
echo "<th align=left>Text</th>";
echo "</tr>";
for ($j=0;$j<$wnum;$j++) {
$r = pg_Fetch_array($wresult, $j, PGSQL_ASSOC);
$datetime = date ("d/m/Y h:ia", $r[modifywhen]);
$status = "Changed";
if ($j == 0) { $status = "Created"; }
if ($r[active] == 'x') { $status = "Deleted"; }
if ($r[active] == 'y') { $status = "Current"; }
echo '<tr align=left bgcolor=lightgrey>';
echo "<td>$status</td><td>".$name[$r[modifywho]]."</td><td>$datetime</td>";
echo "<td>".$bthing[$r[bookedthing]]."</td><td>".$name[$r[createwho]]."</td><td>$r[date]</td>";
echo "<td>$r[starttime]</td><td>$r[endtime]</td><td>".htmlentities($r[text]);
echo "</td>";
echo '</tr>';
}
echo "</TABLE>";
}
}
?>
</BODY>
</HTML>