| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: export.php,v 1.43.2.4 2008/09/15 14:21:02 thepurpleblob Exp $ 2 /** 3 * Export quiz questions into the given category 4 * 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 10 */ 11 12 require_once("../config.php"); 13 require_once ("editlib.php"); 14 require_once ("export_form.php"); 15 16 list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars) = question_edit_setup('export'); 17 18 19 // get display strings 20 $strexportquestions = get_string('exportquestions', 'quiz'); 21 22 // make sure we are using the user's most recent category choice 23 if (empty($categoryid)) { 24 $categoryid = $pagevars['cat']; 25 } 26 27 // ensure the files area exists for this course 28 make_upload_directory("$COURSE->id"); 29 list($catid, $catcontext) = explode(',', $pagevars['cat']); 30 if (!$category = get_record("question_categories", "id", $catid, 'contextid', $catcontext)) { 31 print_error('nocategory','quiz'); 32 } 33 34 /// Header 35 if ($cm!==null) { 36 $strupdatemodule = has_capability('moodle/course:manageactivities', $contexts->lowest()) 37 ? update_module_button($cm->id, $COURSE->id, get_string('modulename', $cm->modname)) 38 : ""; 39 $navlinks = array(); 40 $navlinks[] = array('name' => get_string('modulenameplural', $cm->modname), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/index.php?id=$COURSE->id", 'type' => 'activity'); 41 $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); 42 $navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title'); 43 $navigation = build_navigation($navlinks); 44 print_header_simple($strexportquestions, '', $navigation, "", "", true, $strupdatemodule); 45 46 $currenttab = 'edit'; 47 $mode = 'export'; 48 ${$cm->modname} = $module; 49 include($CFG->dirroot."/mod/$cm->modname/tabs.php"); 50 } else { 51 // Print basic page layout. 52 $navlinks = array(); 53 $navlinks[] = array('name' => $strexportquestions, 'link' => '', 'type' => 'title'); 54 $navigation = build_navigation($navlinks); 55 56 print_header_simple($strexportquestions, '', $navigation); 57 // print tabs 58 $currenttab = 'export'; 59 include ('tabs.php'); 60 } 61 62 $exportfilename = default_export_filename($COURSE, $category); 63 $export_form = new question_export_form($thispageurl, array('contexts'=>$contexts->having_one_edit_tab_cap('export'), 'defaultcategory'=>$pagevars['cat'], 64 'defaultfilename'=>$exportfilename)); 65 66 67 if ($from_form = $export_form->get_data()) { /// Filename 68 69 70 if (! is_readable("format/$from_form->format/format.php")) { 71 error("Format not known ($from_form->format)"); 72 } 73 74 // load parent class for import/export 75 require_once ("format.php"); 76 77 // and then the class for the selected format 78 require_once("format/$from_form->format/format.php"); 79 80 $classname = "qformat_$from_form->format"; 81 $qformat = new $classname(); 82 $qformat->setContexts($contexts->having_one_edit_tab_cap('export')); 83 $qformat->setCategory($category); 84 $qformat->setCourse($COURSE); 85 86 if (empty($from_form->exportfilename)) { 87 $from_form->exportfilename = default_export_filename($COURSE, $category); 88 } 89 $qformat->setFilename($from_form->exportfilename); 90 $canaccessbackupdata = has_capability('moodle/site:backup', $contexts->lowest()); 91 $qformat->set_can_access_backupdata($canaccessbackupdata); 92 $qformat->setCattofile(!empty($from_form->cattofile)); 93 $qformat->setContexttofile(!empty($from_form->contexttofile)); 94 95 if (! $qformat->exportpreprocess()) { // Do anything before that we need to 96 print_error('exporterror', 'quiz', $thispageurl->out()); 97 } 98 99 if (! $qformat->exportprocess()) { // Process the export data 100 print_error('exporterror', 'quiz', $thispageurl->out()); 101 } 102 103 if (! $qformat->exportpostprocess()) { // In case anything needs to be done after 104 print_error('exporterror', 'quiz', $thispageurl->out()); 105 } 106 echo "<hr />"; 107 108 // link to download the finished file 109 $file_ext = $qformat->export_file_extension(); 110 $filename = $from_form->exportfilename . $file_ext; 111 if ($canaccessbackupdata) { 112 $efile = get_file_url($qformat->question_get_export_dir() . '/' . $filename, 113 array('forcedownload' => 1)); 114 echo '<p><div class="boxaligncenter"><a href="' . $efile . '">' . 115 get_string('download', 'quiz') . '</a></div></p>'; 116 echo '<p><div class="boxaligncenter"><font size="-1">' . 117 get_string('downloadextra', 'quiz') . '</font></div></p>'; 118 } else { 119 $efile = get_file_url($filename, null, 'questionfile'); 120 echo '<p><div class="boxaligncenter">' . 121 get_string('yourfileshoulddownload', 'question', $efile) . '</a></div></p>'; 122 echo ' 123 <script type="text/javascript"> 124 //<![CDATA[ 125 126 function redirect() { 127 document.location.replace("' . addslashes_js($efile) . '"); 128 } 129 setTimeout("redirect()", 1000); 130 //]]> 131 </script>'; 132 } 133 134 print_continue('edit.php?' . $thispageurl->get_query_string()); 135 print_footer($COURSE); 136 exit; 137 } 138 139 /// Display export form 140 print_heading_with_help($strexportquestions, 'export', 'quiz'); 141 142 $export_form->display(); 143 144 print_footer($COURSE); 145 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |