function get_content()
 {
     global $CFG, $COURSE;
     if ($this->content !== NULL) {
         return $this->content;
     }
     if (empty($this->instance)) {
         return '';
     }
     $this->content = new object();
     $options = new object();
     $options->noclean = true;
     // Don't clean Javascripts etc
     $this->content->text = format_text($COURSE->summary, FORMAT_HTML, $options);
     if (isediting($COURSE->id)) {
         // ?? courseid param not there??
         if ($COURSE->id == SITEID) {
             $editpage = $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=frontpagesettings';
         } else {
             $editpage = $CFG->wwwroot . '/course/edit.php?id=' . $COURSE->id;
         }
         $this->content->text .= "<div class=\"editbutton\"><a href=\"{$editpage}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" alt=\"" . get_string('edit') . "\" /></a></div>";
     }
     $this->content->footer = '';
     return $this->content;
 }
 function get_content()
 {
     global $CFG, $USER, $COURSE;
     $this->content = new stdClass();
     $this->content->footer = "";
     if (isediting($COURSE)) {
         if ($COURSE->format == 'weeks' || $COURSE->format == 'topics') {
             $this->add_load_event_declared = false;
             $this->content->text = $this->addLoadEvent('massaction_addcheckboxes()', true) . $this->addLoadEvent('disable_js_warning()', true) . generate_form($this->instance->id);
         } else {
             $this->content->text = get_string('unsupported', 'block_massaction', $COURSE->format);
         }
     } else {
         $this->content = '';
     }
     return $this->content;
 }
 /**
  * provides constraint values from filters 
  *
  */
 function filter_get_results($fielddef, $fieldname, $specialvalue = '', $forcereload = false, &$printoutbuffer = null)
 {
     static $FILTERSETS;
     global $CFG, $DB, $PAGE;
     $tracing = 0;
     // computes filter query
     if (empty($this->filterfields->queries[$fielddef])) {
         // if not explicit query, make an implicit one
         $sql = preg_replace('/<%%FILTERS%%>|<%%PARAMS%%>/', '', $this->sql);
         if ($this->allow_filter_desaggregate($fielddef)) {
             // try desagregate
             $sql = preg_replace('/MAX\\(([^\\(]+)\\)/si', '$1', $sql);
             $sql = preg_replace('/SUM\\((.*?)\\) AS/si', '$1 AS', $sql);
             $sql = preg_replace('/COUNT\\((?:DISTINCT)?([^\\(]+)\\)/si', '$1', $sql);
             // purge from unwanted clauses
             if (preg_match('/\\bGROUP BY\\b/si', $sql)) {
                 $sql = preg_replace('/GROUP BY.*(?!GROUP BY).*$/si', '', $sql);
             }
             if (preg_match('/\\bORDER BY\\b/si', $sql)) {
                 $sql = preg_replace('/ORDER BY.*?$/si', '', $sql);
             }
         }
         $filtersql = 'SELECT DISTINCT ' . $fieldname . ' FROM ( ' . $sql . ' ) as subreq ';
         $filtersql .= " ORDER BY {$fieldname} ";
     } else {
         // explicit query, manager will have to ensure consistency of output values to filter requirement
         $filtersql = $this->filterfields->queries[$fielddef];
     }
     $filtersql = $this->protect($filtersql);
     // filter values return from cache
     if (isset($FILTERSETS) && array_key_exists($fielddef, $FILTERSETS) && empty($specialvalue)) {
         if (!empty($this->config->showfilterqueries)) {
             if (!is_null($printoutbuffer)) {
                 $printoutbuffer .= "<div class=\"dashboard-filter-query\" style=\"padding:1px;border:1px solid #808080;margin:2px;font-size;0.75em;font-family:monospace\"><b>STATIC CACHED DATA FILTER :</b> {$filtersql}</div>";
             }
         }
         return $FILTERSETS[$fielddef];
     }
     // check DB cache
     $sqlkey = md5($filtersql);
     if (@$this->config->showbenches) {
         $bench = new StdClass();
         $bench->name = 'Filter cache prefetch ' . $fielddef;
         $bench->start = time();
     }
     $cachefootprint = $DB->get_record('block_dashboard_filter_cache', array('querykey' => $sqlkey, 'access' => $this->config->target));
     if (@$this->config->showbenches) {
         $bench->end = time();
         $this->benches[] = $bench;
     }
     if ((!$PAGE->user_is_editing() || !@$CFG->block_dashboard_enable_isediting_security) && (!@$this->config->uselocalcaching || !$cachefootprint || $cachefootprint && $cachefootprint->timereloaded < time() - @$this->config->cachingttl * 60 || $forcereload)) {
         $DB->delete_records('block_dashboard_filter_cache', array('querykey' => $sqlkey, 'access' => $this->config->target));
         list($usec, $sec) = explode(' ', microtime());
         $t1 = (double) $usec + (double) $sec;
         if ($this->config->target == 'moodle') {
             if (@$this->config->showbenches) {
                 $bench = new StdClass();
                 $bench->name = 'Filter pre-query ' . $fielddef;
                 $bench->start = time();
             }
             $FILTERSET[$fielddef] = $DB->get_records_sql($filtersql);
             if (@$this->config->showbenches) {
                 $bench->end = time();
                 $this->benches[] = $bench;
             }
         } else {
             if (!isediting() || !@$CFG->block_dashboard_enable_isediting_security) {
                 $FILTERSET[$fielddef] = extra_db_query($filtersql, false, true, $error);
                 if ($error) {
                     $this->content->text .= $error;
                 }
             } else {
                 $FILTERSET[$fielddef] = array();
             }
         }
         list($usec, $sec) = explode(' ', microtime());
         $t2 = (double) $usec + (double) $sec;
         // echo $t2 - $t1;  // benching
         // make a footprint
         if (!empty($this->config->uselocalcaching)) {
             $cacherec = new StdClass();
             $cacherec->access = $this->config->target;
             $cacherec->querykey = $sqlkey;
             $cacherec->filterrecord = base64_encode(serialize($FILTERSET[$fielddef]));
             $cacherec->timereloaded = time();
             if ($tracing) {
                 mtrace('Inserting filter cache');
             }
             $DB->insert_record('block_dashboard_filter_cache', $cacherec);
         }
         if (!empty($this->config->showfilterqueries)) {
             if (!is_null($printoutbuffer)) {
                 $printoutbuffer .= "<div class=\"dashboard-filter-query\" style=\"padding:1px;border:1px solid #808080;margin:2px;font-size;0.75em;font-family:monospace\"><b>FILTER :</b> {$filtersql}</div>";
             }
         }
     } else {
         if ($cachefootprint) {
             if ($tracing) {
                 mtrace('Getting filter data from cache');
             }
             list($usec, $sec) = explode(' ', microtime());
             $t1 = (double) $usec + (double) $sec;
             $FILTERSET[$fielddef] = unserialize(base64_decode($cachefootprint->filterrecord));
             list($usec, $sec) = explode(' ', microtime());
             $t2 = (double) $usec + (double) $sec;
             // echo $t2 - $t1;  // benching
         } else {
             $notretrievablestr = get_string('filternotretrievable', 'block_dashboard');
             $this->content->text .= "<div class=\"dashboard-special\">{$notretrievablestr}</div>";
         }
         if (!empty($this->config->showfilterqueries)) {
             if (!is_null($printoutbuffer)) {
                 $printoutbuffer .= "<div class=\"dashboard-filter-query\" style=\"padding:1px;border:1px solid #808080;margin:2px;font-size;0.75em;font-family:monospace\"><b>DB CACHED FILTER :</b> {$filtersql}</div>";
             }
         }
     }
     if (is_array($FILTERSET[$fielddef])) {
         switch ($specialvalue) {
             case 'LAST':
                 $values = array_values($FILTERSET[$fielddef]);
                 $result = end()->{$fieldname};
                 return !empty($FILTERSET[$fielddef]) ? $result : false;
             case 'FIRST':
                 $values = array_values($FILTERSET[$fielddef]);
                 $result = reset($values)->{$fieldname};
                 return !empty($FILTERSET[$fielddef]) ? $result : false;
             default:
                 return $FILTERSET[$fielddef];
         }
     }
 }
