Index: moodle/admin/index.php =================================================================== --- moodle/admin/index.php (revision 1768) +++ moodle/admin/index.php (working copy) @@ -416,7 +416,53 @@ error("A problem occurred inserting current version into databases"); } } + + if(!public_private_tables()){ + if (empty($confirmupgrade)) { + $strdatabasechecking = get_string('publicprivateadd', 'admin'); + $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc'))); + print_header($strdatabasechecking, $stradministration, $navigation, + "", "", false, " ", " "); + notice(get_string('publicprivateupgradesure', 'admin'), 'index.php?confirmupgrade=1'); + print_footer('none'); + exit; + }else{ + $strdatabasesuccess = get_string("databasesuccess"); + $navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc'))); + print_header($strdatabasechecking, $stradministration, $navigation, + "", upgrade_get_javascript(), false, " ", " "); + + /// return to original debugging level + $CFG->debug = $origdebug; + error_reporting($CFG->debug); + upgrade_log_start(); + + print_heading($strdatabasechecking); + $db->debug=true; + /// Launch the old main upgrade (if exists) + $status = true; + if (function_exists('main_upgrade')) { + $status = main_upgrade($CFG->version); + } + /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade + if ($status && function_exists('xmldb_main_upgrade')) { + $status = xmldb_main_upgrade($CFG->version); + } + $db->debug=false; + /// If successful, continue upgrading roles and setting everything properly + if (!$status) { + notify('Public/Private Upgrade failed! See lib/db/upgrade.php'); + print_continue('index.php?confirmupgrade=1&confirmrelease=1&confirmplugincheck=1'); + print_footer('none'); + die; + } + upgrade_log_finish(); + } + + } + + /// Updated human-readable release version if necessary if ($release <> $CFG->release) { // Update the release version Index: moodle/admin/settings/misc.php =================================================================== --- moodle/admin/settings/misc.php (revision 1768) +++ moodle/admin/settings/misc.php (working copy) @@ -18,6 +18,15 @@ $temp->add(new admin_setting_configcheckbox('experimentalsplitrestore', get_string('experimentalsplitrestore', 'admin'), get_string('configexperimentalsplitrestore', 'admin'), 0)); $ADMIN->add('misc', $temp); + + $temp = new admin_settingpage('pubpri', get_string('publicprivate', 'admin')); + + $temp->add(new admin_setting_configcheckbox('enablepublicprivate', get_string('publicprivateenable', 'admin'), get_string('publicprivateenable_description', 'admin'), 1)); + $temp->add(new admin_setting_configcheckbox('default_publicprivate_on_restore', get_string('publicprivaterestore', 'admin'), get_string('publicprivaterestore_description', 'admin'), 1)); + $temp->add(new admin_setting_configcheckbox('publicprivate_option_enable', get_string('publicprivate_option_enable', 'admin'), get_string('publicprivate_option_enable_description', 'admin'), 1)); + $temp->add(new admin_setting_configcheckbox('publicprivate_option_aaenable', get_string('publicprivate_option_aaenable', 'admin'), get_string('publicprivate_option_aaenable_description', 'admin'), 0)); + + $ADMIN->add('misc', $temp); // XMLDB editor $ADMIN->add('misc', new admin_externalpage('xmldbeditor', get_string('xmldbeditor'), "$CFG->wwwroot/$CFG->admin/xmldb/")); Index: moodle/backup/backuplib.php =================================================================== --- moodle/backup/backuplib.php (revision 1768) +++ moodle/backup/backuplib.php (working copy) @@ -703,6 +703,12 @@ //fwrite ($bf,full_tag("SHOWRECENT",3,false,$course->showrecent)); INFO: This is out in 1.3 fwrite ($bf,full_tag("MAXBYTES",3,false,$course->maxbytes)); fwrite ($bf,full_tag("SHOWREPORTS",3,false,$course->showreports)); + if(isset($course->grouppublicprivate)){ + fwrite ($bf,full_tag("GROUPPUBLICPRIVATE",3,false,$course->grouppublicprivate)); + } + if(isset($course->groupautoassign)){ + fwrite ($bf,full_tag("GROUPAUTOASSIGN",3,false,$course->groupautoassign)); + } fwrite ($bf,full_tag("GROUPMODE",3,false,$course->groupmode)); fwrite ($bf,full_tag("GROUPMODEFORCE",3,false,$course->groupmodeforce)); fwrite ($bf,full_tag("DEFAULTGROUPINGID",3,false,$course->defaultgroupingid)); Index: moodle/backup/restorelib.php =================================================================== --- moodle/backup/restorelib.php (revision 1768) +++ moodle/backup/restorelib.php (working copy) @@ -787,6 +787,14 @@ //$course->showrecent = addslashes($course_header->course_showrecent); INFO: This is out in 1.3 $course->maxbytes = addslashes($course_header->course_maxbytes); $course->showreports = addslashes($course_header->course_showreports); + if (isset($course_header->course_grouppublicprivate)) { + $course->grouppublicprivate = addslashes($course_header->course_grouppublicprivate); + }elseif($CFG->default_publicprivate_on_restore && $CFG->enablepublicprivate){ + $enable_publicprivate_on_restore = true; + } + if (isset($course_header->course_groupautoassign)) { + $course->groupautoassign = addslashes($course_header->course_groupautoassign); + } if (isset($course_header->course_groupmode)) { $course->groupmode = addslashes($course_header->course_groupmode); } @@ -857,6 +865,10 @@ } else { $status = false; } + + if(isset($enable_publicprivate_on_restore) && $enable_publicprivate_on_restore == true){ + groups_activate_publicprivate($newid); + } } return $status; @@ -1092,6 +1104,10 @@ $info = restore_read_xml_sections($xml_file); } //Put the info in the DB, recoding ids and saving the in backup tables + + if($CFG->default_publicprivate_on_restore){ + $grouping_publicprivate = groups_get_grouping_publicprivate($restore->course_id); + } $sequence = ""; @@ -1196,6 +1212,10 @@ } $course_module->groupmembersonly = $mod->groupmembersonly; $course_module->instance = 0; + if($course_module->groupingid == 0 && isset($grouping_publicprivate) && $grouping_publicprivate != 0){ + $course_module->groupingid = $grouping_publicprivate; + $course_module->groupmembersonly = 1; + } //NOTE: The instance (new) is calculated and updated in db in the // final step of the restore. We don't know it yet. //print_object($course_module); //Debug @@ -3383,6 +3403,8 @@ } $status = true; + + $old_course_groupautoassign = get_field("course", "groupautoassign", "id", $restore->course_id); //Iterate over each group foreach ($groups as $group) { @@ -3427,6 +3449,10 @@ //If it doesn't exist, create $newid = insert_record('groups', $gro); + if($old_course_groupautoassign == $group->id){ + set_field("course", "groupautoassign", $newid, "id", $restore->course_id); + } + } else { //get current group id $newid = $gro_db->id; @@ -5488,6 +5514,13 @@ case "SHOWREPORTS": $this->info->course_showreports = $this->getContents(); break; + // We have to parse this data out of the XML file if we want to use it! + case "GROUPPUBLICPRIVATE": + $this->info->course_grouppublicprivate = $this->getContents(); + break; + case "GROUPAUTOASSIGN": + $this->info->course_groupautoassign = $this->getContents(); + break; case "GROUPMODE": $this->info->course_groupmode = $this->getContents(); break; Index: moodle/blocks/news_items/block_news_items.php =================================================================== --- moodle/blocks/news_items/block_news_items.php (revision 1768) +++ moodle/blocks/news_items/block_news_items.php (working copy) @@ -27,10 +27,20 @@ require_once($CFG->dirroot.'/mod/forum/lib.php'); // We'll need this $text = ''; + + $news_forum = get_records_select("forum", "course = '$COURSE->id' AND type = 'news' "); if (!$forum = forum_get_course_forum($COURSE->id, 'news')) { return ''; } + + if (empty($news_forum)) + { + $grouping_id = groups_get_grouping_publicprivate($COURSE->id); + $course_module = get_record("course_modules", "instance", $forum->id, "course", $COURSE->id); + set_coursemodule_groupingid($course_module->id, $grouping_id); + set_coursemodule_groupmembersonly($course_module->id,1); + } $modinfo = get_fast_modinfo($COURSE); if (empty($modinfo->instances['forum'][$forum->id])) { Index: moodle/calendar/lib.php =================================================================== --- moodle/calendar/lib.php (revision 1768) +++ moodle/calendar/lib.php (working copy) @@ -1594,6 +1594,14 @@ $allowed->groups = groups_get_all_groups($SESSION->cal_course_referer, $USER->id); } } + + $tgroupsarr = $allowed->groups; + unset($allowed->groups); + foreach($tgroupsarr as $tgroup){ + if($tgroup->id != $course->groupautoassign){ + $allowed->groups[] = $tgroup; + } + } } } Index: moodle/course/edit_form.php =================================================================== --- moodle/course/edit_form.php (revision 1768) +++ moodle/course/edit_form.php (working copy) @@ -273,6 +273,48 @@ //-------------------------------------------------------------------------------- $mform->addElement('header','', get_string('groups', 'group')); + if(has_capability('moodle/course:setgrouppublicprivate', $coursecontext) || $CFG->publicprivate_option_enable == 1){ + + if($CFG->enablepublicprivate == 1 || $course->grouppublicprivate == 1){ + + $choices = array(); + $choices[0] = get_string('disable'); + $choices[1] = get_string('enable'); + + $mform->addElement('select', 'grouppublicprivate', get_string('publicprivate'), $choices); + $mform->setHelpButton('grouppublicprivate', array('grouppublicprivate', get_string('publicprivate')), true); + if(empty($course->grouppublicprivate)){ + $mform->setDefault('grouppublicprivate', 1); + }else{ + $mform->setDefault('grouppublicprivate', $course->grouppublicprivate); + } + + } + } + + if(has_capability('moodle/course:setgroupautoassign', $coursecontext) || $CFG->publicprivate_option_aaenable == 1){ + + $coursegroups = groups_get_all_groups($course->id); + $formcoursegroups = array(); + + $formcoursegroups[0] = "Do not auto-assign"; + + if ($coursegroups) { + foreach ($coursegroups as $group) { + $formcoursegroups[$group->id] = $group->name; + } + } + + if($course->grouppublicprivate == 0){ + $mform->addElement('select', 'groupautoassign', get_string('autoassignuserstogroup'), $formcoursegroups); + }else{ + $mform->addElement('select', 'groupautoassign', get_string('autoassignuserstogroup'), $formcoursegroups, 'DISABLED'); + } + $mform->setHelpButton('groupautoassign', array('groupautoassign', get_string('autoassignuserstogroup')), true); + $mform->setDefault('groupautoassign', $course->groupautoassign); + + } + $choices = array(); $choices[NOGROUPS] = get_string('groupsnone', 'group'); $choices[SEPARATEGROUPS] = get_string('groupsseparate', 'group'); Index: moodle/course/lib.php =================================================================== --- moodle/course/lib.php (revision 1768) +++ moodle/course/lib.php (working copy) @@ -1,7 +1,6 @@ duplicate = get_string("duplicate"); $str->hide = get_string("hide"); $str->show = get_string("show"); + $str->public = get_string("publicprivatemakepublic"); + $str->private = get_string("publicprivatemakeprivate"); $str->clicktochange = get_string("clicktochange"); $str->forcedmode = get_string("forcedmode"); $str->groupsnone = get_string("groupsnone"); @@ -2722,7 +2723,22 @@ } else { $hideshow = ''; } - + + $course = get_record('course', 'id', $mod->course); + if($course->grouppublicprivate == 1){ + if(coursemodule_visible_for_user($mod, 1)){ + $pubpriv = ''."\n"; + }else{ + $pubpriv = ''."\n"; + } + } + if ($mod->groupmode !== false) { if ($mod->groupmode == SEPARATEGROUPS) { $grouptitle = $str->groupsseparate; @@ -2806,7 +2822,7 @@ ''."\n".$hideshow.$groupmode."\n".''; + ' alt="'.$str->delete.'" />'."\n".$hideshow.$pubpriv.$groupmode."\n".''; } /** @@ -3290,6 +3306,14 @@ if (empty($data->sortorder)) { $data->sortorder = 100; } + + if(empty($data->grouppublicprivate)){ + if($CFG->enablepublicprivate){ + $data->grouppublicprivate = 1; + }else{ + $data->grouppublicprivate = 0; + } + } if ($newcourseid = insert_record('course', $data)) { // Set up new course @@ -3316,6 +3340,15 @@ // Trigger events events_trigger('course_created', $course); + /******** START UCLA MOD *******/ + // ERIC BOLLENS - CCLE-657 + + if($course->grouppublicprivate == 1){ + groups_activate_publicprivate($course->id); + } + + /********* END UCLA MOD ********/ + return $course; } @@ -3378,6 +3411,32 @@ // Trigger events events_trigger('course_updated', $course); + + /******** START UCLA MOD *******/ + // ERIC BOLLENS - CCLE-657 + + // only do something if the grouppublicprivate value has changed + if( (isset($oldcourse->grouppublicprivate) && isset($data->grouppublicprivate)) && + $oldcourse->grouppublicprivate != $data->grouppublicprivate){ + if($data->grouppublicprivate == 1){ + $data->groupautoassign = groups_activate_publicprivate($course->id); + }else{ + $data->groupautoassign = groups_deactivate_publicprivate($course->id, $oldcourse->groupautoassign); + } + } + + /********* END UCLA MOD ********/ + + /******** START UCLA MOD *******/ + // ERIC BOLLENS - CCLE-652 + + if( (isset($oldcourse->groupautoassign) && isset($data->groupautoassign)) && + $oldcourse->groupautoassign != $data->groupautoassign){ + groups_remove_autoassigned($data->groupautoassign, $course->id); + } + groups_add_autoassigned($data->groupautoassign, $course->id); + + /********* END UCLA MOD ********/ return true; Index: moodle/course/mod.php =================================================================== --- moodle/course/mod.php (revision 1768) +++ moodle/course/mod.php (working copy) @@ -23,6 +23,8 @@ $duplicate = optional_param('duplicate', 0, PARAM_INT); $cancel = optional_param('cancel', 0, PARAM_BOOL); $cancelcopy = optional_param('cancelcopy', 0, PARAM_BOOL); + $private = optional_param('private', 0, PARAM_INT); + $public = optional_param('public', 0, PARAM_INT); if (isset($SESSION->modform)) { // Variables are stored in the session $mod = $SESSION->modform; @@ -185,13 +187,25 @@ $mod->groupmode = $course->groupmode; /// Default groupmode the same as course } - if (isset($mod->groupingid)) { - set_coursemodule_groupingid($mod->coursemodule, $mod->groupingid); + if(!isset($course->grouppublicprivate) || $course->grouppublicprivate == 0){ + + if (isset($mod->groupingid)) { + set_coursemodule_groupingid($mod->coursemodule, $mod->groupingid); + } + + if (isset($mod->groupmembersonly)) { + set_coursemodule_groupmembersonly($mod->coursemodule, $mod->groupmembersonly); + } + + }else{ + + $groupingid = groups_get_grouping_publicprivate($course->id); + + set_coursemodule_groupingid($mod->coursemodule, $groupingid); + set_coursemodule_groupmembersonly($mod->coursemodule, 1); + } - if (isset($mod->groupmembersonly)) { - set_coursemodule_groupmembersonly($mod->coursemodule, $mod->groupmembersonly); - } $mod->instance = $return; // course_modules and course_sections each contain a reference @@ -389,6 +403,58 @@ } exit; + } else if (!empty($private) and confirm_sesskey()) { + + if (! $cm = get_record("course_modules", "id", $private)) { + error("This course module doesn't exist"); + } + + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:activityvisibility', $context); + + $groupingid = groups_get_grouping_publicprivate($cm->course); + + if($groupingid != 0){ + + set_coursemodule_groupingid($cm->id, $groupingid); + set_coursemodule_groupmembersonly($cm->id, 1); + + rebuild_course_cache($cm->course); + + } + + if (SITEID == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course#section-$sectionreturn"); + } + + exit; + + } else if (!empty($public) and confirm_sesskey()) { + + if (! $cm = get_record("course_modules", "id", $public)) { + error("This course module doesn't exist"); + } + + require_login($cm->course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:activityvisibility', $context); + + set_coursemodule_groupingid($cm->id, 0); + set_coursemodule_groupmembersonly($cm->id, 0); + + rebuild_course_cache($cm->course); + + if (SITEID == $cm->course) { + redirect($CFG->wwwroot); + } else { + redirect("view.php?id=$cm->course#section-$sectionreturn"); + } + + exit; + } else if ($groupmode > -1 and confirm_sesskey()) { $id = required_param( 'id', PARAM_INT ); Index: moodle/course/modedit.php =================================================================== --- moodle/course/modedit.php (revision 1768) +++ moodle/course/modedit.php (working copy) @@ -1,459 +1,465 @@ -libdir.'/gradelib.php'); - - require_login(); - - $add = optional_param('add', 0, PARAM_ALPHA); - $update = optional_param('update', 0, PARAM_INT); - $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true - $type = optional_param('type', '', PARAM_ALPHANUM); - - if (!empty($add)) { - $section = required_param('section', PARAM_INT); - $course = required_param('course', PARAM_INT); - - if (! $course = get_record("course", "id", $course)) { - error("This course doesn't exist"); - } - - require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $course->id); - require_capability('moodle/course:manageactivities', $context); - - if (! $module = get_record("modules", "name", $add)) { - error("This module type doesn't exist"); - } - - $cw = get_course_section($section, $course->id); - - if (!course_allowed_module($course, $module->id)) { - error("This module has been disabled for this particular course"); - } - - $cm = null; - - $form->section = $section; // The section number itself - relative!!! (section column in course_sections) - $form->visible = $cw->visible; - $form->course = $course->id; - $form->module = $module->id; - $form->modulename = $module->name; - $form->groupmode = $course->groupmode; - $form->groupingid = $course->defaultgroupingid; - $form->groupmembersonly = 0; - $form->instance = ''; - $form->coursemodule = ''; - $form->add = $add; - $form->return = 0; //must be false if this is an add, go back to course view on cancel - - // Turn off default grouping for modules that don't provide group mode - if($add=='resource' || $add=='glossary' || $add=='label') { - $form->groupingid=0; - } - - if (!empty($type)) { - $form->type = $type; - } - - $sectionname = get_section_name($course->format); - $fullmodulename = get_string("modulename", $module->name); - - if ($form->section && $course->format != 'site') { - $heading->what = $fullmodulename; - $heading->to = "$sectionname $form->section"; - $pageheading = get_string("addinganewto", "moodle", $heading); - } else { - $pageheading = get_string("addinganew", "moodle", $fullmodulename); - } - - $CFG->pagepath = 'mod/'.$module->name; - if (!empty($type)) { - $CFG->pagepath .= '/'.$type; - } else { - $CFG->pagepath .= '/mod'; - } - - $navlinksinstancename = ''; - } else if (!empty($update)) { - if (! $cm = get_record("course_modules", "id", $update)) { - error("This course module doesn't exist"); - } - - if (! $course = get_record("course", "id", $cm->course)) { - error("This course doesn't exist"); - } - - require_login($course); // needed to setup proper $COURSE - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('moodle/course:manageactivities', $context); - - if (! $module = get_record("modules", "id", $cm->module)) { - error("This module doesn't exist"); - } - - if (! $form = get_record($module->name, "id", $cm->instance)) { - error("The required instance of this module doesn't exist"); - } - - if (! $cw = get_record("course_sections", "id", $cm->section)) { - error("This course section doesn't exist"); - } - - $form->coursemodule = $cm->id; - $form->section = $cw->section; // The section number itself - relative!!! (section column in course_sections) - $form->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides - $form->cmidnumber = $cm->idnumber; // The cm IDnumber - $form->groupmode = groups_get_activity_groupmode($cm); // locked later if forced - $form->groupingid = $cm->groupingid; - $form->groupmembersonly = $cm->groupmembersonly; - $form->course = $course->id; - $form->module = $module->id; - $form->modulename = $module->name; - $form->instance = $cm->instance; - $form->return = $return; - $form->update = $update; - - if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename, - 'iteminstance'=>$form->instance, 'courseid'=>$COURSE->id))) { - // add existing outcomes - foreach ($items as $item) { - if (!empty($item->outcomeid)) { - $form->{'outcome_'.$item->outcomeid} = 1; - } - } - - // set category if present - $gradecat = false; - foreach ($items as $item) { - if ($gradecat === false) { - $gradecat = $item->categoryid; - continue; - } - if ($gradecat != $item->categoryid) { - //mixed categories - $gradecat = false; - break; - } - } - if ($gradecat !== false) { - // do not set if mixed categories present - $form->gradecat = $gradecat; - } - } - - $sectionname = get_section_name($course->format); - $fullmodulename = get_string("modulename", $module->name); - - if ($form->section && $course->format != 'site') { - $heading->what = $fullmodulename; - $heading->in = "$sectionname $cw->section"; - $pageheading = get_string("updatingain", "moodle", $heading); - } else { - $pageheading = get_string("updatinga", "moodle", $fullmodulename); - } - - $navlinksinstancename = array('name' => format_string($form->name,true), 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id", 'type' => 'activityinstance'); - - $CFG->pagepath = 'mod/'.$module->name; - if (!empty($type)) { - $CFG->pagepath .= '/'.$type; - } else { - $CFG->pagepath .= '/mod'; - } - } else { - error('Invalid operation.'); - } - - $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php"; - if (file_exists($modmoodleform)) { - require_once($modmoodleform); - - } else { - error('No formslib form description file found for this activity.'); - } - - $modlib = "$CFG->dirroot/mod/$module->name/lib.php"; - if (file_exists($modlib)) { - include_once($modlib); - } else { - error("This module is missing important code! ($modlib)"); - } - - $mformclassname = 'mod_'.$module->name.'_mod_form'; - $mform =& new $mformclassname($form->instance, $cw->section, $cm); - $mform->set_data($form); - - if ($mform->is_cancelled()) { - if ($return && !empty($cm->id)){ - redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); - } else { - redirect("view.php?id=$course->id#section-".$cw->section); - } - } else if ($fromform = $mform->get_data()) { - if (empty($fromform->coursemodule)) { //add - $cm = null; - if (! $course = get_record("course", "id", $fromform->course)) { - error("This course doesn't exist"); - } - $fromform->instance = ''; - $fromform->coursemodule = ''; - } else { //update - if (! $cm = get_record("course_modules", "id", $fromform->coursemodule)) { - error("This course module doesn't exist"); - } - - if (! $course = get_record("course", "id", $cm->course)) { - error("This course doesn't exist"); - } - $fromform->instance = $cm->instance; - $fromform->coursemodule = $cm->id; - } - - require_login($course->id); // needed to setup proper $COURSE - - if (!empty($fromform->coursemodule)) { - $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); - } else { - $context = get_context_instance(CONTEXT_COURSE, $course->id); - } - require_capability('moodle/course:manageactivities', $context); - - $fromform->course = $course->id; - $fromform->modulename = clean_param($fromform->modulename, PARAM_SAFEDIR); // For safety - - $addinstancefunction = $fromform->modulename."_add_instance"; - $updateinstancefunction = $fromform->modulename."_update_instance"; - - if (!isset($fromform->groupingid)) { - $fromform->groupingid = 0; - } - - if (!isset($fromform->groupmembersonly)) { - $fromform->groupmembersonly = 0; - } - - if (!isset($fromform->name)) { //label - $fromform->name = $fromform->modulename; - } - - if (!empty($fromform->update)) { - - if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { - $fromform->groupmode = $cm->groupmode; // keep original - } - - $returnfromfunc = $updateinstancefunction($fromform); - if (!$returnfromfunc) { - error("Could not update the $fromform->modulename", "view.php?id=$course->id"); - } - if (is_string($returnfromfunc)) { - error($returnfromfunc, "view.php?id=$course->id"); - } - - set_coursemodule_visible($fromform->coursemodule, $fromform->visible); - set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode); - set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid); - set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly); - - if (isset($fromform->cmidnumber)) { //label - // set cm idnumber - set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); - } - - add_to_log($course->id, "course", "update mod", - "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", - "$fromform->modulename $fromform->instance"); - add_to_log($course->id, $fromform->modulename, "update", - "view.php?id=$fromform->coursemodule", - "$fromform->instance", $fromform->coursemodule); - - } else if (!empty($fromform->add)){ - - if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { - $fromform->groupmode = 0; // do not set groupmode - } - - if (!course_allowed_module($course,$fromform->modulename)) { - error("This module ($fromform->modulename) has been disabled for this particular course"); - } - - $returnfromfunc = $addinstancefunction($fromform); - if (!$returnfromfunc) { - error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id"); - } - if (is_string($returnfromfunc)) { - error($returnfromfunc, "view.php?id=$course->id"); - } - - $fromform->instance = $returnfromfunc; - - // course_modules and course_sections each contain a reference - // to each other, so we have to update one of them twice. - - if (! $fromform->coursemodule = add_course_module($fromform) ) { - error("Could not add a new course module"); - } - if (! $sectionid = add_mod_to_section($fromform) ) { - error("Could not add the new course module to that section"); - } - - if (! set_field("course_modules", "section", $sectionid, "id", $fromform->coursemodule)) { - error("Could not update the course module with the correct section"); - } - - // make sure visibility is set correctly (in particular in calendar) - set_coursemodule_visible($fromform->coursemodule, $fromform->visible); - - if (isset($fromform->cmidnumber)) { //label - // set cm idnumber - set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); - } - - add_to_log($course->id, "course", "add mod", - "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", - "$fromform->modulename $fromform->instance"); - add_to_log($course->id, $fromform->modulename, "add", - "view.php?id=$fromform->coursemodule", - "$fromform->instance", $fromform->coursemodule); - } else { - error("Data submitted is invalid."); - } - - // sync idnumber with grade_item - if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, - 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$COURSE->id))) { - if ($grade_item->idnumber != $fromform->cmidnumber) { - $grade_item->idnumber = $fromform->cmidnumber; - $grade_item->update(); - } - } - - $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, - 'iteminstance'=>$fromform->instance, 'courseid'=>$COURSE->id)); - - // create parent category if requested and move to correct parent category - if ($items and isset($fromform->gradecat)) { - if ($fromform->gradecat == -1) { - $grade_category = new grade_category(); - $grade_category->courseid = $COURSE->id; - $grade_category->fullname = stripslashes($fromform->name); - $grade_category->insert(); - if ($grade_item) { - $parent = $grade_item->get_parent_category(); - $grade_category->set_parent($parent->id); - } - $fromform->gradecat = $grade_category->id; - } - foreach ($items as $itemid=>$unused) { - $items[$itemid]->set_parent($fromform->gradecat); - if ($itemid == $grade_item->id) { - // use updated grade_item - $grade_item = $items[$itemid]; - } - } - } - - // add outcomes if requested - if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { - $grade_items = array(); - - // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes - $max_itemnumber = 999; - if ($items) { - foreach($items as $item) { - if ($item->itemnumber > $max_itemnumber) { - $max_itemnumber = $item->itemnumber; - } - } - } - - foreach($outcomes as $outcome) { - $elname = 'outcome_'.$outcome->id; - - if (array_key_exists($elname, $fromform) and $fromform->$elname) { - // so we have a request for new outcome grade item? - if ($items) { - foreach($items as $item) { - if ($item->outcomeid == $outcome->id) { - //outcome aready exists - continue 2; - } - } - } - - $max_itemnumber++; - - $outcome_item = new grade_item(); - $outcome_item->courseid = $COURSE->id; - $outcome_item->itemtype = 'mod'; - $outcome_item->itemmodule = $fromform->modulename; - $outcome_item->iteminstance = $fromform->instance; - $outcome_item->itemnumber = $max_itemnumber; - $outcome_item->itemname = $outcome->fullname; - $outcome_item->outcomeid = $outcome->id; - $outcome_item->gradetype = GRADE_TYPE_SCALE; - $outcome_item->scaleid = $outcome->scaleid; - $outcome_item->insert(); - - // move the new outcome into correct category and fix sortorder if needed - if ($grade_item) { - $outcome_item->set_parent($grade_item->categoryid); - $outcome_item->move_after_sortorder($grade_item->sortorder); - - } else if (isset($fromform->gradecat)) { - $outcome_item->set_parent($fromform->gradecat); - } - } - } - } - - rebuild_course_cache($course->id); - grade_regrade_final_grades($course->id); - - if (isset($fromform->submitbutton)) { - redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); - } else { - redirect("$CFG->wwwroot/course/view.php?id=$course->id"); - } - exit; - - } else { - if (!empty($cm->id)) { - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - } else { - $context = get_context_instance(CONTEXT_COURSE, $course->id); - } - require_capability('moodle/course:manageactivities', $context); - - $streditinga = get_string("editinga", "moodle", $fullmodulename); - $strmodulenameplural = get_string("modulenameplural", $module->name); - - $navlinks = array(); - $navlinks[] = array('name' => $strmodulenameplural, 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", 'type' => 'activity'); - if ($navlinksinstancename) { - $navlinks[] = $navlinksinstancename; - } - $navlinks[] = array('name' => $streditinga, 'link' => '', 'type' => 'title'); - - $navigation = build_navigation($navlinks); - - print_header_simple($streditinga, '', $navigation, $mform->focus(), "", false); - - if (!empty($cm->id)) { - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $overridableroles = get_overridable_roles($context); - $assignableroles = get_assignable_roles($context); - $currenttab = 'update'; - include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php'); - } - $icon = ''; - - print_heading_with_help($pageheading, "mods", $module->name, $icon); - $mform->display(); - print_footer($course); - } -?> +libdir.'/gradelib.php'); + + require_login(); + + $add = optional_param('add', 0, PARAM_ALPHA); + $update = optional_param('update', 0, PARAM_INT); + $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true + $type = optional_param('type', '', PARAM_ALPHANUM); + + if (!empty($add)) { + $section = required_param('section', PARAM_INT); + $course = required_param('course', PARAM_INT); + + if (! $course = get_record("course", "id", $course)) { + error("This course doesn't exist"); + } + + require_login($course); + $context = get_context_instance(CONTEXT_COURSE, $course->id); + require_capability('moodle/course:manageactivities', $context); + + if (! $module = get_record("modules", "name", $add)) { + error("This module type doesn't exist"); + } + + $cw = get_course_section($section, $course->id); + + if (!course_allowed_module($course, $module->id)) { + error("This module has been disabled for this particular course"); + } + + $cm = null; + + $form->section = $section; // The section number itself - relative!!! (section column in course_sections) + $form->visible = $cw->visible; + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->groupmode = $course->groupmode; + $form->groupingid = $course->defaultgroupingid; + $form->groupmembersonly = 0; + $form->instance = ''; + $form->coursemodule = ''; + $form->add = $add; + $form->return = 0; //must be false if this is an add, go back to course view on cancel + + if($course->grouppublicprivate == 1){ + + $form->groupingid = groups_get_grouping_publicprivate($course->id); + $form->groupmembersonly = 1; + + } + // Turn off default grouping for modules that don't provide group mode but only if public/private is off + elseif($add=='resource' || $add=='glossary' || $add=='label') { + $form->groupingid=0; + } + + if (!empty($type)) { + $form->type = $type; + } + + $sectionname = get_section_name($course->format); + $fullmodulename = get_string("modulename", $module->name); + + if ($form->section && $course->format != 'site') { + $heading->what = $fullmodulename; + $heading->to = "$sectionname $form->section"; + $pageheading = get_string("addinganewto", "moodle", $heading); + } else { + $pageheading = get_string("addinganew", "moodle", $fullmodulename); + } + + $CFG->pagepath = 'mod/'.$module->name; + if (!empty($type)) { + $CFG->pagepath .= '/'.$type; + } else { + $CFG->pagepath .= '/mod'; + } + + $navlinksinstancename = ''; + } else if (!empty($update)) { + if (! $cm = get_record("course_modules", "id", $update)) { + error("This course module doesn't exist"); + } + + if (! $course = get_record("course", "id", $cm->course)) { + error("This course doesn't exist"); + } + + require_login($course); // needed to setup proper $COURSE + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + require_capability('moodle/course:manageactivities', $context); + + if (! $module = get_record("modules", "id", $cm->module)) { + error("This module doesn't exist"); + } + + if (! $form = get_record($module->name, "id", $cm->instance)) { + error("The required instance of this module doesn't exist"); + } + + if (! $cw = get_record("course_sections", "id", $cm->section)) { + error("This course section doesn't exist"); + } + + $form->coursemodule = $cm->id; + $form->section = $cw->section; // The section number itself - relative!!! (section column in course_sections) + $form->visible = $cm->visible; //?? $cw->visible ? $cm->visible : 0; // section hiding overrides + $form->cmidnumber = $cm->idnumber; // The cm IDnumber + $form->groupmode = groups_get_activity_groupmode($cm); // locked later if forced + $form->groupingid = $cm->groupingid; + $form->groupmembersonly = $cm->groupmembersonly; + $form->course = $course->id; + $form->module = $module->id; + $form->modulename = $module->name; + $form->instance = $cm->instance; + $form->return = $return; + $form->update = $update; + + if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$form->modulename, + 'iteminstance'=>$form->instance, 'courseid'=>$COURSE->id))) { + // add existing outcomes + foreach ($items as $item) { + if (!empty($item->outcomeid)) { + $form->{'outcome_'.$item->outcomeid} = 1; + } + } + + // set category if present + $gradecat = false; + foreach ($items as $item) { + if ($gradecat === false) { + $gradecat = $item->categoryid; + continue; + } + if ($gradecat != $item->categoryid) { + //mixed categories + $gradecat = false; + break; + } + } + if ($gradecat !== false) { + // do not set if mixed categories present + $form->gradecat = $gradecat; + } + } + + $sectionname = get_section_name($course->format); + $fullmodulename = get_string("modulename", $module->name); + + if ($form->section && $course->format != 'site') { + $heading->what = $fullmodulename; + $heading->in = "$sectionname $cw->section"; + $pageheading = get_string("updatingain", "moodle", $heading); + } else { + $pageheading = get_string("updatinga", "moodle", $fullmodulename); + } + + $navlinksinstancename = array('name' => format_string($form->name,true), 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id", 'type' => 'activityinstance'); + + $CFG->pagepath = 'mod/'.$module->name; + if (!empty($type)) { + $CFG->pagepath .= '/'.$type; + } else { + $CFG->pagepath .= '/mod'; + } + } else { + error('Invalid operation.'); + } + + $modmoodleform = "$CFG->dirroot/mod/$module->name/mod_form.php"; + if (file_exists($modmoodleform)) { + require_once($modmoodleform); + + } else { + error('No formslib form description file found for this activity.'); + } + + $modlib = "$CFG->dirroot/mod/$module->name/lib.php"; + if (file_exists($modlib)) { + include_once($modlib); + } else { + error("This module is missing important code! ($modlib)"); + } + + $mformclassname = 'mod_'.$module->name.'_mod_form'; + $mform =& new $mformclassname($form->instance, $cw->section, $cm); + $mform->set_data($form); + + if ($mform->is_cancelled()) { + if ($return && !empty($cm->id)){ + redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id"); + } else { + redirect("view.php?id=$course->id#section-".$cw->section); + } + } else if ($fromform = $mform->get_data()) { + if (empty($fromform->coursemodule)) { //add + $cm = null; + if (! $course = get_record("course", "id", $fromform->course)) { + error("This course doesn't exist"); + } + $fromform->instance = ''; + $fromform->coursemodule = ''; + } else { //update + if (! $cm = get_record("course_modules", "id", $fromform->coursemodule)) { + error("This course module doesn't exist"); + } + + if (! $course = get_record("course", "id", $cm->course)) { + error("This course doesn't exist"); + } + $fromform->instance = $cm->instance; + $fromform->coursemodule = $cm->id; + } + + require_login($course->id); // needed to setup proper $COURSE + + if (!empty($fromform->coursemodule)) { + $context = get_context_instance(CONTEXT_MODULE, $fromform->coursemodule); + } else { + $context = get_context_instance(CONTEXT_COURSE, $course->id); + } + require_capability('moodle/course:manageactivities', $context); + + $fromform->course = $course->id; + $fromform->modulename = clean_param($fromform->modulename, PARAM_SAFEDIR); // For safety + + $addinstancefunction = $fromform->modulename."_add_instance"; + $updateinstancefunction = $fromform->modulename."_update_instance"; + + if (!isset($fromform->groupingid)) { + $fromform->groupingid = 0; + } + + if (!isset($fromform->groupmembersonly)) { + $fromform->groupmembersonly = 0; + } + + if (!isset($fromform->name)) { //label + $fromform->name = $fromform->modulename; + } + + if (!empty($fromform->update)) { + + if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { + $fromform->groupmode = $cm->groupmode; // keep original + } + + $returnfromfunc = $updateinstancefunction($fromform); + if (!$returnfromfunc) { + error("Could not update the $fromform->modulename", "view.php?id=$course->id"); + } + if (is_string($returnfromfunc)) { + error($returnfromfunc, "view.php?id=$course->id"); + } + + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); + set_coursemodule_groupmode($fromform->coursemodule, $fromform->groupmode); + set_coursemodule_groupingid($fromform->coursemodule, $fromform->groupingid); + set_coursemodule_groupmembersonly($fromform->coursemodule, $fromform->groupmembersonly); + + if (isset($fromform->cmidnumber)) { //label + // set cm idnumber + set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); + } + + add_to_log($course->id, "course", "update mod", + "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", + "$fromform->modulename $fromform->instance"); + add_to_log($course->id, $fromform->modulename, "update", + "view.php?id=$fromform->coursemodule", + "$fromform->instance", $fromform->coursemodule); + + } else if (!empty($fromform->add)){ + + if (!empty($course->groupmodeforce) or !isset($fromform->groupmode)) { + $fromform->groupmode = 0; // do not set groupmode + } + + if (!course_allowed_module($course,$fromform->modulename)) { + error("This module ($fromform->modulename) has been disabled for this particular course"); + } + + $returnfromfunc = $addinstancefunction($fromform); + if (!$returnfromfunc) { + error("Could not add a new instance of $fromform->modulename", "view.php?id=$course->id"); + } + if (is_string($returnfromfunc)) { + error($returnfromfunc, "view.php?id=$course->id"); + } + + $fromform->instance = $returnfromfunc; + + // course_modules and course_sections each contain a reference + // to each other, so we have to update one of them twice. + + if (! $fromform->coursemodule = add_course_module($fromform) ) { + error("Could not add a new course module"); + } + if (! $sectionid = add_mod_to_section($fromform) ) { + error("Could not add the new course module to that section"); + } + + if (! set_field("course_modules", "section", $sectionid, "id", $fromform->coursemodule)) { + error("Could not update the course module with the correct section"); + } + + // make sure visibility is set correctly (in particular in calendar) + set_coursemodule_visible($fromform->coursemodule, $fromform->visible); + + if (isset($fromform->cmidnumber)) { //label + // set cm idnumber + set_coursemodule_idnumber($fromform->coursemodule, $fromform->cmidnumber); + } + + add_to_log($course->id, "course", "add mod", + "../mod/$fromform->modulename/view.php?id=$fromform->coursemodule", + "$fromform->modulename $fromform->instance"); + add_to_log($course->id, $fromform->modulename, "add", + "view.php?id=$fromform->coursemodule", + "$fromform->instance", $fromform->coursemodule); + } else { + error("Data submitted is invalid."); + } + + // sync idnumber with grade_item + if ($grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, + 'iteminstance'=>$fromform->instance, 'itemnumber'=>0, 'courseid'=>$COURSE->id))) { + if ($grade_item->idnumber != $fromform->cmidnumber) { + $grade_item->idnumber = $fromform->cmidnumber; + $grade_item->update(); + } + } + + $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$fromform->modulename, + 'iteminstance'=>$fromform->instance, 'courseid'=>$COURSE->id)); + + // create parent category if requested and move to correct parent category + if ($items and isset($fromform->gradecat)) { + if ($fromform->gradecat == -1) { + $grade_category = new grade_category(); + $grade_category->courseid = $COURSE->id; + $grade_category->fullname = stripslashes($fromform->name); + $grade_category->insert(); + if ($grade_item) { + $parent = $grade_item->get_parent_category(); + $grade_category->set_parent($parent->id); + } + $fromform->gradecat = $grade_category->id; + } + foreach ($items as $itemid=>$unused) { + $items[$itemid]->set_parent($fromform->gradecat); + if ($itemid == $grade_item->id) { + // use updated grade_item + $grade_item = $items[$itemid]; + } + } + } + + // add outcomes if requested + if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) { + $grade_items = array(); + + // Outcome grade_item.itemnumber start at 1000, there is nothing above outcomes + $max_itemnumber = 999; + if ($items) { + foreach($items as $item) { + if ($item->itemnumber > $max_itemnumber) { + $max_itemnumber = $item->itemnumber; + } + } + } + + foreach($outcomes as $outcome) { + $elname = 'outcome_'.$outcome->id; + + if (array_key_exists($elname, $fromform) and $fromform->$elname) { + // so we have a request for new outcome grade item? + if ($items) { + foreach($items as $item) { + if ($item->outcomeid == $outcome->id) { + //outcome aready exists + continue 2; + } + } + } + + $max_itemnumber++; + + $outcome_item = new grade_item(); + $outcome_item->courseid = $COURSE->id; + $outcome_item->itemtype = 'mod'; + $outcome_item->itemmodule = $fromform->modulename; + $outcome_item->iteminstance = $fromform->instance; + $outcome_item->itemnumber = $max_itemnumber; + $outcome_item->itemname = $outcome->fullname; + $outcome_item->outcomeid = $outcome->id; + $outcome_item->gradetype = GRADE_TYPE_SCALE; + $outcome_item->scaleid = $outcome->scaleid; + $outcome_item->insert(); + + // move the new outcome into correct category and fix sortorder if needed + if ($grade_item) { + $outcome_item->set_parent($grade_item->categoryid); + $outcome_item->move_after_sortorder($grade_item->sortorder); + + } else if (isset($fromform->gradecat)) { + $outcome_item->set_parent($fromform->gradecat); + } + } + } + } + + rebuild_course_cache($course->id); + grade_regrade_final_grades($course->id); + + if (isset($fromform->submitbutton)) { + redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); + } else { + redirect("$CFG->wwwroot/course/view.php?id=$course->id"); + } + exit; + + } else { + if (!empty($cm->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + } else { + $context = get_context_instance(CONTEXT_COURSE, $course->id); + } + require_capability('moodle/course:manageactivities', $context); + + $streditinga = get_string("editinga", "moodle", $fullmodulename); + $strmodulenameplural = get_string("modulenameplural", $module->name); + + $navlinks = array(); + $navlinks[] = array('name' => $strmodulenameplural, 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id", 'type' => 'activity'); + if ($navlinksinstancename) { + $navlinks[] = $navlinksinstancename; + } + $navlinks[] = array('name' => $streditinga, 'link' => '', 'type' => 'title'); + + $navigation = build_navigation($navlinks); + + print_header_simple($streditinga, '', $navigation, $mform->focus(), "", false); + + if (!empty($cm->id)) { + $context = get_context_instance(CONTEXT_MODULE, $cm->id); + $overridableroles = get_overridable_roles($context); + $assignableroles = get_assignable_roles($context); + $currenttab = 'update'; + include_once($CFG->dirroot.'/'.$CFG->admin.'/roles/tabs.php'); + } + $icon = ''; + + print_heading_with_help($pageheading, "mods", $module->name, $icon); + $mform->display(); + print_footer($course); + } +?> Index: moodle/course/rest.php =================================================================== --- moodle/course/rest.php (revision 1768) +++ moodle/course/rest.php (working copy) @@ -95,6 +95,19 @@ case 'visible': set_coursemodule_visible($mod->id, $value); break; + + case 'private': + $groupingid = groups_get_grouping_publicprivate($mod->course); + if($groupingid != 0){ + set_coursemodule_groupingid($mod->id, $groupingid); + set_coursemodule_groupmembersonly($mod->id, 1); + } + break; + + case 'public': + set_coursemodule_groupingid($mod->id, 0); + set_coursemodule_groupmembersonly($mod->id, 0); + break; case 'groupmode': set_coursemodule_groupmode($mod->id, $value); Index: moodle/course/view.php =================================================================== --- moodle/course/view.php (revision 1768) +++ moodle/course/view.php (working copy) @@ -198,6 +198,10 @@ $PAGE->print_header(get_string('course').': %fullname%', NULL, '', $bodytags); // Course wrapper start. echo '
'; + + if($course->grouppublicprivate == 1 && (!isset($USER->id) || $USER->id == 1)){ + echo '
AttentionThis is the public display of the course site. If you are enrolled, please log in to view private course materials.
'; + } $modinfo =& get_fast_modinfo($COURSE); get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); Index: moodle/group/assign.php =================================================================== --- moodle/group/assign.php (revision 1768) +++ moodle/group/assign.php (working copy) @@ -31,12 +31,20 @@ } else if (isset($frm->add) and !empty($frm->addselect)) { foreach ($frm->addselect as $groupid) { + if( !($course->grouppublicprivate == 1 && $course->groupautoassign == (int)$groupid) ){ groups_assign_grouping($grouping->id, (int)$groupid); + }else{ + $error_editingspecialgroup = 1; + } } } else if (isset($frm->remove) and !empty($frm->removeselect)) { foreach ($frm->removeselect as $groupid) { + if( !($course->grouppublicprivate == 1 && $course->groupautoassign == (int)$groupid) ){ groups_unassign_grouping($grouping->id, (int)$groupid); + }else{ + $error_editingspecialgroup = 1; + } } } } @@ -105,6 +113,10 @@ ?>

