$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;
                     $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:
Exemple #2
0
     // there should not be any links leading to this place, just redirect
     redirect(new moodle_url('/mod/forum/index.php', array('id' => $id)), get_string('subscribeenrolledonly', 'forum'));
 }
 // Can proceed now, the user is not guest and is enrolled
 foreach ($modinfo->get_instances_of('forum') as $forumid => $cm) {
     $forum = $forums[$forumid];
     $modcontext = context_module::instance($cm->id);
     $cansub = false;
     if (has_capability('mod/forum:viewdiscussion', $modcontext)) {
         $cansub = true;
     }
     if ($cansub && $cm->visible == 0 && !has_capability('mod/forum:managesubscriptions', $modcontext)) {
         $cansub = false;
     }
     if (!forum_is_forcesubscribed($forum)) {
         $subscribed = forum_is_subscribed($USER->id, $forum);
         if ((has_capability('moodle/course:manageactivities', $coursecontext, $USER->id) || $forum->forcesubscribe != FORUM_DISALLOWSUBSCRIBE) && $subscribe && !$subscribed && $cansub) {
             forum_subscribe($USER->id, $forumid, $modcontext);
         } else {
             if (!$subscribe && $subscribed) {
                 forum_unsubscribe($USER->id, $forumid, $modcontext);
             }
         }
     }
 }
 $returnto = forum_go_back_to("index.php?id={$course->id}");
 $shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
 if ($subscribe) {
     redirect($returnto, get_string('nowallsubscribed', 'forum', $shortname), 1);
 } else {
     redirect($returnto, get_string('nowallunsubscribed', 'forum', $shortname), 1);
Exemple #3
0
/**
 * Adds module specific settings to the settings block
 *
 * @param settings_navigation $settings The settings navigation object
 * @param navigation_node $forumnode The node to add module settings to
 */
function forum_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $forumnode) {
    global $USER, $PAGE, $CFG, $DB, $OUTPUT;

    $forumobject = $DB->get_record("forum", array("id" => $PAGE->cm->instance));
    if (empty($PAGE->cm->context)) {
        $PAGE->cm->context = context_module::instance($PAGE->cm->instance);
    }

    // for some actions you need to be enrolled, beiing admin is not enough sometimes here
    $enrolled = is_enrolled($PAGE->cm->context, $USER, '', false);
    $activeenrolled = is_enrolled($PAGE->cm->context, $USER, '', true);

    $canmanage  = has_capability('mod/forum:managesubscriptions', $PAGE->cm->context);
    $subscriptionmode = forum_get_forcesubscribed($forumobject);
    $cansubscribe = ($activeenrolled && $subscriptionmode != FORUM_FORCESUBSCRIBE && ($subscriptionmode != FORUM_DISALLOWSUBSCRIBE || $canmanage));

    if ($canmanage) {
        $mode = $forumnode->add(get_string('subscriptionmode', 'forum'), null, navigation_node::TYPE_CONTAINER);

        $allowchoice = $mode->add(get_string('subscriptionoptional', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_CHOOSESUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);
        $forceforever = $mode->add(get_string("subscriptionforced", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_FORCESUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);
        $forceinitially = $mode->add(get_string("subscriptionauto", "forum"), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_INITIALSUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);
        $disallowchoice = $mode->add(get_string('subscriptiondisabled', 'forum'), new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'mode'=>FORUM_DISALLOWSUBSCRIBE, 'sesskey'=>sesskey())), navigation_node::TYPE_SETTING);

        switch ($subscriptionmode) {
            case FORUM_CHOOSESUBSCRIBE : // 0
                $allowchoice->action = null;
                $allowchoice->add_class('activesetting');
                break;
            case FORUM_FORCESUBSCRIBE : // 1
                $forceforever->action = null;
                $forceforever->add_class('activesetting');
                break;
            case FORUM_INITIALSUBSCRIBE : // 2
                $forceinitially->action = null;
                $forceinitially->add_class('activesetting');
                break;
            case FORUM_DISALLOWSUBSCRIBE : // 3
                $disallowchoice->action = null;
                $disallowchoice->add_class('activesetting');
                break;
        }

    } else if ($activeenrolled) {

        switch ($subscriptionmode) {
            case FORUM_CHOOSESUBSCRIBE : // 0
                $notenode = $forumnode->add(get_string('subscriptionoptional', 'forum'));
                break;
            case FORUM_FORCESUBSCRIBE : // 1
                $notenode = $forumnode->add(get_string('subscriptionforced', 'forum'));
                break;
            case FORUM_INITIALSUBSCRIBE : // 2
                $notenode = $forumnode->add(get_string('subscriptionauto', 'forum'));
                break;
            case FORUM_DISALLOWSUBSCRIBE : // 3
                $notenode = $forumnode->add(get_string('subscriptiondisabled', 'forum'));
                break;
        }
    }

    if ($cansubscribe) {
        if (forum_is_subscribed($USER->id, $forumobject)) {
            $linktext = get_string('unsubscribe', 'forum');
        } else {
            $linktext = get_string('subscribe', 'forum');
        }
        $url = new moodle_url('/mod/forum/subscribe.php', array('id'=>$forumobject->id, 'sesskey'=>sesskey()));
        $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
    }

    if (has_capability('mod/forum:viewsubscribers', $PAGE->cm->context)){
        $url = new moodle_url('/mod/forum/subscribers.php', array('id'=>$forumobject->id));
        $forumnode->add(get_string('showsubscribers', 'forum'), $url, navigation_node::TYPE_SETTING);
    }

    if ($enrolled && forum_tp_can_track_forums($forumobject)) { // keep tracking info for users with suspended enrolments
        if ($forumobject->trackingtype != FORUM_TRACKING_OPTIONAL) {
            //tracking forced on or off in forum settings so dont provide a link here to change it
            //could add unclickable text like for forced subscription but not sure this justifies adding another menu item
        } else {
            if (forum_tp_is_tracked($forumobject)) {
                $linktext = get_string('notrackforum', 'forum');
            } else {
                $linktext = get_string('trackforum', 'forum');
            }
            $url = new moodle_url('/mod/forum/settracking.php', array('id'=>$forumobject->id));
            $forumnode->add($linktext, $url, navigation_node::TYPE_SETTING);
        }
    }

    if (!isloggedin() && $PAGE->course->id == SITEID) {
        $userid = guest_user()->id;
    } else {
        $userid = $USER->id;
    }

    $hascourseaccess = ($PAGE->course->id == SITEID) || can_access_course($PAGE->course, $userid);
    $enablerssfeeds = !empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds);

    if ($enablerssfeeds && $forumobject->rsstype && $forumobject->rssarticles && $hascourseaccess) {

        if (!function_exists('rss_get_url')) {
            require_once("$CFG->libdir/rsslib.php");
        }

        if ($forumobject->rsstype == 1) {
            $string = get_string('rsssubscriberssdiscussions','forum');
        } else {
            $string = get_string('rsssubscriberssposts','forum');
        }

        $url = new moodle_url(rss_get_url($PAGE->cm->context->id, $userid, "mod_forum", $forumobject->id));
        $forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
    }
}
Exemple #4
0
            forum_print_posts_threaded($parent->id, $course->id, 0, false, false, $user_read_array, $discussion->forum, $modcontext);
        }
    }
    $heading = get_string("yourreply", "forum");
} else {
    $forum->intro = trim($forum->intro);
    if (!empty($forum->intro)) {
        print_box(format_text($forum->intro), 'generalbox', 'intro');
    }
    if ($forum->type == 'qanda') {
        $heading = get_string('yournewquestion', 'forum');
    } else {
        $heading = get_string('yournewtopic', 'forum');
    }
}
if ($USER->id != $post->userid) {
    // Not the original author, so add a message to the end
    $data->date = userdate($post->modified);
    if ($post->format == FORMAT_HTML) {
        $data->name = '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $USER->id . '&course=' . $post->course . '">' . fullname($USER) . '</a>';
        $post->message .= '<p>(<span class="edited">' . get_string('editedby', 'forum', $data) . '</span>)</p>';
    } else {
        $data->name = fullname($USER);
        $post->message .= "\n\n(" . get_string('editedby', 'forum', $data) . ')';
    }
}
//load data into form
$subscribe = isset($post->forum) && forum_is_subscribed($USER->id, $post->forum) || !empty($USER->autosubscribe);
$mform_post->set_data(array('general' => $heading, 'subject' => $post->subject, 'message' => $post->message, 'subscribe' => $subscribe ? 1 : 0, 'mailnow' => !empty($post->mailnow), 'userid' => $post->userid, 'parent' => $post->parent, 'discussion' => $post->discussion, 'course' => $course->id) + $page_params + (isset($post->format) ? array('format' => $post->format) : array()) + (isset($dicussion->timestart) ? array('timestart' => $discussion->timestart) : array()) + (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) + (isset($post->groupid) ? array('groupid' => $post->groupid) : array()) + (isset($discussion->id) ? array('discussion' => $discussion->id) : array()));
$mform_post->display();
print_footer($course);
Exemple #5
0
        $post->message .= '<p>(<span class="edited">' . get_string('editedby', 'forum', $data) . '</span>)</p>';
    } else {
        $data->name = fullname($USER);
        $post->message .= "\n\n(" . get_string('editedby', 'forum', $data) . ')';
    }
}
if (!empty($parent)) {
    $heading = get_string("yourreply", "forum");
} else {
    if ($forum->type == 'qanda') {
        $heading = get_string('yournewquestion', 'forum');
    } else {
        $heading = get_string('yournewtopic', 'forum');
    }
}
if (forum_is_subscribed($USER->id, $forum->id)) {
    $subscribe = true;
} else {
    if (forum_user_has_posted($forum->id, 0, $USER->id)) {
        $subscribe = false;
    } else {
        // user not posted yet - use subscription default specified in profile
        $subscribe = !empty($USER->autosubscribe);
    }
}
$draftid_editor = file_get_submitted_draft_itemid('message');
$currenttext = file_prepare_draft_area($draftid_editor, $modcontext->id, 'mod_forum', 'post', empty($post->id) ? null : $post->id, array('subdirs' => true), $post->message);
$mform_post->set_data(array('attachments' => $draftitemid, 'general' => $heading, 'subject' => $post->subject, 'message' => array('text' => $currenttext, 'format' => empty($post->messageformat) ? editors_get_preferred_format() : $post->messageformat, 'itemid' => $draftid_editor), 'subscribe' => $subscribe ? 1 : 0, 'mailnow' => !empty($post->mailnow), 'userid' => $post->userid, 'parent' => $post->parent, 'discussion' => $post->discussion, 'course' => $course->id) + $page_params + (isset($post->format) ? array('format' => $post->format) : array()) + (isset($discussion->timestart) ? array('timestart' => $discussion->timestart) : array()) + (isset($discussion->timeend) ? array('timeend' => $discussion->timeend) : array()) + (isset($post->groupid) ? array('groupid' => $post->groupid) : array()) + (isset($discussion->id) ? array('discussion' => $discussion->id) : array()));
if ($fromform = $mform_post->get_data()) {
    if (empty($SESSION->fromurl)) {
        $errordestination = "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}";
 /**
  * Test that the deprecated forum_is_subscribed accepts numeric forum IDs.
  */
 public function test_forum_is_subscribed_numeric()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Create a course, with a forum.
     $course = $this->getDataGenerator()->create_course();
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_CHOOSESUBSCRIBE);
     $forum = $this->getDataGenerator()->create_module('forum', $options);
     // Create a user enrolled in the course as a students.
     list($author) = $this->helper_create_users($course, 1);
     // Check that the user is currently unsubscribed to the forum.
     $this->assertFalse(forum_is_subscribed($author->id, $forum->id));
     $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
     phpunit_util::reset_debugging();
     // It should match the result of when it's called with the forum object.
     $this->assertFalse(forum_is_subscribed($author->id, $forum));
     $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
     phpunit_util::reset_debugging();
     // And when the user is subscribed, we should also get the correct result.
     \mod_forum\subscriptions::subscribe_user($author->id, $forum);
     $this->assertTrue(forum_is_subscribed($author->id, $forum->id));
     $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
     phpunit_util::reset_debugging();
     // It should match the result of when it's called with the forum object.
     $this->assertTrue(forum_is_subscribed($author->id, $forum));
     $this->assertEquals(1, count(phpunit_util::get_debugging_messages()));
     phpunit_util::reset_debugging();
 }
Exemple #7
0
$returnto = optional_param('backtoindex', 0, PARAM_INT) ? "index.php?id=" . $course->id : "view.php?f={$id}";
if ($force and has_capability('mod/forum:managesubscriptions', $context)) {
    if (forum_is_forcesubscribed($forum)) {
        forum_forcesubscribe($forum->id, 0);
        redirect($returnto, get_string("everyonecannowchoose", "forum"), 1);
    } else {
        forum_forcesubscribe($forum->id, 1);
        redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
    }
}
if (forum_is_forcesubscribed($forum)) {
    redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
}
$info->name = fullname($user);
$info->forum = format_string($forum->name);
if (forum_is_subscribed($user->id, $forum->id)) {
    if (forum_unsubscribe($user->id, $forum->id)) {
        add_to_log($course->id, "forum", "unsubscribe", "view.php?f={$forum->id}", $forum->id, $cm->id);
        redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
    } else {
        print_error('cannotunsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
    }
} else {
    // subscribe
    if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('mod/forum:managesubscriptions', $context)) {
        print_error('disallowsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
    }
    if (!has_capability('mod/forum:viewdiscussion', $context)) {
        print_error('cannotsubscribe', 'forum', $_SERVER["HTTP_REFERER"]);
    }
    if (forum_subscribe($user->id, $forum->id)) {
 /**
  * Test subscription using disallow subscription on create.
  */
 public function test_forum_disallow_subscribe_on_create()
 {
     global $CFG;
     $this->resetAfterTest();
     $usercount = 5;
     $course = $this->getDataGenerator()->create_course();
     $users = array();
     for ($i = 0; $i < $usercount; $i++) {
         $user = $this->getDataGenerator()->create_user();
         $users[] = $user;
         $this->getDataGenerator()->enrol_user($user->id, $course->id);
     }
     $options = array('course' => $course->id, 'forcesubscribe' => FORUM_DISALLOWSUBSCRIBE);
     // Subscription prevented.
     $forum = $this->getDataGenerator()->create_module('forum', $options);
     $result = forum_subscribed_users($course, $forum);
     // No subscriptions by default.
     $this->assertEquals(0, count($result));
     foreach ($users as $user) {
         $this->assertFalse(forum_is_subscribed($user->id, $forum));
     }
 }
Exemple #9
0
/**
 * Generate and return the subscribe or unsubscribe link for a forum.
 * @param object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe.
 * @param object $context the context object for this forum.
 * @param array $messages text used for the link in its various states
 *      (subscribed, unsubscribed, forcesubscribed or cantsubscribe).
 *      Any strings not passed in are taken from the $defaultmessages array
 *      at the top of the function.
 * @param
 */
function forum_get_subscribe_link($forum, $context, $messages = array(), $cantaccessagroup = false, $fakelink = true, $backtoindex = false, $subscribed_forums = null)
{
    global $CFG, $USER;
    $defaultmessages = array('subscribed' => get_string('unsubscribe', 'forum'), 'unsubscribed' => get_string('subscribe', 'forum'), 'cantaccessgroup' => get_string('no'), 'forcesubscribed' => get_string('everyoneissubscribed', 'forum'), 'cantsubscribe' => get_string('disallowsubscribe', 'forum'));
    $messages = $messages + $defaultmessages;
    if (forum_is_forcesubscribed($forum)) {
        return $messages['forcesubscribed'];
    } else {
        if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('mod/forum:managesubscriptions', $context)) {
            return $messages['cantsubscribe'];
        } else {
            if ($cantaccessagroup) {
                return $messages['cantaccessgroup'];
            } else {
                if (is_null($subscribed_forums)) {
                    $subscribed = forum_is_subscribed($USER->id, $forum);
                } else {
                    $subscribed = !empty($subscribed_forums[$forum->id]);
                }
                if ($subscribed) {
                    $linktext = $messages['subscribed'];
                    $linktitle = get_string('subscribestop', 'forum');
                } else {
                    $linktext = $messages['unsubscribed'];
                    $linktitle = get_string('subscribestart', 'forum');
                }
                $options = array();
                if ($backtoindex) {
                    $backtoindexlink = '&amp;backtoindex=1';
                    $options['backtoindex'] = 1;
                } else {
                    $backtoindexlink = '';
                }
                $link = '';
                if ($fakelink) {
                    $link .= '<script type="text/javascript">';
                    $link .= '//<![CDATA[' . "\n";
                    $link .= 'document.getElementById("subscriptionlink").innerHTML = "<a title=\\"' . $linktitle . '\\" href=\\"' . $CFG->wwwroot . '/mod/forum/subscribe.php?id=' . $forum->id . $backtoindexlink . '\\">' . $linktext . '<\\/a>";';
                    $link .= '//]]>';
                    $link .= '</script>';
                    // use <noscript> to print button in case javascript is not enabled
                    $link .= '<noscript>';
                }
                $options['id'] = $forum->id;
                $link .= print_single_button($CFG->wwwroot . '/mod/forum/subscribe.php', $options, $linktext, 'post', '_self', true, $linktitle);
                if ($fakelink) {
                    $link .= '</noscript>';
                }
                return $link;
            }
        }
    }
}
Exemple #10
0
/**
 * Given a new post, subscribes or unsubscribes as appropriate.
 * Returns some text which describes what happened.
 */
function forum_post_subscription($post)
{
    global $USER;
    $subscribed = forum_is_subscribed($USER->id, $post->forum);
    if (isset($post->subscribe) && $post->subscribe && $subscribed || !$post->subscribe && !$subscribed) {
        return "";
    }
    if (!($forum = get_record("forum", "id", $post->forum))) {
        return "";
    }
    $info->name = fullname($USER);
    $info->forum = $forum->name;
    if (!empty($post->subscribe)) {
        forum_subscribe($USER->id, $post->forum);
        return "<p>" . get_string("nowsubscribed", "forum", $info) . "</p>";
    }
    forum_unsubscribe($USER->id, $post->forum);
    return "<p>" . get_string("nownotsubscribed", "forum", $info) . "</p>";
}
Exemple #11
0
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}&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;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;
}
Exemple #13
0
/**
 * 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;
}
Exemple #14
0
/**
 * Given a new post, subscribes or unsubscribes as appropriate.
 * Returns some text which describes what happened.
 */
function forum_post_subscription($post, $forum)
{
    global $USER;
    $action = '';
    $subscribed = forum_is_subscribed($USER->id, $forum);
    if ($forum->forcesubscribe == FORUM_FORCESUBSCRIBE) {
        // database ignored
        return "";
    } elseif ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $forum->course), $USER->id)) {
        if ($subscribed) {
            $action = 'unsubscribe';
            // sanity check, following MDL-14558
        } else {
            return "";
        }
    } else {
        // go with the user's choice
        if (isset($post->subscribe)) {
            // no change
            if (!empty($post->subscribe) && $subscribed || empty($post->subscribe) && !$subscribed) {
                return "";
            } elseif (!empty($post->subscribe) && !$subscribed) {
                $action = 'subscribe';
            } elseif (empty($post->subscribe) && $subscribed) {
                $action = 'unsubscribe';
            }
        }
    }
    $info->name = fullname($USER);
    $info->forum = $forum->name;
    switch ($action) {
        case 'subscribe':
            forum_subscribe($USER->id, $post->forum);
            return "<p>" . get_string("nowsubscribed", "forum", $info) . "</p>";
        case 'unsubscribe':
            forum_unsubscribe($USER->id, $post->forum);
            return "<p>" . get_string("nownotsubscribed", "forum", $info) . "</p>";
    }
}
Exemple #15
0
/**
 * Generate and return the subscribe or unsubscribe link for a forum.
 * @param object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe.
 * @param object $context the context object for this forum.
 * @param array $messages text used for the link in its various states
 *      (subscribed, unsubscribed, forcesubscribed or cantsubscribe).
 *      Any strings not passed in are taken from the $defaultmessages array
 *      at the top of the function.
 * @param
 */
