3 * Export quiz questions into the given category
5 * @author Martin Dougiamas, Howard Miller, and many others.
6 * {@link http://moodle.org}
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package questionbank
9 * @subpackage importexport
12 require_once("../config.php");
13 require_once( "editlib.php" );
15 list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
17 $cattofile = optional_param('cattofile',0, PARAM_BOOL
);
19 $exportfilename = optional_param('exportfilename','',PARAM_FILE
);
20 $format = optional_param('format','', PARAM_FILE
);
21 $categoryid = optional_param('category',0,PARAM_INT
);
23 // get display strings
25 $txt->category
= get_string('category','quiz');
26 $txt->download
= get_string('download','quiz');
27 $txt->downloadextra
= get_string('downloadextra','quiz');
28 $txt->exporterror
= get_string('exporterror','quiz');
29 $txt->exportname
= get_string('exportname','quiz');
30 $txt->exportquestions
= get_string('exportquestions', 'quiz');
31 $txt->fileformat
= get_string('fileformat','quiz');
32 $txt->exportcategory
= get_string('exportcategory','quiz');
33 $txt->modulename
= get_string('modulename','quiz');
34 $txt->modulenameplural
= get_string('modulenameplural','quiz');
35 $txt->tofile
= get_string('tofile','quiz');
38 if (!$course = get_record("course", "id", $courseid)) {
39 error("Course does not exist!");
42 // make sure we are using the user's most recent category choice
43 if (empty($categoryid)) {
44 $categoryid = $pagevars['cat'];
47 if (!$category = get_record("question_categories", "id", $categoryid)) {
48 $category = get_default_question_category($courseid);
51 if (!$categorycourse = get_record("course", "id", $category->course
)) {
52 print_error('nocategory','quiz');
56 // check role capability
57 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
58 require_capability('moodle/question:export', $context);
60 // ensure the files area exists for this course
61 make_upload_directory( "$course->id" );
63 // check category is valid
64 $validcats = question_category_options( $course->id
, true, false );
65 if (!array_key_exists( $categoryid, $validcats)) {
66 print_error( 'invalidcategory','quiz' );
71 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE
, $course->id
))
72 ?
update_module_button($cm->id
, $course->id
, get_string('modulename', $cm->modname
))
75 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname
), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity');
76 $navlinks[] = array('name' => format_string($module->name
), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title');
77 $navlinks[] = array('name' => $txt->exportquestions
, 'link' => '', 'type' => 'title');
78 $navigation = build_navigation($navlinks);
79 print_header_simple($txt->exportquestions
, '', $navigation, "", "", true, $strupdatemodule);
83 $
{$cm->modname
} = $module;
84 include($CFG->dirroot
."/mod/$cm->modname/tabs.php");
86 // Print basic page layout.
88 $navlinks[] = array('name' => $txt->exportquestions
, 'link' => '', 'type' => 'title');
89 $navigation = build_navigation($navlinks);
91 print_header_simple($txt->exportquestions
, '', $navigation);
93 $currenttab = 'export';
97 if (!empty($format)) { /// Filename
99 if (!confirm_sesskey()) {
100 print_error( 'sesskey' );
103 if (! is_readable("format/$format/format.php")) {
104 error( "Format not known ($format)" ); }
106 // load parent class for import/export
107 require("format.php");
109 // and then the class for the selected format
110 require("format/$format/format.php");
112 $classname = "qformat_$format";
113 $qformat = new $classname();
115 $qformat->setCategory( $category );
116 $qformat->setCourse( $course );
117 $qformat->setFilename( $exportfilename );
118 $qformat->setCattofile( $cattofile );
120 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
121 error( $txt->exporterror
, $thispageurl->out());
124 if (! $qformat->exportprocess()) { // Process the export data
125 error( $txt->exporterror
, $thispageurl->out());
128 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
129 error( $txt->exporterror
, $thispageurl->out());
133 // link to download the finished file
134 $file_ext = $qformat->export_file_extension();
135 if ($CFG->slasharguments
) {
136 $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
139 $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
141 echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
142 echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
144 print_continue("edit.php?".$thispageurl->get_query_string());
145 print_footer($course);
149 /// Display upload form
151 // get valid formats to generate dropdown list
152 $fileformatnames = get_import_export_formats( 'export' );
155 if (empty($exportfilename)) {
156 $exportfilename = default_export_filename($course, $category);
159 print_heading_with_help($txt->exportquestions
, 'export', 'quiz');
160 print_simple_box_start('center');
163 <form enctype
="multipart/form-data" method
="post" action
="export.php">
164 <fieldset
class="invisiblefieldset" style
="display: block;">
165 <input type
="hidden" name
="sesskey" value
="<?php echo sesskey(); ?>" />
166 <?php
echo $thispageurl->hidden_params_out(array(), 3); ?
>
167 <table cellpadding
="5">
169 <td align
="right"><?php
echo $txt->category
; ?
>:</td
>
172 question_category_select_menu($course->id
, true, false, $category->id
);
173 echo $txt->tofile
; ?
>
174 <input name
="cattofile" type
="checkbox" />
175 <?php
helpbutton('exportcategory', $txt->exportcategory
, 'quiz'); ?
>
179 <td align
="right"><?php
echo $txt->fileformat
; ?
>:</td
>
181 <?php
choose_from_menu($fileformatnames, 'format', 'gift', '');
182 helpbutton('export', $txt->exportquestions
, 'quiz'); ?
>
186 <td align
="right"><?php
echo $txt->exportname
; ?
>:</td
>
188 <input type
="text" size
="40" name
="exportfilename" value
="<?php echo $exportfilename; ?>" />
193 <input type
="submit" name
="save" value
="<?php echo $txt->exportquestions; ?>" />
202 print_simple_box_end();
203 print_footer($course);