<?php
require ("Conexion/Conexion.php");
require ("lib/lib.php");
if(!isset($_SESSION['WEB2'])){	
	echo "<script language='JavaScript'>location.href = 'index.php'</script>";
	die();
} else{
	Inactividad();
	
	if($_POST['Opcion'] != ''){
		if(preg_match("/^[[:digit:]]+$/", $_POST['Opcion'])){
			$Opcion = $_POST['Opcion'];
			if($_POST['FlotillaID'] != ''){
				if(preg_match("/^[[:digit:]]+$/", $_POST['FlotillaID'])){
					$FlotillaID = $_POST['FlotillaID'];
					$ClienteID = $_SESSION['ClienteID'];
					$QueryHorarios = mssql_query("SELECT Domingo, Lunes, Martes, Miercoles, Jueves, Viernes, Sabado FROM Vehiculo WHERE VehiculoID =
					'$FlotillaID' AND ClienteID = '$ClienteID'");
					if(mssql_num_rows($QueryHorarios) >= 1){
						if($Opcion == 1){
							$EvaluarHorarios = mssql_fetch_array($QueryHorarios);
							$Band = 1	;
						}else
							$Band = 'error2';
					}else
						$Band = 'error2';
						
					if($Band == 1){
						if($EvaluarHorarios['Domingo'] == '000000000000000000000000') $Domingo = '100000000000000000000000';
						else $Domingo = $EvaluarHorarios['Domingo'];
						if($EvaluarHorarios['Lunes'] == '000000000000000000000000') $Lunes = '100000000000000000000000';
						else $Lunes = $EvaluarHorarios['Lunes'];
						if($EvaluarHorarios['Martes'] == '000000000000000000000000') $Martes = '100000000000000000000000';
						else $Martes = $EvaluarHorarios['Martes'];
						if($EvaluarHorarios['Miercoles'] == '000000000000000000000000') $Miercoles = '100000000000000000000000';
						else $Miercoles = $EvaluarHorarios['Miercoles'];
						if($EvaluarHorarios['Jueves'] == '000000000000000000000000') $Jueves = '100000000000000000000000';
						else $Jueves = $EvaluarHorarios['Jueves'];
						if($EvaluarHorarios['Viernes'] == '000000000000000000000000') $Viernes = '100000000000000000000000';
						else $Viernes = $EvaluarHorarios['Viernes'];
						if($EvaluarHorarios['Sabado'] == '000000000000000000000000') $Sabado = '100000000000000000000000';
						else $Sabado = $EvaluarHorarios['Sabado'];
						
						$L1 = HoraIni($Lunes);
						$L2 = HoraFin($Lunes);
						$Ma1 = HoraIni($Martes);
						$Ma2 = HoraFin($Martes);
						$Mi1 = HoraIni($Miercoles);
						$Mi2 = HoraFin($Miercoles);
						$J1 = HoraIni($Jueves);
						$J2 = HoraFin($Jueves);
						$V1 = HoraIni($Viernes);
						$V2 = HoraFin($Viernes);
						$S1 = HoraIni($Sabado);
						$S2 = HoraFin($Sabado);
						$D1 = HoraIni($Domingo);
						$D2 = HoraFin($Domingo);
						
						$Horarios = $Domingo.':'.$Lunes.':'.$Martes.':'.$Miercoles.':'.$Jueves.':'.$Viernes.':'.$Sabado;
						echo '<script type="text/JavaScript">
						var L1 = '.$L1.';
						var L2 = '.$L2.';
						var Ma1 = '.$Ma1.';
						var Ma2 = '.$Ma2.';
						var Mi1 = '.$Mi1.';
						var Mi2 = '.$Mi2.';
						var J1 = '.$J1.';
						var J2 = '.$J2.';
						var V1 = '.$V1.';
						var V2 = '.$V2.';
						var S1 = '.$S1.';
						var S2 = '.$S2.';
						var D1 = '.$D1.';
						var D2 = '.$D2.';	
						</script>';	
	?>
<script>
$(document).ready(function(){
	Lunes( L1, L2);
	Martes( Ma1,Ma2);
	Miercoles(Mi1,Mi2);
	Jueves(J1,J2);
	Viernes(V1,V2);
	Sabado(S1,S2);
	Domingo(D1,D2);
});
	function Lunes(varIni, varFin){
		$('#Lunes').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtLunesIni").val(ui.values[0]);
				$("#edtLunesFin").val(ui.values[1]);
			}
		});		
		$("#edtLunesIni").val($('#Lunes').slider("values", 0));		
		$("#edtLunesFin").val($('#Lunes').slider("values", 1));	
	}
	function Martes(varIni, varFin){
		$('#Martes').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtMartesIni").val(ui.values[0]);
				$("#edtMartesFin").val(ui.values[1]);
			}
		});		
		$("#edtMartesIni").val($('#Martes').slider("values", 0));		
		$("#edtMartesFin").val($('#Martes').slider("values", 1));	
	}
	function Miercoles(varIni, varFin){
		$('#Miercoles').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtMiercolesIni").val(ui.values[0]);
				$("#edtMiercolesFin").val(ui.values[1]);
			}
		});		
		$("#edtMiercolesIni").val($('#Miercoles').slider("values", 0));		
		$("#edtMiercolesFin").val($('#Miercoles').slider("values", 1));	
	}
	function Jueves(varIni, varFin){
		$('#Jueves').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtJuevesIni").val(ui.values[0]);
				$("#edtJuevesFin").val(ui.values[1]);
			}
		});		
		$("#edtJuevesIni").val($('#Jueves').slider("values", 0));		
		$("#edtJuevesFin").val($('#Jueves').slider("values", 1));	
	}
	function Viernes(varIni, varFin){
		$('#Viernes').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtViernesIni").val(ui.values[0]);
				$("#edtViernesFin").val(ui.values[1]);
			}
		});		
		$("#edtViernesIni").val($('#Viernes').slider("values", 0));		
		$("#edtViernesFin").val($('#Viernes').slider("values", 1));	
	}
	function Sabado(varIni, varFin){
		$('#Sabado').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtSabadoIni").val(ui.values[0]);
				$("#edtSabadoFin").val(ui.values[1]);
			}
		});		
		$("#edtSabadoIni").val($('#Sabado').slider("values", 0));		
		$("#edtSabadoFin").val($('#Sabado').slider("values", 1));	
	}
	function Domingo(varIni, varFin){
		$('#Domingo').slider({
			range: true,
			min: 0,
			max: 23,
			values: [ varIni, varFin ],
			slide: function( event, ui ) {
				$("#edtDomingoIni").val(ui.values[0]);
				$("#edtDomingoFin").val(ui.values[1]);
			}
		});		
		$("#edtDomingoIni").val($('#Domingo').slider("values", 0));		
		$("#edtDomingoFin").val($('#Domingo').slider("values", 1));	
	}
	function Marcar(){
		Lunes(0, 23);
		Martes(0, 23);
		Martes(0, 23);
		Miercoles(0, 23);
		Jueves(0, 23);
		Viernes(0, 23);
		Sabado(0, 23);
		Domingo(0, 23);
	}
	function Desmarcar(){
		Lunes(0, 0);
		Martes(0, 0);
		Martes(0, 0);
		Miercoles(0, 0);
		Jueves(0, 0);
		Viernes(0, 0);
		Sabado(0, 0);
		Domingo(0, 0);
	}
