PluginProbe
UpStream: a Project Management Plugin for WordPress / trunk
UpStream: a Project Management Plugin for WordPress vtrunk
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / templates / report-display.php

report-display.php in UpStream: a Project Management Plugin for WordPress trunk, at templates/report-display.php

167 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Template for displaying a report parameters
4 *
5 * This template can be overridden by copying it to yourtheme/upstream/report-parameters.php.
6 *
7 * @package UpStream
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 require_once dirname( __FILE__ ) . '/../includes/admin/metaboxes/metabox-functions.php';
15
16 /* Some hosts disable this function, so let's make sure it is enabled before call it. */
17 if ( function_exists( 'set_time_limit' ) ) {
18 set_time_limit( 120 );
19 }
20
21 $exception = null;
22 $get_data = isset( $_GET ) ? wp_unslash( $_GET ) : array();
23 $server_data = isset( $_SERVER ) ? wp_unslash( $_SERVER ) : array();
24
25 try {
26 if ( ! session_id() ) {
27 session_start();
28 }
29 } catch ( \Exception $e ) {
30 $exception = $e;
31 }
32
33
34 add_action(
35 'init',
36 function() {
37 try {
38 if ( ! session_id() ) {
39 session_start();
40 }
41 } catch ( \Exception $e ) {
42 $exception = $e;
43 }
44 },
45 9
46 );
47
48
49 if ( ! apply_filters( 'upstream_theme_override_header', false ) ) {
50 upstream_get_template_part( 'global/header.php' );
51 }
52
53 if ( ! apply_filters( 'upstream_theme_override_sidebar', false ) ) {
54 upstream_get_template_part( 'global/sidebar.php' );
55 }
56
57 if ( ! apply_filters( 'upstream_theme_override_topnav', false ) ) {
58 upstream_get_template_part( 'global/top-nav.php' );
59 }
60
61
62 $report = UpStream_Report_Generator::get_instance()->get_report( sanitize_text_field( $get_data['report'] ) );
63 if ( ! $report ) {
64 return;
65 }
66
67 $display_options = $report->getDisplayOptions();
68
69 ?>
70
71 <script type="text/javascript">
72
73 jQuery(document).ready(function ($) {
74 /* Load the Visualization API and the piechart package. */
75 google.charts.load('current', {'packages': ['corechart', 'table', 'gantt', 'calendar']});
76
77 /* Set a callback to run when the Google Visualization API is loaded. */
78 google.charts.setOnLoadCallback(drawChart);
79
80 function drawChart() {
81
82 data = <?php echo json_encode( UpStream_Report_Generator::get_instance()->get_report_fields_from_post( false ) ); ?>;
83 data['report'] = '<?php echo esc_attr( $report->id ); ?>';
84 data['action'] = 'upstream_report_data';
85 data['nonce'] = upstream.security;
86
87 var jsonData = $.ajax({
88 url: upstream.ajaxurl,
89 type: 'post',
90 dataType: "json",
91 async: false,
92 data: data
93 }).responseText;
94
95 /* Create our data table out of JSON data loaded from server. */
96 var data = new google.visualization.DataTable(jsonData);
97 var jo = JSON.parse(jsonData);
98 var options = {};
99
100 if ('options' in jo) {
101 options = jo['options'];
102 }
103
104 if (jo['rows'].length == 0) {
105 jQuery('#table_div').html('Report query returned no results.');
106 }
107 else {
108 options.width = '100%';
109 options.height = 500;
110 options.allowHtml = true;
111
112 <?php if ( 'Gantt' == $display_options['visualization_type'] || 'BarChart' == $display_options['visualization_type'] ) : ?>
113 options.height = data.getNumberOfRows() * 45 + 50;
114 <?php elseif ( 'Table' == $display_options['visualization_type'] || 'Calendar' == $display_options['visualization_type'] ) : ?>
115 delete options.height;
116 <?php endif; ?>
117
118 /* Instantiate and draw our chart, passing in some options. */
119 var chart = new google.visualization.<?php echo esc_js( $display_options['visualization_type'] ); ?>(document.getElementById('table_div'));
120 chart.draw(data, options);
121
122 $('body').on('click', '#export_csv', function () {
123 var csvFormattedDataTable = google.visualization.dataTableToCsv(data);
124 var encodedUri = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csvFormattedDataTable);
125 this.href = encodedUri;
126 this.download = 'table-data.csv';
127 this.target = '_blank';
128 });
129
130 $('#print').click(function () {
131 window.print();
132 });
133
134 $('#export_div').css('display', 'block');
135 }
136 }
137
138 });
139 </script>
140
141 <div class="right_col clearfix" role="main">
142 <div class="col-md-12 col-sm-12 col-xs-12">
143 <div class="x_panel" data-section="report-display">
144 <div class="x_title">
145 <h2>
146 <?php echo esc_html( $report->title ); ?>
147 </h2>
148 <div class="clearfix"></div>
149 </div>
150 <div class="x_content">
151 <div id="table_div"></div>
152 </div>
153 <div id="export_div">
154 <a id="export_csv" class="btn btn-success mt-3"><?php esc_html_e( 'Export CSV', 'upstream' ); ?></a>
155 <a id="print" class="btn btn-primary mt-3"><?php esc_html_e( 'Print or Save to PDF', 'upstream' ); ?></a>
156 </div>
157 </div>
158 </div>
159 </div>
160 <?php
161
162
163 if ( ! apply_filters( 'upstream_theme_override_footer', false ) ) {
164 upstream_get_template_part( 'global/footer.php' );
165 }
166 ?>
167