<?php require_once('../Connections/netboxManagerMitru.php'); ?>
<?
date_default_timezone_set('America/La_Paz');
$errorf=false;
if (isset($_GET["delwac"]))
	{
	$delwac=file_get_contents("http://192.168.22.2/jda_scripts/del_wac.php?delwac=".$_GET["delwac"]);	
	}
if (isset($_POST["fechawac"]))
	{ 
	$fechaw=date("Y-m-d H:i",strtotime($_POST["fechawac"]." ".$_POST["horawac"]));
	$fechac1=date("YmdHi",strtotime($_POST["fechawac"]." ".$_POST["horawac"]));
	$fechac2=date("YmdHi");
	if ($fechac1<$fechac2) $errorf=true;
	else
		{
		$hab=$_POST["habwac"];
		$qlang="SELECT * FROM netbox_huespedes.hab_check WHERE hab_nrohab=501 AND hab_activo=1";
		$xlang=mysql_query($qlang);
		$lang=mysql_fetch_assoc($xlang);
		$lang=$lang["hab_idioma"];
		$addwac=file_get_contents("http://192.168.22.2/jda_scripts/add_wac.php?ext=$hab&fecha=".urlencode($fechaw)."&lang=".$lang);
		}
	}

$seccion="funcionesHuesped";
$opcion="wakeup";
$wacs=file_get_contents("http://192.168.22.2/jda_scripts/list_wac.php");
if ($wacs!="**") $wacs=explode("*", $wacs);
$cant=0;
if ($wacs!="**")
for ($i=0;$i<count($wacs);$i++)
	{
	$data=explode("|", $wacs[$i]);
	$wu[$i]["ext"]=$data[0];
	$wu[$i]["hora"]=date("H:i", $data[1]);
	$wu[$i]["fecha"]=date("d/m/Y", $data[1]);
	$wu[$i]["filename"]=$data[2];
	$cant++;	
	}
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>netbox Manager | Hotel Mitru Sur</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- Bootstrap 3.3.2 -->
	<?php include("linksCSS.php"); ?>
  <script language="javascript">
  function delWac(delwac)
  	{
	x=confirm("Está seguro que desea eliminar esta Wake-Up Call?");
	if(x) location.href="wakeUpCalls.php?delwac="+delwac;
	}
  </script>
  </head>
  <body class="skin-blue">
    <div class="wrapper">
      <?php include("header.php"); ?>
      <!-- Left side column. contains the logo and sidebar -->
      <?php include("sidebar.php");  ?>
      <!-- Right side column. Contains the navbar and content of the page -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header no-margin">
          <h1 class="text-center">
            Wake Up Calls</h1>
        </section>
        <!-- Content Header (Page header) -->
        <section class="content-header no-margin">
        <?php if ($errorf) { ?>
        <div class="callout callout-danger">
        <h4>Error de fecha</h4>
        <p>La fecha de Wake-Up Call no puede ser menor a la fecha actual</p>
        </div>
        <?php } ?>
        </section>
        <!-- Main content -->
        <section class="content">
        <div class="row">
         <div class="col-xs-12" >
         <form name="addwac" id="addwac" action="" method="post">
          <table class="table table-bordered table-hover" id="tab2">
            <tbody>
              <tr>
                <td width="25%"><div class="bootstrap-datepicker">
                    <div class="form-group">
                      <label>Fecha</label>
                       <div class="input-group">
                       
                        <input name="fechawac" type="text" class="form-control datepicker" readonly />
                        <div class="input-group-addon">
                          <i class="fa fa-calendar-o"></i>                        </div>
                      </div><!-- /.input group -->
                    </div><!-- /.form group -->
                  </div></td>
                <td width="25%"><div class="bootstrap-timepicker">
                    <div class="form-group">
                       <label>Hora</label>
                       <div class="input-group">
                       
                        <input name="horawac" type="text" class="form-control timepicker" readonly />
                        <div class="input-group-addon">
                          <i class="fa fa-clock-o"></i>                        </div>
                      </div><!-- /.input group -->
                    </div><!-- /.form group -->
                  </div></td>
                <td width="15%">
                <label>Habitación</label>
                <div class="form-group">
                      
                      <select class="form-control" name="habwac">
                      <? for ($piso=2; $piso<=8; $piso++)
					  { 
					  	 $maxhab=7;
					     if ($piso==2) $maxhab=1;
						 if ($piso==7) $maxhab=6;
						 if ($piso==8) $maxhab=6;
					     for ($pos=1;$pos<=$maxhab;$pos++)
						 	{
							$hab=($piso*100)+$pos;
					  ?>
                        <option value="<?= $hab ?>">Habitación <?= $hab ?></option>
                       <?
                            }
					   }
					   ?>
                       <option value="112">PRUEBA 112</option>
                       <option value="999">PRUEBA 999</option>
                      </select>
                    </div></td>
                <td><div class="form-group">
                       <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label><div align="center"><button class="btn btn-block btn-primary" type="submit">Agregar Llamada</button></div></div></td>
              </tr>
            </tbody>
          </table>
          </form>
         </div>
        </div>

        <div class="row">
        	<div class="col-xs-12" >
        		<div class="box">
					<div class="box-body">
