PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.10.2
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.10.2
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
visualizer / classes / Visualizer / Render / Layout.php

Layout.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.10.2, at classes/Visualizer/Render/Layout.php

1,141 lines 49.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // +----------------------------------------------------------------------+
4 // | Copyright 2013 Madpixels (email : visualizer@madpixels.net) |
5 // +----------------------------------------------------------------------+
6 // | This program is free software; you can redistribute it and/or modify |
7 // | it under the terms of the GNU General Public License, version 2, as |
8 // | published by the Free Software Foundation. |
9 // | |
10 // | This program is distributed in the hope that it will be useful, |
11 // | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 // | GNU General Public License for more details. |
14 // | |
15 // | You should have received a copy of the GNU General Public License |
16 // | along with this program; if not, write to the Free Software |
17 // | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
18 // | MA 02110-1301 USA |
19 // +----------------------------------------------------------------------+
20 // | Author: Eugene Manuilov <eugene@manuilov.org> |
21 // +----------------------------------------------------------------------+
22 /**
23 * Layout rendering class.
24 *
25 * @category Visualizer
26 * @package Render
27 */
28 class Visualizer_Render_Layout extends Visualizer_Render {
29
30 /**
31 * Renders template.
32 *
33 * @since 1.0.0
34 *
35 * @abstract
36 * @access protected
37 */
38 protected function _toHTML() {
39 // empty.
40 }
41
42 /**
43 * Show the layout by delegating the call to the layout-specific method with the params.
44 *
45 * @access public
46 */
47 public static function show( $layout ) {
48 return call_user_func( array( __CLASS__, '_render' . str_replace( ' ', '', ucwords( str_replace( '-', ' ', $layout ) ) ) ), func_get_args() );
49 }
50
51 /**
52 * Show the DB query box.
53 *
54 * @access public
55 */
56 public static function _renderDbQuery( $args ) {
57 $query = $args[1];
58 ?>
59 <div id='visualizer-db-query' style="display: none">
60 <div class="visualizer-db-query-form">
61 <div>
62 <form id='db-query-form'>
63 <input type="hidden" name="chart_id" value="<?php echo $args[2]; ?>">
64 <?php do_action( 'visualizer_db_query_add_layout', $args ); ?>
65 <textarea name='query' class='visualizer-db-query' placeholder="<?php _e( 'Your query goes here', 'visualizer' ); ?>"><?php echo $query; ?></textarea>
66 </form>
67 <div class='db-wizard-error'></div>
68 </div>
69 <div>
70 <input type="button" class="button button-primary" id='visualizer-query-fetch' value='<?php _e( 'Show Results', 'visualizer' ); ?>'>
71 </div>
72 </div>
73 <div class='db-wizard-hints'>
74 <ul>
75 <li><?php echo sprintf( __( 'For examples of queries and links to resources that you can use with this feature, please click %1$shere%2$s', 'visualizer' ), '<a href="' . VISUALIZER_DB_QUERY_DOC_URL . '" target="_blank">', '</a>' ); ?></li>
76 <li><?php echo sprintf( __( 'Use %1$sControl+Space%2$s for autocompleting keywords or table names.', 'visualizer' ), '<span class="visualizer-emboss">', '</span>' ); ?></li>
77 <?php do_action( 'visualizer_db_query_add_hints', $args ); ?>
78 </ul>
79 </div>
80 <div class='db-wizard-results'></div>
81
82 </div>
83 <?php
84 }
85
86 /**
87 * Show the DB wizard's results table.
88 *
89 * @access public
90 */
91 public static function _renderDbWizardResults( $args ) {
92 $headers = $args[1];
93 $results = $args[2];
94 ob_start();
95 ?>
96 <table cellspacing="0" width="100%" id="results">
97 <thead>
98 <tr>
99 <?php
100 foreach ( $headers as $header ) {
101 echo '<th>' . $header['label'] . '</th>';
102 }
103 ?>
104 </tr>
105 </thead>
106 <tfoot>
107 </tfoot>
108 <tbody>
109 <?php
110 foreach ( $results as $result ) {
111 echo '<tr>';
112 foreach ( $result as $r ) {
113 echo '<td>' . $r . '</td>';
114 }
115 echo '</tr>';
116 }
117 ?>
118 </tbody>
119 </table>
120 <?php
121 return ob_get_clean();
122 }
123
124 /**
125 * Show the JSON/REST parameters boxes.
126 *
127 * @access public
128 */
129 public static function _renderJsonScreen( $args ) {
130 $id = $args[1];
131 $action = esc_url(
132 add_query_arg(
133 array(
134 'action' => Visualizer_Plugin::ACTION_JSON_SET_DATA,
135 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_JSON_SET_DATA . Visualizer_Plugin::VERSION ),
136 'chart' => $id,
137 ),
138 admin_url( 'admin-ajax.php' )
139 )
140 );
141
142 $is_wc_source = get_post_meta( $id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true );
143 $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true );
144 $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true );
145 $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true );
146 $headers = get_post_meta( $id, Visualizer_Plugin::CF_JSON_HEADERS, true );
147 if ( empty( $headers ) ) {
148 $headers = array();
149 }
150 if ( $headers && empty( $headers['method'] ) ) {
151 $headers['method'] = 'get';
152 }
153 $methods = apply_filters( 'visualizer_json_request_methods', array( 'GET', 'POST' ) );
154
155 // open the headers by default?
156 $headers_open = $headers && array_key_exists( 'auth', $headers ) && ( array_key_exists( 'username', $headers['auth'] ) && ! empty( $headers['auth']['username'] ) ) || ( ! empty( $headers['auth'] ) && is_string( $headers['auth'] ) );
157 ?>
158 <div id="visualizer-json-screen" style="display: none">
159 <div class="visualizer-json-form">
160 <h3 class="viz-step step1"><?php _e( 'STEP 1: Specify the JSON endpoint/URL', 'visualizer' ); ?></h3>
161 <div>
162 <form id="json-endpoint-form">
163 <div class="json-wizard-hints">
164 <ul class="info">
165 <li><?php echo sprintf( __( 'If you want to add authentication or headers to the endpoint or change the request in any way, please refer to our document %1$shere%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/1043-visualizer-how-to-extend-rest-endpoints-with-json-response" target="_blank">', '</a>' ); ?></li>
166 </ul>
167 </div>
168
169 <input
170 type="url"
171 id="vz-import-json-url"
172 name="url"
173 value="<?php echo esc_url( $url ); ?>"
174 placeholder="<?php esc_html_e( 'Please enter the URL', 'visualizer' ); ?>"
175 class="visualizer-input json-form-element"
176 <?php echo $is_wc_source ? 'readonly' : ''; ?>
177 >
178 <button class="button button-secondary button-small" id="visualizer-json-fetch"><?php esc_html_e( 'Fetch Endpoint', 'visualizer' ); ?></button>
179
180 <div class="visualizer-json-subform">
181 <h3 class="viz-substep <?php echo $headers_open ? 'open' : ''; ?>"><?php _e( 'Headers', 'visualizer' ); ?></h3>
182 <div class="json-wizard-headers">
183 <div class="json-wizard-header">
184 <div><?php _e( 'Request Type', 'visualizer' ); ?></div>
185 <div>
186 <select name="method" class="json-form-element">
187 <?php foreach ( $methods as $method ) { ?>
188 <option value="<?php echo $method; ?>" <?php $headers && selected( $headers['method'], $method ); ?>><?php echo $method; ?></option>
189 <?php } ?>
190 </select>
191 </div>
192 </div>
193 <div class="json-wizard-header">
194 <div><?php _e( 'Credentials', 'visualizer' ); ?></div>
195 <div>
196 <input
197 type="text"
198 id="vz-import-json-username"
199 name="username"
200 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'username', $headers['auth'] ) ? $headers['auth']['username'] : '' ); ?>"
201 placeholder="<?php esc_html_e( 'Username/Access Key', 'visualizer' ); ?>"
202 class="json-form-element">
203 &
204 <input
205 type="password"
206 id="vz-import-json-password"
207 name="password"
208 value="<?php echo ( array_key_exists( 'auth', $headers ) && array_key_exists( 'password', $headers['auth'] ) ? $headers['auth']['password'] : '' ); ?>"
209 placeholder="<?php esc_html_e( 'Password/Secret Key', 'visualizer' ); ?>"
210 class="json-form-element">
211 </div>
212 </div>
213 <div class="json-wizard-header">
214 <div></div>
215 <div><?php esc_html_e( 'OR', 'visualizer' ); ?></div>
216 </div>
217 <div class="json-wizard-header">
218 <div><?php esc_html_e( 'Authorization', 'visualizer' ); ?></div>
219 <div>
220 <input
221 type="text"
222 id="vz-import-json-auth"
223 name="auth"
224 value="<?php echo ( array_key_exists( 'auth', $headers ) && is_string( $headers['auth'] ) ? $headers['auth'] : '' ); ?>"
225 placeholder="<?php esc_html_e( 'e.g. SharedKey <AccountName>:<Signature>', 'visualizer' ); ?>"
226 class="visualizer-input json-form-element">
227 </div>
228 </div>
229 <div class="json-wizard-header">
230 <div class="field-title"><?php esc_html_e( 'Additional headers', 'visualizer' ); ?></div>
231 <div>
232 <textarea name="additional_headers" class="visualizer-input" placeholder="<?php esc_html_e( 'Key:Value, Key2:Value2,...', 'visualizer' ); ?>"><?php echo isset( $headers['additional_headers'] ) ? $headers['additional_headers'] : ''; ?></textarea>
233 </div>
234 </div>
235 </div>
236 </div>
237 </form>
238 </div>
239 <h3 class="viz-step step2 <?php echo empty( $url ) ? 'ui-state-disabled' : ''; ?> json-root-form"><?php _e( 'STEP 2: Choose the JSON root', 'visualizer' ); ?></h3>
240 <div>
241 <form id="json-root-form">
242 <input type="hidden" name="chart" value="<?php echo $id; ?>">
243 <select name="root" id="vz-import-json-root" class="json-form-element">
244 <?php
245 if ( ! empty( $root ) ) {
246 ?>
247 <option value="<?php echo esc_attr( $root ); ?>"><?php echo str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $root ); ?></option>
248 <?php
249 }
250 ?>
251 </select>
252 <button class="button button-secondary button-small" id="visualizer-json-parse"><?php esc_html_e( 'Parse Endpoint', 'visualizer' ); ?></button>
253 </form>
254 </div>
255 <h3 class="viz-step step3 <?php echo empty( $root ) ? 'ui-state-disabled' : ''; ?>"><?php _e( 'STEP 3: Specify miscellaneous parameters', 'visualizer' ); ?></h3>
256 <div>
257 <form id="json-conclude-form-helper">
258 <div class="<?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
259 <div class="json-pagination">
260 <select name="paging" id="vz-import-json-paging" class="json-form-element" data-template='<?php echo sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), '?' ); ?>'>
261 <option value="0" class="static"><?php _e( 'Get results from the first page only', 'visualizer' ); ?></option>
262 <?php
263 if ( ! empty( $paging ) ) {
264 ?>
265 <option value="<?php echo esc_attr( $paging ); ?>"><?php echo sprintf( 'Get results from the first %d pages using %s', apply_filters( 'visualizer_json_fetch_pages', 5, $url ), str_replace( Visualizer_Source_Json::TAG_SEPARATOR, Visualizer_Source_Json::TAG_SEPARATOR_VIEW, $paging ) ); ?></option>
266 <?php
267 }
268 ?>
269 </select>
270 <?php
271 if ( ! Visualizer_Module::is_pro() ) {
272 ?>
273 <br/>
274 <br/>
275 <br/>
276 <br/>
277 <?php
278 }
279 ?>
280 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
281 </div>
282 </div>
283 </form>
284 </div>
285 <h3 class="viz-step step4 ui-state-disabled"><?php _e( 'STEP 4: Select the data to display in the chart', 'visualizer' ); ?></h3>
286 <div>
287 <form id="json-conclude-form" action="<?php echo $action; ?>" method="post" target="thehole">
288 <div class="json-wizard-hints html-table-editor-hints">
289 <ul class="info">
290 <li><?php _e( 'If you see Invalid Data in the table, you may have selected the wrong root to fetch data from. Please select an alternative from the JSON root dropdown.', 'visualizer' ); ?></li>
291 <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
292 <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
293 <li><?php _e( 'You can use drag/drop to reorder the columns but this column position is not saved. So when you reload the table, you may have to reorder again.', 'visualizer' ); ?></li>
294 <li><?php _e( 'You can select any number of columns but the chart type selected will determine how many will display in the chart.', 'visualizer' ); ?></li>
295 <li><?php _e( 'Once you have made your selection, click \'Show Chart\' on the right to view the chart.', 'visualizer' ); ?></li>
296 </ul>
297 </div>
298 <div class="json-table"></div>
299 <button class="button button-primary" style="display: none" id="visualizer-json-conclude"></button>
300 </form>
301 </div>
302 </div>
303 </div>
304 <?php
305 }
306
307 /**
308 * Show the simple editor(s).
309 *
310 * @access public
311 */
312 public static function _renderSimpleEditorScreen( $args ) {
313 $chart_id = $args[1];
314 $action = esc_url(
315 add_query_arg(
316 array(
317 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
318 'nonce' => wp_create_nonce(),
319 'chart' => $chart_id,
320 ),
321 admin_url( 'admin-ajax.php' )
322 )
323 );
324 ?>
325 <div class="viz-simple-editor">
326 <div class="viz-simple-editor-type viz-table-editor">
327 <form id="table-editor-form" action="<?php echo $action; ?>" method="post" target="thehole">
328 <div class="html-table-editor-hints">
329 <ul class="info">
330 <li><?php _e( 'Select whether to include the data in the chart. Each column selected will form one series.', 'visualizer' ); ?></li>
331 <li><?php _e( 'If a column is selected to be included, specify its data type.', 'visualizer' ); ?></li>
332 <li><?php _e( 'You can use drag/drop to reorder the columns but this column position is not saved. So when you reload the table, you may have to reorder again.', 'visualizer' ); ?></li>
333 <li><?php _e( 'You can select any number of columns but the chart type selected will determine how many will display in the chart.', 'visualizer' ); ?></li>
334 </ul>
335 </div>
336 <div class="viz-html-table">
337 <?php Visualizer_Render_Layout::show( 'editor-table', null, $chart_id, 'viz-html-table', true, true ); ?>
338 </div>
339 <input type="hidden" name="table_data" value="yes">
340 <input type="hidden" name="editor-type" value="table">
341 </form>
342 </div>
343
344 <?php Visualizer_Render_Layout::show( 'text-editor', $chart_id ); ?>
345
346 </div>
347 <?php
348
349 }
350
351 /**
352 * Show the text area editor.
353 *
354 * @access public
355 */
356 public static function _renderTextEditor( $args ) {
357 $chart_id = $args[1];
358 $csv = apply_filters( Visualizer_Plugin::FILTER_GET_CHART_DATA_AS, array(), $chart_id, 'csv-display' );
359 $data = '';
360 if ( ! empty( $csv ) && isset( $csv['string'] ) ) {
361 $data = str_replace( PHP_EOL, "\n", stripslashes( $csv['string'] ) );
362 }
363 ?>
364 <div class="viz-simple-editor-type viz-text-editor">
365 <textarea id="edited_text"><?php echo $data; ?></textarea>
366 </div>
367 <?php
368 }
369
370 /**
371 * Show the JSON endpoint's parsed table.
372 *
373 * @access public
374 */
375 public static function _renderEditorTable( $args ) {
376 $data = $args[1];
377 $chart_id = $args[2];
378 $class = $args[3];
379 $echo = $args[4];
380 $editable_data = $args[5];
381 $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true );
382 $headers = array();
383
384 if ( is_null( $data ) ) {
385 foreach ( $series as $column ) {
386 $headers[] = $column['label'];
387 }
388 $chart = get_post( $chart_id );
389 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
390 $data = Visualizer_Module::get_chart_data( $chart, $type );
391 } else {
392 $headers = array_keys( $data[0] );
393 }
394
395 $classes = implode( ' ', array( 'viz-editor-table', $class ) );
396
397 if ( $series ) {
398 $temp = $series;
399 $series = array();
400 foreach ( $temp as $array ) {
401 $series[ $array['label'] ] = $array['type'];
402 }
403 }
404 if ( ! $echo ) {
405 ob_start();
406 }
407 ?>
408 <table cellspacing="0" width="100%" class="results cell-border stripe <?php echo $classes; ?>">
409 <thead>
410 <tr>
411 <th><?php _e( 'Label', 'visualizer' ); ?></th>
412 <?php
413 foreach ( $headers as $header ) {
414 if ( $editable_data ) {
415 echo '<th><input type="text" name="header[]" value="' . esc_attr( $header ) . '"></th>';
416 } else {
417 echo '<th>' . $header . '</th>';
418 }
419 }
420 ?>
421 </tr>
422 </thead>
423 <tbody>
424 <tr>
425 <th><?php _e( 'Data Type', 'visualizer' ); ?></th>
426 <?php
427 $index = 0;
428 foreach ( $headers as $header ) {
429 echo '<td>';
430 if ( $editable_data ) {
431 echo '<select name="type[]">';
432 } else {
433 echo '<input name="header[]" type="hidden" value="' . $header . '">';
434 echo '<select name="type[' . $header . ']" class="viz-select-data-type">';
435 }
436 echo '<option value="" title="' . __( 'Exclude from chart', 'visualizer' ) . '">' . __( 'Exclude', 'visualizer' ) . '</option>';
437 echo '<option value="0" disabled title="' . __( 'Include in chart and select data type', 'visualizer' ) . '">--' . __( 'OR', 'visualizer' ) . '--</option>';
438
439 foreach ( Visualizer_Source::getAllowedTypes() as $type ) {
440 $selected = array_key_exists( $header, $series ) && $type === $series[ $header ] ? 'selected' : '';
441 echo '<option value="' . $type . '" ' . $selected . '>' . $type . '</option>';
442 }
443
444 echo '</select></td>';
445 }
446 ?>
447 </tr>
448 <?php
449 // for remote sources, the data exists inside 'data'.
450 if ( array_key_exists( 'data', $data ) ) {
451 $data = $data['data'];
452 }
453
454 foreach ( $data as $row ) {
455 echo '<tr>';
456 echo '<th>' . __( 'Value', 'visualizer' ) . '</th>';
457 $index = 0;
458 if ( empty( $row ) ) {
459 echo '<td></td>';
460 continue;
461 }
462 foreach ( array_values( $row ) as $value ) {
463 if ( $editable_data ) {
464 echo '<td><input type="text" name="data' . $index++ . '[]" value="' . esc_attr( stripslashes( $value ) ) . '"></td>';
465 } else {
466 echo '<td>' . ( is_array( $value ) ? __( 'Invalid Data', 'visualizer' ) : $value ) . '</td>';
467 }
468 }
469
470 echo '</tr>';
471 }
472 ?>
473 </tbody>
474 </table>
475 <?php
476 if ( ! $echo ) {
477 return ob_get_clean();
478 }
479 }
480
481 /**
482 * Generates the permissions tab.
483 *
484 * @access private
485 */
486 private static function _renderPermissions( $args ) {
487 $chart_id = $args[1];
488
489 // ignore for unit tests because Travis throws the error "Indirect modification of overloaded property Visualizer_Render_Page_Data::$permissions has no effect".
490 if ( defined( 'WP_TESTS_DOMAIN' ) ) {
491 return;
492 }
493
494 $permissions = apply_filters( 'visualizer_pro_get_permissions', null, $chart_id );
495 if ( is_array( $permissions ) ) {
496 $permissions = $permissions['permissions'];
497 } else {
498 $permissions = array();
499 }
500 if ( ! isset( $permissions['read'] ) ) {
501 $permissions['read'] = 'all';
502 }
503 if ( ! isset( $permissions['edit'] ) ) {
504 $permissions['edit'] = 'roles';
505 $permissions['edit-specific'] = 'administrator';
506 }
507
508 Visualizer_Render_Sidebar::_renderGroupStart( esc_html__( 'Permissions', 'visualizer' ) . '<span class="dashicons dashicons-lock"></span>', '', apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'chart-permissions' ), 'vz-permissions' );
509 echo '<div style="position: relative">';
510 Visualizer_Render_Sidebar::_renderSectionStart();
511 Visualizer_Render_Sidebar::_renderSectionDescription( esc_html__( 'Configure permissions for the chart.', 'visualizer' ) );
512 Visualizer_Render_Sidebar::_renderSectionEnd();
513
514 Visualizer_Render_Sidebar::_renderSectionStart( esc_html__( 'Who can see this chart?', 'visualizer' ), false );
515 Visualizer_Render_Sidebar::_renderSelectItem(
516 '',
517 'permissions[read]',
518 $permissions['read'],
519 array(
520 'all' => esc_html__( 'All Users', 'visualizer' ),
521 'users' => esc_html__( 'Select Users', 'visualizer' ),
522 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
523 ),
524 '',
525 false,
526 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-read' ),
527 array(
528 'permission-type' => 'read',
529 )
530 );
531
532 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $permissions['read'] ) ? $permissions['read'] : 'roles' );
533
534 Visualizer_Render_Sidebar::_renderSelectItem(
535 '',
536 'permissions[read-specific][]',
537 isset( $permissions['read-specific'] ) ? $permissions['read-specific'] : array(),
538 $options,
539 '',
540 true,
541 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-read-specific' )
542 );
543 Visualizer_Render_Sidebar::_renderSectionEnd();
544
545 Visualizer_Render_Sidebar::_renderSectionStart( esc_html__( 'Who can edit this chart?', 'visualizer' ), false );
546 Visualizer_Render_Sidebar::_renderSelectItem(
547 '',
548 'permissions[edit]',
549 $permissions['edit'],
550 array(
551 'all' => esc_html__( 'All Users', 'visualizer' ),
552 'users' => esc_html__( 'Select Users', 'visualizer' ),
553 'roles' => esc_html__( 'Select Roles', 'visualizer' ),
554 ),
555 '',
556 false,
557 array( 'visualizer-permission', 'visualizer-permission-type', 'visualizer-permission-edit' ),
558 array(
559 'permission-type' => 'edit',
560 )
561 );
562
563 $options = apply_filters( 'visualizer_pro_get_permissions_data', array(), isset( $permissions['edit'] ) ? $permissions['edit'] : 'roles' );
564
565 Visualizer_Render_Sidebar::_renderSelectItem(
566 '',
567 'permissions[edit-specific][]',
568 isset( $permissions['edit-specific'] ) ? $permissions['edit-specific'] : array(),
569 $options,
570 '',
571 true,
572 array( 'visualizer-permission', 'visualizer-permission-specific', 'visualizer-permission-edit-specific' )
573 );
574 Visualizer_Render_Sidebar::_renderSectionEnd();
575 echo apply_filters( 'visualizer_pro_upsell', '', 'chart-permissions' );
576 echo '</div>';
577 Visualizer_Render_Sidebar::_renderGroupEnd();
578 }
579
580 /**
581 * Show the Settings tab for this chart.
582 *
583 * @access public
584 */
585 public static function _renderTabAdvanced( $args ) {
586 $sidebar = $args[2];
587 ?>
588 <ul class="viz-group-wrapper full-height">
589 <li class="viz-group open" id="vz-chart-settings">
590 <ul class="viz-group-content">
591 <ul class="viz-group-wrapper">
592 <form id="settings-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
593 <input type="hidden" id="chart-img" name="chart-img">
594 <?php echo $sidebar; ?>
595 <?php self::_renderPermissions( $args ); ?>
596 <input type="hidden" name="save" value="1">
597 </form>
598 <form id="cancel-form" action="<?php echo esc_url( add_query_arg( 'nonce', wp_create_nonce() ) ); ?>" method="post">
599 <input type="hidden" name="cancel" value="1">
600 </form>
601 </ul>
602 </ul>
603 </li>
604 <?php
605 }
606
607 /**
608 * Show the Docs tab for this chart.
609 *
610 * @access public
611 */
612 public static function _renderTabHelp( $args ) {
613 $chart_id = $args[1];
614 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
615 switch ( $type ) {
616 case 'tabular':
617 $type = 'table';
618 break;
619 case 'polarArea':
620 $type = 'polar-area';
621 break;
622 case 'radar':
623 $type = 'radar-spider';
624 break;
625 }
626
627 $displayType = str_replace( '-', '/', $type );
628 ?>
629 <ul class="viz-group-wrapper full-height">
630 <li class="viz-group open" id="vz-chart-help">
631 <ul class="viz-group-wrapper">
632 <?php
633 // open this tab by default.
634 Visualizer_Render_Sidebar::_renderGroupStart( esc_html__( 'Documentation', 'visualizer' ), '', 'open' );
635 Visualizer_Render_Sidebar::_renderSectionStart( esc_html__( 'General', 'visualizer' ), true );
636 ?>
637 <h4><span class="dashicons dashicons-editor-help"></span><a href="<?php echo VISUALIZER_MAIN_DOC; ?>" target="_blank"><?php _e( 'Main documentation page', 'visualizer' ); ?></a></h4>
638 <h4><span class="dashicons dashicons-media-code"></span><a href="<?php echo VISUALIZER_CODE_SNIPPETS_URL; ?>" target="_blank"><?php _e( 'Custom code snippets', 'visualizer' ); ?></a></h4>
639 <?php
640 Visualizer_Render_Sidebar::_renderSectionEnd();
641 Visualizer_Render_Sidebar::_renderSectionStart( sprintf( __( '%s chart', 'visualizer' ), ucwords( $displayType ) ), true );
642 ?>
643 <h4><span class="dashicons dashicons-video-alt2"></span>&nbsp;<a href="<?php echo str_replace( '#', "$type-chart", VISUALIZER_DEMO_URL ); ?>" target="_blank"><?php _e( 'View demo', 'visualizer' ); ?></a></h4>
644 <h4><span class="dashicons dashicons-search"></span><a href="<?php echo str_replace( '#', $type, VISUALIZER_DOC_COLLECTION ); ?>" target="_blank"><?php echo sprintf( __( 'Articles containing "%s"', 'visualizer' ), $displayType ); ?></a></h4>
645 <?php
646 Visualizer_Render_Sidebar::_renderSectionEnd();
647 Visualizer_Render_Sidebar::_renderGroupEnd();
648 ?>
649 </ul>
650 </li>
651 </ul>
652
653 <?php
654 }
655
656 /**
657 * Show the Data Source tab for this chart.
658 *
659 * @access public
660 */
661 public static function _renderTabBasic( $args ) {
662 $chart_id = $args[1];
663
664 $upload_link = esc_url(
665 add_query_arg(
666 array(
667 'action' => Visualizer_Plugin::ACTION_UPLOAD_DATA,
668 'nonce' => wp_create_nonce(),
669 'chart' => $chart_id,
670 ),
671 admin_url( 'admin-ajax.php' )
672 )
673 );
674
675 // this will allow us to open the correct source tab by default.
676 $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) );
677 // Import from woocommerce report.
678 $is_woocommerce_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ) );
679 if ( ! empty( $is_woocommerce_source ) ) {
680 $source_of_chart .= '_wc';
681 }
682 // both import from wp and import from db have the same source so we need to differentiate.
683 $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true );
684 // if filter config is present, then its import from wp.
685 if ( ! empty( $filter_config ) ) {
686 $source_of_chart .= '_wp';
687 }
688 $editor_type = get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITOR, true );
689 if ( $editor_type ) {
690 $source_of_chart = 'visualizer_source_manual';
691 }
692
693 $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
694 $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true );
695 ?>
696 <ul class="viz-group-wrapper full-height">
697 <li class="viz-group open" id="vz-chart-source">
698 <ul class="viz-group-content">
699 <ul class="viz-group-wrapper">
700 <!-- import from file -->
701 <li class="viz-group visualizer_source_csv">
702 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from file', 'visualizer' ); ?></h2>
703 <div class="viz-group-content">
704 <p class="viz-group-description"><?php esc_html_e( 'Select and upload your data CSV file here. The first row of the CSV file should contain the column headings. The second one should contain series type (string, number, boolean, date, datetime, timeofday).', 'visualizer' ); ?></p>
705 <p class="viz-group-description viz-info-msg"><b><?php echo sprintf( __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %1$s %2$s%3$s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">', $type, '.csv</a>' ); ?></b></p>
706 <form id="vz-csv-file-form" action="<?php echo $upload_link; ?>" method="post"
707 target="thehole" enctype="multipart/form-data">
708 <input type="hidden" id="remote-data" name="remote_data">
709 <div class="">
710 <input type="file" id="csv-file" name="local_data">
711 </div>
712 <input type="button" class="button button-primary" id="vz-import-file"
713 value="<?php _e( 'Import', 'visualizer' ); ?>">
714 </form>
715 </div>
716 </li>
717 <!-- import from url -->
718 <li class="viz-group visualizer-import-url visualizer_source_csv_remote visualizer_source_json">
719 <h2 class="viz-group-title viz-sub-group visualizer-src-tab"><?php _e( 'Import data from URL', 'visualizer' ); ?></h2>
720 <ul class="viz-group-content">
721 <!-- import from csv url -->
722 <li class="viz-subsection">
723 <span class="viz-section-title"><?php _e( 'Import from CSV', 'visualizer' ); ?></span>
724 <div class="viz-section-items section-items">
725 <p class="viz-group-description"><?php echo sprintf( __( 'You can use this to import data from a remote CSV file or %1$sGoogle Spreadsheet%2$s.', 'visualizer' ), '<a href="https://docs.themeisle.com/article/607-how-can-i-populate-data-from-google-spreadsheet" target="_blank" >', '</a>' ); ?> </p>
726 <p class="viz-group-description viz-info-msg"><b><?php echo sprintf( __( 'If you are unsure about how to format your data CSV then please take a look at this sample: %1$s %2$s%3$s. If you are using non-English characters, please make sure you save the file in UTF-8 encoding.', 'visualizer' ), '<a href="' . VISUALIZER_ABSURL . 'samples/' . $type . '.csv" target="_blank">', $type, '.csv</a>' ); ?></b></p>
727 <form id="vz-one-time-import" action="<?php echo $upload_link; ?>" method="post"
728 target="thehole" enctype="multipart/form-data">
729 <div class="remote-file-section">
730 <input type="url" id="vz-schedule-url" name="remote_data" value="<?php echo esc_attr( get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_URL, true ) ); ?>" placeholder="<?php esc_html_e( 'Please enter the URL of CSV file', 'visualizer' ); ?>" class="visualizer-input visualizer-remote-url">
731 </div>
732 <select name="vz-import-time" id="vz-import-time" class="visualizer-select">
733 <?php
734 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true );
735 $schedules = apply_filters(
736 'visualizer_chart_schedules', array(
737 '-1' => __( 'One-time', 'visualizer' ),
738 ),
739 'csv',
740 $chart_id
741 );
742 foreach ( $schedules as $num => $name ) {
743 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
744 $extra = $num == $hours ? 'selected' : '';
745 ?>
746 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
747 <?php
748 }
749 do_action( 'visualizer_chart_schedules_spl', 'csv', $chart_id, 1 );
750 ?>
751 </select>
752
753 <?php
754 if ( ! Visualizer_Module::is_pro() ) {
755 ?>
756 <input type="button" id="view-remote-file" class="button button-primary" value="<?php _e( 'Import', 'visualizer' ); ?>">
757 <?php
758 } else {
759 ?>
760 <input type="button" id="vz-save-schedule" class="button button-primary" value="<?php _e( 'Import & Save schedule', 'visualizer' ); ?>">
761 <?php
762 }
763 ?>
764 </form>
765 </div>
766 </li>
767 <!-- import from json url -->
768 <li class="viz-subsection">
769 <span class="viz-section-title visualizer_source_json"><?php _e( 'Import from JSON', 'visualizer' ); ?></span>
770 <div class="viz-section-items section-items">
771 <p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a remote JSON source. For more info check <a href="https://docs.themeisle.com/article/1052-how-to-generate-charts-from-json-data-rest-endpoints" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
772 <form id="vz-import-json" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
773 <div class="remote-file-section">
774 <?php
775 $bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
776 if ( Visualizer_Module::is_pro() ) {
777 ?>
778 <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
779 <select name="time" id="vz-json-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
780 <?php
781 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
782 $schedules = apply_filters(
783 'visualizer_chart_schedules', array(
784 '-1' => __( 'One-time', 'visualizer' ),
785 ),
786 'json',
787 $chart_id
788 );
789 foreach ( $schedules as $num => $name ) {
790 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
791 $extra = $num == $hours ? 'selected' : '';
792 ?>
793 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
794 <?php
795 }
796 do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
797 ?>
798 </select>
799 <?php
800 }
801 ?>
802 </div>
803
804 <input type="button" id="json-chart-button" class="button button-secondary show-chart-toggle"
805 value="<?php echo $bttn_label; ?>" data-current="chart"
806 data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
807 data-t-chart="<?php echo $bttn_label; ?>">
808 <?php
809 if ( Visualizer_Module::is_pro() ) {
810 ?>
811 <input type="button" id="json-chart-save-button" class="button button-primary "
812 value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
813 <?php
814 }
815 ?>
816 </form>
817 </div>
818 </li>
819 </ul>
820 </li>
821 <!-- import from chart -->
822 <li class="viz-group viz-import-from-other <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature' ); ?>">
823 <h2 class="viz-group-title viz-sub-group"
824 data-current="chart"><?php _e( 'Import from other chart', 'visualizer' ); ?><span
825 class="dashicons dashicons-lock"></span></h2>
826 <div class="viz-group-content edit-data-content">
827 <div>
828 <p class="viz-group-description"><?php _e( 'You can import here data from your previously created charts', 'visualizer' ); ?></p>
829 <form>
830 <select name="vz-import-from-chart" id="chart-id" class="visualizer-select">
831 <?php
832 $fetch_link = esc_url(
833 add_query_arg(
834 array(
835 'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
836 'nonce' => wp_create_nonce(),
837 ),
838 admin_url( 'admin-ajax.php' )
839 )
840 );
841 $query_args_charts = array(
842 'post_type' => Visualizer_Plugin::CPT_VISUALIZER,
843 'posts_per_page' => 300,
844 'no_found_rows' => true,
845 );
846 $charts = array();
847 $query = new WP_Query( $query_args_charts );
848 while ( $query->have_posts() ) {
849 $chart = $query->next_post();
850 $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true );
851
852 $title = '#' . $chart->ID;
853 if ( ! empty( $settings['title'] ) ) {
854 $title = $settings['title'];
855 }
856 // for ChartJS, title is an array.
857 if ( is_array( $title ) && isset( $title['text'] ) ) {
858 $title = $title['text'];
859 }
860 if ( empty( $title ) ) {
861 $title = '#' . $chart->ID;
862 }
863
864 ?>
865 <option value="<?php echo $chart->ID; ?>"><?php echo $title; ?></option>
866 <?php
867 }
868 ?>
869
870 </select>
871 </form>
872 <input type="button" id="existing-chart" class="button button-primary"
873 value="<?php _e( 'Import Chart', 'visualizer' ); ?>"
874 data-viz-link="<?php echo $fetch_link; ?>">
875 <?php echo apply_filters( 'visualizer_pro_upsell', '' ); ?>
876 </div>
877 </div>
878 </li>
879
880 <?php
881 $save_filter = esc_url(
882 add_query_arg(
883 array(
884 'action' => Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY,
885 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_FILTER_QUERY . Visualizer_Plugin::VERSION ),
886 'chart' => $chart_id,
887 ), admin_url( 'admin-ajax.php' )
888 )
889 );
890 ?>
891 <!-- import from WordPress -->
892 <li class="viz-group visualizer_source_query_wp <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wp' ); ?> ">
893 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WordPress', 'visualizer' ); ?><span
894 class="dashicons dashicons-lock"></span></h2>
895 <div class="viz-group-content edit-data-content">
896 <div>
897 <p class="viz-group-description"><?php _e( 'You can import data from WordPress here.', 'visualizer' ); ?></p>
898 <form id="vz-filter-wizard" action="<?php echo $save_filter; ?>" method="post" target="thehole">
899 <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from WordPress.', 'visualizer' ); ?></p>
900 <select name="refresh" id="vz-filter-import-time" class="visualizer-select">
901 <?php
902 $bttn_label = 'visualizer_source_query_wp' === $source_of_chart ? __( 'Modify Filter', 'visualizer' ) : __( 'Create Filter', 'visualizer' );
903 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
904 $schedules = apply_filters(
905 'visualizer_chart_schedules', array(
906 '-1' => __( 'One-time', 'visualizer' ),
907 ),
908 'wp',
909 $chart_id
910 );
911 foreach ( $schedules as $num => $name ) {
912 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
913 $extra = $num == $hours ? 'selected' : '';
914 ?>
915 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
916 <?php
917 }
918 do_action( 'visualizer_chart_schedules_spl', 'wp', $chart_id, 1 );
919 ?>
920 </select>
921
922 <input type="button" id="filter-chart-button" class="button button-secondary show-chart-toggle" value="<?php echo $bttn_label; ?>" data-current="chart" data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo $bttn_label; ?>">
923 <input type="button" id="db-filter-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
924 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
925 </form>
926 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wp' ); ?>
927 </div>
928 </div>
929 </li>
930
931 <!-- import from WooCommerce -->
932 <?php
933 if ( class_exists( 'WooCommerce', false ) ) :
934 $wc_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, true ) );
935 $wc_source_list = apply_filters(
936 'visualizer_woocommerce_report_endpoints',
937 array(
938 array(
939 'name' => esc_html__( 'Sales', 'visualizer' ),
940 'endpoint' => esc_attr( 'sales' ),
941 ),
942 array(
943 'name' => esc_html__( 'Top Sellers', 'visualizer' ),
944 'endpoint' => esc_attr( 'top_sellers' ),
945 ),
946 array(
947 'name' => esc_html__( 'Coupons Totals', 'visualizer' ),
948 'endpoint' => esc_attr( 'coupons/totals' ),
949 ),
950 array(
951 'name' => esc_html__( 'Customers Totals', 'visualizer' ),
952 'endpoint' => esc_attr( 'customers/totals' ),
953 ),
954 array(
955 'name' => esc_html__( 'Orders Totals', 'visualizer' ),
956 'endpoint' => esc_attr( 'orders/totals' ),
957 ),
958 array(
959 'name' => esc_html__( 'Products Totals', 'visualizer' ),
960 'endpoint' => esc_attr( 'products/totals' ),
961 ),
962 array(
963 'name' => esc_html__( 'Reviews Totals', 'visualizer' ),
964 'endpoint' => esc_attr( 'reviews/totals' ),
965 ),
966 )
967 );
968 ?>
969 <li class="viz-group visualizer_woocommerce_source<?php echo 'visualizer_source_json_wc' === $source_of_chart ? ' open' : ''; ?> <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'import-wc-report' ); ?> ">
970 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from WooCommerce Reports', 'visualizer' ); ?><span class="dashicons dashicons-lock"></span></h2>
971 <div class="viz-group-content edit-data-content">
972 <div>
973 <p class="viz-group-description"><?php _e( 'You can choose here to import/synchronize your chart data with a WooCommerce report API. For more info check <a href="https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#reports" target="_blank" >this</a> tutorial', 'visualizer' ); ?></p>
974 <form id="vz-import-woo-report" action="<?php echo $upload_link; ?>" method="post" target="thehole" enctype="multipart/form-data">
975 <div class="remote-file-section">
976 <?php
977 $bttn_label = 'visualizer_source_json_wc' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
978 ?>
979 <p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
980 <select name="time" id="vz-woo-time" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
981 <?php
982 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true );
983 $schedules = apply_filters(
984 'visualizer_chart_schedules', array(
985 '-1' => __( 'One-time', 'visualizer' ),
986 ),
987 'json',
988 $chart_id
989 );
990 foreach ( $schedules as $num => $name ) {
991 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
992 $extra = $num == $hours ? 'selected' : '';
993 ?>
994 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
995 <?php
996 }
997 do_action( 'visualizer_chart_schedules_spl', 'json', $chart_id, 1 );
998 ?>
999 </select>
1000 <p class="viz-group-description"><?php _e( 'Select report endpoint', 'visualizer' ); ?></p>
1001 <select name="vz_woo_source" id="vz-woo-source" class="visualizer-select json-form-element" data-chart="<?php echo $chart_id; ?>">
1002 <option value=""></option>
1003 <?php
1004 if ( ! empty( $wc_source_list ) ) {
1005 foreach ( $wc_source_list as $api ) {
1006 if ( isset( $api['name'] ) && $api['endpoint'] ) {
1007 echo sprintf( '<option value="%2$s" %3$s>%1$s</option>', $api['name'], $api['endpoint'], selected( $wc_source, $api['endpoint'], false ) ); // phpcs:ignore
1008 }
1009 }
1010 }
1011 ?>
1012 </select>
1013 </div>
1014
1015 <input type="button" id="woo-chart-button" class="button button-secondary show-chart-toggle"
1016 value="<?php echo $bttn_label; ?>" data-current="chart"
1017 data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1018 data-t-chart="<?php echo $bttn_label; ?>"
1019 <?php empty( $wc_source ) ? 'disabled' : ''; ?>
1020 >
1021 <input type="button" id="woo-chart-save-button" class="button button-primary "
1022 value="<?php _e( 'Save Schedule', 'visualizer' ); ?>" <?php empty( $wc_source ) ? 'disabled' : ''; ?>>
1023 </form>
1024 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'import-wc-report' ); ?>
1025 </div>
1026 </div>
1027 </li>
1028 <?php endif; ?>
1029 <?php
1030 $save_query = esc_url(
1031 add_query_arg(
1032 array(
1033 'action' => Visualizer_Plugin::ACTION_SAVE_DB_QUERY,
1034 'security' => wp_create_nonce( Visualizer_Plugin::ACTION_SAVE_DB_QUERY . Visualizer_Plugin::VERSION ),
1035 'chart' => $chart_id,
1036 ), admin_url( 'admin-ajax.php' )
1037 )
1038 );
1039 ?>
1040 <!-- import from db -->
1041 <li class="viz-group visualizer_source_query <?php echo apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ); ?>">
1042 <h2 class="viz-group-title viz-sub-group"><?php _e( 'Import from database', 'visualizer' ); ?><span
1043 class="dashicons dashicons-lock"></span></h2>
1044 <div class="viz-group-content edit-data-content">
1045 <div>
1046 <p class="viz-group-description"><?php _e( 'You can import data from the database here.', 'visualizer' ); ?></p>
1047 <form id="vz-db-wizard" action="<?php echo $save_query; ?>" method="post" target="thehole">
1048 <p class="viz-group-description"><?php _e( 'How often do you want to refresh the data from the database.', 'visualizer' ); ?></p>
1049 <select name="refresh" id="vz-db-import-time" class="visualizer-select">
1050 <?php
1051 $bttn_label = 'visualizer_source_query' === $source_of_chart ? __( 'Modify Query', 'visualizer' ) : __( 'Create Query', 'visualizer' );
1052 $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true );
1053 $schedules = apply_filters(
1054 'visualizer_chart_schedules', array(
1055 '-1' => __( 'One-time', 'visualizer' ),
1056 ),
1057 'db',
1058 $chart_id
1059 );
1060 foreach ( $schedules as $num => $name ) {
1061 // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison
1062 $extra = $num == $hours ? 'selected' : '';
1063 ?>
1064 <option value="<?php echo $num; ?>" <?php echo $extra; ?>><?php echo $name; ?></option>
1065 <?php
1066 }
1067 do_action( 'visualizer_chart_schedules_spl', 'db', $chart_id, 1 );
1068 ?>
1069 </select>
1070 <input type="hidden" name="params" id="viz-db-wizard-params">
1071
1072 <input type="button" id="db-chart-button" class="button button-secondary show-chart-toggle" value="<?php echo $bttn_label; ?>" data-current="chart" data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>" data-t-chart="<?php echo $bttn_label; ?>">
1073 <input type="button" id="db-chart-save-button" class="button button-primary" value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
1074 <?php echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' ); ?>
1075 </form>
1076 </div>
1077 </div>
1078 </li>
1079
1080 <!-- manual -->
1081 <li class="viz-group visualizer_source_manual <?php echo ! Visualizer_Module_Admin::proFeaturesLocked() ? apply_filters( 'visualizer_pro_upsell_class', 'only-pro-feature', 'db-query' ) : ''; ?>">
1082 <h2 class="viz-group-title viz-sub-group visualizer-editor-tab" data-current="chart"><?php _e( 'Manual Data', 'visualizer' ); ?>
1083 <span class="dashicons dashicons-lock"></span>
1084 </h2>
1085 <div class="viz-group-content edit-data-content">
1086 <form id="editor-form" action="<?php echo $upload_link; ?>" method="post" target="thehole">
1087 <input type="hidden" id="chart-data" name="chart_data">
1088 <input type="hidden" id="chart-data-src" name="chart_data_src">
1089
1090 <?php if ( Visualizer_Module::can_show_feature( 'simple-editor' ) ) { ?>
1091 <div>
1092 <p class="viz-group-description viz-editor-selection">
1093 <?php _e( 'Use the', 'visualizer' ); ?>
1094 <select name="editor-type" id="viz-editor-type">
1095 <?php
1096 if ( empty( $editor_type ) ) {
1097 $editor_type = Visualizer_Module::is_pro() ? 'excel' : 'text';
1098 }
1099 foreach ( apply_filters( 'visualizer_editors', array( 'text' => __( 'Text', 'visualizer' ), 'table' => __( 'Simple', 'visualizer' ) ) ) as $e_type => $e_label ) {
1100 ?>
1101 <option value="<?php echo $e_type; ?>" <?php selected( $editor_type, $e_type ); ?> ><?php echo $e_label; ?></option>
1102 <?php } ?>
1103 </select>
1104 <?php _e( 'editor to manually edit the chart data.', 'visualizer' ); ?>
1105 </p>
1106 <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1107 <input type="button" id="editor-button" class="button button-primary "
1108 value="<?php _e( 'Edit Data', 'visualizer' ); ?>" data-current="chart"
1109 data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1110 data-t-chart="<?php _e( 'Edit Data', 'visualizer' ); ?>"
1111 >
1112 <p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
1113 </div>
1114 <?php } else { ?>
1115 <input type="button" id="editor-undo" class="button button-secondary" style="display: none" value="<?php _e( 'Undo Changes', 'visualizer' ); ?>">
1116 <input type="button" id="editor-chart-button" class="button button-primary "
1117 value="<?php _e( 'View Editor', 'visualizer' ); ?>" data-current="chart"
1118 data-t-editor="<?php _e( 'Show Chart', 'visualizer' ); ?>"
1119 data-t-chart="<?php _e( 'View Editor', 'visualizer' ); ?>"
1120 >
1121 <p class="viz-group-description viz-info-msg"><?php echo sprintf( __( 'Please make sure you click \'Show Chart\' before you save the chart.', 'visualizer' ) ); ?></p>
1122 <?php } ?>
1123 <?php
1124 if ( ! Visualizer_Module_Admin::proFeaturesLocked() ) {
1125 echo apply_filters( 'visualizer_pro_upsell', '', 'db-query' );
1126 }
1127 ?>
1128 </form>
1129 </div>
1130 </li>
1131 </ul>
1132 </li>
1133 </ul>
1134 </ul>
1135
1136 <span id="visualizer-chart-id" data-id="<?php echo $chart_id; ?>" data-chart-source="<?php echo esc_attr( $source_of_chart ); ?>" data-chart-type="<?php echo esc_attr( $type ); ?>" data-chart-lib="<?php echo esc_attr( $lib ); ?>"></span>
1137 <iframe id="thehole" name="thehole"></iframe>
1138 <?php
1139 }
1140 }
1141