function wikipediacalls_filter($courseid, $text)
{
    global $USER;
    global $CFG;
    global $wikiBlockCount;
    if ($CFG->release < '1.6') {
        $CFG->filter_wikipediacalls_showkeys = 1;
    }
    // Filters special tags inserts
    // get word before [WP] marker
    // replace word and marker by wikipedia link (language aware)
    $lang = substr(@$USER->lang, 0, 2);
    if ($lang == '') {
        $lang = "fr";
    }
    // this collects all wikipedia keys for reporting
    if (isediting($courseid, 0) && $CFG->filter_wikipediacalls_showkeys) {
        $CFG->currenttextiscacheable = true;
        $WPKeys = array();
        preg_match_all("/([^ \\.\\'`\"\\(\\)\\[\\]<>;:]+)\\[WP\\]/", $text, $matches, PREG_PATTERN_ORDER);
        foreach ($matches[1] as $aMatch) {
            $WPKeys[urlencode($aMatch)] = "http://{$lang}.wikipedia.org/wiki/" . urlencode($aMatch);
        }
        preg_match_all("/([^ \\.\\'`\"\\(\\)\\[\\]<>;:]+)\\[WP\\|([^|]*?)\\|([^\\]]*?)\\]/", $text, $matches, PREG_PATTERN_ORDER);
        for ($i = 0; $i < count($matches[2]); $i++) {
            $WPKeys[urlencode($matches[2][$i])] = "http://{$matches[3][$i]}.wikipedia.org/wiki/" . urlencode($matches[2][$i]);
            $i++;
        }
        preg_match_all("/([^ \\.\\'`\"\\(\\)\\[\\]<>;:]+)\\[WP\\|([^|]*?)\\]/", $text, $matches, PREG_PATTERN_ORDER);
        foreach ($matches[2] as $aMatch) {
            $WPKeys[urlencode($aMatch)] = "http://{$lang}.wikipedia.org/wiki/" . str_replace("+", "_", urlencode($aMatch));
        }
    }
    // this inserts any wikipedia calls
    $text = preg_replace("/([^ \\.\\'`\"\\(\\)<>;:\\[\\]]+)\\[WP\\]/", "<a href=\"http://{$lang}.wikipedia.org/wiki/\\1\" target=\"_blank\">\\1</a>", $text);
    $text = preg_replace("/([^ \\.\\'`\"\\(\\)<>;:\\[\\]]+)\\[WP\\|([^|\\]]+)\\|([^|\\]]+)\\]/", "<a href=\"http://\\3.wikipedia.org/wiki/\\2\" target=\"_blank\">\\1</a>", $text);
    $text = preg_replace("/([^ \\.\\'`\"\\(\\)<>;:\\[\\]]+)\\[WP\\|([^\\]]+)\\]/", "<a href=\"http://{$lang}.wikipedia.org/wiki/\\2\" target=\"_blank\">\\1</a>", $text);
    $text = preg_replace("/\\[WP\\]/", '', $text);
    // this prepare wikipedia reports and testing invocator
    if (isediting($courseid, 0) && $CFG->filter_wikipediacalls_showkeys) {
        if (count($WPKeys)) {
            $text = $text . "<br>" . get_string('wikipediakeys', 'wikipediacalls') . " : <br>" . implode('<br>', $WPKeys);
            // pass all keys and call data to session for checking
            if (!isset($wikiBlockCount)) {
                $wikiBlockCount = 0;
            }
            $_SESSION['wikipediaKeys'][$wikiBlockCount] = $WPKeys;
            // if link code is not loaded, load link code
            // REM : no include can be used here as effective code production is delayed
            if (!isset($CFG->testCallsLink)) {
                $CFG->testCallsLink = mb_convert_encoding(implode('', file("{$CFG->dirroot}/filter/wikipediacalls/testWikipediaCallsLink.tpl")), "ASCII", "auto");
            }
            $testCallsLink = str_replace('<%%WWWROOT%%>', $CFG->wwwroot, $CFG->testCallsLink);
            $testCallsLink = str_replace('<%%TESTLINKLABEL%%>', get_string('wikipediacallslinklabel', 'wikipediacalls'), $testCallsLink);
            $testCallsLink = str_replace('<%%WIKIBLOCKID%%>', $wikiBlockCount, $testCallsLink);
            $text = $text . $testCallsLink;
            $wikiBlockCount++;
        }
    }
    // special views for developper
    if (isadmin()) {
        // $CFG->currenttextiscacheable = false; // huge overhead in computing time
        if (preg_match("/\\[MOODLE_CFG\\]/", $text)) {
            print_r($CFG);
        }
        if (preg_match("/\\[MOODLE_USER\\]/", $text)) {
            print_r($USER);
        }
        if (preg_match("/\\[MOODLE_SESSION\\]/", $text)) {
            print_r($_SESSION);
        }
    }
    return $text;
    // Look for all these words in the text
}
if (!($coursecontext = get_context_instance(CONTEXT_COURSE, $course->id))) {
    print_error('nocontext');
}
require_login($course);
// From /course/view.php - Facilitates the correct population of the setttings block.
//$PAGE->set_context($coursecontext);
//$PAGE->set_url('/course/format/topcoll/set_layout.php&id=', array('id' => $courseid)); // From /course/view.php
//$PAGE->set_pagelayout('course'); // From /course/view.php
//$PAGE->set_pagetype('course-view-topcoll'); // From /course/view.php
//$PAGE->set_other_editing_capability('moodle/course:manageactivities'); // From /course/view.php
//$PAGE->set_title(get_string('setlayout', 'format_topcoll') . ' - ' . $course->fullname . ' ' . get_string('course'));
//$PAGE->set_heading(get_string('setlayout', 'format_topcoll') . ' - ' . $course->fullname . ' ' . get_string('course'));
//require_sesskey();
require_capability('moodle/course:update', $coursecontext);
$courseurl = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
if (isediting($courseid)) {
    $mform = new set_layout_form(null, array('courseid' => $courseid, 'setelement' => $setelement, 'setstructure' => $setstructure));
    if ($mform->is_cancelled()) {
        redirect($courseurl);
    } else {
        if ($formdata = $mform->get_data()) {
            put_layout($formdata->id, $formdata->set_element, $formdata->set_structure);
            redirect($courseurl);
        }
    }
    $PAGE = page_create_object(PAGE_COURSE_VIEW, $course->id);
    $pageblocks = blocks_setup($PAGE, BLOCKS_PINNED_BOTH);
    $PAGE->print_header(get_string('setlayout', 'format_topcoll') . ' - ' . $course->fullname . ' ' . get_string('course'), null, '', null);
    // Layout from format.php.
    // Bounds for block widths
    // more flexible for theme designers taken from theme config.php
Esempio n. 6
0
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);
}
$stractivities = get_string("activities");
$strshowalltopics = get_string("showalltopics");
$strtopic = get_string("topic");
$strgroups = get_string("groups");
$strgroupmy = get_string("groupmy");
$editing = $PAGE->user_is_editing();
if ($editing) {
    $strstudents = moodle_strtolower($course->students);
    $strtopichide = get_string("topichide", "", $strstudents);
    $strtopicshow = get_string("topicshow", "", $strstudents);
    $strmarkthistopic = get_string("markthistopic");
    $strmarkedthistopic = get_string("markedthistopic");
    $strmoveup = get_string("moveup");
    $strmovedown = get_string("movedown");
}
$isediting = isediting($course->id);
$isteacher = has_capability('moodle/grade:viewall', $cobject->context);
/// Add the selected_week to the course object (so it can be used elsewhere).
$course->selected_week = $selected_week;
/// Layout the whole page as three big columns.
echo '<table id="layout-table" cellspacing="0"><tr valign="top">';
/// If we are using mandatory activities, until they are completed only show them.
if (!empty($course->usemandatory) && !$cobject->all_mandatory_completed($course->id, $cobject->mods)) {
    /// Start main column
    echo '<td id="middle-column" align="center">';
    echo '<table class="weeks" width="*" cellpadding="8">';
    echo "<tr>";
    echo "<td valign=top class=\"fnweeklycontent\" width=\"100%\">";
    $cobject->print_mandatory_section();
    echo '</td></tr></table>';
    echo '</td>';
Esempio n. 8
0
     }
     echo '</div>';
     print_section($course, $thissection, $mods, $modnamesused);
     if (isediting($course->id)) {
         print_section_add_menus($course, $section, $modnames);
     }
 }
 echo '</td>';
 echo '<td class="right side">';
 if ($displaysection == $section) {
     echo '<a href="view.php?id=' . $course->id . '&amp;week=0#section-' . $section . '" title="' . $strshowallweeks . '">' . '<img src="' . $CFG->pixpath . '/i/all.gif" class="icon wkall" alt="' . $strshowallweeks . '" /></a><br />';
 } else {
     $strshowonlyweek = get_string("showonlyweek", "", $section);
     echo '<a href="view.php?id=' . $course->id . '&amp;week=' . $section . '" title="' . $strshowonlyweek . '">' . '<img src="' . $CFG->pixpath . '/i/one.gif" class="icon wkone" alt="' . $strshowonlyweek . '" /></a><br />';
 }
 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
     if ($thissection->visible) {
         // Show the hide/show eye
         echo '<a href="view.php?id=' . $course->id . '&amp;hide=' . $section . '&amp;sesskey=' . $USER->sesskey . '#section-' . $section . '" title="' . $strweekhide . '">' . '<img src="' . $CFG->pixpath . '/i/hide.gif" class="icon hide" alt="' . $strweekhide . '" /></a><br />';
     } else {
         echo '<a href="view.php?id=' . $course->id . '&amp;show=' . $section . '&amp;sesskey=' . $USER->sesskey . '#section-' . $section . '" title="' . $strweekshow . '">' . '<img src="' . $CFG->pixpath . '/i/show.gif" class="icon hide" alt="' . $strweekshow . '" /></a><br />';
     }
     if ($section > 1) {
         // Add a arrow to move section up
         echo '<a href="view.php?id=' . $course->id . '&amp;random=' . rand(1, 10000) . '&amp;section=' . $section . '&amp;move=-1&amp;sesskey=' . $USER->sesskey . '#section-' . ($section - 1) . '" title="' . $strmoveup . '">' . '<img src="' . $CFG->pixpath . '/t/up.gif" class="iconsmall up" alt="' . $strmoveup . '" /></a><br />';
     }
     if ($section < $course->numsections) {
         // Add a arrow to move section down
         echo '<a href="view.php?id=' . $course->id . '&amp;random=' . rand(1, 10000) . '&amp;section=' . $section . '&amp;move=1&amp;sesskey=' . $USER->sesskey . '#section-' . ($section + 1) . '" title="' . $strmovedown . '">' . '<img src="' . $CFG->pixpath . '/t/down.gif" class="iconsmall down" alt="' . $strmovedown . '" /></a><br />';
     }
 }
