PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.22
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.22
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 / Dashboard / WPDA_Dashboard.php

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

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