Move print generation to separate script.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 1 Feb 2010 19:35:25 +0000 (12:35 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 20:07:40 +0000 (13:07 -0700)
For non-Mozilla browsers, use frames to separate headers from message
data.
Only show print links for parts that can be displayed in a 'full' render.
Re-add support for 'add_printedby' config option.

imp/config/conf.xml
imp/js/imp.js
imp/lib/Contents.php
imp/print.php [new file with mode: 0644]
imp/templates/print/headers.html [new file with mode: 0644]
imp/templates/print/print.html [new file with mode: 0644]

index 17d1a3d..a0ca9e3 100644 (file)
   </configsection>
  </configtab>
 
+ <configsection name="print">
+  <configheader>Print Options</configheader>
+  <configboolean name="add_printedby" desc="Should we add a &quot;Printed
+  By&quot; header to the top of all printed messages?">false</configboolean>
+ </configsection>
+
  <configtab name="compose" desc="Compose">
   <configsection name="msg">
    <configboolean name="prepend_header" desc="Should we include the contents of
index 5c968d1..267886d 100644 (file)
@@ -112,6 +112,11 @@ document.observe('dom:loaded', function() {
 
     IMP.printWindow = function(win)
     {
+        /* Prototypejs not available in this window. */
+        var fs = win.document.getElementById('frameset');
+        if (fs) {
+            fs.rows = (win.document.getElementById('headers').contentWindow.document.getElementById('headerblock').offsetHeight + 5) + 'px,*';
+        }
         win.print();
         win.close();
     };
index b8b21bc..f9b3f92 100644 (file)
@@ -701,8 +701,9 @@ class IMP_Contents
         }
 
         /* Add print link? */
-        if ($mask && self::SUMMARY_PRINT) {
-            $part['print'] = $this->linkViewJS($mime_part, 'view_attach', '', array('css' => 'printAtc', 'onload' => 'IMP.printWindow', 'jstext' => _("Print"), 'params' => $param_array));
+        if (($mask && self::SUMMARY_PRINT) &&
+            $this->canDisplay($id, self::RENDER_FULL)) {
+            $part['print'] = $this->linkViewJS($mime_part, 'print_attach', '', array('css' => 'printAtc', 'jstext' => _("Print"), 'onload' => 'IMP.printWindow', 'params' => $param_array, 'print' => true));
         }
 
         /* Strip Attachment? Allow stripping of base parts other than the
@@ -808,6 +809,8 @@ class IMP_Contents
      *            fully loaded.
      * 'params' - (array) A list of any additional parameters that need to be
      *            passed to view.php. (key = name)
+     * 'print' - (boolean) Generate link to print page?
+     *           DEFAULT: Link to view page.
      * 'widget' - (boolean) If true use Horde::widget() to generate,
      *            Horde::link() otherwise.
      * </pre>
@@ -825,7 +828,7 @@ class IMP_Contents
             $options['jstext'] = sprintf(_("View %s"), $mime_part->getDescription(true));
         }
 
-        $url = Horde::popupJs(Horde::applicationUrl('view.php'), array('menu' => true, 'onload' => empty($options['onload']) ? '' : $options['onload'], 'params' => $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array()), 'urlencode' => true)) . 'return false;';
+        $url = Horde::popupJs(Horde::applicationUrl(empty($options['print']) ? 'view.php' : 'print.php'), array('menu' => true, 'onload' => empty($options['onload']) ? '' : $options['onload'], 'params' => $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array()), 'urlencode' => true)) . 'return false;';
 
         return empty($options['widget'])
             ? Horde::link('#', $options['jstext'], empty($options['css']) ? null : $options['css'], null, $url) . $text . '</a>'
diff --git a/imp/print.php b/imp/print.php
new file mode 100644 (file)
index 0000000..66a0139
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/**
+ * Print a message part.
+ *
+ * <pre>
+ * URL parameters:
+ * ---------------
+ * 'id' - (string) The MIME ID of the part to print.
+ * 'mailbox' - (string) The mailbox of the message.
+ * 'mode' - (string) The print mode to use ('content', 'headers', empty).
+ *          DEFAULT: Prints frameset page
+ * 'uid' - (integer) The UID of the message.
+ * </pre>
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+
+require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('imp', array('session_control' => 'readonly'));
+
+$vars = Horde_Variables::getDefaultVariables();
+
+/* Bug #8708 - Mozilla can't print multipage data in frames. No choice but
+ * to output just the data with no header information. */
+if ($browser->isBrowser('mozilla')) {
+    $vars->mode = 'content';
+}
+
+switch ($vars->mode) {
+case 'content':
+case 'headers':
+    if (!$vars->uid || !$vars->mailbox || !$vars->id) {
+        exit;
+    }
+
+    $contents = IMP_Contents::singleton($vars->uid . IMP::IDX_SEP . $vars->mailbox);
+
+    switch ($vars->mode) {
+    case 'content':
+        $render = $contents->renderMIMEPart($vars->id, IMP_Contents::RENDER_FULL);
+        if (!empty($render)) {
+            reset($render);
+            $key = key($render);
+            $browser->downloadHeaders($render[$key]['name'], $render[$key]['type'], true, strlen($render[$key]['data']));
+            echo $render[$key]['data'];
+        }
+        break;
+
+    case 'headers':
+        $imp_ui = new IMP_Ui_Message();
+        $basic_headers = $imp_ui->basicHeaders();
+        unset($basic_headers['bcc'], $basic_headers['reply-to']);
+        $headerob = $contents->getHeaderOb();
+
+        $headers = array();
+        foreach ($basic_headers as $key => $val) {
+            if ($hdr_val = $headerob->getValue($key)) {
+                $headers[] = array(
+                    'header' => htmlspecialchars($val),
+                    'value' => htmlspecialchars($hdr_val)
+                );
+            }
+        }
+
+        if (!empty($conf['print']['add_printedby'])) {
+            $user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            $headers[] = array(
+                'header' => htmlspecialchars(_("Printed By")),
+                'value' => htmlspecialchars($user_identity->getFullname() ? $user_identity->getFullname() : Horde_Auth::getAuth())
+            );
+        }
+
+        $t = $injector->createInstance('Horde_Template');
+        $t->set('css', Horde_Util::bufferOutput(array('Horde', 'includeStylesheetFiles')));
+
+        $t->set('headers', $headers);
+
+        echo $t->fetch(IMP_TEMPLATES . '/print/headers.html');
+        break;
+    }
+    break;
+
+default:
+    $self_url = Horde::selfUrl(true, true);
+    $t = $injector->createInstance('Horde_Template');
+    $t->set('headers', $self_url->copy()->add('mode', 'headers'));
+    $t->set('content', $self_url->copy()->add('mode', 'content'));
+    echo $t->fetch(IMP_TEMPLATES . '/print/print.html');
+    break;
+}
diff --git a/imp/templates/print/headers.html b/imp/templates/print/headers.html
new file mode 100644 (file)
index 0000000..6102191
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "DTD/xhtml1-frameset.dtd">
+<html>
+ <tag:css />
+ <head></head>
+ <body>
+  <div id="headerblock" class="fixed mimeHeaders">
+  <loop:headers>
+   <div><strong><tag:headers.header />:</strong> <tag:headers.value /></div>
+  </loop:headers>
+  </div>
+ </body>
+</html>
diff --git a/imp/templates/print/print.html b/imp/templates/print/print.html
new file mode 100644 (file)
index 0000000..29c8e59
--- /dev/null
@@ -0,0 +1,8 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "DTD/xhtml1-frameset.dtd">
+<html>
+ <head></head>
+ <frameset id="frameset" framespacing="0" frameborder="0" rows="20%,80%">
+  <frame id="headers" name="headers" src="<tag:headers />" scrolling="auto" noresize="noresize" />
+  <frame name="content" src="<tag:content />" scrolling="auto" noresize="noresize" />
+ </frameset>
+</html>