Esempio n. 9
0
 function get_content()
 {
     global $CFG, $USER, $SITE, $COURSE;
     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 = '';
     } else {
         if ($this->instance->pageid == SITEID) {
             // return $this->content = '';
         }
     }
     if (!empty($this->instance->pageid)) {
         $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
         if ($COURSE->id == $this->instance->pageid) {
             $course = $COURSE;
         } else {
             $course = get_record('course', 'id', $this->instance->pageid);
         }
     } else {
         $context = get_context_instance(CONTEXT_SYSTEM);
         $course = $SITE;
     }
     if (!has_capability('moodle/course:view', $context)) {
         // Just return
         return $this->content;
     }
     if (empty($CFG->loginhttps)) {
         $securewwwroot = $CFG->wwwroot;
     } else {
         $securewwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     }
     /// Course editing on/off
     if (has_capability('moodle/course:update', $context) && $course->id !== SITEID) {
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/edit.gif" class="icon" alt="" />';
         if (isediting($this->instance->pageid)) {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=off&amp;sesskey=' . sesskey() . '">' . get_string('turneditingoff') . '</a>';
         } else {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=on&amp;sesskey=' . sesskey() . '">' . get_string('turneditingon') . '</a>';
         }
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/edit.php?id=' . $this->instance->pageid . '">' . get_string('settings') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/settings.gif" class="icon" alt="" />';
     }
     /// Forum
     $this->content->items[] = '<a href="' . $CFG->wwwroot . '/mod/forum/index.php?id=' . $this->instance->pageid . '">' . get_string('forums', 'forum') . '</a>';
     $this->content->icons[] = '<img src="' . $CFG->modpixpath . '/forum/icon.gif" class="icon" alt="" />';
     /// Backup this course
     if (has_capability('moodle/site:backup', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/backup/backup.php?id=' . $this->instance->pageid . '">' . get_string('backup') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/backup.gif" class="icon" alt="" />';
     }
     /// Restore to this course
     if (has_capability('moodle/site:restore', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '&amp;wdir=/backupdata">' . get_string('restore') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Import data from other courses
     if (has_capability('moodle/site:import', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/import.php?id=' . $this->instance->pageid . '">' . get_string('import') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Reset this course
     if (has_capability('moodle/course:reset', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/reset.php?id=' . $this->instance->pageid . '">' . get_string('reset') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/return.gif" class="icon" alt="" />';
     }
     return $this->content;
 }
 /**
  * Get the block content
  *
  * @return  object  content items and icons arrays of what is to be displayed in this block
  */
 function get_content()
 {
     global $CFG, $COURSE, $USER;
     if (!isloggedin() || isguestuser()) {
         //user is not properly logged in
         return '';
     }
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->footer = '';
     $siteContext = get_context_instance(CONTEXT_SYSTEM);
     if ($COURSE->id == SITEID) {
         $context = $siteContext;
     } else {
         $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     }
     // make sure the user has the required role
     if (!empty($this->config->role)) {
         $sql = "SELECT r.id, r.name\n                      FROM {$CFG->prefix}role r\n                      JOIN {$CFG->prefix}role_assignments ra ON ra.roleid = r.id\n                      JOIN {$CFG->prefix}user u ON u.id = ra.userid\n                     WHERE ra.contextid = {$context->id}\n                           AND u.id = {$USER->id}\n                           AND ra.roleid = {$this->config->role}";
         if (!record_exists_sql($sql)) {
             $this->content->items = array();
             $this->content->icons = array();
             return $this->content;
         }
     }
     $items = array();
     $icons = array();
     $categories = array();
     if (isset($this->config->reports)) {
         // Require the php_report class
         require_once $CFG->dirroot . '/blocks/php_report/php_report_base.php';
         $params = array();
         // set the parameters that we can get from the environment
         // (currently only the course ID)
         if ($this->instance->pagetype == PAGE_COURSE_VIEW) {
             if ($this->instance->pageid != SITEID) {
                 $params['courseid'] = $this->instance->pageid;
             }
         }
         // TODO: figure out capability for showing scheduling icon
         $isediting = isediting($this->instance->pageid);
         // && has_capability('block/php_report:manageactivities', $context);
         $count = 0;
         // create links to the reports
         foreach ($this->config->reports as $report) {
             if (isset(block_elis_reports::$reports_map[$report->id])) {
                 $report->id = block_elis_reports::$reports_map[$report->id];
             }
             $report_instance = php_report::get_default_instance($report->id);
             //make sure the report shortname is valid
             if ($report_instance !== FALSE) {
                 if ($report_instance->is_available() && $report_instance->can_view_report()) {
                     $category = $report_instance->get_category();
                     if (!isset($categories[$category])) {
                         $categories[$category] = array();
                     }
                     $name = $report_instance->get_display_name();
                     $report_link = new moodle_url($CFG->wwwroot . '/blocks/php_report/render_report_page.php', $params + $report->params + array('report' => $report->id));
                     $categories[$category][$count]['item'] = '<a href="' . $report_link->out() . '">' . $name . '</a>';
                     //create an instance specifically for testing scheduling permissions
                     $test_scheduling_permissions_instance = php_report::get_default_instance($report->id, NULL, php_report::EXECUTION_MODE_SCHEDULED);
                     //get_default instance will return FALSE if we are not allowed access to scheduling
                     $can_schedule = $test_scheduling_permissions_instance !== FALSE;
                     if ($isediting && $can_schedule) {
                         // TODO: add permissions to this url
                         $link = new moodle_url('/blocks/php_report/schedule.php?report=' . $report->id . '&action=listinstancejobs&createifnone=1');
                         $image_link = '<a href="#" alt=\'' . get_string('schedule_this_report', 'block_php_report') . '\'  title=\'' . get_string('schedule_this_report', 'block_php_report') . '\' onclick="openpopup(\'' . $link->out() . '\', \'php_report_param_popup\', \'menubar=0,location=0,scrollbars,status,resizable,width=1600,height=600\');return false;">
                                         &nbsp;<img src="' . $CFG->wwwroot . '/blocks/php_report/pix/schedule.png"/>
                                         </a>';
                         $categories[$category][$count]['sched_icon'] = $image_link;
                     }
                     $categories[$category][$count]['icon'] = '<img src="' . $CFG->wwwroot . '/blocks/elis_reports/pix/report.png" />';
                     $count++;
                 }
             }
         }
         // Generates items and icons array
         $this->generate_content($categories, $this->content->items, $this->content->icons);
     }
     return $this->content;
 }
Esempio n. 11
0
function print_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
    /// Prints a section full of activity modules
    global $CFG, $USER;
    static $groupbuttons;
    static $groupbuttonslink;
    static $isteacher;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $untracked;
    static $usetracking;
    $labelformatoptions = new stdClass();
    if (!isset($isteacher)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        $isediting = isediting($course->id);
        $ismoving = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere = get_string("movehere");
            $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
        }
        include_once $CFG->dirroot . '/mod/forum/lib.php';
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
            $untracked = forum_tp_get_untracked_forums($USER->id, $course->id);
        }
    }
    $labelformatoptions->noclean = true;
    /// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = unserialize((string) $course->modinfo);
    $groupings = groups_get_all_groupings($course->id);
    //Acccessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if (($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) && (!$ismoving || $mod->id != $USER->activitycopy) && groups_course_module_visible($mod)) {
                echo '<li class="activity ' . $mod->modname . '" id="module-' . $modnumber . '">';
                // Unique ID
                if ($ismoving) {
                    echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
                         ';
                }
                $instancename = urldecode($modinfo[$modnumber]->name);
                $instancename = format_string($instancename, true, $course->id);
                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->indent) {
                    print_spacer(12, 20 * $mod->indent, false);
                }
                if ($mod->modname == "label") {
                    if (!$mod->visible) {
                        echo "<span class=\"dimmed_text\">";
                    }
                    echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                    if (!$mod->visible) {
                        echo "</span>";
                    }
                } else {
                    // Normal activity
                    //Accessibility: for files get description via icon.
                    $altname = '';
                    if ('resource' == $mod->modname) {
                        if (!empty($modinfo[$modnumber]->icon)) {
                            $possaltname = $modinfo[$modnumber]->icon;
                            $mimetype = mimeinfo_from_icon('type', $possaltname);
                            $altname = get_mimetype_description($mimetype);
                        } else {
                            $altname = $mod->modfullname;
                        }
                    } else {
                        $altname = $mod->modfullname;
                    }
                    // Avoid unnecessary duplication.
                    if (false !== stripos($instancename, $altname)) {
                        $altname = '';
                    }
                    // File type after name, for alphabetic lists (screen reader).
                    if ($altname) {
                        $altname = get_accesshide(' ' . $altname);
                    }
                    $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                    echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
                    if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                        echo " <span class=\"groupinglabel\"> - " . format_string($groupings[$mod->groupingid]->name) . '</span>';
                    }
                }
                if ($usetracking && $mod->modname == 'forum') {
                    $groupmode = groups_get_course_groupmode($course, $mod);
                    $groupid = $groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)) ? groups_get_course_group($course, true) : false;
                    if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) {
                        $unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
                        if ($unread) {
                            echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                            if ($unread == 1) {
                                echo $strunreadpostsone;
                            } else {
                                print_string('unreadpostsnumber', 'forum', $unread);
                            }
                            echo '</a> </span>';
                        }
                    }
                }
                if ($isediting) {
                    // TODO: we must define this as mod property!
                    if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
                        if (!($mod->groupmodelink = $groupbuttonslink)) {
                            $mod->groupmode = $course->groupmode;
                        }
                    } else {
                        $mod->groupmode = false;
                    }
                    echo '&nbsp;&nbsp;';
                    echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
                }
                echo "</li>\n";
            }
        }
    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }
    if ($ismoving) {
        echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
             $goback = true;
         }
     } else {
         if ($edit != -1) {
             // Non-OU: just turn on edit flag
             $USER->editing = $edit;
             $goback = true;
         }
     }
     if ($goback) {
         $url = preg_replace('~&edit=[^&]*~', '', $FULLME);
         redirect($url);
     }
 }
 // Note: Course ID is ignored outside OU
 $editing = class_exists('ouflags') ? isediting($cm->course) : isediting();
 // Display header. Because this pagelib class doesn't actually have a
 // $buttontext parameter, there has to be a really evil hack
 $PAGEWILLCALLSKIPMAINDESTINATION = true;
 $PAGE->print_header($course->shortname . ': ' . format_string($forum->get_name()), null, '', $meta, $buttontext);
 $forum->print_js($cm->id);
 // The left column ...
 if ($hasleft = !empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing)) {
     print '<div id="left-column">';
     blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
     print '</div>';
 }
 if ($hasright = !empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing)) {
     print '<div id="right-column">';
     blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
     print '</div>';
 }
 echo '</td>';
 echo '<td class="right side">';
 if (isediting($course->id) && has_capability('moodle/course:update', $coursecontext)) {
     // Only contemplate allowing a single viewable section when editing, other situations confusing!
     if ($displaysection == $section) {
         // Show the zoom boxes
         echo '<a href="view.php?id=' . $course->id . '&amp;topic=0#section-' . $section . '" title="' . $strshowalltopics . '">' . '<img src="' . $CFG->pixpath . '/i/all.gif" class="icon topicall" alt="' . $strshowalltopics . '" /></a><br />';
         // MDL-20757
     } else {
         $strshowonlytopic = get_string('showonlytopic', '', $section);
         echo '<a href="view.php?id=' . $course->id . '&amp;topic=' . $section . '" title="' . $strshowonlytopic . '">' . '<img src="' . $CFG->pixpath . '/i/one.gif" class="icon topicone" alt="' . $strshowonlytopic . '" /></a><br />';
         // MDL-20757
     }
 }
 if (isediting($course->id) && has_capability('moodle/course:update', $coursecontext)) {
     if ($course->marker == $section) {
         // Show the "light globe" on/off
         echo '<a href="view.php?id=' . $course->id . '&amp;marker=0&amp;sesskey=' . $USER->sesskey . '#section-' . $section . '" title="' . $strmarkedthistopic . '">' . '<img src="' . $CFG->pixpath . '/i/marked.gif" alt="' . $strmarkedthistopic . '" /></a><br />';
     } else {
         echo '<a href="view.php?id=' . $course->id . '&amp;marker=' . $section . '&amp;sesskey=' . $USER->sesskey . '#section-' . $section . '" title="' . $strmarkthistopic . '">' . '<img src="' . $CFG->pixpath . '/i/marker.gif" alt="' . $strmarkthistopic . '" /></a><br />';
     }
     if ($thissection->visible) {
         // Show the hide/show eye
         echo '<a href="view.php?id=' . $course->id . '&amp;hide=' . $section . '&amp;sesskey=' . $USER->sesskey . '#section-' . $section . '" title="' . $strtopichide . '">' . '<img src="' . $CFG->pixpath . '/i/hide.gif" alt="' . $strtopichide . '" /></a><br />';
     } else {
         echo '<a href="view.php?id=' . $course->id . '&amp;show=' . $section . '&amp;sesskey=' . $USER->sesskey . '#section-' . $section . '" title="' . $strtopicshow . '">' . '<img src="' . $CFG->pixpath . '/i/show.gif" alt="' . $strtopicshow . '" /></a><br />';
     }
     if ($section > 1) {
         // Add a arrow to move section up
         echo '<a href="view.php?id=' . $course->id . '&amp;random=' . rand(1, 10000) . '&amp;section=' . $section . '&amp;move=-1&amp;sesskey=' . $USER->sesskey . '#section-' . ($section - 1) . '" title="' . $strmoveup . '">' . '<img src="' . $CFG->pixpath . '/t/up.gif" alt="' . $strmoveup . '" /></a><br />';
 function print_section_fn(&$section, $absolute = false, $width = "100%")
 {
     /// Prints a section full of activity modules
     global $CFG, $USER, $THEME;
     static $initialised;
     static $groupbuttons;
     static $groupbuttonslink;
     static $isteacher, $isteacheredit;
     static $isediting;
     static $ismoving;
     static $strmovehere;
     static $strmovefull;
     static $strunreadpostsone;
     $labelformatoptions = new stdClass();
     if (!isset($isteacher)) {
         $groupbuttons = $this->course->groupmode;
         $groupbuttonslink = !$this->course->groupmodeforce;
         $isteacher = has_capability('moodle/grade:viewall', $this->context);
         $isteacheredit = has_capability('moodle/course:manageactivities', $this->context);
         $isediting = isediting($this->course->id);
         $ismoving = ismoving($this->course->id);
         if ($ismoving) {
             $strmovehere = get_string("movehere");
             $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
         }
     }
     if (!isset($initialised)) {
         include_once $CFG->dirroot . '/mod/forum/lib.php';
         if ($usetracking = forum_tp_can_track_forums()) {
             $strunreadpostsone = get_string('unreadpostsone', 'forum');
         }
         $initialised = true;
     }
     //  Replace this with language file changes (eventually).
     $link_title = array('resource' => 'Lesson', 'choice' => 'Opinion', 'lesson' => 'Reading');
     $labelformatoptions->noclean = true;
     $modinfo = unserialize($this->course->modinfo);
     echo "<table cellpadding=\"1\" cellspacing=\"0\" align=\"center\" width=\"{$width}\">\n";
     if (!empty($section->sequence)) {
         $sectionmods = explode(",", $section->sequence);
         foreach ($sectionmods as $modnumber) {
             if (empty($this->mods[$modnumber])) {
                 continue;
             }
             $mod = $this->mods[$modnumber];
             /// mrc - 20042312 - Begin G8 First Nations School Customization:
             ///     Added check for 'teacheredit' in order to hide invisible activities from
             ///     non-editing teachers.
             ///            if ($mod->visible or $isteacher) {
             if ($mod->visible or $isteacheredit) {
                 /// mrc - 20042312 - End G8 First Nations School Customization:
                 if (right_to_left()) {
                     $tdalign = 'right';
                 } else {
                     $tdalign = 'left';
                 }
                 echo "<tr><td align=\"{$tdalign}\" class=\"activity{$mod->modname}\" width=\"{$width}\">";
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
                         continue;
                     }
                     echo "<a title=\"{$strmovefull}\"" . " href=\"{$CFG->wwwroot}/course/mod.php?moveto={$mod->id}&amp;sesskey={$USER->sesskey}\">" . "<img height=\"16\" width=\"80\" src=\"{$CFG->pixpath}/movehere.gif\" " . " alt=\"{$strmovehere}\" border=\"0\"></a><br />\n";
                 }
                 $instancename = urldecode($modinfo[$modnumber]->name);
                 if (!empty($CFG->filterall)) {
                     $instancename = filter_text("<nolink>{$instancename}</nolink>", $this->course->id);
                 }
                 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->indent) {
                     print_spacer(12, 20 * $mod->indent, false);
                 }
                 //                /// If the questionnaire is mandatory
                 //                if (($mod->modname == 'questionnaire') && empty($mandatorypopup)) {
                 //                    $mandatorypopup = is_mod_mandatory($mod, $USER->id);
                 //                }
                 if ($mod->modname == "label") {
                     if (empty($this->course->usemandatory) || empty($mod->mandatory)) {
                         if (!$mod->visible) {
                             echo "<span class=\"dimmed_text\">";
                         }
                         echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                         if (!$mod->visible) {
                             echo "</span>";
                         }
                     } else {
                         if ($isediting) {
                             $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                             $alttext = isset($link_title[$mod->modname]) ? $link_title[$mod->modname] : $mod->modfullname;
                             echo "<img src=\"{$icon}\"" . " height=16 width=16 alt=\"{$alttext}\">" . " <font size=2><a title=\"{$alttext}\" {$linkcss} {$extra}" . " href=\"{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}\">{$instancename}</a></font>";
                         }
                     }
                 } else {
                     if (!$isediting && $mod->modname == 'forum' && isset($this->course->expforumsec) && $this->course->expforumsec == $section->section) {
                         $page = optional_param('page', 0, PARAM_INT);
                         $changegroup = isset($_GET['group']) ? $_GET['group'] : -1;
                         // Group change requested?
                         $forum = get_record("forum", "id", $mod->instance);
                         $groupmode = groupmode($this->course, $mod);
                         // Groups are being used
                         $currentgroup = get_and_set_current_group($this->course, $groupmode, $changegroup);
                         forum_print_latest_discussions($this->course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
                     } else {
                         // Normal activity
                         if (!$isteacher && !empty($this->course->activitytracking)) {
                             $act_compl = is_activity_complete($mod, $USER->id);
                             if ($act_compl === false) {
                                 echo ' <img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/incomplete.gif" ' . 'height="16" width="16" alt="Activity Not Completed" hspace="10" ' . 'title="Activity Not Completed">';
                             } else {
                                 if ($act_compl === true || is_int($act_compl) && $act_compl >= 50) {
                                     echo ' <img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/completed.gif" ' . 'height="16" width="16" alt="Activity Completed" hspace="10" ' . 'title="Activity Completed">';
                                 } else {
                                     if (is_int($act_compl)) {
                                         echo ' <img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/completedpoor.gif" ' . 'height="16" width="16" alt="Activity Completed Poorly" hspace="10" ' . 'title="Activity Completed Poorly">';
                                     } else {
                                         if ($act_compl == 'submitted') {
                                             echo ' <img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/submitted.gif" ' . 'height="16" width="16" alt="Activity Submitted" hspace="10" ' . 'title="Activity Submitted">';
                                         }
                                     }
                                 }
                             }
                         }
                         $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                         $alttext = isset($link_title[$mod->modname]) ? $link_title[$mod->modname] : $mod->modfullname;
                         echo "<img src=\"{$icon}\"" . " height=16 width=16 alt=\"{$alttext}\">" . " <font size=2><a title=\"{$alttext}\" {$linkcss} {$extra}" . " href=\"{$CFG->wwwroot}/mod/{$mod->modname}/view.php?id={$mod->id}\">{$instancename}</a></font>";
                     }
                 }
                 if ($usetracking && $mod->modname == 'forum') {
                     if ($unread = forum_tp_count_forum_unread_posts($mod, $this->course)) {
                         echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                         if ($unread == 1) {
                             echo $strunreadpostsone;
                         } else {
                             print_string('unreadpostsnumber', 'forum', $unread);
                         }
                         echo '</a></span>';
                     }
                 }
                 if ($isediting) {
                     // TODO: we must define this as mod property!
                     if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
                         if (!($mod->groupmodelink = $groupbuttonslink)) {
                             $mod->groupmode = $course->groupmode;
                         }
                     } else {
                         $mod->groupmode = false;
                     }
                     echo "&nbsp;&nbsp;";
                     echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
                     //                        echo make_editing_buttons($mod, $absolute, true, $mod->indent);
                     if (isadmin()) {
                         if (empty($THEME->custompix)) {
                             $pixpath = $CFG->wwwroot . '/pix';
                         } else {
                             $pixpath = $CFG->wwwroot . '/theme/' . $CFG->theme . '/pix';
                         }
                         if ($mod->hideingradebook) {
                             echo '<a title="Show Grades" href="' . $CFG->wwwroot . '/course/view.php?id=' . $this->course->id . '&hidegrades=0&mid=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/hidegrades.gif" hspace="2" height="11" width="11" border="0" /></a>';
                         } else {
                             echo '<a title="Hide Grades" href="' . $CFG->wwwroot . '/course/view.php?id=' . $this->course->id . '&hidegrades=1&mid=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/showgrades.gif" hspace="2" height="11" width="11" border="0" /></a>';
                         }
                         if (!empty($this->course->usemandatory)) {
                             if ($mod->mandatory) {
                                 echo '<a title="Mandatory off" href="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/mod.php?mandatory=0&id=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/lock.gif" hspace="2" height="11" width="11" border="0" /></a>';
                             } else {
                                 echo '<a title="Mandatory on" href="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/mod.php?mandatory=1&id=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img src="' . $CFG->wwwroot . '/course/format/' . $this->course->format . '/pix/unlock.gif" hspace="2" height="11" width="11" border="0" /></a>';
                             }
                         }
                     }
                 }
                 echo "</td>";
                 echo "</tr>";
             }
         }
     }
     if ($ismoving) {
         echo "<tr><td><a title=\"{$strmovefull}\"" . " href=\"mod.php?movetosection={$section->id}" . '&amp;sesskey=' . $USER->sesskey . '">' . "<img height=\"16\" width=\"80\" src=\"{$CFG->pixpath}/movehere.gif\" " . " alt=\"{$strmovehere}\" border=\"0\"></a></td></tr>\n";
     }
     echo "</table>\n\n";
     //    return $mandatorypopup;
 }
    if ($hideunusedblog) {
        print_header();
    } else {
        $navigation = oublog_build_navigation($cm, $oublog, $oubloginstance, $oubloguser, $extranav);
        print_header_simple(format_string($oublog->name), "", $navigation, "", oublog_get_meta_tags($oublog, $oubloginstance, $currentgroup, $cm), true, $buttontext, navmenu($course, $cm));
    }
} else {
    $navigation = oublog_build_navigation($cm, $oublog, $oubloginstance, null, $extranav);
    print_header_simple(format_string($oublog->name), "", $navigation, "", oublog_get_meta_tags($oublog, $oubloginstance, $currentgroup, $cm), true, $buttontext, navmenu($course, $cm));
}
print '<div class="oublog-topofpage"></div>';
require_once dirname(__FILE__) . '/pagelib.php';
// Initialize $PAGE, compute blocks
$PAGE = page_create_instance($oublog->id);
$pageblocks = blocks_setup($PAGE);
$editing = isediting($cm->course);
if (class_exists('ouflags') && ou_get_is_mobile() && $blogdets == 'show') {
    print '<div id="middle-column">';
    ou_print_mobile_navigation($id, $blogdets, null, $user);
} else {
    // The left column ...
    if ($hasleft = !empty($CFG->showblocksonmodpages) && (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing)) {
        print '<div id="left-column">';
        blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
        print '</div>';
    }
    print '</div>';
    // fix mixed columns in rtl mode and editing mode (nadavkav patch)
    // The right column, BEFORE the middle-column.
    print '<div id="right-column">';
}
function print_section_dblistview($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
    /// Prints a section full of activity modules
    global $CFG, $USER;
    static $initialised;
    static $groupbuttons;
    static $groupbuttonslink;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $usetracking;
    static $groupings;
    if (!isset($initialised)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        $isediting = isediting($course->id);
        $ismoving = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere = get_string("movehere");
            $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
        }
        include_once $CFG->dirroot . '/mod/forum/lib.php';
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
        }
        $initialised = true;
    }
    $labelformatoptions = new object();
    $labelformatoptions->noclean = true;
    /// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = get_fast_modinfo($course);
    //Acccessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if ($ismoving and $mod->id == $USER->activitycopy) {
                // do not display moving mod
                continue;
            }
            if (isset($modinfo->cms[$modnumber])) {
                if (!$modinfo->cms[$modnumber]->uservisible) {
                    // visibility shortcut
                    continue;
                }
            } 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;
                }
            }
            // The magic! ... if indent == 1 then ... hide module
            //            if ($mod->indent == 1) {
            //                $hiddemodule = 'hidden';
            //            } else {
            //                $hiddemodule = '';
            //            }
            echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">';
            // Unique ID
            if ($ismoving) {
                echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
                     ';
            }
            if ($mod->indent) {
                print_spacer(12, 20 * $mod->indent, false);
            }
            $extra = '';
            if (!empty($modinfo->cms[$modnumber]->extra)) {
                $extra = $modinfo->cms[$modnumber]->extra;
            }
            if ($mod->modname == "label") {
                echo "<span class=\"";
                if (!$mod->visible) {
                    echo 'dimmed_text';
                } else {
                    echo 'label';
                }
                echo '">';
                echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                echo "</span>";
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            } else {
                // Normal activity
                $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
                if (!empty($modinfo->cms[$modnumber]->icon)) {
                    $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon;
                } else {
                    $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
                }
                //Accessibility: for files get description via icon.
                $altname = '';
                if ('resource' == $mod->modname) {
                    if (!empty($modinfo->cms[$modnumber]->icon)) {
                        $possaltname = $modinfo->cms[$modnumber]->icon;
                        $mimetype = mimeinfo_from_icon('type', $possaltname);
                        $altname = get_mimetype_description($mimetype);
                    } else {
                        $altname = $mod->modfullname;
                    }
                } else {
                    $altname = $mod->modfullname;
                }
                // Avoid unnecessary duplication.
                if (false !== stripos($instancename, $altname)) {
                    $altname = '';
                }
                // File type after name, for alphabetic lists (screen reader).
                if ($altname) {
                    $altname = get_accesshide(' ' . $altname);
                }
                $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                if ($mod->modname != 'data') {
                    echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
                }
                //echo " $mod->modname ";
                // Special DBLISTVIEW magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav)
                if ($mod->modname == 'resource') {
                    $article = get_record('resource', 'id', $mod->instance);
                    //print_r($article );
                    echo "{$article->summary}";
                }
                if ($mod->modname == 'data') {
                    require_once $CFG->dirroot . '/mod/data/lib.php';
                    if (!($data = get_record('data', 'id', $mod->instance))) {
                        //error('Course module is incorrect');
                    }
                    $sort = 0;
                    $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname ';
                    $count = ' COUNT(DISTINCT c.recordid) ';
                    $tables = $CFG->prefix . 'data_content c,' . $CFG->prefix . 'data_records r,' . $CFG->prefix . 'data_content cs, ' . $CFG->prefix . 'user u ';
                    $where = 'WHERE c.recordid = r.id AND r.dataid = ' . $data->id . ' AND r.userid = u.id ';
                    $sortorder = ' ORDER BY r.id ASC ';
                    $searchselect = '';
                    // If requiredentries is not reached, only show current user's entries
                    //if (!$requiredentries_allowed) {
                    //    $where .= ' AND u.id = ' . $USER->id;
                    //}
                    /// To actually fetch the records
                    //$fromsql    = "FROM $tables $advtables $where $advwhere $groupselect $approveselect $searchselect $advsearchselect";
                    $fromsql = "FROM {$tables} {$where} ";
                    $sqlselect = "SELECT {$what} {$fromsql} {$sortorder}";
                    /// Get the actual records
                    if (!($records = get_records_sql($sqlselect))) {
                        // Nothing to show!
                    }
                    if (empty($data->listtemplate)) {
                        //notify(get_string('nolisttemplate','data'));
                        //data_generate_default_template($data, 'listtemplate', 0, false, false);
                    }
                    echo $data->listtemplateheader;
                    data_print_template('listtemplate', $records, $data);
                    echo $data->listtemplatefooter;
                    //print_r($article );
                    //echo "$article->summary";
                    echo '<hr/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_dblistview') . '</span></a>';
                    if (!empty($data->csstemplate)) {
                        echo '<style>' . $data->csstemplate . '</style>';
                    }
                }
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            }
            if ($usetracking && $mod->modname == 'forum') {
                if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
                    echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                    if ($unread == 1) {
                        echo $strunreadpostsone;
                    } else {
                        print_string('unreadpostsnumber', 'forum', $unread);
                    }
                    echo '</a></span>';
                }
            }
            if ($isediting) {
                // TODO: we must define this as mod property!
                if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
                    if (!($mod->groupmodelink = $groupbuttonslink)) {
                        $mod->groupmode = $course->groupmode;
                    }
                } else {
                    $mod->groupmode = false;
                }
                echo '&nbsp;&nbsp;';
                echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
            }
            echo "</li>\n";
        }
    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }
    if ($ismoving) {
        echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
    function get_content()
    {
        global $CFG, $USER, $COURSE;
        //error_reporting(E_ALL);
        if ($this->content !== NULL) {
            return $this->content;
        }
        if (empty($this->instance)) {
            return $this->content = '';
        }
        if (empty($USER->id)) {
            return $this->content = '';
        }
        $course = $COURSE->id == $this->instance->pageid ? $COURSE : get_record('course', 'id', $this->instance->pageid);
        $context = get_context_instance(CONTEXT_COURSE, $course->id);
        $editing = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
        if (!$editing) {
            return $this->content = '';
        }
        // DBから取得したアイテムを表示すべきものだけ抜き出し、木構造化
        // また、ここでドロップダウンリスト用にフォルダ名列挙もしておく
        $tree = array();
        $dirs = array();
        if ($shared_items = get_records('sharing_cart', 'user', $USER->id)) {
            foreach ($shared_items as $shared_item) {
                $node =& self::path_to_node($tree, explode('/', $shared_item->tree));
                $node[] = array('id' => $shared_item->id, 'path' => $shared_item->tree, 'icon' => empty($shared_item->icon) ? $shared_item->name == 'label' ? '' : '<img src="' . $CFG->wwwroot . '/mod/' . $shared_item->name . '/icon.gif" alt="" class="icon" />' : '<img src="' . $CFG->pixpath . '/' . $shared_item->icon . '" alt="" class="icon" />', 'text' => $shared_item->text, 'sort' => $shared_item->sort);
                $dirs[$shared_item->tree] = $shared_item->tree;
            }
            self::sort_tree($tree);
            unset($dirs['']);
            usort($dirs, 'strnatcasecmp');
        }
        // ツリーをHTMLにレンダリング
        $text = "<ul class=\"list\">\n" . self::render_tree($tree) . '</ul>';
        require_once dirname(__FILE__) . '/shared/SharingCart_CourseScript.php';
        $courseScript = new SharingCart_CourseScript();
        $js_import = $courseScript->import($CFG->wwwroot . '/blocks/sharing_cart/sharing_cart.js', true);
        foreach (sharing_cart_plugins::get_imports() as $import) {
            $js_import .= $courseScript->import($CFG->wwwroot . '/blocks/sharing_cart/plugins/' . $import, true);
        }
        $js_pre = '
<script type="text/javascript">
//<![CDATA[
var sharing_cart = new sharing_cart_handler({
	wwwroot     : "' . $CFG->wwwroot . '",
	pixpath     : "' . $CFG->pixpath . '",
	instance_id : ' . $this->instance->id . ',
	course_id   : ' . $course->id . ',
	return_url  : "' . urlencode($_SERVER['REQUEST_URI']) . '",
	directories : [
		' . implode(',
		', array_map(create_function('$dir', '
			return "\\"".addslashes($dir)."\\"";
		'), $dirs)) . '
	],
	str : {
		rootdir        : "' . get_string('rootdir', 'block_sharing_cart') . '",
		notarget       : "' . get_string('notarget', 'block_sharing_cart') . '",
		copyhere       : "' . get_string('copyhere', 'block_sharing_cart') . '",
		movehere       : "' . get_string('movehere') . '",
		edit           : "' . get_string('edit') . '",
		cancel         : "' . get_string('cancel') . '",
		backup         : "' . get_string('backup', 'block_sharing_cart') . '",
		clipboard      : "' . addslashes(get_string('clipboard', 'block_sharing_cart')) . '",
		confirm_backup : "' . addslashes(get_string('confirm_backup', 'block_sharing_cart')) . '",
		confirm_delete : "' . addslashes(get_string('confirm_delete', 'block_sharing_cart')) . '"
	}
});
' . implode('
', sharing_cart_plugins::get_scripts()) . '
//]]>
</script>
';
        $js_post = $courseScript->addLoadEvent('sharing_cart.init();', true);
        $this->content = new stdClass();
        $this->content->text = $js_import . $js_pre . $text;
        $this->content->footer = '<div id="sharing_cart_header" style="text-align:right;">' . implode('', sharing_cart_plugins::get_headers()) . helpbutton('sharing_cart', $this->title, 'block_sharing_cart', true, false, '', true) . '</div>' . implode('', sharing_cart_plugins::get_footers()) . $js_post;
        return $this->content;
    }
Esempio n. 18
0
 function user_is_editing()
 {
     $this->init_full();
     return isediting($this->modulerecord->course);
 }
 function get_content()
 {
     if ($this->content != NULL) {
         return $this->content;
     }
     global $CFG, $USER;
     // admins will have a problem as they will see all the courses on the entire site
     // retrieve the teacher role id (3)
     $teacher_role = get_field('role', 'id', 'shortname', 'editingteacher');
     // retrieve the non-editing teacher role id (4)
     $ne_teacher_role = get_field('role', 'id', 'shortname', 'teacher');
     // check to see if any roles allow grading of assessments
     $coursecheck = 0;
     $courses = get_my_courses($USER->id, 'fullname', 'id, visible');
     foreach ($courses as $course) {
         // exclude the front page
         if ($course->id == 1) {
             continue;
         }
         // role check bit borrowed from block_narking, thanks to Mark J Tyers [ZANNET]
         $context = get_context_instance(CONTEXT_COURSE, $course->id);
         // check for editing teachers
         $teachers = get_role_users($teacher_role, $context, true);
         $correct_role = false;
         if ($teachers) {
             foreach ($teachers as $teacher) {
                 if ($teacher->id == $USER->id) {
                     $correct_role = true;
                 }
             }
         }
         // check for non-editing teachers
         $teachers_ne = get_role_users($ne_teacher_role, $context, true);
         if ($teachers_ne) {
             foreach ($teachers_ne as $teacher) {
                 if ($teacher->id == $USER->id) {
                     $correct_role = true;
                 }
             }
         }
         // skip this course if no teacher or teacher_non_editing role
         if (!$correct_role) {
             continue;
         }
         $coursecheck++;
     }
     if ($coursecheck > 0) {
         // Grading permissions exist in at least one course, so display the block
         //start building content output
         $this->content = new stdClass();
         // make the non-ajax list whatever happens. Then allow the AJAX tree to usurp it if
         // necessary
         require_once $CFG->dirroot . '/blocks/ajax_marking/html_list.php';
         $AMB_html_list_object = new AMB_html_list();
         $this->content->text .= '<div id="AMB_html_list">';
         $this->content->text .= $AMB_html_list_object->make_html_list();
         $this->content->text .= '</div>';
         $this->content->footer = '';
         // Build the AJAX stuff on top of the plain HTML list
         // Add a style to hide the HTML list and prevent flicker
         $s = '<script type="text/javascript" defer="defer">';
         $s .= '/* <![CDATA[ */ var styleElement = document.createElement("style");';
         $s .= 'styleElement.type = "text/css";';
         $s .= 'if (styleElement.styleSheet) {';
         $s .= 'styleElement.styleSheet.cssText = "#AMB_html_list { display: none; }";';
         $s .= '} else {';
         $s .= 'styleElement.appendChild(document.createTextNode("#AMB_html_list {display: none;}"));';
         $s .= '}';
         $s .= 'document.getElementsByTagName("head")[0].appendChild(styleElement);';
         $s .= '/* ]]> */</script>';
         $this->content->text .= $s;
         $variables = array('wwwroot' => $CFG->wwwroot, 'totalMessage' => get_string('total', 'block_ajax_marking'), 'userid' => $USER->id, 'instructions' => get_string('instructions', 'block_ajax_marking'), 'configNothingString' => get_string('config_nothing', 'block_ajax_marking'), 'nothingString' => get_string('nothing', 'block_ajax_marking'), 'refreshString' => get_string('refresh', 'block_ajax_marking'), 'configureString' => get_string('configure', 'block_ajax_marking'), 'forumSaveString' => get_string('sendinratings', 'forum'), 'quizSaveString' => get_string('savechanges'), 'journalSaveString' => get_string('saveallfeedback', 'journal'), 'connectFail' => get_string('connect_fail', 'block_ajax_marking'), 'nogroups' => get_string('nogroups', 'block_ajax_marking'), 'headertext' => get_string('headertext', 'block_ajax_marking'), 'fullname' => fullname($USER), 'confAssessmentShow' => get_string('confAssessmentShow', 'block_ajax_marking'), 'confCourseShow' => get_string('confCourseShow', 'block_ajax_marking'), 'confGroups' => get_string('confGroups', 'block_ajax_marking'), 'confAssessmentHide' => get_string('confAssessmentHide', 'block_ajax_marking'), 'confCourseHide' => get_string('confCourseHide', 'block_ajax_marking'), 'confDefault' => get_string('confDefault', 'block_ajax_marking'));
         // for integrating the block_marking stuff, this stuff (divs) should all be created
         // by javascript.
         $this->content->text .= "\n                <div id='total'>\n                    <div id='totalmessage'></div>\n                    <div id='count'></div>\n                    <div id='mainIcon'></div>\n                </div>\n                <div id='status'> </div>\n                <div id='treediv' class='yui-skin-sam'>";
         // Don't warn about javascript if the sreenreader option is set - it was deliberate
         if (!$USER->screenreader) {
             $this->content->text .= "<noscript><p>AJAX marking block requires javascript, ";
             $this->content->text .= "but you have it turned off.</p></noscript>";
         }
         // Add a script that makes all of the PHP variables available to javascript
         $this->content->text .= '</div><div id="javaValues"><script type="text/javascript"';
         $this->content->text .= '>/* <![CDATA[ */ var amVariables = {';
         // loop through the PHP $variables above, making them into the right format
         $check = 0;
         foreach ($variables as $variable => $value) {
             if ($check > 0) {
                 // no initial comma, but one before all the others
                 $this->content->text .= ", ";
             }
             $this->content->text .= $variable . ": '" . $value . "'";
             $check++;
         }
         $this->content->text .= '};
                 /* ]]> */</script>
             </div>';
         // Add all of the javascript libraries that the above script depends on
         $scripts = array('yui_yahoo', 'yui_event', 'yui_dom', 'yui_logger', $CFG->wwwroot . '/lib/yui/treeview/treeview-debug.js', 'yui_connection', 'yui_dom-event', 'yui_container', 'yui_utilities', $CFG->wwwroot . '/lib/yui/container/container_core-min.js', $CFG->wwwroot . '/lib/yui/menu/menu-min.js', 'yui_json', 'yui_button', $CFG->wwwroot . '/blocks/ajax_marking/javascript.js');
         // also need to add any js from individual modules
         foreach ($AMB_html_list_object->modulesettings as $modname => $module) {
             // echo "{$CFG->dirroot}{$module->dir}/{$modname}_grading.php ";
             $file_in_mod_directory = file_exists("{$CFG->dirroot}{$module->dir}/{$modname}_grading.js");
             $file_in_block_directory = file_exists("{$CFG->dirroot}/blocks/ajax_marking/{$modname}_grading.js");
             //   echo "{$CFG->dirroot}blocks/ajax_marking/{$modname}_grading.js";
             if ($file_in_mod_directory) {
                 $scripts[] = "{$CFG->wwwroot}{$module->dir}/{$modname}_grading.js";
             } elseif ($file_in_block_directory) {
                 $scripts[] = "{$CFG->dirroot}/blocks/ajax_marking/{$modname}_grading.js";
             }
         }
         $this->content->text .= require_js($scripts) . "";
         // Add the script that will initialise the main AJAX tree widget
         //$this->content->text .= '<script type="text/javascript" defer="defer" '
         //   .'src="'.$CFG->wwwroot.'/blocks/ajax_marking/javascript.js"></script>';
         $this->content->text .= '<script type="text/javascript" defer="defer" >YAHOO.ajax_marking_block.initialise();</script>';
         // Add footer, which will have button added dynamically (not needed if javascript is
         // enabled)
         $this->content->footer .= '<div id="conf_left"></div><div id="conf_right"></div>';
     } else {
         // no grading permissions in any courses - don't display the block. Exception for
         // when the block is just installed and editing is on. Might look broken otherwise.
         if (isediting()) {
             $this->content->text .= get_string('config_nothing', 'block_ajax_marking');
             $this->content->footer = '';
         }
     }
     return $this->content;
 }
function print_section_newsroom($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%")
{
    /// Prints a section full of activity modules
    global $CFG, $USER;
    static $initialised;
    static $groupbuttons;
    static $groupbuttonslink;
    static $isediting;
    static $ismoving;
    static $strmovehere;
    static $strmovefull;
    static $strunreadpostsone;
    static $usetracking;
    static $groupings;
    if (!isset($initialised)) {
        $groupbuttons = ($course->groupmode or !$course->groupmodeforce);
        $groupbuttonslink = !$course->groupmodeforce;
        $isediting = isediting($course->id);
        $ismoving = $isediting && ismoving($course->id);
        if ($ismoving) {
            $strmovehere = get_string("movehere");
            $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'"));
        }
        include_once $CFG->dirroot . '/mod/forum/lib.php';
        if ($usetracking = forum_tp_can_track_forums()) {
            $strunreadpostsone = get_string('unreadpostsone', 'forum');
        }
        $initialised = true;
    }
    $labelformatoptions = new object();
    $labelformatoptions->noclean = true;
    /// Casting $course->modinfo to string prevents one notice when the field is null
    $modinfo = get_fast_modinfo($course);
    //Acccessibility: replace table with list <ul>, but don't output empty list.
    if (!empty($section->sequence)) {
        // Fix bug #5027, don't want style=\"width:$width\".
        echo "<ul class=\"section img-text\">\n";
        $sectionmods = explode(",", $section->sequence);
        foreach ($sectionmods as $modnumber) {
            if (empty($mods[$modnumber])) {
                continue;
            }
            $mod = $mods[$modnumber];
            if ($ismoving and $mod->id == $USER->activitycopy) {
                // do not display moving mod
                continue;
            }
            if (isset($modinfo->cms[$modnumber])) {
                if (!$modinfo->cms[$modnumber]->uservisible) {
                    // visibility shortcut
                    continue;
                }
            } 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;
                }
            }
            // The magic! ... if indent == 1 then ... hide module
            if ($mod->indent == 1) {
                $hiddemodule = 'hidden';
            } else {
                $hiddemodule = '';
            }
            echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">';
            // Unique ID
            if ($ismoving) {
                echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br />
                     ';
            }
            if ($mod->indent) {
                print_spacer(12, 20 * $mod->indent, false);
            }
            $extra = '';
            if (!empty($modinfo->cms[$modnumber]->extra)) {
                $extra = $modinfo->cms[$modnumber]->extra;
            }
            if ($mod->modname == "label") {
                echo "<span class=\"";
                if (!$mod->visible) {
                    echo 'dimmed_text';
                } else {
                    echo 'label';
                }
                echo '">';
                echo format_text($extra, FORMAT_HTML, $labelformatoptions);
                echo "</span>";
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            } else {
                // Normal activity
                $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id);
                if (!empty($modinfo->cms[$modnumber]->icon)) {
                    $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon;
                } else {
                    $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif";
                }
                //Accessibility: for files get description via icon.
                $altname = '';
                if ('resource' == $mod->modname) {
                    if (!empty($modinfo->cms[$modnumber]->icon)) {
                        $possaltname = $modinfo->cms[$modnumber]->icon;
                        $mimetype = mimeinfo_from_icon('type', $possaltname);
                        $altname = get_mimetype_description($mimetype);
                    } else {
                        $altname = $mod->modfullname;
                    }
                } else {
                    $altname = $mod->modfullname;
                }
                // Avoid unnecessary duplication.
                if (false !== stripos($instancename, $altname)) {
                    $altname = '';
                }
                // File type after name, for alphabetic lists (screen reader).
                if ($altname) {
                    $altname = get_accesshide(' ' . $altname);
                }
                $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
                echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>';
                //echo " $mod->modname ";
                // Special NEWSPAPER magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav)
                if ($mod->modname == 'resource') {
                    $article = get_record('resource', 'id', $mod->instance);
                    //print_r($article );
                    echo "{$article->summary}";
                }
                if ($mod->modname == 'oublog') {
                    require_once $CFG->dirroot . '/mod/oublog/locallib.php';
                    $oublog = get_record('oublog', 'id', $mod->instance);
                    if (!($oublogcm = get_coursemodule_from_instance('oublog', $oublog->id))) {
                        //error("Course module ID was incorrect");
                    }
                    $oublogcontext = get_context_instance(CONTEXT_MODULE, $oublogcm->id);
                    //oublog_check_view_permissions($oublog, $oublogcontext, $oublogcm);
                    $currentgroup = oublog_get_activity_group($oublogcm, true);
                    echo '<br/>';
                    /// Get Posts
                    list($posts, $recordcount) = oublog_get_posts($oublog, $oublogcontext, 0, $oublogcm, $currentgroup);
                    //, -1, $oubloguser->id, $tag, $canaudit);
                    $i = 0;
                    foreach ($posts as $post) {
                        if ($i < 3) {
                            echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>';
                            $summaryformatoptions->noclean = false;
                            echo mb_substr(format_text($post->message, FORMAT_HTML, $summaryformatoptions), 1, 600) . "<hr/>";
                        }
                        if ($i > 2 and $i < 6) {
                            echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>';
                        }
                        $i++;
                    }
                    //print_r($article );
                    //echo "$article->summary";
                    echo '<br/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_newsroom') . '</span></a>';
                }
                if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
                    if (!isset($groupings)) {
                        $groupings = groups_get_all_groupings($course->id);
                    }
                    echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>';
                }
            }
            if ($usetracking && $mod->modname == 'forum') {
                if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) {
                    echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">';
                    if ($unread == 1) {
                        echo $strunreadpostsone;
                    } else {
                        print_string('unreadpostsnumber', 'forum', $unread);
                    }
                    echo '</a></span>';
                }
            }
            if ($isediting) {
                // TODO: we must define this as mod property!
                if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') {
                    if (!($mod->groupmodelink = $groupbuttonslink)) {
                        $mod->groupmode = $course->groupmode;
                    }
                } else {
                    $mod->groupmode = false;
                }
                echo '&nbsp;&nbsp;';
                echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
            }
            echo "</li>\n";
        }
    } elseif ($ismoving) {
        echo "<ul class=\"section\">\n";
    }
    if ($ismoving) {
        echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&amp;sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li>
             ';
    }
    if (!empty($section->sequence) || $ismoving) {
        echo "</ul><!--class='section'-->\n\n";
    }
}
 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 . '&nbsp;(<a href="' . $CFG->wwwroot . '/course/mod.php?cancelcopy=true&amp;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 . '&amp;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 . '&amp;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;
 }
