<?php

require_once "../../../app/model/db.class.php";

if ($_REQUEST['accion']=='listado'){

    $id1=$_REQUEST['id1'];
    $id2=$_REQUEST['id2'];

    $tabla=$_REQUEST['tabla'];
    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $query=$obj->consulta("select codigo,descripcion from ".$tabla." order by  orden asc ;");
    $obj->disconnect();

    $cadena="<table class='hovertable1' border='0' cellspacing='0' cellpadding='0' width='100%'>";
   
    while($row = $obj->fetch_assoc($query)) {
  
      $cadena.="<tr>";
      $cadena.="<td align='center'> <img id='elem1'  class='confirmar' src='../imagenes/boton.png' onClick='mostrar_lista(\"".$id1."\",\"".$id2."\",\"".$row['codigo']."\",\"".($row['descripcion'])."\");' height='20' width='30' alt='Seleccionar' title='Seleccionar'></td>";
      $cadena.="<td>".$row['codigo']."</td><td>".($row['descripcion'])."</td></tr>";
    }
    $cadena.="</table>";

    echo $cadena;

}


if ($_REQUEST['accion']=='listadograd'){

    $id1=$_REQUEST['id1'];
    $id2=$_REQUEST['id2'];

    $tabla=$_REQUEST['tabla'];
    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $query=$obj->consulta("select codigo,descripcion from ".$tabla." order by  orden asc ;");
    $obj->disconnect();

    $cadena="<table class='hovertable1' border='0' cellspacing='0' cellpadding='0' width='100%'>";

    while($row = $obj->fetch_assoc($query)) {

      $cadena.="<tr>";
      $cadena.="<td align='center'> <img id='elem1'  class='confirmar' src='imagenes/boton.png' onClick='mostrar_listagrad(\"".$id1."\",\"".$id2."\",\"".$row['codigo']."\",\"".($row['descripcion'])."\");' height='20' width='30' alt='Seleccionar' title='Seleccionar'></td>";
      $cadena.="<td>".$row['codigo']."</td><td>".($row['descripcion'])."</td></tr>";
    }
    $cadena.="</table>";

    echo $cadena;

}


if ($_REQUEST['accion']=='listacurso'){

    $id=$_REQUEST['grado'];
    $id1=$_REQUEST['id1'];
    $id2=$_REQUEST['id2'];
    

    $tabla=$_REQUEST['tabla'];
    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");
    
    $query=$obj->consulta("select * from ".$tabla." where grado='".$id."' order by orden");
    $n=$obj->numero_de_filas($query);
    
    if($n==0){
            echo "no";
        }else{

            $query=$obj->consulta("select * from ".$tabla."  where grado='".$id."'  order by orden");
            

            $cadena="<table class='hovertable1' border='0' cellspacing='0' cellpadding='0' width='100%'>";

              while ( $tsArray = $obj->fetch_assoc($query) )
                {
                $row[] = $tsArray;
                
                }
                
              for($i=0;$i<count($row);$i++)  
              {
                  $cadena.="<tr>";
                  $cadena.="<td align='center'> <img id='elem1'  class='confirmar' src='imagenes/boton.png' onClick='mostrar_lista(\"".$id1."\",\"".$id2."\",\"".$row[$i]['codigo']."\",\"".($row[$i]['descripcion'])."\");' height='20' width='30' alt='Seleccionar' title='Seleccionar'></td>";
                  $cadena.="<td>".$row[$i]['codigo']."</td><td>".($row[$i]['descripcion'])."</td>";

                  $obj = new database();
                  $obj->conectar(); $obj->consulta("set names 'utf8'");
                  $query=$obj->consulta("select * from jornadas where codigo='".$row[$i]['jornada']."';");
                  $jor=  $obj->fetch_assoc($query);

                  $cadena.="<td>".($jor['descripcion'])."</td></tr>";
              }
            $cadena.="</table>";
            $obj->disconnect();
            echo $cadena;
        }
}



if ($_POST['accion']=='al_salir'){

    $tabla=$_POST['tabla'];
    $codigo=$_POST['codigo'];
    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");

    $query=$obj->consulta("select codigo,descripcion from ".$tabla." where codigo='".$codigo."'");
    
    $n=$obj->numero_de_filas($query);
    $obj->disconnect();

    $row = $obj->fetch_assoc($query);

    if ($n>0){
        $cadena=($row['descripcion']);
    }
    else{
        $cadena="0";
    }

    echo $cadena;
}


if ($_POST['accion']=='al_salirc'){

    $id=$_REQUEST['grado'];
    $tabla=$_POST['tabla'];
    $codigo=$_POST['codigo'];
    $obj = new database();
    $obj->conectar(); $obj->consulta("set names 'utf8'");


    $query=$obj->consulta("select * from ".$tabla." where grado='".$id."' order by orden");
    $n=$obj->numero_de_filas($query);
    
    if($n==0){
            echo "no";
        }else{
            $query=$obj->consulta("select codigo,descripcion from ".$tabla." where grado='".$id."' and codigo='".$codigo."' ");
            $n=$obj->numero_de_filas($query);
            $obj->disconnect();

            $row = $obj->fetch_assoc($query);

            if ($n>0){
                $cadena=($row['descripcion']);
            }
            else{
                $cadena="0";
            }

            echo $cadena;
        }
}

?>