</script>
                    <table width="749" border="0" align="center" cellpadding="0" cellspacing="0" title="Deslicé la barra para marcar el horario de carga de la Flotilla.">
                      <tr>
                        <td width="26">&nbsp;</td>
                        <td width="72">&nbsp;</td>
                        <td width="263" align="center">&nbsp;</td>
                        <td width="256" align="center">&nbsp;</td>
                        <td width="17" align="center">&nbsp;</td>
                        <td width="49" align="center">Hora Inicial:</td>
                        <td width="49" align="center">Hora Final:</td>
                        <td width="17">&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Lunes</b></td>
                        <td colspan="2" align="center"><div id="Lunes"></div></td>
                        <td align="center">&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtLunesIni" type="text" disabled="disabled" id="edtLunesIni" size="2" title="Hora Inicial del día Lunes." /></td>
                        <td align="center"><input class="Horarios" name="edtLunesFin" type="text" disabled="disabled" id="edtLunesFin" size="2" title="Hora Final del día Lunes."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Martes</b></td>
                        <td colspan="2" align="center"><div id="Martes"></div></td>
                        <td>&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtMartesIni" type="text" disabled="disabled" id="edtMartesIni" size="2" title="Hora Inicial del día Martes."/></td>
                        <td align="center"><input class="Horarios" name="edtMartesFin" type="text" disabled="disabled" id="edtMartesFin" size="2" title="Hora Final del día Martes."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Miércoles</b></td>
                        <td colspan="2" align="center"><div id="Miercoles"></div></td>
                        <td>&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtMiercolesIni" type="text" disabled="disabled" id="edtMiercolesIni" size="2" title="Hora Inicial del día Miércoles."/></td>
                        <td align="center"><input class="Horarios" name="edtMiercolesFin" type="text" disabled="disabled" id="edtMiercolesFin" size="2" title="Hora Final del día Miércoles."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><div id="Miercoles"></div></td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Jueves</b></td>
                        <td colspan="2" align="center"><div id="Jueves"></div></td>
                        <td>&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtJuevesIni" type="text" disabled="disabled" id="edtJuevesIni" size="2" title="Hora Inicial del día Jueves."/></td>
                        <td align="center"><input class="Horarios" name="edtJuevesFin" type="text" disabled="disabled" id="edtJuevesFin" size="2" title="Hora Final del día Jueves."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Viernes</b></td>
                        <td colspan="2" align="center"><div id="Viernes"></div></td>
                        <td>&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtViernesIni" type="text" disabled="disabled" id="edtViernesIni" size="2" title="Hora Inicial del día Viernes."/></td>
                        <td align="center"><input class="Horarios" name="edtViernesFin" type="text" disabled="disabled" id="edtViernesFin" size="2" title="Hora Final del día Viernes."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Sábado</b></td>
                        <td colspan="2" align="center"><div id="Sabado"></div></td>
                        <td>&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtSabadoIni" type="text" disabled="disabled" id="edtSabadoIni" size="2" title="Hora Inicial del día Sábado."/></td>
                        <td align="center"><input class="Horarios" name="edtSabadoFin" type="text" disabled="disabled" id="edtSabadoFin" size="2" title="Hora Final del día Sábado."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left"><b>Domingo</b></td>
                        <td colspan="2" align="center"><div id="Domingo"></div></td>
                        <td>&nbsp;</td>
                        <td align="center"><input class="Horarios" name="edtDomingoIni" type="text" disabled="disabled" id="edtDomingoIni" size="2" title="Hora Inicial del día Domingo."/></td>
                        <td align="center"><input class="Horarios" name="edtDomingoFin" type="text" disabled="disabled" id="edtDomingoFin" size="2" title="Hora Final del día Domingo."/></td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td colspan="8" align="center"><input class="submit" type="submit" name="submit" id="submit" value="Guardar Cambios" title="Guardar los Horarios establecidos."/></td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td colspan="2" align="center">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                        <td align="left">&nbsp;</td>
                        <td align="center">&nbsp;</td>
                        <td align="center">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
    <?
                    }else
                        echo "<p class='error'>La Flotilla seleccionada no pertenece al Usuario/Cliente Autenticado!</p>";
                }else
                    echo "<p class='error'>El No. de Flotilla debe ser númerico!</p>";
            }else
                echo "<p class='error'>Selecione la Flotilla a Modificar!</p>";
        }else
            echo 'error2';
    }else
        echo 'error1';
}
?>
