dirroot.'/course/lib.php'); require_once($CFG->dirroot.'/backup/restorelib.php'); $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID); // if we're not a course creator , we can only import from our own courses. if (has_capability('moodle/course:create', $syscontext)) { $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")); $options = array(); foreach ($taught_courses as $tcourse) { if ($tcourse->id != $course->id && $tcourse->id != SITEID){ $options[$tcourse->id] = $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. } $fm = '
'; $submit = '
'; if (count($options) > 0) { $table->data[] = array($fm.''.get_string('coursestaught').'', choose_from_menu($options,"fromcourse","","choose","","0",true), $submit); } unset($options); $options = array(); foreach ($cat_courses as $ccourse) { if ($ccourse->id != $course->id && $ccourse->id != SITEID) { $options[$ccourse->id] = $ccourse->fullname; } } $cat = get_record("course_categories","id",$course->category); if (count($options) > 0) { $table->data[] = array($fm.''.get_string('coursescategory').' ('.$cat->name .')', choose_from_menu($options,"fromcourse","","choose","","0",true), $submit); } if (!empty($creator)) { $table->data[] = array($fm.''.get_string('searchcourses').'', '', ''); } if (!empty($fromcoursesearch) && !empty($creator)) { $totalcount = 0; $courses = get_courses_search(explode(" ",$fromcoursesearch),"fullname ASC",$page,50,$totalcount); if (is_array($courses) and count($courses) > 0) { $table->data[] = array(''.get_string('searchresults').'','',''); foreach ($courses as $scourse) { if ($course->id != $scourse->id) { $table->data[] = array('',$scourse->fullname, '' .get_string('usethiscourse')); } } } else { $table->data[] = array('',get_string('noresults'),''); } } print_table($table); ?>