]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10383 - group edit form refactoring and minor bugfixing
authorskodak <skodak>
Wed, 15 Aug 2007 20:33:17 +0000 (20:33 +0000)
committerskodak <skodak>
Wed, 15 Aug 2007 20:33:17 +0000 (20:33 +0000)
group/group.php [moved from group/edit.php with 77% similarity, mode: 0644]
group/group_form.php [moved from group/edit_form.php with 94% similarity]
group/index.php
lib/weblib.php
user/index.php

old mode 100755 (executable)
new mode 100644 (file)
similarity index 77%
rename from group/edit.php
rename to group/group.php
index cfa6cfd..71a307b
@@ -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.'&amp;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.'&amp;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);
         }
     }
 }
similarity index 94%
rename from group/edit_form.php
rename to group/group_form.php
index 7f6877dbfa9d24d8900b7ec3ccdbd8eebccb5358..c8cf93e41119bad1ade7e437a78f8e77ca0edf80 100644 (file)
@@ -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));
             }
         }
 
index ab86fc3bd0e9f251cf824525ac36d3d959d77f8b..ed64bb32d266094ad25180dbb961a9943e2e5714 100644 (file)
@@ -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&amp;courseid='.$courseid.'&amp;id='.$groupid);
+            redirect('group.php?delete=1&amp;courseid='.$courseid.'&amp;id='.$groupid);
             break;
 
         case 'showcreateorphangroupform':
-            redirect('edit.php?courseid='.$courseid);
+            redirect('group.php?courseid='.$courseid);
             break;
 
         case 'showgroupsettingsform':
-            redirect('edit.php?courseid='.$courseid.'&amp;id='.$groupid);
+            redirect('group.php?courseid='.$courseid.'&amp;id='.$groupid);
             break;
 
         case 'updategroups': //Currently reloading.
index b191d09be0c49746465e857f261f0009e265d276..8960daba841def605abe722473e493f06d39b41d 100644 (file)
@@ -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
index 783d305fdf3cdc5e76ddaa0684af9ae02739c60a..1ccbd6d38ae5b2c2b65e2117f4b9ad2fa228aad5 100644 (file)
                 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>';
                 }