$resp_txt = new Ejercicios_texto_texto_resp(NULL, $id_pregunta, $resp_textarea, 0);
                            $resp_txt->insertar();
                        }
                    }
                    echo "insertado";
                }
            } else {
                if ($tipo_origen == 4) {
                    // ES UNA IMAGEN
                    if ($tipo_respuesta == 1) {
                        //La respuesta es un texto
                        //$preg = required_param('pregunta' . $j, PARAM_TEXT);
                        $preg = "foto_" . $id_ejercicio . "_" . $j . ".jpg";
                        $ejercicio_texto_preg = new Ejercicios_texto_texto_preg(NULL, $id_ejercicio, $preg);
                        $id_pregunta = $ejercicio_texto_preg->insertar();
                        $ejercicio_texto_img = new Ejercicios_imagenes_asociadas($NULL, $id_ejercicio, $id_pregunta, $preg);
                        $ejercicio_texto_img->insertar();
                        $num_resp = required_param('num_res_preg' . $j, PARAM_INT);
                        for ($k = 1; $k <= $num_resp; $k++) {
                            $resp_textarea = required_param("respuesta" . $k . "_" . $j, PARAM_TEXT);
                            $resp_txt = new Ejercicios_texto_texto_resp(NULL, $id_pregunta, $resp_textarea, 0);
                            $resp_txt->insertar();
                        }
                    }
                }
            }
        }
    }
}
commit_sql();
redirect('./view.php?id=' . $id_curso . '&opcion=9');
        //echo "es una imagen la pregunta";
        $numero_preguntas = optional_param('numeropreguntas', PARAM_INT);
        //echo "numero preguntas" . $numero_preguntas;
        //SUBO LAS FOTOS A MOODLE
        $m = 1;
        foreach ($_FILES as $name => $values) {
            //tengo que cambiar la ruta donde se guarda
            if (move_uploaded_file($values['tmp_name'], './imagenes/foto_' . $id_ejercicio . '_' . $m . '.jpg')) {
                //  echo 'El archivo ha sido subido correctamente.<br/>';
                $m++;
            }
        }
        for ($i = 0; $i < $numero_preguntas; $i++) {
            //Obtengo la pregunta
            $j = $i + 1;
            $pregunta = optional_param('pregunta' . $j, PARAM_TEXT);
            //Inserto la pregunta Archivo asociación
            $mispreguntas = new Ejercicios_texto_texto_preg(NULL, $id_ejercicio, $pregunta);
            $id_preg = $mispreguntas->insertar();
            // $dirvideoasociado = optional_param('archivovideo'.$j,PARAM_TEXT);
            $rcorrecta = 0;
            //Me da igual si es corrects o incorrecta
            $nombre_foto = 'foto_' . $id_ejercicio . '_' . $j . '.jpg';
            $mi_respuesta = new Ejercicios_imagenes_asociadas(NULL, $id_ejercicio, $id_preg, $nombre_foto);
            $mi_respuesta->insertar();
        }
        //echo "fin insercción";
        break;
}
//Muestro el ejercicio
redirect('./view.php?id=' . $id_curso . '&opcion=8' . '&id_ejercicio=' . $id_ejercicio . '&tipo_origen=' . $tipo_origen . "&tr=" . $tipo_respuesta . "&tipocreacion=" . $tipocreacion);