<?php
require_once("../config/conexion.php");
require_once("../models/Clases.php");
require_once("../models/Permisos.php");
$clases = new Clases();
/* =============================================
  JAVASCRIPT
  ============================================= */
switch ($_GET["op"]) {    
    case "guardarClases":        
        $datos = array("tabla" => "clases_grabadas",
            "mallacurricular" => $_POST["mallacurricular"],
            "semana" => $_POST["semana"],
            "fecha" => $_POST["fecha"],
            "link" => $_POST["link"]
        );
        $clases->mdlIngresarClases($datos);        
        break;      
    case "eliminar_clase":
        $datos = $clases->EliminarClase_por_ID($_POST["clasedbk"]);
        break;  
    case "listarClases":
        $datos = $clases->ConsultarClases($_POST["mallacurricular"]);        
        $accesos ="";
        foreach ($datos as $row) {
            $sub_array = array();
            $sub_array[] = $row["clasedbk"];
            $sub_array[] = $row["semana"];
            $sub_array[] = $row["fecha"];
            if ($_SESSION["perfil"]=="DOCENTE") {
                $sub_array[] = $row["link"];            
                $accesos = $accesos . '
                    <button type="button" onClick="eliminarClase(' . $row["clasedbk"] . ');" id="' . $row["clasedbk"] . '" class="btn btn-outline-danger btn-icon"><div><i class="fa fa-times"></i></div></button>';                        
            }
            if ($_SESSION["perfil"]=="ESTUDIANTE") {
                $sub_array[] = '<a href="'.$row["link"].'" target="_blank" class="btn btn-danger btn-lg active" role="button" aria-pressed="true">Ver</a>';                
            }
            $sub_array[] = $accesos;
            $data[] = $sub_array;
            $accesos = "";
        }
        $results = array(
            "sEcho" => 1,
            "iTotalRecords" => count($data),
            "iTotalDisplayRecords" => count($data),
            "aaData" => $data
        );
        echo json_encode($results);
        break;        
}
?>

