diff --git a/course/import/groups/import_form.php b/course/import/groups/import_form.php
index f0a7f1a..2d630fc 100755
--- a/course/import/groups/import_form.php
+++ b/course/import/groups/import_form.php
@@ -2,7 +2,7 @@
 
 require_once($CFG->libdir.'/formslib.php');
 
-class course_import_groups_form extends moodleform {
+class course_import_groups_form_1 extends moodleform {
 
     function definition() {
 
@@ -34,4 +34,30 @@ class course_import_groups_form extends moodleform {
         }
     }
 }
+
+class course_import_groups_form_2 extends moodleform {
+
+    function definition() {
+        global $CFG;
+
+        $mform    =& $this->_form;
+
+        $options = $this->_customdata['options'];
+        $courseid = $this->_customdata['courseid'];
+        $mform->addElement('header', 'general', '');//fill in the data depending on page params
+        //later using set_data
+
+        $available_string = get_string('availablecourses');
+        $mform->addElement('select', 'fromcourse',
+                           $available_string .
+                           helpbutton('groupfromcourse', $available_string, 'moodle', true, false, '', true), $options);
+
+        $submit_string = get_string('importfromselectedcourse', 'group');
+        $this->add_action_buttons(false, $submit_string);
+
+        $mform->addElement('hidden', 'id');
+        $mform->setType('id', PARAM_INT);
+        $mform->setConstants(array('id'=> $courseid));
+    }
+}
 ?>
diff --git a/course/import/groups/index.php b/course/import/groups/index.php
index 72c9f1c..015ab0f 100755
--- a/course/import/groups/index.php
+++ b/course/import/groups/index.php
@@ -52,8 +52,8 @@
 
     print_header("$course->shortname: $strimportgroups", $course->fullname, $navigation);
 
-/// If a file has been uploaded, then process it
 
+/// If a file has been uploaded, then process it
     require_once($CFG->dirroot.'/lib/uploadlib.php');
     $um = new upload_manager('userfile',false,false,null,false,0);
     if ($um->preprocess_files() and confirm_sesskey()) {
@@ -198,6 +198,51 @@
         echo '<hr />';
     }
 
+    // If a course was selected, then copy its groups
+    if (($data = data_submitted()) && isset($data->fromcourse) ) {
+
+        if (!$course_from = get_record('course', 'id', $data->fromcourse)) {
+            print_error('invalidcoursefrom'); //'The course ID is invalid'
+        }
+
+        $context_from = get_context_instance(CONTEXT_COURSE, $data->fromcourse);
+        require_capability('moodle/course:update', $context_from);
+
+        $sql = "SELECT g1.*
+                  FROM groups g1
+             LEFT JOIN groups g2
+                    ON (g1.name = g2.name AND
+                        g2.courseid = {$id})
+                 WHERE g1.courseid = {$data->fromcourse}
+                   AND ISNULL(g2.id)";
+
+        if ($groups_to_create = get_records_sql($sql)) {
+           foreach ($groups_to_create as $g) {
+               $g->courseid = $id;
+               insert_record('groups', $g);
+           }
+        }
+
+        $sql = "INSERT into groups_members (groupid, userid,timeadded)
+                SELECT g2.id, gm.userid, gm.timeadded
+                  FROM groups_members gm
+                  JOIN groups g1
+                    ON (g1.id = gm.groupid AND
+                        g1.courseid = {$data->fromcourse})
+                  JOIN groups g2
+                    ON (g2.name = g1.name AND
+                        g2.courseid = {$id})
+                  JOIN context ctx
+                    ON (ctx.instanceid = g2.courseid AND
+                        ctx.contextlevel = 50)
+                  JOIN role_assignments ra
+                    ON (ra.contextid = ctx.id AND
+                        gm.userid = ra.userid)";
+
+        execute_sql($sql, false);
+        echo get_string('groups_copied', 'group');
+    }
+
 /// Print the form
     require('mod.php');
 
diff --git a/course/import/groups/mod.php b/course/import/groups/mod.php
index 141a639..5c6142d 100644
--- a/course/import/groups/mod.php
+++ b/course/import/groups/mod.php
@@ -14,14 +14,49 @@
     print_heading_with_help($strimportgroups, 'uploadgroups');
     $maxuploadsize = get_max_upload_file_size();
     echo '<p align="center">';
-    print_simple_box_start('center','80%');
 
     // use formslib
     include_once('import_form.php');
-    $mform_post = new course_import_groups_form($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize));
+    $mform_post = new course_import_groups_form_1($CFG->wwwroot.'/course/import/groups/index.php?id='.$id, array('maxuploadsize'=>$maxuploadsize));
     $mform_post ->display();
 
-    print_simple_box_end();
+
+    $tcourseids = '';
+
+    if ($teachers = get_user_capability_course('moodle/course:update')) {
+        foreach ($teachers as $teacher) {
+            if ($teacher->id != $course->id && $teacher->id != SITEID){
+                $tcourseids .= $teacher->id.',';
+            }
+        }
+    }
+
+    $taught_courses = array();
+    if (!empty($tcourseids)) {
+        $tcourseids = substr($tcourseids,0,-1);
+        $taught_courses = get_records_list('course', 'id', $tcourseids, 'sortorder', 'id, fullname');
+    }
+
+    if (!empty($creator)) {
+        $cat_courses = get_courses($course->category, $sort="c.sortorder ASC", $fields="c.id, c.fullname");
+    } else {
+        $cat_courses = array();
+    }
+
+    $options = array();
+    foreach ($taught_courses as $tcourse) {
+        if ($tcourse->id != $course->id && $tcourse->id != SITEID){
+            $options[$tcourse->id] = format_string($tcourse->fullname);
+        }
+    }
+
+    if (empty($options) && empty($creator)) {
+        notify(get_string('courseimportnotaught'));
+        return; // yay , this will pass control back to the file that included or required us.
+    }
+
+    $mform_post = new course_import_groups_form_2($CFG->wwwroot.'/course/import/groups/index.php', array('courseid' => $course->id, 'options' => $options));
+    $mform_post ->display();
 
     echo '</p>';
 
diff --git a/lang/en_utf8/group.php b/lang/en_utf8/group.php
index c1b6658..a494756 100644
--- a/lang/en_utf8/group.php
+++ b/lang/en_utf8/group.php
@@ -140,4 +140,8 @@ $string['groupsgroupings'] = 'Groups &amp; groupings';
 $string['groupingsonly'] = 'Groupings only';
 $string['groupsonly'] = 'Groups only';
 
-?>
\ No newline at end of file
+$string['groups_copied'] = 'Groups successfully copied.';
+$string['importfromselectedcourse'] = 'Import groups and members from selected course';
+
+
+?>
diff --git a/lang/en_utf8/help/groupfromcourse.html b/lang/en_utf8/help/groupfromcourse.html
new file mode 100644
index 0000000..adfe52a
--- /dev/null
+++ b/lang/en_utf8/help/groupfromcourse.html
@@ -0,0 +1,4 @@
+<h1>Import groups from course</h1>
+
+<p>This tool allow a user to import all groups and group members from courses where he/she has the 'moodle/course:update' capability.</p>
+<p>All groups that exist on the selected course will be copied, and all groups members that have any role assignment on this course will be copied too.</p>
