2006-02-24 15:17:40 +00:00
|
|
|
<?php // $Id$
|
|
|
|
/**
|
|
|
|
* Export quiz questions into the given category
|
|
|
|
*
|
|
|
|
* @version $Id$
|
|
|
|
* @author Martin Dougiamas, Howard Miller, and many others.
|
|
|
|
* {@link http://moodle.org}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package quiz
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once("../config.php");
|
2006-05-02 12:26:03 +00:00
|
|
|
require_once( "editlib.php" );
|
2006-02-24 15:17:40 +00:00
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
// get parameters
|
2006-02-24 15:17:40 +00:00
|
|
|
$categoryid = optional_param('category',0, PARAM_INT);
|
2007-02-07 10:29:53 +00:00
|
|
|
$cattofile = optional_param('cattofile',0, PARAM_BOOL);
|
2006-02-24 15:17:40 +00:00
|
|
|
$courseid = required_param('courseid',PARAM_INT);
|
2006-03-08 13:12:46 +00:00
|
|
|
$exportfilename = optional_param('exportfilename','',PARAM_FILE );
|
2007-02-07 10:29:53 +00:00
|
|
|
$format = optional_param('format','', PARAM_FILE );
|
|
|
|
|
|
|
|
|
|
|
|
// get display strings
|
|
|
|
$txt = new object;
|
|
|
|
$txt->category = get_string('category','quiz');
|
|
|
|
$txt->download = get_string('download','quiz');
|
|
|
|
$txt->downloadextra = get_string('downloadextra','quiz');
|
|
|
|
$txt->exporterror = get_string('exporterror','quiz');
|
|
|
|
$txt->exportname = get_string('exportname','quiz');
|
|
|
|
$txt->exportquestions = get_string('exportquestions', 'quiz');
|
|
|
|
$txt->fileformat = get_string('fileformat','quiz');
|
|
|
|
$txt->exportcategory = get_string('exportcategory','quiz');
|
|
|
|
$txt->modulename = get_string('modulename','quiz');
|
|
|
|
$txt->modulenameplural = get_string('modulenameplural','quiz');
|
|
|
|
$txt->nocategory = get_string('nocategory','quiz');
|
|
|
|
$txt->tofile = get_string('tofile','quiz');
|
|
|
|
|
2006-02-24 15:17:40 +00:00
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $courseid)) {
|
|
|
|
error("Course does not exist!");
|
|
|
|
}
|
2006-05-01 22:26:06 +00:00
|
|
|
|
2006-05-22 13:06:36 +00:00
|
|
|
$showcatmenu = false;
|
2006-05-01 22:26:06 +00:00
|
|
|
if ($categoryid) { // update category in session variable
|
|
|
|
$SESSION->questioncat = $categoryid;
|
|
|
|
} else { // try to get category from modform
|
2006-02-24 15:17:40 +00:00
|
|
|
$showcatmenu = true; // will ensure that user can choose category
|
2006-04-27 06:42:10 +00:00
|
|
|
if (isset($SESSION->questioncat)) {
|
|
|
|
$categoryid = $SESSION->questioncat;
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-01 07:03:57 +00:00
|
|
|
if (! $category = get_record("question_categories", "id", $categoryid)) {
|
2006-02-28 09:36:31 +00:00
|
|
|
$category = get_default_question_category($courseid);
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $categorycourse = get_record("course", "id", $category->course)) {
|
2007-02-07 10:29:53 +00:00
|
|
|
error( $txt->nocategory );
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id, false);
|
2006-09-06 08:55:23 +00:00
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
// check role capability
|
2006-09-06 08:55:23 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/question:export', $context);
|
2006-02-24 15:17:40 +00:00
|
|
|
|
|
|
|
// ensure the files area exists for this course
|
|
|
|
make_upload_directory( "$course->id" );
|
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
/// Header
|
2006-02-24 15:17:40 +00:00
|
|
|
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
|
2006-09-06 08:55:23 +00:00
|
|
|
$strupdatemodule = has_capability('moodle/course:manageactivities', $context)
|
2007-02-07 10:29:53 +00:00
|
|
|
? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename )
|
2006-02-24 15:17:40 +00:00
|
|
|
: "";
|
2007-02-07 10:29:53 +00:00
|
|
|
print_header_simple($txt->exportquestions, '',
|
|
|
|
"<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">$txt->modulenameplural</a>".
|
|
|
|
" -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
|
|
|
|
' -> '.$txt->exportquestions,
|
|
|
|
"", "", true, $strupdatemodule);
|
2006-02-24 15:17:40 +00:00
|
|
|
$currenttab = 'edit';
|
|
|
|
$mode = 'export';
|
2006-03-01 09:30:21 +00:00
|
|
|
include($CFG->dirroot.'/mod/quiz/tabs.php');
|
2006-02-24 15:17:40 +00:00
|
|
|
} else {
|
2007-02-07 10:29:53 +00:00
|
|
|
print_header_simple($txt->exportquestions, '', $txt->exportquestions);
|
2006-03-01 08:43:41 +00:00
|
|
|
// print tabs
|
|
|
|
$currenttab = 'export';
|
|
|
|
include('tabs.php');
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($format)) { /// Filename
|
|
|
|
|
|
|
|
if (!confirm_sesskey()) {
|
2007-02-07 10:29:53 +00:00
|
|
|
print_error( 'sesskey' );
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! is_readable("format/$format/format.php")) {
|
2007-02-07 10:29:53 +00:00
|
|
|
error( "Format not known ($format)" ); }
|
2006-02-24 15:17:40 +00:00
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
// load parent class for import/export
|
|
|
|
require("format.php");
|
|
|
|
|
|
|
|
// and then the class for the selected format
|
2006-02-24 15:17:40 +00:00
|
|
|
require("format/$format/format.php");
|
|
|
|
|
2006-03-01 07:36:09 +00:00
|
|
|
$classname = "qformat_$format";
|
|
|
|
$qformat = new $classname();
|
2006-02-24 15:17:40 +00:00
|
|
|
|
2006-11-29 13:32:00 +00:00
|
|
|
$qformat->setCategory( $category );
|
|
|
|
$qformat->setCourse( $course );
|
|
|
|
$qformat->setFilename( $exportfilename );
|
2007-02-07 10:29:53 +00:00
|
|
|
$qformat->setCattofile( $cattofile );
|
2006-11-29 13:32:00 +00:00
|
|
|
|
|
|
|
if (! $qformat->exportpreprocess()) { // Do anything before that we need to
|
2007-02-07 10:29:53 +00:00
|
|
|
error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 13:32:00 +00:00
|
|
|
if (! $qformat->exportprocess()) { // Process the export data
|
2007-02-07 10:29:53 +00:00
|
|
|
error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
|
2006-03-01 07:36:09 +00:00
|
|
|
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
|
2007-02-07 10:29:53 +00:00
|
|
|
error( $txt->exporterror, "$CFG->wwwroot/question/export.php?courseid={$course->id}&category=$category->id");
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
echo "<hr />";
|
|
|
|
|
|
|
|
// link to download the finished file
|
2006-03-01 07:36:09 +00:00
|
|
|
$file_ext = $qformat->export_file_extension();
|
2006-02-24 15:17:40 +00:00
|
|
|
if ($CFG->slasharguments) {
|
2006-07-18 13:33:45 +00:00
|
|
|
$efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-07-18 13:33:45 +00:00
|
|
|
$efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
|
2006-02-24 15:17:40 +00:00
|
|
|
}
|
2007-02-07 12:10:56 +00:00
|
|
|
echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
|
|
|
|
echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
|
2006-02-24 15:17:40 +00:00
|
|
|
|
2006-03-03 11:17:23 +00:00
|
|
|
print_continue("edit.php?courseid=$course->id");
|
2006-02-24 15:17:40 +00:00
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
/// Display upload form
|
2006-02-24 15:17:40 +00:00
|
|
|
|
|
|
|
// get valid formats to generate dropdown list
|
2007-02-07 10:29:53 +00:00
|
|
|
$fileformatnames = get_import_export_formats( 'export' );
|
2006-02-24 15:17:40 +00:00
|
|
|
|
|
|
|
// get filename
|
|
|
|
if (empty($exportfilename)) {
|
|
|
|
$exportfilename = default_export_filename($course, $category);
|
|
|
|
}
|
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
print_heading_with_help($txt->exportquestions, 'export', 'quiz');
|
2007-02-07 12:10:56 +00:00
|
|
|
print_simple_box_start('center');
|
2007-02-07 10:29:53 +00:00
|
|
|
?>
|
2006-02-24 15:17:40 +00:00
|
|
|
|
2007-02-07 10:29:53 +00:00
|
|
|
<form enctype="multipart/form-data" method="post" action="export.php">
|
2007-02-07 12:10:56 +00:00
|
|
|
<fieldset class="invisiblefieldset">
|
2007-02-07 10:29:53 +00:00
|
|
|
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
|
|
|
|
<input type="hidden" name="courseid" value="<?php echo $course->id; ?>" />
|
|
|
|
|
|
|
|
<table cellpadding="5">
|
|
|
|
<tr>
|
|
|
|
<td align="right"><?php echo $txt->category; ?>:</td>
|
|
|
|
<td>
|
|
|
|
<?php
|
|
|
|
if (!$showcatmenu) { // category already specified
|
|
|
|
echo '<strong>'.question_category_coursename($category).'</strong> '; ?>
|
|
|
|
<input type="hidden" name="category" value="<?php echo $category->id ?>" />
|
|
|
|
<?php
|
|
|
|
} else { // no category specified, let user choose
|
|
|
|
question_category_select_menu($course->id, true, false, $category->id);
|
|
|
|
}
|
|
|
|
echo $txt->tofile; ?>
|
|
|
|
<input name="cattofile" type="checkbox" />
|
|
|
|
<?php helpbutton('exportcategory', $txt->exportcategory, 'quiz'); ?>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td align="right"><?php echo $txt->fileformat; ?>:</td>
|
|
|
|
<td>
|
|
|
|
<?php choose_from_menu($fileformatnames, 'format', 'gift', '');
|
|
|
|
helpbutton('export', $txt->exportquestions, 'quiz'); ?>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td align="right"><?php echo $txt->exportname; ?>:</td>
|
|
|
|
<td>
|
|
|
|
<input type="text" size="40" name="exportfilename" value="<?php echo $exportfilename; ?>" />
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2007-02-07 13:01:39 +00:00
|
|
|
<td align="center" >
|
2007-02-07 10:29:53 +00:00
|
|
|
<input type="submit" name="save" value="<?php echo $txt->exportquestions; ?>" />
|
|
|
|
</td>
|
2007-02-07 13:01:39 +00:00
|
|
|
<td> </td>
|
2007-02-07 10:29:53 +00:00
|
|
|
</tr>
|
|
|
|
</table>
|
2007-02-07 12:10:56 +00:00
|
|
|
</fieldset>
|
2007-02-07 10:29:53 +00:00
|
|
|
</form>
|
|
|
|
<?php
|
2007-02-07 12:10:56 +00:00
|
|
|
|
2006-02-24 15:17:40 +00:00
|
|
|
print_simple_box_end();
|
|
|
|
print_footer($course);
|
2007-02-07 10:29:53 +00:00
|
|
|
?>
|
2006-02-24 15:17:40 +00:00
|
|
|
|