--- /Users/daniele/Desktop/funzionando1.2/latest/moodle20/mod/data/edit.php	2010-09-21 02:01:27.000000000 +0200
+++ /Applications/MAMP/htdocs/moodle20/mod/data/edit.php	2010-09-23 12:43:35.000000000 +0200
@@ -93,10 +93,18 @@
     }
 }

+/// Check to see if groups are being used here
+$currentgroup = groups_get_activity_group($cm);
+$groupmode = groups_get_activity_groupmode($cm);
+
 if ($rid) {    // So do you have access?
     if (!(has_capability('mod/data:manageentries', $context) or data_isowner($rid)) or !confirm_sesskey() ) {
         print_error('noaccess','data');
     }
+} else {
+    if (!data_user_can_add_entry($data, $currentgroup, $groupmode) || data_atmaxentries($data)) {
+        print_error('cannotadd', 'data');
+    }
 }

 if ($cancel) {
@@ -136,10 +144,6 @@
 $PAGE->set_title($data->name);
 $PAGE->set_heading($course->fullname);

-/// Check to see if groups are being used here
-$currentgroup = groups_get_activity_group($cm);
-$groupmode = groups_get_activity_groupmode($cm);
-
 if ($currentgroup) {
     $groupselect = " AND groupid = '$currentgroup'";
     $groupparam = "&amp;groupid=$currentgroup";
@@ -190,10 +194,6 @@

     } else { /// Add some new records

-        if (!data_user_can_add_entry($data, $currentgroup, $groupmode)) {
-            print_error('cannotadd', 'data');
-        }
-
     /// Check if maximum number of entry as specified by this database is reached
     /// Of course, you can't be stopped if you are an editting teacher! =)

