Example #1
0
function eliminar($material, $tipo)
{
    $respuesta = new xajaxResponse();
    $conn = new conexionBD();
    $sql = "UPDATE  `material` SET  {$tipo} =  '' WHERE  Id IN  ({$material})";
    if (!$conn->EjecutarSQL($sql)) {
        $MSG = "Ha ocurrido un error al eliminar los datos del material.\nPor favor, intentelo nuevamente.";
    } else {
        $MSG = "Datos Eliminados correctamente";
    }
    //Eliminamos la fila entera si no tiene ningun elemento mas
    $sql = $conn->EjecutarSQL("SELECT * FROM material WHERE Id IN  ({$material})");
    $row = $conn->FetchArray($sql);
    if ($row['PC'] == '' && $row['Portatil'] == '' && $row['Monitor'] == '' && $row['Otros'] == '') {
        $sql = "DELETE FROM `material`  WHERE Id IN  ({$material})";
        $conn->EjecutarSQL($sql);
        $sql = "UPDATE `profesores` SET Id_material = '' WHERE Id_material IN  ({$material})";
        $conn->EjecutarSQL($sql);
    }
    $respuesta->addAlert($MSG);
    return $respuesta;
}
Example #2
0
function guardar($formulario, $profesor)
{
    $flag = 0;
    extract($formulario);
    $respuesta = new xajaxResponse("utf-8");
    $conn = new conexionBD();
    //Genera una nueva conexion
    $conn->EjecutarSQL("SET NAMES 'utf8'");
    // al guardar los numeros de las lineas nos aseguramos que si borran una no perderemos las referencias.
    foreach ($hdnIdCampos as $id) {
        $profesor = $formulario['hdnProfesor_' . $id];
        $sqlpro = "SELECT * FROM  `equipamiento_eii`.`profesores` WHERE Nombre =  '" . limpiar($profesor) . "' ";
        $result = $conn->EjecutarSQL($sqlpro);
        $filas = mysql_num_rows($result);
        if ($filas == 0) {
            //CONTROL DE ERRORES.  muy importante, si no guarda uno, no guarda nada.
            $conn->EjecutarSQL("ROLLBACK TRANSACTION A1");
            $MSG = "El profesor seleccionado no existe.\nPor favor, intentelo nuevamente.";
            $respuesta->addAlert($MSG);
            return $respuesta;
        }
        $row = $conn->FetchArray($result);
        $monitor = str_replace('||', '"', $formulario['hdnMonitor_' . $id]);
        $Str_SQL = "INSERT INTO material(`Id_profesor`, `PC` ,  `Fecha_PC` ,  `Portatil` ,  `Fecha_Portatil` ,  `Monitor` , `Fecha_Monitor`,  `Otros`, `Fecha_Otros` ) \n  VALUES ('','" . $formulario['hdnPC_' . $id] . "', '" . fecha($formulario['hdnFechaPC_' . $id]) . "', '" . $formulario['hdnPortatil_' . $id] . "', '" . fecha($formulario['hdnFechaPortatil_' . $id]) . "',\n   '" . $monitor . "',\n '" . fecha($formulario['hdnFechaMonitor_' . $id]) . "', '" . $formulario['hdnOtros_' . $id] . "', '" . fecha($formulario['hdnFechaOtros_' . $id]) . "')";
        $Str_SQL2 = "INSERT INTO material(`Id_profesor`, `PC` ,  `Fecha_PC` ,  `Portatil` ,  `Fecha_Portatil` ,  `Monitor` , `Fecha_Monitor`,  `Otros`, `Fecha_Otros` ) \n  VALUES ('" . $row['Id'] . "','" . $formulario['hdnPC_' . $id] . "', '" . fecha($formulario['hdnFechaPC_' . $id]) . "', '" . $formulario['hdnPortatil_' . $id] . "', '" . fecha($formulario['hdnFechaPortatil_' . $id]) . "',\n   '" . $monitor . "',\n '" . fecha($formulario['hdnFechaMonitor_' . $id]) . "', '" . $formulario['hdnOtros_' . $id] . "', '" . fecha($formulario['hdnFechaOtros_' . $id]) . "')";
        if ($row['Id_material'] == '0') {
            if (!$conn->EjecutarSQL($Str_SQL)) {
                //CONTROL DE ERRORES.  muy importante, si no guarda uno, no guarda nada.
                $conn->EjecutarSQL("ROLLBACK TRANSACTION A1");
                $flag = 1;
                $MSG = "Ha ocurrido un error al insertar los datos de los materiales.\nPor favor, intentelo nuevamente.";
            }
        } else {
            if (!$conn->EjecutarSQL($Str_SQL2)) {
                //CONTROL DE ERRORES.  muy importante, si no guarda uno, no guarda nada.
                $conn->EjecutarSQL("ROLLBACK TRANSACTION A1");
                $flag = 1;
                $MSG = "Ha ocurrido un error al insertar los datos de los materiales.\nPor favor, intentelo nuevamente.";
            }
        }
        if ($flag == 0) {
            $lastid = mysql_insert_id();
            $conn->EjecutarSQL("SET NAMES 'utf8'");
            //$row = $conn->FetchArray($result);
            $sql = "UPDATE  `equipamiento_eii`.`material` SET  `Id_profesor` =  '" . $row['Id'] . "'  WHERE  `material`.`Id` = '" . $lastid . "' ";
            if (!$conn->EjecutarSQL($sql)) {
                //CONTROL DE ERRORES.  muy importante, si no guarda uno, no guarda nada.
                $conn->EjecutarSQL("ROLLBACK TRANSACTION A1");
                $MSG = "Ha ocurrido un error al actualizar los materiales.\nPor favor, intentelo nuevamente.";
            }
            if ($row['Id_material'] == '0') {
                $conn->EjecutarSQL("SET NAMES 'utf8'");
                $sql = "UPDATE  `equipamiento_eii`.`profesores` SET  `Id_material` =  '" . $row['Id'] . "' WHERE  `profesores`.`Id` = '" . $row['Id'] . "' ";
                if (!$conn->EjecutarSQL($sql)) {
                    printf("ultimo registro insertado tiene el id %d\n", $lastid);
                }
                $conn->EjecutarSQL("COMMIT TRANSACTION A1");
            }
            $MSG = "Datos guardados con exito";
        }
    }
    $respuesta->addAlert($MSG);
    return $respuesta;
}