3 * Create group OR edit group settings.
5 * @copyright © 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
11 require_once('../config.php');
12 require_once('lib.php');
13 require_once($CFG->libdir
.'/moodlelib.php');
14 require_once($CFG->libdir
.'/uploadlib.php');
19 $courseid = required_param('courseid', PARAM_INT
);
20 $groupingid = optional_param('grouping', false, PARAM_INT
);
21 $newgrouping= optional_param('newgrouping', false, PARAM_INT
);
22 $groupid = optional_param('group', false, PARAM_INT
);
24 $groupsettings->name
= optional_param('name', false, PARAM_TEXT
);
25 $groupsettings->description
= optional_param('description', '', PARAM_TEXT
);
26 $groupsettings->enrolmentkey
= optional_param('enrolmentkey', '', PARAM_TEXT
);
27 $groupsettings->hidepicture
= optional_param('hidepicture', true, PARAM_BOOL
);
29 $delete = optional_param('delete', false, PARAM_BOOL
);
31 // Get the course information so we can print the header and
32 // check the course id is valid
33 $course = groups_get_course_info($courseid);
36 print_error('invalidcourse'); //'The course ID is invalid'
38 if ($delete && !$groupid) {
40 print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
44 // Make sure that the user has permissions to manage groups.
45 require_login($courseid);
47 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
48 if (! has_capability('moodle/course:managegroups', $context)) {
52 /// If data submitted, then process and store.
54 if ($frm = data_submitted() and confirm_sesskey()) {
56 if (isset($frm->cancel
)) {
57 redirect(groups_home_url($courseid, $groupid, $groupingid, false));
59 elseif (isset($frm->confirmdelete
)) {
60 if ($success = groups_delete_group($groupid)) {
61 redirect(groups_home_url($courseid, null, $groupingid, false));
63 print_error('erroreditgroup', 'group', groups_home_url($courseid));
66 elseif (empty($frm->name
)) {
67 $err['name'] = get_string('missingname');
69 elseif (isset($frm->update
)) {
70 if (! $groupid) { //OK, new group.
71 if (GROUP_NOT_IN_GROUPING
== $groupingid) {
72 print_error('errornotingrouping', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
74 $success = (bool)$groupid = groups_create_group($courseid); //$groupsettings);
75 $success = groups_add_group_to_grouping($groupid, $groupingid);
77 elseif ($groupingid != $newgrouping) { //OK, move group.
78 if (GROUP_NOT_IN_GROUPING
== $newgrouping) {
79 print_error('errornotingrouping', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
81 $success = $success && groups_remove_group_from_grouping($groupid, $groupingid);
82 $success = $success && groups_add_group_to_grouping($groupid, $newgrouping);
85 //require_once($CFG->dirroot.'/lib/uploadlib.php');
87 $um = new upload_manager('imagefile',false,false,$course=null,false,$modbytes=0,$silent=false,$allownull=true);
88 if ($um->preprocess_files()) {
89 require_once("$CFG->libdir/gdlib.php");
91 if (save_profile_image($groupid, $um, 'groups')) {
92 $groupsettings->picture
= 1;
98 $success = $success && groups_set_group_settings($groupid, $groupsettings);
101 redirect(groups_home_url($courseid, $groupid, $groupingid, false));
104 print_error('erroreditgroup', 'group', groups_home_url($courseid));
109 /// OR, prepare the form.
112 // Form to edit existing group.
113 $group = groups_get_group_settings($groupid);
115 print_error('errorinvalidgroup', 'group', groups_home_url($courseid));
117 $strname = s($group->name
);
118 $strdesc = s($group->description
);
120 $strbutton = get_string('save', 'group');
121 $strheading = get_string('editgroupsettings', 'group');
123 // Form to create a new one.
124 $strname = get_string('defaultgroupname', 'group');
126 $strbutton = $strheading = get_string('creategroup', 'group');
128 $strgroups = get_string('groups');
129 $strparticipants = get_string('participants');
131 $strheading = get_string('deleteselectedgroup', 'group');
132 } //else { $strheader = get_string('groupinfoedit'); }
134 $maxbytes = get_max_upload_file_size($CFG->maxbytes
, $course->maxbytes
);
135 if (!empty($CFG->gdversion
) and $maxbytes) {
136 $printuploadpicture = true;
138 $printuploadpicture = false;
141 /// Print the page and form
143 print_header("$course->shortname: ". $strheading,
145 "<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
146 "-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
147 "-> $strgroups", '', '', true, '', user_login_string($course, $USER));
149 $usehtmleditor = false;
151 <h3
class="main"><?php
echo $strheading ?
></h3
>
153 <form action
="group.php" method
="post" enctype
="multipart/form-data" class="mform notmform" id
="groupform">
155 <input type
="hidden" name
="sesskey" value
="<?php p(sesskey()); ?>" />
156 <input type
="hidden" name
="courseid" value
="<?php p($courseid); ?>" />
157 <input type
="hidden" name
="grouping" value
="<?php p($groupingid); ?>" />
160 echo '<input type="hidden" name="group" value="'. $groupid .'" />';
164 /*echo 'Are you sure you want to delete group X ?';
165 choose_from_menu_yesno('confirmdelete', false, '', true);*/
168 <p
><?php
print_string('deletegroupconfirm', 'group', $strname); ?
></p
>
169 <input type
="hidden" name
="delete" value
="1" />
170 <input type
="submit" name
="confirmdelete" value
="<?php print_string('yes'); ?>" />
171 <input type
="submit" name
="cancel" value
="<?php print_string('no'); ?>" />
177 <p
><label
for="groupname"><?php
178 print_string('groupname', 'group');
179 if (isset($err['name'])) {
181 formerr($err['name']);
182 } ?
> 
; </label
></p
>
183 <p
class="felement"><input id
="groupname" name
="name" type
="text" size
="40" value
="<?php echo $strname; ?>" /></p
>
186 <p
><label
for="edit-description"><?php
print_string('groupdescription', 'group'); ?
> 
;</label
></p
>
187 <p
><?php
print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?
></p
>
189 <p
><label
for="enrolmentkey"><?php
print_string('enrolmentkey', 'group'); ?
> 
;</label
></p
>
190 <p
><input id
="enrolmentkey" name
="enrolmentkey" type
="text" size
="25" /></p
>
192 <?php
if ($printuploadpicture) { ?
>
193 <p
><label
for="menuhidepicture"><?php
print_string('hidepicture', 'group'); ?
> 
;</label
></p
>
194 <p
><?php
$options = array();
195 $options[0] = get_string('no');
196 $options[1] = get_string('yes');
197 choose_from_menu($options, 'hidepicture', isset($group)?
$group->hidepicture
: 1, '');?
></p
>
199 <p
><label
><?php
/* for="imagefile" */ print_string('newpicture', 'group');
200 helpbutton('picture', get_string('helppicture'));
201 print_string('maxsize', '', display_size($maxbytes), 'group');
202 if (isset($err['imagefile'])) formerr($err['imagefile']);
204 <p
><?php
upload_print_form_fragment(1, array('imagefile'), null,false,null,0,0,false); ?
></p
>
208 if ($groupid) { //OK, editing - option to move grouping.
210 <p
><label
for="groupings"><?php
print_string('addgroupstogrouping', 'group'); ?
></label
></p
>
211 <select name
="newgrouping" id
="groupings" class="select">
213 $groupingids = groups_get_groupings($courseid);
214 if (GROUP_NOT_IN_GROUPING
== $groupingid) {
215 $groupingids[] = GROUP_NOT_IN_GROUPING
;
218 // Put the groupings into a hash and sort them
219 foreach($groupingids as $id) {
220 $listgroupings[$id] = groups_get_grouping_displayname($id, $courseid);
222 natcasesort($listgroupings);
224 // Print out the HTML
226 foreach($listgroupings as $id => $name) {
228 if ($groupingid == $id) {
229 $select = ' selected="selected"';
231 echo "<option value=\"$id\"$select>$name</option>\n";
237 <?php
} //IF($groupid) ?>
240 <label
for="id_submit"> 
;</label
>
241 <span
class="f--element fsubmit">
242 <input type
="submit" name
="update" id
="id_submit" value
="<?php echo $strbutton; ?>" />
243 <input type
="submit" name
="cancel" value
="<?php print_string('cancel', 'group'); ?>" />
247 <?php
} //IF($delete) ?>
249 <span
class="clearer"> 
;</span
>
253 print_footer($course);