<?
$r = "../";
require_once($r."inc/funciones.php");
validNotSession($r);
$mysqli = connectDB($r);
$code=$_GET['id'];
$iduser=$pedidos['iduser'];
$spe=$_SESSION['perfil'];
$sid=$_SESSION['userid'];
//if($spe!=$pad && $spe!=$psu && $sid!=$iduser){ exit(header("Location:".$r."dashboard.php?error=NO TIENES PERMISO PARA ESTA SECCION"));}
$row1 = $mysqli->query("SELECT * FROM z_pedido WHERE codigopedido=$code");
$proid = array();
$canid = array();
while($producto = $row1->fetch_assoc()) {
    array_push($proid,$producto['idproducto']);
    array_push($canid,$producto['cantidad']);
    $estado=$pedidos['estado'];
}

?>
<!DOCTYPE html>
<html lang="en">
  <?php include $r."inc/head.php"; ?>
<body>
  <?php include "nav.php"; ?>
    <div class="container-fluid">
      <div class="card mb-3">
        <div class="card-header h3">
          <i class="fa fa-table"></i> DESCRIPCIÓN PEDIDO N°<? echo $code?></div>
        <div class="card-body">
          <div class="table-responsive">
                  <form id="formulario" action="acciones.php" method="POST" >
            <table class="table table-bordered" width="100%" cellspacing="0">
              <thead>
                <tr>
                  <th>Nombre del Producto</th>
                  <th>Cantidad</th>
                </tr>
              </thead>
                  <tbody>
                    <? $productos = $mysqli->query("SELECT * FROM z_productos"); 
                      while ($pro = $productos->fetch_assoc()){
                      if (in_array($pro["id"], $proid)) {
                          $name='id'.$pro["id"];
                          $name2='can'.$pro["id"];
                          $name3='cantidad'.$pro["id"];
                          $row4 = $mysqli->query("SELECT * FROM z_pedido WHERE codigopedido=$code AND idproducto='".$pro["id"]."'");
                          $row5 = $row4->fetch_assoc();
                          $value=$row5['cantidad'];
                        }else{
                          $name='id'.$pro["id"];
                          $name2='cann'.$pro["id"];
                          $value="";
                        }
                      ?>
                      <tr>
                        <td>
                          <input type="hidden" name="<? echo $name ?>" value="<? echo $pro["id"] ?>"><? echo $pro["producto"]; ?>
                        </td>
                        <td>
                          <input class="form-control border-0 m-0 p-0" type="text" name="<? echo $name2 ?>" value="<? echo $value ?>">
                        </td>
                      </tr>
                    <? } ?>
              <tbody>
            </table>
            
            
        <div class="form-group">
          <label for="cliente" class="col-sm-2 col-form-label">Fecha de entrega</label><? $row10 = $mysqli->query("SELECT * FROM z_pedidos WHERE codigopedido=$code");$pedido = $row10->fetch_assoc(); ?>
          <div class="col-sm-4">
            <input value = "<? echo $pedido['fechaentrega']; ?>" type="date" class="form-control" name="fecha"  min="<? echo date('Y-m-d'); ?>" max="<? echo date('Y-');echo date('m')+01; echo date('-d'); ?>" required>
          </div>
        </div>
                  </form>
          </div>
        </div>
      </div>
    </div>
  <?php include "foot.php"; ?>
</body>
</html>   