0

On the current page I already have button, which enrols me in a course, now I want to add such button to download the summary of the course in pdf. The current button looks like this:

.= html_writer::div(html_writer::tag("button", get_string('enrol', 'local_customenrol'), array('class' => 'ebutton')), 'enrol');

I added the Download in PDF button like this:

.= html_writer::div(html_writer::tag("button", get_string('printpdf', 'local_customenrol'), array('class' => 'printpdf')), 'printpdf');

The enrol button works with javascript in local_customenrol.js, the printing of the page summary is made in printpdf.php, I just can not make it to trigger the download. I preffer to make it in php, if possible, or should I use javascript?

freudsfreund
  • 143
  • 2
  • 20

1 Answers1

0

I've found that to print links to course summary files you have to do something like this:

$course = get_course($courseid);
$url = '';
foreach ($course->get_course_overviewfiles() as $file) {
    $url = file_encode_url($CFG->wwwroot.'/pluginfile.php',
                           '/'.$file->get_contextid().'/'.
                           $file->get_component().'/'.
                           $file->get_filearea().
                           $file->get_filepath().
                           $file->get_filename(), !$isimage); 
    echo html_writer::link($url, 'Download course file', array('class' => 'btn btn-secondary span3'));
}

With this you will print a link for each file attached to an existing course and will not need to render the PDF using php.