PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 All 156 releases
← All changes | modules/cost-tracker/classes/class-cost-tracker-summary.php +123 -97 5.1.1 → 6.2.2 View file →
@@ -7,20 +7,20 @@
7 7 */
8 8
9 9 namespace MainWP\Dashboard\Module\CostTracker;
10 10
11 -use MainWP\Dashboard\MainWP_Menu;
12 11 use MainWP\Dashboard\MainWP_UI;
13 12 use MainWP\Dashboard\MainWP_Utility;
14 -use MainWP\Dashboard\MainWP_DB_Client;
15 -use MainWP\Dashboard\MainWP_DB_Common;
16 -use MainWP\Dashboard\MainWP_Post_Handler;
17 -use MainWP\Dashboard\MainWP_Logger;
18 -use function MainWP\Dashboard\mainwp_current_user_have_right;
19 -use function MainWP\Dashboard\mainwp_do_not_have_permissions;
13 +use MainWP\Dashboard\MainWP_Overview;
14 +use MainWP\Dashboard\MainWP_Ui_Manage_Widgets_Layout;
20 15
16 +// Exit if accessed directly.
17 +if ( ! defined( 'ABSPATH' ) ) {
18 + exit;
19 +}
20 +
21 21 /**
22 - * Class Log_Insights_Page
22 + * Class class Cost_Tracker_Summary {
23 23 *
24 24 * @package MainWP\Dashboard
25 25 */
26 26 class Cost_Tracker_Summary {
@@ -200,9 +200,9 @@
200 200
201 201 /**
202 202 * Method add_meta_boxes()
203 203 *
204 - * Add MainWP Overview Page Widgets.
204 + * Add MainWP Operations Page Widgets.
205 205 *
206 206 * @param array $page Current page.
207 207 *
208 208 * @uses \MainWP\Dashboard\MainWP_System_Handler::apply_filters()
@@ -217,9 +217,9 @@
217 217
218 218 /**
219 219 * Get getmetaboxes
220 220 *
221 - * Adds metaboxes (widgets) to the Overview page.
221 + * Adds metaboxes (widgets) to the Operations page.
222 222 *
223 223 * @since 4.6
224 224 */
225 225 $extMetaBoxs = array();
@@ -239,9 +239,9 @@
239 239 *
240 240 * Contains the list of enabled widgets and allows user to unset unwanted widgets.
241 241 *
242 242 * @param array $enable_widgets Array containing enabled widgets.
243 - * @param int $dashboard_siteid Child site (Overview) ID.
243 + * @param int $dashboard_siteid Child site (Operations) ID.
244 244 *
245 245 * @since 4.6
246 246 */
247 247 $values = apply_filters( 'mainwp_module_cost_tracker_summary_enabled_widgets', static::$enable_widgets, null );
@@ -246,8 +246,33 @@
246 246 */
247 247 $values = apply_filters( 'mainwp_module_cost_tracker_summary_enabled_widgets', static::$enable_widgets, null );
248 248 static::$enable_widgets = array_merge( static::$enable_widgets, $values );
249 249
250 + // Load the widget.
251 + if ( ! empty( static::$enable_widgets['cost_monthly_totals'] ) ) {
252 + MainWP_UI::add_widget_box( 'cost_monthly_totals', array( Cost_Tracker_Monthly_Totals::instance(), 'render' ), $page, array( 1, 1, 12, 40 ) );
253 + }
254 + // Load the widget.
255 + if ( ! empty( static::$enable_widgets['cost_payments_left_this_month'] ) ) {
256 + MainWP_UI::add_widget_box( 'cost_payments_left_this_month', array( Cost_Tracker_Payment_Left_This_Month::instance(), 'render' ), $page, array( -1, -1, 6, 40 ) );
257 + }
258 + // Load the widget.
259 + if ( ! empty( static::$enable_widgets['cost_category_totals'] ) ) {
260 + MainWP_UI::add_widget_box( 'cost_category_totals', array( Cost_Tracker_Category_Totals::instance(), 'render' ), $page, array( -1, -1, 6, 40 ) );
261 + }
262 + // Load the widget.
263 + if ( ! empty( static::$enable_widgets['cost_upcomming_renewals'] ) ) {
264 + MainWP_UI::add_widget_box( 'cost_upcomming_renewals', array( Cost_Tracker_Upcoming_Renewals::instance(), 'render' ), $page, array( -1, -1, 4, 30 ) );
265 + }
266 + // Load the widget.
267 + if ( ! empty( static::$enable_widgets['cost_yearly_renewals'] ) ) {
268 + MainWP_UI::add_widget_box( 'cost_yearly_renewals', array( Cost_Tracker_Yearly_Renewals::instance(), 'render' ), $page, array( -1, -1, 4, 30 ) );
269 + }
270 + // Load the widget.
271 + if ( ! empty( static::$enable_widgets['cost_monthly_renewals'] ) ) {
272 + MainWP_UI::add_widget_box( 'cost_monthly_renewals', array( Cost_Tracker_Monthly_Renewals::instance(), 'render' ), $page, array( -1, -1, 4, 30 ) );
273 + }
274 +
250 275 $i = 1;
251 276 foreach ( $extMetaBoxs as $metaBox ) {
252 277 $enabled = true;
253 278 if ( isset( $metaBox['plugin'] ) ) {
@@ -259,44 +284,14 @@
259 284
260 285 $id = isset( $metaBox['id'] ) ? $metaBox['id'] : $i++;
261 286 $id = 'advanced-' . $id;
262 287
263 - $layout = ! empty( $metaBox['layout'] ) && is_array( $metaBox['layout'] ) ? $metaBox['layout'] : array( 1, 1, 6, 13 );
288 + $layout = ! empty( $metaBox['layout'] ) && is_array( $metaBox['layout'] ) ? $metaBox['layout'] : array( -1, -1, 6, 30 );
264 289
265 290 if ( $enabled ) {
266 291 MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, $layout );
267 292 }
268 293 }
269 -
270 - // Load the widget.
271 - if ( ! empty( static::$enable_widgets['cost_yearly_renewals'] ) ) {
272 - MainWP_UI::add_widget_box( 'cost_yearly_renewals', array( Cost_Tracker_Yearly_Renewals::instance(), 'render' ), $page, array( 1, 1, 6, 13 ) );
273 - }
274 -
275 - // Load the widget.
276 - if ( ! empty( static::$enable_widgets['cost_monthly_renewals'] ) ) {
277 - MainWP_UI::add_widget_box( 'cost_monthly_renewals', array( Cost_Tracker_Monthly_Renewals::instance(), 'render' ), $page, array( 1, 1, 6, 13 ) );
278 - }
279 -
280 - // Load the widget.
281 - if ( ! empty( static::$enable_widgets['cost_upcomming_renewals'] ) ) {
282 - MainWP_UI::add_widget_box( 'cost_upcomming_renewals', array( Cost_Tracker_Upcoming_Renewals::instance(), 'render' ), $page, array( 1, 1, 6, 13 ) );
283 - }
284 -
285 - // Load the widget.
286 - if ( ! empty( static::$enable_widgets['cost_category_totals'] ) ) {
287 - MainWP_UI::add_widget_box( 'cost_category_totals', array( Cost_Tracker_Category_Totals::instance(), 'render' ), $page, array( 1, 1, 6, 13 ) );
288 - }
289 -
290 - // Load the widget.
291 - if ( ! empty( static::$enable_widgets['cost_monthly_totals'] ) ) {
292 - MainWP_UI::add_widget_box( 'cost_monthly_totals', array( Cost_Tracker_Monthly_Totals::instance(), 'render' ), $page, array( 1, 1, 6, 13 ) );
293 - }
294 -
295 - // Load the widget.
296 - if ( ! empty( static::$enable_widgets['cost_payments_left_this_month'] ) ) {
297 - MainWP_UI::add_widget_box( 'cost_payments_left_this_month', array( Cost_Tracker_Payment_Left_This_Month::instance(), 'render' ), $page, array( 1, 1, 6, 13 ) );
298 - }
299 294 }
300 295
301 296 /**
302 297 * Method get default logs filters()
@@ -324,10 +319,10 @@
324 319 *
325 320 * @return void
326 321 */
327 322 public function render_summary_page() {
328 - if ( ! mainwp_current_user_have_right( 'dashboard', 'access_cost_summary_dashboard' ) ) {
329 - mainwp_do_not_have_permissions( esc_html__( 'cost summary', 'mainwp' ) );
323 + if ( ! \mainwp_current_user_can( 'dashboard', 'access_cost_summary_dashboard' ) ) {
324 + \mainwp_do_not_have_permissions( esc_html__( 'cost summary', 'mainwp' ) );
330 325 return;
331 326 }
332 327 $this->on_show_page();
333 328 }
@@ -338,9 +333,9 @@
338 333 *
339 334 * When the page loads render the body content.
340 335 */
341 336 public function on_show_page() {
342 - static::render_header( 'cost_summary' );
337 + static::render_header();
343 338 static::render_summary_body();
344 339 }
345 340
346 341 /**
@@ -349,9 +344,9 @@
349 344 * Render Insights page header.
350 345 */
351 346 public static function render_header() {
352 347 $params = array(
353 - 'title' => esc_html__( 'Cost Summary', 'mainwp' ),
348 + 'title' => esc_html__( 'Operational Costs Summary', 'mainwp' ),
354 349 'which' => 'page_cost_summary',
355 350 'wrap_class' => 'mainwp-module-cost-summary-wrapper',
356 351 );
357 352 MainWP_UI::render_top_header( $params );
@@ -363,26 +358,54 @@
363 358 *
364 359 * Render the summary costs content.
365 360 */
366 361 public static function render_summary_body() {
367 - $screen = get_current_screen();
368 - $costs_data = Cost_Tracker_DB::get_instance()->get_summary_data( array( 'sum_data' => 'all' ) );
362 + $screen = get_current_screen();
363 + $costs_data = Cost_Tracker_DB::get_instance()->get_summary_data( array( 'sum_data' => 'all' ) );
364 + $costs = Cost_Tracker_DB::get_instance()->get_cost_tracker_by( 'all' );
365 + $costs_count = count( $costs );
369 366 ?>
370 - <div class="mainwp-primary-content-wrap">
371 - <div class="ui segment" style="padding-top:0;padding-bottom:0;">
372 - <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
373 - <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'cost-summany-widgets' ) ) : ?>
374 - <div class="ui info message">
367 + <div class="ui segment mainwp-primary-content-wrap">
368 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp-cost-summany-welcome-message' ) && 0 == $costs_count ) : ?>
369 + <div class="ui segment" style="margin-bottom:0px;">
370 + <div class="ui icon message mainwp-welcome-message" style="margin-bottom:0px;">
371 + <em data-emoji=":wave:" class="big"></em>
372 + <div class="content">
373 + <i class="close icon mainwp-notice-dismiss" notice-id="mainwp-cost-summany-welcome-message" style="float:right;cursor:pointer;"></i>
374 + <div class="ui massive header"><?php esc_html_e( 'Welcome to Cost Tracker', 'mainwp' ); ?></div>
375 + <p><?php esc_html_e( 'Track and forecast your agency\'s expenses across all sites and subscriptions.', 'mainwp' ); ?></p>
376 + <?php /* translators: 1: Opening link tag, 2: Closing link tag, 3: Opening link tag, 4: Closing link tag */ ?>
377 + <p><?php printf( esc_html__( 'Start by %1$sadding your first cost%2$s or %3$screating custom cost categories%4$s.', 'mainwp' ), '<a href="admin.php?page=CostTrackerAdd">', '</a>', '<a href="admin.php?page=CostTrackerSettings">', '</a>' ); ?></p>
378 + </div>
379 + </div>
380 + </div>
381 + <?php endif; ?>
382 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'cost-summany-widgets' ) ) : ?>
383 + <div class="ui segment" style="margin-bottom:0px;">
384 + <div class="ui message" style="margin-bottom:0px;">
375 385 <i class="close icon mainwp-notice-dismiss" notice-id="cost-summany-widgets"></i>
376 - <?php printf( esc_html__( 'To hide or show a widget, click the Cog (%1$s) icon.', 'mainwp' ), '<i class="cog icon"></i>' ); ?>
386 + <?php /* translators: 1: Tip emoji icon, 2: Cog icon, 3: Layout icon */ ?>
387 + <?php printf( esc_html__( '%1$s Tip: You can drag and drop widgets to reorder your dashboard, use Page Settings (%2$s) to show or hide widgets, and use Layout (%3$s) in the header to save and load your widget layouts.', 'mainwp' ), '<em data-emoji=":bulb:" class="small"></em>', '<i class="cog fitted icon"></i>', '<i class="all border fitted icon"></i>' ); ?>
377 388 </div>
389 + </div>
378 390 <?php endif; ?>
379 - </div>
391 + <?php if ( 0 < $costs_count && 3 >= $costs_count ) : ?>
392 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'cost-summany-low-data-info' ) ) : ?>
393 + <div class="ui segment" style="margin-bottom:0px;">
394 + <div class="ui info message" style="margin-bottom:0px;">
395 + <i class="close icon mainwp-notice-dismiss" notice-id="cost-summany-low-data-info"></i>
396 + <?php esc_html_e( 'Keep building your cost history. Add more expenses to unlock trend insights.', 'mainwp' ); ?>
397 + </div>
398 + </div>
399 + <?php endif; ?>
400 + <?php endif; ?>
401 + <div id="mainwp-message-zone" class="ui message" style="display:none;"></div>
402 +
380 403 <?php
381 404 /**
382 405 * Action: mainwp_before_overview_widgets
383 406 *
384 - * Fires at the top of the Overview page (before first widget).
407 + * Fires at the top of the Operations page (before first widget).
385 408 *
386 409 * @since 4.6
387 410 */
388 411 do_action( 'mainwp_before_overview_widgets', 'costsummary' );
@@ -387,22 +410,23 @@
387 410 */
388 411 do_action( 'mainwp_before_overview_widgets', 'costsummary' );
389 412 ?>
390 413 <div id="mainwp-grid-wrapper" class="gridster">
391 - <?php
392 - MainWP_UI::do_widget_boxes(
393 - $screen->id,
394 - array(
395 - 'costs_data' => $costs_data,
396 - )
397 - );
398 - ?>
414 + <div id="mainwp-widgets-placeholder" class="ui page dimmer">
415 + <div class="ui double text loader"><?php esc_html_e( 'Loading...', 'mainwp' ); ?></div>
416 + </div>
417 + <script>
418 + jQuery( document ).ready( function () {
419 + jQuery('#mainwp-widgets-placeholder').dimmer('show');
420 + });
421 + </script>
422 + <?php MainWP_UI::do_widget_boxes( $screen->id, array( 'costs_data' => $costs_data, ) ); ?>
399 423 </div>
400 424 <?php
401 425 /**
402 426 * Action: 'mainwp_after_overview_widgets'
403 427 *
404 - * Fires at the bottom of the Overview page (after the last widget).
428 + * Fires at the bottom of the Operations page (after the last widget).
405 429 *
406 430 * @since 4.6
407 431 */
408 432 do_action( 'mainwp_after_overview_widgets', 'costsummary' );
@@ -418,9 +442,9 @@
418 442 } ).modal( 'show' );
419 443 return false;
420 444 };
421 445 jQuery('#reset-costs-summary-widgets-settings').on('click', function () {
422 - mainwp_confirm(__('Are you sure.'), function(){
446 + mainwp_confirm(__('Are you sure?'), function(){
423 447 jQuery('.mainwp_hide_wpmenu_checkboxes input[name="mainwp_show_widgets[]"]').prop('checked', true);
424 448 jQuery('input[name=reset_module_cost_tracker_summary_widgets_settings]').attr('value', 1);
425 449 jQuery('#submit-cost-summary-widgets-settings').click();
426 450 }, false, false, true);
@@ -436,47 +460,49 @@
436 460 jQuery( '#mainwp-upcoming-renewals-table-year' ).DataTable();
437 461 jQuery( '#mainwp-upcoming-renewals-table-next_year' ).DataTable();
438 462 } );
439 463 </script>
464 + </div>
465 + <?php MainWP_Ui_Manage_Widgets_Layout::render_modal_save_layout(); ?>
440 466 <div class="ui modal" id="mainwp-module-log-overview-screen-options-modal">
441 - <i class="close icon"></i>
442 - <div class="header"><?php esc_html_e( 'Page Settings', 'mainwp' ); ?></div>
443 - <div class="content ui form">
467 + <i class="close icon"></i>
468 + <div class="header"><?php esc_html_e( 'Page Settings', 'mainwp' ); ?></div>
469 + <div class="content ui form">
470 + <?php
471 + /**
472 + * Action: mainwp_module_cost_tracker_summary_screen_options_top
473 + *
474 + * Fires at the top of the Sceen Options modal on the Operations page.
475 + *
476 + * @since 4.6
477 + */
478 + do_action( 'mainwp_module_cost_tracker_summary_screen_options_top' );
479 + ?>
480 + <form method="POST" action="" name="mainwp_module_cost_tracker_summary_screen_options_form" id="mainwp-module-log-overview-screen-options-form">
481 + <?php MainWP_UI::generate_wp_nonce( 'mainwp-admin-nonce' ); ?>
482 + <input type="hidden" name="module_cost_tracker_summay_options_nonce" value="<?php echo esc_attr( wp_create_nonce( 'module_cost_tracker_summay_options_nonce' ) ); ?>" />
483 + <?php static::render_screen_options(); ?>
444 484 <?php
445 485 /**
446 - * Action: mainwp_module_cost_tracker_summary_screen_options_top
486 + * Action: mainwp_module_cost_tracker_summary_screen_options_bottom
447 487 *
448 - * Fires at the top of the Sceen Options modal on the Overview page.
488 + * Fires at the bottom of the Sceen Options modal on the Operations page.
449 489 *
450 490 * @since 4.6
451 491 */
452 - do_action( 'mainwp_module_cost_tracker_summary_screen_options_top' );
492 + do_action( 'mainwp_module_cost_tracker_summary_screen_options_bottom' );
453 493 ?>
454 - <form method="POST" action="" name="mainwp_module_cost_tracker_summary_screen_options_form" id="mainwp-module-log-overview-screen-options-form">
455 - <?php wp_nonce_field( 'mainwp-admin-nonce' ); ?>
456 - <input type="hidden" name="module_cost_tracker_summay_options_nonce" value="<?php echo esc_attr( wp_create_nonce( 'module_cost_tracker_summay_options_nonce' ) ); ?>" />
457 - <?php static::render_screen_options( false ); ?>
458 - <?php
459 - /**
460 - * Action: mainwp_module_cost_tracker_summary_screen_options_bottom
461 - *
462 - * Fires at the bottom of the Sceen Options modal on the Overview page.
463 - *
464 - * @since 4.6
465 - */
466 - do_action( 'mainwp_module_cost_tracker_summary_screen_options_bottom' );
467 - ?>
468 - </div>
469 - <div class="actions">
470 - <div class="ui two columns grid">
471 - <div class="left aligned column">
472 - <span data-tooltip="<?php esc_attr_e( 'Resets the page to its original layout and reinstates relocated widgets.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><input type="button" class="ui button" name="reset" id="reset-costs-summary-widgets-settings" value="<?php esc_attr_e( 'Reset Page', 'mainwp' ); ?>" /></span>
473 - </div>
474 - <div class="ui right aligned column">
475 - <input type="submit" class="ui green button" id="submit-cost-summary-widgets-settings" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>" />
476 - </div>
494 + </div>
495 + <div class="actions">
496 + <div class="ui two columns grid">
497 + <div class="left aligned column">
498 + <span data-tooltip="<?php esc_attr_e( 'Resets the page to its original layout and reinstates relocated widgets.', 'mainwp' ); ?>" data-inverted="" data-position="top left"><input type="button" class="ui button" name="reset" id="reset-costs-summary-widgets-settings" value="<?php esc_attr_e( 'Reset Page', 'mainwp' ); ?>" /></span>
477 499 </div>
500 + <div class="ui right aligned column">
501 + <input type="submit" class="ui green button" id="submit-cost-summary-widgets-settings" value="<?php esc_attr_e( 'Save Settings', 'mainwp' ); ?>" />
502 + </div>
478 503 </div>
504 + </div>
479 505
480 506 <input type="hidden" name="reset_module_cost_tracker_summary_widgets_settings" value="" />
481 507 </form>
482 508 </div>
@@ -504,9 +530,9 @@
504 530 $custom_opts = array();
505 531 /**
506 532 * Filter: mainwp_module_cost_tracker_summary_widgets_screen_options
507 533 *
508 - * Filters available widgets on the Overview page allowing users to unsent unwanted widgets.
534 + * Filters available widgets on the Operations page allowing users to unset unwanted widgets.
509 535 *
510 536 * @since 4.6
511 537 */
512 538 $custom_opts = apply_filters( 'mainwp_module_cost_tracker_summary_widgets_screen_options', $custom_opts );
@@ -531,9 +557,9 @@
531 557 ?>
532 558 <?php if ( isset( $_GET['page'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?>
533 559 <div class="ui grid field">
534 560 <label class="six wide column"><?php esc_html_e( 'Show widgets', 'mainwp' ); ?></label>
535 - <div class="ten wide column" <?php echo 'data-tooltip="' . esc_attr__( 'Select widgets that you want to hide in the MainWP Overview page.', 'mainwp' ); ?> data-inverted="" data-position="top left">
561 + <div class="ten wide column" <?php echo 'data-tooltip="' . esc_attr__( 'Select widgets that you want to hide in the MainWP Operations page.', 'mainwp' ); ?> data-inverted="" data-position="top left">
536 562 <ul class="mainwp_hide_wpmenu_checkboxes">
537 563 <?php
538 564 foreach ( $default_widgets as $name => $title ) {
539 565 $_selected = '';