function forum_get_subscribe_link($forum, $context, $messages = array(), $cantaccessagroup = false, $fakelink = true, $backtoindex = false, $subscribed_forums = null)
{
    global $CFG, $USER;
    $defaultmessages = array('subscribed' => get_string('unsubscribe', 'forum'), 'unsubscribed' => get_string('subscribe', 'forum'), 'cantaccessgroup' => get_string('no'), 'forcesubscribed' => get_string('everyoneissubscribed', 'forum'), 'cantsubscribe' => get_string('disallowsubscribe', 'forum'));
    $messages = $messages + $defaultmessages;
    if (forum_is_forcesubscribed($forum)) {
        return $messages['forcesubscribed'];
    } else {
        if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('mod/forum:managesubscriptions', $context)) {
            return $messages['cantsubscribe'];
        } else {
            if ($cantaccessagroup) {
                return $messages['cantaccessgroup'];
            } else {
                if (is_null($subscribed_forums)) {
                    $subscribed = forum_is_subscribed($USER->id, $forum);
                } else {
                    $subscribed = !empty($subscribed_forums[$forum->id]);
                }
                if ($subscribed) {
                    $linktext = $messages['subscribed'];
                    $linktitle = get_string('subscribestop', 'forum');
                } else {
                    $linktext = $messages['unsubscribed'];
                    $linktitle = get_string('subscribestart', 'forum');
                }
                $options = array();
                if ($backtoindex) {
                    $backtoindexlink = '&amp;backtoindex=1';
                    $options['backtoindex'] = 1;
                } else {
                    $backtoindexlink = '';
                }
                $link = '';
                $sesskeylink = '&amp;sesskey=' . sesskey();
                if ($fakelink) {
                    $link .= <<<EOD
<script type="text/javascript">
//<![CDATA[
var subs_link = document.getElementById("subscriptionlink");
if(subs_link){
    subs_link.innerHTML = "<a title=\\"{$linktitle}\\" href='{$CFG->wwwroot}/mod/forum/subscribe.php?id={$forum->id}{$backtoindexlink}{$sesskeylink}'>{$linktext}<\\/a>";
}
//]]>
</script>
<noscript>
EOD;
                }
                $options['id'] = $forum->id;
                $options['sesskey'] = sesskey();
                $link .= print_single_button($CFG->wwwroot . '/mod/forum/subscribe.php', $options, $linktext, 'post', '_self', true, $linktitle);
                if ($fakelink) {
                    $link .= '</noscript>';
                }
                return $link;
            }
        }
    }
}
Exemple #16
0
/**
 * Generate and return the subscribe or unsubscribe link for a forum.
 *
 * @global object
 * @global object
 * @global object
 * @param object $forum the forum. Fields used are $forum->id and $forum->forcesubscribe.
 * @param object $context the context object for this forum.
 * @param array $messages text used for the link in its various states
 *      (subscribed, unsubscribed, forcesubscribed or cantsubscribe).
 *      Any strings not passed in are taken from the $defaultmessages array
 *      at the top of the function.
 * @param bool $cantaccessagroup
 * @param bool $fakelink
 * @param bool $backtoindex
 * @param array $subscribed_forums
 * @return string
 */
function forum_get_subscribe_link($forum, $context, $messages = array(), $cantaccessagroup = false, $fakelink = true, $backtoindex = false, $subscribed_forums = null)
{
    global $CFG, $USER, $PAGE, $OUTPUT;
    $defaultmessages = array('subscribed' => get_string('unsubscribe', 'forum'), 'unsubscribed' => get_string('subscribe', 'forum'), 'cantaccessgroup' => get_string('no'), 'forcesubscribed' => get_string('everyoneissubscribed', 'forum'), 'cantsubscribe' => get_string('disallowsubscribe', 'forum'));
    $messages = $messages + $defaultmessages;
    if (forum_is_forcesubscribed($forum)) {
        return $messages['forcesubscribed'];
    } else {
        if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE && !has_capability('mod/forum:managesubscriptions', $context)) {
            return $messages['cantsubscribe'];
        } else {
            if ($cantaccessagroup) {
                return $messages['cantaccessgroup'];
            } else {
                if (is_null($subscribed_forums)) {
                    $subscribed = forum_is_subscribed($USER->id, $forum);
                } else {
                    $subscribed = !empty($subscribed_forums[$forum->id]);
                }
                if ($subscribed) {
                    $linktext = $messages['subscribed'];
                    $linktitle = get_string('subscribestop', 'forum');
                } else {
                    $linktext = $messages['unsubscribed'];
                    $linktitle = get_string('subscribestart', 'forum');
                }
                $options = array();
                if ($backtoindex) {
                    $backtoindexlink = '&amp;backtoindex=1';
                    $options['backtoindex'] = 1;
                } else {
                    $backtoindexlink = '';
                }
                $link = '';
                if ($fakelink) {
                    $PAGE->requires->js('mod/forum/forum.js');
                    $PAGE->requires->js_function_call('forum_produce_subscribe_link', array($forum->id, $backtoindexlink, $linktext, $linktitle));
                    $link = "<noscript>";
                }
                $options['id'] = $forum->id;
                $form = html_form::make_button($CFG->wwwroot . '/mod/forum/subscribe.php', $options, $linktext);
                $form->button->title = $linktitle;
                $link .= $OUTPUT->button($form);
                if ($fakelink) {
                    $link .= '</noscript>';
                }
                return $link;
            }
        }
    }
}