2007-03-28 08:40:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Create group OR edit group settings.
|
|
|
|
*
|
|
|
|
* @copyright © 2006 The Open University
|
|
|
|
* @author N.D.Freear AT open.ac.uk
|
2007-08-14 00:50:00 +00:00
|
|
|
* @author J.White AT open.ac.uk
|
2007-03-28 08:40:32 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package groups
|
|
|
|
*/
|
2007-08-15 20:33:17 +00:00
|
|
|
|
2007-03-28 08:40:32 +00:00
|
|
|
require_once('../config.php');
|
|
|
|
require_once('lib.php');
|
2007-08-15 20:33:17 +00:00
|
|
|
require_once('group_form.php');
|
2007-03-28 08:40:32 +00:00
|
|
|
|
|
|
|
/// get url variables
|
2007-08-16 09:28:18 +00:00
|
|
|
$courseid = optional_param('courseid', 0, PARAM_INT);
|
|
|
|
$id = optional_param('id', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_BOOL);
|
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2007-03-28 08:40:32 +00:00
|
|
|
|
2008-10-24 13:31:49 +00:00
|
|
|
// This script used to support group delete, but that has been moved. In case
|
|
|
|
// anyone still links to it, let's redirect to the new script.
|
|
|
|
if($delete) {
|
|
|
|
redirect('delete.php?courseid='.$courseid.'&groups='.$id);
|
|
|
|
}
|
|
|
|
|
2007-03-29 08:40:08 +00:00
|
|
|
if ($id) {
|
2008-06-01 13:09:04 +00:00
|
|
|
if (!$group = $DB->get_record('groups', array('id'=>$id))) {
|
2008-05-14 06:15:56 +00:00
|
|
|
print_error('invalidgroupid');
|
2007-08-14 00:50:00 +00:00
|
|
|
}
|
2008-01-18 10:16:39 +00:00
|
|
|
$group->description = clean_text($group->description);
|
2007-08-15 20:33:17 +00:00
|
|
|
if (empty($courseid)) {
|
|
|
|
$courseid = $group->courseid;
|
|
|
|
|
|
|
|
} else if ($courseid != $group->courseid) {
|
2008-05-14 06:15:56 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-08-14 00:50:00 +00:00
|
|
|
}
|
2007-08-15 20:33:17 +00:00
|
|
|
|
2008-06-01 13:09:04 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
|
2008-05-14 06:15:56 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-08-15 20:33:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
} else {
|
2008-06-01 13:09:04 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
|
2008-05-14 06:15:56 +00:00
|
|
|
print_error('invalidcourseid');
|
2007-08-15 20:33:17 +00:00
|
|
|
}
|
2007-08-14 00:50:00 +00:00
|
|
|
$group = new object();
|
2007-08-15 20:33:17 +00:00
|
|
|
$group->courseid = $course->id;
|
2007-03-28 08:40:32 +00:00
|
|
|
}
|
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
require_login($course);
|
2007-08-15 20:33:17 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
|
|
|
require_capability('moodle/course:managegroups', $context);
|
|
|
|
|
|
|
|
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
|
2007-03-28 08:40:32 +00:00
|
|
|
|
2007-08-15 20:33:17 +00:00
|
|
|
if ($id and $delete) {
|
2007-08-14 00:50:00 +00:00
|
|
|
if (!$confirm) {
|
|
|
|
print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
|
|
|
|
$optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
|
|
|
|
$optionsno = array('id'=>$courseid);
|
2007-08-15 20:33:17 +00:00
|
|
|
notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
|
2007-08-14 00:50:00 +00:00
|
|
|
print_footer();
|
|
|
|
die;
|
2007-03-28 08:40:32 +00:00
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
} else if (confirm_sesskey()){
|
|
|
|
if (groups_delete_group($id)) {
|
|
|
|
redirect('index.php?id='.$course->id);
|
|
|
|
} else {
|
2007-08-15 20:33:17 +00:00
|
|
|
print_error('erroreditgroup', 'group', $returnurl);
|
2007-08-14 00:50:00 +00:00
|
|
|
}
|
2007-04-03 06:41:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
/// First create the form
|
2007-08-15 23:51:07 +00:00
|
|
|
$editform = new group_form();
|
2007-08-14 00:50:00 +00:00
|
|
|
$editform->set_data($group);
|
2007-04-03 06:41:58 +00:00
|
|
|
|
2007-03-28 08:40:32 +00:00
|
|
|
if ($editform->is_cancelled()) {
|
2007-08-14 00:50:00 +00:00
|
|
|
redirect($returnurl);
|
|
|
|
|
2007-03-28 08:40:32 +00:00
|
|
|
} elseif ($data = $editform->get_data()) {
|
2007-08-14 00:50:00 +00:00
|
|
|
|
|
|
|
if ($data->id) {
|
2009-02-17 16:50:36 +00:00
|
|
|
groups_update_group($data, $editform);
|
2007-08-14 00:50:00 +00:00
|
|
|
} else {
|
2009-02-17 16:50:36 +00:00
|
|
|
$id = groups_create_group($data, $editform);
|
2007-08-16 21:14:03 +00:00
|
|
|
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
|
2007-03-28 08:40:32 +00:00
|
|
|
}
|
|
|
|
|
2007-08-14 00:50:00 +00:00
|
|
|
redirect($returnurl);
|
|
|
|
}
|
|
|
|
|
2007-04-03 06:41:58 +00:00
|
|
|
$strgroups = get_string('groups');
|
|
|
|
$strparticipants = get_string('participants');
|
|
|
|
|
|
|
|
if ($id) {
|
|
|
|
$strheading = get_string('editgroupsettings', 'group');
|
|
|
|
} else {
|
|
|
|
$strheading = get_string('creategroup', 'group');
|
|
|
|
}
|
2007-08-16 21:14:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
|
|
|
|
array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
|
|
|
|
array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
|
|
|
|
$navigation = build_navigation($navlinks);
|
|
|
|
|
|
|
|
/// Print header
|
|
|
|
print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
|
2007-04-03 06:41:58 +00:00
|
|
|
|
|
|
|
echo '<div id="grouppicture">';
|
|
|
|
if ($id) {
|
|
|
|
print_group_picture($group, $course->id);
|
2007-03-28 08:40:32 +00:00
|
|
|
}
|
2007-04-03 06:41:58 +00:00
|
|
|
echo '</div>';
|
|
|
|
$editform->display();
|
|
|
|
print_footer($course);
|
2007-03-28 08:40:32 +00:00
|
|
|
?>
|