From 885ebb8da2c46ba1c5bfd42bf69159f40f266c68 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 10 May 2008 10:18:31 -0400
Subject: [PATCH] - added enctype for attachments form (#1485056)

---
 program/steps/mail/compose.inc |   81 +++++++++++++++++++---------------------
 1 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 878cf86..676b6b4 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -26,7 +26,7 @@
 
 
 // remove an attachment
-if ($_action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
+if ($RCMAIL->action=='remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs))
 {
   $id = $regs[1];
   if (is_array($_SESSION['compose']['attachments'][$id]))
@@ -39,7 +39,7 @@
   }
 }
 
-if ($_action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
+if ($RCMAIL->action=='display-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_GET['_file'], $regs))
 {
   $id = $regs[1];
   if (is_array($_SESSION['compose']['attachments'][$id]))
@@ -241,7 +241,7 @@
 
 function rcmail_compose_header_from($attrib)
 {
-  global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $compose_mode;
+  global $IMAP, $MESSAGE, $DB, $USER, $OUTPUT, $CONFIG, $compose_mode;
     
   // pass the following attributes to the form class
   $field_attrib = array('name' => '_from');
@@ -298,7 +298,7 @@
         {
             $h2t = new html2text($a_signatures[$identity_id]['text'], false, false);
             $plainTextPart = $h2t->get_text();
-            $a_signatures[$identity_id]['plain_text'] = trim($plainTextPart);
+            $a_signatures[$identity_id]['plain_text'] = trim(html_entity_decode($plainTextPart, ENT_NOQUOTES, 'UTF-8'));
         }
       }
 
@@ -337,7 +337,7 @@
 
 function rcmail_compose_body($attrib)
 {
-  global $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
+  global $RCMAIL, $CONFIG, $OUTPUT, $MESSAGE, $compose_mode;
   
   list($form_start, $form_end) = get_form_tags($attrib);
   unset($attrib['form']);
@@ -410,9 +410,15 @@
     $body = rcmail_create_draft_body($body, $isHtml);
     }
 
+  $tinylang = substr($_SESSION['language'], 0, 2);
+  if (!file_exists('program/js/tiny_mce/langs/'.$tinylang.'.js'))
+    { 
+    $tinylang = 'en'; 
+    } 
+
   $OUTPUT->include_script('tiny_mce/tiny_mce.js');
   $OUTPUT->include_script("editor.js");
-  $OUTPUT->add_script('rcmail_editor_init("$__skin_path");');
+  $OUTPUT->add_script('rcmail_editor_init("$__skin_path", "'.$tinylang.'");');
 
   $out = $form_start ? "$form_start\n" : '';
 
@@ -426,8 +432,7 @@
   $out .= $msgtype->show();
 
   // If desired, set this text area to be editable by TinyMCE
-  if ($isHtml)
-    $attrib['mce_editable'] = "true";
+  if ($isHtml) $attrib['class'] = "mce_editor";
   $textarea = new html_textarea($attrib);
   $out .= $textarea->show($body);
   $out .= $form_end ? "\n$form_end" : '';
@@ -450,14 +455,14 @@
       "googie.setCurrentLanguage('%s');\n".
       "googie.decorateTextarea('%s');\n".
       "%s.set_env('spellcheck', googie);",
-      $GLOBALS['COMM_PATH'],
+      $RCMAIL->comm_path,
       JQ(Q(rcube_label('checkspelling'))),
       JQ(Q(rcube_label('resumeediting'))),
       JQ(Q(rcube_label('close'))),
       JQ(Q(rcube_label('revertto'))),
       JQ(Q(rcube_label('nospellerrors'))),
       $lang_set,
-      substr($_SESSION['user_lang'], 0, 2),
+      substr($_SESSION['language'], 0, 2),
       $attrib['id'],
       JS_OBJECT_NAME), 'foot');
 
@@ -699,30 +704,21 @@
 
 function rcmail_compose_attachment_form($attrib)
 {
-  global $OUTPUT, $SESS_HIDDEN_FIELD;
+  global $OUTPUT;
 
   // add ID if not given
   if (!$attrib['id'])
     $attrib['id'] = 'rcmUploadbox';
   
-  // allow the following attributes to be added to the <div> tag
-  $attrib_str = create_attrib_string($attrib, array('id', 'class', 'style'));
-  $input_field = rcmail_compose_attachment_field(array());
-  $label_send = rcube_label('upload');
-  $label_close = rcube_label('close');
-  $js_instance = JS_OBJECT_NAME;
+  $button = new html_inputfield(array('type' => 'button', 'class' => 'button'));
   
-  $out = <<<EOF
-<div$attrib_str>
-<form action="./" method="post" enctype="multipart/form-data">
-$SESS_HIDDEN_FIELD
-$input_field<br />
-<input type="button" value="$label_close" class="button" onclick="document.getElementById('$attrib[id]').style.visibility='hidden'" />
-<input type="button" value="$label_send" class="button" onclick="$js_instance.command('send-attachment', this.form)" />
-</form>
-</div>
-EOF;
-
+  $out = html::div($attrib,
+    $OUTPUT->form_tag(array('name' => 'form', 'method' => 'post', 'enctype' => 'multipart/form-data')) .
+    rcmail_compose_attachment_field(array()) . html::br() .
+    $button->show(rcube_label('close'), array('onclick' => "document.getElementById('$attrib[id]').style.visibility='hidden'")) .
+    $button->show(rcube_label('upload'), array('onclick' => JS_OBJECT_NAME . ".command('send-attachment', this.form)"))
+  );
+  
   
   $OUTPUT->add_gui_object('uploadbox', $attrib['id']);
   return $out;
@@ -799,9 +795,13 @@
 
   // determine whether HTML or plain text should be checked 
   if ($CONFIG['htmleditor'])
+    {
     $useHtml = true;
+    }
   else
+    {
     $useHtml = false;
+    }
 
   if ($compose_mode == RCUBE_COMPOSE_REPLY ||
       $compose_mode == RCUBE_COMPOSE_FORWARD ||
@@ -811,23 +811,19 @@
     $useHtml = ($hasHtml && $CONFIG['htmleditor']);
   }
 
+  $chosenvalue = $useHtml ? 'html' : 'plain';
+
   $selector = '';
   
   $attrib['name'] = '_editorSelect';
-  $attrib['onchange'] = 'return rcmail_toggle_editor(this)';
+  $attrib['onclick'] = 'return rcmail_toggle_editor(this)';
   foreach ($choices as $value => $text)
   {
-    $checked = '';
-    if ((($value == 'html') && $useHtml) ||
-        (($value != 'html') && !$useHtml))
-      $attrib['checked'] = 'true';
-    else
-      unset($attrib['checked']);
-
     $attrib['id'] = '_' . $value;
+    $attrib['value'] = $value;
     $rb = new html_radiobutton($attrib);
     $selector .= sprintf("%s<label for=\"%s\">%s</label>",
-                         $rb->show($value),
+                         $rb->show($chosenvalue),
                          $attrib['id'],
                          rcube_label($text));
   }
@@ -838,16 +834,15 @@
 
 function get_form_tags($attrib)
 {
-  global $CONFIG, $OUTPUT, $MESSAGE_FORM, $SESS_HIDDEN_FIELD;  
+  global $RCMAIL, $MESSAGE_FORM;
 
   $form_start = '';
   if (!strlen($MESSAGE_FORM))
   {
-    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
+    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
     $hiddenfields->add(array('name' => '_action', 'value' => 'send'));
 
-    $form_start = empty($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
-    $form_start .= "\n$SESS_HIDDEN_FIELD\n";
+    $form_start = empty($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
     $form_start .= $hiddenfields->show();
   }
     
@@ -855,7 +850,7 @@
   $form_name = !empty($attrib['form']) ? $attrib['form'] : 'form';
   
   if (!strlen($MESSAGE_FORM))
-    $OUTPUT->add_gui_object('messageform', $form_name);
+    $RCMAIL->output->add_gui_object('messageform', $form_name);
   
   $MESSAGE_FORM = $form_name;
 
@@ -923,4 +918,4 @@
  	$OUTPUT->set_env('contacts', $a_contacts); 
   } 
 $OUTPUT->send('compose');
-?>
\ No newline at end of file
+?>

--
Gitblit v1.9.1