Index: group/lib/basicgrouplib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/group/lib/basicgrouplib.php,v
retrieving revision 1.8
diff -u -r1.8 basicgrouplib.php
--- group/lib/basicgrouplib.php	20 Jan 2007 10:58:24 -0000	1.8
+++ group/lib/basicgrouplib.php	23 Jan 2007 19:05:46 -0000
@@ -196,28 +196,17 @@
 	return groups_db_group_exists($groupid);
 }
 
+
 /**
  * Determine if a course ID, group name and description match a group in the database.
  *   For backup/restorelib.php
  * @return mixed A group-like object with $group->id, or false.
  */
 function groups_group_matches($courseid, $grp_name, $grp_description) {
-//$gro_db->id; $gro_db = get_record("groups","courseid",$restore->course_id,"name",$gro->name,"description",$gro->description);    
-    global $CFG;
-    $sql = "SELECT g.id, g.name, g.description
-        FROM {$CFG->prefix}groups AS g
-        INNER JOIN {$CFG->prefix}groups_courses_groups AS cg ON g.id = cg.groupid
-        WHERE g.name = '$grp_name'
-        AND g.description = '$grp_description'
-        AND cg.courseid = '$courseid'";
-    $records = get_records_sql($sql);
-    $group = false;
-    if ($records) {
-        $group = $records[0];
-    } 
-    return $group;
+    return groups_db_group_matches($courseid, $grp_name, $grp_description);
 }
 
