mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
1. Converted grouping edit form to mform
2. Added 2 buttons to disable state when pseudogroup is selected
This commit is contained in:
parent
3ce4a4d12a
commit
c7b0485ffb
@ -11,14 +11,10 @@
|
||||
require_once('../config.php');
|
||||
require_once('lib.php');
|
||||
require_once($CFG->libdir.'/moodlelib.php');
|
||||
require_once('grouping_edit_form.php');
|
||||
|
||||
$success = true;
|
||||
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$groupingid = optional_param('grouping', false, PARAM_INT);
|
||||
|
||||
$groupingsettings->name = optional_param('name', false, PARAM_TEXT);
|
||||
$groupingsettings->description= optional_param('description', '', PARAM_TEXT);
|
||||
$id = optional_param('id', false, PARAM_INT);
|
||||
|
||||
$delete = optional_param('delete', false, PARAM_BOOL);
|
||||
|
||||
@ -29,153 +25,75 @@ if (! $course) {
|
||||
$success = false;
|
||||
print_error('invalidcourse'); //'The course ID is invalid'
|
||||
}
|
||||
if (GROUP_NOT_IN_GROUPING == $groupingid) {
|
||||
if (GROUP_NOT_IN_GROUPING == $id) {
|
||||
print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group'));
|
||||
}
|
||||
|
||||
if ($success) {
|
||||
// Make sure that the user has permissions to manage groups.
|
||||
require_login($courseid);
|
||||
/// basic access control checks
|
||||
if ($id) {
|
||||
if (!$grouping = get_record('groups_groupings', 'id', $id)) {
|
||||
error('Grouping ID was incorrect');
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('moodle/course:managegroups', $context);
|
||||
}
|
||||
|
||||
/// First create the form
|
||||
$editform = new grouping_edit_form('grouping.php', compact('grouping', 'courseid'));
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
if (! has_capability('moodle/course:managegroups', $context)) {
|
||||
redirect();
|
||||
/// Override defaults if group is set
|
||||
if (!empty($grouping)) {
|
||||
$editform->set_data($grouping);
|
||||
}
|
||||
|
||||
if ($editform->is_cancelled()) {
|
||||
redirect(groups_home_url($courseid, false, $id, false));
|
||||
} elseif ($data = $editform->get_data()) {
|
||||
$success = true;
|
||||
|
||||
// preprocess data
|
||||
if ($delete) {
|
||||
if ($success = groups_delete_grouping($id)) {
|
||||
redirect(groups_home_url($course->id));
|
||||
} else {
|
||||
print_error('erroreditgrouping', 'group', groups_home_url($course->id));
|
||||
}
|
||||
} elseif (empty($grouping)) { // New grouping
|
||||
if (!$id = groups_create_grouping($course->id, $data)) {
|
||||
print_error('erroreditgrouping');
|
||||
} else {
|
||||
$success = (bool)$id;
|
||||
$data->id = $id;
|
||||
}
|
||||
} else { // Updating grouping
|
||||
if (!groups_update_grouping($data, $course->id)) {
|
||||
print_error('groupingnotupdated');
|
||||
}
|
||||
}
|
||||
|
||||
/// If data submitted, then process and store.
|
||||
|
||||
if ($frm = data_submitted() and confirm_sesskey()) {
|
||||
|
||||
if (isset($frm->cancel)) {
|
||||
redirect(groups_home_url($courseid, null, $groupingid, false));
|
||||
}
|
||||
elseif (isset($frm->confirmdelete)) {
|
||||
if ($success = groups_delete_grouping($groupingid)) {
|
||||
redirect(groups_home_url($courseid));
|
||||
} else {
|
||||
print_error('erroreditgrouping', 'group', groups_home_url($courseid));
|
||||
}
|
||||
}
|
||||
elseif (empty($frm->name)) {
|
||||
$err['name'] = get_string('missingname');
|
||||
}
|
||||
elseif (isset($frm->update)) {
|
||||
|
||||
if ($groupingid) {
|
||||
$success = (bool)groups_set_grouping_settings($groupingid, $groupingsettings);
|
||||
}
|
||||
else { //OK, new group.
|
||||
$success = (bool)$groupingid = groups_create_grouping($courseid, $groupingsettings);
|
||||
}
|
||||
if ($success) {
|
||||
redirect(groups_home_url($courseid, null, $groupingid, false));
|
||||
}
|
||||
else {
|
||||
print_error('erroreditgrouping', 'group', groups_home_url($courseid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// OR, prepare the form.
|
||||
|
||||
if ($groupingid) {
|
||||
// Form to edit existing grouping.
|
||||
$grouping = groups_get_grouping_settings($groupingid);
|
||||
if (! $grouping) {
|
||||
print_error('errorinvalidgrouping', 'group', groups_home_url($courseid));
|
||||
}
|
||||
$strname = s($grouping->name);
|
||||
$strdesc = s($grouping->description);
|
||||
|
||||
$strbutton = get_string('save', 'group');
|
||||
$strheading = get_string('editgroupingsettings', 'group');
|
||||
if ($success) {
|
||||
redirect(groups_home_url($courseid, false, $id, false));
|
||||
} else {
|
||||
// Form to create a new one.
|
||||
$strname = get_string('defaultgroupingname', 'group');
|
||||
$strdesc = '';
|
||||
$strbutton = $strheading = get_string('creategrouping', 'group');
|
||||
print_error('erroreditgrouping', 'group', groups_home_url($courseid));
|
||||
}
|
||||
|
||||
} else { // Prepare and output form
|
||||
$strgroups = get_string('groups');
|
||||
$strparticipants = get_string('participants');
|
||||
if ($delete) {
|
||||
$strheading = get_string('deletegrouping', 'group');
|
||||
|
||||
if ($id) {
|
||||
$strheading = get_string('editgroupingsettings', 'group');
|
||||
} else {
|
||||
$strheading = get_string('creategrouping', 'group');
|
||||
}
|
||||
|
||||
/// Print the page and form
|
||||
|
||||
print_header("$course->shortname: $strgroups",
|
||||
print_header("$course->shortname: ". $strheading,
|
||||
$course->fullname,
|
||||
"<a href=\"$CFG->wwwroot/course/view.php?id=$courseid\">$course->shortname</a> ".
|
||||
"-> <a href=\"$CFG->wwwroot/user/index.php?id=$courseid\">$strparticipants</a> ".
|
||||
"-> $strgroups", '', '', true, '', user_login_string($course, $USER));
|
||||
|
||||
$usehtmleditor = false;
|
||||
?>
|
||||
<h3 class="main"><?php echo $strheading ?></h3>
|
||||
|
||||
<form action="grouping.php" method="post" class="mform notmform" id="groupingform">
|
||||
<input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
|
||||
<input type="hidden" name="courseid" value="<?php p($courseid); ?>" />
|
||||
<?php
|
||||
if ($groupingid) {
|
||||
echo '<input type="hidden" name="grouping" value="'. $groupingid .'" />';
|
||||
}
|
||||
|
||||
if ($delete) {
|
||||
/*echo 'Are you sure you want to delete grouping X ?';
|
||||
choose_from_menu_yesno('confirmdelete', false, '', true);*/
|
||||
?>
|
||||
|
||||
<p><?php print_string('deletegroupingconfirm', 'group', $strname); ?></p>
|
||||
<input type="hidden" name="delete" value="1" />
|
||||
<input type="submit" name="confirmdelete" value="<?php print_string('yes'); ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string('no'); ?>" />
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
|
||||
<div class="f-item">
|
||||
<p><label for="groupingname"><?php
|
||||
print_string('groupingname', 'group');
|
||||
if (isset($err['name'])) {
|
||||
echo' ';
|
||||
formerr($err['name']);
|
||||
} ?> </label></p>
|
||||
<p><input id="groupingname" name="name" type="text" size="40" value="<?php echo $strname; ?>" /></p>
|
||||
</div>
|
||||
|
||||
<p><label for="edit-description"><?php print_string('groupingdescription', 'group'); ?> </label></p>
|
||||
<p><?php print_textarea($usehtmleditor, 5, 45, 200, 400, 'description', $strdesc); ?></p>
|
||||
|
||||
<?php /* TODO:
|
||||
<fieldset>
|
||||
<legend><?php print_string('editgroupingpermissions', 'group'); ?></legend>
|
||||
<ol class="unlist para">
|
||||
<li><label><input type="checkbox" id="perm_viewowngroup" checked="checked" /> <?php print_string('viewowngroup', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_viewallgroupsmembers" checked="checked" /> <?php print_string('viewallgroupsmembers', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_viewallgroupsactivities" checked="checked" /> <?php print_string('viewallgroupsactivities', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_teachersgroupmark" /> <?php print_string('teachersgroupmark', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_teachersgroupview" /> <?php print_string('teachersgroupview', 'group'); ?></label></li>
|
||||
<li><label><input type="checkbox" id="perm_teachersoverride" /> <?php print_string('teachersoverride', 'group'); ?></label></li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
*/ ?>
|
||||
|
||||
<p class="fitem">
|
||||
<label for="id_submit"> </label>
|
||||
<span class="f-element fsubmit">
|
||||
<input type="submit" name="update" id="id_submit" value="<?php echo $strbutton; ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string('cancel', 'group'); ?>" />
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<?php } //IF($delete) ?>
|
||||
|
||||
<span class="clearer"> </span>
|
||||
|
||||
</form>
|
||||
<?php
|
||||
'-> <a href="' .format_string(groups_home_url($courseid, false, $id, false)) . "\">$strgroups</a>".
|
||||
"-> $strheading", '', '', true, '', user_login_string($course, $USER));
|
||||
print_heading($strheading);
|
||||
$editform->display();
|
||||
print_footer($course);
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -25,7 +25,6 @@ $courseid = required_param('id', PARAM_INT);
|
||||
$groupingid = optional_param('grouping', GROUP_NOT_IN_GROUPING, PARAM_INT);
|
||||
$groupid = optional_param('group', false, PARAM_INT);
|
||||
$userid = optional_param('user', false, PARAM_INT);
|
||||
|
||||
$action = groups_param_action();
|
||||
|
||||
|
||||
@ -52,7 +51,6 @@ if (! $course) {
|
||||
print_error('invalidcourse'); //'The course ID is invalid'
|
||||
}
|
||||
|
||||
|
||||
if ($success) {
|
||||
// Make sure that the user has permissions to manage groups.
|
||||
require_login($courseid);
|
||||
@ -162,7 +160,7 @@ if ($success) {
|
||||
$disabled = 'disabled="disabled"';
|
||||
|
||||
// Pre-disable buttons based on URL variables
|
||||
if (isset($groupingid) && $groupingid > -1) {
|
||||
if (!empty($groupingid) && $groupingid > -1) {
|
||||
$showeditgroupsettingsform_disabled = '';
|
||||
$showeditgroupingsettingsform_disabled = '';
|
||||
$deletegroup_disabled = '';
|
||||
@ -178,7 +176,11 @@ if ($success) {
|
||||
$showcreategroupform_disabled = $disabled;
|
||||
}
|
||||
|
||||
if (isset($groupid)) {
|
||||
if ($groupingid == -1) {
|
||||
$printerfriendly_disabled = '';
|
||||
}
|
||||
|
||||
if (!empty($groupid)) {
|
||||
$showaddmembersform_disabled = '';
|
||||
$showeditgroupsettingsform_disabled = '';
|
||||
$deletegroup_disabled = '';
|
||||
|
@ -423,7 +423,6 @@ function groups_remove_all_members($groupid) {
|
||||
* @param object $data - all the data needed for an entry in the 'groups' table
|
||||
*/
|
||||
function groups_update_group($data, $courseid) {
|
||||
global $USER, $CFG;
|
||||
$oldgroup = get_record('groups', 'id', $data->id); // should not fail, already tested above
|
||||
|
||||
// Update with the new data
|
||||
|
@ -92,6 +92,10 @@ UpdatableGroupsCombo.prototype.refreshGroups = function (groupingId) {
|
||||
document.getElementById("showeditgroupingsettingsform").disabled = true;
|
||||
document.getElementById("deletegrouping").disabled = true;
|
||||
document.getElementById("showcreategroupform").disabled = true;
|
||||
document.getElementById("showeditgroupsettingsform").disabled = true;
|
||||
document.getElementById("deletegroup").disabled = true;
|
||||
document.getElementById("showaddmembersform").disabled = true;
|
||||
|
||||
}
|
||||
|
||||
var sUrl = this.wwwRoot+"/group/index.php?id="+this.courseId+"&grouping="+groupingId+"&act_ajax_getgroupsingrouping";
|
||||
|
@ -438,6 +438,27 @@ function groups_set_grouping_for_coursemodule($groupingid, $coursemoduleid) {
|
||||
}
|
||||
|
||||
|
||||
/*****************************
|
||||
Update functions
|
||||
*****************************/
|
||||
|
||||
function groups_update_grouping($data, $courseid) {
|
||||
$oldgrouping = get_record('groups_groupings', 'id', $data->id); // should not fail, already tested above
|
||||
|
||||
// Update with the new data
|
||||
if (update_record('groups_groupings', $data)) {
|
||||
|
||||
$grouping = get_record('groups_groupings', 'id', $data->id);
|
||||
|
||||
add_to_log($grouping->id, "groups_groupings", "update", "grouping.php?courseid=$courseid&id=$grouping->id", "");
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
/*****************************
|
||||
Deletion functions
|
||||
*****************************/
|
||||
|
@ -340,7 +340,7 @@ function groups_grouping_edit_url($courseid, $groupingid=false, $html=true, $par
|
||||
$html ? $sep = '&' : $sep = '&';
|
||||
$url = $CFG->wwwroot.'/group/grouping.php?courseid='.$courseid;
|
||||
if ($groupingid) {
|
||||
$url .= $sep.'grouping='.$groupingid;
|
||||
$url .= $sep.'id='.$groupingid;
|
||||
}
|
||||
if ($param) {
|
||||
$url .= $sep.$param;
|
||||
|
@ -120,6 +120,11 @@ img.grouppicture {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#addmembersform table {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.notifyproblem {
|
||||
text-align: center;
|
||||
padding: 10px;
|
||||
|
Loading…
x
Reference in New Issue
Block a user