PluginProbe
Chartify – WordPress Chart Plugin / 3.0.2
Chartify – WordPress Chart Plugin v3.0.2
3.8.1 3.8.0 3.7.9 3.7.8 3.7.7 3.7.6 3.7.5 trunk 1.0.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 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.1.4 3.1.5 All 84 releases
chart-builder / admin / partials / charts / actions / chart-builder-charts-actions-options.php

chart-builder-charts-actions-options.php in Chartify – WordPress Chart Plugin 3.0.2, at admin/partials/charts/actions/chart-builder-charts-actions-options.php

451 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (isset($_GET['ays_chart_tab'])) {
3 $ays_chart_tab = esc_attr($_GET['ays_chart_tab']);
4 } else {
5 $ays_chart_tab = 'tab1';
6 }
7 $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : '';
8
9 $id = (isset($_GET['id'])) ? absint( esc_attr($_GET['id']) ) : 0;
10
11 $get_all_charts = CBActions()->get_charts('DESC');
12
13 $does_id_exist = false;
14 if (!empty($get_all_charts)) {
15 $does_id_exist = in_array($id, array_column($get_all_charts, 'id'));
16 }
17
18 if (!$does_id_exist && $action == 'edit') {
19 $url = remove_query_arg( array('action', 'id', 'status', 'ays_chart_tab') );
20 wp_redirect( $url );
21 }
22
23 $html_name_prefix = 'ays_';
24 $html_class_prefix = 'ays-chart-';
25
26 $user_id = get_current_user_id();
27 $user = get_userdata($user_id);
28
29 $options = array();
30
31 $google_charts = array(
32 'line_chart' => [
33 'name' => 'Line Chart',
34 'icon' => 'line-chart-logo.png',
35 'demo' => 'http://bit.ly/3P2ZDmy',
36 'pro' => false,
37 ],
38 'bar_chart' => [
39 'name' => 'Bar Chart',
40 'icon' => 'bar-chart-logo.png',
41 'demo' => 'http://bit.ly/3iuLxxV',
42 'pro' => false,
43 ],
44 'pie_chart' => [
45 'name' => 'Pie Chart',
46 'icon' => 'pie-chart-logo.png',
47 'demo' => 'http://bit.ly/3BgvACe',
48 'pro' => false,
49 ],
50 'column_chart' => [
51 'name' => 'Column Chart',
52 'icon' => 'column-chart-logo.png',
53 'demo' => 'http://bit.ly/3Pc1CFe',
54 'pro' => false,
55 ],
56 'org_chart' => [
57 'name' => 'Org Chart',
58 'icon' => 'org-chart-logo.png',
59 'demo' => 'https://bit.ly/3VQXop7',
60 'pro' => false,
61 ],
62 'donut_chart' => [
63 'name' => 'Donut Chart',
64 'icon' => 'donut-chart-logo.png',
65 'demo' => 'http://bit.ly/3HgvEWi',
66 'pro' => false,
67 ],
68 'histogram' => [
69 'name' => 'Histogram',
70 'icon' => 'histogram-logo.png',
71 'demo' => 'http://bit.ly/3upA59L',
72 'pro' => true,
73 ],
74 'geo_chart' => [
75 'name' => 'Geo Chart',
76 'icon' => 'geo-chart-logo.png',
77 'demo' => 'http://bit.ly/3iIq4Sc',
78 'pro' => true,
79 ],
80 'area_chart' => [
81 'name' => 'Area Chart',
82 'icon' => 'area-chart-logo.png',
83 'demo' => 'https://ays-demo.com/area-chart-demo/',
84 'pro' => true,
85 ],
86 'gauge_chart' => [
87 'name' => 'Gauge Chart',
88 'icon' => 'gauge-chart-logo.png',
89 'demo' => 'https://ays-demo.com/gauge-chart-demo/',
90 'pro' => true,
91 ],
92 'combo_chart' => [
93 'name' => 'Combo Chart',
94 'icon' => 'combo-chart-logo.png',
95 'demo' => 'https://ays-demo.com/combo-chart-demo/',
96 'pro' => true,
97 ],
98 'stepped_area_chart' => [
99 'name' => 'Stepped Area Chart',
100 'icon' => 'stepped-area-chart-logo.png',
101 'demo' => 'https://ays-demo.com/stepped-area-chart-demo/',
102 'pro' => true,
103 ],
104 'bubble_chart' => [
105 'name' => 'Bubble Chart',
106 'icon' => 'bubble-chart-logo.png',
107 'demo' => 'https://ays-demo.com/bubble-chart-demo/',
108 'pro' => true,
109 ],
110 'scatter_chart' => [
111 'name' => 'Scatter Chart',
112 'icon' => 'scatter-chart-logo.png',
113 'demo' => 'https://ays-demo.com/scatter-chart-demo/',
114 'pro' => true,
115 ],
116 'table_chart' => [
117 'name' => 'Table Chart',
118 'icon' => 'table-chart-logo.png',
119 'demo' => 'https://ays-demo.com/table-chart-demo/',
120 'pro' => true,
121 ],
122 'timeline_chart' => [
123 'name' => 'Timeline Chart',
124 'icon' => 'timeline-chart-logo.png',
125 'demo' => 'https://ays-demo.com/timeline-chart-demo/',
126 'pro' => true,
127 ],
128 'candlestick_chart' => [
129 'name' => 'Candlestick Chart',
130 'icon' => 'candlestick-chart-logo.png',
131 'demo' => 'https://ays-demo.com/candlestick-chart-demo/',
132 'pro' => true,
133 ],
134 'gantt_chart' => [
135 'name' => 'Gantt Chart',
136 'icon' => 'gantt-chart-logo.png',
137 'demo' => 'https://ays-demo.com/gantt-chart-demo/',
138 'pro' => true,
139 ],
140 'sankey_diagram' => [
141 'name' => 'Sankey Diagram',
142 'icon' => 'sankey-chart-logo.png',
143 'demo' => 'https://ays-demo.com/sankey-diagram-chart-demo/',
144 'pro' => true,
145 ],
146 'treemap' => [
147 'name' => 'Treemap',
148 'icon' => 'treemap-chart-logo.png',
149 'demo' => 'https://ays-demo.com/threemap-chart-demo/',
150 'pro' => true,
151 ],
152 'word_tree' => [
153 'name' => 'Word Tree',
154 'icon' => 'word-tree-logo.png',
155 'demo' => 'https://ays-demo.com/word-tree-chart-demo/',
156 'pro' => true,
157 ],
158 '3dpie_chart' => [
159 'name' => '3D Pie Chart',
160 'icon' => '3d-pie-chart-logo.png',
161 'demo' => 'https://ays-demo.com/3d-pie-chart-demo/',
162 'pro' => true,
163 ],
164 );
165
166 $chartjs_charts = array(
167 'line_chart' => [
168 'name' => 'Line Chart',
169 'icon' => 'line-chart-logo.png',
170 'demo' => '',
171 'pro' => false,
172 ],
173 'bar_chart' => [
174 'name' => 'Bar Chart',
175 'icon' => 'bar-chart-logo.png',
176 'demo' => '',
177 'pro' => false,
178 ],
179 'pie_chart' => [
180 'name' => 'Pie Chart',
181 'icon' => 'pie-chart-logo.png',
182 'demo' => '',
183 'pro' => false,
184 ],
185 );
186
187 $chart_types = array(
188 'line_chart' => "Line Chart",
189 'bar_chart' => "Bar Chart",
190 'pie_chart' => "Pie Chart",
191 'column_chart' => "Column Chart",
192 'org_chart' => 'Org Chart',
193 'donut_chart' => 'Donut Chart',
194 );
195
196 $chart_source_types = array(
197 'google-charts' => "Google Charts",
198 'chart-js' => "Chart.js",
199 );
200
201 $chart_types_names = array(
202 'line_chart' => "Line",
203 'bar_chart' => "Bar",
204 'pie_chart' => "Pie",
205 'column_chart' => "Column",
206 'org_chart' => 'Org',
207 'donut_chart' => 'Donut',
208 );
209
210 $object = array(
211 'title' => '',
212 'description' => '',
213 'type' => 'google-charts',
214 'source_chart_type' => 'pie_chart',
215 'source_type' => 'manual',
216 'source' => '',
217 'status' => 'published',
218 'date_created' => current_time( 'mysql' ),
219 'date_modified' => current_time( 'mysql' ),
220 'options' => json_encode( $options ),
221 );
222
223 $chart_data = array(
224 'chart' => $object,
225 'source_type' => 'manual',
226 'source' => '',
227 'settings' => array(),
228 'options' => array(),
229 );
230
231 $similar_charts = array(
232 'pie_chart' => array(
233 'pie_chart' => 'pie-chart.png',
234 'donut_chart' => 'donut-chart.png',
235 ),
236 'donut_chart' => array(
237 'pie_chart' => 'pie-chart.png',
238 'donut_chart' => 'donut-chart.png',
239 ),
240 'bar_chart' => array(
241 'bar_chart' => 'bar-chart.png',
242 'column_chart' => 'column-chart.png',
243 'line_chart' => 'line-chart.png',
244 ),
245 'line_chart' => array(
246 'bar_chart' => 'bar-chart.png',
247 'column_chart' => 'column-chart.png',
248 'line_chart' => 'line-chart.png',
249 ),
250 'column_chart' => array(
251 'bar_chart' => 'bar-chart.png',
252 'column_chart' => 'column-chart.png',
253 'line_chart' => 'line-chart.png',
254 ),
255 );
256
257 $quiz_queries = array(
258 'q1' => __("The number of times all the users have passed the particular quiz", "chart-builder"),
259 'q2' => __("The number of times the current user has passed all quizzes daily", "chart-builder"),
260 'q3' => __("The number of times the current user has passed the current quiz", "chart-builder"),
261 'q4' => __("The average score of current user of each quiz", "chart-builder"),
262 'q5' => __("The number of times the current user has passed each quiz overall", "chart-builder"),
263 'q6' => __("The current user's scores of the chosen quiz", "chart-builder"),
264 'q7' => __("The average scores of current user of the quizzes for each quiz category (PRO)", "chart-builder"),
265 'q8' => __("The number of times the user passed the chosen category quizzes (PRO)", "chart-builder"),
266 'q9' => __("The number of people who got the particular score (PRO)", "chart-builder"),
267 'q10' => __("The number of people based on the particular Interval score (PRO)", "chart-builder"),
268 'q11' => __("The count of the logged-in users and guests for the last 7 days (PRO)", "chart-builder"),
269 'q12' => __("The answers count for each question of the chosen quiz (PRO)", "chart-builder"),
270 'q13' => __("The answers count of the chosen quiz/question category (PRO)", "chart-builder"),
271 'q14' => __("The number of times all the users passed all the quizzes for the last 7 days (PRO)", "chart-builder")
272 );
273
274 $quiz_query_tooltips = array(
275 '' => __( 'Select a query to display quiz data.', "chart-builder" ),
276 'q1' => __("If you enable this option, you can display how many times all the users passed the particular quiz.", "chart-builder"),
277 'q2' => __("If you enable this option, you can display how many times the current user has passed all quizzes on a daily basis.", "chart-builder"),
278 'q3' => __("If you enable this option, you can display how many times the current user has passed the particular quiz.", "chart-builder"),
279 'q4' => __("If you enable this option, you can show the average score of each quiz the current user has passed.", "chart-builder"),
280 'q5' => __("If you enable this option, you can display how many times the current user has passed each quiz in general.", "chart-builder"),
281 'q6' => __("If you enable this option, the scores the current user got for the particular quiz will be displayed.", "chart-builder"),
282 'q7' => __("If you enable this option, the average scores of quizzes of each quiz category the current user has passed will be displayed for all users.", "chart-builder"),
283 'q8' => __("If you enable this option, you can show how many times the current user passed the quizzes of each category.", "chart-builder"),
284 'q9' => __("If you enable this option, you can group users by score. That is how many people received a particular grade for the chosen quiz.", "chart-builder"),
285 'q10' => __("If you enable this option, you can display the number of people with their score by Intervals.", "chart-builder"),
286 'q11' => __("If you enable this option, you can show the count statistics of the logged-in and non-logged-in users (guests) who passed the particular quiz within the last 7 days.", "chart-builder"),
287 'q12' => __("If you enable this option, you can show all the answers count (Correct/Incorrect/Unanswered) of the chosen quiz for each question of each user.", "chart-builder"),
288 'q13' => "<ul style='padding: 0; list-style-type: none;'>" .
289 '<li>' . sprintf( __("%sBy%s - Choose the method of filtering."), '<b>', '</b>' ) . '</li>' .
290 '<li>' . sprintf( __("%sBy quiz:%s Display all the questions of the chosen quiz"), '<b>', '</b>' ) . '</li>' .
291 '<li>' . sprintf( __("%sBy question category:%s Display all questions of the chosen category (of all quizzes)"), '<b>', '</b>' ) . '</li>' .
292 '<li>' . sprintf( __("%sBy quiz and question category:%s Display all the questions of the particular category of the chosen quiz", "chart-builder"), '<b>', '</b>' ) . '</li>' .
293 '</ul>',
294 'q14' => __("If you enable this option, you can display the number of times all the users (logged-in/guests) passed all the quizzes within the last 7 days", "chart-builder")
295 );
296
297 $heading = '';
298 switch ($action) {
299 case 'add':
300 $heading = __( 'Add new chart', "chart-builder" );
301 break;
302 case 'edit':
303 $heading = __( 'Edit chart', "chart-builder" );
304 $object = $this->db_obj->get_item( $id );
305 $chart_data = CBActions()->get_chart_data( $id );
306 break;
307 }
308
309 if( isset( $_POST['ays_submit'] ) || isset( $_POST['ays_submit_top'] ) ) {
310 $this->db_obj->add_or_edit_item( $id );
311 }
312
313 if( isset( $_POST['ays_apply'] ) || isset( $_POST['ays_apply_top'] ) ){
314 $_POST['save_type'] = 'apply';
315 $this->db_obj->add_or_edit_item( $id );
316 }
317
318 if( isset( $_POST['ays_save_new'] ) || isset( $_POST['ays_save_new_top'] ) ){
319 $_POST['save_type'] = 'save_new';
320 $this->db_obj->add_or_edit_item( $id );
321 }
322
323 $loader_iamge = '<span class="display_none ays_chart_loader_box"><img src="'. CHART_BUILDER_ADMIN_URL .'/images/loaders/loading.gif"></span>';
324
325 /**
326 * Data that need to get form @object variable
327 *
328 * @object is a data directly from database
329 */
330
331 // Date created
332 $date_created = isset( $object['date_created'] ) && CBFunctions()->validateDate( $object['date_created'] ) ? esc_attr($object['date_created']) : current_time( 'mysql' );
333
334 // Date modified
335 $date_modified = current_time( 'mysql' );
336
337 /**
338 * Data that need to get form @chart variable
339 */
340
341 // Chart
342 $chart = $chart_data['chart'];
343
344 // Source type
345 $source_type = stripslashes( $chart['source_type'] );
346
347 if ($action === "add") {
348 // Chart source type
349 $allowed_sources = ['google-charts', 'chart-js'];
350 $chart_source_type = isset($_GET['source']) && in_array($_GET['source'], $allowed_sources, true) ? sanitize_text_field($_GET['source']) : 'google-charts';
351
352 // Chart type
353 $source_chart_type = isset($_GET['type']) ? sanitize_text_field($_GET['type']) : 'pie_chart';
354 } else {
355 $chart_source_type = stripslashes( $chart['type'] );
356 $source_chart_type = stripslashes( $chart['source_chart_type'] );
357 }
358
359 if ($chart_source_type === 'chart-js') {
360 $chart_source_default_data = CBActions()->get_charts_default_data_chartjs();
361 } else {
362 $chart_source_default_data = CBActions()->get_charts_default_data_google();
363 if (!isset($chart_data['source']) || empty($chart_data['source'])) {
364 $chart_source_default_data = ($source_chart_type == 'org_chart') ? $chart_source_default_data['orgTypeChart'] : $chart_source_default_data['commonTypeCharts'];
365 }
366 }
367
368 // Source
369 $source = isset($chart_data['source']) && !empty($chart_data['source']) ? $chart_data['source'] : $chart_source_default_data;
370
371 //Source Ordering for Org Chart Type
372 $ordering = [];
373 if (isset($chart_data['source']) && !empty($chart_data['source'])) {
374 foreach($source as $key => $value) {
375 if ($key != 0) {
376 array_push($ordering, $key);
377 }
378 }
379 } else {
380 $ordering = [1, 2, 3, 4, 5];
381 }
382
383 // Title
384 $title = stripcslashes( $chart['title'] );
385
386 // Description
387 $description = stripcslashes( $chart['description'] );
388
389 // Status
390 $status = stripslashes( $chart['status'] );
391
392 // Quiz query
393 $quiz_query = isset($chart_data['quiz_query']) ? stripslashes($chart_data['quiz_query']) : '';
394
395 // Quiz id
396 $quiz_id = isset($chart_data['quiz_id']) ? intval($chart_data['quiz_id']) : 0;
397
398 // Change the author of the current chart
399 $change_create_author = (isset($chart['author_id']) && $chart['author_id'] != '') ? absint( sanitize_text_field( $chart['author_id'] ) ) : $user_id;
400
401 if ( $change_create_author && $change_create_author > 0 ) {
402 global $wpdb;
403 $users_table = esc_sql( $wpdb->prefix . 'users' );
404 $sql_users = "SELECT ID, display_name FROM {$users_table} WHERE ID = {$change_create_author}";
405
406 $create_author_data = $wpdb->get_row($sql_users, "ARRAY_A");
407
408 if (!isset($create_author_data)) {
409 $create_author_data = array(
410 "ID" => 0,
411 "display_name" => __('Deleted user', 'chart-builder'),
412 );
413 }
414 } else {
415 $change_create_author = $user_id;
416 $create_author_data = array(
417 "ID" => $user_id,
418 "display_name" => $user->data->display_name,
419 );
420 }
421
422 /**
423 * Data that need to get form @settings variable
424 */
425 if ($chart_source_type === "chart-js") {
426 $settings = CBFunctions()->get_chart_settings_chartjs_admin($chart_data['settings']);
427 } else {
428 $settings = CBFunctions()->get_chart_settings_google_admin($chart_data['settings'], $action, $source);
429 }
430
431 /**
432 * Data that need to get form @options variable
433 */
434 $options = $object['options'];
435
436 // Send data to JS
437 $source_data_for_js = array(
438 'source' => $source,
439 'source_ordering' => $ordering,
440 'quiz_query_tooltips' => $quiz_query_tooltips,
441 'action' => $action,
442 'settings' => $settings,
443 'chartType' => $source_chart_type,
444 'chartSourceType' => $chart_source_type,
445 'chartTypesNames' => $chart_types_names,
446 'chartTypesConnections' => $similar_charts,
447 'imagesUrl' => CHART_BUILDER_ADMIN_URL.'/images',
448 'addManualDataRow' => CHART_BUILDER_ADMIN_URL . '/images/icons/add-circle-outline.svg',
449 // 'removeManualDataRow' => CHART_BUILDER_ADMIN_URL . '/images/icons/xmark.svg',
450 );
451 wp_localize_script( $this->plugin_name, "ChartBuilderSourceData" , $source_data_for_js );