2008-05-17 20:03:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2011-04-11 11:29:39 +02:00
|
|
|
* EGroupware: GroupDAV access: infolog handler
|
2008-05-17 20:03:33 +02:00
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package infolog
|
|
|
|
* @subpackage groupdav
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2012-01-26 02:49:56 +01:00
|
|
|
* @copyright (c) 2007-12 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2008-05-17 20:03:33 +02:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2011-02-23 11:59:12 +01:00
|
|
|
require_once EGW_SERVER_ROOT.'/phpgwapi/inc/horde/lib/core.php';
|
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
/**
|
2011-04-11 11:29:39 +02:00
|
|
|
* EGroupware: GroupDAV access: infolog handler
|
2008-05-17 20:03:33 +02:00
|
|
|
*/
|
|
|
|
class infolog_groupdav extends groupdav_handler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* bo class of the application
|
|
|
|
*
|
2008-10-07 14:50:14 +02:00
|
|
|
* @var infolog_bo
|
2008-05-17 20:03:33 +02:00
|
|
|
*/
|
|
|
|
var $bo;
|
2009-10-16 10:36:28 +02:00
|
|
|
|
2011-02-23 11:59:12 +01:00
|
|
|
/**
|
|
|
|
* vCalendar Instance for parsing
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $vCalendar;
|
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
var $filter_prop2infolog = array(
|
|
|
|
'SUMMARY' => 'info_subject',
|
|
|
|
'UID' => 'info_uid',
|
|
|
|
'DTSTART' => 'info_startdate',
|
|
|
|
'DUE' => 'info_enddate',
|
|
|
|
'DESCRIPTION' => 'info_des',
|
|
|
|
'STATUS' => 'info_status',
|
|
|
|
'PRIORITY' => 'info_priority',
|
|
|
|
'LOCATION' => 'info_location',
|
|
|
|
'COMPLETED' => 'info_datecompleted',
|
2011-10-06 12:29:01 +02:00
|
|
|
'CREATED' => 'info_created',
|
2010-03-15 10:55:16 +01:00
|
|
|
);
|
2011-04-11 11:29:39 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Are we using info_id, info_uid or caldav_name for the path/url
|
|
|
|
*
|
|
|
|
* Get's set in constructor to 'caldav_name' and groupdav_handler::$path_extension = ''!
|
|
|
|
*/
|
|
|
|
static $path_attr = 'info_id';
|
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $app 'calendar', 'addressbook' or 'infolog'
|
2011-09-18 12:56:56 +02:00
|
|
|
* @param groupdav $groupdav calling class
|
2008-05-17 20:03:33 +02:00
|
|
|
*/
|
2011-09-18 12:56:56 +02:00
|
|
|
function __construct($app, groupdav $groupdav)
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2011-09-18 12:56:56 +02:00
|
|
|
parent::__construct($app, $groupdav);
|
2009-10-16 10:36:28 +02:00
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$this->bo = new infolog_bo();
|
2011-02-23 11:59:12 +01:00
|
|
|
$this->vCalendar = new Horde_iCalendar;
|
2008-05-17 20:03:33 +02:00
|
|
|
|
2011-04-11 11:29:39 +02:00
|
|
|
// since 1.9.002 we allow clients to specify the URL when creating a new event, as specified by CalDAV
|
|
|
|
if (version_compare($GLOBALS['egw_info']['apps']['calendar']['version'], '1.9.002', '>='))
|
|
|
|
{
|
|
|
|
self::$path_attr = 'caldav_name';
|
|
|
|
groupdav_handler::$path_extension = '';
|
|
|
|
}
|
|
|
|
}
|
2008-11-18 07:11:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the path for an event
|
|
|
|
*
|
|
|
|
* @param array|int $info
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-09-21 22:08:21 +02:00
|
|
|
function get_path($info)
|
2008-11-18 07:11:12 +01:00
|
|
|
{
|
2011-04-11 11:29:39 +02:00
|
|
|
if (is_numeric($info) && self::$path_attr == 'info_id')
|
2008-11-18 07:11:12 +01:00
|
|
|
{
|
|
|
|
$name = $info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!is_array($info)) $info = $this->bo->read($info);
|
2011-04-11 11:29:39 +02:00
|
|
|
$name = $info[self::$path_attr];
|
2008-11-18 07:11:12 +01:00
|
|
|
}
|
2011-04-11 11:29:39 +02:00
|
|
|
return $name.groupdav_handler::$path_extension;
|
2008-11-18 07:11:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
/**
|
2011-09-28 14:35:53 +02:00
|
|
|
* Get filter-array for infolog_bo::search used by getctag and propfind
|
2008-05-17 20:03:33 +02:00
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param int $user account_id
|
2011-09-28 14:35:53 +02:00
|
|
|
* @return array
|
2008-05-17 20:03:33 +02:00
|
|
|
*/
|
2011-09-28 14:35:53 +02:00
|
|
|
private function get_infolog_filter($path, $user)
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2012-01-26 02:49:56 +01:00
|
|
|
if (!($infolog_types = $GLOBALS['egw_info']['user']['preferences']['groupdav']['infolog-types']))
|
2011-09-28 14:35:53 +02:00
|
|
|
{
|
|
|
|
$infolog_types = 'task';
|
|
|
|
}
|
2010-03-11 08:30:46 +01:00
|
|
|
if ($path == '/infolog/')
|
|
|
|
{
|
2010-03-15 10:55:16 +01:00
|
|
|
$task_filter= 'own';
|
2010-03-11 08:30:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-26 02:49:56 +01:00
|
|
|
if ($user == $GLOBALS['egw_info']['user']['account_id'])
|
2010-03-15 10:55:16 +01:00
|
|
|
{
|
2012-01-26 02:49:56 +01:00
|
|
|
$task_filter = 'own';
|
2010-03-15 10:55:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-26 02:49:56 +01:00
|
|
|
$task_filter = 'user' . $user;
|
2010-03-15 10:55:16 +01:00
|
|
|
}
|
2010-03-11 08:30:46 +01:00
|
|
|
}
|
|
|
|
|
2012-01-26 02:49:56 +01:00
|
|
|
$ret = array(
|
2010-03-16 21:44:55 +01:00
|
|
|
'filter' => $task_filter,
|
2011-09-28 14:35:53 +02:00
|
|
|
'info_type' => explode(',', $infolog_types),
|
2010-03-15 10:55:16 +01:00
|
|
|
);
|
2012-01-29 23:34:43 +01:00
|
|
|
//error_log(__METHOD__."('$path', $user) returning ".array2string($ret));
|
2012-01-26 02:49:56 +01:00
|
|
|
return $ret;
|
2011-09-28 14:35:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle propfind in the infolog folder
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param array $options
|
|
|
|
* @param array &$files
|
|
|
|
* @param int $user account_id
|
|
|
|
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
|
|
|
|
*/
|
|
|
|
function propfind($path,$options,&$files,$user,$id='')
|
|
|
|
{
|
|
|
|
// todo add a filter to limit how far back entries from the past get synced
|
|
|
|
$filter = $this->get_infolog_filter($path, $user);
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
// process REPORT filters or multiget href's
|
|
|
|
if (($id || $options['root']['name'] != 'propfind') && !$this->_report_filters($options,$filter,$id))
|
|
|
|
{
|
2011-09-30 14:52:40 +02:00
|
|
|
// return empty collection, as iCal under iOS 5 had problems with returning "404 Not found" status
|
|
|
|
// when trying to request not supported components, eg. VTODO on a calendar collection
|
|
|
|
return true;
|
2010-03-15 10:55:16 +01:00
|
|
|
}
|
2011-10-06 12:29:01 +02:00
|
|
|
// enable time-range filter for tests via propfind / autoindex
|
|
|
|
//$filter[] = $sql = $this->_time_range_filter(array('end' => '20001231T000000Z'));
|
|
|
|
|
2011-10-04 14:16:03 +02:00
|
|
|
if ($id) $path = dirname($path).'/'; // caldav_name get's added anyway in the callback
|
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
if ($this->debug > 1)
|
|
|
|
{
|
|
|
|
error_log(__METHOD__."($path,,,$user,$id) filter=".
|
|
|
|
array2string($filter));
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if we have to return the full calendar data or just the etag's
|
2010-03-15 10:55:16 +01:00
|
|
|
if (!($filter['calendar_data'] = $options['props'] == 'all' &&
|
|
|
|
$options['root']['ns'] == groupdav::CALDAV) && is_array($options['props']))
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
foreach($options['props'] as $prop)
|
|
|
|
{
|
|
|
|
if ($prop['name'] == 'calendar-data')
|
|
|
|
{
|
2010-03-15 10:55:16 +01:00
|
|
|
$filter['calendar_data'] = true;
|
2010-03-07 00:06:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
// return iterator, calling ourself to return result in chunks
|
|
|
|
$files['files'] = new groupdav_propfind_iterator($this,$path,$filter,$files['files']);
|
2011-09-30 14:52:40 +02:00
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
/**
|
|
|
|
* Callback for profind interator
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param array $filter
|
|
|
|
* @param array|boolean $start=false false=return all or array(start,num)
|
|
|
|
* @return array with "files" array with values for keys path and props
|
|
|
|
*/
|
|
|
|
function &propfind_callback($path,array $filter,$start=false)
|
|
|
|
{
|
|
|
|
if ($this->debug) $starttime = microtime(true);
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
if (($calendar_data = $filter['calendar_data']))
|
|
|
|
{
|
|
|
|
$handler = self::_get_handler();
|
|
|
|
}
|
|
|
|
unset($filter['calendar_data']);
|
|
|
|
$task_filter = $filter['filter'];
|
|
|
|
unset($filter['filter']);
|
2008-08-04 21:08:09 +02:00
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
$query = array(
|
|
|
|
'order' => 'info_datemodified',
|
|
|
|
'sort' => 'DESC',
|
|
|
|
'filter' => $task_filter,
|
|
|
|
'date_format' => 'server',
|
2008-08-04 21:08:09 +02:00
|
|
|
'col_filter' => $filter,
|
2012-01-31 19:00:57 +01:00
|
|
|
'custom_fields' => true, // otherwise custom fields get NOT loaded!
|
2010-03-15 10:55:16 +01:00
|
|
|
);
|
|
|
|
|
2010-03-16 21:44:55 +01:00
|
|
|
if (!$calendar_data)
|
2010-03-16 08:01:36 +01:00
|
|
|
{
|
2012-01-31 01:37:01 +01:00
|
|
|
$query['cols'] = array('info_id', 'info_datemodified', 'info_uid', 'caldav_name', 'info_subject');
|
2010-03-16 08:01:36 +01:00
|
|
|
}
|
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
if (is_array($start))
|
|
|
|
{
|
|
|
|
$query['start'] = $offset = $start[0];
|
|
|
|
$query['num_rows'] = $start[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$files = array();
|
|
|
|
// ToDo: add parameter to only return id & etag
|
|
|
|
$tasks =& $this->bo->search($query);
|
|
|
|
if ($tasks && $offset == $query['start'])
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2010-03-16 21:44:55 +01:00
|
|
|
foreach($tasks as $task)
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
$props = array(
|
2011-09-21 22:08:21 +02:00
|
|
|
'getcontenttype' => $this->agent != 'kde' ? 'text/calendar; charset=utf-8; component=VTODO' : 'text/calendar', // Konqueror (3.5) dont understand it otherwise
|
|
|
|
'getlastmodified' => $task['info_datemodified'],
|
2012-01-31 01:37:01 +01:00
|
|
|
'displayname' => $task['info_subject'],
|
2010-03-07 00:06:43 +01:00
|
|
|
);
|
|
|
|
if ($calendar_data)
|
|
|
|
{
|
2011-10-03 14:53:28 +02:00
|
|
|
$content = $handler->exportVTODO($task, '2.0', null); // no METHOD:PUBLISH for CalDAV
|
2011-09-21 22:08:21 +02:00
|
|
|
$props['getcontentlength'] = bytes($content);
|
2010-03-07 00:06:43 +01:00
|
|
|
$props[] = HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-data',$content);
|
|
|
|
}
|
2011-09-21 22:08:21 +02:00
|
|
|
$files[] = $this->add_resource($path, $task, $props);
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
}
|
2010-03-15 10:55:16 +01:00
|
|
|
if ($this->debug) error_log(__METHOD__."($path) took ".(microtime(true) - $starttime).' to return '.count($files).' items');
|
|
|
|
return $files;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the filters from the CalDAV REPORT request
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @param array &$cal_filters
|
|
|
|
* @param string $id
|
|
|
|
* @return boolean true if filter could be processed, false for requesting not here supported VTODO items
|
|
|
|
*/
|
|
|
|
function _report_filters($options,&$cal_filters,$id)
|
|
|
|
{
|
|
|
|
if ($options['filters'])
|
|
|
|
{
|
2011-10-07 11:05:11 +02:00
|
|
|
$cal_filters_in = $cal_filters; // remember filter, to be able to reset standard open-filter, if client sets own filters
|
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
foreach($options['filters'] as $filter)
|
|
|
|
{
|
|
|
|
switch($filter['name'])
|
|
|
|
{
|
|
|
|
case 'comp-filter':
|
|
|
|
if ($this->debug > 1) error_log(__METHOD__."($options[path],...) comp-filter='{$filter['attrs']['name']}'");
|
|
|
|
|
|
|
|
switch($filter['attrs']['name'])
|
|
|
|
{
|
|
|
|
case 'VTODO':
|
2010-06-09 21:44:58 +02:00
|
|
|
case 'VCALENDAR':
|
2010-03-15 10:55:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'prop-filter':
|
|
|
|
if ($this->debug > 1) error_log(__METHOD__."($options[path],...) prop-filter='{$filter['attrs']['name']}'");
|
|
|
|
$prop_filter = $filter['attrs']['name'];
|
|
|
|
break;
|
|
|
|
case 'text-match':
|
|
|
|
if ($this->debug > 1) error_log(__METHOD__."($options[path],...) text-match: $prop_filter='{$filter['data']}'");
|
|
|
|
if (!isset($this->filter_prop2infolog[strtoupper($prop_filter)]))
|
|
|
|
{
|
|
|
|
if ($this->debug) error_log(__METHOD__."($options[path],".array2string($options).",...) unknown property '$prop_filter' --> ignored");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cal_filters[$this->filter_prop2infolog[strtoupper($prop_filter)]] = $filter['data'];
|
|
|
|
}
|
|
|
|
unset($prop_filter);
|
|
|
|
break;
|
|
|
|
case 'param-filter':
|
|
|
|
if ($this->debug) error_log(__METHOD__."($options[path],...) param-filter='{$filter['attrs']['name']}' not (yet) implemented!");
|
|
|
|
break;
|
|
|
|
case 'time-range':
|
2011-10-07 11:05:11 +02:00
|
|
|
$cal_filters[] = $this->_time_range_filter($filter['attrs']);
|
2010-03-15 10:55:16 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ($this->debug) error_log(__METHOD__."($options[path],".array2string($options).",...) unknown filter --> ignored");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 11:05:11 +02:00
|
|
|
// if client set an own filter, reset the open-standard filter
|
2012-01-26 02:49:56 +01:00
|
|
|
/* not longer necessary, as we use now own and user anyway
|
2011-10-07 11:05:11 +02:00
|
|
|
if ($cal_filters != $cal_filters_in)
|
|
|
|
{
|
|
|
|
$cal_filters['filter'] = str_replace(array('open', 'open-user'), array('own', 'user'), $cal_filters['filter']);
|
2012-01-26 02:49:56 +01:00
|
|
|
}*/
|
2010-03-15 10:55:16 +01:00
|
|
|
}
|
|
|
|
// multiget or propfind on a given id
|
|
|
|
//error_log(__FILE__ . __METHOD__ . "multiget of propfind:");
|
|
|
|
if ($options['root']['name'] == 'calendar-multiget' || $id)
|
|
|
|
{
|
|
|
|
$ids = array();
|
|
|
|
if ($id)
|
|
|
|
{
|
2011-04-11 11:29:39 +02:00
|
|
|
$cal_filters[self::$path_attr] = groupdav_handler::$path_extension ?
|
|
|
|
basename($id,groupdav_handler::$path_extension) : $id;
|
2010-03-15 10:55:16 +01:00
|
|
|
}
|
|
|
|
else // fetch all given url's
|
|
|
|
{
|
|
|
|
foreach($options['other'] as $option)
|
|
|
|
{
|
|
|
|
if ($option['name'] == 'href')
|
|
|
|
{
|
|
|
|
$parts = explode('/',$option['data']);
|
2011-04-11 11:29:39 +02:00
|
|
|
if (($id = basename(array_pop($parts))))
|
|
|
|
{
|
|
|
|
$cal_filters[self::$path_attr][] = groupdav_handler::$path_extension ?
|
|
|
|
basename($id,groupdav_handler::$path_extension) : $id;
|
|
|
|
}
|
2010-03-15 10:55:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($this->debug > 1) error_log(__METHOD__ ."($options[path],...,$id) calendar-multiget: ids=".implode(',',$ids));
|
|
|
|
}
|
2008-05-17 20:03:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-06 12:29:01 +02:00
|
|
|
/**
|
|
|
|
* Create SQL filter from time-range filter attributes
|
|
|
|
*
|
|
|
|
* CalDAV time-range for VTODO checks DTSTART, DTEND, DUE, CREATED and allways includes tasks if none given
|
|
|
|
* @see http://tools.ietf.org/html/rfc4791#section-9.9
|
|
|
|
*
|
|
|
|
* @param array $attrs values for keys 'start' and/or 'end', at least one is required by CalDAV rfc!
|
|
|
|
* @return string with sql
|
|
|
|
*/
|
|
|
|
private function _time_range_filter(array $attrs)
|
|
|
|
{
|
|
|
|
$to_or = $to_and = array();
|
|
|
|
if (!empty($attrs['start']))
|
|
|
|
{
|
|
|
|
$start = (int)$this->vCalendar->_parseDateTime($attrs['start']);
|
|
|
|
}
|
|
|
|
if (!empty($attrs['end']))
|
|
|
|
{
|
|
|
|
$end = (int)$this->vCalendar->_parseDateTime($attrs['end']);
|
|
|
|
}
|
|
|
|
elseif (empty($attrs['start']))
|
|
|
|
{
|
|
|
|
error_log(__METHOD__.'('.array2string($attrs).') minimum one of start or end is required!');
|
|
|
|
return '1'; // to not give sql error, but simply not filter out anything
|
|
|
|
}
|
|
|
|
// we dont need to care for DURATION line in rfc4791#section-9.9, as we always put that in DUE/info_enddate
|
|
|
|
|
|
|
|
// we have start- and/or enddate
|
|
|
|
if (isset($start))
|
|
|
|
{
|
|
|
|
$to_and[] = "($start < info_enddate OR $start <= info_startdate)";
|
|
|
|
}
|
|
|
|
if (isset($end))
|
|
|
|
{
|
|
|
|
$to_and[] = "(info_startdate < $end OR info_enddate <= $end)";
|
|
|
|
}
|
|
|
|
$to_or[] = '('.implode(' AND ', $to_and).')';
|
|
|
|
|
|
|
|
/* either start or enddate is already included in the above, because of OR!
|
|
|
|
// only a startdate, no enddate
|
|
|
|
$to_or[] = "NOT info_enddate > 0".($start ? " AND $start <= info_startdate" : '').
|
|
|
|
($end ? " AND info_startdate < $end" : '');
|
|
|
|
|
|
|
|
// only an enddate, no startdate
|
|
|
|
$to_or[] = "NOT info_startdate > 0".($start ? " AND $start < info_enddate" : '').
|
|
|
|
($end ? " AND info_enddate <= $end" : '');*/
|
|
|
|
|
|
|
|
// no startdate AND no enddate (2. half of rfc4791#section-9.9) --> use created and due dates instead
|
|
|
|
$to_or[] = 'NOT info_startdate > 0 AND NOT info_enddate > 0 AND ('.
|
|
|
|
// we have a completed date
|
|
|
|
"info_datecompleted > 0".(isset($start) ? " AND ($start <= info_datecompleted OR $start <= info_created)" : '').
|
|
|
|
(isset($end) ? " AND (info_datecompleted <= $end OR info_created <= $end)" : '').' OR '.
|
|
|
|
// we have no completed date, but always a created date
|
|
|
|
"NOT info_datecompleted > 0". (isset($end) ? " AND info_created < $end" : '').
|
|
|
|
')';
|
|
|
|
$sql = '('.implode(' OR ', $to_or).')';
|
|
|
|
if ($this->debug > 1) error_log(__FILE__ . __METHOD__.'('.array2string($attrs).") time-range={$filter['attrs']['start']}-{$filter['attrs']['end']} --> $sql");
|
|
|
|
return $sql;
|
|
|
|
}
|
2010-03-15 10:55:16 +01:00
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
/**
|
|
|
|
* Handle get request for a task / infolog entry
|
|
|
|
*
|
|
|
|
* @param array &$options
|
|
|
|
* @param int $id
|
2011-03-05 11:21:32 +01:00
|
|
|
* @param int $user=null account_id
|
2008-05-17 20:03:33 +02:00
|
|
|
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
|
|
|
|
*/
|
2011-03-05 11:21:32 +01:00
|
|
|
function get(&$options,$id,$user=null)
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
|
|
|
if (!is_array($task = $this->_common_get_put_delete('GET',$options,$id)))
|
|
|
|
{
|
|
|
|
return $task;
|
|
|
|
}
|
2008-11-03 10:36:20 +01:00
|
|
|
$handler = $this->_get_handler();
|
2011-10-03 14:53:28 +02:00
|
|
|
$options['data'] = $handler->exportVTODO($task, '2.0', null); // no METHOD:PUBLISH for CalDAV
|
2008-05-17 20:03:33 +02:00
|
|
|
$options['mimetype'] = 'text/calendar; charset=utf-8';
|
|
|
|
header('Content-Encoding: identity');
|
2011-10-05 10:15:24 +02:00
|
|
|
header('ETag: "'.$this->get_etag($task).'"');
|
2008-05-17 20:03:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle put request for a task / infolog entry
|
|
|
|
*
|
|
|
|
* @param array &$options
|
|
|
|
* @param int $id
|
|
|
|
* @param int $user=null account_id of owner, default null
|
2010-10-26 11:21:52 +02:00
|
|
|
* @param string $prefix=null user prefix from path (eg. /ralf from /ralf/addressbook)
|
2008-05-17 20:03:33 +02:00
|
|
|
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
|
|
|
|
*/
|
2010-10-26 11:21:52 +02:00
|
|
|
function put(&$options,$id,$user=null,$prefix=null)
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options,true));
|
|
|
|
|
|
|
|
$oldTask = $this->_common_get_put_delete('PUT',$options,$id);
|
|
|
|
if (!is_null($oldTask) && !is_array($oldTask))
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
return $oldTask;
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2008-11-03 10:36:20 +01:00
|
|
|
$handler = $this->_get_handler();
|
2010-03-07 00:06:43 +01:00
|
|
|
$vTodo = htmlspecialchars_decode($options['content']);
|
|
|
|
|
|
|
|
if (is_array($oldTask))
|
|
|
|
{
|
|
|
|
$taskId = $oldTask['info_id'];
|
|
|
|
$retval = true;
|
|
|
|
}
|
2011-04-11 11:29:39 +02:00
|
|
|
else // new entry
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
2011-04-11 11:29:39 +02:00
|
|
|
$taskId = 0;
|
|
|
|
$retval = '201 Created';
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
2011-04-11 11:29:39 +02:00
|
|
|
if (!($infoId = $handler->importVTODO($vTodo, $taskId, false, $user, null, $id)))
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2009-10-16 10:36:28 +02:00
|
|
|
if ($this->debug) error_log(__METHOD__."(,$id) import_vtodo($options[content]) returned false");
|
2008-07-08 07:34:10 +02:00
|
|
|
return '403 Forbidden';
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2010-03-15 10:55:16 +01:00
|
|
|
if ($infoId != $taskId)
|
|
|
|
{
|
|
|
|
$retval = '201 Created';
|
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2011-10-03 17:48:24 +02:00
|
|
|
// we should not return an etag here, as we never store the PUT ical byte-by-byte
|
2011-10-05 10:15:24 +02:00
|
|
|
//header('ETag: "'.$this->get_etag($infoId).'"');
|
2011-04-11 11:29:39 +02:00
|
|
|
|
|
|
|
// send GroupDAV Location header only if we dont use caldav_name as path-attribute
|
|
|
|
if ($retval !== true && self::$path_attr != 'caldav_name')
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2010-03-07 00:06:43 +01:00
|
|
|
$path = preg_replace('|(.*)/[^/]*|', '\1/', $options['path']);
|
|
|
|
header('Location: '.$this->base_uri.$path.self::get_path($infoId));
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
2011-04-11 11:29:39 +02:00
|
|
|
return $retval;
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle delete request for a task / infolog entry
|
|
|
|
*
|
|
|
|
* @param array &$options
|
|
|
|
* @param int $id
|
|
|
|
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
|
|
|
|
*/
|
|
|
|
function delete(&$options,$id)
|
|
|
|
{
|
|
|
|
if (!is_array($task = $this->_common_get_put_delete('DELETE',$options,$id)))
|
|
|
|
{
|
|
|
|
return $task;
|
|
|
|
}
|
2011-04-11 11:29:39 +02:00
|
|
|
return $this->bo->delete($task['info_id']);
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read an entry
|
|
|
|
*
|
2011-10-04 16:18:35 +02:00
|
|
|
* We have to make sure to not return or even consider in read deleted infologs, as the might have
|
|
|
|
* the same UID and/or caldav_name as not deleted ones and would block access to valid entries
|
|
|
|
*
|
2011-04-11 11:29:39 +02:00
|
|
|
* @param string|id $id
|
|
|
|
* @return array|boolean array with entry, false if no read rights, null if $id does not exist
|
2008-05-17 20:03:33 +02:00
|
|
|
*/
|
|
|
|
function read($id)
|
|
|
|
{
|
2011-10-04 16:18:35 +02:00
|
|
|
return $this->bo->read(array(self::$path_attr => $id, "info_status!='deleted'"),false,'server');
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if user has the neccessary rights on a task / infolog entry
|
|
|
|
*
|
|
|
|
* @param int $acl EGW_ACL_READ, EGW_ACL_EDIT or EGW_ACL_DELETE
|
2011-04-11 11:29:39 +02:00
|
|
|
* @param array|int $task task-array or id
|
2008-05-17 20:03:33 +02:00
|
|
|
* @return boolean null if entry does not exist, false if no access, true if access permitted
|
|
|
|
*/
|
|
|
|
function check_access($acl,$task)
|
|
|
|
{
|
2010-03-15 10:55:16 +01:00
|
|
|
if (is_null($task)) return true;
|
2011-04-11 11:29:39 +02:00
|
|
|
|
2012-01-26 02:49:56 +01:00
|
|
|
$access = $this->bo->check_access($task,$acl);
|
|
|
|
|
|
|
|
if (!$access && $acl == EGW_ACL_EDIT && $this->bo->is_responsible($task))
|
|
|
|
{
|
|
|
|
$access = true; // access limited to $this->bo->responsible_edit fields (handled in infolog_bo::write())
|
|
|
|
}
|
|
|
|
if ($this->debug > 1) error_log(__METHOD__."($acl, ".array2string($task).') returning '.array2string($access));
|
|
|
|
return $access;
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
|
2010-04-13 17:31:59 +02:00
|
|
|
/**
|
|
|
|
* Query ctag for infolog
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getctag($path,$user)
|
|
|
|
{
|
2011-09-28 14:35:53 +02:00
|
|
|
return $this->bo->getctag($this->get_infolog_filter($path, $user));
|
2010-04-13 17:31:59 +02:00
|
|
|
}
|
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
/**
|
|
|
|
* Get the etag for an infolog entry
|
|
|
|
*
|
2011-04-11 11:29:39 +02:00
|
|
|
* etag currently uses the modifcation time (info_modified), 1.9.002 adds etag column, but it's not yet used!
|
|
|
|
*
|
|
|
|
* @param array|int $info array with infolog entry or info_id
|
|
|
|
* @return string|boolean string with etag or false
|
2008-05-17 20:03:33 +02:00
|
|
|
*/
|
|
|
|
function get_etag($info)
|
|
|
|
{
|
|
|
|
if (!is_array($info))
|
|
|
|
{
|
2010-02-04 13:08:03 +01:00
|
|
|
$info = $this->bo->read($info,true,'server');
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
if (!is_array($info) || !isset($info['info_id']) || !isset($info['info_datemodified']))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 13:34:55 +02:00
|
|
|
return $info['info_id'].':'.$info['info_datemodified'];
|
2010-03-07 00:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add extra properties for calendar collections
|
|
|
|
*
|
|
|
|
* @param array $props=array() regular props by the groupdav handler
|
|
|
|
* @param string $displayname
|
|
|
|
* @param string $base_uri=null base url of handler
|
2011-10-20 15:35:01 +02:00
|
|
|
* @param int $user=null account_id of owner of collection
|
2010-03-07 00:06:43 +01:00
|
|
|
* @return array
|
|
|
|
*/
|
2011-10-20 15:35:01 +02:00
|
|
|
public function extra_properties(array $props=array(), $displayname, $base_uri=null,$user=null)
|
2010-03-07 00:06:43 +01:00
|
|
|
{
|
|
|
|
// calendar description
|
2011-10-20 15:35:01 +02:00
|
|
|
$displayname = translation::convert(lang('Tasks of'),translation::charset(),'utf-8').' '.$displayname;
|
2011-10-20 16:01:16 +02:00
|
|
|
$props['calendar-description'] = HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-description',$displayname);
|
2010-03-07 00:06:43 +01:00
|
|
|
// supported components, currently only VEVENT
|
2011-10-20 16:01:16 +02:00
|
|
|
$props['supported-calendar-component-set'] = HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'supported-calendar-component-set',array(
|
2010-04-13 17:31:59 +02:00
|
|
|
HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'comp',array('name' => 'VCALENDAR')),
|
2010-03-07 00:06:43 +01:00
|
|
|
HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'comp',array('name' => 'VTODO')),
|
|
|
|
));
|
2011-10-20 15:35:01 +02:00
|
|
|
// supported reports
|
2011-10-20 16:01:16 +02:00
|
|
|
$props['supported-report-set'] = HTTP_WebDAV_Server::mkprop('supported-report-set',array(
|
2010-03-07 00:06:43 +01:00
|
|
|
HTTP_WebDAV_Server::mkprop('supported-report',array(
|
2011-10-20 16:01:16 +02:00
|
|
|
HTTP_WebDAV_Server::mkprop('report',array(
|
|
|
|
HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-query',''))),
|
2010-07-02 07:01:15 +02:00
|
|
|
HTTP_WebDAV_Server::mkprop('report',array(
|
|
|
|
HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-multiget','')))))));
|
2010-03-07 00:06:43 +01:00
|
|
|
|
2011-10-20 15:35:01 +02:00
|
|
|
// get timezone of calendar
|
|
|
|
if ($this->groupdav->prop_requested('calendar-timezone'))
|
|
|
|
{
|
|
|
|
$props['calendar-timezone'] = HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-timezone',
|
2011-10-20 16:01:16 +02:00
|
|
|
calendar_timezones::user_timezone($user));
|
2011-10-20 15:35:01 +02:00
|
|
|
}
|
2010-03-07 00:06:43 +01:00
|
|
|
return $props;
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
2008-11-03 10:36:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the handler and set the supported fields
|
|
|
|
*
|
|
|
|
* @return infolog_ical
|
|
|
|
*/
|
|
|
|
private function _get_handler()
|
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$handler = new infolog_ical();
|
2008-11-03 10:36:20 +01:00
|
|
|
$handler->setSupportedFields('GroupDAV',$this->agent);
|
|
|
|
|
|
|
|
return $handler;
|
|
|
|
}
|
2012-02-04 02:24:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return appliction specific settings
|
|
|
|
*
|
|
|
|
* return array of array with settings
|
|
|
|
*/
|
|
|
|
static function get_settings()
|
|
|
|
{
|
|
|
|
translation::add_app('infolog');
|
|
|
|
$infolog = new infolog_bo();
|
|
|
|
|
|
|
|
if (!($types = $infolog->enums['type']))
|
|
|
|
{
|
|
|
|
$types = array(
|
|
|
|
'task' => 'Tasks',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$settings = array();
|
|
|
|
$settings['infolog-types'] = array(
|
|
|
|
'type' => 'multiselect',
|
|
|
|
'label' => 'InfoLog types to sync',
|
|
|
|
'name' => 'infolog-types',
|
|
|
|
'help' => 'Which InfoLog types should be synced with the device, default only tasks.',
|
|
|
|
'values' => $types,
|
|
|
|
'default' => 'task',
|
|
|
|
'xmlrpc' => True,
|
|
|
|
'admin' => False,
|
|
|
|
);
|
|
|
|
return $settings;
|
|
|
|
}
|
|
|
|
}
|