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.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 5.2.1 All 155 releases
mainwp / modules / cost-tracker / pages / page-cost-tracker-settings.php

page-cost-tracker-settings.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 6.2.2, at modules/cost-tracker/pages/page-cost-tracker-settings.php

438 lines 25.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Module Cost Tracker Settings class.
4 *
5 * @package MainWP\Dashboard
6 * @version 4.6
7 */
8
9 namespace MainWP\Dashboard\Module\CostTracker;
10
11 use MainWP\Dashboard\MainWP_Settings_Indicator;
12 use MainWP\Dashboard\MainWP_Settings;
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Class Cost_Tracker_Settings
21 */
22 class Cost_Tracker_Settings {
23
24 /**
25 * Static variable to hold the single instance of the class.
26 *
27 * @static
28 *
29 * @var mixed Default null
30 */
31 private static $instance = null;
32
33 /**
34 * Static variable to hold the single instance variable.
35 *
36 * @static
37 *
38 * @var string sub dir.
39 */
40 public static $icon_sub_dir = 'cost-tracker-products-icons';
41
42 /**
43 * Get Instance
44 *
45 * Creates public static instance.
46 *
47 * @static
48 *
49 * @return Cost_Tracker_Settings
50 */
51 public static function get_instance() {
52 if ( null === static::$instance ) {
53 static::$instance = new self();
54 }
55 return static::$instance;
56 }
57
58 /**
59 * Constructor
60 *
61 * Runs each time the class is called.
62 */
63 public function __construct() {
64 }
65
66
67 /**
68 * Render settings
69 *
70 * Renders the extension settings page.
71 */
72 public function render_settings_page() {
73 if ( ! \mainwp_current_user_can( 'dashboard', 'manage_cost_tracker' ) ) {
74 \mainwp_do_not_have_permissions( esc_html__( 'manage cost tracker', 'mainwp' ) );
75 return;
76 }
77 MainWP_Settings::render_header( 'CostTrackerSettings' );
78 ?>
79 <div class="ui padded segment" id="mainwp-module-cost-tracker-settings-tab">
80 <h2 class="ui dividing header">
81 <?php esc_html_e( 'Cost Tracker Settings ', 'mainwp' ); ?>
82 <div class="sub header"><?php esc_html_e( 'Customize how you track and manage costs. Adjust currency, categories, and other settings to fit your workflow.', 'mainwp' ); ?></div>
83 </h2>
84 <form id="mainwp-module-cost-tracker-settings-form" method="post" action="admin.php?page=CostTrackerSettings" class="ui form">
85 <?php $this->render_settings_content(); ?>
86 </form>
87 <div class="ui clearing hidden divider"></div>
88 </div>
89 <?php
90 MainWP_Settings::render_footer( 'CostTrackerSettings' );
91 }
92
93 /**
94 * Render settings content.
95 *
96 * Renders the extension settings page.
97 */
98 public function render_settings_content() { //phpcs:ignore -- NOSONAR - complex.
99
100 $currencies = Cost_Tracker_Utility::get_all_currency_symbols();
101 $selected_currency = Cost_Tracker_Utility::get_instance()->get_option( 'currency', 'USD' );
102 $currency_format = Cost_Tracker_Utility::get_instance()->get_option( 'currency_format', array() );
103
104 if ( ! is_array( $currency_format ) ) {
105 $currency_format = array();
106 }
107
108 $default = Cost_Tracker_Utility::default_currency_settings();
109 $currency_format = array_merge( $default, $currency_format );
110
111 $currency_position = $currency_format['currency_position'];
112 $thousand_separator = $currency_format['thousand_separator'];
113 $decimal_separator = $currency_format['decimal_separator'];
114 $decimals = $currency_format['decimals'];
115
116 $cust_product_types = Cost_Tracker_Utility::get_instance()->get_option( 'custom_product_types', array(), true );
117 $cust_payment_methods = Cost_Tracker_Utility::get_instance()->get_option( 'custom_payment_methods', array(), true );
118
119 $default_product_types = Cost_Tracker_Admin::get_default_product_types();
120 $product_colors = Cost_Tracker_Admin::get_product_colors();
121
122 $product_default_icons = Cost_Tracker_Utility::get_product_default_icons();
123 $product_types_icons = Cost_Tracker_Admin::get_product_type_icons();
124 $product_types_default_icons = Cost_Tracker_Admin::get_default_product_types_icons();
125
126 if ( isset( $_GET['message'] ) && ! empty( $_GET['message'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
127 $message = esc_html__( 'Cost Tracker settings saved successfully.', 'mainwp' );
128 ?>
129 <div class="ui green message" id="mainwp-module-cost-tracker-message-zone" >
130 <?php echo esc_html( $message ); ?>
131 <i class="ui close icon"></i>
132 </div>
133 <?php
134 }
135 ?>
136 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cost-settings" default-indi-value="USD">
137 <label class="six wide column middle aligned">
138 <?php MainWP_Settings_Indicator::render_not_default_indicator( 'cost_tracker_currency_selected', $selected_currency ); ?>
139 <?php esc_html_e( 'Currency', 'mainwp' ); ?></label>
140 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Select preferred currency.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
141 <select id="mainwp_module_cost_tracker_settings_currency" name="mainwp_module_cost_tracker_settings_currency" class="ui search selection dropdown settings-field-value-change-handler" aria-label="<?php esc_attr_e( 'Select preferred currency.', 'mainwp' ); ?>">
142 <?php foreach ( $currencies as $code => $name ) : ?>
143 <?php
144 $_select = '';
145 if ( $code === $selected_currency ) {
146 $_select = ' selected ';
147 }
148 echo '<option value="' . esc_html( $code ) . '" ' . esc_html( $_select ) . '>' . esc_html( $name['symbol'] ) . ' - ' . esc_html( $name['name'] ) . '</option>';
149 ?>
150 <?php endforeach; ?>
151 </select>
152 </div>
153 </div>
154
155 <?php
156 $positions = array(
157 'left' => esc_html__( 'Left', 'mainwp' ),
158 'right' => esc_html__( 'Right', 'mainwp' ),
159 'left_space' => esc_html__( 'Left Space', 'mainwp' ),
160 'right_space' => esc_html__( 'Right Space', 'mainwp' ),
161 );
162
163 $def_val = is_array( $default ) && isset( $default['currency_position'] ) ? $default['currency_position'] : '';
164
165 ?>
166 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cost-settings" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
167 <label class="six wide column middle aligned">
168 <?php
169 MainWP_Settings_Indicator::render_not_default_indicator( 'cost_tracker_currency_position', $currency_position );
170 esc_html_e( 'Currency symbol position', 'mainwp' );
171 ?>
172 </label>
173 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Choose the position of the currency symbol: before or after the amount.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
174 <div class="ui selection dropdown">
175 <input type="hidden" class="settings-field-value-change-handler" aria-label="<?php esc_attr_e( 'Select preferred currency symbol position.', 'mainwp' ); ?>" name="mainwp_module_cost_tracker_currency_format[currency_position]" value="<?php echo esc_attr( $currency_position ); ?>">
176 <i class="dropdown icon"></i>
177 <div class="default text"><?php echo esc_html__( 'Left', 'mainwp' ); ?></div>
178 <div class="menu">
179 <?php
180 foreach ( $positions as $code => $name ) {
181 ?>
182 <div class="item" data-value="<?php echo esc_attr( $code ); ?>"><?php echo esc_html( $name ); ?></div>
183 <?php
184 }
185 ?>
186 </div>
187 </div>
188 </div>
189 </div>
190
191 <?php
192 $def_val = is_array( $default ) && isset( $default['thousand_separator'] ) ? $default['thousand_separator'] : '';
193 ?>
194 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cost-settings" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
195 <label class="six wide column middle aligned">
196 <?php
197 MainWP_Settings_Indicator::render_not_default_indicator( 'cost_tracker_thousand_separator', $thousand_separator );
198 esc_html_e( 'Thousand separator', 'mainwp' );
199 ?>
200 </label>
201 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Select a separator for thousands to enhance number readability.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
202 <input type="text" class="regular-text settings-field-value-change-handler" aria-label="<?php esc_attr_e( 'Select a separator for thousands.', 'mainwp' ); ?>" name="mainwp_module_cost_tracker_currency_format[thousand_separator]" value="<?php echo esc_html( $thousand_separator ); ?>" />
203 </div>
204 </div>
205 <?php
206 $def_val = is_array( $default ) && isset( $default['decimal_separator'] ) ? $default['decimal_separator'] : '';
207 ?>
208 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cost-settings" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
209 <label class="six wide column middle aligned">
210 <?php
211 MainWP_Settings_Indicator::render_not_default_indicator( 'cost_tracker_decimal_separator', $decimal_separator );
212 esc_html_e( 'Decimal separator', 'mainwp' );
213 ?>
214 </label>
215 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Choose a symbol to separate decimal portions in numbers.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
216 <input type="text" aria-label="<?php esc_attr_e( 'Choose a symbol to separate decimal portions in numbers.', 'mainwp' ); ?>" name="mainwp_module_cost_tracker_currency_format[decimal_separator]" value="<?php echo esc_html( $decimal_separator ); ?>" class="settings-field-value-change-handler regular-text"/>
217 </div>
218 </div>
219 <?php
220 $def_val = is_array( $default ) && isset( $default['decimals'] ) ? $default['decimals'] : '';
221 ?>
222 <div class="ui grid field settings-field-indicator-wrapper settings-field-indicator-cost-settings" default-indi-value="<?php echo esc_attr( $def_val ); ?>">
223 <label class="six wide column middle aligned">
224 <?php
225 MainWP_Settings_Indicator::render_not_default_indicator( 'cost_tracker_decimals', intval( $decimals ) );
226 esc_html_e( 'Decimal places', 'mainwp' );
227 ?>
228 </label>
229 <div class="five wide column" data-tooltip="<?php esc_attr_e( 'Set the number of decimal places for numerical values.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
230 <input type="number" aria-label="<?php esc_attr_e( 'Set the number of decimal places for numerical values.', 'mainwp' ); ?>" class="regular-text small-text settings-field-value-change-handler" name="mainwp_module_cost_tracker_currency_format[decimals]" id="mainwp_module_cost_tracker_currency_format[decimals]" placeholder="" min="1" max="8" step="1" value="<?php echo intval( $decimals ); ?>">
231 </div>
232 </div>
233 <div class="ui grid field settings-field-indicator-wrapper default-product-categories settings-field-indicator-cost-settings ">
234 <label class="six wide column middle aligned">
235 <?php
236 $indi_val = $cust_product_types ? 1 : 0;
237 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $indi_val );
238 esc_html_e( 'Default product categories', 'mainwp' );
239 ?>
240 </label>
241 <div class="ui five wide column" data-tooltip="<?php esc_attr_e( 'Customize and create product categories.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
242 <?php
243 if ( is_array( $default_product_types ) ) {
244 foreach ( $default_product_types as $slug => $title ) {
245 ?>
246 <div class="cost-tracker-product-types-item">
247
248 <input type="hidden" value="<?php echo esc_attr( $slug ); ?>" name="cost_tracker_default_product_types[slug][]"/>
249 <input type="hidden" value="<?php echo esc_attr( $title ); ?>" name="cost_tracker_default_product_types[title][]"/>
250
251 <div class="ui left right action input">
252 <div class="cost_tracker_settings_product_categories_icon_wrapper">
253 <?php
254 $selected_default_icon = '';
255 $selected_prod_icon = isset( $product_types_icons[ $slug ] ) ? $product_types_icons[ $slug ] : '';
256 if ( empty( $selected_prod_icon ) && isset( $product_types_default_icons[ $slug ] ) ) {
257 $selected_default_icon = $product_types_default_icons[ $slug ];
258 $selected_prod_icon = 'deficon:' . $selected_default_icon;
259 } elseif ( ! empty( $selected_prod_icon ) && false !== strpos( $selected_prod_icon, 'deficon:' ) ) {
260 $selected_default_icon = str_replace( 'deficon:', '', $selected_prod_icon );
261 }
262 $selected_color = isset( $product_colors[ $slug ] ) ? $product_colors[ $slug ] : '#34424D';
263 $this->render_icons_select( $product_default_icons, $selected_default_icon, $selected_color );
264 ?>
265 <input type="hidden" name="cost_tracker_default_product_types[icon][]" id="cost_tracker_default_product_types[icon][]" value="<?php echo esc_attr( $selected_prod_icon ); ?>" />
266 </div>
267 <input type="text" style="width:200px;border-radius:0px" class="regular-text ui disabled input" readonly="readonly" value="<?php echo esc_attr( $title ); ?>"/>
268 <input type="color" data-tooltip="Color will update on save" data-position="top center" data-inverted="" name="cost_tracker_default_product_types[color][]" class="mainwp-color-picker-input" id="cost_tracker_default_product_types[color][]" value="<?php echo esc_attr( $selected_color ); ?>" />
269 </div>
270 </div>
271 <?php
272 }
273 ?>
274 <?php } ?>
275 </div>
276 </div>
277 <div class="ui grid field">
278 <label class="six wide column middle aligned"></label>
279 <div class="ui five wide column module-cost-tracker-settings-custom-product-types-wrapper">
280 <?php
281 foreach ( $cust_product_types as $slug => $title ) {
282 if ( empty( $slug ) || empty( $title ) ) {
283 continue;
284 }
285 ?>
286 <div class="cost-tracker-product-types-item">
287 <input type="hidden" value="<?php echo esc_attr( $slug ); ?>" name="cost_tracker_custom_product_types[slug][]"/>
288 <div class="ui left right action input">
289 <div style="display:inline-block;" class="cost_tracker_settings_product_categories_icon_wrapper">
290 <?php
291 $selected_default_icon = '';
292 $selected_prod_icon = isset( $product_types_icons[ $slug ] ) ? $product_types_icons[ $slug ] : '';
293 if ( empty( $selected_prod_icon ) ) {
294 $selected_default_icon = Cost_Tracker_Utility::get_product_default_icons( false, 'default_custom_product_type' );
295 $selected_prod_icon = 'deficon:' . $selected_default_icon;
296 } elseif ( ! empty( $selected_prod_icon ) && false !== strpos( $selected_prod_icon, 'deficon:' ) ) {
297 $selected_default_icon = str_replace( 'deficon:', '', $selected_prod_icon );
298 }
299 $selected_color = isset( $product_colors[ $slug ] ) ? $product_colors[ $slug ] : '#34424D';
300 $this->render_icons_select( $product_default_icons, $selected_default_icon, $selected_color, 'mainwp-module-cost-tracker-select-custom-product-types-icons' );
301 ?>
302 <input type="hidden" name="cost_tracker_custom_product_types[icon][]" id="cost_tracker_custom_product_types[icon][]" value="<?php echo esc_attr( $selected_prod_icon ); ?>" />
303 </div>
304 <input type="text" style="width:200px;border-radius:0px" class="regular-text settings-field-value-change-handler" value="<?php echo esc_attr( $title ); ?>" name="cost_tracker_custom_product_types[title][]"/>
305 <input type="color" data-tooltip="Color will update on save" data-position="top center" data-inverted="" name="cost_tracker_custom_product_types[color][]" class="mainwp-color-picker-input" id="cost_tracker_custom_product_types[color][]" value="<?php echo esc_attr( $selected_color ); ?>" />
306 </div>
307 </div>
308 <?php
309 }
310 ?>
311 <div class="ui hidden divider cost-tracker-product-types-bottom"></div>
312 <a href="javascript:void(0);" class="module-cost-tracker-add-custom-product-types" add-custom-product-types-tmpl="<?php echo esc_attr( $this->add_custom_product_types_tmpl( $product_default_icons ) ); ?>"><span class="ui green text "><?php esc_html_e( 'Add new', 'mainwp' ); ?></span></a>
313
314 </div>
315 </div>
316
317 <div class="ui grid field settings-field-indicator-wrapper custom-payment-methods settings-field-indicator-cost-settings">
318 <label class="six wide column middle aligned">
319 <?php
320 MainWP_Settings_Indicator::render_not_default_indicator( 'none_preset_value', $cust_payment_methods );
321 esc_html_e( 'Custom payment methods', 'mainwp' );
322 ?>
323 </label>
324 <div class="ui ten wide column module-cost-tracker-settings-custom-payment-methods-wrapper" data-tooltip="<?php esc_attr_e( 'Create custom payment methods.', 'mainwp' ); ?>" data-inverted="" data-position="left center">
325 <?php
326 foreach ( $cust_payment_methods as $slug => $title ) {
327 if ( empty( $slug ) || empty( $title ) ) {
328 continue;
329 }
330 ?>
331 <div class="ui two columns grid cost-tracker-payment-methods-item">
332 <div class="ui column">
333 <input type="hidden" value="<?php echo esc_attr( $slug ); ?>" name="cost_tracker_custom_payment_methods[slug][]"/>
334 <input type="text" class="regular-text settings-field-value-change-handler" value="<?php echo esc_attr( $title ); ?>" name="cost_tracker_custom_payment_methods[title][]" >
335 </div>
336 </div>
337 <?php
338 }
339 ?>
340 <div class="ui hidden divider cost-tracker-payment-methods-bottom"></div>
341 <a href="javascript:void(0);" class="module-cost-tracker-add-custom-payment-methods" add-custom-payment-methods-tmpl="<?php echo esc_attr( $this->add_custom_payment_methods_tmpl() ); ?>"><span class="ui green text "><?php esc_html_e( 'Add new', 'mainwp' ); ?></span></a>
342 </div>
343 </div>
344
345 <?php do_action( 'mainwp_module_cost_tracker_settings_bottom' ); ?>
346
347 <input type="hidden" name="nonce" value="<?php echo esc_html( wp_create_nonce( 'module_cost_tracker_settings_nonce' ) ); ?>">
348 <input type="hidden" name="mwp_cost_tracker_settings_submit" value="1">
349 <div class="ui divider"></div>
350 <input type="submit" value="<?php esc_html_e( 'Save Settings', 'mainwp' ); ?>" class="ui green big button" id="mainwp-module-cost-tracker-manager-save-settings-button" <?php echo apply_filters( 'mainwp_module_cost_tracker_manager_check_status', false ) ? 'disabled' : ''; ?>>
351 <script type="text/javascript">
352 jQuery( document ).ready( function() {
353 jQuery( '.mainwp-module-cost-tracker-select-default-icons' ).dropdown( {
354 onChange: function( val ) {
355 let parent = jQuery( this ).closest('.cost_tracker_settings_product_categories_icon_wrapper');
356 jQuery(parent).find('input[name="cost_tracker_default_product_types[icon][]"]' ).val('deficon:' + val);
357 }
358 } );
359
360 jQuery( '.mainwp-module-cost-tracker-select-custom-product-types-icons' ).dropdown( {
361 onChange: function( val ) {
362 let parent = jQuery( this ).closest('.cost_tracker_settings_product_categories_icon_wrapper');
363 jQuery(parent).find('input[name="cost_tracker_custom_product_types[icon][]"]' ).val('deficon:' + val);
364 }
365 } );
366 } );
367 </script>
368 <?php
369 }
370
371 /**
372 * Method render_icons_select().
373 *
374 * @param array $default_icons default icons.
375 * @param string $selected_def_icon selected default icon.
376 * @param string $icon_color icon color.
377 * @param string $select_img_cls icon class.
378 */
379 public function render_icons_select( $default_icons, $selected_def_icon = '', $icon_color = '', $select_img_cls = 'mainwp-module-cost-tracker-select-default-icons' ) {
380 $color_style = ! empty( $icon_color ) ? ' style="color:' . esc_attr( $icon_color ) . '" ' : '';
381 ?>
382 <div class="ui four column selection search dropdown not-auto-init <?php echo esc_attr( $select_img_cls ); ?>" style="min-width:160px;">
383 <div class="text">
384 <?php echo empty( $selected_def_icon ) ? esc_html_e( 'Select icon', 'mainwp' ) : '<i class="' . esc_attr( $selected_def_icon ) . ' icon card" ' . $color_style . ' ></i>'; //phpcs:ignore -- ok. ?>
385 </div>
386 <i class="dropdown icon"></i>
387 <div class="menu">
388 <?php foreach ( $default_icons as $icon ) : ?>
389 <?php echo '<div class="item" data-value="' . esc_attr( $icon ) . '"><i class="' . esc_attr( $icon ) . ' icon card" ' . $color_style . '></i></div>'; //phpcs:ignore -- ok. ?>
390 <?php endforeach; ?>
391 </div>
392 </div>
393 <?php
394 }
395
396 /**
397 * Method add_custom_product_types_tmpl().
398 *
399 * @param array $product_default_icons default icons.
400 */
401 public function add_custom_product_types_tmpl( $product_default_icons ) {
402 ob_start();
403 ?>
404 <div class="cost-tracker-product-types-item ui left right action input">
405 <input type="hidden" value="" name="cost_tracker_custom_product_types[slug][]"/>
406 <div style="display:inline-block;" class="cost_tracker_settings_product_categories_icon_wrapper">
407 <?php
408 $selected_default_icon = Cost_Tracker_Utility::get_product_default_icons( false, 'default_custom_product_type' );
409 $selected_prod_icon = 'deficon:' . $selected_default_icon;
410 $default_color = '#34424D';
411 $this->render_icons_select( $product_default_icons, $selected_default_icon, $default_color, 'mainwp-module-cost-tracker-select-custom-product-types-icons' );
412 ?>
413 <input type="hidden" name="cost_tracker_custom_product_types[icon][]" id="cost_tracker_custom_product_types[icon][]" value="<?php echo esc_attr( $selected_prod_icon ); ?>" />
414 </div>
415 <input type="text" style="width:200px;border-radius:0px" class="regular-text settings-field-value-change-handler" value="" name="cost_tracker_custom_product_types[title][]"/>
416 <input type="color" data-tooltip="Color will update on save" data-position="top center" data-inverted="" name="cost_tracker_custom_product_types[color][]" class="mainwp-color-picker-input" id="cost_tracker_custom_product_types[color][]" value="#ad0000" />
417 </div>
418 <?php
419 return ob_get_clean();
420 }
421
422 /**
423 * Method add_custom_payment_methods_tmpl().
424 */
425 public function add_custom_payment_methods_tmpl() {
426 ob_start();
427 ?>
428 <div class="ui two columns grid cost-tracker-payment-methods-item">
429 <div class="ui column">
430 <input type="hidden" value="" name="cost_tracker_custom_payment_methods[slug][]"/>
431 <input type="text" class="regular-text settings-field-value-change-handler" value="" placeholder="<?php esc_attr_e( 'Title', 'mainwp' ); ?>" name="cost_tracker_custom_payment_methods[title][]"/>
432 </div>
433 </div>
434 <?php
435 return ob_get_clean();
436 }
437 }
438