Esempio n. 22
0
 function get_content()
 {
     global $CFG, $USER, $SITE, $COURSE;
     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 = '';
     } else {
         if ($this->instance->pageid == SITEID) {
             // return $this->content = '';
         }
     }
     if (!empty($this->instance->pageid)) {
         $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
         if ($COURSE->id == $this->instance->pageid) {
             $course = $COURSE;
         } else {
             $course = get_record('course', 'id', $this->instance->pageid);
         }
     } else {
         $context = get_context_instance(CONTEXT_SYSTEM);
         $course = $SITE;
     }
     if (!has_capability('moodle/course:view', $context)) {
         // Just return
         return $this->content;
     }
     if (empty($CFG->loginhttps)) {
         $securewwwroot = $CFG->wwwroot;
     } else {
         $securewwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     }
     /// Course editing on/off
     if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/edit.gif" class="icon" alt="" />';
         if (isediting($this->instance->pageid)) {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=off&amp;sesskey=' . sesskey() . '">' . get_string('turneditingoff') . '</a>';
         } else {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=on&amp;sesskey=' . sesskey() . '">' . get_string('turneditingon') . '</a>';
         }
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/edit.php?id=' . $this->instance->pageid . '">' . get_string('settings') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/settings.gif" class="icon" alt="" />';
     }
     /// Assign roles to the course
     if ($course->id !== SITEID and has_capability('moodle/role:assign', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php?contextid=' . $context->id . '">' . get_string('assignroles', 'role') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/roles.gif" class="icon" alt="" />';
     }
     /// View course grades (or just your own grades, same link)
     /// find all accessible reports
     if ($course->id !== SITEID) {
         $reportavailable = false;
         if (has_capability('moodle/grade:viewall', $context)) {
             $reportavailable = true;
         } else {
             if (!empty($course->showgrades)) {
                 if ($reports = get_list_of_plugins('grade/report')) {
                     // Get all installed reports
                     arsort($reports);
                     // user is last, we want to test it first
                     foreach ($reports as $plugin) {
                         if (has_capability('gradereport/' . $plugin . ':view', $context)) {
                             //stop when the first visible plugin is found
                             $reportavailable = true;
                             break;
                         }
                     }
                 }
             }
         }
         if ($reportavailable) {
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/report/index.php?id=' . $this->instance->pageid . '">' . get_string('grades') . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/grades.gif" class="icon" alt="" />';
         }
     }
     /// Course outcomes (to help give it more prominence because it's important)
     if (!empty($CFG->enableoutcomes)) {
         if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/edit/outcome/course.php?id=' . $this->instance->pageid . '">' . get_string('outcomes', 'grades') . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/outcomes.gif" class="icon" alt="" />';
         }
     }
     /// Manage metacourses
     if ($course->metacourse) {
         if (has_capability('moodle/course:managemetacourse', $context)) {
             $strchildcourses = get_string('childcourses');
             $this->content->items[] = '<a href="importstudents.php?id=' . $this->instance->pageid . '">' . $strchildcourses . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/course.gif" class="icon" alt="" />';
         } else {
             if (has_capability('moodle/role:assign', $context)) {
                 $strchildcourses = get_string('childcourses');
                 $this->content->items[] = '<span class="dimmed_text">' . $strchildcourses . '</span>';
                 $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/course.gif" class="icon" alt="" />';
             }
         }
     }
     /// Manage groups in this course
     if ($course->id !== SITEID && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
         $strgroups = get_string('groups');
         $this->content->items[] = '<a title="' . $strgroups . '" href="' . $CFG->wwwroot . '/group/index.php?id=' . $this->instance->pageid . '">' . $strgroups . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/group.gif" class="icon" alt="" />';
     }
     /// Backup this course
     if ($course->id !== SITEID and has_capability('moodle/site:backup', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/backup/backup.php?id=' . $this->instance->pageid . '">' . get_string('backup') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/backup.gif" class="icon" alt="" />';
     }
     /// Restore to this course
     if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '&amp;wdir=/backupdata">' . get_string('restore') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Import data from other courses
     if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/import.php?id=' . $this->instance->pageid . '">' . get_string('import') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// update this course
     //TODO fix the capability used here!!!
     if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/backup/get_incremental.php?id=' . $COURSE->id . '">' . get_string('update') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// export this course to an offline user.
     //TODO fix the capability used here!!!
     if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/backup/export_incremental.php?id=' . $COURSE->id . '">' . get_string('export', 'local') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Reset this course
     if ($course->id !== SITEID and has_capability('moodle/course:reset', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/reset.php?id=' . $this->instance->pageid . '">' . get_string('reset') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/return.gif" class="icon" alt="" />';
     }
     /// View course reports
     if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/report.php?id=' . $this->instance->pageid . '">' . get_string('reports') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/stats.gif" class="icon" alt="" />';
     }
     /// Manage questions
     if ($course->id !== SITEID) {
         $questionlink = '';
         $questioncaps = array('moodle/question:add', 'moodle/question:editmine', 'moodle/question:editall', 'moodle/question:viewmine', 'moodle/question:viewall', 'moodle/question:movemine', 'moodle/question:moveall');
         foreach ($questioncaps as $questioncap) {
             if (has_capability($questioncap, $context)) {
                 $questionlink = 'edit.php';
                 break;
             }
         }
         if (!$questionlink && has_capability('moodle/question:managecategory', $context)) {
             $questionlink = 'category.php';
         }
         if ($questionlink) {
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/question/' . $questionlink . '?courseid=' . $this->instance->pageid . '">' . get_string('questions', 'quiz') . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/questions.gif" class="icon" alt="" />';
         }
     }
     /// Manage files
     if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '">' . get_string('files') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/files.gif" class="icon" alt="" />';
     }
     /// Authorize hooks
     if ($course->enrol == 'authorize' || empty($course->enrol) && $CFG->enrol == 'authorize' && $course->id !== SITEID) {
         require_once $CFG->dirroot . '/enrol/authorize/const.php';
         $paymenturl = '<a href="' . $CFG->wwwroot . '/enrol/authorize/index.php?course=' . $course->id . '">' . get_string('payments') . '</a> ';
         if (has_capability('enrol/authorize:managepayments', $context)) {
             if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
                 $paymenturl .= '<a href="' . $CFG->wwwroot . '/enrol/authorize/index.php?status=' . AN_STATUS_AUTH . '&amp;course=' . $course->id . '">' . get_string('paymentpending', 'moodle', $cnt) . '</a>';
             }
         }
         $this->content->items[] = $paymenturl;
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/payment.gif" class="icon" alt="" />';
     }
     /// Unenrol link
     if (empty($course->metacourse) && $course->id !== SITEID) {
         if (has_capability('moodle/legacy:guest', $context, NULL, false)) {
             // Are a guest now
             $this->content->items[] = '<a href="enrol.php?id=' . $this->instance->pageid . '">' . get_string('enrolme', '', format_string($course->shortname)) . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" class="icon" alt="" />';
         } else {
             if (has_capability('moodle/role:unassignself', $context, NULL, false) and get_user_roles($context, $USER->id, false)) {
                 // Have some role
                 $this->content->items[] = '<a href="unenrol.php?id=' . $this->instance->pageid . '">' . get_string('unenrolme', '', format_string($course->shortname)) . '</a>';
                 $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" class="icon" alt="" />';
             }
         }
     }
     /// Link to the user own profile
     $this->content->items[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $USER->id . '&amp;course=' . $course->id . '">' . get_string('profile') . '</a>';
     $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" alt="" />';
     return $this->content;
 }
