/** * Add content to a block instance. This * method should fail gracefully. Do not * call something like error() * * @param object $block Passed by refernce: this is the block instance object * Course Module Record is $block->cm * Module Record is $block->module * Module Instance Record is $block->moduleinstance * Course Record is $block->course * * @return boolean If an error occures, just return false and * optionally set error message to $block->content->text * Otherwise keep $block->content->text empty on errors **/ function set_instance(&$block) { global $CFG; require_once $CFG->dirroot . '/mod/forum/lib.php'; ob_start(); forum_print_latest_discussions($block->course, $block->moduleinstance, 0); $block->content->text = ob_get_contents(); ob_end_clean(); return true; }
if (!empty($USER->id)) { $SESSION->fromdiscussion = $CFG->wwwroot; $subtext = ''; if (forum_is_subscribed($USER->id, $newsforum)) { if (!forum_is_forcesubscribed($newsforum)) { $subtext = get_string('unsubscribe', 'forum'); } } else { $subtext = get_string('subscribe', 'forum'); } print_heading_block($newsforum->name); echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id=' . $newsforum->id . '">' . $subtext . '</a></div>'; } else { print_heading_block($newsforum->name); } forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC'); } break; case FRONTPAGECOURSELIST: if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) { print_heading_block(get_string('mycourses')); print_my_moodle(); } else { if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or count_records('course') <= FRONTPAGECOURSELIMIT) { // admin should not see list of courses when there are too many of them print_heading_block(get_string('availablecourses')); print_courses(0); } } break; case FRONTPAGECATEGORYNAMES:
print_string("allowsdiscussions", "forum"); } else { echo ' '; } echo '</p>'; if (!empty($showall)) { forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); } else { forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); } break; case 'teacher': if (!empty($showall)) { forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); } else { forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); } break; default: if (!empty($forum->intro)) { print_box(format_text($forum->intro), 'generalbox', 'intro'); } echo '<br />'; if (!empty($showall)) { forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); } else { forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); } break; } print_footer($course);
case 'blog': if (!empty($forum->intro)) { echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro'); } echo '<br />'; if (!empty($showall)) { forum_print_latest_discussions($course, $forum, 0, 'plain', '', -1, -1, -1, 0, $cm); } else { forum_print_latest_discussions($course, $forum, -1, 'plain', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm); } break; default: if (!empty($forum->intro)) { echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro'); } echo '<br />'; if (!empty($showall)) { forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm); } else { forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm); } break; } echo $OUTPUT->footer($course);
if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) { echo '<td style="width:' . $preferred_width_left . 'px" id="left-column">'; print_container_start(); blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT); print_container_end(); echo '</td>'; } echo '<td id="middle-column">'; print_container_start(); echo skip_main_destination(); if ($forum = forum_get_course_forum($course->id, 'social')) { print_heading_block(get_string('socialheadline')); $cm = get_coursemodule_from_instance('forum', $forum->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); echo '<div class="subscribelink">', forum_get_subscribe_link($forum, $context), '</div>'; forum_print_latest_discussions($course, $forum, 10, 'plain', '', false); } else { notify('Could not find or create a social forum here'); } print_container_end(); echo '</td>'; // The right column if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) { echo '<td style="width:' . $preferred_width_right . 'px" id="right-column">'; print_container_start(); blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT); print_container_end(); echo '</td>'; } echo '</tr>'; echo '</table>';
function cms_render_news($course) { global $CFG; if ($course->newsitems) { // Print forums only when needed require_once $CFG->dirroot . '/mod/forum/lib.php'; if (!($newsforum = forum_get_course_forum($course->id, 'news'))) { error('Could not find or create a main news forum for the course'); } if (isset($USER->id)) { $SESSION->fromdiscussion = $CFG->wwwroot; if (forum_is_subscribed($USER->id, $newsforum->id)) { $subtext = get_string('unsubscribe', 'forum'); } else { $subtext = get_string('subscribe', 'forum'); } $headertext = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>' . '<td><div class="title">' . $newsforum->name . '</div></td>' . '<td><div class="link"><a href="mod/forum/subscribe.php?id=' . $newsforum->id . '">' . $subtext . '</a></div></td>' . '</tr></table>'; } else { $headertext = $newsforum->name; } ob_start(); print_heading_block($headertext); forum_print_latest_discussions($course, $newsforum, $course->newsitems, 'plain', 'p.modified DESC'); $return = ob_get_contents(); ob_end_clean(); return $return; } return ''; }
/** * Called from {@link page_print_position()} and it is * supposed to print the front page settings in the * center column for the site course and only for * the default page (EG: the landing page). * * @return boolean **/ function page_frontpage_settings() { global $CFG, $SESSION, $SITE, $PAGE, $COURSE; // Cheap check first - course ID if ($COURSE->id != SITEID) { return false; } // More expensive check - make sure we are viewing default page $default = page_get_default_page(); $current = $PAGE->get_formatpage(); if (empty($default->id) or empty($current->id) or $default->id != $current->id) { return false; } $editing = $PAGE->user_is_editing(); /// START COPY/PASTE FROM INDEX.PHP print_container_start(); /// Print Section if ($SITE->numsections > 0) { if (!($section = get_record('course_sections', 'course', $SITE->id, 'section', 1))) { delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case $section->course = $SITE->id; $section->section = 1; $section->summary = ''; $section->sequence = ''; $section->visible = 1; $section->id = insert_record('course_sections', $section); } if (!empty($section->sequence) or !empty($section->summary) or $editing) { print_box_start('generalbox sitetopic'); /// If currently moving a file then show the current clipboard if (ismoving($SITE->id)) { $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname))); echo '<p><font size="2">'; echo "{$stractivityclipboard} (<a href=\"course/mod.php?cancelcopy=true&sesskey={$USER->sesskey}\">" . get_string('cancel') . '</a>)'; echo '</font></p>'; } $options = NULL; $options->noclean = true; echo format_text($section->summary, FORMAT_HTML, $options); if ($editing) { $streditsummary = get_string('editsummary'); echo "<a title=\"{$streditsummary}\" " . " href=\"course/editsection.php?id={$section->id}\"><img src=\"{$CFG->pixpath}/t/edit.gif\" " . " class=\"iconsmall\" alt=\"{$streditsummary}\" /></a><br /><br />"; } get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); print_section($SITE, $section, $mods, $modnamesused, true); if ($editing) { print_section_add_menus($SITE, $section->section, $modnames); } print_box_end(); } } if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) { $frontpagelayout = $CFG->frontpageloggedin; } else { $frontpagelayout = $CFG->frontpage; } foreach (explode(',', $frontpagelayout) as $v) { switch ($v) { /// Display the main part of the front page. case FRONTPAGENEWS: if ($SITE->newsitems) { // Print forums only when needed require_once $CFG->dirroot . '/mod/forum/lib.php'; if (!($newsforum = forum_get_course_forum($SITE->id, 'news'))) { error('Could not find or create a main news forum for the site'); } if (!empty($USER->id)) { $SESSION->fromdiscussion = $CFG->wwwroot; if (forum_is_subscribed($USER->id, $newsforum)) { $subtext = get_string('unsubscribe', 'forum'); } else { $subtext = get_string('subscribe', 'forum'); } print_heading_block($newsforum->name); echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id=' . $newsforum->id . '">' . $subtext . '</a></div>'; } else { print_heading_block($newsforum->name); } forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC'); } break; case FRONTPAGECOURSELIST: if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) { print_heading_block(get_string('mycourses')); print_my_moodle(); } else { if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() or count_records('course') <= FRONTPAGECOURSELIMIT) { // admin should not see list of courses when there are too many of them print_heading_block(get_string('availablecourses')); print_courses(0); } } break; case FRONTPAGECATEGORYNAMES: print_heading_block(get_string('categories')); print_box_start('generalbox categorybox'); print_whole_category_list(NULL, NULL, NULL, -1, false); print_box_end(); print_course_search('', false, 'short'); break; case FRONTPAGECATEGORYCOMBO: print_heading_block(get_string('categories')); print_box_start('generalbox categorybox'); print_whole_category_list(NULL, NULL, NULL, -1, true); print_box_end(); print_course_search('', false, 'short'); break; case FRONTPAGETOPICONLY: // Do nothing!! :-) break; } // echo '<br />'; REMOVED FOR THE FORMAT } print_container_end(); /// END COPY/PASTE FROM INDEX.PHP return true; }
/** * Prints the news forum as simple compact list of discussion headers. */ function local_my_print_latestnews_headers() { global $PAGE, $SITE, $CFG, $OUTPUT, $USER, $SESSION; $str = ''; if ($SITE->newsitems) { // Print forums only when needed. require_once $CFG->dirroot . '/mod/forum/lib.php'; if (!($newsforum = forum_get_course_forum($SITE->id, 'news'))) { print_error('cannotfindorcreateforum', 'forum'); } $renderer = $PAGE->get_renderer('local_my'); $renderer->print_forum_link($newforum); if (isloggedin()) { if (!isset($SESSION)) { $SESSION = new StdClass(); } $SESSION->fromdiscussion = $CFG->wwwroot; $subtext = ''; if (forum_is_subscribed($USER->id, $newsforum)) { if (!forum_is_forcesubscribed($newsforum)) { $subtext = get_string('unsubscribe', 'forum'); } } else { $subtext = get_string('subscribe', 'forum'); } $str .= '<div class="block block_my_newsheads">'; $str .= '<div class="header">'; $str .= '<div class="title">'; $str .= '<h2>' . $forumname . '</h2>'; $str .= '</div>'; $str .= '</div>'; $str .= '<div class="content">'; $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey())); $str .= html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink')); $str .= '</div>'; } else { $str .= '<div class="block block_my_newsheads">'; $str .= '<div class="header">'; $str .= '<div class="title">'; $str .= $OUTPUT->heading($forumname, 2, 'headingblock header'); $str .= '</div>'; $str .= '</div>'; } ob_start(); forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'header', 'p.modified DESC'); $str .= ob_get_clean(); $str .= '</div>'; $str .= html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews')); } return $str; }
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}&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 " "; 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 . '&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 . '&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 . '&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 . '&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}" . '&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; }