Updated the 19 build version to 20100915
[moodle.git] / group / group.php
blobc503141e8b533a2512cffdab183e40df0a043d29
1 <?php
2 /**
3 * Create group OR edit group settings.
5 * @copyright &copy; 2006 The Open University
6 * @author N.D.Freear AT open.ac.uk
7 * @author J.White AT open.ac.uk
8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 * @package groups
12 require_once('../config.php');
13 require_once('lib.php');
14 require_once('group_form.php');
16 /// get url variables
17 $courseid = optional_param('courseid', 0, PARAM_INT);
18 $id = optional_param('id', 0, PARAM_INT);
19 $delete = optional_param('delete', 0, PARAM_BOOL);
20 $confirm = optional_param('confirm', 0, PARAM_BOOL);
22 // This script used to support group delete, but that has been moved. In case
23 // anyone still links to it, let's redirect to the new script.
24 if($delete) {
25 redirect('delete.php?courseid='.$courseid.'&groups='.$id);
28 if ($id) {
29 if (!$group = get_record('groups', 'id', $id)) {
30 error('Group ID was incorrect');
32 $group->description = clean_text($group->description);
33 if (empty($courseid)) {
34 $courseid = $group->courseid;
36 } else if ($courseid != $group->courseid) {
37 error('Course ID was incorrect');
40 if (!$course = get_record('course', 'id', $courseid)) {
41 error('Course ID was incorrect');
44 } else {
45 if (!$course = get_record('course', 'id', $courseid)) {
46 error('Course ID was incorrect');
48 $group = new object();
49 $group->courseid = $course->id;
52 require_login($course);
53 $context = get_context_instance(CONTEXT_COURSE, $course->id);
54 require_capability('moodle/course:managegroups', $context);
56 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
58 if ($id and $delete) {
59 if (!$confirm) {
60 print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
61 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
62 $optionsno = array('id'=>$courseid);
63 notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
64 print_footer();
65 die;
67 } else if (confirm_sesskey()){
68 if (groups_delete_group($id)) {
69 redirect('index.php?id='.$course->id);
70 } else {
71 print_error('erroreditgroup', 'group', $returnurl);
76 /// First create the form
77 $editform = new group_form();
78 $editform->set_data($group);
80 if ($editform->is_cancelled()) {
81 redirect($returnurl);
83 } elseif ($data = $editform->get_data()) {
85 if ($data->id) {
86 if (!groups_update_group($data, $editform->_upload_manager)) {
87 error('Error updating group');
89 } else {
90 if (!$id = groups_create_group($data, $editform->_upload_manager)) {
91 error('Error creating group');
93 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
96 redirect($returnurl);
99 $strgroups = get_string('groups');
100 $strparticipants = get_string('participants');
102 if ($id) {
103 $strheading = get_string('editgroupsettings', 'group');
104 } else {
105 $strheading = get_string('creategroup', 'group');
109 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
110 array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
111 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
112 $navigation = build_navigation($navlinks);
114 /// Print header
115 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
117 echo '<div id="grouppicture">';
118 if ($id) {
119 print_group_picture($group, $course->id);
121 echo '</div>';
122 $editform->display();
123 print_footer($course);