3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
7 require_once($CFG->dirroot
.'/course/lib.php');
8 require_once($CFG->dirroot
.'/backup/restorelib.php');
10 $syscontext = get_context_instance(CONTEXT_SYSTEM
);
12 // if we're not a course creator , we can only import from our own courses.
13 if (has_capability('moodle/course:create', $syscontext)) {
17 $strimport = get_string("importdata");
21 if ($teachers = get_user_capability_course('moodle/course:update')) {
22 foreach ($teachers as $teacher) {
23 if ($teacher->id
!= $course->id
&& $teacher->id
!= SITEID
){
24 $tcourseids .= $teacher->id
.',';
29 $taught_courses = array();
30 if (!empty($tcourseids)) {
31 $tcourseids = substr($tcourseids,0,-1);
32 $taught_courses = get_records_list('course', 'id', $tcourseids);
35 if (!empty($creator)) {
36 $cat_courses = get_courses($course->category
);
38 $cat_courses = array();
41 print_heading(get_string("importactivities"));
44 foreach ($taught_courses as $tcourse) {
45 if ($tcourse->id
!= $course->id
&& $tcourse->id
!= SITEID
){
46 $options[$tcourse->id
] = format_string($tcourse->fullname
);
50 if (empty($options) && empty($creator)) {
51 notify(get_string('courseimportnotaught'));
52 return; // yay , this will pass control back to the file that included or required us.
56 include_once('import_form.php');
58 $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')));
59 $mform_post ->display();
64 foreach ($cat_courses as $ccourse) {
65 if ($ccourse->id
!= $course->id
&& $ccourse->id
!= SITEID
) {
66 $options[$ccourse->id
] = format_string($ccourse->fullname
);
69 $cat = get_record("course_categories","id",$course->category
);
71 if (count($options) > 0) {
72 $mform_post = new course_import_activities_form_1($CFG->wwwroot
.'/course/import/activities/index.php', array('options'=>$options, 'courseid' => $course->id
, 'text' => get_string('coursescategory')));
73 $mform_post ->display();
76 if (!empty($creator)) {
77 $mform_post = new course_import_activities_form_2($CFG->wwwroot
.'/course/import/activities/index.php', array('courseid' => $course->id
));
78 $mform_post ->display();
81 if (!empty($fromcoursesearch) && !empty($creator)) {
83 $courses = get_courses_search(explode(" ",$fromcoursesearch),"fullname ASC",$page,50,$totalcount);
84 if (is_array($courses) and count($courses) > 0) {
85 $table->data
[] = array('<b>'.get_string('searchresults').'</b>','','');
86 foreach ($courses as $scourse) {
87 if ($course->id
!= $scourse->id
) {
88 $table->data
[] = array('',format_string($scourse->fullname
),
89 '<a href="'.$CFG->wwwroot
.'/course/import/activities/index.php?id='.$course->id
.'&fromcourse='.$scourse->id
.'">'.get_string('usethiscourse').'</a>');
94 $table->data
[] = array('',get_string('noresults'),'');