+
 /**
  * Determines if a specified user is a member of a specified group
  * @param int $groupid The group about which the request has been made
Index: group/lib/groupinglib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/group/lib/groupinglib.php,v
retrieving revision 1.8
diff -u -r1.8 groupinglib.php
--- group/lib/groupinglib.php	20 Jan 2007 10:58:24 -0000	1.8
+++ group/lib/groupinglib.php	23 Jan 2007 19:05:46 -0000
@@ -36,8 +36,8 @@
         return false;
     }
     $sql = "SELECT gg.*
-        FROM {$CFG->prefix}groups_groupings AS gg
-        INNER JOIN {$CFG->prefix}groups_courses_groupings AS cg ON gg.id = cg.groupingid
+        FROM {$CFG->prefix}groups_groupings gg
+        INNER JOIN {$CFG->prefix}groups_courses_groupings cg ON gg.id = cg.groupingid
         WHERE cg.courseid = '$courseid'";
     $groupings = get_records_sql($sql);
     return $groupings;
@@ -130,11 +130,11 @@
     $join = '';
     $where= '';
     if ($courseid) {
-        $join = "INNER JOIN {$CFG->prefix}groups_courses_groups AS cg ON g.id = cg.groupid";
+        $join = "INNER JOIN {$CFG->prefix}groups_courses_groups cg ON g.id = cg.groupid";
         $where= "AND cg.courseid = '$courseid'";
     }
     $sql = "SELECT g.id
-        FROM {$CFG->prefix}groups AS g
+        FROM {$CFG->prefix}groups g
         $join
         WHERE g.id NOT IN 
         (SELECT groupid FROM {$CFG->prefix}groups_groupings_groups)
@@ -280,8 +280,8 @@
 function groups_grouping_matches($courseid, $gg_name, $gg_description) {
     global $CFG;
     $sql = "SELECT gg.id, gg.name, gg.description
-        FROM {$CFG->prefix}groups_groupings AS gg
-        INNER JOIN {$CFG->prefix}groups_courses_groupings AS cg ON gg.id = cg.groupingid
+        FROM {$CFG->prefix}groups_groupings gg
+        INNER JOIN {$CFG->prefix}groups_courses_groupings cg ON gg.id = cg.groupingid
         WHERE gg.name = '$gg_name'
         AND gg.description = '$gg_description'
         AND cg.courseid = '$courseid'";
Index: group/db/dbgroupinglib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/group/db/dbgroupinglib.php,v
retrieving revision 1.5
diff -u -r1.5 dbgroupinglib.php
--- group/db/dbgroupinglib.php	17 Jan 2007 13:56:10 -0000	1.5
+++ group/db/dbgroupinglib.php	23 Jan 2007 19:05:45 -0000
@@ -214,10 +214,10 @@
     } else {
         global $CFG;
         $sql = "SELECT gm.id
-        FROM {$CFG->prefix}groups_groupings_groups AS gg
-        INNER JOIN {$CFG->prefix}groups_members AS gm
+        FROM {$CFG->prefix}groups_groupings_groups gg
+        INNER JOIN {$CFG->prefix}groups_members gm
         ON gg.groupid = gm.groupid
-        WHERE gm.userid = $userid AND gg.groupingid = $groupingid";
+        WHERE gm.userid = '$userid' AND gg.groupingid = '$groupingid'";
         $belongstogroup = record_exists_sql($sql);
     }
     return $belongstogroup;
Index: group/db/dbbasicgrouplib.php
===================================================================
RCS file: /cvsroot/moodle/moodle/group/db/dbbasicgrouplib.php,v
retrieving revision 1.9
diff -u -r1.9 dbbasicgrouplib.php
--- group/db/dbbasicgrouplib.php	20 Jan 2007 10:57:48 -0000	1.9
+++ group/db/dbbasicgrouplib.php	23 Jan 2007 19:05:45 -0000
@@ -99,13 +99,13 @@
         $groupids = false;
     } else {  
         global $CFG;
-        $sql = "SELECT g.id, userid 
-                FROM {$CFG->prefix}groups_members AS gm 
-                INNER JOIN {$CFG->prefix}groups AS g
+        $sql = "SELECT g.id, gm.userid 
+                FROM {$CFG->prefix}groups_members gm 
+                INNER JOIN {$CFG->prefix}groups g
                 ON gm.groupid = g.id
-                INNER JOIN {$CFG->prefix}groups_courses_groups AS cg
+                INNER JOIN {$CFG->prefix}groups_courses_groups cg
                 ON g.id = cg.groupid
-                WHERE cg.courseid  = $courseid AND gm.userid=$userid";
+                WHERE cg.courseid  = '$courseid' AND gm.userid = '$userid'";
                 
         $groups = get_records_sql($sql);
         $groupids = groups_groups_to_groupids($groups);
@@ -152,10 +152,10 @@
 function groups_db_users_in_common_group($userid1, $userid2) {
 	global $CFG;
     $havecommongroup = false;
-	$sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members AS gm1 " .
-			"INNER JOIN {$CFG->prefix}groups_members AS gm2 " .
-			"ON gm1.groupid =gm2.groupid" .
-			"WHERE gm1.userid = $userid1 AND gm2.userid = $userid2";
+	$sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members gm1 " .
+			"INNER JOIN {$CFG->prefix}groups_members gm2 " .
+			"ON gm1.groupid = gm2.groupid" .
+			"WHERE gm1.userid = '$userid1' AND gm2.userid = '$userid2'";
     $commongroups = get_record_sql($sql);
     if ($commongroups) {
     	$havecommongroup = true;
@@ -189,6 +189,29 @@
 
 
 /**
+ * Determine if a course ID, group name and description match a group in the database.
+ *   For backup/restorelib.php
+ * @return mixed A group-like object with $group->id, or false.
+ */
+function groups_db_group_matches($courseid, $grp_name, $grp_description) {
+//$gro_db->id; $gro_db = get_record("groups","courseid",$restore->course_id,"name",$gro->name,"description",$gro->description);    
+    global $CFG;
+    $sql = "SELECT g.id, g.name, g.description
+        FROM {$CFG->prefix}groups g
+        INNER JOIN {$CFG->prefix}groups_courses_groups cg ON g.id = cg.groupid
+        WHERE g.name = '$grp_name'
+        AND g.description = '$grp_description'
+        AND cg.courseid = '$courseid'";
+    $records = get_records_sql($sql);
+    $group = false;
+    if ($records) {
+        $group = $records[0];
+    } 
+    return $group;
+}
+
+
+/**
  * Determines if a specified user is a member of a specified group
  * @param int $groupid The group about which the request has been made
  * @param int $userid The user about which the request has been made
