PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.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.84, at WPDataAccess/Dashboard/WPDA_Dashboard.php

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