<?php $__env->startSection('CSS'); ?>
<?php echo HTML::style('WebPro/css/jquerysctipttop.css'); ?>

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css">
<?php echo HTML::style('DataTables/dataTables.bootstrap.min.css'); ?>

<?php echo HTML::style('bootstrap-daterangepicker/daterangepicker.css'); ?>

<?php $__env->stopSection(); ?>


<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<h2><i class="icons-web-site" style="font-size: 30px !important;"></i> Páginas de Sitio </h2>
	</div><!--/col-md-12-->
</div><!--/row-->

<div class="row">
	<div class="col-md-12">
		<?php if(Session::has('message')): ?>
		<div class="alert alert-info"><?php echo Session::get('message'); ?></div>
		<?php endif; ?>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<div class="header">
				<h3 class="content-header">
					Estadisticas de la página <strong> <?php echo $EntradaxCliente->nombre; ?> </strong>
					<div data-toggle="buttons" class="button-group pull-right">
						<a class="refresh tooltips" data-toggle="tooltip" data-original-title="Reestablecer estadísticas" onclick="Eliminar(<?php echo $EntradaxCliente->id; ?>)" href="javascript:Eliminar(<?php echo $EntradaxCliente->id; ?>);" style="color: rgba(0, 0, 0, 0.3)">
							<i class="fa fa-trash-o"></i>
						</a>
						<a class="refresh tooltips" data-toggle="tooltip" data-original-title="Actualizar registros" onclick="Actualizar()" href="javascript:Actualizar();" style="color: rgba(0, 0, 0, 0.3)">
							<i class="fa fa-repeat"> </i>
						</a>
					</div>
				</h3>
			</div>
			<div class="porlets-content">
				<form id="frmFiltroFechas" class="form-inline" style="padding-bottom: 15px;">
					<div class="form-group">
						<label for="FiltroFechas" style="padding-top: 10px;"> Visitas y conversiones de: </label>
						<input id="FiltroFechas" type="text" name="filtrofechas" value="" readonly>
					</div>
					<button type="submit" class="btn btn-primary"> Filtrar </button>
					<button id="btnLimpiar" type="button" class="btn btn-default"> Limpiar </button>
				</form>
				<div class="table-responsive">
					<table class="table table-hover" id="tblEstadisticas">
						<thead>
							<tr>
								<th class="col-md-4"> Visitas </th>
								<th class="col-md-4"> Conversiones </th>
								<th class="col-md-4"> Porcentaje de conversión </th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div class="bottom"> </div>
		</div>
	</div>
</div><!--/row end-->

<div class="row">
	<div class="col-md-12">
		<div class="block-web">
			<div class="header">
				<h3 class="content-header">
					Gráfica visitas y conversiones de la página <strong> <?php echo $EntradaxCliente->nombre; ?> </strong>
				</h3>
			</div>
			<div class="porlets-content">
				<div id="Grafico"></div>
			</div>
		</div><!--/block-web--> 
	</div><!--/col-md-12--> 
</div><!--/row-->

<?php $__env->stopSection(); ?>

<?php $__env->startSection('JS'); ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<?php echo HTML::script('SysWeb/SumeClientes/Fechas.js'); ?>

<?php echo HTML::script('DataTables/jquery.dataTables.min.js'); ?>

<?php echo HTML::script('DataTables/dataTables.bootstrap.min.js'); ?>

<?php echo HTML::script('bootstrap-daterangepicker/moment.min.js'); ?>

<?php echo HTML::script('bootstrap-daterangepicker/daterangepicker.js'); ?>

