123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- /* AJAX
- * Selecciona los datos de la carrera
- * Recibe:
- * json de la clase
- * Return:
- * resultado o cadena de error
- */
- require_once("../../include/constantes.php");
- require_once("../../include/nocache.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../classes/ValidaSesion.php");
- //require_once("../classes/LogActividad.php");//die on error
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 102, GEMA);
- if(!$objSesion->tieneAcceso() || !$objSesion->puedeEditar()){
- $return["error"] = "Error! No tienes permisos para realizar esta acción.";
- }else if(!isset($_POST["json"]) || !isset($_SESSION["periodo_id"])){
- $return["error"] = "Error! No se recibió la información de los alumnos.";
- }else{
- $clase = json_decode($_POST["json"], true);
-
- $error = true;
- $return["error"] = "";
- $sin_borrar = 0;
-
- try {
- $pdo->beginTransaction();
- $error = false;
- $arregloQuery = array();
- //---- Borrar todas las materias de alumnos actuales revalidadas----
- $stmt = $pdo->prepare('Select * from fd_alumnomaterias(:usr, :per, NULL, 1)');//solo revalidadas
- $stmt->bindParam(":per", $_SESSION["periodo_id"]);
- foreach($clase as $alumno){
- $stmt->bindParam(":usr", $alumno["id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] .= "Ocurrió un error al borrar las materias del alumno '".$alumno["id"]."'. ";//.$t[2];
- $error = true;
- }else{
- $res = $stmt->fetch();
- $sin_borrar+= $res["fd_alumnomaterias"];
- }
- }
- $stmt->closeCursor();
-
- //---- Insertar nueva información ----------
- if(!$error){
- $stmt = $pdo->prepare('Select * from fi_alumnomaterias(:usr, :per, :mat, NULL)');
- $stmt->bindParam(":per", $_SESSION["periodo_id"]);
- foreach($clase as $alumno){
- $stmt->bindParam(":usr", $alumno["id"]);
- foreach($alumno["matArr"] as $mat){
- //foreach($mat["califArr"] as $calif){
- //if($calif["revalidada"] && !$error && $calif["calif"] != ""){
- if($mat["califArr"][0]["revalidada"] && !$error && $mat["califArr"][0]["calif"] != ""){
- $stmt->bindParam(":mat", $mat["id"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] .= "Ocurrió un error al guardar la materia '".$mat["desc"]."' del alumno '".$alumno["id"]."'. ".$t[2];
- $error = true;
- }
- }
- //}
- }
- }
- $stmt->closeCursor();
- }
- //---- Insertar nueva calificacion ----------
- if(!$error){
- $stmt = $pdo->prepare('Select * from fi_alumnomaterias_calif(:usr, :per, :mat, 1, :calif)');//tipo revalidada
- $stmt->bindParam(":per", $_SESSION["periodo_id"]);
- foreach($clase as $alumno){
- $stmt->bindParam(":usr", $alumno["id"]);
- foreach($alumno["matArr"] as $mat){
- foreach($mat["califArr"] as $calif){
- if($calif["revalidada"] && !$error && $calif["calif"] != ""){
- $stmt->bindParam(":mat", $mat["id"]);
- $stmt->bindParam(":calif", $calif["calif"]);
- if(!$stmt->execute()){
- $t = $stmt->errorInfo();
- $return["error"] .= "Ocurrió un error al guardar la calificación de la materia '".$mat["desc"]."' del alumno '".$alumno["id"]."'. ".$t[2];
- $error = true;
- }
- }
- }
- }
- }
- $stmt->closeCursor();
- }
-
- $return["sin_borrar"] = $sin_borrar;
- if(!$error){
- $pdo->commit();
- unset($return["error"]);
- $return["ok"] = "Las materias revalidadas se guardaron correctamente";
- }else
- $pdo->rollBack();
- $stmt = null; // cierra conexion
- } catch(PDOException $e) {
- $pdo->rollBack();
- $return["error"] = "Ocurrió un error al insertar las materias revalidadas de los alumnos.";
- }
- }
- $return["json"] = json_encode($return);
- echo json_encode($return);
- ?>
|