MDL-65470 pix: update Moodle logo
[moodle.git] / lib / tests / other / pdflibtestpage.php
CommitLineData
0a39261b 1<?php
0a39261b 2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
b38d2ce7 18 * Produces a sample PDF using lib/pdflib.php
0a39261b 19 *
b38d2ce7 20 * @package core
685dc443 21 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
b412f9c4 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
0a39261b 23 */
24
1fcf0ca8 25require(__DIR__ . '/../../../config.php');
0a39261b 26require_once($CFG->libdir . '/pdflib.php');
27
28require_login();
b0c6dc1c 29$context = context_system::instance();
b38d2ce7 30require_capability('moodle/site:config', $context);
0a39261b 31
32$getpdf = optional_param('getpdf', 0, PARAM_INT);
64d11846
PS
33$fontfamily = optional_param('fontfamily', PDF_FONT_NAME_MAIN, PARAM_ALPHA); // to be configurable
34
35if (!$fontfamily) {
36 $fontfamily = PDF_FONT_NAME_MAIN;
37}
0a39261b 38
39/**
40 * Extend the standard PDF class to get access to some protected values we want to display
41 * at the test page.
42 *
43 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
44 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45 */
0a39261b 46if ($getpdf) {
64d11846 47 $doc = new pdf();
0a39261b 48
49 $doc->SetTitle('Moodle PDF library test');
50 $doc->SetAuthor('Moodle ' . $CFG->release);
b38d2ce7 51 $doc->SetCreator('lib/tests/other/pdflibtestpage.php');
0a39261b 52 $doc->SetKeywords('Moodle, PDF');
53 $doc->SetSubject('This has been generated by Moodle as its PDF library test page');
54 $doc->SetMargins(15, 30);
55
56 $doc->setPrintHeader(true);
57 $doc->setHeaderMargin(10);
58 $doc->setHeaderFont(array($fontfamily, 'b', 10));
4df2aeba 59 $doc->setHeaderData('pix/moodlelogo.png', 40, $SITE->fullname, $CFG->wwwroot);
0a39261b 60
61 $doc->setPrintFooter(true);
62 $doc->setFooterMargin(10);
63 $doc->setFooterFont(array($fontfamily, '', 8));
64
65 $doc->AddPage();
66
67 $doc->SetTextColor(255,255,255);
68 $doc->SetFillColor(255,203,68);
69 $doc->SetFont($fontfamily, 'B', 24);
70 $doc->Cell(0, 0, 'Moodle PDF library test', 0, 1, 'C', 1);
71
72 $doc->SetFont($fontfamily, '', 12);
73 $doc->Ln(6);
74 $doc->SetTextColor(0,0,0);
75
76 $c = '<h3>General information</h3>';
77 $c .= 'Moodle release: ' . $CFG->release . '<br />';
136d9a47 78 $c .= 'PDF producer: TCPDF ' . TCPDF_STATIC::getTCPDFVersion() . ' (http://www.tcpdf.org) <br />';
64d11846 79 $c .= 'Font family used: ' . $fontfamily . '<br />';
0a39261b 80
81 $c .= '<h3>Current settings</h3>';
82 $c .= '<table border="1" cellspacing="0" cellpadding="1">';
64d11846 83 foreach (array('K_PATH_MAIN', 'K_PATH_URL', 'K_PATH_FONTS', 'PDF_FONT_NAME_MAIN', 'K_PATH_CACHE', 'K_PATH_IMAGES', 'K_BLANK_IMAGE',
0a39261b 84 'K_CELL_HEIGHT_RATIO', 'K_SMALL_RATIO', 'PDF_CUSTOM_FONT_PATH', 'PDF_DEFAULT_FONT') as $setting) {
85 if (defined($setting)) {
86 $c .= '<tr style="font-size: x-small;"><td>' . $setting . '</td><td>' . constant($setting) . '</td></tr>';
87 }
88 }
0a39261b 89 $c .= '</table><br />';
90
64d11846
PS
91 $c .= '<h3>Available font families</h3>';
92 $fontfamilies = $doc->get_font_families();
93 $list = array();
94 foreach ($fontfamilies as $family => $fonts) {
95 $f = $family;
96 $spacer = '';
97 if ($doc->is_core_font_family($family)) {
98 $f .= '<sup>*</sup>';
99 } else {
100 $spacer = ' ';
101 }
102 if (count($fonts) > 1) {
103 $f .= $spacer . '<i>(' . implode(', ', $fonts) . ')</i>';
104 }
105 $list[] = $f;
106 }
107 $c .= implode($list, ', ');
108 $c .= '<p><i><small>Note: * Standard core fonts are not embedded in PDF files, PDF viewers are using local fonts.</small></i></p>';
0a39261b 109
110 $c .= '<h3>Installed languages and their alphabets</h3>';
111 $languages = array();
112 $langdirs = get_list_of_plugins('lang', '', $CFG->dataroot);
d0a0db42 113 array_unshift($langdirs, 'en');
0a39261b 114 foreach ($langdirs as $langdir) {
64d11846 115 $enlangconfig = $CFG->dirroot . '/lang/en/langconfig.php';
d0a0db42 116 if ('en' == $langdir) {
64d11846 117 $langconfig = $enlangconfig;
0a39261b 118 } else {
119 $langconfig = $CFG->dataroot . '/lang/' . $langdir . '/langconfig.php';
120 }
64d11846
PS
121 // Ignore parents here for now.
122 $string = array();
0a39261b 123 if (is_readable($langconfig)) {
124 include($langconfig);
125 if (is_array($string)) {
126 $languages[$langdir] = new stdClass();
127 $languages[$langdir]->langname = isset($string['thislanguage']) ? $string['thislanguage'] : '(unknown)';
64d11846 128 $languages[$langdir]->alphabet = isset($string['alphabet']) ? '"' . $string['alphabet'] . '"': '(no alphabet defined)';
0a39261b 129 }
130 }
131 }
132 $c .= '<dl>';
133 foreach ($languages as $langcode => $language) {
134 $c .= '<dt>' . $language->langname . ' (' . $langcode . ')</dt>';
64d11846 135 $c .= '<dd>' . $language->alphabet . '</dd>';
0a39261b 136 }
137 $c .= '</dl>';
138
139 $doc->writeHTML($c);
140
141 $doc->Output('pdflibtestpage.pdf');
142 exit();
143}
144
b38d2ce7 145$PAGE->set_url('/lib/tests/other/pdflibtestpage.php');
0a39261b 146$PAGE->set_context($context);
147$PAGE->set_title('PDF library test');
148$PAGE->set_heading('PDF library test');
149
150echo $OUTPUT->header();
151echo $OUTPUT->heading('Press the button to generate test PDF', 2);
64d11846 152echo $OUTPUT->continue_button(new moodle_url($PAGE->url, array('getpdf' => 1, 'fontfamily' => PDF_FONT_NAME_MAIN)));
0a39261b 153echo $OUTPUT->footer();