Ignore:
Timestamp:
11/03/11 13:21:19 (12 years ago)
Author:
wmerlotto
Message:

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo calendar.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/calendar/inc/class.bocalendar.inc.php

    r4935 r5132  
    9797                ); 
    9898 
    99                 var $wdays; 
    100  
    10199                var $debug = False; 
    102100//              var $debug = True; 
     
    111109                var $year; 
    112110                var $prefs; 
    113  
     111                var $wdays;  
    114112                var $owner; 
    115113                var $holiday_color; 
    116114                var $printer_friendly = False; 
    117  
     115                var $repetido; 
    118116                var $cached_holidays; 
    119117 
     
    142140        var $async = false; 
    143141 
     142                var $alreadyNotifieds; 
     143                var $alreadyExtNotifieds = array(); 
     144                 
     145                var $extAdded; 
     146                var $extDeleted; 
     147                 
    144148                function bocalendar($session=0) 
    145149                { 
     
    300304                                MCAL_RECUR_DAILY        => 'Daily', 
    301305                                MCAL_RECUR_WEEKLY       => 'Weekly', 
    302             //MCAL_RECUR_MONTHLY_WDAY   => 'Monthly (by day)', 
     306                                MCAL_RECUR_MONTHLY_WDAY => 'Monthly (by day)', 
    303307                                MCAL_RECUR_MONTHLY_MDAY => 'Monthly (by date)', 
    304308                                MCAL_RECUR_YEARLY       => 'Yearly' 
     
    382386                        $this->wdays = Array(MCAL_M_SUNDAY,MCAL_M_MONDAY,MCAL_M_TUESDAY,MCAL_M_WEDNESDAY, 
    383387                            MCAL_M_THURSDAY,MCAL_M_FRIDAY,MCAL_M_SATURDAY); 
    384                 } 
    385  
    386                 function delegar($idDelegador,$idDelegado,$idEvento) { 
    387  
    388                         $this->so->cal->stream->lock(array("phpgw_cal_user")); 
    389                          
    390                         if(substr($idDelegado,-1) == 'U') { 
    391                             $idDelegado = substr($idDelegado,0,-1); 
    392                         } 
    393  
    394                         $sql = "SELECT * FROM phpgw_cal_user where cal_id=$idEvento and cal_login=$idDelegado"; 
    395  
    396                         if($idDelegado != '') 
    397                         { 
    398                                 $this->so->cal->stream->query($sql,__LINE__,__FILE__); 
    399                                 if($this->so->cal->stream->next_record()) 
    400                                 { 
    401                                         throw new Exception("The selected User is already included in this event"); 
    402                                 }else{ 
    403                                         $sql = "update phpgw_cal_user set cal_login = $idDelegado,cal_status='U' where cal_id=$idEvento  
    404                                                 and cal_login=$idDelegador"; 
    405  
    406                                         $this->so->cal->stream->query($sql,__LINE__,__FILE__,0,-1,true); 
    407                                  
    408                                         $event = $this->so->read_entry($idEvento); 
    409  
    410                                         $this->send_update(MSG_ADDED,array($idDelegado => 'U'),$event,$event); 
    411                                 } 
    412                         }else { 
    413                                 throw new Exception('999'); 
    414                         } 
    415  
    416                         $this->so->cal->stream->unlock(); 
    417388                } 
    418389 
     
    656627//                              print_debug('exception time',$event['recur_exception'][count($event['recur_exception']) -1]); 
    657628//                              print_debug('count event exceptions',count($event['recur_exception'])); 
    658                                 $this->so->add_entry($event); 
     629                                $this->so->add_entry($event,true,$event['owner']); 
    659630                                $cd = 16; 
    660631 
     
    756727                                if($this->check_perms(PHPGW_ACL_DELETE,$event)) 
    757728                                { 
    758                                         $this->send_update(MSG_DELETED,$event['participants'],$event); 
     729                                        $this->send_update(MSG_DELETED,$event['participants'],$event,false,$event['owner']); 
    759730                                } 
    760731                                else 
     
    815786                    $participants = $event['participants']; 
    816787 
    817             //        $new_event = Array(); 
    818             //        $new_event['owner'] = $owner; 
    819             //        $new_event['participants'] = $participants; 
    820             //        $new_event['start'] = $event['start']; 
    821             //        $new_event['end'] = $event['end']; 
    822             // 
    823             //        $return[] = $new_event; 
    824788 
    825789                    switch($event['recur_type']) { 
     
    998962                function update($params='') 
    999963                { 
     964                        $prefix = ( $params['from_mobile'] ? "mobile.ui_mobile" : "calendar.ui" ) . "calendar"; 
    1000965                         
    1001                         if($params['from_mobile']) { 
    1002                                 $ui_return = "mobile.ui_mobilecalendar.edit"; 
    1003                                 $ui_index = "mobile.ui_mobilecalendar.index"; 
    1004                                 $ui_overlap = "mobile.ui_mobilecalendar.overlap"; 
    1005                         } 
    1006                         else { 
    1007                                 $ui_return = "calendar.uicalendar.edit"; 
    1008                                 $ui_index = "calendar.uicalendar.index";                 
    1009                                 $ui_overlap = "calendar.uicalendar.overlap"; 
    1010                         } 
     966                        $ui_return = "$prefix.edit"; 
     967                        $ui_index = "$prefix.index"; 
    1011968                         
    1012969                        if(!is_object($GLOBALS['phpgw']->datetime)) 
     
    1014971                                $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time'); 
    1015972                        } 
    1016  
    1017973                        $l_cal = (@isset($params['cal']) && $params['cal']?$params['cal']:$_POST['cal']); 
    1018  
    1019                         $post_max_size = ini_get('post_max_size'); 
    1020                         $mul = substr($post_max_size, -1); 
    1021                         $mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1))); 
    1022                         if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$post_max_size && $post_max_size) 
    1023                              $l_cal['attachment'] = 'ERROR'; 
    1024  
    1025                         if(count($_FILES['cal']) > 0){ 
    1026  
    1027                             if($l_cal['attachment'] != '') 
    1028                                $attachments = unserialize($l_cal['attachment']); 
    1029                             else 
    1030                                $attachments = Array(); 
    1031  
    1032                             foreach ($_FILES['cal']['error']['attachment'] as $key => $error) { 
    1033  
    1034                                 if ($error == UPLOAD_ERR_OK) { 
    1035  
    1036                                     $new_file= $GLOBALS['phpgw_info']['server']['temp_dir'].'/'.$_SESSION[ 'phpgw_session' ][ 'session_id' ].md5($attachment['name'].microtime()); 
    1037                                     move_uploaded_file($_FILES['cal']['tmp_name']['attachment'][$key], $new_file); 
    1038                                     $attach = Array('tmp_name' => $new_file, 'name' => $_FILES['cal']['name']['attachment'][$key], 'type' =>  $_FILES['cal']['type']['attachment'][$key]); 
    1039  
    1040                                     $attachments[] = $attach; 
    1041  
    1042                                 }elseif($error == UPLOAD_ERR_INI_SIZE){ 
    1043                                     $attachments = 'ERROR'; 
    1044                                     break; 
    1045  
    1046                                 } 
    1047                             } 
    1048                             $l_cal['attachment'] = $attachments; 
    1049  
    1050                         } 
    1051974                        $l_participants = (@$params['participants']?$params['participants']:$_POST['participants']); 
    1052                         $this->ex_participants = (@$params['ex_participants']?$params['ex_participants']:$_POST['ex_participants']); 
     975 
     976                        require_once($_SESSION['rootPath'].'/calendar/inc/class.ex_participants.inc.php'); 
     977                        $this->ex_participants = new exParticipants(); 
     978                        $this->ex_participants->setParticipantsByString(@$params['ex_participants']?$params['ex_participants']:$_POST['ex_participants']); 
     979 
     980                        if(@$params['h_exParticipants']?$params['h_exParticipants']:$_POST['h_exParticipants']) 
     981                             $this->ex_participants->updateAttribBySerializable(@$params['h_exParticipants']?$params['h_exParticipants']:$_POST['h_exParticipants']); 
     982 
    1053983                        $l_categories = (@$params['categories']?$params['categories']:$_POST['categories']); 
    1054984                        $l_start = (@isset($params['start']) && $params['start']?$params['start']:$_POST['start']); 
     
    10831013                                        } 
    10841014                                } 
    1085                                 unset($l_cal['participants']); 
     1015 
    10861016 
    10871017                                if (!is_object($GLOBALS['phpgw']->categories)) 
     
    11201050                                $event['title'] = stripslashes($event['title']); 
    11211051                                $event['description'] = stripslashes($event['description']); 
    1122                                 $event['observations'] = stripslashes($event['observations']); 
    11231052                                $event['ex_participants'] = stripslashes($event['ex_participants']); 
    11241053                                $datetime_check = $this->validate_update($event); 
     
    11361065                                                return; 
    11371066                                } 
    1138                                 $overlapping_events = False; 
     1067                                //$overlapping_events = False; 
    11391068                        } 
    11401069                        else 
     
    11631092                                if(!isset($l_cal['ex_participants'])) 
    11641093                                { 
    1165                                         $l_cal['ex_participants'] = $this->ex_participants; 
     1094                                        $l_cal['ex_participants'] = $this->ex_participants->getParticipantsSerializable(); 
    11661095                                } 
    11671096 
     
    11731102                                $is_public = ($l_cal['type'] != 'private' && $l_cal['type'] != 'privateHiddenFields'); 
    11741103                                $this->so->event_init(); 
     1104 
     1105                                if($l_cal['uid']) 
    11751106                                $this->add_attribute('uid',$l_cal['uid']); 
     1107                                else 
     1108                                $this->add_attribute('uid',time().'@Expresso'); 
     1109                                 
     1110 
    11761111                                $this->add_attribute('type',$l_cal['type']); 
    11771112                                if($l_cal['ex_participants']) { 
     
    11881123                                $this->so->set_title($l_cal['title']); 
    11891124                                $this->so->set_description($l_cal['description']); 
    1190                                 $this->so->set_observations($l_cal['observations']); 
    1191                                 $this->so->set_notifications_owner($l_cal['notifications_owner']); 
    1192                                 $this->so->set_attachment($l_cal['attachment']); 
    11931125                                $this->so->set_ex_participants($l_cal['ex_participants']); 
    11941126                                $this->so->set_start($l_start['year'],$l_start['month'],$l_start['mday'],$l_start['hour'],$l_start['min'],0); 
     
    11971129                                $this->so->add_attribute('reference',(@isset($l_cal['reference']) && $l_cal['reference']?$l_cal['reference']:0)); 
    11981130                                $this->so->add_attribute('location',(@isset($l_cal['location']) && $l_cal['location']?$l_cal['location']:'')); 
    1199                                 $this->so->add_attribute('repeat',(@isset($l_cal['recur_type']) && $l_cal['recur_type']?$l_cal['recur_type']:'')); 
    1200                                 $this->so->add_attribute('alarmd',(@isset($l_cal['alarmdays'])?$l_cal['alarmdays']:0)); 
    1201                                 $this->so->add_attribute('alarmh',(@isset($l_cal['alarmhours'])?$l_cal['alarmhours']:0)); 
    1202                                 $this->so->add_attribute('alarmm',(@isset($l_cal['alarmminutes'])?$l_cal['alarmminutes']:0)); 
    12031131                                if($l_cal['id']) 
    12041132                                { 
     
    12221150                                                $this->so->set_recur_none(); 
    12231151 
    1224                                                 $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    1225                                                 $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); 
    1226                                                 $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); 
     1152                                                $this->repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    12271153 
    12281154                                                break; 
     
    12301156                                                $this->so->set_recur_daily((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); 
    12311157 
    1232                                                 $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    1233                                                 $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); 
     1158                                                $this->repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    12341159 
    12351160                                                $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; 
     
    12381163                                                if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: 
    12391164                                                { 
    1240                                                         $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); 
    12411165                                                         
    12421166                                                        $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 
     
    12501174                                        case MCAL_RECUR_WEEKLY: 
    12511175 
    1252                                                 $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    1253                                                 $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); 
     1176                                                $this->repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    12541177 
    12551178                                                $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; 
     
    12591182                                                { 
    12601183 
    1261                                                         $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); 
    12621184                                                        $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 
    12631185                                                        $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; 
     
    12801202                                                        } 
    12811203                                                } 
    1282                                                 $this->so->add_attribute('rpt_wdays',(@isset($rpt_wdays) && $rpt_wdays?$rpt_wdays:'')); 
    12831204                                                $this->so->set_recur_weekly((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval'],$l_cal['recur_data']); 
    12841205                                                break; 
     
    12861207                                                $this->so->set_recur_monthly_mday((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); 
    12871208 
    1288                                                 $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    1289                                                 $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); 
     1209                                                $this->repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    12901210 
    12911211                                                $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; 
     
    12941214                                                if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: 
    12951215                                                { 
    1296                                                         $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); 
     1216 
    12971217                                                        $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 
    12981218                                                        $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; 
     
    13091229                                                $this->so->set_recur_yearly((int)$l_recur_enddate['year'],(int)$l_recur_enddate['month'],(int)$l_recur_enddate['mday'],(int)$l_cal['recur_interval']); 
    13101230 
    1311                                                 $repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    1312                                                 $this->so->add_attribute('recur_type',(@isset($repetido) && $repetido?$repetido:0)); 
     1231                                                $this->repetido = (int)$l_cal['recur_type']; // recebe o tipo de repeticao; 
    13131232 
    13141233                                                $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; 
     
    13171236                                                if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: 
    13181237                                                { 
    1319                                                         $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:'')); 
     1238 
    13201239                                                        $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 
    13211240                                                        $end_rept = mktime($_POST['start']['hour'],$_POST['start']['min'],0,intval($tmp_end[1]),$tmp_end[0],$tmp_end[2]); // transforma a data inicial + hora e minuto de inicio da repeticao em UNIX timestamp; 
     
    13401259                                                } 
    13411260                                                $acct_type = $GLOBALS['phpgw']->accounts->get_type((int)$parts[$i]); 
    1342                                                 if($acct_type == 'u') 
     1261                                                if($acct_type == 'u' || $acct_type == 's') 
    13431262                                                { 
    13441263                                                        $part[(int)$parts[$i]] = $accept_type; 
     
    14221341                                $event = $this->get_cached_event(); 
    14231342 
    1424                                 if ($l_cal['alarmdays'] > 0 || $l_cal['alarmhours'] > 0 || 
    1425                                                 $l_cal['alarmminutes'] > 0) 
     1343                                if ($l_cal['alarmdays'] > 0 || $l_cal['alarmhours'] > 0 ||$l_cal['alarmminutes'] > 0) 
    14261344                                { 
    14271345                                        $offset = ($l_cal['alarmdays'] * 24 * 3600) + 
     
    14351353                                                'owner'   => $this->owner, 
    14361354                                                'enabled' => 1, 
    1437                                                 'repeat'  => $repetido, // para repetir alarme; 
     1355                                                'repeat'  => $this->repetido, // para repetir alarme; 
    14381356                                                'init_rept' => $init_rept, // inicio repeticao; 
    14391357                                                'end_rept' => $end_rept, // fim repeticao; 
     
    14631381                                } 
    14641382 
     1383                            $overlapping_events = $this->event_overlap( $event, $send_to_ui, $prefix ); 
     1384 
     1385                            if( $overlapping_events ) 
     1386                                return( $overlapping_events ); 
     1387                        } 
     1388 
     1389                                $event['ex_participants'] = $this->ex_participants->getParticipantsSerializable(); 
     1390                         
     1391                        if($event['owner'] != $GLOBALS['phpgw_info']['user']['account_id']) $userSend = $event['owner']; 
     1392                        else $userSend = false; 
     1393        
     1394                        if(!$event['id']) 
     1395                        { 
     1396                                /** Whenever a recurrent event is edit in a way that a new   
     1397                                 * exception is created, an exception must be added to  
     1398                                 * the old event. This is necessary to keep consistency  
     1399                                 * with synchornization solutions in accordancy to  
     1400                                 * the iCalendar RFC.  
     1401                                 */  
     1402                                $old_event = $this->so->read_entry($_POST['cal']['reference']);  
     1403 
     1404                                $date = $_POST['cal']['date'];  
     1405                                $year  = substr($date,0,4);  
     1406                                $month = substr($date,4,2);  
     1407                                $day   = substr($date,6,2);  
     1408 
     1409                                $exception_time = mktime($old_event['start']['hour'],$old_event['start']['min'],0,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset;  
     1410                                $old_event['recur_exception'][] = (int)$exception_time;  
     1411                                $this->so->add_entry($old_event,false);  
     1412                             
     1413                             
     1414                                $this->so->add_entry($event,false); 
     1415                                print_debug('New Event ID',$event['id']); 
     1416                                $send_type = MSG_ADDED; 
     1417                        } 
     1418                        else 
     1419                        { 
     1420                                print_debug('Updating Event ID',$event['id']); 
     1421                                $new_event = $event; 
     1422                                $old_event = $this->read_entry($event['id']); 
     1423                                // if old event has alarm and the start-time changed => update them 
     1424                                //echo "<p>checking ".count($old_event['alarm'])." alarms of event #$event[id] start moved from ".print_r($old_event['start'],True)." to ".print_r($event['start'],True)."</p>\n"; 
     1425                                if ($old_event['alarm'] && 
     1426                                        $this->maketime($old_event['start']) != $this->maketime($event['start'])) 
     1427                                { 
     1428                                        $this->so->delete_alarms($old_event['id']); 
     1429                                        foreach($old_event['alarm'] as $id => $alarm) 
     1430                                        { 
     1431                                                $alarm['time'] = $this->maketime($event['start']) - $alarm['offset']; 
     1432                                                $event['alarm'][] = $alarm; 
     1433                                        } 
     1434                                        //echo "updated alarms<pre>".print_r($event['alarm'],True)."</pre>\n"; 
     1435                                } 
     1436                                $this->so->cal->event = $event; 
     1437                                $this->so->add_entry($event,false); 
     1438                                $this->prepare_recipients($new_event,$old_event,$userSend); 
     1439                                $send_type = MSG_MODIFIED; 
     1440                        } 
     1441                      
     1442                        //Retira da lista usuarios ja notificados 
     1443                        $to_notify = $event['participants']; 
     1444                        foreach ($this->alreadyNotifieds as $key => $value)  
     1445                            if(array_key_exists($value,$to_notify)) 
     1446                                unset ($to_notify[$value]); 
     1447                        //------------------------------------------------// 
     1448                            
     1449                        if(count($to_notify) > 0 && $userSend !== -2)     
     1450                            $this->send_update( $send_type,$to_notify,'',$this->get_cached_event(),$userSend); 
     1451 
     1452                        $date = sprintf("%04d%02d%02d",$event['start']['year'],$event['start']['month'],$event['start']['mday']); 
     1453                        if($send_to_ui) 
     1454                        { 
     1455                                $this->read_sessiondata(); 
     1456                                if ($this->return_to) 
     1457                                { 
     1458                                        $GLOBALS['phpgw']->redirect_link('/index.php','menuaction='.$this->return_to); 
     1459                                        $GLOBALS['phpgw']->common->phpgw_exit(); 
     1460                                } 
     1461                                Execmethod($ui_index); 
     1462                        } 
     1463                        else 
     1464                        { 
     1465                                return (int)$event['id']; 
     1466                        } 
     1467 
     1468                        return True; 
     1469                } 
     1470 
     1471                function event_overlap( $event, $send_to_ui = false, $prefix = "calendar.uicalendar" ,$user = false) 
     1472                { 
     1473                    $event_ids = array(); 
     1474 
    14651475                                if($event['id']) 
    14661476                                { 
     
    14721482                                } 
    14731483 
    1474                                 if (isset($repetido) and $repetido > 0){ 
     1484                    if (isset($this->repetido) and $this->repetido > 0) 
     1485                    {  
    14751486                                    $events = $this->expand_repetition($event); 
    14761487                                    $overlapping_events = False; 
     
    14921503                                    } 
    14931504                                } 
    1494                                 else { 
     1505                    else  
     1506                    {  
    14951507                                    $overlapping_events = $this->overlap( 
    14961508                                        $this->maketime($event['start']), 
     
    15011513                                    ); 
    15021514                                } 
    1503                         } 
    1504                         if(!$this->ex_participants) 
    1505                                 $this->ex_participants = $event['ex_participants'];                      
     1515                                       
    15061516                        if($overlapping_events) 
    15071517                        { 
     1518                            $this->store_to_appsession( $event ); 
    15081519                                if($send_to_ui) 
    15091520                                { 
    1510                                         $event['ex_participants'] = $this->ex_participants; 
    15111521                                        unset($GLOBALS['phpgw_info']['flags']['noheader']); 
    15121522                                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']); 
    1513                                         ExecMethod($ui_overlap, 
     1523                                    ExecMethod("$prefix.overlap", 
    15141524                                                Array( 
    15151525                                                        'o_events'      => $overlapping_events, 
    1516                                                         'this_event'    => $event 
     1526                                                    'this_event'        => $event, 
     1527                                                    'this_account' => $user 
    15171528                                                ) 
    15181529                                        ); 
    1519                                         if(!$params['from_mobile']) 
     1530 
     1531                                    if( $prefix === "calendar.uicalendar" ) 
    15201532                                                $GLOBALS['phpgw']->common->phpgw_exit(True); 
    1521                                         else 
    1522                                                 return; 
    1523                                 } 
    1524                                 else 
    1525                                 { 
    1526                                         return $overlapping_events; 
    1527                                 } 
    1528                         } 
    1529                         else 
    1530                         { 
    1531                                 if(!$event['id']) 
    1532                                 { 
    1533                                         $this->so->add_entry($event); 
    1534                                         $this->send_update(MSG_ADDED,$event['participants'],'',$this->get_cached_event()); 
    1535                                         print_debug('New Event ID',$event['id']); 
    1536                                 } 
    1537                                 else 
    1538                                 { 
    1539                                         print_debug('Updating Event ID',$event['id']); 
    1540                                         $new_event = $event; 
    1541                                         $old_event = $this->read_entry($event['id']); 
    1542                                         // if old event has alarm and the start-time changed => update them 
    1543                                         //echo "<p>checking ".count($old_event['alarm'])." alarms of event #$event[id] start moved from ".print_r($old_event['start'],True)." to ".print_r($event['start'],True)."</p>\n"; 
    1544                                         if ($old_event['alarm'] && 
    1545                                                 $this->maketime($old_event['start']) != $this->maketime($event['start'])) 
    1546                                         { 
    1547                                                 $this->so->delete_alarms($old_event['id']); 
    1548                                                 foreach($old_event['alarm'] as $id => $alarm) 
    1549                                                 { 
    1550                                                         $alarm['time'] = $this->maketime($event['start']) - $alarm['offset']; 
    1551                                                         $event['alarm'][] = $alarm; 
    1552                                                 } 
    1553                                                 //echo "updated alarms<pre>".print_r($event['alarm'],True)."</pre>\n"; 
    1554                                         } 
    1555                                         $this->so->cal->event = $event; 
    1556                                         $this->so->add_entry($event); 
    1557                                         $this->prepare_recipients($new_event,$old_event); 
    1558                                 } 
    1559  
    1560                                 $date = sprintf("%04d%02d%02d",$event['start']['year'],$event['start']['month'],$event['start']['mday']); 
    1561                                 if($send_to_ui) 
    1562                                 { 
    1563                                         $this->read_sessiondata(); 
    1564                                         if ($this->return_to) 
    1565                                         { 
    1566                                                 $GLOBALS['phpgw']->redirect_link('/index.php','menuaction='.$this->return_to); 
    1567                                                 $GLOBALS['phpgw']->common->phpgw_exit(); 
    1568                                         } 
    1569                                         Execmethod($ui_index); 
    1570                                 } 
    1571                                 else 
    1572                                 { 
    1573                                         return (int)$event['id']; 
    1574                                 } 
    1575                         } 
    1576                         return True; 
     1533                                } 
     1534 
     1535                            return( $overlapping_events ); 
     1536                        } 
     1537 
     1538                    return( false ); 
    15771539                } 
    15781540 
     
    17001662                                $error = 43; 
    17011663                        } 
    1702                         elseif ($event['type'] != 'hourAppointment' && $event['title'] == '') 
     1664                        elseif ($event['title'] == '') 
    17031665                        { 
    17041666                                $error = 40; 
    17051667                        } 
    1706                         elseif ($event['repeat'] != 0) 
    1707                         { 
    1708                                 if( $event['rpt_end_use'] != 'y') 
    1709                                 { 
    1710                                         $error = 46; 
    1711                                 } 
    1712                         //} 
    1713                           if ($event['repeat'] == 2) 
    1714                           { 
    1715                                 if($event['rpt_wdays'] == '') { 
    1716                                         $error = 44; 
    1717                                 } 
    1718                                 if( $event['rpt_end_use'] != 'y') 
    1719                                 { 
    1720                                         $error = 46; 
    1721                                 } 
    1722  
    1723                                 if (  ( isset($event['alarmd'])  && ($event['alarmd'] != 0) ) || ( isset($event['alarmh'])  && ($event['alarmh'] != 0) ) || ( isset($event['alarmm'])  && ($event['alarmm'] != 0) ) ) 
    1724                                 { 
    1725                                         if( isset($event['recur_type']) && ($event['recur_type'] != 0) ) 
    1726                                         { 
    1727                                                 if( $event['rpt_end_use'] != 'y') 
    1728                                                 { 
    1729                                                         $error = 45; 
    1730                                                 } 
    1731                                         } 
    1732                                 } 
    1733                            } 
    1734  
    1735                         //} 
    1736                   if (  ( isset($event['alarmd'])  && ($event['alarmd'] != 0) ) || ( isset($event['alarmh'])  && ($event['alarmh'] != 0) ) || ( isset($event['alarmm'])  && ($event['alarmm'] != 0) ) ) 
    1737                   { 
    1738                         if( isset($event['recur_type']) && ($event['recur_type'] != 0) ) 
    1739                         { 
    1740                                 if( $event['rpt_end_use'] != 'y') 
    1741                                 { 
    1742                                         $error = 45; 
    1743                                 } 
    1744                         } 
    1745                   } 
    1746                 } 
    17471668                        elseif (($GLOBALS['phpgw']->datetime->time_valid($event['start']['hour'],$event['start']['min'],0) == False) || ($GLOBALS['phpgw']->datetime->time_valid($event['end']['hour'],$event['end']['min'],0) == False)) 
    17481669                        { 
    17491670                                $error = 41; 
    17501671                        } 
    1751                         elseif (($GLOBALS['phpgw']->datetime->date_valid($event['start']['year'],$event['start']['month'],$event['start']['mday']) == False)  
    1752                                 || ($GLOBALS['phpgw']->datetime->date_valid($event['end']['year'],$event['end']['month'],$event['end']['mday']) == False) 
    1753                                 || ($GLOBALS['phpgw']->datetime->date_compare($event['start']['year'],$event['start']['month'],$event['start']['mday'],$event['end']['year'],$event['end']['month'],$event['end']['mday']) == 1) 
    1754                                 || $event['start']['year'] > 2037 || $event['end']['year'] > 2037) 
     1672                        elseif (($GLOBALS['phpgw']->datetime->date_valid($event['start']['year'],$event['start']['month'],$event['start']['mday']) == False) || ($GLOBALS['phpgw']->datetime->date_valid($event['end']['year'],$event['end']['month'],$event['end']['mday']) == False) || ($GLOBALS['phpgw']->datetime->date_compare($event['start']['year'],$event['start']['month'],$event['start']['mday'],$event['end']['year'],$event['end']['month'],$event['end']['mday']) == 1)) 
    17551673                        { 
    17561674                                $error = 42; 
     
    17581676                        elseif ($GLOBALS['phpgw']->datetime->date_compare($event['start']['year'],$event['start']['month'],$event['start']['mday'],$event['end']['year'],$event['end']['month'],$event['end']['mday']) == 0) 
    17591677                        { 
    1760                                 if ( ($GLOBALS['phpgw']->datetime->time_compare($event['start']['hour'],$event['start']['min'],0,$event['end']['hour'],$event['end']['min'],0) == 1) 
    1761                                    ||($GLOBALS['phpgw']->datetime->time_compare($event['start']['hour'],$event['start']['min'],0,$event['end']['hour'],$event['end']['min'],0) == 0) ) 
    1762                                 { 
    1763                                         $error = 47; 
    1764                                 } 
    1765                         } 
    1766                         if($event['attachment'] == 'ERROR') 
    1767                             $error = 99; 
     1678                                if ($GLOBALS['phpgw']->datetime->time_compare($event['start']['hour'],$event['start']['min'],0,$event['end']['hour'],$event['end']['min'],0) == 1) 
     1679                                { 
     1680                                        $error = 42; 
     1681                                } 
     1682                        } 
    17681683                         
    17691684                        return $error; 
     
    17891704                } 
    17901705                 
    1791                 function participants_unanswered($participants,$event) 
    1792                 { 
    1793                         foreach($participants as $uid => $status) 
    1794                         {                                
    1795                                 if (isset($event['participants'][$uid]) && $event['participants'][$uid] == 'U' && $status == 'U') 
    1796                                 { 
    1797                                         return False; 
    1798                                 } 
    1799                         } 
    1800                         return True; 
    1801                 } 
    1802  
    18031706                function overlap($starttime,$endtime,$participants,$owner=0,$id=0,$restore_cache=False) 
    18041707                { 
     
    19091812                                                                $temp_start_time >= $temp_event_start && 
    19101813                                                                $temp_end_time <= $temp_event_end) && 
    1911                                                                 $this->participants_not_rejected($participants,$event) && $this->participants_unanswered($participants,$event)) 
     1814                                                                $this->participants_not_rejected($participants,$event)) 
    19121815                                                        { 
    19131816                                                                if($this->debug) 
     
    20801983                function get_short_field($event,$is_private=True,$field='') 
    20811984                { 
    2082                         if($is_private) 
     1985                        if($is_private && $event['type'] == 'E') 
     1986                        { 
     1987                                return lang('Restrict'); 
     1988                        } 
     1989                        else if($is_private && $event['type'] == 'P') 
    20831990                        { 
    20841991                                return lang('private'); 
     
    23422249                        $search_date_day = date('d',$datetime); 
    23432250                        $search_date_dow = date('w',$datetime); 
    2344                         $search_beg_day = mktime(12,0,0,$search_date_month,$search_date_day,$search_date_year); 
     2251                        $search_beg_day = mktime(0,0,0,$search_date_month,$search_date_day,$search_date_year); 
    23452252                        if($this->debug) 
    23462253                        { 
     
    24092316                                                        break; 
    24102317                                                case MCAL_RECUR_WEEKLY: 
    2411                                                         if (floor(($search_beg_day - $event_beg_day)/604800)  % ($freq ? $freq : 1)) 
     2318                                                        if ((floor($search_beg_day / 604800) - floor($event_beg_day / 604800)) % $freq) 
    24122319                                                        { 
    24132320                                                                continue; 
     
    29342841                @abstract set the participant response $status for event $cal_id and notifies the owner of the event 
    29352842                */ 
    2936                 function set_status($cal_id,$status) 
     2843                function set_status($cal_id,$status,$user = false) 
    29372844                { 
    29382845                        $status2msg = array( 
     
    29462853                        } 
    29472854                        $event = $this->so->read_entry($cal_id); 
    2948                         $account_id = $GLOBALS['phpgw_info']['user']['account_id']; 
     2855                        if($user) $account_id = $user; 
     2856                        else $account_id = $GLOBALS['phpgw_info']['user']['account_id']; 
    29492857                        if(($status2msg[$status] == "5" && $event['participants'][$account_id] == "A") || 
    29502858                         ($status2msg[$status] == "3" && $event['participants'][$account_id] == "R")) { 
    29512859                                return True; 
    29522860                        } 
    2953                         $this->so->set_status($cal_id,$status); 
     2861                        $this->so->set_status($cal_id,$status,$account_id); 
    29542862                        $event = $this->so->read_entry($cal_id); 
    2955                         $this->send_update($status2msg[$status],$event['participants'],$event); 
    2956  
     2863                        $this->send_update($status2msg[$status],$event['participants'],$event,false,$account_id); 
     2864 
     2865                        $sts = array_values( $event['participants'] ); 
     2866 
     2867                        //verifica se todos os participantes rejeitaram o evento 
     2868                        while( $sts[0] && $sts[0] === 'R' ) array_pop( $sts ); 
     2869 
     2870                        if( empty( $sts ) ) 
     2871                        { 
     2872                                $this->so->delete_entry( $cal_id ); 
     2873                                $this->so->expunge(); 
     2874                        } 
    29572875                } 
    29582876 
     
    30152933                } 
    30162934 
    3017                 function create_vcard($event_arrays) 
    3018                 { 
     2935 
     2936                function create_vcard($event_arrays , $metodo = 'PUBLISH', $externo = false,$importAccount = false) 
     2937                { 
     2938                    if(!$importAccount) 
     2939                        $importAccount['mail'] = $GLOBALS['phpgw_info']['user']['email']; 
     2940 
    30192941            if(!is_array($event_arrays)) 
    30202942                                return null; 
    30212943 
    3022                         $sender = $GLOBALS['phpgw_info']['user']['email']; 
    3023                         $uid_dono = $GLOBALS['phpgw_info']['user']['account_lid']; 
    3024                         $tmpattach="BEGIN:VCALENDAR\n" 
    3025                         ."PRODID:-//Expresso Livre//Calendar//EN\n" 
    3026                         ."VERSION:1.0\n"; 
    3027             foreach ($event_arrays as $event) 
    3028             { 
    3029                                 // It translates int to string 
    3030                                 if (!is_object($event) && !is_array($event) || !array_key_exists  ('end', $event)) 
    3031                                         $event = $event_arrays; 
    3032  
    3033                                 //set to GMT 
    3034                                 //Aqui estou pegando o horário do evento e setando para GMT de acordo com o fuso horário estabelecido nas configurações do expresso. 
    3035                                 $start_time = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$event['start']['month'],$event['start']['mday'],$event['start']['year']) - $GLOBALS['phpgw']->datetime->tz_offset; 
    3036                                 $end_time = mktime($event['end']['hour'],$event['end']['min'],$event['end']['sec'],$event['end']['month'],$event['end']['mday'],$event['end']['year']) - $GLOBALS['phpgw']->datetime->tz_offset; 
    3037                                  
    3038                                 $start_time = date("Ymd\THis\Z", $start_time); 
    3039                                 $end_time = date("Ymd\THis\Z", $end_time); 
     2944                    $tmpattach="BEGIN:VCALENDAR\r\n" 
     2945                        ."PRODID:-//Expresso Livre//Calendar//EN\r\n" 
     2946                        ."VERSION:2.0\r\n" 
     2947                        ."CALSCALE:GREGORIAN\r\n" 
     2948                        ."METHOD:".$metodo."\r\n"; 
     2949 
     2950                    //$offset = ((int)substr(date('O',$GLOBALS['phpgw']->datetime->users_localtime), 0, 3)); 
     2951                    $offset = (($GLOBALS['phpgw']->datetime->tz_offset)/60)/60; 
    30402952         
    3041                                 // Necessário espaços após quebra-de-linha, na descrição, caso contrário  
    3042                                 // ocorrerá erro ao importar o agendamento no Outlook (erro lunar). 
    3043                                 $description = str_replace("\n","\n ", $event['description']); 
    3044                                  
    3045                                 $tmpattach.="BEGIN:VEVENT\r\n" 
    3046                                 ."DTSTART:".$start_time."\r\n" 
    3047                                 ."DTEND:".$end_time."\r\n" 
     2953                        foreach ($event_arrays as $event_array) 
     2954                        { 
     2955                            $sy = $event_array['start']['year']; 
     2956                            $sm = $event_array['start']['month']; 
     2957                            $sd = $event_array['start']['mday']; 
     2958                            $sh = $event_array['start']['hour'] -= $offset; 
     2959                            $sn = $event_array['start']['min']; 
     2960                            $dtstart = sprintf("%04d%02d%02dT%02d%02d00Z", $sy, $sm, $sd, $sh, $sn); 
     2961 
     2962                            $ey = $event_array['end']['year']; 
     2963                            $em = $event_array['end']['month']; 
     2964                            $ed = $event_array['end']['mday']; 
     2965                            $eh = $event_array['end']['hour'] -= $offset; 
     2966                            $en = $event_array['end']['min']; 
     2967                            $dtend = sprintf("%04d%02d%02dT%02d%02d00Z", $ey, $em, $ed, $eh, $en); 
     2968 
     2969                            // Necessário espaços após quebra-de-linha, na descrição, caso contrário 
     2970                            // ocorrerá erro ao importar o agendamento no Outlook (erro lunar). 
     2971                            $description = str_replace("\n","\n ",$event_array['description']); 
     2972                            $tmpattach.="BEGIN:VEVENT\r\n"; 
     2973                                                         
     2974                                                        if(isset($event_array['organizer']) && $event_array['owner'] != -2) 
     2975                                                        { 
     2976                                $ldap = $this->getLdap();   
     2977                                $justthese = array("mail","cn"); 
     2978                                $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l)(phpgwAccountType=s)(phpgwAccountType=i))(uidNumber=".$event_array['owner']."))"; 
     2979                                $search = ldap_search($ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     2980                                $entry = ldap_get_entries($ldap, $search);                                         
     2981                                                                $organizer = 'ORGANIZER;CN='.$entry[0]['cn'][0].':mailto:'.$entry[0]['mail'][0]."\r\n"; 
     2982                                                        }    
     2983                                                        else{    
     2984                                                                $email = explode('&lt;', $event_array['organizer']); 
     2985                                                                $email2 = explode('&gt;', $email[1]); 
     2986                                $organizer = 'ORGANIZER;CN='.rtrim($email[0]).':mailto:'.$email2[0]."\r\n"; 
     2987                                                        } 
     2988                                                                  
     2989                            if(!$externo) 
     2990                            { 
     2991                                                            $tmpattach.= 
     2992                                "DTSTART:".$dtstart."\r\n" 
     2993                                ."DTEND:".$dtend."\r\n" 
    30482994                                ."LAST-MODIFIED:".gmdate("Ymd\THis\Z")."\r\n" //Hora no formato UTC 
    3049                                 //."UID:Expresso-".$event['id'].$event['uid']."\r\n" 
    3050                                 ."UID:Expresso-".$event[id]."@".$uid_dono."\n" 
     2995                                                                .$organizer 
     2996                                ."UID:".$event_array['uid']."\r\n" 
     2997                                                                .$this->mb_wordwrap($this->getvCalendarParticipants($event_array['participants'],$event_array['id']),74,"\r\n ") 
     2998                                                                .$this->mb_wordwrap($this->getvCalendarExternalParticipants($event_array['id']),74,"\r\n ") 
    30512999                                ."DESCRIPTION:".$description."\r\n" 
    3052                                 ."SUMMARY:".$event['title']."\r\n" 
    3053                                 ."LOCATION:".$event['location']."\r\n" 
    3054                                 ."ORGANIZER:mailto:".$sender."\n"; 
    3055                                 $expart=preg_split('/,/', $event['ex_participants']); 
    3056  
    3057                                 foreach ($expart as $mail) 
     3000                                ."SUMMARY:".$event_array['title']."\r\n" 
     3001                                ."LOCATION:".$event_array['location']."\r\n" 
     3002                                ."END:VEVENT\r\n"; 
     3003                            } 
     3004                             else 
     3005                            { 
     3006                                                                $tmpattach.= 
     3007                                "DTSTART:".$dtstart."\r\n" 
     3008                                ."DTEND:".$dtend."\r\n" 
     3009                                ."DTSTAMP:".gmdate("Ymd\THis\Z")."\r\n" //Hora no formato UTC 
     3010                                .$organizer 
     3011                                .$this->mb_wordwrap("UID:".$event_array['uid']."\r\n",74,"\r\n "); 
     3012 
     3013                                switch ($metodo) { 
     3014                                    case 'PUBLISH': 
     3015                                          $tmpattach.= 
     3016                                             $this->mb_wordwrap($this->getvCalendarParticipants($event_array['participants'],$event_array['id']),74,"\r\n ") 
     3017                                                                                        .$this->mb_wordwrap($this->getvCalendarExternalParticipants($event_array['id']),74,"\r\n ") 
     3018                                            .$this->mb_wordwrap("DESCRIPTION:".$description."\r\n",74,"\r\n ") 
     3019                                            .$this->mb_wordwrap("SUMMARY:".$event_array['title']."\r\n",74,"\r\n ") 
     3020                                            .$this->mb_wordwrap("LOCATION:".$event_array['location']."\r\n",74,"\r\n "); 
     3021                                        break; 
     3022                                    case 'REPLY': 
     3023                                            $tmpattach.= 
     3024                                             $this->mb_wordwrap("ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;X-NUM-GUESTS=0:mailto:".$importAccount['mail']."\r\n",74,"\r\n ") 
     3025                                            .'DESCRIPTION:\n'."\r\n" 
     3026                                            .$this->mb_wordwrap("LAST-MODIFIED:".gmdate("Ymd\THis\Z")."\r\n",74,"\r\n ") //Hora no formato UTC 
     3027                                            .$this->mb_wordwrap("LOCATION:".$event_array['location']."\r\n",74,"\r\n ") 
     3028                                            ."SEQUENCE:0\r\n" 
     3029                                            ."STATUS:CONFIRMED\r\n" 
     3030                                            .$this->mb_wordwrap("SUMMARY:".$event_array['title']."\r\n",74,"\r\n ") 
     3031                                            ."TRANSP:OPAQUE\r\n"; 
     3032                                        break; 
     3033                                    default: 
     3034                                           $tmpattach.= 
     3035                                             "DESCRIPTION:".$description."\r\n" 
     3036                                            ."SUMMARY:".$event_array['title']."\r\n" 
     3037                                            ."LOCATION:".$event_array['location']."\r\n"; 
     3038                                        break; 
     3039                                } 
     3040                                  $tmpattach.= "END:VEVENT\r\n"; 
     3041                            } 
     3042                             
     3043                        } 
     3044                    $tmpattach.="END:VCALENDAR\r\n\r\n\r\n"; 
     3045                    return $tmpattach; 
     3046                } 
     3047 
     3048                function mb_wordwrap($str, $width=74, $break="\r\n") 
     3049                { 
     3050                    // Return short or empty strings untouched 
     3051                    if(empty($str) || mb_strlen($str, 'ISSO-8859-1') <= $width) 
     3052                        return $str; 
     3053 
     3054                    $br_width  = mb_strlen($break, 'ISSO-8859-1'); 
     3055                    $str_width = mb_strlen($str, 'ISSO-8859-1'); 
     3056                    $return = ''; 
     3057                    $last_space = false; 
     3058 
     3059                    for($i=0, $count=0; $i < $str_width; $i++, $count++) 
     3060                    { 
     3061                        // If we're at a break 
     3062                        if (mb_substr($str, $i, $br_width, 'ISSO-8859-1') == $break) 
     3063                        { 
     3064                            $count = 0; 
     3065                            $return .= mb_substr($str, $i, $br_width, 'ISSO-8859-1'); 
     3066                            $i += $br_width - 1; 
     3067                            continue; 
     3068                        } 
     3069 
     3070                        // Keep a track of the most recent possible break point 
     3071                        if(mb_substr($str, $i, 1, 'ISSO-8859-1') == " ") 
     3072                        { 
     3073                            $last_space = $i; 
     3074                        } 
     3075 
     3076                        // It's time to wrap 
     3077                        if ($count > $width) 
    30583078                                { 
    3059                                     if($mail != "") 
     3079                            // There are no spaces to break on!  Going to truncate :( 
     3080                            if(!$last_space) 
    30603081                                    { 
    3061                                         $tmpattach.="ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:".$mail."\n"; 
     3082                                $return .= $break; 
     3083                                $count = 0; 
     3084                            } 
     3085                            else 
     3086                            { 
     3087                                // Work out how far back the last space was 
     3088                                $drop = $i - $last_space; 
     3089 
     3090                                // Cutting zero chars results in an empty string, so don't do that 
     3091                                if($drop > 0) 
     3092                                { 
     3093                                    $return = mb_substr($return, 0, -$drop); 
     3094                                } 
     3095 
     3096                                // Add a break 
     3097                                $return .= $break; 
     3098 
     3099                                // Update pointers 
     3100                                $i = $last_space + ($br_width - 1); 
     3101                                $last_space = false; 
     3102                                $count = 0; 
    30623103                                    } 
    30633104                                } 
    30643105                                 
    3065                                 while (list($id,$status) = each($event['participants'])) 
     3106                        // Add character from the input string to the output 
     3107                        $return .= mb_substr($str, $i, 1, 'ISSO-8859-1'); 
     3108                    } 
     3109                    return $return; 
     3110                } 
     3111 
     3112                function getvCalendarParticipants($pExtParticipants,$pCalId) 
    30663113                                { 
    3067  
    3068                                       $preferences = CreateObject('phpgwapi.preferences',$id); 
    3069                                       $mail = $preferences->email_address($id); 
    3070                                       if ( $sender != $mail) 
     3114                    $participants = explode(',', $pExtParticipants); 
     3115                    $return = ''; 
     3116 
     3117                    foreach ($participants as $participant) 
    30713118                                      { 
    3072                                          if($status == 'U' ){ 
    3073                                                   $tmpattach.="ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:".$mail."\n"; 
     3119                        $array = explode('"', $participant); 
     3120                        $mail = str_replace('<','', str_replace('>','',$array['2'])); 
     3121                        if($mail && $array['1']) 
     3122                             $return .= 'ATTENDEE;CN='.$array['1'].';RSVP=TRUE:mailto:'.$mail."\r\n"; 
     3123                    } 
     3124                    $db = $this->getDb(); 
     3125                    $db->query('SELECT cal_login FROM phpgw_cal_user WHERE cal_id = '.$pCalId); 
     3126                    $parts = array(); 
     3127                    while($db->next_record()) 
     3128                        array_push($parts, $db->row()); 
     3129 
     3130                    $ldap = $this->getLdap(); 
     3131                    foreach ($parts as $part) 
     3132                    { 
     3133                        $justthese = array('mail','cn'); 
     3134                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$part['cal_login']."))"; 
     3135                        $search = ldap_search($ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     3136                        $entry = ldap_get_entries($ldap, $search); 
     3137                        $return .= 'ATTENDEE;CN='.$entry[0]['cn'][0].';RSVP=TRUE:mailto:'.$entry[0]['mail'][0]."\r\n"; 
    30743138                                                        } 
    3075                                          elseif($status == 'A' ){ 
    3076                                                  $tmpattach.="ATTENDEE;RSVP=TRUE;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT:mailto:".$mail."\n"; 
     3139 
     3140                    return $return; 
    30773141                                                        } 
    3078                                          elseif($status == 'T' ){ 
    3079                                                  $tmpattach.="ATTENDEE;RSVP=TRUE;PARTSTAT=TENTATIVE;ROLE=REQ-PARTICIPANT:mailto:".$mail."\n"; 
     3142                                 
     3143                function getCalendarParticipantsArray($pCalId) 
     3144                { 
     3145                    $db = $this->getDb(); 
     3146                    $db->query('SELECT cal_login FROM phpgw_cal_user WHERE cal_id = '.$pCalId); 
     3147                    $parts = array(); 
     3148                    while($db->next_record()) 
     3149                        array_push($parts, $db->row()); 
     3150 
     3151                    $ldap = $this->getLdap(); 
     3152                    foreach ($parts as $part) 
     3153                    { 
     3154                        $justthese = array('mail','cn'); 
     3155                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(uidNumber=".$part['cal_login']."))"; 
     3156                        $search = ldap_search($ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     3157                        $entry = ldap_get_entries($ldap, $search); 
     3158                        $return [$entry[0]['mail'][0]] = array( 'CN'=> $entry[0]['cn'][0],'RSVP'=> 'TRUE' ,'ROLE' => 'REQ-PARTICIPANT'); 
     3159                    } 
     3160                    return $return; 
     3161                } 
     3162 
     3163                function getvCalendarExternalParticipants($pCalId) 
     3164                { 
     3165 
     3166                    $db = $this->getDb(); 
     3167                    $sql = "SELECT ex_participants FROM phpgw_cal WHERE cal_id = '$pCalId'"; 
     3168                                $db->query($sql); 
     3169                                 
     3170                    $parts = array(); 
     3171                    while($db->next_record()) 
     3172                        array_push($parts, $db->row()); 
     3173 
     3174                                        $participants = explode(',', $parts[0]['ex_participants']); 
     3175                    $return = ''; 
     3176                                         
     3177                                        $participants = unserialize(base64_decode($parts[0]['ex_participants'])); 
     3178 
     3179                    foreach ($participants as $participant) 
     3180                    {    
     3181                           $part = array(); 
     3182 
     3183                           if(preg_match("(\"[^\"]*\"[ ]*<[^>]*@[^>]*>)", $participant['mail'])) 
     3184                           { 
     3185                              $cn = null; 
     3186                              $mail = null; 
     3187                              preg_match ("(\"([^\"]*)\")", $participant['mail'], $cn); 
     3188                              preg_match ('(<([^>]*@[^>]*)>)', $participant['mail'], $mail); 
     3189 
     3190                              if($mail[1]) 
     3191                              $part['mail'] =  $mail[1]; 
     3192 
     3193                              if($cn[1]) 
     3194                                $part['cn'] =  $cn[1]; 
     3195 
    30803196                                                         } 
    30813197                                         else 
     3198                           if(preg_match("(<[^>]*@[^>]*>)", $participant['mail'])) 
    30823199                                                  { 
    3083                                                      $tmpattach.="ATTENDEE;RSVP=TRUE;PARTSTAT=DECLINED;ROLE=REQ-PARTICIPANT:mailto:".$mail."\n"; 
     3200                              $mail = null; 
     3201                              preg_match ('(<([^>]*@[^>]*)>)', $participant['mail'], $mail); 
     3202                              if($mail[1]) 
     3203                                $part['mail'] =  $mail[1]; 
     3204 
    30843205                                                   } 
     3206                           else 
     3207                           if(preg_match("([^ ]*@[^ ]*)", $participant['mail'])) 
     3208                           { 
     3209                              $mail = null; 
     3210                              preg_match ('([^ ]*@[^ ]*)', $participant['mail'], $mail); 
     3211                              if($mail[0]) 
     3212                                $part['mail'] =  $mail[0]; 
     3213 
     3214                           } 
     3215 
     3216                          if(count($part) > 0) 
     3217                          { 
     3218                              if($part['cn'])  
     3219                                                                $return .= 'ATTENDEE;CN='.$part['cn'].';RSVP=TRUE:mailto:'.$part['mail']."\r\n"; 
     3220                              else  
     3221                                                                $return .= 'ATTENDEE;RSVP=TRUE:mailto:'.$part['mail']."\r\n";   
     3222                              
    30853223                                      } 
    30863224                                } 
    3087                                 $tmpattach.="END:VEVENT"."\n"; 
    3088                                 //."END:VEVENT\r\n"; 
    3089                         } 
    3090                     $tmpattach.="END:VCALENDAR\r\n"; 
    3091                     return $tmpattach; 
     3225 
     3226                    return $return; 
     3227                        } 
     3228 
     3229 
     3230                function getDb() 
     3231                { 
     3232                    include_once('../phpgwapi/inc/class.db.inc.php'); 
     3233                    // Conecta ao banco de dados 
     3234                    if (is_array($_SESSION['phpgw_info']['expresso']['server'])) 
     3235                        $GLOBALS['phpgw_info']['server'] = $_SESSION['phpgw_info']['expresso']['server']; 
     3236                    else 
     3237                        $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server']; 
     3238 
     3239                    $db = new db(); 
     3240                    $db->Halt_On_Error = 'no'; 
     3241                    $db->connect( 
     3242                                $_SESSION['phpgw_info']['expresso']['server']['db_name'], 
     3243                                $_SESSION['phpgw_info']['expresso']['server']['db_host'], 
     3244                                $_SESSION['phpgw_info']['expresso']['server']['db_port'], 
     3245                                $_SESSION['phpgw_info']['expresso']['server']['db_user'], 
     3246                                $_SESSION['phpgw_info']['expresso']['server']['db_pass'], 
     3247                                $_SESSION['phpgw_info']['expresso']['server']['db_type'] 
     3248                                ); 
     3249                                // Fim Conecta Banco de dados 
     3250                    return $db; 
     3251                } 
     3252 
     3253                function getLdap() 
     3254                { 
     3255                    require_once($_SESSION['rootPath'].'/header.inc.php'); 
     3256                    require_once($_SESSION['rootPath'].'/phpgwapi/inc/class.common.inc.php'); 
     3257    
     3258                    $common = new common(); 
     3259                                 
     3260                    if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) && 
     3261                        (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) && 
     3262                        (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) ) 
     3263                        { 
     3264                            $ldap = $common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'], 
     3265                                                         $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'], 
     3266                                                         $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']); 
     3267                        } 
     3268                        else 
     3269                        { 
     3270                            $ldap = $common->ldapConnect(); 
     3271                        } 
     3272                        
     3273                    return $ldap; 
     3274                } 
     3275 
     3276                function getvCalendarOrganizer($pOrganizer) 
     3277                { 
     3278 
     3279                     
     3280                       $organizer = array(); 
     3281        
     3282                       if(preg_match("(\"[^\"]*\"[ ]*<[^>]*@[^>]*>)", $pOrganizer)) 
     3283                       { 
     3284                          $cn = null; 
     3285                          $mail = null; 
     3286                          preg_match ("(\"([^\"]*)\")", $pOrganizer, $cn); 
     3287                          preg_match ('(<([^>]*@[^>]*)>)', $pOrganizer, $mail); 
     3288 
     3289                          if($mail[1]) 
     3290                          $organizer['mail'] =  $mail[1]; 
     3291 
     3292                          if($cn[1]) 
     3293                            $organizer['cn'] =  $cn[1]; 
     3294 
     3295                       } 
     3296                       else 
     3297                       if(preg_match("(<[^>]*@[^>]*>)", $pOrganizer)) 
     3298                       { 
     3299                          $mail = null; 
     3300                          preg_match ('(<([^>]*@[^>]*)>)', $pOrganizer, $mail); 
     3301                          if($mail[1]) 
     3302                            $organizer['mail'] =  $mail[1]; 
     3303 
     3304                       } 
     3305                       else 
     3306                       if(preg_match("([^ ]*@[^ ]*)", $pOrganizer)) 
     3307                       { 
     3308                          $mail = null; 
     3309                          preg_match ('([^ ]*@[^ ]*)', $pOrganizer, $mail); 
     3310                          if($mail[0]) 
     3311                            $organizer['mail'] =  $mail[0]; 
     3312 
     3313                       } 
     3314                        
     3315                       if($organizer['cn']) $return = 'ORGANIZER;CN="'.$organizer['cn'].'":MAILTO:'.$organizer['mail']."\r\n"; 
     3316                       else $return = 'ORGANIZER;MAILTO:'.$organizer['mail']."\r\n"; 
     3317                        
     3318                    return $return; 
    30923319                } 
    30933320 
     
    31013328                @param $new_event Event after the change 
    31023329                */ 
    3103                 function send_update($msg_type,$to_notify,$old_event,$new_event=False,$user=False) 
    3104                 {                        
    3105                         if (!is_array($to_notify)) 
    3106                         { 
    3107                                 $to_notify = array(); 
    3108                         } 
     3330                function send_update($msg_type,$to_notify,$old_event,$new_event = False, $user = False) 
     3331                        { 
     3332           
     3333                        if (!is_array($to_notify)) $to_notify = array(); 
    31093334                        $owner = $old_event ? $old_event['owner'] : $new_event['owner']; 
    3110                         if ($owner && !isset($to_notify[$owner]) && $msg_type != MSG_ALARM) 
    3111                         { 
    3112                                 $to_notify[$owner] = 'owner';   // always include the event-owner 
    3113                         } 
     3335 
     3336                        if($owner === -2) 
     3337                            $to_notify[-2] = 'A';  
     3338 
    31143339                        $version = $GLOBALS['phpgw_info']['apps']['calendar']['version']; 
    3115  
    31163340                        $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences(); 
    3117  
    3118                     $preferences = CreateObject('phpgwapi.preferences',(int)$this->owner);  
    3119                     $GLOBALS['phpgw']->accounts->get_account_name((int)$owner,$lid,$fname,$lname);  
    31203341                  
    3121                         if($new_event['notifications_owner'] == '1'){  
    3122                         $sender = $preferences->email_address((int)$owner);  
    3123                         $sender_name = $fname.' '.$lname;  
    3124                     }else{  
    3125                         $sender = $GLOBALS['phpgw_info']['user']['email'];  
    3126                         $sender_name = $GLOBALS['phpgw_info']['user']['fullname'];  
     3342                        /* 
     3343                         * Caso o evento seja de uma conta compartilha busca obusca o cn e o email da conta 
     3344                         */  
     3345                        if($user) 
     3346                        { 
     3347                            $ldap = $this->getLdap();   
     3348                            $justthese = array("mail","cn"); 
     3349                            $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l)(phpgwAccountType=s)(phpgwAccountType=i))(uidNumber=".$user."))"; 
     3350                            $search = ldap_search($ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     3351                            $entry = ldap_get_entries($ldap, $search); 
     3352                            $sMail = $entry[0]['mail'][0]; 
     3353                            $sCN = $entry[0]['cn'][0]; 
     3354                            $sUN = $user; 
    31273355                        }  
     3356                        else 
     3357                        { 
     3358                            $sMail = $GLOBALS['phpgw_info']['user']['email']; 
     3359                            $sCN = $GLOBALS['phpgw_info']['user']['fullname']; 
     3360                            $sUN = $GLOBALS['phpgw_info']['user']['account_id']; 
     3361                        } 
     3362                        //------------------------------------------------------------------------------------// 
    31283363                  
    31293364                    $temp_tz_offset = $this->prefs['common']['tz_offset']; 
    3130                          
    31313365                        $temp_timeformat = $this->prefs['common']['timeformat']; 
    31323366                        $temp_dateformat = $this->prefs['common']['dateformat']; 
    3133  
    31343367                        $tz_offset = ((60 * 60) * (int)$temp_tz_offset); 
    31353368 
     
    31383371                                $t_old_start_time = $this->maketime($old_event['start']); 
    31393372                                if($t_old_start_time < (time() - 86400)) 
    3140                                 { 
    31413373                                        return False; 
    31423374                                } 
    3143                         } 
    31443375 
    31453376                        $temp_user = $GLOBALS['phpgw_info']['user']; 
    3146  
    3147                         if (!$user) 
    3148                         { 
    3149                                 $user = $this->owner; 
    3150                         } 
     3377                        if (!$user) $user = $this->owner; 
    31513378                        $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences($user); 
     3379                        $this->prefs = $GLOBALS['phpgw_info']['user']['preferences']; 
    31523380 
    31533381                        $event = $msg_type == MSG_ADDED || $msg_type == MSG_MODIFIED ? $new_event : $old_event; 
     
    32163444                        $notify_msg = $this->prefs['calendar']['notify'.$msg]; 
    32173445                        if (empty($notify_msg)) 
    3218                         { 
    32193446                                $notify_msg = $this->prefs['calendar']['notifyAdded'];  // use a default 
    3220                         } 
     3447                         
    32213448                        $details = array(                       // event-details for the notify-msg 
    32223449                                'id'          => $msg_type == MSG_ADDED ? $new_event['id'] : $old_event['id'], 
     
    32523479                        $mail->Host = $emailadmin['smtpServer']; 
    32533480                        $mail->Port = $emailadmin['smtpPort']; 
    3254                         $mail->From = $GLOBALS['phpgw']->preferences->values['email']; 
    3255                         $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname']; 
    3256                         //$mail->IsHTML(true); 
    3257                         $mail->IsCalendar(true); 
    3258  
     3481                        $mail->From = $sMail; 
     3482                        $mail->FromName = $sCN; 
     3483                        $mail->IsHTML(true); 
     3484                        //Inicializa vari?vel de retorno. 
     3485                        $returncode=true;                
    32593486                        // Aqui e enviado o email 
    32603487                        foreach($to_notify as $userid => $statusid)  
     
    32643491                                $userid = (int)$userid; 
    32653492 
    3266                                 if ($statusid == 'R' || $GLOBALS['phpgw']->accounts->get_type($userid) == 'g') 
    3267                                 { 
    3268                                         continue;       // dont notify rejected participants 
    3269                                 } 
    3270                                 if($userid != $GLOBALS['phpgw_info']['user']['account_id'] || ($msg_type == MSG_ADDED && $userid != $owner) || $msg_type == MSG_ALARM || isset($new_event['attachment'])) 
    3271                                 //if($userid != $owner ||  $msg_type == MSG_ALARM || isset($new_event['attachment'])) 
     3493                                if ($statusid == 'R' || $GLOBALS['phpgw']->accounts->get_type($userid) == 'g' || ($sUN == $userid &&  $msg_type != MSG_ALARM)) 
     3494                                    continue;   // dont notify rejected participants or to == send 
     3495                                 
     3496                                if($userid != $sUN  ||  $msg_type == MSG_ALARM) 
    32723497                                { 
    32733498                                        print_debug('Msg Type',$msg_type); 
     3499                                         
    32743500                                        print_debug('UserID',$userid); 
    32753501 
     
    32853511 
    32863512                                        $to = $preferences->email_address($userid); 
     3513                                         
     3514                                         
     3515                                        if( $userid === -2 ) 
     3516                                        { 
     3517                                                $to = htmlspecialchars_decode( $event['organizer'] ); 
     3518                                        } 
    32873519                                         
    32883520                                        if (empty($to) || $to[0] == '@' || $to[0] == '$')       // we have no valid email-address 
     
    34033635                                                                                        if( trim($tmpmail) == trim($to) & trim($tmpuid) == trim($NewKey)) 
    34043636                                                                                        { 
    3405                                                                                                         if( ( $typesend == 3 ) || ( $typesend == 2 ) ) 
     3637                                                                                                        if($typesend == 3) 
    34063638                                                                                                        { 
    3407                                                                                                                 $question = ""; 
    3408                                                                                                                  
    3409                                                                                                                 if( $typesend == 2 ) 
    3410                                                                                                                         $question = lang("Do you wish to change your participation in this event?"); 
    34113639 
    34123640                                                                                                                $lang1 = lang("To See Commitment"); 
     
    34153643                                                                                                                                                                   </form>"; 
    34163644                                                                                                                $lang2 = lang("To accept"); 
    3417                                                                                                                 $varbuttom1 ="<input type='submit' value='$lang2' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=3&response=1&user_id=$userid\",\"frontpage\",\"height=200,width=450,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; 
     3645                                                                                                                $varbuttom1 ="<input type='submit' value='$lang2' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=3&response=1&user=".$tmpuid."\",\"frontpage\",\"height=100,width=500,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; 
     3646                                                                                                                 
     3647                                                                                                                $lang6 = lang("Tentative"); 
     3648                                                                                                                $varbuttom5 ="<input type='submit' value='$lang6' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=2&response=3&user=".$tmpuid."\",\"frontpage\",\"height=100,width=500,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; 
     3649                                                                                                                 
    34183650 
    34193651                                                                                                                $lang3 = lang("To reject"); 
    3420                                                                                                                 $varbuttom2 ="<input type='submit' value='$lang3' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=0&response=0\",\"frontpage\",\"height=100,width=400,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; 
     3652                                                                                                                $varbuttom2 ="<input type='submit' value='$lang3' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=0&response=2&user=".$tmpuid."\",\"frontpage\",\"height=100,width=500,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>"; 
    34213653                                                                                                                 
    34223654                                                                                                                $lang4 = lang("Alarm"); 
     
    34263658                                                                                                                                                                   </form>"; 
    34273659                                                                                                                                                                    
    3428                                                                                                                 $lang5 = lang("Delegate"); 
    3429                                                                                                                 $varbuttom4 = "<form action='".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.screen_delegate_event&id_event=$event[id]&date=$newall3&delegator=$tmpuid' method='POST'> 
     3660                                                                                                                $lang5 = lang("Suggest new hour");  
     3661                                                                                                                $varbuttom4 = "<form action=".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.view&cal_id=$event[id]&date=$newall3&type=1' method='POST'> 
    34303662                                                                                                                                                                  <input type='submit' value='$lang5'> 
    34313663                                                                                                                                                                   </form>"; 
    3432                                                                                                                  
    3433                                                                                                                 $lang6 = lang("Tentative"); 
    3434                                                                                                                 $varbuttom5 ="<input type='submit' value='$lang6' onClick='javascript:window.open(\"".$GLOBALS['phpgw_info']['server']['webserver_url']."/index.php?menuaction=calendar.uicalendar.set_action&cal_id=$event[id]&action=2&response=1&user_id=$userid\",\"frontpage\",\"height=200,width=450,statusbar=no,toolbar=no,scrollbars=no,menubar=no,left=300,top=200\")'>";                                                                                                              
    34353664                                                                                                        } 
    34363665                                                                                                        else 
     
    34663695                                                         
    34673696                                                        // A constante PHPGW_APP_TPL nao existe para envio de alarmes (cront, asyncservice). 
    3468                                                         define ("PHPGW_APP_TPL",PHPGW_API_INC . "/../../calendar/templates/".$GLOBALS['phpgw_info']['user']['preferences']['common']['template_dir'].""); 
     3697                                                        if(!PHPGW_APP_TPL) 
     3698                                                         define ("PHPGW_APP_TPL",PHPGW_INCLUDE_ROOT . "/calendar/templates/".$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].""); 
    34693699                                                         
    3470                                                         $body = CreateObject('phpgwapi.Template',PHPGW_APP_TPL); 
     3700                                                                $body = CreateObject('phpgwapi.Template',PHPGW_INCLUDE_ROOT . "/calendar/templates/".$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].""); 
    34713701                                                        $body->set_file(Array('calendar' => 'body_email.tpl')); 
    34723702                                                        $body->set_block('calendar','list'); 
     
    34863716                                                                'var8'                          => $var8, 
    34873717                                                                'vardata8'                      => $vardata8, 
    3488                                                                 'question'                      => $question,                                                                                                                    
    34893718                                                                'varbuttom'                     => $varbuttom, 
    34903719                                                                'varbuttom1'            => $varbuttom1, 
     
    35163745                                                        break; 
    35173746                                        } 
     3747                                        
    35183748                                        $mail->AddAddress($to); 
    3519                                         //$mail->Body = $tmpbody; 
    3520                                         $tmpattach_n = $this->create_vcard($GLOBALS['bocalendar']->so->cal->event); 
    3521                                         $tmpattach = str_replace("Expresso-","",$tmpattach_n); 
    3522                                         $mail->Body = "This is a multi-part message in MIME format."; 
    3523                                         $mail->Body .= "\n--01BD3665.3AF0D360\n"; 
    3524                                         $mail->Body .= "Content-Type: text/html; charset=\"iso-8859-1\"\nContent-Transfer-Encoding: 8bit\n"; 
    3525                                         $mail->Body .= $tmpbody; 
    3526                                         $mail->Body .= "\n--01BD3665.3AF0D360\n"; 
    3527                                         $mail->Body .="Content-Type:text/calendar; method=REQUEST; charset=US-ASCII\nContent-Transfer-Encoding:7bit\n\n"; 
    3528                                         $mail->Body .= $tmpattach; 
    3529                                         $mail->Body .= "\n--01BD3665.3AF0D360--\n"; 
    3530                                         $mail->From = $sender; 
    3531                                         $mail->FromName = $sender_name; 
     3749                                        $mail->Body = $tmpbody;       
     3750                                        $mail->From = $sMail; 
     3751                                        $mail->FromName = $sCN; 
    35323752                                        $mail->Sender = $mail->From; 
    35333753                                        $mail->SenderName = $mail->FromName; 
     
    35353755                                        unset($vardata5); 
    35363756                                        unset($vardata6); 
    3537                                 } 
    3538                         } 
    3539  
    3540                         //Inicializa variï¿œvel de retorno. 
    3541                         $returncode=true;                        
    3542                         if(count($mail->to)) { 
    3543  
    3544                             if(isset($new_event['attachment'])){ 
    3545                                 foreach($new_event['attachment'] as $attach){ 
    3546                                     $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $attach['type']); 
     3757                                         
     3758                                        // Envia aviso ao participante. 
     3759                                        if(!$mail->Send()) {                             
     3760                                                $returncode = false; 
     3761                                                $errorInfo['participants'] = $mail->ErrorInfo; 
     3762                        } 
     3763 
     3764                                        $mail->ClearAddresses();     
     3765 
    35473766                                } 
    35483767                            } 
    3549                                 // Envia aviso a todos os participantes. 
    3550                                 if(!$mail->Send()) {                             
    3551                                         $returncode = false; 
    3552                                         $errorInfo['participants'] = $mail->ErrorInfo; 
     3768 
     3769                        if(!is_object($this->ex_participants)) 
     3770                        { 
     3771                            include_once($_SESSION['rootPath'].'/calendar/inc/class.ex_participants.inc.php'); 
     3772                            $objexP = new exParticipants(); 
     3773                            $objexP->setParticipantsBySerializable($this->ex_participants); 
    35533774                                } 
    35543775                                else 
    3555                                         $returncode =  true; 
    3556                         } 
     3776                            $objexP = $this->ex_participants; 
     3777 
    35573778                         
    3558                         if(count($to_notify) && $this->ex_participants){ 
     3779                        if($msg_type === MSG_ADDED && count($this->extAdded) > 0) 
     3780                               $extMails = $this->extAdded;   
     3781                        else if($msg_type === MSG_DELETED && count($this->extDeleted) > 0) 
     3782                                $extMails = $this->extDeleted;   
     3783                        else  
     3784                            $extMails = array_diff($objexP->getParticipantsMailsArray(), $this->alreadyExtNotifieds); 
     3785                                
     3786                        if(count($extMails) > 0){ 
    35593787                                $mail->ClearAllRecipients(); 
    3560                                 $var = explode(",",trim($this->ex_participants)); 
    3561                                 $mail->IsHTML(true); 
     3788                               
    35623789                                $to = array(); 
    35633790                                if(!$subject) { 
     
    35673794                                } 
    35683795                                 
    3569                                 foreach($var as $index => $ex_participant){ 
     3796                                foreach($extMails as $index => $ex_participant){ 
    35703797                                        $ex_participant = trim($ex_participant); 
    35713798                                        $ex_participant = preg_replace('#"(.*)" <(.*)\@(.*)\.(.*)>#','\\2@\\3.\\4',$ex_participant); 
     
    35793806                                $_body = explode("<hr size='1' width='100%'>",$tmpbody); 
    35803807                                $tmpbody = $_body[0] ? $_body[0] : $subject ; 
    3581                                 $tmpbody.= "<br><b>".lang("external participants").":: </b> ".htmlentities($this->ex_participants); 
    3582                                 $tmpbody.= "<br>".lang("Summary").": ".$this->so->cal->event[title]."<br>"; 
     3808                                $tmpbody.= "<br><b>".lang("external participants").":: </b> ".htmlentities($objexP->getParticipantsMailsString()); 
     3809                                $tmpbody.= "<br>".lang("Summary").": ".$this->so->cal->event[description]."<br>"; 
    35833810                                $tmpbody.= "<br>".lang("Start time").": ".$GLOBALS['phpgw']->common->show_date($starttime)."<br>".lang("End date").": ".$GLOBALS['phpgw']->common->show_date($endtime)."<br>"; 
    35843811                                $tmpbody.= "<br><br><hr size='1' width='100%'><font color='red'>" 
     
    35923819                                //attach extern vcalendar/icalendar (ics)                        
    35933820                                // define('context','$GLOBALS.bocalendar.so.cal.event'); 
    3594                                 $tmpattach = $this->create_vcard($GLOBALS['bocalendar']->so->cal->event); 
     3821                                 
     3822                                $evt = $GLOBALS['bocalendar']->so->cal->event; 
     3823                                                                  
     3824                                /* 
     3825                                 * Cria Arqvuio ICS 
     3826                                 */ 
     3827                                require_once $_SESSION['rootPath'].'/API/class.servicelocator.php'; 
     3828                                $icalService = ServiceLocator::getService('ical'); 
     3829 
     3830                                if($msg_type == MSG_DELETED) 
     3831                                { 
     3832                                        $icalService->createICal(strtoupper($method)); 
     3833                                        $icalService->addEvent( 
     3834                                            $old_event['start']['year'].'-'.$old_event['start']['month'].'-'.$old_event['start']['mday'].' '.$old_event['start']['hour'].':'.$old_event['start']['min'].':00', 
     3835                                            $old_event['end']['year'].'-'.$old_event['end']['month'].'-'.$old_event['end']['mday'].' '.$old_event['end']['hour'].':'.$old_event['end']['min'].':00', 
     3836                                            array($sMail => array('CN'=> $sCN)), 
     3837                                            $old_event['title'], 
     3838                                            $old_event['description'], 
     3839                                            $old_event['location'], 
     3840                                            false, 
     3841                                            false, 
     3842                                            false, 
     3843                                            $old_event['uid'] 
     3844                                            ); 
     3845                                } 
     3846                                else 
     3847                                { 
     3848                                        $attendee = array(); 
     3849                                        foreach($to as $value) 
     3850                                            $attendee[$value] = array('RSVP' => 'TRUE','ROLE' => 'REQ-PARTICIPANT'); 
     3851 
     3852                                        $attendee =  array_merge($attendee,$this->getCalendarParticipantsArray($evt['id'])); 
     3853                                        $icalService->createICal(strtoupper($method)); 
     3854                                        $icalService->addEvent( 
     3855                                            $evt['start']['year'].'-'.$evt['start']['month'].'-'.$evt['start']['mday'].' '.$evt['start']['hour'].':'.$evt['start']['min'].':00', 
     3856                                            $evt['end']['year'].'-'.$evt['end']['month'].'-'.$evt['end']['mday'].' '.$evt['end']['hour'].':'.$evt['end']['min'].':00', 
     3857                                            array($sMail => array('CN'=> $sCN)), 
     3858                                            $evt['title'], 
     3859                                            $evt['description'], 
     3860                                            $evt['location'], 
     3861                                            $attendee, 
     3862                                            false, 
     3863                                            false, 
     3864                                            $evt['uid'] 
     3865                                            ); 
     3866 
     3867                                } 
     3868 
     3869 
     3870                                $tmpattach = $icalService->getICal(); 
     3871                                //-------------------------------------------------// 
     3872                                 
    35953873                                if($tmpattach){                                  
    3596                                         $tmpbody .="<a href='../index.php?menuaction=calendar.uicalendar.add&date=" 
    3597                                         .$GLOBALS['bocalendar']->so->cal->event[start][year] 
    3598                                 .$event_month 
    3599                                 .$GLOBALS['bocalendar']->so->cal->event[start][mday] 
    3600                                         ."&hour=".$GLOBALS['bocalendar']->so->cal->event[start][hour] 
    3601                                         ."&minute=".$GLOBALS['bocalendar']->so->cal->event[start][min] 
    3602                                         ."&title=".$GLOBALS['bocalendar']->so->cal->event['title'] 
    3603                                         ."&description=".$GLOBALS['bocalendar']->so->cal->event['description'] 
    3604                                         ."&location=".$GLOBALS['bocalendar']->so->cal->event['location']."'>" 
    3605                                         ."<h2>".lang("Add to my expresso")."</h2>"; 
    36063874                                        $tempdir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP; 
    36073875                                        srand((double)microtime()*1000000); 
     
    36143882                                        fclose($attach_fd); 
    36153883                                } 
    3616  
    3617                                 if(isset($new_event['attachment'])){ 
    3618                                     foreach($new_event['attachment'] as $attach){ 
    3619                                         $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $attach['type']); 
    3620                                     } 
    3621                                 } 
    3622                                  
    3623                                 $mail->From = $sender; 
    3624                                 $mail->FromName = $sender_name; 
     3884                                $mail->From = $sMail; 
     3885                                $mail->FromName = $sCN; 
    36253886                                $mail->Sender = $mail->From; 
    36263887                                $mail->SenderName = $mail->FromName; 
     
    36513912                        $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] = $temp_dateformat; 
    36523913                         
    3653                         // Notifica por email o criador do compromisso, com as possï¿œveis falhas.                                               
     3914                        // Notifica por email o criador do compromisso, com as poss?veis falhas.                                                 
    36543915                        if($errorInfo) { 
    36553916                                $tmpbody = "<font color='red'>".lang("The following commitment had problems for DELIVERING the NOTIFICATION messages.").".</font><br>"; 
     
    36783939                                $mail->Host = $emailadmin['smtpServer']; 
    36793940                                $mail->Port = $emailadmin['smtpPort']; 
    3680                                 $mail->From = $sender; 
    3681                                 $mail->FromName = $sender_name; 
     3941                                $mail->From = $sMail; 
     3942                                $mail->FromName = $sCN; 
    36823943                                $mail->Sender = $mail->From; 
    36833944                                $mail->SenderName = $mail->FromName; 
     
    36853946                                $mail->Subject = lang("calendar event")." - ".lang("email notification");                                                        
    36863947                                $mail->Body = $tmpbody;                                  
    3687                                 $mail->AddAddress($sender); 
     3948                                $mail->AddAddress($sMail); 
    36883949                                if(!$mail->Send())                       
    36893950                                        $returncode = false; 
     
    36933954                        return $returncode; 
    36943955                } 
     3956                 
     3957                 
     3958                 
     3959                /** 
     3960                 * @license http://www.gnu.org/copyleft/gpl.html GPL 
     3961                 * @author Prognus Software Livre (http://www.prognus.com.br) 
     3962                 */ 
     3963                function send_suggestion_external_owner($cal_id, $uid, $to, $time_suggest, $array_data_inicio, $array_data_final, $title, $description, $location, $ex_participants,$user = false) 
     3964                { 
     3965 
     3966                    if($cal_id) 
     3967                        $event =  $this->so->read_entry($cal_id); 
     3968                    else 
     3969                    { 
     3970                        $event = $this->restore_from_appsession(); 
     3971                        $this->so->add_entry( $event , false); 
     3972                    } 
     3973                     
     3974                    $this->so->cal->set_status($event['id'],$user,2); 
     3975 
     3976 
     3977                    if($user && $user != $GLOBALS['phpgw_info']['user']['account_id']) 
     3978                    { 
     3979                        $ldap = $this->getLdap(); 
     3980                        $justthese = array("mail","cn"); 
     3981                        $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l)(phpgwAccountType=s)(phpgwAccountType=i))(uidNumber=".$user."))"; 
     3982                        $search = ldap_search($ldap, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese); 
     3983                        $entry = ldap_get_entries($ldap, $search); 
     3984                        $ownerMail = $entry[0]['mail'][0]; 
     3985                        $ownerCN = $entry[0]['cn'][0]; 
     3986                     } 
     3987                     else 
     3988                     { 
     3989                        $ownerMail = $GLOBALS['phpgw_info']['user']['email']; 
     3990                        $ownerCN = $GLOBALS['phpgw_info']['user']['fullname']; 
     3991                     } 
     3992                      
     3993                    require_once $_SESSION['rootPath'] . '/API/class.servicelocator.php'; 
     3994                    $icalService = ServiceLocator::getService('ical'); 
     3995                    $dia_inicio = $array_data_inicio[0]; 
     3996                    $mes_inicio = $array_data_inicio[1]; 
     3997                    $ano_inicio = $array_data_inicio[2]; 
     3998                    $hora_inicio = $time_suggest['hora_inicio']; 
     3999                    $minuto_inicio = $time_suggest['minuto_inicio']; 
     4000                    $dia_final = $array_data_final[0]; 
     4001                    $mes_final = $array_data_final[1]; 
     4002                    $ano_final = $array_data_final[2]; 
     4003                    $hora_final = $time_suggest['hora_final']; 
     4004                    $minuto_final = $time_suggest['minuto_final']; 
     4005 
     4006                    $dtStart = $array_data_inicio[2] . '/' . 
     4007                               $array_data_inicio[1] . '/' . 
     4008                               $array_data_inicio[0] . ' ' . 
     4009                               $time_suggest['hora_inicio'] . ':' . 
     4010                               $time_suggest['minuto_inicio'] . ':00'; 
     4011 
     4012                    $dtEnd = $array_data_final[2] . '/' . 
     4013                             $array_data_final[1] . '/' . 
     4014                             $array_data_final[0] . ' ' . 
     4015                             $time_suggest['hora_final'] . ':' . 
     4016                             $time_suggest['minuto_final'] . ':00'; 
     4017 
     4018                    $icalService->createICal('REPLY'); 
     4019 
     4020                    $other = array( 'X-MICROSOFT-CDO-IMPORTANCE' => '1', 
     4021                                    'X-EXPRESSO-SUGGESTION-HOUR' => '1', 
     4022                                    'CLASS' => 'PUBLIC', 
     4023                                    'PRIORITY' => '5', 
     4024                                    'SEQIENCE' => '0', 
     4025                                    'TRANSP' => 'OPAQUE'); 
     4026 
     4027                    /* Corpo do email */ 
     4028                    $tmpbody2 = lang("The sender suggested a new hours for the appointment"); 
     4029                    $tmpbody2.= " <br /> <b>" . lang("Title") . ":</b> $title"; 
     4030                    $tmpbody2.= " <br /> <b>" . lang("Details") . ":</b> <br /> <br /> <b>" . lang("Start") . "  </b>" . $dia_inicio . "/" . $mes_inicio . "/" . $ano_inicio . " - " . $hora_inicio . ":" . $minuto_inicio; 
     4031                    $tmpbody2.= " <br /> <b>" . lang("End") . " </b>" . $dia_final . "/" . $mes_final . "/" . $ano_final . " - " . $hora_final . ":" . $minuto_final . "<br><br><br><br>"; 
     4032                    $tmpbody = lang("The sender suggested a new hours for the appointment"); 
     4033                    $tmpbody.= " \r\n " . lang("Title") . ": $title"; 
     4034                    $tmpbody.= " \r\n " . lang("Suggestion") . ": \r\n \r\n " . lang("Start") . "  " . $dia_inicio . "/" . $mes_inicio . "/" . $ano_inicio . " - " . $hora_inicio . ":" . $minuto_inicio; 
     4035                    $tmpbody.= " \r\n " . lang("End") . " " . $dia_final . "/" . $mes_final . "/" . $ano_final . " - " . $hora_final . ":" . $minuto_final . ""; 
     4036 
     4037                    $icalService->addEvent($dtStart, 
     4038                            $dtEnd, 
     4039                            $to, 
     4040                            $title, 
     4041                            utf8_encode($tmpbody), 
     4042                            $location, 
     4043                            array($ownerMail => array('CN' => $ownerCN, 'PARTSTAT' => 'TENTATIVE')), 
     4044                            $other, 
     4045                            false, 
     4046                            $uid 
     4047                    ); 
     4048                    
     4049                    $tmpattach =  $icalService->getICal();                    
     4050                     
     4051                    $mailService = ServiceLocator::getService('mail'); 
     4052                    $mailService->addStringAttachment($tmpattach, 'suggestion.ics', 'application/ics'); 
     4053                    $mailService->addStringAttachment($tmpattach, 'vcalendar.ics', 'text/calendar; charset=utf-8; method=REPLY;', '7bit', 'inline'); 
     4054                    $mailService->sendMail($to, $ownerMail, $title, $tmpbody2); 
     4055                      
     4056                    return $event['id'];                     
     4057                }                
    36954058                 
    36964059                function send_alarm($alarm) 
     
    37644127                } 
    37654128 
    3766                 function prepare_recipients(&$new_event,$old_event) 
    3767                 { 
    3768                                                  
    3769                         // Find modified and deleted users..... 
    3770                         while(list($old_userid,$old_status) = each($old_event['participants'])) 
    3771                         { 
    3772                                 if(isset($new_event['participants'][$old_userid])) 
    3773                                 { 
    3774                                         print_debug('Modifying event for user',$old_userid); 
    3775                                         $this->modified[(int)$old_userid] = $new_status; 
    3776                                 } 
    3777                                 else 
    3778                                 { 
    3779                                         print_debug('Deleting user from the event',$old_userid); 
    3780                                         $this->deleted[(int)$old_userid] = $old_status; 
    3781                                 } 
    3782                         } 
    3783                         // Find new users..... 
    3784                         while(list($new_userid,$new_status) = each($new_event['participants'])) 
    3785                         { 
    3786                                 if(!isset($old_event['participants'][$new_userid])) 
    3787                                 { 
    3788                                         print_debug('Adding event for user',$new_userid); 
    3789                                         $this->added[$new_userid] = 'U'; 
    3790                                         $new_event['participants'][$new_userid] = 'U'; 
    3791                                 } 
     4129                function prepare_recipients(&$new_event,$old_event,$userSend) 
     4130                { 
     4131                        //Verifica se ouve alguem deletado 
     4132                        foreach($old_event['participants'] as $key => $value) 
     4133                           if(!array_key_exists($key, $new_event['participants'])) 
     4134                                { 
     4135                               $this->deleted[$key] = $value; 
     4136                               $this->alreadyNotifieds[] = $key; //Adiciona a variavel de ja notificados para não serem notificados 2 vezes; 
     4137                                } 
     4138                        //Verifica se ouve alguem adicionado 
     4139                        foreach($new_event['participants'] as $key => $value) 
     4140                           if(!array_key_exists($key, $old_event['participants'])) 
     4141                                { 
     4142                               $this->added[$key] = $value; 
     4143                               $this->alreadyNotifieds[] = $key; //Adiciona a variavel de ja notificados para não serem notificados 2 vezes; 
    37924144                        } 
    37934145                         
    3794                         if(count($this->added) > 0 || count($this->modified) > 0 || count($this->deleted) > 0) 
    3795                         { 
    3796                                 if(count($this->added) > 0) 
    3797                                 { 
    3798                                         $this->ex_participants = ''; 
    3799                                         $this->send_update(MSG_ADDED,$this->added,'',$new_event); 
    3800                                 } 
    3801                                 if(count($this->modified) > 0) 
    3802                                 { 
    3803                                         $this->send_update(MSG_MODIFIED,$this->modified,$old_event,$new_event); 
    3804                                 } 
    3805                                 if(count($this->deleted) > 0) 
    3806                                 { 
    3807                                         $this->ex_participants = ''; 
    3808                                         $this->send_update(MSG_DELETED,$this->deleted,$old_event); 
    3809                                 } 
    3810                         } 
     4146                        //Verifica se ouve alguem modificado 
     4147                        foreach($new_event['participants'] as $key => $value) 
     4148                        { 
     4149                            if(array_key_exists($key, $old_event['participants']))                        
     4150                                { 
     4151                                if($old_event['participants'][$key] != $value) 
     4152                                { 
     4153                                    $this->modified[$key] = $value;   
     4154                                    $this->alreadyNotifieds[] = $key; //Adiciona a variavel de ja notificados para não serem notificados 2 vezes; 
     4155                                } 
     4156                                } 
     4157                        } 
     4158                         //Verificando alterações em usuarios externos 
     4159                         include_once($_SESSION['rootPath'].'/calendar/inc/class.ex_participants.inc.php'); 
     4160                         $extOld = new exParticipants(); 
     4161                         $extNew = new exParticipants(); 
     4162                          
     4163                         $extOld->setParticipantsBySerializable($old_event['ex_participants']); 
     4164                         $extNew->setParticipantsBySerializable($new_event['ex_participants']); 
     4165                         
     4166                         $oldArray = $extOld->getParticipantsMailsArray(); 
     4167                         $newArray = $extNew->getParticipantsMailsArray(); 
     4168                          
     4169                        //Verifica se ouve alguem deletado 
     4170                        $this->extDeleted = array_diff($oldArray, $newArray); 
     4171                         
     4172                        //Verifica se ouve alguem adicionado 
     4173                        $this->extAdded = array_diff($newArray, $oldArray); 
     4174                         
     4175                        $this->alreadyExtNotifieds = array_merge($this->alreadyExtNotifieds, $this->extDeleted); 
     4176                        $this->alreadyExtNotifieds = array_merge($this->alreadyExtNotifieds, $this->extAdded); 
     4177                        //---------------------------------------------------------------------------------// 
     4178                         
     4179                        if(count($this->added) > 0 || count($this->extAdded)) 
     4180                                $this->send_update(MSG_ADDED,$this->added,'',$new_event,$userSend); 
     4181                         
     4182                        if(count($this->modified) > 0) 
     4183                                $this->send_update(MSG_MODIFIED,$this->modified,$old_event,$new_event,$userSend); 
     4184                         
     4185                        if(count($this->deleted) > 0 || count($this->extDeleted)) 
     4186                                $this->send_update(MSG_DELETED,$this->deleted,$old_event,false,$userSend); 
     4187                                                 
    38114188                } 
    38124189 
     
    40214398                        ); 
    40224399 
     4400                        $owner = $event['owner']; 
     4401 
     4402                        $owner_name = ( $owner === -2 )? $event['organizer'] : $GLOBALS['phpgw']->common->grab_owner_name( $owner ); 
     4403 
    40234404                        $var['owner'] = Array( 
    40244405                                'field' => lang('Created By'), 
    4025                                 'data'  => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']) 
     4406                                'data'  => $owner_name 
    40264407                        ); 
    40274408 
     
    40314412                        ); 
    40324413 
    4033                         $var['observations'] = Array( 
    4034                                 'field' => $this->translate('Observations'), 
    4035                                 'data'  => $event['observations'] 
    4036                         ); 
    4037                          
    4038                         $var['attachment'] = Array( 
    4039                                 'field' => $this->translate('Attachment'), 
    4040                                 'data'  => $event['attachment'] 
    4041                         ); 
    4042  
    4043                         $var['alter_by'] = Array( 
    4044                                 'field' => $this->translate('Alter by'), 
    4045                                 'data'  => $event['alter_by'] 
    4046                         ); 
     4414                        if($event['public']){ 
     4415                                $type = lang('Public'); 
     4416                        }else if (!$event['public'] && $event['type'] == 'E'){ 
     4417                                $type = lang('Restrict'); 
     4418                        }else{ 
     4419                                $type = lang('Private'); 
     4420                        } 
    40474421 
    40484422                        $var['access'] = Array( 
    40494423                                'field' => lang('Access'), 
    4050                                 'data'  => $event['public'] ? lang('Public') : lang('Private') 
     4424                                'data'  => $type 
    40514425                        ); 
    40524426 
Note: See TracChangeset for help on using the changeset viewer.