Changeset 6071


Ignore:
Timestamp:
05/02/12 16:30:34 (12 years ago)
Author:
gustavo
Message:

Ticket #2676 - Falha ao anexar arquivo no expresso mail

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/js/draw_api.js

    r6047 r6071  
    36713671        content.find(".attachment td").filter(".value").prepend(DataLayer.render("../prototype/modules/mail/templates/attachment.ejs", {ID:ID})); 
    36723672        var fileUploadMSG = $('#fileupload_msg'+ID); 
    3673         var maxAttachmentSise = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false; 
     3673        var maxAttachmentSize = (preferences.max_attachment_size !== "" && preferences.max_attachment_size != 0) ? (parseInt(preferences.max_attachment_size.replace('M', '')) * 1048576 ) : false; 
    36743674 
    36753675        fileUploadMSG.find(".button-files-upload").fileupload({ 
    3676                 sequentialUploads: true, 
     3676                type: 'post', 
     3677                dataType : 'json', 
     3678                url: "../prototype/post.php", 
     3679                forceIframeTransport: true, 
     3680                formData: function(form) { 
     3681                        return [ 
     3682                                { 
     3683                                        name : "mailAttachment[0][source]", 
     3684                                        value : "files0" 
     3685                                }, 
     3686                                { 
     3687                                        name : "mailAttachment[0][disposition]", 
     3688                                        value : $(form[0]['attDisposition'+$(form[0]['abaID']).val()]).val() 
     3689                                }, 
     3690                                { 
     3691                                        name: "MAX_FILE_SIZE", 
     3692                                        value : maxAttachmentSize 
     3693                                } 
     3694                        ]; 
     3695                }, 
    36773696                add: function (e, data) { 
    36783697                         
    3679                         if(!maxAttachmentSise || data.files[0].size < maxAttachmentSise || is_ie) { 
     3698                        if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize || is_ie) { 
    36803699                                setTimeout(function() { 
    3681                                         $('#attDisposition'+ID).val('attachment'); 
    3682                                         delete data.fileInput;  
     3700                    $('#attDisposition'+ID).val('attachment'); 
     3701                                        if(!data.fileInput){ 
     3702                                                $(fileUploadMSG).find("input")[0].files = data.files; 
     3703                                                data['fileInput'] = $(fileUploadMSG).find("input"); 
     3704                                        } 
     3705                                        if(!data.form) 
     3706                                                data['form'] = fileUploadMSG.parents("form:first"); 
    36833707                                        data.submit(); 
    3684                                 }, 5000); 
     3708                                }, 3000); 
    36853709                        }                
    36863710                        var attach = {}; 
     
    36903714                                attach.fileName = data.files[0].name.substr(0, 32) + " ... " + data.files[0].name.substr(data.files[0].name.length-9, data.files[0].name.length); 
    36913715                        attach.fileSize = formatBytes(data.files[0].size); 
    3692                         if(maxAttachmentSise && data.files[0].size > maxAttachmentSise) 
    3693                                 attach.error = 'Tamanho de arquivo nao permitido!!' 
     3716                        data.files[0].size = 300; 
     3717                        if(maxAttachmentSize && data.files[0].size > maxAttachmentSize) 
     3718                                attach.error = 'Tamanho de arquivo nao permitido!!!' 
    36943719 
    36953720                        var upload = $(DataLayer.render("../prototype/modules/mail/templates/attachment_add_itemlist.ejs", {file : attach}));                            
     
    37083733                        fileUploadMSG.find('.attachments-list').append(upload); 
    37093734 
    3710                         if(!maxAttachmentSise || data.files[0].size < maxAttachmentSise) 
     3735                        if(!maxAttachmentSize || data.files[0].size < maxAttachmentSize) 
    37113736                            fileUploadMSG.find('.attachments-list').find('[type=file]').addClass('hidden');      
    37123737                        else 
     
    37153740                done: function(e, data){ 
    37163741                        if(!!data.result && data.result != "[]" ){ 
    3717                                 var newAttach = jQuery.parseJSON(data.result); 
    3718                                  
    3719                                 //Compatibilidade com Firefox3.6         
    3720                                 if(newAttach === null ) newAttach = jQuery.parseJSON(data.result.text()); 
    3721                                  
    3722                                 var newAttach = jQuery.parseJSON(data.result);                                
    3723                                 if(newAttach.rollback !== false) 
    3724                                 { 
    3725                                     fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>').find('.status-upload').addClass('ui-icon ui-icon-check'); 
    3726                                     addAttachment(ID,newAttach['mailAttachment'][0][0].id); 
    3727                                 } 
    3728                                 else                              
    3729                                   fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');    
     3742                                var newAttach = data.result;                              
     3743                                if(!newAttach.mailAttachment.error){ 
     3744                                        if(newAttach.rollback !== false) 
     3745                                        { 
     3746                                                fileUploadMSG.find('.in-progress:first').parents('p').append('<input type="hidden" name="fileId[]" value="'+newAttach['mailAttachment'][0][0].id+'"/>').find('.status-upload').addClass('ui-icon ui-icon-check'); 
     3747                                                addAttachment(ID,newAttach['mailAttachment'][0][0].id); 
     3748                                        } 
     3749                                        else                              
     3750                                                fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error');    
     3751                                }else{ 
     3752                                        fileUploadMSG.find('.in-progress:first').parents('p').find('.status-upload').append(newAttach.mailAttachment.error).addClass('message-attach-error');    
     3753                                } 
    37303754                                 
    37313755                        }else { 
    37323756                                fileUploadMSG.find(' .progress.on-complete:first').parents('p').find('.status-upload').append('Erro ao fazer upload!').addClass('message-attach-error'); 
    37333757                        } 
    3734                         fileUploadMSG.find(' .in-progress:first').remove(); 
    3735                                  
    3736                      
     3758            fileUploadMSG.find(' .in-progress:first').remove(); 
    37373759                } 
    37383760        }).find('[name="files[]"]').css({"height" : "20px", "width": "100px", "border-width": "0 0 0px 0px", "-moz-transform" : "none","-o-transform" : 'none'}); 
  • trunk/prototype/modules/mail/interceptors/Attachments.php

    r5637 r6071  
    55        public function encodeCreateAttachment( &$uri , &$params , &$criteria , $original ){             
    66            if(!isset($params['source'])) return false; 
     7                         
    78 
    89            if(isset($_FILES[$params['source']])) 
    910                $params =  $_FILES[$params['source']]; 
    10  
     11                                 
     12                                if($params['error'] !== 0){ 
     13                                        switch ($params['error']){ 
     14                                                case 1: 
     15                                                        throw  new Exception('Tamanho de arquivo nao permitido!!! (php.ini)');  
     16                                                case 2: 
     17                                                        throw  new Exception('Tamanho de arquivo nao permitido!!!');  
     18                                                case 3: 
     19                                                        throw  new Exception('Ocorreu um erro durante o upload');  
     20                                                case 4: 
     21                                                        throw  new Exception('Nao e um arquivo valido');  
     22                                        } 
     23                                } 
     24                                 
    1125                $params['owner'] = Config::me('uidNumber');  
    1226 
  • trunk/prototype/modules/mail/templates/attachment.ejs

    r5785 r6071  
    1 <form id="fileupload_msg<%=data.ID%>" class="fileupload" action="mailAttachment:detail" method="POST"> 
     1<div id="fileupload_msg<%=data.ID%>" class="fileupload" style="margin : 15px 0px -15px -10px;"> 
    22  <div class="row fileupload-buttonbar"> 
    33      <div class="button-files-upload"> 
     
    1717         </div> 
    1818        <br /> 
    19 </form> 
     19</div> 
  • trunk/prototype/post.php

    r5811 r6071  
    33 * com o source em base64 melhoria na performace. 
    44 */ 
     5 
    56$data = $_POST; 
     7         
    68if( count($_FILES) ) 
    79{ 
     
    1416                                $counter = count($files); 
    1517                                $files[$name.$counter] = array('name' => $file['name'][$counter],  
    16                                                                                                 'type' => $file['type'][$counter], 
    17                                                                                                 'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])), 
    18                                                                                                 'size' => $file['size'][$counter]); 
     18                                        'type' => $file['type'][$counter], 
     19                                        'source' => base64_encode(file_get_contents( $file['tmp_name'][$counter], $file['size'][$counter])), 
     20                                        'size' => $file['size'][$counter], 
     21                                        'error' => $file['error'][$counter] 
     22                                ); 
    1923                        } 
    2024                }else 
     
    2529} 
    2630 
     31if(isset($data['MAX_FILE_SIZE'])) 
     32        unset($data['MAX_FILE_SIZE']); 
     33         
    2734require_once "api/controller.php"; 
     35 
     36Controller::addFallbackHandler( 0, function($e){ throw $e; } ); 
    2837 
    2938$result = array(); 
     
    3342                $content = array($content); 
    3443                 
    35         foreach($content as $key => $value) 
    36                 $result[$concept][] =  isset($data['criteria']) ?  Controller::put( array( 'concept' => $concept ), $value, isset($data['criteria'])) : Controller::put( array( 'concept' => $concept ), $value); 
     44        foreach($content as $key => $value){ 
     45                try{ 
     46                        $result[$concept][] = Controller::put( array( 'concept' => $concept ), $value ); 
     47                }catch(Exception $e){ 
     48                        $result[$concept]['error'] = $e->getMessage();                   
     49                }  
     50        } 
    3751}        
    3852echo json_encode( $result ); 
Note: See TracChangeset for help on using the changeset viewer.