Clean up strings
[moodle.git] / question / export.php
blob201a70b93e97011206f0d1fe2e5069c4106eb9d8
1 <?php // $Id$
2 /**
3 * Export quiz questions into the given category
5 * @version $Id$
6 * @author Martin Dougiamas, Howard Miller, and many others.
7 * {@link http://moodle.org}
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package quiz
12 require_once("../config.php");
13 require_once( "editlib.php" );
15 $categoryid = optional_param('category',0, PARAM_INT);
16 $courseid = required_param('courseid',PARAM_INT);
17 $format = optional_param('format','', PARAM_FILE );
18 $exportfilename = optional_param('exportfilename','',PARAM_FILE );
20 if (! $course = get_record("course", "id", $courseid)) {
21 error("Course does not exist!");
24 $showcatmenu = false;
25 if ($categoryid) { // update category in session variable
26 $SESSION->questioncat = $categoryid;
27 } else { // try to get category from modform
28 $showcatmenu = true; // will ensure that user can choose category
29 if (isset($SESSION->questioncat)) {
30 $categoryid = $SESSION->questioncat;
34 if (! $category = get_record("question_categories", "id", $categoryid)) {
35 $category = get_default_question_category($courseid);
38 if (! $categorycourse = get_record("course", "id", $category->course)) {
39 error( get_string('nocategory','quiz') );
42 require_login($course->id, false);
44 $context = get_context_instance(CONTEXT_COURSE, $course->id);
45 require_capability('moodle/question:export', $context);
47 // ensure the files area exists for this course
48 make_upload_directory( "$course->id" );
50 $strexportquestions = get_string("exportquestions", "quiz");
51 $strquestions = get_string("questions", "quiz");
53 $strquizzes = get_string('modulenameplural', 'quiz');
54 $streditingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz");
56 $dirname = get_string("exportfilename","quiz");
58 /// Header:
60 if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
61 $strupdatemodule = has_capability('moodle/course:manageactivities', $context)
62 ? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
63 : "";
64 print_header_simple($strexportquestions, '',
65 "<a href=\"$CFG->wwwroot/mod/quiz/index.php?id=$course->id\">".get_string('modulenameplural', 'quiz').'</a>'.
66 " -> <a href=\"$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id\">".format_string($quiz->name).'</a>'.
67 ' -> '.$strexportquestions,
68 "", "", true, $strupdatemodule);
69 $currenttab = 'edit';
70 $mode = 'export';
71 include($CFG->dirroot.'/mod/quiz/tabs.php');
72 } else {
73 print_header_simple($strexportquestions, '', $strexportquestions);
74 // print tabs
75 $currenttab = 'export';
76 include('tabs.php');
79 if (!empty($format)) { /// Filename
81 if (!confirm_sesskey()) {
82 echo( 'Sesskey error' );
85 if (! is_readable("format/$format/format.php")) {
86 error('Format not known ('.clean_text($form->format).')');
89 require("format.php"); // Parent class
90 require("format/$format/format.php");
92 $classname = "qformat_$format";
93 $qformat = new $classname();
95 if (! $qformat->exportpreprocess($category, $course)) { // Do anything before that we need to
96 error( get_string('exporterror','quiz'),
97 "$CFG->wwwroot/question/export.php?courseid={$course->id}&amp;category=$category->id");
100 if (! $qformat->exportprocess($exportfilename)) { // Process the export data
101 error( get_string('exporterror','quiz'),
102 "$CFG->wwwroot/question/export.php?courseid={$course->id}&amp;category=$category->id");
105 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
106 error( get_string('exporterror','quiz'),
107 "$CFG->wwwroot/question/export.php?courseid={$course->id}&amp;category=$category->id");
109 echo "<hr />";
111 // link to download the finished file
112 $file_ext = $qformat->export_file_extension();
113 $download_str = get_string( 'download', 'quiz' );
114 $downloadextra_str = get_string( 'downloadextra','quiz' );
115 if ($CFG->slasharguments) {
116 $efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
118 else {
119 $efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
121 echo "</p><center><a href=\"$efile\">$download_str</a></center></p>";
122 echo "</p><center><font size=\"-1\">$downloadextra_str</font></center></p>";
124 print_continue("edit.php?courseid=$course->id");
125 print_footer($course);
126 exit;
129 /// Print upload form
131 // get valid formats to generate dropdown list
132 $fileformatnames = get_import_export_formats( "export" );
134 // get filename
135 if (empty($exportfilename)) {
136 $exportfilename = default_export_filename($course, $category);
139 print_heading_with_help($strexportquestions, "export", "quiz");
141 print_simple_box_start("center");
142 echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"export.php\">\n";
143 echo "<input type=\"hidden\" name=\"sesskey\" value=\"" . sesskey() . "\" />\n";
144 echo "<table cellpadding=\"5\">\n";
146 echo "<tr><td align=\"right\">\n";
147 print_string("category", "quiz");
148 echo ":</td><td>";
149 if (!$showcatmenu) { // category already specified
150 echo question_category_coursename($category);
151 echo " <input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
152 } else { // no category specified, let user choose
153 question_category_select_menu($course->id, true, false, $category->id);
155 //echo str_replace('&nbsp;', '', $category->name) . " ($categorycourse->shortname)";
156 echo "</td></tr>\n";
158 echo "<tr><td align=\"right\">";
159 print_string("fileformat", "quiz");
160 echo ":</td><td>";
161 choose_from_menu($fileformatnames, "format", "gift", "");
162 helpbutton("export", $strexportquestions, "quiz");
163 echo "</td></tr>\n";
165 echo "<tr><td align=\"right\">";
166 print_string("exportname", "quiz" );
167 echo ":</td><td>";
168 echo "<input type=\"text\" size=\"40\" name=\"exportfilename\" value=\"$exportfilename\" />";
169 echo "</td></tr>\n";
171 echo "<tr><td align=\"center\" colspan=\"2\">";
172 echo " <input type=\"hidden\" name=\"courseid\" value=\"$course->id\" />";
173 echo " <input type=\"submit\" name=\"save\" value=\"".get_string("exportquestions","quiz")."\" />";
174 echo "</td></tr>\n";
176 echo "</table>\n";
177 echo "</form>\n";
178 print_simple_box_end();
180 print_footer($course);