mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-10383 - group edit form refactoring and minor bugfixing
This commit is contained in:
parent
2c386f82e5
commit
c4e953e69e
57
group/edit.php → group/group.php
Executable file → Normal file
57
group/edit.php → group/group.php
Executable file → Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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 "<form $CFG->frametarget method=\"get\" action=\"$CFG->wwwroot/group/edit.php\">".
|
||||
'<div>'.
|
||||
'<input type="hidden" name="courseid" value="'. $courseid .'" />'.
|
||||
'<input type="hidden" name="id" value="'. $groupid .'" />'.
|
||||
'<input type="hidden" name="grouping" value="-1" />'.
|
||||
'<input type="hidden" name="edit" value="on" />'.
|
||||
'<input type="submit" value="'. $string .'" /></div></form>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the editing button on groups page
|
||||
|
@ -252,7 +252,7 @@
|
||||
echo '</td><td class="content">';
|
||||
echo '<h3>'.$group->name;
|
||||
if (has_capability('moodle/course:managegroups', $context)) {
|
||||
echo ' <a title="'.get_string('editgroupprofile').'" href="'.groups_group_edit_url($course->id, $group->id).'">';
|
||||
echo ' <a title="'.get_string('editgroupprofile').'" href="'.$CFG->wwwroot.'/group/group.php?id='.$group->id.'&courseid='.$group->courseid.'">';
|
||||
echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.get_string('editgroupprofile').'" />';
|
||||
echo '</a>';
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user