PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.2
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.2
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.2, at WPDataProjects/Project/WPDP_Project_Table_Form.php

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