From: nicolasconnault Date: Fri, 30 Mar 2007 05:14:29 +0000 (+0000) Subject: 1. Converted grouping edit form to mform X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c7b0485ffb1271a1d6c00487f4cd5a0becee9781;p=moodle.git 1. Converted grouping edit form to mform 2. Added 2 buttons to disable state when pseudogroup is selected --- diff --git a/group/grouping.php b/group/grouping.php index d6af0eadd0..fd00673b7a 100644 --- a/group/grouping.php +++ b/group/grouping.php @@ -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); - - $context = get_context_instance(CONTEXT_COURSE, $courseid); - if (! has_capability('moodle/course:managegroups', $context)) { - redirect(); - } +/// 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); +} -/// If data submitted, then process and store. +/// First create the form +$editform = new grouping_edit_form('grouping.php', compact('grouping', 'courseid')); - if ($frm = data_submitted() and confirm_sesskey()) { +/// Override defaults if group is set +if (!empty($grouping)) { + $editform->set_data($grouping); +} - 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)); - } +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($frm->name)) { - $err['name'] = get_string('missingname'); + } elseif (empty($grouping)) { // New grouping + if (!$id = groups_create_grouping($course->id, $data)) { + print_error('erroreditgrouping'); + } else { + $success = (bool)$id; + $data->id = $id; } - 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)); - } + } else { // Updating grouping + if (!groups_update_grouping($data, $course->id)) { + print_error('groupingnotupdated'); } } - -/// 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, "wwwroot/course/view.php?id=$courseid\">$course->shortname ". "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". - "-> $strgroups", '', '', true, '', user_login_string($course, $USER)); - - $usehtmleditor = false; -?> -

- -
- - -'; - } - - if ($delete) { - /*echo 'Are you sure you want to delete grouping X ?'; - choose_from_menu_yesno('confirmdelete', false, '', true);*/ -?> - -

- - - - - -
-

-

-
- -

-

- - - -
    -
  1. -
  2. -
  3. -
  4. -
  5. -
  6. -
- -*/ ?> - -

- - - - - -

- - - -  - -
- $strgroups". + "-> $strheading", '', '', true, '', user_login_string($course, $USER)); + print_heading($strheading); + $editform->display(); print_footer($course); } - ?> diff --git a/group/index.php b/group/index.php index d685c398ba..4ccce4e82c 100644 --- a/group/index.php +++ b/group/index.php @@ -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 = ''; diff --git a/group/lib/basicgrouplib.php b/group/lib/basicgrouplib.php index b6b121d1b1..1bbd4085f6 100644 --- a/group/lib/basicgrouplib.php +++ b/group/lib/basicgrouplib.php @@ -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 diff --git a/group/lib/clientlib.js b/group/lib/clientlib.js index f7363342a7..88058e25c9 100644 --- a/group/lib/clientlib.js +++ b/group/lib/clientlib.js @@ -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"; diff --git a/group/lib/groupinglib.php b/group/lib/groupinglib.php index 77a321c2a3..e741a5a50c 100644 --- a/group/lib/groupinglib.php +++ b/group/lib/groupinglib.php @@ -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 *****************************/ diff --git a/group/lib/utillib.php b/group/lib/utillib.php index fa296d2021..883fa594e6 100644 --- a/group/lib/utillib.php +++ b/group/lib/utillib.php @@ -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; diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index ab454510f7..6705e6359e 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -120,6 +120,11 @@ img.grouppicture { text-align: center; } +#addmembersform table { + margin-left: auto; + margin-right: auto; +} + .notifyproblem { text-align: center; padding: 10px;