<table id="tab1" class="table table-bordered table-hover">
	<thead>
          <tr>
    			<th width="25%" scope="col"><div align="center">Fecha</div></th>
    			<th width="25%" scope="col"><div align="center">Hora</div></th>
    			<th width="15%" scope="col"><div align="center">Habitación</div></th>
    			<th scope="col"><div align="center">Eliminar</div></th>
  			</tr>
           </thead>
           <tbody>
  <?php
  for($j=0; $j<$cant; $j++)
  	{  
  ?>
  <tr>
    <td><div align="center"><?php echo($wu[$j]["fecha"]); ?></div></td>
    <td><div align="center"><?php echo($wu[$j]["hora"]); ?></div></td>
    <td><div align="center"><?php echo($wu[$j]["ext"]); ?></div></td>
    <td><div align="center"><div align="center"><button class="btn btn-block btn-danger" onClick="delWac('<?php echo($wu[$j]["filename"]); ?>')">Eliminar</button></div></div></td>
  </tr>
  <?php
	}
  ?>
  </tbody>
</table>
		</div>
        </div>
        </div>
        </div>
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->
	 <?php include("footer.php"); ?>
    </div><!-- ./wrapper -->

    <!-- jQuery 2.1.3 -->
    <script src="../plugins/jQuery/jQuery-2.1.3.min.js"></script>
    <!-- Bootstrap 3.3.2 JS -->
    <script src="../bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
    <!-- Slimscroll -->
    <script src="../plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
    <!-- FastClick -->
    <script src='../plugins/fastclick/fastclick.min.js'></script>
    <!-- AdminLTE App -->
    <script src="../dist/js/app.min.js" type="text/javascript"></script>    
    <!-- Bootstrap WYSIHTML5 -->
    <script src="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js" type="text/javascript"></script>
    <!-- iCheck -->
    <script src="../plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
    <script src="../plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
    <script src="../plugins/iCheck/icheck.min.js" type="text/javascript"></script>
    <script src="../plugins/timepicker/bootstrap-timepicker.js" type="text/javascript"></script>
    <script src="../plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
    <!-- Page script -->
    <script type="text/javascript">
      $(function () {

        "use strict";

        //iCheck for checkbox and radio inputs
        $('input[type="checkbox"]').iCheck({
          checkboxClass: 'icheckbox_minimal-blue',
          radioClass: 'iradio_minimal-blue'
        });

        //When unchecking the checkbox
        $("#check-all").on('ifUnchecked', function (event) {
          //Uncheck all checkboxes
          $("input[type='checkbox']", ".table-mailbox").iCheck("uncheck");
        });
        //When checking the checkbox
        $("#check-all").on('ifChecked', function (event) {
          //Check all checkboxes
          $("input[type='checkbox']", ".table-mailbox").iCheck("check");
        });
        //Handle starring for glyphicon and font awesome
        $(".fa-star, .fa-star-o, .glyphicon-star, .glyphicon-star-empty").click(function (e) {
          e.preventDefault();
          //detect type
          var glyph = $(this).hasClass("glyphicon");
          var fa = $(this).hasClass("fa");

          //Switch states
          if (glyph) {
            $(this).toggleClass("glyphicon-star");
            $(this).toggleClass("glyphicon-star-empty");
          }

          if (fa) {
            $(this).toggleClass("fa-star");
            $(this).toggleClass("fa-star-o");
          }
        });

        //Initialize WYSIHTML5 - text editor
        $("#email_message").wysihtml5();
      });
	  
	    $(function () {
        $('#tab1').dataTable();
		$('#tab1d').dataTable({
          "bPaginate": true,
          "bLengthChange": false,
          "bFilter": false,
          "bSort": true,
          "bInfo": true,
          "bAutoWidth": false
        });
      });
	          //Timepicker
        $(".timepicker").timepicker({
          showInputs: false,
		  minuteStep: 5
        });
	          //Datepicker
        $(".datepicker").datepicker({
          setDate: new Date(),
          autoclose: true,
		  showInputs: false
        });
    </script>
    <!-- AdminLTE for demo purposes -->
    <!-- <script src="../dist/js/demo.js" type="text/javascript"></script> -->

  </body>
</html>
