Index: import_form.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/import/activities/import_form.php,v retrieving revision 1.4 diff -u -r1.4 import_form.php --- import_form.php 12 Jan 2007 19:01:33 -0000 1.4 +++ import_form.php 15 Nov 2007 10:46:13 -0000 @@ -13,6 +13,11 @@ $courseid = $this->_customdata['courseid']; $mform->addElement('header', 'general', '');//fill in the data depending on page params //later using set_data + + if ( (count($options) > 100) && (strcmp($text, get_string('coursescategory')) == 0) ) { + $note = 'Too many courses to display ('.count($options).'). Use search instead.'; + $mform->addElement('static', 'notice', $text, $note); + } else { $mform->addElement('select', 'fromcourse', $text, $options); // buttons @@ -22,6 +27,7 @@ $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->setConstants(array('id'=> $courseid)); + } } Index: mod.php =================================================================== RCS file: /cvsroot/moodle/moodle/course/import/activities/mod.php,v retrieving revision 1.8.2.1 diff -u -r1.8.2.1 mod.php --- mod.php 28 Feb 2007 16:15:36 -0000 1.8.2.1 +++ mod.php 15 Nov 2007 10:46:13 -0000 @@ -8,45 +8,31 @@ require_once($CFG->dirroot.'/backup/restorelib.php'); $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID); + $catcontext = get_context_instance(CONTEXT_COURSECAT, $course->category); - // if we're not a course creator , we can only import from our own courses. - if (has_capability('moodle/course:create', $syscontext)) { + // if the user is not a course creator or admin, only import from users own courses. + if (has_capability('moodle/course:create', $syscontext) || has_capability('moodle/course:create', $catcontext)) { $creator = true; } $strimport = get_string("importdata"); - - $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); - } - - if (!empty($creator)) { - $cat_courses = get_courses($course->category); - } else { - $cat_courses = array(); - } - print_heading(get_string("importactivities")); + + // Get courses the user has taught. $options = array(); - foreach ($taught_courses as $tcourse) { - if ($tcourse->id != $course->id && $tcourse->id != SITEID){ - $options[$tcourse->id] = format_string($tcourse->fullname); - } + if ($mycourses = get_my_courses($USER->id, null, null, false, 0)) { + foreach ($mycourses as $mycourse) { + if ($mycourse->id != $course->id && $mycourse->id != SITEID){ + $coursecontext = get_context_instance(CONTEXT_COURSE, $mycourse->id); + if (has_capability('moodle/course:update',$coursecontext)) { + $options[$mycourse->id] = format_string($mycourse->fullname); + } + } + } } + // If the user hasn't taught any courses and is not a course creator or admin, there's nothing to import - return if (empty($options) && empty($creator)) { notify(get_string('courseimportnotaught')); return; // yay , this will pass control back to the file that included or required us. @@ -55,15 +41,25 @@ // quick forms include_once('import_form.php'); - $mform_post = new course_import_activities_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text'=> get_string('coursestaught'))); - $mform_post ->display(); - + if (count($options) > 0) { + $mform_post = new course_import_activities_form_1($CFG->wwwroot.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id, 'text'=> get_string('coursestaught'))); + $mform_post ->display(); + } unset($options); + + + // Get courses in the same category if user has course create capabilities in the site or category context. + if (!empty($creator)) { + $cat_courses = get_courses($course->category); + } else { + $cat_courses = array(); + } + $options = array(); foreach ($cat_courses as $ccourse) { if ($ccourse->id != $course->id && $ccourse->id != SITEID) { - $options[$ccourse->id] = format_string($ccourse->fullname); + $options[$ccourse->id] = format_string($ccourse->fullname); } } $cat = get_record("course_categories","id",$course->category); @@ -73,6 +69,8 @@ $mform_post ->display(); } + + // Display a search box if user has course create capabilities if (!empty($creator)) { $mform_post = new course_import_activities_form_2($CFG->wwwroot.'/course/import/activities/index.php', array('courseid' => $course->id)); $mform_post ->display();