merging MOODLE_19_QUESTIONS with HEAD

This commit is contained in:
jamiesensei 2007-08-09 21:51:09 +00:00
parent 3bee1ead40
commit 271e6decda
47 changed files with 2807 additions and 1546 deletions

View file

@ -10,66 +10,44 @@
*/
require_once("../config.php");
require_once( "editlib.php" );
require_once("editlib.php");
require_once("export_form.php");
list($thispageurl, $courseid, $cmid, $cm, $module, $pagevars) = question_edit_setup();
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('export');
$cattofile = optional_param('cattofile',0, PARAM_BOOL);
$exportfilename = optional_param('exportfilename','',PARAM_FILE );
$format = optional_param('format','', PARAM_FILE );
$categoryid = optional_param('category',0,PARAM_INT);
// 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->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->tofile = get_string('tofile','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->tofile = get_string('tofile', 'quiz');
if (!$course = get_record("course", "id", $courseid)) {
error("Course does not exist!");
}
// make sure we are using the user's most recent category choice
if (empty($categoryid)) {
$categoryid = $pagevars['cat'];
}
if (!$category = get_record("question_categories", "id", $categoryid)) {
$category = get_default_question_category($courseid);
}
if (!$categorycourse = get_record("course", "id", $category->course)) {
print_error('nocategory','quiz');
}
// check role capability
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/question:export', $context);
// ensure the files area exists for this course
make_upload_directory( "$course->id" );
// check category is valid
$validcats = question_category_options( $course->id, true, false );
if (!array_key_exists( $categoryid, $validcats)) {
print_error( 'invalidcategory','quiz' );
make_upload_directory("$COURSE->id");
list($catid, $catcontext) = explode(',', $pagevars['cat']);
if (!$category = get_record("question_categories", "id", $catid, 'contextid', $catcontext)) {
print_error('nocategory','quiz');
}
/// Header
if ($cm!==null) {
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
? update_module_button($cm->id, $course->id, get_string('modulename', $cm->modname))
$strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest())
? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname))
: "";
$navlinks = array();
$navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$course->id", 'type' => 'activity');
@ -87,119 +65,80 @@
$navlinks = array();
$navlinks[] = array('name' => $txt->exportquestions, 'link' => '', 'type' => 'title');
$navigation = build_navigation($navlinks);
print_header_simple($txt->exportquestions, '', $navigation);
// print tabs
$currenttab = 'export';
include('tabs.php');
}
if (!empty($format)) { /// Filename
$exportfilename = default_export_filename($COURSE, $category);
$export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'],
'defaultfilename'=>$exportfilename));
if (!confirm_sesskey()) {
print_error( 'sesskey' );
if ($from_form = $export_form->get_data()) { /// Filename
if (! is_readable("format/$from_form->format/format.php")) {
error("Format not known ($from_form->format)");
}
if (! is_readable("format/$format/format.php")) {
error( "Format not known ($format)" ); }
// load parent class for import/export
require("format.php");
require_once("format.php");
// and then the class for the selected format
require("format/$format/format.php");
require_once("format/$from_form->format/format.php");
$classname = "qformat_$format";
$classname = "qformat_$from_form->format";
$qformat = new $classname();
$qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
$qformat->setCategory($category);
$qformat->setCourse($COURSE);
$qformat->setCategory( $category );
$qformat->setCourse( $course );
$qformat->setFilename( $exportfilename );
$qformat->setCattofile( $cattofile );
if (empty($from_form->exportfilename)) {
$from_form->exportfilename = default_export_filename($COURSE, $category);
}
$qformat->setFilename($from_form->exportfilename);
$qformat->setCattofile(!empty($from_form->cattofile));
$qformat->setContexttofile(!empty($from_form->contexttofile));
if (! $qformat->exportpreprocess()) { // Do anything before that we need to
error( $txt->exporterror, $thispageurl->out());
error($txt->exporterror, $thispageurl->out());
}
if (! $qformat->exportprocess()) { // Process the export data
error( $txt->exporterror, $thispageurl->out());
error($txt->exporterror, $thispageurl->out());
}
if (! $qformat->exportpostprocess()) { // In case anything needs to be done after
error( $txt->exporterror, $thispageurl->out());
error($txt->exporterror, $thispageurl->out());
}
echo "<hr />";
// link to download the finished file
$file_ext = $qformat->export_file_extension();
if ($CFG->slasharguments) {
$efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."?forcedownload=1";
$efile = "{$CFG->wwwroot}/file.php/".$qformat->question_get_export_dir()."/$from_form->exportfilename".$file_ext."?forcedownload=1";
}
else {
$efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$exportfilename".$file_ext."&forcedownload=1";
$efile = "{$CFG->wwwroot}/file.php?file=/".$qformat->question_get_export_dir()."/$from_form->exportfilename".$file_ext."&forcedownload=1";
}
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>";
print_continue("edit.php?".$thispageurl->get_query_string());
print_footer($course);
print_footer($COURSE);
exit;
}
/// Display upload form
/// Display export form
// get valid formats to generate dropdown list
$fileformatnames = get_import_export_formats( 'export' );
// get filename
if (empty($exportfilename)) {
$exportfilename = default_export_filename($course, $category);
}
print_heading_with_help($txt->exportquestions, 'export', 'quiz');
print_simple_box_start('center');
?>
<form enctype="multipart/form-data" method="post" action="export.php">
<fieldset class="invisiblefieldset" style="display: block;">
<input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />
<?php echo $thispageurl->hidden_params_out(array(), 3); ?>
<table cellpadding="5">
<tr>
<td align="right"><?php echo $txt->category; ?>:</td>
<td>
<?php
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>
<td align="center" >
<input type="submit" name="save" value="<?php echo $txt->exportquestions; ?>" />
</td>
<td>&nbsp;</td>
</tr>
</table>
</fieldset>
</form>
<?php
print_simple_box_end();
print_footer($course);
$export_form->display();
print_footer($COURSE);
?>