} // Get an optional format $format = optional_param('format', '', PARAM_ALPHA); if ($format == 'csv') { // Log report action if (version_compare($version, '2.7') < 0) { add_to_log($course->id, 'elang', 'view report', 'mod/elang/view.php?id=' . $cm->id . '&format=csv', 'csv', $cm->id, $USER->id); } else { // Log this request. $params = array('context' => $context, 'courseid' => $course->id, 'other' => array('action' => 'csv')); $event = \mod_elang\event\report_viewed::create($params); $event->trigger(); } // Set the http header for csv file header('Content-type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename="' . Elang\generateTitle($elang, json_decode($elang->options, true)) . ' ' . date('Y-m-d H:i:s') . '.csv"'); $handle = fopen('php://output', 'w'); // Prepare first row $data = array(); $data[] = get_string('csvfirstname', 'elang'); $data[] = get_string('csvlastname', 'elang'); $data[] = get_string('csvemail', 'elang'); foreach ($solutions as $solution) { foreach ($solution->json as $input) { $data[] = $solution->number; } } // Write header fputcsv($handle, $data); // Get the group id $id_group = optional_param('id_group', 0, PARAM_INT);
// Verify access right require_capability('mod/elang:view', $context); // Add a view log if (version_compare($version, '2.7') < 0) { add_to_log($course->id, 'elang', 'view', 'view.php?id=' . $cm->id, $elang->id, $cm->id); } else { // Log this request. $params = array('objectid' => $cm->id, 'context' => $context); $event = \mod_elang\event\course_module_viewed::create($params); $event->add_record_snapshot('elang', $elang); $event->trigger(); } // Get the options for the exercise $options = json_decode($elang->options, true); // Get the page title $title = Elang\generateTitle($elang, $options); // Get the module general settings $config = get_config('elang'); ?> <!DOCTYPE html> <html<?php echo get_html_lang(); ?> > <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <title><?php echo format_string($title);
/** * Serves the files from the elang file areas * * @param stdClass $course the course object * @param stdClass $cm the course module object * @param stdClass $context the elang's context * @param string $filearea the name of the file area * @param array $args extra arguments (itemid, path) * @param boolean $forcedownload whether or not force download * @param array $options additional options affecting the file serving * * @return void * * @category files * * @since 0.0.1 */ function elang_pluginfile($course, $cm, $context, $filearea, array $args, $forcedownload, array $options = array()) { global $DB, $CFG, $USER; require_once dirname(__FILE__) . '/locallib.php'; if ($context->contextlevel != CONTEXT_MODULE) { send_file_not_found(); } require_login($course, true, $cm); if (!has_capability('mod/elang:view', $context)) { send_file_not_found(); } if ($filearea == 'subtitle') { $vtt = new \Captioning\Format\WebvttFile(); $idlang = $cm->instance; $records = $DB->get_records('elang_cues', array('id_elang' => $idlang), 'begin ASC'); $elang = $DB->get_record('elang', array('id' => $idlang)); $options = json_decode($elang->options, true); $repeatedunderscore = isset($options['repeatedunderscore']) ? $options['repeatedunderscore'] : 10; $i = 0; $users = $DB->get_records('elang_users', array('id_elang' => $idlang, 'id_user' => $USER->id), '', 'id_cue,json'); foreach ($records as $id => $record) { if (isset($users[$id])) { $data = json_decode($users[$id]->json, true); } else { $data = array(); } $cue = new \Captioning\Format\WebvttCue(\Captioning\Format\WebvttCue::ms2tc($record->begin), \Captioning\Format\WebvttCue::ms2tc($record->end), Elang\generateCueText(json_decode($record->json, true), $data, '-', $repeatedunderscore)); $i++; $cue->setIdentifier($i); $vtt->addCue($cue); } send_file($vtt->build()->getFileContent(), end($args), 0, 0, true, false, 'text/vtt'); } elseif ($filearea == 'pdf') { $idlang = $cm->instance; $records = $DB->get_records('elang_cues', array('id_elang' => $idlang), 'begin ASC'); $elang = $DB->get_record('elang', array('id' => $idlang)); $options = json_decode($elang->options, true); $repeatedunderscore = isset($options['repeatedunderscore']) ? $options['repeatedunderscore'] : 10; require_once $CFG->libdir . '/pdflib.php'; $doc = new pdf(); $doc->SetMargins(isset($options['left']) ? $options['left'] : 20, isset($options['top']) ? $options['top'] : 20); $doc->SetFont('', '', isset($options['size']) ? $options['size'] : 16); $doc->setPrintHeader(false); $doc->setPrintFooter(false); $doc->AddPage(); $doc->WriteHtml('<h1>' . sprintf(get_string('pdftitle', 'elang'), $course->fullname) . '</h1>'); $doc->WriteHtml('<h2>' . sprintf(get_string('pdfsubtitle', 'elang'), Elang\generateTitle($elang, $options), userdate($elang->timecreated, get_string('strftimedaydate'))) . '</h2>'); $doc->WriteHtml($elang->intro); $i = 1; foreach ($records as $id => $record) { $doc->Write(5, '', '', false, '', true); $doc->WriteHtml('<h3>' . sprintf(get_string('pdfcue', 'elang'), $i++, \Captioning\Format\WebvttCue::ms2tc($record->begin), \Captioning\Format\WebvttCue::ms2tc($record->end)) . '</h3>'); $doc->Write(5, Elang\generateCueText(json_decode($record->json, true), array(), '_', $repeatedunderscore), '', false, '', true); } send_file($doc->Output('', 'S'), end($args), 0, 0, true, false, 'application/pdf'); } else { $fs = get_file_storage(); $relativepath = implode('/', $args); $fullpath = rtrim('/' . $context->id . '/mod_elang/' . $filearea . '/0/' . $relativepath, '/'); $file = $fs->get_file_by_hash(sha1($fullpath)); if (!$file) { send_file_not_found(); } send_stored_file($file, 86400, 0, $forcedownload, $options); } }