PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.79
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.79
5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 5.5.43 All 159 releases
wp-data-access / WPDataProjects / Project / WPDP_Project_Table_Form.php

WPDP_Project_Table_Form.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.79, at WPDataProjects/Project/WPDP_Project_Table_Form.php

1,996 lines 71.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
5 *
6 * @package WPDataProjects\Project
7 */
8 // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing -- verified in function is_authorized
9 namespace WPDataProjects\Project;
10
11 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Exist;
12 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
13 use WPDataAccess\Plugin_Table_Models\WPDA_Table_Settings_Model;
14 use WPDataAccess\WPDA;
15 use WPDataProjects\Data_Dictionary\WPDP_List_Columns_Cache;
16 use WPDataAccess\Utilities\WPDA_Message_Box;
17 use WPDataAccess\Plugin_Table_Models\WPDP_Project_Design_Table_Model;
18 use WPDataAccess\Utilities\WPDA_Reverse_Engineering;
19 use WPDataProjects\WPDP;
20 use WPDataAccess\Dashboard\WPDA_Dashboard;
21 /**
22 * Class WPDP_Project_Table_Form
23 *
24 * @author Peter Schulz
25 * @since 2.0.0
26 */
27 class WPDP_Project_Table_Form {
28 /**
29 * Menu slug
30 *
31 * @var string
32 */
33 protected $page = null;
34
35 /**
36 * Database schema name
37 *
38 * @var string
39 */
40 protected $wpda_schema_name = '';
41
42 /**
43 * Database schema name (as saved in column wpda_schema_name)
44 *
45 * Used to allow older versions of the plugin to have an empty schema name stored in column wpda_schema_name.
46 *
47 * @var string
48 */
49 protected $wpda_schema_name_db = '';
50
51 /**
52 * Database table name
53 *
54 * @var string
55 */
56 protected $wpda_table_name = null;
57
58 /**
59 * Options set name
60 *
61 * @var string
62 */
63 protected $wpda_table_setname = null;
64
65 /**
66 * Database table structure
67 *
68 * @var array|null
69 */
70 protected $table_structure = null;
71
72 /**
73 * Handle to instance of class WPDA_Dictionary_Exist
74 *
75 * @var object|null
76 */
77 protected $wpda_data_dictionary = null;
78
79 /**
80 * Handle to instance of class WPDP_List_Columns
81 *
82 * @var object|null
83 */
84 protected $wpda_list_columns = null;
85
86 /**
87 * Requested action
88 *
89 * @var string
90 */
91 protected $action = null;
92
93 /**
94 * Requested action2
95 *
96 * @var string
97 */
98 protected $action2 = null;
99
100 /**
101 * Indicate whether the table has a primary key
102 *
103 * @var boolean|null
104 */
105 protected $has_primary_key = null;
106
107 /**
108 * Available tabs
109 *
110 * @var array
111 */
112 protected $tabs;
113
114 /**
115 * Current tab
116 *
117 * @var
118 */
119 protected $current_tab;
120
121 const WPNONCE_SEED = 'wpda-data-templates-';
122
123 protected $wpnonce;
124
125 protected $wpnonce_requested = null;
126
127 /**
128 * Table design (taken from WPDA_Design_Table_Model)
129 *
130 * @var array|null
131 */
132 protected $wpda_table_design = null;
133
134 /**
135 * WPDP_Project_Table_Form constructor
136 */
137 public function __construct() {
138 global $wpdb;
139 if ( isset( $_REQUEST['page'] ) ) {
140 $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) );
141 // input var okay.
142 } else {
143 wp_die( esc_attr__( 'ERROR: Wrong arguments [missing page]', 'wp-data-access' ) );
144 }
145 if ( isset( $_REQUEST['action'] ) ) {
146 $this->action = sanitize_text_field( wp_unslash( $_REQUEST['action'] ) );
147 }
148 if ( isset( $_REQUEST['action2'] ) ) {
149 $this->action2 = sanitize_text_field( wp_unslash( $_REQUEST['action2'] ) );
150 }
151 $this->tabs = array(
152 'tableinfo' => __( 'Table Settings', 'wp-data-access' ),
153 'relation' => __( 'Relationships', 'wp-data-access' ),
154 'listtable' => __( 'List Table', 'wp-data-access' ),
155 'tableform' => __( 'Data Entry', 'wp-data-access' ),
156 'reconcile' => __( 'Reconcile', 'wp-data-access' ),
157 );
158 $this->current_tab = 'tableinfo';
159 if ( isset( $_REQUEST['tab'] ) ) {
160 $tab = sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) );
161 if ( isset( $this->tabs[$tab] ) ) {
162 $this->current_tab = $tab;
163 }
164 }
165 $this->wpnonce_requested = ( isset( $_POST['wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wpnonce'] ) ) : null );
166 if ( isset( $_REQUEST['wpda_table_name'] ) && !is_array( $_REQUEST['wpda_table_name'] ) ) {
167 $wpda_project_design_table_model = new WPDP_Project_Design_Table_Model();
168 if ( 'reconcile' === $this->action ) {
169 $wpda_table_name_re = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) );
170 $this->is_authorized( $wpda_table_name_re );
171 $wpda_schema_name_re = ( isset( $_REQUEST['wpda_schema_name'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_schema_name'] ) ) : '' );
172 $wpda_reverse_engineering = new WPDA_Reverse_Engineering($wpda_table_name_re, $wpda_schema_name_re);
173 $table_structure = $wpda_reverse_engineering->get_designer_format( 'advanced' );
174 if ( isset( $_REQUEST['keep_options'] ) ) {
175 $param_keep_options = sanitize_text_field( wp_unslash( $_REQUEST['keep_options'] ) );
176 } else {
177 $param_keep_options = 'off';
178 }
179 $result_update = $wpda_project_design_table_model->reconcile( $table_structure, $param_keep_options );
180 if ( false === $result_update ) {
181 $msg = new WPDA_Message_Box(array(
182 'message_text' => __( 'Update failed', 'wp-data-access' ),
183 'message_type' => 'error',
184 'message_is_dismissible' => false,
185 ));
186 $msg->box();
187 }
188 if ( 0 === $result_update ) {
189 $msg = new WPDA_Message_Box(array(
190 'message_text' => __( 'Nothing to save', 'wp-data-access' ),
191 ));
192 $msg->box();
193 } else {
194 $msg = new WPDA_Message_Box(array(
195 'message_text' => __( 'Succesfully saved changes to database', 'wp-data-access' ),
196 ));
197 $msg->box();
198 }
199 } elseif ( 'reverse_engineering' === $this->action ) {
200 if ( isset( $_REQUEST['wpda_table_name'] ) ) {
201 $wpda_table_name_re = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) );
202 $this->is_authorized( WPDP_Project_Design_Table_Model::get_base_table_name() );
203 $wpda_schema_name_re = ( isset( $_REQUEST['wpda_schema_name'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_schema_name'] ) ) : '' );
204 $wpda_reverse_engineering = new WPDA_Reverse_Engineering($wpda_table_name_re, $wpda_schema_name_re);
205 $table_structure = $wpda_reverse_engineering->get_designer_format( 'advanced' );
206 if ( count( $table_structure ) > 0 ) {
207 // phpcs:ignore -- 8.1 proof
208 $this->wpda_schema_name = $wpda_schema_name_re;
209 $this->wpda_table_name = $wpda_table_name_re;
210 $this->get_unique_setname();
211 $this->wpda_table_design = $table_structure;
212 } else {
213 wp_die( esc_attr__( 'ERROR: Reverse engineering table failed [invalid structure]', 'wp-data-access' ) );
214 }
215 if ( !WPDP_Project_Design_Table_Model::insert_reverse_engineered(
216 $this->wpda_table_name,
217 $this->wpda_table_setname,
218 $this->wpda_table_design,
219 $this->wpda_schema_name
220 ) ) {
221 $db_error = ( '' === $wpdb->last_error ? '' : ' [' . $wpdb->last_error . ']' );
222 wp_die( esc_attr__( 'ERROR: Reverse engineering table failed', 'wp-data-access' ) . esc_html( $db_error ) );
223 } else {
224 // Convert named array to object (needed to display structure).
225 $this->wpda_table_design = json_decode( json_encode( $table_structure ) );
226 $wpda_project_design_table_model->prepare_query( $this->wpda_table_setname );
227 }
228 $this->action2 = 'edit';
229 $msg = new WPDA_Message_Box(array(
230 'message_text' => __( 'Table added to respository', 'wp-data-access' ),
231 ));
232 $msg->box();
233 } else {
234 wp_die( esc_attr__( 'ERROR: Wrong arguments', 'wp-data-access' ) );
235 }
236 } elseif ( null !== $this->action2 ) {
237 // Check authorization
238 $table_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) );
239 $this->is_authorized( $table_name );
240 $result_update = $wpda_project_design_table_model->update();
241 if ( false === $result_update ) {
242 $msg = new WPDA_Message_Box(array(
243 'message_text' => __( 'Update failed', 'wp-data-access' ),
244 'message_type' => 'error',
245 'message_is_dismissible' => false,
246 ));
247 $msg->box();
248 } else {
249 if ( 0 === $result_update ) {
250 $msg = new WPDA_Message_Box(array(
251 'message_text' => __( 'Nothing to save', 'wp-data-access' ),
252 ));
253 $msg->box();
254 } else {
255 $msg = new WPDA_Message_Box(array(
256 'message_text' => __( 'Successfully saved changes to database', 'wp-data-access' ),
257 ));
258 $msg->box();
259 }
260 }
261 }
262 $wpda_project_design_table_model->query();
263 $structure_messages = $wpda_project_design_table_model->validate();
264 foreach ( $structure_messages as $messages ) {
265 if ( 'ERR' === $messages[0] ) {
266 $msg = new WPDA_Message_Box(array(
267 'message_text' => $messages[1],
268 'message_type' => 'error',
269 'message_is_dismissible' => false,
270 ));
271 $msg->box();
272 } else {
273 $msg = new WPDA_Message_Box(array(
274 'message_text' => $messages[1],
275 ));
276 $msg->box();
277 }
278 }
279 $this->table_structure = $wpda_project_design_table_model->get_table_design();
280 $this->wpda_table_setname = $wpda_project_design_table_model->get_table_setname();
281 $this->wpda_schema_name = ( isset( $_REQUEST['wpda_schema_name'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpda_schema_name'] ) ) : '' );
282 $this->wpda_schema_name_db = $this->wpda_schema_name;
283 if ( '' === $this->wpda_schema_name ) {
284 $this->wpda_schema_name = $wpdb->dbname;
285 }
286 $this->wpda_table_name = sanitize_text_field( wp_unslash( $_REQUEST['wpda_table_name'] ) );
287 $this->wpda_data_dictionary = new WPDA_Dictionary_Exist($this->wpda_schema_name, $this->wpda_table_name);
288 if ( $this->wpda_data_dictionary->table_exists() ) {
289 $this->wpda_list_columns = WPDP_List_Columns_Cache::get_list_columns(
290 $this->wpda_schema_name,
291 $this->wpda_table_name,
292 'tableform',
293 $this->wpda_table_setname
294 );
295 if ( 0 === count( $this->wpda_list_columns->get_table_primary_key() ) ) {
296 // phpcs:ignore -- 8.1 proof
297 $this->has_primary_key = false;
298 } else {
299 $this->has_primary_key = true;
300 }
301 } else {
302 wp_die( esc_attr__( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) );
303 }
304 } else {
305 wp_die( esc_attr__( 'ERROR: Argument wpda_table_name not found', 'wp-data-access' ) );
306 }
307 $this->wpnonce = wp_create_nonce( self::WPNONCE_SEED . $this->wpda_table_name );
308 }
309
310 public function prepare_form() {
311 }
312
313 protected function is_authorized( $table_name ) {
314 if ( !wp_verify_nonce( $this->wpnonce_requested, self::WPNONCE_SEED . $table_name ) ) {
315 wp_die( esc_attr__( 'ERROR: Not authorized', 'wp-data-access' ) );
316 }
317 }
318
319 /**
320 * Create a unique setname for this table
321 */
322 public function get_unique_setname() {
323 $this->wpda_table_setname = 'default';
324 // Default for first options set
325 global $wpdb;
326 $query = "select 'x' from `%1s` where wpda_table_name = %s";
327 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL -- plugin table
328 $wpdb->get_results( $wpdb->prepare(
329 $query,
330 // phpcs:ignore WordPress.DB.PreparedSQL
331 array(WPDA::remove_backticks( WPDP_Project_Design_Table_Model::get_base_table_name() ), $this->wpda_table_name)
332 ) );
333 if ( $wpdb->num_rows > 0 ) {
334 $query = "select 'x' from `%1s` where wpda_schema_name = %s and wpda_table_name = %s and wpda_table_setname = %s";
335 $i = $wpdb->num_rows + 1;
336 $this->wpda_table_setname = "options_set_{$i}";
337 $wpdb->get_results( $wpdb->prepare( $query, array(
338 WPDA::remove_backticks( WPDP_Project_Design_Table_Model::get_base_table_name() ),
339 $this->wpda_schema_name,
340 $this->wpda_table_name,
341 $this->wpda_table_setname
342 ) ) );
343 while ( $wpdb->num_rows > 0 ) {
344 // Search until a free options set is found
345 $this->wpda_table_setname = "options_set_{$i}";
346 $wpdb->get_results( $wpdb->prepare( $query, array(
347 WPDA::remove_backticks( WPDP_Project_Design_Table_Model::get_base_table_name() ),
348 $this->wpda_schema_name,
349 $this->wpda_table_name,
350 $this->wpda_table_setname
351 ) ) );
352 $i++;
353 }
354 }
355 // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL
356 }
357
358 /**
359 * Adds tabs to page
360 */
361 protected function add_tabs() {
362 ?>
363 <div style="display:none">
364 <?php
365 foreach ( $this->tabs as $tab => $name ) {
366 $form_id = esc_attr( $tab ) . '_form_id';
367 $page = esc_attr( WPDP::PAGE_TEMPLATES );
368 $schema_name = esc_attr( $this->wpda_schema_name_db );
369 $table_name = esc_attr( $this->wpda_table_name );
370 $set_name = esc_attr( $this->wpda_table_setname );
371 $tab_value = esc_attr( $tab );
372 $tab_form = "\n\t\t\t\t\t\t<form id='{$form_id}' method='post' action='?page={$page}&tab={$tab_value}'>\n\t\t\t\t\t\t\t<input type='hidden' name='wpda_schema_name' value='{$schema_name}'/>\n\t\t\t\t\t\t\t<input type='hidden' name='wpda_table_name' value='{$table_name}'/>\n\t\t\t\t\t\t\t<input type='hidden' name='wpda_table_setname' value='{$set_name}'/>\n\t\t\t\t\t\t\t<input type='hidden' name='wpda_table_setname_old' value='{$set_name}'/>\n\t\t\t\t\t\t\t<input type='hidden' name='action' value='edit'/>\n\t\t\t\t\t\t</form>\n\t\t\t\t\t";
373 // phpcs:disable WordPress.Security.EscapeOutput
374 echo $tab_form;
375 // phpcs:enable WordPress.Security.EscapeOutput
376 }
377 ?>
378 </div>
379 <h2 class="nav-tab-wrapper">
380 <?php
381 foreach ( $this->tabs as $tab => $name ) {
382 $class = ( $tab === $this->current_tab ? ' nav-tab-active' : '' );
383 echo '<a class="nav-tab' . esc_attr( $class ) . '"' . ' href="javascript:void(0)"' . ' onclick="submit_form(\'' . esc_attr( $tab ) . '_form_id\')"' . '>' . esc_attr( $name ) . '</a>';
384 }
385 ?>
386 </h2>
387 <div class="wpdp-spacer"></div>
388 <?php
389 }
390
391 /**
392 * Show page
393 */
394 public function show() {
395 ?>
396 <div class="wrap">
397 <?php
398 $this->show_title();
399 $this->add_tabs();
400 switch ( $this->current_tab ) {
401 case 'tableinfo':
402 $this->show_table_info();
403 break;
404 case 'relation':
405 if ( true === $this->has_primary_key ) {
406 $this->show_relations();
407 } else {
408 $this->show_view();
409 }
410 break;
411 case 'listtable':
412 $this->show_list_table();
413 break;
414 case 'tableform':
415 if ( true === $this->has_primary_key ) {
416 $this->show_table_form();
417 } else {
418 $this->show_view();
419 }
420 break;
421 case 'reconcile':
422 $this->show_reconcile();
423 break;
424 }
425 ?>
426 </div>
427 <script type='text/javascript'>
428 function submit_form(form_id) {
429 if (wpda_columns_updated===true) {
430 if (confirm("Your changes will not be saved! Continue?")) {
431 jQuery('#' + form_id).submit();
432 }
433 } else {
434 jQuery('#' + form_id).submit();
435 }
436 }
437 jQuery(function () {
438 jQuery('#wpda_table_structure').sortable();
439 jQuery('#wpda_list_table_options').sortable();
440 jQuery('#wpda_form_options').sortable();
441 jQuery('.wpda_tooltip').tooltip();
442 });
443 </script>
444 <?php
445 if ( 'view' === $this->action ) {
446 // Set all forms to read only
447 ?>
448 <script type='text/javascript'>
449 jQuery(function () {
450 jQuery("input").attr("disabled", true);
451 jQuery("select").attr("disabled", true);
452 });
453 </script>
454 <?php
455 } else {
456 // Keep track of changes
457 ?>
458 <script type='text/javascript'>
459 var wpda_columns_updated = false;
460 jQuery(function () {
461 jQuery("input").on("change", function() { wpda_columns_updated = true; });
462 jQuery("select").on("change", function() { wpda_columns_updated = true; });
463 });
464 </script>
465 <?php
466 }
467 }
468
469 protected function show_title() {
470 $title = 'Project Templates';
471 ?>
472 <h1 class="wp-heading-inline">
473 <a
474 href="?page=<?php
475 echo esc_attr( $this->page );
476 ?>"
477 class="dashicons dashicons-arrow-left-alt2"
478 title="<?php
479 esc_html_e( 'Template list', 'wp-data-access' );
480 ?>"
481 ></a>
482 <?php
483 echo esc_attr( $title );
484 ?>
485 </h1>
486 <?php
487 }
488
489 protected function show_view() {
490 ?>
491 <div class="wpdp-spacer"></div>
492 <div>
493 <fieldset class="wpda_fieldset wpdp_fieldset">
494 <strong>
495 Sorry, this feature is only available for tables containing a primary or unique key.
496 </strong>
497 </fieldset>
498 </div>
499 <?php
500 }
501
502 /**
503 * Show table info
504 */
505 protected function show_table_info() {
506 global $wpdb;
507 if ( '' === $this->wpda_schema_name || $wpdb->dbname === $this->wpda_schema_name ) {
508 $wpda_table_name = $this->wpda_table_name;
509 } else {
510 $wpda_table_name = $this->wpda_table_name . ' (' . $this->wpda_schema_name . ')';
511 }
512 $tab_label = ( isset( $this->table_structure->tableinfo->tab_label ) ? $this->table_structure->tableinfo->tab_label : '' );
513 $default_where = ( isset( $this->table_structure->tableinfo->default_where ) ? $this->table_structure->tableinfo->default_where : '' );
514 $default_orderby = ( isset( $this->table_structure->tableinfo->default_orderby ) ? $this->table_structure->tableinfo->default_orderby : '' );
515 $hyperlinks_parent = ( isset( $this->table_structure->tableinfo->hyperlinks_parent ) ? $this->table_structure->tableinfo->hyperlinks_parent : array() );
516 $hyperlinks_child = ( isset( $this->table_structure->tableinfo->hyperlinks_child ) ? $this->table_structure->tableinfo->hyperlinks_child : array() );
517 $html = '';
518 $html_child = '';
519 $settings_db = WPDA_Table_Settings_Model::query( $this->wpda_table_name, $this->wpda_schema_name );
520 if ( isset( $settings_db[0]['wpda_table_settings'] ) && '' !== $settings_db[0]['wpda_table_settings'] ) {
521 $settings = json_decode( $settings_db[0]['wpda_table_settings'] );
522 if ( isset( $settings->hyperlinks ) && is_array( $settings->hyperlinks ) ) {
523 foreach ( $settings->hyperlinks as $hyperlink ) {
524 if ( isset( $hyperlink->hyperlink_label ) ) {
525 $hyperlink_label = $hyperlink->hyperlink_label;
526 if ( isset( $hyperlinks_parent->{$hyperlink_label} ) ) {
527 $checked = ( $hyperlinks_parent->{$hyperlink_label} ? 'checked' : '' );
528 } else {
529 $checked = '';
530 }
531 $html .= "<label style='padding-right: 10px;'>\n\t\t\t\t\t\t\t\t\t<input type='checkbox' name='{$hyperlink_label}_hyperlink' style='width: 16px; height: 16px;' {$checked}/>\n\t\t\t\t\t\t\t\t\t{$hyperlink_label}\n\t\t\t\t\t\t\t\t</label>";
532 if ( isset( $hyperlinks_child->{$hyperlink_label} ) ) {
533 $checked = ( $hyperlinks_child->{$hyperlink_label} ? 'checked' : '' );
534 } else {
535 $checked = '';
536 }
537 $html_child .= "<label style='padding-right: 10px;'>\n\t\t\t\t\t\t\t\t\t<input type='checkbox' name='{$hyperlink_label}_hyperlink_child' style='width: 16px; height: 16px;' {$checked}/>\n\t\t\t\t\t\t\t\t\t{$hyperlink_label}\n\t\t\t\t\t\t\t\t</label>";
538 }
539 }
540 }
541 }
542 if ( '' === $html && '' === $html_child ) {
543 $hint = 'Hyperlinks';
544 } else {
545 $hint = __( 'Hyperlinks - uncheck to disable', 'wp-data-access' ) . ' <span class="dashicons dashicons-editor-help wpda_tooltip" title="Use table settings to define where hyperlinks are shown."></span>';
546 }
547 if ( '' === $html ) {
548 $html = '--';
549 }
550 if ( '' === $html_child ) {
551 $html_child = '--';
552 }
553 ?>
554 <form id="wpdp_form_table_info" method="post">
555
556 <fieldset class="wpda_fieldset wpdp_fieldset">
557 <legend>
558 <label style="font-weight: normal;">
559 <?php
560 esc_html_e( 'Manage table settings for table ', 'wp-data-access' );
561 ?>
562 </label>
563 <label>
564 <?php
565 echo esc_attr( $wpda_table_name );
566 ?>
567 </label>
568 </legend>
569
570 <table class="wpda-table-structure wpdp-table-structure">
571 <tr>
572 <td style="text-align: right; padding-right: 5px; width: 140px;" class="wpdp-label-column">
573 <label>
574 <?php
575 esc_html_e( 'Template set name', 'wp-data-access' );
576 ?>
577 </label>
578 </td>
579 <td>
580 <input type="text" name="wpda_table_setname" value="<?php
581 echo esc_attr( $this->wpda_table_setname );
582 ?>"/>
583 <input type="hidden" name="wpda_table_setname_old" value="<?php
584 echo esc_attr( $this->wpda_table_setname );
585 ?>"/>
586 </td>
587 <td style="width:5px;"></td>
588 <td style="width:1%;" class="icon">
589 <i title="A template set is used to connect a table to a Data Project." class="fas fa-circle-question pointer wpda_tooltip"></i>
590 </td>
591 </tr>
592 <tr>
593 <td style="text-align: right; padding-right: 5px;">
594 <label>
595 <?php
596 esc_html_e( 'Tab label', 'wp-data-access' );
597 ?>
598 </label>
599 </td>
600 <td>
601 <input type="text" name="tab_label" value="<?php
602 echo esc_attr( $tab_label );
603 ?>"/>
604 </td>
605 <td style="width:5px;"></td>
606 <td style="width:1%;" class="icon">
607 <i title="Label shown on tab when table is shown as child table." class="fas fa-circle-question pointer wpda_tooltip"></i>
608 </td>
609 </tr>
610 </table>
611 </fieldset>
612
613 <div class="wpdp-spacer"></div>
614 <div class="wpdp-spacer"></div>
615
616 <fieldset class="wpda_fieldset wpdp_fieldset">
617 <legend>
618 <label style="font-weight: normal;">
619 <?php
620 echo esc_attr( $hint );
621 ?>
622 </label>
623 </legend>
624
625 <table class="wpda-table-structure wpdp-table-structure">
626 <tr>
627 <td style="text-align: right; padding-right: 5px; padding-top: 10px;" class="wpdp-label-column">
628 <label>
629 <?php
630 esc_html_e( 'Hyperlinks parent', 'wp-data-access' );
631 ?>
632 </label>
633 </td>
634 <td style="padding-top: 10px;">
635 <?php
636 // phpcs:disable WordPress.Security.EscapeOutput
637 echo $html;
638 // phpcs:enable WordPress.Security.EscapeOutput
639 ?>
640 </td>
641 </tr>
642 <tr>
643 <td style="text-align: right; padding-right: 5px;" class="wpdp-label-column">
644 <label>
645 <?php
646 esc_html_e( 'Hyperlinks child', 'wp-data-access' );
647 ?>
648 </label>
649 </td>
650 <td>
651 <?php
652 // phpcs:disable WordPress.Security.EscapeOutput
653 echo $html_child;
654 // phpcs:enable WordPress.Security.EscapeOutput
655 ?>
656 </td>
657 </tr>
658 </table>
659 </fieldset>
660
661 <?php
662 do_action( 'wpda_data_projects_add_table_option', $this->wpda_schema_name, $this->wpda_table_name );
663 ?>
664
665 <div class="wpdp-spacer"></div>
666 <div class="wpdp-spacer"></div>
667
668 <fieldset class="wpda_fieldset wpdp_fieldset">
669 <legend>
670 <label style="font-weight: normal;">
671 <?php
672 esc_html_e( 'Child table setting only', 'wp-data-access' );
673 ?>
674 <span class="dashicons dashicons-editor-help wpda_tooltip" title="These settings only affect child tables! Parent table settings are available on Data Projects page."></span>
675 </label>
676 </legend>
677
678 <table class="wpda-table-structure wpdp-table-structure">
679 <tr>
680 <td style="text-align: right; padding-right: 5px;" class="wpdp-label-column">
681 <label>
682 <?php
683 esc_html_e( 'Default WHERE', 'wp-data-access' );
684 ?>
685 </label>
686 </td>
687 <td>
688 <input type="text" name="default_where" value="<?php
689 echo esc_attr( $default_where );
690 ?>"/>
691 </td>
692 <td style="width:5px;"></td>
693 <td style="width:1%;" class="icon">
694 <i title="Enter a valid sql where clause, for example: name like 'Peter%'" class="fas fa-circle-question pointer wpda_tooltip"></i>
695 </td>
696 </tr>
697 <tr>
698 <td style="text-align: right; padding-right: 5px;" class="wpdp-label-column">
699 <label>
700 <?php
701 esc_html_e( 'Default ORDER BY', 'wp-data-access' );
702 ?>
703 </label>
704 </td>
705 <td>
706 <input type="text" name="default_orderby" value="<?php
707 echo esc_attr( $default_orderby );
708 ?>"/>
709 </td>
710 <td style="width:5px;"></td>
711 <td style="width:1%;" class="icon">
712 <i title="Enter a valid sql order by clause, for example: course_date desc, student_name asc" class="fas fa-circle-question pointer wpda_tooltip"></i>
713 </td>
714 </tr>
715 </table>
716 </fieldset>
717
718 <div class="wpdp-button-panel">
719 <input type="hidden" name="wpda_schema_name"
720 value="<?php
721 echo esc_attr( $this->wpda_schema_name_db );
722 ?>"/>
723 <input type="hidden" name="wpda_table_name"
724 value="<?php
725 echo esc_attr( $this->wpda_table_name );
726 ?>"/>
727 <input type="hidden" name="action" value="edit"/>
728 <input type="hidden" name="action2" value="tableinfo"/>
729 <input type="hidden" name="wpnonce"
730 value="<?php
731 echo esc_attr( $this->wpnonce );
732 ?>"/>
733 <button type="submit" class="button button-primary">
734 <i class="fas fa-check wpda_icon_on_button"></i>
735 <?php
736 esc_html_e( 'Save table info', 'wp-data-access' );
737 ?>
738 </button>
739 <a href="?page=<?php
740 echo esc_attr( $this->page );
741 ?>" class="button button-secondary">
742 <i class="fas fa-times-circle wpda_icon_on_button"></i>
743 <?php
744 esc_html_e( 'Back to list', 'wp-data-access' );
745 ?>
746 </a>
747 </div>
748
749 </form>
750 <?php
751 }
752
753 /**
754 * Show relationships
755 */
756 protected function show_relations() {
757 $source_table_columns = $this->wpda_list_columns->get_table_columns();
758 $target_table_names = WPDA_Dictionary_Lists::get_tables( true, $this->wpda_schema_name );
759 $available_databases = WPDA_Dictionary_Lists::get_db_schemas();
760 $i = 0;
761 global $wpdb;
762 if ( '' === $this->wpda_schema_name || $wpdb->dbname === $this->wpda_schema_name ) {
763 $wpda_table_name = $this->wpda_table_name;
764 } else {
765 $wpda_table_name = $this->wpda_table_name . ' (' . $this->wpda_schema_name . ')';
766 }
767 ?>
768 <script type='text/javascript'>
769 var row_num = 0;
770 var col_num = [];
771
772 function wpdp_get_tables(schema_name, index, target_id, selected_value, target_column_name = false, source_column_name= false) {
773 var url = location.pathname + '?action=wpda_get_tables';
774 var data = {
775 wpdaschema_name: schema_name,
776 wpda_wpnonce: '<?php
777 echo esc_attr( wp_create_nonce( 'wpda-getdata-access-' . WPDA::get_current_user_login() ) );
778 ?>'
779 };
780 jQuery.post(
781 url,
782 data,
783 function (data) {
784 jQuery(target_id).find('option').remove();
785 var jsonData = JSON.parse(data);
786 for (i = 0; i < jsonData.length; i++) {
787 jQuery(target_id).append(
788 newitem = jQuery("<option></option>")
789 .attr("value", jsonData[i]['table_name'])
790 .text(jsonData[i]['table_name'])
791 );
792 if (jsonData[i]['table_name'] === selected_value) {
793 newitem.attr("selected", true);
794 }
795 }
796 if (!target_column_name) {
797 jQuery(target_id).trigger("change");
798 } else {
799 wpdp_get_columns(selected_value, index, '#target_column_name_' + index, target_column_name[0], schema_name);
800 for (i=1; i<target_column_name.length; i++) {
801 add_column(index, target_column_name[i]);
802 jQuery('#source_column_name_' + index + '_' + i).val(source_column_name[i]);
803 wpdp_get_columns(selected_value, index, '#target_column_name_' + index + '_' + i, target_column_name[i], schema_name);
804 }
805 }
806 }
807 );
808 }
809
810 function wpdp_get_columns(table_name, index, target_id, selected_value, schema_name = '') {
811 if (schema_name === '') {
812 schema_name = '<?php
813 echo esc_attr( $this->wpda_schema_name );
814 ?>';
815 }
816 var url = location.pathname + '?action=wpda_get_columns';
817 var data = {
818 wpdaschema_name: schema_name,
819 table_name: table_name,
820 wpda_wpnonce: '<?php
821 echo esc_attr( wp_create_nonce( 'wpda-getdata-access-' . WPDA::get_current_user_login() ) );
822 ?>'
823 };
824 jQuery.post(
825 url,
826 data,
827 function (data) {
828 jQuery(target_id).find('option').remove();
829 var jsonData = JSON.parse(data);
830 for (i = 0; i < jsonData.length; i++) {
831 jQuery(target_id).append(
832 newitem = jQuery("<option></option>")
833 .attr("value", jsonData[i]['column_name'])
834 .text(jsonData[i]['column_name'])
835 );
836 if (jsonData[i]['column_name'] === selected_value) {
837 newitem.attr("selected", true);
838 }
839 }
840 }
841 );
842 }
843
844 function add_row(relation_type, source_column_name, target_table_name, target_column_name, relation_table_name, target_schema_name = '') {
845 if (relation_type === undefined || relation_type === '') {
846 relation_type = '1n';
847 }
848 if (source_column_name === undefined || source_column_name === '') {
849 source_column_name = [''];
850 }
851 if (relation_table_name === undefined || relation_table_name === '') {
852 relation_table_name = '';
853 }
854 if (target_schema_name === '' || target_schema_name === '<?php
855 echo esc_attr( $this->wpda_schema_name );
856 ?>') {
857 target_schema_name = '<?php
858 echo esc_attr( $this->wpda_schema_name );
859 ?>';
860 populate_lookup = false;
861 } else {
862 populate_lookup = true;
863 }
864 var new_row = '<tr id="relation_' + row_num + '">' +
865 '<td class="wpda-table-structure-first-column-move wpda-table-structure-top">' +
866 ' <span class="dashicons dashicons-move grabbable" style="padding-top:5px;"></span>' +
867 ' <input type="hidden" name="row_num[]" value="' + row_num + '" />' +
868 '</td>' +
869 '<td class="wpda-table-structure-top">' +
870 ' <select id="relation_type_' + row_num + '" name="relation_type[]" onchange="change_relationship(event, ' + row_num + ')">' +
871 ' <option value="1n" ' + (relation_type === '1n' ? 'selected' : '') + '>1:n</option>' +
872 ' <option value="nm" ' + (relation_type === 'nm' ? 'selected' : '') + '>n:m</option>' +
873 ' <option value="lookup" ' + (relation_type === 'lookup' ? 'selected' : '') + '>lookup listbox</option>' +
874 ' <option value="autocomplete" ' + (relation_type === 'autocomplete' ? 'selected' : '') + '>lookup autocomplete</option>' +
875 ' </select>' +
876 '</td>' +
877 '<td class="wpda-table-structure-top">' +
878 ' <select name="source_column_name[]" id="source_column_name_' + row_num + '">' +
879 <?php
880 foreach ( $source_table_columns as $column ) {
881 ?>
882 '<option value="<?php
883 echo esc_attr( $column['column_name'] );
884 ?>" ' + (source_column_name[0] === "<?php
885 echo esc_attr( $column['column_name'] );
886 ?>" ? "selected" : "") + '><?php
887 echo esc_attr( $column['column_name'] );
888 ?></option>' +
889 <?php
890 }
891 ?>
892 ' </select>' +
893 ' <input type="hidden" name="num_source_column_name[]" id="num_source_column_name_' + row_num + '" value="0" />' +
894 '</td>' +
895 '<td class="wpda-table-structure-top">' +
896 ' <a href="javascript:void(0)" style="vertical-align:-webkit-baseline-middle;padding-top:7px;"' +
897 ' class="dashicons dashicons-plus wpda_tooltip" title="Add column"' +
898 ' onclick="add_column(' + row_num + ')" id="remove_column_names_' + row_num + '"' +
899 ' ></a>' +
900 '</td>' +
901 '<td class="wpda-table-structure-top">' +
902 ' <select id="target_schema_name_' + row_num + '" name="target_schema_name[]" onchange="wpdp_get_tables(jQuery(this).val(), ' + row_num + ', \'#target_table_name_' + row_num + '\', \'\')" class="wpda_tooltip" title="Create lookup to other database"' + (relation_type==="lookup"||relation_type==="autocomplete" ? "" : "style=\'display:none;\'") + '>' +
903 <?php
904 global $wpdb;
905 foreach ( $available_databases as $available_database ) {
906 if ( $wpdb->dbname === $available_database['schema_name'] ) {
907 $database_printed = "WordPress database ({$available_database['schema_name']})";
908 } else {
909 $database_printed = $available_database['schema_name'];
910 }
911 ?>
912 '<option value="<?php
913 echo esc_attr( $available_database['schema_name'] );
914 ?>" ' + (target_schema_name === "<?php
915 echo esc_attr( $available_database['schema_name'] );
916 ?>" ? "selected" : "") + '><?php
917 echo esc_attr( $database_printed );
918 ?></option>' +
919 <?php
920 }
921 ?>
922 ' </select>' +
923 ' <select id="target_table_name_' + row_num + '" name="target_table_name[]" onchange="wpdp_get_columns(jQuery(this).val(), ' + row_num + ', \'#target_column_name_' + row_num + '\', \'\', jQuery(\'#target_schema_name_' + row_num + '\').val())">' +
924 ' <option value=""></option>' +
925 <?php
926 foreach ( $target_table_names as $target_table_name ) {
927 ?>
928 '<option value="<?php
929 echo esc_attr( $target_table_name['table_name'] );
930 ?>" ' + (target_table_name === "<?php
931 echo esc_attr( $target_table_name['table_name'] );
932 ?>" ? "selected" : "") + '><?php
933 echo esc_attr( $target_table_name['table_name'] );
934 ?></option>' +
935 <?php
936 }
937 ?>
938 ' </select>' +
939 '</td>' +
940 '<td class="wpda-table-structure-top">' +
941 ' <select name="target_column_name[]" id="target_column_name_' + row_num + '"></select>' +
942 '</td>' +
943 '<td class="wpda-table-structure-top">' +
944 ' <select name="relation_table_name_' + row_num + '" id="relation_table_name_' + row_num + '"></select>' +
945 '</td>' +
946 '<td class="wpda-table-structure-last-column wpda-table-structure-top">' +
947 ' <a href="javascript:void(0)" class="dashicons dashicons-trash" onclick="rem_row(event)" style="float:right;padding-top:5px;"></a>' +
948 '</td>' +
949 '</tr>';
950 if (jQuery("#wpda_table_structure tr").length === 0) {
951 jQuery("#wpda_table_structure").append(new_row);
952 } else {
953 jQuery("#wpda_table_structure tr:last").after(new_row);
954 }
955 col_num[row_num] = 0;
956 if (jQuery('#target_table_name_' + row_num + ' option:selected').val() !== '') {
957 // console.log(target_column_name[0])
958 wpdp_get_columns(jQuery('#target_table_name_' + row_num).val(), row_num, '#target_column_name_' + row_num, target_column_name[0]);
959 for (i = 1; i < target_column_name.length; i++) {
960 add_column(row_num, target_column_name[i]);
961 jQuery('#source_column_name_' + row_num + '_' + i).val(source_column_name[i]);
962 }
963 }
964 jQuery('#relation_table_name_' + row_num).append("<option value=''></option>");
965 <?php
966 foreach ( $target_table_names as $target_table_name ) {
967 $option = "<option value='" . esc_attr( $target_table_name['table_name'] ) . "'>" . esc_attr( $target_table_name['table_name'] ) . '</option>';
968 ?>
969 jQuery('#relation_table_name_' + row_num).append("<?php
970 // phpcs:disable WordPress.Security.EscapeOutput
971 echo $option;
972 // phpcs:enable WordPress.Security.EscapeOutput
973 ?>");
974 jQuery('#relation_table_name_' + row_num).val(relation_table_name);
975 <?php
976 }
977 ?>
978 if (relation_type === '1n' || relation_type === 'lookup' || relation_type === 'autocomplete') {
979 jQuery('#relation_table_name_' + row_num).hide();
980 }
981 if (populate_lookup) {
982 // If lookup table is stored in another schema, we need to populate the listboxes with ajax calls
983 wpdp_get_tables(jQuery('#target_schema_name_' + row_num).val(), row_num, '#target_table_name_' + row_num, target_table_name, target_column_name, source_column_name);
984 }
985 row_num++;
986 }
987
988 function change_relationship(e, index) {
989 if (jQuery(e.target).val() === 'nm') {
990 jQuery('#relation_table_name_' + index).show();
991 } else {
992 jQuery('#relation_table_name_' + index).hide();
993 }
994
995 if (jQuery(e.target).val() === 'lookup' || jQuery(e.target).val() === 'autocomplete') {
996 jQuery('#target_schema_name_' + index).show();
997 } else {
998 jQuery('#target_schema_name_' + index).hide();
999 }
1000 }
1001
1002 function rem_row(e) {
1003 var curr_id = e.target.parentNode.parentNode.id;
1004 if (confirm("Delete relationship?")) {
1005 jQuery("#" + curr_id).remove();
1006 }
1007 }
1008
1009 function add_column(index, selected_value = '') {
1010 var source_column_name_list =
1011 '<select name="source_column_name_' + index + '_' + (col_num[index] + 1) + '" id="source_column_name_' + index + '_' + (col_num[index] + 1) + '">' +
1012 <?php
1013 foreach ( $source_table_columns as $column ) {
1014 ?>
1015 '<option value="<?php
1016 echo esc_attr( $column['column_name'] );
1017 ?>"><?php
1018 echo esc_attr( $column['column_name'] );
1019 ?></option>' +
1020 <?php
1021 }
1022 ?>
1023 '</select>';
1024 jQuery(source_column_name_list).insertAfter(jQuery('#source_column_name_' + index).parent().children().last());
1025
1026 var remove_column_names_list =
1027 '<div id="remove_column_names_' + index + '_' + (col_num[index] + 1) + '" style="padding-top:4px;">' +
1028 ' <a href="javascript:void(0)"' +
1029 ' style="vertical-align:-webkit-baseline-middle;padding-top:5px;"' +
1030 ' class="dashicons dashicons-minus wpda_tooltip"' +
1031 ' title="Remove column"' +
1032 ' onclick="rem_column(' + index + ',' + (col_num[index] + 1) + ')"' +
1033 ' ></a>' +
1034 '</div>';
1035 jQuery(remove_column_names_list).insertAfter(jQuery('#remove_column_names_' + index).parent().children().last());
1036
1037 var target_column_name_list =
1038 '<select name="target_column_name_' + index + '_' + (col_num[index] + 1) + '" id="target_column_name_' + index + '_' + (col_num[index] + 1) + '">' +
1039 '</select>';
1040 jQuery(target_column_name_list).insertAfter(jQuery('#target_column_name_' + index).parent().children().last());
1041 if (
1042 jQuery('#relation_type_' + index).val()==='lookup' ||
1043 jQuery('#relation_type_' + index).val()==='autocomplete'
1044 ) {
1045 // Is lookup accessing a remote database?
1046 wpdp_get_columns(
1047 jQuery('#target_table_name_' + index).val(),
1048 index,
1049 '#target_column_name_' + index + '_' + (col_num[index] + 1),
1050 selected_value,
1051 jQuery('#target_schema_name_' + index).val()
1052 );
1053 } else {
1054 wpdp_get_columns(
1055 jQuery('#target_table_name_' + index).val(),
1056 index,
1057 '#target_column_name_' + index + '_' + (col_num[index] + 1),
1058 selected_value
1059 );
1060 }
1061
1062 col_num[index] += 1;
1063 jQuery('#num_source_column_name_' + index).val(col_num[index]);
1064 }
1065
1066 function rem_column(index, seq) {
1067 jQuery('#source_column_name_' + index + '_' + seq).remove();
1068 jQuery('#remove_column_names_' + index + '_' + seq).remove();
1069 jQuery('#target_column_name_' + index + '_' + seq).remove();
1070 }
1071 </script>
1072 <form id="wpdp_form_relations" method="post">
1073 <fieldset class="wpda_fieldset wpdp_fieldset">
1074 <legend>
1075 <label style="font-weight: normal;">
1076 <?php
1077 esc_html_e( 'Manage relationships for table', 'wp-data-access' );
1078 ?>
1079 </label>
1080 <label>
1081 <?php
1082 echo esc_attr( $wpda_table_name );
1083 ?>
1084 </label>
1085 </legend>
1086
1087 <table class="wpda-table-structure">
1088 <thead>
1089 <tr>
1090 <th class="wpda-table-structure-first-column-move"></th>
1091 <th>
1092 <?php
1093 esc_html_e( 'Type', 'wp-data-access' );
1094 ?>
1095 </th>
1096 <th>
1097 <?php
1098 esc_html_e( 'Source column name', 'wp-data-access' );
1099 ?>
1100 </th>
1101 <th style="width:20px;"></th>
1102 <th>
1103 <?php
1104 esc_html_e( 'Target table name', 'wp-data-access' );
1105 ?>
1106 </th>
1107 <th>
1108 <?php
1109 esc_html_e( 'Target column name', 'wp-data-access' );
1110 ?>
1111 </th>
1112 <th>
1113 <span style="vertical-align:inherit">
1114 <?php
1115 esc_html_e( 'Relation table name (only n:m)', 'wp-data-access' );
1116 ?>
1117 </span>
1118 <span
1119 class="dashicons dashicons-info wpda_tooltip"
1120 title="<?php
1121 esc_html_e( 'Table shown on the other end of the n:m relationship (instead of target table shown for 1:n relationships). Not available for 1:n relationships.', 'wp-data-access' );
1122 ?>"
1123 style="cursor:pointer;"
1124 ></span>
1125 </th>
1126 <th class="wpda-table-structure-last-column">
1127 <a href="javascript:void(0)"
1128 style="vertical-align:-webkit-baseline-middle;float:right;"
1129 class="dashicons dashicons-plus add-row"
1130 onclick="add_row()"
1131 ></a>
1132 </th>
1133 </tr>
1134 </thead>
1135 <tbody id="wpda_table_structure">
1136 </tbody>
1137 </table>
1138 </fieldset>
1139
1140 <div class="wpdp-button-panel">
1141 <input type="hidden" name="wpda_schema_name"
1142 value="<?php
1143 echo esc_attr( $this->wpda_schema_name_db );
1144 ?>"/>
1145 <input type="hidden" name="wpda_table_name"
1146 value="<?php
1147 echo esc_attr( $this->wpda_table_name );
1148 ?>"/>
1149 <input type="hidden" name="wpda_table_setname"
1150 value="<?php
1151 echo esc_attr( $this->wpda_table_setname );
1152 ?>"/>
1153 <input type="hidden" name="wpda_table_setname_old"
1154 value="<?php
1155 echo esc_attr( $this->wpda_table_setname );
1156 ?>"/>
1157 <input type="hidden" name="action" value="edit"/>
1158 <input type="hidden" name="action2" value="relation"/>
1159 <input type="hidden" name="wpnonce"
1160 value="<?php
1161 echo esc_attr( $this->wpnonce );
1162 ?>"/>
1163 <button type="submit" class="button button-primary">
1164 <i class="fas fa-check wpda_icon_on_button"></i>
1165 <?php
1166 esc_html_e( 'Save relationships', 'wp-data-access' );
1167 ?>
1168 </button>
1169 <a href="?page=<?php
1170 echo esc_attr( $this->page );
1171 ?>" class="button button-secondary">
1172 <i class="fas fa-times-circle wpda_icon_on_button"></i>
1173 <?php
1174 esc_html_e( 'Back to list', 'wp-data-access' );
1175 ?>
1176 </a>
1177 </div>
1178
1179 </form>
1180 <?php
1181 if ( isset( $this->table_structure->relationships ) ) {
1182 $relationships = $this->table_structure->relationships;
1183 if ( 0 < count( $relationships ) ) {
1184 // phpcs:ignore -- 8.1 proof
1185 foreach ( $relationships as $relationship ) {
1186 ?>
1187 <script type='text/javascript'>
1188 <?php
1189 if ( !is_array( $relationship->source_column_name ) ) {
1190 $source_column_name_array = '[""]';
1191 } else {
1192 $source_column_name_array = wp_json_encode( $relationship->source_column_name );
1193 }
1194 // phpcs:disable WordPress.Security.EscapeOutput
1195 echo 'var source_column_name_array = ' . $source_column_name_array . ";\n";
1196 // phpcs:enable WordPress.Security.EscapeOutput
1197 if ( !is_array( $relationship->target_column_name ) ) {
1198 $target_column_name_array = '[""]';
1199 } else {
1200 $target_column_name_array = wp_json_encode( $relationship->target_column_name );
1201 }
1202 // phpcs:disable WordPress.Security.EscapeOutput
1203 echo 'var target_column_name_array = ' . $target_column_name_array . ";\n";
1204 // phpcs:enable WordPress.Security.EscapeOutput
1205 if ( isset( $relationship->relation_table_name ) ) {
1206 $relation_table_name = $relationship->relation_table_name;
1207 } else {
1208 $relation_table_name = '';
1209 }
1210 if ( isset( $relationship->target_schema_name ) ) {
1211 $target_schema_name = $relationship->target_schema_name;
1212 } else {
1213 $target_schema_name = '';
1214 }
1215 ?>
1216 add_row(
1217 '<?php
1218 echo esc_attr( $relationship->relation_type );
1219 ?>',
1220 source_column_name_array,
1221 '<?php
1222 echo esc_attr( $relationship->target_table_name );
1223 ?>',
1224 target_column_name_array,
1225 '<?php
1226 echo esc_attr( $relation_table_name );
1227 ?>',
1228 '<?php
1229 echo esc_attr( $target_schema_name );
1230 ?>'
1231 );
1232 </script>
1233 <?php
1234 }
1235 } else {
1236 ?>
1237 <script type='text/javascript'>
1238 add_row('', '', '', '');
1239 </script>
1240 <?php
1241 }
1242 } else {
1243 ?>
1244 <script type='text/javascript'>
1245 add_row('', '', '', '');
1246 </script>
1247 <?php
1248 }
1249 }
1250
1251 /**
1252 * Show list table settings
1253 */
1254 protected function show_list_table() {
1255 if ( null === $this->table_structure ) {
1256 return __( 'Invalid structure', 'wp-data-access' );
1257 }
1258 global $wpdb;
1259 if ( '' === $this->wpda_schema_name || $wpdb->dbname === $this->wpda_schema_name ) {
1260 $wpda_table_name = $this->wpda_table_name;
1261 } else {
1262 $wpda_table_name = $this->wpda_table_name . ' (' . $this->wpda_schema_name . ')';
1263 }
1264 ?>
1265 <form id="wpdp_form_labels" method="post">
1266 <fieldset class="wpda_fieldset wpdp_fieldset">
1267 <legend>
1268 <label style="font-weight: normal;">
1269 <?php
1270 esc_html_e( 'Manage columns for list table of table', 'wp-data-access' );
1271 ?>
1272 </label>
1273 <label>
1274 <?php
1275 echo esc_attr( $wpda_table_name );
1276 ?>
1277 </label>
1278 </legend>
1279
1280 <table class="wpda-table-structure">
1281 <thead>
1282 <tr>
1283 <th class="wpda-table-structure-first-column-move"></th>
1284 <th>
1285 <?php
1286 esc_html_e( 'Column name', 'wp-data-access' );
1287 ?>
1288 </th>
1289 <th>
1290 <?php
1291 esc_html_e( 'Data type', 'wp-data-access' );
1292 ?>
1293 </th>
1294 <th>
1295 <?php
1296 esc_html_e( 'Key', 'wp-data-access' );
1297 ?>
1298 </th>
1299 <th>
1300 <?php
1301 esc_html_e( 'Mandatory', 'wp-data-access' );
1302 ?>
1303 </th>
1304 <th>
1305 <?php
1306 esc_html_e( 'Visible', 'wp-data-access' );
1307 ?>
1308 </th>
1309 <th>
1310 <?php
1311 esc_html_e( 'Label', 'wp-data-access' );
1312 ?>
1313 </th>
1314 <th></th>
1315 <th>
1316 <?php
1317 esc_html_e( 'Lookup', 'wp-data-access' );
1318 ?>
1319 </th>
1320 </tr>
1321 </thead>
1322 <tbody id="wpda_list_table_options">
1323 <?php
1324 $table_structure = array();
1325 if ( isset( $this->table_structure->listtable_column_options ) ) {
1326 $structure = $this->table_structure->listtable_column_options;
1327 foreach ( $this->table_structure->table as $column ) {
1328 $table_structure[$column->column_name] = $column;
1329 }
1330 } else {
1331 $structure = $this->table_structure->table;
1332 }
1333 $i = 0;
1334 foreach ( $structure as $column ) {
1335 $column_name = $column->column_name;
1336 if ( isset( $this->table_structure->listtable_column_options ) && isset( $table_structure[$column_name] ) ) {
1337 $data_type = $table_structure[$column_name]->data_type;
1338 $type_attribute = $table_structure[$column_name]->type_attribute;
1339 $key = $table_structure[$column_name]->key;
1340 $mandatory = $table_structure[$column_name]->mandatory;
1341 $max_length = $table_structure[$column_name]->max_length;
1342 } else {
1343 // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
1344 $msg = new WPDA_Message_Box(array(
1345 'message_text' => sprintf( __( 'Column %s not found for list table', 'wp-data-access' ), esc_attr( $column_name ) ),
1346 'message_type' => 'error',
1347 'message_is_dismissible' => false,
1348 ));
1349 // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
1350 $msg->box();
1351 break;
1352 }
1353 if ( '' === $max_length ) {
1354 $data_type = $data_type . ' ' . $type_attribute;
1355 } else {
1356 $data_type = $data_type . ' (' . $max_length . ') ' . $type_attribute;
1357 }
1358 if ( isset( $this->table_structure->listtable_column_options ) ) {
1359 $show_in_list = ( 'on' === $column->show ? 'checked' : '' );
1360 $label_in_list = $column->label;
1361 $lookup_in_list = ( isset( $column->lookup ) ? $column->lookup : '' );
1362 } else {
1363 $show_in_list = 'checked';
1364 $label_in_list = ucfirst( str_replace( '_', ' ', $column_name ) );
1365 $lookup_in_list = '';
1366 }
1367 $i++;
1368 ?>
1369 <tr id="listtable_<?php
1370 echo esc_attr( $i );
1371 ?>">
1372 <td class="wpda-table-structure-first-column-move">
1373 <span class="dashicons dashicons-move grabbable" style="float:left;"></span>
1374 </td>
1375 <td>
1376 <?php
1377 echo esc_attr( $column_name );
1378 ?>
1379 <input type="hidden" name="list_item_name[]"
1380 value="<?php
1381 echo esc_attr( $column_name );
1382 ?>"/>
1383 </td>
1384 <td>
1385 <?php
1386 echo esc_attr( $data_type );
1387 ?>
1388 </td>
1389 <td>
1390 <?php
1391 echo esc_attr( $key );
1392 ?>
1393 </td>
1394 <td>
1395 <?php
1396 echo esc_attr( $mandatory );
1397 ?>
1398 </td>
1399 <td>
1400 <input type="checkbox"
1401 name="<?php
1402 echo esc_attr( $column_name );
1403 ?>_show"
1404 <?php
1405 echo esc_attr( $show_in_list );
1406 ?>
1407 style="vertical-align:middle;width:16px;height:16px;"
1408 />
1409 </td>
1410 <td>
1411 <input type="text"
1412 name="<?php
1413 echo esc_attr( $column_name );
1414 ?>"
1415 value="<?php
1416 echo esc_attr( $label_in_list );
1417 ?>"
1418 style="vertical-align:middle;"
1419 />
1420 </td>
1421 <td></td>
1422 <td class="wpda-table-structure-last-column">
1423 <?php
1424 $has_lookup = false;
1425 if ( isset( $this->table_structure->relationships ) ) {
1426 foreach ( $this->table_structure->relationships as $relationship ) {
1427 if ( $column_name === $relationship->source_column_name[0] && ('lookup' === $relationship->relation_type || 'autocomplete' === $relationship->relation_type) ) {
1428 if ( isset( $relationship->target_schema_name ) ) {
1429 $target_schema_name = $relationship->target_schema_name;
1430 } else {
1431 $target_schema_name = $this->wpda_schema_name;
1432 }
1433 $lookup_column_list = WPDA_Dictionary_Lists::get_table_columns( $relationship->target_table_name, $target_schema_name );
1434 ?>
1435 <select name="<?php
1436 echo esc_attr( $column_name );
1437 ?>_lookup">
1438 <?php
1439 foreach ( $lookup_column_list as $lookup_column ) {
1440 ?>
1441 <option value="<?php
1442 echo esc_attr( $lookup_column['column_name'] );
1443 ?>"
1444 <?php
1445 if ( $lookup_in_list === $lookup_column['column_name'] ) {
1446 echo 'selected';
1447 }
1448 ?>
1449 >
1450 <?php
1451 echo esc_attr( $lookup_column['column_name'] );
1452 ?>
1453 </option>
1454 <?php
1455 }
1456 ?>
1457 </select>
1458 <?php
1459 $has_lookup = true;
1460 }
1461 }
1462 }
1463 if ( !$has_lookup ) {
1464 echo '--';
1465 }
1466 ?>
1467 </td>
1468 </tr>
1469 <?php
1470 }
1471 ?>
1472 </tbody>
1473 </table>
1474 </fieldset>
1475
1476 <div class="wpdp-button-panel">
1477 <input type="hidden" name="wpda_schema_name"
1478 value="<?php
1479 echo esc_attr( $this->wpda_schema_name_db );
1480 ?>"/>
1481 <input type="hidden" name="wpda_table_name"
1482 value="<?php
1483 echo esc_attr( $this->wpda_table_name );
1484 ?>"/>
1485 <input type="hidden" name="wpda_table_setname"
1486 value="<?php
1487 echo esc_attr( $this->wpda_table_setname );
1488 ?>"/>
1489 <input type="hidden" name="wpda_table_setname_old"
1490 value="<?php
1491 echo esc_attr( $this->wpda_table_setname );
1492 ?>"/>
1493 <input type="hidden" name="action" value="edit"/>
1494 <input type="hidden" name="action2" value="listtable"/>
1495 <input type="hidden" name="wpnonce"
1496 value="<?php
1497 echo esc_attr( $this->wpnonce );
1498 ?>"/>
1499 <button type="submit" class="button button-primary">
1500 <i class="fas fa-check wpda_icon_on_button"></i>
1501 <?php
1502 esc_html_e( 'Save list table columns', 'wp-data-access' );
1503 ?>
1504 </button>
1505 <a href="?page=<?php
1506 echo esc_attr( $this->page );
1507 ?>" class="button button-secondary">
1508 <i class="fas fa-times-circle wpda_icon_on_button"></i>
1509 <?php
1510 esc_html_e( 'Back to list', 'wp-data-access' );
1511 ?>
1512 </a>
1513 </div>
1514
1515 </form>
1516 <?php
1517 }
1518
1519 /**
1520 * Show data entry form settings
1521 */
1522 protected function show_table_form() {
1523 if ( null === $this->table_structure ) {
1524 return __( 'Invalid structure', 'wp-data-access' );
1525 }
1526 global $wpdb;
1527 if ( '' === $this->wpda_schema_name || $wpdb->dbname === $this->wpda_schema_name ) {
1528 $wpda_table_name = $this->wpda_table_name;
1529 } else {
1530 $wpda_table_name = $this->wpda_table_name . ' (' . $this->wpda_schema_name . ')';
1531 }
1532 ?>
1533 <form id="wpdp_form_labels" method="post">
1534 <fieldset class="wpda_fieldset wpdp_fieldset">
1535 <legend>
1536 <label style="font-weight: normal;">
1537 <?php
1538 esc_html_e( 'Manage columns for data entry form for table', 'wp-data-access' );
1539 ?>
1540 </label>
1541 <label>
1542 <?php
1543 echo esc_attr( $wpda_table_name );
1544 ?>
1545 </label>
1546 </legend>
1547
1548 <table class="wpda-table-structure">
1549 <thead>
1550 <tr>
1551 <th class="wpda-table-structure-first-column-move"></th>
1552 <th>
1553 <?php
1554 esc_html_e( 'Column name', 'wp-data-access' );
1555 ?>
1556 </th>
1557 <th>
1558 <?php
1559 esc_html_e( 'Data type', 'wp-data-access' );
1560 ?>
1561 </th>
1562 <th>
1563 <?php
1564 esc_html_e( 'Key', 'wp-data-access' );
1565 ?>
1566 </th>
1567 <th>
1568 <?php
1569 esc_html_e( 'Mandatory', 'wp-data-access' );
1570 ?>
1571 </th>
1572 <th>
1573 <?php
1574 esc_html_e( 'Visible', 'wp-data-access' );
1575 ?>
1576 </th>
1577 <th>
1578 <?php
1579 esc_html_e( 'Read only', 'wp-data-access' );
1580 ?>
1581 </th>
1582 <th>
1583 <?php
1584 esc_html_e( 'Less', 'wp-data-access' );
1585 ?>
1586 </th>
1587 <th>
1588 <?php
1589 esc_html_e( 'Label', 'wp-data-access' );
1590 ?>
1591 </th>
1592 <th></th>
1593 <th>
1594 <?php
1595 esc_html_e( 'Default value', 'wp-data-access' );
1596 ?>
1597 </th>
1598 <th></th>
1599 <th>
1600 <?php
1601 esc_html_e( 'Lookup', 'wp-data-access' );
1602 ?>
1603 </th>
1604 <th>
1605 <span style="vertical-align:inherit">
1606 <?php
1607 esc_html_e( 'ID?', 'wp-data-access' );
1608 ?>
1609 </span>
1610 <span
1611 class="dashicons dashicons-info wpda_tooltip"
1612 title="<?php
1613 esc_html_e( 'Enable to hide ID in lookup', 'wp-data-access' );
1614 ?>"
1615 style="cursor:pointer;"
1616 ></span>
1617
1618 </th>
1619 </tr>
1620 </thead>
1621 <tbody id="wpda_form_options">
1622 <?php
1623 $table_structure = array();
1624 if ( isset( $this->table_structure->tableform_column_options ) ) {
1625 $structure = $this->table_structure->tableform_column_options;
1626 foreach ( $this->table_structure->table as $column ) {
1627 $table_structure[$column->column_name] = $column;
1628 }
1629 } else {
1630 $structure = $this->table_structure->table;
1631 }
1632 $i = 0;
1633 foreach ( $structure as $column ) {
1634 $column_name = $column->column_name;
1635 if ( isset( $this->table_structure->tableform_column_options ) && isset( $table_structure[$column_name] ) ) {
1636 $data_type = $table_structure[$column_name]->data_type;
1637 $type_attribute = $table_structure[$column_name]->type_attribute;
1638 $key = $table_structure[$column_name]->key;
1639 $mandatory = $table_structure[$column_name]->mandatory;
1640 $max_length = $table_structure[$column_name]->max_length;
1641 } else {
1642 // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
1643 $msg = new WPDA_Message_Box(array(
1644 'message_text' => sprintf( __( 'Column %s not found for data entry form', 'wp-data-access' ), esc_attr( $column_name ) ),
1645 'message_type' => 'error',
1646 'message_is_dismissible' => false,
1647 ));
1648 // phpcs:enable WordPress.WP.I18n.MissingTranslatorsComment
1649 $msg->box();
1650 break;
1651 }
1652 if ( '' === $max_length ) {
1653 $data_type = $data_type . ' ' . $type_attribute;
1654 } else {
1655 $data_type = $data_type . ' (' . $max_length . ') ' . $type_attribute;
1656 }
1657 if ( isset( $this->table_structure->tableform_column_options ) ) {
1658 $show_on_form = ( 'on' === $column->show ? 'checked' : '' );
1659 $label_on_form = $column->label;
1660 $lookup_in_list = ( isset( $column->lookup ) ? $column->lookup : '' );
1661 } else {
1662 $show_on_form = 'checked';
1663 $label_on_form = ucfirst( str_replace( '_', ' ', $column_name ) );
1664 $lookup_in_list = '';
1665 }
1666 if ( isset( $column->readonly ) ) {
1667 $readonly_on_form = ( 'on' === $column->readonly ? 'checked' : '' );
1668 } else {
1669 $readonly_on_form = '';
1670 }
1671 if ( isset( $column->less ) ) {
1672 $less_on_form = ( 'on' === $column->less ? 'checked' : '' );
1673 } else {
1674 $less_on_form = 'checked';
1675 }
1676 if ( isset( $column->default ) ) {
1677 $default_on_form = esc_html( $column->default );
1678 } else {
1679 $default_on_form = '';
1680 }
1681 if ( isset( $column->hide_lookup_key ) ) {
1682 $hide_id = ( 'on' === $column->hide_lookup_key ? 'checked' : '' );
1683 } else {
1684 $hide_id = 'checked';
1685 }
1686 $i++;
1687 ?>
1688 <tr id="tableform_<?php
1689 echo esc_attr( $i );
1690 ?>">
1691 <td class="wpda-table-structure-first-column-move">
1692 <span class="dashicons dashicons-move grabbable" style="float:left;"></span>
1693 </td>
1694 <td>
1695 <?php
1696 echo esc_attr( $column_name );
1697 ?>
1698 <input type="hidden" name="list_item_name[]"
1699 value="<?php
1700 echo esc_attr( $column_name );
1701 ?>"/>
1702 </td>
1703 <td>
1704 <?php
1705 echo esc_attr( $data_type );
1706 ?>
1707 <?php
1708 echo ( $this->wpda_list_columns->get_auto_increment_column_name() === $column_name ? ' (auto increment)' : '' );
1709 ?>
1710 </td>
1711 <td>
1712 <?php
1713 echo ( 'Yes' === $key ? 'Yes' : '' );
1714 ?>
1715 </td>
1716 <td>
1717 <?php
1718 echo ( 'Yes' === $mandatory ? 'Yes' : '' );
1719 ?>
1720 </td>
1721 <td>
1722 <?php
1723 if ( $this->wpda_list_columns->get_auto_increment_column_name() === $column_name ) {
1724 // Allow to hide auto_increment column
1725 $l_key = 'No';
1726 $l_mandatory = 'No';
1727 } else {
1728 $l_key = $key;
1729 $l_mandatory = $mandatory;
1730 }
1731 ?>
1732 <input type="checkbox"
1733 name="<?php
1734 echo esc_attr( $column_name );
1735 ?>_show"
1736 <?php
1737 echo esc_attr( $show_on_form );
1738 ?>
1739 <?php
1740 if ( 'Yes' === $l_key || 'Yes' === $l_mandatory ) {
1741 echo ' disabled="disabled"';
1742 }
1743 ?>
1744 style="vertical-align:middle;width:16px;height:16px;"
1745 />
1746 <?php
1747 if ( 'Yes' === $l_key || 'Yes' === $l_mandatory ) {
1748 ?>
1749 <input name="<?php
1750 echo esc_attr( $column_name );
1751 ?>_show"
1752 type="hidden"
1753 value="true"/>
1754 <?php
1755 }
1756 ?>
1757 </td>
1758 <td>
1759 <input type="checkbox" name="<?php
1760 echo esc_attr( $column_name );
1761 ?>_readonly"
1762 style="vertical-align:middle;width:16px;height:16px;"
1763 <?php
1764 echo esc_attr( $readonly_on_form );
1765 ?>
1766 />
1767 </td>
1768 <td>
1769 <input type="checkbox" name="<?php
1770 echo esc_attr( $column_name );
1771 ?>_less"
1772 style="vertical-align:middle;width:16px;height:16px;"
1773 <?php
1774 echo esc_attr( $less_on_form );
1775 ?>
1776 />
1777 </td>
1778 <td>
1779 <input type="text"
1780 name="<?php
1781 echo esc_attr( $column_name );
1782 ?>"
1783 value="<?php
1784 echo esc_attr( $label_on_form );
1785 ?>"
1786 style="vertical-align:middle;"
1787 />
1788 </td>
1789 <td></td>
1790 <td>
1791 <input type="text"
1792 name="<?php
1793 echo esc_attr( $column_name );
1794 ?>_default"
1795 value="<?php
1796 echo esc_attr( $default_on_form );
1797 ?>"
1798 style="vertical-align:middle;"
1799 />
1800 </td>
1801 <td></td>
1802 <td>
1803 <?php
1804 $has_lookup = false;
1805 if ( isset( $this->table_structure->relationships ) ) {
1806 foreach ( $this->table_structure->relationships as $relationship ) {
1807 if ( $column_name === $relationship->source_column_name[0] && ('lookup' === $relationship->relation_type || 'autocomplete' === $relationship->relation_type) ) {
1808 if ( isset( $relationship->target_schema_name ) ) {
1809 $target_schema_name = $relationship->target_schema_name;
1810 } else {
1811 $target_schema_name = $this->wpda_schema_name;
1812 }
1813 $lookup_column_list = WPDA_Dictionary_Lists::get_table_columns( $relationship->target_table_name, $target_schema_name );
1814 ?>
1815 <select name="<?php
1816 echo esc_attr( $column_name );
1817 ?>_lookup">
1818 <?php
1819 foreach ( $lookup_column_list as $lookup_column ) {
1820 ?>
1821 <option value="<?php
1822 echo esc_attr( $lookup_column['column_name'] );
1823 ?>"
1824 <?php
1825 if ( $lookup_in_list === $lookup_column['column_name'] ) {
1826 echo 'selected';
1827 }
1828 ?>
1829 >
1830 <?php
1831 echo esc_attr( $lookup_column['column_name'] );
1832 ?>
1833 </option>
1834 <?php
1835 }
1836 ?>
1837 </select>
1838 <?php
1839 $has_lookup = true;
1840 }
1841 }
1842 }
1843 if ( !$has_lookup ) {
1844 echo '--';
1845 }
1846 ?>
1847 </td>
1848 <td class="wpda-table-structure-last-column">
1849 <?php
1850 if ( $has_lookup ) {
1851 ?>
1852 <input type="checkbox"
1853 name="<?php
1854 echo esc_attr( $column_name );
1855 ?>_hide_lookup_key"
1856 <?php
1857 echo esc_attr( $hide_id );
1858 ?>
1859 style="vertical-align:middle;width:16px;height:16px;"
1860 />
1861 <?php
1862 }
1863 ?>
1864 </td>
1865 </tr>
1866 <?php
1867 }
1868 ?>
1869 </tbody>
1870 </table>
1871 </fieldset>
1872
1873 <div class="wpdp-button-panel">
1874 <input type="hidden" name="wpda_schema_name"
1875 value="<?php
1876 echo esc_attr( $this->wpda_schema_name_db );
1877 ?>"/>
1878 <input type="hidden" name="wpda_table_name"
1879 value="<?php
1880 echo esc_attr( $this->wpda_table_name );
1881 ?>"/>
1882 <input type="hidden" name="wpda_table_setname"
1883 value="<?php
1884 echo esc_attr( $this->wpda_table_setname );
1885 ?>"/>
1886 <input type="hidden" name="wpda_table_setname_old"
1887 value="<?php
1888 echo esc_attr( $this->wpda_table_setname );
1889 ?>"/>
1890 <input type="hidden" name="action" value="edit"/>
1891 <input type="hidden" name="action2" value="tableform"/>
1892 <input type="hidden" name="wpnonce"
1893 value="<?php
1894 echo esc_attr( $this->wpnonce );
1895 ?>"/>
1896 <button type="submit" class="button button-primary">
1897 <i class="fas fa-check wpda_icon_on_button"></i>
1898 <?php
1899 esc_html_e( 'Save data entry form columns', 'wp-data-access' );
1900 ?>
1901 </button>
1902 <a href="?page=<?php
1903 echo esc_attr( $this->page );
1904 ?>" class="button button-secondary">
1905 <i class="fas fa-times-circle wpda_icon_on_button"></i>
1906 <?php
1907 esc_html_e( 'Back to list', 'wp-data-access' );
1908 ?>
1909 </a>
1910 </div>
1911
1912 </form>
1913 <?php
1914 }
1915
1916 protected function show_reconcile() {
1917 ?>
1918 <div class="wrap" style="padding-left:8px;">
1919 <form method="post">
1920 <fieldset class="wpda_fieldset wpdp_fieldset">
1921 <legend>
1922 <label style="font-weight: normal;">
1923 <?php
1924 esc_html_e( 'Reconcile columns for table', 'wp-data-access' );
1925 ?>
1926 </label>
1927 <label>
1928 <?php
1929 echo esc_attr( $this->wpda_table_name );
1930 ?>
1931 </label>
1932 </legend>
1933
1934 <div>
1935 <strong>Update table design from database table</strong>
1936 <ul class="wpdp-reconcile">
1937 <li>Add new columns</li>
1938 <li>Remove deleted columns</li>
1939 <li>Change column settings</li>
1940 <li>Update settings</li>
1941 </ul>
1942 <label style="line-height:30px;padding-bottom:8px">
1943 <input type="checkbox" name="keep_options" style="vertical-align:middle;">
1944 <strong>Keep options?</strong> (enable to keep settings of unchanged columns)
1945 </label>
1946 </div>
1947 </fieldset>
1948
1949 <div class="wpdp-spacer"></div>
1950 <div class="wpdp-spacer"></div>
1951
1952 <div class="wpdp-button-panel">
1953 <input type="hidden" name="action" value="reconcile"/>
1954 <input type="hidden" name="wpda_schema_name"
1955 value="<?php
1956 echo esc_attr( $this->wpda_schema_name_db );
1957 ?>">
1958 <input type="hidden" name="wpda_table_name"
1959 value="<?php
1960 echo esc_attr( $this->wpda_table_name );
1961 ?>">
1962 <input type="hidden" name="wpda_table_setname"
1963 value="<?php
1964 echo esc_attr( $this->wpda_table_setname );
1965 ?>"/>
1966 <input type="hidden" name="wpnonce"
1967 value="<?php
1968 echo esc_attr( $this->wpnonce );
1969 ?>"/>
1970 <button type="submit" class="button button-primary wpda_tooltip"
1971 onclick="return (confirm('<?php
1972 esc_html_e( 'Reconcile table? Your current modifications will be lost!', 'wp-data-access' );
1973 ?>'));"
1974 >
1975 <i class="fas fa-check wpda_icon_on_button"></i>
1976 <?php
1977 esc_html_e( 'Reconcile Table', 'wp-data-access' );
1978 ?>
1979 </button>
1980 <a href="?page=<?php
1981 echo esc_attr( $this->page );
1982 ?>" class="button button-secondary">
1983 <i class="fas fa-times-circle wpda_icon_on_button"></i>
1984 <?php
1985 esc_html_e( 'Back to list', 'wp-data-access' );
1986 ?>
1987 </a>
1988 </div>
1989 </form>
1990 </div>
1991 <?php
1992 }
1993
1994 }
1995
1996 // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing