/** * init() * * Initialize the class. * * @since 1.0.0 */ function init() { // Register the admin screen. add_action('admin_menu', array(&$this, 'register_admin_screen'), 20); $shortname = 'colabs'; $options_gateways = array(); $currencies = colabs_get_currencies(); foreach ($currencies as $key => $currency) { $options_currency[$key] = $currency['name'] . ' (' . $currency['symbol'] . ')'; } $currency_symbol = colabs_get_currency_symbol(get_option('colabs_currency_code')); $options_gateways[] = array("name" => __('Payments General', 'colabsthemes'), "icon" => "general", "type" => "heading"); $options_gateways[] = array("name" => __('Currency', 'colabsthemes'), "desc" => sprintf(__("This is the currency you want to collect payments in. It applies mainly to PayPal payments since other payment gateways accept more currencies. If your currency is not listed then PayPal currently does not support it. See the list of supported <a target='_new' href='%s'>PayPal currencies</a>.", 'colabsthemes'), 'https://www.paypal.com/cgi-bin/webscr?cmd=p/sell/mc/mc_intro-outside'), "id" => $shortname . "_currency_code", "options" => $options_currency, "type" => "select2"); $options_gateways[] = array("name" => __("Symbol Position", "colabsthemes"), "desc" => __("Some currencies place the symbol on the right side vs the left. Select how you would like your currency symbol to be displayed.", "colabsthemes"), "id" => $shortname . "_currency_position", "std" => "left", "type" => "select2", "options" => array('left' => sprintf(__('Left of Currency (%s100)', 'colabsthemes'), $currency_symbol), 'left_space' => sprintf(__('Left of Currency with Space (%s 100)', 'colabsthemes'), $currency_symbol), 'right' => sprintf(__('Right of Currency (100%s)', 'colabsthemes'), $currency_symbol), 'right_space' => sprintf(__('Right of Currency with Space (100 %s)', 'colabsthemes'), $currency_symbol))); $this->default_options_gateways = $options_gateways; }
function colabs_get_price($price, $currency_code = '', $currency_symbol = '') { if ('' == $currency_code) { $currency_code = get_option('colabs_currency_code'); } if ($currency_symbol == '') { $currency_symbol = colabs_get_currency_symbol($currency_code); } $position = get_option('colabs_currency_position'); $price = number_format(floatval($price)); switch ($position) { case 'left': $price = $currency_symbol . $price; break; case 'left_space': $price = $currency_symbol . ' ' . $price; break; case 'right': $price = $price . $currency_symbol; break; case 'right_space': $price = $price . ' ' . $currency_symbol; break; } return $price; }
public function get_main_chart() { global $wp_locale; // Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date $orders = $this->get_order_report_data(array('data' => array('total_price' => array('type' => 'meta', 'function' => 'SUM', 'name' => 'total_sales'), 'ID' => array('type' => 'post_data', 'function' => 'COUNT', 'name' => 'total_orders', 'distinct' => true), 'post_date' => array('type' => 'post_data', 'function' => '', 'name' => 'post_date')), 'group_by' => $this->group_by_query, 'order_by' => 'post_date ASC', 'query_type' => 'get_results', 'filter_range' => true)); // Prepare data for report $order_counts = $this->prepare_chart_data($orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby); $order_amounts = $this->prepare_chart_data($orders, 'post_date', 'total_sales', $this->chart_interval, $this->start_date, $this->chart_groupby); // Encode in json format $chart_data = json_encode(array('order_counts' => array_values($order_counts), 'order_amounts' => array_values($order_amounts))); ?> <div class="chart-container"> <div class="chart-placeholder main" ></div> </div> <script type="text/javascript"> var main_chart; jQuery(function($){ var order_data = jQuery.parseJSON( '<?php echo $chart_data; ?> ' ); var drawGraph = function( highlight ) { var series = [ { label: "<?php echo esc_js(__('Number of orders', 'colabsthemes')); ?> ", data: order_data.order_counts, color: '<?php echo $this->chart_colours['order_count']; ?> ', bars: { fillColor: '<?php echo $this->chart_colours['order_count']; ?> ', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' }, shadowSize: 0, hoverable: false }, { label: "<?php echo esc_js(__('Average sales amount', 'colabsthemes')); ?> ", data: [ [ <?php echo min(array_keys($order_amounts)); ?> , <?php echo $this->average_sales; ?> ], [ <?php echo max(array_keys($order_amounts)); ?> , <?php echo $this->average_sales; ?> ] ], yaxis: 2, color: '<?php echo $this->chart_colours['average']; ?> ', points: { show: false }, lines: { show: true, lineWidth: 2, fill: false }, shadowSize: 0, hoverable: false }, { label: "<?php echo esc_js(__('Sales amount', 'colabsthemes')); ?> ", data: order_data.order_amounts, yaxis: 2, color: '<?php echo $this->chart_colours['sales_amount']; ?> ', points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true }, lines: { show: true, lineWidth: 4, fill: false }, shadowSize: 0, prepend_tooltip: "<?php echo colabs_get_currency_symbol(get_option('colabs_currency_code')); ?> " } ]; if ( highlight !== 'undefined' && series[ highlight ] ) { highlight_series = series[ highlight ]; highlight_series.color = '#ea6d37'; if ( highlight_series.bars ) highlight_series.bars.fillColor = '#ea6d37'; if ( highlight_series.lines ) { highlight_series.lines.lineWidth = 5; } } main_chart = jQuery.plot( jQuery('.chart-placeholder.main'), series, { legend: { show: false }, grid: { color: '#aaa', borderColor: 'transparent', borderWidth: 0, hoverable: true }, xaxes: [ { color: '#aaa', position: "bottom", tickColor: 'transparent', mode: "time", timeformat: "<?php if ($this->chart_groupby == 'day') { echo '%d %b'; } else { echo '%b'; } ?> ", monthNames: <?php echo json_encode(array_values($wp_locale->month_abbrev)); ?> , tickLength: 1, minTickSize: [1, "<?php echo $this->chart_groupby; ?> "], font: { color: "#aaa" } } ], yaxes: [ { min: 0, minTickSize: 1, tickDecimals: 0, color: '#d4d9dc', font: { color: "#aaa" } }, { position: "right", min: 0, tickDecimals: 2, alignTicksWithAxis: 1, color: 'transparent', font: { color: "#aaa" } } ], } ); jQuery('.chart-placeholder').resize(); } drawGraph(); jQuery('.highlight_series').hover( function() { drawGraph( jQuery(this).data('series') ); }, function() { drawGraph(); } ); function showTooltip(x, y, contents) { jQuery('<div class="chart-tooltip">' + contents + '</div>').css( { top: y - 16, left: x + 20 }).appendTo("body").fadeIn(200); } var prev_data_index = null; var prev_series_index = null; jQuery(".chart-placeholder").bind( "plothover", function (event, pos, item) { if (item) { if ( prev_data_index != item.dataIndex || prev_series_index != item.seriesIndex ) { prev_data_index = item.dataIndex; prev_series_index = item.seriesIndex; jQuery( ".chart-tooltip" ).remove(); if ( item.series.points.show || item.series.enable_tooltip ) { var y = item.series.data[item.dataIndex][1]; tooltip_content = ''; if ( item.series.prepend_label ) tooltip_content = tooltip_content + item.series.label + ": "; if ( item.series.prepend_tooltip ) tooltip_content = tooltip_content + item.series.prepend_tooltip; tooltip_content = tooltip_content + y; if ( item.series.append_tooltip ) tooltip_content = tooltip_content + item.series.append_tooltip; showTooltip( item.pageX, item.pageY, tooltip_content ); } } } else { jQuery(".chart-tooltip").remove(); prev_data_index = null; } }); var dates = jQuery( ".range_datepicker" ).datepicker({ changeMonth: true, changeYear: true, defaultDate: "", dateFormat: "yy-mm-dd", numberOfMonths: 1, maxDate: "+0D", showButtonPanel: true, showOn: "focus", buttonImageOnly: true, onSelect: function( selectedDate ) { var option = jQuery(this).is('.from') ? "minDate" : "maxDate", instance = jQuery( this ).data( "datepicker" ), date = jQuery.datepicker.parseDate( instance.settings.dateFormat || jQuery.datepicker._defaults.dateFormat, selectedDate, instance.settings ); dates.not( this ).datepicker( "option", option, date ); } }); var a = document.createElement('a'); if ( typeof a.download == "undefined" ) { $('.export_csv').hide(); } // Export $('.export_csv').click(function(){ var exclude_series = $(this).data( 'exclude_series' ) || ''; exclude_series = exclude_series.toString(); exclude_series = exclude_series.split(','); var xaxes_label = $(this).data('xaxes'); var groupby = $(this).data('groupby'); var export_format = $(this).data('export'); var csv_data = "data:application/csv;charset=utf-8," if ( export_format == 'table' ) { $(this).closest('div').find('thead tr,tbody tr').each(function() { $(this).find('th,td').each(function() { value = $(this).text(); value = value.replace( '[?]', '' ); csv_data += '"' + value + '"' + ","; }); csv_data = csv_data.substring( 0, csv_data.length - 1 ); csv_data += "\n"; }); $(this).closest('div').find('tfoot tr').each(function() { $(this).find('th,td').each(function() { value = $(this).text(); value = value.replace( '[?]', '' ); csv_data += '"' + value + '"' + ","; if ( $(this).attr('colspan') > 0 ) for ( i = 1; i < $(this).attr('colspan'); i++ ) csv_data += '"",'; }); csv_data = csv_data.substring( 0, csv_data.length - 1 ); csv_data += "\n"; }); } else { if ( ! window.main_chart ) return false; var the_series = window.main_chart.getData(); var series = []; csv_data += xaxes_label + ","; $.each(the_series, function( index, value ) { if ( ! exclude_series || $.inArray( index.toString(), exclude_series ) == -1 ) series.push( value ); }); // CSV Headers for ( var s = 0; s < series.length; ++s ) { csv_data += series[s].label + ','; } csv_data = csv_data.substring( 0, csv_data.length - 1 ); csv_data += "\n"; // Get x axis values var xaxis = {} for ( var s = 0; s < series.length; ++s ) { var series_data = series[s].data; for ( var d = 0; d < series_data.length; ++d ) { xaxis[series_data[d][0]] = new Array(); // Zero values to start for ( var i = 0; i < series.length; ++i ) { xaxis[series_data[d][0]].push(0); } } } // Add chart data for ( var s = 0; s < series.length; ++s ) { var series_data = series[s].data; for ( var d = 0; d < series_data.length; ++d ) { xaxis[series_data[d][0]][s] = series_data[d][1]; } } // Loop data and output to csv string $.each( xaxis, function( index, value ) { var date = new Date( parseInt( index ) ); if ( groupby == 'day' ) csv_data += date.getFullYear() + "-" + parseInt( date.getMonth() + 1 ) + "-" + date.getDate() + ','; else csv_data += date.getFullYear() + "-" + parseInt( date.getMonth() + 1 ) + ','; for ( var d = 0; d < value.length; ++d ) { val = value[d]; if( Math.round( val ) != val ) val = val.toFixed(2); csv_data += val + ','; } csv_data = csv_data.substring( 0, csv_data.length - 1 ); csv_data += "\n"; } ); } // Set data as href and return $(this).attr( 'href', encodeURI( csv_data ) ); return true; }); }); </script> <?php }