[Jaws-commits] r13196 - in branches/0.8/html/gadgets/Contact: . images languages resources schema templates

afz at jaws-project.com afz at jaws-project.com
Thu Aug 2 05:53:26 UTC 2012


Author: afz
Date: 2012-08-02 05:53:25 +0000 (Thu, 02 Aug 2012)
New Revision: 13196

Added:
   branches/0.8/html/gadgets/Contact/images/attachment.png
Modified:
   branches/0.8/html/gadgets/Contact/Actions.php
   branches/0.8/html/gadgets/Contact/AdminAjax.php
   branches/0.8/html/gadgets/Contact/AdminHTML.php
   branches/0.8/html/gadgets/Contact/Package.php
   branches/0.8/html/gadgets/Contact/languages/en.php
   branches/0.8/html/gadgets/Contact/resources/script.js
   branches/0.8/html/gadgets/Contact/resources/style.css
   branches/0.8/html/gadgets/Contact/resources/style.rtl.css
   branches/0.8/html/gadgets/Contact/schema/schema.xml
   branches/0.8/html/gadgets/Contact/templates/AdminMailer.html
Log:
[Contact]: Added attachment support to Mailer(by Mohsen)

Modified: branches/0.8/html/gadgets/Contact/Actions.php
===================================================================
--- branches/0.8/html/gadgets/Contact/Actions.php	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/Actions.php	2012-08-02 05:53:25 UTC (rev 13196)
@@ -27,3 +27,5 @@
 $actions['Recipients']    = array('AdminAction');
 $actions['Properties']    = array('AdminAction');
 $actions['Mailer']        = array('AdminAction');
+$actions['UploadFile']    = array('StandaloneAdminAction');
+

Modified: branches/0.8/html/gadgets/Contact/AdminAjax.php
===================================================================
--- branches/0.8/html/gadgets/Contact/AdminAjax.php	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/AdminAjax.php	2012-08-02 05:53:25 UTC (rev 13196)
@@ -287,11 +287,11 @@
      * @param   string  $message    Message body of the Email
      * @return  boolean  true on success or false on failure
      */
-    function SendEmail($target, $subject, $message)
+    function SendEmail($target, $subject, $message, $attachment)
     {
         $this->CheckSession('Contact', 'AccessToMailer');
         $gadget = $GLOBALS['app']->LoadGadget('Contact', 'AdminHTML');
-        $gadget->SendEmail($target, $subject, $message);
+        $gadget->SendEmail($target, $subject, $message, $attachment);
         return $GLOBALS['app']->Session->PopLastResponse();
     }
 

Modified: branches/0.8/html/gadgets/Contact/AdminHTML.php
===================================================================
--- branches/0.8/html/gadgets/Contact/AdminHTML.php	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/AdminHTML.php	2012-08-02 05:53:25 UTC (rev 13196)
@@ -781,6 +781,22 @@
         $label->SetID('');
         $tpl->SetVariable('lbl_subject', $label->Get());
 
+        // Attachment
+        $entry =& Piwi::CreateWidget('FileEntry', 'attachment', '');
+        $entry->SetID('attachment');
+        $entry->SetSize(1);
+        $entry->AddEvent(ON_CHANGE, 'uploadFile();');
+        $tpl->SetVariable('attachment', $entry->Get());
+        $label =& Piwi::CreateWidget('Label', _t('CONTACT_MAILER_ATTACHMENT'), $entry);
+        $tpl->SetVariable('lbl_attachment', $label->Get());
+
+        $button =& Piwi::CreateWidget('Button', 'btn_upload', '', 'gadgets/Contact/images/attachment.png');
+        $tpl->SetVariable('btn_upload', $button->Get());
+
+        // $button =& Piwi::CreateWidget('Button', 'btn_remove', '', STOCK_DELETE);
+        // $button->AddEvent(ON_CLICK, 'removeAttachment()');
+        // $tpl->SetVariable('btn_remove', $button->Get());
+
         // Message
         $editor =& $GLOBALS['app']->LoadEditor('Contact', 'message');
         $editor->setID('message');
@@ -822,6 +838,28 @@
     }
 
     /**
+     * Uploads attachment file
+     *
+     * @access  public
+     * @return  
+     */
+    function UploadFile()
+    {
+        $res = Jaws_Utils::UploadFiles($_FILES, Jaws_Utils::upload_tmp_dir());
+        if (Jaws_Error::IsError($res)) {
+            $response = array('type'    => 'error',
+                              'message' => $res->getMessage());
+        } else {
+            $response = array('type'    => 'notice',
+                              'filename' => $res['attachment'],
+                              'filesize' => Jaws_Utils::FormatSize($_FILES['attachment']['size']));
+        }
+
+        $response = $GLOBALS['app']->UTF8->json_encode($response);
+        return "<script type='text/javascript'>parent.onUpload($response);</script>";
+    }
+
+    /**
      * Prepares the message body of the Email
      *
      * @access  public
@@ -867,7 +905,7 @@
      * @param   string  $message    Message body of the Email
      * @return  string HTML content
      */
-    function SendEmail($target, $subject, $message)
+    function SendEmail($target, $subject, $message, $attachment)
     {
         $this->CheckPermission('AccessToMailer');
         require_once JAWS_PATH . 'include/Jaws/Mail.php';
@@ -915,6 +953,13 @@
         $message = $this->PrepareMessage($message);
         $format = $GLOBALS['app']->Registry->Get('/gadgets/Contact/email_format');
         $mail->SetBody($message, $format);
+        if (!empty($attachment)) {
+            $attachment = Jaws_Utils::upload_tmp_dir() . '/' . $attachment;
+            if (file_exists($attachment)) {
+                $mail->SetBody($attachment, 'file');
+                Jaws_Utils::Delete($attachment);
+            }
+        }
 
         $result = $mail->send();
         if (Jaws_Error::IsError($result)) {

Modified: branches/0.8/html/gadgets/Contact/Package.php
===================================================================
--- branches/0.8/html/gadgets/Contact/Package.php	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/Package.php	2012-08-02 05:53:25 UTC (rev 13196)
@@ -12,7 +12,7 @@
               'license' => 'GPL',
               'authors' => array(array('lead', 'ion', 'Jonathan Hernandez', 'ion at suavizado.com'),
                                  array('lead', 'ali', 'Ali Fazelzadeh', 'afz at php.net'),
+                                 array('developer', 'mkh', 'Mohsen Khahani', 'mohsen at khahani.com')
                                  ),
               'deps'    => array(),
               );
-?>
\ No newline at end of file

Added: branches/0.8/html/gadgets/Contact/images/attachment.png
===================================================================
(Binary files differ)


Property changes on: branches/0.8/html/gadgets/Contact/images/attachment.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/0.8/html/gadgets/Contact/languages/en.php
===================================================================
--- branches/0.8/html/gadgets/Contact/languages/en.php	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/languages/en.php	2012-08-02 05:53:25 UTC (rev 13196)
@@ -99,6 +99,8 @@
 define('_EN_CONTACT_MAILER_FROM', "From");
 define('_EN_CONTACT_MAILER_SUBJECT', "Subject");
 define('_EN_CONTACT_MAILER_MESSAGE', "Message");
+define('_EN_CONTACT_MAILER_ATTACHMENT', "Attachment");
+define('_EN_CONTACT_MAILER_REMOVE_ATTACHMENT', "Remove");
 define('_EN_CONTACT_MAILER_BUTTON_NEW', "New");
 define('_EN_CONTACT_MAILER_BUTTON_PREVIEW', "Preview");
 define('_EN_CONTACT_MAILER_BUTTON_SEND', "Send");

Modified: branches/0.8/html/gadgets/Contact/resources/script.js
===================================================================
--- branches/0.8/html/gadgets/Contact/resources/script.js	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/resources/script.js	2012-08-02 05:53:25 UTC (rev 13196)
@@ -70,7 +70,7 @@
 
     sendemail: function(response) {
         if (response[0]['css'] == 'notice-message') {
-            $('frm_email').reset();
+            newEmail();
         }
         showResponse(response);
     }
@@ -406,12 +406,99 @@
  */
 function newEmail()
 {
-    $('frm_email').reset();
-    $('options_1').checked = true;
-    switchEmailTarget(1);
+    $('groups').value = 0;
+    $('users').value = 0;
+    $('to').value = '';
+    $('cc').value = '';
+    $('bcc').value = '';
+    $('from').value = '';
+    $('subject').value = '';
+    $('message').value = '';
+    $('filename').value = '';
+    $('frm_file').reset();
+
+    $('attachment').show();
+    $('btn_upload').show();
+    $('attach_loading').hide();
+    $('btn_remove').hide();
+    $('file_link').hide();
+    $('file_size').hide();
+    toggleDisableForm(false);
 }
 
 /**
+ * Disables/Enables form elements
+ */
+function toggleDisableForm(disabled)
+{
+    $('options_1').disabled   = disabled;
+    $('options_2').disabled   = disabled;
+    $('to').disabled          = disabled;
+    $('cc').disabled          = disabled;
+    $('bcc').disabled         = disabled;
+    $('groups').disabled      = disabled;
+    $('users').disabled       = disabled;
+    $('subject').disabled     = disabled;
+    $('message').disabled     = disabled;
+    $('btn_send').disabled    = disabled;
+    $('btn_preview').disabled = disabled;
+    $('btn_new').disabled     = disabled;
+}
+
+/**
+ * Uploads the attachment file
+ */
+function uploadFile() {
+    showWorkingNotification();
+    var iframe = new Element('iframe', {id:'ifrm_upload', name:'ifrm_upload'});
+    $('send_email').insert(iframe);
+    $('attachment').hide();
+    $('btn_upload').hide();
+    $('attach_loading').show();
+    toggleDisableForm(true);
+    $('frm_file').submit();
+}
+
+/**
+ * Sets the uploaded file as attachment
+ */
+function onUpload(response) {
+    hideWorkingNotification();
+    toggleDisableForm(false);
+    if (response.type === 'error') {
+        alert(response.message);
+        $('frm_file').reset();
+        $('btn_upload').show();
+        $('attachment').show();
+    } else {
+        $('filename').value = response.filename;
+        $('file_link').update(response.filename);
+        $('file_size').update('(' + response.filesize + ')');
+        $('file_link').show();
+        $('file_size').show();
+        $('btn_remove').show();
+        $('attachment').hide();
+    }
+    $('attach_loading').hide();
+    $('ifrm_upload').remove();
+}
+
+/**
+ * Removes the attachment
+ */
+function removeAttachment() {
+    $('filename').value = '';
+    $('frm_file').reset();
+    $('btn_remove').hide();
+    $('file_link').hide();
+    $('file_size').hide();
+    $('file_link').update('');
+    $('file_size').update('');
+    $('btn_upload').show();
+    $('attachment').show();
+}
+
+/**
  * Opens popup window with a preview of the message body
  */
 function previewMessage()
@@ -438,8 +525,8 @@
             $('groups').focus();
             return;
         }
