コード例 #1
0
}
$info = new stdClass();
$info->name = fullname($user);
$info->forum = format_string($forum->name);
if (hsuforum_is_subscribed($user->id, $forum->id)) {
    if (is_null($sesskey)) {
        // we came here via link in email
        $PAGE->set_title($course->shortname);
        $PAGE->set_heading($course->fullname);
        echo $OUTPUT->header();
        echo $OUTPUT->confirm(get_string('confirmunsubscribe', 'hsuforum', format_string($forum->name)), new moodle_url($PAGE->url, array('sesskey' => sesskey())), new moodle_url('/mod/hsuforum/view.php', array('f' => $id)));
        echo $OUTPUT->footer();
        exit;
    }
    require_sesskey();
    if (hsuforum_unsubscribe($user->id, $forum->id)) {
        redirect($returnto, get_string("nownotsubscribed", "hsuforum", $info), 1);
    } else {
        print_error('cannotunsubscribe', 'hsuforum', $_SERVER["HTTP_REFERER"]);
    }
} else {
    // subscribe
    if ($forum->forcesubscribe == HSUFORUM_DISALLOWSUBSCRIBE && !has_capability('mod/hsuforum:managesubscriptions', $context)) {
        print_error('disallowsubscribe', 'hsuforum', $_SERVER["HTTP_REFERER"]);
    }
    if (!has_capability('mod/hsuforum:viewdiscussion', $context)) {
        print_error('noviewdiscussionspermission', 'hsuforum', $_SERVER["HTTP_REFERER"]);
    }
    if (is_null($sesskey)) {
        // we came here via link in email
        $PAGE->set_title($course->shortname);
コード例 #2
0
        $forum = $forums[$forumid];
        $modcontext = context_module::instance($cm->id);
        $cansub = false;
        if (has_capability('mod/hsuforum:viewdiscussion', $modcontext)) {
            $cansub = true;
        }
        if ($cansub && $cm->visible == 0 && !has_capability('mod/hsuforum:managesubscriptions', $modcontext)) {
            $cansub = false;
        }
        if (!hsuforum_is_forcesubscribed($forum)) {
            $subscribed = hsuforum_is_subscribed($USER->id, $forum);
            if ((has_capability('moodle/course:manageactivities', $coursecontext, $USER->id) || $forum->forcesubscribe != HSUFORUM_DISALLOWSUBSCRIBE) && $subscribe && !$subscribed && $cansub) {
                hsuforum_subscribe($USER->id, $forumid, $modcontext);
            } else {
                if (!$subscribe && $subscribed) {
                    hsuforum_unsubscribe($USER->id, $forumid, $modcontext);
                }
            }
        }
    }
    $returnto = hsuforum_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', 'hsuforum', $shortname), 1);
    } else {
        redirect($returnto, get_string('nowallunsubscribed', 'hsuforum', $shortname), 1);
    }
}
/// First, let's process the general forums and build up a display
if ($generalforums) {
    foreach ($generalforums as $forum) {
コード例 #3
0
/**
 * Given a new post, subscribes or unsubscribes as appropriate.
 * Returns some text which describes what happened.
 *
 * @global objec
 * @param object $post
 * @param object $forum
 */
function hsuforum_post_subscription($post, $forum)
{
    global $USER;
    $action = '';
    $subscribed = hsuforum_is_subscribed($USER->id, $forum);
    if ($forum->forcesubscribe == HSUFORUM_FORCESUBSCRIBE) {
        // database ignored
        return "";
    } elseif ($forum->forcesubscribe == HSUFORUM_DISALLOWSUBSCRIBE && !has_capability('moodle/course:manageactivities', context_course::instance($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 = new stdClass();
    $info->name = fullname($USER);
    $info->forum = format_string($forum->name);
    switch ($action) {
        case 'subscribe':
            hsuforum_subscribe($USER->id, $post->forum);
            return "<p>" . get_string("nowsubscribed", "hsuforum", $info) . "</p>";
        case 'unsubscribe':
            hsuforum_unsubscribe($USER->id, $post->forum);
            return "<p>" . get_string("nownotsubscribed", "hsuforum", $info) . "</p>";
    }
}
コード例 #4
0
    /** It has to be one or the other, not both or neither */
    if (!($subscribe xor $unsubscribe)) {
        print_error('invalidaction');
    }
    if ($subscribe) {
        $users = $subscriberselector->get_selected_users();
        foreach ($users as $user) {
            if (!hsuforum_subscribe($user->id, $id)) {
                print_error('cannotaddsubscriber', 'hsuforum', '', $user->id);
            }
        }
    } else {
        if ($unsubscribe) {
            $users = $existingselector->get_selected_users();
            foreach ($users as $user) {
                if (!hsuforum_unsubscribe($user->id, $id)) {
                    print_error('cannotremovesubscriber', 'hsuforum', '', $user->id);
                }
            }
        }
    }
    $subscriberselector->invalidate_selected_users();
    $existingselector->invalidate_selected_users();
    $subscriberselector->set_existing_subscribers($existingselector->find_users(''));
}
$strsubscribers = get_string("subscribers", "hsuforum");
$PAGE->navbar->add($strsubscribers);
$PAGE->set_title($strsubscribers);
$PAGE->set_heading($COURSE->fullname);
if (has_capability('mod/hsuforum:managesubscriptions', $context)) {
    if ($edit != -1) {
コード例 #5
0
$PAGE->set_context(context_user::instance($USER->id));
$return = $CFG->wwwroot . '/';
if (isguestuser()) {
    redirect($return);
}
$strunsubscribeall = get_string('unsubscribeall', 'hsuforum');
$PAGE->navbar->add(get_string('modulename', 'hsuforum'));
$PAGE->navbar->add($strunsubscribeall);
$PAGE->set_title($strunsubscribeall);
$PAGE->set_heading($COURSE->fullname);
echo $OUTPUT->header();
echo $OUTPUT->heading($strunsubscribeall);
if (data_submitted() and $confirm and confirm_sesskey()) {
    $forums = hsuforum_get_optional_subscribed_forums();
    foreach ($forums as $forum) {
        hsuforum_unsubscribe($USER->id, $forum->id, context_module::instance($forum->cm));
    }
    $DB->set_field('user', 'autosubscribe', 0, array('id' => $USER->id));
    echo $OUTPUT->box(get_string('unsubscribealldone', 'hsuforum'));
    echo $OUTPUT->continue_button($return);
    echo $OUTPUT->footer();
    die;
} else {
    $a = count(hsuforum_get_optional_subscribed_forums());
    if ($a) {
        $msg = get_string('unsubscribeallconfirm', 'hsuforum', $a);
        echo $OUTPUT->confirm($msg, new moodle_url('unsubscribeall.php', array('confirm' => 1)), $return);
        echo $OUTPUT->footer();
        die;
    } else {
        echo $OUTPUT->box(get_string('unsubscribeallempty', 'hsuforum'));