+ + +

WARNING: You may not add or remove the Course Members group, for it is a component of public/private functionality.

+
Index: moodle/group/group.php =================================================================== --- moodle/group/group.php (revision 1768) +++ moodle/group/group.php (working copy) @@ -58,9 +58,13 @@ if ($id and $delete) { if (!$confirm) { print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group')); + if($course->groupautoassign == $group->id && $course->grouppublicprivate == 1){ + notice('

WARNING: This is a special group for public/private. It cannot be edited. To remove it, public/private must be turned off.

', 'index.php?id=' . $course->id); + }else{ $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1); $optionsno = array('id'=>$courseid); notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get'); + } print_footer(); die; Index: moodle/group/grouping.php =================================================================== --- moodle/group/grouping.php (revision 1768) +++ moodle/group/grouping.php (working copy) @@ -52,9 +52,14 @@ if ($id and $delete) { if (!$confirm) { print_header(get_string('deletegrouping', 'group'), get_string('deletegrouping', 'group')); + if($grouping->id == groups_get_grouping_publicprivate($course->id, $course->groupautoassign) + && $course->grouppublicprivate == 1){ + notice('

WARNING: This is a special grouping for public/private. It cannot be edited. To remove it, public/private must be turned off.

', 'groupings.php?id=' . $course->id); + }else{ $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1); $optionsno = array('id'=>$courseid); notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get'); + } print_footer(); die; Index: moodle/group/lib.php =================================================================== --- moodle/group/lib.php (revision 1768) +++ moodle/group/lib.php (working copy) @@ -13,6 +13,18 @@ * require_once $CFG->dirroot.'/group/lib.php' must be used */ + /** UCLA Modifications: + * CCLE-271 - Public/Private Functionality - Eric Bollens + * groups_add_autoassigned() :: adds a user to the autoassign group + * groups_add_member_with_type() :: extension of groups_remove_member() + * groups_remove_autoassigned() :: removes a user from the autoassign group + * groups_remove_member_with_type() :: extension of groups_remove_member() + * groups_is_member_with_type() :: extension of groups_is_member() + * groups_activate_publicprivate() :: activates public/private for a course + * groups_deactivate_publicprivate() :: deactivates public/private for a course + * groups_get_grouping_publicprivate() :: finds grouping the public/private group is in + */ + /** * Adds a specified user to a group * @param int $userid The user id @@ -725,4 +737,321 @@ return $roles; } +/******** START UCLA MOD *******/ +// ERIC BOLLENS - CCLE-652 + +/** + * Function to add all course users to auto-assigned group. + * + * @param int $groupid Group all users should be auto-assigned to. + * @param int $courseid The course where group actions are performed. + */ +function groups_add_autoassigned($groupid, $courseid){ + if($groupid != 0){ + global $CFG; + $context = get_context_instance(CONTEXT_COURSE, $courseid); + $sql = "SELECT DISTINCT ra.userid + FROM " . $CFG->prefix . "role_assignments ra + WHERE ra.contextid = " . $context->id; + $rs = get_recordset_sql($sql); + while($row = rs_fetch_next_record($rs)){ + if(!groups_add_member_with_type($groupid, $row->userid, 'auto')){ + print_error('erroraddremoveuser', 'group', $returnurl); + } + } + } +} + +/** + * Adds a specified user to a group with type setting + * @param int $userid The user id + * @param int $groupid The group id + * @param varchar $type The type name + * @return boolean True if user added successfully or the user is already a + * member of the group, false otherwise. + */ +function groups_add_member_with_type($groupid, $userid, $type) { + if (!groups_group_exists($groupid)) { + return false; + } + + if (groups_is_member_with_type($groupid, $userid, $type)) { + return true; + } + + $member = new object(); + $member->groupid = $groupid; + $member->userid = $userid; + $member->timeadded = time(); + $member->type = $type; + + if (!insert_record('groups_members', $member)) { + return false; + } + + //update group info + set_field('groups', 'timemodified', $member->timeadded, 'id', $groupid); + + // MDL-9983 + $eventdata = new object(); + $eventdata->groupid = $groupid; + $eventdata->userid = $userid; + events_trigger('group_user_added', $eventdata); + + return true; +} + +/** + * Function to remove all auto-assigned group assignments except $groupid. + * + * @param int $groupid All other auto-assigned group assignments to be deleted. + * @param int $courseid The course where group actions are performed. + */ +function groups_remove_autoassigned($groupid, $courseid){ + global $CFG; + $sql = "SELECT gm.groupid, gm.userid + FROM " . $CFG->prefix . "groups_members gm + LEFT JOIN " . $CFG->prefix . "groups gr ON gm.groupid = gr.id + WHERE gm.type = 'auto' AND gr.courseid = " . $courseid; + $rs = get_recordset_sql($sql); + while($row = rs_fetch_next_record($rs)){ + if($row->groupid != $groupid){ + if(!groups_remove_member_with_type($row->groupid, $row->userid, "auto")){ + print_error('erroraddremoveuser', 'group', $returnurl); + } + } + } +} + +/** + * Deletes the link between the specified user and group with type. + * @param int $groupid The group to delete the user from + * @param int $userid The user to delete + * @param varchar $type The type name + * @return boolean True if deletion was successful, false otherwise + */ +function groups_remove_member_with_type($groupid, $userid, $type) { + if (!groups_group_exists($groupid)) { + return false; + } + + if (!groups_is_member_with_type($groupid, $userid, $type)) { + return true; + } + + if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid, 'type', $type)) { + return false; + } + //update group info + set_field('groups', 'timemodified', time(), 'id', $groupid); + + return true; +} + +/** + * Determines if the user is a member of the given group with type. + * NOTE: the original version of this file is in lib/groupslib.php + * + * @uses $USER If $userid is null, use the global object. + * @param int $groupid The group to check for membership. + * @param int $userid The user to check against the group. + * @param varchar $type The type name + * @return boolean True if the user is a member, false otherwise. + */ +function groups_is_member_with_type($groupid, $userid=null, $type=null) { + global $USER; + + if (!$userid) { + $userid = $USER->id; + } + + return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid, 'type', $type); +} + + +/********* END UCLA MOD ********/ + +/******** START UCLA MOD *******/ +// ERIC BOLLENS - CCLE-657 + +/** + * Activates public/private group functionality for a course. + * @param int $courseid The course to activate functionality for + */ +function groups_activate_publicprivate($courseid){ + + global $CFG; + + // act on an existing 'Course Members' group + if($groupid = groups_get_group_by_name($courseid, get_string('publicprivategroupname'))){ + $data = groups_get_group($groupid); + // have to make sure we don't get an error by trying to overwrite + // existing _deprecated_ group. we'll cycle through with a while + // loop until we find a safe value if necessary. + if(!groups_get_group_by_name($courseid, $data->name . ' ' . get_string('autoassigndeprecatedgroup'))){ + $data->name = $data->name . ' ' . get_string('autoassigndeprecatedgroup'); + }else{ + $i = 1; + while(groups_get_group_by_name($courseid, $data->name . ' ' . get_string('autoassigndeprecatedgroup') . ' [' . $i . ']')){ + $i++; + } + $data->name = $data->name . ' ' . get_string('autoassigndeprecatedgroup') . ' [' . $i . ']'; + } + if(!groups_update_group($data)){ + error('Error updating group'); + } + unset($data); + } + + // create the new 'Course Members' group + $data = new object(); + $data->courseid = $courseid; + $data->name = get_string('publicprivategroupname'); + $data->description = 'Group created and used for public/private functionality. All users should belong to this group.'; + if(!($newgroupid = groups_create_group($data))){ + error('Error creating group'); + } + unset($data); + + // act on an existing 'Private Course Material' grouping + if($groupingid = groups_get_grouping_by_name($courseid, get_string('publicprivategroupingname'))){ + $data = groups_get_grouping($groupingid); + // have to make sure we don't get an error by trying to overwrite + // existing _deprecated_ group. we'll cycle through with a while + // loop until we find a safe value if necessary. + if(!groups_get_grouping_by_name($courseid, $data->name . ' ' . get_string('autoassigndeprecatedgroup'))){ + $data->name = $data->name . ' ' . get_string('autoassigndeprecatedgroup'); + }else{ + $i = 1; + while(groups_get_grouping_by_name($courseid, $data->name . ' ' . get_string('autoassigndeprecatedgroup') . ' [' . $i . ']')){ + $i++; + } + $data->name = $data->name . ' ' . get_string('autoassigndeprecatedgroup') . ' [' . $i . ']'; + } + if(!groups_update_grouping($data)){ + error('Error updating grouping'); + } + unset($data); + } + + // create new 'Private Course Material' grouping + $data = new object(); + $data->courseid = $courseid; + $data->name = get_string('publicprivategroupingname'); + $data->description = 'Grouping created and used for public/private functionality. ' . get_string('publicprivategroupname') . ' group should be in this grouping.'; + if(!($newgroupingid = groups_create_grouping($data))){ + error('Error creating grouping'); + } + unset($data); + + // now have a new 'Course Members' group and 'Private Course Material' grouping + // they have IDs stored in: $newgroupid and $newgroupingid + + // need to add the group to the grouping + if(!groups_assign_grouping($newgroupingid, $newgroupid)){ + error('Error linking group and grouping'); + } + + // need to update course settings + if(!set_field("course", "grouppublicprivate", 1, "id", $courseid) + || !set_field("course", "groupautoassign", $newgroupid, "id", $courseid) + || !set_field("course", "guest", 1, "id", $courseid)){ + error('Failed to apply public/private course settings'); + } + + // need to set all 'public' course modules to private initially + $sql = "SELECT * + FROM " . $CFG->prefix . "course_modules + WHERE course = " . $courseid . " + AND groupmembersonly = 0 + AND groupingid = 0;"; + $mods = get_recordset_sql($sql); + while($mod = rs_fetch_next_record($mods)){ + set_coursemodule_groupingid($mod->id, $newgroupingid); + set_coursemodule_groupmembersonly($mod->id, 1); + } + + /* CCLE-829 :: autoassigned stuff should be automatically set on activation */ + groups_remove_autoassigned($newgroupid, $courseid); + groups_add_autoassigned($newgroupid, $courseid); + + // feed back the newgroupid so that it can be set as the autoassign group + return $newgroupid; + +} + +/** + * Deactivates public/private group functionality for a course. + * @param int $courseid The course to deactivate functionality for + */ +function groups_deactivate_publicprivate($courseid, $groupautoassign){ + + $groupid = $groupautoassign; + $groupingid = groups_get_grouping_publicprivate($courseid, $groupautoassign); + + // detect public/private group + if($groupid == 0){ + error('Discontinuity in public/private course settings [groupid]'); + } + + if($groupingid == 0){ + error('Discontinuity in public/private course settings [groupingid]'); + } + + // need to remove groupmembersonly setting to prevent discontinuity: CCLE-678 + set_field('course_modules', 'groupmembersonly', 0, 'groupingid', $groupingid); + // now delete group and grouping + groups_delete_group($groupid); + groups_delete_grouping($groupingid); + + // need to update course settings + if(!set_field("course", "grouppublicprivate", 0, "id", $courseid) + || !set_field("course", "groupautoassign", 0, "id", $courseid) + || !set_field("course", "guest", 0, "id", $courseid)){ + error('Failed to apply public/private course settings'); + } + + /* CCLE-829 :: remove all autoassigned for groupid = 0 doesn't exist */ + groups_remove_autoassigned(0, $courseid); + + return $course->groupautoassign; +} + +/********* END UCLA MOD ********/ + +/******** START UCLA MOD *******/ +// ERIC BOLLENS - CCLE-659 + +/** + * Finds the public/private grouping for a course, or returns false. + * @param int $courseid The course to find public/private group for + * @return int Returns grouping id if exists, or 0 if not. + */ +function groups_get_grouping_publicprivate($courseid, $groupautoassign=NULL){ + + global $CFG; + + if($groupautoassign == NULL){ + $course = get_record('course', 'id', $courseid); + if(!isset($course->grouppublicprivate) || $course->grouppublicprivate == 0){ + return 0; + } + $groupautoassign = $course->groupautoassign; + } + + $sql = "SELECT gr.id AS id + FROM " . $CFG->prefix . "groupings gr + LEFT JOIN " . $CFG->prefix . "groupings_groups gg + ON gg.groupingid = gr.id + WHERE gr.courseid = " . $courseid . " + AND gg.groupid = " . $groupautoassign; + if(!($grouping = get_record_sql($sql))){ + error("Public/private mismatch with group and grouping."); + } + return $grouping->id; + +} + +/********* END UCLA MOD ********/ + ?> Index: moodle/group/members.php =================================================================== --- moodle/group/members.php (revision 1768) +++ moodle/group/members.php (working copy) @@ -206,8 +206,11 @@

- + groupautoassign == $groupid && $course->grouppublicprivate == 1){ ?> +

WARNING: This is a special group for public/private. It cannot be edited.

+ +
@@ -230,8 +233,10 @@

+ groupautoassign != $groupid || $course->grouppublicprivate != 1){ ?>
+

Index: moodle/lang/en_utf8/admin.php =================================================================== --- moodle/lang/en_utf8/admin.php (revision 1768) +++ moodle/lang/en_utf8/admin.php (working copy) @@ -814,5 +814,17 @@ $string['xmlrpcrecommended'] = 'Installing the optional xmlrpc extension is useful for Moodle Networking functionality.'; $string['xmlstrictheaders'] = 'XML strict headers'; $string['ziprequired'] = 'The Zip PHP extension is now required by Moodle, info-ZIP binaries or PclZip library are not used anymore.'; +$string['publicprivate'] = 'Public/Private'; +$string['publicprivateadd'] = 'Add Public/Private functionality'; +$string['publicprivateupgradesure'] = 'Public/Private functionality appears to be present, but not installed.

+Moodle would now like to install Public/Private functionality on the server.

'; +$string['publicprivateenable'] = 'Enable Public/Private'; +$string['publicprivateenable_description'] = 'This setting enables the use of the experimental public/private modification. Groupings must be enabled for this to work correctly. NOTE: Disabling this will turn off public/private toggle, but sites already using public/private will still operate via the method.'; +$string['publicprivaterestore'] = 'Default Public/Private on Restore'; +$string['publicprivaterestore_description'] = 'In the event that a restore occurs from an instance of Moodle that does not include public/private, if this setting is defined, the restored course will default to public/private enabled.'; +$string['publicprivate_option_enable'] = 'Course Editors Can Set Public/Private'; +$string['publicprivate_option_enable_description'] = 'If checked, course editors can turn public/private on/off. Otherwise, only administrators can do this.'; +$string['publicprivate_option_aaenable'] = 'Course Editors Can Set Group Auto-Assign'; +$string['publicprivate_option_aaenable_description'] = 'If checked, course editors can define an auto-assign group for a course (unless public/private is set in which case this setting is frozen). Otherwise, only administrators can do this.'; ?> Index: moodle/lang/en_utf8/help/groupautoassign.html =================================================================== --- moodle/lang/en_utf8/help/groupautoassign.html (revision 0) +++ moodle/lang/en_utf8/help/groupautoassign.html (revision 0) @@ -0,0 +1,3 @@ +

Group Auto-Assign

+ +

All users in a course will automatically be assigned to a group if it is set in the Course Settings. All users automatically assigned to a group can be removed from their auto-assignments simply by changing the auto-assigned group, or by changing the setting back to "Do not auto-assign".

\ No newline at end of file Index: moodle/lang/en_utf8/help/grouppublicprivate.html =================================================================== --- moodle/lang/en_utf8/help/grouppublicprivate.html (revision 0) +++ moodle/lang/en_utf8/help/grouppublicprivate.html (revision 0) @@ -0,0 +1,5 @@ +

Public/Private Functionality

+ +

Enabling public/private functionality for a course alters several settings in order to create a hybrid course with both public and private material.

+ +

When enabled, it will create a toggle for all activities that allow for the material to be set either private to course users or public to guests as well. To this end, it creates a special group ("Course Members") and a special grouping ("Private Course Material"). It disables the auto-assign groups and available to guest settings.

\ No newline at end of file Index: moodle/lang/en_utf8/moodle.php =================================================================== --- moodle/lang/en_utf8/moodle.php (revision 1768) +++ moodle/lang/en_utf8/moodle.php (working copy) @@ -1,7 +1,6 @@ Index: moodle/lang/en_utf8/role.php =================================================================== --- moodle/lang/en_utf8/role.php (revision 1768) +++ moodle/lang/en_utf8/role.php (working copy) @@ -195,4 +195,7 @@ $string['user:viewusergrades'] = 'View user grades'; $string['course:managegrades'] = 'Manage grades'; +$string['course:setgrouppublicprivate'] = 'Modify public/private setting'; +$string['course:setgroupautoassign'] = 'Modify group auto-assign setting'; + ?> Index: moodle/lib/accesslib.php =================================================================== --- moodle/lib/accesslib.php (revision 1768) +++ moodle/lib/accesslib.php (working copy) @@ -2938,7 +2938,17 @@ if (!$ra->id = insert_record('role_assignments', $ra)) { return false; } - + + // if the role assignment is at a course context level, we need to check for an auto-assign + if($context->contextlevel == CONTEXT_COURSE){ + $course = get_record('course', 'id', $context->instanceid); + if($course->groupautoassign != 0){ + if(!groups_add_member_with_type($course->groupautoassign, $userid, 'auto')){ + print_error('erroraddremoveuser', 'group', $returnurl); + } + } + } + } else { // We already have one, just update it $ra->id = $ra->id; $ra->hidden = $hidden; @@ -3068,6 +3078,15 @@ // delete lastaccess records delete_records('user_lastaccess', 'userid', $ra->userid, 'courseid', $context->instanceid); + + // if the role assignment is at a course context level, we need to check for an auto-assign + $course = get_record('course', 'id', $context->instanceid); + if($course->groupautoassign != 0){ + if(!groups_remove_member_with_type($course->groupautoassign, $ra->userid, 'auto')){ + print_error('erroraddremoveuser', 'group', $returnurl); + } + } + } //unassign roles in metacourses if needed Index: moodle/lib/ajax/ajaxlib.php =================================================================== --- moodle/lib/ajax/ajaxlib.php (revision 1768) +++ moodle/lib/ajax/ajaxlib.php (working copy) @@ -167,6 +167,8 @@ $output .= " main.portal.strings['hide']='".get_string('hide')."';\n"; $output .= " main.portal.strings['hidesection']='".get_string('hidesection', '', '_var_')."';\n"; $output .= " main.portal.strings['show']='".get_string('show')."';\n"; + $output .= " main.portal.strings['publicprivatemakepublic']='".get_string('publicprivatemakepublic')."';\n"; + $output .= " main.portal.strings['publicprivatemakeprivate']='".get_string('publicprivatemakeprivate')."';\n"; $output .= " main.portal.strings['delete']='".get_string('delete')."';\n"; $output .= " main.portal.strings['move']='".get_string('move')."';\n"; $output .= " main.portal.strings['movesection']='".get_string('movesection', '', '_var_')."';\n"; Index: moodle/lib/ajax/section_classes.js =================================================================== --- moodle/lib/ajax/section_classes.js (revision 1768) +++ moodle/lib/ajax/section_classes.js (working copy) @@ -614,6 +614,10 @@ this.groupmode = this.SEPARATEGROUPS; } else if (buttons[x].className == 'editing_groupsvisible') { this.groupmode = this.VISIBLEGROUPS; + } else if (buttons[x].className == 'editing_makepublic') { + this.publicprivate = 1; + } else if (buttons[x].className == 'editing_makeprivate') { + this.publicprivate = 0; } } @@ -670,6 +674,15 @@ commandContainer.appendChild(button); this.viewButton = button; + if (this.publicprivate == 0) { + var button = main.mk_button('a', '/t/public.png', main.portal.strings['publicprivatemakeprivate']); + } else { + var button = main.mk_button('a', '/t/private.png', main.portal.strings['publicprivatemakepublic']); + } + YAHOO.util.Event.addListener(button, 'click', this.toggle_publicprivate, this, true); + commandContainer.appendChild(button); + this.viewButton = button; + // Add the groupmode button if needed. if (this.groupmode != null) { if (this.groupmode == this.NOGROUPS) { @@ -794,7 +807,41 @@ } } +resource_class.prototype.toggle_publicprivate = function(target, e, superficial, force) { + var strpublic = main.portal.strings['publicprivatemakeprivate']; + var strprivate = main.portal.strings['publicprivatemakepublic']; + if (force != null) { + if (this.debug) { + YAHOO.log("Resource "+this.getEl().id+" forced to "+force); + } + this.hidden = !force; + } + // this is for when it's public (unlocked icon) + if (this.publicprivate == 0) { + this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/public.png/i, 'private.png'); + this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strpublic, strprivate); + this.viewButton.title = this.viewButton.title.replace(strpublic, strprivate); + this.publicprivate = 1; + if (!superficial) { + main.connect('POST', 'class=resource&field=private', null, 'id='+this.id); + } + document.location.reload(); + // this is for when it's private (locked icon) + } else { + this.viewButton.childNodes[0].src = this.viewButton.childNodes[0].src.replace(/private.png/i, 'public.png'); + this.viewButton.childNodes[0].alt = this.viewButton.childNodes[0].alt.replace(strprivate, strpublic); + this.viewButton.title = this.viewButton.title.replace(strprivate, strpublic); + this.publicprivate = 0; + + if (!superficial) { + main.connect('POST', 'class=resource&field=public', null, 'id='+this.id); + } + document.location.reload(); + } +} + + resource_class.prototype.groupImages = ['/t/groupn.gif', '/t/groups.gif', '/t/groupv.gif']; Index: moodle/lib/db/access.php =================================================================== --- moodle/lib/db/access.php (revision 1768) +++ moodle/lib/db/access.php (working copy) @@ -1021,6 +1021,25 @@ ) ), + 'moodle/course:setgrouppublicprivate' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + + 'moodle/course:setgroupautoassign' => array( + + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'admin' => CAP_ALLOW + ) + ), + 'moodle/site:mnetlogintoremote' => array( 'captype' => 'read', Index: moodle/lib/db/install.xml =================================================================== --- moodle/lib/db/install.xml (revision 1768) +++ moodle/lib/db/install.xml (working copy) @@ -53,8 +53,10 @@ - - + + + + @@ -1554,7 +1556,8 @@ - + + Index: moodle/lib/db/upgrade.php =================================================================== --- moodle/lib/db/upgrade.php (revision 1768) +++ moodle/lib/db/upgrade.php (working copy) @@ -3168,6 +3168,24 @@ $db->debug = true; // Restoring debug level upgrade_main_savepoint($result, 2007101547); } + + if( !public_private_tables() ){ + + update_capabilities(); + + $crs = new XMLDBTable('course'); + $crs_gpp = new XMLDBField('grouppublicprivate'); + $crs_gpp->setAttributes(XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, 0, 'hiddensections'); + $crs_gaa = new XMLDBField('groupautoassign'); + $crs_gaa->setAttributes(XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, null, 0, 'grouppublicprivate'); + $gm = new XMLDBTable('groups_members'); + $gm_t = new XMLDBField('type'); + $gm_t->setAttributes(XMLDB_TYPE_CHAR, '36', null, XMLDB_NOTNULL, null, null, null, ''); + $result = $result && add_field($crs, $crs_gpp); + $result = $result && add_field($crs, $crs_gaa); + $result = $result && add_field($gm, $gm_t); + + } return $result; } Index: moodle/lib/db/upgradelib.php =================================================================== --- moodle/lib/db/upgradelib.php (revision 1768) +++ moodle/lib/db/upgradelib.php (working copy) @@ -691,4 +691,37 @@ rs_close($rs); } +function public_private_tables(){ + + global $CFG; + + $course_groupautoassign = false; + $course_grouppublicprivate = false; + $groups_members_type = false; + + $sql = "SHOW columns IN {$CFG->prefix}course"; + $rs = get_recordset_sql($sql); + while ($rec = rs_fetch_next_record($rs)){ + if($rec->Field == 'grouppublicprivate'){ + $course_grouppublicprivate = true; + }elseif($rec->Field == 'groupautoassign'){ + $course_groupautoassign = true; + } + } + + $sql = "SHOW columns IN {$CFG->prefix}groups_members"; + $rs = get_recordset_sql($sql); + while ($rec = rs_fetch_next_record($rs)){ + if($rec->Field == 'type'){ + $groups_members_type = true; + } + } + + if($course_grouppublicprivate && $course_groupautoassign && $groups_members_type){ + return true; + } + + return false; +} + ?> Index: moodle/lib/grouplib.php =================================================================== --- moodle/lib/grouplib.php (revision 1768) +++ moodle/lib/grouplib.php (working copy) @@ -431,11 +431,12 @@ function groups_print_activity_menu($cm, $urlroot, $return=false, $hideallparticipants=false) { global $CFG, $USER, $SESSION; - // groupings are ignored when not enabled - if (empty($CFG->enablegroupings)) { + // ignore groupings in all cases! + // if (empty($CFG->enablegroupings)) { $cm->groupingid = 0; - } + // } + // groupings are ignored when not enabled if (!$groupmode = groups_get_activity_groupmode($cm)) { if ($return) { return ''; @@ -487,12 +488,16 @@ $groupsmenu[0] = get_string('allparticipants'); } + // Ensure that the group is not the auto-assign group + $course = get_record('course', 'id', $cm->course); if ($allowedgroups) { foreach ($allowedgroups as $group) { + if($group->id != $course->groupautoassign){ $groupsmenu[$group->id] = format_string($group->name); } + } } - + if ($groupmode == VISIBLEGROUPS) { $grouplabel = get_string('groupsvisible'); } else { @@ -596,11 +601,12 @@ function groups_get_activity_group($cm, $update=false) { global $CFG, $USER, $SESSION; - // groupings are ignored when not enabled - if (empty($CFG->enablegroupings)) { + // ignore groupings in all cases! + // if (empty($CFG->enablegroupings)) { $cm->groupingid = 0; - } + // } + // groupings are ignored when not enabled if (!$groupmode = groups_get_activity_groupmode($cm)) { // NOGROUPS used return false; @@ -625,8 +631,15 @@ $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = 0; // all groups by default if user has accessallgroups } else if ($usergroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid)) { - $fistgroup = reset($usergroups); - $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = $fistgroup->id; + // Ensure that the group is not the auto-assign group + $course = get_record('course', 'id', $cm->course); + foreach ($usergroups as $group) { + if($group->id != $course->groupautoassign && empty($SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid])){ + $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = $group->id; + } + } + // $fistgroup = reset($usergroups); + // $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = $fistgroup->id; } else { // this happen when user not assigned into group in SEPARATEGROUPS mode or groups do not exist yet @@ -659,6 +672,12 @@ } } + // Ensure that the group is not the auto-assign group + $course = get_record('course', 'id', $cm->course); + if($SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] == $course->groupautoassign){ + $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid] = 0; + } + return $SESSION->activegroup[$cm->course][$groupmode][$cm->groupingid]; } @@ -676,6 +695,9 @@ $userid=$USER->id; } + // ignore groupings in all cases! + $cm->groupingid = 0; + // Get groupmode for activity, taking into account course settings $groupmode=groups_get_activity_groupmode($cm); Index: moodle/mod/wiki/lib.php =================================================================== --- moodle/mod/wiki/lib.php (revision 1768) +++ moodle/mod/wiki/lib.php (working copy) @@ -399,18 +399,8 @@ $groupmode = groups_get_activity_groupmode($wiki); // if groups mode is in use and no group supplied, use the first one found if ($groupmode && !$groupid) { - if(($mygroupids=mygroupid($course->id)) && count($mygroupids)>0) { - // Use first group. They ought to be able to change later - $groupid=$mygroupids[0]; - } else { - // Whatever groups are in the course, pick one - $coursegroups = groups_get_all_groups($course->id); - if(!$coursegroups || count($coursegroups)==0) { - error("Can't access wiki in group mode when no groups are configured for the course"); - } - $unkeyed=array_values($coursegroups); // Make sure first item is index 0 - $groupid=$unkeyed[0]->id; - } + $cm = get_coursemodule_from_instance('wiki', $wiki->id); + $groupid = groups_get_activity_group($cm); } /// If the wiki entry doesn't exist, can this user create it? @@ -455,17 +445,28 @@ $groupmode = groups_get_activity_groupmode($wiki); if($groupmode) { if(!$groupid) { - if(($mygroupids=mygroupid($course->id)) && count($mygroupids)>0) { + if(($mygroupids=mygroupid($course->id)) && count($mygroupids)>1) { // Use first group. They ought to be able to change later + if($mygroupids[0] != $course->groupautoassign){ $groupid=$mygroupids[0]; + }else{ + $groupid=$mygroupids[1]; + } } else { // Whatever groups are in the course, pick one $coursegroups = groups_get_all_groups($course->id); if(!$coursegroups || count($coursegroups)==0) { error("Can't access wiki in group mode when no groups are configured for the course"); } + if($CFG->enablepublicprivate && count($coursegroups)<2) { + error("Can't access wiki in group mode when no groups are configured for the course"); + } $unkeyed=array_values($coursegroups); // Make sure first item is index 0 + if($unkeyed[0]->id != $course->groupautoassign){ $groupid=$unkeyed[0]->id; + }else{ + $groupid=$unkeyed[1]->id; + } } } @@ -539,7 +540,9 @@ $cm->groupingid = $wiki->groupingid; $cm->groupmembersonly = $wiki->groupmembersonly; if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { - $groupingid = $wiki->groupingid; + // ignore groupings in all cases! + // $groupingid = $wiki->groupingid; + $groupingid = 0; } @@ -711,7 +714,8 @@ if ($groups = groups_get_all_groups($course->id, null, $groupingid)) { $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename; foreach ($groups as $group) { - + + if($group->id != $course->groupautoassign){ /// If this group already has an entry, use its pagename. if (isset($wiki_entries[$group->id])) { $pagename = $wiki_entries[$group->id]->pagename; @@ -719,9 +723,10 @@ else { $pagename = $defpagename; } - $key = 'view.php?id='.$id.($group->id?"&groupid=".$group->id:"").'&page='.$pagename; $wikis[$key] = $group->name.':'.$pagename; + + } } } } @@ -731,6 +736,7 @@ $defpagename = empty($wiki->pagename) ? get_string('wikidefaultpagename', 'wiki') : $wiki->pagename; foreach ($groups as $group) { + if($group->id != $course->groupautoassign){ /// If this group already has an entry, use its pagename. if (isset($wiki_entries[$group->id])) { $pagename = $wiki_entries[$group->id]->pagename; @@ -740,6 +746,7 @@ } $key = 'view.php?id='.$id.($group->id?"&groupid=".$group->id:"").'&page='.$pagename; $wikis[$key] = $group->name.':'.$pagename; + } } } Index: moodle/pix/i/warning.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: moodle\pix\i\warning.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: moodle/pix/t/private.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: moodle\pix\t\private.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Index: moodle/pix/t/public.png =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Property changes on: moodle\pix\t\public.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream