| 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); |