MDL-11071 Added disabledif logic to groupings/groups common dialogue
[moodle-pu.git] / group / group.php
blobb39757879e18874174893f483674e455128781d4
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 if ($id) {
23 if (!$group = get_record('groups', 'id', $id)) {
24 error('Group ID was incorrect');
26 if (empty($courseid)) {
27 $courseid = $group->courseid;
29 } else if ($courseid != $group->courseid) {
30 error('Course ID was incorrect');
33 if (!$course = get_record('course', 'id', $courseid)) {
34 error('Course ID was incorrect');
37 } else {
38 if (!$course = get_record('course', 'id', $courseid)) {
39 error('Course ID was incorrect');
41 $group = new object();
42 $group->courseid = $course->id;
45 require_login($course);
46 $context = get_context_instance(CONTEXT_COURSE, $course->id);
47 require_capability('moodle/course:managegroups', $context);
49 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
51 if ($id and $delete) {
52 if (!$confirm) {
53 print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group'));
54 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
55 $optionsno = array('id'=>$courseid);
56 notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get');
57 print_footer();
58 die;
60 } else if (confirm_sesskey()){
61 if (groups_delete_group($id)) {
62 // MDL-9983
63 $eventdata = new object();
64 $eventdata->group = $id;
65 $eventdata->course = $courseid;
66 events_trigger('group_deleted', $eventdata);
67 redirect('index.php?id='.$course->id);
68 } else {
69 print_error('erroreditgroup', 'group', $returnurl);
74 /// First create the form
75 $editform = new group_form();
76 $editform->set_data($group);
78 if ($editform->is_cancelled()) {
79 redirect($returnurl);
81 } elseif ($data = $editform->get_data()) {
83 if ($data->id) {
84 if (!groups_update_group($data, $editform->_upload_manager)) {
85 error('Error updating group');
87 } else {
88 if (!$id = groups_create_group($data, $editform->_upload_manager)) {
89 error('Error updating group');
91 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&amp;group='.$id;
94 redirect($returnurl);
97 $strgroups = get_string('groups');
98 $strparticipants = get_string('participants');
100 if ($id) {
101 $strheading = get_string('editgroupsettings', 'group');
102 } else {
103 $strheading = get_string('creategroup', 'group');
107 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
108 array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
109 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
110 $navigation = build_navigation($navlinks);
112 /// Print header
113 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
115 echo '<div id="grouppicture">';
116 if ($id) {
117 print_group_picture($group, $course->id);
119 echo '</div>';
120 $editform->display();
121 print_footer($course);