<?php
session_start();

   include_once("../scripts/connect.php");
   $conexion=conecta_default();

   include("../scripts/session.php");
   //Validar Session

   $sesion=new Sesion("","","");/*Se crea un objeto nuevo con el privilegio necesario para la pag. actual*/
    if(!$sesion->isValida("1")){ /*Sesion invalida*/
	 header("Location: ../login.php?err=NoSesion");
    }/*no hay sesion*/

    else{
       $dato=explode("|",$_SESSION['usuario']);
       $sesion->setDatos($dato[0],$dato[1],$dato[2]);
    }

    //fin validar session

    $id_dist = $sesion->id;
	

?>

<html>
<head>
<title></title>
<body>
<center><font size="5"><b><br>Lista de Promociones Inactivas en Sistema</b><br></font><br><form name="busca" action="promociones.php" method="post">
		
<input type="submit" name="buscar" id="continuar" value="Regresar" ></form><table border="1">
                    <tr><th>Id Prom</th><th>Descripcion</th><th>Precio</th><th>Puntos</th><th>Contenido Predeterminado</th><th>Calificado</th></tr>
                    <?php
                    $q2 = "SELECT id_promo, promodesc, precio, puntos, tipo_promo, calf, activa from promod where tipo_promo=3 and activa=0 order by calf desc ";
                        
                           
                    $cr2 = mysqli_query($conexion, $q2) or die ('Error en la consulta' . mysqli_error($conexion));
                    while($r1 = mysqli_fetch_row($cr2)){
                        $r1[1] = utf8_encode($r1[1]);

                        $q21 = "SELECT idprod, cant, nombreProd from promo join productos on promo.idprod=productos.id_prod
                                where promo.promo ='$r1[0]' and tipo_prod=1";
                        $c21 = mysqli_query($conexion, $q21) or die ('Error en la consulta' . mysqli_error($conexion));
                        while($r11 = mysqli_fetch_row($c21)){
                            $r11[2] = utf8_encode($r11[2]);
                            $prom_prods[] = $r11;
                        }

                        $on_click = "'addprodventa(" . $i . "," . $r1[0] . "," . $r1[2] . "," . $r1[3] . "," . $r1[3] .
                            (($r1[4] == 3) ? "," . json_encode($prom_prods) . ");" : ");");
                        ?>

                        <tr bgcolor='#fcb4b4'><td><?php echo "$r1[0]";?></td>
                            <?php echo "<td id='nom$i' align='center'>$r1[1]</td><td align='center'>$r1[2]</td><td align='center'>$r1[3]</td>";?>
                            <td align="center">
                                <?php
                                foreach ($prom_prods as $prom_prod)
                                    echo"$prom_prod[1] $prom_prod[2]<br>";
                                unset($prom_prods);
                                $i++;
                                ?>
                            </td>
                            <td align="center"><?php echo(($r1[5] == 1) ? "Si" : "No");?></td>
                        </tr>
                    <?php } ?>
                </table>
                


</center>

<br />
</body>

</html>

