Changeset 6891


Ignore:
Timestamp:
07/27/12 14:47:35 (12 years ago)
Author:
acoutinho
Message:

Ticket #2966 - Notificao e resposta de tasks / codec de normalizacao impressao de eventos

Location:
sandbox/2.4.2-expresso1
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sandbox/2.4.2-expresso1/expressoMail1_2/js/main.js

    r6788 r6891  
    39073907                wfolders.makeWindow('null','import'); 
    39083908} 
    3909 function import_calendar(data){ 
    3910     var import_url = '$this.db_functions.import_vcard&msg_folder='+data; 
    3911     var logUser; 
    3912     var up; 
    3913     var owner; 
     3909 
     3910   function import_calendar(data){ 
     3911        var import_url = '$this.db_functions.import_vcard&msg_folder='+data; 
     3912        var logUser; 
     3913        var up; 
     3914        var owner; 
     3915        
     3916        //Verifica o contexto de importação 
     3917        var decodeOwner = function(){ 
     3918            
     3919            owner = User.me.id; 
     3920            var imapBox = openTab.imapBox[currentTab].split(cyrus_delimiter); 
     3921            if(imapBox.length > 1){ 
     3922                var user = DataLayer.get('user', {filter: ['=','uid',imapBox[1]]});              
     3923                owner = $.isArray(user) ? user[0].id : user.id; 
     3924            } 
     3925            
     3926            return owner; 
     3927        } 
     3928        
     3929        function handler_import_calendar(data){ 
     3930                if(data === true){ 
     3931                        write_msg(get_lang("The event was imported successfully.")); 
     3932                } 
     3933                else if( data['url'] ) 
     3934                { 
     3935                    var form = document.createElement( "form" ); 
    39143936     
    3915     //Verifica o contexto de importação 
    3916     var decodeOwner = function(){ 
    3917          
    3918         owner = User.me.id; 
    3919         var imapBox = openTab.imapBox[currentTab].split(cyrus_delimiter); 
    3920         if(imapBox.length > 1){ 
    3921             var user = DataLayer.get('user', {filter: ['=','uid',imapBox[1]]});              
    3922             owner = $.isArray(user) ? user[0].id : user.id; 
    3923         } 
    3924          
    3925         return owner; 
     3937                    form.setAttribute( "action", DEFAULT_URL + data['url'] + '&isPost=true' ); 
     3938                    form.setAttribute( "method", "POST" ); 
     3939     
     3940                    document.body.appendChild( form ); 
     3941     
     3942                    form.submit(); 
     3943                } 
     3944                else 
     3945                    write_msg(get_lang(data)); 
     3946        }    
     3947            if(defaultCalendar == "expressoCalendar" && $("#expressoCalendarid")[0]){ 
     3948                    import_implements_calendar(); 
     3949                    $( "#import-dialog" ).dialog({ 
     3950                            autoOpen: false, 
     3951                            height: 220, 
     3952                            modal: true, 
     3953                            resizable : false, 
     3954                            close: function(event) { 
     3955                                    event.stopPropagation(); 
     3956                            }, 
     3957                            closeOnEscape: true 
     3958                    }); 
     3959                    
     3960                    $.ajax({ 
     3961                            url: "controller.php?action="+import_url+'&from_ajax=true&id_user='+User.me.id+'&readable=true&cirus_delimiter='+cyrus_delimiter+'&analize=true&uidAccount='+decodeOwner(), 
     3962                            async: false, 
     3963                            success: function(data){ 
     3964                                            data = connector.unserialize(data); 
     3965     
     3966     
     3967                                            var createDialog = function(typeImport, propaget){ 
     3968                                                
     3969                                                    if(typeof(typeImport) == "object"){ 
     3970                                                        var calendarPermission = typeImport.calendar; 
     3971                                                        typeImport = typeImport.action; 
     3972                                                    } 
     3973                                                    
     3974                                                    switch(parseInt(typeImport)){ 
     3975                                                    case 1: 
     3976                                                    case 7: 
     3977                                                    case 10: 
     3978                                                        $("#select-agenda").html(''); 
     3979     
     3980                                                        var options = ''; 
     3981     
     3982                                                        if(typeImport == 10){ 
     3983                                                            for(var i = 0; i < calendarPermission.length; i++) 
     3984                                                                options += '<option value="'+calendarPermission[i]+'">'+Calendar.signatureOf[calendarPermission[i]].calendar.name+'</option>' 
     3985                                                        }else{ 
     3986                                                            for(var id in Calendar.signatures) 
     3987                                                               options += parseInt(Calendar.signatures[id].isOwner) ? '<option value="'+Calendar.signatures[id].calendar.id+'">'+Calendar.signatures[id].calendar.name+'</option>' : '';                                                    
     3988                                                        } 
     3989                                                        
     3990                                                        $("#select-agenda").append(options); 
     3991                                                        $("#select-agenda").css("display", "block"); 
     3992                                                        
     3993                                                        $("#import-dialog" ).dialog({ 
     3994                                                            buttons: { 
     3995                                                                Cancel: function() { 
     3996                                                                    $( this ).dialog( "close" ); 
     3997                                                                }, 
     3998                                                                "Importar" : function(){ 
     3999                                                                        $.ajax({ 
     4000                                                                            url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&status='+$("#select-status option:selected").val()+'&uidAccount='+decodeOwner(), 
     4001                                                                            success: function(msg){ 
     4002                                                                                var alt = ( (msg = connector.unserialize(msg)) == "ok") ? "Importado com sucesso para " : "Ocorreu um erro ao importar o evento para a agenda "; 
     4003                                                                                alert( alt + $("#select-agenda option:selected").text() ); 
     4004                                                                            } 
     4005                                                                        }); 
     4006                                                                        $( this ).dialog( "close" ); 
     4007                                                                } 
     4008                                                            } 
     4009                                                            }); 
     4010     
     4011                                                            if(typeImport == 7){ 
     4012                                                                $("#import-dialog").find('#select-status option[value=1]').attr('selected','selected').trigger('change'); 
     4013                                                                $("#import-dialog").find('#select-status').attr('disabled','disabled'); 
     4014                                                            } 
     4015                                                        break; 
     4016                                                    case 3: 
     4017                                                            $.ajax({ 
     4018                                                                    url: "controller.php?action="+import_url+'&from_ajax=true&selected=true', 
     4019                                                                    success: function(msg){ 
     4020                                                                            alert( ( ( connector.unserialize(msg)) == "ok") ? "Seu evento foi removido " : "Ocorreu um erro ao remover o evento" ); 
     4021                                                                    } 
     4022                                                            }); 
     4023                                                            return; 
     4024                                                            break;  
     4025                                                    case 5: 
     4026                                                            $.ajax({ 
     4027                                                                    url: "controller.php?action="+import_url+'&from_ajax=true&selected=true', 
     4028                                                                    success: function(msg){ 
     4029                                                                            alert( ( ( connector.unserialize(msg)) == "ok") ? "Seu evento foi Atualizado com sucesso" : "Ocorreu um erro ao atualizar evento" ); 
     4030                                                                    } 
     4031                                                            }); 
     4032                                                            return; 
     4033                                                            break;  
     4034                                                    case 6: 
     4035                                                            var acceptedSuggestion = confirm("Deseja atualizar o evento de acordo com a sugestão ?"); 
     4036                                                            $.ajax({ 
     4037                                                                    url: "controller.php?action="+import_url+'&from_ajax=true&id_user='+User.me.id+'&selected=true&cirus_delimiter='+cyrus_delimiter+'&acceptedSuggestion='+acceptedSuggestion+"&from="+document.getElementById('from_values_'+currentTab).value+'&uidAccount='+decodeOwner(), 
     4038                                                                    success: function(msg){ 
     4039                                                                            if(acceptedSuggestion) 
     4040                                                                                    alert( ( ( connector.unserialize(msg)) == "ok") ? "Evento atualizado com sucesso " : "Ocorreu um erro ao atualizar o evento" ); 
     4041                                                                    } 
     4042                                                            }); 
     4043                                                            return; 
     4044                                                            break; 
     4045                                                    case 9: 
     4046                                                            alert('Seu evento não possui alterações!'); 
     4047                                                            return; 
     4048                                                            break; 
     4049                                                    case 11: 
     4050                                                            alert('Este evento já fora importando por algum dos particpantes e já se encontra disponível em sua agenda compartilhada!'); 
     4051                                                            return; 
     4052                                                            break; 
     4053                                                    default: 
     4054                                                            up = true; 
     4055                                                            $("#select-agenda").css("display", "none"); 
     4056                                                            $("#import-dialog" ).children("p:first-child").css("display", "none"); 
     4057                                                            $("#import-dialog" ).dialog({ 
     4058                                                                    height: 160, 
     4059                                                                    title: 'Atualizar Evento', 
     4060                                                                    buttons: { 
     4061                                                                            Cancel: function() { 
     4062                                                                                    $( this ).dialog( "close" ); 
     4063                                                                            }, 
     4064                                                                       "Atualizar": function() { 
     4065                                                                                    
     4066                                                                                    $.ajax({ 
     4067                                                                                             url: "controller.php?action="+import_url+'&from_ajax=true&cirus_delimiter='+cyrus_delimiter+'&selected='+ (parseInt(typeImport) == 2 || parseInt(typeImport) == 4 ? 'true' : $("#select-agenda option:selected").val()) +'&status='+$("#select-status option:selected").val()+'&uidAccount='+decodeOwner(), 
     4068                                                                                             success: function(msg){ 
     4069                                                                                                            alert( ( (msg = connector.unserialize(msg)) == "ok") ? "Atualizado com sucesso" : "Ocorreu um erro ao atualizar o evento" ); 
     4070                                                                                            } 
     4071                                                                                    }); 
     4072                                                                                    $( this ).dialog( "close" ); 
     4073                                                                            } 
     4074                                                                    } 
     4075                                                            }); 
     4076                                                            $(".ui-dialog-buttonpane").find(".ui-button:last").children().html("Atualizar"); 
     4077                                                    } 
     4078                                                    $( "#import-dialog" ).dialog( "open" ); 
     4079                                                                                                                                    
     4080                                            }; 
     4081                                            createDialog(data, true); 
     4082                                    
     4083                    }, 
     4084                    beforeSend: function( jqXHR, settings ){ 
     4085                                            connector.showProgressBar(); 
     4086                                    }, 
     4087                                    complete: function( jqXHR, settings ){ 
     4088                                            connector.hideProgressBar(); 
     4089                                    } 
     4090                }); 
     4091                            
     4092                    } 
     4093                    else 
     4094                    { 
     4095                        if(confirm(get_lang("Do you confirm this import to your Calendar?"))){ 
     4096                            cExecute( import_url + "&from_ajax=true", handler_import_calendar); 
     4097                        } 
     4098                    } 
    39264099    } 
    3927      
    3928     function handler_import_calendar(data){ 
    3929             if(data === true){ 
    3930                     write_msg(get_lang("The event was imported successfully.")); 
    3931             } 
    3932             else if( data['url'] ) 
    3933             { 
    3934                 var form = document.createElement( "form" ); 
    3935  
    3936                 form.setAttribute( "action", DEFAULT_URL + data['url'] + '&isPost=true' ); 
    3937                 form.setAttribute( "method", "POST" ); 
    3938  
    3939                 document.body.appendChild( form ); 
    3940  
    3941                 form.submit(); 
    3942             } 
    3943             else 
    3944                 write_msg(get_lang(data)); 
    3945     }    
    3946         if(defaultCalendar == "expressoCalendar" && $("#expressoCalendarid")[0]){ 
    3947                 import_implements_calendar(); 
    3948                 $( "#import-dialog" ).dialog({ 
    3949                         autoOpen: false, 
    3950                         height: 220, 
    3951                         modal: true, 
    3952                         resizable : false, 
    3953                         close: function(event) { 
    3954                                 event.stopPropagation(); 
    3955                         }, 
    3956                         closeOnEscape: true 
    3957                 }); 
    3958                  
    3959                 $.ajax({ 
    3960                         url: "controller.php?action="+import_url+'&from_ajax=true&id_user='+User.me.id+'&readable=true&cirus_delimiter='+cyrus_delimiter+'&analize=true&uidAccount='+decodeOwner(), 
    3961                         async: false, 
    3962                         success: function(data){ 
    3963                                         data = connector.unserialize(data); 
    3964  
    3965  
    3966                                         var createDialog = function(typeImport, propaget){ 
    3967                                              
    3968                                                 if(typeof(typeImport) == "object"){ 
    3969                                                     var calendarPermission = typeImport.calendar; 
    3970                                                     typeImport = typeImport.action; 
    3971                                                 } 
    3972                                                  
    3973                                                 switch(parseInt(typeImport)){ 
    3974                                                 case 1: 
    3975                                                 case 7: 
    3976                                                 case 10: 
    3977                                                     $("#select-agenda").html(''); 
    3978  
    3979                                                     var options = ''; 
    3980  
    3981                                                     if(typeImport == 10){ 
    3982                                                         for(var i = 0; i < calendarPermission.length; i++) 
    3983                                                             options += '<option value="'+calendarPermission[i]+'">'+Calendar.signatureOf[calendarPermission[i]].calendar.name+'</option>' 
    3984                                                     }else{ 
    3985                                                         for(var id in Calendar.signatures) 
    3986                                                            options += parseInt(Calendar.signatures[id].isOwner) ? '<option value="'+Calendar.signatures[id].calendar.id+'">'+Calendar.signatures[id].calendar.name+'</option>' : '';                                                     
    3987                                                     } 
    3988                                                      
    3989                                                     $("#select-agenda").append(options); 
    3990                                                     $("#select-agenda").css("display", "block"); 
    3991                                                      
    3992                                                     $("#import-dialog" ).dialog({ 
    3993                                                         buttons: { 
    3994                                                             Cancel: function() { 
    3995                                                                 $( this ).dialog( "close" ); 
    3996                                                             }, 
    3997                                                             "Importar" : function(){ 
    3998                                                                     $.ajax({ 
    3999                                                                         url: "controller.php?action="+import_url+'&from_ajax=true&selected='+$("#select-agenda option:selected").val()+'&status='+$("#select-status option:selected").val()+'&uidAccount='+decodeOwner(), 
    4000                                                                         success: function(msg){ 
    4001                                                                             var alt = ( (msg = connector.unserialize(msg)) == "ok") ? "Importado com sucesso para " : "Ocorreu um erro ao importar o evento para a agenda "; 
    4002                                                                             alert( alt + $("#select-agenda option:selected").text() ); 
    4003                                                                         } 
    4004                                                                     }); 
    4005                                                                     $( this ).dialog( "close" ); 
    4006                                                             } 
    4007                                                         } 
    4008                                                         }); 
    4009  
    4010                                                         if(typeImport == 7){ 
    4011                                                             $("#import-dialog").find('#select-status option[value=1]').attr('selected','selected').trigger('change'); 
    4012                                                             $("#import-dialog").find('#select-status').attr('disabled','disabled'); 
    4013                                                         } 
    4014                                                     break; 
    4015                                                 case 3: 
    4016                                                         $.ajax({ 
    4017                                                                 url: "controller.php?action="+import_url+'&from_ajax=true&selected=true', 
    4018                                                                 success: function(msg){ 
    4019                                                                         alert( ( ( connector.unserialize(msg)) == "ok") ? "Seu evento foi removido " : "Ocorreu um erro ao remover o evento" ); 
    4020                                                                 } 
    4021                                                         }); 
    4022                                                         return; 
    4023                                                         break;   
    4024                                                 case 5: 
    4025                                                         $.ajax({ 
    4026                                                                 url: "controller.php?action="+import_url+'&from_ajax=true&selected=true', 
    4027                                                                 success: function(msg){ 
    4028                                                                         alert( ( ( connector.unserialize(msg)) == "ok") ? "Seu evento foi Atualizado com sucesso" : "Ocorreu um erro ao atualizar evento" ); 
    4029                                                                 } 
    4030                                                         }); 
    4031                                                         return; 
    4032                                                         break;   
    4033                                                 case 6: 
    4034                                                         var acceptedSuggestion = confirm("Deseja atualizar o evento de acordo com a sugestão ?"); 
    4035                                                         $.ajax({ 
    4036                                                                 url: "controller.php?action="+import_url+'&from_ajax=true&id_user='+User.me.id+'&selected=true&cirus_delimiter='+cyrus_delimiter+'&acceptedSuggestion='+acceptedSuggestion+"&from="+document.getElementById('from_values_'+currentTab).value, 
    4037                                                                 success: function(msg){ 
    4038                                                                         if(acceptedSuggestion) 
    4039                                                                                 alert( ( ( connector.unserialize(msg)) == "ok") ? "Evento atualizado com sucesso " : "Ocorreu um erro ao atualizar o evento" ); 
    4040                                                                 } 
    4041                                                         }); 
    4042                                                         return; 
    4043                                                         break; 
    4044                                                 case 9: 
    4045                                                         alert('Seu evento não possui alterações!'); 
    4046                                                         return; 
    4047                                                         break; 
    4048                                                 case 11: 
    4049                                                         alert('Este evento já fora importando por algum dos particpantes e já se encontra disponível em sua agenda compartilhada!'); 
    4050                                                         return; 
    4051                                                         break; 
    4052                                                 default: 
    4053                                                         up = true; 
    4054                                                         $("#select-agenda").css("display", "none"); 
    4055                                                         $("#import-dialog" ).children("p:first-child").css("display", "none"); 
    4056                                                         $("#import-dialog" ).dialog({ 
    4057                                                                 height: 160, 
    4058                                                                 title: 'Atualizar Evento', 
    4059                                                                 buttons: { 
    4060                                                                         Cancel: function() { 
    4061                                                                                 $( this ).dialog( "close" ); 
    4062                                                                         }, 
    4063                                                                    "Atualizar": function() { 
    4064                                                                                  
    4065                                                                                 $.ajax({ 
    4066                                                                                          url: "controller.php?action="+import_url+'&from_ajax=true&selected='+ (parseInt(typeImport) == 2 || parseInt(typeImport) == 4 ? 'true' : $("#select-agenda option:selected").val()) +'&status='+$("#select-status option:selected").val(), 
    4067                                                                                          success: function(msg){ 
    4068                                                                                                         alert( ( (msg = connector.unserialize(msg)) == "ok") ? "Atualizado com sucesso para " : "Ocorreu um erro ao atualizar o evento" ); 
    4069                                                                                         } 
    4070                                                                                 }); 
    4071                                                                                 $( this ).dialog( "close" ); 
    4072                                                                         } 
    4073                                                                 } 
    4074                                                         }); 
    4075                                                         $(".ui-dialog-buttonpane").find(".ui-button:last").children().html("Atualizar"); 
    4076                                                 } 
    4077                                                 $( "#import-dialog" ).dialog( "open" );  
    4078                                                                                                                                  
    4079                                         }; 
    4080                                         createDialog(data, true); 
    4081                                  
    4082                 }, 
    4083                 beforeSend: function( jqXHR, settings ){ 
    4084                                         connector.showProgressBar(); 
    4085                                 }, 
    4086                                 complete: function( jqXHR, settings ){ 
    4087                                         connector.hideProgressBar(); 
    4088                                 } 
    4089             }); 
    4090                          
    4091                 } 
    4092                 else 
    4093                 { 
    4094                     if(confirm(get_lang("Do you confirm this import to your Calendar?"))){ 
    4095                         cExecute( import_url + "&from_ajax=true", handler_import_calendar); 
    4096                     } 
    4097                 } 
    4098 } 
     4100 
    40994101function open_msg_part(data){ 
    41004102        var handler_open_msg_part = function (data) 
  • sandbox/2.4.2-expresso1/prototype/modules/calendar/interceptors/DBMapping.php

    r6876 r6891  
    820820     
    821821    static private function countMyCalendarsEvent($id, $owner) { 
    822                 $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'user', $owner), array('=', 'isOwner', '1')))); 
     822                $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'isOwner', '1'), array('=', 'user', $owner)))); 
    823823                $calendars = array(); 
    824824                foreach ($sig as $val) 
     
    939939 
    940940     public function createDefaultGroup(&$uri, &$result, &$criteria, $original) { 
    941         $existDefaultGroup = false; 
    942  
    943         foreach($result as $v){ 
    944             if($v['type'] == 1 && $v['calendar']['type'] == 1) 
    945                 $existDefaultGroup = true; 
    946         } 
    947  
    948         if(!$existDefaultGroup){ 
    949  
    950             $cal = array('name' => 'Sem grupo', 
    951                 'description' => 'Sem grupo', 
    952                 'timezone' => (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo', 
    953                 'dtstamp' => time() . '000', 
    954                 'type' => '1' 
    955             ); 
    956  
    957             $calCreated = Controller::create(array('concept' => 'calendar'), $cal); 
    958  
    959             $sig = array('user' => $_SESSION['wallet']['user']['uidNumber'], 
    960                 'calendar' => $calCreated['id'], 
    961                 'isOwner' => '1', 
    962                 'dtstamp' => time() . '000', 
    963                 'fontColor' => 'FFFFFF', 
    964                 'backgroundColor' => '3366CC', 
    965                 'borderColor' => '3366CC', 
    966                 'type' => '1' 
    967             ); 
    968  
    969             $sigCreated = Controller::create(array('concept' => 'calendarSignature'), $sig); 
    970             $sigCreated = Controller::read(array('concept' => 'calendarSignature', 'id' => $sigCreated['id']), false, array('deepness' => 2 )); 
    971  
    972             array_push($result, $sigCreated); 
    973  
     941        if( $original['criteria']['filter'][1][0] == '=' && 
     942        $original['criteria']['filter'][1][1] == 'user' && 
     943        $original['criteria']['filter'][1][2] == $_SESSION['phpgw_session']['account_id']){ 
     944 
     945            $existDefaultGroup = false; 
     946 
     947            foreach($result as $v){ 
     948                if($v['type'] == 1 && $v['calendar']['type'] == 1) 
     949                    $existDefaultGroup = true; 
     950            } 
     951 
     952            if(!$existDefaultGroup){ 
     953 
     954                $cal = array('name' => 'Sem grupo', 
     955                    'description' => 'Sem grupo', 
     956                    'timezone' => (date_default_timezone_get()) ? date_default_timezone_get() : 'America/Sao_Paulo', 
     957                    'dtstamp' => time() . '000', 
     958                    'type' => '1' 
     959                ); 
     960 
     961                $calCreated = Controller::create(array('concept' => 'calendar'), $cal); 
     962 
     963                $sig = array('user' => $_SESSION['wallet']['user']['uidNumber'], 
     964                    'calendar' => $calCreated['id'], 
     965                    'isOwner' => '1', 
     966                    'dtstamp' => time() . '000', 
     967                    'fontColor' => 'FFFFFF', 
     968                    'backgroundColor' => '3366CC', 
     969                    'borderColor' => '3366CC', 
     970                    'type' => '1' 
     971                ); 
     972 
     973                $sigCreated = Controller::create(array('concept' => 'calendarSignature'), $sig); 
     974                $sigCreated = Controller::read(array('concept' => 'calendarSignature', 'id' => $sigCreated['id']), false, array('deepness' => 2 )); 
     975 
     976                array_push($result, $sigCreated); 
     977            } 
    974978 
    975979        } 
  • sandbox/2.4.2-expresso1/prototype/modules/calendar/js/calendar.codecs.js

    r6885 r6891  
    10741074 
    10751075        return notArray ? res[0] : res; 
     1076    } 
     1077 
     1078}); 
     1079 
     1080 
     1081DataLayer.codec( "schedulable", "print", { 
     1082 
     1083    decoder: function( evtObj ){ 
     1084 
     1085    }, 
     1086 
     1087 
     1088    encoder: function( evtObj ){ 
     1089     
     1090    if(!(!!evtObj)) 
     1091        return undefined; 
     1092 
     1093    var notArray = false; 
     1094           
     1095    if( notArray = $.type(evtObj) !== "array" ) 
     1096        evtObj = [ evtObj ]; 
     1097 
     1098    var pref = User.preferences; 
     1099    var res = []; 
     1100 
     1101    for(var i = 0; i < evtObj.length; i++){ 
     1102       res.push(DataLayer.encode('schedulable:' + (evtObj[i].type == '1' ?  'preview' : 'task'), evtObj[i])); 
     1103    } 
     1104 
     1105    if( !notArray ){ 
     1106        var dates = {}; 
     1107 
     1108        var typeRepeat = { 
     1109        'none': false,  
     1110        'daily': 'Repetição diária', 
     1111        'weekly': 'Repetição semanal', 
     1112        'monthly': 'Repetição mensal', 
     1113        'yearly': 'repetição anual' 
     1114        } 
     1115 
     1116        for (var i=0; i < res.length; i++) { 
     1117            var startDate = Date.parseExact( res[i]['startDate'], User.preferences.dateFormat ); 
     1118            var endDate   = Date.parseExact( res[i]['endDate'], User.preferences.dateFormat ); 
     1119                   
     1120            var duration = parseInt( endDate.getTime() ) - parseInt( startDate.getTime() ); 
     1121             
     1122            var occurrences = [ startDate.getTime() ]; 
     1123                     
     1124            if( res[i].occurrences ) 
     1125            { 
     1126                occurrences = res[i].occurrences; 
     1127            } 
     1128 
     1129            for( var ii = 0; ii < occurrences.length; ii++ ) 
     1130            { 
     1131                var currentDate = new Date( occurrences[ii] ); 
     1132                var counter = currentDate.clone(); 
     1133                         
     1134                var res2 = $.extend( {}, res[i], { 
     1135                    'startDate': currentDate.toString( User.preferences.dateFormat ),  
     1136                    'endDate': new Date( occurrences[ii] + duration ).toString( User.preferences.dateFormat ) 
     1137                }); 
     1138 
     1139                if(res[i].repeat) 
     1140                    res2.repeat = typeRepeat[res[i].repeat.frequency]; 
     1141                       
     1142                var index = dateCalendar.dayNames[counter.getDay()] +' '+counter.toString('dd/MM'); 
     1143 
     1144                if(!dates[index] || !$.isArray(dates[index].events)) 
     1145                    dates[index] = {events:  []};                     
     1146 
     1147                dates[index].events.push(res2); 
     1148                   
     1149            } 
     1150        } 
     1151 
     1152        var calendarView = $('#calendar').fullCalendar('getView'); 
     1153        var start = calendarView.visStart.getTime(); 
     1154        var end = calendarView.visEnd.getTime(); 
     1155        var next = start; 
     1156        var response = []; 
     1157 
     1158        while (next){ 
     1159            var index = dateCalendar.dayNames[new Date(next).getDay()] +' '+ new Date(next).toString('dd/MM'); 
     1160             
     1161            var event = {}; 
     1162            event[index] = {events: dates[index] ? dates[index].events : false}; 
     1163 
     1164            response[response.length] = event; 
     1165            next = (next + 86400000) > end ? false : (next + 86400000); 
     1166        } 
     1167 
     1168 
     1169        res = {events: response}; 
     1170    } 
     1171 
     1172    return notArray ? res[0] : res; 
    10761173    } 
    10771174 
  • sandbox/2.4.2-expresso1/prototype/services/iCal.php

    r6528 r6891  
    122122                    break; 
    123123 
     124        case TASK_ID: 
     125 
     126            $todo = $ical->newComponent('todo'); 
     127 
     128            $todo->setProperty('summary', $v['summary']); 
     129            $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 
     130            $todo->setProperty('priority', $v['priority']); 
     131            $todo->setProperty('percent-complete', $v['percentage']); 
     132            $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 
     133 
     134            $timezone = new DateTimeZone('UTC'); 
     135            $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 
     136            $apTimezoneOBJ = new DateTimeZone($apTimezone); 
     137 
     138            $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 
     139            $sTime->setTimezone($apTimezoneOBJ); 
     140            $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 
     141            $eTime->setTimezone($apTimezoneOBJ); 
     142 
     143            if (isset($v['allDay']) && $v['allDay'] == 1) { 
     144                $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
     145                $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 
     146                //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 
     147            } else { 
     148                $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     149                $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     150                //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 
     151            } 
     152 
     153            if(isset($v['due']) && $v['due'] != ''){ 
     154                $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 
     155                $dueTime->setTimezone($apTimezoneOBJ); 
     156 
     157                $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     158            } 
     159             
     160            $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 
     161                    
     162            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
     163                $participants = $v['participants']; 
     164            else 
     165                $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 
     166             
     167            if (is_array($participants) && count($participants) > 0) 
     168                foreach ($participants as $ii => $vv) { 
     169                 
     170                    if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 
     171                    { 
     172                        if ($vv['isExternal'] == 1) 
     173                            $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 
     174                        else 
     175                            $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 
     176                    } 
     177                 
     178                    if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 
     179                    { 
     180                        $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 
     181                        if(is_array($alarms)) 
     182                            self::createAlarms($alarms, $todo); 
     183                    } 
     184                 
     185                } 
     186             
     187 
     188            if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 
     189                $this->createAttendee($v['participants'], $todo); 
     190 
     191            if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 
     192                $this->createAttachment($v['attachments'], $todo); 
     193 
     194            $todo->setProperty('uid', $v['uid']);   
     195             
     196            break; 
     197 
    124198                default: 
    125199                    break; 
     
    219293 
    220294    public function parse($data, $params = false) { 
    221         Config::regSet('noAlarm', TRUE); //Evita o envio de notificação 
     295        Config::regSet('noAlarm', TRUE); //Evita o envio de notificação 
    222296        $vcalendar = new icalCreator( ); 
    223297        $vcalendar->parse(trim($data)); 
     
    232306            $interation = array(); 
    233307            $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 
     308             
     309            ob_start(); 
     310            print_r(strtoupper($component->objName)); 
     311            $output = ob_get_clean(); 
     312            file_put_contents( "/tmp/acoutinho.log",  $output , FILE_APPEND); 
     313         
    234314 
    235315            switch (strtoupper($component->objName)) { 
     
    238318                    switch ($method) { 
    239319                        case 'PUBLISH': 
    240                             //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
     320                            //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
    241321                            if (!$schedulable = self::_getSchedulable($uid)) 
    242322                                $interation = self::_makeVEVENT($schedulable, $component, $params); 
     
    273353                                    } 
    274354 
    275                                     Config::regSet('noAlarm', FALSE); //reativa notificação 
     355                                    Config::regSet('noAlarm', FALSE); //reativa notificação 
    276356                                } else { 
    277357 
    278                                     if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     358                                    if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
    279359                                        $interation = self::_makeVEVENT($schedulable, $component, $params); 
    280360                                    else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 
    281361                                        //Ler melhor rfc sobre isto 3.2.2.2 
    282                                         //Aparentemente é para retornar um ical com o evento atualizado para o attende 
     362                                        //Aparentemente é para retornar um ical com o evento atualizado para o attende 
    283363                                    } 
    284364 
     
    289369                                        }else 
    290370                                            $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 
    291                                         //Verifica a importação de eventos em que não participo 
     371                                        //Verifica a importação de eventos em que não participo 
    292372                                        if ($pID) { 
    293373                                            $interation['participant://' . $pID]['status'] = $params['status']; 
     
    298378                                $interation = self::_makeVEVENT(array(), $component, $params); 
    299379 
    300                                 if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 
     380                                if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 
    301381 
    302382                                    /* Data de Inicio */ 
     
    316396                                        $sc['allDay'] = 1; 
    317397                                        $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
    318                                     } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     398                                    } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    319399                                        $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 
    320400                                    else { 
    321401                                        $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
    322402                                        if (strpos($params['prodid'], 'Outlook') !== false) { 
    323                                             //Se o ics veio em utc não aplicar horario de verão 
     403                                            //Se o ics veio em utc não aplicar horario de verão 
    324404                                            $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 
    325405                                            $sTime->setTimezone($objTimezone); 
    326                                             if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     406                                            if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
    327407                                                $sc['startTime'] = $sc['startTime'] - 3600000; 
    328408                                        } 
     
    335415                                    if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
    336416                                        $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
    337                                     else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     417                                    else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    338418                                        $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 
    339419                                    else { 
    340420                                        $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    341421                                        if (strpos($params['prodid'], 'Outlook') !== false) { 
    342                                             //Se o ics veio em utc não aplicar horario de verão 
     422                                            //Se o ics veio em utc não aplicar horario de verão 
    343423                                            $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 
    344424                                            $eTime->setTimezone($objTimezone); 
     
    527607                            else // Importar evento 
    528608                                $interation = self::_makeVEVENT(array(), $component, $params); 
    529  
    530  
    531  
    532609                            break; 
    533610                    } 
     
    536613                    $return[] = $interation; 
    537614                    break; 
    538                 case 'VTIMEZONE': 
    539  
    540  
    541                     break; 
     615                /***********************************************************************TODO*******************************************************************************/ 
     616        case 'VTODO': 
     617        switch ($method) { 
     618            case 'PUBLISH': 
     619                //Caso a tarefa não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 
     620                if (!$schedulable = self::_getSchedulable($uid)) 
     621                    $interation = self::_makeVEVENT($schedulable, $component, $params); 
     622                else{ 
     623                    $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 
     624                    array('AND', 
     625                        array('=', 'calendar', $params['calendar']), 
     626                        array('=', 'schedulable', $schedulable['id']) 
     627                    ))); 
     628 
     629                    if(!$links &&  !isset($links[0])) 
     630                        Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 
     631                } 
     632                break; 
     633 
     634            case 'REQUEST': 
     635                $schedulable = self::_getSchedulable($uid); 
     636 
     637                if ($schedulable) { //Caso tarefa exista 
     638                    if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 
     639                         
     640                        $calendarToSchedulable = array(); 
     641                        $calendarToSchedulable['calendar'] = $params['calendar']; 
     642                        $calendarToSchedulable['schedulable'] = $schedulable['id']; 
     643                        $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 
     644         
     645                        if (isset($params['status'])) { 
     646                            if($params['owner'] != Config::me("uidNumber")){                         
     647                                $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) );                         
     648                                $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 
     649                            }else 
     650                                $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 
     651                                $interation['participant://' . $pID]['status'] = $params['status']; 
     652                        } 
     653                        Config::regSet('noAlarm', FALSE); //reativa notificação 
     654                    } else { 
     655 
     656                        if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     657                            $interation = self::_makeVEVENT($schedulable, $component, $params); 
     658                        else if ($component->getProperty('sequence', false, false) === $schedulable['sequence']) { 
     659                        //Ler melhor rfc sobre isto 3.2.2.2 
     660                        //Aparentemente é para retornar um ical com o evento atualizado para o attende 
     661                        } 
     662 
     663                        if (isset($params['status'])) { 
     664                            if($params['owner'] != Config::me("uidNumber")){                         
     665                               $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) );                      
     666                                $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 
     667                            }else 
     668                                $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 
     669                            //Verifica a importação de eventos em que não participo 
     670                            if ($pID) { 
     671                                $interation['participant://' . $pID]['status'] = $params['status']; 
     672                            } 
     673                        } 
     674                    } 
     675                } else { // Importar tarefa 
     676                    $interation = self::_makeVEVENT(array(), $component, $params); 
     677 
     678                    if (strpos($params['prodid'], 'kigkonsult.se') !== false) { //envia notificação para fora 
     679 
     680                        /* Data de Inicio */ 
     681                        $startTime = $component->getProperty('dtstart', false, true); 
     682                        $tzid = isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 
     683 
     684                        /* Tiem zone do evento */    
     685                        if ($tzid) 
     686                            $sc['timezone'] = self::nomalizeTZID($tzid); 
     687                        else 
     688                            $sc['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 
     689 
     690                        $objTimezone = new DateTimeZone($sc['timezone']); 
     691 
     692                        if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 
     693                            $sc['allDay'] = 1; 
     694                            $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
     695                        } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz']))/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     696                            $sc['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID']) . '000'; 
     697                        else { 
     698                            $sc['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
     699                            if (strpos($params['prodid'], 'Outlook') !== false) { 
     700                                //Se o ics veio em utc não aplicar horario de verão 
     701                                $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), new DateTimeZone('UTC')); 
     702                                $sTime->setTimezone($objTimezone); 
     703                                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     704                                $sc['startTime'] = $sc['startTime'] - 3600000; 
     705                            } 
     706                        } 
     707 
     708                        /* Data de Termino */ 
     709                        $endTime = $component->getProperty('dtend', false, true); 
     710 
     711                        if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
     712                            $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $sc['timezone']) . '000'; 
     713                        else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     714                            $sc['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID']) . '000'; 
     715                        else { 
     716                            $sc['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
     717                            if (strpos($params['prodid'], 'Outlook') !== false) { 
     718                                //Se o ics veio em utc não aplicar horario de verão 
     719                                $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), new DateTimeZone('UTC')); 
     720                                $eTime->setTimezone($objTimezone); 
     721                                if ($eTime->format('I')) 
     722                                    $sc['endTime'] = $sc['endTime'] - 3600000; 
     723                            } 
     724                        } 
     725 
     726 
     727                        if ($uid = $component->getProperty('uid', false, false))                     
     728                            $sc['uid'] = $uid; 
     729 
     730                        $sc['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     731 
     732                        /* Definindo Description */ 
     733                        if ($desc = $component->getProperty('description', false, false)) 
     734                            $sc['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     735 
     736            if ($priority = $component->getProperty('priority', false, false)) 
     737                $sc['priority'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $priority), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     738 
     739            if ($status = $component->getProperty('status', false, false)) 
     740                $sc['status'] = $this->decodeStatusTodo(mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $status), 'UTF-8', 'UTF-8,ISO-8859-1')); 
     741 
     742            if ($percentage = $component->getProperty('percent-complete', false, false)) 
     743                $sc['percentage'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $percentage), 'UTF-8', 'UTF-8,ISO-8859-1'); 
     744 
     745            $todo->setProperty('priority', $v['priority']); 
     746            $todo->setProperty('percent-complete', $v['percentage']); 
     747            $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 
     748 
     749                        /* Definindo location */ 
     750                        if ($location = $component->getProperty('location', false, false)) 
     751                            $sc['location'] = mb_convert_encoding($location, 'UTF-8', 'UTF-8,ISO-8859-1'); 
     752 
     753 
     754 
     755                        if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 
     756                            $participant = array(); 
     757                            $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 
     758 
     759                            $participantID = mt_rand() . '2(Formatter)'; 
     760 
     761                            $participant['isOrganizer'] = '1'; 
     762 
     763                            $user = null; 
     764 
     765                            $participant['isExternal'] = 1; 
     766                            /* Gera um randon id para o contexto formater */ 
     767                            $userID = mt_rand() . '4(Formatter)'; 
     768 
     769                            $user['mail'] = $mailUser; 
     770                            $organizerMail = $mailUser; 
     771 
     772                            $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 
     773                            $user['isExternal'] = '1'; 
     774                            $participant['user'] = $user; 
     775 
     776                            $sc['participants'][] = $participant; 
     777                        } 
     778 
     779 
     780                        $participant['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 
     781                        $participant['isOrganizer'] = '0'; 
     782                        $participant['isExternal'] = 0; 
     783                        $participant['user'] = array('mail' => Config::me('mail'), 'name' => Config::me('cn')); 
     784                        $sc['participants'][] = $participant; 
     785                        $sc['type'] = TODO_ID; 
     786 
     787 
     788                        $ical['source'] = Controller::format(array('service' => 'iCal'), array($sc), array('method' => 'REPLY')); 
     789                        $ical['type'] = 'application/ics'; 
     790                        $ical['name'] = 'outlook.ics'; 
     791 
     792                        $ical2['source'] = $ical['source']; 
     793                        $ical2['type'] = 'text/calendar; method=REPLY'; 
     794                        $ical2['name'] = 'thunderbird.ics'; 
     795 
     796                        $timezone = new DateTimeZone('UTC'); 
     797                        $sTime = new DateTime('@' . (int) ($sc['startTime'] / 1000), $timezone); 
     798                        $eTime = new DateTime('@' . (int) ($sc['endTime'] / 1000), $timezone); 
     799 
     800                        if (isset($sc['timezone'])) { 
     801                            $sTime->setTimezone(new DateTimeZone($sc['timezone'])); 
     802                            $eTime->setTimezone(new DateTimeZone($sc['timezone'])); 
     803                        } 
     804 
     805                        $data = array('startDate' => date_format($sTime, 'd/m/Y'), 
     806                        'startTime' => (isset($sc['allDay']) && $sc['allDay'] ) ? '' : date_format($sTime, 'H:i'), 
     807                        'endDate' => date_format($eTime, 'd/m/Y'), 
     808                        'endTime' => isset($sc['allDay']) ? '' : date_format($eTime, 'H:i'), 
     809                        'eventTitle' => $sc['summary'], 
     810                        'eventLocation' => isset($sc['location']) ? $sc['location'] : '', 
     811                        'timezone' => ($sc['timezone']) ? $sc['timezone'] : 'UTC', 
     812                        'participant' => (isset($part['user']['name']) ? $part['user']['name'] : $part['user']['mail'])); 
     813 
     814                        $subject['notificationType'] = 'Convite Aceito'; 
     815                        $subject['eventTitle'] = mb_convert_encoding($sc['summary'], 'ISO-8859-1', 'ISO-8859-1,UTF-8'); 
     816                        $subject['startDate'] = date_format($sTime, 'd/m/Y'); 
     817                        $subject['startTime'] = ($sc['allDay']) ? '' : date_format($sTime, 'H:i'); 
     818                        $subject['endDate'] = date_format($eTime, 'd/m/Y'); 
     819                        $subject['endTime'] = ($sc['allDay']) ? '' : date_format($eTime, 'H:i'); 
     820                        $subject['participant'] = Config::me('uid'); 
     821 
     822                        $params['status'] = isset($params['status']) ? $params['status'] : STATUS_ACCEPTED; 
     823 
     824                        switch ($params['status']) { 
     825                            case STATUS_ACCEPTED: 
     826                                $tpl = 'notify_accept_body'; 
     827                                $subject['notificationType'] = 'Convite Aceito'; 
     828                                break; 
     829                            case STATUS_TENTATIVE: 
     830                                $tpl = 'notify_attempt_body'; 
     831                                $subject['notificationType'] = 'Convite  aceito provisoriamente'; 
     832                                break; 
     833                            case STATUS_CANCELLED: 
     834                                $tpl = 'notify_reject_body'; 
     835                                $subject['notificationType'] = 'Convite rejeitado'; 
     836                                break; 
     837                        } 
     838 
     839                        require_once ROOTPATH . '/api/parseTPL.php'; 
     840 
     841                        $mail = array(); 
     842                        $mail['attachments'][] = $ical; 
     843                        $mail['attachments'][] = $ical2; 
     844 
     845                        $mail['isHtml'] = true; 
     846                        $mail['body'] = parseTPL::load_tpl($data, ROOTPATH . '/modules/calendar/templates/' . $tpl . '.tpl'); 
     847                        $mail['subject'] = parseTPL::load_tpl($subject, ROOTPATH . '/modules/calendar/templates/notify_subject.tpl'); 
     848 
     849                        $mail['from'] = '"' . Config::me('cn') . '" <' . Config::me('mail') . '>'; 
     850                        $mail['to'] = $organizerMail; 
     851 
     852 
     853                        Controller::create(array('service' => 'SMTP'), $mail); 
     854                    } 
     855                } 
     856                break; 
     857 
     858            case 'REFRESH': 
     859                break; 
     860 
     861            case 'CANCEL': 
     862                if ($schedulable = self::_getSchedulable($uid)) 
     863                    $interation['schedulable://' . $schedulable['id']] = false; 
     864                break; 
     865 
     866            case 'ADD': 
     867                break; 
     868 
     869            case 'REPLY': 
     870                if ($schedulable = self::_getSchedulable($uid)) { 
     871                    while ($property = $component->getProperty('attendee', FALSE, TRUE)) 
     872                        if ($pID = self::_getParticipantByMail(str_replace('MAILTO:', '', $property['value']), $schedulable['participants'])) 
     873                            $interation['participant://' . $pID] = array('id' => $pID, 'status' => constant('STATUS_' . strtoupper($property['params']['PARTSTAT']))); 
     874 
     875                    $interation['schedulable://' . $schedulable['id']]['sequence'] = $schedulable['sequence'] + 1; 
     876                } 
     877                break; 
     878 
     879            case 'COUNTER': 
     880                if ($params['acceptedSuggestion'] !== 'false') { 
     881 
     882                    $schedulable = self::_getSchedulable($uid); 
     883                    $params['calendar'] = self::_existInMyCalendars($schedulable['id'], $params['owner']); 
     884 
     885                    $interation = self::_makeCOUNTER($schedulable, $component, $params); 
     886                    Config::regSet('noAlarm', FALSE); 
     887                } else { 
     888                    $response = array(); 
     889                    $response['from'] = $params['from']; 
     890                    $response['type'] = 'suggestionResponse'; 
     891                    $response['status'] = 'DECLINECOUNTER'; 
     892                    $response['schedulable'] = self::_getSchedulable($uid); 
     893 
     894                    Controller::create(array('concept' => 'notification'), $response); 
     895                } 
     896                break; 
     897 
     898            case 'DECLINECOUNTER': 
     899                break; 
     900 
     901            default: 
     902 
     903                $schedulable = self::_getSchedulable($uid); 
     904 
     905                if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) { //Caso o evento exista 
     906                    $interation = self::_makeVEVENT($schedulable, $component, $params); 
     907 
     908                    if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 
     909                        $calendarToSchedulable = array(); 
     910                        $calendarToSchedulable['calendar'] = $params['calendar']; 
     911                        $calendarToSchedulable['schedulable'] = $schedulable['id']; 
     912                        $interation['calendarToSchedulable://' . mt_rand() . '(Formatter)'] = $calendarToSchedulable; 
     913                    } 
     914                } 
     915                else // Importar evento 
     916                $interation = self::_makeVEVENT(array(), $component, $params); 
     917 
     918                break; 
     919            } 
     920     
     921            $return[] = $interation; 
     922        break; 
     923        /***********************************************************************TODO*******************************************************************************/ 
     924        case 'VTIMEZONE': 
     925                break; 
    542926            } 
    543927        } 
     
    556940            $interation = array(); 
    557941            $uid = $component->getProperty('uid', false, false); //Resgata o uid do componente 
    558  
    559942            switch (strtoupper($component->objName)) { 
    560943                case 'VEVENT': 
     
    583966                                        } 
    584967                                    } else { 
    585                                         if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     968                                        if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
    586969                                            $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 
    587970                                        else 
     
    6491032                    $return[$uid] = $interation; 
    6501033                    break; 
     1034                case 'VTODO': 
     1035                    switch ($method) { 
     1036                        case 'PUBLISH': 
     1037                            $interation = ICAL_ACTION_IMPORT; 
     1038                            break; 
     1039 
     1040                        case 'REQUEST': 
     1041                            $schedulable = self::_getSchedulable($uid); 
     1042                            
     1043                            if ($schedulable) { //Caso o evento exista 
     1044                                $isOrganizer = false; 
     1045                                $isParticipant = false; 
     1046 
     1047                                foreach ($schedulable['participants'] as $value) 
     1048                                    if ($value['user']['id'] == $params['owner']) { 
     1049                                        $isParticipant = true; 
     1050                                        if ($value['isOrganizer']) 
     1051                                            $isOrganizer = true; 
     1052 
     1053                                        if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 
     1054                                             
     1055                                            ob_start(); 
     1056                                            print_r($schedulable['id']); 
     1057                                            print_r( $params['owner']); 
     1058                                            $output = ob_get_clean(); 
     1059                                            file_put_contents( "/tmp/acoutinho.log",  $output , FILE_APPEND); 
     1060                                             
     1061                                            $interation = ICAL_ACTION_IMPORT; 
     1062                                            break; 
     1063                                        } 
     1064                                    } else { 
     1065                                        if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 
     1066                                            $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 
     1067                                        else 
     1068                                            $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; 
     1069                                    } 
     1070                                if (!$isParticipant){ 
     1071                                      $interation = self::_checkParticipantByPermissions($schedulable); 
     1072                                    } 
     1073                            }else 
     1074                                $interation = ICAL_ACTION_IMPORT; 
     1075                            break; 
     1076 
     1077                        case 'REFRESH': 
     1078                            break; 
     1079 
     1080                        case 'CANCEL': 
     1081                            $interation = ICAL_ACTION_DELETE; 
     1082                            break; 
     1083 
     1084                        case 'ADD': 
     1085                            break; 
     1086 
     1087                        case 'REPLY': 
     1088                            $interation = ICAL_ACTION_REPLY; 
     1089                            break; 
     1090 
     1091                        case 'COUNTER': 
     1092                            $interation = ICAL_ACTION_SUGGESTION; 
     1093                            break; 
     1094 
     1095                        case 'DECLINECOUNTER': 
     1096                            $interation = ICAL_ACTION_NONE; 
     1097                            break; 
     1098 
     1099                        default: 
     1100                            $schedulable = self::_getSchedulable($uid); 
     1101 
     1102                            if ($schedulable && ( self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence'])) //Caso o evento exista 
     1103                                $interation = ICAL_ACTION_UPDATE; 
     1104                            else if ($schedulable) 
     1105                                $interation = ICAL_ACTION_NONE; 
     1106                            else // Importar evento 
     1107                                $interation = ICAL_ACTION_IMPORT; 
     1108 
     1109                            break; 
     1110                    } 
     1111 
     1112                    $return[$uid] = $interation; 
     1113                    break; 
    6511114                case 'VTIMEZONE': 
    652  
    653  
    654                     break; 
     1115                break; 
    6551116            } 
    6561117        } 
     
    6901151    } 
    6911152 
     1153    public function decodeStatusTodo( $action ) 
     1154    { 
     1155     $a = array( 
     1156        'NEED_ACTION' => STATUS_TODO_NEED_ACTION, 
     1157        'IN_PROGRESS' => STATUS_TODO_IN_PROGRESS  , 
     1158        'COMPLETED' =>  STATUS_TODO_COMPLETED , 
     1159        'CANCELLED'  => STATUS_TODO_CANCELLED 
     1160    ); 
     1161 
     1162    return isset($a[$id]) ? $a[$id] : 'STATUS_TODO_NEED_ACTION'; 
     1163     
     1164    } 
     1165 
     1166 
     1167    private function _getStatusTodo($id) { 
     1168        $a = array( 
     1169            STATUS_TODO_NEED_ACTION => 'NEED_ACTION', 
     1170            STATUS_TODO_IN_PROGRESS => 'IN_PROGRESS', 
     1171            STATUS_TODO_COMPLETED => 'COMPLETED', 
     1172            STATUS_TODO_CANCELLED => 'CANCELLED' 
     1173        ); 
     1174 
     1175    return isset($a[$id]) ? $a[$id] : 'NEED_ACTION'; 
     1176    } 
     1177 
    6921178    private static function _checkParticipantByPermissions($schedulable) { 
    6931179 
     
    7681254            $schedulable['allDay'] = 1; 
    7691255            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    770         } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1256        } elseif (isset($startTime['params']['TZID']) && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    7711257            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $startTime['params']['TZID'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    7721258            $schedulable['allDay'] = 0; 
     
    7741260            $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
    7751261            if (strpos($params['prodid'], 'Outlook') !== false) { 
    776                 //Se o ics veio em utc não aplicar horario de verão 
     1262                //Se o ics veio em utc não aplicar horario de verão 
    7771263                $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 
    7781264                $sTime->setTimezone($objTimezone); 
    779                 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     1265                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
    7801266                    $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 
    7811267            } 
     
    7871273        if ($endTime['params']['VALUE'] === 'DATE') 
    7881274            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
    789         else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1275        else if (isset($endTime['params']['TZID']) && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    7901276            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $endTime['params']['TZID'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
    7911277        else { 
    7921278            $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    7931279            if (strpos($params['prodid'], 'Outlook') !== false) { 
    794                 //Se o ics veio em utc não aplicar horario de verão 
     1280                //Se o ics veio em utc não aplicar horario de verão 
    7951281                $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 
    7961282                $eTime->setTimezone($objTimezone); 
     
    8261312            $schedulable['allDay'] = 1; 
    8271313            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 
    828         } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1314        } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    8291315            $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 
    8301316            $schedulable['allDay'] = 0; 
     
    8321318            $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 
    8331319            if (strpos($params['prodid'], 'Outlook') !== false) { 
    834                 //Se o ics veio em utc não aplicar horario de verão 
     1320                //Se o ics veio em utc não aplicar horario de verão 
    8351321                $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 
    8361322                $sTime->setTimezone($objTimezone); 
    837                 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
     1323                if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 
    8381324                    $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 
    8391325            } 
     
    8501336        if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 
    8511337            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 
    852         else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
     1338        else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 
    8531339            $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 
    8541340        else { 
    8551341            $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 
    8561342            if (strpos($params['prodid'], 'Outlook') !== false) { 
    857                 //Se o ics veio em utc não aplicar horario de verão 
     1343                //Se o ics veio em utc não aplicar horario de verão 
    8581344                $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 
    8591345                $eTime->setTimezone($objTimezone); 
     
    8801366            $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 
    8811367        else if (!isset($schedulable['class'])) 
    882             $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 
     1368            $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 
    8831369 
    8841370        /* Definindo RRULE */ 
     
    9061392        $participantsInEvent = array(); 
    9071393 
    908         //TODO: Participants com delegated não estao sendo levados em conta 
     1394        //TODO: Participants com delegated não estao sendo levados em conta 
    9091395        while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 
    9101396            $participant = array(); 
     
    9231409            $participant['isOrganizer'] = '0'; 
    9241410 
    925             /* Verifica se este usuario é um usuario interno do ldap */ 
     1411            /* Verifica se este usuario é um usuario interno do ldap */ 
    9261412            $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 
    9271413 
     
    9581444            $participant['acl'] = 'rowi'; 
    9591445 
    960             /* Verifica se este usuario é um usuario interno do ldap */ 
     1446            /* Verifica se este usuario é um usuario interno do ldap */ 
    9611447            $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 
    9621448 
     
    9801466            $interation['participant://' . $participantID] = $participant; 
    9811467            $schedulable['participants'][] = $participantID; 
    982         } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 
     1468        } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 
    9831469            $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 
    9841470 
     
    10941580 
    10951581    static private function _existInMyCalendars($id, $owner) { 
    1096         $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'user', $owner), array('=', 'isOwner', '1')))); 
     1582        $sig = Controller::find(array('concept' => 'calendarSignature'), array('user', 'calendar', 'isOwner'), array('filter' => array('AND', array('=', 'isOwner', '1'), array('=', 'user', $owner)))); 
    10971583        $calendars = array(); 
    10981584        foreach ($sig as $val) 
Note: See TracChangeset for help on using the changeset viewer.