<?php $__env->startSection('CSS'); ?>
<?php echo HTML::style('DataTables/dataTables.bootstrap.min.css'); ?>

<?php echo HTML::style('DataTables/responsive.dataTables.min.css'); ?>

<style type="text/css">
	/*.porcentajes{ display: none; }*/
</style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('Contenido'); ?>
<div class="row">
	<div class="col-md-12">
		<h2><i class="fa fa-envelope-o"></i> E-Mail Marketing </h2>
	</div><!--/col-md-12-->
</div><!--/row-->

<div class="row">
	<?php /*
	<div class="col-md-12">
		<nav class="navbar navbar-inverse">
			<ul class="nav navbar-nav">
				<li><a href="<?php echo URL::to('templates'); ?>">Ver todos los Templates</a></li>
				<li><a href="<?php echo URL::to('templates/create'); ?>">Crear un Template</a>
			</ul>
		</nav>
	</div>
	*/ ?>
	<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">
					Secuencia de seguimiento de la lista <strong> <?php echo $ListaEmail->nombre; ?> </strong>
					<div data-toggle="buttons" class="button-group pull-right">
						<a class="refresh" onclick="Actualizar()" href="javascript:Actualizar();" style="color: rgba(0, 0, 0, 0.3)"> <i class="fa fa-repeat"> </i> </a>
						<a class="btn active small border-gray right-margin" href="javascript:;" onclick="CambioVista(1)">
							<span class="button-content">
								<input type="radio" name="radio-toggle-1" value="1">
								#
							</span>
						</a>
						<a class="btn small border-gray" href="javascript:;" onclick="CambioVista(2)">
							<span class="button-content">
								<input type="radio" name="radio-toggle-1" value="2">
								%
							</span>
						</a>
					</div>
				</h3>
			</div>
			<div class="porlets-content">
				<div class="table-responsive">
					<table class="table table-striped table-bordered table-hover" id="tblSecuenciasSeguimientos">
						<thead>
							<tr>
								<th class="col-md-1"> Orden </th>
								<th class="col-md-2"> Asunto </th>
								<th class="col-md-1"> Enviar <i class="fa fa-clock-o"> </i> </th>
								<th class="col-md-2"> Acciones </th>
								<th class="col-md-6 text-center" colspan="12"> Seguimiento </th>
							</tr>
							<tr>
								<th class="col-md-6" colspan="4"></th>
								<th class="col-md-1"> Enviados </th>
								<th class="col-md-1"> Enviados </th>
								<th class="col-md-1"> Abiertos </th>
								<th class="col-md-1"> Abiertos </th>
								<th class="col-md-1"> Clics </th>
								<th class="col-md-1"> Clics </th>
								<th class="col-md-1"> Rebotes </th>
								<th class="col-md-1"> Rebotes </th>
								<th class="col-md-1"> Quejas </th>
								<th class="col-md-1"> Quejas </th>
								<th class="col-md-1"> Desuscritos </th>
								<th class="col-md-1"> Desuscritos </th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
			<div class="bottom">
				<?php echo HTML::linkRoute('SysWebEmailMarketingListasSubscriptoresSecuenciasSeguimientosAgregar', 'Agregar', array($ListaEmail->id), array('class' => 'btn btn-primary')); ?>

				<?php echo HTML::linkRoute('SysWebEmailMarketingListasSubscriptores', 'Regresar', array(), array('class' => 'btn btn-default')); ?>

				<button type="button" id="btnIniciar" class="btn btn-success tooltips" data-toggle="tooltip" data-original-title="Si ya tenías registrados los suscriprores, ahora puedes iniciar la secuencia de seguimiento" <?php if($Total == 0): ?> disabled <?php endif; ?>>
					Iniciar
				</button>
			</div>
		</div>
	</div>
</div><!--/row end-->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JS'); ?>
<?php echo HTML::script('DataTables/jquery.dataTables.min.js'); ?>

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

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

