Esempio n. 1
0
//HUB_SCREENSHOT_FILE_TYPE and HUB_BACKUP_FILE_TYPE
$token = optional_param('token', '', PARAM_ALPHANUM);
$filetype = optional_param('filetype', '', PARAM_ALPHA);
//can be screenshots, backup, ...
$screenshotnumber = optional_param('screenshotnumber', 1, PARAM_INT);
//the screenshot number of this course
$courseid = optional_param('courseid', '', PARAM_ALPHANUM);
// check the communication token
$hub = new local_hub();
$communication = $hub->get_communication(WSSERVER, REGISTEREDSITE, '', $token);
if (!empty($token) && !empty($communication) and get_config('local_hub', 'hubenabled')) {
    //retrieve the site
    $siteurl = $communication->remoteurl;
    $site = $hub->get_site_by_url($siteurl);
    //check that the course exist
    $course = $DB->get_record('hub_course_directory', array('id' => $courseid, 'siteid' => $site->id));
    if (!empty($course) && !empty($_FILES)) {
        switch ($filetype) {
            case HUB_BACKUP_FILE_TYPE:
                //check that the backup doesn't already exist
                $backup = $hub->backup_exits($courseid);
                if (empty($backup)) {
                    $hub->add_backup($_FILES['file'], $courseid);
                }
                break;
            case HUB_SCREENSHOT_FILE_TYPE:
                $hub->add_screenshot($_FILES['file'], $courseid, $screenshotnumber);
                break;
        }
    }
}