function get_content() { global $USER, $CFG; // TODO: FIX: HACK: (any other tags I should add? :P) // Hacker's improvised caching scheme: avoid fetching the mod // data from db if the course format has already fetched them if (!isset($GLOBALS['modnamesplural']) || !isset($GLOBALS['modnamesused'])) { require_once $CFG->dirroot . '/course/lib.php'; if (!empty($this->instance)) { get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused); } } else { $modnamesplural = $GLOBALS['modnamesplural']; $modnamesused = $GLOBALS['modnamesused']; } if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if (isset($modnamesused) && $modnamesused) { foreach ($modnamesused as $modname => $modfullname) { if ($modname != 'label') { $this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/' . $modname . '/index.php?id=' . $this->instance->pageid . '">' . $modnamesplural[$modname] . '</a>'; $this->content->icons[] = '<img src="' . $CFG->modpixpath . '/' . $modname . '/icon.gif" class="icon" alt="" />'; } } } return $this->content; }
function definition() { global $DB, $USER, $CFG; $mform = & $this->_form; $mform->addElement('header', 'crformheader', get_string('usermodactions', 'block_cobalt_reports'), ''); $columns = $DB->get_columns('user'); $modules = array(); // Fix for http://tracker.moodle.org/browse/CONTRIB-2945 require_once($CFG->dirroot . "/course/lib.php"); get_all_mods($this->_customdata['report']->courseid, $mods, $modnames, $modnamesplural, $modnamesused); if ($mods) { foreach ($mods as $m) { $instance = $DB->get_record("$m->modname", array("id" => "$m->instance")); $modules[$m->id] = $instance->name; } } $mform->addElement('select', 'cmid', get_string('module', 'block_cobalt_reports'), $modules); $this->_customdata['compclass']->add_form_elements($mform, $this); // buttons $this->add_action_buttons(true, get_string('add')); }
public function edit_form_add(&$mform) { global $COURSE, $CFG; require_once $CFG->dirroot . '/course/lib.php'; get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesusesd); $modinfo = unserialize((string) $COURSE->modinfo); $modules = array(); foreach ($mods as $mod) { $instancename = urldecode($modinfo[$mod->id]->name); $instancename = format_string($instancename, true, $COURSE->id); $modules[$mod->id] = shorten_text($mod->modfullname . ': ' . $instancename, 28); } natcasesort($modules); // Add our choose option to the front $options = array(0 => get_string('choose', 'pagemenu')) + $modules; $mform->addElement('select', 'moduleid', get_string('addmodule', 'pagemenu'), $options); $mform->setType('moduleid', PARAM_INT); }
function definition() { global $USER, $CFG, $db; $mform =& $this->_form; $mform->addElement('header', '', get_string('usermodactions', 'block_configurable_reports'), ''); $columns = $db->MetaColumns($CFG->prefix . 'user'); $modules = array(); get_all_mods($this->_customdata['report']->courseid, $mods, $modnames, $modnamesplural, $modnamesused); if ($mods) { foreach ($mods as $m) { $instance = get_record("{$m->modname}", "id", "{$m->instance}"); $modules[$m->id] = $instance->name; } } $mform->addElement('select', 'cmid', get_string('module', 'block_configurable_reports'), $modules); $this->_customdata['compclass']->add_form_elements($mform, $this); // buttons $this->add_action_buttons(true, get_string('add')); }
function cms_render($pagedata, $course) { global $sections, $USER; // Insert dynamic content // content marked as private should be shown with a special style to people with editing rights // and should not be shown to others $context = get_context_instance(CONTEXT_COURSE, $course->id); $canedit = has_capability('format/cms:editpage', $context, $USER->id); $private = $canedit ? '<div class="private">$1</div>' : ''; $search = array("#\\[\\[INCLUDE (.+?)\\]\\]#ie", "#\\[\\[SCRIPT (.+?)\\]\\]#ie", "#\\[\\[PAGE (.+?)\\]\\]#ie", "#\\[\\[NEWS\\]\\]#ie", "#\\[\\[PRIVATE (.+?)\\]\\]#is", "#\\[\\[TOC\\]\\]#ie", "#\\[\\[([^\\[\\]]+?)\\s*\\|\\s*(.+?)\\]\\]#es", "#\\._\\.#ie"); $replace = array('cms_safe_include("$1", true)', 'cms_safe_include("$1", false)', 'cms_include_page("$1", $course)', 'cms_render_news($course)', $private, 'cms_print_toc($pagedata->id)', 'cms_render_link("$1" ,"$2")', ''); $body = preg_replace($search, $replace, $pagedata->body); // Search sections. preg_match_all("/{#section([0-9]+)}/i", $body, $match); $cmssections = $match[1]; // At this point allow only course level not site level. if (!empty($cmssections)) { foreach ($cmssections as $cmssection) { if (!empty($sections[$cmssection])) { $thissection = $sections[$cmssection]; } else { unset($thissection); // make sure that the section doesn't exist. if (!record_exists('course_sections', 'section', $cmssection, 'course', $course->id)) { $thissection->course = $course->id; // Create a new section structure $thissection->section = $cmssection; $thissection->summary = ''; $thissection->visible = 1; if (!($thissection->id = insert_record('course_sections', $thissection))) { notify('Error inserting new topic!'); } } else { $thissection = get_record('course_sections', 'course', $course->id, 'section', $cmssection); } } if (!empty($thissection)) { if (empty($mods)) { get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); } $showsection = ($canedit or $thissection->visible or !$course->hiddensections); if ($showsection) { $content = '<div id="cms-section-' . $cmssection . '">'; $content .= cms_get_section($course, $thissection, $mods, $modnamesused); if (isediting($course->id)) { $content .= cms_section_add_menus($course, $cmssection, $modnames, false); } $content .= '</div>'; $body = preg_replace("/{#section{$cmssection}}/", $content, $body); } } else { $body = preg_replace("/{#section{$cmssection}}/", "", $body); } } } $options = new stdClass(); $options->noclean = true; return format_text(stripslashes($body), FORMAT_HTML, $options); }
function sections($config) { global $COURSE, $CFG, $USER, $THEME; // probably inefficient, but it works get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused); // sections $sections = get_all_sections($COURSE->id); // name for sections $sectionname = get_string("name{$COURSE->format}", "format_{$COURSE->format}"); // TODO: this fallback should be unnecessary if ($sectionname == "[[name{$COURSE->format}]]") { $sectionname = get_string("name{$COURSE->format}"); } $return = array(); // check what the course format is like // highlight for current week or highlighted topic if (in_array($COURSE->format, array('weeks', 'weekscss'))) { $format = 'week'; $highlight = ceil((time() - $COURSE->startdate) / 604800); } else { $format = 'topic'; $highlight = $COURSE->marker; } $modinfo = unserialize($COURSE->modinfo); // I think $display is the section currently being displayed // Why are we calling course_set_display? // For Moodle 2.0 we should just use $PAGE and check type // and also $PAGE->activityrecord $path = str_replace($CFG->httpswwwroot . '/', '', $CFG->pagepath); if (substr($path, 0, 7) == 'course/') { //TODO: this code is hackish, we shouldn't use course_set_display # get current section being displayed $week = optional_param('week', -1, PARAM_INT); if ($week != -1) { // the course format should already be doing this $display = course_set_display($COURSE->id, $week); } else { if (isset($USER->display[$COURSE->id])) { $display = $USER->display[$COURSE->id]; } else { $display = course_set_display($COURSE->id, 0); } } } elseif (substr($path, 0, 4) == 'mod/') { // Moodle 2: use $PAGE->activityrecord->section; $id = optional_param('id', -1, PARAM_INT); if ($id == -1) { $display = 0; } else { $sql = "select section from {$CFG->prefix}course_sections where id=(select section from {$CFG->prefix}course_modules where id={$id})"; $row = get_record_sql($sql); $display = $row->section; } } else { $display = 0; } foreach ($sections as $section) { // don't show the flowing sections if (!($section->visible && $section->section && $section->section <= $COURSE->numsections)) { continue; } $text = trim($section->summary); if (empty($text)) { $text = ucwords($sectionname) . " " . $section->section; } else { $text = $this->truncate_html(filter_text($text, $COURSE->id), $config); } // expand section if it's the one currently displayed $expand = false; if ($section->section == $display) { $expand = true; } $sectionstyle = 'yui_menu_icon_section'; // highlight marked section if ($section->section == $highlight) { $sectionstyle .= ' highlight'; } $iconpath = $CFG->wwwroot; if ($THEME->custompix) { $iconpath .= "/theme/" . current_theme() . "/pix"; } else { $iconpath .= '/pix'; //$iconpath .= '/'; } $iconpath = $CFG->wwwroot . "/theme/" . current_theme() . "/pix"; // decide what URL we want to use // A lot of this should really be done by the course format // // = intoaction config values = // * 'introhide' link to the section page (this effectively // hides the other sections // * 'introscroll' link to the fragment id of the section on // on the current page // whether or not any of the sections are hidden $hidden = false; foreach (array('topic', 'week') as $param) { if (isset($_GET[$param]) && $_GET[$param] != 'all') { $hidden = true; } } $introaction = isset($config->introaction) ? $config->introaction : 'introhide'; if ($introaction == 'introhide' || $hidden) { // link to the section, this will effectively hide all // the other sections $url = "{$CFG->wwwroot}/course/view.php?id={$COURSE->id}" . "&{$format}={$section->section}"; } else { // this pretty much just a hack // use $PAGE in Moodle 2 for great justice if (strpos($_SERVER['REQUEST_URI'], 'course/view.php') != 0) { $url = "#section-{$section->section}"; } else { $url = false; } } if ($url === false) { $item = new yui_menu_item($this, $text, ''); //$iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav) } else { $item = new yui_menu_item_link($this, $text, $url, ''); // $iconpath . '/i/one.gif'); // redundant icons, lets save space (nadavkav) } $item->expand = $expand; if (isset($section->sequence)) { $sectionmods = explode(",", $section->sequence); } else { $sectionmods = array(); } foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; // don't do anything invisible or labels if (!$mod->visible || $mod->modname == 'label') { continue; } // figure out the text and url $text = urldecode($modinfo[$modnumber]->name); if (!empty($CFG->filterall)) { $text = filter_text($text, $COURSE->id); } if (trim($text) == '') { $text = $mod->modfullname; } $text = $this->truncate_html($text, $config); $url = "{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}"; $name = "yui_menu_mod_{$mod->modname}_{$modnumber}"; // figure out if it is the current page $pageurl = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $pageurl = '~https?://' . preg_quote($pageurl, '~') . '~'; if (preg_match($pageurl, $CFG->wwwroot . $url)) { $style = "yui_menu_mod_{$mod->modname} highlight"; } else { $style = "yui_menu_mod_{$mod->modname}"; } $icon = "{$iconpath}/mod/{$mod->modname}/icon.gif"; if ($mod->modname == 'resource') { $info = resource_get_coursemodule_info($mod); if (isset($info) && isset($info->icon)) { $icon = "{$CFG->pixpath}/{$info->icon}"; } } $child = new yui_menu_item_link($this, $text, $url, $icon); $child->style = $style; $item->children[$modnumber] = $child; } $return[] = $item; } return $return; }
/** * Retrieve all dynamic files * * @return string[] The array of dynamic files */ function offline_get_dynamic_files() { global $CFG, $COURSE, $USER, $DB; require_once $CFG->dirroot . '/course/lib.php'; // Include homepage and accessible course pages $files = array('.', $CFG->wwwroot . '/', $CFG->wwwroot . '/index.php', $CFG->wwwroot . '/lib/offline/go_offline.js', $CFG->wwwroot . '/user/editadvanced.php?id=' . $USER->id); // get all accessible courses if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) { $courses = get_my_courses($USER->id, 'visible DESC,sortorder ASC', array('summary')); } else { if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or $DB->count_records('course') <= FRONTPAGECOURSELIMIT) { $categories = get_child_categories(0); if (is_array($categories) && count($categories) == 1) { $category = array_shift($categories); $courses = get_courses_wmanagers($category->id, 'c.sortorder ASC', array('password', 'summary', 'currency')); } else { $courses = get_courses_wmanagers('all', 'c.sortorder ASC', array('password', 'summary', 'currency')); } unset($categories); } } // make sure the course is visible and retrieve other modules and main course pages foreach ($courses as $course) { if ($course->visible == 1 || has_capability('moodle/course:viewhiddencourses', $course->context)) { $files[] = $CFG->wwwroot . '/course/view.php?id=' . $course->id; //Get all the module main pages foreach (get_list_of_plugins() as $module) { if ($module != 'label') { $files[] = $CFG->wwwroot . '/mod/' . $module . '/index.php?id=' . $course->id; } } //Get all the relevant forums require_once $CFG->dirroot . '/mod/forum/lib.php'; $forums = forum_get_readable_forums($USER->id, $course->id); foreach ($forums as $forum) { $files[] = $CFG->wwwroot . '/mod/forum/view.php?f=' . $forum->id; } $modinfo =& get_fast_modinfo($course); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); foreach ($mods as $mod) { if ($mod->modname == 'forum') { $files[] = $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id; $cm = get_coursemodule_from_id('forum', $mod->id); $discussions = forum_get_discussions($cm); foreach ($discussions as $d) { $files[] = $CFG->wwwroot . '/mod/forum/discuss.php?d=' . $d->discussion; } } } //Get all the relevant assignments foreach ($modinfo->instances['assignment'] as $cm) { if (!$cm->uservisible) { continue; } $files[] = $CFG->wwwroot . '/mod/assignment/view.php?id=' . $cm->id; } } } $files = str_replace('&', '&', $files); return $files; }
/** * Generate the list of modules for the given course. * * @param stdClass $course The course to get modules for */ protected function get_course_modules($course) { global $CFG; $mods = $modnames = $modnamesplural = $modnamesused = array(); // This function is included when we include course/lib.php at the top // of this file get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); $resources = array(); $activities = array(); foreach ($modnames as $modname => $modnamestr) { if (!course_allowed_module($course, $modname)) { continue; } $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (!file_exists($libfile)) { continue; } include_once $libfile; $gettypesfunc = $modname . '_get_types'; if (function_exists($gettypesfunc)) { $types = $gettypesfunc(); foreach ($types as $type) { if (!isset($type->modclass) || !isset($type->typestr)) { debugging('Incorrect activity type in ' . $modname); continue; } if ($type->modclass == MOD_CLASS_RESOURCE) { $resources[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr; } else { $activities[html_entity_decode($type->type, ENT_QUOTES, 'UTF-8')] = $type->typestr; } } } else { $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); if ($archetype == MOD_ARCHETYPE_RESOURCE) { $resources[$modname] = $modnamestr; } else { // all other archetypes are considered activity $activities[$modname] = $modnamestr; } } } return array($resources, $activities); }
/** * Get all the modules * * @return array */ function certificate_get_mods() { global $COURSE, $CFG, $DB; $strtopic = get_string("topic"); $strweek = get_string("week"); $strsection = get_string("section"); // Collect modules data get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused); $modules = array(); $sections = get_all_sections($COURSE->id); // Sort everything the same as the course for ($i = 0; $i <= $COURSE->numsections; $i++) { // should always be true if (isset($sections[$i])) { $section = $sections[$i]; if ($section->sequence) { switch ($COURSE->format) { case "topics": $sectionlabel = $strtopic; break; case "weeks": $sectionlabel = $strweek; break; default: $sectionlabel = $strsection; } $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $sectionmod) { if (empty($mods[$sectionmod])) { continue; } $mod = $mods[$sectionmod]; $mod->courseid = $COURSE->id; $instance = $DB->get_record($mod->modname, array('id' => $mod->instance)); if ($grade_items = grade_get_grade_items_for_activity($mod)) { $mod_item = grade_get_grades($COURSE->id, 'mod', $mod->modname, $mod->instance); $item = reset($mod_item->items); if (isset($item->grademax)) { $modules[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name; } } } } } } return $modules; }
/** * Render contents of main part of subpage * @param mod_subpage $subpage * @param course_modinfo $modinfo * @param array $sections * @param boolean $editing whether the user is allowed to edit this page * @param int $moveitem (currently not used) * @param boolean $movesection whether the user is allowed to move sections * @return string html for display */ public function render_subpage($subpage, $modinfo, $sections, $editing, $moveitem, $movesection) { global $PAGE, $OUTPUT, $CFG, $USER; $this->subpagecm = $subpage->get_course_module()->id; if (!empty($USER->activitycopy) && $movesection) { $content = $this->render_cancel_link($this->subpagecm); } else { $content = ''; } $content .= $this->render_intro($subpage); $streditsummary = get_string('editsummary'); $strdelete = get_string('delete'); if ($editing) { $strmoveup = get_string('moveup'); $strmovedown = get_string('movedown'); $strhide = get_string('hide'); $strshow = get_string('show'); $strstealth = get_string('stealth', 'subpage'); $strunstealth = get_string('unstealth', 'subpage'); } $coursecontext = get_context_instance(CONTEXT_COURSE, $subpage->get_course()->id); get_all_mods($subpage->get_course()->id, $mods, $modnames, $modnamesplural, $modnamesused); foreach ($mods as $modid => $unused) { if (!isset($modinfo->cms[$modid])) { rebuild_course_cache($subpage->get_course()->id); $modinfo =& get_fast_modinfo($subpage->get_course()); debugging('Rebuilding course cache', DEBUG_DEVELOPER); break; } } $lastpageorder = $subpage->get_last_section_pageorder(); if ($subpage->get_course()->format == 'weeks') { $content .= html_writer::start_tag('ul', array('class' => 'weeks')); } else { $content .= html_writer::start_tag('ul', array('class' => 'topics')); } foreach ($sections as $section) { // Check to see whether cms within the section are visible or not // If all cms are not visible then we don't show the section at all, // unless editing $visible = false; if ($section->sequence) { // get cm_info for this resources $instances = explode(',', $section->sequence); } else { $instances = array(); } foreach ($instances as $instance) { $cm = $modinfo->get_cm($instance); // check to see whether cm is visible if ($cm->uservisible) { $visible = true; break; } } // If section is empty so should be hidden, record that in object $section->autohide = !$visible; $content .= html_writer::start_tag('li', array('class' => 'section main clearfix', 'id' => 'section-' . $section->section)); $content .= html_writer::tag('div', ' ', array('class' => 'left side')); $content .= html_writer::start_tag('div', array('class' => 'right side')); if ($editing && has_capability('moodle/course:update', $coursecontext)) { // Show the hide/show eye if ($section->visible) { $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&hide=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strhide)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/hide'), 'class' => 'icon hide', 'alt' => $strhide)); $content .= html_writer::end_tag('a'); } else { $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&show=' . $section->section . '&sesskey=' . sesskey() . '#section-' . $section->id, 'title' => $strshow)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/show'), 'class' => 'icon show', 'alt' => $strshow)); $content .= html_writer::end_tag('a'); } // Show the stealth/unstealth section link if ($section->stealth) { $content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php')); $content .= html_writer::start_tag('div'); $content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'unstealth', 'value' => $section->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('unstealth', 'mod_subpage'), 'type' => 'image', 'title' => $strunstealth, 'alt' => $strunstealth)); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('form'); } else { $content .= html_writer::start_tag('form', array('method' => 'post', 'action' => 'stealth.php')); $content .= html_writer::start_tag('div'); $content .= html_writer::empty_tag('input', array('name' => 'id', 'value' => $subpage->get_course_module()->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'sesskey', 'value' => sesskey(), 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'stealth', 'value' => $section->id, 'type' => 'hidden')); $content .= html_writer::empty_tag('input', array('name' => 'icon', 'src' => $OUTPUT->pix_url('stealth', 'mod_subpage'), 'type' => 'image', 'title' => $strstealth, 'alt' => $strstealth)); $content .= html_writer::end_tag('div'); $content .= html_writer::end_tag('form'); } $content .= html_writer::empty_tag('br', array()); if ($movesection) { $content .= html_writer::start_tag('span', array('class' => 'section_move_commands')); if ($section->pageorder > 1) { // Add a arrow to move section up $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&random=' . rand(1, 10000) . '§ion=' . $section->id . '&move=-1&sesskey=' . sesskey() . '#section-' . ($section->id - 1), 'title' => $strmoveup)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/up'), 'class' => 'icon up', 'alt' => $strmoveup)); $content .= html_writer::end_tag('a'); $content .= html_writer::empty_tag('br', array()); } if ($section->pageorder < $lastpageorder) { // Add an arrow to move section down $content .= html_writer::start_tag('a', array('href' => 'view.php?id=' . $subpage->get_course_module()->id . '&random=' . rand(1, 10000) . '§ion=' . $section->id . '&move=1&sesskey=' . sesskey() . '#section-' . ($section->id + 1), 'title' => $strmovedown)); $content .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/down'), 'class' => 'icon down', 'alt' => $strmovedown)); $content .= html_writer::end_tag('a'); $content .= html_writer::empty_tag('br', array()); } $content .= html_writer::end_tag('span'); } } $content .= html_writer::end_tag('div'); $content .= html_writer::start_tag('div', array('class' => 'content')); // Only show the section if visible and not stealthed or to users with permission if (($section->visible && !$section->stealth || has_capability('moodle/course:viewhiddensections', $coursecontext)) && ($editing || !$section->autohide)) { if ($section->stealth) { $content .= html_writer::start_tag('div', array('class' => 'stealthed')); } if (!empty($section->name)) { $content .= html_writer::tag('h3', format_string($section->name), array('class' => 'sectionname')); } $summary = ''; if ($section->summary) { $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $section->id); $summaryformatoptions = new stdClass(); $summaryformatoptions->noclean = true; $summaryformatoptions->overflowdiv = true; $summary .= format_text($summarytext, $section->summaryformat, $summaryformatoptions); } if ($editing && has_capability('moodle/course:update', $coursecontext)) { $summary .= html_writer::start_tag('a', array('href' => $CFG->wwwroot . '/course/editsection.php?id=' . $section->id . '&returnurl=' . urlencode($CFG->wwwroot . '/mod/subpage/view.php?id=' . $subpage->get_course_module()->id . '&recache=1&sesskey=' . sesskey()), 'title' => $streditsummary)); $summary .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'class' => 'icon edit', 'alt' => $streditsummary)); $summary .= html_writer::end_tag('a'); $summary .= html_writer::empty_tag('br', array()); $summary .= html_writer::start_tag('a', array('href' => $CFG->wwwroot . '/mod/subpage/view.php?id=' . $subpage->get_course_module()->id . '&delete=' . $section->id . '&sesskey=' . sesskey(), 'title' => $strdelete)); if (empty($section->sequence)) { $summary .= html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'class' => 'icon delete', 'alt' => $strdelete)); } $summary .= html_writer::end_tag('a'); $summary .= html_writer::empty_tag('br', array()); $summary .= html_writer::empty_tag('br', array()); } if ($summary !== '') { $content .= html_writer::tag('div', $summary, array('class' => 'summary')); } $content .= $this->render_section($subpage, $modinfo, $section, $editing, $moveitem, $mods, $modnamesused); if ($editing) { $content .= print_section_add_menus($subpage->get_course(), $section->section, $modnames, false, true); if (!empty($CFG->enablecourseajax) and $PAGE->theme->enablecourseajax) { // hacky way to add list to empty section to allow drag/drop into // empty sections $content = str_replace('</div><div class="section_add_menus">', '</div><ul class="section img-text"><li></li></ul>' . '<div class="section_add_menus">', $content); } } //now add returnto links to editing links: $pattern = '/mod.php\\?[A-Za-z0-9-&;=%:\\/\\-.]+/'; $content = preg_replace_callback($pattern, 'mod_subpage_renderer::subpage_url_regex', $content); if ($section->stealth) { $content .= html_writer::end_tag('div'); } } $content .= html_writer::end_tag('div'); //end of div class=content $content .= html_writer::end_tag('li'); } $content .= html_writer::end_tag('ul'); if ($editing) { $content .= $this->render_add_button($subpage); $content .= $this->render_bulkmove_buttons($subpage); } return $content; }
/** * Simply prints all grade of one student from all modules from a given course * used in the grade book for student view, and grade button under user profile * @param int $userid; * @param int $courseid; */ function print_student_grade($user, $course) { global $CFG; if (!empty($user)) { $grades[$user->id] = array(); // Collect all grades in this array $gradeshtml[$user->id] = array(); // Collect all grades html formatted in this array $totals[$user->id] = array(); // Collect all totals in this array } $strmax = get_string("maximumshort"); /// Collect modules data get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); /// Search through all the modules, pulling out grade data $sections = get_all_sections($course->id); // Sort everything the same as the course // prints table // flag for detecting whether to print table header or not $nograde = 0; for ($i = 0; $i <= $course->numsections; $i++) { if (isset($sections[$i])) { // should always be true $section = $sections[$i]; if ($section->sequence) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $sectionmod) { $mod = $mods[$sectionmod]; if (empty($mod->modname)) { continue; // Just in case, see MDL-7150 } if (!($instance = get_record($mod->modname, 'id', $mod->instance))) { continue; } if (!($cm = get_coursemodule_from_instance($mod->modname, $mod->instance))) { continue; } if (!$cm->visible) { $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); if (!has_capability('moodle/course:viewhiddenactivities', $modcontext)) { continue; } } $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php"; if (file_exists($libfile)) { require_once $libfile; $gradefunction = $mod->modname . '_grades'; if (function_exists($gradefunction)) { // Skip modules without grade function if ($modgrades = $gradefunction($mod->instance)) { if (!empty($modgrades->maxgrade)) { if ($mod->visible) { $maxgrade = $modgrades->maxgrade; } else { $maxgrade = $modgrades->maxgrade; } } else { $maxgrade = ''; } if ($maxgrade) { if (!$nograde) { echo '<table align="center" class="grades"><tr><th scope="col">' . get_string('activity') . '</th><th scope="col">' . get_string('yourgrade', 'grades') . '</th><th scope="col">' . get_string('maxgrade', 'grades') . '</th></tr>'; } $nograde++; $link_id = grade_get_module_link($course->id, $mod->instance, $mod->module); $link = $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $link_id->id; echo '<tr>'; if (!empty($modgrades->grades[$user->id])) { $currentgrade = $modgrades->grades[$user->id]; echo "<td><a href='{$link}'>{$mod->modfullname}: " . format_string($instance->name, true) . "</a></td><td>{$currentgrade}</td><td>{$maxgrade}</td>"; } else { echo "<td><a href='{$link}'>{$mod->modfullname}: " . format_string($instance->name, true) . "</a></td><td>" . get_string('nograde') . "</td><td>{$maxgrade}</td>"; } echo '</tr>'; } } } } } } } } // a new Moodle nesting record? ;-) if ($nograde) { echo '</table>'; } }
function allmetadata_print_big_search_form($course) { global $CFG; global $words, $subject, $searchcourseid, $phrase, $user, $userid, $modname, $fullwords, $notwords, $datefrom, $dateto; print_simple_box(get_string('searchallmetadataintro', 'allmetadata'), 'center', '', '', 'searchbox', 'intro'); print_simple_box_start("center"); echo "<script type=\"text/javascript\" language=\"javascript\">\n"; echo "var timefromitems = ['fromday','frommonth','fromyear','fromhour', 'fromminute'];\n"; echo "var timetoitems = ['today','tomonth','toyear','tohour','tominute'];\n"; echo "</script>\n"; echo '<form name="search" action="search_allmetadata.php" method="get">'; echo '<input type="hidden" value="' . $course->id . '" name="id" alt="">'; echo '<table cellpadding="10" class="searchbox" id="form">'; echo '<tr>'; echo '<td class="c0">' . get_string('searchwords', 'allmetadata') . ':</td>'; echo '<td class="c1"><input type="text" size="35" name="words" value="' . s($words) . '" alt=""></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchphrase', 'allmetadata') . ':</td>'; echo '<td class="c1"><input type="text" size="35" name="phrase" value="' . s($phrase) . '" alt=""></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchnotwords', 'allmetadata') . ':</td>'; echo '<td class="c1"><input type="text" size="35" name="notwords" value="' . s($notwords) . '" alt=""></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchfullwords', 'allmetadata') . ':</td>'; echo '<td class="c1"><input type="text" size="35" name="fullwords" value="' . s($fullwords) . '" alt=""></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchdatefrom', 'allmetadata') . ':</td>'; echo '<td class="c1">'; echo '<input name="timefromrestrict" type="checkbox" value="1" alt="' . get_string('searchdatefrom', 'allmetadata') . '" onclick="return lockoptions(\'search\', \'timefromrestrict\', timefromitems)" /> '; if (empty($dateto)) { $datefrom = make_timestamp(2000, 1, 1, 0, 0, 0); } print_date_selector('fromday', 'frommonth', 'fromyear', $datefrom); print_time_selector('fromhour', 'fromminute', $datefrom); echo '<input type="hidden" name="hfromday" value="0" />'; echo '<input type="hidden" name="hfrommonth" value="0" />'; echo '<input type="hidden" name="hfromyear" value="0" />'; echo '<input type="hidden" name="hfromhour" value="0" />'; echo '<input type="hidden" name="hfromminute" value="0" />'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchdateto', 'allmetadata') . ':</td>'; echo '<td class="c1">'; echo '<input name="timetorestrict" type="checkbox" value="1" alt="' . get_string('searchdateto', 'allmetadata') . '" onclick="return lockoptions(\'search\', \'timetorestrict\', timetoitems)" /> '; if (empty($dateto)) { $dateto = time() + 3600; } print_date_selector('today', 'tomonth', 'toyear', $dateto); print_time_selector('tohour', 'tominute', $dateto); echo '<input type="hidden" name="htoday" value="0" />'; echo '<input type="hidden" name="htomonth" value="0" />'; echo '<input type="hidden" name="htoyear" value="0" />'; echo '<input type="hidden" name="htohour" value="0" />'; echo '<input type="hidden" name="htominute" value="0" />'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchsubject', 'allmetadata') . ':</td>'; echo '<td class="c1"><input type="text" size="35" name="subject" value="' . s($subject) . '" alt=""></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchuser', 'allmetadata') . ':</td>'; echo '<td class="c1"><input type="text" size="35" name="user" value="' . s($user) . '" alt=""></td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchwhichmetadatas', 'allmetadata') . ':</td>'; echo '<td class="c1">'; //Metadata Modules available //function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) $allmods = get_all_mods($course->id, &$mods, &$modnames, &$modnamesplural, &$modnamesused); $metamods = array(); if (array_key_exists("metadatadc", $modnamesplural)) { $metamods = array_merge(array("metadatadc" => get_string('modulenameplural', 'metadatadc')), $metamods); //array_unshift($metamods, get_string('modulenameplural', 'metadatadc')); } if (array_key_exists("metadatalom", $modnamesplural)) { $metamods = array_merge(array("metadatalom" => get_string('modulenameplural', 'metadatalom')), $metamods); //array_unshift($metamods, get_string('modulenameplural', 'metadatalom')); } if (count($metamods) == 1) { //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0) choose_from_menu($metamods, 'metamodname', '', 'choose', ''); } elseif (count($metamods) > 1) { array_unshift($metamods, get_string('allmetadata', 'allmetadata')); choose_from_menu($metamods, 'metamodname', '', 'choose', ''); } else { echo '<strong>' . get_string('nometadata', 'allmetadata') . '</strong>'; } echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchwhichcourse', 'allmetadata') . ':</td>'; echo '<td class="c1">'; //Courses available //get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*") $allcourses = array(); if ($allcs = get_courses("all", "c.id ASC", "c.id,c.fullname")) { foreach ($allcs as $allc) { $namec = $allc->fullname; $idc = $allc->id; $onecourse = array($idc => $namec); array_push_associative($allcourses, $onecourse); } } if (count($allcourses) == 1) { //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0) choose_from_menu($allcourses, 'searchcourseid', '', get_string('allcourses', 'allmetadata'), ''); } elseif (count($allcourses) > 1) { //array_unshift($allcourses, get_string('allcourses', 'allmetadata')); //array_push($allcourses, get_string('mycourses', 'allmetadata')); $mycourse = array("9999" => get_string('mycourses', 'allmetadata')); array_push_associative($allcourses, $mycourse); choose_from_menu($allcourses, 'searchcourseid', '', get_string('allcourses', 'allmetadata'), ''); } else { echo '<strong>' . get_string('nocourses', 'allmetadata') . '</strong>'; } echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="c0">' . get_string('searchwhichmods', 'allmetadata') . ':</td>'; echo '<td class="c1">'; //Resources-Activities Modules available $modsmetadata = array("metadatadc" => get_string('modulenameplural', 'metadatadc'), "metadatalom" => get_string('modulenameplural', 'metadatalom')); $modsra = array(); //Don't show the metadatalom/metadatadc mods $modsra = array_diff($modnamesplural, $modsmetadata); if (count($modsra) == 1) { //choose_from_menu($options, $name, $selected='', $nothing='choose', $script='', $nothingvalue='0', $return=false, $disabled=false, $tabindex=0) choose_from_menu($modsra, 'modname', '', 'choose', ''); } elseif (count($modsra) > 1) { array_unshift($modsra, get_string('allmods', 'allmetadata')); choose_from_menu($modsra, 'modname', '', 'choose', ''); } else { echo '<strong>' . get_string('nomodules', 'allmetadata') . '</strong>'; } echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td class="submit" colspan="2" align="center">'; echo '<input type="submit" value="' . get_string('searchallmetadatas', 'allmetadata') . '" alt=""></td>'; echo '</tr>'; echo '</table>'; echo '</form>'; echo "<script type=\"text/javascript\">"; echo "lockoptions('search','timefromrestrict', timefromitems);"; echo "lockoptions('search','timetorestrict', timetoitems);"; echo "</script>\n"; print_simple_box_end(); }
function display() { global $CFG, $PAGE, $COURSE; require_capability('moodle/course:manageactivities', $this->context); get_all_mods($COURSE->id, $mods, $modnames, $modnamesplural, $modnamesused); // Right now storing modules in a section corresponding to the current // page - probably should all be section 0 though if ($COURSE->id == SITEID) { $section = 1; // Front page only has section 1 - so use 1 as default } else { if (isset($page->id)) { $section = $page->id; } else { $section = 0; } } $PAGE->print_tabs('activities'); print_box_start('boxwidthwide boxaligncenter pageeditingtable', 'editing-table'); print_section_add_menus($COURSE, $section, $modnames); if (!empty($modnamesused)) { $modinfo = get_fast_modinfo($COURSE); $vars = new stdClass(); $vars->delete = get_string("delete"); $vars->update = get_string("update"); $vars->sesskey = sesskey(); foreach ($modnamesused as $module => $modnamestr) { $orderby = 'i.name'; $fields = 'i.id, i.name, m.name ' . sql_as() . ' module, c.id ' . sql_as() . 'cmid, c.visible'; // Going to be executing SQL that could fail on purpose - avoid debug messages $debug = $CFG->debug; // Store current value $CFG->debug = false; // disable_debugging() doesn't seem to work // Check for field named type if (execute_sql("SELECT type FROM {$CFG->prefix}{$module} WHERE 1 = 2", false)) { // Has type - incorperate it into the sql $orderby = "i.type, {$orderby}"; $fields = "{$fields}, i.type"; } // Restore debug value $CFG->debug = $debug; $instances = get_records_sql("SELECT {$fields}\n FROM {$CFG->prefix}course_modules c,\n {$CFG->prefix}modules m,\n {$CFG->prefix}{$module} i\n WHERE i.course = {$COURSE->id}\n AND m.name = '{$module}'\n AND c.instance = i.id\n AND c.module = m.id\n ORDER BY {$orderby}"); if (!empty($instances)) { $lasttype = ''; print "<h2><a href=\"{$CFG->wwwroot}/mod/{$module}/index.php?id={$COURSE->id}\">{$modnamestr}</a></h2>\n"; print "<ul class=\"activity-list\">\n"; foreach ($instances as $instance) { if (!empty($instance->type) and $lasttype != $instance->type) { if (!empty($lasttype)) { // Switching types and it isn't the first time, close previously opened list print "</ul>\n</li>\n"; } // Try to get a name for the type (check module first) $strtype = get_string($instance->type, $module); if (strpos($strtype, '[') !== false) { $strtype = get_string($module . ':' . $instance->type, 'format_page'); } print "<li><div class=\"plus-minus\"><p><span class=\"no-space\"><strong>{$strtype}</strong></span></p></div>\n<ul>\n"; $lasttype = $instance->type; } if (!empty($modinfo->cms[$instance->cmid]->icon)) { $icon = "{$CFG->pixpath}/" . urldecode($modinfo->cms[$instance->cmid]->icon); } else { $icon = "{$CFG->modpixpath}/{$module}/icon.gif"; } if (empty($instance->visible)) { $linkclass = ' class="dimmed"'; } else { $linkclass = ''; } print '<li>'; print '<img src="' . $icon . '" class="icon" />'; print "<a{$linkclass} href=\"{$CFG->wwwroot}/mod/{$module}/view.php?id={$instance->cmid}\">" . format_string(strip_tags($instance->name), true, $COURSE->id) . '</a> '; print '<span class="commands">'; print "<a title=\"{$vars->update}\" href=\"{$CFG->wwwroot}/course/mod.php?update={$instance->cmid}&sesskey={$vars->sesskey}\">"; print "<img src=\"{$CFG->pixpath}/t/edit.gif\" class=\"icon-edit\" alt=\"{$vars->update}\" /></a> "; print "<a title=\"{$vars->delete}\" href=\"{$CFG->wwwroot}/course/format/page/format.php?id={$COURSE->id}&action=deletemod&sesskey={$vars->sesskey}&cmid={$instance->cmid}\">"; print "<img src=\"{$CFG->pixpath}/t/delete.gif\" class=\"icon-edit\" alt=\"{$vars->delete}\" /></a></span>"; print "</li>\n"; } if (!empty($lasttype)) { // Close type list since we know it was opened print "</ul>\n</li>\n"; } print "</ul>\n"; } } } else { print_box(get_string('noacivitiesfound', 'format_page')); } print_box_end(); }
function get_course_mods($id, $username = '') { global $CFG, $DB; $username = utf8_decode($username); $username = strtolower($username); if ($username) { $user = get_complete_user_data('username', $username); } $sections = get_all_sections($id); $forum = forum_get_course_forum($id, 'news'); $news_forum_id = $forum->id; get_all_mods($id, $mods, $modnames, $modnamesplural, $modnamesused); $context = get_context_instance(CONTEXT_COURSE, $id); $e = array(); foreach ($sections as $section) { if (!$section->visible) { continue; } $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; $resource['completion_info'] = ''; if ($username) { $cm = get_coursemodule_from_id(false, $mod->id); if (!coursemodule_visible_for_user($cm, $user->id)) { if (!$mod->showavailability) { // Mod not visible, and no completion info to show continue; } $resource['available'] = 0; $ci = new condition_info($mod); $resource['completion_info'] = $ci->get_full_information(); } else { $resource['available'] = 1; } } else { $resource['available'] = 1; } $e[$section->section]['section'] = $section->section; $e[$section->section]['name'] = $section->name; $e[$section->section]['summary'] = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); $e[$section->section]['summary'] = str_replace('pluginfile.php', '/auth/joomdle/pluginfile_joomdle.php', $e[$section->section]['summary']); $resource['id'] = $mod->id; $resource['name'] = $mod->name; $resource['mod'] = $mod->modname; // Format for mod->icon is: f/type-24 $type = substr($mod->icon, 2); $parts = explode('-', $type); $type = $parts[0]; $resource['type'] = $type; //In forum, type is unused, so we use it for forum type: news/general if ($mod->modname == 'forum') { $cm = get_coursemodule_from_id('forum', $mod->id); if ($cm->instance == $news_forum_id) { $resource['type'] = 'news'; } } $e[$section->section]['mods'][] = $resource; } } return $e; }
/** * セクション内のリンクを全て書き換える * ※convert.phpを読み込むこと * * * @param &object $course * @param int $sectionid * @param string $directoryname : 書き換え後のディレクトリ名(全てのリンクを書き換える) * @param bool $ismcopy : TRUE:ファイルをコピーする, FALSE:リンクの書き換えのみ * @param bool $ismessage : TRUE:処理メッセージを表示する, FALSE:処理メッセージを表示しない */ function topicsadv_format_rename_section_links(&$course, $sectionid, $directoryname, $iscopy = true, $ismessage = true) { global $CFG; $status = ''; // セクション内の全てのモジュールを読み込む get_all_mods($course->id, &$mods, &$modnames, &$modnamesplural, &$modnamesused); // セクションの概要を追加 $sectionobject = new stdClass(); $sectionobject->modname = 'course_section'; $sectionobject->section = $sectionid; $mods[] = $sectionobject; foreach ($mods as $mod) { // セクション内の確認 if ($mod->section == $sectionid) { // 各モジュールのリンクを取得 if (function_exists($mod->modname . '_get_links') && function_exists($mod->modname . '_rename_links')) { // コンテンツ内のリンク一覧を取得 $func = $mod->modname . '_get_links'; $links = $func($course, $mod); // リンクがある場合はリンクの張り替えを行う if (is_array($links)) { // ディレクトリの作成 if ($iscopy) { if (!check_dir_exists($CFG->dataroot . '/' . $course->id . '/' . $directoryname, true)) { error("Can't create directory"); } } foreach ($links as $link) { // 元ファイルのファイル名取得 $pathinfo = pathinfo($link); if ($link != $course->id . '/' . $directoryname . '/' . $pathinfo['basename']) { // モジュールファイルをコピーする // 20080323空白が%20のときは変換する $directoryname = preg_replace('|%20|', ' ', $directoryname); $pathinfo['basename'] = preg_replace('|%20|', ' ', $pathinfo['basename']); if ($iscopy && (file_exists($CFG->dataroot . '/' . $link) && !file_exists($CFG->dataroot . '/' . $course->id . '/' . $directoryname . '/' . $pathinfo['basename']))) { copy($CFG->dataroot . '/' . $link, $CFG->dataroot . '/' . $course->id . '/' . $directoryname . '/' . $pathinfo['basename']); } // モジュールリンクを置換する $func = $mod->modname . '_rename_links'; $func($course, $mod, $link, $course->id . '/' . $directoryname . '/' . $pathinfo['basename']); if ($ismessage) { $status .= '<li>' . $link . ' --> ' . $course->id . '/' . $directoryname . '/' . $pathinfo['basename'] . '</li>'; } } } } } else { // 注意事項の追加 if ($ismessage) { notify($mod->modfullname . get_string('notrename', 'format_topicsadv')); } } } } // 結果表示 if ($status) { echo '<ul>' . $status . '</ul>'; } // コースのキャッシュを再構築 rebuild_course_cache($course->id, true); }
/** * Return an array of modules that can be moved in this situation * The Array is keyed first with sections (subpage or main course) * and then the modules within each section by cmid * @param Object $subpage current subpage * @param Array $allsubpages * @param Array $coursesections * @param Object $modinfo * @param String $move to or from * @return Array mixed */ public static function moveable_modules($subpage, $allsubpages, $coursesections, course_modinfo $modinfo, $move) { global $OUTPUT; get_all_mods($subpage->get_course()->id, $allmods, $modnames, $modnamesplural, $modnamesused); $mods = array(); $subsections = array(); if (!empty($allsubpages) && $move === 'to') { foreach ($allsubpages as $sub) { $subsections += $sub->get_sections(); } $sections = $coursesections; } else { $subsections = $subpage->get_sections(); $sections = $subsections; } if ($sections) { foreach ($sections as $section) { if (!empty($section->sequence)) { if ($move === 'to' && array_key_exists($section->id, $subsections)) { continue; } $sectionalt = isset($section->pageorder) ? $section->pageorder : $section->section; if ($move === 'to') { // Include the required course/format library. global $CFG; require_once "{$CFG->dirroot}/course/format/" . $subpage->get_course()->format . "/lib.php"; $callbackfunction = 'callback_' . $subpage->get_course()->format . '_get_section_name'; if (function_exists($callbackfunction)) { $name = $callbackfunction($subpage->get_course(), $section); } else { $name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt; } } else { $name = $section->name ? $section->name : get_string('section') . ' ' . $sectionalt; } $sectionmods = explode(',', $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($allmods[$modnumber]) || $modnumber === $subpage->get_course_module()->id) { continue; } $instancename = format_string($modinfo->cms[$modnumber]->name, true, $subpage->get_course()->id); $icon = $modinfo->get_cm($modnumber)->get_icon_url(); $mod = $allmods[$modnumber]; $mods[$section->section]['section'] = $name; $mods[$section->section]['pageorder'] = $sectionalt; $mods[$section->section]['mods'][$modnumber] = "<span><img src='{$icon}' /> " . $instancename . "</span>"; } } } } return $mods; }
/** * Specifies which values for the log 'module' field count as resources * when tracking resource views * * @return array The list of appropriate field values */ function get_resource_modules() { global $CFG, $SITE; //course API require_once $CFG->dirroot . '/course/lib.php'; //retrieve information about all modules on the site get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); //make sure to always count 'resource' for legacy reasons $result = array('resource'); foreach ($modnames as $modname => $modnamestr) { //make sure the module is valid $libfile = "{$CFG->dirroot}/mod/{$modname}/lib.php"; if (!file_exists($libfile)) { continue; } //check to see if the module is considered a resource in a "legacy" way include_once $libfile; $gettypesfunc = $modname . '_get_types'; if (function_exists($gettypesfunc)) { //look through supported "types" for resource if ($types = $gettypesfunc()) { foreach ($types as $type) { if ($type->modclass == MOD_CLASS_RESOURCE) { $result[] = $modname; break; } } } } } return $result; }
function getmoddata($courseid, $requestid) { global $DB; //fetch info and ids about the modules in this course $course = $DB->get_record('course', array('id' => $courseid)); $modinfo =& get_fast_modinfo($course); get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused); $sections = get_all_sections($courseid); /* Displays the type of mod name - assignment/ quiz etc foreach($modnames as $modname) { array_push($return['messages'],$modname); } */ $sectionarray = array(); foreach ($sections as $section) { //$sectionarray[$section->id] = get_section_name($course,$section); //here we will store all the mods for the section $sectionarray[$section->section] = array(); } //for each mod add its name and id to an array for its section foreach ($mods as $mod) { //$modname = htmlspecialchars($modinfo->cms[$mod->id]->name, ENT_QUOTES); $modname = htmlspecialchars($mod->name, ENT_QUOTES); $modtype = $mod->modfullname; $sectionid = $modinfo->cms[$mod->id]->sectionnum; array_push($sectionarray[$sectionid], "<module sectionid='" . $sectionid . "' modid='" . $mod->id . "' modname='" . $modname . "' modtype='" . $modtype . "' />"); } //init xml output $xml_output = "<course courseid='" . $courseid . "'>"; //go through each section adding a sect header and all the modules in it foreach ($sections as $section) { //$sectionarray[$section->id] = get_section_name($course,$section); //here we will store all the mods for the section $sectionname = htmlspecialchars(get_section_name($course, $section), ENT_QUOTES); $xml_output .= "<section sectionid='" . $section->section . "' sectionname='" . $sectionname . "'>"; foreach ($sectionarray[$section->section] as $line) { $xml_output .= "\t" . $line; } $xml_output .= "</section>"; } //close off xml output $xml_output .= "</course>"; //"section", "section, id, course, name, summary, summaryformat, sequence, visible"); //Return the data //$xml_output = prepareXMLReturn($return,$requestid); return $xml_output; }
/** * Called from {@link page_print_position()} and it is * supposed to print the front page settings in the * center column for the site course and only for * the default page (EG: the landing page). * * @return boolean **/ function page_frontpage_settings() { global $CFG, $SESSION, $SITE, $PAGE, $COURSE; // Cheap check first - course ID if ($COURSE->id != SITEID) { return false; } // More expensive check - make sure we are viewing default page $default = page_get_default_page(); $current = $PAGE->get_formatpage(); if (empty($default->id) or empty($current->id) or $default->id != $current->id) { return false; } $editing = $PAGE->user_is_editing(); /// START COPY/PASTE FROM INDEX.PHP print_container_start(); /// Print Section if ($SITE->numsections > 0) { if (!($section = get_record('course_sections', 'course', $SITE->id, 'section', 1))) { delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case $section->course = $SITE->id; $section->section = 1; $section->summary = ''; $section->sequence = ''; $section->visible = 1; $section->id = insert_record('course_sections', $section); } if (!empty($section->sequence) or !empty($section->summary) or $editing) { print_box_start('generalbox sitetopic'); /// If currently moving a file then show the current clipboard if (ismoving($SITE->id)) { $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname))); echo '<p><font size="2">'; echo "{$stractivityclipboard} (<a href=\"course/mod.php?cancelcopy=true&sesskey={$USER->sesskey}\">" . get_string('cancel') . '</a>)'; echo '</font></p>'; } $options = NULL; $options->noclean = true; echo format_text($section->summary, FORMAT_HTML, $options); if ($editing) { $streditsummary = get_string('editsummary'); echo "<a title=\"{$streditsummary}\" " . " href=\"course/editsection.php?id={$section->id}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" " . " class=\"iconsmall\" alt=\"{$streditsummary}\" /></a><br /><br />"; } get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); print_section($SITE, $section, $mods, $modnamesused, true); if ($editing) { print_section_add_menus($SITE, $section->section, $modnames); } print_box_end(); } } if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) { $frontpagelayout = $CFG->frontpageloggedin; } else { $frontpagelayout = $CFG->frontpage; } foreach (explode(',', $frontpagelayout) as $v) { switch ($v) { /// Display the main part of the front page. case FRONTPAGENEWS: if ($SITE->newsitems) { // Print forums only when needed require_once $CFG->dirroot . '/mod/forum/lib.php'; if (!($newsforum = forum_get_course_forum($SITE->id, 'news'))) { error('Could not find or create a main news forum for the site'); } if (!empty($USER->id)) { $SESSION->fromdiscussion = $CFG->wwwroot; if (forum_is_subscribed($USER->id, $newsforum)) { $subtext = get_string('unsubscribe', 'forum'); } else { $subtext = get_string('subscribe', 'forum'); } print_heading_block($newsforum->name); echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id=' . $newsforum->id . '">' . $subtext . '</a></div>'; } else { print_heading_block($newsforum->name); } forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC'); } break; case FRONTPAGECOURSELIST: if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) { print_heading_block(get_string('mycourses')); print_my_moodle(); } else { if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or count_records('course') <= FRONTPAGECOURSELIMIT) { // admin should not see list of courses when there are too many of them print_heading_block(get_string('availablecourses')); print_courses(0); } } break; case FRONTPAGECATEGORYNAMES: print_heading_block(get_string('categories')); print_box_start('generalbox categorybox'); print_whole_category_list(NULL, NULL, NULL, -1, false); print_box_end(); print_course_search('', false, 'short'); break; case FRONTPAGECATEGORYCOMBO: print_heading_block(get_string('categories')); print_box_start('generalbox categorybox'); print_whole_category_list(NULL, NULL, NULL, -1, true); print_box_end(); print_course_search('', false, 'short'); break; case FRONTPAGETOPICONLY: // Do nothing!! :-) break; } // echo '<br />'; REMOVED FOR THE FORMAT } print_container_end(); /// END COPY/PASTE FROM INDEX.PHP return true; }
function certificate_get_mod_grades() { global $course, $CFG; $strgrade = get_string('grade', 'certificate'); /// Collect modules data get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); $printgrade = array(); $sections = get_all_sections($course->id); // Sort everything the same as the course for ($i = 0; $i <= $course->numsections; $i++) { // should always be true if (isset($sections[$i])) { $section = $sections[$i]; if ($section->sequence) { switch ($course->format) { case 'topics': $sectionlabel = get_string('topic'); break; case 'weeks': $sectionlabel = get_string('week'); break; default: $sectionlabel = get_string('section'); } $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $sectionmod) { if (empty($mods[$sectionmod])) { continue; } $mod = $mods[$sectionmod]; $mod->courseid = $course->id; $instance = get_record($mod->modname, 'id', $mod->instance); if ($grade_items = grade_get_grade_items_for_activity($mod)) { $mod_item = grade_get_grades($course->id, 'mod', $mod->modname, $mod->instance); $item = reset($mod_item->items); if (isset($item->grademax)) { $printgrade[$mod->id] = $sectionlabel . ' ' . $section->section . ' : ' . $instance->name . ' ' . $strgrade; } } } } } } if (isset($printgrade)) { $gradeoptions['0'] = get_string('no'); $gradeoptions['1'] = get_string('coursegrade', 'certificate'); foreach ($printgrade as $key => $value) { $gradeoptions[$key] = $value; } } else { $gradeoptions['0'] = get_string('nogrades', 'certificate'); } return $gradeoptions; }
function fetchcourseitems($courseid) { global $CFG, $DB; $xml_output = ""; if (!($course = $DB->get_record('course', array('id' => $courseid)))) { print_error('invalidcourseid'); } require_course_login($course); //$modinfo =& get_fast_modinfo($course); $modinfo = get_fast_modinfo($course); get_all_mods($courseid, $mods, $modnames, $modnamesplural, $modnamesused); if (!($sections = get_all_sections($courseid))) { $xml_output .= 'Error finding or creating section structures for this course'; } //loop through the sections foreach ($sections as $thissection) { //display a section seperator for each secton if (!$thissection->visible) { $xml_output .= "\t<item label='---------(hidden)" . "' url='' />\n"; continue; } else { $xml_output .= "\t<item label='-----------------" . "' url='' />\n"; } //loop through all the mods for each section $sectionmods = explode(",", $thissection->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if (isset($modinfo->cms[$modnumber])) { if (!$modinfo->cms[$modnumber]->uservisible) { // visibility shortcut continue; } //here we get the name of the mod. We need to encode it //because the xml breaks otherwise when there arequotes etc. $instancename = htmlspecialchars($modinfo->cms[$modnumber]->name, ENT_QUOTES); } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod)) { // full visibility check continue; } //we have a mod, but for some reasonwe could not establish its name. $instancename = "mod with no name"; } //end of if isset //this works for now, but ultimately we will need to ad the "extra" paramaters from $modinfo $xml_output .= "\t<item label='" . $instancename . "' url='" . urlencode($CFG->wwwroot . "/mod/" . $mod->modname . "/view.php?id=" . $modnumber) . "' />\n"; } //end of for each mod } //end of for each section return $xml_output; }
function get_content() { global $USER, $CFG; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } $course = get_record('course', 'id', $this->instance->pageid); $context = get_context_instance(CONTEXT_COURSE, $course->id); $isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context); $ismoving = ismoving($this->instance->pageid); $sections = get_all_sections($this->instance->pageid); if (!empty($sections) && isset($sections[0])) { $section = $sections[0]; } if (!empty($section) || $isediting) { get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused); } $groupbuttons = $course->groupmode; $groupbuttonslink = !$course->groupmodeforce; if ($ismoving) { $strmovehere = get_string('movehere'); $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'")); $strcancel = get_string('cancel'); $stractivityclipboard = $USER->activitycopyname; } /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = unserialize((string) $course->modinfo); $editbuttons = ''; if ($ismoving) { $this->content->icons[] = '<img src="' . $CFG->pixpath . '/t/move.gif" class="iconsmall" alt="" />'; $this->content->items[] = $USER->activitycopyname . ' (<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&sesskey=' . $USER->sesskey . '">' . $strcancel . '</a>)'; } if (!empty($section) && !empty($section->sequence)) { $sectionmods = explode(',', $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($isediting && !$ismoving) { if ($groupbuttons) { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } $editbuttons = '<div class="buttons">' . make_editing_buttons($mod, true, true) . '</div>'; } else { $editbuttons = ''; } if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) { if ($ismoving) { if ($mod->id == $USER->activitycopy) { continue; } $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } $instancename = urldecode($modinfo[$modnumber]->name); $instancename = format_string($instancename, true, $this->instance->pageid); $linkcss = $mod->visible ? '' : ' class="dimmed" '; if (!empty($modinfo[$modnumber]->extra)) { $extra = urldecode($modinfo[$modnumber]->extra); } else { $extra = ''; } if (!empty($modinfo[$modnumber]->icon)) { $icon = $CFG->pixpath . '/' . urldecode($modinfo[$modnumber]->icon); } else { $icon = $CFG->modpixpath . '/' . $mod->modname . '/icon.gif'; } if ($mod->modname == 'label') { $this->content->items[] = format_text($extra, FORMAT_HTML) . $editbuttons; $this->content->icons[] = ''; } else { $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . $instancename . '</a>' . $editbuttons; //Accessibility: incidental image - should be empty Alt text $this->content->icons[] = '<img src="' . $icon . '" class="icon" alt="" />'; } } } } if ($ismoving) { $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } if ($isediting && $modnames) { $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true); } else { $this->content->footer = ''; } return $this->content; }
/** * セクション内のコンテンツを削除 * * @param object &$restore * @return bool */ function project_remove_section_contents(&$restore) { global $CFG; $status = true; // 対象のコース情報の取得 if (!($course = get_record("course", "id", $restore->course_id))) { error("Course ID was incorrect (can't find it)"); } // 対象のセクション情報の取得 if (!($section = get_course_section($restore->section, $restore->course_id))) { error("Section data was incorrect (can't find it)"); } if ($restore->currentdirectoryname) { $currentdirectoryname = $restore->currentdirectoryname; } else { // 現在のセクションのディレクトリ名を取得 if (!($sectiontitle = project_format_get_title($course, $section->id))) { error("Section directory was incorrect"); } $currentdirectoryname = $sectiontitle->directoryname; } // インスタンスを削除する // セクション内のモジュールを取得 get_all_mods($course->id, &$mods, &$modnames, &$modnamesplural, &$modnamesused); $modules = array(); foreach ($mods as $mod) { if ($mod->section == $section->id) { $modules[] = $mod; } } // セクション内からモジュールを削除する foreach ($modules as $mod) { $modlib = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php"; if (file_exists($modlib)) { include_once $modlib; } else { error("This module is missing important code! ({$modlib})"); } $deleteinstancefunction = $mod->modname . "_delete_instance"; if (!$deleteinstancefunction($mod->instance)) { notify("Could not delete the {$mod->type} (instance)"); } if (!delete_course_module($mod->id)) { notify("Could not delete the {$mod->type} (coursemodule)"); } if (!delete_mod_from_section($mod->id, $section->id)) { notify("Could not delete the {$mod->type} from that section"); } } // ディレクトリを削除する if (!($basedir = make_upload_directory("{$course->id}"))) { error("The site administrator needs to fix the file permissions"); } if (!defined('RESTORE_SILENTLY')) { echo "<li>" . get_string("deletedirectory", 'format_project'); } if (!($status = fulldelete($basedir . "/" . $currentdirectoryname))) { if (!defined('RESTORE_SILENTLY')) { notify("Error deleting directory"); } else { $errorstr = "Error deleting directory."; return false; } } if (!defined('RESTORE_SILENTLY')) { echo '</li>'; } return $status; }
public function definition() { global $USER, $CFG, $COURSE; $mform = & $this->_form; $templateuser = $USER; $context = $this->_customdata['context']; $mform->addElement('header', 'settingsheader', get_string('toolsettings', 'local_ltiprovider')); $tools = array(); $tools[$context->id] = get_string('course'); get_all_mods($this->_customdata['courseid'], $mods, $modnames, $modnamesplural, $modnamesused); foreach ($mods as $mod) { $tools[$mod->context->id] = format_string($mod->name); } $mform->addElement('select', 'contextid', get_string('tooltobeprovide', 'local_ltiprovider'), $tools); $mform->setDefault('contextid', $context->id); $mform->addElement('checkbox', 'sendgrades', null, get_string('sendgrades', 'local_ltiprovider')); $mform->setDefault('sendgrades', 1); $mform->addElement('checkbox', 'forcenavigation', null, get_string('forcenavigation', 'local_ltiprovider')); $mform->setDefault('forcenavigation', 1); $mform->addElement('duration', 'enrolperiod', get_string('enrolperiod', 'local_ltiprovider'), array('optional' => true, 'defaultunit' => 86400)); $mform->setDefault('enrolperiod', 0); $mform->addHelpButton('enrolperiod', 'enrolperiod', 'local_ltiprovider'); $mform->addElement('date_selector', 'enrolstartdate', get_string('enrolstartdate', 'local_ltiprovider'), array('optional' => true)); $mform->setDefault('enrolstartdate', 0); $mform->addHelpButton('enrolstartdate', 'enrolstartdate', 'local_ltiprovider'); $mform->addElement('date_selector', 'enrolenddate', get_string('enrolenddate', 'local_ltiprovider'), array('optional' => true)); $mform->setDefault('enrolenddate', 0); $mform->addHelpButton('enrolenddate', 'enrolenddate', 'local_ltiprovider'); $mform->addElement('text', 'maxenrolled', get_string('maxenrolled', 'local_ltiprovider')); $mform->setDefault('maxenrolled', 0); $mform->addHelpButton('maxenrolled', 'maxenrolled', 'local_ltiprovider'); $mform->setType('maxenrolled', PARAM_INT); $assignableroles = get_assignable_roles($context); $mform->addElement('select', 'croleinst', get_string('courseroleinstructor', 'local_ltiprovider'), $assignableroles); $mform->setDefault('croleinst', '3'); $mform->setAdvanced('croleinst'); $mform->addElement('select', 'crolelearn', get_string('courserolelearner', 'local_ltiprovider'), $assignableroles); $mform->setDefault('crolelearn', '5'); $mform->setAdvanced('crolelearn'); $mform->addElement('select', 'aroleinst', get_string('activityroleinstructor', 'local_ltiprovider'), $assignableroles); $mform->disabledIf('aroleinst', 'contextid', 'eq', $context->id); $mform->setDefault('aroleinst', '3'); $mform->setAdvanced('aroleinst'); $mform->addElement('select', 'arolelearn', get_string('activityrolelearner', 'local_ltiprovider'), $assignableroles); $mform->disabledIf('arolelearn', 'contextid', 'eq', $context->id); $mform->setDefault('arolelearn', '5'); $mform->setAdvanced('arolelearn'); $mform->addElement('header', 'remotesystem', get_string('remotesystem', 'local_ltiprovider')); $mform->addElement('text', 'secret', get_string('secret', 'local_ltiprovider'), 'maxlength="64" size="25"'); $mform->setType('secret', PARAM_MULTILANG); $mform->setDefault('secret', md5(uniqid(rand(), 1))); $mform->addRule('secret', get_string('required'), 'required'); $textlib = textlib_get_instance(); $choices = $textlib->get_encodings(); $mform->addElement('select', 'encoding', get_string('remoteencoding', 'local_ltiprovider'), $choices); $mform->setDefault('encoding', 'UTF-8'); $mform->addElement('header', 'defaultheader', get_string('userdefaultvalues', 'local_ltiprovider')); $choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse')); $mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices); $mform->setDefault('maildisplay', 2); $mform->addElement('text', 'city', get_string('city'), 'maxlength="100" size="25"'); $mform->setType('city', PARAM_MULTILANG); if (empty($CFG->defaultcity)) { $mform->setDefault('city', $templateuser->city); } else { $mform->setDefault('city', $CFG->defaultcity); } $mform->addRule('city', get_string('required'), 'required'); $mform->addElement('select', 'country', get_string('selectacountry'), get_string_manager()->get_list_of_countries()); if (empty($CFG->country)) { $mform->setDefault('country', $templateuser->country); } else { $mform->setDefault('country', $CFG->country); } $mform->setAdvanced('country'); $choices = get_list_of_timezones(); $choices['99'] = get_string('serverlocaltime'); $mform->addElement('select', 'timezone', get_string('timezone'), $choices); $mform->setDefault('timezone', $templateuser->timezone); $mform->setAdvanced('timezone'); $mform->addElement('select', 'lang', get_string('preferredlanguage'), get_string_manager()->get_list_of_translations()); $mform->setDefault('lang', $templateuser->lang); $mform->setAdvanced('lang'); $mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"'); $mform->setType('institution', PARAM_MULTILANG); $mform->setDefault('institution', $templateuser->institution); $mform->setAdvanced('institution'); $mform->addElement('header', 'layoutandcss', get_string('layoutandcss', 'local_ltiprovider')); $mform->addElement('checkbox', 'hidepageheader', null, get_string('hidepageheader', 'local_ltiprovider')); $mform->addElement('checkbox', 'hidepagefooter', null, get_string('hidepagefooter', 'local_ltiprovider')); $mform->addElement('checkbox', 'hideleftblocks', null, get_string('hideleftblocks', 'local_ltiprovider')); $mform->addElement('checkbox', 'hiderightblocks', null, get_string('hiderightblocks', 'local_ltiprovider')); $mform->setAdvanced('hideleftblocks'); $mform->setAdvanced('hiderightblocks'); $editoroptions = array(); $displayoptions = array('rows' => '4', 'cols' => ''); $mform->addElement('textarea', 'customcss', get_string('customcss', 'local_ltiprovider'), $displayoptions, $editoroptions); $mform->setAdvanced('customcss'); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(); }
function get_content() { global $USER, $CFG, $DB, $OUTPUT; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->items = array(); $this->content->icons = array(); $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } $course = $this->page->course; require_once $CFG->dirroot . '/course/lib.php'; $context = context_course::instance($course->id); $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context); $modinfo = get_fast_modinfo($course); /// extra fast view mode if (!$isediting) { if (!empty($modinfo->sections[0])) { $options = array('overflowdiv' => true); foreach ($modinfo->sections[0] as $cmid) { $cm = $modinfo->cms[$cmid]; if (!$cm->uservisible) { continue; } list($content, $instancename) = get_print_section_cm_text($cm, $course); if (!($url = $cm->get_url())) { $this->content->items[] = $content; $this->content->icons[] = ''; } else { $linkcss = $cm->visible ? '' : ' class="dimmed" '; //Accessibility: incidental image - should be empty Alt text $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" /> '; $this->content->items[] = '<a title="' . $cm->modplural . '" ' . $linkcss . ' ' . $cm->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>'; } } } return $this->content; } /// slow & hacky editing mode $ismoving = ismoving($course->id); $section = get_course_section(0, $course->id); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); $groupbuttons = $course->groupmode; $groupbuttonslink = !$course->groupmodeforce; if ($ismoving) { $strmovehere = get_string('movehere'); $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'")); $strcancel = get_string('cancel'); $stractivityclipboard = $USER->activitycopyname; } /// Casting $course->modinfo to string prevents one notice when the field is null $editbuttons = ''; if ($ismoving) { $this->content->icons[] = '<img src="' . $OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />'; $this->content->items[] = $USER->activitycopyname . ' (<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&sesskey=' . sesskey() . '">' . $strcancel . '</a>)'; } if (!empty($section->sequence)) { $sectionmods = explode(',', $section->sequence); $options = array('overflowdiv' => true); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if (!$ismoving) { if ($groupbuttons) { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } $editbuttons = '<div class="buttons">' . make_editing_buttons($mod, true, true) . '</div>'; } else { $editbuttons = ''; } if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) { if ($ismoving) { if ($mod->id == $USER->activitycopy) { continue; } $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } list($content, $instancename) = get_print_section_cm_text($modinfo->cms[$modnumber], $course); $linkcss = $mod->visible ? '' : ' class="dimmed" '; if (!($url = $mod->get_url())) { $this->content->items[] = $content . $editbuttons; $this->content->icons[] = ''; } else { //Accessibility: incidental image - should be empty Alt text $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" /> '; $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra . ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons; } } } } if ($ismoving) { $this->content->items[] = '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . sesskey() . '">' . '<img style="height:16px; width:80px; border:0px" src="' . $OUTPUT->pix_url('movehere') . '" alt="' . $strmovehere . '" /></a>'; $this->content->icons[] = ''; } if (!empty($modnames)) { $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true); } else { $this->content->footer = ''; } return $this->content; }
function get_course_grade($id) { global $course, $CFG, $USER; $course = get_record("course", "id", $id); $strgrades = get_string("grades"); $strgrade = get_string("grade"); $strmax = get_string("maximumshort"); $stractivityreport = get_string("activityreport"); /// Get a list of all students $columnhtml = array(); // Accumulate column html in this array. $grades = array(); // Collect all grades in this array $maxgrades = array(); // Collect all max grades in this array $totalgrade = 0; $totalmaxgrade = 1.0E-6; /// Collect modules data $test = get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); /// Search through all the modules, pulling out grade data $sections = get_all_sections($course->id); // Sort everything the same as the course for ($i = 0; $i <= $course->numsections; $i++) { if (isset($sections[$i])) { // should always be true $section = $sections[$i]; if (!empty($section->sequence)) { $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $sectionmod) { $mod = $mods[$sectionmod]; if ($mod->visible) { $instance = get_record("{$mod->modname}", "id", "{$mod->instance}"); $libfile = "{$CFG->dirroot}/mod/{$mod->modname}/lib.php"; if (file_exists($libfile)) { require_once $libfile; $gradefunction = $mod->modname . "_grades"; if (function_exists($gradefunction)) { // Skip modules without grade function if ($modgrades = $gradefunction($mod->instance)) { if (empty($modgrades->grades[$USER->id])) { $grades[] = ""; } else { $grades[] = $modgrades->grades[$USER->id]; $totalgrade += (double) $modgrades->grades[$USER->id]; } if (empty($modgrades->maxgrade) || empty($modgrades)) { $maxgrades[] = ""; } else { $maxgrades[] = $modgrades->maxgrade; $totalmaxgrade += $modgrades->maxgrade; } } } $gradefunction = $mod->modname . "_get_user_grades"; if (function_exists($gradefunction)) { // Skip modules without grade function if ($modgrades = $gradefunction($mod->instance)) { /* if (empty($modgrades->grades[$USER->id])) { $grades[] = ""; } else { $grades[] = $modgrades->grades[$USER->id]; $totalgrade += (float)$modgrades->grades[$USER->id]; } if (empty($modgrades->maxgrade) || empty($modgrades)) { $maxgrades[] = ""; } else { $maxgrades[] = $modgrades->maxgrade; $totalmaxgrade += $modgrades->maxgrade; }*/ } } } } } } } } $coursegrade->percentage = round($totalgrade * 100 / $totalmaxgrade, 2); $coursegrade->points = $totalgrade; return $coursegrade; }
if ($completion->is_enabled() && ajaxenabled()) { // This value tracks whether there has been a dynamic change to the page. // It is used so that if a user does this - (a) set some tickmarks, (b) // go to another page, (c) clicks Back button - the page will // automatically reload. Otherwise it would start with the wrong tick // values. echo html_writer::start_tag('form', array('action' => '.', 'method' => 'get')); echo html_writer::start_tag('div'); echo html_writer::empty_tag('input', array('type' => 'hidden', 'id' => 'completion_dynamic_change', 'name' => 'completion_dynamic_change', 'value' => '0')); echo html_writer::end_tag('div'); echo html_writer::end_tag('form'); } // Course wrapper start. echo html_writer::start_tag('div', array('class' => 'course-content')); $modinfo = get_fast_modinfo($COURSE); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); foreach ($mods as $modid => $unused) { if (!isset($modinfo->cms[$modid])) { rebuild_course_cache($course->id); $modinfo = get_fast_modinfo($COURSE); debugging('Rebuilding course cache', DEBUG_DEVELOPER); break; } } if (!($sections = $modinfo->get_section_info_all())) { // No sections found $section = new stdClass(); $section->course = $course->id; // Create a default section. $section->section = 0; $section->visible = 1;
/** * Function used by the site index page to display category specific information. */ function fn_display_category_content($course, $catid) { global $USER, $CFG; $totcount = 99; $isteacher = isteacher($course->id); $isediting = isediting($course->id); $ismoving = ismoving($course->id); if (!($category = get_record('course_categories', 'id', $catid))) { error('Invalid category requested.'); } $courses = get_courses_page($catid, 'c.sortorder ASC', 'c.id,c.sortorder,c.shortname,c.fullname,c.summary,c.visible,c.teacher,c.guest,c.password', $totcount); /// Store a course section per category id. Code it by using the 'catid' plus 10 as the section number. $sectnum = $catid + 10; if (!($section = get_record('course_sections', 'course', $course->id, 'section', $sectnum))) { $section = new stdClass(); $section->course = $course->id; $section->section = $sectnum; $section->summary = $category->name; $section->sequence = ''; $section->visible = 1; if (!($section->id = insert_record('course_sections', $section))) { error('Could not create section for category ' . $category->name); } } if (!empty($section) || $isediting) { get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); } $groupbuttons = $course->groupmode; $groupbuttonslink = !$course->groupmodeforce; if ($ismoving) { $strmovehere = get_string('movehere'); $strmovefull = strip_tags(get_string('movefull', '', "'{$USER->activitycopyname}'")); $strcancel = get_string('cancel'); $stractivityclipboard = $USER->activitycopyname; } $modinfo = unserialize($course->modinfo); $editbuttons = ''; print_simple_box_start("center", "100%", '', 5, "coursebox"); echo '<table class="topics" width="100%">'; echo '<tr id="section-' . $section . '" class="section main">'; echo '<td class="content">'; print_heading_block('<div align="center">' . $category->name . '</div>'); echo '<table class="section" width="100%">'; if (!empty($section) && !empty($section->sequence)) { $sectionmods = explode(',', $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($isediting && !$ismoving) { if ($groupbuttons) { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } $editbuttons = '<br />' . make_editing_buttons($mod, true, true); } else { $editbuttons = ''; } if ($mod->visible || $isteacher) { echo '<tr><td class="activity ' . $mod->modname . '">'; if ($ismoving) { if ($mod->id == $USER->activitycopy) { continue; } echo '<a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img height="16" width="80" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" border="0" /></a>'; } $instancename = urldecode($modinfo[$modnumber]->name); $instancename = format_string($instancename, true, $course->id); $linkcss = $mod->visible ? '' : ' class="dimmed" '; if (!empty($modinfo[$modnumber]->extra)) { $extra = urldecode($modinfo[$modnumber]->extra); } else { $extra = ''; } if (!empty($modinfo[$modnumber]->icon)) { $icon = $CFG->pixpath . '/' . urldecode($modinfo[$modnumber]->icon); } else { $icon = $CFG->modpixpath . '/' . $mod->modname . '/icon.gif'; } if ($mod->modname == 'label') { echo format_text($extra, FORMAT_HTML) . $editbuttons; } else { echo '<img src="' . $icon . '" height="16" width="16" alt="' . $mod->modfullname . '" /> ' . '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . $instancename . '</a>' . $editbuttons; } echo "</td>"; echo "</tr>"; } } } else { echo "<tr><td></td></tr>"; // needed for XHTML compatibility } if ($ismoving) { echo '<tr><td><a title="' . $strmovefull . '" href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img height="16" width="80" src="' . $CFG->pixpath . '/movehere.gif" alt="' . $strmovehere . '" border="0" /></a></td></tr>'; } if ($isediting && $modnames) { echo '<tr><td>'; print_section_add_menus($course, $section->section, $modnames, true); echo '</td></tr>'; } echo "</table>\n\n"; echo '</td></tr></table>'; print_simple_box_end(); if (empty($courses)) { print_heading(FN_translate_course_string(get_string("nocoursesyet"))); } else { foreach ($courses as $course) { print_course($course); } } }
print_box_start('generalbox sitetopic'); /// If currently moving a file then show the current clipboard if (ismoving($SITE->id)) { $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname))); echo '<p><font size="2">'; echo "{$stractivityclipboard} (<a href=\"course/mod.php?cancelcopy=true&sesskey={$USER->sesskey}\">" . get_string('cancel') . '</a>)'; echo '</font></p>'; } $options = NULL; $options->noclean = true; echo format_text($section->summary, FORMAT_HTML, $options); if ($editing) { $streditsummary = get_string('editsummary'); echo "<a title=\"{$streditsummary}\" " . " href=\"course/editsection.php?id={$section->id}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" " . " class=\"iconsmall\" alt=\"{$streditsummary}\" /></a><br /><br />"; } get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); print_section($SITE, $section, $mods, $modnamesused, true); if ($editing) { print_section_add_menus($SITE, $section->section, $modnames); } print_box_end(); } } if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) { $frontpagelayout = $CFG->frontpageloggedin; } else { $frontpagelayout = $CFG->frontpage; } foreach (explode(',', $frontpagelayout) as $v) { switch ($v) { /// Display the main part of the front page.
/** * Print out the course page. Use the course 'format.php' file. This may make sense to replace with a * function at some point, but for now, many things trigger on its existence. * */ function print_body() { /// These globals are needed for the included 'format.php' file. global $CFG, $USER, $SESSION, $COURSE, $THEME, $course; global $mods, $modnames, $modnamesplural, $modnamesused, $sections; /// These are needed in various library functions. global $PAGE, $pageblocks, $section, $marker; /// These are needed in various library functions. global $preferred_width_left, $preferred_width_right; /// These may be used in blocks. // Course wrapper start. echo '<div class="course-content">'; get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); if (!($sections = get_all_sections($course->id))) { // No sections found // Double-check to be extra sure if (!($section = get_record('course_sections', 'course', $course->id, 'section', 0))) { $section->course = $course->id; // Create a default section. $section->section = 0; $section->visible = 1; $section->id = insert_record('course_sections', $section); } if (!($sections = get_all_sections($course->id))) { // Try again error('Error finding or creating section structures for this course'); } } if (empty($course->modinfo)) { // Course cache was never made. rebuild_course_cache($course->id); if (!($course = get_record('course', 'id', $course->id))) { error("That's an invalid course id"); } } // Include the actual course format. require $CFG->dirroot . '/course/format/' . $course->format . '/format.php'; // Content wrapper end. echo "</div>\n\n"; }