weekly release 2.8dev
[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
b38d2ce7 25require(dirname(__FILE__) . '/../../../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);
65b6adb1 33$fontfamily = optional_param('fontfamily', PDF_DEFAULT_FONT, PARAM_ALPHA); // to be configurable
0a39261b 34
35/**
36 * Extend the standard PDF class to get access to some protected values we want to display
37 * at the test page.
38 *
39 * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 */
42class testable_pdf extends pdf {
43 public function returnFontsList() {
44 return $this->fontlist;
45 }
46 public function _getfontpath() {
47 return parent::_getfontpath();
48 }
49}
50
51if ($getpdf) {
52 $doc = new testable_pdf();
53
54 $doc->SetTitle('Moodle PDF library test');
55 $doc->SetAuthor('Moodle ' . $CFG->release);
b38d2ce7 56 $doc->SetCreator('lib/tests/other/pdflibtestpage.php');
0a39261b 57 $doc->SetKeywords('Moodle, PDF');
58 $doc->SetSubject('This has been generated by Moodle as its PDF library test page');
59 $doc->SetMargins(15, 30);
60
61 $doc->setPrintHeader(true);
62 $doc->setHeaderMargin(10);
63 $doc->setHeaderFont(array($fontfamily, 'b', 10));
970c4419 64 $doc->setHeaderData('pix/moodlelogo-med.png', 40, $SITE->fullname, $CFG->wwwroot);
0a39261b 65
66 $doc->setPrintFooter(true);
67 $doc->setFooterMargin(10);
68 $doc->setFooterFont(array($fontfamily, '', 8));
69
70 $doc->AddPage();
71
72 $doc->SetTextColor(255,255,255);
73 $doc->SetFillColor(255,203,68);
74 $doc->SetFont($fontfamily, 'B', 24);
75 $doc->Cell(0, 0, 'Moodle PDF library test', 0, 1, 'C', 1);
76
77 $doc->SetFont($fontfamily, '', 12);
78 $doc->Ln(6);
79 $doc->SetTextColor(0,0,0);
80
81 $c = '<h3>General information</h3>';
82 $c .= 'Moodle release: ' . $CFG->release . '<br />';
136d9a47 83 $c .= 'PDF producer: TCPDF ' . TCPDF_STATIC::getTCPDFVersion() . ' (http://www.tcpdf.org) <br />';
0a39261b 84 $c .= 'Font of this test page: ' . $fontfamily . '<br />';
85
86 $c .= '<h3>Current settings</h3>';
87 $c .= '<table border="1" cellspacing="0" cellpadding="1">';
88 foreach (array('K_PATH_MAIN', 'K_PATH_URL', 'K_PATH_FONTS', 'K_PATH_CACHE', 'K_PATH_IMAGES', 'K_BLANK_IMAGE',
89 'K_CELL_HEIGHT_RATIO', 'K_SMALL_RATIO', 'PDF_CUSTOM_FONT_PATH', 'PDF_DEFAULT_FONT') as $setting) {
90 if (defined($setting)) {
91 $c .= '<tr style="font-size: x-small;"><td>' . $setting . '</td><td>' . constant($setting) . '</td></tr>';
92 }
93 }
94 $c .= '<tr style="font-size: x-small;"><td>Effective font path</td><td>' . $doc->_getfontpath() . '</td></tr>';
95 $c .= '</table><br />';
96
97 $c .= '<h3>Available font files</h3>';
98 $fontfiles = $doc->returnFontsList();
99 sort($fontfiles);
100 $c .= implode(', ', $fontfiles);
101 $c .= '<br />';
102
103 $c .= '<h3>Installed languages and their alphabets</h3>';
104 $languages = array();
105 $langdirs = get_list_of_plugins('lang', '', $CFG->dataroot);
d0a0db42 106 array_unshift($langdirs, 'en');
0a39261b 107 foreach ($langdirs as $langdir) {
d0a0db42
PS
108 if ('en' == $langdir) {
109 $langconfig = $CFG->dirroot . '/lang/en/langconfig.php';
0a39261b 110 } else {
111 $langconfig = $CFG->dataroot . '/lang/' . $langdir . '/langconfig.php';
112 }
113 if (is_readable($langconfig)) {
114 include($langconfig);
115 if (is_array($string)) {
116 $languages[$langdir] = new stdClass();
117 $languages[$langdir]->langname = isset($string['thislanguage']) ? $string['thislanguage'] : '(unknown)';
118 $languages[$langdir]->alphabet = isset($string['alphabet']) ? $string['alphabet'] : '(no alphabet defined)';
119 }
120 }
121 }
122 $c .= '<dl>';
123 foreach ($languages as $langcode => $language) {
124 $c .= '<dt>' . $language->langname . ' (' . $langcode . ')</dt>';
d0a0db42 125 $c .= '<dd>"' . $language->alphabet . '"</dd>';
0a39261b 126 }
127 $c .= '</dl>';
128
129 $doc->writeHTML($c);
130
131 $doc->Output('pdflibtestpage.pdf');
132 exit();
133}
134
b38d2ce7 135$PAGE->set_url('/lib/tests/other/pdflibtestpage.php');
0a39261b 136$PAGE->set_context($context);
137$PAGE->set_title('PDF library test');
138$PAGE->set_heading('PDF library test');
139
140echo $OUTPUT->header();
141echo $OUTPUT->heading('Press the button to generate test PDF', 2);
eb788065 142echo $OUTPUT->continue_button(new moodle_url($PAGE->url, array('getpdf' => 1)));
0a39261b 143echo $OUTPUT->footer();