PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.84 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 All 160 releases
wp-data-access / WPDataAccess / Data_Publisher / WPDA_Publisher_Form.php

WPDA_Publisher_Form.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.84, at WPDataAccess/Data_Publisher/WPDA_Publisher_Form.php

1,332 lines 49.3 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 WPDataAccess\Data_Publisher
7 */
8 namespace WPDataAccess\Data_Publisher;
9
10 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
11 use WPDataAccess\Data_Dictionary\WPDA_List_Columns_Cache;
12 use WPDataAccess\Data_Tables\WPDA_Data_Tables;
13 use WPDataAccess\Plugin_Table_Models\WPDA_Table_Settings_Model;
14 use WPDataAccess\Plugin_Table_Models\WPDA_Publisher_Model;
15 use WPDataAccess\Premium\WPDAPRO_CPT\WPDAPRO_CPT_Services;
16 use WPDataAccess\Premium\WPDAPRO_Data_Publisher\WPDAPRO_Data_Publisher_Manage_Styles;
17 use WPDataAccess\Simple_Form\WPDA_Simple_Form;
18 use WPDataAccess\Simple_Form\WPDA_Simple_Form_Item_Boolean;
19 use WPDataAccess\Simple_Form\WPDA_Simple_Form_Item_Enum;
20 use WPDataAccess\Simple_Form\WPDA_Simple_Form_Item_Enum_Radio;
21 use WPDataAccess\WPDA;
22 use function GuzzleHttp\Psr7\_caseless_remove;
23 /**
24 * Class WPDA_Publisher_Form extends WPDA_Simple_Form
25 *
26 * Data entry form which allows users to create, update and test data tables. A data table consists of a database
27 * table, a number of columns and some options. A shortcode can be generated for a data table. The shortcode can
28 * be copied to the clipboard and from there pasted in a WordPress post or page. The shortcode is used to add a
29 * dynamic HTML table to a post or page that supports searching, pagination and sorting. Tables are created with
30 * jQuery DataTables.
31 *
32 * @author Peter Schulz
33 * @since 2.0.15
34 */
35 class WPDA_Publisher_Form extends WPDA_Simple_Form {
36 protected $hyperlinks = array();
37
38 protected $color = array();
39
40 protected $databases = array();
41
42 protected $cpts = array();
43
44 protected $cpts_non_selectable = array();
45
46 protected $cpts_selected = array();
47
48 protected $cfds = array();
49
50 protected $cfds_selectable = array();
51
52 protected $cfds_hidden = array();
53
54 protected $pub_data_source = 'Table';
55
56 /**
57 * WPDA_Publisher_Form constructor.
58 *
59 * @param string $schema_name Database schema name
60 * @param string $table_name Database table name
61 * @param object $wpda_list_columns Handle to instance of WPDA_List_Columns
62 * @param array $args
63 */
64 public function __construct(
65 $schema_name,
66 $table_name,
67 &$wpda_list_columns,
68 $args = array()
69 ) {
70 // Add column labels.
71 $args['column_headers'] = array(
72 'pub_id' => __( 'ID', 'wp-data-access' ),
73 'pub_name' => __( 'Name', 'wp-data-access' ),
74 'pub_schema_name' => __( 'Database', 'wp-data-access' ),
75 'pub_data_source' => __( 'Data Source', 'wp-data-access' ),
76 'pub_table_name' => __( 'Table/View Name', 'wp-data-access' ),
77 'pub_column_names' => __( 'Column Names (* = all)', 'wp-data-access' ),
78 'pub_format' => __( 'Column Labels', 'wp-data-access' ),
79 'pub_query' => __( '* Query', 'wp-data-access' ),
80 'pub_sort_icons' => __( 'Sort Icons', 'wp-data-access' ),
81 'pub_styles' => __( 'Styling', 'wp-data-access' ),
82 'pub_style_premium' => __( 'Enable Premium Styling', 'wp-data-access' ),
83 'pub_style_user' => __( 'Use Custom Style', 'wp-data-access' ),
84 'pub_style_color' => __( 'Color', 'wp-data-access' ),
85 'pub_style_space' => __( 'Spacing', 'wp-data-access' ),
86 'pub_style_corner' => __( 'Border Radius', 'wp-data-access' ),
87 'pub_style_modal_width' => __( 'Modal Width', 'wp-data-access' ),
88 'pub_responsive' => __( 'Output', 'wp-data-access' ),
89 'pub_responsive_popup_title' => __( 'Popup Title', 'wp-data-access' ),
90 'pub_responsive_cols' => __( 'Number Of Columns', 'wp-data-access' ),
91 'pub_responsive_type' => __( 'Type', 'wp-data-access' ),
92 'pub_responsive_modal_hyperlinks' => __( 'Hyperlinks On Modal', 'wp-data-access' ),
93 'pub_responsive_icon' => __( 'Show Icon', 'wp-data-access' ),
94 'pub_flat_scrollx' => __( 'Horizontal Scrollbar', 'wp-data-access' ),
95 'pub_default_where' => __( 'WHERE Clause', 'wp-data-access' ),
96 'pub_default_orderby' => __( 'Default Order By', 'wp-data-access' ),
97 'pub_table_options_searching' => __( 'Allow Searching?', 'wp-data-access' ),
98 'pub_table_options_ordering' => __( 'Allow Ordering?', 'wp-data-access' ),
99 'pub_table_options_paging' => __( 'Allow Paging?', 'wp-data-access' ),
100 'pub_table_options_serverside' => __( 'Server Side Processing?', 'wp-data-access' ),
101 'pub_table_options_nl2br' => __( 'NL > BR', 'wp-data-access' ),
102 'pub_table_options_advanced' => __( 'Advanced Options', 'wp-data-access' ),
103 'pub_extentions' => __( 'Extensions', 'wp-data-access' ),
104 'pub_cpt' => __( 'Post type', 'wp-data-access' ),
105 'pub_cpt_fields' => __( 'Custom fields', 'wp-data-access' ),
106 'pub_cpt_query' => __( 'CPT query', 'wp-data-access' ),
107 'pub_cpt_format' => __( 'Field labels', 'wp-data-access' ),
108 );
109 $this->check_table_type = false;
110 $this->title = 'Data Tables';
111 $args['help_url'] = 'https://docs.legacy.wpdataaccess.com/docs/data-tables-getting-started/';
112 parent::__construct(
113 $schema_name,
114 $table_name,
115 $wpda_list_columns,
116 $args
117 );
118 // Get available databases.
119 $schema_names = WPDA_Dictionary_Lists::get_db_schemas();
120 foreach ( $schema_names as $schema_name ) {
121 array_push( $this->databases, $schema_name['schema_name'] );
122 // phpcs:ignore -- 8.1 proof
123 }
124 // Add scripts and styles.
125 WPDA_Data_Tables::enqueue_styles_and_script();
126 }
127
128 /**
129 * Overwrites method add_buttons
130 */
131 public function add_buttons() {
132 $index = $this->get_item_index( 'pub_id' );
133 $pub_id_item = $this->form_items[$index];
134 $pub_id = $pub_id_item->get_item_value();
135 $disabled = ( 'new' === $this->action ? 'disabled' : '' );
136 ?>
137 <a href="javascript:void(0)"
138 onclick="test_publication()"
139 class="button wpda_tooltip <?php
140 echo esc_attr( $disabled );
141 ?>"
142 title="Test"
143 >
144 <i class="fas fa-bug wpda_icon_on_button"></i>
145 <?php
146 echo esc_attr__( 'Test', 'wp-data-access' );
147 ?>
148 </a>
149 <?php
150 $this->show_shortcode( $pub_id );
151 }
152
153 /**
154 * Overwrites method prepare_items
155 *
156 * @param bool $set_back_form_values
157 */
158 public function prepare_items( $set_back_form_values = false ) {
159 parent::prepare_items( $set_back_form_values );
160 $i = 0;
161 foreach ( $this->form_items as $form_item ) {
162 // Prepare listbox for column pub_schema_name
163 if ( $form_item->get_item_name() === 'pub_schema_name' ) {
164 if ( '' === $form_item->get_item_value() || null === $form_item->get_item_value() ) {
165 $form_item->set_item_value( WPDA::get_user_default_scheme() );
166 }
167 $form_item->set_enum( $this->databases );
168 $this->form_items[$i] = new WPDA_Simple_Form_Item_Enum($form_item);
169 }
170 if ( $form_item->get_item_name() === 'pub_sort_icons' ) {
171 $form_item->set_enum( array('Show', 'Hide') );
172 $form_item->set_enum_options( array('default', 'none') );
173 }
174 if ( $form_item->get_item_name() === 'pub_data_source' ) {
175 if ( null !== $form_item->get_item_value() ) {
176 $this->pub_data_source = $form_item->get_item_value();
177 }
178 }
179 // Prepare listbox for column pub_table_name
180 if ( $form_item->get_item_name() === 'pub_table_name' ) {
181 $this->form_items[$i] = new WPDA_Simple_Form_Item_Enum($form_item);
182 }
183 // Set default value for popup title.
184 if ( $form_item->get_item_name() === 'pub_responsive_popup_title' ) {
185 $form_item->set_item_default_value( __( 'Row details', 'wp-data-access' ) );
186 }
187 // Prepare listbox for column pub_responsive.
188 if ( $form_item->get_item_name() === 'pub_responsive' ) {
189 $form_item->set_enum( array('Responsive', 'Flat') );
190 $form_item->set_enum_options( array('Yes', 'No') );
191 }
192 // Prepare selection for column pub_column_names.
193 if ( $form_item->get_item_name() === 'pub_column_names' ) {
194 $title = __( 'Select columns shown in data table', 'wp-data-access' );
195 $form_item->set_item_hide_icon( true );
196 $form_item->set_item_js( 'jQuery("#pub_column_names").parent().parent().find("td.icon").append("<a id=\'select_columns\' class=\'button wpda_tooltip\' href=\'javascript:void(0)\' title=\'' . esc_attr( $title ) . '\' onclick=\'select_columns()\'>' . '<i class=\'fas fa-list wpda_icon_on_button\'></i> ' . __( 'Select', 'wp-data-access' ) . '</a>");' );
197 }
198 // Prepare column label settings.
199 if ( $form_item->get_item_name() === 'pub_format' ) {
200 $title = __( 'Define columns for data table (not necessary if already defined in Data Explorer table settings)', 'wp-data-access' );
201 $form_item->set_item_hide_icon( true );
202 $form_item->set_item_class( 'hide_item' );
203 $form_item->set_item_js( 'jQuery("#pub_format").parent().parent().find("td.data").append("<a id=\'format_columns\' class=\'button wpda_tooltip\' href=\'javascript:void(0)\' title=\'' . esc_attr( $title ) . '\' onclick=\'format_columns()\'>' . '<i class=\'fas fa-tag wpda_icon_on_button\'></i> ' . __( 'Click to define column labels', 'wp-data-access' ) . '</a>");' );
204 }
205 if ( 'pub_responsive_popup_title' === $form_item->get_item_name() || 'pub_responsive_cols' === $form_item->get_item_name() || 'pub_responsive_type' === $form_item->get_item_name() || 'pub_responsive_modal_hyperlinks' === $form_item->get_item_name() || 'pub_responsive_icon' === $form_item->get_item_name() || 'pub_flat_scrollx' === $form_item->get_item_name() ) {
206 $form_item->set_hide_item_init( true );
207 }
208 if ( 'pub_table_options_advanced' === $form_item->get_item_name() ) {
209 if ( '' === $form_item->get_item_value() || null === $form_item->get_item_value() ) {
210 $form_item->set_item_value( '{}' );
211 }
212 }
213 if ( 'pub_table_options_searching' === $form_item->get_item_name() || 'pub_table_options_ordering' === $form_item->get_item_name() || 'pub_table_options_paging' === $form_item->get_item_name() || 'pub_table_options_serverside' === $form_item->get_item_name() ) {
214 if ( 'pub_table_options_searching' !== $form_item->get_item_name() ) {
215 $form_item->set_hide_item_init( true );
216 }
217 $form_item->checkbox_value_on = 'on';
218 if ( 'new' === $this->action ) {
219 $form_item->set_item_value( 'on' );
220 }
221 $this->form_items[$i] = new WPDA_Simple_Form_Item_Boolean($form_item);
222 }
223 if ( 'pub_table_options_nl2br' === $form_item->get_item_name() ) {
224 $form_item->set_hide_item_init( true );
225 $form_item->checkbox_value_on = 'on';
226 $this->form_items[$i] = new WPDA_Simple_Form_Item_Boolean($form_item);
227 }
228 if ( $form_item->get_item_name() === 'pub_styles' ) {
229 $options = $form_item->get_item_enum();
230 $option_values = $options;
231 $option_values[0] = 'default = stripe + hover + order-column + row-border';
232 $form_item->set_enum( $option_values );
233 $form_item->set_enum_options( $options );
234 }
235 if ( 'pub_default_orderby' === $form_item->get_item_name() ) {
236 $form_item->set_item_hide_icon( true );
237 }
238 $i++;
239 }
240 }
241
242 protected function init_custom_fields() {
243 }
244
245 protected function add_fieldsets() {
246 $fields = array();
247 foreach ( $this->form_items as $item ) {
248 $fields[$item->get_item_name()] = true;
249 }
250 $data = array(
251 'pub_id',
252 'pub_name',
253 'pub_schema_name',
254 'pub_table_name',
255 'pub_column_names',
256 'pub_format'
257 );
258 $styling = array('pub_sort_icons', 'pub_styles');
259 $this->fieldsets = array(
260 'Publication Data' => array(
261 'id' => 'pub_main',
262 'fields' => $data,
263 ),
264 'Publication Type' => array(
265 'id' => 'pub_type',
266 'fields' => array(
267 'pub_responsive',
268 'pub_responsive_popup_title',
269 'pub_responsive_cols',
270 'pub_responsive_type',
271 'pub_responsive_modal_hyperlinks',
272 'pub_responsive_icon',
273 'pub_flat_scrollx'
274 ),
275 'expandable' => true,
276 ),
277 'Publication Styling' => array(
278 'id' => 'pub_styling',
279 'fields' => $styling,
280 'expandable' => true,
281 ),
282 );
283 $this->fieldsets['Advanced Settings'] = array(
284 'id' => 'pub_advanced',
285 'fields' => array(
286 'pub_default_where',
287 'pub_default_orderby',
288 'pub_table_options_searching',
289 'pub_table_options_ordering',
290 'pub_table_options_paging',
291 'pub_table_options_serverside',
292 'pub_table_options_nl2br',
293 'pub_table_options_advanced'
294 ),
295 'expandable' => true,
296 );
297 }
298
299 /**
300 * Overwrites method show
301 *
302 * @param bool $allow_save
303 * @param string $add_param
304 */
305 public function show( $allow_save = true, $add_param = '' ) {
306 parent::show( $allow_save, $add_param );
307 $index = $this->get_item_index( 'pub_id' );
308 $pub_id_item = $this->form_items[$index];
309 $pub_id = $pub_id_item->get_item_value();
310 $index = $this->get_item_index( 'pub_schema_name' );
311 $schema_name_item = $this->form_items[$index];
312 $schema_name = $schema_name_item->get_item_value();
313 global $wpdb;
314 $wpdb_name = $wpdb->dbname;
315 $index = $this->get_item_index( 'pub_table_name' );
316 $table_name_item = $this->form_items[$index];
317 $table_name = $table_name_item->get_item_value();
318 $table_columns = WPDA_List_Columns_Cache::get_list_columns( $schema_name, $table_name );
319 $columns = array();
320 foreach ( $table_columns->get_table_columns() as $table_column ) {
321 array_push( $columns, $table_column['column_name'] );
322 // phpcs:ignore -- 8.1 proof
323 }
324 $column_labels = $table_columns->get_table_column_headers();
325 $json_editing = WPDA::get_option( WPDA::OPTION_DP_JSON_EDITING );
326 $wpda_table_settings_db = WPDA_Table_Settings_Model::query( $table_name, $schema_name );
327 if ( isset( $wpda_table_settings_db[0]['wpda_table_settings'] ) ) {
328 $wpda_table_settings = json_decode( $wpda_table_settings_db[0]['wpda_table_settings'] );
329 if ( isset( $wpda_table_settings->hyperlinks ) ) {
330 foreach ( $wpda_table_settings->hyperlinks as $hyperlink ) {
331 $hyperlink_label = ( isset( $hyperlink->hyperlink_label ) ? $hyperlink->hyperlink_label : '' );
332 $hyperlink_html = ( isset( $hyperlink->hyperlink_html ) ? $hyperlink->hyperlink_html : '' );
333 if ( $hyperlink_label !== '' && $hyperlink_html !== '' ) {
334 array_push( $this->hyperlinks, $hyperlink_label );
335 // phpcs:ignore -- 8.1 proof
336 }
337 }
338 }
339 }
340 ?>
341 <style>
342 #pub_cpt_fields,
343 #pub_cpt_format,
344 #pub_default_orderby {
345 display: none;
346 }
347 table.wpda_simple_table td.icon a.button.wpda_tooltip {
348 width: 120px;
349 text-align: center;
350 }
351 span.pub_premium {
352 line-height: 40px;
353 }
354 span.pub_buttons {
355 float: right;
356 margin-top: 5px;
357 margin-bottom: 5px;
358 }
359 div.multiselect_sortable_content {
360 margin: 0 0 0 6px;
361 }
362 div.selection div.selection_title,
363 div.selectable div.selectable_title {
364 font-weight: bold;
365 }
366 div.selection ul.selection_content,
367 div.selectable ul.selectable_content {
368 background-color: white;
369 border: 1px solid #8c8f94;
370 border-radius: 4px;
371 height: 120px;
372 }
373 div.selection ul.selection_content li,
374 div.selectable ul.selectable_content li {
375 cursor: pointer;
376 padding: 0 10px;
377 margin: 0;
378 border: 0;
379 user-select: none;
380 }
381 div.selection ul.selection_content li:hover,
382 div.selectable ul.selectable_content li:hover {
383 font-weight: bold;
384 background-color: lightgrey;
385 }
386 select.multiselect_sortable_hide {
387 display: none;
388 }
389 .pub-post-types {
390 padding-top: 20px !important;
391 }
392 #manual_styling div {
393 display: grid;
394 grid-template-columns: 1fr 1fr 1fr 1fr;
395 gap: 10px;
396 width: 100%;
397 }
398 #manual_styling div span {
399 display: grid;
400 grid-template-rows: auto 1fr;
401 }
402 #manual_styling div span span {
403 display: grid;
404 grid-template-columns: 1fr auto;
405 }
406 </style>
407 <script type='text/javascript'>
408 let wpda_qb_columns = [];
409 let wpda_sp_columns = [];
410
411 let cpts_all = <?php
412 echo wp_json_encode( $this->cpts );
413 ?>;
414 let cpts_non_selectable = <?php
415 echo wp_json_encode( $this->cpts_non_selectable );
416 ?>;
417
418 let cfds_selected = <?php
419 echo wp_json_encode( $this->cfds );
420 ?>;
421 let cfds_selection = <?php
422 echo wp_json_encode( $this->cfds_selectable );
423 ?>;
424 let cfds_hidden = <?php
425 echo wp_json_encode( $this->cfds_hidden );
426 ?>;
427 let cfds_default_selectable = [];
428 let cfds_default_hidden = [];
429
430 function set_responsive_columns() {
431 if (jQuery('#pub_responsive').val() == 'Yes') {
432 // Show responsive settings
433 jQuery('#pub_responsive_popup_title').parent().parent().show();
434 jQuery('#pub_responsive_cols').parent().parent().show();
435 jQuery('#pub_responsive_type').parent().parent().show();
436 jQuery('#pub_responsive_modal_hyperlinks').parent().parent().show();
437 jQuery('#pub_responsive_icon').parent().parent().show();
438 jQuery('#pub_flat_scrollx').parent().parent().hide();
439 } else {
440 // Hide responsive settings
441 jQuery('#pub_responsive_popup_title').parent().parent().hide();
442 jQuery('#pub_responsive_cols').parent().parent().hide();
443 jQuery('#pub_responsive_type').parent().parent().hide();
444 jQuery('#pub_responsive_modal_hyperlinks').parent().parent().hide();
445 jQuery('#pub_responsive_icon').parent().parent().hide();
446 jQuery('#pub_flat_scrollx').parent().parent().show();
447 }
448 }
449
450 function get_selected_columns() {
451 let selectedColumns = table_columns;
452 let dataSource = "<?php
453 echo esc_attr( $this->pub_data_source );
454 ?>";
455 if (dataSource==="CPT") {
456 selectedColumns = cpt_fields;
457 } else if (dataSource==="Table") {
458 if (jQuery("#pub_column_names").val() !== "*") {
459 selectedColumns = jQuery("#pub_column_names").val().split(",");
460 }
461 }
462 return selectedColumns;
463 }
464
465 <?php
466 ?>
467
468 function pre_submit_form() {
469 // Simple form will automatically find and execute this function before the submit_form().
470 // Check column names
471 if (jQuery("#pub_column_names").val().trim()==="") {
472 jQuery("#pub_column_names").val("*");
473 }
474 // Process order by.
475 let defaultOrderBy = "";
476 jQuery(".wpda_dp_orderby").each(function() {
477 let index = jQuery(this).data("index");
478 let column = jQuery("#orderby" + index).val();
479 let order = jQuery("#order" + index).val();
480 if (column!=="") {
481 if (defaultOrderBy!=="") {
482 defaultOrderBy += "|";
483 }
484 defaultOrderBy += column;
485 if (order!=="") {
486 defaultOrderBy += "," + order;
487 }
488 }
489 });
490 jQuery("#pub_default_orderby").val(defaultOrderBy);
491
492 <?php
493 ?>
494
495 return true;
496 }
497
498 function getListValues(list) {
499 let values = [];
500 list.each(
501 function() {
502 values.push(jQuery(this).text());
503 }
504 );
505 return values;
506 }
507
508 function update_table_list(table_name = '') {
509 var url = location.pathname + '?action=wpda_get_tables';
510 var data = {
511 wpdaschema_name: jQuery("[name='pub_schema_name']").val(),
512 wpda_wpnonce: '<?php
513 echo esc_attr( wp_create_nonce( 'wpda-getdata-access-' . WPDA::get_current_user_login() ) );
514 ?>'
515 };
516 jQuery.post(
517 url,
518 data,
519 function (data) {
520 jQuery('[name="pub_table_name"]').empty();
521 var tables = JSON.parse(data);
522 for (var i = 0; i < tables.length; i++) {
523 jQuery('<option/>', {
524 value: tables[i].table_name,
525 html: tables[i].table_name
526 }).appendTo("[name='pub_table_name']");
527 }
528 if (table_name!=='') {
529 jQuery("[name='pub_table_name']").val(table_name);
530 } else {
531 jQuery('#pub_column_names').val('*');
532 jQuery('#pub_format').val('');
533 table_columns = [];
534 }
535 }
536 );
537 }
538
539 function updateWordPressDatabaseName() {
540 jQuery("#pub_schema_name option[value='<?php
541 echo esc_attr( $wpdb_name );
542 ?>']").text("WordPress database (<?php
543 echo esc_attr( $wpdb_name );
544 ?>)");
545 }
546
547 jQuery(function () {
548 updateWordPressDatabaseName();
549
550 pub_table_options_searching = jQuery('#pub_table_options_searching').parent().parent();
551 pub_table_options_ordering = jQuery('#pub_table_options_ordering').parent().parent().children();
552 pub_table_options_ordering_tr = jQuery(pub_table_options_ordering).parent().parent();
553 pub_table_options_paging = jQuery('#pub_table_options_paging').parent().parent().children();
554 pub_table_options_paging_tr = jQuery(pub_table_options_paging).parent().parent();
555 pub_table_options_serverside = jQuery('#pub_table_options_serverside').parent().parent().children();
556 pub_table_options_serverside_tr = jQuery(pub_table_options_serverside).parent().parent();
557 pub_table_options_nl2br = jQuery('#pub_table_options_nl2br').parent().parent().children();
558 pub_table_options_nl2br_tr = jQuery(pub_table_options_nl2br).parent().parent();
559
560 jQuery('<span style="width:10px;display:inline-block;"></span>').appendTo(pub_table_options_searching);
561 pub_table_options_ordering.appendTo(pub_table_options_searching);
562 jQuery('<span style="width:10px;display:inline-block;"></span>').appendTo(pub_table_options_searching);
563 pub_table_options_paging.appendTo(pub_table_options_searching);
564 jQuery('<span style="width:10px;display:inline-block;"></span>').appendTo(pub_table_options_searching);
565 pub_table_options_serverside.appendTo(pub_table_options_searching);
566 jQuery('<span style="width:10px;display:inline-block;"></span>').appendTo(pub_table_options_searching);
567 pub_table_options_nl2br.appendTo(pub_table_options_searching);
568
569 pub_table_options_ordering_tr.remove();
570 pub_table_options_paging_tr.remove();
571 pub_table_options_serverside_tr.remove();
572 pub_table_options_nl2br_tr.remove();
573
574 set_responsive_columns();
575
576 <?php
577 if ( WPDA::OPTION_DP_JSON_EDITING[1] === $json_editing ) {
578 ?>
579 var cm = wp.codeEditor.initialize(jQuery('#pub_table_options_advanced'), cm_settings);
580 <?php
581 }
582 ?>
583
584 jQuery("[name='pub_schema_name']").on('change', function () {
585 update_table_list();
586 });
587 update_table_list('<?php
588 echo esc_attr( $table_name );
589 ?>');
590
591 jQuery("[name='pub_table_name']").on('change', function () {
592 jQuery('#pub_column_names').val('*');
593 jQuery('#pub_format').val('');
594 table_columns = [];
595 });
596
597 <?php
598 ?>
599
600 jQuery('#pub_default_where').closest("tr").find('td.icon').empty().append('<i title="Enter a valid sql where clause, for example:\nfirst_name like \'Peter%\'" class="fas fa-circle-question pointer wpda_tooltip"></i>');
601 jQuery('#pub_table_options_searching').closest("tr").find('td.icon').empty().append('<i title="When paging is disabled, all rows are fetch on page load (this implicitly disables server side processing)\n\nEnable NL > BR to automatically convert New Lines to <BR> tags" class="fas fa-circle-question pointer wpda_tooltip"></i>');
602 jQuery('#pub_table_options_advanced').closest("tr").find('td.icon').empty().append('<i title=\'Must be valid JSON:\n{"option":"value","option2","value2"}\' class="fas fa-circle-question pointer wpda_tooltip"></i>');
603 jQuery('#pub_table_options_advanced').closest("tr").find('td.icon').append('<br/><a href="https://datatables.net/reference/option/" target="_blank" title="Click to check jQuery DataTables website for available\noptions (opens in a new tab or window)" class="dashicons dashicons-external wpda_tooltip" style="margin-top:5px;"></a>');
604 jQuery('#pub_styles').closest("tr").find('td.icon').empty().append('<i title="Hold control key to selected multiple" class="fas fa-circle-question pointer wpda_tooltip"></i>');
605
606 jQuery( '.wpda_tooltip' ).tooltip();
607 jQuery( '.wpda_tooltip_ic' ).tooltip({
608 tooltipClass: "wpda_tooltip_css_ic",
609 });
610
611 <?php
612 if ( 'view' === $this->action ) {
613 ?>
614 jQuery('#format_columns').prop("readonly", true).prop("disabled", true).addClass("disabled");
615 jQuery('#select_columns').prop("readonly", true).prop("disabled", true).addClass("disabled");
616 <?php
617 }
618 ?>
619
620 jQuery('#pub_responsive').on('change', function () {
621 set_responsive_columns();
622 });
623
624 // Add default order by UI.
625 jQuery("#pub_default_orderby").before(createOrderByLine(0));
626 // Restore default sorting.
627 let defaultSorting = jQuery("#pub_default_orderby").val();
628 let arraySorting = defaultSorting.split("|");
629 for (let i=0; i<arraySorting.length; i++) {
630 if (arraySorting[i]!=="") {
631 if (jQuery("#orderby" + i).length===0) {
632 // Add order by line.
633 jQuery("#pub_default_orderby").before(createOrderByLine(i));
634 }
635 let orderBy = arraySorting[i].split(",");
636 if (orderBy[0]!=="") {
637 jQuery("#orderby" + i).val(orderBy[0]);
638 jQuery("#order" + i).val(orderBy[1]);
639 }
640 }
641 }
642
643 <?php
644 ?>
645 });
646
647 let no_cols_selected = '* (= show all columns)';
648
649 let table_columns = [];
650 let cpt_fields = [];
651 <?php
652 foreach ( $columns as $column ) {
653 ?>
654 table_columns.push('<?php
655 echo esc_attr( $column );
656 ?>');
657 <?php
658 }
659 ?>
660
661 var hyperlinks = [];
662 <?php
663 if ( null !== $this->hyperlinks && is_array( $this->hyperlinks ) ) {
664 foreach ( $this->hyperlinks as $hyperlink ) {
665 // phpcs:disable WordPress.Security.EscapeOutput
666 echo "hyperlinks.push('{$hyperlink}');";
667 // phpcs:enable WordPress.Security.EscapeOutput
668 }
669 }
670 ?>
671
672 function select_available(e) {
673 var option = jQuery("#columns_available option:selected");
674 var add_to = jQuery("#columns_selected");
675
676 option.remove();
677 new_option = add_to.append(option);
678
679 if (jQuery("#columns_selected option[value='*']").length > 0) {
680 // Remove ALL from selected list.
681 jQuery("#columns_selected option[value='*']").remove();
682 }
683
684 jQuery('select#columns_selected option').prop("selected", false);
685 }
686
687 function select_selected() {
688 var option = jQuery("#columns_selected option:selected");
689 if (option[0].value === '*') {
690 // Cannot remove ALL.
691 return;
692 }
693
694 var add_to = jQuery("#columns_available");
695
696 option.remove();
697 add_to.append(option);
698
699 if (jQuery('select#columns_selected option').length === 0) {
700 jQuery("#columns_selected").append(jQuery('<option></option>').attr('value', '*').text(no_cols_selected));
701 }
702
703 jQuery('select#columns_available option').prop("selected", false);
704 }
705
706 function select_columns() {
707 if (!(Array.isArray(table_columns) && table_columns.length)) {
708 alert("<?php
709 echo esc_attr__( 'To select columns you need to save your data table first', 'wp-data-access' );
710 ?>");
711 return;
712 }
713
714 var columns_available = jQuery(
715 '<select id="columns_available" name="columns_available[]" multiple size="8" style="width:200px" onchange="select_available()">' +
716 '</select>'
717 );
718 jQuery.each(table_columns, function (i, val) {
719 columns_available.append(jQuery('<option></option>').attr('value', val).text(val));
720 });
721 for (let i=0; i<hyperlinks.length;i++) {
722 columns_available.append(jQuery('<option></option>').attr('value', 'wpda_hyperlink_' + i).text('Hyperlink: ' + hyperlinks[i]));
723 }
724
725 var currently_select_option = '';
726 var currently_select_values = jQuery('#pub_column_names').val();
727 if (currently_select_values == '*') {
728 currently_select_values = [];
729 } else {
730 currently_select_values = currently_select_values.split(',');
731 }
732 if (currently_select_values.length === 0) {
733 currently_select_option = '<option value="*">' + no_cols_selected + '</option>';
734 } else {
735 for (let i=0; i < currently_select_values.length; i++) {
736 if (currently_select_values[i].substr(0,15)==='wpda_hyperlink_') {
737 hyperlink_no = currently_select_values[i].substr(15);
738 if (hyperlink_no<hyperlinks.length) {
739 option_text = 'Hyperlink: ' + hyperlinks[hyperlink_no];
740 currently_select_option += '<option value="' + currently_select_values[i] + '">' + option_text + '</option>';
741 }
742 } else {
743 option_text = currently_select_values[i];
744 currently_select_option += '<option value="' + currently_select_values[i] + '">' + option_text + '</option>';
745 }
746 }
747 }
748
749 var columns_selected = jQuery(
750 '<select id="columns_selected" name="columns_selected[]" multiple size="8" style="width:200px" onchange="select_selected()">' +
751 currently_select_option +
752 '</select>'
753 );
754
755 var dialog_table = jQuery('<table style="width:410px"></table>');
756 var dialog_table_row = dialog_table.append(jQuery('<tr></tr>'));
757 dialog_table_row.append(jQuery('<td width="50%"></td>').append(columns_available));
758 dialog_table_row.append(jQuery('<td width="50%"></td>').append(columns_selected));
759
760 var dialog_text = jQuery('<div style="width:410px"></div>');
761 var dialog = jQuery('<div></div>');
762
763 dialog.append(dialog_text);
764 dialog.append(dialog_table);
765
766 jQuery(dialog).dialog(
767 {
768 dialogClass: 'wp-dialog no-close',
769 title: 'Add column(s) to data table',
770 modal: true,
771 autoOpen: true,
772 closeOnEscape: false,
773 resizable: false,
774 width: 'auto',
775 buttons: {
776 "OK": function () {
777 var selected_columns = '';
778 jQuery("#columns_selected option").each(
779 function () {
780 selected_columns += jQuery(this).val() + ',';
781 }
782 );
783 if (selected_columns !== '') {
784 selected_columns = selected_columns.slice(0, -1);
785 }
786 jQuery('#pub_column_names').val(selected_columns);
787 jQuery(this).dialog('destroy').remove();
788 },
789 "Cancel": function () {
790 jQuery(this).dialog('destroy').remove();
791 }
792 }
793 }
794 );
795
796 wpda_add_icons_to_dialog_buttons();
797
798 // Remove selected columns from available columns
799 for (let i = 0; i < currently_select_values.length; i++) {
800 jQuery("#columns_available option[value='" + currently_select_values[i] + "']").remove();
801 }
802 }
803
804 function format_cpt_columns() {
805 if (!(Array.isArray(cpt_fields) && cpt_fields.length)) {
806 alert("<?php
807 echo esc_attr__( 'To format columns you need to save your data table first', 'wp-data-access' );
808 ?>");
809 return;
810 }
811
812 let pub_cpt_format = null;
813 try {
814 pub_cpt_format = JSON.parse(jQuery('#pub_cpt_format').val());
815 } catch (e) {
816 pub_cpt_format = null;
817 }
818
819 let dialog_table = jQuery('<table></table>');
820 dialog_table.append(
821 jQuery('<tr></tr>').append(
822 jQuery('<th style="text-align:left;"><?php
823 echo esc_attr__( 'Field Name', 'wp-data-access' );
824 ?></th>'),
825 jQuery('<th style="text-align:left;"><?php
826 echo esc_attr__( 'Field Label', 'wp-data-access' );
827 ?></th>'),
828 )
829 );
830
831 for (let i=0; i<cpt_fields.length; i++) {
832 let label = cpt_fields[i];
833 try {
834 label = pub_cpt_format.cpt_format.cpt_labels[cpt_fields[i]];
835 } catch (e) {
836 label = cpt_fields[i];
837 }
838 dialog_table.append(
839 jQuery('<tr></tr>').append(
840 jQuery('<td style="text-align:left;">' + cpt_fields[i] + '</td>'),
841 jQuery('<td style="text-align:left;"><input type="text" class="cpt_label" name="' + cpt_fields[i] + '" value="' + label + '"></td>'),
842 )
843 );
844 }
845
846 let dialog_text = jQuery('<div></div>');
847 let dialog = jQuery('<div id="define_cpt_labels"></div>');
848
849 dialog.append(dialog_text);
850 dialog.append(dialog_table);
851
852 jQuery(dialog).dialog({
853 dialogClass: 'wp-dialog no-close',
854 title: 'Define field labels',
855 modal: true,
856 autoOpen: true,
857 closeOnEscape: false,
858 resizable: false,
859 width: 'auto',
860 buttons: {
861 "OK": function () {
862 // Create JSON from defined field labels
863 var cpt_labels = {};
864 jQuery("#define_cpt_labels input.cpt_label").each(
865 function () {
866 cpt_labels[jQuery(this).attr('name')] = jQuery(this).val();
867 }
868 );
869
870 // Write JSON to column pub_format
871 cpt_format = {
872 "cpt_format": {
873 "cpt_labels": cpt_labels
874 }
875 };
876 jQuery('#pub_cpt_format').val(JSON.stringify(cpt_format));
877 jQuery(this).dialog('destroy').remove();
878 },
879 "Cancel": function () {
880 jQuery(this).dialog('destroy').remove();
881 }
882 }
883 });
884
885 wpda_add_icons_to_dialog_buttons();
886 }
887
888 function format_columns() {
889 if (!(Array.isArray(table_columns) && table_columns.length)) {
890 alert("<?php
891 echo esc_attr__( 'To format columns you need to save your data table first', 'wp-data-access' );
892 ?>");
893 return;
894 }
895
896 var pub_format_json_string = jQuery('#pub_format').val();
897
898 var columns_labels = [];
899
900 if (pub_format_json_string !== '') {
901 // Use previously defined formatting
902 var pub_format = JSON.parse(pub_format_json_string);
903 if (typeof pub_format['pub_format']['column_labels'] !== 'undefined') {
904 columns_labels = pub_format['pub_format']['column_labels'];
905 }
906 } else {
907 // Get column labels from table settings
908 columns_labels = <?php
909 echo json_encode( $column_labels );
910 ?>;
911 }
912
913 var dialog_table = jQuery('<table></table>');
914 dialog_table.append(
915 jQuery('<tr></tr>').append(
916 jQuery('<th style="text-align:left;"><?php
917 echo esc_attr__( 'Column Name', 'wp-data-access' );
918 ?></th>'),
919 jQuery('<th style="text-align:left;"><?php
920 echo esc_attr__( 'Column Label', 'wp-data-access' );
921 ?></th>'),
922 )
923 );
924
925 <?php
926 foreach ( $table_columns->get_table_columns() as $table_column ) {
927 ?>
928 columns_label = '<?php
929 echo esc_attr( $table_column['column_name'] );
930 ?>';
931 if (typeof columns_labels !== 'undefined') {
932 if (columns_label in columns_labels) {
933 columns_label = columns_labels[columns_label];
934 }
935 }
936 dialog_table.append(
937 jQuery('<tr></tr>').append(
938 jQuery('<td style="text-align:left;"><?php
939 echo esc_attr( $table_column['column_name'] );
940 ?></td>'),
941 jQuery('<td style="text-align:left;"><input type="text" class="column_label" name="<?php
942 echo esc_attr( $table_column['column_name'] );
943 ?>" value="' + columns_label + '"></td>'),
944 )
945 );
946 <?php
947 }
948 ?>
949
950 var dialog_text = jQuery('<div></div>');
951 var dialog = jQuery('<div id="define_column_labels"></div>');
952
953 dialog.append(dialog_text);
954 dialog.append(dialog_table);
955
956 jQuery(dialog).dialog({
957 dialogClass: 'wp-dialog no-close',
958 title: 'Define column labels',
959 modal: true,
960 autoOpen: true,
961 closeOnEscape: false,
962 resizable: false,
963 width: 'auto',
964 buttons: {
965 "OK": function () {
966 // Create JSON from defined column labels
967 var column_labels = {};
968 jQuery('.column_label').each(
969 function () {
970 column_labels[jQuery(this).attr('name')] = jQuery(this).val();
971 }
972 );
973
974 // Write JSON to column pub_format
975 pub_format = {
976 "pub_format": {
977 "column_labels": column_labels
978 }
979 };
980 jQuery('#pub_format').val(JSON.stringify(pub_format));
981 jQuery(this).dialog('destroy').remove();
982 },
983 "Cancel": function () {
984 jQuery(this).dialog('destroy').remove();
985 }
986 }
987 });
988
989 wpda_add_icons_to_dialog_buttons();
990 }
991
992 function getQuery() {
993 url = location.pathname + '?action=wpda_query_builder_open_sql';
994 jQuery.ajax({
995 method: 'POST',
996 url: url,
997 data: {
998 wpda_wpnonce: "<?php
999 echo esc_attr( wp_create_nonce( 'wpda-query-builder-' . WPDA::get_current_user_id() ) );
1000 ?>",
1001 wpda_exclude: ""
1002 }
1003 }).done(
1004 function (msg) {
1005 if (!Array.isArray(msg.data)) {
1006 // Show queries
1007 list = jQuery("<ul/>");
1008 for (var queryName in msg.data) {
1009 dbs = msg.data[queryName].schema_name;
1010 qry = msg.data[queryName].query;
1011
1012 query = jQuery(`
1013 <div class="wpda-query-select">
1014 <div class="wpda-query-select-title ui-widget-header">
1015 ${queryName}
1016 <span class="fas fa-copy wpda-query-select-title-copy wpda_tooltip_left" title="Copy SQL"></span>
1017 </div>
1018 <div class="wpda-query-select-content">
1019 <textarea>${qry}</textarea>
1020 </div>
1021 </div>
1022 `);
1023 listitem = jQuery("<li/>").attr("data-dbs", dbs);
1024 listitem.append(query);
1025
1026 list.append(listitem);
1027 }
1028 dialog = jQuery("<div class='wpda-query'/>").attr("title", "Select from Query Builder");
1029 dialog.append(list);
1030 dialog.dialog({
1031 modal: true,
1032 resizable: false,
1033 width: "700px"
1034 });
1035 jQuery(".wpda_tooltip_left").tooltip({
1036 tooltipClass: "wpda_tooltip_dashboard",
1037 position: { my: "right top", at: "right bottom" }
1038 });
1039
1040 jQuery(".wpda-query-select-title-copy").on("click", function() {
1041 selectedDbs = jQuery(this).closest("li").data("dbs");
1042 selectedQuery = jQuery(this).closest("li").find("textarea").val();
1043
1044 jQuery("#pub_schema_name").val(selectedDbs);
1045 jQuery("#pub_query").val(selectedQuery);
1046
1047 jQuery(this).closest('.ui-dialog-content').dialog('close');
1048 });
1049 } else {
1050 // No queries found
1051 }
1052 }
1053 ).fail(
1054 function (msg) {
1055 console.log("WP Data Access error (getSQLFromQueryBuilder):", msg);
1056 }
1057 );
1058 }
1059
1060 function test_publication() {
1061 jQuery.ajax({
1062 type: "POST",
1063 url: "<?php
1064 echo esc_url( admin_url( 'admin-ajax.php?action=wpda_test_publication' ) );
1065 ?>",
1066 data: {
1067 wpnonce: "<?php
1068 echo esc_attr( wp_create_nonce( "wpda-publication-{$pub_id}" ) );
1069 ?>",
1070 pub_id: "<?php
1071 echo esc_attr( $pub_id );
1072 ?>"
1073 }
1074 }).done(
1075 function(html) {
1076 jQuery("body").append(html);
1077 jQuery('#data_publisher_test_container_<?php
1078 echo esc_html( $pub_id );
1079 ?>').show();
1080 }
1081 );
1082 }
1083
1084 function addOrderByColumn() {
1085 let index = 0;
1086 jQuery(".wpda_dp_orderby").each(function() {
1087 if (parseInt(jQuery(this).data("index"))>index) {
1088 index = parseInt(jQuery(this).data("index"));
1089 }
1090 });
1091 index++;
1092 jQuery("#pub_default_orderby").before(createOrderByLine(index));
1093 }
1094
1095 function removeOrderByColumn(elem) {
1096 elem.parent().remove();
1097 }
1098
1099 function createOrderByLine(index) {
1100 let selectedColumns = get_selected_columns();
1101
1102 let options = '<option value=""></option>';
1103 for (let i=0; i<selectedColumns.length; i++) {
1104 options += `<option value="${i}">${selectedColumns[i]}</option>`;
1105 }
1106 let columns = `<select id="orderby${index}">${options}</select>`;
1107
1108 let order = `<select id="order${index}"><option></option><option value="asc">Ascending</option><option value="desc">Descending</option></select>`;
1109
1110 let icon = "";
1111 if (index===0) {
1112 icon = `<i class="fas fa-plus-circle wpda_tooltip" title="Add column" onclick="addOrderByColumn()"></i>`;
1113 } else {
1114 icon = `<i class="fas fa-minus-circle wpda_tooltip" title="Remove column" onclick="removeOrderByColumn(jQuery(this))"></i>`;
1115 }
1116
1117 return `<div data-index="${index}" class="wpda_dp_orderby">${columns}${order}${icon}</div>`;
1118 }
1119 </script>
1120 <?php
1121 }
1122
1123 protected function show_shortcode( $pub_id ) {
1124 // Show data table shortcode directly from Data Tables main page
1125 $shortcode_enabled = 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_POST ) && 'on' === WPDA::get_option( WPDA::OPTION_PLUGIN_WPDATAACCESS_PAGE );
1126 ?>
1127 <div id="wpda_publication_<?php
1128 echo esc_attr( $pub_id );
1129 ?>"
1130 title="<?php
1131 echo esc_attr__( 'Shortcode', 'wp-data-access' );
1132 ?>"
1133 style="display:none"
1134 >
1135 <p class="wpda_shortcode_content">
1136 Copy the shortcode below into your post or page to make this data table available on your website.
1137 </p>
1138 <p class="wpda_shortcode_text">
1139 <strong>
1140 [wpdataaccess pub_id="<?php
1141 echo esc_attr( $pub_id );
1142 ?>"]
1143 </strong>
1144 </p>
1145 <p class="wpda_shortcode_buttons">
1146 <button class="button wpda_shortcode_clipboard wpda_shortcode_button"
1147 type="button"
1148 data-clipboard-text='[wpdataaccess pub_id="<?php
1149 echo esc_attr( $pub_id );
1150 ?>"]'
1151 onclick="jQuery.notify('<?php
1152 echo esc_attr__( 'Shortcode successfully copied to clipboard!', 'wp-data-access' );
1153 ?>','info')"
1154 >
1155 <?php
1156 echo esc_attr__( 'Copy', 'wp-data-access' );
1157 ?>
1158 </button>
1159 <button class="button button-primary wpda_shortcode_button"
1160 type="button"
1161 onclick="jQuery('.ui-dialog-content').dialog('close')"
1162 >
1163 <?php
1164 echo esc_attr__( 'Close', 'wp-data-access' );
1165 ?>
1166 </button>
1167 </p>
1168 <?php
1169 if ( !$shortcode_enabled ) {
1170 ?>
1171 <p>
1172 Shortcode wpdataaccess is not enabled for all output types.
1173 <a href="<?php
1174 echo esc_url( admin_url( 'options-general.php' ) );
1175 ?>?page=wpdataaccess" class="wpda_shortcode_link">&raquo; Manage settings</a>
1176 </p>
1177 <?php
1178 }
1179 ?>
1180 </div>
1181 <a href="javascript:void(0)"
1182 class="button view wpda_tooltip"
1183 title="<?php
1184 echo esc_attr__( 'Get shortcode', 'wp-data-access' );
1185 ?>"
1186 onclick="jQuery('#wpda_publication_<?php
1187 echo esc_attr( $pub_id );
1188 ?>').dialog()"
1189 >
1190 <span style="white-space:nowrap">
1191 <i class="fas fa-code wpda_icon_on_button"></i>
1192 <?php
1193 echo esc_attr__( 'Shortcode', 'wp-data-access' );
1194 ?>
1195 </span>
1196 </a>
1197 <?php
1198 WPDA::shortcode_popup();
1199 }
1200
1201 public static function test_publication() {
1202 $pub_id = ( isset( $_REQUEST['pub_id'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['pub_id'] ) ) : null );
1203 $wp_nonce = ( isset( $_REQUEST['wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ) : '' );
1204 // input var okay.
1205 $datatables_enabled = WPDA::get_option( WPDA::OPTION_BE_LOAD_DATATABLES ) === 'on';
1206 $datatables_responsive_enabled = WPDA::get_option( WPDA::OPTION_BE_LOAD_DATATABLES_RESPONSE ) === 'on';
1207 if ( !wp_verify_nonce( $wp_nonce, "wpda-publication-{$pub_id}" ) ) {
1208 $publication = '<strong>' . __( 'ERROR: Not authorized', 'wp-data-access' ) . '</strong>';
1209 } elseif ( null === $pub_id ) {
1210 $publication = '<strong>' . __( 'ERROR: Cannot test data table [wrong arguments]', 'wp-data-access' ) . '</strong>';
1211 } elseif ( !$datatables_enabled || !$datatables_responsive_enabled ) {
1212 $publication = '<strong>' . __( 'ERROR: Cannot test data table', 'wp-data-access' ) . '</strong><br/><br/>' . __( 'SOLUTION: Load jQuery DataTables: WP Data Access > Manage Plugin > Back-End Settings', 'wp-data-access' );
1213 } else {
1214 $wpda_data_tables = new WPDA_Data_Tables();
1215 $publication = $wpda_data_tables->show(
1216 $pub_id,
1217 '',
1218 '',
1219 '',
1220 '',
1221 '',
1222 '',
1223 '',
1224 '',
1225 ''
1226 );
1227 // , '', '', '', true );
1228 }
1229 ob_start();
1230 ?>
1231 <div id="data_publisher_test_container_<?php
1232 echo esc_html( $pub_id );
1233 ?>">
1234 <style>
1235 #data_publisher_test_header_<?php
1236 echo esc_html( $pub_id );
1237 ?> {
1238 height: 30px;
1239 background-color: #ccc;
1240 padding: 10px;
1241 margin-bottom: 10px;
1242 }
1243
1244 #data_publisher_test_header_<?php
1245 echo esc_html( $pub_id );
1246 ?> span strong {
1247 padding-top: 10px;
1248 font-size: 14px;
1249 vertical-align: middle;
1250 }
1251
1252 #data_publisher_test_container_<?php
1253 echo esc_html( $pub_id );
1254 ?> {
1255 display: none;
1256 padding: 10px;
1257 position: absolute;
1258 top: 30px;
1259 left: 10px;
1260 color: black;
1261 overflow-y: auto;
1262 background-color: white;
1263 border: 1px solid #ccc;
1264 width: calc(100% - 100px);
1265 z-index: 9999;
1266 }
1267
1268 #data_publisher_test_container_<?php
1269 echo esc_html( $pub_id );
1270 ?> thead input[type='search'],
1271 #data_publisher_test_container_<?php
1272 echo esc_html( $pub_id );
1273 ?> thead select,
1274 #data_publisher_test_container_<?php
1275 echo esc_html( $pub_id );
1276 ?> tfoot input[type='search'],
1277 #data_publisher_test_container_<?php
1278 echo esc_html( $pub_id );
1279 ?> tfoot select {
1280 padding-top: 5px;
1281 padding-bottom: 5px;
1282 }
1283
1284 #data_publisher_test_container_<?php
1285 echo esc_html( $pub_id );
1286 ?> .dataTables_filter {
1287 height: 42px;
1288 }
1289
1290 .dataTables_wrapper .dataTables_filter {
1291 height: 35px;
1292 }
1293 </style>
1294 <div id="data_publisher_test_header_<?php
1295 echo esc_attr( $pub_id );
1296 ?>">
1297 <span><strong><?php
1298 echo esc_attr__( 'Test', 'wp-data-access' );
1299 ?> (pub_id=<?php
1300 echo esc_attr( $pub_id );
1301 ?>
1302 - <?php
1303 echo esc_attr__( 'data table looks different on your website', 'wp-data-access' );
1304 ?>)
1305 </strong></span>
1306 <span class="button" style="float:right;"
1307 onclick="jQuery('#data_publisher_test_container_<?php
1308 echo esc_attr( $pub_id );
1309 ?>').hide(); jQuery('#data_publisher_test_container_<?php
1310 echo esc_attr( $pub_id );
1311 ?>').remove();">x</span><br/>
1312 </div>
1313 <?php
1314 // phpcs:disable WordPress.Security.EscapeOutput
1315 echo $publication;
1316 // phpcs:enable WordPress.Security.EscapeOutput
1317 ?>
1318 </div>
1319 <script type='text/javascript'>
1320 jQuery("#data_publisher_test_container_<?php
1321 echo esc_attr( $pub_id );
1322 ?>").appendTo("#wpbody-content");
1323 </script>
1324 <?php
1325 // phpcs:disable WordPress.Security.EscapeOutput
1326 echo ob_get_clean();
1327 // phpcs:enable WordPress.Security.EscapeOutput
1328 wp_die();
1329 }
1330
1331 }
1332