PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.40
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.40
5.5.85 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 All 161 releases
wp-data-access / WPDataAccess / Dashboard / WPDA_Dashboard.php

WPDA_Dashboard.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.40, at WPDataAccess/Dashboard/WPDA_Dashboard.php

2,256 lines 73.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:ignore Standard.Category.SniffName.ErrorCode
4 namespace WPDataAccess\Dashboard;
5
6 use WP_Data_Access_Admin;
7 use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists;
8 use WPDataAccess\Plugin_Table_Models\WPDA_Design_Table_Model;
9 use WPDataAccess\Plugin_Table_Models\WPDA_Publisher_Model;
10 use WPDataAccess\Plugin_Table_Models\WPDP_Project_Model;
11 use WPDataAccess\Premium\WPDAPRO_Dashboard\WPDAPRO_Dashboard;
12 use WPDataAccess\Premium\WPDAPRO_Dashboard\WPDAPRO_Widget_Project;
13 use WPDataAccess\Premium\WPDAPRO_Data_Forms\WPDAPRO_Data_Forms_Init;
14 use WPDataAccess\Utilities\WPDA_Message_Box;
15 use WPDataAccess\WPDA;
16 use WPDataAccess\Connection\WPDADB;
17 use WPDataProjects\WPDP;
18 use WPDataAccess\Settings\WPDA_Settings_Dashboard;
19 /**
20 * Dashboard class
21 */
22 class WPDA_Dashboard {
23 /**
24 * Nonce seed
25 */
26 const DASHBOARD_SAVE = 'WPDA_DASHBOARD_SAVE';
27
28 /**
29 * Nonce seed
30 */
31 const USER_DASHBOARD = 'wpda-user-dashboard-widgets';
32
33 /**
34 * Meta key
35 */
36 const USER_NEW_MESSAGE = 'wpda_new_dashboard_message';
37
38 /**
39 * Available dashboards
40 *
41 * @var array|null
42 */
43 protected $dashboards = null;
44
45 /**
46 * Number of dashboard columns
47 *
48 * @var int
49 */
50 protected $number_of_columns = 2;
51
52 /**
53 * Nonce for adding objects
54 *
55 * @var null
56 */
57 protected $wp_nonce_add = null;
58
59 /**
60 * Nonce for save actions
61 *
62 * @var null
63 */
64 protected $wp_nonce_save = null;
65
66 /**
67 * Current dashboard
68 *
69 * @var WPDAPRO_Dashboard|null
70 */
71 protected $dashboard = null;
72
73 /**
74 * Widgets on current dashboard
75 *
76 * @var array|null
77 */
78 protected $dashboard_widgets = null;
79
80 /**
81 * Dashboard positions of all visible objects
82 *
83 * @var array|null
84 */
85 protected $dashboard_positions = null;
86
87 /**
88 * Shared dashboards
89 *
90 * @var array
91 */
92 protected $shared_dashboards = array();
93
94 /**
95 * Dashboard access
96 *
97 * @var array
98 */
99 protected $shared_access = array();
100
101 /**
102 * Locked dashboards
103 *
104 * @var array
105 */
106 protected $shared_locked = array();
107
108 /**
109 * Locked dashboards
110 *
111 * @var array
112 */
113 protected $locked_dashboards = array();
114
115 /**
116 * Indicates if current user can create dashboards
117 *
118 * @var bool
119 */
120 protected $cannot_create_dashboard = false;
121
122 /**
123 * Available tabs on current dashboard
124 *
125 * @var string[]
126 */
127 protected $tabs = array('Default');
128
129 /**
130 * Current tabs
131 *
132 * @var int|mixed|string|null
133 */
134 protected $tab = 'Default';
135
136 /**
137 * Current tab label
138 *
139 * @var string
140 */
141 protected $tab_name = '';
142
143 /**
144 * Current tab index
145 *
146 * @var false|int|string
147 */
148 protected $tab_index = 0;
149
150 /**
151 * Indicates if default tab show be hidden
152 *
153 * @var bool
154 */
155 protected $hide_default_tab = false;
156
157 /**
158 * Indicates if dashboard is locked
159 *
160 * @var bool
161 */
162 protected $is_locked = false;
163
164 /**
165 * Message
166 *
167 * @var null
168 */
169 protected $message = null;
170
171 /**
172 * Message type
173 *
174 * @var string|null
175 */
176 protected $message_type = null;
177
178 private $current_version;
179
180 private $option_legacy_tools;
181
182 /**
183 * Constructor
184 *
185 * @param boolean $widget_mode True = allowed to manage dashboards and widgets.
186 */
187 public function __construct( $widget_mode = false ) {
188 if ( $widget_mode ) {
189 // Prepare nonces.
190 $this->wp_nonce_add = wp_create_nonce( WPDA_Widget::WIDGET_ADD . WPDA::get_current_user_login() );
191 $this->wp_nonce_save = wp_create_nonce( static::DASHBOARD_SAVE . WPDA::get_current_user_login() );
192 // Load Data Tables resources.
193 \WPDataAccess\Data_Tables\WPDA_Data_Tables::enqueue_styles_and_script();
194 }
195 $this->current_version = get_user_meta( WPDA::get_current_user_id(), 'wpda_data_explorer', true );
196 // Start with empty array.
197 if ( $widget_mode ) {
198 update_user_meta( WPDA::get_current_user_id(), self::USER_DASHBOARD, array() );
199 }
200 $this->option_legacy_tools = WPDA::get_option( WPDA::OPTION_PLUGIN_LEGACY_TOOLS );
201 }
202
203 /**
204 * Add dashboard
205 *
206 * @param boolean $widget_mode True = user is allowed to manage dashboards.
207 *
208 * @return void
209 */
210 public static function add_dashboard( $widget_mode = false ) {
211 $dashboard = new WPDA_Dashboard($widget_mode);
212 $dashboard->dashboard();
213 }
214
215 /**
216 * Construct plugin dashboard
217 *
218 * @return void
219 */
220 public function dashboard() {
221 wp_enqueue_style( 'wpdataaccess_dashboard' );
222 wp_enqueue_script( 'wpdataaccess_dashboard' );
223 if ( WPDA::current_user_is_admin() ) {
224 $this->dashboard_default();
225 $this->dashboard_mobile();
226 }
227 if ( isset( $_REQUEST['page'] ) ) {
228 // phpcs:ignore WordPress.Security.NonceVerification
229 switch ( $_REQUEST['page'] ) {
230 // phpcs:ignore WordPress.Security.NonceVerification
231 case 'wpda_dashboard':
232 $this->toolbar();
233 $this->add_forms();
234 $this->tabs();
235 $this->columns();
236 $this->add_panels();
237 $this->dashboard_js();
238 break;
239 case WP_Data_Access_Admin::PAGE_MAIN:
240 if ( !isset( $_REQUEST['page_action'] ) ) {
241 // phpcs:ignore WordPress.Security.NonceVerification
242 if ( !isset( $_REQUEST['table_name'] ) ) {
243 // phpcs:ignore WordPress.Security.NonceVerification
244 $this->toolbar_wpda();
245 } else {
246 if ( !isset( $_REQUEST['action'] ) || 'new' !== $_REQUEST['action'] && 'edit' !== $_REQUEST['action'] ) {
247 $this->toolbar_wpda_table();
248 } else {
249 $this->toolbar_wpda_row();
250 }
251 }
252 } elseif ( 'wpda_backup' === $_REQUEST['page_action'] && (!isset( $_REQUEST['action'] ) || 'remove' === $_REQUEST['action'] || 'update' === $_REQUEST['action'] || 'add' === $_REQUEST['action']) ) {
253 // phpcs:ignore WordPress.Security.NonceVerification
254 $this->toolbar_backup();
255 } elseif ( 'wpda_import_csv' === $_REQUEST['page_action'] ) {
256 // phpcs:ignore WordPress.Security.NonceVerification
257 $this->toolbar_import_csv();
258 }
259 break;
260 case WP_Data_Access_Admin::PAGE_APPS:
261 $this->toolbar_apps();
262 break;
263 case WP_Data_Access_Admin::PAGE_QUERY_BUILDER:
264 $this->toolbar_sql();
265 break;
266 case WP_Data_Access_Admin::PAGE_DESIGNER:
267 if ( !isset( $_REQUEST['action'] ) || 'new' !== $_REQUEST['action'] && 'edit' !== $_REQUEST['action'] ) {
268 $this->toolbar_designer();
269 }
270 break;
271 case WP_Data_Access_Admin::PAGE_PUBLISHER:
272 if ( (!isset( $_REQUEST['action'] ) || 'new' !== $_REQUEST['action'] && 'edit' !== $_REQUEST['action'] || isset( $_REQUEST['postaction'] ) && 'list' === $_REQUEST['postaction']) && !(isset( $_REQUEST['page_action'] ) && 'wpda_mngstl' === $_REQUEST['page_action']) ) {
273 $this->toolbar_publisher();
274 }
275 break;
276 case WP_Data_Access_Admin::PAGE_CHARTS:
277 $this->toolbar_charts();
278 break;
279 case WPDP::PAGE_MAIN:
280 if ( !isset( $_REQUEST['action'] ) || 'new' !== $_REQUEST['action'] && 'edit' !== $_REQUEST['action'] ) {
281 $this->toolbar_projects();
282 }
283 break;
284 case WPDP::PAGE_TEMPLATES:
285 if ( !isset( $_REQUEST['action'] ) || 'new' !== $_REQUEST['action'] && 'edit' !== $_REQUEST['action'] ) {
286 $this->toolbar_templates();
287 }
288 break;
289 }
290 }
291 if ( isset( $_GET['page_iaction'] ) ) {
292 // Perform interactive action to auto start user selected feature.
293 ?>
294 <script>
295 jQuery(function() {
296 const iaction = "<?php
297 echo esc_attr( sanitize_text_field( $_GET['page_iaction'] ) );
298 ?>";
299 switch (iaction) {
300 case "create_new_app":
301 var interval = setInterval(
302 function() {
303 if (window.ppActionCreateApp !== undefined) {
304 window.ppActionCreateApp();
305 clearInterval(interval);
306 }
307 }, 100);
308 break;
309 case "wpda_import_sql":
310 var interval = setInterval(
311 function() {
312 if (window.ppActionEnableImport !== undefined) {
313 window.ppActionEnableImport();
314 clearInterval(interval);
315 }
316 }, 100);
317 break;
318 case "manage_databases":
319 jQuery('#wpda_manage_databases').show();
320 jQuery('#local_database').focus();
321 break;
322 }
323 });
324 </script>
325 <?php
326 }
327 }
328
329 /**
330 * Get correct help url for current page
331 *
332 * @return string
333 */
334 protected function get_help_url() {
335 $help_root = 'https://wpdataaccess.com/docs/';
336 if ( isset( $_REQUEST['page'] ) ) {
337 // phpcs:ignore WordPress.Security.NonceVerification
338 switch ( $_REQUEST['page'] ) {
339 // phpcs:ignore WordPress.Security.NonceVerification
340 case \WP_Data_Access_Admin::PAGE_MAIN:
341 $help_url = $help_root . 'data-explorer/data-explorer-getting-started/';
342 break;
343 case \WP_Data_Access_Admin::PAGE_QUERY_BUILDER:
344 $help_url = $help_root . 'sql-query-builder/query-builder-getting-started/';
345 break;
346 case \WP_Data_Access_Admin::PAGE_DESIGNER:
347 $help_url = $help_root . 'data-designer/data-designer-getting-started/';
348 break;
349 case \WP_Data_Access_Admin::PAGE_PUBLISHER:
350 $help_url = $help_root . 'data-tables/data-tables-getting-started/';
351 break;
352 case \WP_Data_Access_Admin::PAGE_DASHBOARD:
353 $help_url = $help_root . 'dashboards-and-widgets/bi-getting-started/';
354 break;
355 case \WP_Data_Access_Admin::PAGE_CHARTS:
356 $help_url = $help_root . 'charts-legacy/chart-widgets/';
357 break;
358 case WPDP::PAGE_MAIN:
359 $help_url = $help_root . 'data-forms/data-projects/';
360 break;
361 case WPDP::PAGE_TEMPLATES:
362 $help_url = $help_root . 'templates/project-templates/';
363 break;
364 case 'wpdataaccess':
365 $current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' );
366 // phpcs:ignore WordPress.Security.NonceVerification
367 switch ( $current_tab ) {
368 case 'backend':
369 $help_url = $help_root . 'plugin-settings/back-end/';
370 break;
371 case 'frontend':
372 $help_url = $help_root . 'plugin-settings/front-end/';
373 break;
374 case 'pds':
375 $help_url = $help_root . 'remote-connection-wizard/start-here/';
376 break;
377 case 'dashboard':
378 $help_url = $help_root . 'plugin-settings/dashboard/';
379 break;
380 case 'datatables':
381 $help_url = $help_root . 'plugin-settings/data-table/';
382 break;
383 case 'dataforms':
384 $help_url = $help_root . 'plugin-settings/data-form/';
385 break;
386 case 'databackup':
387 $help_url = $help_root . 'plugin-settings/data-backup/';
388 break;
389 case 'uninstall':
390 $help_url = $help_root . 'plugin-settings/uninstall/';
391 break;
392 case 'repository':
393 $help_url = $help_root . 'plugin-settings/manage-repository/';
394 break;
395 case 'roles':
396 $help_url = $help_root . 'plugin-settings/manage-roles/';
397 break;
398 case 'system':
399 $help_url = $help_root . 'plugin-settings/system-info/';
400 break;
401 default:
402 $help_url = $help_root . 'plugin-settings/getting-started/';
403 }
404 break;
405 default:
406 $help_url = $help_root . 'tool-guide/wp-data-access-getting-started/';
407 }
408 } else {
409 $help_url = $help_root . 'tool-guide/wp-data-access-getting-started/';
410 }
411 return $help_url;
412 }
413
414 /**
415 * Construct default dashboard
416 *
417 * @return void
418 */
419 protected function dashboard_default() {
420 ?>
421 <div id="wpda-dashboard" style="display:none">
422 <div class="wpda-dashboard">
423 <div class="wpda-dashboard-group wpda-dashboard-group-administration">
424 <div class="icons">
425 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
426 echo admin_url( 'admin.php' );
427 // phpcs:ignore WordPress.Security.EscapeOutput
428 ?>?page=wpda_navi" title="Quick links and frequently asked questions">
429 <div class="fa-solid fa-house"></div>
430 <div class="label">Tool Guide</div>
431 </a>
432 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
433 echo admin_url( 'admin.php' );
434 // phpcs:ignore WordPress.Security.EscapeOutput
435 ?>?page=wpda_apps" title="Build data-driven Apps with the new
436 Table Builder, Form Builder and Chart Builder">
437 <div class="fa-solid">
438 <svg xmlns="http://www.w3.org/2000/svg" height="26px" width="26px" viewBox="4 4 16 16" fill="inherit">
439 <path d="M4 8h4V4H4v4zm6 12h4v-4h-4v4zm-6 0h4v-4H4v4zm0-6h4v-4H4v4zm6 0h4v-4h-4v4zm6-10v4h4V4h-4zm-6 4h4V4h-4v4zm6 6h4v-4h-4v4zm0 6h4v-4h-4v4z"/>
440 </svg>
441 </div>
442 <div class="label">App Builder</div>
443 </a>
444 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
445 echo admin_url( 'admin.php' );
446 // phpcs:ignore WordPress.Security.EscapeOutput
447 ?>?page=wpda" title="Data Explorer
448
449 Manage local and remote data and databases">
450 <div class="fa-solid fa-database"></div>
451 <div class="label">Explorer</div>
452 </a>
453 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
454 echo admin_url( 'admin.php' );
455 // phpcs:ignore WordPress.Security.EscapeOutput
456 ?>?page=wpda_query_builder" title="SQL Query Builder">
457 <div class="fa-solid fa-code"></div>
458 <div class="label">SQL</div>
459 </a>
460 </div>
461 <div class="subject">Data(base) Administration & App Development</div>
462 </div>
463 <div class="wpda-dashboard-group wpda-dashboard-group-projects"
464 <?php
465 if ( !$this->option_legacy_tools['tables'][0] && !$this->option_legacy_tools['forms'][0] && !$this->option_legacy_tools['templates'][0] && !$this->option_legacy_tools['designer'][0] && !$this->option_legacy_tools['dashboards'][0] && !$this->option_legacy_tools['charts'][0] ) {
466 echo 'style="display: none"';
467 }
468 ?>
469 >
470 <div class="icons">
471 <a class="wpda-dashboard-item wpda_tooltip_icons"
472 href="<?php
473 echo admin_url( 'admin.php' );
474 // phpcs:ignore WordPress.Security.EscapeOutput
475 ?>?page=wpda_publisher"
476 title="OLD Table Builder
477
478 Use App Builder to access the NEW Table Builder
479 "
480 <?php
481 if ( !$this->option_legacy_tools['tables'][0] ) {
482 echo 'style="display: none"';
483 }
484 ?>
485 >
486 <div class="fa-solid fa-table"></div>
487 <div class="label">Tables</div>
488 </a>
489 <a class="wpda-dashboard-item wpda_tooltip_icons"
490 href="<?php
491 echo admin_url( 'admin.php' );
492 // phpcs:ignore WordPress.Security.EscapeOutput
493 ?>?page=wpda_wpdp"
494 title="OLD Form Builder
495
496 Use App Builder to access the NEW Form Builder
497 "
498 <?php
499 if ( !$this->option_legacy_tools['forms'][0] ) {
500 echo 'style="display: none"';
501 }
502 ?>
503 >
504 <div class="fa-solid fa-wand-magic-sparkles"></div>
505 <div class="label">Forms</div>
506 </a>
507 <a class="wpda-dashboard-item wpda_tooltip_icons"
508 href="<?php
509 echo admin_url( 'admin.php' );
510 // phpcs:ignore WordPress.Security.EscapeOutput
511 ?>?page=wpda_templates"
512 title="OLD Form Templates
513
514 Customize forms using templates"
515 <?php
516 if ( !$this->option_legacy_tools['templates'][0] ) {
517 echo 'style="display: none"';
518 }
519 ?>
520 >
521 <div class="fa-solid fa-desktop"></div>
522 <div class="label">Templates</div>
523 </a>
524 <a class="wpda-dashboard-item wpda_tooltip_icons"
525 href="<?php
526 echo admin_url( 'admin.php' );
527 // phpcs:ignore WordPress.Security.EscapeOutput
528 ?>?page=wpda_designer"
529 title="Create database tables and indexes"
530 <?php
531 if ( !$this->option_legacy_tools['designer'][0] ) {
532 echo 'style="display: none"';
533 }
534 ?>
535 >
536 <div class="fa-solid fa-drafting-compass"></div>
537 <div class="label">Designer</div>
538 </a>
539 <?php
540 ?>
541 </div>
542 <div class="subject">Legacy Tools</div>
543 </div>
544 <div class="wpda-dashboard-group wpda-dashboard-group-settings">
545 <div class="icons">
546 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
547 echo admin_url( 'options-general.php' );
548 // phpcs:ignore WordPress.Security.EscapeOutput
549 ?>?page=wpdataaccess" title="Manage plugin user interface and behavior">
550 <div class="fa-solid fa-cog"></div>
551 <div class="label">Settings</div>
552 </a>
553 <?php
554 if ( wpda_freemius()->is_registered() ) {
555 ?>
556 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
557 echo admin_url( 'admin.php' );
558 // phpcs:ignore WordPress.Security.EscapeOutput
559 ?>?page=<?php
560 echo esc_attr( WP_Data_Access_Admin::MAIN_PAGE_SLUG );
561 ?>-account" title="Manage your WP Data Access account">
562 <div class="fa-solid fa-user"></div>
563 <div class="label">Account</div>
564 </a>
565 <?php
566 }
567 ?>
568 <a class="wpda-dashboard-item wpda_tooltip_icons" target="_blank" href="https://wpdataaccess.com/pricing/" title="Pricing, licensing and ordering">
569 <div class="fa-solid fa-hand-holding-usd"></div>
570 <div class="label">Pricing</div>
571 </a>
572 <a class="wpda-dashboard-item wpda_tooltip_icons" href="<?php
573 echo admin_url( 'admin.php' );
574 // phpcs:ignore WordPress.Security.EscapeOutput
575 ?>?page=<?php
576 echo esc_attr( WP_Data_Access_Admin::MAIN_PAGE_SLUG );
577 ?>-pricing" title="Upgrade your WP Data Access account">
578 <div class="fa-solid fa-gem"></div>
579 <div class="label">Upgrade</div>
580 </a>
581 </div>
582 <div class="subject">Plugin & User Management</div>
583 </div>
584 <div class="wpda-dashboard-group wpda-dashboard-group-support">
585 <div class="icons">
586 <a class="wpda-dashboard-item wpda_tooltip_icons" target="_blank" href="<?php
587 echo $this->get_help_url();
588 // phpcs:ignore WordPress.Security.EscapeOutput
589 ?>" title="Online help and documentation">
590 <div class="fa-solid fa-question-circle"></div>
591 <div class="label">Docs</div>
592 </a>
593 <a class="wpda-dashboard-item wpda_tooltip_icons" target="_blank" href="https://wordpress.org/support/plugin/wp-data-access/" title="Public support forum">
594 <div class="fa-solid fa-life-ring"></div>
595 <div class="label">Forum</div>
596 </a>
597 <?php
598 ?>
599 </div>
600 <div class="subject">Help</div>
601 </div>
602 </div>
603 </div>
604 <?php
605 }
606
607 /**
608 * Construct mobile dashboard
609 *
610 * @return void
611 */
612 protected function dashboard_mobile() {
613 $premium_separator = 'wpda-separator';
614 ?>
615 <div id="wpda-dashboard-mobile" style="display:none">
616 <div id="wpda-dashboard-drop-down">
617 <div class="wpda_nav_toggle" onclick="toggleMenu()"><i class="fas fa-bars"></i></div>
618 <div class="wpda_nav_title">WP Data Access</div>
619 </div>
620 <ul>
621 <li class="menu-item"><a href="<?php
622 echo admin_url( 'admin.php' );
623 // phpcs:ignore WordPress.Security.EscapeOutput
624 ?>?page=wpda"><i class="fas fa-database"></i> Explorer</a></li>
625 <li class="menu-item"><a href="<?php
626 echo admin_url( 'admin.php' );
627 // phpcs:ignore WordPress.Security.EscapeOutput
628 ?>?page=wpda_query_builder"><i class="fas fa-code"></i> SQL</a></li>
629 <li class="menu-item wpda-separator"><a href="<?php
630 echo admin_url( 'admin.php' );
631 // phpcs:ignore WordPress.Security.EscapeOutput
632 ?>?page=wpda_designer"><i class="fas fa-drafting-compass"></i> Designer</a></li>
633 <li class="menu-item wpda-separator"><a href="<?php
634 echo admin_url( 'admin.php' );
635 // phpcs:ignore WordPress.Security.EscapeOutput
636 ?>?page=wpda_apps"><span style="display: inline-block; width: 20px"><svg xmlns="http://www.w3.org/2000/svg" height="12px" width="12px" viewBox="4 4 16 16" fill="inherit">
637 <path d="M4 8h4V4H4v4zm6 12h4v-4h-4v4zm-6 0h4v-4H4v4zm0-6h4v-4H4v4zm6 0h4v-4h-4v4zm6-10v4h4V4h-4zm-6 4h4V4h-4v4zm6 6h4v-4h-4v4zm0 6h4v-4h-4v4z"/>
638 </svg></span> Apps</a></li>
639 <?php
640 ?>
641 <li class="menu-item <?php
642 echo esc_attr( $premium_separator );
643 ?>"><a href="<?php
644 echo admin_url( 'admin.php' );
645 // phpcs:ignore WordPress.Security.EscapeOutput
646 ?>?page=wpda_publisher"><i class="fas fa-address-card"></i> Tables</a></li>
647 <?php
648 ?>
649 <li class="menu-item"><a href="<?php
650 echo admin_url( 'admin.php' );
651 // phpcs:ignore WordPress.Security.EscapeOutput
652 ?>?page=wpda_wpdp"><i class="fas fa-magic"></i> Forms</a></li>
653 <li class="menu-item wpda-separator"><a href="<?php
654 echo admin_url( 'admin.php' );
655 // phpcs:ignore WordPress.Security.EscapeOutput
656 ?>?page=wpda_templates"><i class="fas fa-desktop"></i> Templates</a></li>
657 <li class="menu-item"><a href="<?php
658 echo admin_url( 'options-general.php' );
659 // phpcs:ignore WordPress.Security.EscapeOutput
660 ?>?page=wpdataaccess"><i class="fas fa-cog"></i> Settings</a></li>
661 <?php
662 if ( wpda_freemius()->is_registered() ) {
663 ?>
664 <li class="menu-item"><a href="<?php
665 echo admin_url( 'admin.php' );
666 // phpcs:ignore WordPress.Security.EscapeOutput
667 ?>?page=<?php
668 echo esc_attr( WP_Data_Access_Admin::MAIN_PAGE_SLUG );
669 ?>-account"><i class="fas fa-user"></i> Account</a></li>
670 <?php
671 }
672 ?>
673 <?php
674 $menufound = false;
675 global $submenu;
676 if ( isset( $submenu[WPDA::get_option( WP_Data_Access_Admin::PAGE_MAIN )] ) ) {
677 foreach ( $submenu[WPDA::get_option( WP_Data_Access_Admin::PAGE_MAIN )] as $pluginmenu ) {
678 if ( WP_Data_Access_Admin::MAIN_PAGE_SLUG . '-pricing' === $pluginmenu[2] ) {
679 $menufound = true;
680 break;
681 }
682 }
683 }
684 ?>
685 <li class="menu-item <?php
686 echo ( $menufound ? '' : 'wpda-separator' );
687 ?>"><a href="https://wpdataaccess.com/pricing/" target="_blank"><i class="fas fa-hand-holding-usd"></i> Pricing</a></li>
688 <?php
689 if ( $menufound ) {
690 ?>
691 <li class="menu-item wpda-separator"><a href="<?php
692 echo admin_url( 'admin.php' );
693 // phpcs:ignore WordPress.Security.EscapeOutput
694 ?>?page=<?php
695 echo esc_attr( WP_Data_Access_Admin::MAIN_PAGE_SLUG );
696 ?>-pricing"><i class="fas fa-gem"></i> Upgrade</a></li>
697 <?php
698 }
699 ?>
700 <li class="menu-item"><a target="_blank" href="https://wpdataaccess.com/docs/tool-guide/wp-data-access-getting-started/"><i class="fas fa-question"></i> Online Documentation</a></li>
701 <li class="menu-item"><a target="_blank" href="https://wordpress.org/support/plugin/wp-data-access/"><i class="fas fa-life-ring"></i> Support Forum</a></li>
702 <?php
703 ?>
704 </ul>
705 </div>
706 <?php
707 }
708
709 /**
710 * Add dashboard tabs
711 *
712 * @return void
713 */
714 protected function tabs() {
715 }
716
717 /**
718 * Construct toolbar
719 *
720 * @return void
721 */
722 protected function toolbar() {
723 if ( $this->cannot_create_dashboard ) {
724 return;
725 }
726 $remove_columns_message = __( 'Remove columns outside of range? Widgets will no longer be available!', 'wp-data-access' );
727 ?>
728 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
729 <div class="wpda-nowrap">
730 <div>
731 <?php
732 if ( WPDA::current_user_is_admin() ) {
733 ?>
734 <div>
735 <a href="javascript:addPanel()"
736 class="wpda-dashboard-item wpda_tooltip"
737 title="Create new widget"
738 >
739 <i class="fas fa-folder-plus"></i>
740 <div>
741 Create widget
742 </div>
743 </a>
744 </div>
745 <?php
746 }
747 ?>
748 </div>
749 </div>
750 <div>
751 <?php
752 $this->get_promotions( 'toolbar' );
753 ?>
754 </div>
755 <div style="white-space:nowrap">
756 <div>
757 <div>
758 <a href="javascript:removeColumns(1)"
759 class="wpda-dashboard-item wpda_tooltip"
760 title="One column"
761 >
762 <i class="fas fa-dice-one"></i>
763 <div>
764 1 column
765 </div>
766 </a>
767 </div><div>
768 <a href="javascript:removeColumns(2); addColumns(2)"
769 class="wpda-dashboard-item wpda_tooltip"
770 title="Switch to two column layout"
771 >
772 <i class="fas fa-dice-two"></i>
773 <div>
774 2 columns
775 </div>
776 </a>
777 </div><div>
778 <a href="javascript:removeColumns(3); addColumns(3)"
779 class="wpda-dashboard-item wpda_tooltip"
780 title="Switch to three column layout"
781 >
782 <i class="fas fa-dice-three"></i>
783 <div>
784 3 columns
785 </div>
786 </a>
787 </div><div>
788 <a href="javascript:addColumns(4)"
789 class="wpda-dashboard-item wpda_tooltip"
790 title="Switch to four column layout"
791 >
792 <i class="fas fa-dice-four"></i>
793 <div>
794 4 columns
795 </div>
796 </a>
797 </div>
798 </div>
799 </div>
800 </div>
801 <?php
802 if ( wpda_freemius()->is_free_plan() ) {
803 ?>
804 <div class="wpda_dashboard_free_message">
805 <table>
806 <tr>
807 <td style="text-align:left">
808 The free version of WP Data Access has limited dashboard support.
809 Data Widgets can be added and moved, but not saved or shared.
810 Update to premium to analyse, report and share your data.
811 </td>
812 <td style="white-space:nowrap">
813 <a href="https://wpdataaccess.com/pricing/" target="_blank" class="button button-primary">UPGRADE TO PREMIUM</a>
814 <a href="https://wpdataaccess.com/docs/dashboards-and-widgets/bi-getting-started/" target="_blank" class="button">READ MORE</a>
815 </td>
816 </tr>
817 </table>
818 </div>
819 <?php
820 }
821 ?>
822 <script type="application/javascript">
823 function manageTabs() {
824 closePanel();
825 jQuery("#wpda-manage-tabs").show();
826 }
827 function noColumns() {
828 return jQuery(".wpda-dashboard-column").length;
829 }
830 function addColumns(colNum) {
831 if (noColumns()<colNum) {
832 for (var i=noColumns()+1; i<=colNum; i++) {
833 jQuery("#wpda-dashboard-content").append('<div id="wpda-dashboard-column-' + i + '" class="wpda-dashboard-column wpda-dashboard-column-' + i + '"></div>');
834 }
835 refreshPanels(colNum);
836 resetColumnSelection();
837 makeSortable();
838 saveDashBoard();
839 }
840 }
841 function removeColumns(colNum) {
842 if (noColumns()>colNum) {
843 if (confirm("<?php
844 echo esc_html( $remove_columns_message );
845 ?>")) {
846 noCols = noColumns();
847 for (var i=colNum+1; i<=noCols; i++) {
848 jQuery("#wpda-dashboard-column-" + i).remove();
849 }
850 refreshPanels(colNum);
851 makeSortable();
852 saveDashBoard();
853 }
854 }
855 }
856 function refreshPanels(colNum) {
857 for (var i=1; i<=4; i++) {
858 jQuery(".wpda-dashboard-column").removeClass("wpda-dashboard-column-" + i);
859 }
860 jQuery(".wpda-dashboard-column").addClass("wpda-dashboard-column-" + colNum);
861 refreshAllPanels();
862 }
863 jQuery(function(){
864 jQuery("#wpda_delete_new_dashboard_message").on("click", function() {
865 if (confirm("Remove message and link? This cannot be undone!")) {
866 jQuery.ajax({
867 type: "POST",
868 url: wpda_ajaxurl + "?action=wpda_remove_new_dashboard_message",
869 data: {
870 wp_nonce: wpda_wpnonce_save
871 }
872 }).done(
873 function(data) {
874 if (data==="OK") {
875 jQuery("#wpda_delete_new_dashboard_message_container").hide();
876 }
877 }
878 );
879 }
880 });
881 });
882 </script>
883 <?php
884 }
885
886 /**
887 * Data Explorer main page toolbar
888 *
889 * @return void
890 */
891 protected function toolbar_wpda() {
892 $schema_name = ( isset( $_REQUEST['wpdaschema_name'] ) ? esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ) ) : '' );
893 // phpcs:ignore WordPress.Security.NonceVerification
894 ?>
895 <form id="wpda_new_design" style="display: none" method="post" action="?page=<?php
896 echo esc_attr( WP_Data_Access_Admin::PAGE_DESIGNER );
897 ?>">
898 <input type="hidden" name="action" value="create_table">
899 <input type="hidden" name="caller" value="dataexplorer">
900 </form>
901 <form id="wpda_goto_backup" style="display: none" method="post" action="?page=<?php
902 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
903 ?>&page_action=wpda_backup">
904 <input type="hidden" name="wpdaschema_name" value="<?php
905 echo esc_attr( $schema_name );
906 ?>">
907 </form>
908 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
909 <div class="wpda-nowrap">
910 <div>
911 <div>
912 <a href="<?php
913 echo admin_url( 'admin.php' );
914 // phpcs:ignore WordPress.Security.EscapeOutput
915 ?>?page=<?php
916 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
917 ?>&page_action=wpda_global_search"
918 class="wpda-dashboard-item wpda_tooltip"
919 title="Search and replace text in multiple databases and tables"
920 >
921 <i class="fas fa-search-plus"></i>
922 <div>
923 Search & Replace
924 </div>
925 </a>
926 </div><div>
927 <a href="javascript:jQuery('#wpda_new_design').submit()"
928 class="wpda-dashboard-item wpda_tooltip"
929 title="Create new table design"
930 >
931 <i class="fas fa-plus-circle"></i>
932 <div>
933 Create table design
934 </div>
935 </a>
936 </div>
937 </div><div>
938 <div>
939 <?php
940 if ( 'new' !== $this->current_version ) {
941 ?>
942 <a onclick="jQuery('#upload_file_container_multi').show();"
943 href="javascript:void(0)"
944 class="wpda-dashboard-item wpda_tooltip"
945 title="Import and execute SQL script files"
946 >
947 <i class="fas fa-file-code"></i>
948 <div>
949 Import SQL files
950 </div>
951 </a>
952 <?php
953 } else {
954 ?>
955 <a onClick="window.ppActionEnableImport();"
956 href="javascript:void(0)"
957 class="wpda-dashboard-item wpda_tooltip"
958 title="Import and execute SQL script files"
959 >
960 <i class="fas fa-file-code"></i>
961 <div>
962 Import SQL files
963 </div>
964 </a>
965 <?php
966 }
967 ?>
968 </div><div>
969 <a href="<?php
970 echo admin_url( 'admin.php' );
971 // phpcs:ignore WordPress.Security.EscapeOutput
972 ?>?page=<?php
973 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
974 ?>&page_action=wpda_import_csv"
975 class="wpda-dashboard-item wpda_tooltip"
976 title="Import CSV files"
977 >
978 <i class="fas fa-file-csv"></i>
979 <div>
980 Import CSV files
981 </div>
982 </a>
983 </div><div>
984 <a href="javascript:void(0)"
985 id="wpda_toolbar_icon_go_backup"
986 class="wpda-dashboard-item wpda_tooltip"
987 title="Data Backup - unattended exports"
988 >
989 <i class="fas fa-file-archive"></i>
990 <div>
991 Data Backup
992 </div>
993 </a>
994 </div>
995 </div><div>
996 <?php
997 if ( 'new' !== $this->current_version ) {
998 ?>
999 <div>
1000 <a onclick="jQuery('#wpda_db_container').show(); jQuery('#local_database').focus();"
1001 href="javascript:void(0)"
1002 class="wpda-dashboard-item wpda_tooltip"
1003 title="Add remote database or create local database"
1004 >
1005 <i id="wpda_toolbar_icon_add_database" class="fas fa-database"></i>
1006 <div>
1007 Add database
1008 </div>
1009 </a>
1010 </div>
1011 <?php
1012 } else {
1013 ?>
1014 <div>
1015 <a onclick="jQuery('#wpda_manage_databases').show(); jQuery('#local_database').focus();"
1016 href="javascript:void(0)"
1017 class="wpda-dashboard-item wpda_tooltip"
1018 title="Manage remote database connections and local databases"
1019 >
1020 <i id="wpda_toolbar_icon_add_database" class="fas fa-server"></i>
1021 <div>
1022 Databases
1023 </div>
1024 </a>
1025 </div><?php
1026 }
1027 ?>
1028 <?php
1029 ?>
1030 </div>
1031 </div>
1032 <div class="wpda-promotion" style="font-size: 16px">
1033 <?php
1034 if ( 'new' !== $this->current_version ) {
1035 ?>
1036 <a href="?page=<?php
1037 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
1038 ?>&de=new"
1039 style="display: flex; align-items: center; gap: 5px;"
1040 >
1041 <i class="fas fa-toggle-off"></i>
1042 <span>Switch to new Data Explorer</span>
1043 </a>
1044 <?php
1045 } else {
1046 ?>
1047 <span
1048 style="display: flex; align-items: center; gap: 5px; white-space: nowrap;"
1049 >
1050 <a href="?page=<?php
1051 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
1052 ?>&de=old"
1053 style="display: flex; align-items: center; gap: 5px; white-space: nowrap;"
1054 >
1055 <i class="fas fa-toggle-on"></i>
1056 <span>Switch to old Data Explorer</span>
1057 </a>
1058 <span>
1059 <a href="https://wpdataaccess.com/2024/01/26/the-new-data-explorer-wp-data-access-5-4-0/"
1060 target="_blank"
1061 class="wpda_tooltip"
1062 title="Click to read more"
1063 >
1064 <i class="fas fa-circle-info"></i>
1065 </a>
1066 </span>
1067 </span>
1068 <?php
1069 }
1070 ?>
1071 </div>
1072 <?php
1073 //$this->get_promotions('wpda');
1074 ?>
1075 </div>
1076 <?php
1077 }
1078
1079 /**
1080 * Data Explorer table page toolbar
1081 *
1082 * @return void
1083 */
1084 protected function toolbar_wpda_table() {
1085 ?>
1086 <form id="wpda_new_row" style="display: none" method="post" action="?page=<?php
1087 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
1088 ?>">
1089 <?php
1090 if ( isset( $_REQUEST['wpdaschema_name'] ) ) {
1091 // phpcs:ignore WordPress.Security.NonceVerification
1092 $schema_name = esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ) );
1093 // phpcs:ignore WordPress.Security.NonceVerification
1094 echo "<input type='hidden' name='wpdaschema_name' value='{$schema_name}'>";
1095 // phpcs:ignore WordPress.Security.EscapeOutput
1096 }
1097 ?>
1098 <input type="hidden" id="wpda_new_row_table_name" name="table_name" value="">
1099 <input type="hidden" name="action" value="new">
1100 </form>
1101 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1102 <div class="wpda-nowrap">
1103 <div>
1104 <div>
1105 <a href="javascript:void(0)"
1106 id="wpda_toolbar_icon_add_row"
1107 class="wpda-dashboard-item wpda_tooltip"
1108 title="Add new row to table"
1109 >
1110 <i class="fas fa-plus-circle"></i>
1111 <div>
1112 Add row
1113 </div>
1114 </a>
1115 </div><div>
1116 <a onclick="jQuery('#upload_file_container').show()"
1117 href="javascript:void(0)"
1118 class="wpda-dashboard-item wpda_tooltip"
1119 title="Allows only imports into table authors"
1120 >
1121 <i class="fas fa-code"></i>
1122 <div>
1123 Import rows
1124 </div>
1125 </a>
1126 </div>
1127 </div>
1128 </div>
1129 <?php
1130 $this->get_promotions( 'table' );
1131 ?>
1132 </div>
1133 <?php
1134 }
1135
1136 /**
1137 * Data Explorer data entry form toolbar
1138 *
1139 * @return void
1140 */
1141 protected function toolbar_wpda_row() {
1142 ?>
1143 <form id="wpda_new_row" style="display: none" method="post" action="?page=<?php
1144 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
1145 ?>">
1146 <?php
1147 if ( isset( $_REQUEST['wpdaschema_name'] ) ) {
1148 // phpcs:ignore WordPress.Security.NonceVerification
1149 $schema_name = esc_attr( sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ) );
1150 // phpcs:ignore WordPress.Security.NonceVerification
1151 echo "<input type='hidden' name='wpdaschema_name' value='{$schema_name}'>";
1152 // phpcs:ignore WordPress.Security.EscapeOutput
1153 }
1154 ?>
1155 <input type="hidden" id="wpda_new_row_table_name" name="table_name" value="">
1156 <input type="hidden" name="action" value="new">
1157 </form>
1158 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1159 <div class="wpda-nowrap">
1160 <div>
1161 <div>
1162 <a href="javascript:void(0)"
1163 id="wpda_toolbar_icon_add_row"
1164 class="wpda-dashboard-item wpda_tooltip"
1165 title="Add new row to table"
1166 >
1167 <i class="fas fa-plus-circle"></i>
1168 <div>
1169 Add row
1170 </div>
1171 </a>
1172 </div>
1173 </div>
1174 </div>
1175 <?php
1176 $this->get_promotions( 'row' );
1177 ?>
1178 </div>
1179 <?php
1180 }
1181
1182 /**
1183 * Data Backup toolbar
1184 *
1185 * @return void
1186 */
1187 protected function toolbar_backup() {
1188 ?>
1189 <form id="wpda_new_backup" style="display: none" method="post" action="?page=<?php
1190 echo esc_attr( WP_Data_Access_Admin::PAGE_MAIN );
1191 ?>&page_action=wpda_backup">
1192 <input type="hidden" id="wpda_new_backup_wpdaschema_name" name="wpdaschema_name" value="">
1193 <input type="hidden" name="action" value="new">
1194 <input type="hidden" name="wp_nonce" value="<?php
1195 echo esc_attr( wp_create_nonce( 'wpda-backup-' . WPDA::get_current_user_login() ) );
1196 ?>"/>
1197 </form>
1198 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1199 <div class="wpda-nowrap">
1200 <div>
1201 <div>
1202 <a href="javascript:void(0)"
1203 id="wpda_toolbar_icon_add_backup"
1204 class="wpda-dashboard-item wpda_tooltip"
1205 title="Create new data backup"
1206 >
1207 <i class="fas fa-plus-circle"></i>
1208 <div>
1209 Create backup
1210 </div>
1211 </a>
1212 </div>
1213 </div>
1214 </div>
1215 <?php
1216 $this->get_promotions( 'backup' );
1217 ?>
1218 </div>
1219 <?php
1220 }
1221
1222 /**
1223 * CSV import toolbar
1224 *
1225 * @return void
1226 */
1227 protected function toolbar_import_csv() {
1228 if ( !isset( $_REQUEST['action'] ) || '-1' === $_REQUEST['action'] || 'bulk-delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action'] ) {
1229 ?>
1230 <form id="wpda_upload_csv" style="display:none" method="post" action="?page=wpda&page_action=wpda_import_csv">
1231 <input type="hidden" name="action" value="upload">
1232 </form>
1233 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1234 <div class="wpda-nowrap">
1235 <div>
1236 <div>
1237 <a href="javascript:jQuery('#wpda_upload_csv').submit()"
1238 class="wpda-dashboard-item wpda_tooltip"
1239 title="Upload new CSV File"
1240 >
1241 <i class="fas fa-plus-circle"></i>
1242 <div>
1243 Upload CSV file
1244 </div>
1245 </a>
1246 </div>
1247 </div>
1248 </div>
1249 <?php
1250 $this->get_promotions( 'csv' );
1251 ?>
1252 </div>
1253 <?php
1254 }
1255 }
1256
1257 /**
1258 * Data Apps toolbar.
1259 *
1260 * @return void
1261 */
1262 protected function toolbar_apps() {
1263 ?>
1264 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1265 <div class="wpda-nowrap">
1266 <div>
1267 <div>
1268 <a href="javascript:window.ppActionCreateApp()"
1269 class="wpda-dashboard-item wpda_tooltip wpda-create-new-app"
1270 title="Create new app"
1271 >
1272 <i class="fas fa-plus-circle"></i>
1273 <div>
1274 Create new app
1275 </div>
1276 </a>
1277 </div><div>
1278 <a href="javascript:window.ppActionRenameDatabase()"
1279 class="wpda-dashboard-item wpda_tooltip wpda-rename-database"
1280 title="Rename Database"
1281 >
1282 <svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 2 24 24" stroke-linecap="round" stroke-linejoin="round" height="32px" width="32px" xmlns="http://www.w3.org/2000/svg">
1283 <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
1284 <path d="M4 6c0 1.657 3.582 3 8 3s8 -1.343 8 -3s-3.582 -3 -8 -3s-8 1.343 -8 3"></path>
1285 <path d="M4 6v6c0 1.657 3.582 3 8 3c.478 0 .947 -.016 1.402 -.046"></path>
1286 <path d="M20 12v-6"></path>
1287 <path d="M4 12v6c0 1.526 3.04 2.786 6.972 2.975"></path>
1288 <path d="M18.42 15.61a2.1 2.1 0 0 1 2.97 2.97l-3.39 3.42h-3v-3l3.42 -3.39z"></path>
1289 </svg>
1290 <div>
1291 Rename Database
1292 </div>
1293 </a>
1294 </div>
1295 </div>
1296 </div>
1297 <div class="wpda-promotion" style="font-size: 16px">
1298 <span>
1299 <a href="https://wpdataaccess.com/docs/app-builder/whats-the-app-builder/"
1300 target="_blank"
1301 class="wpda_tooltip"
1302 title="Online App Builder documentation"
1303 >
1304 <i class="fas fa-circle-info"></i>
1305 </a>
1306 </span>
1307 </div>
1308 <?php
1309 // $this->get_promotions('apps');
1310 ?>
1311 </div>
1312 <?php
1313 }
1314
1315 /**
1316 * Query Builder toolbar
1317 *
1318 * @return void
1319 */
1320 protected function toolbar_sql() {
1321 ?>
1322 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1323 <div class="wpda-nowrap">
1324 <div>
1325 <div>
1326 <a href="javascript:tabNew()"
1327 class="wpda-dashboard-item wpda_tooltip"
1328 title="Create new query"
1329 >
1330 <i class="fas fa-plus-circle"></i>
1331 <div>
1332 Create new query
1333 </div>
1334 </a>
1335 </div><div>
1336 <a href="javascript:openQuery()"
1337 class="wpda-dashboard-item wpda_tooltip"
1338 title="Open existing query"
1339 >
1340 <i class="fas fa-folder-open"></i>
1341 <div>
1342 Open existing query
1343 </div>
1344 </a>
1345 </div>
1346 </div>
1347 </div>
1348 <?php
1349 $this->get_promotions( 'sql' );
1350 ?>
1351 </div>
1352 <?php
1353 }
1354
1355 /**
1356 * Data Designer toolbar
1357 *
1358 * @return void
1359 */
1360 protected function toolbar_designer() {
1361 ?>
1362 <form id="wpda_new_design" style="display: none" method="post" action="?page=<?php
1363 echo esc_attr( WP_Data_Access_Admin::PAGE_DESIGNER );
1364 ?>">
1365 <input type="hidden" name="action" value="edit">
1366 <input type="hidden" name="table_name" value="<?php
1367 echo esc_attr( WPDA_Design_Table_Model::get_base_table_name() );
1368 ?>">
1369 </form>
1370 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1371 <div class="wpda-nowrap">
1372 <div>
1373 <div>
1374 <a href="javascript:jQuery('#wpda_new_design').submit()"
1375 class="wpda-dashboard-item wpda_tooltip"
1376 title="Create new table design"
1377 >
1378 <i class="fas fa-plus-circle"></i>
1379 <div>
1380 Create table design
1381 </div>
1382 </a>
1383 </div><div>
1384 <a onclick="jQuery('#upload_file_container').show()"
1385 href="javascript:void(0)"
1386 class="wpda-dashboard-item wpda_tooltip"
1387 title="Import table designs"
1388 >
1389 <i class="fas fa-code"></i>
1390 <div>
1391 Import table designs
1392 </div>
1393 </a>
1394 </div>
1395 </div>
1396 </div>
1397 <?php
1398 $this->get_promotions( 'designer' );
1399 ?>
1400 </div>
1401 <?php
1402 }
1403
1404 /**
1405 * Data Tables toolbar
1406 *
1407 * @return void
1408 */
1409 protected function toolbar_publisher() {
1410 ?>
1411 <form id="wpda_new_publication" style="display: none" method="post" action="?page=<?php
1412 echo esc_attr( WP_Data_Access_Admin::PAGE_PUBLISHER );
1413 ?>">
1414 <input type="hidden" id="wpda_new_publication_table_name" name="table_name" value="">
1415 <input type="hidden" name="action" value="new">
1416 </form>
1417 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1418 <div class="wpda-nowrap">
1419 <div>
1420 <div>
1421 <a href="javascript:void(0)"
1422 id="wpda_toolbar_icon_add_publication"
1423 class="wpda-dashboard-item wpda_tooltip"
1424 title="Create new data table"
1425 >
1426 <i class="fas fa-plus-circle"></i>
1427 <div>
1428 Create data table
1429 </div>
1430 </a>
1431 </div><div>
1432 <a onclick="jQuery('#upload_file_container').show()"
1433 href="javascript:void(0)"
1434 class="wpda-dashboard-item wpda_tooltip"
1435 title="Import data tables"
1436 >
1437 <i class="fas fa-code"></i>
1438 <div>
1439 Import data tables
1440 </div>
1441 </a>
1442 </div><?php
1443 ?>
1444 </div>
1445 </div>
1446 <?php
1447 $this->get_promotions( 'publisher' );
1448 ?>
1449 </div>
1450 <?php
1451 }
1452
1453 /**
1454 * Charts toolbar
1455 *
1456 * @return void
1457 */
1458 protected function toolbar_charts() {
1459 }
1460
1461 /**
1462 * Data Projects toolbar
1463 *
1464 * @return void
1465 */
1466 protected function toolbar_projects() {
1467 ?>
1468 <form id="wpda_new_project" style="display: none" method="post" action="?page=<?php
1469 echo esc_attr( WPDP::PAGE_MAIN );
1470 ?>">
1471 <input type="hidden" name="action" value="new">
1472 <input type="hidden" name="mode" value="edit">
1473 <input type="hidden" name="table_name" value="<?php
1474 echo esc_attr( WPDP_Project_Model::get_base_table_name() );
1475 ?>">
1476 </form>
1477 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1478 <div class="wpda-nowrap">
1479 <div>
1480 <div>
1481 <a href="javascript:jQuery('#wpda_new_project').submit()"
1482 class="wpda-dashboard-item wpda_tooltip"
1483 title="Create new project"
1484 >
1485 <i class="fas fa-plus-circle"></i>
1486 <div>
1487 Create project
1488 </div>
1489 </a>
1490 </div><div>
1491 <a onclick="jQuery('#upload_file_container_multi').show()"
1492 href="javascript:void(0)"
1493 class="wpda-dashboard-item wpda_tooltip"
1494 title="Import projects"
1495 >
1496 <i class="fas fa-code"></i>
1497 <div>
1498 Import projects
1499 </div>
1500 </a>
1501 </div>
1502 </div>
1503 </div>
1504 <?php
1505 $this->get_promotions( 'projects' );
1506 ?>
1507 </div>
1508 <?php
1509 }
1510
1511 /**
1512 * Project Templates toolbar
1513 *
1514 * @return void
1515 */
1516 protected function toolbar_templates() {
1517 ?>
1518 <div id="wpda-dashboard-toolbar" class="wpda-dashboard-toolbar" style="display:none">
1519 <div class="wpda-nowrap">
1520 <div>
1521 <div>
1522 <a onclick="jQuery('#no_repository_buttons').hide(); jQuery('#add_table_to_repository').show()"
1523 href="javascript:void(0)"
1524 class="wpda-dashboard-item wpda_tooltip"
1525 title="Create new project template"
1526 >
1527 <i class="fas fa-plus-circle"></i>
1528 <div>
1529 Create project template
1530 </div>
1531 </a>
1532 </div>
1533 </div>
1534 </div>
1535 <?php
1536 $this->get_promotions( 'templates' );
1537 ?>
1538 </div>
1539 <?php
1540 }
1541
1542 /**
1543 * Widgets toolbar
1544 *
1545 * @return void
1546 */
1547 protected function add_forms() {
1548 ?>
1549 <div id="wpda-select-panel-type" class="wpda-add-panel" style="display: none">
1550 <form>
1551 <fieldset class="wpda_fieldset wpda_fieldset_dashboard">
1552 <legend>
1553 Create widget
1554 </legend>
1555 <div>
1556 <label>
1557 Widget type
1558 </label>
1559 <select id="wpda-select-panel-type-choice">
1560 <?php
1561 if ( class_exists( 'Code_Manager\\Code_Manager_Model' ) ) {
1562 ?>
1563 <option value="code">Custom Code</option>
1564 <?php
1565 }
1566 ?>
1567 <option value="chart" selected>Chart</option>
1568 <option value="pub">Data Table</option>
1569 <?php
1570 if ( class_exists( 'WPDataAccess\\Premium\\WPDAPRO_Dashboard\\WPDAPRO_Widget_Project' ) ) {
1571 ?>
1572 <option value="project">Data Project</option>
1573 <?php
1574 }
1575 ?>
1576 <option value="dbs">Database Info</option>
1577 </select>
1578 <?php
1579 if ( !class_exists( 'Code_Manager\\Code_Manager_Model' ) || !class_exists( 'WPDataAccess\\Premium\\WPDAPRO_Dashboard\\WPDAPRO_Widget_Project' ) ) {
1580 ?>
1581 <a href="https://wpdataaccess.com/docs/dashboards-and-widgets/bi-getting-started/" target="_blank">
1582 <i class="fas fa-question-circle pointer wpda_tooltip"
1583 style="font-size: 170%; vertical-align: middle"
1584 title="Your installation does not support all available widget types! Click to learn how to install more widget types..."></i>
1585 </a>
1586 <?php
1587 }
1588 ?>
1589 </div>
1590 </fieldset>
1591 <div class="wpda-panel-buttons">
1592 <span class="wpda-panel-buttons">
1593 <button id="wpda-select-panel-type-button" class="button button-primary">
1594 <i class="fas fa-check wpda_icon_on_button"></i>
1595 Next
1596 </button>
1597 <button id="wpda-select-panel-type-button-cancel" class="button button-secondary">
1598 <i class="fas fa-times-circle wpda_icon_on_button"></i>
1599 Cancel
1600 </button>
1601 </span>
1602 </div>
1603 </form>
1604 </div>
1605 <div id="wpda-add-panel" class="wpda-add-panel" style="display: none">
1606 <form>
1607 <fieldset class="wpda_fieldset wpda_fieldset_dashboard">
1608 <legend>
1609 Create widget
1610 </legend>
1611 <div>
1612 <label>
1613 Widget type
1614 </label>
1615 <input type="text" id="wpda-add-panel-type-show" readonly>
1616 <input type="hidden" id="wpda-add-panel-type">
1617 </div>
1618 <div>
1619 <label>
1620 Widget name
1621 </label>
1622 <input type="text" id="wpda-add-panel-name" required/>
1623 </div>
1624 <div id="wpda-panel-code" style="display: none">
1625 <label>
1626 Select shortcode
1627 </label>
1628 <select id="wpda-add-panel-code">
1629 <?php
1630 if ( class_exists( 'Code_Manager\\Code_Manager_Model' ) ) {
1631 $codes = \Code_Manager\Code_Manager_Model::get_active_shortcodes();
1632 foreach ( $codes as $code ) {
1633 ?>
1634 <option value="<?php
1635 echo esc_attr( $code['code_id'] );
1636 ?>"><?php
1637 echo esc_attr( $code['code_name'] ) . ' (' . esc_attr( $code['code_type'] ) . ')';
1638 ?></option>
1639 <?php
1640 }
1641 }
1642 ?>
1643 </select>
1644 </div>
1645 <div id="wpda-panel-project">
1646 <label>
1647 Select project
1648 </label>
1649 <select id="wpda-add-panel-project">
1650 <?php
1651 $projects = WPDP_Project_Model::get_project_list();
1652 foreach ( $projects as $project ) {
1653 ?>
1654 <option value="<?php
1655 echo esc_attr( $project['project_id'] );
1656 ?>"><?php
1657 echo esc_attr( $project['project_name'] ) . ' (project_id=' . esc_attr( $project['project_id'] ) . ')';
1658 ?></option>
1659 <?php
1660 }
1661 ?>
1662 </select>
1663 </div>
1664 <div id="wpda-panel-publication">
1665 <label>
1666 Select data table
1667 </label>
1668 <select id="wpda-add-panel-publication">
1669 <?php
1670 $pubs = WPDA_Publisher_Model::get_publication_list();
1671 foreach ( $pubs as $pub ) {
1672 ?>
1673 <option value="<?php
1674 echo esc_attr( $pub['pub_id'] );
1675 ?>"><?php
1676 echo esc_attr( $pub['pub_name'] ) . ' (pub_id=' . esc_attr( $pub['pub_id'] ) . ')';
1677 ?></option>
1678 <?php
1679 }
1680 ?>
1681 </select>
1682 </div>
1683 <div id="wpda-panel-dbms">
1684 <label>
1685 Select database
1686 </label>
1687 <select id="wpda-add-panel-dbms">
1688 <option value="wpdb" selected>WordPress database (
1689 <?php
1690 global $wpdb;
1691 echo esc_attr( $wpdb->dbname );
1692 ?>
1693 )</option>
1694 <?php
1695 $rdbs = WPDADB::get_remote_databases();
1696 ksort( $rdbs );
1697 //phpcs:ignore - 8.1 proof
1698 foreach ( $rdbs as $key => $rdb ) {
1699 ?>
1700 <option value="<?php
1701 echo esc_attr( $key );
1702 ?>"><?php
1703 echo esc_attr( $key );
1704 ?></option>
1705 <?php
1706 }
1707 ?>
1708 </select>
1709 </div>
1710 <div>
1711 <label>
1712 Add to column
1713 </label>
1714 <select id="wpda-add-panel-column">
1715 <option value="1" selected>1</option>
1716 <option value="2">2</option>
1717 </select>
1718 <select id="wpda-add-panel-position">
1719 <option value="prepend" selected>Before</option>
1720 <option value="append">After</option>
1721 </select>
1722 </div>
1723 </fieldset>
1724 <div class="wpda-panel-buttons">
1725 <span class="wpda-panel-buttons">
1726 <button id="wpda-add-panel-button" class="button button-primary">
1727 <i class="fas fa-check wpda_icon_on_button"></i>
1728 Create
1729 </button>
1730 <button id="wpda-add-panel-button-back" class="button">
1731 <i class="fas fa-angle-left wpda_icon_on_button"></i>
1732 Back
1733 </button>
1734 <button id="wpda-add-panel-button-cancel" class="button button-secondary">
1735 <i class="fas fa-times-circle wpda_icon_on_button"></i>
1736 Cancel
1737 </button>
1738 </span>
1739 </div>
1740 </div>
1741 </form>
1742 <script type="application/javascript">
1743 jQuery(function() {
1744 jQuery("#wpda-select-panel-type-button").on("click", function() {
1745 jQuery("#wpda-panel-code").hide();
1746 jQuery("#wpda-panel-project").hide();
1747 jQuery("#wpda-panel-publication").hide();
1748 jQuery("#wpda-panel-dbms").hide();
1749
1750 jQuery("#wpda-add-panel-type-show").val(jQuery("#wpda-select-panel-type-choice option:selected").text());
1751 jQuery("#wpda-add-panel-type").val(jQuery("#wpda-select-panel-type-choice").val());
1752
1753 switch (jQuery("#wpda-select-panel-type-choice").val()) {
1754 case "code":
1755 jQuery("#wpda-panel-code").show();
1756 break;
1757 case "dbs":
1758 jQuery("#wpda-panel-dbms").show();
1759 break;
1760 case "project":
1761 jQuery("#wpda-panel-project").show();
1762 break;
1763 case "pub":
1764 jQuery("#wpda-panel-publication").show();
1765 break;
1766 }
1767
1768 jQuery("#wpda-select-panel-type").hide();
1769 jQuery("#wpda-add-panel").show();
1770
1771 return false;
1772 });
1773
1774 jQuery("#wpda-select-panel-type-button-cancel").on("click", function() {
1775 jQuery("#wpda-select-panel-type").hide();
1776
1777 return false;
1778 });
1779
1780 jQuery("#wpda-add-panel-button").on("click", function () {
1781 panelName = jQuery("#wpda-add-panel-name").val();
1782
1783 if (panelName=="") {
1784 alert("Widget name is required");
1785 } else {
1786 switch (jQuery("#wpda-add-panel-type").val()) {
1787 case "chart":
1788 addPanelChartToDashboard(
1789 "<?php
1790 echo esc_attr( $this->wp_nonce_add );
1791 ?>",
1792 panelName,
1793 null,
1794 null,
1795 jQuery("#wpda-add-panel-column").val(),
1796 jQuery("#wpda-add-panel-position").val(),
1797 );
1798 break;
1799 case "code":
1800 addPanelCodeToDashboard(
1801 "<?php
1802 echo esc_attr( $this->wp_nonce_add );
1803 ?>",
1804 panelName,
1805 jQuery("#wpda-add-panel-code").val(),
1806 jQuery("#wpda-add-panel-column").val(),
1807 jQuery("#wpda-add-panel-position").val(),
1808 );
1809 break;
1810 case "dbs":
1811 addPanelDbmsToDashboard(
1812 "<?php
1813 echo esc_attr( $this->wp_nonce_add );
1814 ?>",
1815 panelName,
1816 jQuery("#wpda-add-panel-dbms").val(),
1817 jQuery("#wpda-add-panel-column").val(),
1818 jQuery("#wpda-add-panel-position").val(),
1819 );
1820 break;
1821 case "project":
1822 addPanelProjectToDashboard(
1823 "<?php
1824 echo esc_attr( $this->wp_nonce_add );
1825 ?>",
1826 panelName,
1827 jQuery("#wpda-add-panel-project").val(),
1828 jQuery("#wpda-add-panel-column").val(),
1829 jQuery("#wpda-add-panel-position").val(),
1830 );
1831 break;
1832 case "pub":
1833 addPanelPublicationToDashboard(
1834 "<?php
1835 echo esc_attr( $this->wp_nonce_add );
1836 ?>",
1837 panelName,
1838 jQuery("#wpda-add-panel-publication").val(),
1839 jQuery("#wpda-add-panel-column").val(),
1840 jQuery("#wpda-add-panel-position").val(),
1841 );
1842 break;
1843 default:
1844 alert("Unknown panel type");
1845 }
1846 }
1847
1848 return false;
1849 });
1850
1851 jQuery("#wpda-add-panel-button-back").on("click", function() {
1852 jQuery("#wpda-add-panel").hide();
1853 jQuery("#wpda-select-panel-type").show();
1854
1855 return false;
1856 });
1857
1858 jQuery("#wpda-add-panel-button-cancel").on("click", function () {
1859 closePanel();
1860
1861 return false;
1862 });
1863 });
1864 </script>
1865 <?php
1866 }
1867
1868 /**
1869 * Add dashboard columns
1870 *
1871 * @return void
1872 */
1873 protected function columns() {
1874 ?>
1875 <div id="wpda-dashboard-content" class="wpda-dashboard-content">
1876 <?php
1877 // Following line requires PHP 7.
1878 // $last_key = array_key_last($this->dashboard_positions[0]); .
1879 $last_key = 1;
1880 if ( is_array( $this->dashboard_positions ) && count( $this->dashboard_positions ) > 0 ) {
1881 //phpcs:ignore - 8.1 proof
1882 foreach ( $this->dashboard_positions[0] as $key => $val ) {
1883 $last_key = $key;
1884 }
1885 }
1886 $this->number_of_columns = $last_key;
1887 for ($i = 1; $i <= $this->number_of_columns; $i++) {
1888 ?>
1889 <div id="wpda-dashboard-column-<?php
1890 echo esc_attr( $i );
1891 ?>" class="wpda-dashboard-column wpda-dashboard-column-<?php
1892 echo esc_attr( $this->number_of_columns );
1893 ?>">
1894 </div>
1895 <?php
1896 }
1897 ?>
1898 </div>
1899 <?php
1900 }
1901
1902 /**
1903 * Add panels to dashboard
1904 *
1905 * @return void
1906 */
1907 protected function add_panels() {
1908 }
1909
1910 /**
1911 * Add panel
1912 *
1913 * @param string $dashboard_widget Widget name.
1914 * @param string $column Column name.
1915 * @param string $position Position.
1916 * @param string $widget_id Widget ID.
1917 * @return void
1918 */
1919 protected static function add_panel(
1920 $dashboard_widget,
1921 $column,
1922 $position,
1923 $widget_id = null
1924 ) {
1925 }
1926
1927 /**
1928 * Get available databases as option list
1929 *
1930 * @return string
1931 */
1932 private function get_databases() {
1933 // Get available databases.
1934 $dbs = WPDA_Dictionary_Lists::get_db_schemas();
1935 foreach ( $dbs as $db ) {
1936 $databases[] = $db['schema_name'];
1937 }
1938 global $wpdb;
1939 $database_options = '';
1940 foreach ( $databases as $database ) {
1941 $selected = ( WPDA::get_user_default_scheme() === $database ? 'selected' : '' );
1942 if ( $database === $wpdb->dbname ) {
1943 $database_text = "WordPress database ({$database})";
1944 } else {
1945 $database_text = $database;
1946 }
1947 $database_options .= '<option value="' . esc_attr( $database ) . '" ' . esc_attr( $selected ) . '>' . esc_attr( $database_text ) . '</option>';
1948 }
1949 // Return available databases as option list.
1950 return $database_options;
1951 }
1952
1953 /**
1954 * Add javascript functions
1955 *
1956 * @return void
1957 */
1958 public function dashboard_js() {
1959 ?>
1960 <script type="application/javascript">
1961 let wpda_wpnonce_save = "<?php
1962 echo esc_attr( wp_create_nonce( static::DASHBOARD_SAVE . WPDA::get_current_user_login() ) );
1963 ?>";
1964 let wpda_wpnonce_add = "<?php
1965 echo esc_attr( wp_create_nonce( WPDA_Widget::WIDGET_ADD . WPDA::get_current_user_login() ) );
1966 ?>";
1967 let wpda_wpnonce_qb = "<?php
1968 echo esc_attr( wp_create_nonce( 'wpda-query-builder-' . WPDA::get_current_user_id() ) );
1969 ?>";
1970 let wpda_wpnonce_refresh = "<?php
1971 echo esc_attr( wp_create_nonce( WPDA_Widget::WIDGET_REFRESH . WPDA::get_current_user_login() ) );
1972 ?>";
1973 let wpda_ajaxurl = "<?php
1974 echo admin_url( 'admin-ajax.php' );
1975 // phpcs:ignore WordPress.Security.EscapeOutput
1976 ?>";
1977 let wpda_databases = '<?php
1978 echo $this->get_databases();
1979 // phpcs:ignore WordPress.Security.EscapeOutput
1980 ?>';
1981 let wpda_shared_dashboards = <?php
1982 echo json_encode( $this->shared_dashboards );
1983 // phpcs:ignore
1984 ?>;
1985
1986 function saveWidgetPositions() {} // Implemented in the premium version
1987 function saveDashBoard(callback) {
1988 saveWidgetPositions();
1989 jQuery.ajax({
1990 type: "POST",
1991 url: wpda_ajaxurl + "?action=wpda_save_dashboard",
1992 data: {
1993 wp_nonce: wpda_wpnonce_save,
1994 wpda_widgets: dashboardWidgets,
1995 wpda_positions: dashboardWidgetPosition,
1996 wpda_deleted: dashboardWidgetDeleted,
1997 wpda_tabname: "<?php
1998 echo esc_attr( $this->tab_name );
1999 ?>"
2000 }
2001 }).done(
2002 function(data) {
2003 dashboardWidgetDeleted = [];
2004 if (callback!==undefined) {
2005 callback();
2006 }
2007 }
2008 ).fail(
2009 function (msg) {
2010 console.log("WP Data Access error (saveDashBoard):", msg);
2011 }
2012 );
2013 }
2014 <?php
2015 ?>
2016 </script>
2017 <?php
2018 }
2019
2020 /**
2021 * Save dashboard and widgets
2022 *
2023 * @return void
2024 */
2025 public static function save() {
2026 $wp_nonce = ( isset( $_POST['wp_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wp_nonce'] ) ) : '' );
2027 if ( !wp_verify_nonce( $wp_nonce, static::DASHBOARD_SAVE . WPDA::get_current_user_login() ) ) {
2028 WPDA::sent_header( 'application/json' );
2029 echo static::msg( 'ERROR', 'Token expired, please refresh page' );
2030 // phpcs:ignore WordPress.Security.EscapeOutput
2031 wp_die();
2032 }
2033 $widgets = ( isset( $_POST['wpda_widgets'] ) ? WPDA::sanitize_text_field_array( $_POST['wpda_widgets'] ) : array() );
2034 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
2035 $save = array();
2036 foreach ( $widgets as $widget ) {
2037 $save[$widget['widgetName']] = $widget;
2038 }
2039 update_user_meta( WPDA::get_current_user_id(), self::USER_DASHBOARD, $save );
2040 echo self::msg( 'SUCCESS', 'Widget succesfully saved' );
2041 // phpcs:ignore WordPress.Security.EscapeOutput
2042 wp_die();
2043 }
2044
2045 /**
2046 * Get list of all widgets
2047 *
2048 * @return void
2049 */
2050 public static function get_list() {
2051 $wp_nonce = ( isset( $_POST['wpda_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wpda_wpnonce'] ) ) : '' );
2052 if ( !wp_verify_nonce( $wp_nonce, WPDA_Widget::WIDGET_REFRESH . WPDA::get_current_user_login() ) ) {
2053 WPDA::sent_header( 'application/json' );
2054 echo static::msg( 'ERROR', 'Token expired, please refresh page' );
2055 // phpcs:ignore WordPress.Security.EscapeOutput
2056 wp_die();
2057 }
2058 // Placeholder: implemented in the premium version.
2059 echo '';
2060 wp_die();
2061 }
2062
2063 /**
2064 * Delete widget
2065 *
2066 * @return void
2067 */
2068 public static function delete_widget() {
2069 $wp_nonce = ( isset( $_POST['wpda_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wpda_wpnonce'] ) ) : '' );
2070 if ( !wp_verify_nonce( $wp_nonce, self::DASHBOARD_SAVE . WPDA::get_current_user_login() ) ) {
2071 WPDA::sent_header( 'application/json' );
2072 echo static::msg( 'ERROR', 'Token expired, please refresh page' );
2073 // phpcs:ignore WordPress.Security.EscapeOutput
2074 wp_die();
2075 }
2076 // Placeholder: implemented in the premium version.
2077 echo '';
2078 wp_die();
2079 }
2080
2081 /**
2082 * Edit chart
2083 *
2084 * @return void
2085 */
2086 public static function edit_chart() {
2087 $wp_nonce = ( isset( $_POST['wpda_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wpda_wpnonce'] ) ) : '' );
2088 if ( !wp_verify_nonce( $wp_nonce, WPDA_Widget::WIDGET_REFRESH . WPDA::get_current_user_login() ) ) {
2089 WPDA::sent_header( 'application/json' );
2090 echo static::msg( 'ERROR', 'Token expired, please refresh page' );
2091 // phpcs:ignore WordPress.Security.EscapeOutput
2092 wp_die();
2093 }
2094 // Placeholder: implemented in the premium version.
2095 echo '';
2096 wp_die();
2097 }
2098
2099 /**
2100 * Load widget via ajax
2101 *
2102 * @return void
2103 */
2104 public static function load_widget() {
2105 $wp_nonce = ( isset( $_POST['wpda_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wpda_wpnonce'] ) ) : '' );
2106 if ( !wp_verify_nonce( $wp_nonce, WPDA_Widget::WIDGET_REFRESH . WPDA::get_current_user_login() ) ) {
2107 WPDA::sent_header( 'application/json' );
2108 echo static::msg( 'ERROR', 'Token expired, please refresh page' );
2109 // phpcs:ignore WordPress.Security.EscapeOutput
2110 wp_die();
2111 }
2112 // Placeholder: implemented in the premium version.
2113 echo '';
2114 wp_die();
2115 }
2116
2117 /**
2118 * Construct tab name
2119 *
2120 * @param string $tab_name Original tab name.
2121 * @return string
2122 */
2123 public static function get_tab_name( $tab_name ) {
2124 return '_' . str_replace( ' ', '_', $tab_name );
2125 }
2126
2127 /**
2128 * Permanently remove plugin info message from dashboard
2129 *
2130 * @return void
2131 */
2132 public static function remove_new_dashboard_message() {
2133 WPDA::sent_header( 'text/html; charset=UTF-8' );
2134 $wp_nonce = ( isset( $_POST['wp_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['wp_nonce'] ) ) : '' );
2135 if ( wp_verify_nonce( $wp_nonce, self::DASHBOARD_SAVE . WPDA::get_current_user_login() ) ) {
2136 // Permanently remove message from dashboard toolbar.
2137 update_user_meta( WPDA::get_current_user_id(), self::USER_NEW_MESSAGE, 'removed' );
2138 echo 'OK';
2139 } else {
2140 echo 'FAILED';
2141 }
2142 wp_die();
2143 }
2144
2145 /**
2146 * Construct ajax message
2147 *
2148 * @param string $status Status.
2149 * @param string $msg Message.
2150 * @return false|string
2151 */
2152 public static function msg( $status, $msg ) {
2153 $error = array(
2154 'status' => $status,
2155 'msg' => $msg,
2156 );
2157 return json_encode( $error );
2158 // phpcs:ignore
2159 }
2160
2161 private function get_promotions( $tool ) {
2162 switch ( $tool ) {
2163 case 'publisher':
2164 case 'projects':
2165 case 'templates':
2166 case 'charts':
2167 $promotions = array(array(
2168 'This tool will transition to the new App Builder. Please migrate on time.' => array(null, 'fa-lightbulb'),
2169 ));
2170 break;
2171 case 'csv':
2172 $promotions = array(array(
2173 'Use the connection wizards for automated CSV synchronization.' => array('https://wpdataaccess.com/docs/remote-data-files/csv-files/', 'fa-lightbulb'),
2174 ));
2175 break;
2176 case 'publisher_OLD':
2177 $promotions = array(
2178 array(
2179 'Change data table color, spacing, border radius and modal popup behaviour.' => array('https://wpdataaccess.com/data-tables-styling/premium-styling/', 'fa-palette'),
2180 ),
2181 array(
2182 'Reorder data table elements with drag and drop.' => array('https://wpdataaccess.com/docs/data-tables/extension-manager/', 'fa-star'),
2183 ),
2184 array(
2185 'Add buttons to support CSV, Excel, PDF and SQL downloads.' => array('https://wpdataaccess.com/docs/data-tables/extension-manager/', 'fa-cloud-download'),
2186 ),
2187 array(
2188 'Add user friendly Search Panes to simplify searching.' => array('https://wpdataaccess.com/docs/data-tables-interactive-filters/search-panes/', 'fa-magic'),
2189 ),
2190 array(
2191 'Use the Search Builder to add interactive searching.' => array('https://wpdataaccess.com/docs/data-tables-interactive-filters/search-builder/', 'fa-search'),
2192 ),
2193 array(
2194 'Synchronize your Google Sheets from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-data-files/public-url/#google-sheets', 'fa-database'),
2195 )
2196 );
2197 break;
2198 case 'wpda':
2199 $promotions = array(
2200 array(
2201 'Access your SQL Server tables from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-database-connections/sql-server/', 'fa-database'),
2202 ),
2203 array(
2204 'Access your PostgreSQL tables from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-database-connections/postgresql/', 'fa-database'),
2205 ),
2206 array(
2207 'Access your Oracle tables from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-database-connections/oracle/', 'fa-database'),
2208 ),
2209 array(
2210 'Access your remote MariaDB | MySQL tables from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-database-connections/mariadb-mysql/', 'fa-database'),
2211 ),
2212 array(
2213 'Access your CSV files directly from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-data-files/csv-files/', 'fa-lightbulb'),
2214 ),
2215 array(
2216 'Access your MS Access tables from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-data-files/ms-access/', 'fa-database'),
2217 ),
2218 array(
2219 'Synchronize your Google Sheets from the Data Explorer.' => array('https://wpdataaccess.com/docs/remote-data-files/public-url/#google-sheets', 'fa-database'),
2220 )
2221 );
2222 break;
2223 default:
2224 $promotions = array();
2225 }
2226 if ( count( $promotions ) > 0 ) {
2227 //phpcs:ignore - 8.1 proof
2228 $promotion_index = random_int( 0, count( $promotions ) - 1 );
2229 $promotion = $promotions[$promotion_index];
2230 $promotion_text = key( $promotion );
2231 $promotion_url = $promotion[$promotion_text][0];
2232 $promotion_icon = $promotion[$promotion_text][1];
2233 ?>
2234 <div class="wpda-promotion">
2235 <span><i class="fas <?php
2236 echo esc_attr( $promotion_icon );
2237 ?>"></i></span>
2238 <?php
2239 echo esc_attr( $promotion_text );
2240 ?>
2241 <?php
2242 if ( null !== $promotion_url ) {
2243 ?>
2244 <a href="<?php
2245 echo esc_url( $promotion_url );
2246 ?>" target="_blank">Read more...</a>
2247 <?php
2248 }
2249 ?>
2250 </div>
2251 <?php
2252 }
2253 }
2254
2255 }
2256