Added toggle_all link + formatting changes
[squirrelmail.git] / src / printer_friendly_bottom.php
... / ...
CommitLineData
1<?php
2
3/**
4 * printer_friendly_bottom.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * with javascript on, it is the bottom frame of printer_friendly_main.php
10 * else, it is alone in a new window
11 *
12 * - this is the page that does all the work, really.
13 *
14 * $Id$
15 */
16
17require_once('../src/validate.php');
18require_once('../functions/strings.php');
19require_once('../config/config.php');
20require_once('../src/load_prefs.php');
21require_once('../functions/imap.php');
22require_once('../functions/page_header.php');
23require_once('../functions/html.php');
24
25$pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
26$mailbox = urldecode($mailbox);
27$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
28sqimap_mailbox_select($imapConnection, $mailbox);
29$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
30$id = $passed_id;
31if (isset($passed_ent_id)) {
32 $message = $message->getEntity($passed_ent_id);
33}
34
35
36/* --start display setup-- */
37
38$rfc822_header = $message->rfc822_header;
39/* From and Date are usually fine as they are... */
40$from = decodeHeader($rfc822_header->getAddr_s('from'));
41$date = getLongDateString($rfc822_header->date);
42$subject = trim(decodeHeader($rfc822_header->subject));
43
44/* we can clean these up if the list is too long... */
45$cc = decodeHeader($rfc822_header->getAddr_s('cc'));
46$to = decodeHeader($rfc822_header->getAddr_s('to'));
47
48$ent_ar = $message->findDisplayEntity();
49$body = '';
50if ($ent_ar[0] != '') {
51 for ($i = 0; $i < count($ent_ar); $i++) {
52 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
53 $body .= '<hr noshade size=1>';
54 }
55 $hookResults = do_hook('message_body', $body);
56 $body = $hookResults[1];
57} else {
58 $body = _("Message not printable");
59}
60
61 /* now, if they choose to, we clean up the display a bit... */
62
63if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
64
65 $num_leading_spaces = 9; // nine leading spaces for indentation
66
67 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
68 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
69 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
70
71 // the body should have no leading zeros
72 // disabled because it destroys html mail
73
74// $body = pf_clean_string($body, 0);
75
76 // clean up everything else...
77 $subject = pf_clean_string($subject, $num_leading_spaces);
78 $from = pf_clean_string($from, $num_leading_spaces);
79 $date = pf_clean_string($date, $num_leading_spaces);
80
81} // end cleanup
82
83// --end display setup--
84
85
86/* --start browser output-- */
87displayHtmlHeader( _("Printer Friendly"), '', FALSE );
88
89echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
90 /* headers (we use table because translations are not all the same width) */
91 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0"' ) .
92 html_tag( 'tr',
93 html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
94 html_tag( 'td', htmlentities($from), 'left' )
95 ) . "\n" .
96 html_tag( 'tr',
97 html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
98 html_tag( 'td', htmlentities($subject), 'left' )
99 ) . "\n" .
100 html_tag( 'tr',
101 html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
102 html_tag( 'td', htmlentities($date), 'left' )
103 ) . "\n" .
104 html_tag( 'tr',
105 html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
106 html_tag( 'td', htmlentities($to), 'left' )
107 ) . "\n";
108 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
109 echo html_tag( 'tr',
110 html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
111 html_tag( 'td', htmlentities($cc), 'left' )
112 );
113 }
114 /* body */
115 echo html_tag( 'tr',
116 html_tag( 'td', '<hr noshade size=1><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
117 ) . "\n" .
118
119 '</table>' . "\n" .
120 '</body></html>';
121
122/* --end browser output-- */
123
124
125/* --start pf-specific functions-- */
126
127/* $string = pf_clean_string($string, 9); */
128function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
129 global $data_dir, $username;
130
131 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
132 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
133
134 $leading_spaces = '';
135 while ( strlen($leading_spaces) < $num_leading_spaces )
136 $leading_spaces .= ' ';
137
138 $clean_string = '';
139 while ( strlen($unclean_string) > $wrap_at )
140 {
141 $this_line = substr($unclean_string, 0, $wrap_at);
142 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
143 {
144 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
145 $clean_string .= $leading_spaces;
146 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
147 }
148 else
149 {
150 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
151 $clean_string .= "\n" . $leading_spaces;
152 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
153 }
154 }
155
156 $clean_string .= $unclean_string;
157
158 return $clean_string;
159} /* end pf_clean_string() function */
160
161/* --end pf-specific functions */
162
163?>