-        var target = {'group': $F('groups'),
-                      'user' : $F('users')};
+        var target = {'group': $('groups').value,
+                      'user' : $('users').value};
     } else {
         // Already we have isValidEmail() but validation becomes 
         // too complicated in case of 3 fields (to, cc, bcc) so let server do the job
@@ -448,9 +535,9 @@
             $('to').focus();
             return;
         }
-        var target = {'to' : $F('to'),
-                      'cc' : $F('cc'),
-                      'bcc': $F('bcc')};
+        var target = {'to' : $('to').value,
+                      'cc' : $('cc').value,
+                      'bcc': $('bcc').value};
     }
 
     if (!$('subject').present()) {
@@ -466,7 +553,7 @@
         return;
     }
 
-    contactAsync.sendemail(target, $F('subject'), body);
+    contactAsync.sendemail(target, $('subject').value, body, $('filename').value);
 }
 
 var contactAsync = new contactadminajax(ContactCallback);

Modified: branches/0.8/html/gadgets/Contact/resources/style.css
===================================================================
--- branches/0.8/html/gadgets/Contact/resources/style.css	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/resources/style.css	2012-08-02 05:53:25 UTC (rev 13196)
@@ -41,7 +41,7 @@
   display: block;
 }
 #send_email th {
-  width: 70px;
+  width: 85px;
   text-align: left;
 }
 #send_email select {
@@ -51,7 +51,7 @@
   margin: 5px 0;
 }
 #send_email input[type=text] {
-  width: 450px;
+  width: 435px;
   margin: 2px 0;
 }
 #send_email textarea {
@@ -63,13 +63,47 @@
 #send_email label {
   margin-top: 10px;
 }
+#send_email .options {
+  margin-bottom: 10px;
+}
 #send_email .options label {
   margin: 0 5px;
 }
-#frm_email {
-  margin-top: 10px;
+#ifrm_upload {
+  display: none;
 }
-
+#frm_file {
+  padding: 5px 0;
+}
+#frm_file .actions {
+  position: relative;
+}
+#frm_file .actions button {
+  width: 24px;
+  height: 24px;
+  margin: 0;
+}
+#frm_file .wrapper {
+  position: absolute;
+  top: 0;
+  width: 24px;
+  height: 24px;
+  overflow: hidden;
+}
+#frm_file .wrapper input {
+  margin: 0;
+  font-size: 30px;
+  opacity: 0;
+  filter: alpha(opacity=0);
+}
+#file_size {
+  font-style: italic;
+  color: #555;
+}
+a#btn_remove {
+  color: red;
+  text-decoration: none;
+}
 .buttons {
     text-align: right;
 }

