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
);
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!");
43 if (!$category = get_record("question_categories", "id", $pagevars['cat'])) {
44 $category = get_default_question_category($courseid);
47 if (!$categorycourse = get_record("course", "id", $category->course
)) {
48 print_error('nocategory','quiz');
52 // check role capability
53 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
54 require_capability('moodle/question:export', $context);
56 // ensure the files area exists for this course
57 make_upload_directory( "$course->id" );
59 // check category is valid
60 if (!empty($pagevars['cat'])) {
61 $validcats = question_category_options( $course->id
, true, false );
62 if (!array_key_exists( $pagevars['cat'], $validcats)) {
63 print_error( 'invalidcategory','quiz' );
69 $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE
, $course->id
))
70 ?
update_module_button($cm->id
, $course->id
, get_string('modulename', $cm->modname
))
73 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname
), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity');
74 $navlinks[] = array('name' => format_string($module->name
), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?cmid={$cm->id}", 'type' => 'title');
75 $navlinks[] = array('name' => $txt->exportquestions
, 'link' => '', 'type' => 'title');
76 $navigation = build_navigation($navlinks);
77 print_header_simple($txt->exportquestions
, '', $navigation, "", "", true, $strupdatemodule);
81 $
{$cm->modname
} = $module;
82 include($CFG->dirroot
."/mod/$cm->modname/tabs.php");
84 // Print basic page layout.
86 $navlinks[] = array('name' => $txt->exportquestions
, 'link' => '', 'type' => 'title');
87 $navigation = build_navigation($navlinks);
89 print_header_simple($txt->exportquestions
, '', $navigation);
91 $currenttab = 'export';
95 if (!empty($format)) { /// Filename
97 if (!confirm_sesskey()) {
98 print_error( 'sesskey' );
101 if (! is_readable("format/$format/format.php")) {
102 error( "Format not known ($format)" ); }
104 // load parent class for import/export
105 require("format.php");
107 // and then the class for the selected format
108 require("format/$format/format.php");
110 $classname = "qformat_$format";
111 $qformat = new $classname();
113 $qformat->setCategory( $category );
114 $qformat->setCourse( $course );
115 $qformat->setFilename( $exportfilename );
116 $qformat->setCattofile( $cattofile );
118 if (! $qformat->exportpreprocess()) { // Do anything before that we need to
119 error( $txt->exporterror
, $thispageurl->out());
122 if (! $qformat->exportprocess()) { // Process the export data
123 error( $txt->exporterror
, $thispageurl->out());
126 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
127 error( $txt->exporterror
, $thispageurl->out());
131 // link to download the finished file
132 $file_ext = $qformat->export_file_extension();
133 if ($CFG->slasharguments
) {
134 $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
137 $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
139 echo "<p><div class=\"boxaligncenter\"><a href=\"$efile\">$txt->download</a></div></p>";
140 echo "<p><div class=\"boxaligncenter\"><font size=\"-1\">$txt->downloadextra</font></div></p>";
142 print_continue("edit.php?".$thispageurl->get_query_string());
143 print_footer($course);
147 /// Display upload form
149 // get valid formats to generate dropdown list
150 $fileformatnames = get_import_export_formats( 'export' );
153 if (empty($exportfilename)) {
154 $exportfilename = default_export_filename($course, $category);
157 print_heading_with_help($txt->exportquestions
, 'export', 'quiz');
158 print_simple_box_start('center');
161 <form enctype
="multipart/form-data" method
="post" action
="export.php">
162 <fieldset
class="invisiblefieldset" style
="display: block;">
163 <input type
="hidden" name
="sesskey" value
="<?php echo sesskey(); ?>" />
164 <?php
echo $thispageurl->hidden_params_out(array(), 3); ?
>
165 <table cellpadding
="5">
167 <td align
="right"><?php
echo $txt->category
; ?
>:</td
>
170 question_category_select_menu($course->id
, true, false, $category->id
);
171 echo $txt->tofile
; ?
>
172 <input name
="cattofile" type
="checkbox" />
173 <?php
helpbutton('exportcategory', $txt->exportcategory
, 'quiz'); ?
>
177 <td align
="right"><?php
echo $txt->fileformat
; ?
>:</td
>
179 <?php
choose_from_menu($fileformatnames, 'format', 'gift', '');
180 helpbutton('export', $txt->exportquestions
, 'quiz'); ?
>
184 <td align
="right"><?php
echo $txt->exportname
; ?
>:</td
>
186 <input type
="text" size
="40" name
="exportfilename" value
="<?php echo $exportfilename; ?>" />
191 <input type
="submit" name
="save" value
="<?php echo $txt->exportquestions; ?>" />
200 print_simple_box_end();
201 print_footer($course);