<script type="text/javascript">
	var grafica;
	function Actualizar(){
		var table = $("#tblEstadisticas").DataTable();
		table.ajax.reload(null, false);
	}
	function Eliminar(id){
		var id = id;
		var mensaje = "<div class='row'> \
							<div class='col-xs-12'> \
								<form id='frmEliminar'> \
									<h2> ¿Seguro que desea reestablecer las estadísticas? </h2> \
									<div class='alert alert-warning' role='alert'> \
										<strong> Si las reestableces se borrararán todas las estádisticas capturadas hasta la fecha, incluyendo las estadisticas de las variaciones. \
										Debes tomar en cuenta que si borras las de esté sitio y no las de una variación asociada obtendras resultados inapropiados </strong> \
									</div> \
									<input type='hidden' name='idP' value='"+id+"'> \
								</form> \
							</div> \
						</div>";
		BootstrapDialog.show({
			title: "Reestablecer estadisticas",
			type: BootstrapDialog.TYPE_DANGER,
			message: mensaje,
			draggable: true,
			cssClass: "ModalEliminar",
			buttons: [{
				id: "btnEliminar",
				label: "Reestablecer",
				cssClass: "btn-danger",
				action: function(dialogItself){
					$("#btnEliminar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Eliminando');
					$.post(
						"<?php echo URL::route('SysWebSwebSitioEliminarEstadisticas'); ?>",
						{idP:id, tipo:"entrada"},
						function(data){
							$("#btnEnviar").prop("disabled", false).html("Reestablecer");
							if(data.success){
								new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
								dialogItself.close();
								var table = $("#tblEstadisticas").DataTable();
								table.ajax.reload(null, false);
								Grafica('');
							}
							else{
								if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
								$.each(data.errMensajes, function(key, value){ if(value != ''){ $("#err"+key).html(value); } else{ $("#err"+key).html(""); } });
							}
						},
						"json"
					);
				}
			}]
		});
	}
	function Grafica(filtro){
		filtro = filtro;
		ruta = (filtro != '')?"<?php echo URL::route('SysWebSWebEntradasVisitanteGrafica', array($EntradaxCliente->id)); ?>/0/"+filtro:"<?php echo URL::route('SysWebSWebEntradasVisitanteGrafica', array($EntradaxCliente->id)); ?>";
		$.get(
			ruta,
			function(data){
				if(data.success){
					if( typeof grafica  == "undefined" ){
						grafica = Morris.Line({
							element: "Grafico",
							hideHover: "auto",
							data: data.data,
							xkey: "period",
							ykeys: ["v", "c"],
							labels: ["Visitas", "Conversiones"],
							lineColors: ["#0197DA", "#56BE22"],
							xLabelFormat: function(d) {
								return moment(d.toString()).format("DD-MM-YYYY");
							},
							hoverCallback: function (index, options, content) {
								var row = options.data[index];
								var Titulo = moment(row.period, "YYYY-MM-DD").format("DD-MM-YYYY");
								var contenido = '<div class="morris-hover-row-label"> '+Titulo+' </div> \
													<div class="morris-hover-point" style="color: #0197DA"> \
														Visitas: '+row.v+' \
													</div> \
													<div class="morris-hover-point" style="color: #56BE22"> \
													Conversiones: '+row.c+' \
												</div>';
								return(contenido);
							},
							resize: true
						});
					}
					else{
						grafica.setData(data.data);
					}
				}
				else{
					if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
				}
			},
			"json"
		);
	}
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
$("#tblEstadisticas").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": {
		url: "<?php echo URL::route('SysWebSWebEntradasVisitanteEstadisticas', array($EntradaxCliente->id)); ?>",
		data: function (d) { d.filtrofechas = $("#FiltroFechas").val(); }
	},
	columns: [
		{data: 'visitantes', name: 'visitantes', "searchable": false, "orderable": false},
		{data: 'conversiones', name: 'conversiones', "searchable": false, "orderable": false, "class": "text-center"},
		{data: 'calificacion_conversion', name: 'calificacion_conversion', "orderable": false}
	],
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	"fnDrawCallback": function( oSettings ) {
		$(".tooltips").tooltip();
	},
	"paging":   false,
	"ordering": false,
	"info":     false,
	"searching": false
});
$("#FiltroFechas").daterangepicker({
	"ranges": {
		"Hoy": [moment(), moment()],
		"Ayer": [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
		"Últimos 7 días": [moment().subtract(6, 'days'), moment()],
		"Últimos 30 días": [moment().subtract(29, 'days'), moment()],
		"Este mes": [moment().startOf('month'), moment().endOf('month')],
		"Último mes": [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
	},
	"alwaysShowCalendars": true,
	locale: {
		format: 'DD/MM/YYYY'
	},
	autoUpdateInput: false,
	"startDate": moment(),
	"endDate": moment()
}, function(start, end, label) {
	console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});
$("#FiltroFechas").on("apply.daterangepicker", function(ev, picker) { $(this).val(picker.startDate.format("DD/MM/YYYY") + " - " + picker.endDate.format("DD/MM/YYYY")); });
$("#FiltroFechas").on("cancel.daterangepicker", function(ev, picker) { $(this).val(""); });
$("#frmFiltroFechas").submit(function(e){
	e.preventDefault();
	var table = $("#tblEstadisticas").DataTable();
	table.ajax.reload(null, false);
	var filtro = $("#FiltroFechas").val();
	if(filtro!=""){
		var fecha1 = filtro.substr(0, 10);
		fecha1 = moment(fecha1, "DD/MM/YYYY").format("DD-MM-YYYY");
		var fecha2 = filtro.substr(13, 10);
		fecha2 = moment(fecha2, "DD/MM/YYYY").format("DD-MM-YYYY");
		Grafica(fecha1+'--'+fecha2);
	}
	else{
		Grafica('');
	}
});
$("#btnLimpiar").click(function(e){
	e.preventDefault();
	$("#FiltroFechas").val("");
	var table = $("#tblEstadisticas").DataTable();
	table.ajax.reload(null, false);
	Grafica('');
});
Grafica('');
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>