Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / course / import / activities / mod.php
blob2cdcab69e0a3ac185a23be1907643387f1fb2b1d
1 <?php // $Id$
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)) {
14 $creator = true;
17 $strimport = get_string("importdata");
19 $tcourseids = '';
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);
37 } else {
38 $cat_courses = array();
41 print_heading(get_string("importactivities"));
43 $options = array();
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.
55 // quick forms
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();
61 unset($options);
62 $options = array();
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)) {
82 $totalcount = 0;
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.'&amp;fromcourse='.$scourse->id.'">'.get_string('usethiscourse').'</a>');
93 else {
94 $table->data[] = array('',get_string('noresults'),'');
97 if (!empty($table)) {
98 print_table($table);