require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/local/codechecker/locallib.php';
$path = optional_param('path', '', PARAM_PATH);
if ($path) {
    $pageparams = array('path' => $path);
} else {
    $pageparams = array();
}
require_login();
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
admin_externalpage_setup('local_codechecker', '', $pageparams);
$PAGE->set_heading($SITE->fullname);
$PAGE->set_title($SITE->fullname . ': ' . get_string('pluginname', 'local_codechecker'));
raise_memory_limit(MEMORY_HUGE);
set_time_limit(300);
$mform = new local_codechecker_form(new moodle_url('/local/codechecker/'));
$mform->set_data((object) array('path' => $path));
if ($data = $mform->get_data()) {
    redirect(new moodle_url('/local/codechecker/', array('path' => $data->path)));
}
if ($path) {
    $fullpath = $CFG->dirroot . '/' . trim($path, '/');
    if (!is_file($fullpath) && !is_dir($fullpath)) {
        $fullpath = null;
    }
}
$output = $PAGE->get_renderer('local_codechecker');
echo $OUTPUT->header();
if ($path) {
    if ($fullpath) {
        $phpcs = new PHP_CodeSniffer();
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->dirroot . '/local/codechecker/locallib.php';
$path = optional_param('path', '', PARAM_PATH);
$exclude = optional_param('exclude', '', PARAM_NOTAGS);
$pageparams = array();
if ($path) {
    $pageparams['path'] = $path;
}
if ($exclude) {
    $pageparams['exclude'] = $exclude;
}
admin_externalpage_setup('local_codechecker', '', $pageparams);
// We are going to need lots of memory and time.
raise_memory_limit(MEMORY_HUGE);
set_time_limit(300);
$mform = new local_codechecker_form(new moodle_url('/local/codechecker/'));
$mform->set_data((object) $pageparams);
if ($data = $mform->get_data()) {
    redirect(new moodle_url('/local/codechecker/', $pageparams));
}
if ($path) {
    $fullpath = $CFG->dirroot . '/' . trim($path, '/');
    if (!is_file($fullpath) && !is_dir($fullpath)) {
        $fullpath = null;
    }
}
$output = $PAGE->get_renderer('local_codechecker');
echo $OUTPUT->header();
if ($path) {
    if ($fullpath) {
        $reportfile = make_temp_directory('phpcs') . '/phpcs_' . random_string(10) . '.xml';