Changeset 7006
- Timestamp:
- 08/14/12 15:23:24 (12 years ago)
- Location:
- trunk/prototype
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/modules/calendar/css/style.css
r6996 r7006 543 543 .calendar-addevent-details-txt-timezone, .calendar-addtask-details-txt-timezone{width: 217px;} 544 544 545 .div-addtask #calendar_addtask_details1 .time-previs ao{ width: 40px; }546 547 .div-addtask #calendar_addtask_details1 .date-previs ao{ width: 80px; }545 .div-addtask #calendar_addtask_details1 .time-prevision { width: 40px; } 546 547 .div-addtask #calendar_addtask_details1 .date-prevision{ width: 80px; } 548 548 549 549 .div-addtask #calendar_addtask_details1 .start-time{ width: 40px; } … … 551 551 .div-addtask #calendar_addtask_details1 .end-time{ width: 40px; } 552 552 .div-addtask #calendar_addtask_details1 .end-date{ width: 80px; } 553 .div-addtask #calendar_addtask_details1 .previs ao-termino { margin: 0 0 0 30px; }553 .div-addtask #calendar_addtask_details1 .prevision-termino { margin: 0 0 0 30px; } 554 554 .div-addtask #calendar_addtask_details1 .subitem { margin: 5px; display: block;} 555 555 .div-addtask #calendar_addtask_details1 .subitem .span_done{ margin: 0 30px;} … … 614 614 .div-addactivity #group_addactivity_details1 .end-time{ width: 40px; } 615 615 .div-addactivity #group_addactivity_details1 .end-date{ width: 80px; } 616 .div-addactivity #group_addactivity_details1 .previs ao-termino { margin: 0 0 0 30px; }616 .div-addactivity #group_addactivity_details1 .prevision-termino { margin: 0 0 0 30px; } 617 617 .div-addactivity #group_addactivity_details1 .subitem { margin: 5px; display: block;} 618 618 .div-addactivity #group_addactivity_details1 .subitem .span_done{ margin: 0 30px;} -
trunk/prototype/modules/calendar/interceptors/DBMapping.php
r6996 r7006 13 13 { 14 14 15 if (isset($params['startTime']) && !is_numeric($params['startTime'])) {15 if (isset($params['startTime']) && !is_numeric($params['startTime'])) 16 16 $params['startTime'] = self::parseTimeDate($params['startTime'], $params['timezone']); 17 $params['rangeStart'] = $params['startTime']; 18 } 17 18 $params['rangeStart'] = $params['startTime']; 19 19 20 if (isset($params['endTime']) && !is_numeric($params['endTime'])) { 20 21 $params['endTime'] = self::parseTimeDate($params['endTime'], $params['timezone']); 21 22 22 23 if ($params['allDay']) 23 $params['endTime'] = $params['endTime'] + 86400000; 24 $params['endTime'] = $params['endTime'] + 86400000; 25 } 24 26 25 26 }27 $params['rangeEnd'] = $params['endTime']; 28 27 29 28 30 if (isset($params['due']) && $params['due'] != '' && !is_numeric($params['due'])) -
trunk/prototype/modules/calendar/js/calendar.codecs.js
r6996 r7006 901 901 'status': 'Status', 902 902 'percentage': 'Porcentagem', 903 'priority': 'Prior udade',903 'priority': 'Prioridade', 904 904 'due' : 'Previsão de término' 905 905 } -
trunk/prototype/modules/calendar/js/init.js
r6996 r7006 249 249 endTime: new Date().toString('yyyy-MM-dd 00:00:00'), 250 250 allDay: '1', 251 priority: '1', 251 252 participants: 252 253 [{ -
trunk/prototype/modules/calendar/js/task.helpers.js
r6996 r7006 25 25 var start_time = $(".new-task-win.active .start-time").val(); 26 26 var end_time = $(".new-task-win.active .end-time").val(); 27 var due_date = $(".new-task-win.active .date-previs ao").val();28 var due_time = $.trim($(".new-task-win.active .time-previs ao").val());27 var due_date = $(".new-task-win.active .date-prevision").val(); 28 var due_time = $.trim($(".new-task-win.active .time-prevision").val()); 29 29 var isAllDay = $('.new-task-win.active input[name="allDay"]').is(':checked'); 30 30 var customDate = $(".endRepeat").val() == "customDate"; … … 431 431 UI.dialogs.addTask.find(".input-group .h1").Watermark("Tarefa sem título"); 432 432 if (User.preferences.hourFormat.length == 5) { 433 UI.dialogs.addTask.find(".end-time, .start-time, .time-previs ao").mask("99:99", {433 UI.dialogs.addTask.find(".end-time, .start-time, .time-prevision").mask("99:99", { 434 434 completed: function () { 435 435 updateMap(); … … 439 439 $.mask.definitions['{'] = '[ap]'; 440 440 $.mask.definitions['}'] = '[m]'; 441 UI.dialogs.addTask.find(".end-time, .start-time ").mask("99:99 {}", {441 UI.dialogs.addTask.find(".end-time, .start-time, .time-prevision").mask("99:99 {}", { 442 442 completed: function () { 443 443 $(this).val(date.Calendar.defaultToAmPm($(this).val())); -
trunk/prototype/modules/calendar/templates/attendees_task.ejs
r6996 r7006 118 118 </ul> 119 119 </dd> 120 <dd class="attendee-list-add " <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%>>120 <dd class="attendee-list-add <%= data.task.isOrganizer ? '' : 'hidden'%>"> 121 121 <fieldset class="add-attendee-input input-field-rounded ui-corner-all"> 122 122 <span class="ui-icon ui-icon-plus" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%>></span> … … 154 154 <dl class="block-add-attendee search <%= data.task.isOrganizer ? '' : 'hidden'%>"> 155 155 <dt class="add-attendee search">Adicionar outros convidados</dt> 156 <dd class="add-attendee ">156 <dd class="add-attendee <%= data.task.isOrganizer ? '' : 'hidden'%>"> 157 157 <fieldset class="block-add-attendee" title="Participantes"> 158 158 <fieldset class="add-attendee-search search-field ui-corner-all"> -
trunk/prototype/modules/calendar/templates/task_add.ejs
r6996 r7006 20 20 <input type="text" class="time end-time<%= (data.task.allDay) ? ' hidden' : '' %>" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%> value="<%= (data.task.endHour) ? data.task.endHour : '' %>" name="endHour" /> 21 21 22 <span class="previs ao-termino">Previsão término:</span>23 <input type="text" name="dueDate" class="date date-previs ao" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%> value="<%= data.task.dueDate %>">24 <input type="text" name="dueTime" class="time time-previs ao" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%> value="<%= data.task.dueTime %>">22 <span class="prevision-termino">Previsão término:</span> 23 <input type="text" name="dueDate" class="date date-prevision" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%> value="<%= data.task.dueDate %>"> 24 <input type="text" name="dueTime" class="time time-prevision" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%> value="<%= data.task.dueTime %>"> 25 25 26 26 <a href="#" class="calendar_addtask_details_lnk_timezone" <%= data.task.isOrganizer ? '' : 'disabled="disabled"'%>>Fuso horário</a> -
trunk/prototype/services/iCal.php
r6996 r7006 109 109 110 110 break; 111 111 case TASK_ID: 112 113 $todo = $ical->newComponent('todo'); 114 115 $todo->setProperty('summary', $v['summary']); 116 $todo->setProperty('description', isset($v['description']) ? $v['description'] : ''); 117 $todo->setProperty('priority', $v['priority']); 118 $todo->setProperty('percent-complete', $v['percentage']); 119 $todo->setProperty('status', $this->_getStatusTodo($v['status'])); 120 121 $timezone = new DateTimeZone('UTC'); 122 $apTimezone = self::nomalizeTZID(( isset($v['timezone']) && $v['timezone'] != 'null' ) ? $v['timezone'] : $params['defaultTZI']); 123 $apTimezoneOBJ = new DateTimeZone($apTimezone); 124 125 $sTime = new DateTime('@' . (int) ($v['startTime'] / 1000), $timezone); 126 $sTime->setTimezone($apTimezoneOBJ); 127 $eTime = new DateTime('@' . (int) ($v['endTime'] / 1000), $timezone); 128 $eTime->setTimezone($apTimezoneOBJ); 129 130 if (isset($v['allDay']) && $v['allDay'] == 1) { 131 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array("VALUE" => "DATE")); 132 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array("VALUE" => "DATE")); 133 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'TRUE'); 134 } else { 135 $todo->setProperty('dtstart', $sTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 136 $todo->setProperty('dtend', $eTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 137 //$todo->setProperty('X-MICROSOFT-CDO-ALLDAYEVENT', 'FALSE'); 138 } 139 140 if(isset($v['due']) && $v['due'] != ''){ 141 $dueTime = new DateTime('@' . (int) ($v['due'] / 1000), $timezone); 142 $dueTime->setTimezone($apTimezoneOBJ); 143 144 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 145 } 146 147 $todo->setProperty('due', $dueTime->format(DATE_RFC822), array('TZID' => $apTimezone)); 148 149 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 150 $participants = $v['participants']; 151 else 152 $participants = Controller::find(array('concept' => 'participant'), false, array('filter' => array('=', 'schedulable', $v['id']))); 153 154 if (is_array($participants) && count($participants) > 0) 155 foreach ($participants as $ii => $vv) { 156 157 if(isset($participants[$ii]['user']) && !is_array($participants[$ii]['user'])) 158 { 159 if ($vv['isExternal'] == 1) 160 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'], 'service' => 'PostgreSQL')); 161 else 162 $participants[$ii]['user'] = Controller::read(array('concept' => 'user', 'id' => $vv['user'])); 163 } 164 165 if ($participants[$ii]['user']['id'] == Config::me('uidNumber')) 166 { 167 $alarms = (isset($participants[$ii]['alarms'])) ? $participants[$ii]['alarms'] : Controller::find(array('concept' => 'alarm'), null, array('filter' => array('AND', array('=', 'participant', $vv['id']), array('=', 'schedulable', $v['id'])))); 168 if(is_array($alarms)) 169 self::createAlarms($alarms, $todo); 170 } 171 172 } 173 174 if (isset($v['participants']) && is_array($v['participants']) && count($v['participants']) > 0) 175 $this->createAttendee($v['participants'], $todo); 176 177 if (isset($v['attachments']) && is_array($v['attachments']) && count($v['attachments']) > 0) 178 $this->createAttachment($v['attachments'], $todo); 179 180 $todo->setProperty('uid', $v['uid']); 181 182 break; 112 183 default: 113 184 break; … … 412 483 case 'PUBLISH': 413 484 //Caso o evento não exista o mesmo cria um novo evento, se já existir o mesmo referencia o evento com agenda 414 415 $interation = self::_makeVEVENT($schedulable, $component, $params);416 417 418 array('AND',419 array('=', 'calendar', $params['calendar']),420 array('=', 'schedulable', $schedulable['id'])421 )));422 423 424 425 426 485 if (!$schedulable = self::_getSchedulable($uid)) 486 $interation = self::_makeVEVENT($schedulable, $component, $params); 487 else{ 488 $links = Controller::read(array('concept' => 'calendarToSchedulable'), array('id'), array('filter' => 489 array('AND', 490 array('=', 'calendar', $params['calendar']), 491 array('=', 'schedulable', $schedulable['id']) 492 ))); 493 494 if(!$links && !isset($links[0])) 495 Controller::create(array('concept' => 'calendarToSchedulable'), array('calendar' => $params['calendar'], 'schedulable' => $schedulable['id'])); 496 497 } 427 498 break; 428 499 … … 441 512 $user = Controller::Read(array('concept' => 'user'), false, array('filter' => array('=', 'id', $params['owner'])) ); 442 513 $pID = self::_getParticipantByMail($user[0]['mail'], $schedulable['participants']); 443 }else 444 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 445 $interation['participant://' . $pID]['status'] = $params['status']; 514 }else{ 515 $pID = self::_getParticipantByMail(Config::me('mail'), $schedulable['participants']); 516 //caso nõa seja participante adiciona a lista de participantes 517 if(!$pID){ 518 $pID = mt_rand() . '2(Formatter)'; 519 $interation['participant://' . $pID]['status'] = $params['status']; 520 $interation['participant://' . $pID]['user'] = $params['owner']; 521 $interation['participant://' . $pID]['isOrganizer'] = '0'; 522 $interation['participant://' . $pID]['schedulable'] = $schedulable['id']; 523 }else 524 $interation['participant://' . $pID]['status'] = $params['status']; 525 } 446 526 } 447 527 … … 1049 1129 foreach ($schedulable['participants'] as $value) 1050 1130 if ($value['user']['id'] == $params['owner']) { 1051 $isParticipant = true;1052 if ($value['isOrganizer'])1053 $isOrganizer = true;1054 1055 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) {1056 $interation = ICAL_ACTION_UPDATE;1057 $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');1058 break;1059 }1131 $isParticipant = true; 1132 if ($value['isOrganizer']) 1133 $isOrganizer = true; 1134 1135 if (!self::_existInMyCalendars($schedulable['id'], $params['owner'])) { 1136 $interation = ICAL_ACTION_UPDATE; 1137 $interation = ( strrpos($value['acl'], ATTENDEE_ACL_PARTICIPATION_REQUIRED) ) ? ICAL_ACTION_IMPORT_REQUIRED : array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1138 break; 1139 } 1060 1140 } else { 1061 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento1062 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE;1063 else1064 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE;1141 if (self::_getTime($component, 'dtstamp') > $schedulable['dtstamp'] || $component->getProperty('sequence', false, false) > $schedulable['sequence']) //Organizador esta requisitando que você atualize o evento 1142 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_UPDATE : ICAL_ACTION_UPDATE; 1143 else 1144 $interation = ($isOrganizer) ? ICAL_ACTION_ORGANIZER_NONE : ICAL_ACTION_NONE; 1065 1145 } 1066 1146 if (!$isParticipant){ … … 1068 1148 } 1069 1149 }else 1070 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds');1150 $interation = array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1071 1151 1072 1152 if(($interation != ICAL_ACTION_NONE) && ($interation != ICAL_ACTION_ORGANIZER_NONE) && ($interation != ICAL_ACTION_ORGANIZER_UPDATE) && ($interation != ICAL_ACTION_NONE)) { … … 1269 1349 private static function _checkParticipantByPermissions($schedulable) { 1270 1350 1271 $calendarIds = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=','isOwner','0'), array('=', 'user', Config::me("uidNumber")))));1272 1273 if($calendarIds && isset($calendarIds[0])){1274 $ids = array();1275 foreach($calendarIds as $value)1276 array_push($ids, $value['calendar']);1277 1278 $signaturesOfOwners = Controller::find(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('IN', 'calendar', $ids) , array('=','isOwner','1')), 'deepness' => 2 ));1279 1280 foreach($signaturesOfOwners as $value){1281 if(self::_getParticipantByMail($value['user']['mail'], $schedulable['participants'])){1282 $eventoFromCalendar = Controller::read( array( 'concept' => 'calendarToSchedulable') , false, array('filter' => array('AND', array('=','schedulable',$schedulable['id']), array('=','calendar', $value['calendar']['id']))));1283 1284 return ($eventoFromCalendar && isset($eventoFromCalendar[0])) ? ICAL_ACTION_NONE_FROM_PERMISSION : array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => array($value['calendar']['id']) );1285 }1286 }1287 }1288 return ICAL_ACTION_ORGANIZER_NONE;1351 $calendarIds = Controller::find(array('concept' => 'calendarSignature'), array('calendar'), array('filter' => array('AND', array('=','isOwner','0'), array('=', 'user', Config::me("uidNumber"))))); 1352 1353 if($calendarIds && isset($calendarIds[0])){ 1354 $ids = array(); 1355 foreach($calendarIds as $value) 1356 array_push($ids, $value['calendar']); 1357 1358 $signaturesOfOwners = Controller::find(array('concept' => 'calendarSignature'), false, array('filter' => array('AND', array('IN', 'calendar', $ids) , array('=','isOwner','1')), 'deepness' => 2 )); 1359 1360 foreach($signaturesOfOwners as $value){ 1361 if(self::_getParticipantByMail($value['user']['mail'], $schedulable['participants'])){ 1362 $eventoFromCalendar = Controller::read( array( 'concept' => 'calendarToSchedulable') , false, array('filter' => array('AND', array('=','schedulable',$schedulable['id']), array('=','calendar', $value['calendar']['id'])))); 1363 1364 return ($eventoFromCalendar && isset($eventoFromCalendar[0])) ? ICAL_ACTION_NONE_FROM_PERMISSION : array('action' => ICAL_ACTION_IMPORT_FROM_PERMISSION, 'calendar' => array($value['calendar']['id']) ); 1365 } 1366 } 1367 } 1368 return array('action' => ICAL_ACTION_IMPORT, 'type' => 'calendarIds'); 1289 1369 } 1290 1370 1291 1371 1292 private static function _getParticipantByMail($mail, &$participants, $isFull ) {1372 private static function _getParticipantByMail($mail, &$participants, $isFull = false) { 1293 1373 if ($participants && $participants != '') 1294 1374 foreach ($participants as $i => $v) … … 1382 1462 } 1383 1463 1384 static private function _makeVEVENT($schedulable, $component, $params) { 1385 $interation = array(); 1386 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 1387 1388 /* Data de Inicio */ 1389 $startTime = $component->getProperty('dtstart', false, true); 1390 1391 $tzid = (isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']); 1392 1393 /* Tiem zone do evento */ 1394 if ($tzid){ 1395 $tzid = self::nomalizeTZID($tzid); 1396 $schedulable['timezone'] = $tzid; 1397 }else 1398 $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 1399 1400 $objTimezone = new DateTimeZone($schedulable['timezone']); 1401 1402 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 1403 $schedulable['allDay'] = 1; 1404 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 1405 } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 1406 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 1407 $schedulable['allDay'] = 0; 1408 } else { 1409 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 1410 if (strpos($params['prodid'], 'Outlook') !== false) { 1411 //Se o ics veio em utc não aplicar horario de verão 1412 $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 1413 $sTime->setTimezone($objTimezone); 1414 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 1415 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 1416 } 1417 } 1418 1419 /* Data de Termino */ 1420 $endTime = $component->getProperty('dtend', false, true); 1421 1422 $tzid = isset($endTime['params']['TZID']) ? $endTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 1423 1424 if($tzid) 1425 $tzid = self::nomalizeTZID($tzid); 1426 1427 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 1428 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 1429 else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 1430 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 1431 else { 1432 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 1433 if (strpos($params['prodid'], 'Outlook') !== false) { 1434 //Se o ics veio em utc não aplicar horario de verão 1435 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 1436 $eTime->setTimezone($objTimezone); 1437 if ($eTime->format('I')) 1438 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 1439 } 1440 } 1441 1442 1443 $schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1444 1445 /* Definindo Description */ 1446 if ($desc = $component->getProperty('description', false, false)) 1447 $schedulable['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1448 1449 /* Definindo location */ 1450 if ($location = $component->getProperty('location', false, false)) 1451 $schedulable['location'] = mb_convert_encoding($location, 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1452 1453 1454 /* Definindo Class */ 1455 $class = $component->getProperty('class', false, false); 1456 if ($class && defined(constant(strtoupper('CLASS_' . $class)))) 1457 $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 1458 else if (!isset($schedulable['class'])) 1459 $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 1460 1461 /* Definindo RRULE */ 1462 if ($rrule = $component->getProperty('rrule', false, false)) { 1463 /* Gera um randon id para o contexto formater */ 1464 $repeatID = mt_rand() . '3(Formatter)'; 1465 1466 $repeat = array(); 1467 $repeat['schedulable'] = $eventID; 1468 foreach ($rrule as $i => $v) { 1469 if (strtolower($i) == 'freq') 1470 $repeat['frequency'] = $v; 1471 else if (strtolower($i) == 'until') 1472 $repeat['endTime'] = $v; 1473 else 1474 $repeat[strtolower($i)] = $v; 1475 } 1476 1477 $interation['repeat://' . $repeatID] = $repeat; 1478 } 1479 1480 1481 $schedulable['calendar'] = $params['calendar']; 1482 1483 $participantsInEvent = array(); 1484 1485 //TODO: Participants com delegated nao estao sendo levados em conta 1486 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 1487 $participant = array(); 1488 1489 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1490 1491 $participantID = ($tpID = self::_getParticipantByMail($mailUser, $schedulable['participants'])) ? $tpID : mt_rand() . '2(Formatter)'; 1492 $participant['schedulable'] = $eventID; 1493 1494 if (isset($params['status']) && $mailUser == Config::me('mail')) 1495 $participant['status'] = $params['status']; 1496 else 1497 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1498 1499 1500 $participant['isOrganizer'] = '0'; 1501 1502 /* Verifica se este usuario é um usuario interno do ldap */ 1503 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1504 1505 $user = null; 1506 if ($intUser && count($intUser) > 0) { 1507 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1508 $participant['user'] = $intUser[0]['id']; 1509 } else { 1510 $participant['isExternal'] = 1; 1511 /* Gera um randon id para o contexto formater */ 1512 $userID = mt_rand() . '4(Formatter)'; 1513 1514 $user['mail'] = $mailUser; 1515 $user['isExternal'] = '1'; 1516 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1517 $user['participants'] = array($participantID); 1518 $participant['user'] = $userID; 1519 $interation['user://' . $userID] = $user; 1520 } 1521 1522 $interation['participant://' . $participantID] = $participant; 1523 $schedulable['participants'][] = $participantID; 1524 }; 1525 1526 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 1527 $participant = array(); 1528 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1529 1530 $participantID = mt_rand() . '2(Formatter)'; 1531 1532 $participant['schedulable'] = $eventID; 1533 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1534 $participant['isOrganizer'] = '1'; 1535 $participant['acl'] = 'rowi'; 1536 1537 /* Verifica se este usuario é um usuario interno do ldap */ 1538 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1539 1540 $user = null; 1541 if ($intUser && count($intUser) > 0) { 1542 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1543 $participant['user'] = $intUser[0]['id']; 1544 } else { 1545 $participant['isExternal'] = 1; 1546 /* Gera um randon id para o contexto formater */ 1547 $userID = mt_rand() . '4(Formatter)'; 1548 1549 $user['mail'] = $mailUser; 1550 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1551 $user['participants'] = array($participantID); 1552 $user['isExternal'] = '1'; 1553 $participant['user'] = $userID; 1554 $interation['user://' . $userID] = $user; 1555 } 1556 1557 $interation['participant://' . $participantID] = $participant; 1558 $schedulable['participants'][] = $participantID; 1559 } else if (!is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 1560 $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 1561 1562 if (!self::_getParticipantByMail($user['mail'], $schedulable['participants'])) { 1563 $participantID = mt_rand() . '2(Formatter)'; 1564 1565 $participant['schedulable'] = $eventID; 1566 $participant['status'] = STATUS_CONFIRMED; 1567 $participant['isOrganizer'] = '1'; 1568 $participant['acl'] = 'rowi'; 1569 $participant['isExternal'] = 0; 1570 $participant['user'] = $params['owner']; 1571 $interation['participant://' . $participantID] = $participant; 1572 $schedulable['participants'][] = $participantID; 1573 } 1574 } 1575 1576 $alarms = array(); 1577 1578 /* Definindo ALARMES */ 1579 while ($alarmComp = $component->getComponent('valarm')) 1580 { 1581 $alarm = array(); 1582 $alarmID = mt_rand() . '6(Formatter)'; 1583 $action = $alarmComp->getProperty('action', false, true); 1584 $trygger = $alarmComp->getProperty('trigger', false, true); 1585 $alarm['type'] = self::decodeAlarmAction($action['value']); 1586 1587 if(isset($trygger['value']['day'])) 1588 { 1589 $alarm['time'] = $trygger['value']['day']; 1590 $alarm['unit'] = 'd'; 1591 } 1592 else if(isset($trygger['value']['hour'])) 1593 { 1594 $alarm['time'] = $trygger['value']['hour']; 1595 $alarm['unit'] = 'h'; 1596 } 1597 else if(isset($trygger['value']['min'])) 1598 { 1599 $alarm['time'] = $trygger['value']['min']; 1600 $alarm['unit'] = 'm'; 1601 } 1602 1603 foreach ($interation as $iint => &$vint) 1604 { 1605 if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber')) 1606 { 1607 $alarm['participant'] = str_replace('participant://', '', $iint); 1608 $vint['alarms'][] = $alarmID; 1609 } 1610 } 1611 $alarm['schedulable'] = $eventID; 1612 1613 $interation['alarm://' . $alarmID ] = $alarm; 1614 1615 } 1616 1617 1618 /* Definindo DTSTAMP */ 1619 if ($dtstamp = self::_getTime($component, 'dtstamp')) 1620 $schedulable['dtstamp'] = $dtstamp; 1621 1622 /* Definindo TRANSP */ 1623 if (($tranp = $component->getProperty('transp', false, true)) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') 1624 $schedulable['transparent'] = 1; 1625 1626 /* Definindo last_update */ 1627 if ($lastUpdate = self::_getTime($component, 'LAST-MODIFIED')) 1628 $schedulable['lastUpdate'] = $lastUpdate; 1629 1630 1631 if ($sequence = $component->getProperty('SEQUENCE', false, false)) 1632 $schedulable['sequence'] = $sequence; 1633 1634 if ($uid = $component->getProperty('uid', false, false)) 1635 ; 1636 $schedulable['uid'] = $uid; 1637 1638 while ($attach = $component->getProperty('ATTACH', FALSE, TRUE)) { 1639 1640 $attachCurrent = array('name' => $attach['params']['X-FILENAME'], 1641 'size' => strlen($attach['value']), 1642 'type' => self::_getContentType($attach['params']['X-FILENAME']) 1643 ); 1644 1645 $ids = Controller::find(array('concept' => 'attachment'), array('id'), array('filter' => array('AND', array('=', 'name', $attachCurrent['name']), array('=', 'size', $attachCurrent['size']), array('=', 'type', $attachCurrent['type'])))); 1646 1647 if (!is_array($ids)) { 1648 $attachCurrent['source'] = $attach['value']; 1649 //insere o anexo no banco e pega id para colcar no relacionamento 1650 $idAttachment = Controller::create(array('concept' => 'attachment'), $attachCurrent); 1651 }else 1652 $idAttachment = array('id' => $ids[0]['id']); 1653 1654 $calendarToAttachmentId = mt_rand() . '2(Formatter)'; 1655 $calendarToAttachment['attachment'] = $idAttachment['id']; 1656 $calendarToAttachment['schedulable'] = $eventID; 1657 $interation['schedulableToAttachment://' . $calendarToAttachmentId] = $calendarToAttachment; 1658 1659 $schedulable['attachments'][] = $calendarToAttachmentId; 1660 } 1661 1662 $interation['schedulable://' . $eventID] = $schedulable; 1663 1664 return $interation; 1464 static private function _makeVEVENT($schedulable, $component, $params) { 1465 $interation = array(); 1466 $eventID = isset($schedulable['id']) ? $schedulable['id'] : mt_rand() . '(Formatter)'; 1467 1468 /* Data de Inicio */ 1469 $startTime = $component->getProperty('dtstart', false, true); 1470 1471 $tzid = (isset($startTime['params']['TZID']) ? $startTime['params']['TZID'] : $params['X-WR-TIMEZONE']); 1472 1473 /* Tiem zone do evento */ 1474 if ($tzid){ 1475 $tzid = self::nomalizeTZID($tzid); 1476 $schedulable['timezone'] = $tzid; 1477 }else 1478 $schedulable['timezone'] = isset($params['calendar_timezone']) ? $params['calendar_timezone'] : 'America/Sao_Paulo'; 1479 1480 $objTimezone = new DateTimeZone($schedulable['timezone']); 1481 1482 if (isset($startTime['params']['VALUE']) && $startTime['params']['VALUE'] === 'DATE' && isset($params['calendar_timezone'])) { 1483 $schedulable['allDay'] = 1; 1484 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($startTime['value'])) . '000'; 1485 } elseif ($tzid && !isset($startTime['value']['tz'])) {/* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 1486 $schedulable['startTime'] = self::date2timestamp($startTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($startTime['value'])) . '000'; 1487 $schedulable['allDay'] = 0; 1488 } else { 1489 $schedulable['startTime'] = self::date2timestamp($startTime['value']) . '000'; 1490 if (strpos($params['prodid'], 'Outlook') !== false) { 1491 //Se o ics veio em utc não aplicar horario de verão 1492 $sTime = new DateTime('@' . (int) ($schedulable['startTime'] / 1000), new DateTimeZone('UTC')); 1493 $sTime->setTimezone($objTimezone); 1494 if ($sTime->format('I')) //Se o ics veio em utc não aplicar horario de verão 1495 $schedulable['startTime'] = $schedulable['startTime'] - 3600000; 1496 } 1497 } 1498 1499 /* Data de Termino */ 1500 $endTime = $component->getProperty('dtend', false, true); 1501 1502 $tzid = isset($endTime['params']['TZID']) ? $endTime['params']['TZID'] : $params['X-WR-TIMEZONE']; 1503 1504 if($tzid) 1505 $tzid = self::nomalizeTZID($tzid); 1506 1507 if (isset($endTime['params']['VALUE']) && $endTime['params']['VALUE'] === 'DATE') 1508 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $schedulable['timezone'], '@' . self::date2timestamp($endTime['value'])) . '000'; 1509 else if ($tzid && !isset($endTime['value']['tz'])) /* Caso não tenha um tz na data mais exista um parametro TZID deve ser aplicado o timezone do TZID a data */ 1510 $schedulable['endTime'] = self::date2timestamp($endTime['value']) - self::_getTzOffset('UTC', $tzid, '@' . self::date2timestamp($endTime['value'])) . '000'; 1511 else { 1512 $schedulable['endTime'] = self::date2timestamp($endTime['value']) . '000'; 1513 if (strpos($params['prodid'], 'Outlook') !== false) { 1514 //Se o ics veio em utc não aplicar horario de verão 1515 $eTime = new DateTime('@' . (int) ($schedulable['endTime'] / 1000), new DateTimeZone('UTC')); 1516 $eTime->setTimezone($objTimezone); 1517 if ($eTime->format('I')) 1518 $schedulable['endTime'] = $schedulable['endTime'] - 3600000; 1519 } 1520 } 1521 1522 1523 $schedulable['summary'] = mb_convert_encoding($component->getProperty('summary', false, false), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1524 1525 /* Definindo Description */ 1526 if ($desc = $component->getProperty('description', false, false)) 1527 $schedulable['description'] = mb_convert_encoding(str_ireplace(array('\n', '\t'), array("\n", "\t"), $desc), 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1528 1529 /* Definindo location */ 1530 if ($location = $component->getProperty('location', false, false)) 1531 $schedulable['location'] = mb_convert_encoding($location, 'ISO-8859-1', 'UTF-8,ISO-8859-1'); 1532 1533 1534 /* Definindo Class */ 1535 $class = $component->getProperty('class', false, false); 1536 if ($class && defined(constant(strtoupper('CLASS_' . $class)))) 1537 $schedulable['class'] = constant(strtoupper('CLASS_' . $class)); 1538 else if (!isset($schedulable['class'])) 1539 $schedulable['class'] = CLASS_PRIVATE; // padrão classe private 1540 1541 /* Definindo RRULE */ 1542 if ($rrule = $component->getProperty('rrule', false, false)) { 1543 /* Gera um randon id para o contexto formater */ 1544 $repeatID = mt_rand() . '3(Formatter)'; 1545 1546 $repeat = array(); 1547 $repeat['schedulable'] = $eventID; 1548 foreach ($rrule as $i => $v) { 1549 if (strtolower($i) == 'freq') 1550 $repeat['frequency'] = $v; 1551 else if (strtolower($i) == 'until') 1552 $repeat['endTime'] = $v; 1553 else 1554 $repeat[strtolower($i)] = $v; 1555 } 1556 1557 $interation['repeat://' . $repeatID] = $repeat; 1558 } 1559 1560 1561 $schedulable['calendar'] = $params['calendar']; 1562 1563 $participantsInEvent = array(); 1564 1565 //TODO: Participants com delegated nao estao sendo levados em conta 1566 while ($property = $component->getProperty('attendee', FALSE, TRUE)) { 1567 $participant = array(); 1568 1569 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1570 1571 $participantID = ($tpID = self::_getParticipantByMail($mailUser, $schedulable['participants'])) ? $tpID : mt_rand() . '2(Formatter)'; 1572 $participant['schedulable'] = $eventID; 1573 1574 if (isset($params['status']) && $mailUser == Config::me('mail')) 1575 $participant['status'] = $params['status']; 1576 else 1577 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1578 1579 1580 $participant['isOrganizer'] = '0'; 1581 1582 /* Verifica se este usuario é um usuario interno do ldap */ 1583 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1584 1585 $user = null; 1586 if ($intUser && count($intUser) > 0) { 1587 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1588 $participant['user'] = $intUser[0]['id']; 1589 } else { 1590 $participant['isExternal'] = 1; 1591 /* Gera um randon id para o contexto formater */ 1592 $userID = mt_rand() . '4(Formatter)'; 1593 1594 $user['mail'] = $mailUser; 1595 $user['isExternal'] = '1'; 1596 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1597 $user['participants'] = array($participantID); 1598 $participant['user'] = $userID; 1599 $interation['user://' . $userID] = $user; 1600 } 1601 1602 $interation['participant://' . $participantID] = $participant; 1603 $schedulable['participants'][] = $participantID; 1604 }; 1605 1606 if ($property = $component->getProperty('organizer', FALSE, TRUE)) { 1607 $participant = array(); 1608 $mailUser = trim(str_replace('MAILTO:', '', $property['value'])); 1609 1610 $participantID = mt_rand() . '2(Formatter)'; 1611 1612 $participant['schedulable'] = $eventID; 1613 $participant['status'] = (isset($property['params']['PARTSTAT']) && constant('STATUS_' . $property['params']['PARTSTAT']) !== null ) ? constant('STATUS_' . $property['params']['PARTSTAT']) : STATUS_UNANSWERED; 1614 $participant['isOrganizer'] = '1'; 1615 $participant['acl'] = 'rowi'; 1616 1617 /* Verifica se este usuario é um usuario interno do ldap */ 1618 $intUser = Controller::find(array('concept' => 'user'), array('id', 'isExternal'), array('filter' => array('OR', array('=', 'mail', $mailUser), array('=', 'mailAlternateAddress', $mailUser)))); 1619 1620 $user = null; 1621 if ($intUser && count($intUser) > 0) { 1622 $participant['isExternal'] = isset($intUser[0]['isExternal']) ? $intUser[0]['isExternal'] : 0; 1623 $participant['user'] = $intUser[0]['id']; 1624 } else { 1625 $participant['isExternal'] = 1; 1626 /* Gera um randon id para o contexto formater */ 1627 $userID = mt_rand() . '4(Formatter)'; 1628 1629 $user['mail'] = $mailUser; 1630 $user['name'] = ( isset($property['params']['CN']) ) ? $property['params']['CN'] : ''; 1631 $user['participants'] = array($participantID); 1632 $user['isExternal'] = '1'; 1633 $participant['user'] = $userID; 1634 $interation['user://' . $userID] = $user; 1635 } 1636 1637 $interation['participant://' . $participantID] = $participant; 1638 $schedulable['participants'][] = $participantID; 1639 } else if (!isset($schedulable['participants']) || !is_array($schedulable['participants']) || count($schedulable['participants']) < 1) {//caso não tenha organizador o usuario se torna organizador 1640 $user = Controller::read(array('concept' => 'user', 'id' => $params['owner']), array('mail')); 1641 1642 if (!self::_getParticipantByMail($user['mail'], $schedulable['participants'])) { 1643 $participantID = mt_rand() . '2(Formatter)'; 1644 1645 $participant['schedulable'] = $eventID; 1646 $participant['status'] = STATUS_CONFIRMED; 1647 $participant['isOrganizer'] = '1'; 1648 $participant['acl'] = 'rowi'; 1649 $participant['isExternal'] = 0; 1650 $participant['user'] = $params['owner']; 1651 $interation['participant://' . $participantID] = $participant; 1652 $schedulable['participants'][] = $participantID; 1653 } 1654 } 1655 1656 $alarms = array(); 1657 1658 /* Definindo ALARMES */ 1659 while ($alarmComp = $component->getComponent('valarm')) 1660 { 1661 $alarm = array(); 1662 $alarmID = mt_rand() . '6(Formatter)'; 1663 $action = $alarmComp->getProperty('action', false, true); 1664 $trygger = $alarmComp->getProperty('trigger', false, true); 1665 $alarm['type'] = self::decodeAlarmAction($action['value']); 1666 1667 if(isset($trygger['value']['day'])) 1668 { 1669 $alarm['time'] = $trygger['value']['day']; 1670 $alarm['unit'] = 'd'; 1671 } 1672 else if(isset($trygger['value']['hour'])) 1673 { 1674 $alarm['time'] = $trygger['value']['hour']; 1675 $alarm['unit'] = 'h'; 1676 } 1677 else if(isset($trygger['value']['min'])) 1678 { 1679 $alarm['time'] = $trygger['value']['min']; 1680 $alarm['unit'] = 'm'; 1681 } 1682 1683 foreach ($interation as $iint => &$vint) 1684 { 1685 if(isset($vint['user']) && $vint['user'] == Config::me('uidNumber')) 1686 { 1687 $alarm['participant'] = str_replace('participant://', '', $iint); 1688 $vint['alarms'][] = $alarmID; 1689 } 1690 } 1691 $alarm['schedulable'] = $eventID; 1692 1693 $interation['alarm://' . $alarmID ] = $alarm; 1694 1695 } 1696 1697 1698 /* Definindo DTSTAMP */ 1699 if ($dtstamp = self::_getTime($component, 'dtstamp')) 1700 $schedulable['dtstamp'] = $dtstamp; 1701 1702 /* Definindo TRANSP */ 1703 if (($tranp = $component->getProperty('transp', false, true)) && $tranp && is_string($tranp) && strtoupper($tranp) == 'OPAQUE') 1704 $schedulable['transparent'] = 1; 1705 1706 /* Definindo last_update */ 1707 if ($lastUpdate = self::_getTime($component, 'LAST-MODIFIED')) 1708 $schedulable['lastUpdate'] = $lastUpdate; 1709 1710 1711 if ($sequence = $component->getProperty('SEQUENCE', false, false)) 1712 $schedulable['sequence'] = $sequence; 1713 1714 if ($uid = $component->getProperty('uid', false, false)) 1715 ; 1716 $schedulable['uid'] = $uid; 1717 1718 while ($attach = $component->getProperty('ATTACH', FALSE, TRUE)) { 1719 1720 $attachCurrent = array('name' => $attach['params']['X-FILENAME'], 1721 'size' => strlen($attach['value']), 1722 'type' => self::_getContentType($attach['params']['X-FILENAME']) 1723 ); 1724 1725 $ids = Controller::find(array('concept' => 'attachment'), array('id'), array('filter' => array('AND', array('=', 'name', $attachCurrent['name']), array('=', 'size', $attachCurrent['size']), array('=', 'type', $attachCurrent['type'])))); 1726 1727 if (!is_array($ids)) { 1728 $attachCurrent['source'] = $attach['value']; 1729 //insere o anexo no banco e pega id para colcar no relacionamento 1730 $idAttachment = Controller::create(array('concept' => 'attachment'), $attachCurrent); 1731 }else 1732 $idAttachment = array('id' => $ids[0]['id']); 1733 1734 $calendarToAttachmentId = mt_rand() . '2(Formatter)'; 1735 $calendarToAttachment['attachment'] = $idAttachment['id']; 1736 $calendarToAttachment['schedulable'] = $eventID; 1737 $interation['schedulableToAttachment://' . $calendarToAttachmentId] = $calendarToAttachment; 1738 1739 $schedulable['attachments'][] = $calendarToAttachmentId; 1740 } 1741 1742 $schedulable['type'] = '1'; 1743 1744 $interation['schedulable://' . $eventID] = $schedulable; 1745 1746 1747 1748 1749 1750 return $interation; 1665 1751 } 1666 1752
Note: See TracChangeset
for help on using the changeset viewer.