Updated PaintWeb to the latest snapshot.
[moodle/mihaisucan.git] / group / grouping.php
bloba37f5780b8c9a593feffd9c87d77574d503a8f23
1 <?php
2 /**
3 * Create grouping OR edit grouping 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
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once('grouping_form.php');
15 /// get url variables
16 $courseid = optional_param('courseid', 0, PARAM_INT);
17 $id = optional_param('id', 0, PARAM_INT);
18 $delete = optional_param('delete', 0, PARAM_BOOL);
19 $confirm = optional_param('confirm', 0, PARAM_BOOL);
21 if ($id) {
22 if (!$grouping = get_record('groupings', 'id', $id)) {
23 error('Group ID was incorrect');
25 $grouping->description = clean_text($grouping->description);
26 if (empty($courseid)) {
27 $courseid = $grouping->courseid;
29 } else if ($courseid != $grouping->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 $grouping = new object();
42 $grouping->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/groupings.php?id='.$course->id;
52 if ($id and $delete) {
53 if (!$confirm) {
54 print_header(get_string('deletegrouping', 'group'), get_string('deletegrouping', 'group'));
55 $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1);
56 $optionsno = array('id'=>$courseid);
57 notice_yesno(get_string('deletegroupingconfirm', 'group', $grouping->name), 'grouping.php', 'groupings.php', $optionsyes, $optionsno, 'get', 'get');
58 print_footer();
59 die;
61 } else if (confirm_sesskey()){
62 if (groups_delete_grouping($id)) {
63 redirect($returnurl);
64 } else {
65 print_error('erroreditgrouping', 'group', $returnurl);
70 /// First create the form
71 $editform = new grouping_form();
72 $editform->set_data($grouping);
74 if ($editform->is_cancelled()) {
75 redirect($returnurl);
77 } elseif ($data = $editform->get_data()) {
78 $success = true;
80 if ($data->id) {
81 if (!groups_update_grouping($data)) {
82 error('Error updating grouping');
85 } else {
86 if (!groups_create_grouping($data)) {
87 error('Error creating grouping');
91 redirect($returnurl);
95 $strgroupings = get_string('groupings', 'group');
96 $strparticipants = get_string('participants');
98 if ($id) {
99 $strheading = get_string('editgroupingsettings', 'group');
100 } else {
101 $strheading = get_string('creategrouping', 'group');
104 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
105 array('name'=>$strgroupings, 'link'=>$CFG->wwwroot.'/group/groupings.php?id='.$courseid, 'type'=>'misc'),
106 array('name'=>$strheading, 'link'=>'', 'type'=>'misc'));
107 $navigation = build_navigation($navlinks);
109 /// Print header
110 print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
113 print_heading($strheading);
114 $editform->display();
115 print_footer($course);