123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- require_once '../classes/Etapa.php';
- require_once '../classes/Proyecto.php';
- require_once '../classes/Recurso.php';
- require_once '../include/bd_pdo.php';
- if(!isset($_POST['concurso']) && !isset($_POST['json'])){
- $return['error'] = 'Error! No se recibieron los datos.';
- } else {
- $concurso = filter_input(INPUT_POST, "concurso", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $clase = json_decode($_POST["json"], true);
- $error = false;
- try {
- $pdo->beginTransaction();
- $stmt = $pdo->prepare('Select * from cidit_fd_fechaetapas(:concurso, NULL)');
- $stmt->bindParam(':concurso', $concurso);
- if(!$stmt->execute()){
- $return["error"] = "Error al borrar las fechas del concurso";
- $error = true;
- }else{
- $stmt->closeCursor();
- $stmt = null;
-
- //recorre objeto json
- foreach($clase as $etapa){
- if(!$error){//si no hay errores
- $orden = 1;
- foreach($etapa["fechas"] as $fecha_row){//recorre listado de fechas
- if(count($fecha_row) > 0){
- $fechas_str = implode(",", $fecha_row);//obiene fechas (inicial, final) y convierte en texto
- $stmt = $pdo->prepare('Select * from cidit_fi_fechaetapas(:concurso, :etapa, :fechas, :orden)');
- $stmt->bindParam(':concurso', $concurso);
- $stmt->bindParam(':etapa', $etapa["id"]);
- $stmt->bindParam(':fechas', $fechas_str);
- $stmt->bindParam(':orden', $orden);
- if(!$stmt->execute()){
- //$t = $stmt->errorInfo();
- $return["error"] = "Error al insertar las fechas del concurso.";//.$t[2];
- $error = true;
- break;
- }
- }
- $orden++;
- $stmt->closeCursor();
- }
- }
- }
- }
- $stmt->closeCursor();
- $stmt = null;
- if(!$error){
- $pdo->commit();
- $return["ok"]= "Las fechas se actualizaron correctamente";
- }else{
- $pdo->rollBack();
- }
-
- } catch(PDOException $e) {
- $pdo->rollBack();
- $return["error"] = "Error al insertar las fechas del concurso.";//.$e->getMessage();
- }
- }
- $return["json"] = json_encode($return);
- echo json_encode($return);
- ?>
|