← All changes
|
admin/partials/charts/actions/chart-builder-charts-actions-options.php
+471
-171
trunk
→
3.8.1
View file →
| @@ -1,171 +1,471 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | - $action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; | |
| 4 | - | |
| 5 | - $id = (isset($_GET['id'])) ? absint( esc_attr($_GET['id']) ) : 0; | |
| 6 | - | |
| 7 | - $html_name_prefix = 'ays_'; | |
| 8 | - $html_class_prefix = 'ays-chart-'; | |
| 9 | - | |
| 10 | - $user_id = get_current_user_id(); | |
| 11 | - | |
| 12 | - $options = array( | |
| 13 | - | |
| 14 | - ); | |
| 15 | - | |
| 16 | - $chart_types = array( | |
| 17 | - 'bar_chart' => "Bar Chart", | |
| 18 | - 'pie_chart' => "Pie Chart", | |
| 19 | - 'column_chart' => "Column Chart", | |
| 20 | - ); | |
| 21 | - | |
| 22 | - $object = array( | |
| 23 | - 'title' => '', | |
| 24 | - 'description' => '', | |
| 25 | - 'type' => 'google-charts', | |
| 26 | - 'source_chart_type' => 'pie_chart', | |
| 27 | - 'source_type' => 'manual', | |
| 28 | - 'source' => '', | |
| 29 | - 'status' => 'published', | |
| 30 | - 'date_created' => current_time( 'mysql' ), | |
| 31 | - 'date_modified' => current_time( 'mysql' ), | |
| 32 | - 'options' => json_encode( $options ), | |
| 33 | - ); | |
| 34 | - | |
| 35 | - $chart_data = array( | |
| 36 | - 'chart' => $object, | |
| 37 | - 'source_type' => 'manual', | |
| 38 | - 'source' => '', | |
| 39 | - 'settings' => array(), | |
| 40 | - 'options' => array(), | |
| 41 | - ); | |
| 42 | - | |
| 43 | - $tooltip_trigger_options = array( | |
| 44 | - "hover" => __("While hovering", "chart-builder"), | |
| 45 | - "selection" => __("When selected", "chart-builder"), | |
| 46 | - "none" => __("Disable", "chart-builder") | |
| 47 | - ); | |
| 48 | - | |
| 49 | - $chart_source_default_data = CBActions()->get_charts_default_data(); | |
| 50 | - | |
| 51 | - $heading = ''; | |
| 52 | - switch ($action) { | |
| 53 | - case 'add': | |
| 54 | - $heading = __( 'Add new chart', "chart-builder" ); | |
| 55 | - break; | |
| 56 | - case 'edit': | |
| 57 | - $heading = __( 'Edit chart', "chart-builder" ); | |
| 58 | - $object = $this->db_obj->get_item( $id ); | |
| 59 | - $chart_data = CBActions()->get_chart_data( $id ); | |
| 60 | - break; | |
| 61 | - } | |
| 62 | - | |
| 63 | - if( isset( $_POST['ays_submit'] ) || isset( $_POST['ays_submit_top'] ) ) { | |
| 64 | - $this->db_obj->add_or_edit_item( $id ); | |
| 65 | - } | |
| 66 | - | |
| 67 | - if( isset( $_POST['ays_apply'] ) || isset( $_POST['ays_apply_top'] ) ){ | |
| 68 | - $_POST['save_type'] = 'apply'; | |
| 69 | - $this->db_obj->add_or_edit_item( $id ); | |
| 70 | - } | |
| 71 | - | |
| 72 | - if( isset( $_POST['ays_save_new'] ) || isset( $_POST['ays_save_new_top'] ) ){ | |
| 73 | - $_POST['save_type'] = 'save_new'; | |
| 74 | - $this->db_obj->add_or_edit_item( $id ); | |
| 75 | - } | |
| 76 | - | |
| 77 | - | |
| 78 | - $loader_iamge = '<span class="display_none ays_chart_loader_box"><img src="'. CHART_BUILDER_ADMIN_URL .'/images/loaders/loading.gif"></span>'; | |
| 79 | - | |
| 80 | - /** | |
| 81 | - * Data that need to get form @object variable | |
| 82 | - * | |
| 83 | - * @object is a data directly from database | |
| 84 | - */ | |
| 85 | - | |
| 86 | - // Date created | |
| 87 | - $date_created = isset( $object['date_created'] ) && CBFunctions()->validateDate( $object['date_created'] ) ? esc_attr($object['date_created']) : current_time( 'mysql' ); | |
| 88 | - | |
| 89 | - // Date modified | |
| 90 | - $date_modified = current_time( 'mysql' ); | |
| 91 | - | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * Data that need to get form @chart_data variable | |
| 95 | - */ | |
| 96 | - | |
| 97 | - | |
| 98 | - | |
| 99 | - /** | |
| 100 | - * Data that need to get form @chart variable | |
| 101 | - */ | |
| 102 | - | |
| 103 | - // Chart | |
| 104 | - $chart = $chart_data['chart']; | |
| 105 | - | |
| 106 | - // Source | |
| 107 | - $source = isset($chart_data['source']) && $chart_data['source'] != '' ? $chart_data['source'] : $chart_source_default_data; | |
| 108 | - | |
| 109 | - // Source type | |
| 110 | - $source_type = stripslashes( $chart['source_type'] ); | |
| 111 | - | |
| 112 | - // Chart type | |
| 113 | - $source_chart_type = stripslashes( $chart['source_chart_type'] ); | |
| 114 | - | |
| 115 | - // Title | |
| 116 | - $title = stripcslashes( $chart['title'] ); | |
| 117 | - | |
| 118 | - // Description | |
| 119 | - $description = stripcslashes( $chart['description'] ); | |
| 120 | - | |
| 121 | - // Status | |
| 122 | - $status = stripslashes( $chart['status'] ); | |
| 123 | - | |
| 124 | - | |
| 125 | - /** | |
| 126 | - * Data that need to get form @settings variable | |
| 127 | - */ | |
| 128 | - | |
| 129 | - // Settings | |
| 130 | - $settings = $chart_data['settings']; | |
| 131 | - | |
| 132 | - // Width | |
| 133 | - $settings['width'] = isset( $settings['width'] ) && $settings['width'] != '' ? esc_attr( $settings['width'] ) : '100'; | |
| 134 | - | |
| 135 | - // Height | |
| 136 | - $settings['height'] = isset( $settings['height'] ) && $settings['height'] != '' ? esc_attr( $settings['height'] ) : '400'; | |
| 137 | - | |
| 138 | - // Font size | |
| 139 | - $settings['font_size'] = isset( $settings['font_size'] ) && $settings['font_size'] != '' ? esc_attr( $settings['font_size'] ) : '15'; | |
| 140 | - | |
| 141 | - // Title color | |
| 142 | - $settings['title_color'] = isset( $settings['title_color'] ) && $settings['title_color'] != '' ? esc_attr( $settings['title_color'] ) : '#000000'; | |
| 143 | - | |
| 144 | - // Tooltip trigger | |
| 145 | - $settings['tooltip_trigger'] = isset( $settings['tooltip_trigger'] ) && $settings['tooltip_trigger'] != '' ? esc_attr( $settings['tooltip_trigger'] ) : 'hover'; | |
| 146 | - $settings['tooltip_trigger_options'] = $tooltip_trigger_options; | |
| 147 | - | |
| 148 | - // Show color code | |
| 149 | - $settings['show_color_code'] = ( isset( $settings['show_color_code'] ) && $settings['show_color_code'] != '' ) ? $settings['show_color_code'] : 'off'; | |
| 150 | - $settings['show_color_code'] = isset( $settings['show_color_code'] ) && $settings['show_color_code'] == 'on' ? 'checked' : ''; | |
| 151 | - | |
| 152 | - $settings['colors'] = ['#3366cc', '#dc3912', '#ff9900', '#109618', '#990099', '#0099c6', '#dd4477', '#66aa00', '#b82e2e', '#316395']; | |
| 153 | - | |
| 154 | - | |
| 155 | -/** | |
| 156 | - * Data that need to get form @options variable | |
| 157 | - */ | |
| 158 | - | |
| 159 | - // Options | |
| 160 | - $options = $object['options']; | |
| 161 | - | |
| 162 | - // Send data to JS | |
| 163 | - $source_data_for_js = array( | |
| 164 | - 'source' => $source, | |
| 165 | - 'action' => $action, | |
| 166 | - 'settings' => $settings, | |
| 167 | - 'chartType' => $source_chart_type, | |
| 168 | - 'addManualDataRow' => CHART_BUILDER_ADMIN_URL . '/images/icons/add-circle-outline.svg', | |
| 169 | - // 'removeManualDataRow' => CHART_BUILDER_ADMIN_URL . '/images/icons/xmark.svg', | |
| 170 | - ); | |
| 171 | - wp_localize_script($this->plugin_name, "ChartBuilderSourceData" , $source_data_for_js); | |
| 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( wp_unslash($_GET['action'] )) : ''; | |
| 8 | + | |
| 9 | + $id = (isset($_GET['id'])) ? absint( esc_attr(wp_unslash($_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( | |
| 290 | + /* translators: %1$s: Opening <b> tag, %2$s: Closing </b> tag */ | |
| 291 | + __( "%1\$sBy%2\$s - Choose the method of filtering.", "chart-builder"),'<b>', '</b>' | |
| 292 | + ) . | |
| 293 | + '</li>' . | |
| 294 | + '<li>' . sprintf( | |
| 295 | + /* translators: %1$s: Opening <b> tag, %2$s: Closing </b> tag */ | |
| 296 | + __( "%1\$sBy quiz:%2\$s Display all the questions of the chosen quiz", "chart-builder"), '<b>', '</b>' | |
| 297 | + ) . | |
| 298 | + '</li>' . | |
| 299 | + '<li>' . sprintf( | |
| 300 | + /* translators: %1$s: Opening <b> tag, %2$s: Closing </b> tag */ | |
| 301 | + __( "%1\$sBy question category:%2\$s Display all questions of the chosen category (of all quizzes)", "chart-builder"), '<b>', '</b>' | |
| 302 | + ) . | |
| 303 | + '</li>' . | |
| 304 | + '<li>' . sprintf( | |
| 305 | + /* translators: %1$s: Opening <b> tag, %2$s: Closing </b> tag */ | |
| 306 | + __( "%1\$sBy quiz and question category:%2\$s Display all the questions of the particular category of the chosen quiz", "chart-builder"), '<b>', '</b>' | |
| 307 | + ) . | |
| 308 | + '</li>' . | |
| 309 | + '</ul>', | |
| 310 | + '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") | |
| 311 | + ); | |
| 312 | + | |
| 313 | + $heading = ''; | |
| 314 | + switch ($action) { | |
| 315 | + case 'add': | |
| 316 | + $heading = __( 'Add new chart', "chart-builder" ); | |
| 317 | + break; | |
| 318 | + case 'edit': | |
| 319 | + $heading = __( 'Edit chart', "chart-builder" ); | |
| 320 | + $object = $this->db_obj->get_item( $id ); | |
| 321 | + $chart_data = CBActions()->get_chart_data( $id ); | |
| 322 | + break; | |
| 323 | + } | |
| 324 | + | |
| 325 | + if( isset( $_POST['ays_submit'] ) || isset( $_POST['ays_submit_top'] ) ) { | |
| 326 | + $this->db_obj->add_or_edit_item( $id ); | |
| 327 | + } | |
| 328 | + | |
| 329 | + if( isset( $_POST['ays_apply'] ) || isset( $_POST['ays_apply_top'] ) ){ | |
| 330 | + $_POST['save_type'] = 'apply'; | |
| 331 | + $this->db_obj->add_or_edit_item( $id ); | |
| 332 | + } | |
| 333 | + | |
| 334 | + if( isset( $_POST['ays_save_new'] ) || isset( $_POST['ays_save_new_top'] ) ){ | |
| 335 | + $_POST['save_type'] = 'save_new'; | |
| 336 | + $this->db_obj->add_or_edit_item( $id ); | |
| 337 | + } | |
| 338 | + | |
| 339 | + $loader_iamge = '<span class="display_none ays_chart_loader_box"><img src="'. esc_url(plugins_url('admin/images/loaders/loading.gif', dirname(__FILE__))) .'"></span>';// phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage | |
| 340 | + | |
| 341 | + /** | |
| 342 | + * Data that need to get form @object variable | |
| 343 | + * | |
| 344 | + * @object is a data directly from database | |
| 345 | + */ | |
| 346 | + | |
| 347 | + // Date created | |
| 348 | + $date_created = isset( $object['date_created'] ) && CBFunctions()->validateDate( $object['date_created'] ) ? esc_attr($object['date_created']) : current_time( 'mysql' ); | |
| 349 | + | |
| 350 | + // Date modified | |
| 351 | + $date_modified = current_time( 'mysql' ); | |
| 352 | + | |
| 353 | + /** | |
| 354 | + * Data that need to get form @chart variable | |
| 355 | + */ | |
| 356 | + | |
| 357 | + // Chart | |
| 358 | + $chart = $chart_data['chart']; | |
| 359 | + | |
| 360 | + // Source type | |
| 361 | + $source_type = stripslashes( $chart['source_type'] ); | |
| 362 | + | |
| 363 | + if ($action === "add") { | |
| 364 | + // Chart source type | |
| 365 | + $allowed_sources = ['google-charts', 'chart-js']; | |
| 366 | + $chart_source_type = isset($_GET['source']) && in_array($_GET['source'], $allowed_sources, true) ? sanitize_text_field(wp_unslash($_GET['source'])) : 'google-charts'; | |
| 367 | + | |
| 368 | + // Chart type | |
| 369 | + $source_chart_type = isset($_GET['type']) ? sanitize_text_field(wp_unslash($_GET['type'])) : 'pie_chart'; | |
| 370 | + } else { | |
| 371 | + $chart_source_type = stripslashes( $chart['type'] ); | |
| 372 | + $source_chart_type = stripslashes( $chart['source_chart_type'] ); | |
| 373 | + } | |
| 374 | + | |
| 375 | + if ($chart_source_type === 'chart-js') { | |
| 376 | + $chart_source_default_data = CBActions()->get_charts_default_data_chartjs(); | |
| 377 | + } else { | |
| 378 | + $chart_source_default_data = CBActions()->get_charts_default_data_google(); | |
| 379 | + if (!isset($chart_data['source']) || empty($chart_data['source'])) { | |
| 380 | + $chart_source_default_data = ($source_chart_type == 'org_chart') ? $chart_source_default_data['orgTypeChart'] : $chart_source_default_data['commonTypeCharts']; | |
| 381 | + } | |
| 382 | + } | |
| 383 | + | |
| 384 | + // Source | |
| 385 | + $source = isset($chart_data['source']) && !empty($chart_data['source']) ? $chart_data['source'] : $chart_source_default_data; | |
| 386 | + | |
| 387 | + //Source Ordering for Org Chart Type | |
| 388 | + $ordering = []; | |
| 389 | + if (isset($chart_data['source']) && !empty($chart_data['source'])) { | |
| 390 | + foreach($source as $key => $value) { | |
| 391 | + if ($key != 0) { | |
| 392 | + array_push($ordering, $key); | |
| 393 | + } | |
| 394 | + } | |
| 395 | + } else { | |
| 396 | + $ordering = [1, 2, 3, 4, 5]; | |
| 397 | + } | |
| 398 | + | |
| 399 | + // Title | |
| 400 | + $title = stripcslashes( $chart['title'] ); | |
| 401 | + | |
| 402 | + // Description | |
| 403 | + $description = stripcslashes( $chart['description'] ); | |
| 404 | + | |
| 405 | + // Status | |
| 406 | + $status = stripslashes( $chart['status'] ); | |
| 407 | + | |
| 408 | + // Quiz query | |
| 409 | + $quiz_query = isset($chart_data['quiz_query']) ? stripslashes($chart_data['quiz_query']) : ''; | |
| 410 | + | |
| 411 | + // Quiz id | |
| 412 | + $quiz_id = isset($chart_data['quiz_id']) ? intval($chart_data['quiz_id']) : 0; | |
| 413 | + | |
| 414 | + // Change the author of the current chart | |
| 415 | + $change_create_author = (isset($chart['author_id']) && $chart['author_id'] != '') ? absint( sanitize_text_field( $chart['author_id'] ) ) : $user_id; | |
| 416 | + | |
| 417 | + if ( $change_create_author && $change_create_author > 0 ) { | |
| 418 | + global $wpdb; | |
| 419 | + $users_table = esc_sql( $wpdb->prefix . 'users' ); | |
| 420 | + $create_author_data = $wpdb->get_row( // phpcs:ignore | |
| 421 | + $wpdb->prepare( | |
| 422 | + "SELECT ID, display_name FROM {$wpdb->users} WHERE ID = %d", | |
| 423 | + $change_create_author | |
| 424 | + ), | |
| 425 | + ARRAY_A | |
| 426 | + ); | |
| 427 | + | |
| 428 | + if (!isset($create_author_data)) { | |
| 429 | + $create_author_data = array( | |
| 430 | + "ID" => 0, | |
| 431 | + "display_name" => __('Deleted user', 'chart-builder'), | |
| 432 | + ); | |
| 433 | + } | |
| 434 | + } else { | |
| 435 | + $change_create_author = $user_id; | |
| 436 | + $create_author_data = array( | |
| 437 | + "ID" => $user_id, | |
| 438 | + "display_name" => $user->data->display_name, | |
| 439 | + ); | |
| 440 | + } | |
| 441 | + | |
| 442 | + /** | |
| 443 | + * Data that need to get form @settings variable | |
| 444 | + */ | |
| 445 | + if ($chart_source_type === "chart-js") { | |
| 446 | + $settings = CBFunctions()->get_chart_settings_chartjs_admin($chart_data['settings'], $source); | |
| 447 | + } else { | |
| 448 | + $settings = CBFunctions()->get_chart_settings_google_admin($chart_data['settings'], $action, $source); | |
| 449 | + } | |
| 450 | + | |
| 451 | + /** | |
| 452 | + * Data that need to get form @options variable | |
| 453 | + */ | |
| 454 | + $options = $object['options']; | |
| 455 | + | |
| 456 | + // Send data to JS | |
| 457 | + $source_data_for_js = array( | |
| 458 | + 'source' => $source, | |
| 459 | + 'source_ordering' => $ordering, | |
| 460 | + 'quiz_query_tooltips' => $quiz_query_tooltips, | |
| 461 | + 'action' => $action, | |
| 462 | + 'settings' => $settings, | |
| 463 | + 'chartType' => $source_chart_type, | |
| 464 | + 'chartSourceType' => $chart_source_type, | |
| 465 | + 'chartTypesNames' => $chart_types_names, | |
| 466 | + 'chartTypesConnections' => $similar_charts, | |
| 467 | + 'imagesUrl' => CHART_BUILDER_ADMIN_URL.'/images', | |
| 468 | + 'addManualDataRow' => CHART_BUILDER_ADMIN_URL . '/images/icons/add-circle-outline.svg', | |
| 469 | + // 'removeManualDataRow' => CHART_BUILDER_ADMIN_URL . '/images/icons/xmark.svg', | |
| 470 | + ); | |
| 471 | + wp_localize_script( $this->plugin_name, "ChartBuilderSourceData" , $source_data_for_js ); | |