2005-06-20 11:51:54 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - iCalendar Parser *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* Written by Lars Kneschke <lkneschke@egroupware.org> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2006-03-17 21:53:26 +01:00
|
|
|
require_once EGW_SERVER_ROOT.'/infolog/inc/class.boinfolog.inc.php';
|
|
|
|
require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/Horde/iCalendar.php';
|
2005-06-20 11:51:54 +02:00
|
|
|
|
|
|
|
class vcalinfolog extends boinfolog
|
|
|
|
{
|
2006-03-17 21:53:26 +01:00
|
|
|
var $status2vtodo = array(
|
|
|
|
'offer' => 'NEEDS-ACTION',
|
|
|
|
'not-started' => 'NEEDS-ACTION',
|
|
|
|
'ongoing' => 'IN-PROCESS',
|
|
|
|
'done' => 'COMPLETED',
|
|
|
|
'cancelled' => 'CANCELLED',
|
|
|
|
'billed' => 'DONE',
|
|
|
|
'call' => 'NEEDS-ACTION',
|
|
|
|
'will-call' => 'IN-PROCESS',
|
|
|
|
);
|
|
|
|
var $vtodo2status = array(
|
|
|
|
'NEEDS-ACTION' => 'not-started',
|
|
|
|
'IN-PROCESS' => 'ongoing',
|
|
|
|
'COMPLETED' => 'done',
|
|
|
|
'CANCELLED' => 'cancelled',
|
|
|
|
);
|
2005-06-20 11:51:54 +02:00
|
|
|
function exportVTODO($_taskID, $_version)
|
|
|
|
{
|
|
|
|
$taskData = $this->read($_taskID);
|
2005-07-20 14:09:32 +02:00
|
|
|
|
|
|
|
$taskData = $GLOBALS['egw']->translation->convert($taskData,$GLOBALS['egw']->translation->charset(),'UTF-8');
|
2005-06-20 11:51:54 +02:00
|
|
|
|
2005-07-14 19:21:01 +02:00
|
|
|
//_debug_array($taskData);
|
2005-06-20 11:51:54 +02:00
|
|
|
|
|
|
|
$taskGUID = $GLOBALS['phpgw']->common->generate_uid('infolog_task',$_taskID);
|
|
|
|
#print "<br>";
|
|
|
|
#print $GLOBALS['phpgw']->contenthistory->getTSforAction($eventGUID,'add');
|
|
|
|
#print "<br>";
|
|
|
|
|
|
|
|
$vcal = &new Horde_iCalendar;
|
|
|
|
$vcal->setAttribute('VERSION',$_version);
|
|
|
|
$vcal->setAttribute('METHOD','PUBLISH');
|
|
|
|
|
|
|
|
$vevent = Horde_iCalendar::newComponent('VTODO',$vcal);
|
|
|
|
|
|
|
|
$options = array();
|
|
|
|
|
|
|
|
$vevent->setAttribute('SUMMARY',$taskData['info_subject']);
|
|
|
|
$vevent->setAttribute('DESCRIPTION',$taskData['info_des']);
|
2006-03-17 21:53:26 +01:00
|
|
|
$vevent->setAttribute('LOCATION',$taskData['info_location']);
|
2005-06-20 11:51:54 +02:00
|
|
|
if($taskData['info_startdate'])
|
|
|
|
$vevent->setAttribute('DTSTART',$taskData['info_startdate']);
|
|
|
|
if($taskData['info_enddate'])
|
|
|
|
$vevent->setAttribute('DUE',$taskData['info_enddate']);
|
2006-03-17 21:53:26 +01:00
|
|
|
if($taskData['info_datecompleted'])
|
|
|
|
$vevent->setAttribute('COMPLETED',$taskData['info_datecompleted']);
|
2005-06-20 11:51:54 +02:00
|
|
|
$vevent->setAttribute('DTSTAMP',time());
|
|
|
|
$vevent->setAttribute('CREATED',$GLOBALS['phpgw']->contenthistory->getTSforAction($eventGUID,'add'));
|
|
|
|
$vevent->setAttribute('LAST-MODIFIED',$GLOBALS['phpgw']->contenthistory->getTSforAction($eventGUID,'modify'));
|
|
|
|
$vevent->setAttribute('UID',$taskGUID);
|
2006-03-17 21:53:26 +01:00
|
|
|
$vevent->setAttribute('CLASS',$taskData['info_access'] == 'public' ? 'PUBLIC' : 'PRIVATE');
|
|
|
|
$vevent->setAttribute('STATUS',isset($this->status2vtodo[$taskData['info_status']]) ?
|
|
|
|
$this->status2vtodo[$taskData['info_status']] : 'NEEDS-ACTION');
|
2005-07-14 19:21:01 +02:00
|
|
|
// 3=urgent => 1, 2=high => 2, 1=normal => 3, 0=low => 4
|
|
|
|
$vevent->setAttribute('PRIORITY',4-$taskData['info_priority']);
|
|
|
|
|
2005-06-20 11:51:54 +02:00
|
|
|
#$vevent->setAttribute('TRANSP','OPAQUE');
|
|
|
|
# status
|
|
|
|
# ATTENDEE
|
|
|
|
|
|
|
|
$options = array('CHARSET' => 'UTF-8','ENCODING' => 'QUOTED-PRINTABLE');
|
|
|
|
$vevent->setParameter('SUMMARY', $options);
|
|
|
|
$vevent->setParameter('DESCRIPTION', $options);
|
|
|
|
|
|
|
|
$vcal->addComponent($vevent);
|
|
|
|
|
|
|
|
#print "<pre>";
|
|
|
|
#print $vcal->exportvCalendar();
|
|
|
|
#print "</pre>";
|
2006-06-01 18:27:49 +02:00
|
|
|
|
2005-06-20 11:51:54 +02:00
|
|
|
return $vcal->exportvCalendar();
|
|
|
|
}
|
|
|
|
|
|
|
|
function importVTODO(&$_vcalData, $_taskID=-1)
|
|
|
|
{
|
2006-03-21 14:19:38 +01:00
|
|
|
if(!$taskData = $this->vtodotoegw($_vcalData)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($_taskID>0)
|
|
|
|
$taskData['info_id'] = $_taskID;
|
|
|
|
|
|
|
|
#_debug_array($taskData);exit;
|
|
|
|
return $this->write($taskData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchVTODO($_vcalData) {
|
2006-06-01 18:27:49 +02:00
|
|
|
if(!$egwData = $this->vtodotoegw($_vcalData)) {
|
2006-03-21 14:19:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$filter = array('col_filter' => $egwData);
|
|
|
|
if($foundItems = $this->search($filter)) {
|
|
|
|
if(count($foundItems) > 0) {
|
|
|
|
#error_log(__LINE__);
|
|
|
|
#error_log(print_r($foundItems, true));
|
|
|
|
$itemIDs = array_keys($foundItems);
|
|
|
|
#error_log($itemIDs[0]);
|
|
|
|
return $itemIDs[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
function vtodotoegw($_vcalData) {
|
2005-06-20 11:51:54 +02:00
|
|
|
$vcal = &new Horde_iCalendar;
|
|
|
|
if(!$vcal->parsevCalendar($_vcalData))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2005-06-20 11:51:54 +02:00
|
|
|
$components = $vcal->getComponents();
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2005-06-20 11:51:54 +02:00
|
|
|
if(count($components) > 0)
|
|
|
|
{
|
|
|
|
$component = $components[0];
|
|
|
|
if(is_a($component, 'Horde_iCalendar_vtodo'))
|
|
|
|
{
|
|
|
|
if($_taskID>0)
|
|
|
|
$taskData['info_id'] = $_taskID;
|
2006-03-17 21:53:26 +01:00
|
|
|
|
2005-06-20 11:51:54 +02:00
|
|
|
foreach($component->_attributes as $attributes)
|
|
|
|
{
|
|
|
|
#print $attributes['name'].' - '.$attributes['value'].'<br>';
|
|
|
|
switch($attributes['name'])
|
|
|
|
{
|
|
|
|
case 'CLASS':
|
2005-07-20 14:09:32 +02:00
|
|
|
$taskData['info_access'] = strtolower($attributes['value']);
|
2005-06-20 11:51:54 +02:00
|
|
|
break;
|
|
|
|
case 'DESCRIPTION':
|
2005-07-20 14:09:32 +02:00
|
|
|
$taskData['info_des'] = $attributes['value'];
|
2005-06-20 11:51:54 +02:00
|
|
|
break;
|
2006-03-17 21:53:26 +01:00
|
|
|
case 'LOCATION':
|
|
|
|
$taskData['info_location'] = $attributes['value'];
|
|
|
|
break;
|
2005-06-20 11:51:54 +02:00
|
|
|
case 'DUE':
|
|
|
|
$taskData['info_enddate'] = $attributes['value'];
|
|
|
|
break;
|
2006-03-17 21:53:26 +01:00
|
|
|
case 'COMPLETED':
|
|
|
|
$taskData['info_datecompleted'] = $attributes['value'];
|
|
|
|
break;
|
2005-06-20 11:51:54 +02:00
|
|
|
case 'DTSTART':
|
|
|
|
$taskData['info_startdate'] = $attributes['value'];
|
|
|
|
break;
|
|
|
|
case 'PRIORITY':
|
2005-07-14 19:21:01 +02:00
|
|
|
// 1 => 3=urgent, 2 => 2=high, 3 => 1=normal, 4 => 0=low
|
|
|
|
if (1 <= $attributes['value'] && $attributes['value'] <= 4)
|
|
|
|
{
|
|
|
|
$taskData['info_priority'] = 4 - $attributes['value'];
|
|
|
|
}
|
|
|
|
else
|
2005-06-20 11:51:54 +02:00
|
|
|
{
|
2005-07-14 19:21:01 +02:00
|
|
|
$taskData['info_priority'] = 1; // default = normal
|
2005-06-20 11:51:54 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'STATUS':
|
2006-03-17 21:53:26 +01:00
|
|
|
$taskData['info_status'] = isset($this->vtodo2status[strtoupper($attributes['value'])]) ?
|
|
|
|
$this->vtodo2status[strtoupper($attributes['value'])] : 'ongoing';
|
2005-06-20 11:51:54 +02:00
|
|
|
break;
|
|
|
|
case 'SUMMARY':
|
|
|
|
$taskData['info_subject'] = $attributes['value'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
$taskData = $GLOBALS['egw']->translation->convert($taskData, 'UTF-8');
|
2006-03-17 21:53:26 +01:00
|
|
|
|
2006-03-21 14:19:38 +01:00
|
|
|
return $taskData;
|
2005-06-20 11:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|