<script type="text/javascript">
	function Actualizar(){
		var table = $("#tblSecuenciasSeguimientos").DataTable();
		table.ajax.reload(null, false);
	}
	function CambioVista(value){
		var value = value;
		var table = $("#tblSecuenciasSeguimientos").DataTable();
		if(value == 1){
			table.columns(".numeros").visible(true, false);
			table.columns(".porcentajes").visible(false, false);
		}
		else if(value == 2){
			table.columns(".porcentajes").visible(true, false);
			table.columns(".numeros").visible(false, false);
		}
	}
	function PruebaEnvio(idSS){
		var idSS = idSS;
		$.post(
			"<?php echo URL::route('SysWebEmailMarketingPruebaEnvioSSObtencionCampos'); ?>",
			{idSS:idSS},
			function(data){
				if(data.success){
					var fielset = "";
					if(data.campos.length > 0){
						var campos = "";
						for(i=0; i<data.campos.length; i++){
							campos += "<div class='form-group'> \
											<label> "+data.campos[i].nombre+" </label> <br> \
											<input type='text' name='"+data.campos[i].slug+"' class='form-control'> \
											<input type='hidden' name='Campos[]' value='"+data.campos[i].slug+"'> \
											<spam id='err"+data.campos[i].slug+"' class='text-danger'> </spam> \
										</div>"
						}
						var fielset = "<fielset> \
											<legend> Campos personalizados del mensaje </legend> \
											"+campos+" \
										</fielset>";
					}
					var mensaje = " \
						<div class='row'> \
							<div class='col-xs-12'> \
								<form id='frmPruebaEnvio'> \
									<div class='form-group'> \
										<label> Correo electronico a enviar </label> <br> \
										<input type='text' name='correo_electronico0' class='form-control'> \
										<spam id='errcorreo_electronico0' class='text-danger'> </spam> \
									</div> \
									<fielset> \
										<legend> Campos personalizados del mensaje </legend> \
										"+campos+"\
									</fielset> \
									<input type='hidden' name='idSS' value='"+idSS+"'> \
								</form> \
							</div> \
						</div> \
					";
					BootstrapDialog.show({
						title: "Correo de prueba de secuencia de seguimiento",
						type: BootstrapDialog.TYPE_DEFAULT,
						message: mensaje,
						draggable: true,
						buttons: [{
							id: "btnEnviar",
							label: "Enviar",
							cssClass: "btn-primary",
							action: function(dialogItself){
								$("#btnEnviar").prop("disabled", true).html('<i class="fa fa-spinner fa-spin"></i> Enviando');
								$.post(
									"<?php echo URL::route('SysWebEmailMarketingPruebaEnvioSSEnviar'); ?>",
									$("#frmPruebaEnvio").serialize(),
									function(data){
										$("#btnEnviar").prop("disabled", false).html("Enviar");
										if(data.success){
											new PNotify({ title: "Felicidades!", text: data.mensaje, type: "success" });
											dialogItself.close();
										}
										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"
								);
							}
						}]
					});
				}
				else{
					if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
				}
			},
			"json"
		);
	}
</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('JSOr'); ?>
$("#tblSecuenciasSeguimientos").DataTable({
	"processing": true,
	"serverSide": true,
	"ajax": "<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresSecuenciasSeguimientos', $ListaEmail->id); ?>",
	columns: [
		{data: 'posicion', name: 'posicion', "searchable": false},
		{data: 'asunto', name: 'asunto'},
		{data: 'dias_despues', name: 'dias_despues', "searchable": false},
		{data: 'acciones', name: 'acciones', "searchable": false},
		{data: 'enviados', name: 'enviados', "searchable": false},
		{data: 'enviadop', name: 'enviadop', "searchable": false, "visible": false},
		{data: 'abiertos', name: 'abiertos', "searchable": false, className: "numeros"},
		{data: 'abiertop', name: 'abiertop', "searchable": false, "visible": false, className: "porcentajes"},
		{data: 'clics', name: 'clics', "searchable": false, className: "numeros"},
		{data: 'clicp', name: 'clicp', "searchable": false, "visible": false, className: "porcentajes"},
		{data: 'rebotes', name: 'rebotes', "searchable": false, className: "numeros"},
		{data: 'rebotep', name: 'rebotep', "searchable": false, "visible": false, className: "porcentajes"},
		{data: 'quejas', name: 'quejas', "searchable": false, className: "numeros"},
		{data: 'quejap', name: 'quejap', "searchable": false, "visible": false, className: "porcentajes"},
		{data: 'desuscritos', name: 'desuscritos', "searchable": false, className: "numeros"},
		{data: 'desuscritop', name: 'desuscritop', "searchable": false, "visible": false, className: "porcentajes"}
	],
	"language": {
		"url": "<?php echo asset('DataTables/Spanish.json'); ?>"
	},
	"ordering": false,
	"fnDrawCallback": function( oSettings ) {
		$(".tooltips").tooltip();
	}/*,
	responsive: true*/
});
<?php if(Session::has('MensajeS')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('MensajeS'); ?>", type: "success" });
<?php endif; ?>
<?php if(Session::has('MensajeE')): ?>
new PNotify({ title: "Realizado", text: "<?php echo Session::get('MensajeE'); ?>", type: "error" });
<?php endif; ?>
$("#btnIniciar").click(function(){
	$("#btnIniciar").html('<i class="fa fa-spinner fa-spin"></i> Cargando').prop("disabled", true);
	$.post(
		"<?php echo URL::route('SysWebEmailMarketingListasSubscriptoresSecuenciasSeguimientosIniciar', array($ListaEmail->id)); ?>",
		{ idLE : <?php echo $ListaEmail->id; ?> },
		function(data){
			$("#btnIniciar").html("Iniciar").prop("disabled", false);
			if(data.success){
				if(data.mensaje != ''){ new PNotify({ title: "Realizado", text: data.mensaje, type: "success" }); }
			}
			else{
				if(data.mensaje != ''){ new PNotify({ title: "Error", text: data.mensaje, type: "error" }); }
			}
		},
		"json"
	);
});
<?php $__env->stopSection(); ?>
<?php echo $__env->make('BaseSistemaWeb', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>