Editing teacher can now subscribe users to a forum, see http://moodle.org/mod/forum/discuss.php?d=11089

This commit is contained in:
gustav_delius 2004-08-15 12:38:29 +00:00
parent b3d3ca5b79
commit 90e7063e45
4 changed files with 327 additions and 74 deletions

View File

@ -43,6 +43,7 @@ $string['editing'] = 'Editing';
$string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.'; $string['emptymessage'] = 'Something was wrong with your post. Perhaps you left it blank, or the attachment was too big. Your changes have NOT been saved.';
$string['everyonecanchoose'] = 'Everyone can choose to be subscribed'; $string['everyonecanchoose'] = 'Everyone can choose to be subscribed';
$string['everyoneissubscribed'] = 'Everyone is subscribed to this forum'; $string['everyoneissubscribed'] = 'Everyone is subscribed to this forum';
$string['existingsubscribers'] = 'Existing subscribers';
$string['forcesubscribe'] = 'Force everyone to be subscribed'; $string['forcesubscribe'] = 'Force everyone to be subscribed';
$string['forcesubscribeq'] = 'Force everyone to be subscribed?'; $string['forcesubscribeq'] = 'Force everyone to be subscribed?';
$string['forum'] = 'Forum'; $string['forum'] = 'Forum';
@ -101,6 +102,7 @@ $string['postrating3'] = 'Mostly Connected Knowing';
$string['posts'] = 'Posts'; $string['posts'] = 'Posts';
$string['posttoforum'] = 'Post to forum'; $string['posttoforum'] = 'Post to forum';
$string['postupdated'] = 'Your post was updated'; $string['postupdated'] = 'Your post was updated';
$string['potentialsubscribers'] = 'Potential subscribers';
$string['processingpost'] = 'Processing post $a'; $string['processingpost'] = 'Processing post $a';
$string['processingdigest'] = 'Processing email digest for user $a'; $string['processingdigest'] = 'Processing email digest for user $a';
$string['prune'] = 'Split'; $string['prune'] = 'Split';

View File

@ -2809,4 +2809,23 @@ function forum_change_discussionid($postid, $discussionid) {
return true; return true;
} }
function forum_update_subscriptions_button($courseid, $forumid) {
// Prints the editing button on subscribers page
global $CFG, $USER;
if (isteacheredit($courseid)) {
if (!empty($USER->subscriptionsediting)) {
$string = get_string("turneditingoff");
$edit = "off";
} else {
$string = get_string("turneditingon");
$edit = "on";
}
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/mod/forum/subscribers.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$forumid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
}
}
?> ?>

80
mod/forum/subscriber.html Normal file
View File

@ -0,0 +1,80 @@
<form name="subscriberform" id="subscriberform" method="post" action="subscribers.php">
<input type="hidden" name="previoussearch" value="<?php echo $previoussearch ?>">
<input type="hidden" name="id" value="<?php echo $id?>">
<table align="center" border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top">
<?php echo count($subscribers) . " ". $strexistingsubscribers ?>
</td>
<td></td>
<td valign="top">
<?php echo $usercount . " " . $strpotentialsubscribers ?>
</td>
</tr>
<tr>
<td valign="top">
<select name="removeselect[]" size="20" id="removeselect" multiple
onFocus="document.subscriberform.add.disabled=true;
document.subscriberform.remove.disabled=false;
document.subscriberform.addselect.selectedIndex=-1;">
<?php
foreach ($subscribers as $subscriber) {
$fullname = fullname($subscriber, true);
echo "<option value=\"$subscriber->id\">".$fullname.", ".$subscriber->email."</option>\n";
}
?>
</select></td>
<td valign="top">
<br />
<input name="add" type="submit" id="add" value="&larr;" />
<br />
<input name="remove" type="submit" id="remove" value="&rarr;" />
<br />
</td>
<td valign="top">
<select name="addselect[]" size="20" id="addselect" multiple
onFocus="document.subscriberform.add.disabled=false;
document.subscriberform.remove.disabled=true;
document.subscriberform.removeselect.selectedIndex=-1;">
<?php
if (!empty($searchusers)) {
echo "<optgroup label=\"$strsearchresults (" . count($searchusers) . ")\">\n";
foreach ($searchusers as $user) {
$fullname = fullname($user, true);
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
}
echo "</optgroup>\n";
}
if (!empty($users)) {
foreach ($users as $user) {
$fullname = fullname($user, true);
echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
}
}
?>
</select>
<br />
<input type="text" name="searchtext" size="30" value="<?php echo $searchtext ?>"
onFocus ="document.subscriberform.add.disabled=true;
document.subscriberform.remove.disabled=true;
document.subscriberform.removeselect.selectedIndex=-1;
document.subscriberform.addselect.selectedIndex=-1;"
onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
if (keyCode == 13) {
document.subscriberform.previoussearch.value=1;
document.subscriberform.submit();
} " />
<input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
<?php
if (!empty($searchusers)) {
echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
}
?>
</td>
</tr>
</table>
</form>

View File

@ -7,6 +7,8 @@
optional_variable($subscribe, ''); // 'all' or 'none' optional_variable($subscribe, ''); // 'all' or 'none'
optional_variable($unsubscribe, ''); // a single user id optional_variable($unsubscribe, ''); // a single user id
optional_variable($group); // change of group optional_variable($group); // change of group
optional_variable($edit); // Turn editing on and off
if (! $forum = get_record("forum", "id", $id)) { if (! $forum = get_record("forum", "id", $id)) {
error("Forum ID is incorrect"); error("Forum ID is incorrect");
@ -29,6 +31,18 @@
unset($SESSION->fromdiscussion); unset($SESSION->fromdiscussion);
add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", $forum->id, $cm->id); add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", $forum->id, $cm->id);
if (isteacheredit($course->id)) {
if (isset($_GET['edit'])) {
if($edit == "on") {
$USER->subscriptionsediting = true;
} else {
$USER->subscriptionsediting = false;
}
}
} else {
$USER->subscriptionsediting = false;
}
$strunsubscribeshort = get_string("unsubscribeshort", "forum"); $strunsubscribeshort = get_string("unsubscribeshort", "forum");
$strsubscribeall = get_string("subscribeall", "forum"); $strsubscribeall = get_string("subscribeall", "forum");
@ -38,102 +52,240 @@
if ($course->category) { if ($course->category) {
$navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
<a href=\"index.php?id=$course->id\">$strforums</a> -> <a href=\"index.php?id=$course->id\">$strforums</a> ->
<a href=\"view.php?f=$forum->id\">$forum->name</a> -> $strsubscribers"; <a href=\"view.php?f=$forum->id\">$forum->name</a> -> $strsubscribers";
} else { } else {
$navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> -> $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->
<a href=\"view.php?f=$forum->id\">$forum->name</a> -> $strsubscribers"; <a href=\"view.php?f=$forum->id\">$forum->name</a> -> $strsubscribers";
} }
print_header("$course->shortname: $strsubscribers", "$course->fullname", "$navigation"); print_header("$course->shortname: $strsubscribers", "$course->fullname", "$navigation",
"", "", true, forum_update_subscriptions_button($course->id, $id));
if (empty($USER->subscriptionsediting)) { /// Display an overview of subscribers
/// Check to see if groups are being used in this forum /// Check to see if groups are being used in this forum
if ($groupmode = groupmode($course, $cm)) { // Groups are being used if ($groupmode = groupmode($course, $cm)) { // Groups are being used
$currentgroup = setup_and_print_groups($course, $groupmode, "subscribers.php?id=$forum->id"); $currentgroup = setup_and_print_groups($course, $groupmode, "subscribers.php?id=$forum->id");
} else {
$currentgroup = false;
}
if ($subscribe == 'all') {
if ($forum->type == 'teacher') {
$users = get_course_teachers($course->id);
} elseif ($currentgroup) {
$users = get_group_users($currentgroup);
} else { } else {
$users = get_course_users($course->id); $currentgroup = false;
} }
if ($users) {
foreach ($users as $user) { if ($subscribe == 'all') {
forum_subscribe($user->id, $forum->id); if ($forum->type == 'teacher') {
$users = get_course_teachers($course->id);
} elseif ($currentgroup) {
$users = get_group_users($currentgroup);
} else {
$users = get_course_users($course->id);
} }
} if ($users) {
} else if ($subscribe == 'none') {
if ($currentgroup) {
if ($users = get_group_users($currentgroup)) {
foreach ($users as $user) { foreach ($users as $user) {
forum_unsubscribe($user->id, $forum->id); forum_subscribe($user->id, $forum->id);
} }
} }
} else if ($subscribe == 'none') {
if ($currentgroup) {
if ($users = get_group_users($currentgroup)) {
foreach ($users as $user) {
forum_unsubscribe($user->id, $forum->id);
}
}
} else {
delete_records("forum_subscriptions", "forum", $forum->id);
}
}
if ($unsubscribe) {
if ($user = get_record('user', 'id', $unsubscribe)) {
forum_unsubscribe($user->id, $forum->id);
$info->name = fullname($user);
$info->forum = $forum->name;
notify(get_string("nownotsubscribed", "forum", $info));
}
}
if (! $users = forum_subscribed_users($course, $forum, $currentgroup) ) {
if (!$forum->forcesubscribe) {
echo '<center>';
$options['id'] = $forum->id;
$options['subscribe'] = 'all';
print_single_button('subscribers.php', $options, $strsubscribeall);
echo '</center>';
}
print_heading(get_string("nosubscribers", "forum"));
} else { } else {
delete_records("forum_subscriptions", "forum", $forum->id);
if (!$forum->forcesubscribe) {
echo '<table align="center"><tr>';
echo '<td>';
$options['id'] = $forum->id;
$options['subscribe'] = 'all';
print_single_button('subscribers.php', $options, $strsubscribeall);
echo '</td>';
echo '<td>';
$options['subscribe'] = 'none';
print_single_button('subscribers.php', $options, $strsubscribenone);
echo '</td>';
echo '</tr></table>';
}
print_heading(get_string("subscribersto","forum", "'$forum->name'"));
echo '<table align="center" cellpadding="5" cellspacing="5">';
foreach ($users as $user) {
echo "<tr><td>";
print_user_picture($user->id, $course->id, $user->picture);
echo "</td><td bgcolor=\"$THEME->cellcontent\">";
echo "$user->firstname $user->lastname";
echo "</td><td bgcolor=\"$THEME->cellcontent\">";
echo "$user->email";
echo "</td><td>";
echo "<font size=1><a href=\"subscribers.php?id=$forum->id&unsubscribe=$user->id\">$strunsubscribeshort</a></font>";
echo "</td></tr>";
}
echo "</table>";
}
print_footer($course);
exit;
}
/// We are in editing mode.
if (!isteacheredit($course->id)) {
error("You must be an editing teacher in this course, or an admin");
}
$strexistingsubscribers = get_string("existingsubscribers", 'forum');
$strpotentialsubscribers = get_string("potentialsubscribers", 'forum');
$straddsubscriber = get_string("addsubscriber", 'forum');
$strremovesubscriber = get_string("removesubscriber", 'forum');
$strsearch = get_string("search");
$strsearchresults = get_string("searchresults");
$strshowall = get_string("showall");
$strsubscribers = get_string("subscribers", "forum");
$strforums = get_string("forums", "forum");
if ($frm = data_submitted()) {
/// A form was submitted so process the input
if (!empty($frm->add) and !empty($frm->addselect)) {
foreach ($frm->addselect as $addsubscriber) {
if (! forum_subscribe($addsubscriber, $id)) {
error("Could not add subscriber with id $addsubscriber to this forum!");
}
}
} else if (!empty($frm->remove) and !empty($frm->removeselect)) {
foreach ($frm->removeselect as $removesubscriber) {
if (! forum_unsubscribe($removesubscriber, $id)) {
error("Could not remove subscriber with id $removesubscriber from this forum!");
}
}
} else if (!empty($frm->showall)) {
unset($frm->searchtext);
$frm->previoussearch = 0;
} }
} }
if ($unsubscribe) { $previoussearch = (!empty($frm->search) or ($frm->previoussearch == 1)) ;
if ($user = get_record('user', 'id', $unsubscribe)) {
forum_unsubscribe($user->id, $forum->id); /// Get all existing subscribers for this forum.
$info->name = fullname($user); if (!$subscribers = forum_subscribed_users($course, $forum)) {
$info->forum = $forum->name; $subscribers = array();
notify(get_string("nownotsubscribed", "forum", $info));
}
} }
$subscriberarray = array();
foreach ($subscribers as $subscriber) {
$subscriberarray[] = $subscriber->id;
}
$subscriberlist = implode(',', $subscriberarray);
unset($subscriberarray);
if (! $users = forum_subscribed_users($course, $forum, $currentgroup) ) { /// Get search results excluding any users already subscribed
switch ($CFG->dbtype) {
if (!$forum->forcesubscribe) { case "mysql":
echo '<center>'; $fullname = " CONCAT(u.firstname,\" \",u.lastname) ";
$options['id'] = $forum->id; $LIKE = "LIKE";
$options['subscribe'] = 'all'; break;
print_single_button('subscribers.php', $options, $strsubscribeall); case "postgres7":
echo '</center>'; $fullname = " u.firstname||' '||u.lastname ";
} $LIKE = "ILIKE";
break;
print_heading(get_string("nosubscribers", "forum")); default:
$fullname = " u.firstname||\" \"||u.lastname ";
$LIKE = "ILIKE";
}
if (!empty($subscriberlist)) {
$except = " AND u.id NOT IN ($subscriberlist) ";
} else { } else {
$except = '';
}
if (!empty($frm->searchtext) and $previoussearch) {
$searchusers = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'
AND ($fullname $LIKE '%$frm->searchtext%' OR u.email $LIKE '%$frm->searchtext%')
$except
UNION
SELECT u.id, u.firstname, u.lastname, u.email
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_teachers s
WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'
AND ($fullname $LIKE '%$frm->searchtext%' OR u.email $LIKE '%$frm->searchtext%')
$except
ORDER BY u.firstname ASC, u.lastname ASC");
if (!$forum->forcesubscribe) { $usercount = count_records_sql("SELECT COUNT(*)
echo '<table align="center"><tr>'; FROM {$CFG->prefix}user u,
echo '<td>'; {$CFG->prefix}user_students s
$options['id'] = $forum->id; WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'
$options['subscribe'] = 'all'; $except") +
print_single_button('subscribers.php', $options, $strsubscribeall); count_records_sql("SELECT COUNT(*)
echo '</td>'; FROM {$CFG->prefix}user u,
echo '<td>'; {$CFG->prefix}user_teachers s
$options['subscribe'] = 'none'; WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'
print_single_button('subscribers.php', $options, $strsubscribenone); $except");
echo '</td>'; }
echo '</tr></table>';
/// If no search results then get potential subscribers for this forum excluding users already subscribed
if (empty($searchusers)) {
if (!$users = get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_students s
WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'
$except
UNION
SELECT u.id, u.firstname, u.lastname, u.email
FROM {$CFG->prefix}user u,
{$CFG->prefix}user_teachers s
WHERE s.course = '$course->id' AND s.userid = u.id AND u.deleted = '0'
$except
ORDER BY u.firstname ASC, u.lastname ASC")) {
$users = array();
} }
$usercount = count($users);
print_heading(get_string("subscribersto","forum", "'$forum->name'"));
echo '<table align="center" cellpadding="5" cellspacing="5">';
foreach ($users as $user) {
echo "<tr><td>";
print_user_picture($user->id, $course->id, $user->picture);
echo "</td><td bgcolor=\"$THEME->cellcontent\">";
echo "$user->firstname $user->lastname";
echo "</td><td bgcolor=\"$THEME->cellcontent\">";
echo "$user->email";
echo "</td><td>";
echo "<font size=1><a href=\"subscribers.php?id=$forum->id&unsubscribe=$user->id\">$strunsubscribeshort</a></font>";
echo "</td></tr>";
}
echo "</table>";
} }
print_footer($course);
$searchtext = (isset($frm->searchtext)) ? $frm->searchtext : "";
$previoussearch = ($previoussearch) ? '1' : '0';
print_simple_box_start("center", "", "$THEME->cellheading");
include('subscriber.html');
print_simple_box_end();
print_footer();
?> ?>