2008-10-07 14:50:14 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* InfoLog - SIF Parser
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Lars Kneschke <lkneschke@egroupware.org>
|
2009-07-15 22:04:17 +02:00
|
|
|
* @author Joerg Lehrke <jlehrke@noc.de>
|
2008-10-07 14:50:14 +02:00
|
|
|
* @package infolog
|
|
|
|
* @subpackage syncml
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/lib/core.php';
|
2008-10-07 14:50:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* InfoLog: Create and parse SIF
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class infolog_sif extends infolog_bo
|
|
|
|
{
|
|
|
|
// array containing the result of the xml parser
|
|
|
|
var $_extractedSIFData;
|
|
|
|
|
|
|
|
// array containing the current mappings(task or note)
|
|
|
|
var $_currentSIFMapping;
|
|
|
|
|
|
|
|
var $_sifNoteMapping = array(
|
|
|
|
'Body' => 'info_des',
|
|
|
|
'Categories' => 'info_cat',
|
|
|
|
'Color' => '',
|
|
|
|
'Date' => 'info_startdate',
|
|
|
|
'Height' => '',
|
|
|
|
'Left' => '',
|
|
|
|
'Subject' => 'info_subject',
|
|
|
|
'Top' => '',
|
|
|
|
'Width' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
// mappings for SIFTask to InfologTask
|
|
|
|
var $_sifTaskMapping = array(
|
2009-07-15 22:04:17 +02:00
|
|
|
'ActualWork' => '',
|
2008-10-07 14:50:14 +02:00
|
|
|
'BillingInformation' => '',
|
2009-07-15 22:04:17 +02:00
|
|
|
'Body' => 'info_des',
|
|
|
|
'Categories' => 'info_cat',
|
|
|
|
'Companies' => '',
|
|
|
|
'Complete' => 'complete',
|
|
|
|
'DateCompleted' => 'info_datecompleted',
|
|
|
|
'DueDate' => 'info_enddate',
|
|
|
|
'Importance' => 'info_priority',
|
|
|
|
'IsRecurring' => '',
|
|
|
|
'Mileage' => '',
|
|
|
|
'PercentComplete' => 'info_percent',
|
|
|
|
'ReminderSet' => '',
|
|
|
|
'ReminderTime' => '',
|
|
|
|
'Sensitivity' => 'info_access',
|
|
|
|
'StartDate' => 'info_startdate',
|
|
|
|
'Status' => 'info_status',
|
|
|
|
'Subject' => 'info_subject',
|
|
|
|
'TeamTask' => '',
|
|
|
|
'TotalWork' => '',
|
|
|
|
'RecurrenceType' => '',
|
|
|
|
'Interval' => '',
|
|
|
|
'MonthOfYear' => '',
|
|
|
|
'DayOfMonth' => '',
|
|
|
|
'DayOfWeekMask' => '',
|
|
|
|
'Instance' => '',
|
|
|
|
'PatternStartDate' => '',
|
|
|
|
'NoEndDate' => '',
|
|
|
|
'PatternEndDate' => '',
|
|
|
|
'Occurrences' => '',
|
2008-10-07 14:50:14 +02:00
|
|
|
);
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
// standard headers
|
|
|
|
const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>';
|
|
|
|
const SIF_decl = '<SIFVersion>1.1</SIFVersion>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* name and version of the sync-client
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $productName = 'mozilla plugin';
|
|
|
|
var $productSoftwareVersion = '0.3';
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
/**
|
|
|
|
* Shall we use the UID extensions of the description field?
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $uidExtension = false;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
/**
|
|
|
|
* user preference: Use this timezone for import from and export to device
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $tzid = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Logging
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
var $log = false;
|
|
|
|
var $logfile="/tmp/log-infolog-sif";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
if ($this->log) $this->logfile = $GLOBALS['egw_info']['server']['temp_dir']."/log-infolog-sif";
|
|
|
|
$this->vCalendar = new Horde_iCalendar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get DateTime value for a given time and timezone
|
|
|
|
*
|
|
|
|
* @param int|string|DateTime $time in server-time as returned by calendar_bo for $data_format='server'
|
|
|
|
* @param string $tzid TZID of event or 'UTC' or NULL for palmos timestamps in usertime
|
|
|
|
* @return mixed attribute value to set: integer timestamp if $tzid == 'UTC' otherwise Ymd\THis string IN $tzid
|
|
|
|
*/
|
|
|
|
function getDateTime($time, $tzid)
|
|
|
|
{
|
|
|
|
if (empty($tzid) || $tzid == 'UTC')
|
|
|
|
{
|
|
|
|
return $this->vCalendar->_exportDateTime(egw_time::to($time,'ts'));
|
|
|
|
}
|
|
|
|
if (!is_a($time,'DateTime'))
|
|
|
|
{
|
|
|
|
$time = new egw_time($time,egw_time::$server_timezone);
|
|
|
|
}
|
|
|
|
if (!isset(self::$tz_cache[$tzid]))
|
|
|
|
{
|
|
|
|
self::$tz_cache[$tzid] = calendar_timezones::DateTimeZone($tzid);
|
|
|
|
}
|
|
|
|
// check for date --> export it as such
|
|
|
|
if ($time->format('Hi') == '0000')
|
|
|
|
{
|
|
|
|
$arr = egw_time::to($time, 'array');
|
|
|
|
$time = new egw_time($arr, self::$tz_cache[$tzid]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$time->setTimezone(self::$tz_cache[$tzid]);
|
|
|
|
}
|
|
|
|
return $time->format('Ymd\THis');
|
|
|
|
}
|
2009-07-15 22:04:17 +02:00
|
|
|
|
|
|
|
function startElement($_parser, $_tag, $_attributes)
|
|
|
|
{
|
|
|
|
// nothing to do
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
function endElement($_parser, $_tag)
|
|
|
|
{
|
|
|
|
#error_log("infolog: tag=$_tag data=".trim($this->sifData));
|
|
|
|
if (!empty($this->_currentSIFMapping[$_tag]))
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->_extractedSIFData[$this->_currentSIFMapping[$_tag]] = trim($this->sifData);
|
|
|
|
}
|
|
|
|
unset($this->sifData);
|
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
function characterData($_parser, $_data)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
$this->sifData .= $_data;
|
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
/**
|
|
|
|
* Convert SIF data into a eGW infolog entry
|
|
|
|
*
|
|
|
|
* @param string $sifData the SIF data
|
|
|
|
* @param string $_sifType type (note/task)
|
2009-11-19 16:30:53 +01:00
|
|
|
* @param int $_id=-1 the infolog id
|
2009-07-15 22:04:17 +02:00
|
|
|
* @return array infolog entry or false on error
|
|
|
|
*/
|
2009-11-19 16:30:53 +01:00
|
|
|
function siftoegw($sifData, $_sifType, $_id=-1)
|
2009-07-15 22:04:17 +02:00
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($_sifType, $_id)\n" .
|
|
|
|
array2string($sifData) . "\n", 3, $this->logfile);
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
$sysCharSet = $GLOBALS['egw']->translation->charset();
|
2008-10-07 14:50:14 +02:00
|
|
|
|
|
|
|
switch ($_sifType)
|
|
|
|
{
|
|
|
|
case 'note':
|
|
|
|
$this->_currentSIFMapping = $this->_sifNoteMapping;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'task':
|
|
|
|
$this->_currentSIFMapping = $this->_sifTaskMapping;
|
|
|
|
break;
|
2010-02-09 22:56:39 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
// we don't know how to handle this
|
|
|
|
return false;
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->xml_parser = xml_parser_create('UTF-8');
|
|
|
|
xml_set_object($this->xml_parser, $this);
|
|
|
|
xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
|
|
|
|
xml_set_character_data_handler($this->xml_parser, "characterData");
|
|
|
|
$this->strXmlData = xml_parse($this->xml_parser, $sifData);
|
2009-07-15 22:04:17 +02:00
|
|
|
|
|
|
|
if (!$this->strXmlData)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
error_log(sprintf("XML error: %s at line %d",
|
|
|
|
xml_error_string(xml_get_error_code($this->xml_parser)),
|
|
|
|
xml_get_current_line_number($this->xml_parser)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
if (!array($this->_extractedSIFData))
|
|
|
|
{
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()[PARSER FAILD]\n",
|
|
|
|
3, $this->logfile);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$infoData = array();
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
switch ($_sifType)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
case 'task':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_type'] = 'task';
|
|
|
|
$infoData['info_status'] = 'not-started';
|
2009-07-15 22:04:17 +02:00
|
|
|
|
|
|
|
if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']))
|
|
|
|
{
|
|
|
|
$minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$minimum_uid_length = 8;
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
foreach ($this->_extractedSIFData as $key => $value)
|
|
|
|
{
|
|
|
|
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
|
2008-10-07 14:50:14 +02:00
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8', $sysCharSet);
|
2009-07-15 22:04:17 +02:00
|
|
|
#error_log("infolog key=$key => value=$value");
|
|
|
|
if (empty($value)) continue;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
switch($key)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
case 'info_access':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = ((int)$value > 0) ? 'private' : 'public';
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'info_datecompleted':
|
|
|
|
case 'info_enddate':
|
|
|
|
case 'info_startdate':
|
2009-07-15 22:04:17 +02:00
|
|
|
if (!empty($value))
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = $this->vCalendar->_parseDateTime($value);
|
2008-10-07 14:50:14 +02:00
|
|
|
// somehow the client always deliver a timestamp about 3538 seconds, when no startdate set.
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($infoData[$key] < 10000) unset($infoData[$key]);
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'info_cat':
|
2009-07-15 22:04:17 +02:00
|
|
|
if (!empty($value))
|
|
|
|
{
|
2009-11-19 16:30:53 +01:00
|
|
|
$categories = $this->find_or_add_categories(explode(';', $value), $_id);
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_cat'] = $categories[0];
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'info_priority':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = (int)$value;
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'info_status':
|
2009-07-15 22:04:17 +02:00
|
|
|
switch ($value)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
case '0':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'not-started';
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
case '1':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'ongoing';
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
case '2':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'done';
|
|
|
|
$infoData['info_percent'] = 100;
|
2009-07-15 22:04:17 +02:00
|
|
|
break;
|
|
|
|
case '3':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'waiting';
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
case '4':
|
2009-07-15 22:04:17 +02:00
|
|
|
if ($this->productName == 'blackberry plug-in')
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'deferred';
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'cancelled';
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
default:
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = 'ongoing';
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
case 'complete':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_status'] = 'done';
|
|
|
|
$infoData['info_percent'] = 100;
|
2009-07-15 22:04:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'info_des':
|
|
|
|
// extract our UID and PARENT_UID information
|
|
|
|
if (preg_match('/\s*\[UID:(.+)?\]/Usm', $value, $matches))
|
|
|
|
{
|
|
|
|
if (strlen($matches[1]) >= $minimum_uid_length)
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_uid'] = $matches[1];
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
|
|
|
//$value = str_replace($matches[0], '', $value);
|
|
|
|
}
|
|
|
|
if (preg_match('/\s*\[PARENT_UID:(.+)?\]/Usm', $value, $matches))
|
|
|
|
{
|
|
|
|
if (strlen($matches[1]) >= $minimum_uid_length)
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_id_parent'] = $this->getParentID($matches[1]);
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
|
|
|
//$value = str_replace($matches[0], '', $value);
|
|
|
|
}
|
|
|
|
|
2008-10-07 14:50:14 +02:00
|
|
|
default:
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = str_replace("\r\n", "\n", $value);
|
|
|
|
}
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
|
|
|
|
"key=$key => value=" . $infoData[$key] . "\n", 3, $this->logfile);
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
if (empty($infoData['info_datecompleted']))
|
|
|
|
{
|
|
|
|
$infoData['info_datecompleted'] = 0;
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'note':
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_type'] = 'note';
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
foreach ($this->_extractedSIFData as $key => $value)
|
2008-10-07 14:50:14 +02:00
|
|
|
{
|
2009-07-15 22:04:17 +02:00
|
|
|
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
|
2008-10-07 14:50:14 +02:00
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8', $sysCharSet);
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
#error_log("infolog client key=$key => value=" . $value);
|
2008-10-07 14:50:14 +02:00
|
|
|
switch ($key)
|
|
|
|
{
|
|
|
|
case 'info_startdate':
|
2009-07-15 22:04:17 +02:00
|
|
|
if (!empty($value))
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = $this->vCalendar->_parseDateTime($value);
|
2008-10-07 14:50:14 +02:00
|
|
|
// somehow the client always deliver a timestamp about 3538 seconds, when no startdate set.
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($infoData[$key] < 10000) $infoData[$key] = '';
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = '';
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'info_cat':
|
2009-07-15 22:04:17 +02:00
|
|
|
if (!empty($value))
|
|
|
|
{
|
2009-11-19 16:30:53 +01:00
|
|
|
$categories = $this->find_or_add_categories(explode(';', $value), $_id);
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_cat'] = $categories[0];
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData[$key] = str_replace("\r\n", "\n", $value);
|
|
|
|
}
|
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
|
|
|
|
"key=$key => value=" . $infoData[$key] . "\n", 3, $this->logfile);
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($this->log)
|
|
|
|
{
|
|
|
|
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n" .
|
|
|
|
array2string($infoData) . "\n", 3, $this->logfile);
|
|
|
|
}
|
|
|
|
return $infoData;
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
/**
|
|
|
|
* Search for SIF data a matching infolog entry
|
|
|
|
*
|
|
|
|
* @param string $sifData the SIF data
|
|
|
|
* @param string $_sifType type (note/task)
|
|
|
|
* @param int $contentID=null infolog_id (or null, if unkown)
|
|
|
|
* @param boolean $relax=false if true, a weaker match algorithm is used
|
|
|
|
* @return infolog_id of a matching entry or false, if nothing was found
|
|
|
|
*/
|
|
|
|
function searchSIF($_sifData, $_sifType, $contentID=null, $relax=false)
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
if (!($egwData = $this->siftoegw($_sifData, $_sifType, $contentID))) return array();
|
2009-07-15 22:04:17 +02:00
|
|
|
|
|
|
|
if ($contentID) $egwData['info_id'] = $contentID;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
if ($_sifType == 'note') unset($egwData['info_startdate']);
|
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
return $this->findInfo($egwData, $relax, $this->tzid);
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
/**
|
|
|
|
* Add SIF data entry
|
|
|
|
*
|
|
|
|
* @param string $sifData the SIF data
|
|
|
|
* @param string $_sifType type (note/task)
|
|
|
|
* @param boolean $merge=false reserved for future use
|
|
|
|
* @return infolog_id of the new entry or false, for errors
|
|
|
|
*/
|
|
|
|
function addSIF($_sifData, $_id, $_sifType, $merge=false)
|
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($this->tzid)
|
|
|
|
{
|
|
|
|
date_default_timezone_set($this->tzid);
|
|
|
|
}
|
|
|
|
$egwData = $this->siftoegw($_sifData, $_sifType, $_id);
|
|
|
|
if ($this->tzid)
|
2009-07-15 22:04:17 +02:00
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
date_default_timezone_set($GLOBALS['egw_info']['server']['server_timezone']);
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
if (!$egwData) return false;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($_id > 0) $egwData['info_id'] = $_id;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
return $this->write($egwData, true, true, false);
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Export an infolog entry as SIF data
|
|
|
|
*
|
|
|
|
* @param int $_id the infolog_id of the entry
|
|
|
|
* @param string $_sifType type (note/task)
|
|
|
|
* @return string SIF representation of the infolog entry
|
|
|
|
*/
|
|
|
|
function getSIF($_id, $_sifType)
|
|
|
|
{
|
|
|
|
$sysCharSet = $GLOBALS['egw']->translation->charset();
|
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
if (!($infoData = $this->read($_id, true, 'server'))) return false;
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
switch($_sifType)
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
case 'task':
|
2010-02-09 22:56:39 +01:00
|
|
|
if ($infoData['info_id_parent'])
|
|
|
|
{
|
|
|
|
$parent = $this->read($infoData['info_id_parent']);
|
|
|
|
$infoData['info_id_parent'] = $parent['info_uid'];
|
|
|
|
}
|
|
|
|
else
|
2009-07-15 22:04:17 +02:00
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_id_parent'] = '';
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
if (!preg_match('/\[UID:.+\]/m', $infoData['info_des']))
|
|
|
|
{
|
|
|
|
$infoData['info_des'] .= "\r\n[UID:" . $infoData['info_uid'] . "]";
|
|
|
|
if ($infoData['info_id_parent'] != '')
|
2009-07-15 22:04:17 +02:00
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
$infoData['info_des'] .= "\r\n[PARENT_UID:" . $infoData['info_id_parent'] . "]";
|
2009-07-15 22:04:17 +02:00
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
$sifTask = self::xml_decl . "\n<task>" . self::SIF_decl;
|
|
|
|
|
|
|
|
foreach ($this->_sifTaskMapping as $sifField => $egwField)
|
|
|
|
{
|
|
|
|
if (empty($egwField)) continue;
|
2009-07-15 22:04:17 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
$value = $GLOBALS['egw']->translation->convert($infoData[$egwField], $sysCharSet, 'utf-8');
|
2009-07-15 22:04:17 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
switch ($sifField)
|
2009-07-15 22:04:17 +02:00
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Complete':
|
|
|
|
// is handled with DateCompleted
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'DateCompleted':
|
|
|
|
if ($infoData[info_status] != 'done')
|
|
|
|
{
|
|
|
|
$sifTask .= "<DateCompleted></DateCompleted><Complete>0</Complete>";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$sifTask .= "<Complete>1</Complete>";
|
2009-07-15 22:04:17 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'DueDate':
|
|
|
|
case 'StartDate':
|
|
|
|
$sifTask .= '<$sifField>';
|
|
|
|
if (!empty($value))
|
|
|
|
{
|
|
|
|
$sifTask .= $this->getDateTime($value, $this->tzid);
|
|
|
|
}
|
|
|
|
$sifTask .= '</$sifField>';
|
|
|
|
break;
|
2009-07-15 22:04:17 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Importance':
|
|
|
|
if ($value > 3) $value = 3;
|
|
|
|
$sifTask .= "<$sifField>$value</$sifField>";
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Sensitivity':
|
|
|
|
$value = ($value == 'private' ? '2' : '0');
|
|
|
|
$sifTask .= "<$sifField>$value</$sifField>";
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Status':
|
|
|
|
switch ($value)
|
|
|
|
{
|
|
|
|
case 'cancelled':
|
|
|
|
case 'deferred':
|
|
|
|
$value = '4';
|
|
|
|
break;
|
|
|
|
case 'waiting':
|
|
|
|
case 'nonactive':
|
|
|
|
$value = '3';
|
|
|
|
break;
|
|
|
|
case 'done':
|
|
|
|
case 'archive':
|
|
|
|
case 'billed':
|
|
|
|
$value = '2';
|
|
|
|
break;
|
|
|
|
case 'not-started':
|
|
|
|
case 'template':
|
|
|
|
$value = '0';
|
|
|
|
break;
|
|
|
|
default: //ongoing
|
|
|
|
$value = 1;
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
2010-02-09 22:56:39 +01:00
|
|
|
}
|
|
|
|
$sifTask .= "<$sifField>$value</$sifField>";
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Categories':
|
|
|
|
if (!empty($value) && $value)
|
|
|
|
{
|
|
|
|
$value = implode('; ', $this->get_categories(array($value)));
|
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
2010-02-09 22:56:39 +01:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
default:
|
|
|
|
$value = @htmlspecialchars($value, ENT_QUOTES, 'utf-8');
|
|
|
|
$sifTask .= "<$sifField>$value</$sifField>";
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
$sifTask .= '<ActualWork>0</ActualWork><IsRecurring>0</IsRecurring></task>';
|
|
|
|
return $sifTask;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
|
|
|
case 'note':
|
2010-02-09 22:56:39 +01:00
|
|
|
$sifNote = self::xml_decl . "\n<note>" . self::SIF_decl;
|
|
|
|
|
|
|
|
foreach ($this->_sifNoteMapping as $sifField => $egwField)
|
2009-07-15 22:04:17 +02:00
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
if(empty($egwField)) continue;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
$value = $GLOBALS['egw']->translation->convert($infoData[$egwField], $sysCharSet, 'utf-8');
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
switch ($sifField)
|
2008-10-07 14:50:14 +02:00
|
|
|
{
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Date':
|
|
|
|
$sifNote .= '<$sifField>';
|
|
|
|
if (!empty($value))
|
|
|
|
{
|
|
|
|
$sifNote .= $this->getDateTime($value, $this->tzid);
|
|
|
|
}
|
|
|
|
$sifNote .= '</$sifField>';
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
case 'Categories':
|
|
|
|
if (!empty($value))
|
|
|
|
{
|
|
|
|
$value = implode('; ', $this->get_categories(array($value)));
|
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-07 14:50:14 +02:00
|
|
|
break;
|
2010-02-09 22:56:39 +01:00
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2010-02-09 22:56:39 +01:00
|
|
|
default:
|
|
|
|
$value = @htmlspecialchars($value, ENT_QUOTES, 'utf-8');
|
|
|
|
$sifNote .= "<$sifField>$value</$sifField>";
|
|
|
|
break;
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
$sifNote .= '</note>';
|
|
|
|
return $sifNote;
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
return false;
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
/**
|
|
|
|
* Set the supported fields
|
|
|
|
*
|
|
|
|
* Currently we only store name and version, manucfacturer is always Funambol
|
|
|
|
*
|
|
|
|
* @param string $_productName
|
|
|
|
* @param string $_productSoftwareVersion
|
|
|
|
*/
|
|
|
|
function setSupportedFields($_productName='', $_productSoftwareVersion='')
|
2008-10-07 14:50:14 +02:00
|
|
|
{
|
2009-07-15 22:04:17 +02:00
|
|
|
$state = &$_SESSION['SyncML.state'];
|
|
|
|
$deviceInfo = $state->getClientDeviceInfo();
|
2008-10-07 14:50:14 +02:00
|
|
|
|
2009-07-15 22:04:17 +02:00
|
|
|
if (isset($deviceInfo) && is_array($deviceInfo))
|
2008-10-07 14:50:14 +02:00
|
|
|
{
|
2009-07-15 22:04:17 +02:00
|
|
|
if (isset($deviceInfo['uidExtension']) &&
|
|
|
|
$deviceInfo['uidExtension'])
|
|
|
|
{
|
|
|
|
$this->uidExtension = true;
|
|
|
|
}
|
2010-02-09 22:56:39 +01:00
|
|
|
if (isset($deviceInfo['tzid']) &&
|
|
|
|
$deviceInfo['tzid'])
|
|
|
|
{
|
|
|
|
switch ($deviceInfo['tzid'])
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
$this->tzid = false;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$this->tzid = null;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->tzid = $deviceInfo['tzid'];
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
2009-07-15 22:04:17 +02:00
|
|
|
// store product name and version, to be able to use it elsewhere
|
|
|
|
if ($_productName)
|
2008-10-07 14:50:14 +02:00
|
|
|
{
|
2009-07-15 22:04:17 +02:00
|
|
|
$this->productName = strtolower($_productName);
|
|
|
|
if (preg_match('/^[^\d]*(\d+\.?\d*)[\.|\d]*$/', $_productSoftwareVersion, $matches))
|
2008-10-07 14:50:14 +02:00
|
|
|
{
|
2009-07-15 22:04:17 +02:00
|
|
|
$this->productSoftwareVersion = $matches[1];
|
2008-10-07 14:50:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|