PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.2.4
GiveWP – Donation Plugin and Fundraising Platform v2.2.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / reports / reports.php
give / includes / admin / reports Last commit date
class-donor-reports-table.php 8 years ago class-earnings-report.php 8 years ago class-form-reports-table.php 8 years ago class-forms-report.php 8 years ago class-gateways-report.php 8 years ago class-gateways-reports-table.php 8 years ago class-give-graph.php 8 years ago graphing.php 7 years ago reports.php 8 years ago
reports.php
348 lines
1 <?php
2 /**
3 * Admin Reports Page
4 *
5 * Language Changes from EDD:
6 * 1. "Report Type" stays
7 * 2. "Earnings" changes to "Income"
8 * 3. "Donors" changes to "Donors"
9 * 4. "Payment Method" stays.
10 *
11 * @package Give
12 * @subpackage Admin/Reports
13 * @copyright Copyright (c) 2016, WordImpress
14 * @license https://opensource.org/licenses/gpl-license GNU Public License
15 * @since 1.0
16 */
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Reports Page
25 *
26 * Renders the reports page contents.
27 *
28 * @since 1.0
29 * @return void
30 */
31 function give_reports_page() {
32 $current_page = admin_url( 'edit.php?post_type=give_forms&page=give-reports' );
33 $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'earnings';
34 $views = give_reports_default_views();
35 ?>
36 <div class="wrap give-settings-page">
37
38 <h1 class="screen-reader-text"><?php echo get_admin_page_title(); ?></h1>
39
40 <h2 class="nav-tab-wrapper">
41 <?php foreach ( $views as $tab => $label ) { ?>
42 <a href="<?php echo esc_url( add_query_arg( array(
43 'tab' => $tab,
44 'settings-updated' => false,
45 ), $current_page ) ); ?>" class="nav-tab <?php echo $tab === $active_tab ? esc_attr( 'nav-tab-active' ) : ''; ?>"><?php echo esc_html( $label ); ?></a>
46 <?php } ?>
47 <?php if ( current_user_can( 'export_give_reports' ) ) { ?>
48 <a href="<?php echo esc_url( add_query_arg( array(
49 'tab' => 'export',
50 'settings-updated' => false,
51 ), $current_page ) ); ?>" class="nav-tab <?php echo 'export' === $active_tab ? esc_attr( 'nav-tab-active' ) : ''; ?>"><?php esc_html_e( 'Export', 'give' ); ?></a>
52 <?php }
53 /**
54 * Fires in the report tabs.
55 *
56 * Allows you to add new report tabs.
57 *
58 * @since 1.0
59 */
60 do_action( 'give_reports_tabs' );
61 ?>
62 </h2>
63
64 <?php
65 /**
66 * Fires before the report page.
67 *
68 * @since 1.0
69 */
70 do_action( 'give_reports_page_top' );
71
72 // Set $active_tab prior to hook firing.
73 if ( in_array( $active_tab, array_keys( $views ) ) ) {
74 $active_tab = 'reports';
75 }
76
77 /**
78 * Fires the report page active tab.
79 *
80 * @since 1.0
81 */
82 do_action( "give_reports_tab_{$active_tab}" );
83
84 /**
85 * Fires after the report page.
86 *
87 * @since 1.0
88 */
89 do_action( 'give_reports_page_bottom' );
90 ?>
91 </div><!-- .wrap -->
92 <?php
93 }
94
95 /**
96 * Default Report Views
97 *
98 * @since 1.0
99 * @return array $views Report Views
100 */
101 function give_reports_default_views() {
102 $views = array(
103 'earnings' => esc_html__( 'Income', 'give' ),
104 'forms' => esc_html__( 'Forms', 'give' ),
105 'gateways' => esc_html__( 'Donation Methods', 'give' ),
106 );
107
108 $views = apply_filters( 'give_report_views', $views );
109
110 return $views;
111 }
112
113 /**
114 * Default Report Views
115 *
116 * Checks the $_GET['view'] parameter to ensure it exists within the default allowed views.
117 *
118 * @param string $default Default view to use.
119 *
120 * @since 1.0
121 * @return string $view Report View
122 */
123 function give_get_reporting_view( $default = 'earnings' ) {
124
125 if ( ! isset( $_GET['view'] ) || ! in_array( $_GET['view'], array_keys( give_reports_default_views() ) ) ) {
126 $view = $default;
127 } else {
128 $view = $_GET['view'];
129 }
130
131 return apply_filters( 'give_get_reporting_view', $view );
132 }
133
134 /**
135 * Renders the Reports page
136 *
137 * @since 1.0
138 * @return void
139 */
140 function give_reports_tab_reports() {
141
142 if( ! current_user_can( 'view_give_reports' ) ) {
143 wp_die( __( 'You do not have permission to access this report', 'give' ), __( 'Error', 'give' ), array( 'response' => 403 ) );
144 }
145
146 $current_view = 'earnings';
147 $views = give_reports_default_views();
148
149 if ( isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $views ) ) {
150 $current_view = $_GET['tab'];
151 }
152
153 /**
154 * Fires the report page view.
155 *
156 * @since 1.0
157 */
158 do_action( "give_reports_view_{$current_view}" );
159 }
160
161 add_action( 'give_reports_tab_reports', 'give_reports_tab_reports' );
162
163 /**
164 * Renders the Reports Page Views Drop Downs
165 *
166 * @since 1.0
167 * @return void
168 */
169 function give_report_views() {
170 $views = give_reports_default_views();
171 $current_view = isset( $_GET['view'] ) ? $_GET['view'] : 'earnings';
172 /**
173 * Fires before the report page actions form.
174 *
175 * @since 1.0
176 */
177 do_action( 'give_report_view_actions_before' );
178 ?>
179 <form id="give-reports-filter" method="get">
180 <select id="give-reports-view" name="view">
181 <option value="-1"><?php esc_html_e( 'Report Type', 'give' ); ?></option>
182 <?php foreach ( $views as $view_id => $label ) : ?>
183 <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current_view ); ?>><?php echo $label; ?></option>
184 <?php endforeach; ?>
185 </select>
186
187 <?php
188 /**
189 * Fires in the report page actions area.
190 *
191 * Allows you to add new elements/actions after the "Report Type" drop down.
192 *
193 * @since 1.0
194 */
195 do_action( 'give_report_view_actions' );
196 ?>
197
198 <input type="hidden" name="post_type" value="give_forms"/>
199 <input type="hidden" name="page" value="give-reports"/>
200 <?php submit_button( esc_html__( 'Show', 'give' ), 'secondary', 'submit', false ); ?>
201 </form>
202 <?php
203 /**
204 * Fires after the report page actions form.
205 *
206 * @since 1.0
207 */
208 do_action( 'give_report_view_actions_after' );
209 }
210
211 /**
212 * Renders the Reports Give Form Table
213 *
214 * @since 1.0
215 * @uses Give_Form_Reports_Table::prepare_items()
216 * @uses Give_Form_Reports_Table::display()
217 * @return void
218 */
219 function give_reports_forms_table() {
220
221 if ( isset( $_GET['form-id'] ) ) {
222 return;
223 }
224
225 include GIVE_PLUGIN_DIR . 'includes/admin/reports/class-form-reports-table.php';
226
227 $give_table = new Give_Form_Reports_Table();
228 $give_table->prepare_items();
229 $give_table->display();
230 ?>
231 <input type="hidden" name="post_type" value="give_forms"/>
232 <input type="hidden" name="page" value="give-reports"/>
233 <input type="hidden" name="tab" value="forms"/>
234 <?php
235 }
236
237 add_action( 'give_reports_view_forms', 'give_reports_forms_table' );
238
239 /**
240 * Renders the detailed report for a specific give form.
241 *
242 * @since 1.0
243 * @return void
244 */
245 function give_reports_form_details() {
246 if ( ! isset( $_GET['form-id'] ) ) {
247 return;
248 }
249 ?>
250 <div class="tablenav top reports-forms-details-wrap">
251 <div class="actions bulkactions">
252 <button onclick="history.go(-1);" class="button-secondary"><?php esc_html_e( 'Go Back', 'give' ); ?></button>
253 </div>
254 </div>
255 <?php
256 give_reports_graph_of_form( absint( $_GET['form-id'] ) );
257 }
258
259 add_action( 'give_reports_view_forms', 'give_reports_form_details' );
260
261 /**
262 * Renders the Gateways Table
263 *
264 * @since 1.3
265 * @uses Give_Gateway_Reports_Table::prepare_items()
266 * @uses Give_Gateway_Reports_Table::display()
267 * @return void
268 */
269 function give_reports_gateways_table() {
270 include GIVE_PLUGIN_DIR . 'includes/admin/reports/class-gateways-reports-table.php';
271
272 $give_table = new Give_Gateway_Reports_Table();
273 $give_table->prepare_items();
274 $give_table->display();
275 }
276
277 add_action( 'give_reports_view_gateways', 'give_reports_gateways_table' );
278
279 /**
280 * Renders the Reports Earnings Graphs
281 *
282 * @since 1.0
283 * @return void
284 */
285 function give_reports_earnings() {
286 ?>
287 <div class="tablenav top reports-table-nav">
288 <h2 class="reports-earnings-title screen-reader-text"><?php _e( 'Income Report', 'give' ); ?></h2>
289 </div>
290 <?php
291 give_reports_graph();
292 }
293
294 add_action( 'give_reports_view_earnings', 'give_reports_earnings' );
295
296
297 /**
298 * Retrieves estimated monthly earnings and sales
299 *
300 * @since 1.0
301 * @return array
302 */
303 function give_estimated_monthly_stats() {
304
305 $estimated = Give_Cache::get( 'give_estimated_monthly_stats', true );
306
307 if ( false === $estimated ) {
308
309 $estimated = array(
310 'earnings' => 0,
311 'sales' => 0,
312 );
313
314 $stats = new Give_Payment_Stats;
315
316 $to_date_earnings = $stats->get_earnings( 0, 'this_month' );
317 $to_date_sales = $stats->get_sales( 0, 'this_month' );
318
319 $current_day = date( 'd', current_time( 'timestamp' ) );
320 $current_month = date( 'n', current_time( 'timestamp' ) );
321 $current_year = date( 'Y', current_time( 'timestamp' ) );
322 $days_in_month = cal_days_in_month( CAL_GREGORIAN, $current_month, $current_year );
323
324 $estimated['earnings'] = ( $to_date_earnings / $current_day ) * $days_in_month;
325 $estimated['sales'] = ( $to_date_sales / $current_day ) * $days_in_month;
326
327 // Cache for one day
328 Give_Cache::set( 'give_estimated_monthly_stats', $estimated, DAY_IN_SECONDS, true );
329 }
330
331 return maybe_unserialize( $estimated );
332 }
333
334 /**
335 * Assign Get form method for reporting tabs
336 *
337 * @since 1.8.12
338 *
339 * @return string
340 */
341 function give_reports_set_form_method() {
342 return 'get';
343 }
344 add_filter( 'give-reports_form_method_tab_forms', 'give_reports_set_form_method', 10 );
345 add_filter( 'give-reports_form_method_tab_donors', 'give_reports_set_form_method', 10 );
346
347 // @TODO: After release 1.8 Donations -> Reports generates with new setting api, so we can remove some old code from this file.
348