| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Module Cost Tracker Summary class. |
| 4 |
* |
| 5 |
* @package MainWP\Dashboard |
| 6 |
* @version 4.6 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace MainWP\Dashboard\Module\CostTracker; |
| 10 |
|
| 11 |
use MainWP\Dashboard\MainWP_UI; |
| 12 |
use MainWP\Dashboard\MainWP_Utility; |
| 13 |
use MainWP\Dashboard\MainWP_Overview; |
| 14 |
use MainWP\Dashboard\MainWP_Ui_Manage_Widgets_Layout; |
| 15 |
|
| 16 |
// Exit if accessed directly. |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Class class Cost_Tracker_Summary { |
| 23 |
* |
| 24 |
* @package MainWP\Dashboard |
| 25 |
*/ |
| 26 |
class Cost_Tracker_Summary { |
| 27 |
|
| 28 |
/** |
| 29 |
* Get Class Name |
| 30 |
* |
| 31 |
* @return string __CLASS__ |
| 32 |
*/ |
| 33 |
public static function get_class_name() { |
| 34 |
return __CLASS__; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* The single instance of the class |
| 39 |
* |
| 40 |
* @var mixed Default null |
| 41 |
*/ |
| 42 |
protected static $instance = null; |
| 43 |
|
| 44 |
/** |
| 45 |
* Enabled widgets |
| 46 |
* |
| 47 |
* @var array $enable_widgets |
| 48 |
*/ |
| 49 |
private static $enable_widgets = array( |
| 50 |
'cost_upcomming_renewals' => true, |
| 51 |
'cost_monthly_renewals' => true, |
| 52 |
'cost_yearly_renewals' => true, |
| 53 |
'cost_monthly_totals' => true, |
| 54 |
'cost_category_totals' => true, |
| 55 |
'cost_payments_left_this_month' => true, |
| 56 |
); |
| 57 |
|
| 58 |
/** |
| 59 |
* Current page. |
| 60 |
* |
| 61 |
* @static |
| 62 |
* @var string $page Current page. |
| 63 |
*/ |
| 64 |
public static $page; |
| 65 |
|
| 66 |
/** |
| 67 |
* Check if there is a session, |
| 68 |
* if there isn't one create it. |
| 69 |
* |
| 70 |
* @return static::singlton Overview Page Session. |
| 71 |
* |
| 72 |
* @uses \MainWP\Dashboard\MainWP_Overview |
| 73 |
*/ |
| 74 |
public static function instance() { |
| 75 |
if ( null === static::$instance ) { |
| 76 |
static::$instance = new self(); |
| 77 |
} |
| 78 |
|
| 79 |
return static::$instance; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* MainWP_Overview constructor. |
| 84 |
* |
| 85 |
* Run each time the class is called. |
| 86 |
*/ |
| 87 |
public function __construct() { |
| 88 |
add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Hook admin init. |
| 93 |
*/ |
| 94 |
public function admin_init() { |
| 95 |
$this->handle_update_screen_options(); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
/** |
| 100 |
* Handle update screen options. |
| 101 |
*/ |
| 102 |
public function handle_update_screen_options() { //phpcs:ignore -- NOSONAR - complex. |
| 103 |
$update_opts = false; |
| 104 |
if ( isset( $_POST['module_cost_tracker_summay_options_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['module_cost_tracker_summay_options_nonce'] ), 'module_cost_tracker_summay_options_nonce' ) ) { |
| 105 |
$update_opts = true; |
| 106 |
} |
| 107 |
if ( $update_opts ) { |
| 108 |
$show_wids = array(); |
| 109 |
if ( isset( $_POST['mainwp_show_widgets'] ) && is_array( $_POST['mainwp_show_widgets'] ) ) { |
| 110 |
$selected_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_show_widgets'] ) ); |
| 111 |
foreach ( $selected_wids as $name ) { |
| 112 |
$show_wids[ $name ] = 1; |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
if ( isset( $_POST['mainwp_widgets_name'] ) && is_array( $_POST['mainwp_widgets_name'] ) ) { |
| 117 |
$name_wids = array_map( 'sanitize_text_field', wp_unslash( $_POST['mainwp_widgets_name'] ) ); |
| 118 |
foreach ( $name_wids as $name ) { |
| 119 |
if ( ! isset( $show_wids[ $name ] ) ) { |
| 120 |
$show_wids[ $name ] = 0; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
global $current_user; |
| 126 |
|
| 127 |
if ( $current_user ) { |
| 128 |
update_user_option( $current_user->ID, 'mainwp_module_cost_tracker_summary_show_widgets', $show_wids, true ); |
| 129 |
if ( isset( $_POST['reset_module_cost_tracker_summary_widgets_settings'] ) && ! empty( $_POST['reset_module_cost_tracker_summary_widgets_settings'] ) ) { |
| 130 |
update_user_option( $current_user->ID, 'mainwp_module_cost_tracker_summary_show_widgets', false, true ); |
| 131 |
update_user_option( $current_user->ID, 'mainwp_widgets_sorted_' . strtolower( 'mainwp_page_CostSummary' ), false, true ); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
/** |
| 139 |
* Method on_load_page() |
| 140 |
* |
| 141 |
* Run on page load. |
| 142 |
* |
| 143 |
* @param mixed $page Page name. |
| 144 |
*/ |
| 145 |
public function on_load_page( $page ) { |
| 146 |
|
| 147 |
static::$page = $page; |
| 148 |
|
| 149 |
$val = get_user_option( 'screen_layout_' . $page ); |
| 150 |
if ( ! $val ) { |
| 151 |
global $current_user; |
| 152 |
update_user_option( $current_user->ID, 'screen_layout_' . $page, 2, true ); |
| 153 |
} |
| 154 |
|
| 155 |
wp_enqueue_script( 'common' ); |
| 156 |
wp_enqueue_script( 'wp-lists' ); |
| 157 |
wp_enqueue_script( 'postbox' ); |
| 158 |
wp_enqueue_script( 'dashboard' ); |
| 159 |
wp_enqueue_script( 'widgets' ); |
| 160 |
|
| 161 |
static::add_meta_boxes( $page ); |
| 162 |
|
| 163 |
add_filter( 'mainwp_header_actions_right', array( $this, 'screen_options' ), 10, 2 ); |
| 164 |
add_filter( 'mainwp_widget_boxes_show_widgets', array( $this, 'hook_show_widgets' ), 10, 2 ); |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Method screen_options() |
| 169 |
* |
| 170 |
* Create Page Settings button. |
| 171 |
* |
| 172 |
* @param mixed $input Page Settings button HTML. |
| 173 |
* |
| 174 |
* @return mixed Page Settings button. |
| 175 |
*/ |
| 176 |
public function screen_options( $input ) { |
| 177 |
return $input . |
| 178 |
'<a class="ui button basic icon" onclick="mainwp_module_cost_tracker_summary_screen_options(); return false;" data-inverted="" data-position="bottom right" href="#" target="_blank" data-tooltip="' . esc_html__( 'Page Settings', 'mainwp' ) . '" aria-label="' . esc_html__( 'Page Settings', 'mainwp' ) . '"> |
| 179 |
<i class="cog icon"></i> |
| 180 |
</a>'; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* Method hook_show_widgets() |
| 185 |
* |
| 186 |
* Hook show widgets. |
| 187 |
* |
| 188 |
* @param array $values Show widgets settings. |
| 189 |
* @param string $page Page slug. |
| 190 |
* |
| 191 |
* @return array $values Show widgets settings. |
| 192 |
*/ |
| 193 |
public function hook_show_widgets( $values, $page ) { |
| 194 |
if ( strtolower( $page ) === strtolower( static::$page ) ) { |
| 195 |
return get_user_option( 'mainwp_module_cost_tracker_summary_show_widgets' ); |
| 196 |
} |
| 197 |
return $values; |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
/** |
| 202 |
* Method add_meta_boxes() |
| 203 |
* |
| 204 |
* Add MainWP Operations Page Widgets. |
| 205 |
* |
| 206 |
* @param array $page Current page. |
| 207 |
* |
| 208 |
* @uses \MainWP\Dashboard\MainWP_System_Handler::apply_filters() |
| 209 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid() |
| 210 |
* @uses \MainWP\Dashboard\MainWP_UI::add_widget_box() |
| 211 |
* @uses \MainWP\Dashboard\MainWP_Connection_Status::get_class_name() |
| 212 |
* @uses \MainWP\Dashboard\MainWP_Recent_Pages::get_class_name() |
| 213 |
* @uses \MainWP\Dashboard\MainWP_Recent_Posts::get_class_name() |
| 214 |
* @uses \MainWP\Dashboard\MainWP_Security_Issues_Widget::get_class_name() |
| 215 |
*/ |
| 216 |
public static function add_meta_boxes( $page ) { //phpcs:ignore -- NOSONAR - complex method. |
| 217 |
|
| 218 |
/** |
| 219 |
* Get getmetaboxes |
| 220 |
* |
| 221 |
* Adds metaboxes (widgets) to the Operations page. |
| 222 |
* |
| 223 |
* @since 4.6 |
| 224 |
*/ |
| 225 |
$extMetaBoxs = array(); |
| 226 |
$extMetaBoxs = apply_filters( 'mainwp_cost_summary_getmetaboxes', $extMetaBoxs ); |
| 227 |
|
| 228 |
foreach ( $extMetaBoxs as $box ) { |
| 229 |
if ( isset( $box['plugin'] ) ) { |
| 230 |
$name = basename( $box['plugin'], '.php' ); |
| 231 |
static::$enable_widgets[ $name ] = true; |
| 232 |
} elseif ( ! empty( $box['widget_id'] ) ) { |
| 233 |
static::$enable_widgets[ $box['widget_id'] ] = true; |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Unset unwanted Widgets |
| 239 |
* |
| 240 |
* Contains the list of enabled widgets and allows user to unset unwanted widgets. |
| 241 |
* |
| 242 |
* @param array $enable_widgets Array containing enabled widgets. |
| 243 |
* @param int $dashboard_siteid Child site (Operations) ID. |
| 244 |
* |
| 245 |
* @since 4.6 |
| 246 |
*/ |
| 247 |
$values = apply_filters( 'mainwp_module_cost_tracker_summary_enabled_widgets', static::$enable_widgets, null ); |
| 248 |
static::$enable_widgets = array_merge( static::$enable_widgets, $values ); |
| 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 |
|
| 275 |
$i = 1; |
| 276 |
foreach ( $extMetaBoxs as $metaBox ) { |
| 277 |
$enabled = true; |
| 278 |
if ( isset( $metaBox['plugin'] ) ) { |
| 279 |
$name = basename( $metaBox['plugin'], '.php' ); |
| 280 |
if ( isset( static::$enable_widgets[ $name ] ) && ! static::$enable_widgets[ $name ] ) { |
| 281 |
$enabled = false; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
$id = isset( $metaBox['id'] ) ? $metaBox['id'] : $i++; |
| 286 |
$id = 'advanced-' . $id; |
| 287 |
|
| 288 |
$layout = ! empty( $metaBox['layout'] ) && is_array( $metaBox['layout'] ) ? $metaBox['layout'] : array( -1, -1, 6, 30 ); |
| 289 |
|
| 290 |
if ( $enabled ) { |
| 291 |
MainWP_UI::add_widget_box( $id, $metaBox['callback'], $page, $layout ); |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* Method get default logs filters() |
| 298 |
*/ |
| 299 |
public static function get_default_filters() { |
| 300 |
$format = 'Y-m-d'; |
| 301 |
return array( |
| 302 |
'ranges' => 'thismonth', |
| 303 |
'dtsstart' => gmdate( $format, strtotime( gmdate( 'Y-m-01' ) ) ), |
| 304 |
'dtsstop' => gmdate( $format, time() ), |
| 305 |
); |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Method render_footer() |
| 310 |
* |
| 311 |
* Render Insights page footer. Closes the page container. |
| 312 |
*/ |
| 313 |
public static function render_footer() { |
| 314 |
echo '</div>'; |
| 315 |
} |
| 316 |
|
| 317 |
/** |
| 318 |
* Render summary page. |
| 319 |
* |
| 320 |
* @return void |
| 321 |
*/ |
| 322 |
public function render_summary_page() { |
| 323 |
if ( ! \mainwp_current_user_can( 'dashboard', 'access_cost_summary_dashboard' ) ) { |
| 324 |
\mainwp_do_not_have_permissions( esc_html__( 'cost summary', 'mainwp' ) ); |
| 325 |
return; |
| 326 |
} |
| 327 |
$this->on_show_page(); |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
/** |
| 332 |
* Method on_show_page() |
| 333 |
* |
| 334 |
* When the page loads render the body content. |
| 335 |
*/ |
| 336 |
public function on_show_page() { |
| 337 |
static::render_header(); |
| 338 |
static::render_summary_body(); |
| 339 |
} |
| 340 |
|
| 341 |
/** |
| 342 |
* Method render_header() |
| 343 |
* |
| 344 |
* Render Insights page header. |
| 345 |
*/ |
| 346 |
public static function render_header() { |
| 347 |
$params = array( |
| 348 |
'title' => esc_html__( 'Operational Costs Summary', 'mainwp' ), |
| 349 |
'which' => 'page_cost_summary', |
| 350 |
'wrap_class' => 'mainwp-module-cost-summary-wrapper', |
| 351 |
); |
| 352 |
MainWP_UI::render_top_header( $params ); |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
/** |
| 357 |
* Method render_summary_body() |
| 358 |
* |
| 359 |
* Render the summary costs content. |
| 360 |
*/ |
| 361 |
public static function render_summary_body() { |
| 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 ); |
| 366 |
?> |
| 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;"> |
| 385 |
<i class="close icon mainwp-notice-dismiss" notice-id="cost-summany-widgets"></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>' ); ?> |
| 388 |
</div> |
| 389 |
</div> |
| 390 |
<?php endif; ?> |
| 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 |
|
| 403 |
<?php |
| 404 |
/** |
| 405 |
* Action: mainwp_before_overview_widgets |
| 406 |
* |
| 407 |
* Fires at the top of the Operations page (before first widget). |
| 408 |
* |
| 409 |
* @since 4.6 |
| 410 |
*/ |
| 411 |
do_action( 'mainwp_before_overview_widgets', 'costsummary' ); |
| 412 |
?> |
| 413 |
<div id="mainwp-grid-wrapper" class="gridster"> |
| 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, ) ); ?> |
| 423 |
</div> |
| 424 |
<?php |
| 425 |
/** |
| 426 |
* Action: 'mainwp_after_overview_widgets' |
| 427 |
* |
| 428 |
* Fires at the bottom of the Operations page (after the last widget). |
| 429 |
* |
| 430 |
* @since 4.6 |
| 431 |
*/ |
| 432 |
do_action( 'mainwp_after_overview_widgets', 'costsummary' ); |
| 433 |
?> |
| 434 |
<script type="text/javascript"> |
| 435 |
jQuery(function( $ ) { |
| 436 |
jQuery( '.mainwp-widget .mainwp-dropdown-tab .item' ).tab(); |
| 437 |
mainwp_module_cost_tracker_summary_screen_options = function () { |
| 438 |
jQuery( '#mainwp-module-log-overview-screen-options-modal' ).modal( { |
| 439 |
allowMultiple: true, |
| 440 |
onHide: function () { |
| 441 |
} |
| 442 |
} ).modal( 'show' ); |
| 443 |
return false; |
| 444 |
}; |
| 445 |
jQuery('#reset-costs-summary-widgets-settings').on('click', function () { |
| 446 |
mainwp_confirm(__('Are you sure?'), function(){ |
| 447 |
jQuery('.mainwp_hide_wpmenu_checkboxes input[name="mainwp_show_widgets[]"]').prop('checked', true); |
| 448 |
jQuery('input[name=reset_module_cost_tracker_summary_widgets_settings]').attr('value', 1); |
| 449 |
jQuery('#submit-cost-summary-widgets-settings').click(); |
| 450 |
}, false, false, true); |
| 451 |
return false; |
| 452 |
}); |
| 453 |
|
| 454 |
jQuery( '#mainwp-upcoming-renewals-table-today' ).DataTable(); |
| 455 |
jQuery( '#mainwp-upcoming-renewals-table-tomorrow' ).DataTable(); |
| 456 |
jQuery( '#mainwp-upcoming-renewals-table-week' ).DataTable(); |
| 457 |
jQuery( '#mainwp-upcoming-renewals-table-next_week' ).DataTable(); |
| 458 |
jQuery( '#mainwp-upcoming-renewals-table-month' ).DataTable(); |
| 459 |
jQuery( '#mainwp-upcoming-renewals-table-next_month' ).DataTable(); |
| 460 |
jQuery( '#mainwp-upcoming-renewals-table-year' ).DataTable(); |
| 461 |
jQuery( '#mainwp-upcoming-renewals-table-next_year' ).DataTable(); |
| 462 |
} ); |
| 463 |
</script> |
| 464 |
</div> |
| 465 |
<?php MainWP_Ui_Manage_Widgets_Layout::render_modal_save_layout(); ?> |
| 466 |
<div class="ui modal" id="mainwp-module-log-overview-screen-options-modal"> |
| 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(); ?> |
| 484 |
<?php |
| 485 |
/** |
| 486 |
* Action: mainwp_module_cost_tracker_summary_screen_options_bottom |
| 487 |
* |
| 488 |
* Fires at the bottom of the Sceen Options modal on the Operations page. |
| 489 |
* |
| 490 |
* @since 4.6 |
| 491 |
*/ |
| 492 |
do_action( 'mainwp_module_cost_tracker_summary_screen_options_bottom' ); |
| 493 |
?> |
| 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> |
| 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> |
| 503 |
</div> |
| 504 |
</div> |
| 505 |
|
| 506 |
<input type="hidden" name="reset_module_cost_tracker_summary_widgets_settings" value="" /> |
| 507 |
</form> |
| 508 |
</div> |
| 509 |
</div> |
| 510 |
<?php |
| 511 |
} |
| 512 |
|
| 513 |
/** |
| 514 |
* Method render_screen_options() |
| 515 |
* |
| 516 |
* Render Page Settings. |
| 517 |
* |
| 518 |
* @return void Render Page Settings html. |
| 519 |
*/ |
| 520 |
public static function render_screen_options() { |
| 521 |
$default_widgets = array( |
| 522 |
'cost_upcomming_renewals' => esc_html__( 'Upcoming Renewals', 'mainwp' ), |
| 523 |
'cost_monthly_renewals' => esc_html__( 'Upcoming Monthly Renewals', 'mainwp' ), |
| 524 |
'cost_yearly_renewals' => esc_html__( 'Upcoming Yearly Renewals', 'mainwp' ), |
| 525 |
'cost_monthly_totals' => esc_html__( 'Monthly Totals', 'mainwp' ), |
| 526 |
'cost_category_totals' => esc_html__( 'Annual Expense Distribution by Category', 'mainwp' ), |
| 527 |
'cost_payments_left_this_month' => esc_html__( 'Payment Left For This Month', 'mainwp' ), |
| 528 |
); |
| 529 |
|
| 530 |
$custom_opts = array(); |
| 531 |
/** |
| 532 |
* Filter: mainwp_module_cost_tracker_summary_widgets_screen_options |
| 533 |
* |
| 534 |
* Filters available widgets on the Operations page allowing users to unset unwanted widgets. |
| 535 |
* |
| 536 |
* @since 4.6 |
| 537 |
*/ |
| 538 |
$custom_opts = apply_filters( 'mainwp_module_cost_tracker_summary_widgets_screen_options', $custom_opts ); |
| 539 |
|
| 540 |
if ( is_array( $custom_opts ) && ! empty( $custom_opts ) ) { |
| 541 |
$default_widgets = array_merge( $default_widgets, $custom_opts ); |
| 542 |
} |
| 543 |
|
| 544 |
$show_widgets = get_user_option( 'mainwp_module_cost_tracker_summary_show_widgets' ); |
| 545 |
if ( ! is_array( $show_widgets ) ) { |
| 546 |
$show_widgets = array(); |
| 547 |
} |
| 548 |
|
| 549 |
/** |
| 550 |
* Action: mainwp_screen_options_modal_top |
| 551 |
* |
| 552 |
* Fires at the top of the Page Settings modal element. |
| 553 |
* |
| 554 |
* @since 4.6 |
| 555 |
*/ |
| 556 |
do_action( 'mainwp_screen_options_modal_top', 'costsummary' ); |
| 557 |
?> |
| 558 |
<?php if ( isset( $_GET['page'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized ?> |
| 559 |
<div class="ui grid field"> |
| 560 |
<label class="six wide column"><?php esc_html_e( 'Show widgets', 'mainwp' ); ?></label> |
| 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"> |
| 562 |
<ul class="mainwp_hide_wpmenu_checkboxes"> |
| 563 |
<?php |
| 564 |
foreach ( $default_widgets as $name => $title ) { |
| 565 |
$_selected = ''; |
| 566 |
if ( ! isset( $show_widgets[ $name ] ) || 1 === (int) $show_widgets[ $name ] ) { |
| 567 |
$_selected = 'checked'; |
| 568 |
} |
| 569 |
?> |
| 570 |
<li> |
| 571 |
<div class="ui checkbox"> |
| 572 |
<input type="checkbox" id="mainwp_show_widget_<?php echo esc_attr( $name ); ?>" name="mainwp_show_widgets[]" <?php echo esc_html( $_selected ); ?> value="<?php echo esc_attr( $name ); ?>"> |
| 573 |
<label for="mainwp_show_widget_<?php echo esc_attr( $name ); ?>" ><?php echo esc_html( $title ); ?></label> |
| 574 |
</div> |
| 575 |
<input type="hidden" name="mainwp_widgets_name[]" value="<?php echo esc_attr( $name ); ?>"> |
| 576 |
</li> |
| 577 |
<?php |
| 578 |
} |
| 579 |
?> |
| 580 |
</ul> |
| 581 |
</div> |
| 582 |
</div> |
| 583 |
<?php endif; ?> |
| 584 |
<?php |
| 585 |
/** |
| 586 |
* Action: mainwp_screen_options_modal_bottom |
| 587 |
* |
| 588 |
* Fires at the bottom of the Page Settings modal element. |
| 589 |
* |
| 590 |
* @since 4.6 |
| 591 |
*/ |
| 592 |
do_action( 'mainwp_screen_options_modal_bottom', 'costsummary' ); |
| 593 |
} |
| 594 |
} |
| 595 |
|