Modified: branches/0.8/html/gadgets/Contact/resources/style.rtl.css
===================================================================
--- branches/0.8/html/gadgets/Contact/resources/style.rtl.css	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/resources/style.rtl.css	2012-08-02 05:53:25 UTC (rev 13196)
@@ -63,12 +63,12 @@
 #send_email label {
   margin-top: 10px;
 }
+#send_email .options {
+  margin-bottom: 10px;
+}
 #send_email .options label {
   margin: 0 5px;
 }
-#frm_email {
-  margin-top: 10px;
-}
 
 .buttons {
     text-align: left;

Modified: branches/0.8/html/gadgets/Contact/schema/schema.xml
===================================================================
--- branches/0.8/html/gadgets/Contact/schema/schema.xml	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/schema/schema.xml	2012-08-02 05:53:25 UTC (rev 13196)
@@ -18,6 +18,8 @@
             <name>user</name>
             <type>text</type>
             <length>48</length>
+            <notnull>false</notnull>
+            <default></default>
         </field>
 
         <field>

Modified: branches/0.8/html/gadgets/Contact/templates/AdminMailer.html
===================================================================
--- branches/0.8/html/gadgets/Contact/templates/AdminMailer.html	2012-08-02 00:14:27 UTC (rev 13195)
+++ branches/0.8/html/gadgets/Contact/templates/AdminMailer.html	2012-08-02 05:53:25 UTC (rev 13196)
@@ -2,25 +2,41 @@
 {menubar}
 <div id="send_email">
   <div class="options">{options}</div>
-  <form id="frm_email">
-    <table width="100%" border="0" cellpadding="0" cellspacing="0">
-      <tbody id="batch_mail">
-        <tr><th>{lbl_group}:</th><td>{groups}</td></tr>
-        <tr><th>{lbl_user}:</th><td>{users}</td></tr>
-      </tbody>
-      <tbody id="free_mail" style="display:none;">
-        <tr><th>{lbl_to}:</th><td>{to}</td></tr>
-        <tr><th>{lbl_cc}:</th><td>{cc}</td></tr>
-        <tr><th>{lbl_bcc}:</th><td>{bcc}</td></tr>
-      </tbody>
-      <tbody>
-        <tr><th>{lbl_from}:</th><td>{from}</td></tr>
-        <tr><th>{lbl_subject}:</th><td>{subject}</td></tr>
-        <tr><th colspan="2">{lbl_message}:</th></tr>
-        <tr><td colspan="2">{message}</td></tr>
-      </tbody>
-    </table>
-  </form>
+  <table width="100%" border="0" cellpadding="0" cellspacing="0">
+    <tbody id="batch_mail">
+      <tr><th>{lbl_group}:</th><td>{groups}</td></tr>
+      <tr><th>{lbl_user}:</th><td>{users}</td></tr>
+    </tbody>
+    <tbody id="free_mail" style="display:none;">
+      <tr><th>{lbl_to}:</th><td>{to}</td></tr>
+      <tr><th>{lbl_cc}:</th><td>{cc}</td></tr>
+      <tr><th>{lbl_bcc}:</th><td>{bcc}</td></tr>
+    </tbody>
+    <tbody>
+      <tr><th>{lbl_from}:</th><td>{from}</td></tr>
+      <tr><th>{lbl_subject}:</th><td>{subject}</td></tr>
+      <tr><th>{lbl_attachment}:</th>
+          <td>
+            <input type="hidden" name="filename" id="filename" value="" />
+            <form id="frm_file" name="frm_file" method="post"
+                  target="ifrm_upload" action="{base_script}"
+                  enctype="multipart/form-data" onsubmit="return true">
+              <input type="hidden" name="gadget" value="Contact" />
+              <input type="hidden" name="action" value="UploadFile" />
+              <div class="actions">
+                {btn_upload}
+                <img id="attach_loading" src="images/loading.gif" />
+                <a id="file_link"></a> <small id="file_size"></small>
+                <a id="btn_remove" href="javascript:removeAttachment()"><img src="images/stock/cancel.png" /></a>
+                <div class="wrapper">{attachment}</div>
+              </div>
+            </form>
+          </td>
+      </tr>
+      <tr><th colspan="2">{lbl_message}:</th></tr>
+      <tr><td colspan="2">{message}</td></tr>
+    </tbody>
+  </table>
   <div class="buttons" colspan="2">{btn_new}{btn_preview}{btn_send}</div>
 </div>
 <script type="text/javascript">
@@ -28,5 +44,7 @@
       groupHasNoUser         = "{groupHasNoUser}",
       incompleteMailerFields = "{incompleteMailerFields}";
   newEmail();
+  $('options_1').checked = true;
+  switchEmailTarget(1);
 </script>
 <!-- END mailer -->



More information about the Jaws-commits mailing list