$viewpage .= isset($_REQUEST['id']) ? '?id=' . $_REQUEST['id'] : '';
$viewpage .= isset($_REQUEST['do']) ? '&do=' . $_REQUEST['do'] : '';
activityLog($viewpage, "REQUEST");
activityLog("lib.php Loaded", "REQUIRE_ONCE");
require_once $CFG->dirroot . "/lib/uploadlib.php";
activityLog("uploadlib.php Loaded", "REQUIRE_ONCE");
if (isset($PAGE) and is_callable(array($PAGE->requires, 'js'))) {
    // Are we using new moodle or old?
    $jsurl = new moodle_url($CFG->wwwroot . '/mod/turnitintool/turnitintool.js');
    $PAGE->requires->js($jsurl, true);
    $cssurl = new moodle_url($CFG->wwwroot . '/mod/turnitintool/styles.css');
    $PAGE->requires->css($cssurl);
} else {
    require_js($CFG->wwwroot . '/mod/turnitintool/turnitintool.js');
}
activityLog("turnitintool.js Loaded", "REQUIRE_JS");
turnitintool_process_api_error();
$id = required_param('id', PARAM_INT);
// Course Module ID, or
$a = optional_param('a', 0, PARAM_INT);
// turnitintool ID
if ($id) {
    if (!($cm = get_coursemodule_from_id('turnitintool', $id))) {
        turnitintool_print_error("Course Module ID was incorrect");
    }
    if (!($course = turnitintool_get_record("course", "id", $cm->course))) {
        turnitintool_print_error("Course is misconfigured");
    }
    if (!($turnitintool = turnitintool_get_record("turnitintool", "id", $cm->instance))) {
        turnitintool_print_error("Course module is incorrect");
    }
/**
 * Checks for error session array and if it is present display the error stored and exit
 */
function turnitintool_process_api_error()
{
    if (isset($_SESSION['turnitintool_errorarray'])) {
        $errorarray = $_SESSION['turnitintool_errorarray'];
        activityLog($errorarray['input'], "API_ERROR");
        unset($_SESSION['turnitintool_errorarray']);
        turnitintool_print_error($errorarray['input'], $errorarray['module'], $errorarray['link'], $errorarray['param'], $errorarray['file'], $errorarray['line']);
        exit;
    }
}