source: github/program/steps/mail/compose.inc @ 5084427

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 5084427 was 5084427, checked in by thomascube <thomas@…>, 7 years ago

Changed label and icon for attachment removal and some styles

  • Property mode set to 100644
File size: 26.2 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc                                        |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Compose a new mail message with all headers and attachments         |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22
23require_once('Mail/mimeDecode.php');
24
25
26$MESSAGE_FORM = NULL;
27$REPLY_MESSAGE = NULL;
28$FORWARD_MESSAGE = NULL;
29$DRAFT_MESSAGE = NULL;
30
31
32if (!is_array($_SESSION['compose']))
33  $_SESSION['compose'] = array('id' => uniqid(rand()));
34
35// remove an attachment
36if ($_action=='remove-attachment' && !empty($_GET['_filename']))
37  {
38  if (is_array($_SESSION['compose']['attachments']))
39    foreach ($_SESSION['compose']['attachments'] as $i => $attachment)
40      if ($attachment['name'] == $_GET['_filename'])
41        {
42        @unlink($attachment['path']);
43        unset($_SESSION['compose']['attachments'][$i]);
44        $commands = sprintf("parent.%s.remove_from_attachment_list('%s');\n", $JS_OBJECT_NAME, $_GET['_filename']);
45        rcube_remote_response($commands); 
46        exit;
47        }
48  }
49
50// add some labels to client
51rcube_add_label('nosubject', 'norecipientwarning', 'nosubjectwarning', 'nobodywarning', 'notsentwarning', 'savingmessage', 'savingmessage', 'messagesaved');
52
53
54if ($_GET['_reply_uid'] || $_GET['_forward_uid'] || $_GET['_draft_uid'])
55  {
56  $msg_uid = ($_GET['_reply_uid'] ? $_GET['_reply_uid'] : ($_GET['_forward_uid'] ? $_GET['_forward_uid'] : $_GET['_draft_uid']));
57
58  // similar as in program/steps/mail/show.inc
59  $MESSAGE = array();
60  $MESSAGE['headers'] = $IMAP->get_headers($msg_uid);
61 
62  $MESSAGE['source'] = rcmail_message_source($msg_uid);
63 
64  $mmd = new Mail_mimeDecode($MESSAGE['source']);
65  $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE,
66                                             'decode_headers' => TRUE,
67                                             'decode_bodies' => FALSE));
68
69  $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
70  $MESSAGE['parts'] = $mmd->getMimeNumbers($MESSAGE['structure']);
71
72  if ($_GET['_reply_uid'])
73    {
74    $REPLY_MESSAGE = &$MESSAGE;
75    $_SESSION['compose']['reply_uid'] = $_GET['_reply_uid'];
76    $_SESSION['compose']['reply_msgid'] = $REPLY_MESSAGE['headers']->messageID;
77    $_SESSION['compose']['references']  = $REPLY_MESSAGE['headers']->reference;
78    $_SESSION['compose']['references'] .= !empty($REPLY_MESSAGE['headers']->reference) ? ' ' : '';
79    $_SESSION['compose']['references'] .= $REPLY_MESSAGE['headers']->messageID;
80
81    if ($_GET['_all'])
82      $REPLY_MESSAGE['reply_all'] = 1;
83
84    }
85  else if ($_GET['_forward_uid'])
86    {
87    $FORWARD_MESSAGE = $MESSAGE;
88    $_SESSION['compose']['forward_uid'] = $_GET['_forward_uid'];
89    }
90  else
91    {
92    $DRAFT_MESSAGE = $MESSAGE;
93    $_SESSION['compose']['draft_uid'] = $_GET['_draft_uid'];
94    }
95
96  }
97
98/****** compose mode functions ********/
99
100
101function rcmail_compose_headers($attrib)
102  {
103  global $IMAP, $REPLY_MESSAGE, $DRAFT_MESSAGE, $DB;
104  static $sa_recipients = array();
105
106  list($form_start, $form_end) = get_form_tags($attrib);
107 
108  $out = '';
109  $part = strtolower($attrib['part']);
110 
111  switch ($part)
112    {
113    case 'from':
114      return rcmail_compose_header_from($attrib);
115
116    case 'to':
117      $fname = '_to';
118      $header = 'to';
119
120      // we have contact id's as get parameters
121      if (!empty($_GET['_to']) && preg_match('/^[0-9]+(,[0-9]+)*$/', $_GET['_to']))
122        {
123        $a_recipients = array();
124        $sql_result = $DB->query("SELECT name, email
125                                  FROM ".get_table_name('contacts')."
126                                  WHERE user_id=?
127                                  AND    del<>1
128                                  AND    contact_id IN (".$_GET['_to'].")",
129                                  $_SESSION['user_id']);
130                                         
131        while ($sql_arr = $DB->fetch_assoc($sql_result))
132          $a_recipients[] = format_email_recipient($sql_arr['email'], $sql_arr['name']);
133         
134        if (sizeof($a_recipients))
135          $fvalue = join(', ', $a_recipients);
136        }
137      else if (!empty($_GET['_to']))
138        $fvalue = $_GET['_to'];
139       
140    case 'cc':
141      if (!$fname)
142        {
143        $fname = '_cc';
144        $header = 'cc';
145        }
146    case 'bcc':
147      if (!$fname)
148        $fname = '_bcc';
149       
150      $allow_attrib = array('id', 'class', 'style', 'cols', 'rows', 'wrap', 'tabindex');
151      $field_type = 'textarea';           
152      break;
153
154    case 'replyto':
155    case 'reply-to':
156      $fname = '_replyto';
157      $allow_attrib = array('id', 'class', 'style', 'size', 'tabindex');
158      $field_type = 'textfield';
159      break;
160   
161    }
162 
163  if ($fname && !empty($_POST[$fname]))
164    $fvalue = get_input_value($fname, RCUBE_INPUT_POST, TRUE);
165  else if ($header && is_object($REPLY_MESSAGE['headers']))
166    {
167    // get recipent address(es) out of the message headers
168    if ($header=='to' && $REPLY_MESSAGE['headers']->replyto)
169      $fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->replyto);
170
171    else if ($header=='to' && $REPLY_MESSAGE['headers']->from)
172      $fvalue = $IMAP->decode_header($REPLY_MESSAGE['headers']->from);
173
174    // add recipent of original message if reply to all
175    else if ($header=='cc' && $REPLY_MESSAGE['reply_all'])
176      {
177      if ($IMAP->decode_header($REPLY_MESSAGE['headers']->to))
178        $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->to);
179
180      if ($IMAP->decode_header($REPLY_MESSAGE['headers']->cc))
181        {
182        if($fvalue)
183          $fvalue .= ', ';
184
185        $fvalue .= $IMAP->decode_header($REPLY_MESSAGE['headers']->cc);
186        }
187      }
188
189    // split recipients and put them back together in a unique way
190    if (!empty($fvalue))
191      {
192      $to_addresses = $IMAP->decode_address_list($fvalue);
193      $fvalue = '';
194      foreach ($to_addresses as $addr_part)
195        {
196        if (!in_array($addr_part['mailto'], $sa_recipients) && (!$REPLY_MESSAGE['FROM'] || !in_array($addr_part['mailto'], $REPLY_MESSAGE['FROM'])))
197          {
198          $fvalue .= (strlen($fvalue) ? ', ':'').$addr_part['string'];
199          $sa_recipients[] = $addr_part['mailto'];
200          }
201        }
202      }
203    }
204  else if ($header && is_object($DRAFT_MESSAGE['headers']))
205    {
206    // get drafted headers
207    if ($header=='to' && $DRAFT_MESSAGE['headers']->to)
208      $fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->to);
209
210    if ($header=='cc' && $DRAFT_MESSAGE['headers']->cc)
211      $fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->cc);
212
213    if ($header=='bcc' && $DRAFT_MESSAGE['headers']->bcc)
214      $fvalue = $IMAP->decode_header($DRAFT_MESSAGE['headers']->bcc);
215
216    }
217
218       
219  if ($fname && $field_type)
220    {
221    // pass the following attributes to the form class
222    $field_attrib = array('name' => $fname);
223    foreach ($attrib as $attr => $value)
224      if (in_array($attr, $allow_attrib))
225        $field_attrib[$attr] = $value;
226
227    // create teaxtarea object
228    $input = new $field_type($field_attrib);
229    $out = $input->show($fvalue);   
230    }
231 
232  if ($form_start)
233    $out = $form_start.$out;
234
235  return $out; 
236  }
237
238
239
240function rcmail_compose_header_from($attrib)
241  {
242  global $IMAP, $REPLY_MESSAGE, $DRAFT_MESSAGE, $DB, $OUTPUT, $JS_OBJECT_NAME;
243   
244  // pass the following attributes to the form class
245  $field_attrib = array('name' => '_from');
246  foreach ($attrib as $attr => $value)
247    if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex')))
248      $field_attrib[$attr] = $value;
249
250  // extract all recipients of the reply-message
251  $a_recipients = array();
252  if ($REPLY_MESSAGE && is_object($REPLY_MESSAGE['headers']))
253    {
254    $REPLY_MESSAGE['FROM'] = array();
255
256    $a_to = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->to);       
257    foreach ($a_to as $addr)
258      {
259      if (!empty($addr['mailto']))
260        $a_recipients[] = $addr['mailto'];
261      }
262
263    if (!empty($REPLY_MESSAGE['headers']->cc))
264      {
265      $a_cc = $IMAP->decode_address_list($REPLY_MESSAGE['headers']->cc);
266      foreach ($a_cc as $addr)
267        {
268        if (!empty($addr['mailto']))
269          $a_recipients[] = $addr['mailto'];
270        }
271      }
272    }
273
274  // get this user's identities
275  $sql_result = $DB->query("SELECT identity_id, name, email, signature
276                            FROM   ".get_table_name('identities')."
277                            WHERE user_id=?
278                            AND    del<>1
279                            ORDER BY ".$DB->quoteIdentifier('standard')." DESC, name ASC",
280                           $_SESSION['user_id']);
281                                   
282  if ($DB->num_rows($sql_result))
283    {
284    $from_id = 0;
285    $a_signatures = array();
286   
287    $field_attrib['onchange'] = "$JS_OBJECT_NAME.change_identity(this)";
288    $select_from = new select($field_attrib);
289   
290    while ($sql_arr = $DB->fetch_assoc($sql_result))
291      {
292      $select_from->add(format_email_recipient($sql_arr['email'], $sql_arr['name']), $sql_arr['identity_id']);
293
294      // add signature to array
295      if (!empty($sql_arr['signature']))
296        $a_signatures[$sql_arr['identity_id']] = $sql_arr['signature'];
297     
298      // set identity if it's one of the reply-message recipients
299      if (in_array($sql_arr['email'], $a_recipients))
300        $from_id = $sql_arr['identity_id'];
301       
302      if ($REPLY_MESSAGE && is_array($REPLY_MESSAGE['FROM']))
303        $REPLY_MESSAGE['FROM'][] = $sql_arr['email'];
304
305      if (strstr($DRAFT_MESSAGE['headers']->from,$sql_arr['email']))
306        $from_id = $sql_arr['identity_id'];
307
308      }
309
310    // overwrite identity selection with post parameter
311    if (isset($_POST['_from']))
312      $from_id = $_POST['_from'];
313
314    $out = $select_from->show($from_id);
315   
316
317    // add signatures to client
318    $OUTPUT->add_script(sprintf("%s.set_env('signatures', %s);", $JS_OBJECT_NAME, array2js($a_signatures))); 
319    }
320  else
321    {
322    $input_from = new textfield($field_attrib);
323    $out = $input_from->show($_POST['_from']);
324    }
325 
326  if ($form_start)
327    $out = $form_start.$out;
328
329  return $out;
330  }
331
332 
333
334function rcmail_compose_body($attrib)
335  {
336  global $CONFIG, $OUTPUT, $REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE, $JS_OBJECT_NAME;
337 
338  list($form_start, $form_end) = get_form_tags($attrib);
339  unset($attrib['form']);
340 
341  if (empty($attrib['id']))
342    $attrib['id'] = 'rcmComposeMessage';
343 
344  $attrib['name'] = '_message';
345  $textarea = new textarea($attrib);
346
347  $body = '';
348 
349  // use posted message body
350  if (!empty($_POST['_message']))
351    $body = get_input_value('_message', RCUBE_INPUT_POST, TRUE);
352   
353  // compose reply-body
354  else if (is_array($REPLY_MESSAGE['parts']))
355    {
356    $body = rcmail_first_text_part($REPLY_MESSAGE['parts']);
357    if (strlen($body))
358      $body = rcmail_create_reply_body($body);
359    }
360
361  // forward message body inline
362  else if (is_array($FORWARD_MESSAGE['parts']))
363    {
364    $body = rcmail_first_text_part($FORWARD_MESSAGE['parts']);
365    if (strlen($body))
366      $body = rcmail_create_forward_body($body);
367    }
368
369  // forward message body inline
370  else if (is_array($DRAFT_MESSAGE['parts']))
371    {
372    $body = rcmail_first_text_part($DRAFT_MESSAGE['parts']);
373    if (strlen($body))
374      $body = rcmail_create_draft_body($body);
375    }
376 
377  $out = $form_start ? "$form_start\n" : '';
378
379  // Check if a previous save was done so we can delete it upon the next save
380  if (!empty($_POST['_draft_newsaveid']))
381    $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => $_POST['_draft_newsaveid']));
382  else if (strlen($DRAFT_MESSAGE['headers']->messageID) > 6)
383    $saveid = new hiddenfield(array('name' => '_draft_saveid', 'value' => str_replace(array('<','>'),"",$DRAFT_MESSAGE['headers']->messageID) ));
384
385  if ($saveid)
386    $out .= $saveid->show();
387
388  $newsaveid = new hiddenfield(array('name' => '_draft_newsaveid', 'value' => sprintf('%s@%s', md5(uniqid('rcmail'.rand(),true)), $_SESSION['imap_host']) ));
389  $out .= $newsaveid->show();
390 
391  $drafttoggle = new hiddenfield(array('name' => '_draft', 'value' => 'yes'));
392  $out .= $drafttoggle->show();
393
394  $out .= $textarea->show($body);
395  $out .= $form_end ? "\n$form_end" : '';
396 
397  // include GoogieSpell
398  if (!empty($CONFIG['enable_spellcheck']))
399    {
400    $OUTPUT->include_script('googiespell.js');
401    $OUTPUT->add_script(sprintf("var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n".
402                                "googie.lang_chck_spell = \"%s\";\n".
403                                "googie.lang_rsm_edt = \"%s\";\n".
404                                "googie.lang_close = \"%s\";\n".
405                                "googie.lang_revert = \"%s\";\n".
406                                "googie.lang_no_error_found = \"%s\";\n".
407                                "googie.decorateTextarea('%s');\n".
408                                "%s.set_env('spellcheck', googie);",
409                                $GLOBALS['COMM_PATH'],
410                                rep_specialchars_output(rcube_label('checkspelling')),
411                                rep_specialchars_output(rcube_label('resumeediting')),
412                                rep_specialchars_output(rcube_label('close')),
413                                rep_specialchars_output(rcube_label('revertto')),
414                                rep_specialchars_output(rcube_label('nospellerrors')),
415                                $attrib['id'],
416                                $JS_OBJECT_NAME), 'foot');
417
418    rcube_add_label('checking');
419    }
420 
421  return $out;
422  }
423
424
425function rcmail_create_reply_body($body)
426  {
427  global $IMAP, $REPLY_MESSAGE;
428
429  // soft-wrap message first
430  $body = wordwrap($body, 75);
431 
432  // split body into single lines
433  $a_lines = preg_split('/\r?\n/', $body);
434 
435  // add > to each line
436  for($n=0; $n<sizeof($a_lines); $n++)
437    {
438    if (strpos($a_lines[$n], '>')===0)
439      $a_lines[$n] = '>'.$a_lines[$n];
440    else
441      $a_lines[$n] = '> '.$a_lines[$n];
442    }
443 
444  $body = join("\n", $a_lines);
445
446  // add title line
447  $pefix = sprintf("\n\n\nOn %s, %s wrote:\n",
448           $REPLY_MESSAGE['headers']->date,
449           $IMAP->decode_header($REPLY_MESSAGE['headers']->from));
450           
451
452  // try to remove the signature
453  if ($sp = strrpos($body, '-- '))
454    {
455    if ($body{$sp+3}==' ' || $body{$sp+3}=="\n" || $body{$sp+3}=="\r")
456      $body = substr($body, 0, $sp-1);
457    }
458
459  return $pefix.$body;
460  }
461
462
463function rcmail_create_forward_body($body)
464  {
465  global $IMAP, $FORWARD_MESSAGE;
466
467  // soft-wrap message first
468  $body = wordwrap($body, 80);
469 
470  $prefix = sprintf("\n\n\n-------- Original Message --------\nSubject: %s\nDate: %s\nFrom: %s\nTo: %s\n\n",
471                   $FORWARD_MESSAGE['subject'],
472                   $FORWARD_MESSAGE['headers']->date,
473                   $IMAP->decode_header($FORWARD_MESSAGE['headers']->from),
474                   $IMAP->decode_header($FORWARD_MESSAGE['headers']->to));
475
476  // add attachments
477  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($FORWARD_MESSAGE['parts']) && sizeof($FORWARD_MESSAGE['parts'])>1)
478    {
479    $temp_dir = rcmail_create_compose_tempdir();
480
481    if (!is_array($_SESSION['compose']['attachments']))
482      $_SESSION['compose']['attachments'] = array();
483 
484    foreach ($FORWARD_MESSAGE['parts'] as $part)
485      {
486      if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
487               (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name'])))
488        {
489        $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
490        if ($fp = fopen($tmp_path, 'w'))
491          {
492          fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']));
493          fclose($fp);
494
495          if ($part->d_parameters['filename'])
496            $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'],
497                                                          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
498                                                          'path' => $tmp_path);
499                                   
500          else if ($part->ctype_parameters['name'])
501            $_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'],
502                                                          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
503                                                          'path' => $tmp_path);
504                                                         
505          else if ($part->headers['content-description'])
506            $_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'],
507                                                          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
508                                                          'path' => $tmp_path);
509          }
510        }
511      }
512
513    $_SESSION['compose']['forward_attachments'] = TRUE;
514    }
515
516  return $prefix.$body;
517  }
518
519function rcmail_create_draft_body($body)
520  {
521  global $IMAP, $DRAFT_MESSAGE;
522   
523  // add attachments
524  if (!isset($_SESSION['compose']['forward_attachments']) && is_array($DRAFT_MESSAGE['parts']) && sizeof($DRAFT_MESSAGE['parts'])>1)
525    {
526    $temp_dir = rcmail_create_compose_tempdir();
527
528    if (!is_array($_SESSION['compose']['attachments']))
529      $_SESSION['compose']['attachments'] = array();
530 
531    foreach ($DRAFT_MESSAGE['parts'] as $part)
532      {
533      if ($part->disposition=='attachment' || $part->disposition=='inline' || $part->headers['content-id'] ||
534               (empty($part->disposition) && ($part->d_parameters['filename'] || $part->ctype_parameters['name'])))
535        {
536        $tmp_path = tempnam($temp_dir, 'rcmAttmnt');
537        if ($fp = fopen($tmp_path, 'w'))
538          {                     
539          fwrite($fp, $IMAP->mime_decode($part->body, $part->headers['content-transfer-encoding']));
540          fclose($fp);         
541                               
542          if ($part->d_parameters['filename'])
543            $_SESSION['compose']['attachments'][] = array('name' => $part->d_parameters['filename'],
544                                                          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
545                                                          'path' => $tmp_path);
546
547          else if ($part->ctype_parameters['name'])
548            $_SESSION['compose']['attachments'][] = array('name' => $part->ctype_parameters['name'],
549                                                          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
550                                                          'path' => $tmp_path);
551
552          else if ($part->headers['content-description'])
553            $_SESSION['compose']['attachments'][] = array('name' => $part->headers['content-description'],
554                                                          'mimetype' => $part->ctype_primary . '/' . $part->ctype_secondary,
555                                                          'path' => $tmp_path);
556          }
557        }
558      }
559
560    $_SESSION['compose']['forward_attachments'] = TRUE;
561    }
562
563  return $body;
564  }
565
566
567function rcmail_compose_subject($attrib)
568  {
569  global $CONFIG, $REPLY_MESSAGE, $FORWARD_MESSAGE, $DRAFT_MESSAGE;
570 
571  list($form_start, $form_end) = get_form_tags($attrib);
572  unset($attrib['form']);
573 
574  $attrib['name'] = '_subject';
575  $textfield = new textfield($attrib);
576
577  $subject = '';
578
579  // use subject from post
580  if (isset($_POST['_subject']))
581    $subject = get_input_value('_subject', RCUBE_INPUT_POST, TRUE);
582   
583  // create a reply-subject
584  else if (isset($REPLY_MESSAGE['subject']))
585    {
586    if (eregi('^re:', $REPLY_MESSAGE['subject']))
587      $subject = $REPLY_MESSAGE['subject'];
588    else
589      $subject = 'Re: '.$REPLY_MESSAGE['subject'];
590    }
591
592  // create a forward-subject
593  else if (isset($FORWARD_MESSAGE['subject']))
594    {
595    if (eregi('^fwd:', $REPLY_MESSAGE['subject']))
596      $subject = $FORWARD_MESSAGE['subject'];
597    else
598      $subject = 'Fwd: '.$FORWARD_MESSAGE['subject'];
599    }
600
601  // creeate a draft-subject
602  else if (isset($DRAFT_MESSAGE['subject']))
603    $subject = $DRAFT_MESSAGE['subject'];
604 
605  $out = $form_start ? "$form_start\n" : '';
606  $out .= $textfield->show($subject);
607  $out .= $form_end ? "\n$form_end" : '';
608         
609  return $out;
610  }
611
612
613function rcmail_compose_attachment_list($attrib)
614  {
615  global $OUTPUT, $JS_OBJECT_NAME;
616 
617  // add ID if not given
618  if (!$attrib['id'])
619    $attrib['id'] = 'rcmAttachmentList';
620 
621  // allow the following attributes to be added to the <ul> tag
622  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
623 
624  $out = '<ul'. $attrib_str . ">\n";
625 
626  if (is_array($_SESSION['compose']['attachments']))
627    {
628    if ($attrib['deleteicon'])
629      $button = sprintf('<img src="%s%s" alt="%s" border="0" / style="padding-right:2px;vertical-align:middle">',
630                        $CONFIG['skin_path'],
631                        $attrib['deleteicon'],
632                        rcube_label('delete'));
633    else
634      $button = rcube_label('delete');
635
636    foreach ($_SESSION['compose']['attachments'] as $i => $a_prop)
637      $out .= sprintf('<li id="%s"><a href="#" onclick="%s.command(\'remove-attachment\',\'%s\')" title="%s">%s</a>%s</li>',
638                      $a_prop['name'],
639                      $JS_OBJECT_NAME,
640                      $a_prop['name'],
641                      rcube_label('delete'),
642                      $button, $a_prop['name']);
643    }
644
645  $OUTPUT->add_script(sprintf("%s.gui_object('attachmentlist', '%s');", $JS_OBJECT_NAME, $attrib['id'])); 
646   
647  $out .= '</ul>';
648  return $out;
649  }
650
651
652
653function rcmail_compose_attachment_form($attrib)
654  {
655  global $OUTPUT, $JS_OBJECT_NAME, $SESS_HIDDEN_FIELD;
656
657  // add ID if not given
658  if (!$attrib['id'])
659    $attrib['id'] = 'rcmUploadbox';
660 
661  // allow the following attributes to be added to the <div> tag
662  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
663  $input_field = rcmail_compose_attachment_field(array());
664  $label_send = rcube_label('upload');
665  $label_close = rcube_label('close');
666 
667  $out = <<<EOF
668<div$attrib_str>
669<form action="./" method="post" enctype="multipart/form-data">
670$SESS_HIDDEN_FIELD
671$input_field<br />
672<input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" />
673<input type="button" value="$label_send" class="button" onclick="$JS_OBJECT_NAME.command('send-attachment', this.form)" />
674</form>
675</div>
676EOF;
677
678 
679  $OUTPUT->add_script(sprintf("%s.gui_object('uploadbox', '%s');", $JS_OBJECT_NAME, $attrib['id'])); 
680  return $out;
681  }
682
683
684function rcmail_compose_attachment_field($attrib)
685  {
686  // allow the following attributes to be added to the <input> tag
687  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style', 'size'));
688 
689  $out = '<input type="file" name="_attachments[]"'. $attrib_str . " />";
690  return $out;
691  }
692
693function rcmail_priority_selector($attrib)
694  {
695  list($form_start, $form_end) = get_form_tags($attrib);
696  unset($attrib['form']);
697 
698  $attrib['name'] = '_priority';
699  $selector = new select($attrib);
700
701  $selector->add(array(rcube_label('lowest'),
702                       rcube_label('low'),
703                       rcube_label('normal'),
704                       rcube_label('high'),
705                       rcube_label('highest')),
706                 array(5, 4, 0, 2, 1));
707                 
708  $sel = isset($_POST['_priority']) ? $_POST['_priority'] : 0;
709
710  $out = $form_start ? "$form_start\n" : '';
711  $out .= $selector->show($sel);
712  $out .= $form_end ? "\n$form_end" : '';
713         
714  return $out;
715  }
716
717
718function rcmail_receipt_checkbox($attrib)
719  {
720  list($form_start, $form_end) = get_form_tags($attrib);
721  unset($attrib['form']);
722
723  $attrib['name'] = '_receipt';
724  $checkbox = new checkbox(array('name' => '_receipt', 'id' => 'receipt', 'value' => 1));
725
726  $out = $form_start ? "$form_start\n" : '';
727  $out .= $checkbox->show(0);
728  $out .= $form_end ? "\n$form_end" : '';
729
730  return $out;
731  }
732
733
734function get_form_tags($attrib)
735  {
736  global $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $MESSAGE_FORM, $SESS_HIDDEN_FIELD; 
737
738  $form_start = '';
739  if (!strlen($MESSAGE_FORM))
740    {
741    $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
742    $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
743
744    $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
745    $form_start .= "\n$SESS_HIDDEN_FIELD\n";
746    $form_start .= $hiddenfields->show();
747    }
748   
749  $form_end = (strlen($MESSAGE_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
750  $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
751 
752  if (!strlen($MESSAGE_FORM))
753    $OUTPUT->add_script("$JS_OBJECT_NAME.gui_object('messageform', '$form_name');");
754 
755  $MESSAGE_FORM = $form_name;
756
757  return array($form_start, $form_end); 
758  }
759
760
761function format_email_recipient($email, $name='')
762  {
763  if ($name && $name != $email)
764    return sprintf('%s <%s>', strpos($name, ",") ? '"'.$name.'"' : $name, $email);
765  else
766    return $email;
767  }
768
769
770function rcmail_charset_pulldown($selected='ISO-8859-1')
771  {
772  $select = new select();
773 
774 
775  return $select->show($selected);
776  }
777
778
779/****** get contacts for this user and add them to client scripts ********/
780
781$sql_result = $DB->query("SELECT name, email
782                          FROM ".get_table_name('contacts')." WHERE  user_id=?
783                          AND  del<>1",$_SESSION['user_id']);
784                                   
785if ($DB->num_rows($sql_result))
786  {       
787  $a_contacts = array();
788  while ($sql_arr = $DB->fetch_assoc($sql_result))
789    if ($sql_arr['email'])
790      $a_contacts[] = format_email_recipient($sql_arr['email'], rep_specialchars_output($sql_arr['name'], 'js'));
791 
792  $OUTPUT->add_script(sprintf("$JS_OBJECT_NAME.set_env('contacts', %s);", array2js($a_contacts)));
793  }
794
795
796
797
798parse_template('compose');
799?>
Note: See TracBrowser for help on using the repository browser.