function backup_to_restore_array($backup, $k = 0) { if (is_array($backup)) { foreach ($backup as $key => $value) { $newkey = str_replace('backup', 'restore', $key); $restore[$newkey] = backup_to_restore_array($value, $key); } } else { if (is_object($backup)) { $tmp = get_object_vars($backup); foreach ($tmp as $key => $value) { $newkey = str_replace('backup', 'restore', $key); $restore->{$newkey} = backup_to_restore_array($value, $key); } } else { $newkey = str_replace('backup', 'restore', $k); $restore = $backup; } } return $restore; }
$tocontext = get_context_instance(CONTEXT_COURSE, $id); if ($fromcourse) { $fromcontext = get_context_instance(CONTEXT_COURSE, $fromcourse); } $syscontext = get_context_instance(CONTEXT_SYSTEM, SITEID); if (!has_capability('moodle/course:manageactivities', $tocontext)) { error("You need do not have the required permissions to import activities to this course"); } // if we're not a course creator , we can only import from our own courses. if (has_capability('moodle/course:create', $syscontext)) { $creator = true; } if ($from = get_record('course', 'id', $fromcourse)) { if (!has_capability('moodle/course:manageactivities', $fromcontext)) { error("You need to have the required permissions in the course you are importing data from, as well"); } if (!empty($filename) && file_exists($CFG->dataroot . '/' . $filename) && !empty($SESSION->import_preferences)) { $restore = backup_to_restore_array($SESSION->import_preferences); $restore->restoreto = 1; $restore->course_id = $id; $restore->importing = 1; // magic variable so we know that we're importing rather than just restoring. $SESSION->restore = $restore; redirect($CFG->wwwroot . '/backup/restore.php?file=' . $filename . '&id=' . $fromcourse . '&to=' . $id); } else { redirect($CFG->wwwroot . '/backup/backup.php?id=' . $from->id . '&to=' . $course->id); } } print_header("{$course->shortname}: {$strimportactivities}", $course->fullname, "<a href=\"{$CFG->wwwroot}/course/view.php?id={$course->id}\">{$course->shortname}</a> " . "-> <a href=\"{$CFG->wwwroot}/course/import.php?id={$course->id}\">" . get_string('import') . "</a> " . "-> {$strimportactivities}"); require_once 'mod.php'; print_footer();