Exemplo n.º 1
0
    if ($folder->get('artefacttype') == 'folder' && $folder->get('locked')) {
        throw new AccessDeniedException(get_string('cannotextractfileinfoldersubmitted', 'artefact.file'));
    }
}
try {
    $zipinfo = $file->read_archive();
} catch (SystemException $e) {
    $message = get_string('invalidarchive', 'artefact.file');
}
if ($zipinfo) {
    $quotaallowed = false;
    if ($file->get('owner')) {
        $quotaallowed = $USER->quota_allowed($zipinfo->totalsize);
    } else {
        if ($file->get('group')) {
            $quotaallowed = group_quota_allowed($file->get('group'), $zipinfo->totalsize);
        } else {
            // no institution quotas yet
            $quotaallowed = true;
        }
    }
    $message = $quotaerror = false;
    if ($quotaallowed) {
        $name = $file->unzip_directory_name();
        $message = get_string('fileswillbeextractedintofolder', 'artefact.file', $name['fullname']);
        $goto = files_page($file);
        if ($parent = $file->get('parent')) {
            $goto .= (strpos($goto, '?') === false ? '?' : '&') . 'folder=' . $parent;
        }
        $form = pieform(array('name' => 'unzip_artefact', 'elements' => array('fileid' => array('type' => 'hidden', 'value' => $fileid), 'submit' => array('type' => 'submitcancel', 'class' => 'btn btn-success', 'value' => array(get_string('Decompress', 'artefact.file'), get_string('cancel')), 'goto' => $goto))));
    } else {
Exemplo n.º 2
0
function group_quota_add($groupid, $bytes)
{
    if (!group_quota_allowed($groupid, $bytes)) {
        throw new QuotaExceededException('Adding ' . $bytes . ' bytes would exceed the group\'s quota');
    }
    if (!($group = get_record('group', 'id', $groupid, 'deleted', 0))) {
        throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
    }
    $newquota = $group->quotaused + $bytes;
    $group = new StdClass();
    $group->id = $groupid;
    $group->quotaused = $newquota;
    update_record('group', $group);
}
Exemplo n.º 3
0
 /**
  * Processes a newly uploaded file, copies it to disk, and creates
  * a new artefact object.
  * Takes the name of a file input.
  * Returns false for no errors, or a string describing the error.
  */
 public static function save_uploaded_file($inputname, $data, $inputindex = null, $resized = false)
 {
     require_once 'uploadmanager.php';
     $um = new upload_manager($inputname, false, $inputindex);
     if ($error = $um->preprocess_file()) {
         throw new UploadException($error);
     }
     if (isset($inputindex)) {
         if ($resized) {
             $um->file['size'][$inputindex] = filesize($um->file['tmp_name'][$inputindex]);
         }
         $size = $um->file['size'][$inputindex];
         $tmpname = $um->file['tmp_name'][$inputindex];
         $filetype = $um->file['type'][$inputindex];
     } else {
         if ($resized) {
             $um->file['size'] = filesize($um->file['tmp_name']);
         }
         $size = $um->file['size'];
         $tmpname = $um->file['tmp_name'];
         $filetype = $um->file['type'];
     }
     if (!empty($data->owner)) {
         global $USER;
         if ($data->owner == $USER->get('id')) {
             $owner = $USER;
             $owner->quota_refresh();
         } else {
             $owner = new User();
             $owner->find_by_id($data->owner);
         }
         if (!$owner->quota_allowed($size)) {
             throw new QuotaExceededException(get_string('uploadexceedsquota', 'artefact.file'));
         }
     }
     if (!empty($data->group)) {
         require_once 'group.php';
         if (!group_quota_allowed($data->group, $size)) {
             throw new QuotaExceededException(get_string('uploadexceedsquotagroup', 'artefact.file'));
         }
     }
     $data->size = $size;
     $data->filetype = $filetype;
     $data->oldextension = $um->original_filename_extension();
     $f = self::new_file($tmpname, $data);
     $f->commit();
     $id = $f->get('id');
     // Save the file using its id as the filename, and use its id modulo
     // the number of subdirectories as the directory name.
     if ($error = $um->save_file(self::get_file_directory($id), $id)) {
         $f->delete();
         throw new UploadException($error);
     } else {
         if (isset($owner)) {
             $owner->quota_add($size);
             $owner->commit();
         } else {
             if (!empty($data->group)) {
                 group_quota_add($data->group, $size);
             }
         }
     }
     return $id;
 }