本文整理汇总了PHP中send_temp_file函数的典型用法代码示例。如果您正苦于以下问题:PHP send_temp_file函数的具体用法?PHP send_temp_file怎么用?PHP send_temp_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_temp_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: local_mail_downloadall
function local_mail_downloadall($message) {
$attachments = local_mail_attachments($message);
if (count($attachments) > 1) {
foreach ($attachments as $attach) {
$filename = clean_filename($attach->get_filename());
$filesforzipping[$filename] = $attach;
}
$filename = clean_filename(fullname($message->sender()) . '-' .
$message->subject() . '.zip');
if ($zipfile = pack_files($filesforzipping)) {
send_temp_file($zipfile, $filename);
}
}
}
示例2: download_submissions
/**
* creates a zip of all assignment submissions and sends a zip to the browser
*/
public function download_submissions() {
global $CFG,$DB;
require_once($CFG->libdir.'/filelib.php');
$submissions = $this->get_submissions('','');
if (empty($submissions)) {
print_error('errornosubmissions', 'assignment', new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id)));
}
$filesforzipping = array();
$fs = get_file_storage();
$groupmode = groups_get_activity_groupmode($this->cm);
$groupid = 0; // All users
$groupname = '';
if ($groupmode) {
$groupid = groups_get_activity_group($this->cm, true);
$groupname = groups_get_group_name($groupid).'-';
}
$filename = str_replace(' ', '_', clean_filename($this->course->shortname.'-'.$this->assignment->name.'-'.$groupname.$this->assignment->id.".zip")); //name of new zip file.
foreach ($submissions as $submission) {
// If assignment is open and submission is not finalized then don't add it to zip.
$submissionstatus = $this->is_finalized($submission);
if ($this->isopen() && empty($submissionstatus)) {
continue;
}
$a_userid = $submission->userid; //get userid
if ((groups_is_member($groupid,$a_userid)or !$groupmode or !$groupid)) {
$a_assignid = $submission->assignment; //get name of this assignment for use in the file names.
$a_user = $DB->get_record("user", array("id"=>$a_userid),'id,username,firstname,lastname'); //get user firstname/lastname
$files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false);
foreach ($files as $file) {
//get files new name.
$fileext = strstr($file->get_filename(), '.');
$fileoriginal = str_replace($fileext, '', $file->get_filename());
$fileforzipname = clean_filename(fullname($a_user) . "_" . $fileoriginal."_".$a_userid.$fileext);
//save file name to array for zipping.
$filesforzipping[$fileforzipname] = $file;
}
}
} // end of foreach loop
// Throw error if no files are added.
if (empty($filesforzipping)) {
print_error('errornosubmissions', 'assignment', new moodle_url('/mod/assignment/submissions.php', array('id'=>$this->cm->id)));
}
if ($zipfile = assignment_pack_files($filesforzipping)) {
send_temp_file($zipfile, $filename); //send file and delete after sending.
}
}
示例3: print_grades
/**
* To be implemented by child classes
* @param boolean $feedback
* @param boolean $publish Whether to output directly, or send as a file
* @return string
*/
public function print_grades($feedback = false)
{
global $CFG;
require_once $CFG->libdir . '/filelib.php';
$export_tracking = $this->track_exports();
$strgrades = get_string('grades');
/// Calculate file name
$shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("{$shortname} {$strgrades}.xml");
make_temp_directory('gradeexport');
$tempfilename = $CFG->tempdir . '/gradeexport/' . md5(sesskey() . microtime() . $downloadfilename);
if (!($handle = fopen($tempfilename, 'w+b'))) {
print_error('cannotcreatetempdir');
}
/// time stamp to ensure uniqueness of batch export
fwrite($handle, '<results batch="xml_export_' . time() . '">' . "\n");
$export_buffer = array();
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->init();
while ($userdata = $gui->next_user()) {
$user = $userdata->user;
if (empty($user->idnumber)) {
//id number must exist otherwise we cant match up students when importing
continue;
}
// studentgrades[] index should match with corresponding $index
foreach ($userdata->grades as $itemid => $grade) {
$grade_item = $this->grade_items[$itemid];
$grade->grade_item =& $grade_item;
$gradestr = $this->format_grade($grade, $this->displaytype);
// no formating for now
// MDL-11669, skip exported grades or bad grades (if setting says so)
if ($export_tracking) {
$status = $geub->track($grade);
if ($this->updatedgradesonly && ($status == 'nochange' || $status == 'unknown')) {
continue;
}
}
fwrite($handle, "\t<result>\n");
if ($export_tracking) {
fwrite($handle, "\t\t<state>{$status}</state>\n");
}
// only need id number
fwrite($handle, "\t\t<assignment>{$grade_item->idnumber}</assignment>\n");
// this column should be customizable to use either student id, idnumber, uesrname or email.
fwrite($handle, "\t\t<student>{$user->idnumber}</student>\n");
fwrite($handle, "\t\t<score>{$gradestr}</score>\n");
if ($this->export_feedback) {
$feedbackstr = $this->format_feedback($userdata->feedbacks[$itemid]);
fwrite($handle, "\t\t<feedback>{$feedbackstr}</feedback>\n");
}
fwrite($handle, "\t</result>\n");
}
}
fwrite($handle, "</results>");
fclose($handle);
$gui->close();
$geub->close();
if (defined('BEHAT_SITE_RUNNING')) {
// If behat is running, we cannot test the output if we force a file download.
include $tempfilename;
} else {
@header("Content-type: text/xml; charset=UTF-8");
send_temp_file($tempfilename, $downloadfilename, false);
}
}
示例4: download_items
/**
* @param $list array List of item id's to download. Empty array means all files.
* @return void
*/
public function download_items(array $list = array())
{
global $CFG, $DB;
// More efficient to load this here.
require_once $CFG->libdir . '/filelib.php';
$filesforzipping = array();
$fs = get_file_storage();
$filename = clean_filename('mediagallery-export-' . $this->record->name . '.zip');
$files = $fs->get_area_files($this->get_collection()->context->id, 'mod_mediagallery', 'item', false, 'id', false);
$items = $this->get_items();
$keyed = array_flip($list);
foreach ($files as $file) {
$selected = isset($keyed[$file->get_itemid()]) || empty($list);
if ($selected && isset($items[$file->get_itemid()])) {
$filesforzipping[$file->get_filename()] = $file;
}
}
if (empty($filesforzipping)) {
return;
}
$tempzip = tempnam($CFG->tempdir . '/', 'mediagallery_');
$zipper = new \zip_packer();
$zipper->archive_to_pathname($filesforzipping, $tempzip);
// Send file and delete after sending.
send_temp_file($tempzip, $filename);
}
示例5: view_bulk_certificates
//.........这里部分代码省略.........
echo $OUTPUT->render($select);
echo '<br>';
echo '<form id="bulkissue" name="bulkissue" method="post" action="view.php">';
echo html_writer::label(get_string('bulkaction', 'simplecertificate'), 'menutype', true);
echo ' ';
$selectoptions = array('pdf' => get_string('onepdf', 'simplecertificate'), 'zip' => get_string('multipdf', 'simplecertificate'), 'email' => get_string('sendtoemail', 'simplecertificate'));
echo html_writer::select($selectoptions, 'type', 'pdf');
$table = new html_table();
$table->width = "95%";
$table->tablealign = "center";
//strgrade
$table->head = array(' ', get_string('fullname'), get_string('grade'));
$table->align = array("left", "left", "center");
$table->size = array('1%', '89%', '10%');
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
$chkbox = html_writer::checkbox('selectedusers[]', $user->id, false);
$name = $OUTPUT->user_picture($user) . fullname($user);
$table->data[] = array($chkbox, $name, $this->get_grade($user->id));
}
}
$downloadbutton = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download')), get_string('bulkbuttonlabel', 'simplecertificate'));
echo $OUTPUT->paging_bar($usercount, $page, $perpage, $url);
echo '<br />';
echo html_writer::table($table);
echo html_writer::tag('div', $downloadbutton, array('style' => 'text-align: center'));
echo '</form>';
} else {
if ($action == 'download') {
$type = $url->get_param('type');
// Calculate file name
$filename = str_replace(' ', '_', clean_filename($this->get_instance()->coursename . ' ' . get_string('modulenameplural', 'simplecertificate') . ' ' . strip_tags(format_string($this->get_instance()->name, true)) . '.' . strip_tags(format_string($type, true))));
switch ($type) {
//One pdf with all certificates
case 'pdf':
$pdf = $this->create_pdf_object();
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
//To one pdf file
$issuecert = $this->get_issue($user);
$this->create_pdf($issuecert, $pdf, true);
//Save certificate PDF
if (!$this->issue_file_exists($issuecert)) {
//To force file creation
$issuecert->haschage = true;
$this->get_issue_file($issuecert);
}
}
}
$pdf->Output($filename, 'D');
break;
//One zip with all certificates in separated files
//One zip with all certificates in separated files
case 'zip':
$filesforzipping = array();
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
$issuecert = $this->get_issue($user);
if ($file = $this->get_issue_file($issuecert)) {
$fileforzipname = $file->get_filename();
$filesforzipping[$fileforzipname] = $file;
} else {
error_log(get_string('filenotfound', 'simplecertificate'));
print_error(get_string('filenotfound', 'simplecertificate'));
}
}
}
$tempzip = $this->create_temp_file('issuedcertificate_');
//zipping files
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filesforzipping, $tempzip)) {
//send file and delete after sending.
send_temp_file($tempzip, $filename);
}
break;
case 'email':
foreach ($users as $user) {
$canissue = $this->can_issue($user, $issuelist != 'allusers');
if (empty($canissue)) {
$issuecert = $this->get_issue($user);
if ($this->get_issue_file($issuecert)) {
$this->send_certificade_email($issuecert);
} else {
error_log(get_string('filenotfound', 'simplecertificate'));
print_error('filenotfound', 'simplecertificate');
}
}
}
$url->remove_params('action', 'type');
redirect($url, get_string('emailsent', 'simplecertificate'), 5);
break;
}
exit;
}
}
echo $OUTPUT->footer();
}
示例6: badges_download
/**
* Download all user badges in zip archive.
*
* @param int $userid ID of badge owner.
*/
function badges_download($userid)
{
global $CFG, $DB;
$context = context_user::instance($userid);
$records = $DB->get_records('badge_issued', array('userid' => $userid));
// Get list of files to download.
$fs = get_file_storage();
$filelist = array();
foreach ($records as $issued) {
$badge = new badge($issued->badgeid);
// Need to make image name user-readable and unique using filename safe characters.
$name = $badge->name . ' ' . userdate($issued->dateissued, '%d %b %Y') . ' ' . hash('crc32', $badge->id);
$name = str_replace(' ', '_', $name);
if ($file = $fs->get_file($context->id, 'badges', 'userbadge', $issued->badgeid, '/', $issued->uniquehash . '.png')) {
$filelist[$name . '.png'] = $file;
}
}
// Zip files and sent them to a user.
$tempzip = tempnam($CFG->tempdir . '/', 'mybadges');
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filelist, $tempzip)) {
send_temp_file($tempzip, 'badges.zip');
} else {
debugging("Problems with archiving the files.", DEBUG_DEVELOPER);
die;
}
}
示例7: dirname
<?php
// $Id$
require_once dirname(__FILE__) . '/../config.php';
require_once $CFG->libdir . '/filelib.php';
// Note: file.php always calls require_login() with $setwantsurltome=false
// in order to avoid messing redirects. MDL-14495
require_login(0, true, null, false);
$relativepath = get_file_argument();
if (!$relativepath) {
print_error('invalidarg', 'question');
}
$pathname = $CFG->dataroot . '/temp/questionexport/' . $USER->id . '/' . $relativepath;
send_temp_file($pathname, $relativepath);
示例8: download_submissions
/**
* Download a zip file of all assignment submissions
*
* @return void
*/
private function download_submissions() {
global $CFG,$DB;
// More efficient to load this here.
require_once($CFG->libdir.'/filelib.php');
// Load all users with submit.
$students = get_enrolled_users($this->context, "mod/assign:submit");
// Build a list of files to zip.
$filesforzipping = array();
$fs = get_file_storage();
$groupmode = groups_get_activity_groupmode($this->get_course_module());
// All users.
$groupid = 0;
$groupname = '';
if ($groupmode) {
$groupid = groups_get_activity_group($this->get_course_module(), true);
$groupname = groups_get_group_name($groupid).'-';
}
// Construct the zip file name.
$filename = clean_filename($this->get_course()->shortname.'-'.
$this->get_instance()->name.'-'.
$groupname.$this->get_course_module()->id.".zip");
// Get all the files for each student.
foreach ($students as $student) {
$userid = $student->id;
if ((groups_is_member($groupid, $userid) or !$groupmode or !$groupid)) {
// Get the plugins to add their own files to the zip.
$submissiongroup = false;
$groupname = '';
if ($this->get_instance()->teamsubmission) {
$submission = $this->get_group_submission($userid, 0, false);
$submissiongroup = $this->get_submission_group($userid);
$groupname = '-' . $submissiongroup->name;
} else {
$submission = $this->get_user_submission($userid, false);
}
if ($this->is_blind_marking()) {
$prefix = clean_filename(str_replace('_', ' ', get_string('participant', 'assign') . $groupname) .
"_" . $this->get_uniqueid_for_user($userid) . "_");
} else {
$prefix = clean_filename(str_replace('_', ' ', fullname($student) . $groupname) .
"_" . $this->get_uniqueid_for_user($userid) . "_");
}
if ($submission) {
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
$pluginfiles = $plugin->get_files($submission);
foreach ($pluginfiles as $zipfilename => $file) {
$subtype = $plugin->get_subtype();
$type = $plugin->get_type();
$prefixedfilename = $prefix . $subtype . '_' . $type . '_' . $zipfilename;
$filesforzipping[$prefixedfilename] = $file;
}
}
}
}
}
}
if ($zipfile = $this->pack_files($filesforzipping)) {
$this->add_to_log('download all submissions', get_string('downloadall', 'assign'));
// Send file and delete after sending.
send_temp_file($zipfile, $filename);
}
}
示例9: block_quickmail_pluginfile
function block_quickmail_pluginfile($course, $record, $context, $filearea, $args, $forcedownload)
{
$fs = get_file_storage();
global $DB;
list($itemid, $filename) = $args;
if ($filearea == 'attachment_log') {
$time = $DB->get_field('block_quickmail_log', 'time', array('id' => $itemid));
if ("{$time}_attachments.zip" == $filename) {
$path = quickmail::zip_attachments($context, 'log', $itemid);
send_temp_file($path, 'attachments.zip');
}
}
$params = array('component' => 'block_quickmail', 'filearea' => $filearea, 'itemid' => $itemid, 'filename' => $filename);
$instanceid = $DB->get_field('files', 'id', $params);
if (empty($instanceid)) {
send_file_not_found();
} else {
$file = $fs->get_file_by_id($instanceid);
send_stored_file($file);
}
}
示例10: get_records
/// Get all the chapters
$chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum');
/// Generate the manifest and all the contents
chapters2imsmanifest($chapters, $book, $cm);
/// Now zip everything
make_upload_directory('temp');
$zipfile = $CFG->dataroot . "/temp/" . time() . '.zip';
$files = get_directory_list($CFG->dataroot . "/{$cm->course}/moddata/book/{$book->id}", basename($zipfile), false, true, true);
foreach ($files as $key => $value) {
$files[$key] = $CFG->dataroot . "/{$cm->course}/moddata/book/{$book->id}/" . $value;
}
zip_files($files, $zipfile);
/// Now delete all the temp dirs
delete_dir_contents($CFG->dataroot . "/{$cm->course}/moddata/book/{$book->id}");
/// Now serve the file
send_temp_file($zipfile, clean_filename($book->name) . '.zip');
/**
* This function will create the default imsmanifest plus contents for the book chapters passed as array
* Everything will be created under the book moddata file area *
*/
function chapters2imsmanifest($chapters, $book, $cm)
{
global $CFG;
/// Init imsmanifest and others
$imsmanifest = '';
$imsitems = '';
$imsresources = '';
/// Moodle and Book version
$moodle_release = $CFG->release;
$moodle_version = $CFG->version;
$book_version = get_field('modules', 'version', 'name', 'book');
示例11: required_param
* @package mod_folder
* @copyright 2015 Andrew Hancox <andrewdchancox@googlemail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once __DIR__ . "/../../config.php";
$id = required_param('id', PARAM_INT);
// Course module ID.
$cm = get_coursemodule_from_id('folder', $id, 0, true, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/folder:view', $context);
$folder = $DB->get_record('folder', array('id' => $cm->instance), '*', MUST_EXIST);
$downloadable = folder_archive_available($folder, $cm);
if (!$downloadable) {
print_error('cannotdownloaddir', 'repository');
}
folder_downloaded($folder, $course, $cm, $context);
$fs = get_file_storage();
$file = $fs->get_file($context->id, 'mod_folder', 'content', 0, '/', '.');
if (!$file) {
print_error('cannotdownloaddir', 'repository');
}
$zipper = get_file_packer('application/zip');
$filename = clean_filename($folder->name . "-" . date("Ymd")) . ".zip";
$temppath = make_request_directory() . $filename;
if ($zipper->archive_to_pathname(array('/' => $file), $temppath)) {
send_temp_file($temppath, $filename);
} else {
print_error('cannotdownloaddir', 'repository');
}
示例12: download_zip
//.........这里部分代码省略.........
{
global $CFG, $DB;
require_once $CFG->libdir . '/filelib.php';
$context = $this->get_context();
$cm = $this->get_coursemodule();
$conditions = array();
$conditions['publication'] = $this->get_instance()->id;
$filesforzipping = array();
$fs = get_file_storage();
$filearea = 'attachment';
// Find out current groups mode.
$groupmode = groups_get_activity_groupmode($this->get_coursemodule());
$currentgroup = groups_get_activity_group($this->get_coursemodule(), true);
// Get group name for filename.
$groupname = '';
// Get all ppl that are allowed to submit assignments.
list($esql, $params) = get_enrolled_sql($context, 'mod/publication:view', $currentgroup);
$showall = false;
if (has_capability('mod/publication:approve', $context) || has_capability('mod/publication:grantextension', $context)) {
$showall = true;
}
if (is_array($users) && count($users) > 0) {
$customusers = " and u.id IN (" . implode($users, ', ') . ") ";
} else {
if ($users == false) {
$customusers = " AND 1=2 ";
}
}
if ($showall) {
$sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'WHERE u.deleted = 0 AND eu.id=u.id ' . $customusers;
} else {
$sql = 'SELECT u.id FROM {user} u ' . 'LEFT JOIN (' . $esql . ') eu ON eu.id=u.id ' . 'LEFT JOIN {publication_file} files ON (u.id = files.userid) ' . 'WHERE u.deleted = 0 AND eu.id=u.id ' . $customusers . 'AND files.publication = ' . $this->get_instance()->id . ' ';
if ($this->get_instance()->mode == PUBLICATION_MODE_UPLOAD) {
// Mode upload.
if ($this->get_instance()->obtainteacherapproval) {
// Need teacher approval.
$where = 'files.teacherapproval = 1';
} else {
// No need for teacher approval.
// Teacher only hasnt rejected.
$where = '(files.teacherapproval = 1 OR files.teacherapproval IS NULL)';
}
} else {
// Mode import.
if (!$this->get_instance()->obtainstudentapproval) {
// No need to ask student and teacher has approved.
$where = 'files.teacherapproval = 1';
} else {
// Student and teacher have approved.
$where = 'files.teacherapproval = 1 AND files.studentapproval = 1';
}
}
$sql .= 'AND ' . $where . ' ';
$sql .= 'GROUP BY u.id';
}
$users = $DB->get_records_sql($sql, $params);
if (!empty($users)) {
$users = array_keys($users);
}
// If groupmembersonly used, remove users who are not in any group.
if ($users and !empty($CFG->enablegroupmembersonly) and $cm->groupmembersonly) {
if ($groupingusers = groups_get_grouping_members($cm->groupingid, 'u.id', 'u.id')) {
$users = array_intersect($users, array_keys($groupingusers));
}
}
$filename = str_replace(' ', '_', clean_filename($this->course->shortname . '-' . $this->get_instance()->name . '-' . $groupname . $this->get_instance()->id . '.zip'));
// Name of new zip file.
$userfields = get_all_user_name_fields();
$userfields['id'] = 'id';
$userfields['username'] = 'username';
$userfields = implode(', ', $userfields);
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->context);
// Get all files from each user.
foreach ($users as $uploader) {
$auserid = $uploader;
$conditions['userid'] = $uploader;
$records = $DB->get_records('publication_file', $conditions);
$aassignid = $auserid;
// Get name of this assignment for use in the file names.
// Get user firstname/lastname.
$auser = $DB->get_record('user', array('id' => $auserid), $userfields);
foreach ($records as $record) {
if (has_capability('mod/publication:approve', $this->get_context()) || $this->has_filepermission($record->fileid)) {
// Is teacher or file is public.
$file = $fs->get_file_by_id($record->fileid);
// Get files new name.
$fileext = strstr($file->get_filename(), '.');
$fileoriginal = str_replace($fileext, '', $file->get_filename());
$fileforzipname = clean_filename(($viewfullnames ? fullname($auser) : '') . '_' . $fileoriginal . '_' . $auserid . $fileext);
// Save file name to array for zipping.
$filesforzipping[$fileforzipname] = $file;
}
}
}
// End of foreach.
if ($zipfile = $this->pack_files($filesforzipping)) {
send_temp_file($zipfile, $filename);
// Send file and delete after sending.
}
}
示例13: watermark_and_sent
function watermark_and_sent(stdClass $issuedcert)
{
global $CFG, $USER, $COURSE, $DB, $PAGE;
if ($issuedcert->haschange) {
//This issue have a haschange flag, try to reissue
if (empty($issuedcert->timedeleted)) {
require_once $CFG->dirroot . '/mod/simplecertificate/locallib.php';
try {
// Try to get cm
$cm = get_coursemodule_from_instance('simplecertificate', $issuedcert->certificateid, 0, false, MUST_EXIST);
$context = context_module::instance($cm->id);
//Must set a page context to issue ....
$PAGE->set_context($context);
$simplecertificate = new simplecertificate($context, null, null);
$file = $simplecertificate->get_issue_file($issuedcert);
} catch (moodle_exception $e) {
// Only debug, no errors
debugging($e->getMessage(), DEBUG_DEVELOPER, $e->getTrace());
}
} else {
//Have haschange and timedeleted, somehting wrong, it will be impossible to reissue
//add wraning
debugging("issued certificate [{$issuedcert->id}], have haschange and timedeleted");
}
$issuedcert->haschange = 0;
$DB->update_record('simplecertificate_issues', $issuedcert);
}
if (empty($file)) {
$fs = get_file_storage();
if (!$fs->file_exists_by_hash($issuedcert->pathnamehash)) {
print_error(get_string('filenotfound', 'simplecertificate', ''));
}
$file = $fs->get_file_by_hash($issuedcert->pathnamehash);
}
$canmanage = false;
if (!empty($COURSE)) {
$canmanage = has_capability('mod/simplecertificate:manage', context_course::instance($COURSE->id));
}
if ($canmanage || !empty($USER) && $USER->id == $issuedcert->userid) {
send_stored_file($file, 0, 0, true);
} else {
require_once $CFG->libdir . '/pdflib.php';
require_once $CFG->dirroot . '/mod/simplecertificate/lib/fpdi/fpdi.php';
// copy to a tmp file
$tmpfile = $file->copy_content_to_temp();
// TCPF doesn't import files yet, so i must use FPDI
$pdf = new FPDI();
$pageCount = $pdf->setSourceFile($tmpfile);
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
// get the size of the imported page
$size = $pdf->getTemplateSize($templateId);
// create a page (landscape or portrait depending on the imported page size)
if ($size['w'] > $size['h']) {
$pdf->AddPage('L', array($size['w'], $size['h']));
// Font size 1/3 Height if it landscape
$fontsize = $size['h'] / 3;
} else {
$pdf->AddPage('P', array($size['w'], $size['h']));
// Font size 1/3 Width if it portrait
$fontsize = $size['w'] / 3;
}
// use the imported page
$pdf->useTemplate($templateId);
// Calculating the rotation angle
$rotAngle = atan($size['h'] / $size['w']) * 180 / pi();
// Find the middle of the page to use as a pivot at rotation.
$mX = $size['w'] / 2;
$mY = $size['h'] / 2;
// Set the transparency of the text to really light
$pdf->SetAlpha(0.25);
$pdf->StartTransform();
$pdf->Rotate($rotAngle, $mX, $mY);
$pdf->SetFont("freesans", "B", $fontsize);
$pdf->SetXY(0, $mY);
$boder_style = array('LTRB' => array('width' => 2, 'dash' => $fontsize / 5, 'cap' => 'round', 'join' => 'round', 'phase' => $fontsize / $mX));
$pdf->Cell($size['w'], $fontsize, get_string('certificatecopy', 'simplecertificate'), $boder_style, 0, 'C', false, '', 4, true, 'C', 'C');
$pdf->StopTransform();
// Reset the transparency to default
$pdf->SetAlpha(1);
}
// Set protection seems not work, so comment
// $pdf->SetProtection(array('print', 'modify', 'print-high'),null, random_string(), '1',null);
// For DEGUG
// $pdf->Output($file->get_filename(), 'I');
// Save and send tmpfiles
$pdf->Output($tmpfile, 'F');
send_temp_file($tmpfile, $file->get_filename());
}
}
示例14: download_submissions
//.........这里部分代码省略.........
}
if ((groups_is_member($groupid, $userid) or !$groupmode or !$groupid)) {
// Get the plugins to add their own files to the zip.
$submissiongroup = false;
$groupname = '';
if ($this->get_instance()->teamsubmission) {
$submission = $this->get_group_submission($userid, 0, false);
$submissiongroup = $this->get_submission_group($userid);
if ($submissiongroup) {
$groupname = $submissiongroup->name . '-';
} else {
$groupname = get_string('defaultteam', 'assign') . '-';
}
} else {
$submission = $this->get_user_submission($userid, false);
}
if ($this->is_blind_marking()) {
$prefix = str_replace('_', ' ', $groupname . get_string('participant', 'assign'));
$prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($userid));
} else {
$prefix = str_replace('_', ' ', $groupname . fullname($student));
$prefix = clean_filename($prefix . '_' . $this->get_uniqueid_for_user($userid));
}
if ($submission) {
$downloadasfolders = get_user_preferences('assign_downloadasfolders', 1);
foreach ($this->submissionplugins as $plugin) {
if ($plugin->is_enabled() && $plugin->is_visible()) {
if ($downloadasfolders) {
// Create a folder for each user for each assignment plugin.
// This is the default behavior for version of Moodle >= 3.1.
$submission->exportfullpath = true;
$pluginfiles = $plugin->get_files($submission, $student);
foreach ($pluginfiles as $zipfilepath => $file) {
$subtype = $plugin->get_subtype();
$type = $plugin->get_type();
$zipfilename = basename($zipfilepath);
$prefixedfilename = clean_filename($prefix .
'_' .
$subtype .
'_' .
$type .
'_');
if ($type == 'file') {
$pathfilename = $prefixedfilename . $file->get_filepath() . $zipfilename;
} else if ($type == 'onlinetext') {
$pathfilename = $prefixedfilename . '/' . $zipfilename;
} else {
$pathfilename = $prefixedfilename . '/' . $zipfilename;
}
$pathfilename = clean_param($pathfilename, PARAM_PATH);
$filesforzipping[$pathfilename] = $file;
}
} else {
// Create a single folder for all users of all assignment plugins.
// This was the default behavior for version of Moodle < 3.1.
$submission->exportfullpath = false;
$pluginfiles = $plugin->get_files($submission, $student);
foreach ($pluginfiles as $zipfilename => $file) {
$subtype = $plugin->get_subtype();
$type = $plugin->get_type();
$prefixedfilename = clean_filename($prefix .
'_' .
$subtype .
'_' .
$type .
'_' .
$zipfilename);
$filesforzipping[$prefixedfilename] = $file;
}
}
}
}
}
}
}
$result = '';
if (count($filesforzipping) == 0) {
$header = new assign_header($this->get_instance(),
$this->get_context(),
'',
$this->get_course_module()->id,
get_string('downloadall', 'assign'));
$result .= $this->get_renderer()->render($header);
$result .= $this->get_renderer()->notification(get_string('nosubmission', 'assign'));
$url = new moodle_url('/mod/assign/view.php', array('id'=>$this->get_course_module()->id,
'action'=>'grading'));
$result .= $this->get_renderer()->continue_button($url);
$result .= $this->view_footer();
} else if ($zipfile = $this->pack_files($filesforzipping)) {
\mod_assign\event\all_submissions_downloaded::create_from_assign($this)->trigger();
// Send file and delete after sending.
send_temp_file($zipfile, $filename);
// We will not get here - send_temp_file calls exit.
}
return $result;
}
示例15: get_string
if (0 === strpos($filename, 'form-')) {
$path = get_string('questionforms', 'offlinequiz');
} else {
if (0 === strpos($filename, 'answer-')) {
$path = get_string('answerforms', 'offlinequiz');
} else {
$path = get_string('correctionforms', 'offlinequiz');
}
}
$path = clean_filename($path);
$filelist[$path . '/' . $filename] = $file;
}
}
$zipper = new zip_packer();
if ($zipper->archive_to_pathname($filelist, $tempzip)) {
send_temp_file($tempzip, $zipfilename);
}
}
// Print the page header.
echo $OUTPUT->header();
// Print the offlinequiz name heading and tabs for teacher.
$currenttab = 'createofflinequiz';
require 'tabs.php';
$hasscannedpages = offlinequiz_has_scanned_pages($offlinequiz->id);
if ($offlinequiz->grade == 0) {
echo '<div class="linkbox"><strong>';
echo $OUTPUT->notification(get_string('gradeiszero', 'offlinequiz'), 'notifyproblem');
echo '</strong></div>';
}
// Preview.
if ($mode == 'preview') {