PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.2.6
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.2.6
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / framework / class-settings.php

class-settings.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.2.6, at includes/framework/class-settings.php

183 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WeDevs\ERP\Framework;
4
5 /**
6 * ERP Admin settings class
7 */
8 class ERP_Admin_Settings {
9
10 private static $settings = array();
11 private static $section = array();
12
13 /**
14 * Include all settings file
15 *
16 * @since 0.1
17 *
18 * @return array
19 */
20 public static function get_settings() {
21
22 if ( !self::$settings ) {
23 $settings = array();
24
25 $settings[] = include __DIR__ . '/settings/general.php';
26 $settings[] = include __DIR__ . '/settings/email.php';
27
28 $settings = apply_filters( 'erp_settings_pages', $settings );
29
30 // Display integrations tab only if any integration exist.
31 $integrations = wperp()->integration->get_integrations();
32 if ( ! empty( $integrations ) ) {
33 $settings[] = include __DIR__ . '/settings/integration.php';
34 }
35
36 $licenses = erp_addon_licenses();
37 if ( $licenses ) {
38 $settings[] = include __DIR__ . '/settings/license.php';
39 }
40
41 self::$settings = $settings;
42 }
43
44 return self::$settings;
45 }
46
47 /**
48 * Get current tab and subtab/section
49 *
50 * @since 0.1
51 *
52 * @return array()
53 */
54 public static function get_current_tab_and_section() {
55
56 $settings = self::get_settings();
57 $query_arg = array( 'tab' => false, 'subtab' => false );
58
59 if ( ! isset( $settings[0] ) ) {
60 return $query_arg;
61 }
62
63 $default = $settings[0]->get_id();
64
65 if ( empty( $default ) ) {
66 return $query_arg;
67 }
68
69 $current_tab = $query_arg['tab'] = isset( $_GET['tab'] ) ? sanitize_title( $_GET['tab'] ) : $settings[0]->get_id();
70
71 foreach ( $settings as $obj ) {
72 $sections[$obj->get_id()] = isset( $obj->sections ) ? $obj->sections : array();
73 }
74
75 if ( ! isset( $sections[$current_tab] ) ) {
76 return $query_arg;
77 }
78
79 if ( ! is_array( $sections[$current_tab] ) ) {
80 return $query_arg;
81 }
82
83 if ( ! count( $sections[$current_tab] ) ) {
84 return $query_arg;
85 }
86
87 $query_arg['subtab'] = isset( $_GET['section'] ) ? sanitize_title( $_GET['section'] ) : key( $sections[$current_tab] );
88
89 return $query_arg;
90 }
91
92 /**
93 * Show settings all tab and subtab fields
94 *
95 * @since 0.1
96 *
97 * @return void
98 */
99 public static function output() {
100 global $current_section, $current_tab, $current_class;
101
102 $settings = self::get_settings();
103 $query_arg = self::get_current_tab_and_section();
104 $current_tab = $query_arg['tab'];
105 $current_section = $query_arg['subtab'];
106 $sections = [];
107
108 if ( ! $settings ) {
109 return;
110 }
111
112 echo '<h2 class="nav-tab-wrapper erp-nav-tab-wrapper">';
113
114 foreach ( $settings as $obj ) {
115
116 $url = sprintf('admin.php?page=erp-settings&tab=%s', $obj->get_id() );
117 $class = ( $current_tab == $obj->get_id() ) ? ' nav-tab-active' : '';
118 if ( $current_tab == $obj->get_id() && $current_class === null ) {
119 $current_class = $obj;
120 }
121
122 printf('<a class="nav-tab%s" href="%s">%s</a>', $class, $url, $obj->get_label() );
123 }
124
125 echo '</h2>';
126
127 self::section_output();
128
129 $current_class->save( $current_section );
130 $current_class->output( $current_section );
131
132 }
133
134 /**
135 * Show settings subtab fields
136 *
137 * @since 0.1
138 *
139 * @return void
140 */
141 public static function section_output() {
142 $settings = self::get_settings();
143 $query_arg = self::get_current_tab_and_section();
144 $current_tab = $query_arg['tab'];
145 $current_section = $query_arg['subtab'];
146 $sections = [];
147
148 if ( ! $current_section ) {
149 return;
150 }
151
152 foreach ( $settings as $obj ) {
153 $sections[$obj->get_id()] = isset( $obj->sections ) ? $obj->sections : array();
154 }
155
156 $tab_sections = $sections[$current_tab];
157
158 // don't print sub-sections if only one section available
159 if ( count( $tab_sections ) < 1 ) {
160 return;
161 }
162
163 if ( ! array_key_exists( $current_section, $tab_sections ) ) {
164 return;
165 }
166
167 echo '<ul class="erp-subsubsub">';
168
169 echo '<li>';
170 foreach ( $tab_sections as $slug => $label ) {
171 $url = 'admin.php?page=erp-settings&tab='.$current_tab.'&section='.$slug;
172 $class = ( $current_section == $slug ) ? ' erp-nav-tab-active' : '';
173 $link[] = '<a class="erp-nav-tab'.$class.'" href="'.$url.'">' . $label . '</a>';
174 }
175
176 echo implode( ' | </li><li>', $link );
177 echo '</li>';
178
179 echo '</ul>';
180
181 }
182 }
183