<?php if(isset($_GET["opt"]) && $_GET["opt"]=="all"):?>
<?php
$user = UserData::getById($_SESSION["user_id"]);
$grades = ItemData::getAll();
?>
<section class="content-header">
<a href='index.php?view=items&opt=new' class='btn btn-default pull-right'><i class='glyphicon glyphicon-plus-sign'></i> Agregar Mesa</a>
			<h1>Mesas</h1>
</section>
<section class="content">
<div class="row">

	<div class="col-md-12">
	<?php if(isset($_COOKIE["gradeupdated"])):?>
			<p class="alert alert-success"><i class='glyphicon glyphicon-ok-sign'></i> La categoria <b><?php echo $_COOKIE["gradeupdated"]; ?></b> ha sido actualizada exitosamente.</p>
		<?php 
		setcookie("gradeupdated","",time()-18600);
		endif; ?>

	<?php if(isset($_COOKIE["gradedeleted"])):?>
			<p class="alert alert-danger"><i class='glyphicon glyphicon-minus-sign'></i> La categoria <b><?php echo $_COOKIE["gradedeleted"]; ?></b> ha sido eliminada exitosamente.</p>
		<?php 
		setcookie("gradedeleted","",time()-18600);
		endif; ?>
		<?php if(isset($_COOKIE["gradeadded"])):?>
			<p class="alert alert-info"><i class='glyphicon glyphicon-ok-sign'></i> La categoria <b><?php echo $_COOKIE["gradeadded"]; ?></b> ha sido agregada exitosamente.</p>
		<?php 
		setcookie("gradeadded","",time()-18600);
		endif; ?>
<?php if(count($grades)>0):?>

<div class="box box-solid box-primary">
                                <div class="box-header">
                                    <h3 class="box-title"></h3>
                                </div>
                                <div class="box-body table-responsive">
<table class="table table-bordered table-hover datatable">
<thead>
	<th>Nombre</th>
	<th></th>
</thead>
<?php foreach($grades as $career):?>
<tr>
	<td><b><?php echo $career->name; ?></b></td>
	<td style="width:90px;">
		<a href="./?view=items&opt=edit&id=<?php echo $career->id; ?>" class="btn btn-xs btn-warning"><i class='glyphicon glyphicon-pencil'></i></a>
				<a href="#" id="del-<?php echo $career->id; ?>" class="btn btn-xs btn-danger"><i class='glyphicon glyphicon-trash'></i></a>
<!--		<a href="index.php?view=hidecategory&id=<?php echo $career->id; ?>" class="btn btn-sm btn-default tip" title="Desactivar Categoria"><i class='glyphicon glyphicon-eye-close'></i></a> -->
<script>
	$("#del-<?php echo $career->id?>").click(function(){
		c = confirm("Seguro quieres eliminar ??");
		if(c==true){
			window.location = "index.php?action=items&opt=del&id=<?php echo $career->id; ?>";
		}
	});
</script>
	</td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
<?php else: // no careers ?>
<div class="jumbotron">
	<h2><i class="glyphicon glyphicon-minus-sign"></i> No hay categorias </h2>
</div>
<?php endif; ?>
	</div>
</div>
</section>
<?php elseif(isset($_GET["opt"]) && $_GET["opt"]=="new"):?>
<?php
$user = UserData::getById($_SESSION["user_id"]);
?>
<section class="content">
<div class="row">

	<div class="col-md-12">
		<h2><i class='glyphicon glyphicon-plus-sign'></i> Agregar Mesa</h2>
<br>
<div class="box box-solid box-primary">
                                <div class="box-header">
                                    <h3 class="box-title"></h3>

                                </div>
                                <div class="box-body table-responsive">
<form class="form-horizontal" method="post" action="index.php?action=items&opt=add" role="form">
  <div class="form-group">
    <label for="inputEmail1" class="col-lg-3 control-label">Nombre</label>
    <div class="col-lg-8">
      <input type="text" class="form-control" name="name" id="name" placeholder="Nombre de la mesa">
    </div>
  </div>
  <div class="form-group">
    <div class="col-lg-offset-3 col-lg-9">
      <button type="submit" class="btn btn-success"><i class='glyphicon glyphicon-plus-sign'></i> Agregar Mesa</button>
    </div>
  </div>
</form>
</div>
</div>
	</div>
</div>
</section>
<?php elseif (isset($_GET["opt"]) && $_GET["opt"]=="edit"):?>
<?php $user = ItemData::getById($_GET["id"]);?>
<div class="row">
	<div class="col-md-12">
	<h1>Editar Mesa</h1>
	<br>
		<form class="form-horizontal" method="post" id="addproduct" action="index.php?action=items&opt=update" role="form">


  <div class="form-group">
    <label for="inputEmail1" class="col-lg-2 control-label">Nombre*</label>
    <div class="col-md-6">
      <input type="text" name="name" value="<?php echo $user->name;?>" class="form-control" id="name" placeholder="Nombre">
    </div>
  </div>

  <div class="form-group">
    <div class="col-lg-offset-2 col-lg-10">
    <input type="hidden" name="user_id" value="<?php echo $user->id;?>">
      <button type="submit" class="btn btn-primary">Actualizar Mesa</button>
    </div>
  </div>
</form>
	</div>
</div>
<?php endif; ?>