Пример #1
0
/**
 * Serves seplment submissions and other files.
 *
 * @param mixed $course course or id of the course
 * @param mixed $cm course module or id of the course module
 * @param context $context
 * @param string $filearea
 * @param array $args
 * @param bool $forcedownload
 * @return bool false if file not found, does not return if found - just send the file
 */
function seplsubmission_onlinetext_pluginfile($course, $cm, context $context, $filearea, $args, $forcedownload)
{
    global $DB, $CFG;
    if ($context->contextlevel != CONTEXT_MODULE) {
        return false;
    }
    require_login($course, false, $cm);
    $itemid = (int) array_shift($args);
    $record = $DB->get_record('sepl_submission', array('id' => $itemid), 'userid, seplment, groupid', MUST_EXIST);
    $userid = $record->userid;
    $groupid = $record->groupid;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $sepl = new sepl($context, $cm, $course);
    if ($sepl->get_instance()->id != $record->seplment) {
        return false;
    }
    if ($sepl->get_instance()->teamsubmission && !$sepl->can_view_group_submission($groupid)) {
        return false;
    }
    if (!$sepl->get_instance()->teamsubmission && !$sepl->can_view_submission($userid)) {
        return false;
    }
    $relativepath = implode('/', $args);
    $fullpath = "/{$context->id}/seplsubmission_onlinetext/{$filearea}/{$itemid}/{$relativepath}";
    $fs = get_file_storage();
    if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
        return false;
    }
    // Download MUST be forced - security!
    send_stored_file($file, 0, 0, true);
}
Пример #2
0
/**
 * Permission control method for submission plugin ---- required method for AJAXmoodle based comment API
 *
 * @param stdClass $options
 * @return array
 */
function seplsubmission_comments_comment_permissions(stdClass $options)
{
    global $USER, $CFG, $DB;
    if ($options->commentarea != 'submission_comments' && $options->commentarea != 'submission_comments_upgrade') {
        throw new comment_exception('invalidcommentarea');
    }
    if (!($submission = $DB->get_record('sepl_submission', array('id' => $options->itemid)))) {
        throw new comment_exception('invalidcommentitemid');
    }
    $context = $options->context;
    require_once $CFG->dirroot . '/mod/sepl/locallib.php';
    $seplment = new sepl($context, null, null);
    if ($seplment->get_instance()->id != $submission->seplment) {
        throw new comment_exception('invalidcontext');
    }
    if ($seplment->get_instance()->teamsubmission && !$seplment->can_view_group_submission($submission->groupid)) {
        return array('post' => false, 'view' => false);
    }
    if (!$seplment->get_instance()->teamsubmission && !$seplment->can_view_submission($submission->userid)) {
        return array('post' => false, 'view' => false);
    }
    return array('post' => true, 'view' => true);
}