-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreport_helper.php
5676 lines (5535 loc) · 296 KB
/
report_helper.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
/**
* Indicia, the OPAL Online Recording Toolkit.
*
* This program 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
* any later version.
* This program 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 this program. If not, see http://www.gnu.org/licenses/gpl.html.
*
* @author Indicia Team
* @license http://www.gnu.org/licenses/gpl.html GPL 3.0
* @link https://github.com/indicia-team/client_helpers
*/
/**
* Link in other required php files.
*/
require_once 'lang.php';
require_once 'helper_base.php';
/**
* Static helper class that provides methods for dealing with reports.
*/
class report_helper extends helper_base {
/**
* Accept parameter values that should be initially applied globally to all reports on a page.
*
* @var array
*/
public static $initialFilterParamsToApply = [];
/**
* Accept parameter values that should be globally skipped on parameters forms.
*
* @var array
*/
public static $filterParamsToGloballySkip = [];
/**
* Control which outputs a treeview of the reports available on the warehouse, with
* radio buttons for selecting a report. The title and description of the currently selected
* report are displayed alongside.
*
* @param array $options Options array which accepts the following standard options: id,
* fieldname, class, default, readAuth.
*/
public static function report_picker($options) {
self::add_resource('reportPicker');
$options = array_merge(array(
'id' => 'report-picker',
'fieldname' => 'report_name',
'default' => '',
'class' => ''
), $options);
// add class rather than replacing existing
$options['class'] .= ' report-picker-container ui-widget ui-widget-content ui-helper-clearfix';
$reports = '';
$response = self::http_post(self::$base_url.'index.php/services/report/report_list?nonce='.
$options['readAuth']['nonce'].'&auth_token='.$options['readAuth']['auth_token']);
if (isset($response['output'])) {
$output = json_decode($response['output'], true);
if (isset($output['error']))
return $output['error'];
$reports .= self::get_report_list_level($options['id'], $options['fieldname'], $options['default'], $output);
}
self::$javascript .= '$("#'.$options['id'].' > ul").treeview({collapsed: true});'."\n";
self::$javascript .= "indiciaData.reportList=".$response['output'].";\n";
self::$javascript .= '$(\'#'.$options['id'].' > ul input[checked="checked"]\').click();'."\n";
self::$javascript .= '$(\'#'.$options['id'].' > ul input[checked="checked"]\').parents("#'.$options['id'].' ul").show();'."\n";
$options['reports']=$reports;
$options['moreinfo']=lang::get('More info');
return self::apply_template('report_picker', $options);
}
/**
* Outputs a single level of the hierarchy of available reports, then iterates into sub-
* folders.
* @param string $ctrlId The fieldname for the report_picker control (=HTML form value)
* @param string $default Name of the report to be initially selected
* @param array $list Array of the reports and folders within the level to be output.
* @return string HTML for the unordered list containing the level.
* @access private
*/
private static function get_report_list_level($ctrlId, $fieldName, $default, $list) {
$r = '';
foreach($list as $name=>$item) {
if ($item['type']=='report') {
$id = 'opt_'.str_replace('/','_',$item['path']);
$checked = $item['path']==$default ? ' checked="checked"' : '';
$r .= '<li><label class="ui-helper-reset auto">'.
'<input type="radio" id="'.$id.'" name="'.$fieldName.'" value="'.$item['path'].
'" onclick="displayReportMetadata(\'' . $ctrlId . '\', \'' . $item['path'] . '\');" ' . $checked . '/>'.
htmlspecialchars($item['title']) .
"</label></li>\n";
}
else {
$name = ucwords(str_replace('_', ' ', $name));
$r .= "<li>$name\n";
$r .= self::get_report_list_level($ctrlId, $fieldName, $default, $item['content']);
$r .= "</li>\n";
}
}
if (!empty($r))
$r = "<ul>\n$r\n</ul>\n";
return $r;
}
/**
* A link to download the output of a report.
*
* Returns a simple HTML link to download the contents of a report defined by
* the options. The options arguments supported are the same as for the
* report_grid method. Pagination information will be ignored (e.g.
* itemsPerPage). If this download link is to be displayed alongside a
* report_grid to provide a download of the same data, set the id option to
* the same value for both the report_download_link and report_grid controls
* to link them together. Use the itemsPerPage parameter to control how many
* records are downloaded.
*
* @param array
* $options Options array with the following possibilities:
* * caption - link caption.
* * class - class attribute for the link generated.
* * dataSource - path to the report file.
* * format - Default to csv. Specify the download format, one of csv, json,
* xml, nbn.
* * itemsPerPage - max size of download file. Default 20000.
*/
public static function report_download_link($options) {
$options = array_merge(array(
'caption' => 'Download this report',
'format' => 'csv',
'itemsPerPage' => 20000,
'class' => '',
), $options);
// Option for a special report for downloading.
if (!empty($options['dataSourceDownloadLink'])) {
$origDataSource = $options['dataSource'];
$options['dataSource'] = $options['dataSourceDownloadLink'];
}
$options = self::getReportGridOptions($options);
$options['linkOnly'] = TRUE;
$currentParamValues = self::getReportGridCurrentParamValues($options);
$sortAndPageUrlParams = self::getReportGridSortPageUrlParams($options);
// Don't want to paginate the download link.
unset($sortAndPageUrlParams['page']);
$extras = self::getReportSortingPagingParams($options, $sortAndPageUrlParams);
$link = self::get_report_data($options, $extras . '&' . self::array_to_query_string($currentParamValues, TRUE), TRUE);
if (isset($origDataSource)) {
$options['dataSource'] = $origDataSource;
}
$class = $options['class'] ? " class=\"$options[class]\"" : '';
global $indicia_templates;
return str_replace(
['{link}', '{caption}', '{class}'],
[$link, lang::get($options['caption']), $class],
$indicia_templates['report_download_link']
);
}
/**
* Converts media paths to thumbnail HTML.
*
* Creates thumbnails for images and other media to insert into a grid column
* or other report output.
*
* @param array $mediaPaths
* List of paths to media.
* @param string $preset
* Size preset, e.g. thumb or med.
* @param string $entity
* Entity name.
* @param int $rowId
* Record ID.
*
* @param string
* HTML for thumbnails.
*/
public static function mediaToThumbnails(array $mediaPaths, $preset, $entity, $rowId) {
$imagePath = self::get_uploaded_image_folder();
$imgclass = count($mediaPaths)>1 ? 'multi' : 'single';
$group = count($mediaPaths)>1 && !empty($rowId) ? "group-$rowId" : '';
$r = '';
foreach($mediaPaths as $path) {
// Attach info so the file's caption and licence can be loaded
// on view. We can only do this if we know the row's ID.
$mediaInfoAttr = '';
if (!empty($rowId) && !empty($entity)) {
$mediaInfo = htmlspecialchars(json_encode([
"{$entity}_id" => $rowId,
'path' => $path,
]));
$mediaInfoAttr = " data-media-info=\"$mediaInfo\"";
}
if (preg_match('/^https:\/\/static\.inaturalist\.org/', $path)) {
$imgLarge = str_replace('/square.', '/original.', $path);
$path = $preset === 'med' ? str_replace('/square.', '/medium.', $path) : $path;
$r .= "<a href=\"$imgLarge\" data-fancybox=\"$group\"$mediaInfoAttr class=\"inaturalist $imgclass\"><img src=\"$path\" /></a>";
}
elseif (preg_match('/^http(s)?:\/\/(www\.)?(?P<site>[a-z]+(\.kr)?)/', $path, $matches)) {
// HTTP, means an external file.
// Flickr URLs sometimes have . in them.
$matches['site'] = str_replace('.', '', $matches['site']);
$r .= "<a href=\"$path\" class=\"social-icon $matches[site]\"></a>";
}
elseif (preg_match('/(\.wav|\.mp3)$/', strtolower($path))) {
$r .= <<<HTML
<audio controls src="$imagePath$path"$mediaInfoAttr type="audio/mpeg" />
HTML;
}
else {
$r .= <<<HTML
<a href="$imagePath$path" class="$imgclass"
data-fancybox="$group"$mediaInfoAttr>
<img src="$imagePath$preset-$path" />
</a>
HTML;
}
}
return $r;
}
/**
* Outputs a grid that loads the content of a report or Indicia table.
*
* The grid supports a simple pagination footer as well as column title sorting through PHP. If
* used as a PHP grid, note that the current web page will reload when you page or sort the grid, with the
* same $_GET parameters but no $_POST information. If you need 2 grids on one page, then you must define a different
* id in the options for each grid.
*
* For summary reports, the user can optionally setup clicking functionality so that another report is called when the user clicks on the grid.
*
* The grid operation will be handled by AJAX calls when possible to avoid reloading the web page.
*
* @param array $options Options array with the following possibilities:<ul>
* <li><b>id</b><br/>
* Optional unique identifier for the grid's container div. This is required if there is more than
* one grid on a single web page to allow separation of the page and sort $_GET parameters in the URLs
* generated.</li>
* <li><b>reportGroup</b><br/>
* When joining multiple reports together, this can be used on a report that has autoParamsForm set to false to bind the report to the
* parameters form from a different report by giving both report controls the same reportGroup string. This will only work when all
* parameters required by this report are covered by the other report's parameters form.</li>
* <li><b>rememberParamsReportGroup</b><br/>
* Enter any value in this parameter to allow the report to save its parameters for the next time the report is loaded.
* The parameters are saved site wide, so if several reports share the same value and the same report group then the parameter
* settings will be shared across the reports even if they are on different pages of the site. For example if several reports on the
* site have an ownData boolean parameter which filters the data to the user's own data, this can be set so that the reports all
* share the setting. This functionality requires cookies to be enabled on the browser.</li>
* <li><b>rememberGridPosition</b><br/>
* If true, then the grid's last paging position, row filter and sort
* information are stored in a cookie and recalled the next time the page is
* visited.</li>
* <li><b>mode</b><br/>
* Pass report for a report, or direct for an Indicia table or view. Default is report.</li>
* <li><b>readAuth</b><br/>
* Read authorisation tokens.</li>
* <li><b>dataSource</b><br/>
* Name of the report file or singular form of the table/view.</li>
* <li><b>dataSourceDownloadLink</b><br/>
* Optionally use a different data source for the download link displayed beneath the grid..</li>
* <li><b>view</b>
* When loading from a view, specify list, gv or detail to determine which view variant is loaded. Default is list.
* </li>
* <li><b>itemsPerPage</b><br/>
* Number of rows to display per page. Defaults to 20.</li>
* <li><b>columns</b><br/>
* Optional. Specify a list of the columns you want to output if you need more control over the columns, for example to
* specify the order, change the caption or build a column with a configurable data display using a template.
* Pass an array to this option, with each array entry containing an associative array that specifies the
* information about the column represented by the position within the array. The associative array for the column can contain
* the following keys:
* - fieldname: name of the field to output in this column. Does not need to be specified when using the template option.
* - display: caption of the column, which defaults to the fieldname if not specified
* - actions: list of action buttons to add to each grid row. Each button is defined by a sub-array containing
* values for caption, visibility_field, url, urlParams, class, img and javascript. The visibility field is an optional
* name of a field in the data which contains true or false to define the visibility of this action. The javascript, url
* and urlParams values can all use the field names from the report in braces as substitutions, for example {id} is replaced
* by the value of the field called id in the respective row. In addition, the url can use {currentUrl} to represent the
* current page's URL, {rootFolder} to represent the folder on the server that the current PHP page is running from, {input_form}
* (provided it is returned by the report) to represent the path to the form that created the record, {imageFolder} for the image
* upload folder and {sep} to specify either a ? or & between the URL and the first query parameter, depending on whether
* {rootFolder} already contains a ?. The url and urlParams can also have replacements from any query string parameter in the URL
* so report parameters can be passed through to linked actions. Because the javascript may pass the field values as parameters to functions,
* there are escaped versions of each of the replacements available for the javascript action type. Add -escape-quote or
* -escape-dblquote to the fieldname for quote escaping, -escape-htmlquote/-escape-htmldblquote for escaping quotes in HTML
* attributes, or -escape-urlpath to convert text to a format suitable for part of a URL path (lowercase with hyphens).
* For example this would be valid in the action javascript: foo("{bar-escape-dblquote}"); even if the field value contains a
* double quote which would have broken the syntax. Set img to the path to an image to use an image for the action instead of
* a text caption - the caption then becomes the image's title. The image path can contain {rootFolder} to be replaced by the
* root folder of the site, in this case it excludes the path parameter used in Drupal when dirty URLs are used (since this
* is a direct link to a URL).
* - visible: true or false, defaults to true
* - responsive-hide: an array, keyed by breakpoint name, with boolean values
* to indicate whether the column will be hidden when the breakpoint
* condition is met. Only takes effect if the 'responsiveOpts'option is set.
* - template: allows you to create columns that contain dynamic content using a template, rather than just the output
* of a field. The template text can contain fieldnames in braces, which will be replaced by the respective field values.
* Add -escape-quote or -escape-dblquote to the fieldname for quote escaping, -escape-htmlquote/-escape-htmldblquote
* for escaping quotes in HTML attributes, or -escape-urlpath for URL path segments as described above. Note that template
* columns cannot be sorted by clicking grid headers.
* An example array for the columns option is:
* array(
* array('fieldname' => 'survey', 'display' => 'Survey Title'),
* array('display' => 'action', 'template' => '<a href="www.mysite.com\survey\{id}\edit">Edit</a>'),
* array('display' => 'Actions', 'actions' => array(
* array('caption' => 'edit', 'url' => '{currentUrl}', 'urlParams'=>array('survey_id' => '{id}'))
* ))
* )
* - json: set to true if the column contains a json string object with properties that can be decoded to give strings that
* can be used as replacements in a template. For example, a column is returned from a report with fieldname='data', json=true
* and containing a data value '{"species":"Arnica montana","date":"14/04/2004"}'. A second column with fieldname='comment'
* contains the value 'Growing on a mountain pasture'. A third column is setup in the report with template set to
* '<div>{species} was recorded on {date}.<br/>{comment}</div>'. The json data and the second column's raw value are all
* available in the template replacements, so the output is set to
* '<div>Arnica montana was recorded on 14/04/2004.<br/>Growing on a mountain pasture</div>'
* template
* - img: set to true if the column contains a path to an image (relative to the warehouse upload folder). If so then the
* path is replaced by an image thumbnail with a fancybox zoom to the full image. Multiple images can be included by
* separating each path with a comma.
* </li>
* <li><b>rowId</b>
* Optional. Names the field in the data that contains the unique identifier
* for each row. If set, then the <tr> elements have their id attributes
* set to row + this field value, e.g. row37. This is used to allow
* synchronisation of the selected table rows with a report map output showing
* the same data. Also used to obtain media data (caption and licence info)
* when showing a popup after clicking on a media thumbnail.
* </li>
* <li><b>entity</b>
* If the report grid contains a media column with thumbnails, then the rowId
* is used to determine how to load the media's caption and licence info from
* the database. If rowId is of the form '<table>_id', e.g. 'sample_id', then
* entity will be worked out by the code so setting this option is
* unnecessary. However if rowId is just set to 'id' or some other form, then
* the code will default the entity to 'occurrence' so will need to be
* overridden for data from other tables.
* <li><b>includeAllColumns</b>
* Defaults to true. If true, then any columns in the report, view or table which are not in the columns
* option array are automatically added to the grid after any columns specified in the columns option array.
* Therefore the default state for a report_grid control is to include all the report, view or table columns
* in their default state, since the columns array will be empty.</li>
* <li><b>headers</b>
* Should a header row be included? Defaults to true.
* <li><b>sortable</b>
* If a header is included, should columns which allow sorting be sortable by clicking? Defaults to true.
* <li><b>galleryColCount</b>
* If set to a value greater than one, then each grid row will contain more than one record of data from the database, allowing
* a gallery style view to be built. Defaults to 1.
* <li><b>autoParamsForm</b>
* Defaults to true. If true, then if a report requires parameters, a parameters input form will be auto-generated
* at the top of the grid. If set to false, then it is possible to manually build a parameters entry HTML form if you
* follow the following guidelines. First, you need to specify the id option for the report grid, so that your
* grid has a reproducable id. Next, the form you want associated with the grid must itself have the same id, but with
* the addition of params on the end. E.g. if the call to report_grid specifies the option 'id' to be 'my-grid' then
* the parameters form must be called 'my-grid-params'. Finally the input controls which define each parameter must have
* the name 'param-id-' followed by the actual parameter name, replacing id with the grid id. So, in our example,
* a parameter called survey will need an input or select control with the name attribute set to 'param-my-grid-survey'.
* The submit button for the form should have the method set to "get" and should post back to the same page.
* As a final alternative, if parameters are required by the report but some can be hard coded then
* those may be added to the filters array.</li>
* <li><b>fieldsetClass</b><br/>
* Optional. Class name(s) to add to fieldsets generated by the auto parameters form.</li>
* <li><b>filters</b><br/>
* Array of key value pairs to include as a filter against the data.
* </li>
* <li><b>extraParams</b><br/>
* Array of additional key value pairs to attach to the request. This should include fixed values which cannot be
* changed by the user and therefore are not needed in the parameters form. extraParams can be overridden by loaded
* context filters (permissions filters, e.g. for verification).
* </li>
* <li><b>immutableParams</b><br/>
* Immutable parameters are parameters to apply to the report grid which cannot be changed under any circumstance.
* </li>
* <li><b>paramDefaults</b>
* Optional associative array of parameter default values. Default values appear in the parameter form and can be overridden.</li>
* <li><b>paramsOnly</b>
* Defaults to false. If true, then this method will only return the parameters form, not the grid content. autoParamsForm
* is ignored if this flag is set.</li>
* <li><b>ignoreParams</b>
* Array that can be set to a list of the report parameter names that should not be included in the parameters form. Useful
* when using paramsOnly=true to display a parameters entry form, but the system has default values for some of the parameters
* which the user does not need to be asked about. Can also be used to provide parameter values that can be overridden only via
* a URL parameter.</li>
* <li><b>completeParamsForm</b>
* Defaults to true. If false, the control HTML is returned for the params form without being wrapped in a <form> and
* without the Run Report button, allowing it to be embedded into another form.</li>
* <li><b>paramsFormButtonCaption</b>
* Caption of the button to run the report on the report parameters form. Defaults to Run Report. This caption
* is localised when appropriate.
* <li><b>paramsInMapToolbar</b>
* If set to true, then the parameters for this report are not output, but are passed to a map_panel control
* (which must therefore exist on the same web page) and are output as part of the map's toolbar.
* </li>
* <li><b>footer</b>
* Additional HTML to include in the report footer area. {currentUrl} is replaced by the
* current page's URL, {rootFolder} is replaced by the folder on the server that the current PHP page
* is running from.</li>
* </li>
* <li><b>downloadLink</b>
* Should a download link be included in the report footer? Defaults to false.</li>
* <li><b>sharing</b>
* Assuming the report has been written to take account of website sharing agreements, set this to define the task
* you are performing with the report and therefore the type of sharing to allow. Options are reporting (default),
* verification, moderation, peer_review, data_flow, editing, website (this website only) or me (my data only).</li>
* <li><b>UserId</b>
* If sharing=me, then this must contain the Indicia user ID of the user to return data for.
* </li>
* <li><b>sendOutputToMap</b>
* Default false. If set to true, then the records visible on the current page are drawn onto a map. This is different to the
* report_map method when linked to a report_grid, which loads its own report data for display on a map, just using the same input parameters
* as other reports. In this case the report_grid's report data is used to draw the features on the map, so only 1 report request is made.
* </li>
* <li><b>linkFilterToMap</b>
* Default true but requires a rowId to be set. If true, then filtering the grid causes the map to also filter.
* </li>
* <li><b>includePopupFilter</b>
* Set to true if you want to include a filter in the report header that
* displays a popup allowing the user to select exactly what data they want to
* display on the report.
* </li>
* <li><b>zoomMapToOutput</b>
* Default true. When combined with sendOutputToMap=true, defines that the map will automatically zoom to show the records.
* </li>
* <li><b>rowClass</b>
* A CSS class to add to each row in the grid. Can include field value replacements in braces, e.g. {certainty} to construct classes from
* field values, e.g. to colour rows in the grid according to the data.
* </li>
* <li><b>callback</b>
* Set to the name of a JavaScript function that should already exist which
* will be called each time the grid reloads (e.g. when paginating or sorting).
* </li>
* <li><b>linkToReportPath</b>
* Allows drill down into reports. Holds the URL of the report that is called when the user clicks on
* a report row. When this is not set, the report click functionality is disabled. The replacement #param# will
* be filled in with the row ID of the clicked on row.
* </li>
* <li><b>ajax</b>
* If true, then the first page of records is loaded via an AJAX call after the initial page load, otherwise
* they are loaded using PHP during page build. This means the grid load will be delayed till after the
* rest of the page, speeding up the load time of the rest of the page. If used on a tabbed output then
* the report will load when the tab is first viewed.
* Default false.
* </li>
* <li><b>ajaxLinksOnly</b>
* If true, then sort and pagination links designed for use when JavaScript is disabled will be ommitted. Useful
* on public facing pages to prevent search engines navigating links.
* Default false.
* </li>
* <li><b>autoloadAjax</b>
* Set to true to prevent autoload of the grid in Ajax mode. You would then need to call the grid's ajaxload() method
* when ready to load. This might be useful e.g. if a parameter is obtained from some other user input beforehand.
* Default false.
* </li>
* <li><b>pager</b>
* Include a pager? Default true. Removing the pager can have a big improvement on performance where there are lots of records to count.
* </li>
* <li><b>imageThumbPreset</b>
* Defaults to thumb. Preset name for the image to be loaded from the warehouse as the preview thumbnail for images, e.g. thumb or med.
* </li>
* <li><b>responsiveOpts</b>
* Set to an array of options to pass to FooTable to make the table responsive.
* Used in conjunction with the columns['responsive-hide'] option to determine
* which columns are hidden at different breakpoints.
* Supported options are
* - breakpoints: an array keyed by breakpoint name with values of screen
* width at which to apply the breakpoint. Footable defaults apply if
* omitted.
* </li>
* <li><b>includeColumnsPicker</b>
* Adds a menu button to the header which allows the user to pick which columns are visible.
* When using this option you must set the id option as well to a unique identifier
* for the grid in order to enable saving of the settings in a cookie.
* </li>
* </ul>
*/
public static function report_grid($options) {
global $indicia_templates;
self::add_resource('fancybox');
$options = self::getReportGridOptions($options);
$sortAndPageUrlParams = self::getReportGridSortPageUrlParams($options);
$extras = self::getReportSortingPagingParams($options, $sortAndPageUrlParams);
if ($options['ajax'])
$options['extraParams']['limit']=0;
// Request report data.
self::request_report(
$response,
$options,
$currentParamValues,
// Only get a count if doing a pager and not doing Ajax population as Ajax can update the pager later.
$options['pager'] && !$options['ajax'],
$extras
);
if (isset($response['count'])) {
// Pass knownCount into any subsequent AJAX calls as this allows better performance
$options['extraParams']['knownCount'] = $response['count'];
}
if ($options['ajax'])
unset($options['extraParams']['limit']);
if (isset($response['error'])) return $response['error'];
$r = self::paramsFormIfRequired($response, $options, $currentParamValues);
// return the params form, if that is all that is being requested, or the parameters are not complete.
if ((isset($options['paramsOnly']) && $options['paramsOnly']) || !isset($response['records'])) return $r;
$records = $response['records'];
self::report_grid_get_columns($response, $options);
$pageUrl = self::reportGridGetReloadUrl($sortAndPageUrlParams);
$thClass = $options['thClass'];
$r .= $indicia_templates['loading_overlay'];
$r .= "\n";
$thead = '';
$tbody = '';
$tfoot = '';
if ($options['headers']!==false) {
//$thead .= "\n<thead class=\"$thClass\">\n";
// build a URL with just the sort order bit missing, so it can be added for each table heading link
$sortUrl = $pageUrl . ($sortAndPageUrlParams['page']['value'] ?
$sortAndPageUrlParams['page']['name'].'='.$sortAndPageUrlParams['page']['value'].'&' :
''
);
$sortdirval = $sortAndPageUrlParams['sortdir']['value'] ? strtolower($sortAndPageUrlParams['sortdir']['value']) : 'asc';
// Flag if we know any column data types and therefore can display a filter row
$wantFilterRow=false;
$filterRow='';
$imgPath = empty(self::$images_path) ? self::relative_client_helper_path()."../media/images/" : self::$images_path;
// Output the headers. Repeat if galleryColCount>1;
for ($i=0; $i<$options['galleryColCount']; $i++) {
foreach ($options['columns'] as &$field) {
if (isset($field['visible']) && ($field['visible'] === 'false' || $field['visible'] === false)) {
// skip this column as marked invisible
continue;
}
if (isset($field['actions']))
report_helper::translateActions($field['actions']);
// allow the display caption to be overriden in the column specification
if (empty($field['display']) && empty($field['fieldname'])) {
$caption = '';
}
else {
$caption = empty($field['display']) ? $field['fieldname'] : lang::get($field['display']);
}
if ($options['sortable'] && isset($field['fieldname']) && !(isset($field['img']) && $field['img'] == 'true')) {
if (empty($field['orderby'])) {
$field['orderby'] = $field['fieldname'];
}
$sortLink = $sortUrl.$sortAndPageUrlParams['orderby']['name'].'='.$field['orderby'];
// reverse sort order if already sorted by this field in ascending dir
if ($sortAndPageUrlParams['orderby']['value'] == $field['orderby'] && $sortAndPageUrlParams['sortdir']['value'] != 'DESC') {
$sortLink .= '&'.$sortAndPageUrlParams['sortdir']['name']."=DESC";
}
$sortHref = self::getGridNavHref($sortLink, $options['ajaxLinksOnly']);
// store the field in a hidden input field
$sortBy = lang::get("Sort by {1}", $caption);
$captionLink = "<input type=\"hidden\" value=\"$field[orderby]\"/>" .
"<a$sortHref title=\"$sortBy\">$caption</a>";
// set a style for the sort order
$orderStyle = ($sortAndPageUrlParams['orderby']['value'] == $field['orderby']) ? ' '.$sortdirval : '';
$orderStyle .= ' sortable';
$fieldId = ' id="' . $options['id'] . '-th-' . $field['orderby'] . '"';
}
else {
$orderStyle = '';
$fieldId = '';
$captionLink=$caption;
}
$colClass = isset($field['fieldname']) ? " col-$field[fieldname]" : '';
if (!$colClass && isset($field['actions'])) {
$colClass = ' col-actions';
}
// Create a data-hide attribute for responsive tables.
$datahide = '';
if (isset($field['responsive-hide'])) {
$datahide = implode(',', array_keys(array_filter($field['responsive-hide'])));
if($datahide != '') {
$datahide = " data-hide=\"$datahide\" data-editable=\"true\"";
}
}
$thead .= "<th$fieldId class=\"$thClass$colClass$orderStyle\"$datahide>$captionLink</th>\n";
if (isset($field['datatype']) && !empty($caption)) {
switch ($field['datatype']) {
case 'text':
case 'species':
$title = lang::get("Search for {1} text begins with .... Use * as a wildcard.", $caption);
break;
case 'date':
$title = lang::get("Search on {1} - search for an exact date or use a vague date such as a year to select a range of dates.", $caption);
break;
default:
$title = lang::get("Search on {1} - either enter an exact number, use >, >=, <, or <= before the number to filter for " .
"{1} more or less than your search value, or enter a range such as 1000-2000.", $caption);
}
$title = htmlspecialchars(lang::get('Type here to filter then press Tab or Return to apply the filter.').' '.$title);
// Filter, which when clicked, displays a popup with a series of
// checkboxes representing a distinct set of data from a column on
// the report. The user can then deselect these checkboxes to
// remove data from the report.
if (!empty($options['includePopupFilter'])&&$options['includePopupFilter']===true) {
self::$javascript.="indiciaData.includePopupFilter=true;";
$popupFilterIcon = $imgPath."desc.gif";
$popupFilterIconHtml='<img class="col-popup-filter" id="col-popup-filter-'.$field['fieldname'].'-'.$options['id'].'" src="'.$popupFilterIcon.'" >';
}
if (empty($popupFilterIconHtml))
$popupFilterIconHtml='';
//The filter's input id includes the grid id ($options['id']) in its id as there maybe more than one grid and we need to make the id unique.
$filterRow .= "<th class=\"$colClass\"><input title=\"$title\" type=\"text\" class=\"col-filter\" id=\"col-filter-".$field['fieldname']."-".$options['id']."\"/>$popupFilterIconHtml</th>";//Add a icon for the popup filter
$wantFilterRow = true;
} else
$filterRow .= "<th class=\"$colClass\"></th>";
}
// Clean up dangling reference variable
unset($field);
}
$thead = str_replace(array('{class}','{title}','{content}'), array('','',$thead), $indicia_templates['report-thead-tr']);
if ($wantFilterRow && (!isset($options["forceNoFilterRow"]) || !$options["forceNoFilterRow"]))
$thead .= str_replace(array('{class}','{title}','{content}'),
array(' class="filter-row"',' title="'.lang::get('Use this row to filter the grid').'"',$filterRow), $indicia_templates['report-thead-tr']);
$thead = str_replace(array('{class}', '{content}'), array(" class=\"$thClass\"", $thead), $indicia_templates['report-thead']);
}
$currentUrl = self::get_reload_link_parts();
// automatic handling for Drupal clean urls.
$pathParam = (function_exists('variable_get') && variable_get('clean_url', 0)=='0') ? 'q' : '';
$rootFolder = self::getRootFolder(true);
// amend currentUrl path if we have Drupal 6/7 dirty URLs so javascript will work properly
if (isset($currentUrl['params']['q']) && strpos($currentUrl['path'], '?')===false) {
$currentUrl['path'] = $currentUrl['path'].'?q='.$currentUrl['params']['q'];
}
$tfoot .= '<tfoot>';
$tfoot .= '<tr><td colspan="'.count($options['columns'])*$options['galleryColCount'].'">'.self::outputPager($options, $pageUrl, $sortAndPageUrlParams, $response).'</td></tr>'.
$extraFooter = '';
if (isset($options['footer']) && !empty($options['footer'])) {
$footer = helper_base::getStringReplaceTokens($options['footer'], $options['readAuth']);
// Allow other modules to hook in.
if (function_exists('hostsite_invoke_alter_hooks')) {
hostsite_invoke_alter_hooks('iform_user_replacements', $footer);
}
// Merge in any references to the parameters sent to the report: could extend this in the future to pass in the extraParams
foreach($currentParamValues as $key=>$param){
$footer = str_replace(array('{'.$key.'}'), array($param), $footer);
}
$extraFooter .= '<div class="left">'.$footer.'</div>';
}
if (isset($options['downloadLink']) && $options['downloadLink'] && (count($records)>0 || $options['ajax'])) {
$downloadOpts = array_merge($options);
unset($downloadOpts['itemsPerPage']);
$extraFooter .= '<div class="right">'.self::report_download_link($downloadOpts).'</div>';
}
if (!empty($extraFooter))
$tfoot .= '<tr><td colspan="'.count($options['columns']).'">'.$extraFooter.'</td></tr>';
$tfoot .= '</tfoot>';
$altRowClass = '';
$outputCount = 0;
$imagePath = self::get_uploaded_image_folder();
$addFeaturesJs = '';
$haveUpdates = FALSE;
$updateformID = 0;
// Knowing the entity helps build image metadata for popups.
if (isset($options['rowId']) && preg_match('/^([a-z_]+)_id$/', $options['rowId'], $matches)) {
$entity = $matches[1];
}
else {
// Assume the ID is for occurrence data unless specified.
$entity = isset($options['entity']) ? $options['entity'] : 'occurrence';
}
if (count($records)>0) {
$rowInProgress = FALSE;
$rowTitle = !empty($options['rowId']) ?
' title="'.lang::get('Click the row to highlight the record on the map. Double click to zoom in.').'"' : '';
foreach ($records as $rowIdx => $row) {
// Don't output the additional row we requested just to check if the next page link is required.
if ($outputCount>=$options['itemsPerPage'])
break;
// Put some extra useful paths into the row data, so it can be used in the templating
$row = array_merge($row, array(
'rootFolder'=>$rootFolder,
'sep'=>strpos($rootFolder, '?')===FALSE ? '?' : '&',
'imageFolder'=>$imagePath,
// allow the current URL to be replaced into an action link. We extract url parameters from the url, not $_GET, in case
// the url is being rewritten.
'currentUrl' => $currentUrl['path']
));
// set a unique id for the row if we know the identifying field.
$rowId = isset($options['rowId']) ? $row[$options['rowId']] : '';
$rowIdAttr = $rowId ? " id=\"row$rowId\"" : '';
if ($rowIdx % $options['galleryColCount']==0) {
$classes = [];
if ($altRowClass)
$classes[]=$altRowClass;
if (isset($options['rowClass']))
$classes[]=self::mergeParamsIntoTemplate($row, $options['rowClass'], true, true);
$classes=implode(' ',$classes);
$rowClass = empty($classes) ? '' : " class=\"$classes\"";
$tr = '';
$rowInProgress=true;
}
// decode any data in columns that are defined as containing JSON
foreach ($options['columns'] as $field) {
if (isset($field['json']) && $field['json'] && isset($row[$field['fieldname']])) {
$row = array_merge(json_decode($row[$field['fieldname']], true), $row);
}
}
foreach ($options['columns'] as $field) {
$classes = [];
if ($options['sendOutputToMap'] && isset($field['mappable']) && ($field['mappable']==='true' || $field['mappable']===true)) {
$data = json_encode($row + array('type' => 'linked'));
$addFeaturesJs.= "div.addPt(features, ".$data.", '".$field['fieldname']."', {}".
", '$rowId');\n";
}
if (isset($field['visible']) && ($field['visible']==='false' || $field['visible']===false))
continue; // skip this column as marked invisible
if (isset($field['img']) && $field['img']=='true' && !empty($row[$field['fieldname']]) && !isset($field['template'])) {
$imgs = explode(',', $row[$field['fieldname']]);
$value='';
$row[$field['fieldname']] = self::mediaToThumbnails($imgs, $options['imageThumbPreset'], $entity, $rowId);
}
if (isset($field['img']) && $field['img']=='true')
$classes[] = 'table-gallery';
if (isset($field['actions'])) {
$value = self::get_report_grid_actions($field['actions'], $row, $pathParam);
$classes[]='col-actions';
} elseif (isset($field['template'])) {
$value = self::mergeParamsIntoTemplate($row, $field['template'], true, true, true);
} else if (isset($field['update']) &&(!isset($field['update']['permission']) || hostsite_user_has_permission($field['update']['permission']))){
// TODO include checks to ensure method etc are included in structure -
$updateformID++;
$update = $field['update'];
$url = iform_ajaxproxy_url(null, $update['method']);
$class = isset($field['update']['class']) ? $field['update']['class'] : '';
$value = isset($field['fieldname']) && isset($row[$field['fieldname']]) ? $row[$field['fieldname']] : '';
$value = <<<FORM
<form id="updateform-$updateformID" method="post" action="$url">
<input type="hidden" name="website_id" value="$update[website_id]">
<input type="hidden" name="transaction_id" value="updateform-$updateformID-field">
<input id="updateform-$updateformID-field" name="$update[tablename]:$update[fieldname]"
class="update-input $class" value="$value">
FORM;
if(isset($field['update']['parameters'])){
foreach($field['update']['parameters'] as $pkey=>$pvalue){
$value.="<input type=\"hidden\" name=\"".$field['update']['tablename'].":".$pkey."\" value=\"".$pvalue."\">";
}
}
$value.="</form>";
$value=self::mergeParamsIntoTemplate($row, $value, true);
$haveUpdates = true;
self::$javascript .= <<<JS
$('#updateform-$updateformID').ajaxForm({
async: true,
dataType: 'json',
success: function(data, status, form){
if (checkErrors(data)) {
var selector = '#'+data.transaction_id.replace(/:/g, '\\:');
$(selector).removeClass('input-saving');
$(selector).removeClass('input-edited');
}
}
});
JS;
}
else {
$value = isset($field['fieldname']) && isset($row[$field['fieldname']]) ? $row[$field['fieldname']] : '';
// The verification_1 form depends on the tds in the grid having a class="data fieldname".
$classes[]='data';
}
if (isset($field['fieldname'])) {
$classes[]="col-$field[fieldname]";
}
if (isset($field['class']))
$classes[] = $field['class'];
if (count($classes)>0)
$class = ' class="'.implode(' ', $classes).'"';
else
$class = '';
$tr .= str_replace(array('{class}','{content}'), array($class, $value), $indicia_templates['report-tbody-td']);
}
if ($rowIdx % $options['galleryColCount']==$options['galleryColCount']-1) {
$rowInProgress=false;
$tbody .= str_replace(array('{class}','{rowId}','{rowTitle}','{content}'), array($rowClass, $rowIdAttr, $rowTitle, $tr), $indicia_templates['report-tbody-tr']);
}
$altRowClass = empty($altRowClass) ? $options['altRowClass'] : '';
$outputCount++;
}
// implement links from the report grid rows if configuration options set
if (isset($options['linkToReportPath'])) {
$path=$options['linkToReportPath'];
if (isset($options['rowId'])) {
//if the user clicks on a summary table row then open the report specified using the row ID as a parameter.
self::$javascript .= "
$('#".$options['id']." tbody').click(function(evt) {
var tr=$(evt.target).parents('tr')[0], rowId=tr.id.substr(3);
window.location='$path'.replace(/#param#/g, rowId);
});
";
}
}
if ($rowInProgress)
$tbody .= str_replace(array('{class}','{rowId}','{title}','{content}'), array($rowClass, $rowIdAttr, $rowTitle, $tr), $indicia_templates['report-tbody-tr']);
} else {
$tbody .= str_replace(array('{class}','{rowId}','{rowTitle}','{content}'), array(' class="empty-row"','','','<td colspan="'.count($options['columns'])*$options['galleryColCount'].
'">' . lang::get('No information available') . '</td>'), $indicia_templates['report-tbody-tr']);
}
$tbody = str_replace('{content}', $tbody, $indicia_templates['report-tbody']);
$r .= str_replace(array('{class}', '{content}'), array(' class="'.$options['class'].'"', "$thead\n$tbody\n$tfoot"), $indicia_templates['report-table'])."\n";
if($haveUpdates){
self::$javascript .= "
function checkErrors(data) {
if (typeof data.error!==\"undefined\") {
if (typeof data.errors!==\"undefined\") {
$.each(data.errors, function(idx, error) {
alert(error);
});
} else {
alert('An error occured when trying to save the data: '+data.error);
}
// data.transaction_id stores the last cell at the time of the post.
var selector = '#'+data.transaction_id.replace(/:/g, '\\\\:');
$(selector).focus();
$(selector).select();
return false;
} else {
return true;
}
}
$('.update-input').focus(function(evt) {
$(evt.target).addClass('input-selected');
}).change(function(evt) {
$(evt.target).addClass('input-edited');
}).blur(function(evt) {
var selector = '#'+evt.target.id.replace(/:/g, '\\:');
currentCell = evt.target.id;
$(selector).removeClass('input-selected');
if ($(selector).hasClass('input-edited')) {
$(selector).addClass('input-saving');
// WARNING No validation currently applied...
$(selector).parent().submit();
}
});
";
}
if ($options['sendOutputToMap']) {
$strokeWidthFn = "getstrokewidth: function(feature) {
var width=feature.geometry.getBounds().right - feature.geometry.getBounds().left,
strokeWidth=(width===0) ? 1 : %d - (width / feature.layer.map.getResolution());
return (strokeWidth<%d) ? %d : strokeWidth;
}";
self::addFeaturesLoadingJs($addFeaturesJs, 'OpenLayers.Util.extend(OpenLayers.Feature.Vector.style[\'default\'], '.
'{"strokeColor":"#0000ff","fillColor":"#3333cc","fillOpacity":0.6,"strokeWidth":"${getstrokewidth}"})',
'{"strokeColor":"#ff0000","fillColor":"#ff0000","fillOpacity":0.6,"strokeWidth":"${getstrokewidth}"}',
', {context: { '.sprintf($strokeWidthFn, 9, 2, 2).' }}',
', {context: { '.sprintf($strokeWidthFn, 10, 3, 3).' }}', $options['zoomMapToOutput']);
}
$uniqueName = 'grid_' . preg_replace( "/[^a-z0-9]+/", "_", $options['id']);
$group = preg_replace( "/[^a-zA-Z0-9]+/", "_", $options['reportGroup']);
// $r may be empty if a spatial report has put all its controls on the map toolbar, when using params form only mode.
// In which case we don't need to output anything.
if (!empty($r)) {
if ($options['includeColumnsPicker']) {
$icon = $imgPath."plus.gif";
$r .='<img class="col-picker" style="position: absolute; right: 4px; top: 4px;" src="'.$icon.'" >';
self::add_resource('jquery_cookie');
}
// Output a div to keep the grid and pager together
$r = "<div id=\"".$options['id']."\" class=\"report-grid-container\">$r</div>\n";
// Add responsive behaviour to table if specified in options.
// The table is made responsive with the footables plugin based on the
// data-hide attributes added to the <th> elements
if (!empty($options['responsiveOpts'])) {
// Add the javascript plugins.
self::add_resource('indiciaFootableReport');
// Add inline javascript to invoke the plugins on this grid.
$footable_options = json_encode($options['responsiveOpts']);
self::$javascript .= "jQuery('#{$options['id']}').indiciaFootableReport($footable_options);\n";
// Footable needs calling after each Ajax update. There is an existing
// callback option which we can use but it only accepts a single function.
// Therefore, create a new function and append any pre-existing callback.
// Note, '-' is not allowed in JavaScript identifiers.
$callback = 'callback_' . str_replace('-', '_', $options['id']);
// create JS call to existing callback if it exists
$callToCallback = empty($options['callback']) ? '' : " window['$options[callback]']();\n";
self::$javascript .= "
window['$callback'] = function() {
jQuery('#$options[id]').find('table').trigger('footable_redraw');
$callToCallback}";
// Store the callback name to pass to jquery.reportgrid.js.
$options['callback'] = $callback;
}
// Now AJAXify the grid
self::add_resource('reportgrid');
global $indicia_templates;
$warehouseUrl = parent::getProxiedBaseUrl();
$rootFolder = self::getRootFolder() . (empty($pathParam) ? '' : "?$pathParam=");
if (isset($options['sharing'])) {
$options['extraParams']['sharing']=$options['sharing'];
}
// Full list of report parameters to load on startup.
$extraParams = array_merge(
$options['extraParams'],
$currentParamValues,
self::$initialFilterParamsToApply
);
$extraParams = json_encode($extraParams, JSON_FORCE_OBJECT);
// List of report parameters that cannot be changed by the user.
$fixedParams = json_encode($options['extraParams'], JSON_FORCE_OBJECT);
$immutableParams = json_encode($options['immutableParams'], JSON_FORCE_OBJECT);
self::$javascript .= "
if (typeof indiciaData.reports.$group==='undefined') { indiciaData.reports.$group={}; }
indiciaFns.simpleTooltip('input.col-filter','tooltip');
indiciaData.reports.$group.$uniqueName = $('#".$options['id']."').reportgrid({
id: '$options[id]',
mode: '$options[mode]',
dataSource: '" . str_replace('\\','/',$options['dataSource']) . "',
extraParams: $extraParams,
fixedParams: $fixedParams,
immutableParams: $immutableParams,
view: '$options[view]',
itemsPerPage: $options[itemsPerPage],
auth_token: '{$options['readAuth']['auth_token']}',
nonce: '{$options['readAuth']['nonce']}',
callback: '$options[callback]',
url: '$warehouseUrl',
reportGroup: '$options[reportGroup]',
rememberGridPosition: " . ($options['rememberGridPosition'] ? 'true' : 'false') . ",
autoParamsForm: '$options[autoParamsForm]',
rootFolder: '" . $rootFolder . "',
imageFolder: '" . self::get_uploaded_image_folder() . "',
imageThumbPreset: '$options[imageThumbPreset]',
currentUrl: '$currentUrl[path]',
rowId: '" . (isset($options['rowId']) ? $options['rowId'] : '') . "',
currentPageCount: " . min($options['itemsPerPage'], count($records)) . ",
galleryColCount: $options[galleryColCount],
pagingTemplate: '$indicia_templates[paging]',
pathParam: '$pathParam',
sendOutputToMap: " . ((isset($options['sendOutputToMap']) && $options['sendOutputToMap']) ? 'true' : 'false') . ",
linkFilterToMap: " . (!empty($options['rowId']) && $options['linkFilterToMap'] ? 'true' : 'false') . ",
msgRowLinkedToMapHint: '" . addslashes(lang::get('Click the row to highlight the record on the map. Double click to zoom in.')) . "',
msgNoInformation: '" . addslashes(lang::get('No information available')) . "',
langFirst: '" . lang::get('first') . "',
langPrev: '" . lang::get('prev') . "',
langNext: '" . lang::get('next') . "',
langLast: '" . lang::get('last') . "',
langShowing: '" . lang::get('Showing records {1} to {2} of {3}') . "',
noRecords: '" . lang::get('No records')."',
noInfoAsPageTooHigh: '" . lang::get('No information available for the requested page of data. Use the page buttons below to load a different page.')."',
altRowClass: '$options[altRowClass]',
actionButtonTemplate: '" . $indicia_templates['report-action-button'] ."'";
if (!empty($options['rowClass']))
self::$javascript .= ",\n rowClass: '".$options['rowClass']."'";
if (isset($options['filters']))
self::$javascript .= ",\n filters: ".json_encode($options['filters']);
if (isset($orderby))
self::$javascript .= ",\n orderby: '".$orderby."'";
if (isset($sortdir))
self::$javascript .= ",\n sortdir: '".$sortdir."'";
if (isset($response['count']))
self::$javascript .= ",\n recordCount: ".$response['count'];
if (isset($options['columns']))
self::$javascript .= ",\n columns: ".json_encode($options['columns']);
self::$javascript .= "\n});\n";
}
if (isset($options['sendOutputToMap']) && $options['sendOutputToMap']) {
self::$javascript.= "mapSettingsHooks.push(function(opts) {\n";
self::$javascript.= " opts.clickableLayers.push(indiciaData.reportlayer);\n";
self::$javascript.= " opts.clickableLayersOutputMode='reportHighlight';\n";
self::$javascript .= "});\n";
}
if ($options['ajax'] && $options['autoloadAjax']) {
self::$onload_javascript .= <<<JS
if (!indiciaData.reports.$group.{$uniqueName}[0].settings.populated) {
indiciaData.reports.$group.$uniqueName.ajaxload(true);
}
JS;
}
elseif (!$options['ajax']) {
self::$onload_javascript .= "indiciaData.reports.$group.$uniqueName.setupPagerEvents();\n";
}
return $r;
}
/**
* Returns a navigation link for report_grid data.
*
* If JavaScript disabled, links are used in column headers and pagination to
* reload the page with parameters added to sort or page through the data.
* These can be disabled, e.g. on public facing pages where you don't want
* search engines paging through the data.
*