{include file="$admingentemplates/admin_top.tpl"}
<link type="text/css" href="{$site_root}{$template_root}/css/jquery.css" rel="stylesheet" />
{literal}
<style type="text/css" media="screen">
    .jqplot-axis {
      font-size: 0.85em;
    }
    .jqplot-title {
      font-size: 1.1em;
    }
  </style>
{/literal}
<script language="JavaScript" type="text/javascript" src="{$site_root}{$template_root}/js/jquery-ui.js"></script>

<div class="back">
    <a href="{$site_url}{$site_root}/admin/admin_marketing.php">{$lang.button.back}</a>
</div>

<div class="cr"></div>
<div class="show_help" style="display: none;">&nbsp;</div>
<div class="red_header">{if $market_name} {$market_name} {else} {$lang.admin_market.general_statistic} {/if}</div>
<div class="cr">&nbsp;</div>
<div class="cr">&nbsp;</div>
<div class="help_text" style="display:block;">
    <div class="close_help">
        <img src="{$site_root}{$template_root}/images/close_help.png" alt="">
    </div>
    <div class="help_body">
        <span class="help_title">{$lang.help}:</span>{$help.admin_market_statistic}
    </div>
</div>
<div class="cr">&nbsp;</div>

<div style="padding-top:8px;">
	<table border="0" cellspacing="0" cellpadding="5" width="100%">
		<tr>
			<td align="left" valign="top" width="25%">
				<div style="padding-left:10px;padding-top:10px;">
					<div>
						{$lang.admin_index.y_label_clicks}:&nbsp;<b>{$data.click}</b>
					</div>			
					<div style="padding-top:20px;">
						{$lang.admin_index.y_label_reg}:&nbsp;<b><a href="admin_users.php?sel=market&id_marketing={$id_market}" target="_blank">{$data.reg}&nbsp;{$lang.button.users}</a></b>
					</div>
				</div>
			</td>
			<td>
				<div style="padding-top:10px;">
					<div style="padding:0px 10px 10px 10px;border-bottom-width:1px;border-bottom-style: solid;border-bottom-color:#e5eaef;">
						<div style="float:left;">
							<font class="text">{$lang.admin_market.select_period}</font>
							<select name="period" id="period_general" onchange="GetData('diagramm_general');">
								<option  value="" selected>{$lang.index.please_select}</option>
								<option value="day">{$lang.admin_index.periods.day}</option>
								<option value="week">{$lang.admin_index.periods.week}</option>
								<option value="month">{$lang.admin_index.periods.month}</option>
								<option value="year">{$lang.admin_index.periods.year}</option>
							</select>
							<font class="text">{$lang.admin_market.select_type}</font>
							<select name="stat_type" id="stat_type" onchange="GetData('diagramm_general');">
								<option value="reg" selected>{$lang.admin_index.y_label_reg}</option>
								<option value="click">{$lang.admin_index.y_label_clicks}</option>
							</select>
						</div>
						<div align="right" style="height:22px;">
							<div id="button_g">
							<font class="text">{$lang.button.view}:</font>&nbsp;
							<img align="top" style="cursor:pointer;" src="{$site_root}{$template_root}/images/admin_marketing_view1.gif" onclick="SetDiagrammType('g','gis');" title="{$lang.admin_market.column}">
							&nbsp;&nbsp;&nbsp;
							<img align="top" style="cursor:pointer;" src="{$site_root}{$template_root}/images/admin_marketing_view2.gif" onclick="SetDiagrammType('g','gra');" title="{$lang.admin_market.line}">
							</div>
						</div>
					</div>
					<div id="diagramm_general">
					</div>
				</div>
			</td>
		</tr>
		<tr><td colspan="2"><hr style="width: 100%;"></td></tr>
		<tr>
			<td align="left" valign="top" width="25%">
				<div style="padding-left:10px;padding-top:10px;">
					<div>
						{$lang.admin_market.sales_statistic}:&nbsp;<b><a href="admin_pays.php" target="_blank">{$data.all_num} {$lang.admin_market.sales_statistic_text}</a>&nbsp;/&nbsp;{$data.all}&nbsp;{$site_unit_costunit}</b>
					</div>
					<div style="padding-left:32px;padding-top:20px;">
						<b><a href="admin_pays.php" target="_blank">{$data.servises_num}&nbsp;{$lang.admin_market.sales_servises}</a>&nbsp;/&nbsp;{$data.servises}&nbsp;{$site_unit_costunit}</b>
					</div>
					<div style="padding-left:52px;padding-top:20px;">
						<b>{$lang.voip.razdel_name} - <a href="admin_voip_statistics.php" target="">{$data.voip_call_num}</a>&nbsp;/&nbsp;{$data.voip_call}&nbsp;{$site_unit_costunit}</b>
					</div>
					<div style="padding-left:52px;padding-top:20px;">
						<b>{$lang.banners.razdel_name} - <a href="admin_pays.php" target="_blank">{$data.user_banners_num}</a>&nbsp;/&nbsp;{$data.user_banners}&nbsp;{$site_unit_costunit}</b>
					</div>
					<div style="padding-left:52px;padding-top:20px;">
						<b>{$lang.admin_market.sales_lift_up} - <a href="admin_pays.php" target="_blank">{$data.liftup_num}</a>&nbsp;/&nbsp;{$data.liftup}&nbsp;{$site_unit_costunit}</b>
					</div>
					<div style="padding-left:52px;padding-top:20px;">
						<b>{$lang.modules.ecards.name} - <a href="admin_cards.php?sel=orders" target="_blank">{$data.ecards_num}</a>&nbsp;/&nbsp;{$data.ecards}&nbsp;{$site_unit_costunit}</b>
					</div>
					{if $use_pilot_module_giftshop}
					<div style="padding-left:52px;padding-top:20px;">
						<b>{$lang.admin_market.sales_gifts} - <a href="admin_giftshop.php?sel=orders" target="_blank">{$data.giftshop_num}</a>&nbsp;/&nbsp;{$data.giftshop}&nbsp;{$site_unit_costunit}</b>
					</div>
					{/if}
					{if $use_pilot_module_games}
					<div style="padding-left:52px;padding-top:20px;">
						<b>{$lang.admin_market.sales_games} - <a href="admin_games.php?sel=orders" target="_blank">{$data.games_num}</a>&nbsp;/&nbsp;{$data.games}&nbsp;{$site_unit_costunit}</b>
					</div>
					{/if}
				</div>
			</td>
			<td>
				<div style="padding-top:10px;">
					<div style="padding:0px 10px 10px 10px;border-bottom-width:1px;border-bottom-style: solid;border-bottom-color:#e5eaef;">
						<div style="float:left;">
							<font class="text">{$lang.admin_market.select_period}</font>
							<select name="period" id="period_payment" onchange="GetData('diagramm_payment');">
								<option  value="" selected>{$lang.index.please_select}</option>
								<option value="day">{$lang.admin_index.periods.day}</option>
								<option value="week">{$lang.admin_index.periods.week}</option>
								<option value="month">{$lang.admin_index.periods.month}</option>
								<option value="year">{$lang.admin_index.periods.year}</option>
							</select>
							<font class="text">{$lang.admin_market.select_type}</font>
							<select name="services" id="services" onchange="GetData('diagramm_payment');">
								<option  value="all" selected> {$lang.index.please_select}  </option>
								{foreach from=$payment_stat.services key=service item=_item}
									<option value="{$service}" {if $select_payments eq $service} selected {/if}> {$lang.index.payments.$service} </option>
								{/foreach}
								<option value="{$key_membership}" {if $select_payments eq $key_membership} selected {/if}> {$lang.index.payments.$key_membership} </option>
							</select>
						</div>
						<div align="right" style="height:22px;">
							<div id="button_b" style="display:none;">
							<font class="text">{$lang.button.view}:</font>&nbsp;
							<img align="top" style="cursor:pointer;" src="{$site_root}{$template_root}/images/admin_marketing_view1.gif" onclick="SetDiagrammType('b','gis');" title="{$lang.admin_market.column}">
							&nbsp;&nbsp;&nbsp;
							<img align="top" style="cursor:pointer;" src="{$site_root}{$template_root}/images/admin_marketing_view2.gif" onclick="SetDiagrammType('b','gra');" title="{$lang.admin_market.line}">
							</div>
						</div>
					</div>
					<div id="diagramm_payment">
					</div>
				</div>
			</td>
		</tr>
	</table>
