1<?php 2/** 3 * Copyright 2001-2017 Horde LLC (http://www.horde.org/) 4 * 5 * See the enclosed file LICENSE for license information (ASL). If you 6 * did not receive this file, see http://www.horde.org/licenses/apache. 7 * 8 * @package Mnemo 9 */ 10require_once __DIR__ . '/../lib/Application.php'; 11Horde_Registry::appInit('mnemo'); 12 13/* Check if a passphrase has been sent. */ 14$passphrase = Horde_Util::getFormData('memo_passphrase'); 15 16/* We can either have a UID or a memo id and a notepad. Check for UID 17 * first. */ 18if ($uid = Horde_Util::getFormData('uid')) { 19 $storage = $GLOBALS['injector']->getInstance('Mnemo_Factory_Driver')->create(); 20 try { 21 $note = $storage->getByUID($uid, $passphrase); 22 } catch (Mnemo_Exception $e) { 23 Horde::url('list.php', true)->redirect(); 24 } 25 $note_id = $note['memo_id']; 26 $notelist_id = $note['memolist_id']; 27} else { 28 /* If we aren't provided with a memo and memolist, redirect to 29 * list.php. */ 30 $note_id = Horde_Util::getFormData('note'); 31 $notelist_id = Horde_Util::getFormData('notepad'); 32 if (!isset($note_id) || !$notelist_id) { 33 Horde::url('list.php', true)->redirect(); 34 } 35 36 /* Get the current memo. */ 37 $note = Mnemo::getMemo($notelist_id, $note_id, $passphrase); 38} 39try { 40 $share = $GLOBALS['mnemo_shares']->getShare($notelist_id); 41} catch (Horde_Share_Exception $e) { 42 $notification->push(sprintf(_("There was an error viewing this notepad: %s"), $e->getMessage()), 'horde.error'); 43 Horde::url('list.php', true)->redirect(); 44} 45if (!$share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ)) { 46 $notification->push(_("You do not have permission to view this notepad."), 'horde.error'); 47 Horde::url('list.php', true)->redirect(); 48} 49 50/* If the requested note doesn't exist, display an error message. */ 51if (!$note || !isset($note['memo_id'])) { 52 $notification->push(_("Note not found."), 'horde.error'); 53 Horde::url('list.php', true)->redirect(); 54} 55 56/* Let's assume that the note content can be converted to ISO-8859-1 if this 57 * is the current language's charset, as long as we don't have UTF-8 support 58 * in Horde_Pdf. */ 59if ($GLOBALS['registry']->getLanguageCharset() == 'ISO-8859-1') { 60 $note = Horde_String::convertCharset($note, 'UTF-8', 'ISO-8859-1'); 61} 62 63/* Set up the PDF object. */ 64$pdf = new Horde_Pdf_Writer(array('format' => 'Letter', 'unit' => 'pt')); 65$pdf->setMargins(50, 50); 66 67/* Enable automatic page breaks. */ 68$pdf->setAutoPageBreak(true, 50); 69 70/* Start the document. */ 71$pdf->open(); 72 73/* Start a page. */ 74$pdf->addPage(); 75 76/* Write the header in Times 24 Bold. */ 77$pdf->setFont('Times', 'B', 24); 78$pdf->multiCell(0, 24, $note['desc'], 'B', 1); 79$pdf->newLine(20); 80 81/* Write the note body in Times 14. */ 82$pdf->setFont('Times', '', 14); 83$pdf->write(14, $note['body']); 84 85/* Output the generated PDF. */ 86$browser->downloadHeaders($note['desc'] . '.pdf', 'application/pdf'); 87echo $pdf->getOutput(); 88