diff --git a/calendar/lib.php b/calendar/lib.php index 8c5ce62530e..2766e8bf6d5 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -341,6 +341,7 @@ function calendar_get_upcoming($courses, $groups, $users, $daysinfuture, $maxeve } if($events !== false) { + foreach($events as $event) { if($processed >= $display->maxevents) { @@ -1082,7 +1083,10 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU // Otherwise (not editing teacher) show events from the group he is a member of else if(isset($USER->groupmember[$courseid])) { - $grouparray[] = $USER->groupmember[$courseid]; + //changed to 2D array + foreach ($USER->groupmember[$courseid] as $groupid){ + $grouparray[] = $groupid; + } } } if(empty($grouparray)) { diff --git a/course/groups.php b/course/groups.php index f36b500f2b7..2e37ecab0a7 100644 --- a/course/groups.php +++ b/course/groups.php @@ -1,5 +1,28 @@ $strgroups", "", "", true, '', user_login_string($course, $USER)); - /// First, process any inputs there may be. if ($data = data_submitted() and confirm_sesskey()) { @@ -57,7 +79,8 @@ if (!empty($data->nonmembers) and !empty($data->groupid)) { $groupmodified = false; foreach ($data->nonmembers as $userid) { - if (!user_group($course->id, $userid)) { // Just to make sure (another teacher could be editing) + //since we allow people to be in more than 1 group, this has to go. + if (!ismember($data->groupid,$userid)) {// Just to make sure (another teacher could be editing) $record->groupid = $data->groupid; $record->userid = $userid; $record->timeadded = time(); @@ -172,7 +195,9 @@ if ($groupusers = get_group_users($group->id)) { foreach ($groupusers as $groupuser) { $listmembers[$group->id][$groupuser->id] = $nonmembers[$groupuser->id]; - unset($nonmembers[$groupuser->id]); + //we do not remove people from $nonmembers, everyone is displayed + //this is to enable people to be registered in multiple groups + //unset($nonmembers[$groupuser->id]); $countusers++; } natcasesort($listmembers[$group->id]); diff --git a/lang/en/help/uploadgroups.html b/lang/en/help/uploadgroups.html new file mode 100755 index 00000000000..035edc50da7 --- /dev/null +++ b/lang/en/help/uploadgroups.html @@ -0,0 +1,34 @@ +

Upload groups

+ +

This facility allows the batch upload of groups into Moodle.

+ + + + +

Here is an example of a valid import file:

+

groupname,idnumber,lang,description,picture
+group1, Phil101, en, this group requires extra attention!, 0
+group2, Math243, , , +

+ diff --git a/lib/datalib.php b/lib/datalib.php index f0deaf1df68..7f8045e0052 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -1914,6 +1914,27 @@ function get_users_unconfirmed($cutofftime=2000000000) { } +/** + * Full list of bogus accounts that are probably not ever going to be used + * + * @uses $CFG + * @param string $cutofftime ? + * @return object {@link $USER} records + * @todo Finish documenting this function + */ + +function get_users_not_fully_set_up($cutofftime=2000000000) { + global $CFG; + return get_records_sql("SELECT * + FROM {$CFG->prefix}user + WHERE confirmed = 1 + AND lastaccess > 0 + AND lastaccess < '$cutofftime' + AND deleted = 0 + AND (lastname = '' OR firstname = '' OR email = '')"); +} + + /** * shortdesc (optional) * @@ -2009,18 +2030,32 @@ function get_users_not_in_group($courseid) { * Returns an array of user objects * * @uses $CFG - * @param int $groupid The group in question. + * @param int $groupid The group(s) in question. * @param string $sort How to sort the results - * @return object + * @return object (changed to groupids) */ -function get_group_students($groupid, $sort='u.lastaccess DESC') { +function get_group_students($groupids, $sort='u.lastaccess DESC') { + global $CFG; + + if (is_array($groupids)){ + $groups = $groupids; + $groupstr = '(m.groupid = '.array_shift($groups); + foreach ($groups as $index => $value){ + $groupstr .= ' OR m.groupid = '.$value; + } + $groupstr .= ')'; + } + else { + $groupstr = 'm.groupid = '.$groupids; + } + return get_records_sql("SELECT DISTINCT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}groups_members m, {$CFG->prefix}groups g, {$CFG->prefix}user_students s - WHERE m.groupid = '$groupid' + WHERE $groupstr AND m.userid = u.id AND m.groupid = g.id AND g.courseid = s.course @@ -2028,7 +2063,6 @@ function get_group_students($groupid, $sort='u.lastaccess DESC') { ORDER BY $sort"); } - /** * Returns list of all the teachers who can access a group * @@ -2060,18 +2094,20 @@ function get_group_teachers($courseid, $groupid) { * @uses $CFG * @param int $courseid The course in question. * @param int $userid The id of the user as found in the 'user' table. + * @param int $groupid The id of the group the user is in. * @return object * @todo Finish documenting this function */ function user_group($courseid, $userid) { global $CFG; - return get_record_sql("SELECT g.* + return get_records_sql("SELECT g.* FROM {$CFG->prefix}groups g, {$CFG->prefix}groups_members m WHERE g.courseid = '$courseid' AND g.id = m.groupid - AND m.userid = '$userid'"); + AND m.userid = '$userid' + ORDER BY name ASC"); } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 8a3097cea28..2e6f318f029 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2708,7 +2708,8 @@ function get_complete_user_data($field, $value) { if ($groups = get_records('groups_members', 'userid', $user->id)) { foreach ($groups as $groupmember) { $courseid = get_field('groups', 'courseid', 'id', $groupmember->groupid); - $user->groupmember[$courseid] = $groupmember->groupid; + //change this to 2D array so we can put multiple groups in a course + $user->groupmember[$courseid][] = $groupmember->groupid; } } @@ -3358,8 +3359,6 @@ function remove_course_userdata($courseid, $showfeedback=true, } - - /// GROUPS ///////////////////////////////////////////////////////// @@ -3377,20 +3376,37 @@ function ismember($groupid, $userid=0) { if (!$groupid) { // No point doing further checks return false; } - + //if groupid is supplied in array format if (!$userid) { if (empty($USER->groupmember)) { return false; } + //changed too for multiple groups foreach ($USER->groupmember as $courseid => $mgroupid) { - if ($mgroupid == $groupid) { + //need to loop one more time... + foreach ($mgroupid as $index => $mygroupid) + if ($mygroupid == $groupid) { + return true; + } + } + return false; + } + + if (is_array($groupid)){ + foreach ($groupid as $index => $val){ + if (record_exists('groups_members', 'groupid', $val, 'userid', $userid)){ return true; } } - return false; } + else { + return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid); + } + return false; - return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid); + //else group id is in single format + + //return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid); } /** @@ -3418,10 +3434,10 @@ function add_user_to_group ($groupid, $userid) { */ function mygroupid($courseid) { global $USER; - if (empty($USER->groupmember[$courseid])) { return 0; } else { + //this is an array of ids >.< return $USER->groupmember[$courseid]; } } @@ -3469,12 +3485,14 @@ function set_current_group($courseid, $groupid) { */ function get_current_group($courseid, $full=false) { global $SESSION, $USER; - + if (!isset($SESSION->currentgroup[$courseid])) { if (empty($USER->groupmember[$courseid]) or isteacheredit($courseid)) { + return 0; } else { - $SESSION->currentgroup[$courseid] = $USER->groupmember[$courseid]; + //trying to add a hack >.<, always first select the first one in list + $SESSION->currentgroup[$courseid] = $USER->groupmember[$courseid][0]; } } @@ -3516,12 +3534,25 @@ function get_and_set_current_group($course, $groupmode, $groupid=-1) { if (isteacheredit($course->id)) { // Sets current default group $currentgroupid = set_current_group($course->id, $group->id); - } else if ($groupmode == VISIBLEGROUPS) { // All groups are visible - $currentgroupid = $group->id; + } else if ($groupmode == VISIBLEGROUPS) { + // All groups are visible + //if (ismember($group->id)){ + $currentgroupid = set_current_group($course->id, $group->id);//set this since he might post + /*)}else { + $currentgroupid = $group->id;*/ + } else if ($groupmode == SEPARATEGROUPS) { // student in separate groups switching + if (ismember($group->id)){//check if is a member + $currentgroupid = set_current_group($course->id, $group->id); //might need to set_current_group? + } + else { + echo ($group->id); + notify('you do not belong to this group!',error); + } } } } else { // When groupid = 0 it means show ALL groups - if (isteacheredit($course->id)) { // Sets current default group + //this is changed, non editting teacher needs access to group 0 as well, for viewing work in visible groups (need to set current group for multiple pages) + if (isteacheredit($course->id) OR (isteacher($course->id) AND ($groupmode == VISIBLEGROUPS))) { // Sets current default group $currentgroupid = set_current_group($course->id, 0); } else if ($groupmode == VISIBLEGROUPS) { // All groups are visible @@ -3550,6 +3581,8 @@ function get_and_set_current_group($course, $groupmode, $groupid=-1) { */ function setup_and_print_groups($course, $groupmode, $urlroot) { + global $USER, $SESSION; //needs his id, need to hack his groups in session + if (isset($_GET['group'])) { $changegroup = $_GET['group']; /// 0 or higher } else { @@ -3557,15 +3590,25 @@ function setup_and_print_groups($course, $groupmode, $urlroot) { } $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); - if ($currentgroup === false) { return false; } if ($groupmode == SEPARATEGROUPS and !isteacheredit($course->id) and !$currentgroup) { - print_heading(get_string('notingroup')); - print_footer($course); - exit; + //we are in separate groups and the current group is group 0, as last set. + //this can mean that either, this guy has no group + //or, this guy just came from a visible all forum, and he left when he set his current group to 0 (show all) + + //for the second situation, we need to perform the trick and get him a group. + $courseid = $course->id; + if (!empty($USER->groupmember[$courseid])){ + $currentgroup = get_and_set_current_group($course, $groupmode, $USER->groupmember[$courseid][0]); + } + else {//else he has no group in this course + print_heading(get_string('notingroup')); + print_footer($course); + exit; + } } if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { @@ -3574,6 +3617,21 @@ function setup_and_print_groups($course, $groupmode, $urlroot) { print_group_menu($groups, $groupmode, $currentgroup, $urlroot); echo ''; } + }//added code here to allow non-editting teacher to swap in-between his own groups + //added code for students in separategrous to swtich groups + else if ($groupmode == SEPARATEGROUPS and (isteacher($course->id) or isstudent($course->id))) { + $validgroups = array(); + //get all the groups this guy is in in this course + if ($p = user_group($course->id,$USER->id)){ + //extract the name and id for the group + foreach ($p as $index => $object){ + $validgroups[$object->id] = $object->name; + } + echo '
'; + //print them in the menu + print_group_menu($validgroups, $groupmode, $currentgroup, $urlroot,0); + echo '
'; + } } return $currentgroup; diff --git a/lib/weblib.php b/lib/weblib.php index 94bc4192829..d5590751442 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3319,12 +3319,15 @@ function update_groups_button($courseid) { * @param int $groupmode ? * @param string $currentgroup ? * @param string $urlroot ? + * @param boolean $showall: if set to 0, it is a student in separate groups, do not display all participants * @todo Finish documenting this function */ -function print_group_menu($groups, $groupmode, $currentgroup, $urlroot) { +function print_group_menu($groups, $groupmode, $currentgroup, $urlroot, $showall=1) { /// Add an "All groups" to the start of the menu - $groupsmenu[0] = get_string('allparticipants'); + if ($showall){ + $groupsmenu[0] = get_string('allparticipants'); + } foreach ($groups as $key => $groupname) { $groupsmenu[$key] = $groupname; } @@ -4227,7 +4230,7 @@ function print_side_block_start($heading='', $attributes = array()) { /** * Print table ending tags for a side block box. */ -function print_side_block_end($attributes) { +function print_side_block_end($attributes = array()) { global $CFG; echo ''; @@ -4354,6 +4357,10 @@ function page_id_and_class(&$getid, &$getclass) { if (empty($path) || $path == 'index') { $id = 'site-index'; $class = 'course'; + } else if (substr($path, 0, 5) == 'admin') { + $id = str_replace('/', '-', $path); + $id = str_replace('admin2', 'admin', $id); + $class = 'admin'; } else { $id = str_replace('/', '-', $path); $class = explode('-', $id); diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index eca4d62e31a..3e51f381fff 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -660,7 +660,7 @@ class assignment_base { } else { $currentgroup = false; } - $limit = " LIMIT ".($offset+1).", 1"; + $limit = sql_paging_limit($offset+1, 1); /// Get all teachers and students if ($currentgroup) { @@ -835,6 +835,20 @@ class assignment_base { add_to_log($course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id); print_header_simple(format_string($this->assignment->name,true), "", ''.$this->strassignments.' -> '.format_string($this->assignment->name,true).' -> '. $this->strsubmissions, '', '', true, update_module_button($cm->id, $course->id, $this->strassignment), navmenu($course, $cm)); + + ///Position swapped + if ($groupmode = groupmode($course, $cm)) { // Groups are being used + $currentgroup = setup_and_print_groups($course, $groupmode, 'submissions.php?id='.$this->cm->id); + } else { + $currentgroup = false; + } + + /// Get all teachers and students + if ($currentgroup) { + $users = get_group_users($currentgroup); + } else { + $users = get_course_users($course->id); + } $tablecolumns = array('picture', 'fullname', 'grade', 'comment', 'timemodified', 'timemarked', 'status'); $tableheaders = array('', get_string('fullname'), get_string('grade'), get_string('comment', 'assignment'), get_string('lastmodified').' ('.$course->student.')', get_string('lastmodified').' ('.$course->teacher.')', get_string('status')); @@ -844,7 +858,7 @@ class assignment_base { $table->define_columns($tablecolumns); $table->define_headers($tableheaders); - $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id); + $table->define_baseurl($CFG->wwwroot.'/mod/assignment/submissions.php?id='.$this->cm->id.'&currentgroup='.$currentgroup); $table->sortable(true); $table->collapsible(true); @@ -871,19 +885,7 @@ class assignment_base { $table->setup(); /// Check to see if groups are being used in this assignment - if ($groupmode = groupmode($course, $cm)) { // Groups are being used - $currentgroup = setup_and_print_groups($course, $groupmode, 'submissions.php?id='.$this->cm->id); - } else { - $currentgroup = false; - } - /// Get all teachers and students - if ($currentgroup) { - $users = get_group_users($currentgroup); - } else { - $users = get_course_users($course->id); - } - if (!$teacherattempts) { $teachers = get_course_teachers($course->id); if (!empty($teachers)) { @@ -1558,9 +1560,11 @@ function assignment_grades($assignmentid) { $assignment->id, '', 'userid,grade'); if ($assignment->grade > 0) { - foreach ($grades as $userid => $grade) { - if ($grade == -1) { - $grades[$userid] = '-'; + if ($grades) { + foreach ($grades as $userid => $grade) { + if ($grade == -1) { + $grades[$userid] = '-'; + } } } $return->grades = $grades; diff --git a/mod/exercise/view.php b/mod/exercise/view.php index f528439382d..1c281a6c024 100644 --- a/mod/exercise/view.php +++ b/mod/exercise/view.php @@ -340,12 +340,11 @@ $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); /// Allow the teacher to change groups (for this session) - if ($groupmode) { - if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { - print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id"); - } - } + if ($groupmode){ + $currentgroup = setup_and_print_groups($course, $groupmode, 'view.php?id='.$cm->id); + } + print_heading_with_help(get_string("managingassignment", "exercise"), "managing", "exercise"); exercise_print_assignment_info($exercise); diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 9d26a49ff79..c72a5260359 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -62,7 +62,6 @@ } } - $logparameters = "d=$discussion->id"; if ($parent) { $logparameters .= "&parent=$parent"; @@ -139,12 +138,12 @@ } if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate - $mygroupid = mygroupid($course->id); - + //change this to ismember + $mygroupid = mygroupid($course->id);//only useful if 0, otherwise it's an array now if ($groupmode == SEPARATEGROUPS) { require_login(); - if ((empty($mygroupid) and $discussion->groupid == -1) || ($mygroupid == $discussion->groupid)) { + if ((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid) || $mygroupid == $discussion->groupid)) { $canreply = true; } elseif ($discussion->groupid == -1) { $canreply = false; @@ -155,7 +154,7 @@ } } else if ($groupmode == VISIBLEGROUPS) { - $canreply = ((empty($mygroupid) and $discussion->groupid == -1) || ($mygroupid == $discussion->groupid)); + $canreply = ((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid) || $mygroupid == $discussion->groupid)); } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 150cc3b6ded..16831c4af01 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -838,7 +838,8 @@ function forum_print_recent_activity($course, $isteacher, $timestart) { $groupmode[$post->forum] = groupmode($course, $cm[$post->forum]); } if ($groupmode[$post->forum]) { - if ($mygroupid != $post->groupid) { + //hope i didn't break anything + if (!@in_array($mygroupid, $post->groupid))/*$mygroupid != $post->groupid*/{ continue; } } @@ -990,7 +991,7 @@ function forum_scale_used ($forumid,$scaleid) { $rec = get_record("forum","id","$forumid","scale","-$scaleid"); - if (!empty($rec) && !empty($scaleid)) { + if (!empty($rec) && !empty($scaleid)) { $return = true; } @@ -1053,8 +1054,13 @@ function forum_search_posts($searchterms, $courseid, $page=0, $recordsperpage=50 if ($groupid) { $separategroups = SEPARATEGROUPS; $selectgroup = " AND ( NOT (cm.groupmode='$separategroups'". - " OR (c.groupmode='$separategroups' AND c.groupmodeforce='1') )". - " OR d.groupid = '$groupid')"; + " OR (c.groupmode='$separategroups' AND c.groupmodeforce='1') )";//. + foreach ($groupid as $index => $value){ + $selectgroup .= " OR d.groupid = '$value'"; + } + $selectgroup .= ")"; + + // " OR d.groupid = '$groupid')"; $selectcourse = " AND d.course = '$courseid' AND c.id='$courseid'"; $coursetable = ", {$CFG->prefix}course c"; } else { @@ -1384,7 +1390,6 @@ function forum_get_user_discussions($courseid, $userid, $groupid=0) { ORDER BY p.created DESC"); } - function forum_subscribed_users($course, $forum, $groupid=0) { /// Returns list of user objects that are subscribed to this forum global $CFG; @@ -1881,7 +1886,7 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring="" if (!empty($group->picture) and empty($group->hidepicture)) { print_group_picture($group, $forum->course, false, false, true); } else if (isset($group->id)) { - echo ''.$group->name.''; + echo ''.$group->name.''; } echo "\n"; } @@ -2570,9 +2575,9 @@ function forum_user_has_posted_discussion($forumid, $userid) { } } -function forum_user_can_post_discussion($forum, $currentgroup=false) { +function forum_user_can_post_discussion($forum, $currentgroup=false, $groupmode='') { // $forum is an object - global $USER; + global $USER, $SESSION; if ($forum->type == "eachuser") { return (! forum_user_has_posted_discussion($forum->id, $USER->id)); @@ -2583,7 +2588,13 @@ function forum_user_can_post_discussion($forum, $currentgroup=false) { } else if (isteacher($forum->course)) { return true; } else { - return ($forum->open == 2); + //else it might be group 0 in visible mode + if ($groupmode == VISIBLEGROUPS){ + return ($forum->open == 2 AND ismember($currentgroup)); + } + else { + return ($forum->open == 2); + } } } @@ -2623,7 +2634,6 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis $currentgroup=-1, $groupmode=-1, $page=-1) { global $CFG, $USER; - /// Sort out some defaults if ((!$maxdiscussions) && ($displayformat == 'plain')) { @@ -2659,8 +2669,8 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions=5, $dis } /// If the user can post discussions, then this is a good place to put the button for it - - if (forum_user_can_post_discussion($forum, $currentgroup)) { + //add group mode in there, to test for visible group + if (forum_user_can_post_discussion($forum, $currentgroup, $groupmode)) { echo '
'; echo "
wwwroot/mod/forum/post.php\">"; echo "id\" />"; @@ -3608,10 +3618,8 @@ function forum_tp_clean_read_records() { delete_records('forum_read', 'id', $oldreadpost->id); } } - } - /** * Sets the last post for a given discussion **/ @@ -3653,4 +3661,20 @@ function forum_get_post_actions() { return array('add discussion','add post','delete discussion','delete post','move discussion','prune post','update post'); } +///this function returns all the separate forum ids, given a courseid +//@ param int $courseid +//@ return array +function forum_get_separate_modules($courseid) { + + global $CFG,$db; + $forummodule = get_record("modules", "name", "forum"); + + $sql = 'SELECT f.id, f.id FROM '.$CFG->prefix.'forum f, '.$CFG->prefix.'course_modules cm WHERE + f.id = cm.instance AND cm.module ='.$forummodule->id.' AND cm.visible = 1 AND cm.course = '.$courseid.' + AND cm.groupmode ='.SEPARATEGROUPS; + + return get_records_sql($sql); + +} + ?> diff --git a/mod/forum/post.php b/mod/forum/post.php index dff4dbb37f8..e8f110376bc 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -260,7 +260,7 @@ if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { if (groupmode($course, $cm) and !isteacheredit($course->id)) { // Make sure user can post here $mygroupid = mygroupid($course->id); - if (!((empty($mygroupid) and $discussion->groupid == -1) || ($mygroupid == $discussion->groupid))) { + if (!((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid)/*$mygroupid == $discussion->groupid*/))) { error("Sorry, but you can not post in this discussion."); } } diff --git a/mod/forum/user.php b/mod/forum/user.php index a1697572df4..8e277fbff2a 100644 --- a/mod/forum/user.php +++ b/mod/forum/user.php @@ -49,11 +49,16 @@ $currenttab = $mode; include($CFG->dirroot.'/user/tabs.php'); /// Prints out tabs as part of user page - $isseparategroups = ($course->groupmode == SEPARATEGROUPS and + $isseparategroups = /*(($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce and - !isteacheredit($course->id)); + !isteacheredit($course->id))*/forum_get_separate_modules($course->id); - $groupid = $isseparategroups ? get_current_group($course->id) : NULL; + //editting teacher can view everything so do not pass in groupid + if (isteacheredit ($course->id)){ + $isseparategroups = false; + } + + $groupid = $isseparategroups ? /*get_current_group*/mygroupid($course->id) : NULL; switch ($mode) { case 'posts' : diff --git a/mod/forum/view.php b/mod/forum/view.php index f63d6aa98f0..bf8df6db581 100644 --- a/mod/forum/view.php +++ b/mod/forum/view.php @@ -90,8 +90,9 @@ } else { $groupmode = groupmode($course, $cm); // Groups are being used } + $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); - + if ($groupmode and ($currentgroup === false) and !isteacheredit($course->id)) { print_heading(get_string("notingroup", "forum")); print_footer($course); @@ -103,7 +104,14 @@ echo ''; + ///2 ways to do this, 1. we can changed the setup_and_print_groups functions + ///in moodlelib, taking in 1 more parameter, and tell the function when to + ///allow student menus, 2, we can just use this code to explicitly print this + ///menu for students in forums. + + //now we need a menu for separategroups as well! if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { + //the following query really needs to change if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { echo ''; + } + } if (!empty($USER->id)) { echo '
'; print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id"); @@ -111,6 +119,23 @@ } } + //only print menus the student is in any course + else if ($groupmode == SEPARATEGROUPS){ + $validgroups = array(); + //get all the groups this guy is in in this course + + if ($p = user_group($course->id,$USER->id)){ + //extract the name and id for the group + foreach ($p as $index => $object){ + $validgroups[$object->id] = $object->name; + } + //print_r($validgroups); + echo ''; + //print them in the menu + print_group_menu($validgroups, $groupmode, $currentgroup, "view.php?id=$cm->id",0); + echo ''; @@ -248,6 +273,8 @@ } else { forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); } + + break; } diff --git a/mod/wiki/lib.php b/mod/wiki/lib.php index 6d65174c724..d2ebfcf6864 100644 --- a/mod/wiki/lib.php +++ b/mod/wiki/lib.php @@ -357,12 +357,9 @@ function wiki_get_default_entry(&$wiki, &$course, $userid=0, $groupid=0) { /// Optionally, will return wiki entry for $userid student wiki, or /// $groupid group or teacher wiki. /// Creates one if it needs to and it can. - global $USER; - /// If the wiki entry doesn't exist, can this user create it? if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false) { - if (wiki_can_add_entry($wiki, $USER, $course, $userid, $groupid)) { wiki_add_entry($wiki, $course, $userid, $groupid); if (($wiki_entry = wiki_get_entry($wiki, $course, $userid, $groupid)) === false) { @@ -370,6 +367,7 @@ function wiki_get_default_entry(&$wiki, &$course, $userid=0, $groupid=0) { } } } + //print_object($wiki_entry); return $wiki_entry; } @@ -400,15 +398,18 @@ function wiki_get_entry(&$wiki, &$course, $userid=0, $groupid=0) { case 'group': /// If there is a groupmode, get the user's group id. $groupmode = groupmode($course, $wiki); - + //echo "groupid is in wiki_get_entry ".$groupid."
"; /// If a specific group was requested, return it, if allowed. if ($groupid and wiki_user_can_access_group_wiki($wiki, $groupid, $course)) { $wentry = wiki_get_group_entry($wiki, $groupid); } else if ($groupmode) { + $mygroupids = mygroupid($course->id); /// If there is no entry for this user, check if this user is a teacher. - if (!$wentry = wiki_get_group_entry($wiki, mygroupid($course->id))) { -/* if (isteacher($course->id, $USER->id)) { + //this is broken for multiple groups /*mygroupid($course->id)*/ + //while ($groupindex < size(mygroupids) AND !$wentry = wiki_get_group_entry($)) + if (!$wentry = wiki_get_group_entry($wiki, $mygroupids[0])){//always default to first group it returns, can change later! + /* if (isteacher($course->id, $USER->id)) { /// If this user is a teacher, return the first entry. if ($wentries = wiki_get_entries($wiki)) { $wentry = current($wentries); @@ -425,7 +426,8 @@ function wiki_get_entry(&$wiki, &$course, $userid=0, $groupid=0) { case 'teacher': /// If there is a groupmode, get the user's group id. if (groupmode($course, $wiki)) { - $groupid = $groupid ? $groupid : mygroupid($course->id); + $mygroupids = mygroupid($course->id);//same here, default to the first one + $groupid = $groupid ? $groupid : $mygroupids[0]/*mygroupid($course->id)*/; } /// If a specific group was requested, return it, if allowed. @@ -501,6 +503,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { } } else if ($groupmode == SEPARATEGROUPS) { + if ($students = get_group_students($mygroupid)) { $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename; foreach ($students as $student) { @@ -566,6 +569,7 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { } if ($viewall !== false) { + $sql = 'SELECT w.id, w.userid, w.pagename, u.firstname, u.lastname ' .' FROM '.$CFG->prefix.'wiki_entries w, '.$CFG->prefix.'user u ' .' WHERE w.wikiid = '.$wiki->id.' AND u.id = w.userid ' @@ -588,6 +592,8 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { case 'group': /// If the user is an editing teacher, or a non-editing teacher not assigned to a group, show all group /// wikis, regardless of creation. + + /// If user is a member of multiple groups, need to show current group etc? /// Get all the existing entries for this wiki. $wiki_entries = wiki_get_entries($wiki, 'group'); @@ -610,6 +616,26 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { } } } + //if a studnet with multiple groups in SPG + else if ($groupmode == SEPARATEGROUPS){ + if ($groups = get_groups($course->id, $user->id)){ + + $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename; + foreach ($groups as $group) { + /// If this group already has an entry, use its pagename. + if (isset($wiki_entries[$group->id])) { + $pagename = $wiki_entries[$group->id]->pagename; + } + else { + $pagename = $defpagename; + } + $key = 'view.php?id='.$id.($group->id?"&groupid=".$group->id:"").'&page='.$pagename; + $wikis[$key] = $group->name.':'.$pagename; + } + + } + + } /// A user can see other group wikis if there are visible groups. else if ($groupmode == VISIBLEGROUPS) { $sql = 'SELECT w.id, w.groupid, w.pagename, g.name as gname ' @@ -686,9 +712,11 @@ function wiki_get_other_wikis(&$wiki, &$user, &$course, $currentid=0) { .' ORDER BY w.groupid'; $wiki_entries = get_records_sql($sql); $wiki_entries=is_array($wiki_entries)?$wiki_entries:array(); + + foreach ($wiki_entries as $wiki_entry) { - if (($viewall === true) or $viewall == $wiki_entry->groupid) { - $key = 'view.php??id='.$id.($wiki_entry->groupid?"&groupid=".$wiki_entry->groupid:"").'&page='.$wiki_entry->pagename; + if (($viewall === true) or @in_array($wiki_entry->groupid, $viewall)/*$viewall == $wiki_entry->groupid*/) { + $key = 'view.php?id='.$id.($wiki_entry->groupid?"&groupid=".$wiki_entry->groupid:"").'&page='.$wiki_entry->pagename; $wikis[$key] = $wiki_entry->gname.':'.$wiki_entry->pagename; if ($currentid == $wiki_entry->id) { $wikis['selected'] = $key; @@ -728,9 +756,12 @@ function wiki_add_entry(&$wiki, &$course, $userid=0, $groupid=0) { /// Get the groupmode. It's been added to the wiki object. $groupmode = groupmode($course, $wiki); + ///give the first groupid by default and try + $mygroups = mygroupid($course->id); + /// If there is a groupmode, get the group id. if ($groupmode) { - $groupid = $groupid ? $groupid : mygroupid($course->id); + $groupid = $groupid ? $groupid : $mygroups[0]/*mygroupid($course->id)*/; } /// If mode is 'nogroups', then groupid is zero. else { @@ -748,7 +779,8 @@ function wiki_add_entry(&$wiki, &$course, $userid=0, $groupid=0) { /// If there is a groupmode, get the user's group id. if ($groupmode and $groupid == 0) { - $groupid = mygroupid($course->id); + $mygroupid = mygroupid($course->id); + $groupid = $mygroupid[0]/*mygroupid($course->id)*/; } $wiki_entry->wikiid = $wiki->id; @@ -799,10 +831,12 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) { return ($mygroupid != 0); } /// If requesting a group, must be an editing teacher, a non-editing teacher with no assigned group, - /// or a non-editing teacher requesting their group. + /// or a non-editing teacher requesting their group. or a student in group, but wiki is empty. else { return (isteacheredit($course->id) or - (isteacher($course->id) and ($mygroupid == 0 or $mygroupid == $groupid))); + (isteacher($course->id) and ($mygroupid == 0 or @in_array($groupid, $mygroupid))) or + (isstudent($course->id, $user->id) and @in_array($groupid, $mygroupid)) + ); } break; @@ -819,7 +853,7 @@ function wiki_can_add_entry(&$wiki, &$user, &$course, $userid=0, $groupid=0) { /// in their group. Non-editing teachers with no assigned group and editing teachers can create any wiki. else { return (isteacheredit($course->id) or - (isteacher($course->id) and ($mygroupid == 0 or $mygroupid == $groupid))); + (isteacher($course->id) and ($mygroupid == 0 or @in_array($groupid, $mygroupid)))); } break; } @@ -875,7 +909,6 @@ function wiki_can_edit_entry(&$wiki_entry, &$wiki, &$user, &$course) { break; } } - return $can_edit; } @@ -925,7 +958,7 @@ function wiki_user_can_access_group_wiki(&$wiki, $groupid, &$course) { /// - they are an editing teacher or administrator, /// - they are a non-editing teacher not assigned to a specific group. if (($groupmode == NOGROUPS) or ($groupmode == VISIBLEGROUPS) or - (($groupmode == SEPARATEGROUPS) and ($usersgroup == $groupid)) or + (($groupmode == SEPARATEGROUPS) and @in_array($groupid, $usersgroup)/*($usersgroup == $groupid)*/) or (isteacheredit($course->id, $USER->id)) or (isteacher($course->id, $USER->id) and !$usersgroup)) { $can_access = true; @@ -948,7 +981,7 @@ function wiki_user_can_access_teacher_wiki(&$wiki, $groupid, &$course) { /// - group mode is SEPARATEGROUPS, and they are a member of the requested group, /// - they are a teacher or administrator, if (($groupmode == NOGROUPS) or ($groupmode == VISIBLEGROUPS) or - (($groupmode == SEPARATEGROUPS) and (mygroupid($course->id) == $groupid)) or + (($groupmode == SEPARATEGROUPS) and (@in_array($groupid, mygroupid($course->id))/*mygroupid($course->id) == $groupid*/)) or (isteacher($course->id, $USER->id))){ $can_access = true; } diff --git a/mod/wiki/view.php b/mod/wiki/view.php index 673d74571d8..fb3a760eeed 100644 --- a/mod/wiki/view.php +++ b/mod/wiki/view.php @@ -19,8 +19,6 @@ /// Only want to add edit log entries if we have made some changes ie submitted a form $editsave = optional_param('thankyou'); - - if ($id) { if (! $cm = get_record("course_modules", "id", $id)) { @@ -37,6 +35,7 @@ } else { if (! $wiki = get_record("wiki", "id", $wid)) { +echo "here?"; error("Course module is incorrect"); } if (! $course = get_record("course", "id", $wiki->course)) { @@ -62,9 +61,8 @@ /// Globally disable CamelCase, if the option is selected for this wiki. $moodle_disable_camel_case = ($wiki->disablecamelcase == 1); - + if (($wiki_entry = wiki_get_default_entry($wiki, $course, $userid, $groupid))) { - /// ################# EWIKI Part ########################### /// The wiki_entry->pagename is set to the specified value of the wiki, /// or the default value in the 'lang' file if the specified value was empty. @@ -215,6 +213,7 @@ else { $content = ''; $content2 = '
'.get_string('nowikicreated', 'wiki').'
'; + } # Group wiki, ...: No page and no ewiki_title @@ -250,10 +249,11 @@ /// Print Page echo '
'; - /// The top row contains links to other wikis, if applicable. if ($wiki_list = wiki_get_other_wikis($wiki, $USER, $course, $wiki_entry->id)) { + //echo "wiki list ";print_r($wiki_list); $selected=""; + if (isset($wiki_list['selected'])) { $selected = $wiki_list['selected']; unset($wiki_list['selected']); diff --git a/user/view.php b/user/view.php index 7cb087fdbfa..d4241159a09 100644 --- a/user/view.php +++ b/user/view.php @@ -55,7 +55,17 @@ if (groupmode($course) == SEPARATEGROUPS and !isteacheredit($course->id)) { // Groups must be kept separate require_login(); - if (!$currentuser && !isteacheredit($course->id, $user->id) && !ismember(mygroupid($course->id), $user->id)) { + ///this is changed because of mygroupid + $gtrue = false; + if ($mygroups = mygroupid($course->id)){ + foreach ($mygroups as $group){ + if (ismember($group, $user->id)){ + $gtrue = true; + } + } + } + + if (!$currentuser && !isteacheredit($course->id, $user->id) && !$gtrue) { print_header("$personalprofile: ", "$personalprofile: ", "id\">$course->shortname -> id\">$participants", @@ -108,8 +118,6 @@ $currenttab = 'profile'; include('tabs.php'); - - echo ""; echo ""; echo "
"; @@ -216,7 +224,12 @@ $courselisting = ''; foreach ($mycourses as $mycourse) { if ($mycourse->visible and $mycourse->category) { - $courselisting .= "wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">$mycourse->fullname, "; + if ($mycourse->id != $course->id){ + $courselisting .= "wwwroot/user/view.php?id=$user->id&course=$mycourse->id\">$mycourse->fullname, "; + } + else { + $courselisting .= "$mycourse->fullname, "; + } } } print_row(get_string('courses').':', rtrim($courselisting,', ')); @@ -230,11 +243,23 @@ } print_row(get_string("lastaccess").":", $datestring); + $groupstr = ''; + + ///printing groups + if (isteacher($course->id)){ + if ($mygroups = user_group($course->id, $user->id)){ + foreach ($mygroups as $group){ + $groupstr .= link_to_popup_window('/user/index.php?id='.$course->id.'&group='.$group->id,'popup',$group->name,400,500,'edit group','none',true).", "; + } + } + print_row(get_string("group").":", rtrim($groupstr, ', ')); + } + ///End of printing groups + echo "
"; echo "
"; - $internalpassword = false; if (is_internal_auth($USER->auth) or (!empty($CFG->{'auth_'.$USER->auth.'_stdchangepassword'}))) { if (empty($CFG->loginhttps)) { @@ -302,7 +327,6 @@ echo ""; echo "
\n"; - print_footer($course); /// Functions ///////