</div>
<div class="cr">&nbsp;</div>
<script type="text/javascript">
{literal}
$(window).load(function () {
	G_TYPE = 'gis';
	GetData('diagramm_general');
	B_TYPE = 'gis';
	GetData('diagramm_payment');
});

function GetData(par) {
	var period;
	var stat_type;
	var services;
	var type;
	
	if(par == 'diagramm_general') {
		period = $("#period_general option:selected").val();
		stat_type = $("#stat_type option:selected").val();
		services='';
		type = G_TYPE;
		if (stat_type == 'click') {
			$("#button_g").hide(100);
			type = 'gis';
		} else {
			$("#button_g").show(100);
		}
	} else {
		period = $("#period_payment option:selected").val();
		services = $("#services option:selected").val();
		stat_type = 'billing';
		type = B_TYPE;
		if (services == 'all') {
			$("#button_b").hide(100);
			type = 'gis';
		} else {
			$("#button_b").show(100);
		}
	}
	if (stat_type == 'click') {
		$("#period_general").attr("disabled","disabled");
	} else {
		$("#period_general").removeAttr("disabled");
	}
	id_market = {/literal}{$id_market}{literal};
	ajaxLoadingImage(1, par);
	$.post("{/literal}{$file_name}{literal}",{sel:'get_stat',period:period,stat_type:stat_type,services:services,id_market:id_market,async:false,type:type}, 
		function(data){
			resp = getJQData(data);
			if (type == 'gis')
				drawDiagrammG(par,resp['title'],resp['data'],resp['y_max'],resp['x_ticks'],resp['x_label'],resp['y_label']);
			else
				drawDiagrammB(par,resp['title'],resp['data'],resp['y_max'],resp['x_ticks'],resp['x_label'],resp['y_label']);
		}
	);
}

function drawDiagrammG(id_div, title, data, y_max, x_ticks,x_label, y_label){
	$.jqplot.config.enablePlugins = true;
	$('#'+id_div).html('');
	ajaxLoadingImage(0, id_div);
	
	var value;
	var barW;

	if(data == null || data == undefined) data=[0];

	if(x_ticks == null || x_ticks == undefined) x_ticks=['{/literal}{$lang.admin_index.x_ticks.no_campaign}{literal}'];

	if(y_max == null || y_max == undefined) y_max=1;

	if (data.length>1){
		value = [data];
	}
	else {
		value = [data];
	}

	if (data.length>12) barW = 10;
	else barW = 40;

    plot3b = $.jqplot(id_div, value, {
        title: title,
        seriesDefaults: {
        	sortMergedLabels:true,
        	useSeriesColor: true,
            renderer: $.jqplot.BarRenderer,
            rendererOptions: {barWidth: barW}
        },
        series: [{label: '1st Qtr'},{label: '2nd Qtr'}],
        axes: {
            xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: x_ticks,
                rendererOptions:{tickRenderer:$.jqplot.CanvasAxisTickRenderer},
                tickOptions:{angle:-40, fontWeight:'normal', fontStretch:1},
                labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                label:x_label
            },
            yaxis: {
            	min: 0, 
            	max: y_max,
            	numberTicks:5,
            	labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
				label:y_label
            }
        }
     });  
}

function drawDiagrammB(id_div,title, data, y_max, x_ticks,x_label, y_label) {
	$.jqplot.config.enablePlugins = true;
	$('#'+id_div).html('');
	ajaxLoadingImage(0, id_div);

	if(data == null || data == undefined) {
		data=[0];
	}
	if(x_ticks == null || x_ticks == undefined ) {
		x_ticks=['no company'];
	}

	if(y_max == null || y_max == undefined) y_max=1;

	if (data.length>1){
		value = [data];
	}
	else {
		value = [data];
	}
	
	plot4 = $.jqplot(id_div, [data], { 
    title:title, 
    series:[{label:'Declining line'}], 
    axes:{
        xaxis: {
                renderer: $.jqplot.CategoryAxisRenderer,
                ticks: x_ticks,
                showLabel: true,
                rendererOptions:{tickRenderer:$.jqplot.CanvasAxisTickRenderer},
                tickOptions:{angle:-40, fontWeight:'normal', fontStretch:1},
                labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
                label:x_label
        }, 
        yaxis:{
        	min:0, 
        	max:y_max, 
        	numberTicks:5,
        	showLabel: true,
        	labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
			label:y_label
       	}
    }
});
}

function SetDiagrammType(type,par) {
	if (type == 'g') {
		G_TYPE = par;
		GetData('diagramm_general');
	}
	if (type == 'b') {
		B_TYPE = par;
		GetData('diagramm_payment');
	}
}

{/literal}
</script>
{include file="$admingentemplates/admin_bottom.tpl"}