2008-05-17 20:03:33 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare: GroupDAV access: infolog handler
|
|
|
|
*
|
|
|
|
* @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>
|
2009-10-16 10:36:28 +02:00
|
|
|
* @copyright (c) 2007-9 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2008-05-17 20:03:33 +02:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* eGroupWare: GroupDAV access: infolog handler
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param string $app 'calendar', 'addressbook' or 'infolog'
|
|
|
|
* @param int $debug=null debug-level to set
|
|
|
|
* @param string $base_uri=null base url of handler
|
|
|
|
*/
|
|
|
|
function __construct($app,$debug=null,$base_uri=null)
|
|
|
|
{
|
|
|
|
parent::__construct($app,$debug,$base_uri);
|
2009-10-16 10:36:28 +02:00
|
|
|
|
2009-06-08 18:21:14 +02:00
|
|
|
$this->bo = new infolog_bo();
|
2008-05-17 20:03:33 +02:00
|
|
|
}
|
|
|
|
|
2008-11-18 07:11:12 +01:00
|
|
|
const PATH_ATTRIBUTE = 'info_id';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the path for an event
|
|
|
|
*
|
|
|
|
* @param array|int $info
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
static function get_path($info)
|
|
|
|
{
|
|
|
|
if (is_numeric($info) && self::PATH_ATTRIBUTE == 'info_id')
|
|
|
|
{
|
|
|
|
$name = $info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!is_array($info)) $info = $this->bo->read($info);
|
|
|
|
$name = $info[self::PATH_ATTRIBUTE];
|
|
|
|
}
|
2008-11-21 08:35:47 +01:00
|
|
|
return '/infolog/'.$name.'.ics';
|
2008-11-18 07:11:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-17 20:03:33 +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')
|
|
|
|
*/
|
2008-08-04 21:08:09 +02:00
|
|
|
function propfind($path,$options,&$files,$user,$id='')
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2009-10-16 10:36:28 +02:00
|
|
|
$starttime = microtime(true);
|
|
|
|
|
2008-08-04 21:08:09 +02:00
|
|
|
// todo add a filter to limit how far back entries from the past get synced
|
|
|
|
$filter = array(
|
|
|
|
'info_type' => 'task',
|
|
|
|
);
|
|
|
|
if ($id) $filter['info_id'] = $id; // propfind on a single id
|
|
|
|
|
2008-05-17 20:03:33 +02:00
|
|
|
// ToDo: add parameter to only return id & etag
|
2009-10-16 10:36:28 +02:00
|
|
|
if (($tasks =& $this->bo->search($params=array(
|
2008-07-07 10:12:54 +02:00
|
|
|
'order' => 'info_datemodified',
|
|
|
|
'sort' => 'DESC',
|
|
|
|
'filter' => 'own', // filter my: entries user is responsible for,
|
|
|
|
// filter own: entries the user own or is responsible for
|
2008-08-04 21:08:09 +02:00
|
|
|
'col_filter' => $filter,
|
2008-07-07 10:12:54 +02:00
|
|
|
))))
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
2009-10-16 10:36:28 +02:00
|
|
|
foreach($tasks as &$task)
|
2008-05-17 20:03:33 +02:00
|
|
|
{
|
|
|
|
$files['files'][] = array(
|
2008-11-18 07:11:12 +01:00
|
|
|
'path' => self::get_path($task),
|
2008-05-17 20:03:33 +02:00
|
|
|
'props' => array(
|
|
|
|
HTTP_WebDAV_Server::mkprop('getetag',$this->get_etag($task)),
|
2008-11-03 10:36:20 +01:00
|
|
|
HTTP_WebDAV_Server::mkprop('getcontenttype',$this->agent != 'kde' ?
|
2008-08-04 21:08:09 +02:00
|
|
|
'text/calendar; charset=utf-8; component=VTODO' : 'text/calendar'), // Konqueror (3.5) dont understand it otherwise
|
|
|
|
// getlastmodified and getcontentlength are required by WebDAV and Cadaver eg. reports 404 Not found if not set
|
|
|
|
HTTP_WebDAV_Server::mkprop('getlastmodified', $task['info_datemodified']),
|
|
|
|
HTTP_WebDAV_Server::mkprop('getcontentlength',''),
|
2008-05-17 20:03:33 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2009-10-16 10:36:28 +02:00
|
|
|
if ($this->debug) error_log(__METHOD__."($path) took ".(microtime(true) - $starttime).' to return '.count($files['files']).' items');
|
2008-05-17 20:03:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle get 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 get(&$options,$id)
|
|
|
|
{
|
|
|
|
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();
|
2008-07-08 07:34:10 +02:00
|
|
|
$options['data'] = $handler->exportVTODO($id,'2.0',false,false); // keep UID the client set and no extra charset attributes
|
2008-05-17 20:03:33 +02:00
|
|
|
$options['mimetype'] = 'text/calendar; charset=utf-8';
|
|
|
|
header('Content-Encoding: identity');
|
|
|
|
header('ETag: '.$this->get_etag($task));
|
|
|
|
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
|
|
|
|
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
|
|
|
|
*/
|
|
|
|
function put(&$options,$id,$user=null)
|
|
|
|
{
|
|
|
|
$ok = $this->_common_get_put_delete('PUT',$options,$id);
|
|
|
|
if (!is_null($ok) && !is_array($ok))
|
|
|
|
{
|
|
|
|
return $ok;
|
|
|
|
}
|
2008-11-03 10:36:20 +01:00
|
|
|
$handler = $this->_get_handler();
|
2008-07-08 09:47:16 +02:00
|
|
|
if (!($info_id = $handler->importVTODO($options['content'],is_numeric($id) ? $id : -1)))
|
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
|
|
|
}
|
|
|
|
header('ETag: '.$this->get_etag($info_id));
|
|
|
|
if (is_null($ok) || $id != $info_id)
|
|
|
|
{
|
2008-11-18 07:11:12 +01:00
|
|
|
header('Location: '.$this->base_uri.self::get_path($info_id));
|
2008-05-17 20:03:33 +02:00
|
|
|
return '201 Created';
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
return $this->bo->delete($id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read an entry
|
|
|
|
*
|
|
|
|
* @param string/id $id
|
|
|
|
* @return array/boolean array with entry, false if no read rights, null if $id does not exist
|
|
|
|
*/
|
|
|
|
function read($id)
|
|
|
|
{
|
2010-02-04 13:08:03 +01:00
|
|
|
return $this->bo->read($id,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
|
|
|
|
* @param array/int $task task-array or id
|
|
|
|
* @return boolean null if entry does not exist, false if no access, true if access permitted
|
|
|
|
*/
|
|
|
|
function check_access($acl,$task)
|
|
|
|
{
|
|
|
|
return $this->bo->check_access($task,$acl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the etag for an infolog entry
|
|
|
|
*
|
|
|
|
* @param array/int $info array with infolog entry or info_id
|
|
|
|
* @return string/boolean string with etag or false
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return '"'.$info['info_id'].':'.$info['info_datemodified'].'"';
|
|
|
|
}
|
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;
|
|
|
|
}
|
2009-10-16 10:36:28 +02:00
|
|
|
}
|