From: skodak Date: Wed, 15 Aug 2007 20:33:17 +0000 (+0000) Subject: MDL-10383 - group edit form refactoring and minor bugfixing X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c4e953e69e31ae10cf184f09818067711e854c6b;p=moodle.git MDL-10383 - group edit form refactoring and minor bugfixing --- diff --git a/group/edit.php b/group/group.php old mode 100755 new mode 100644 similarity index 77% rename from group/edit.php rename to group/group.php index cfa6cfdc9b..71a307bc51 --- a/group/edit.php +++ b/group/group.php @@ -8,60 +8,51 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package groups */ -/// include libraries + require_once('../config.php'); -require_once($CFG->libdir.'/moodlelib.php'); -require_once($CFG->libdir.'/uploadlib.php'); require_once('lib.php'); -require_once('edit_form.php'); +require_once('group_form.php'); /// get url variables -$courseid = required_param('courseid', PARAM_INT); +$courseid = optional_param('courseid', PARAM_INT); $id = optional_param('id', 0, PARAM_INT); $delete = optional_param('delete', 0, PARAM_BOOL); $confirm = optional_param('confirm', 0, PARAM_BOOL); -/// Course must be valid -if (!$course = get_record('course', 'id', $courseid)) { - error('Course ID was incorrect'); -} - -/// Delete action should not be called without a group id -if ($delete && !$id) { - error(get_string('errorinvalidgroup')); -} - -/// basic access control checks -if (! $course = get_record('course', 'id', $courseid)) { - error("Incorrect course id "); -} -$context = get_context_instance(CONTEXT_COURSE, $course->id); -require_capability('moodle/course:managegroups', $context); - -$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id; - if ($id) { if (!$group = get_record('groups', 'id', $id)) { error('Group ID was incorrect'); } - if ($group->courseid != $courseid) { - error('incorrect courseid'); + if (empty($courseid)) { + $courseid = $group->courseid; + + } else if ($courseid != $group->courseid) { + error('Course ID was incorrect'); } + + if (!$course = get_record('course', 'id', $courseid)) { + error('Course ID was incorrect'); + } + } else { + if (!$course = get_record('course', 'id', $courseid)) { + error('Course ID was incorrect'); + } $group = new object(); - $group->courseid = $courseid; + $group->courseid = $course->id; } -if ($id and $delete) { +$context = get_context_instance(CONTEXT_COURSE, $course->id); +require_capability('moodle/course:managegroups', $context); + +$returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id; +if ($id and $delete) { if (!$confirm) { print_header(get_string('deleteselectedgroup', 'group'), get_string('deleteselectedgroup', 'group')); $optionsyes = array('id'=>$id, 'delete'=>1, 'courseid'=>$courseid, 'sesskey'=>sesskey(), 'confirm'=>1); $optionsno = array('id'=>$courseid); - if (!$group = get_record('groups', 'id', $id)) { - error('Group ID was incorrect'); - } - notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'edit.php', 'index.php', $optionsyes, $optionsno, 'post', 'get'); + notice_yesno(get_string('deletegroupconfirm', 'group', $group->name), 'group.php', 'index.php', $optionsyes, $optionsno, 'get', 'get'); print_footer(); die; @@ -74,7 +65,7 @@ if ($id and $delete) { events_trigger('group_deleted', $eventdata); redirect('index.php?id='.$course->id); } else { - print_error('erroreditgroup', 'group', groups_home_url($course->id)); + print_error('erroreditgroup', 'group', $returnurl); } } } diff --git a/group/edit_form.php b/group/group_form.php similarity index 94% rename from group/edit_form.php rename to group/group_form.php index 7f6877dbfa..c8cf93e411 100644 --- a/group/edit_form.php +++ b/group/group_form.php @@ -56,14 +56,14 @@ class group_edit_form extends moodleform { $name = $data['name']; if ($data['id'] and $group = get_record('groups', 'id', $data['id'])) { if ($group->name != stripslashes($name)) { - if (groups_group_name_exists($COURSE->id, name)) { + if (groups_get_group_by_name($COURSE->id, $name)) { $errors['name'] = get_string('groupnameexists', 'group', stripslashes($name)); } } } else { - if (groups_group_name_exists($COURSE->id, $name)) { - $errors['name'] = get_string('groupnameexists', 'group', $name); + if (groups_get_group_by_name($COURSE->id, $name)) { + $errors['name'] = get_string('groupnameexists', 'group', stripslashes($name)); } } diff --git a/group/index.php b/group/index.php index ab86fc3bd0..ed64bb32d2 100644 --- a/group/index.php +++ b/group/index.php @@ -56,15 +56,15 @@ if (!$course = groups_get_course_info($courseid)) { die; // Client side JavaScript takes it from here. case 'deletegroup': - redirect('edit.php?delete=1&courseid='.$courseid.'&id='.$groupid); + redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid); break; case 'showcreateorphangroupform': - redirect('edit.php?courseid='.$courseid); + redirect('group.php?courseid='.$courseid); break; case 'showgroupsettingsform': - redirect('edit.php?courseid='.$courseid.'&id='.$groupid); + redirect('group.php?courseid='.$courseid.'&id='.$groupid); break; case 'updategroups': //Currently reloading. diff --git a/lib/weblib.php b/lib/weblib.php index b191d09be0..8960daba84 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -4607,30 +4607,6 @@ function update_categories_search_button($search,$page,$perpage) { } } -/** - * Prints the editing button on group page - * - * @uses $CFG - * @uses $USER - * @param int $courseid The course group is associated with - * @param int $groupid The group to update - * @return string - */ -function update_group_button($courseid, $groupid) { - global $CFG, $USER; - - if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_GROUP, $groupid))) { - $string = get_string('editgroupprofile'); - - return "
frametarget method=\"get\" action=\"$CFG->wwwroot/group/edit.php\">". - '
'. - ''. - ''. - ''. - ''. - '
'; - } -} /** * Prints the editing button on groups page diff --git a/user/index.php b/user/index.php index 783d305fdf..1ccbd6d38a 100644 --- a/user/index.php +++ b/user/index.php @@ -252,7 +252,7 @@ echo ''; echo '

'.$group->name; if (has_capability('moodle/course:managegroups', $context)) { - echo ' '; + echo ' '; echo ''.get_string('editgroupprofile').''; echo ''; }