forked from ndlibersa/reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
1110 lines (898 loc) · 35.5 KB
/
report.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
<?php
/*
**************************************************************************************************************************
** CORAL Usage Statistics Reporting Module v. 1.0
**
** Copyright (c) 2010 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
**
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/
session_start();
include_once 'directory.php';
$reportID = $_REQUEST['reportID'];
$outputType = $_REQUEST['outputType'];
$startPage = $_REQUEST['startPage'];
$numberOfRecords = $_REQUEST['numberOfRecords'];
$sortColumn = $_REQUEST['sortColumn'];
$sortOrder = $_REQUEST['sortOrder'];
$useHidden = $_REQUEST['useHidden'];
$titleID = $_REQUEST['titleID'];
if (!$reportID){
header("Location: index.php");
}
if (!$outputType){
$outputType = 'web';
}
//defaults if not entered
if (!$startPage) $startPage = 1;
$endPage = 100000;
$report = new Report(new NamedArguments(array('primaryKey' => $reportID)));
$hidden_inputs ='<input type="hidden" name="reportID" value="' . $reportID . '">';
//need to define this here rather than in css for excel
$usageFlaggedColor = "#738291"; //light blue
$usageOverridenColor = "#a9c0d8"; //blue
$usageMergedColor = "#d8d5da";
$levelColors = array ( array('','',''), array('#e9e33c', 'levelOne','yellow'),
array('#e9913c"', 'levelTwo','orange'),
array('#e93c3c"', 'levelThree','red'));
$showUnadjusted = 'N';
//Get the report parameters
//first do the title parameter if entered
if ($titleID != ''){
$title = $report->getUsageTitle($titleID);
$paramDisplay = "<b>Title:</b> " . $title . "<br />";
$rprt_prm_add = '&titleID=' . $titleID;
$hidden_inputs .= '<input type="hidden" name="titleID" value="' . $titleID . '">';
}
$parm = new ReportParameter();
//loop through each parameter
foreach ($report->getParameters() as $parm) {
if (($parm->parameterTypeCode == 'ms') && ($useHidden == '')){
$prm_value = $_REQUEST["prm_" . $parm->reportParameterID];
$prm_value = preg_replace('/\\\\/', ',',$prm_value);
$values = array();
$values = explode(',', $prm_value);
$prm_value = implode("', '",$values);
}else{
$prm_value = $_REQUEST["prm_" . $parm->reportParameterID];
$prm_value = preg_replace('/^\s+/', '', $prm_value);
$prm_value = preg_replace('/\s+$/', '', $prm_value);
}
$rprt_prm_add .= '&prm_' . $parm->reportParameterID . '=' . $prm_value;
if ($prm_value){
if ($parm->parameterTypeCode == 'chk'){
if (($prm_value == 'on') || ($prm_value == 'Y')){
$showUnadjusted = 'Y';
$hidden_inputs .= '<input type="hidden" name="prm_' . $parm->reportParameterID . '" value="Y">';
$paramDisplay .= "<b>Numbers are not adjusted for use violations</b><br />";
}
}else if ($parm->parameterAddWhereClause == 'limit'){
//decide what to do
$add_where='';
$max_rows=$prm_value;
$paramDisplay = $paramDisplay . "<b>Limit:</b> Top " . $prm_value . "<br />";
}else{
//if the parm comes through as an id (for publisher / platform or title), display actual value for user friendliness
if (($parm->parameterDisplayPrompt == 'Provider / Publisher') || ($parm->parameterDisplayPrompt == 'Provider') || ($parm->parameterDisplayPrompt == 'Publisher')){
$displayValue = implode(", ",$parm->getPubPlatDisplayName($prm_value));
$paramDisplay = $paramDisplay . "<b>" . $parm->parameterDisplayPrompt . ":</b> " . $displayValue . "<br />";
}else{
// only display the param info at the top if it was entered
$paramDisplay = $paramDisplay . "<b>" . $parm->parameterDisplayPrompt . ":</b> '" . $prm_value . "'<br />";
}
//now make the actual change to the SQL statement parameter
if ($parm->parameterAddWhereNumber == 2){
$addWhere2 .= ' AND ' . $parm->parameterAddWhereClause;
$prm_value=strtoupper($prm_value);
$addWhere2 = preg_replace('/PARM/', $prm_value, $addWhere2);
}else{
$addWhere .= ' AND ' . $parm->parameterAddWhereClause;
$prm_value=strtoupper($prm_value);
$addWhere = preg_replace('/PARM/', $prm_value, $addWhere);
}
$hidden_inputs .= '<input type="hidden" name="prm_' . $parm->reportParameterID . '" value="' . $prm_value . '">';
}
}
}
//if titleID was passed in, add that to addwhere
if (($reportID == '1') && ($titleID != '')){
$addWhere2 .= ' AND t.titleID = ' . $titleID;
}
// Get the report summing columns into sumColsArray for faster lookup later
//returns array of objects
$sumColsArray = array();
foreach($report->getReportSums() as $reportSum) {
$sumColsArray[$reportSum->reportColumnName] = $reportSum->reportAction;
}
// Get the report grouping columns into groupColsArray for faster lookup later
$groupColsArray = array();
//returns array of objects
foreach($report->getGroupingColumns() as $reportGroup) {
$groupColsArray[$reportGroup->reportGroupingColumnName] = 'N';
$perform_subtotal_flag='Y';
}
//formulate report SQL
// Figure archive sql
$rprt_sql = $report->reportSQL;
// only use tsm if tsm is used in the sql statement - may not be the case for yearly rollups
if (preg_match('/mus/i',$rprt_sql)){
$archiveAddWhere = $addWhere . ' AND mus.archiveInd = 1';
$archive_rprt_sql = $report->reportSQL;
// replace ADD_WHERE with the new $addWhere
$addWhere .= ' AND mus.archiveInd = 0';
}else{
$archiveAddWhere = $addWhere . ' AND yus.archiveInd = 1';
$archive_rprt_sql = $rprt_sql;
// replace ADD_WHERE with the new $addWhere
$addWhere .= ' AND yus.archiveInd = 0';
}
$archive_rprt_sql = preg_replace('/ADD_WHERE2/', $addWhere2, $archive_rprt_sql);
$archive_rprt_sql = preg_replace('/ADD_WHERE/', $archiveAddWhere, $archive_rprt_sql);
$rprt_sql = preg_replace('/ADD_WHERE2/', $addWhere2, $rprt_sql);
$rprt_sql = preg_replace('/ADD_WHERE/', $addWhere, $rprt_sql);
//add on the order
if ($sortColumn){
$rprt_sql .= ' ORDER BY ' . $sortColumn . ' ' . $sortOrder;
}else{
$rprt_sql .= ' ' . $report->orderBySQL;
}
//change default number of records per page if there is a report specific one
if (($rprt_dflt_rec_page_nbr) && ($numberOfRecords == '')) $numberOfRecords = $rprt_dflt_rec_page_nbr;
if (!$numberOfRecords) $numberOfRecords = 100000;
$endPage = $startPage + $numberOfRecords - 1;
$pageTitle = $report->reportName;
//Get outlier information
$outlierArray = array();
$outlier = array();
foreach($report->getOutliers() as $outlierArray) {
$outlier[$outlierArray['outlierLevel']]['overageCount'] = $outlierArray['overageCount'];
$outlier[$outlierArray['outlierLevel']]['overagePercent'] = $outlierArray['overagePercent'];
$outlier[$outlierArray['outlierLevel']]['outlierLevel'] = $outlierArray['outlierLevel'];
}
if ($outputType == 'web'){
include 'templates/header.php';
}else if ($outputType == 'print'){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CORAL E-Journal Usage Statistics Reporting - <?php echo $pageTitle; ?></title>
<link rel="stylesheet" href="css/print.css" type="text/css" media="screen" />
</head>
<body>
<?php
}else if ($outputType == 'pop'){
include 'templates/header.php';
}else{
$excelfile = $report->reportName;
$excelfile = str_replace (' ','_',$excelfile);
//required to allow downloads in IE 6 and 7
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary");
header("Content-type: application/vnd.ms-excel;");
header("Content-Disposition: attachment; filename='" . $excelfile . "'");
echo "<html><head></head><body>";
}
?>
<center>
<table class='noborder' style='width:780px;'>
<tr>
<td class='noborder' align='center' colspan='2'>
<table class='noborder' style='text-align:left;'>
<tr>
<?php if ($outputType == 'web'){ ?>
<td class="head" align='left' valign='top' style="min-height:98px;width:480px;background-image:url('images/reportingtitlereport.gif');background-repeat:no-repeat;"> <a href='index.php' style="border:none;outline: none;-moz-outline-style: none;"><img src='images/transparent.gif' style='width:480px;height:98px;border:none' /></a> </td>
<td class='noborder' style='height:98px;max-height:124px;min-width:300px; width:100%' align='left' valign='bottom'>
<table class="noborder" style="min-width:300px;min-height:98px;max-height:124px; width:100%">
<tr valign="bottom" style="vertical-align:bottom;">
<td class="head" style="padding:5px;vertical-align:bottom;">
<form name='viewreport' method='post' target='_self'>
<?php echo $hidden_inputs; ?>
<input type="hidden" name="sortColumn" value='<?php echo $sortColumn; ?>'>
<input type="hidden" name="sortOrder" value='<?php echo $sortOrder; ?>'>
<input type="hidden" name="outputType" value='web'>
<input type="hidden" name="useHidden" value=1>
<font size="+1"><?php echo $report->reportName; ?></font>
<a href="javascript:showPopup('report','<?php echo $reportID; ?>');" title='Click to show information about this report' style="border:none"><img src='images/help.gif' style="border:none"></a><br />
<?php echo $paramDisplay; ?>
<a href="index.php?&reportID=<?php echo $reportID . $rprt_prm_add; ?>">Modify Parameters</a>
<a href="index.php">Create New Report</a>
<br />
<a href="javascript:viewReportOutput('xls');" style="border:none"><img border='0' src="images/xls.gif"></a>
<a href="javascript:viewReportOutput('print');" style="border:none"><img border='0' src="images/printer.gif"></a><br />
</form>
</td>
<td class="head" align="right" valign="top"> </td>
</tr>
</table>
</td>
</tr>
<?php }else{ ?>
<td class='head'>
<font size="+1"><?php echo $report->reportName; ?></font><br />
<?php echo $paramDisplay; ?>
<br />
</td>
</tr>
<?php
}
$platArray = array();
$pubArray = array();
// determine how many times we should loop through the report (loop twice if there are archive records)
$archiveArray = $report->getReportResults($archive_rprt_sql);
if (count($archiveArray) > 0){
$numberLoops = 2;
}else{
$numberLoops = 1;
}
for($a = 1; $a <= $numberLoops; $a++){
$rowcount = 1;
$rowoutput = array();
$sumArray = array();
$totalSumArray = array();
$holdArray = array();
$fieldNameArray = array();
if (($reportID == '1') || ($reportID == '2')){
$textAdd = "By Month and Journal";
}
//archive loop
$reportArray = array();
if ($a == 2){
$reportArray = $archiveArray;
if ($outputType == 'web'){
?>
</table>
<tr>
<td colspan="2" class="shadednoborder" style='text-align:left;border-left: 1px solid #c6d7e8;'>
<br />
<font size="+1">Number of Successful Full-Text Article Requests from an Archive <?php echo $textAdd; ?></font>
</td>
</tr>
<tr>
<td colspan="2" class="shadednoborder">
<table style="width:100%">
<?php }else{ ?>
</table>
<tr><td colspan='2' align='left' class='noborder'> </td></tr>
<tr><td colspan='2' align='left' class='noborder'> </td></tr>
<tr>
<td colspan='2' align='left' class='noborder'>
<font size="+1">Number of Successful Full-Text Article Requests from an Archive <?php echo $textAdd; ?></font>
</td>
</tr>
<tr>
<td colspan='2' align='center' class='noborder'>
<table border='1'>
<?php
}
}else{ //if on the first loop
// run the report sql we just created for the actual report output
$reportArray = $report->getReportResults($rprt_sql);
if ($outputType == 'web'){
?>
<tr>
<td colspan="2" class="shadednoborder" style='text-align:left;border-left: 1px solid #c6d7e8;'>
<font size="+1">Number of Successful Full-Text Article Requests <?php echo $textAdd; ?></font>
</td>
</tr>
<tr>
<td colspan="2" class="shadednoborder">
<table style="width:100%">
<?php }else{ ?>
<tr>
<td colspan='2' align='left' class='noborder'>
<font size="+1">Number of Successful Full-Text Article Requests <?php echo $textAdd; ?></font>
</td>
</tr>
<tr>
<td colspan='2' align='center' class='noborder'>
<table border='1'>
<?php
}
}
//loop through resultset
foreach ($reportArray as $rowArray){
$groupArrayCount=count($groupColsArray);
$titleID = $rowArray['titleID'];
$overrides = array('JAN' => $rowArray['JAN_OVERRIDE'],
'FEB' => $rowArray['FEB_OVERRIDE'],
'MAR' => $rowArray['MAR_OVERRIDE'],
'APR' => $rowArray['APR_OVERRIDE'],
'MAY' => $rowArray['MAY_OVERRIDE'],
'JUN' => $rowArray['JUN_OVERRIDE'],
'JUL' => $rowArray['JUL_OVERRIDE'],
'AUG' => $rowArray['AUG_OVERRIDE'],
'SEP' => $rowArray['SEP_OVERRIDE'],
'OCT' => $rowArray['OCT_OVERRIDE'],
'NOV' => $rowArray['NOV_OVERRIDE'],
'DEC' => $rowArray['DEC_OVERRIDE'],
'YTD_TOTAL' => $rowArray['YTD_OVERRIDE'],
'YTD_HTML' => $rowArray['HTML_OVERRIDE'],
'YTD_PDF' => $rowArray['PDF_OVERRIDE']);
$outliers = array('JAN' => $rowArray['JAN_OUTLIER'],
'FEB' => $rowArray['FEB_OUTLIER'],
'MAR' => $rowArray['MAR_OUTLIER'],
'APR' => $rowArray['APR_OUTLIER'],
'MAY' => $rowArray['MAY_OUTLIER'],
'JUN' => $rowArray['JUN_OUTLIER'],
'JUL' => $rowArray['JUL_OUTLIER'],
'AUG' => $rowArray['AUG_OUTLIER'],
'SEP' => $rowArray['SEP_OUTLIER'],
'OCT' => $rowArray['OCT_OUTLIER'],
'NOV' => $rowArray['NOV_OUTLIER'],
'DEC' => $rowArray['DEC_OUTLIER']);
$pub_plat_id = $rowArray['publisherPlatformID'];
$plat_id = $rowArray['platformID'];
$merge_ind = $rowArray['MERGE_IND'];
$printISSN = $rowArray['PRINT_ISSN'];
$onlineISSN = $rowArray['ONLINE_ISSN'];
if ($plat_id) $platArray[] = $plat_id;
if ($pub_plat_id) $pubArray[] = $pub_plat_id;
if ($rowcount == $startPage){
$reset='Y';
}else{
$reset='N';
}
$performCheck='N';
$print_subtotal_flag='N';
$rowoutput[$rowcount] = "<tr border=1 class='data'>\n";
$displayCols='Y';
$index=0;
foreach ($rowArray as $field => $data) {
//stop displaying columns once we hit title ID or platform ID
if (($field == 'titleID') || ($field == 'platformID')) $displayCols = 'N';
if ($displayCols == 'Y') {
if ($data == '') $data = ' ';
//on the first row, load all of the display field names into array for later use
if ($rowcount == "1"){
$fieldNameArray[] = $field;
}
//if sort is explicitly requested we will group on this column if it is allowed according to DB
$sortIndex=$index+1;
if (($sortColumn == $sortIndex) && ($data != $holdArray[$index]) && (array_key_exists($field,$groupColsArray))){
$hold_rprt_grpng_data = $holdArray[$index];
$print_subtotal_flag='Y';
//if no sort order is specified, use default grouping
}else if (($sortOrder == '') && ($data != $holdArray[$index]) && ($holdArray[$index] != '') && (array_key_exists($field,$groupColsArray))){
$groupColsArray[$field] = 'Y';
//default echo flag to Y, we will reset later
$print_subtotal_flag = 'Y';
$performCheck='Y';
if ($groupArrayCount == 1){
$hold_rprt_grpng_data = $holdArray[$index];
}else{
$hold_rprt_grpng_data='Group';
}
}
if (($data != $holdArray[$index]) || ($reset == 'Y') || ($outputType == 'xls') || (($perform_subtotal_flag == 'Y') && ($sortOrder == '') && ($groupArrayCount > 1))) {
$reset = 'Y';
$print_data = $data;
} else {
//echo it out if it's a number, needs to be printed regardless
if (preg_match('/^[+-]?\d+$/', $print_data)){
$print_data = ' ';
}else{
$print_data = $data;
}
}
if (($outputType == 'web') && ($print_data != ' ')){
if ($field == 'TITLE'){
if ($reportID != '1'){
$print_data .= "<br /><font size='-4'><a target='_BLANK' href='report.php?reportID=1&prm_4=" . $showUnadjusted . "&titleID=" . $titleID . "&outputType=web'>view related titles</a></font>";
}
//echo link resolver link
$config = new Configuration();
if ((($printISSN) || ($onlineISSN)) && ($config->settings->baseURL)){
if (($printISSN) && !($onlineISSN)){
$urlAdd = "rft.issn=" . $printISSN;
}else if (($printISSN) && ($onlineISSN)){
$urlAdd = "rft.issn=" . $printISSN . "&rft.eissn=" . $onlineISSN;
}else{
$urlAdd = "rft.eissn=" . $onlineISSN;
}
$resolverURL = $config->settings->baseURL;
//check if there is already a ? in the URL so that we don't add another when appending the parms
if (strpos($resolverURL, "?") > 0){
$resolverURL .= "&";
}else{
$resolverURL .= "?";
}
$resolverURL .= $urlAdd;
$print_data .= "<br /><font size='-4'><a target='_BLANK' href='" . $resolverURL . "'>view in link resolver</a></font>";
}
}
//no longer using since notes are printed at the bottom of the screen
//if (($field == 'PLATFORM') && (preg_match('/^[+-]?\d+$/',$plat_id))){
// $print_data .= "<br /><font size='-4'><a href=\"javascript:showPubPlat('',$plat_id);\">view platform notes</a></font>";
//}
//if (($field == 'Publisher') && (preg_match('/^[+-]?\d+$/', $pub_plat_id))){
// if (count($report->getPublisherInformation($pub_plat_id)) > 0){
// $print_data .= "<br /><font size='-4'><a href=\"javascript:showPubPlat($pub_plat_id,'');\">view publisher notes</a></font>";
// }
//}
}
//Display adjusted numbers
if (($showUnadjusted == 'N') && (isset($overrides[$field]) || isset($outliers[$field]))){
if (isset($overrides[$field])){
$rowoutput[$rowcount] .= "<td bgcolor='$usageOverridenColor' class='usageOverriden' border=1>" . $overrides[$field] . '</td>';
}else if ($outliers[$field] > 0){
$rowoutput[$rowcount] .= "<td bgcolor='$usageFlaggedColor' class='usageFlagged' border=1>" . $print_data . '</td>';
}else{
if ($rowcount % 2) {
$rowoutput[$rowcount] .= "<td class='alt' border=1>" . $print_data . '</td>';
}else{
$rowoutput[$rowcount] .= "<td border=1>" . $print_data . '</td>';
}
}
//display unadjusted numbers
}else if (($showUnadjusted == 'Y') && ($outliers[$field] > 0)){
if ($outliers[$field] >= 4) { $outliers[$field] = $outliers[$field] - 3;}
$rowoutput[$rowcount] .= "<td bgcolor='" . $levelColors[$outliers{$field}][2] . "' class='" . $levelColors[$outliers[$field]][1] . "' border=1>" . $print_data . "</td>";
}else if ($merge_ind == 1){
$rowoutput[$rowcount] .= "<td bgcolor='$usageMergedColor' class='usageMerged' border=1>" . $print_data . '</td>';
}else{
if ($rowcount % 2) {
$rowoutput[$rowcount] .= "<td class='alt' border=1>" . $print_data . '</td>';
}else{
$rowoutput[$rowcount] .= "<td border=1>" . $print_data . '</td>';
}
}
$holdArray[$index] = $data;
}//end if display columns is Y
$index++;
}//end loop through columns
// loop through the group arrays, if any are N then echo flag is N otherwise it will be left to Y
if ($performCheck == 'Y'){
foreach ($groupColsArray as $key=>$value) {
if ($value == 'N'){
$print_subtotal_flag='N';
}
}
}
//determine if the previous row needs to be grouped
if (($outputType != 'xls') && ($print_subtotal_flag == 'Y') && ($report->groupTotalInd == '1')){
$groupRow=$rowcount-.5;
$rowoutput[$groupRow] .= "</tr>\n";
if ($countForGrouping > 1){
$rowoutput[$groupRow] .= "<tr class='data'>\n";
$index=0;
foreach ($fieldNameArray as $sumfield) {
$total='';
if ($index==0){
$rowoutput[$groupRow] .= "<td class='sum'>Total for " . $hold_rprt_grpng_data . "</td>";
$index++;
}else{
if ($sumColsArray[$sumfield] == 'dollarsum'){
foreach ($sumArray[$sumfield] as $amt){
$total += $amt;
}
if ($total > 0){
$total = money_format($total);
}else{
$total = " ";
}
}else if ($sumColsArray[$sumfield] == 'sum'){
foreach ($sumArray[$sumfield] as $amt){
if ($amt >= "0"){
$total += $amt;
}
}
if ($total >= "0"){
$total = number_format($total);
}else{
$total = " ";
}
}else{
$total=" ";
}
$rowoutput[$groupRow] .= "<td class='sum'>" . $total . "</td>";
}
}
$rowoutput[$groupRow] .= "</tr>\n";
}
$sumArray = array();
$countForGrouping=0;
$rowoutput[$groupRow] .= "<tr class='data'><td colspan=" . count($fieldNameArray) . "> </td></tr>\n";
$rowoutput[$groupRow] .= "<tr class='data'>\n";
}
// Now that we've figured out the summing as of the previous row, we can add in this row's summing
$index=0;
$displaySumCols='Y';
foreach ($rowArray as $field => $data) {
//stop checking columns once we hit title ID or platform ID
if (($field == 'titleID') || ($field == 'platformID')) $displaySumCols = 'N';
if ($displaySumCols == 'Y'){
$sortIndex=$index+1;
if (($sortColumn == $sortIndex) && (array_key_exists($field, $groupColsArray))){
$hold_rprt_grpng_data = $holdArray[$index];
}else if (($sortOrder == '') && (array_key_exists($field, $groupColsArray))){
$groupArrayCount=count($groupColsArray);
if ($groupArrayCount == 1){
$hold_rprt_grpng_data = $holdArray[$index];
}else{
$hold_rprt_grpng_data='Group';
}
}
// get the numbers out for summing
$data = preg_replace('/[^0-9.-]/','', $data);
$sumArray[$field][] = $data;
$totalSumArray[$field] = $totalSumArray[$field] + $data;
}
$index++;
}
$rowcount++;
$countForGrouping++;
}
$rowcount--;
$displayCols = 'Y';
$colcount=1;
if ($rowcount > 0){
echo "<tbody id='mybody'><tr valign='bottom' id='eee'>\n";
foreach ($reportArray[0] as $field => $data) {
//stop displaying columns once we hit title ID or platform ID
if (($field == 'titleID') || ($field == 'platformID')) $displayCols = 'N';
if ($displayCols == 'Y') {
$fieldDisplay = $field;
$fieldDisplay = str_replace("_", " ", $field);
$fieldDisplay = ucwords(strtolower($fieldDisplay));
echo "<th style='align:center;'>" . $fieldDisplay;
$displaySortColumn=$colcount;
$ascColumnSel='';
$descColumnSel='';
if (($sortColumn==$displaySortColumn) && ($sortOrder == 'asc')) $ascColumnSel='_sel';
if (($sortColumn==$displaySortColumn) && ($sortOrder == 'desc')) $descColumnSel='_sel';
if ($outputType == 'web'){
?>
<div style='width:100%;min-width:22px;align:center;margin:0px;padding:0px;'>
<a href="javascript:sortRecords('<?php echo $displaySortColumn; ?>', 'asc');" style="border:none">
<img align='center' src='images/arrowdown<?php echo $ascColumnSel; ?>.gif' border=0></a>
<a href="javascript:sortRecords('<?php echo $displaySortColumn; ?>', 'desc');" style="border:none">
<img align='center' src='images/arrowup<?php echo $descColumnSel; ?>.gif' border=0></a>
</div>
<?php
}
echo "</th>\n";
$colcount++;
}
}
echo "</tr>\n";
}
//echo the data table!!
if (($max_rows > 0) && ($max_rows <= count($rowoutput))){
$resizedArray = array();
$resizedArray = array_slice($rowoutput, 0, $max_rows);
foreach ($resizedArray as $printout){
echo $printout;
}
}else{
foreach ($rowoutput as $printout){
echo $printout;
}
}
// one last grouping summary
if (($outputType != 'xls') && ($perform_subtotal_flag == 'Y') && ($report->groupTotalInd == '1') && ($hold_rprt_grpng_data)) {
if ($countForGrouping > 1){
echo "<tr class='data'>\n";
$index=0;
foreach ($fieldNameArray as $sumfield) {
$total='';
if ($index==0){
echo "<td class='sum'>Total for " . $hold_rprt_grpng_data . "</td>";
$index++;
}else{
if ($sumColsArray[$sumfield] == 'dollarsum'){
foreach ($sumArray[$sumfield] as $amt){
$total += $amt;
}
if ($total > 0){
$total = money_format($total);
}else{
$total = " ";
}
}else if ($sumColsArray[$sumfield] == 'sum'){
foreach ($sumArray[$sumfield] as $amt){
if ($amt >= "0"){
$total += $amt;
}
}
if ($total >= "0"){
$total = number_format($total);
}else{
$total = " ";
}
}else{
$total=" ";
}
echo "<td class='sum'>" . $total . "</td>";
}
}
echo "</tr>\n";
}
$sumArray = array();
echo "<tr class='data'><td colspan=" . count($fieldNameArray) . "> </td></tr>\n";
}
}
if (($outputType != 'xls') && ($perform_subtotal_flag == 'Y')) {
echo "<tr class='data'>";
echo "<td class='sum'>Total for Report</td>";
$colNum=0;
foreach ($fieldNameArray as $field) {
$colNum++;
//don't print first col since we already put "Total" text in
if ($colNum > 1){
$sumfield=$field;
$total='';
if ($sumColsArray[$sumfield] == 'dollarsum'){
$total = money_format($totalSumArray[$sumfield]);
}else if ($sumColsArray[$sumfield] == 'sum'){
$total=number_format($totalSumArray[$sumfield]);
if (!$total) $total = '-';
}else if ($sumColsArray[$sumfield] == 'avg'){
if ($rowcount > 0 ) {
$total = number_format($totalSumArray[$sumfield] / $rowcount) . '%';
}else{
$total='';
}
}
if (!$total) $total=' ';
echo "<td class='sum'>$total</td>";
}
}
echo "</tr>\n";
}
if ($rowcount == 0){
echo "<tr class='data'><td colspan='$colcount'><i>Sorry, no rows were returned.</i></td></tr>";
}else{
if ($endPage > $rowcount) $endPage = $rowcount;
if ($outputType != 'web') $startPage=1; $endPage=$rowcount;
if (($max_rows > 0) && ($rowcount > $max_rows)){
echo "<tr><td colspan='$colcount' align='right'><i>Showing rows $startPage to $max_rows of $max_rows</i></td></tr>";
}else{
echo "<tr><td colspan='$colcount' align='right'><i>Showing rows $startPage to $rowcount of $rowcount</i></td></tr>";
}
}
?>
</tbody>
</table>
</center>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class='noborder' style='text-align:left;'>
<br />
<br />
<?php
//echo $rprt_sql;
//for excel
$modcolcount = $colcount-2;
if ($outputType != 'xls'){
?>
<table style='width:350px;border-width:1px'>
<tr>
<td colspan='2'><font style='font-weight:bold'>Key</font></td>
</tr>
<tr>
<?php
if ($showUnadjusted == 'N') {
?>
<td style='width:20px;' bgcolor='<?php echo $usageFlaggedColor; ?>' class='usageFlagged'> </td>
<td>Programmatically flagged as outlier based on previous 12 month average. The number has not been adjusted.</td>
</tr>
<tr>
<td style='width:20px;' bgcolor='<?php echo $usageOverridenColor; ?>' class='usageOverriden'> </td>
<td>Programmatically flagged as outlier based on previous 12 month average. The number has been adjusted manually by Electronic Resources.</td>
</tr>
<tr>
<td style='width:20px;' bgcolor='<?php echo $usageMergedColor; ?>' class='usageMerged'> </td>
<td>Multiple titles with the same print ISSN (generally multiple parts) have been merged together.</td>
<?php
}else{
?>
<td style='width:20px;' bgcolor='<?php echo $levelColors[1][0]; ?>' class='<?php echo $levelColors[1][1]; ?>'> </td>
<td>Programmatically flagged as outlier using the following formula: Count is <?php echo $outlier[1]['overageCount']; ?> over <?php echo $outlier[1]['overagePercent']; ?>% of the previous 12 month average. </td>
</tr>
<tr>
<td style='width:20px;' bgcolor='<?php echo $levelColors[2][0]; ?>' class='<?php echo $levelColors[2][1]; ?>'> </td>
<td>Programmatically flagged as outlier using the following formula: Count is <?php echo $outlier[2]['overageCount']; ?> over <?php echo $outlier[2]['overagePercent']; ?>% of the previous 12 month average. </td>
</tr>
<tr>
<td style='width:20px;' bgcolor='<?php echo $levelColors[3][0]; ?>' class='<?php echo $levelColors[3][1]; ?>'> </td>
<td>Programmatically flagged as outlier using the following formula: Count is <?php echo $outlier[3]['overageCount']; ?> over <?php echo $outlier[3]['overagePercent']; ?>% of the previous 12 month average. </td>
</tr>
<tr>
<td style='width:20px;' bgcolor='<?php echo $usageMergedColor; ?>' class='usageMerged'> </td>
<td>Multiple titles with the same print ISSN (generally multiple parts) have been merged together.</td>
<?php
}
?>
</tr>
</table>
<?php
//excel
}else{
?>
<table style='border-width:1px'>
<tr>
<td colspan='<?php echo $colcount; ?>'>
<table style='border:0px;'>
<tr>
<td class='noborder' align='right'><font style='font-weight:bold'>Color Background Key</font></td>
<?php
if ($showUnadjusted == 'N') {
?>
<td style='width:20px;' bgcolor='<?php echo $usageFlaggedColor; ?>' class='usageFlagged'> </td>
<td class='noborder' colspan='<?php echo $modcolcount; ?>'>Programmatically flagged as outlier based on previous 12 month average. The number has not been adjusted.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='<?php echo $colcount; ?>'>
<table style='border:0px;'>
<tr>
<td class='noborder'> </td>
<td style='width:20px;' bgcolor='<?php echo $usageOverridenColor; ?>' class='usageOverriden'> </td>
<td class='noborder' colspan='<?php echo $modcolcount; ?>'>Programmatically flagged as outlier based on previous 12 month average. The number has been adjusted manually by Electronic Resources.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='<?php echo $colcount; ?>'>
<table style='border:0px;'>
<tr>
<td class='noborder'> </td>
<td style='width:20px;' bgcolor='<?php echo $usageMergedColor; ?>' class='usageMerged'> </td>
<td class='noborder'colspan='<?php echo $modcolcount; ?>'>Multiple titles with the same print ISSN (generally multiple parts) have been merged together.</td>
</tr>
</table>
<?php
}else{
?>
<td style='width:20px;' bgcolor='<?php echo $levelColors[1][2]; ?>'> </td>
<td class='noborder' colspan='<?php echo $modcolcount; ?>'>Programmatically flagged as outlier using the following formula: Count is <?php echo $outlier[1]['overageCount']; ?> over <?php echo $outlier[1]['overagePercent']; ?>% of the previous 12 month average. </td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='<?php echo $colcount; ?>'>
<table style='border:0px;'>
<tr>
<td class='noborder'> </td>
<td style='width:20px;' bgcolor='<?php echo $levelColors[2][2]; ?>'> </td>
<td class='noborder' colspan='<?php echo $modcolcount; ?>'>Programmatically flagged as outlier using the following formula: Count is <?php echo $outlier[2]['overageCount']; ?> over <?php echo $outlier[2]['overagePercent']; ?>% of the previous 12 month average.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='<?php echo $colcount; ?>'>
<table style='border:0px;'>
<tr>
<td class='noborder'> </td>
<td style='width:20px;' bgcolor='<?php echo $levelColors[3][2]; ?>'> </td>
<td class='noborder' colspan='<?php echo $modcolcount; ?>'>Programmatically flagged as outlier using the following formula: Count is <?php echo $outlier[3]['overageCount']; ?> over <?php echo $outlier[3]['overagePercent']; ?>% of the previous 12 month average.</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan='<?php echo $colcount; ?>'>
<table style='border:0px;'>
<tr>
<td class='noborder'> </td>
<td style='width:20px;' bgcolor='<?php echo $usageMergedColor; ?>' class='usageMerged'> </td>
<td class='noborder' colspan='<?php echo $modcolcount; ?>'>Multiple titles with the same print ISSN (generally multiple parts) have been merged together.</td>
</tr>
</table>
<?php
}
}
?>
</td>
</tr>
<tr>
<td class='noborder' style='text-align:left;'>
<br />
<br />
<?php
if (count($platArray) > 0){
//pull out unique platforms
$uniq_plat = array_unique($platArray);
$platIDs = join(',', $uniq_plat);