Adding template for error box.
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
f226cba7 1<?php
2
35586184 3/**
4 * printer_friendly_bottom.php
5 *
35586184 6 * with javascript on, it is the bottom frame of printer_friendly_main.php
7 * else, it is alone in a new window
8 *
9 * - this is the page that does all the work, really.
10 *
47ccfad4 11 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 13 * @version $Id$
8f6f9ba5 14 * @package squirrelmail
35586184 15 */
16
30967a1e 17/**
18 * Path for SquirrelMail required files.
19 * @ignore
20 */
86725763 21define('SM_PATH','../');
22
23/* SquirrelMail required files. */
5c4ff7bf 24include_once(SM_PATH . 'include/validate.php');
86725763 25require_once(SM_PATH . 'functions/imap.php');
f226cba7 26
0b97a708 27/* get some of these globals */
f38b7cf0 28sqgetGlobalVar('username', $username, SQ_SESSION);
29sqgetGlobalVar('key', $key, SQ_COOKIE);
30sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
0b97a708 31
f38b7cf0 32sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
33sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
d4538b25 34
f38b7cf0 35if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
d4538b25 36 $passed_ent_id = '';
91e0dccc 37}
4c8986b4 38sqgetGlobalVar('show_html_default', $show_html_default, SQ_FORM);
0b97a708 39/* end globals */
40
18680db6 41$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
d4538b25 42$mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
43if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
7f6171be 44 $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id];
d4538b25 45} else {
46 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
47}
48if ($passed_ent_id) {
7f6171be 49 $message = $message->getEntity($passed_ent_id);
5caf2d0c 50}
32f4e318 51
52/* --start display setup-- */
53
91e0dccc 54$rfc822_header = $message->rfc822_header;
32f4e318 55/* From and Date are usually fine as they are... */
a91189d6 56$from = $rfc822_header->getAddr_s('from');
7e1c2d41 57$date = getLongDateString($rfc822_header->date);
a91189d6 58$subject = trim($rfc822_header->subject);
32f4e318 59
60/* we can clean these up if the list is too long... */
a91189d6 61$cc = $rfc822_header->getAddr_s('cc');
62$to = $rfc822_header->getAddr_s('to');
32f4e318 63
c8d6aef3 64if ($show_html_default == 1) {
65 $ent_ar = $message->findDisplayEntity(array());
66} else {
67 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
68}
18680db6 69$body = '';
70if ($ent_ar[0] != '') {
71 for ($i = 0; $i < count($ent_ar); $i++) {
a2bfcbce 72 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
83ae18bc 73 $body .= '<hr style="height: 1px;" />';
18680db6 74 }
75 $hookResults = do_hook('message_body', $body);
76 $body = $hookResults[1];
32f4e318 77} else {
18680db6 78 $body = _("Message not printable");
32f4e318 79}
3bbf5974 80
2b0f4faf 81/* now we clean up the display a bit... */
91e0dccc 82
2b0f4faf 83$num_leading_spaces = 9; // nine leading spaces for indentation
f226cba7 84
d3c4749f 85// sometimes I see ',,' instead of ',' separating addresses *shrug*
2b0f4faf 86$cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
87$to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
f226cba7 88
2b0f4faf 89// clean up everything else...
90$subject = pf_clean_string($subject, $num_leading_spaces);
91$from = pf_clean_string($from, $num_leading_spaces);
92$date = pf_clean_string($date, $num_leading_spaces);
f226cba7 93
2b0f4faf 94// end cleanup
18680db6 95
a91189d6 96$to = decodeHeader($to);
97$cc = decodeHeader($cc);
98$from = decodeHeader($from);
99$subject = decodeHeader($subject);
100
d3c4749f 101$attachments = pf_show_attachments($message,$ent_ar,$mailbox,$passed_id);
102
32f4e318 103// --end display setup--
f226cba7 104
f226cba7 105
32f4e318 106/* --start browser output-- */
04628296 107displayHtmlHeader( $subject, '', FALSE );
f226cba7 108
eb6d43d8 109echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
ae426785 110 /* headers (we use table because translations are not all the same width) */
3c816b1a 111 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0" width="100%"' ) .
1c663478 112 html_tag( 'tr',
a2bfcbce 113 html_tag( 'td', '<b>'._("From").':</b>&nbsp;', 'left' ,'','valign="top"') .
a91189d6 114 html_tag( 'td', $from, 'left' )
1c663478 115 ) . "\n" .
116 html_tag( 'tr',
a2bfcbce 117 html_tag( 'td', '<b>'._("Subject").':</b>&nbsp;', 'left','','valign="top"' ) .
a91189d6 118 html_tag( 'td', $subject, 'left' )
7e1c2d41 119 ) . "\n" .
120 html_tag( 'tr',
a2bfcbce 121 html_tag( 'td', '<b>'._("Date").':</b>&nbsp;', 'left' ) .
83be314a 122 html_tag( 'td', htmlspecialchars($date), 'left' )
7e1c2d41 123 ) . "\n" .
124 html_tag( 'tr',
a2bfcbce 125 html_tag( 'td', '<b>'._("To").':</b>&nbsp;', 'left','','valign="top"' ) .
a91189d6 126 html_tag( 'td', $to, 'left' )
127 ) . "\n";
48027e89 128 if ( strlen($cc) > 0 ) { /* only show Cc: if it's there... */
1c663478 129 echo html_tag( 'tr',
a2bfcbce 130 html_tag( 'td', '<b>'._("Cc").':</b>&nbsp;', 'left','','valign="top"' ) .
a91189d6 131 html_tag( 'td', $cc, 'left' )
1c663478 132 );
133 }
1c663478 134 /* body */
7e1c2d41 135 echo html_tag( 'tr',
83ae18bc 136 html_tag( 'td', '<hr style="height: 1px;" /><br />' . "\n" . $body, 'left', '', 'colspan="2"' )
d3c4749f 137 ) . "\n" ;
5c4ff7bf 138
d3c4749f 139 if (! empty($attachments)) {
140 // attachments title
141 echo html_tag( 'tr',
f369f2c0 142 html_tag( 'td','<b>'._("Attachments:").'</b>', 'left', '', 'colspan="2"' )
d3c4749f 143 ) . "\n" ;
144 // list of attachments
145 echo html_tag( 'tr',
146 html_tag( 'td',$attachments, 'left', '', 'colspan="2"' )
147 ) . "\n" ;
148 // add separator line
149 echo html_tag( 'tr',
150 html_tag( 'td', '<hr style="height: 1px;" />', 'left', '', 'colspan="2"' )
151 ) . "\n" ;
152 }
1c663478 153
5c4ff7bf 154 echo '</table>' . "\n";
155$oTemplate->display('footer.tpl');
f226cba7 156
32f4e318 157/* --end browser output-- */
f226cba7 158
f226cba7 159
32f4e318 160/* --start pf-specific functions-- */
f226cba7 161
b5cd24a8 162/**
163 * Function should clean layout of printed messages when user
164 * enables "Printer Friendly Clean Display" option.
9dbdf00b 165 * For example: $string = pf_clean_string($string, 9);
b5cd24a8 166 *
167 * @param string unclean_string
168 * @param integer num_leading_spaces
169 * @return string
91e0dccc 170 * @access private
b5cd24a8 171 */
f226cba7 172function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
173 global $data_dir, $username;
a91189d6 174 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
f6d2358f 175 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
32f4e318 176 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
f226cba7 177
178 $leading_spaces = '';
179 while ( strlen($leading_spaces) < $num_leading_spaces )
180 $leading_spaces .= ' ';
181
182 $clean_string = '';
183 while ( strlen($unclean_string) > $wrap_at )
184 {
185 $this_line = substr($unclean_string, 0, $wrap_at);
32f4e318 186 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
f226cba7 187 {
188 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
189 $clean_string .= $leading_spaces;
190 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
191 }
192 else
193 {
134e4174 194 $i = strrpos( $this_line, ' ');
195 $clean_string .= substr( $this_line, 0, $i);
196 $clean_string .= "\n" . $leading_spaces;
197 $unclean_string = substr($unclean_string, 1+$i);
198 }
f226cba7 199 }
200 $clean_string .= $unclean_string;
201
202 return $clean_string;
32f4e318 203} /* end pf_clean_string() function */
f226cba7 204
d3c4749f 205/**
206 * Displays attachment information
207 *
208 * Stripped version of formatAttachments() function from functions/mime.php.
209 * @param object $message SquirrelMail message object
210 * @param array $exclude_id message parts that are not attachments.
211 * @param string $mailbox mailbox name
212 * @param integer $id message id
213 * @return string html formated attachment information.
214 */
215function pf_show_attachments($message, $exclude_id, $mailbox, $id) {
216 global $where, $what, $startMessage, $color, $passed_ent_id;
217
218 $att_ar = $message->getAttachments($exclude_id);
219
220 if (!count($att_ar)) return '';
221
222 $attachments = '';
223
224 $urlMailbox = urlencode($mailbox);
225
226 foreach ($att_ar as $att) {
227 $ent = $att->entity_id;
228 $header = $att->header;
229 $type0 = strtolower($header->type0);
230 $type1 = strtolower($header->type1);
231 $name = '';
232
233 if ($type0 =='message' && $type1 == 'rfc822') {
234 $rfc822_header = $att->rfc822_header;
235 $filename = $rfc822_header->subject;
236 if (trim( $filename ) == '') {
237 $filename = 'untitled-[' . $ent . ']' ;
238 }
239 $from_o = $rfc822_header->from;
240 if (is_object($from_o)) {
434fb973 241 $from_name = decodeHeader($from_o->getAddress(true));
d3c4749f 242 } else {
243 $from_name = _("Unknown sender");
244 }
245 $description = '<tr>'.
246 html_tag( 'td',_("From:"), 'right') .
247 html_tag( 'td',$from_name, 'left') .
248 '</tr>';
249 } else {
250 $filename = $att->getFilename();
251 if ($header->description) {
252 $description = '<tr>'.
f369f2c0 253 html_tag( 'td',_("Info:"), 'right') .
d3c4749f 254 html_tag( 'td',decodeHeader($header->description), 'left') .
255 '</tr>';
256 } else {
257 $description = '';
258 }
259 }
260
261 $display_filename = $filename;
262
263 // TODO: maybe make it nicer?
179aed24 264 $attachments .= '<table cellpadding="1" cellspacing="0" width="100%" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' .
5c4ff7bf 265 '<tr>'.
266 html_tag( 'td',_("Size:"), 'right', '', 'width="25%"') .
179aed24 267 html_tag( 'td',show_readable_size($header->size), 'left', '', 'width="75%"') .
268 '</tr><tr>' . "\n" .
269 html_tag( 'td',_("Type:"), 'right', '', 'width="25%"') .
5c4ff7bf 270 html_tag( 'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1), 'left', '', 'width="75%"') .
d3c4749f 271 '</tr>';
272 if (! empty($description)) {
273 $attachments .= $description;
274 }
275 $attachments .= "</table>\n";
276 }
277 return $attachments;
278}
279
280
32f4e318 281/* --end pf-specific functions */
a2b193bc 282
7f6171be 283?>