<?php
require_once("../../config.php");

require_once($CFG->libdir.'/weblib.php');

$systemcontext = context_system::instance();

$PAGE->set_url("/local/treestudyplan/doc.php",array());
$PAGE->requires->css(new moodle_url($CFG->wwwroot.'/local/treestudyplan/css/devstyles.css'));
$PAGE->set_pagelayout('base');
$PAGE->set_context($systemcontext);
require_login();

$pi = $_SERVER['PATH_INFO'];
$file = $CFG->dirroot."/local/treestudyplan/doc".$pi;

// Fallback to index
if(!file_exists($file)){
	$file = $CFG->dirroot."/local/treestudyplan/doc/index.htm";
}

$mime = mime_content_type($file);
$text_types = ["text/html","text/plain"];

if( in_array($mime,$text_types))
{
	print $OUTPUT->header();
	print file_get_contents($file);
	print $OUTPUT->footer();
}
else {
	header("Content-type: {$mime}");
	print file_get_contents($file);
}