-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshots.php
1844 lines (1574 loc) · 77.5 KB
/
snapshots.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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<!--
Copyright: Darren Hester 2006, www.designsbydarren.com
License: Released Under the "Creative Commons License",
creativecommons.org/licenses/by-nc/2.5/
-->
<head>
<!-- Meta Data -->
<meta name = "pinterest" content = "nopin" description = "The rights for images on this website lie with the copyright holder, and not BRDatabase!" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="title" content="BRDatabase, locomotive allocations, withdrawals and scrapping details in the UK" />
<meta name="description" content="Locomotive history, railway statistics, steam, diesel and electric locomotives UK" />
<meta name="keywords" content="steam, diesel, electric, locomotives, railways, LNER, LMS, GWR, Southern, Stanier, Gresley, Collett, Maunsell, Bulleid, Churchward, Riddles, Britannia, locos, //withdrawals, North British, Swindon, Crewe, Doncaster, Derby, Darlington, Eastleigh, Ashford, Brighton, Cowlairs, Inverurie, Gorton, Great Central, Great Northern, scrapping, allocations " />
<meta http-equiv="Content-Language" content="en-gb">
<!-- Site Title -->
<!-- Link to Style External Sheet -->
<style type="text/css">
@import "css/nestedsidebar.css";
@import "css/style.css";
</style>
<link rel="stylesheet" href="css/bubble-tooltip.css" media="screen" />
<script type="text/javascript" src="scripts/bubble-tooltip.js"></script>
<script type="text/javascript" src="scripts/sorttable.js"></script>
<script type="text/javascript">
//<![CDATA[
//Nested Side Bar Menu (Mar 20th, 09)
//By Dynamic Drive: www.dynamicdrive.com/style/
var menuids=["sidebarmenu1"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas
function initsidebarmenu()
{
for (var i=0; i<menuids.length; i++)
{
var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
for (var t=0; t<ultags.length; t++)
{
ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle"
if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
{
//dynamically position first level submenus to be width of main menu item
ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px"
}
else //else if this is a sub level submenu (ul)
{
//position menu to the right of menu item that activated it
ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"
}
ultags[t].parentNode.onmouseover=function()
{
this.getElementsByTagName("ul")[0].style.display="block"
}
ultags[t].parentNode.onmouseout=function()
{
this.getElementsByTagName("ul")[0].style.display="none"
}
}
for (var t=ultags.length-1; t>-1; t--)
{ // loop through all sub menus again, and use "display:none" to hide menus
// (to prevent possible page scrollbars
ultags[t].style.visibility="visible"
ultags[t].style.display="none"
}
}
}
if (window.addEventListener)
window.addEventListener("load", initsidebarmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", initsidebarmenu)
//]]>
</script><!--end script -->
</head>
<body>
<?php require_once "lib/quickdb.class.php"; require_once "lib/brlib.php"; fn_check_country($_SERVER['REMOTE_ADDR']); ?>
<div id="page_wrapper">
<div id="header_wrapper">
<div id="header">
<h1>BR<font color="#FFDF8C">Database</font></h1>
<h2>Complete BR Locomotive Database 1948-1997</h2>
<!--
<div id="topright">
<form method="get" id="searchform" action="">
<div class="searchbox">
<label for="s">Search:</label>
<input type="text" value="" name="s" id="s" size="14" />
<input type="hidden" id="searchsubmit" value="Search" />
</div>
</form>
</div>
-->
</div><!-- end header -->
<div id="navcontainer">
<ul id="navlist">
<li><a href="index.php">Home</a></li>
<li><a href="lazarus/index.php">Guestbook</a></li>
<li><a href="contact.php">Contact</a></li>
<li><a href="links.php">Links</a></li>
<li><a href="preferences.php">Preferences</a></li>
</ul>
</div><!-- end navcontainer -->
</div><!-- end header_wrapper -->
<div id="left_side">
<h3>Menu</h3>
<div class="sidebarmenu">
<?php include "includes/master_menu.html"; ?>
</div><!-- end sidebarmenu -->
<h3>Quick Search</h3>
<p>
Enter locomotive number in the box below and press 'Go'!
</p>
<div id="bubble_tooltip">
<div class="bubble_top"><span></span></div>
<div class="bubble_middle"><span id="bubble_tooltip_content">Content is coming here as you probably can see. Content is coming here as you probably can see.</span></div>
<div class="bubble_bottom"></div>
</div>
<!-- search bar -->
<?php include "includes/searchbar.html"; ?>
<h3>Counter</h3>
<div class='featurebox_side'>
<?php include "lib/counter.php"; ?>
</div><!-- end featurebox_side -->
<h3>Advertising</h3>
<div class='featurebox_side'>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4778123637289700";
/* test */
google_ad_slot = "6591011963";
google_ad_width = 125;
google_ad_height = 125;
//-->
</script>
<script type="text/javascript"
src="pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br /><br />
</div><!-- end featurebox_side -->
<h3>In Touch</h3>
<div class='featurebox_side'>
<!-- AddThis Button BEGIN -->
<script type="text/javascript">var addthis_config = {"data_track_clickback":true};</script>
<a class="addthis_button" href="www.addthis.com/bookmark.php?v=250&username=ij1001"><img src="s7.addthis.com/static/btn/sm-share-en.gif" width="83" height="16" alt="Bookmark and Share" style="border:0" /></a><script type="text/javascript" src="s7.addthis.com/js/250/addthis_widget.js#username=ij1001"></script>
<!-- AddThis Button END -->
<br /><br />
<a href="twitter.com/brdatabase"><img src="./images/twitter.png" width="83" height="16" alt="Follow BRDatabase on Twitter" style="border:0" /></a>
</div><!-- end featurebox_side -->
</div><!-- end left_side-->
<div id="content">
<?php
// 1 possible parameter
// page <$pg> - page selected
$pg = ""; // $_GET parameters
foreach ($_GET as $key => $value)
{
if ($key == "page")
{
$pg = $value;
if (!empty($pg))
fn_check_alpha($pg, 12);
}
else
if ($key == "fbclid")
{
}
else
fn_poem($key, $value, 99);
}
if (isset($pg) or !empty($pg))
{
if ($pg == "workings")
{
printf("<h4>Locomotive Workings Snapshot</h4>\n");
}
else
if ($pg == "locos")
{
printf("<h4>Locomotive Allocation Snapshot</h4>\n");
}
else
if ($pg == "regional")
{
printf("<h4>Regional Events Snapshot</h4>\n");
}
else
{
die("Unknown page request");
}
}
else
{
// default page requested
printf("<h4>Snapshots Page</h4>");
printf("<p>You have three options: <br /> 1) obtain a snapshot of all locomotives extant in a particular month grouped by depot");
printf("<br /> 2) obtain a snapshot of workings and dispositions of all locos for a given month");
printf("<br /> 3) take a snapshot by region of all withdrawals/new builds/allocations and storages</p>");
printf("<ul><li><a href=\"%s?page=locos\">Allocation Snapshot</a></li>\n", $PHP_SELF);
printf(" <li><a href=\"%s?page=workings\">Workings Snapshot</a></li>\n", $PHP_SELF);
printf(" <li><a href=\"%s?page=regional\">Regional Snapshot</a></li></ul>\n", $PHP_SELF);
die(1);
}
$formsubmitted = 0;
if (isset($_POST['year_select']))
{
$formsubmitted = 1;
// 5 possible parameters
// mon_select <$mval> - month start 01-12
// year_select <$yval> - year start (4 digits)
// locotype <$type> - array of loco types (D, S etc...)
// region <$reg> - array of regions ( )
// region_sel <$r> - selected region
$mval = $yval = $type = $reg = $r = "";
// $_POST parameters
foreach ($_POST as $key => $value)
{
if ($key == "mon_select")
{
$mval = $value;
if (!empty($mval))
fn_check_digit($mval, 2);
}
else
if ($key == "year_select")
{
$yval = $value;
if (!empty($yval))
fn_check_digit($yval, 4);
}
else
if ($key == "locotype") // this is an array - taken from form so already uppercase
{
$type = $value;
if (is_array($type))
for ($nx = 0; $nx < count($type); $nx++)
if (!empty($type[$nx]))
fn_check_type($type[$nx]);
}
else
if ($key == "region") // this is an array
{
$reg = $value;
if (is_array($reg))
for ($nx = 0; $nx < count($reg); $nx++)
if (!empty($reg[$nx]))
fn_check_alpha($reg[$nx], 3);
}
else
if ($key == "region_sel")
{
$r = $value;
if (!empty($r))
fn_check_alpha($r, 3);
}
else
fn_poem($key, $value, 99);
}
// Parameters now checked
$region = $r;
$m = $mval;
$y = $yval;
$srchdate = $y . "-" . $m . "-01";
$sclause = $dclause = $eclause = " 1 = 0 ";
for ($nc = 0; $nc < count($type); $nc++)
{
switch ($type[$nc][0])
{
case 'S':
$gots = 1;
$sclause = " 1 = 1 ";
break;
case 'D':
$gotd = 1;
$dclause = " 1 = 1 ";
break;
case 'E':
$gote = 1;
$eclause = " 1 = 1 ";
break;
}
}
$regionclause = "";
for ($nc = 0; $nc < count($reg); $nc++)
{
if ($nc == 0)
{
$regionclause = ' AND dep_cd.region IN ("' . $reg[$nc] . '"';
}
else
{
$regionclause .= ', "' . $reg[$nc] . '"';
}
if ($nc == (count($reg)-1))
{
$regionclause .= ') ';
}
}
} //
if ($pg == "workings" && $formsubmitted)
{
printf("<div class='featurebox_center'>\n");
printf("</div> <!-- featurebox_center -->\n");
}
else
if ($pg == "regional" && $formsubmitted)
{
printf("<div class='featurebox_center'>\n");
include_once "lib/quickdb.class.php";
include_once "lib/brlib.php";
include_once "lib/MyTables.class.php";
#echo "Regional: " . $mval . ", " . $yval . " - " . $region . "<br />";
$search_date = $mval . "-" . $yval;
if ($mval != "00")
{
if ($mval == "01")
$caps = "January " . $yval;
else
if ($mval == "02")
$caps = "February " . $yval;
else
if ($mval == "03")
$caps = "March " . $yval;
else
if ($mval == "04")
$caps = "April " . $yval;
else
if ($mval == "05")
$caps = "May " . $yval;
else
if ($mval == "06")
$caps = "June " . $yval;
else
if ($mval == "07")
$caps = "July " . $yval;
else
if ($mval == "08")
$caps = "August " . $yval;
else
if ($mval == "09")
$caps = "September " . $yval;
else
if ($mval == "10")
$caps = "October " . $yval;
else
if ($mval == "11")
$caps = "November " . $yval;
else
if ($mval == "12")
$caps = "December " . $yval;
}
else
$caps = $yval;
$tb = new MyTables("rsnapshot");
$tb->sortable();
$tb->colour_coordinate("Y");
$tb->add_column("number", "Number", 10);
$tb->add_column("loco_class", "Class", 8);
$tb->add_column("region", "Region", 5);
$tb->add_column("allocation1", "Allocation", 5);
$tb->add_column("depot1", "Depot", 18);
$tb->add_column("event_date2", "Date", 11);
$tb->add_column("status", "Event", 43);
$sqld =
'SELECT "NEW" AS status,
"D" AS type,
d.loco_id AS loco_id,
dn.number AS number,
concat("locoqry.php?action=locodata&id=", d.loco_id,
"&type=D&loco=", dn.number) AS number_hl,
dn.number_type AS number_type,
d.b_date AS event_date1,
concat(date_format(d.b_date, "%Y%m%d"),
lpad(d.loco_id, 10, "0")) AS event_date1_fmt,
d.first_depot AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code1_hl,
dp.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name1_hl,
dp.depot_id AS depot_id1,
dcc.region AS region1,
d.b_date AS event_date2,
concat(date_format(d.b_date, "%Y%m%d"),
lpad(d.loco_id, 10, "0")) AS event_date2_fmt,
d.first_depot AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code2_hl,
dp.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name2_hl,
dp.depot_id AS depot_id2,
dcc.region AS region2,
dc.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
dc.d_class_id, "&type=D&page=fleet") AS loco_class_hl
FROM diesels d
JOIN d_nums dn
ON dn.loco_id = d.loco_id
AND dn.first_number = "Y"
JOIN ref_depot_codes dcc
ON dcc.depot_code = d.first_depot
AND dcc.date_from = (SELECT max(dcc1.date_from)
FROM ref_depot_codes dcc1
WHERE dcc1.depot_code = d.first_depot
AND dcc1.date_from <= d.b_date)
JOIN ref_depot dp
ON dp.depot_id = dcc.depot_id
JOIN d_class_link dcl
ON dcl.loco_id = d.loco_id
AND dcl.start_date = (SELECT max(dcl1.start_date)
FROM d_class_link dcl1
WHERE dcl1.loco_id = d.loco_id
AND dcl1.start_date <= d.b_date)
JOIN d_class dc
ON dc.d_class_id = dcl.d_class_id
WHERE dcc.region = "' . $region . '"
AND date_format(d.b_date, "%m-%Y") = "' . $search_date . '"
UNION
SELECT "WDN" AS status,
"D" AS type,
d.loco_id AS loco_id,
dn.number AS number,
concat("locoqry.php?action=locodata&id=", d.loco_id,
"&type=D&loco=", dn.number) AS number_hl,
dn.number_type AS number_type,
d.w_date AS event_date1,
concat(date_format(d.w_date, "%Y%m%d"),
lpad(d.loco_id, 10, "0")) AS event_date1_fmt,
d.last_depot AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code1_hl,
dp.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name1_hl,
dp.depot_id AS depot_id1,
dcc.region AS region1,
d.w_date AS event_date2,
concat(date_format(d.w_date, "%Y%m%d"),
lpad(d.loco_id, 10, "0")) AS event_date2_fmt,
d.last_depot AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code2_hl,
dp.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name2_hl,
dp.depot_id AS depot_id2,
dcc.region AS region2,
dc.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
dc.d_class_id, "&type=D&page=fleet") AS loco_class_hl
FROM diesels d
JOIN d_nums dn
ON dn.loco_id = d.loco_id
AND dn.start_date = (SELECT max(dn1.start_date)
FROM d_nums dn1
WHERE dn1.loco_id = dn.loco_id
AND dn1.carried_number = "Y"
AND dn1.start_date <= d.w_date)
JOIN ref_depot_codes dcc
ON dcc.depot_code = d.last_depot
AND dcc.date_from = (SELECT max(dcc1.date_from)
FROM ref_depot_codes dcc1
WHERE dcc1.depot_code = d.last_depot
AND dcc1.date_from <= d.w_date)
JOIN ref_depot dp
ON dp.depot_id = dcc.depot_id
JOIN d_class_link dcl
ON dcl.loco_id = d.loco_id
AND dcl.start_date = (SELECT max(dcl1.start_date)
FROM d_class_link dcl1
WHERE dcl1.loco_id = d.loco_id
AND dcl1.start_date <= d.w_date)
JOIN d_class dc
ON dc.d_class_id = dcl.d_class_id
WHERE dcc.region = "' . $region . '"
AND date_format(d.w_date, "%m-%Y") = "' . $search_date . '"
UNION
SELECT CASE WHEN ifnull(dpc1.region, "X") = "' . $region . '" THEN
CASE WHEN ifnull(dpc2.region, "X") = "' . $region . '" THEN
"INT"
ELSE
"IRO"
END
ELSE
"IRI"
END AS status,
"D" AS type,
da2.loco_id AS loco_id,
dn.number AS number,
concat("locoqry.php?action=locodata&id=", da2.loco_id,
"&type=D&loco=", dn.number) AS number_hl,
dn.number_type AS number_type,
da1.alloc_date AS event_date1,
concat(date_format(da2.alloc_date, "%Y%m%d"),
lpad(da2.loco_id, 10, "0")) AS event_date1_fmt,
coalesce(dpc1.displayed_depot_code, da1.allocation) AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp1.depot_id) AS depot_code1_hl,
dp1.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp1.depot_id) AS depot_name1_hl,
dp1.depot_id AS depot_id1,
dpc1.region AS region1,
da2.alloc_date AS event_date2,
concat(date_format(da2.alloc_date, "%Y%m%d"),
lpad(da2.loco_id, 10, "0")) AS event_date2_fmt,
coalesce(dpc2.displayed_depot_code, da2.allocation) AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp2.depot_id) AS depot_code2_hl,
dp2.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp2.depot_id) AS depot_name2_hl,
dp2.depot_id AS depot_id2,
dpc2.region AS region2,
dc.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
dc.d_class_id, "&type=D&page=fleet") AS loco_class_hl
FROM d_alloc da2
JOIN ref_depot_codes dpc2
ON dpc2.depot_code = da2.allocation
AND dpc2.date_from = (SELECT max(dpc2a.date_from)
FROM ref_depot_codes dpc2a
WHERE dpc2a.depot_code = da2.allocation
AND dpc2a.date_from <= da2.alloc_date)
JOIN ref_depot dp2
ON dp2.depot_id = dpc2.depot_id
JOIN d_alloc da1
ON da1.loco_id = da2.loco_id
AND concat(da1.alloc_date, da1.seq) = (SELECT max(concat(da1a.alloc_date, da1a.seq))
FROM d_alloc da1a
WHERE da1a.loco_id = da2.loco_id
AND concat(da1a.alloc_date, da1a.seq) <
concat(da2.alloc_date, da2.seq))
JOIN ref_depot_codes dpc1
ON dpc1.depot_code = da1.allocation
AND dpc1.date_from = (SELECT max(dpc1a.date_from)
FROM ref_depot_codes dpc1a
WHERE dpc1a.depot_code = da1.allocation
AND dpc1a.date_from <= da1.alloc_date)
JOIN ref_depot dp1
ON dp1.depot_id = dpc1.depot_id
JOIN d_nums dn
ON dn.loco_id = da2.loco_id
AND dn.start_date = (SELECT max(dn1.start_date)
FROM d_nums dn1
WHERE dn1.loco_id = da2.loco_id
AND dn1.start_date <= da2.alloc_date)
JOIN d_class_link dcl
ON dcl.loco_id = da2.loco_id
AND dcl.start_date = (SELECT max(dcl1.start_date)
FROM d_class_link dcl1
WHERE dcl1.loco_id = da2.loco_id
AND dcl1.start_date <= da2.alloc_date)
JOIN d_class dc
ON dc.d_class_id = dcl.d_class_id
WHERE date_format(da2.alloc_date, "%m-%Y") = "' . $search_date . '"
AND (dpc1.region = "' . $region . '" OR dpc2.region = "' . $region . '")';
$sqle =
'SELECT "NEW" AS status,
"E" AS type,
e.loco_id AS loco_id,
en.number AS number,
concat("locoqry.php?action=locodata&id=", e.loco_id,
"&type=E&loco=", en.number) AS number_hl,
en.number_type AS number_type,
e.b_date AS event_date1,
concat(date_format(e.b_date, "%Y%m%d"),
lpad(e.loco_id, 10, "0")) AS event_date1_fmt,
e.first_depot AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code1_hl,
dp.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name1_hl,
dp.depot_id AS depot_id1,
dcc.region AS region1,
e.b_date AS event_date2,
concat(date_format(e.b_date, "%Y%m%d"),
lpad(e.loco_id, 10, "0")) AS event_date2_fmt,
e.first_depot AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code2_hl,
dp.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name2_hl,
dp.depot_id AS depot_id2,
dcc.region AS region2,
ec.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
ec.e_class_id, "&type=E&page=fleet") AS loco_class_hl
FROM electric e
JOIN e_nums en
ON en.loco_id = e.loco_id
AND en.first_number = "Y"
JOIN ref_depot_codes dcc
ON dcc.depot_code = e.first_depot
AND dcc.date_from = (SELECT max(dcc1.date_from)
FROM ref_depot_codes dcc1
WHERE dcc1.depot_code = e.first_depot
AND dcc1.date_from <= e.b_date)
JOIN ref_depot dp
ON dp.depot_id = dcc.depot_id
JOIN e_class_link ecl
ON ecl.loco_id = e.loco_id
AND ecl.start_date = (SELECT max(ecl1.start_date)
FROM e_class_link ecl1
WHERE ecl1.loco_id = e.loco_id
AND ecl1.start_date <= e.b_date)
JOIN e_class ec
ON ec.e_class_id = ecl.e_class_id
WHERE dcc.region = "' . $region . '"
AND date_format(e.b_date, "%m-%Y") = "' . $search_date . '"
UNION
SELECT "WDN" AS status,
"E" AS type,
e.loco_id AS loco_id,
en.number AS number,
concat("locoqry.php?action=locodata&id=", e.loco_id,
"&type=E&loco=", en.number) AS number_hl,
en.number_type AS number_type,
e.w_date AS event_date1,
concat(date_format(e.w_date, "%Y%m%d"),
lpad(e.loco_id, 10, "0")) AS event_date1_fmt,
e.last_depot AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code1_hl,
dp.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name1_hl,
dp.depot_id AS depot_id1,
dcc.region AS region1,
e.w_date AS event_date2,
concat(date_format(e.w_date, "%Y%m%d"),
lpad(e.loco_id, 10, "0")) AS event_date2_fmt,
e.last_depot AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code2_hl,
dp.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name2_hl,
dp.depot_id AS depot_id2,
dcc.region AS region2,
ec.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
ec.e_class_id, "&type=E&page=fleet") AS loco_class_hl
FROM electric e
JOIN e_nums en
ON en.loco_id = e.loco_id
AND en.start_date = (SELECT max(en1.start_date)
FROM e_nums en1
WHERE en1.loco_id = en.loco_id
AND en1.carried_number = "Y"
AND en1.start_date <= e.w_date)
JOIN ref_depot_codes dcc
ON dcc.depot_code = e.last_depot
AND dcc.date_from = (SELECT max(dcc1.date_from)
FROM ref_depot_codes dcc1
WHERE dcc1.depot_code = e.last_depot
AND dcc1.date_from <= e.w_date)
JOIN ref_depot dp
ON dp.depot_id = dcc.depot_id
JOIN e_class_link ecl
ON ecl.loco_id = e.loco_id
AND ecl.start_date = (SELECT max(ecl1.start_date)
FROM e_class_link ecl1
WHERE ecl1.loco_id = e.loco_id
AND ecl1.start_date <= e.w_date)
JOIN e_class ec
ON ec.e_class_id = ecl.e_class_id
WHERE dcc.region = "' . $region . '"
AND date_format(e.w_date, "%m-%Y") = "' . $search_date . '"
UNION
SELECT CASE WHEN ifnull(dpc1.region, "X") = "' . $region . '" THEN
CASE WHEN ifnull(dpc2.region, "X") = "' . $region . '" THEN
"INT"
ELSE
"IRO"
END
ELSE
"IRI"
END AS status,
"E" AS type,
ea2.loco_id AS loco_id,
en.number AS number,
concat("locoqry.php?action=locodata&id=", ea2.loco_id,
"&type=E&loco=", en.number) AS number_hl,
en.number_type AS number_type,
ea1.alloc_date AS event_date1,
concat(date_format(ea2.alloc_date, "%Y%m%d"),
lpad(ea2.loco_id, 10, "0")) AS event_date1_fmt,
coalesce(dpc1.displayed_depot_code, ea1.allocation) AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp1.depot_id) AS depot_code1_hl,
dp1.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp1.depot_id) AS depot_name1_hl,
dp1.depot_id AS depot_id1,
dpc1.region AS region1,
ea2.alloc_date AS event_date2,
concat(date_format(ea2.alloc_date, "%Y%m%d"),
lpad(ea2.loco_id, 10, "0")) AS event_date2_fmt,
coalesce(dpc2.displayed_depot_code, ea2.allocation) AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp2.depot_id) AS depot_code2_hl,
dp2.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp2.depot_id) AS depot_name2_hl,
dp2.depot_id AS depot_id2,
dpc2.region AS region2,
ec.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
ec.e_class_id, "&type=E&page=fleet") AS loco_class_hl
FROM e_alloc ea2
JOIN ref_depot_codes dpc2
ON dpc2.depot_code = ea2.allocation
AND dpc2.date_from = (SELECT max(dpc2a.date_from)
FROM ref_depot_codes dpc2a
WHERE dpc2a.depot_code = ea2.allocation
AND dpc2a.date_from <= ea2.alloc_date)
JOIN ref_depot dp2
ON dp2.depot_id = dpc2.depot_id
JOIN e_alloc ea1
ON ea1.loco_id = ea2.loco_id
AND concat(ea1.alloc_date, ea1.seq) = (SELECT max(concat(ea1a.alloc_date, ea1a.seq))
FROM e_alloc ea1a
WHERE ea1a.loco_id = ea2.loco_id
AND concat(ea1a.alloc_date, ea1a.seq) <
concat(ea2.alloc_date, ea2.seq))
JOIN ref_depot_codes dpc1
ON dpc1.depot_code = ea1.allocation
AND dpc1.date_from = (SELECT max(dpc1a.date_from)
FROM ref_depot_codes dpc1a
WHERE dpc1a.depot_code = ea1.allocation
AND dpc1a.date_from <= ea1.alloc_date)
JOIN ref_depot dp1
ON dp1.depot_id = dpc1.depot_id
JOIN e_nums en
ON en.loco_id = ea2.loco_id
AND en.start_date = (SELECT max(en1.start_date)
FROM e_nums en1
WHERE en1.loco_id = ea2.loco_id
AND en1.start_date <= ea2.alloc_date)
JOIN e_class_link ecl
ON ecl.loco_id = ea2.loco_id
AND ecl.start_date = (SELECT max(ecl1.start_date)
FROM e_class_link ecl1
WHERE ecl1.loco_id = ea2.loco_id
AND ecl1.start_date <= ea2.alloc_date)
JOIN e_class ec
ON ec.e_class_id = ecl.e_class_id
WHERE date_format(ea2.alloc_date, "%m-%Y") = "' . $search_date . '"
AND (dpc1.region = "' . $region . '" OR dpc2.region = "' . $region . '")';
$sqls =
'SELECT "NEW" AS status,
"S" AS type,
s.loco_id AS loco_id,
sn.number AS number,
concat("locoqry.php?action=locodata&id=", s.loco_id,
"&type=S&loco=", sn.number) AS number_hl,
sn.number_type AS number_type,
s.b_date AS event_date1,
concat(date_format(s.b_date, "%Y%m%d"),
lpad(s.loco_id, 10, "0")) AS event_date1_fmt,
s.first_depot AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code1_hl,
dp.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name1_hl,
dp.depot_id AS depot_id1,
dcc.region AS region1,
s.b_date AS event_date2,
concat(date_format(s.b_date, "%Y%m%d"),
lpad(s.loco_id, 10, "0")) AS event_date2_fmt,
s.first_depot AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code2_hl,
dp.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name2_hl,
dp.depot_id AS depot_id2,
dcc.region AS region2,
sc.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
sc.s_class_id, "&type=S&page=fleet") AS loco_class_hl
FROM steam s
JOIN s_nums sn
ON sn.loco_id = s.loco_id
AND sn.first_number = "Y"
JOIN ref_depot_codes dcc
ON dcc.depot_code = s.first_depot
AND dcc.date_from = (SELECT max(dcc1.date_from)
FROM ref_depot_codes dcc1
WHERE dcc1.depot_code = s.first_depot
AND dcc1.date_from <= s.b_date)
JOIN ref_depot dp
ON dp.depot_id = dcc.depot_id
JOIN s_class_link scl
ON scl.loco_id = s.loco_id
AND scl.start_date = (SELECT max(scl1.start_date)
FROM s_class_link scl1
WHERE scl1.loco_id = s.loco_id
AND scl1.start_date <= s.b_date)
JOIN s_class sc
ON sc.s_class_id = scl.s_class_id
WHERE dcc.region = "' . $region . '"
AND date_format(s.b_date, "%m-%Y") = "' . $search_date . '"
UNION
SELECT "WDN" AS status,
"S" AS type,
s.loco_id AS loco_id,
sn.number AS number,
concat("locoqry.php?action=locodata&id=", s.loco_id,
"&type=S&loco=", sn.number) AS number_hl,
sn.number_type AS number_type,
s.w_date AS event_date1,
concat(date_format(s.w_date, "%Y%m%d"),
lpad(s.loco_id, 10, "0")) AS event_date1_fmt,
s.last_depot AS depot_code1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code1_hl,
dp.depot_name AS depot_name1,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name1_hl,
dp.depot_id AS depot_id1,
dcc.region AS region1,
s.w_date AS event_date2,
concat(date_format(s.w_date, "%Y%m%d"),
lpad(s.loco_id, 10, "0")) AS event_date2_fmt,
s.last_depot AS depot_code2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_code2_hl,
dp.depot_name AS depot_name2,
concat("sites.php?page=depots&action=query&id=",
dp.depot_id) AS depot_name2_hl,
dp.depot_id AS depot_id2,
dcc.region AS region2,
sc.identifier AS loco_class,
concat("locoqry.php?action=class&id=",
sc.s_class_id, "&type=S&page=fleet") AS loco_class_hl
FROM steam s
JOIN s_nums sn
ON sn.loco_id = s.loco_id
AND sn.start_date = (SELECT max(sn1.start_date)
FROM s_nums sn1
WHERE sn1.loco_id = sn.loco_id
AND sn1.carried_number = "Y"
AND sn1.start_date <= s.w_date)
JOIN ref_depot_codes dcc
ON dcc.depot_code = s.last_depot
AND dcc.date_from = (SELECT max(dcc1.date_from)
FROM ref_depot_codes dcc1
WHERE dcc1.depot_code = s.last_depot
AND dcc1.date_from <= s.w_date)
JOIN ref_depot dp
ON dp.depot_id = dcc.depot_id
JOIN s_class_link scl
ON scl.loco_id = s.loco_id
AND scl.start_date = (SELECT max(scl1.start_date)
FROM s_class_link scl1
WHERE scl1.loco_id = s.loco_id