/**
 * 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 . '&amp;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 . '&amp;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);
        }
    }
}
Esempio n. 24
0
        $weekperiod = $weekday . ' - ' . $endweekday;
        echo '<div class="content">';
        if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {
            // Hidden for students
            print_heading($currenttext . $weekperiod . ' (' . get_string('notavailable') . ')', null, 3, 'weekdates');
        } else {
            print_heading($currenttext . $weekperiod, null, 3, 'weekdates');
            echo '<div class="summary">';
            $summaryformatoptions->noclean = true;
            echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
            if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
                echo ' <a title="' . $streditsummary . '" href="editsection.php?id=' . $thissection->id . '">' . '<img src="' . $CFG->pixpath . '/t/edit.gif" class="icon edit" alt="' . $streditsummary . '" /></a><br /><br />';
            }
            echo '</div>';
            print_section($course, $thissection, $mods, $modnamesused);
            if (isediting($course->id)) {
                print_section_add_menus($course, $section, $modnames);
            }
        }
        echo '</div>';
        echo "</li>\n";
    }
    $section++;
    $weekdate = $nextweekdate;
}
echo "</ul>\n";
if (!empty($sectionmenu)) {
    echo '<div align="center" class="jumpmenu">';
    echo popup_form($CFG->wwwroot . '/course/view.php?id=' . $course->id . '&amp;', $sectionmenu, 'sectionmenu', '', get_string('jumpto'), '', '', true);
    echo '</div>';
}
Esempio n. 25
0
 function get_content()
 {
     global $CFG, $USER, $SITE, $COURSE;
     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 = '';
     } else {
         if ($this->instance->pageid == SITEID) {
             // return $this->content = '';
         }
     }
     if (!empty($this->instance->pageid)) {
         $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
         if ($COURSE->id == $this->instance->pageid) {
             $course = $COURSE;
         } else {
             $course = get_record('course', 'id', $this->instance->pageid);
         }
     } else {
         $context = get_context_instance(CONTEXT_SYSTEM);
         $course = $SITE;
     }
     if (!has_capability('moodle/course:view', $context)) {
         // Just return
         return $this->content;
     }
     if (empty($CFG->loginhttps)) {
         $securewwwroot = $CFG->wwwroot;
     } else {
         $securewwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     }
     /// Course editing on/off
     if (has_capability('moodle/course:update', $context) && $course->id !== SITEID) {
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/edit.gif" class="icon" alt="" />';
         if (isediting($this->instance->pageid)) {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=off&amp;sesskey=' . sesskey() . '">' . get_string('turneditingoff') . '</a>';
         } else {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=on&amp;sesskey=' . sesskey() . '">' . get_string('turneditingon') . '</a>';
         }
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/edit.php?id=' . $this->instance->pageid . '">' . get_string('settings') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/settings.gif" class="icon" alt="" />';
     }
     /// Assign roles to the course
     if (has_capability('moodle/role:assign', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php?contextid=' . $context->id . '">' . get_string('assignroles', 'role') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/roles.gif" class="icon" alt="" />';
     }
     /// View course grades (or just your own grades, same link)
     if ((has_capability('moodle/grade:viewall', $context) or has_capability('moodle/grade:view', $context) && $course->showgrades) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/report/index.php?id=' . $this->instance->pageid . '">' . get_string('grades') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/grades.gif" class="icon" alt="" />';
     }
     /// Course outcomes (to help give it more prominence because it's important)
     if (!empty($CFG->enableoutcomes)) {
         if (has_capability('moodle/course:update', $context) && $course->id !== SITEID) {
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/edit/outcome/course.php?id=' . $this->instance->pageid . '">' . get_string('outcomes', 'grades') . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/outcomes.gif" class="icon" alt="" />';
         }
     }
     /// Manage metacourses
     if ($course->metacourse) {
         if (has_capability('moodle/course:managemetacourse', $context)) {
             $strchildcourses = get_string('childcourses');
             $this->content->items[] = '<a href="importstudents.php?id=' . $this->instance->pageid . '">' . $strchildcourses . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/course.gif" class="icon" alt="" />';
         } else {
             if (has_capability('moodle/role:assign', $context)) {
                 $strchildcourses = get_string('childcourses');
                 $this->content->items[] = '<span class="dimmed_text">' . $strchildcourses . '</span>';
                 $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/course.gif" class="icon" alt="" />';
             }
         }
     }
     /// Manage groups in this course
     if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context) && $course->id !== SITEID) {
         $strgroups = get_string('groups');
         $this->content->items[] = '<a title="' . $strgroups . '" href="' . $CFG->wwwroot . '/group/index.php?id=' . $this->instance->pageid . '">' . $strgroups . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/group.gif" class="icon" alt="" />';
     }
     /// Backup this course
     if (has_capability('moodle/site:backup', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/backup/backup.php?id=' . $this->instance->pageid . '">' . get_string('backup') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/backup.gif" class="icon" alt="" />';
     }
     /// Restore to this course
     if (has_capability('moodle/site:restore', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '&amp;wdir=/backupdata">' . get_string('restore') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Import data from other courses
     if (has_capability('moodle/site:import', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/import.php?id=' . $this->instance->pageid . '">' . get_string('import') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Reset this course
     if (has_capability('moodle/course:reset', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/reset.php?id=' . $this->instance->pageid . '">' . get_string('reset') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/return.gif" class="icon" alt="" />';
     }
     /// View course reports
     if (has_capability('moodle/site:viewreports', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/report.php?id=' . $this->instance->pageid . '">' . get_string('reports') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/stats.gif" class="icon" alt="" />';
     }
     /// Manage questions
     if ($course->id !== SITEID) {
         $questioncaps = array('moodle/question:add', 'moodle/question:editmine', 'moodle/question:editall', 'moodle/question:viewmine', 'moodle/question:viewall', 'moodle/question:movemine', 'moodle/question:moveall');
         $questionpermission = false;
         foreach ($questioncaps as $questioncap) {
             if (has_capability($questioncap, $context)) {
                 $questionpermission = true;
                 break;
             }
         }
         if ($questionpermission) {
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/question/edit.php?courseid=' . $this->instance->pageid . '">' . get_string('questions', 'quiz') . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/questions.gif" class="icon" alt="" />';
         }
     }
     /// Manage files
     if (has_capability('moodle/course:managefiles', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '">' . get_string('files') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/files.gif" class="icon" alt="" />';
     }
     /// Authorize hooks
     if ($course->enrol == 'authorize' || empty($course->enrol) && $CFG->enrol == 'authorize' && $course->id !== SITEID) {
         require_once $CFG->dirroot . '/enrol/authorize/const.php';
         $paymenturl = '<a href="' . $CFG->wwwroot . '/enrol/authorize/index.php?course=' . $course->id . '">' . get_string('payments') . '</a> ';
         if (has_capability('enrol/authorize:managepayments', $context)) {
             if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
                 $paymenturl .= '<a href="' . $CFG->wwwroot . '/enrol/authorize/index.php?status=' . AN_STATUS_AUTH . '&amp;course=' . $course->id . '">' . get_string('paymentpending', 'moodle', $cnt) . '</a>';
             }
         }
         $this->content->items[] = $paymenturl;
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/payment.gif" class="icon" alt="" />';
     }
     /// Unenrol link
     if (empty($course->metacourse) && $course->id !== SITEID) {
         if (has_capability('moodle/legacy:guest', $context, NULL, false)) {
             // Are a guest now
             $this->content->items[] = '<a href="enrol.php?id=' . $this->instance->pageid . '">' . get_string('enrolme', '', format_string($course->shortname)) . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" class="icon" alt="" />';
         } else {
             if (has_capability('moodle/role:unassignself', $context, NULL, false)) {
                 // Have some role
                 $this->content->items[] = '<a href="unenrol.php?id=' . $this->instance->pageid . '">' . get_string('unenrolme', '', format_string($course->shortname)) . '</a>';
                 $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" class="icon" alt="" />';
             }
         }
     }
     /// Should the following two be in this block?
     /// View own activity report
     //        if ($course->showreports) {
     //            $this->content->items[]='<a href="user.php?id='.$this->instance->pageid.'&amp;user='******'">'.get_string('activityreport').'</a>';
     //            $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/report.gif" alt="" />';
     //        }
     /// Edit your own profile
     //        $fullname = fullname($USER, has_capability('moodle/site:viewfullnames', $context));
     //        $editmyprofile = '<a title="'.$fullname.'" href="'.$CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&amp;course='.$this->instance->pageid.'">'.get_string('editmyprofile').'</a>';
     //        if (empty($USER->description)) {
     //                //Accessibility: replace non-standard <blink> with CSS (<a> makes title visible in IE).
     //            $text = get_string('profile').' '.get_string('missingdescription');
     //            $this->content->items[]= $editmyprofile.' <a title="'.$text.'" class="useredit blink">*<span class="accesshide">'.$text.'</span></a>';
     //        } else {
     //            $this->content->items[]= $editmyprofile;
     //        }
     //        $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" alt="" />';
     return $this->content;
 }
Esempio n. 26
0
function scorm_course_format_display($user, $course)
{
    global $CFG;
    $strupdate = get_string('update');
    $strmodule = get_string('modulename', 'scorm');
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    echo '<div class="mod-scorm">';
    if ($scorms = get_all_instances_in_course('scorm', $course)) {
        // The module SCORM activity with the least id is the course
        $scorm = current($scorms);
        if (!($cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id))) {
            error('Course Module ID was incorrect');
        }
        $colspan = '';
        $headertext = '<table width="100%"><tr><td class="title">' . get_string('name') . ': <b>' . format_string($scorm->name) . '</b>';
        if (has_capability('moodle/course:manageactivities', $context)) {
            if (isediting($course->id)) {
                // Display update icon
                $path = $CFG->wwwroot . '/course';
                $headertext .= '<span class="commands">' . '<a title="' . $strupdate . '" href="' . $path . '/mod.php?update=' . $cm->id . '&amp;sesskey=' . sesskey() . '">' . '<img src="' . $CFG->pixpath . '/t/edit.gif" class="iconsmall" alt="' . $strupdate . '" /></a></span>';
            }
            $headertext .= '</td>';
            // Display report link
            $trackedusers = get_record('scorm_scoes_track', 'scormid', $scorm->id, '', '', '', '', 'count(distinct(userid)) as c');
            if ($trackedusers->c > 0) {
                $headertext .= '<td class="reportlink">' . '<a ' . $CFG->frametarget . '" href="' . $CFG->wwwroot . '/mod/scorm/report.php?id=' . $cm->id . '">' . get_string('viewallreports', 'scorm', $trackedusers->c) . '</a>';
            } else {
                $headertext .= '<td class="reportlink">' . get_string('noreports', 'scorm');
            }
            $colspan = ' colspan="2"';
        }
        $headertext .= '</td></tr><tr><td' . $colspan . '>' . format_text(get_string('summary') . ':<br />' . $scorm->summary) . '</td></tr></table>';
        print_simple_box($headertext, '', '100%');
        scorm_view_display($user, $scorm, 'view.php?id=' . $course->id, $cm, '100%');
    } else {
        if (has_capability('moodle/course:update', $context)) {
            // Create a new activity
            redirect($CFG->wwwroot . '/course/mod.php?id=' . $course->id . '&amp;section=0&sesskey=' . sesskey() . '&amp;add=scorm');
        } else {
            notify('Could not find a scorm course here');
        }
    }
    echo '</div>';
}
Esempio n. 27
0
 function get_content()
 {
     global $CFG, $USER, $SITE;
     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 = '';
     } else {
         if ($this->instance->pageid == SITEID) {
             // return $this->content = '';
         }
     }
     if (!empty($this->instance->pageid)) {
         $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
     }
     if (empty($context)) {
         $context = get_context_instance(CONTEXT_SYSTEM);
     }
     if (!($course = get_record('course', 'id', $this->instance->pageid))) {
         $course = $SITE;
     }
     if (!has_capability('moodle/course:view', $context)) {
         // Just return
         return $this->content;
     }
     if (empty($CFG->loginhttps)) {
         $securewwwroot = $CFG->wwwroot;
     } else {
         $securewwwroot = str_replace('http:', 'https:', $CFG->wwwroot);
     }
     /// Course editing on/off
     if (has_capability('moodle/course:update', $context) && $course->id !== SITEID) {
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/edit.gif" class="icon" alt="" />';
         if (isediting($this->instance->pageid)) {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=off&amp;sesskey=' . sesskey() . '">' . get_string('turneditingoff') . '</a>';
         } else {
             $this->content->items[] = '<a href="view.php?id=' . $this->instance->pageid . '&amp;edit=on&amp;sesskey=' . sesskey() . '">' . get_string('turneditingon') . '</a>';
         }
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/edit.php?id=' . $this->instance->pageid . '">' . get_string('settings') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/settings.gif" class="icon" alt="" />';
     }
     /// Assign roles to the course
     if (has_capability('moodle/role:assign', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/roles/assign.php?contextid=' . $context->id . '">' . get_string('assignroles', 'role') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/roles.gif" class="icon" alt="" />';
     }
     /// Manage metacourses
     if ($course->metacourse) {
         if (has_capability('moodle/course:managemetacourse', $context)) {
             $strchildcourses = get_string('childcourses');
             $this->content->items[] = '<a href="importstudents.php?id=' . $this->instance->pageid . '">' . $strchildcourses . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/course.gif" class="icon" alt="" />';
         } else {
             if (has_capability('moodle/role:assign', $context)) {
                 $strchildcourses = get_string('childcourses');
                 $this->content->items[] = '<span class="dimmed_text">' . $strchildcourses . '</span>';
                 $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/course.gif" class="icon" alt="" />';
             }
         }
     }
     /// Manage groups in this course
     if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context) && $course->id !== SITEID) {
         $strgroups = get_string('groups');
         $this->content->items[] = '<a title="' . $strgroups . '" href="' . groups_home_url($this->instance->pageid) . '">' . $strgroups . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/group.gif" class="icon" alt="" />';
     }
     /// Backup this course
     if (has_capability('moodle/site:backup', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/backup/backup.php?id=' . $this->instance->pageid . '">' . get_string('backup') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/backup.gif" class="icon" alt="" />';
     }
     /// Restore to this course
     if (has_capability('moodle/site:restore', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '&amp;wdir=/backupdata">' . get_string('restore') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Import data from other courses
     if (has_capability('moodle/site:import', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/import.php?id=' . $this->instance->pageid . '">' . get_string('import') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/restore.gif" class="icon" alt="" />';
     }
     /// Reset this course
     if (has_capability('moodle/course:reset', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/reset.php?id=' . $this->instance->pageid . '">' . get_string('reset') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/return.gif" class="icon" alt="" />';
     }
     /// View course reports
     if (has_capability('moodle/site:viewreports', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/report.php?id=' . $this->instance->pageid . '">' . get_string('reports') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/stats.gif" class="icon" alt="" />';
     }
     /// Manage questions
     if (has_capability('moodle/question:manage', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/question/edit.php?courseid=' . $this->instance->pageid . '&amp;clean=true">' . get_string('questions', 'quiz') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/questions.gif" class="icon" alt="" />';
     }
     /// Manage scales
     if (has_capability('moodle/course:managescales', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="scales.php?id=' . $this->instance->pageid . '">' . get_string('scales') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/scales.gif" class="icon" alt="" />';
     }
     /// Manage files
     if (has_capability('moodle/course:managefiles', $context) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/files/index.php?id=' . $this->instance->pageid . '">' . get_string('files') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/files.gif" class="icon" alt="" />';
     }
     /// Authorize hooks
     if ($course->enrol == 'authorize' || empty($course->enrol) && $CFG->enrol == 'authorize' && $course->id !== SITEID) {
         require_once $CFG->dirroot . '/enrol/authorize/const.php';
         $paymenturl = '<a href="' . $CFG->wwwroot . '/enrol/authorize/index.php?course=' . $course->id . '">' . get_string('payments') . '</a> ';
         if (has_capability('enrol/authorize:managepayments', $context)) {
             if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
                 $paymenturl .= '<a href="' . $CFG->wwwroot . '/enrol/authorize/index.php?status=' . AN_STATUS_AUTH . '&amp;course=' . $course->id . '">' . get_string('paymentpending', 'moodle', $cnt) . '</a>';
             }
         }
         $this->content->items[] = $paymenturl;
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/payment.gif" class="icon" alt="" />';
     }
     /// View course grades (or just your own grades, same link)
     if ((has_capability('moodle/course:viewcoursegrades', $context) or has_capability('moodle/user:viewusergrades', $context) && $course->showgrades) && $course->id !== SITEID) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/grade/index.php?id=' . $this->instance->pageid . '">' . get_string('grades') . '</a>';
         $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/grades.gif" class="icon" alt="" />';
     }
     if (empty($course->metacourse) && $course->id !== SITEID) {
         if (has_capability('moodle/legacy:guest', $context, NULL, false)) {
             // Are a guest now
             $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/enrol.php?id=' . $this->instance->pageid . '">' . get_string('enrolme', '', format_string($course->shortname)) . '</a>';
             $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" class="icon" alt="" />';
         } else {
             if (has_capability('moodle/role:unassignself', $context, NULL, false)) {
                 // Have some role
                 $this->content->items[] = '<a href="' . $CFG->wwwroot . '/course/unenrol.php?id=' . $this->instance->pageid . '">' . get_string('unenrolme', '', format_string($course->shortname)) . '</a>';
                 $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" class="icon" alt="" />';
             }
         }
     }
     /// Link to the user own profile
     $this->content->items[] = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $USER->id . '&amp;course=' . $course->id . '">' . get_string('profile') . '</a>';
     $this->content->icons[] = '<img src="' . $CFG->pixpath . '/i/user.gif" alt="" />';
     return $this->content;
 }