/** * Display the file resource * * Displays a file resource embedded, in a frame, or in a popup. * Output depends on type of file resource. * * @param CFG global object */ function display() { global $CFG, $THEME, $USER; require_once $CFG->libdir . '/filelib.php'; /// Set up generic stuff first, including checking for access parent::display(); /// Set up some shorthand variables $cm = $this->cm; $course = $this->course; $resource = $this->resource; /// Fetch parameters $inpopup = optional_param('inpopup', 0, PARAM_BOOL); $page = optional_param('page', 0, PARAM_INT); $frameset = optional_param('frameset', '', PARAM_ALPHA); /// Init some variables $errorcode = 0; $buttontext = 0; $querystring = ''; $resourcetype = ''; $mimetype = mimeinfo("type", $resource->reference); $pagetitle = strip_tags($course->shortname . ': ' . format_string($resource->name)); $formatoptions = new object(); $formatoptions->noclean = true; /// Cache this per request static $items; /// Check for errors $errorcode = $this->check4errors($resource->reference, $course, $resource); /// If there are any error, show it instead of the resource page if ($errorcode) { if (!has_capability('moodle/course:activityvisibility', get_context_instance(CONTEXT_COURSE, $course->id))) { /// Resource not available page $errortext = get_string('resourcenotavailable', 'resource'); } else { /// Depending of the error, show different messages and pages if ($errorcode == 1) { $errortext = get_string('invalidfiletype', 'error', $resource->reference); } else { if ($errorcode == 2) { $errortext = get_string('filenotfound', 'error', $resource->reference); } else { if ($errorcode == 3) { $errortext = get_string('packagenotdeplyed', 'resource'); } else { if ($errorcode == 4) { $errortext = get_string('packagechanged', 'resource'); } else { if ($errorcode == 5) { $errortext = get_string('packagenotdeplyed', 'resource'); // no button though since from repository. } } } } } } /// Display the error and exit if ($inpopup) { print_header($pagetitle, $course->fullname . ' : ' . $resource->name); } else { $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), user_login_string($course) . '<hr style="width:95%">' . navmenu($course, $cm)); } print_simple_box_start('center', '60%'); echo '<p align="center">' . $errortext . '</p>'; /// If errors were 3 or 4 and isteacheredit(), show the deploy button if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) && ($errorcode == 3 || $errorcode == 4)) { $link = 'type/ims/deploy.php'; $options['courseid'] = $course->id; $options['cmid'] = $cm->id; $options['file'] = $resource->reference; $options['sesskey'] = $USER->sesskey; $options['inpopup'] = $inpopup; if ($errorcode == 3) { $label = get_string('deploy', 'resource'); } else { if ($errorcode == 4) { $label = get_string('redeploy', 'resource'); } } $method = 'post'; /// Let's go with the button echo '<center>'; print_single_button($link, $options, $label, $method); echo '</center>'; } print_simple_box_end(); /// Close button if inpopup if ($inpopup) { close_window_button(); } print_footer(); exit; } /// Load serialized IMS CP index to memory only once. if (empty($items)) { if (!$this->isrepository) { $resourcedir = $CFG->dataroot . '/' . $course->id . '/' . $CFG->moddata . '/resource/' . $resource->id; } else { $resourcedir = $CFG->repository . $resource->reference; } if (!($items = ims_load_serialized_file($resourcedir . '/moodle_inx.ser'))) { error(get_string('errorreadingfile', 'error', 'moodle_inx.ser')); } } /// Check whether this is supposed to be a popup, but was called directly if (empty($frameset) && $resource->popup && !$inpopup) { /// Make a page and a pop-up window $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), user_login_string($course) . '<hr style="width:95%">' . navmenu($course, $cm)); echo "\n<script type=\"text/javascript\">"; echo "\n<!--\n"; echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n"; echo "\n-->\n"; echo '</script>'; if (trim(strip_tags($resource->summary))) { print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center"); } $link = "<a href=\"{$CFG->wwwroot}/mod/resource/view.php?inpopup=true&id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">" . format_string($resource->name, true) . "</a>"; echo "<p> </p>"; echo '<p align="center">'; print_string('popupresource', 'resource'); echo '<br />'; print_string('popupresourcelink', 'resource', $link); echo "</p>"; print_footer($course); exit; } /// No frames or framesets anymore, except iframe. in print_ims, iframe filled. /// needs callback to this file to display table of contents in the iframe so /// $frameset = 'toc' leads to output of toc and blank or 'ims' produces the /// iframe. if (empty($frameset) || $frameset == 'ims') { /// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-( global $jsarg; $jsarg = 'false'; if (!empty($this->parameters->navigationmenu)) { $jsarg = 'true'; } /// Define $CFG->javascript to use our custom javascript. Save the original one to add it from ours. Global too! :-( global $standard_javascript; $standard_javascript = $CFG->javascript; // Save original javascript file $CFG->javascript = $CFG->dirroot . '/mod/resource/type/ims/javascript.php'; //Use our custom IMS javascript code /// moodle header if ($resource->popup) { //print_header($pagetitle, $course->fullname.' : '.$resource->name); print_header(); } else { $navigation = build_navigation($this->navlinks, $cm); print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), user_login_string($course) . '<hr style="width:95%">' . navmenu($course, $cm, "parent")); } /// content - this produces everything else $this->print_ims($cm, $course, $items, $resource, $page); print_footer('empty'); /// log it. add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id); exit; } if ($frameset == 'toc') { print_header(); $this->print_toc($items, $resource, $page); echo '</div></div></body></html>'; exit; } }
$page = optional_param('page', 0, PARAM_INT); /// Calculate the path of the IMS CP to be displayed $deploydir = $CFG->repository . '/' . $directory; /// Confirm that the IMS package has been deployed. Hash not generated /// for repository ones. if (!file_exists($deploydir . '/moodle_inx.ser')) { $errortext = "Not Deployed"; print_header(); print_simple_box_start('center', '60%'); echo '<p align="center">' . $errortext . '</p>'; print_footer(); exit; } /// Load serialized IMS CP index to memory only once. if (empty($items)) { if (!($items = ims_load_serialized_file($deploydir . '/moodle_inx.ser'))) { error(get_string('errorreadingfile', 'error', 'moodle_inx.ser')); } } /// fast forward to first non-index page while (empty($items[$page]->href)) { $page++; } /// Select direction if (get_string('thisdirection') == 'rtl') { $direction = ' dir="rtl"'; } else { $direction = ' dir="ltr"'; } /// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-( global $jsarg;
/// Loops though dir building a list of all relevent entries. Ignores files. /// Asks for deploy if admin user AND no serialized file found. while (false !== ($filename = readdir($repository_dir))) { if ($filename != '.' && $filename != '..' && is_dir("{$CFG->repository}/{$directory}/{$filename}")) { unset($item); $item->type = ''; $item->name = 0; $item->path = "{$directory}/{$filename}"; /// No manifest => normal, browsable directory. if (!file_exists("{$CFG->repository}/{$item->path}/imsmanifest.xml")) { $item->type = 'directory'; $item->name = $filename; } else { if (file_exists("{$CFG->repository}/{$item->path}/moodle_inx.ser")) { $item->type = 'deployed'; $index = ims_load_serialized_file("{$CFG->repository}/{$item->path}/moodle_inx.ser"); $item->name = $index['title']; } else { $item->type = 'not deployed'; $item->name = $filename; } } $items[] = $item; } } closedir($repository_dir); /// Prints the toolbar. echo '<div id="ims_toolbar" style="padding:10px;">'; ims_print_crumbtrail($directory, $choose); /// If admin, add extra buttons - redeploy & help. if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {