diff --git a/phpgwapi/inc/class.groupdav.inc.php b/phpgwapi/inc/class.groupdav.inc.php
index 1e40741ce5..bddac89311 100644
--- a/phpgwapi/inc/class.groupdav.inc.php
+++ b/phpgwapi/inc/class.groupdav.inc.php
@@ -158,7 +158,7 @@ class groupdav extends HTTP_WebDAV_Server
$files['files'][] = array(
'path' => '/',
'props' => array(
- self::mkprop('displayname','eGroupWare'),
+ self::mkprop('displayname','EGroupware (Cal|Card|Group)DAV server'),
self::mkprop('resourcetype','collection'),
// adding the calendar extra property (calendar-home-set, etc.) here, allows apple iCal to "autodetect" the URL
self::mkprop(groupdav::CALDAV,'calendar-home-set',$this->base_uri.'/calendar/'),
@@ -291,7 +291,7 @@ class groupdav extends HTTP_WebDAV_Server
/**
* GET method handler
*
- * @param array parameter passing array
+ * @param array $options parameter passing array
* @return bool true on success
*/
function GET(&$options)
@@ -300,15 +300,165 @@ class groupdav extends HTTP_WebDAV_Server
if (!$this->_parse_path($options['path'],$id,$app,$user))
{
+ return $this->autoindex($options);
+
+ error_log(__METHOD__."(".array2string($options).") 404 Not Found");
return '404 Not Found';
}
if (($handler = self::app_handler($app)))
{
return $handler->get($options,$id);
}
+ error_log(__METHOD__."(".array2string($options).") 501 Not Implemented");
return '501 Not Implemented';
}
+ /**
+ * Display an automatic index (listing and properties) for a collection
+ *
+ * @param array $options parameter passing array, index "path" contains requested path
+ */
+ protected function autoindex($options)
+ {
+ $propfind_options = array(
+ 'path' => $options['path'],
+ 'depth' => 1,
+ );
+ $files = array();
+ if (($ret = $this->PROPFIND($propfind_options,$files)) !== true)
+ {
+ return $ret; // no collection
+ }
+ header('Content-type: text/html; charset='.$GLOBALS['egw']->translation->charset());
+ echo "\n
\n\t".'EGroupware (Cal|Card|Group)DAV server '.htmlspecialchars($options['path'])."\n";
+ echo "\t\n";
+ echo "\t\n";
+ echo "\n\n";
+
+ echo '(Cal|Card|Group)DAV ';
+ $path = '/groupdav.php';
+ foreach(explode('/',substr($options['path'],0,-1)) as $n => $name)
+ {
+ $path .= ($n != 1 ? '/' : '').$name;
+ echo html::a_href(htmlspecialchars($name.'/'),$path.($n ? '/' : ''));
+ }
+ echo "
\n";
+ $collection_props = self::props2array($files['files'][0]['props']);
+ echo ''.lang('Collection listing').': '.htmlspecialchars($collection_props['DAV:displayname'])."
\n";
+ //_debug_array($files['files']);
+
+ if (count($files['files']) <= 1)
+ {
+ echo ''.lang('Collection empty.')."
\n";
+ }
+ else
+ {
+ echo "\n\t".lang('Name')." | ".lang('Size')." | ".lang('Last modified')." | ".
+ lang('ETag')." | ".lang('Content type')." | ".lang('Resource type')." |
\n";
+
+ foreach($files['files'] as $n => $file)
+ {
+ if (!$n) continue; // own entry --> displaying properies later
+
+ $props = self::props2array($file['props']);
+ //echo $file['path']; _debug_array($props);
+ $class = $class == 'row_on' ? 'row_off' : 'row_on';
+ if (substr($file['path'],-1) == '/')
+ {
+ $name = basename(substr($file['path'],0,-1)).'/';
+ }
+ else
+ {
+ $name = basename($file['path']);
+ }
+ echo "\t\n\t\t".html::a_href(htmlspecialchars($name),'/groupdav.php'.$file['path'])." | \n";
+ echo "\t\t".$props['DAV:getcontentlength']." | \n";
+ echo "\t\t".(!empty($props['DAV:getlastmodified']) ? date('Y-m-d H:i:s',$props['DAV:getlastmodified']) : '')." | \n";
+ echo "\t\t".$props['DAV:getetag']." | \n";
+ echo "\t\t".htmlspecialchars($props['DAV:getcontenttype'])." | \n";
+ echo "\t\t".self::prop_value($props['DAV:resourcetype'])." | \n\t
\n";
+ }
+ echo "
\n";
+ }
+ echo ''.lang('Properties')."
\n";
+ echo "\n\t".lang('Namespace')." | ".lang('Name')." | ".lang('Value')." |
\n";
+ foreach($collection_props as $name => $value)
+ {
+ $class = $class == 'row_on' ? 'row_off' : 'row_on';
+ $ns = explode(':',$name);
+ $name = array_pop($ns);
+ $ns = implode(':',$ns);
+ echo "\t\n\t\t".htmlspecialchars($ns)." | ".htmlspecialchars($name)." | \n";
+ echo "\t\t".self::prop_value($value)." | \n\t
\n";
+ }
+ echo "
\n";
+
+ echo "\n\n";
+
+ common::egw_exit();
+ }
+
+ /**
+ * Format a property value for output
+ *
+ * @param mixed $value
+ * @return string
+ */
+ protected static function prop_value($value)
+ {
+ if (is_array($value))
+ {
+ if (isset($value[0]['ns']))
+ {
+ $value = self::props2array($value);
+ }
+ $value = htmlspecialchars(array2string($value));
+ }
+ elseif (preg_match('/^https?:\/\//',$value))
+ {
+ $value = html::a_href($value,$value);
+ }
+ else
+ {
+ $value = htmlspecialchars($value);
+ }
+ return $value;
+ }
+
+ /**
+ * Return numeric indexed array with values for keys 'ns', 'name' and 'val' as array 'ns:name' => 'val'
+ *
+ * @param array $props
+ * @return array
+ */
+ protected static function props2array(array $props)
+ {
+ $arr = array();
+ foreach($props as $prop)
+ {
+ switch($prop['ns'])
+ {
+ case 'DAV:';
+ $ns = 'DAV';
+ break;
+ case self::CALDAV:
+ $ns = 'CalDAV';
+ break;
+ case self::CARDDAV:
+ $ns = 'CardDAV';
+ break;
+ case self::GROUPDAV:
+ $ns = 'GroupDAV';
+ break;
+ default:
+ $ns = $prop['ns'];
+ }
+ $arr[$ns.':'.$prop['name']] = $prop['val'];
+ }
+ return $arr;
+ }
+
/**
* PUT method handler
*
@@ -480,14 +630,6 @@ class groupdav extends HTTP_WebDAV_Server
{
if ($this->debug) error_log(__METHOD__." called with ('$path') id=$id, app='$app', user=$user");
$parts = explode('/',$path);
- if ($this->debug) error_log(__METHOD__." called parts: ".print_r($parts,true));
- if (in_array($parts[1],array('principals','groups')))
- {
- $user = $GLOBALS['egw_info']['user']['account_id'];
- list(,$app,$id) = $parts;
- return true;
- }
-
list($id) = explode('.',array_pop($parts)); // remove evtl. .ics extension
$app = array_pop($parts);