Exemple #1
0
 public function form_fields()
 {
     $form_fields = array(array('title' => __('Reference ID', APP_TD), 'type' => 'text', 'name' => 'cp_sys_ad_conf_id', 'default' => cp_generate_id(), 'extra' => array('readonly' => 'readonly')), array('title' => __('Views Today', APP_TD), 'type' => 'text', 'name' => 'cp_daily_count', 'sanitize' => 'absint', 'default' => '0', 'extra' => array('readonly' => 'readonly')), array('title' => __('Views Total', APP_TD), 'type' => 'text', 'name' => 'cp_total_count', 'sanitize' => 'absint', 'default' => '0', 'extra' => array('readonly' => 'readonly')), array('title' => __('Submitted from IP', APP_TD), 'type' => 'text', 'name' => 'cp_sys_userIP', 'default' => appthemes_get_ip(), 'extra' => array('readonly' => 'readonly')));
     if (cp_payments_is_enabled()) {
         $form_fields[] = array('title' => __('Last Payment', APP_TD), 'type' => 'text', 'name' => 'cp_sys_total_ad_cost', 'default' => '0', 'desc' => APP_Currencies::get_current_symbol(), 'extra' => array('readonly' => 'readonly'));
     }
     return $form_fields;
 }
function cp_dashboard_charts()
{
    global $wpdb, $cp_options;
    $sql = "SELECT COUNT(post_title) as total, post_date FROM {$wpdb->posts} WHERE post_type = %s AND post_date > %s GROUP BY DATE(post_date) DESC";
    $results = $wpdb->get_results($wpdb->prepare($sql, APP_POST_TYPE, appthemes_mysql_date(current_time('mysql'), -30)));
    $listings = array();
    // put the days and total posts into an array
    foreach ((array) $results as $result) {
        $the_day = date('Y-m-d', strtotime($result->post_date));
        $listings[$the_day] = $result->total;
    }
    // setup the last 30 days
    for ($i = 0; $i < 30; $i++) {
        $each_day = date('Y-m-d', strtotime('-' . $i . ' days'));
        // if there's no day with posts, insert a goose egg
        if (!in_array($each_day, array_keys($listings))) {
            $listings[$each_day] = 0;
        }
    }
    // sort the values by date
    ksort($listings);
    // Get sales - completed orders with a cost
    $results = array();
    $currency_symbol = $cp_options->curr_symbol;
    if (current_theme_supports('app-payments')) {
        $sql = "SELECT sum( m.meta_value ) as total, p.post_date FROM {$wpdb->postmeta} m INNER JOIN {$wpdb->posts} p ON m.post_id = p.ID WHERE m.meta_key = 'total_price' AND p.post_status IN ( '" . APPTHEMES_ORDER_COMPLETED . "', '" . APPTHEMES_ORDER_ACTIVATED . "' ) AND p.post_date > %s GROUP BY DATE(p.post_date) DESC";
        $results = $wpdb->get_results($wpdb->prepare($sql, appthemes_mysql_date(current_time('mysql'), -30)));
        $currency_symbol = APP_Currencies::get_current_symbol();
    }
    $sales = array();
    // put the days and total posts into an array
    foreach ((array) $results as $result) {
        $the_day = date('Y-m-d', strtotime($result->post_date));
        $sales[$the_day] = $result->total;
    }
    // setup the last 30 days
    for ($i = 0; $i < 30; $i++) {
        $each_day = date('Y-m-d', strtotime('-' . $i . ' days'));
        // if there's no day with posts, insert a goose egg
        if (!in_array($each_day, array_keys($sales))) {
            $sales[$each_day] = 0;
        }
    }
    // sort the values by date
    ksort($sales);
    ?>

<div id="placeholder"></div>

<script language="javascript" type="text/javascript">
// <![CDATA[
jQuery(function() {

	var posts = [
		<?php 
    foreach ($listings as $day => $value) {
        $sdate = strtotime($day);
        $sdate = $sdate * 1000;
        // js timestamps measure milliseconds vs seconds
        $newoutput = "[{$sdate}, {$value}],\n";
        echo $newoutput;
    }
    ?>
	];

	var sales = [
		<?php 
    foreach ($sales as $day => $value) {
        $sdate = strtotime($day);
        $sdate = $sdate * 1000;
        // js timestamps measure milliseconds vs seconds
        $newoutput = "[{$sdate}, {$value}],\n";
        echo $newoutput;
    }
    ?>
	];


	var placeholder = jQuery("#placeholder");

	var output = [
		{
			data: posts,
			label: "<?php 
    _e('New Ad Listings', APP_TD);
    ?>
",
			symbol: ''
		},
		{
			data: sales,
			label: "<?php 
    _e('Total Sales', APP_TD);
    ?>
",
			symbol: '<?php 
    echo $currency_symbol;
    ?>
',
			yaxis: 2
		}
	];

	var options = {
		series: {
			lines: { show: true },
			points: { show: true }
		},
		grid: {
			tickColor:'#f4f4f4',
			hoverable: true,
			clickable: true,
			borderColor: '#f4f4f4',
			backgroundColor:'#FFFFFF'
		},
		xaxis: {
			mode: 'time',
			timeformat: "%m/%d"
		},
		yaxis: {
			min: 0
		},
		y2axis: {
			min: 0,
			tickFormatter: function(v, axis) {
				return "<?php 
    echo $currency_symbol;
    ?>
" + v.toFixed(axis.tickDecimals)
			}
		},
		legend: {
			position: 'nw'
		}
	};

	jQuery.plot(placeholder, output, options);

	// reload the plot when browser window gets resized
	jQuery(window).resize(function() {
		jQuery.plot(placeholder, output, options);
	});

	function showChartTooltip(x, y, contents) {
		jQuery('<div id="charttooltip">' + contents + '</div>').css( {
			position: 'absolute',
			display: 'none',
			top: y + 5,
			left: x + 5,
			opacity: 1
		} ).appendTo("body").fadeIn(200);
	}

	var previousPoint = null;
	jQuery("#placeholder").bind("plothover", function (event, pos, item) {
		jQuery("#x").text(pos.x.toFixed(2));
		jQuery("#y").text(pos.y.toFixed(2));
		if (item) {
			if (previousPoint != item.datapoint) {
				previousPoint = item.datapoint;

				jQuery("#charttooltip").remove();
				var x = new Date(item.datapoint[0]), y = item.datapoint[1];
				var xday = x.getDate(), xmonth = x.getMonth()+1; // jan = 0 so we need to offset month
				showChartTooltip(item.pageX, item.pageY, xmonth + "/" + xday + " - <b>" + item.series.symbol + y + "</b> " + item.series.label);
			}
		} else {
			jQuery("#charttooltip").remove();
			previousPoint = null;
		}
	});
});
// ]]>
</script>


<?php 
}
Exemple #3
0
 /**
  * Verifies that the default currency returns correctly
  */
 public function test_currency_defaults()
 {
     $code = 'USD';
     $name = 'US Dollars';
     $symbol = '&#36;';
     $currency = APP_Currencies::get_current_currency();
     $this->assertNotEmpty($currency);
     $this->assertEquals(compact('code', 'name', 'symbol'), $currency);
     $this->assertEquals($name, APP_Currencies::get_current_currency('name'));
     $this->assertEquals($symbol, APP_Currencies::get_current_currency('symbol'));
     $this->assertEquals($name, APP_Currencies::get_current_name());
     $this->assertEquals($symbol, APP_Currencies::get_current_symbol());
 }
 public function form()
 {
     // translators: Start/End Date Help Text. Can be any format accepted by php.net/strtotime and php.net/date_parse.
     $date_format = __('( MM/DD/YYYY )', 'appthemes-coupons');
     return array(array('title' => __('Coupon Code', 'appthemes-coupons'), 'type' => 'text', 'name' => 'code', 'extra' => array('style' => 'width: 150px;')), array('title' => __('Discount Amount', 'appthemes-coupons'), 'type' => 'text', 'name' => 'amount', 'extra' => array('style' => 'width: 50px;')), array('title' => __('Discount Type', 'appthemes-coupons'), 'type' => 'select', 'name' => 'type', 'values' => array('flat' => sprintf(__('Flat Discount (%s)', 'appthemes-coupons'), APP_Currencies::get_current_symbol()), 'percent' => __('Percentage Discount (%)', 'appthemes-coupons'))), array('title' => __('Start Date', 'appthemes-coupons'), 'type' => 'text', 'name' => 'start_date', 'desc' => $date_format, 'extra' => array('style' => 'width: 150px;')), array('title' => __('End Date', 'appthemes-coupons'), 'type' => 'text', 'name' => 'end_date', 'desc' => $date_format, 'extra' => array('style' => 'width: 150px;')), array('title' => __('Use Limit', 'appthemes-coupons'), 'type' => 'text', 'name' => 'use_limit', 'desc' => __('( 0 for Unlimited )', 'appthemes-coupons'), 'extra' => array('style' => 'width: 50px;')), array('title' => __('Use Limit Per User', 'appthemes-coupons'), 'type' => 'text', 'name' => 'user_use_limit', 'desc' => __('( 0 for Unlimited )', 'appthemes-coupons'), 'extra' => array('style' => 'width: 50px;')));
 }