PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.3.13
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.3.13
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 / settings / integration.php

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

194 lines 7.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use WeDevs\ERP\Framework\ERP_Settings_Page;
4
5 /**
6 * Integration class
7 */
8 class ERP_Integration_Settings extends ERP_Settings_Page {
9 /**
10 * Class constructor
11 */
12 function __construct() {
13 $this->id = 'erp-integration';
14 $this->label = __( 'Integrations', 'erp' );
15
16 add_action( 'erp_admin_field_integrations', [ $this, 'integrations' ] );
17 }
18
19 /**
20 * Get settings array.
21 *
22 * @return array
23 */
24 public function get_settings() {
25 $fields = [
26 [
27 'title' => __( 'Integrations', 'erp' ),
28 'desc' => __( 'Various integrations to WP ERP. Click <strong>Configure</strong> to manage the settings.', 'erp' ),
29 'type' => 'title',
30 'id' => 'integration_settings'
31 ],
32
33 [ 'type' => 'integrations' ],
34 [ 'type' => 'sectionend', 'id' => 'script_styling_options' ],
35
36 ]; // End general settings
37
38 return apply_filters( 'erp_integration_settings', $fields );
39 }
40
41 /**
42 * Display integrations settings.
43 *
44 * @return void
45 */
46 function integrations() {
47 $integrations = wperp()->integration->get_integrations();
48 ?>
49 <tr valign="top">
50 <td class="erp-settings-table-wrapper" colspan="2">
51 <table class="erp-settings-table widefat" cellspacing="0">
52 <thead>
53 <tr>
54 <?php
55 $columns = apply_filters( 'erp_integration_setting_columns', array(
56 'name' => __( 'Integration', 'erp' ),
57 'description' => __( 'Description', 'erp' ),
58 'actions' => ''
59 ) );
60
61 foreach ( $columns as $key => $column ) {
62 echo '<th class="erp-settings-table-' . esc_attr( $key ) . '">' . esc_html( $column ) . '</th>';
63 }
64 ?>
65 </tr>
66 </thead>
67 <tbody>
68 <?php
69 foreach ( $integrations as $integration_key => $integration ) {
70 echo '<tr>';
71
72 foreach ( $columns as $key => $column ) {
73 switch ( $key ) {
74 case 'name' :
75 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
76 <a href="' . admin_url( 'admin.php?page=erp-settings&tab=erp-integration&section=' . strtolower( $integration_key ) ) . '">' . $integration->get_title() . '</a>
77 </td>';
78 break;
79
80 case 'status':
81 case 'module':
82 case 'recipient':
83 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
84
85 </td>';
86 break;
87
88 case 'description':
89 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
90 <span class="help">' . $integration->get_description() . '</span>
91 </td>';
92 break;
93
94 case 'actions' :
95 echo '<td class="erp-settings-table-' . esc_attr( $key ) . '">
96 <a class="button alignright" href="' . admin_url( 'admin.php?page=erp-settings&tab=erp-integration&section=' . strtolower( $integration_key ) ) . '">' . __( 'Configure', 'erp' ) . '</a>
97 </td>';
98 break;
99
100 default :
101 do_action( 'erp_integration_setting_column_' . $key, $integration );
102 break;
103 }
104 }
105 }
106 ?>
107 </tbody>
108 </table>
109 </td>
110 </tr>
111
112 <style>p.submit { display: none; }</style>
113 <?php
114 }
115
116 /**
117 * Output the settings.
118 *
119 * @param boolean $section (optional)
120 *
121 * @return void
122 */
123 public function output( $section = false ) {
124 $current_section = isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : false;
125
126 // Define integrations that can be customised here
127 $integrations = wperp()->integration->get_integrations();
128
129 if ( $current_section ) {
130 foreach ( $integrations as $integration_key => $integration ) {
131 if ( strtolower( $integration_key ) == $current_section ) {
132 $integration->admin_options();
133 break;
134 }
135 }
136 } else {
137 parent::output();
138 }
139 }
140
141 /**
142 * Save the settings.
143 *
144 * @param boolean $section (optional)
145 *
146 * @return void
147 */
148 function save( $section = false ) {
149 if ( isset( $_POST['_wpnonce']) && wp_verify_nonce( $_POST['_wpnonce'], 'erp-settings-nonce' ) ) {
150 $current_section = isset( $_GET['section'] ) ? sanitize_key( $_GET['section'] ) : false;
151
152 // saving individual integration settings
153 if ( $current_section ) {
154 $integrations = wperp()->integration->get_integrations();
155
156 foreach ( $integrations as $integration_key => $integration ) {
157 if ( strtolower( $integration_key ) == $current_section ) {
158
159 $settings = $integration->get_form_fields();
160 $update_options = array();
161
162 if ( $settings) {
163 foreach ($settings as $field) {
164 if ( ! isset( $field['id'] ) || ! isset( $_POST[ $field['id'] ] ) ) {
165 continue;
166 }
167
168 $option_value = $this->parse_option_value( $field );
169
170 if ( ! is_null( $option_value ) ) {
171 $update_options[ $field['id'] ] = $option_value;
172 }
173 }
174 }
175
176 do_action( $integration->get_option_id() . '_action', $update_options );
177
178 $update_options = apply_filters( $integration->get_option_id() . '_filter', $update_options );
179
180 update_option( $integration->get_option_id(), $update_options );
181
182 break;
183 }
184 }
185
186 } else {
187 parent::save();
188 }
189 }
190 }
191 }
192
193 return new ERP_Integration_Settings();
194