Changeset 5132 for trunk/calendar/inc/class.bocalendar.inc.php
- Timestamp:
- 11/03/11 13:21:19 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/calendar/inc/class.bocalendar.inc.php
r4935 r5132 97 97 ); 98 98 99 var $wdays;100 101 99 var $debug = False; 102 100 // var $debug = True; … … 111 109 var $year; 112 110 var $prefs; 113 111 var $wdays; 114 112 var $owner; 115 113 var $holiday_color; 116 114 var $printer_friendly = False; 117 115 var $repetido; 118 116 var $cached_holidays; 119 117 … … 142 140 var $async = false; 143 141 142 var $alreadyNotifieds; 143 var $alreadyExtNotifieds = array(); 144 145 var $extAdded; 146 var $extDeleted; 147 144 148 function bocalendar($session=0) 145 149 { … … 300 304 MCAL_RECUR_DAILY => 'Daily', 301 305 MCAL_RECUR_WEEKLY => 'Weekly', 302 //MCAL_RECUR_MONTHLY_WDAY => 'Monthly (by day)',306 MCAL_RECUR_MONTHLY_WDAY => 'Monthly (by day)', 303 307 MCAL_RECUR_MONTHLY_MDAY => 'Monthly (by date)', 304 308 MCAL_RECUR_YEARLY => 'Yearly' … … 382 386 $this->wdays = Array(MCAL_M_SUNDAY,MCAL_M_MONDAY,MCAL_M_TUESDAY,MCAL_M_WEDNESDAY, 383 387 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=$idEvento404 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();417 388 } 418 389 … … 656 627 // print_debug('exception time',$event['recur_exception'][count($event['recur_exception']) -1]); 657 628 // print_debug('count event exceptions',count($event['recur_exception'])); 658 $this->so->add_entry($event );629 $this->so->add_entry($event,true,$event['owner']); 659 630 $cd = 16; 660 631 … … 756 727 if($this->check_perms(PHPGW_ACL_DELETE,$event)) 757 728 { 758 $this->send_update(MSG_DELETED,$event['participants'],$event );729 $this->send_update(MSG_DELETED,$event['participants'],$event,false,$event['owner']); 759 730 } 760 731 else … … 815 786 $participants = $event['participants']; 816 787 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;824 788 825 789 switch($event['recur_type']) { … … 998 962 function update($params='') 999 963 { 964 $prefix = ( $params['from_mobile'] ? "mobile.ui_mobile" : "calendar.ui" ) . "calendar"; 1000 965 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"; 1011 968 1012 969 if(!is_object($GLOBALS['phpgw']->datetime)) … … 1014 971 $GLOBALS['phpgw']->datetime = createobject('phpgwapi.date_time'); 1015 972 } 1016 1017 973 $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 else1030 $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 }1051 974 $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 1053 983 $l_categories = (@$params['categories']?$params['categories']:$_POST['categories']); 1054 984 $l_start = (@isset($params['start']) && $params['start']?$params['start']:$_POST['start']); … … 1083 1013 } 1084 1014 } 1085 unset($l_cal['participants']); 1015 1086 1016 1087 1017 if (!is_object($GLOBALS['phpgw']->categories)) … … 1120 1050 $event['title'] = stripslashes($event['title']); 1121 1051 $event['description'] = stripslashes($event['description']); 1122 $event['observations'] = stripslashes($event['observations']);1123 1052 $event['ex_participants'] = stripslashes($event['ex_participants']); 1124 1053 $datetime_check = $this->validate_update($event); … … 1136 1065 return; 1137 1066 } 1138 $overlapping_events = False;1067 //$overlapping_events = False; 1139 1068 } 1140 1069 else … … 1163 1092 if(!isset($l_cal['ex_participants'])) 1164 1093 { 1165 $l_cal['ex_participants'] = $this->ex_participants ;1094 $l_cal['ex_participants'] = $this->ex_participants->getParticipantsSerializable(); 1166 1095 } 1167 1096 … … 1173 1102 $is_public = ($l_cal['type'] != 'private' && $l_cal['type'] != 'privateHiddenFields'); 1174 1103 $this->so->event_init(); 1104 1105 if($l_cal['uid']) 1175 1106 $this->add_attribute('uid',$l_cal['uid']); 1107 else 1108 $this->add_attribute('uid',time().'@Expresso'); 1109 1110 1176 1111 $this->add_attribute('type',$l_cal['type']); 1177 1112 if($l_cal['ex_participants']) { … … 1188 1123 $this->so->set_title($l_cal['title']); 1189 1124 $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']);1193 1125 $this->so->set_ex_participants($l_cal['ex_participants']); 1194 1126 $this->so->set_start($l_start['year'],$l_start['month'],$l_start['mday'],$l_start['hour'],$l_start['min'],0); … … 1197 1129 $this->so->add_attribute('reference',(@isset($l_cal['reference']) && $l_cal['reference']?$l_cal['reference']:0)); 1198 1130 $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));1203 1131 if($l_cal['id']) 1204 1132 { … … 1222 1150 $this->so->set_recur_none(); 1223 1151 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; 1227 1153 1228 1154 break; … … 1230 1156 $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']); 1231 1157 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; 1234 1159 1235 1160 $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; … … 1238 1163 if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: 1239 1164 { 1240 $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:''));1241 1165 1242 1166 $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; … … 1250 1174 case MCAL_RECUR_WEEKLY: 1251 1175 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; 1254 1177 1255 1178 $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; … … 1259 1182 { 1260 1183 1261 $this->so->add_attribute('rpt_end_use',(@isset($l_cal['rpt_use_end']) && $l_cal['rpt_use_end']?$l_cal['rpt_use_end']:''));1262 1184 $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 1263 1185 $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; … … 1280 1202 } 1281 1203 } 1282 $this->so->add_attribute('rpt_wdays',(@isset($rpt_wdays) && $rpt_wdays?$rpt_wdays:''));1283 1204 $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']); 1284 1205 break; … … 1286 1207 $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']); 1287 1208 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; 1290 1210 1291 1211 $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; … … 1294 1214 if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: 1295 1215 { 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 1297 1217 $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 1298 1218 $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; … … 1309 1229 $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']); 1310 1230 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; 1313 1232 1314 1233 $tmp_init = explode("/",$_POST['start']['str']); // recebe a data inicial da repeticao; … … 1317 1236 if($l_cal['rpt_use_end'] == 'y') // verifica se foi indicada data final da repeticao, se sim: 1318 1237 { 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 1320 1239 $tmp_end = explode("/",$_POST['recur_enddate']['str']); // recebe data final da repeticao; 1321 1240 $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; … … 1340 1259 } 1341 1260 $acct_type = $GLOBALS['phpgw']->accounts->get_type((int)$parts[$i]); 1342 if($acct_type == 'u' )1261 if($acct_type == 'u' || $acct_type == 's') 1343 1262 { 1344 1263 $part[(int)$parts[$i]] = $accept_type; … … 1422 1341 $event = $this->get_cached_event(); 1423 1342 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) 1426 1344 { 1427 1345 $offset = ($l_cal['alarmdays'] * 24 * 3600) + … … 1435 1353 'owner' => $this->owner, 1436 1354 'enabled' => 1, 1437 'repeat' => $ repetido, // para repetir alarme;1355 'repeat' => $this->repetido, // para repetir alarme; 1438 1356 'init_rept' => $init_rept, // inicio repeticao; 1439 1357 'end_rept' => $end_rept, // fim repeticao; … … 1463 1381 } 1464 1382 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 1465 1475 if($event['id']) 1466 1476 { … … 1472 1482 } 1473 1483 1474 if (isset($repetido) and $repetido > 0){ 1484 if (isset($this->repetido) and $this->repetido > 0) 1485 { 1475 1486 $events = $this->expand_repetition($event); 1476 1487 $overlapping_events = False; … … 1492 1503 } 1493 1504 } 1494 else { 1505 else 1506 { 1495 1507 $overlapping_events = $this->overlap( 1496 1508 $this->maketime($event['start']), … … 1501 1513 ); 1502 1514 } 1503 } 1504 if(!$this->ex_participants) 1505 $this->ex_participants = $event['ex_participants']; 1515 1506 1516 if($overlapping_events) 1507 1517 { 1518 $this->store_to_appsession( $event ); 1508 1519 if($send_to_ui) 1509 1520 { 1510 $event['ex_participants'] = $this->ex_participants;1511 1521 unset($GLOBALS['phpgw_info']['flags']['noheader']); 1512 1522 unset($GLOBALS['phpgw_info']['flags']['nonavbar']); 1513 ExecMethod($ui_overlap,1523 ExecMethod("$prefix.overlap", 1514 1524 Array( 1515 1525 'o_events' => $overlapping_events, 1516 'this_event' => $event 1526 'this_event' => $event, 1527 'this_account' => $user 1517 1528 ) 1518 1529 ); 1519 if(!$params['from_mobile']) 1530 1531 if( $prefix === "calendar.uicalendar" ) 1520 1532 $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 ); 1577 1539 } 1578 1540 … … 1700 1662 $error = 43; 1701 1663 } 1702 elseif ($event['t ype'] != 'hourAppointment' && $event['title'] == '')1664 elseif ($event['title'] == '') 1703 1665 { 1704 1666 $error = 40; 1705 1667 } 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 }1747 1668 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)) 1748 1669 { 1749 1670 $error = 41; 1750 1671 } 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)) 1755 1673 { 1756 1674 $error = 42; … … 1758 1676 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) 1759 1677 { 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 } 1768 1683 1769 1684 return $error; … … 1789 1704 } 1790 1705 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 1803 1706 function overlap($starttime,$endtime,$participants,$owner=0,$id=0,$restore_cache=False) 1804 1707 { … … 1909 1812 $temp_start_time >= $temp_event_start && 1910 1813 $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)) 1912 1815 { 1913 1816 if($this->debug) … … 2080 1983 function get_short_field($event,$is_private=True,$field='') 2081 1984 { 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') 2083 1990 { 2084 1991 return lang('private'); … … 2342 2249 $search_date_day = date('d',$datetime); 2343 2250 $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); 2345 2252 if($this->debug) 2346 2253 { … … 2409 2316 break; 2410 2317 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) 2412 2319 { 2413 2320 continue; … … 2934 2841 @abstract set the participant response $status for event $cal_id and notifies the owner of the event 2935 2842 */ 2936 function set_status($cal_id,$status )2843 function set_status($cal_id,$status,$user = false) 2937 2844 { 2938 2845 $status2msg = array( … … 2946 2853 } 2947 2854 $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']; 2949 2857 if(($status2msg[$status] == "5" && $event['participants'][$account_id] == "A") || 2950 2858 ($status2msg[$status] == "3" && $event['participants'][$account_id] == "R")) { 2951 2859 return True; 2952 2860 } 2953 $this->so->set_status($cal_id,$status );2861 $this->so->set_status($cal_id,$status,$account_id); 2954 2862 $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 } 2957 2875 } 2958 2876 … … 3015 2933 } 3016 2934 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 3019 2941 if(!is_array($event_arrays)) 3020 2942 return null; 3021 2943 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; 3040 2952 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('<', $event_array['organizer']); 2985 $email2 = explode('>', $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" 3048 2994 ."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 ") 3051 2999 ."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) 3058 3078 { 3059 if($mail != "") 3079 // There are no spaces to break on! Going to truncate :( 3080 if(!$last_space) 3060 3081 { 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; 3062 3103 } 3063 3104 } 3064 3105 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) 3066 3113 { 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) 3071 3118 { 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"; 3074 3138 } 3075 elseif($status == 'A' ){ 3076 $tmpattach.="ATTENDEE;RSVP=TRUE;PARTSTAT=ACCEPTED;ROLE=REQ-PARTICIPANT:mailto:".$mail."\n";3139 3140 return $return; 3077 3141 } 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 3080 3196 } 3081 3197 else 3198 if(preg_match("(<[^>]*@[^>]*>)", $participant['mail'])) 3082 3199 { 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 3084 3205 } 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 3085 3223 } 3086 3224 } 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; 3092 3319 } 3093 3320 … … 3101 3328 @param $new_event Event after the change 3102 3329 */ 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(); 3109 3334 $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 3114 3339 $version = $GLOBALS['phpgw_info']['apps']['calendar']['version']; 3115 3116 3340 $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);3120 3341 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; 3127 3355 } 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 //------------------------------------------------------------------------------------// 3128 3363 3129 3364 $temp_tz_offset = $this->prefs['common']['tz_offset']; 3130 3131 3365 $temp_timeformat = $this->prefs['common']['timeformat']; 3132 3366 $temp_dateformat = $this->prefs['common']['dateformat']; 3133 3134 3367 $tz_offset = ((60 * 60) * (int)$temp_tz_offset); 3135 3368 … … 3138 3371 $t_old_start_time = $this->maketime($old_event['start']); 3139 3372 if($t_old_start_time < (time() - 86400)) 3140 {3141 3373 return False; 3142 3374 } 3143 }3144 3375 3145 3376 $temp_user = $GLOBALS['phpgw_info']['user']; 3146 3147 if (!$user) 3148 { 3149 $user = $this->owner; 3150 } 3377 if (!$user) $user = $this->owner; 3151 3378 $GLOBALS['phpgw_info']['user']['preferences'] = $GLOBALS['phpgw']->preferences->create_email_preferences($user); 3379 $this->prefs = $GLOBALS['phpgw_info']['user']['preferences']; 3152 3380 3153 3381 $event = $msg_type == MSG_ADDED || $msg_type == MSG_MODIFIED ? $new_event : $old_event; … … 3216 3444 $notify_msg = $this->prefs['calendar']['notify'.$msg]; 3217 3445 if (empty($notify_msg)) 3218 {3219 3446 $notify_msg = $this->prefs['calendar']['notifyAdded']; // use a default 3220 }3447 3221 3448 $details = array( // event-details for the notify-msg 3222 3449 'id' => $msg_type == MSG_ADDED ? $new_event['id'] : $old_event['id'], … … 3252 3479 $mail->Host = $emailadmin['smtpServer']; 3253 3480 $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; 3259 3486 // Aqui e enviado o email 3260 3487 foreach($to_notify as $userid => $statusid) … … 3264 3491 $userid = (int)$userid; 3265 3492 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) 3272 3497 { 3273 3498 print_debug('Msg Type',$msg_type); 3499 3274 3500 print_debug('UserID',$userid); 3275 3501 … … 3285 3511 3286 3512 $to = $preferences->email_address($userid); 3513 3514 3515 if( $userid === -2 ) 3516 { 3517 $to = htmlspecialchars_decode( $event['organizer'] ); 3518 } 3287 3519 3288 3520 if (empty($to) || $to[0] == '@' || $to[0] == '$') // we have no valid email-address … … 3403 3635 if( trim($tmpmail) == trim($to) & trim($tmpuid) == trim($NewKey)) 3404 3636 { 3405 if( ( $typesend == 3 ) || ( $typesend == 2 ))3637 if($typesend == 3) 3406 3638 { 3407 $question = "";3408 3409 if( $typesend == 2 )3410 $question = lang("Do you wish to change your participation in this event?");3411 3639 3412 3640 $lang1 = lang("To See Commitment"); … … 3415 3643 </form>"; 3416 3644 $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 3418 3650 3419 3651 $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\")'>"; 3421 3653 3422 3654 $lang4 = lang("Alarm"); … … 3426 3658 </form>"; 3427 3659 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'> 3430 3662 <input type='submit' value='$lang5'> 3431 3663 </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\")'>";3435 3664 } 3436 3665 else … … 3466 3695 3467 3696 // 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'].""); 3469 3699 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'].""); 3471 3701 $body->set_file(Array('calendar' => 'body_email.tpl')); 3472 3702 $body->set_block('calendar','list'); … … 3486 3716 'var8' => $var8, 3487 3717 'vardata8' => $vardata8, 3488 'question' => $question,3489 3718 'varbuttom' => $varbuttom, 3490 3719 'varbuttom1' => $varbuttom1, … … 3516 3745 break; 3517 3746 } 3747 3518 3748 $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; 3532 3752 $mail->Sender = $mail->From; 3533 3753 $mail->SenderName = $mail->FromName; … … 3535 3755 unset($vardata5); 3536 3756 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 3547 3766 } 3548 3767 } 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); 3553 3774 } 3554 3775 else 3555 $returncode = true;3556 } 3776 $objexP = $this->ex_participants; 3777 3557 3778 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){ 3559 3787 $mail->ClearAllRecipients(); 3560 $var = explode(",",trim($this->ex_participants)); 3561 $mail->IsHTML(true); 3788 3562 3789 $to = array(); 3563 3790 if(!$subject) { … … 3567 3794 } 3568 3795 3569 foreach($ varas $index => $ex_participant){3796 foreach($extMails as $index => $ex_participant){ 3570 3797 $ex_participant = trim($ex_participant); 3571 3798 $ex_participant = preg_replace('#"(.*)" <(.*)\@(.*)\.(.*)>#','\\2@\\3.\\4',$ex_participant); … … 3579 3806 $_body = explode("<hr size='1' width='100%'>",$tmpbody); 3580 3807 $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>"; 3583 3810 $tmpbody.= "<br>".lang("Start time").": ".$GLOBALS['phpgw']->common->show_date($starttime)."<br>".lang("End date").": ".$GLOBALS['phpgw']->common->show_date($endtime)."<br>"; 3584 3811 $tmpbody.= "<br><br><hr size='1' width='100%'><font color='red'>" … … 3592 3819 //attach extern vcalendar/icalendar (ics) 3593 3820 // 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 3595 3873 if($tmpattach){ 3596 $tmpbody .="<a href='../index.php?menuaction=calendar.uicalendar.add&date="3597 .$GLOBALS['bocalendar']->so->cal->event[start][year]3598 .$event_month3599 .$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>";3606 3874 $tempdir = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP; 3607 3875 srand((double)microtime()*1000000); … … 3614 3882 fclose($attach_fd); 3615 3883 } 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; 3625 3886 $mail->Sender = $mail->From; 3626 3887 $mail->SenderName = $mail->FromName; … … 3651 3912 $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'] = $temp_dateformat; 3652 3913 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. 3654 3915 if($errorInfo) { 3655 3916 $tmpbody = "<font color='red'>".lang("The following commitment had problems for DELIVERING the NOTIFICATION messages.").".</font><br>"; … … 3678 3939 $mail->Host = $emailadmin['smtpServer']; 3679 3940 $mail->Port = $emailadmin['smtpPort']; 3680 $mail->From = $s ender;3681 $mail->FromName = $s ender_name;3941 $mail->From = $sMail; 3942 $mail->FromName = $sCN; 3682 3943 $mail->Sender = $mail->From; 3683 3944 $mail->SenderName = $mail->FromName; … … 3685 3946 $mail->Subject = lang("calendar event")." - ".lang("email notification"); 3686 3947 $mail->Body = $tmpbody; 3687 $mail->AddAddress($s ender);3948 $mail->AddAddress($sMail); 3688 3949 if(!$mail->Send()) 3689 3950 $returncode = false; … … 3693 3954 return $returncode; 3694 3955 } 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 } 3695 4058 3696 4059 function send_alarm($alarm) … … 3764 4127 } 3765 4128 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; 3792 4144 } 3793 4145 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 3811 4188 } 3812 4189 … … 4021 4398 ); 4022 4399 4400 $owner = $event['owner']; 4401 4402 $owner_name = ( $owner === -2 )? $event['organizer'] : $GLOBALS['phpgw']->common->grab_owner_name( $owner ); 4403 4023 4404 $var['owner'] = Array( 4024 4405 'field' => lang('Created By'), 4025 'data' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner'])4406 'data' => $owner_name 4026 4407 ); 4027 4408 … … 4031 4412 ); 4032 4413 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 } 4047 4421 4048 4422 $var['access'] = Array( 4049 4423 'field' => lang('Access'), 4050 'data' => $ event['public'] ? lang('Public') : lang('Private')4424 'data' => $type 4051 4425 ); 4052 4426
Note: See TracChangeset
for help on using the changeset viewer.