Skip to content

Commit

Permalink
MDL-10383 - group edit form refactoring and minor bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Aug 15, 2007
1 parent 2c386f8 commit c4e953e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 64 deletions.
57 changes: 24 additions & 33 deletions group/edit.php → group/group.php 100755 → 100644
Expand Up @@ -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;

Expand All @@ -74,7 +65,7 @@
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);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions group/edit_form.php → group/group_form.php
Expand Up @@ -56,14 +56,14 @@ function validation($data) {
$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));
}
}

Expand Down
6 changes: 3 additions & 3 deletions group/index.php
Expand Up @@ -56,15 +56,15 @@
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.
Expand Down
24 changes: 0 additions & 24 deletions lib/weblib.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion user/index.php
Expand Up @@ -252,7 +252,7 @@
echo '</td><td class="content">';
echo '<h3>'.$group->name;
if (has_capability('moodle/course:managegroups', $context)) {
echo '&nbsp;<a title="'.get_string('editgroupprofile').'" href="'.groups_group_edit_url($course->id, $group->id).'">';
echo '&nbsp;<a title="'.get_string('editgroupprofile').'" href="'.$CFG->wwwroot.'/group/group.php?id='.$group->id.'&amp;courseid='.$group->courseid.'">';
echo '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.get_string('editgroupprofile').'" />';
echo '</a>';
}
Expand Down

0 comments on commit c4e953e

Please sign in to comment.