moodle/group/group.php

136 lines
4.4 KiB
PHP
Raw Normal View History

<?php
/**
* Create group OR edit group settings.
*
* @copyright &copy; 2006 The Open University
* @author N.D.Freear AT open.ac.uk
* @author J.White AT open.ac.uk
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package groups
*/
require_once('../config.php');
require_once('lib.php');
require_once('group_form.php');
/// get url variables
$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);
// 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');
}
if (empty($courseid)) {
$courseid = $group->courseid;
} else if ($courseid != $group->courseid) {
2008-05-14 06:15:56 +00:00
print_error('invalidcourseid');
}
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');
}
} 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');
}
$group = new object();
$group->courseid = $course->id;
}
2009-09-16 08:16:44 +00:00
if ($id !== 0) {
$PAGE->set_url('/group/group.php', array('id'=>$id));
2009-09-16 08:16:44 +00:00
} else {
$PAGE->set_url('/group/group.php', array('courseid'=>$courseid));
2009-09-16 08:16:44 +00:00
}
require_login($course);
$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;
if ($id and $delete) {
if (!$confirm) {
$PAGE->set_title(get_string('deleteselectedgroup', 'group'));
2010-05-27 09:33:46 +00:00
$PAGE->set_heading($course->fullname . ': '. get_string('deleteselectedgroup', 'group'));
echo $OUTPUT->header();
$optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
$optionsno = array('id'=>$courseid);
$formcontinue = new single_button(new moodle_url('group.php', $optionsyes), get_string('yes'), 'get');
$formcancel = new single_button(new moodle_url($baseurl, $optionsno), get_string('no'), 'get');
echo $OUTPUT->confirm(get_string('deletegroupconfirm', 'group', $group->name), $formcontinue, $formcancel);
echo $OUTPUT->footer();
die;
} else if (confirm_sesskey()){
if (groups_delete_group($id)) {
redirect('index.php?id='.$course->id);
} else {
print_error('erroreditgroup', 'group', $returnurl);
}
2007-04-03 06:41:58 +00:00
}
}
// Prepare the description editor: We do support files for group descriptions
$editoroptions = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'maxbytes'=>$course->maxbytes, 'trust'=>false, 'context'=>$context, 'noclean'=>true);
if (!empty($group->id)) {
$group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', $group->id);
} else {
$group = file_prepare_standard_editor($group, 'description', $editoroptions, $context, 'group', 'description', null);
}
/// First create the form
$editform = new group_form(null, array('editoroptions'=>$editoroptions));
$editform->set_data($group);
2007-04-03 06:41:58 +00:00
if ($editform->is_cancelled()) {
redirect($returnurl);
} elseif ($data = $editform->get_data()) {
if ($data->id) {
groups_update_group($data, $editform, $editoroptions);
} else {
$id = groups_create_group($data, $editform, $editoroptions);
$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id;
}
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');
}
$PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
$PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
$PAGE->navbar->add($strheading);
/// Print header
$PAGE->set_title($strgroups);
2010-05-27 09:33:46 +00:00
$PAGE->set_heading($course->fullname . ': '.$strgroups);
echo $OUTPUT->header();
2007-04-03 06:41:58 +00:00
echo '<div id="grouppicture">';
if ($id) {
print_group_picture($group, $course->id);
}
2007-04-03 06:41:58 +00:00
echo '</div>';
$editform->display();
echo $OUTPUT->footer();