| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: subscribers.php,v 1.40.2.2 2008/02/13 17:01:42 skodak Exp $ 2 3 require_once("../../config.php"); 4 require_once ("lib.php"); 5 6 $id = required_param('id',PARAM_INT); // forum 7 $group = optional_param('group',0,PARAM_INT); // change of group 8 $edit = optional_param('edit',-1,PARAM_BOOL); // Turn editing on and off 9 10 if (! $forum = get_record("forum", "id", $id)) { 11 error("Forum ID is incorrect"); 12 } 13 14 if (! $course = get_record("course", "id", $forum->course)) { 15 error("Could not find this course!"); 16 } 17 18 if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { 19 $cm->id = 0; 20 } 21 22 require_login($course->id, false, $cm); 23 24 $context = get_context_instance(CONTEXT_MODULE, $cm->id); 25 26 if (!has_capability('mod/forum:viewsubscribers', $context)) { 27 error('You do not have the permission to view forum subscribers'); 28 } 29 30 unset($SESSION->fromdiscussion); 31 32 add_to_log($course->id, "forum", "view subscribers", "subscribers.php?id=$forum->id", $forum->id, $cm->id); 33 34 $strsubscribeall = get_string("subscribeall", "forum"); 35 $strsubscribenone = get_string("subscribenone", "forum"); 36 $strsubscribers = get_string("subscribers", "forum"); 37 $strforums = get_string("forums", "forum"); 38 39 $navigation = build_navigation($strsubscribers, $cm); 40 41 if (has_capability('mod/forum:managesubscriptions', $context)) { 42 print_header_simple("$strsubscribers", "", $navigation, 43 "", "", true, forum_update_subscriptions_button($course->id, $id)); 44 if ($edit != -1) { 45 $USER->subscriptionsediting = $edit; 46 } 47 } else { 48 print_header_simple("$strsubscribers", "", $navigation, "", "", true, ''); 49 unset($USER->subscriptionsediting); 50 } 51 52 /// Check to see if groups are being used in this forum 53 groups_print_activity_menu($cm, "subscribers.php?id=$forum->id"); 54 $currentgroup = groups_get_activity_group($cm); 55 $groupmode = groups_get_activity_groupmode($cm); 56 57 if (empty($USER->subscriptionsediting)) { /// Display an overview of subscribers 58 59 if (! $users = forum_subscribed_users($course, $forum, $currentgroup) ) { 60 61 print_heading(get_string("nosubscribers", "forum")); 62 63 } else { 64 65 print_heading(get_string("subscribersto","forum", "'".format_string($forum->name)."'")); 66 67 echo '<table align="center" cellpadding="5" cellspacing="5">'; 68 foreach ($users as $user) { 69 echo '<tr><td>'; 70 print_user_picture($user, $course->id); 71 echo '</td><td>'; 72 echo fullname($user); 73 echo '</td><td>'; 74 echo $user->email; 75 echo '</td></tr>'; 76 } 77 echo "</table>"; 78 } 79 80 print_footer($course); 81 exit; 82 } 83 84 /// We are in editing mode. 85 86 $strexistingsubscribers = get_string("existingsubscribers", 'forum'); 87 $strpotentialsubscribers = get_string("potentialsubscribers", 'forum'); 88 $straddsubscriber = get_string("addsubscriber", 'forum'); 89 $strremovesubscriber = get_string("removesubscriber", 'forum'); 90 $strsearch = get_string("search"); 91 $strsearchresults = get_string("searchresults"); 92 $strshowall = get_string("showall"); 93 $strsubscribers = get_string("subscribers", "forum"); 94 $strforums = get_string("forums", "forum"); 95 96 if ($frm = data_submitted()) { 97 98 /// A form was submitted so process the input 99 100 if (!empty($frm->add) and !empty($frm->addselect)) { 101 102 foreach ($frm->addselect as $addsubscriber) { 103 if (! forum_subscribe($addsubscriber, $id)) { 104 error("Could not add subscriber with id $addsubscriber to this forum!"); 105 } 106 } 107 } else if (!empty($frm->remove) and !empty($frm->removeselect)) { 108 foreach ($frm->removeselect as $removesubscriber) { 109 if (! forum_unsubscribe($removesubscriber, $id)) { 110 error("Could not remove subscriber with id $removesubscriber from this forum!"); 111 } 112 } 113 } else if (!empty($frm->showall)) { 114 unset($frm->searchtext); 115 $frm->previoussearch = 0; 116 } 117 } 118 119 $previoussearch = (!empty($frm->search) or (!empty($frm->previoussearch) && $frm->previoussearch == 1)) ; 120 121 /// Get all existing subscribers for this forum. 122 if (!$subscribers = forum_subscribed_users($course, $forum, $currentgroup)) { 123 $subscribers = array(); 124 } 125 126 $subscriberarray = array(); 127 foreach ($subscribers as $subscriber) { 128 $subscriberarray[] = $subscriber->id; 129 } 130 $subscriberlist = implode(',', $subscriberarray); 131 132 unset($subscriberarray); 133 134 /// Get search results excluding any users already subscribed 135 136 if (!empty($frm->searchtext) and $previoussearch) { 137 $searchusers = search_users($course->id, $currentgroup, $frm->searchtext, 'firstname ASC, lastname ASC', $subscriberlist); 138 } 139 140 /// If no search results then get potential subscribers for this forum excluding users already subscribed 141 if (empty($searchusers)) { 142 if ($currentgroup) { 143 $users = get_group_users($currentgroup, 'firstname ASC, lastname ASC', $subscriberlist); 144 } else { 145 $users = get_course_users($course->id, 'firstname ASC, lastname ASC', $subscriberlist); 146 } 147 if (!$users) { 148 $users = array(); 149 } 150 151 } 152 153 $searchtext = (isset($frm->searchtext)) ? $frm->searchtext : ""; 154 $previoussearch = ($previoussearch) ? '1' : '0'; 155 156 print_simple_box_start('center'); 157 158 include ('subscriber.html'); 159 160 print_simple_box_end(); 161 162 print_footer($course); 163 164 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |