Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.FdlDav.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * FREEDOM File system
8  *
9  * @author Anakeen
10  * @version $Id: Class.FdlDav.php,v 1.18 2008/12/01 16:29:18 eric Exp $
11  * @package FDL
12  */
13 /**
14  */
15 
16 require_once "DAV/Class.ServerDav.php";
17 /**
18  * Filesystem access using WebDAV
19  *
20  * @access public
21  */
23 {
24  /**
25  * Root directory for WebDAV access
26  *
27  * Defaults to webserver document root (set by ServeRequest)
28  *
29  * @access private
30  * @var string
31  */
32  var $base = "";
33 
34  public $db_freedom = "";
35  /**
36  * Type : 'webdav' or 'freedav'
37  *
38  * Default type is 'webdav'
39  */
40  public $type = 'webdav';
41  /**
42  * Root directory id for WebDAV access
43  *
44  * Defaut root is 9 (freedom root folder)
45  *
46  * @var int
47  */
48  public $racine = 9;
49  /**
50  * Maximum number of documents listed in a folder
51  *
52  * Default is 'ALL' (no limit)
53  *
54  * @var int
55  */
56  private $folder_max_item = 'ALL';
57  /**
58  * PgSQL database for property/locking information storage
59  *
60  * @access private
61  * @var string
62  */
63  public $db_webdav = "dbname=webdav user=anakeen";
64 
65  private $db_res; // db ressource
66  function __construct($dbaccess = "")
67  {
68  // establish connection to property/locking db
69  if ($dbaccess != "") $this->db_webdav = $dbaccess;
70 
71  $this->db_res = pg_connect($this->db_webdav) or die("connection error");
72 
73  parent::__construct();
74  }
75  /**
76  * Serve a webdav request
77  *
78  * @access public
79  * @param string
80  */
81  function ServeRequest()
82  {
83  // special treatment for litmus compliance test
84  // reply on its identifier header
85  // not needed for the test itself but eases debugging
86  foreach (apache_request_headers() as $key => $value) {
87  if (stristr($key, "litmus")) {
88  error_log("Litmus test $value");
89  header("X-Litmus-reply: " . $value);
90  }
91  }
92  $this->base = "";
93  // TODO throw on connection problems
94  // let the base class do all the work
95  parent::ServeRequest();
96  }
97  /**
98  * No authentication is needed here
99  *
100  * @access private
101  * @param string HTTP Authentication type (Basic, Digest, ...)
102  * @param string Username
103  * @param string Password
104  * @return bool true on successful authentication
105  */
106  function check_auth($type, $user, $pass)
107  {
108  return true;
109  }
110  /**
111  * PROPFIND method handler
112  *
113  * @param array $options general parameter passing array
114  * @param array $files return array for file properties
115  * @return bool true on success
116  */
117  function PROPFIND(&$options, &$files)
118  {
119  // get absolute fs path to requested resource
120  $fspath = $options["path"];
121 
122  error_log(" >PROPFIND depth:" . $options["depth"]);
123  //$this->logArray($options);
124  // prepare property array
125  $files["files"] = array();
126  // store information for the requested path itself
127  // information for contained resources requested?
128  if (!empty($options["depth"])) { // TODO check for is_dir() first?
129  // make sure path ends with '/'
130  $options["path"] = $this->_slashify($options["path"]);
131  // try to open directory
132  $freefiles = $this->readfolder($fspath);
133  $files["files"] = $freefiles;
134  } else {
135 
136  $freefiles = $this->readfolder($fspath, true);
137  $files["files"] = $freefiles;
138  }
139 
140  if (count($files["files"]) == 0) return false;
141  // ok, all done
142  error_log("PROPFIND OK");
143  return true;
144  }
145 
146  function readfolder($fspath, $onlyfld = false)
147  {
148  include_once ('FDL/Class.SearchDoc.php');
149 
150  $files = array();
151  $fldid = $this->path2id($fspath, $vid);
152 
153  if (strtolower($fspath) == "/freedav") {
154  $info = array();
155  $info["props"] = array();
156  $info["props"][] = $this->mkprop("resourcetype", "collection");
157  $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
158  $info["props"][] = $this->mkprop("displayname", $fspath);
159  $info["path"] = $fspath;
160  $files[] = $info;
161  } else {
162  if ($vid) {
163  $files = $this->vidpropinfo($fspath, $fldid, (!$onlyfld));
164  } else {
165  $fld = new_doc($this->db_freedom, $fldid, true);
166  if ($fld->isAlive()) {
167  // error_log("READFOLDER FIRST:".dirname($fspath)."/".$fld->title."ONLY:".intval($onlyfld));
168  //$files=$this->docpropinfo($fld,$this->_slashify(dirname($fspath)),true);
169  if (($fld->doctype == 'D') || ($fld->doctype == 'S')) $dpath = $this->_slashify($fspath);
170  else $dpath = $fspath;
171  $files = $this->docpropinfo($fld, $dpath, true);
172  if (!$onlyfld) {
173  $s = new SearchDoc($this->db_freedom);
174  $s->dirid = $fld->initid;
175  $s->slice = $this->getFolderMaxItem();
176  $s->setObjectReturn();
177  $s->search();
178  if ($s->count() > 0) {
179  while ($doc = $s->getNextDoc()) {
180  $files = array_merge($files, $this->docpropinfo($doc, $fspath, false));
181  }
182  }
183  }
184  }
185  }
186  }
187  return $files;
188  }
189 
190  private static function logArray($a, $level = 0)
191  {
192  if (is_array($a)) {
193  foreach ($a as $k => $v) {
194  error_log(str_pad('.', $level * 3) . "$k=>" . self::logArray($v, $level + 1));
195  }
196  } else {
197  error_log(str_pad('.', $level * 3) . $a);
198  }
199  }
200  function path2id($fspath, &$vid = null)
201  {
202  //error_log("FSPATH :".$fspath);
203  if ($fspath == '/') return $this->racine;
204 
205  $fspath = $this->_unslashify($fspath);
206  if (preg_match('/\/vid-([0-9]+)-([0-9]+)-[a-f0-9]+$/', $fspath, $reg)) {
207  // main directory
208  $fid = $reg[1];
209  $vid = $reg[2];
210  //error_log("FSPATH4 :.$fspath vid:[$vid]");
211  // $dvi=new DocVaultIndex($this->db_freedom);
212  //$fid=$dvi->getDocId($vid);
213  //error_log("FSPATH3 :.$fspath vid:[$vid]");
214 
215  } else if (preg_match('/\/vid-([0-9]+)-([0-9]+)/', $fspath, $reg)) {
216  include_once ('FDL/Lib.Vault.php');
217  $fid = $reg[1];
218  $tmpvid = $reg[2];
219  $info = vault_properties($tmpvid);
220 
221  $fsbase = basename($fspath);
222  if ($info->name == $fsbase) {
223  $vid = $tmpvid;
224  } else {
225  $fid = 0;
226  }
227  // error_log("FSPATH3 :.$fspath vid:[$vid]");
228 
229  } else {
230  if (!seems_utf8($fspath)) $fspath = utf8_encode($fspath);
231  $query = sprintf("SELECT value FROM dav.properties WHERE name='fid' and path = '%s'", pg_escape_string($fspath));
232 
233  $res = pg_query($this->db_res, $query);
234  while ($row = pg_fetch_assoc($res)) {
235  $fid = $row["value"];
236  }
237  // error_log("PATH2ID:".$query."[$fid]");
238  pg_free_result($res);
239  }
240  // error_log("FSPATH :".$fspath. "=>".$fid);
241  return $fid;
242  }
243  /**
244  * @param Doc $doc
245  *
246  * @return array
247  */
249  {
250  $fileAttributes = $doc->GetFileAttributes();
251  $tinfo = array();
252  foreach ($fileAttributes as $fileAttribute) {
253  if ($fileAttribute->getOption('hideindav') == 'yes') {
254  continue;
255  }
256  $result = $doc->vault_properties($fileAttribute);
257  if (count($result) > 0 && is_array($result[0])) {
258  foreach ($result as $tmp) {
259  $state = intval($tmp["teng_state"]);
260  if ($state == 0 || $state == 1) { // only valid files
261  $tinfo[] = $tmp;
262  }
263  }
264  }
265  }
266  return $tinfo;
267  }
268 
269  function docpropinfo(&$doc, $path, $firstlevel)
270  {
271  // error_log("docpropinfo $doc->initid $doc->id $path #$firstlevel");
272  // map URI path to filesystem path
273  $fspath = $this->base . $path;
274  // create result array
275  $tinfo = array();
276  $info = array();
277  // TODO remove slash append code when base clase is able to do it itself
278  //$info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path;
279  if ($doc->id == $this->racine) $doc->title = '';
280  // no special beautified displayname here ...
281  // creation and modification time
282  // type and size (caller already made sure that path exists)
283  if (($doc->doctype == 'D') || ($doc->doctype == 'S')) {
284  // directory (WebDAV collection)
285  $info = array();
286  $info["props"] = array();
287  $info["props"][] = $this->mkprop("resourcetype", "collection");
288  $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
289  $info["props"][] = $this->mkprop("displayname", strtr($doc->title, "/", "-"));
290  $path = $this->_slashify($path);
291  if ($firstlevel) $info["path"] = $path;
292  else $info["path"] = $path . strtr($doc->title, "/", "-");
293  //$info["path"] = $path;
294  $info["props"][] = $this->mkprop("creationdate", $doc->revdate);
295  $info["props"][] = $this->mkprop("getlastmodified", $doc->revdate);
296  //error_log("FOLDER:".$path.":".$doc->title);
297  // get additional properties from database
298  $query = sprintf("SELECT ns, name, value FROM dav.properties WHERE path = '%s'", pg_escape_string($path));
299  $res = pg_query($this->db_res, $query);
300  while ($row = pg_fetch_assoc($res)) {
301  $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
302  }
303  pg_free_result($res);
304  $tinfo[] = $info;
305  if (($firstlevel) || ($doc->title != "")) {
306  //$query = "REPLACE INTO dav.properties SET path = '".pg_escape_string($this->_unslashify($info["path"]))."', name = 'fid', ns= '$prop[ns]', value = '".$doc->initid."'";
307  $query = sprintf("delete from dav.properties where path= '%s' and name= 'fid'", pg_escape_string($this->_unslashify($info["path"])));
308 
309  pg_query($this->db_res, $query);
310  $ns = ''; // @TODO verify $prop['ns']
311  $query = sprintf("INSERT INTO dav.properties (path, name, ns, value) values ('%s', 'fid', '%s', '%s')", pg_escape_string($this->_unslashify($info["path"])) , pg_escape_string($ns) , pg_escape_string($doc->initid));
312 
313  pg_query($this->db_res, $query);
314  }
315  } else {
316  // simple document : search attached files
317  // $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
318  $afiles = $this->GetFilesProperties($doc);
319  //error_log("READFILES examine :".count($afiles).'-'.$doc->title.'-'.$doc->id);
320  $bpath = $this->mybasename($path);
321  $dpath = $this->_slashify(dirname($path));
322  //error_log("FILEDEBUG:".$path."-".$bpath."- $path #$firstlevel");
323  $path = $this->_slashify($path);
324  foreach ($afiles as $afile) {
325  $info = array();
326  $info["props"][] = $this->mkprop("resourcetype", "");
327  $aname = strtr($afile["name"], "/", "-");
328  //error_log("FILE TEST [$aname] [$bpath] #$firstlevel");
329  if ((!$firstlevel) || ($aname == $bpath)) {
330  if ($firstlevel) $info["path"] = $dpath . $aname;
331  else $info["path"] = $path . $aname;
332  $filename = $afile["path"];
333 
334  if (file_exists($filename)) {
335  $info["props"][] = $this->mkprop("displayname", $aname);
336  $info["props"][] = $this->mkprop("creationdate", filectime($filename));
337  $info["props"][] = $this->mkprop("getlastmodified", filemtime($filename));
338  $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($filename));
339  $info["props"][] = $this->mkprop("getcontentlength", intval($afile["size"]));
340  // get additional properties from database
341  $query = sprintf("SELECT ns, name, value FROM dav.properties WHERE path = '%s'", pg_escape_string($this->_unslashify($info["path"])));
342  $res = pg_query($this->db_res, $query);
343  while ($row = pg_fetch_assoc($res)) {
344  $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]);
345  }
346  pg_free_result($res);
347  // error_log("PROP:".print_r($info,true));
348  // error_log("PROP:".$query);
349  $tinfo[] = $info;
350  //$query = "REPLACE INTO properties SET path = '".pg_escape_string($this->_unslashify($info["path"]))."', name = 'fid', ns= '$prop[ns]', value = '".$doc->id."'";
351  $query = sprintf("delete from dav.properties where path= '%s' and name= 'fid'", pg_escape_string($this->_unslashify($info["path"])));
352  pg_query($this->db_res, $query);
353  $ns = ''; // @TODO verify ns
354  $query = sprintf("INSERT INTO dav.properties (path, name, ns, value) values ('%s', 'fid', '%s', '%s')", pg_escape_string($this->_unslashify($info["path"])) , pg_escape_string($ns) , pg_escape_string($doc->initid));
355  pg_query($this->db_res, $query);
356  // error_log($query);
357  //error_log("FILE:".$afile["name"]."-".$afile["size"]."-".$path);
358 
359  } else {
360  error_log("FILE ERROR:" . $doc->title . "-" . $doc->id . "-" . $filename);
361  }
362  }
363  //error_log("PROP:".$query);
364 
365  }
366  }
367 
368  return $tinfo;
369  }
370  /**
371  * virtual path
372  */
373  function vidpropinfo($path, $docid, $withfile = false)
374  {
375  // map URI path to filesystem path
376  // create result array
377  $tinfo = array();
378  $info = array();
379  // TODO remove slash append code when base clase is able to do it itself
380  //$info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path;
381  // no special beautified displayname here ...
382  $onlyfile = false;
383  if (preg_match("/\/vid-([^\/]*)\/(.*)/", $path, $reg)) {
384  $onlyfile = $reg[2];
385  }
386  // creation and modification time
387  // directory (WebDAV collection)
388  if (!$onlyfile) {
389  $info = array();
390  $info["props"] = array();
391  $info["props"][] = $this->mkprop("resourcetype", "collection");
392  $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory");
393  $info["props"][] = $this->mkprop("displayname", $path);
394  // $info["props"][] = $this->mkprop("urn:schemas-microsoft-com:", "Win32FileAttributes", "00000001");
395  $path = $this->_slashify($path);
396  $info["path"] = $path;
397  //$info["path"] = $path;
398  $info["props"][] = $this->mkprop("creationdate", time());
399  $info["props"][] = $this->mkprop("getlastmodified", time());
400  //error_log("VIRTUAL FOLDER:".$path.":");
401 
402  }
403  $tinfo[] = $info;
404  if ($withfile || $onlyfile) {
405  // simple document : search attached files
406  $doc = new_doc($this->db_freedom, $docid, true);
407  // $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath));
408  $afiles = $this->GetFilesProperties($doc);
409  //error_log("VIDPROP examine :".count($afiles).'-'.$doc->title.'-'.$doc->id);
410  $bpath = $this->mybasename($path);
411  $dpath = $this->_slashify(dirname($path));
412  //error_log("FILEDEBUG:".$path."-".$bpath."-".$path);
413  $path = $this->_slashify($path);
414  foreach ($afiles as $afile) {
415  $aname = $afile["name"];
416  //error_log("SEARCH FILE:[$aname] [$onlyfile]");
417  if ((!$onlyfile) || ($aname == $onlyfile)) {
418  $info = array();
419  //error_log("FOUND FILE:".$aname);
420  $info["props"][] = $this->mkprop("resourcetype", "");
421 
422  $info["props"][] = $this->mkprop("displayname", $aname);
423  $info["path"] = $path . $aname;
424  $filename = $afile["path"];
425  $info["props"][] = $this->mkprop("creationdate", filectime($filename));
426  $info["props"][] = $this->mkprop("getlastmodified", filemtime($filename));
427  $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($filename));
428  $info["props"][] = $this->mkprop("getcontentlength", intval($afile["size"]));
429  $err = $doc->canEdit();
430  if ($err != "") {
431  // add read only attributes for windows
432  $info["props"][] = $this->mkprop("urn:schemas-microsoft-com:", "Win32FileAttributes", "00000001");
433  }
434  $tinfo[] = $info;
435  }
436  //error_log("PROP:".$query);
437 
438  }
439  }
440 
441  return $tinfo;
442  }
443  /**
444  * detect if a given program is found in the search PATH
445  *
446  * helper function used by _mimetype() to detect if the
447  * external 'file' utility is available
448  *
449  * @param string program name
450  * @param string optional search path, defaults to $PATH
451  * @return bool true if executable program found in path
452  */
453  function _can_execute($name, $path = false)
454  {
455  // path defaults to PATH from environment if not set
456  if ($path === false) {
457  $path = getenv("PATH");
458  }
459  // check method depends on operating system
460  if (!strncmp(PHP_OS, "WIN", 3)) {
461  // on Windows an appropriate COM or EXE file needs to exist
462  $exts = array(
463  ".exe",
464  ".com"
465  );
466  $check_fn = "file_exists";
467  } else {
468  // anywhere else we look for an executable file of that name
469  $exts = array(
470  ""
471  );
472  $check_fn = "is_executable";
473  }
474  // now check the directories in the path for the program
475  foreach (explode(PATH_SEPARATOR, $path) as $dir) {
476  // skip invalid path entries
477  if (!file_exists($dir)) continue;
478  if (!is_dir($dir)) continue;
479  // and now look for the file
480  foreach ($exts as $ext) {
481  if ($check_fn("$dir/$name" . $ext)) return true;
482  }
483  }
484 
485  return false;
486  }
487  /**
488  * try to detect the mime type of a file
489  *
490  * @param string file path
491  * @return string guessed mime type
492  */
493  function _mimetype($fspath)
494  {
495  return strtok(trim(shell_exec(sprintf("file -ib %s", escapeshellarg($fspath)))) , ';');
496  if (@is_dir($fspath)) {
497  // directories are easy
498  return "httpd/unix-directory";
499  } else if (function_exists("mime_content_type")) {
500  // use mime magic extension if available
501  $mime_type = mime_content_type($fspath);
502  } else if ($this->_can_execute("file")) {
503  // it looks like we have a 'file' command,
504  // lets see it it does have mime support
505  $fp = popen("file -i '$fspath' 2>/dev/null", "r");
506  $reply = fgets($fp);
507  pclose($fp);
508  // popen will not return an error if the binary was not found
509  // and find may not have mime support using "-i"
510  // so we test the format of the returned string
511  // the reply begins with the requested filename
512  if (!strncmp($reply, "$fspath: ", strlen($fspath) + 2)) {
513  $reply = substr($reply, strlen($fspath) + 2);
514  // followed by the mime type (maybe including options)
515  if (preg_match('/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) {
516  $mime_type = $matches[0];
517  }
518  }
519  }
520 
521  if (empty($mime_type)) {
522  // Fallback solution: try to guess the type by the file extension
523  // TODO: add more ...
524  // TODO: it has been suggested to delegate mimetype detection
525  // to apache but this has at least three issues:
526  // - works only with apache
527  // - needs file to be within the document tree
528  // - requires apache mod_magic
529  // TODO: can we use the registry for this on Windows?
530  // OTOH if the server is Windos the clients are likely to
531  // be Windows, too, and tend do ignore the Content-Type
532  // anyway (overriding it with information taken from
533  // the registry)
534  // TODO: have a seperate PEAR class for mimetype detection?
535  switch (strtolower(strrchr($this->mybasename($fspath) , "."))) {
536  case ".html":
537  $mime_type = "text/html";
538  break;
539 
540  case ".gif":
541  $mime_type = "image/gif";
542  break;
543 
544  case ".jpg":
545  $mime_type = "image/jpeg";
546  break;
547 
548  default:
549  $mime_type = "application/octet-stream";
550  break;
551  }
552  }
553 
554  return $mime_type;
555  }
556  /**
557  * GET method handler
558  *
559  * @param array parameter passing array
560  * @return bool true on success
561  */
562  function GET(&$options)
563  {
564  error_log("---------->GET :" . $options["path"]);
565  include_once ("FDL/Class.Doc.php");
566  // get absolute fs path to requested resource
567  $fspath = $this->base . $options["path"];
568 
569  $fldid = $this->path2id($options["path"], $vid);
570  $doc = new_doc($this->db_freedom, $fldid, true);
571  if (!$doc->isAlive()) {
572  $this->cleanDeleted($fldid);
573  return false;
574  }
575  $afiles = $this->GetFilesProperties($doc);
576 
577  $bpath = $options["path"];
578  if (!seems_utf8($bpath)) $bpath = utf8_encode($bpath);
579 
580  $bpath = $this->mybasename($bpath); // basename
581  foreach ($afiles as $afile) {
582  $path = $afile["name"];
583  //error_log("GET SEARCH:".$bpath.'->'.$path);
584  if (($vid == $afile["vid"]) || ($path == $bpath)) {
585  error_log("GET FOUND:" . $path . '-' . $afile["path"]);
586  $fspath = $afile["path"];
587  break;
588  }
589  }
590  // sanity check
591  if (!file_exists($fspath)) return false;
592  // is this a collection?
593  if (is_dir($fspath)) {
594  return $this->GetDir($fspath, $options);
595  }
596  // detect resource type
597  $options['mimetype'] = $this->_mimetype($fspath);
598  // detect modification time
599  // see rfc2518, section 13.7
600  // some clients seem to treat this as a reverse rule
601  // requiering a Last-Modified header if the getlastmodified header was set
602  $options['mtime'] = filemtime($fspath);
603  // detect resource size
604  $options['size'] = filesize($fspath);
605  // no need to check result here, it is handled by the base class
606  $options['stream'] = fopen($fspath, "r");
607 
608  header("Cache-control: no-cache");
609  header("Pragma: no-cache"); // HTTP 1.0
610  error_log("GET NO CACHE :" . $options["path"]);
611  return true;
612  }
613  /**
614  * GET method handler for directories
615  *
616  * This is a very simple mod_index lookalike.
617  * See RFC 2518, Section 8.4 on GET/HEAD for collections
618  *
619  * @param string directory path
620  * @return void function has to handle HTTP response itself
621  */
622  function GetDir($fspath, &$options)
623  {
624 
625  echo "<html><head><title>Index of " . htmlspecialchars($options['path']) . "</title></head>\n";
626 
627  echo "<h1>Index of " . htmlspecialchars($options['path']) . "</h1>\n";
628 
629  echo "<pre>WebDAV Server: HTML view is not implemented yet";
630 
631  echo "<hr>";
632 
633  echo "</pre>";
634 
635  echo "</html>\n";
636 
637  exit;
638  }
639  /**
640  * PUT method handler
641  *
642  * @param array parameter passing array
643  * @return bool true on success
644  */
645  function PUT(&$options)
646  {
647  error_log("---------->PUT :" . $options["path"]);
648  include_once ("FDL/Class.Doc.php");
649 
650  $bpath = $this->mybasename($options["path"]);
651  if (!seems_utf8($bpath)) $bpath = utf8_encode($bpath);
652  $fldid = $this->path2id($options["path"], $vid);
653  if ($fldid) {
654  $stat = "204 No Content";
655  $options["new"] = false;
656  $doc = new_doc($this->db_freedom, $fldid, true);
657  $err = $doc->canEdit();
658  if ($err == "") {
659  if ($doc->doctype == 'C') {
660  /*
661  * @var DocFam $doc
662  */
663  $doc->saveVaultFile($vid, $options["stream"]);
664  } else {
665  $afiles = $doc->GetFileAttributes();
666  //error_log("PUT SEARCH FILES:".count($afiles));
667 
668  /*
669  * @var NormalAttribute $afile
670  */
671  foreach ($afiles as $afile) {
672  if ($afile->getOption('hideindav') == 'yes') {
673  continue;
674  }
675  $fnames = array();
676  if ($afile->inArray()) {
677  $tval = $doc->getMultipleRawValues($afile->id);
678  foreach ($tval as $k => $v) {
679  $fnames[$k] = $doc->vault_filename($afile->id, false, $k);
680  }
681  } else $fnames[-1] = $doc->vault_filename($afile->id);
682  foreach ($fnames as $k => $fname) {
683  // error_log("PUT SEARCH:.$bpath $fname");
684  if ($fname == $bpath) {
685 
686  $doc->saveFile($afile->id, $options["stream"], $bpath, $k);
687  $doc->postStore();
688  $err = $doc->Modify();
689 
690  break;
691  }
692  }
693  }
694  }
695  }
696  } else {
697  error_log("PUT " . $this->type);
698  if ($this->type == 'freedav') {
699  error_log(" CANCEL PUT :" . $options["path"]);
700  return false; // no creation in freedav
701 
702  }
703  $options["new"] = true;
704  $stat = "201 Created";
705  if ($options["new"]) {
706  $dir = dirname($options["path"]);
707  $fldid = $this->path2id($dir);
708  $fld = new_doc($this->db_freedom, $fldid);
709  $err = $fld->canModify();
710  if ($err == "") {
711  //error_log("PUT NEW FILE IN:".$dir);
712  $ndoc = createDoc($this->db_freedom, "SIMPLEFILE");
713  if ((!$ndoc) || (!$ndoc->fromid)) $ndoc = createDoc($this->db_freedom, "FILE");
714  if ($ndoc && $ndoc->fromid) {
715  $fa = $ndoc->GetFirstFileAttributes();
716  $bpath = $bpath;
717  $ndoc->saveFile($fa->id, $options["stream"], $bpath);
718  // $ndoc->setTitle($bpath);
719  $err = $ndoc->Add();
720  $err = $ndoc->postStore();
721  $err = $ndoc->Modify();
722  error_log("PUT NEW FILE:" . $fa->id . "-" . $ndoc->id);
723  if ($err == "") {
724  $err = $fld->addFile($ndoc->initid);
725  error_log("PUT ADD IN FOLDER:" . $err . $fld->id . "UID:" . ($fld->userid));
726  $this->readfolder($dir);
727  }
728  } else {
729  $err = "not allowed";
730  }
731  }
732  }
733  }
734  if (!$err) {
735  error_log(" CREATE PUT OK :" . $options["path"]);
736  } else {
737  error_log(" CREATE PUT KO : $err:" . $options["path"]);
738  }
739  if ($err != "") $stat = false;
740 
741  return $stat;
742  }
743  /**
744  * MKCOL method handler
745  *
746  * @param array general parameter passing array
747  * @return bool true on success
748  */
749  function MKCOL($options)
750  {
751 
752  error_log("---------- >MKCOL :" . $options["path"]);
753  $err = '';
754  include_once ("FDL/Class.Doc.php");
755 
756  if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet
757  return "415 Unsupported media type";
758  }
759  $path = $this->_unslashify($options["path"]);
760  $fldid = $this->path2id(dirname($options["path"]));
761  if ($fldid) {
762  $fld = new_doc($this->db_freedom, $fldid);
763  $nfld = createDoc($this->db_freedom, "SIMPLEFOLDER");
764  if ((!$nfld) || (!$nfld->fromid)) $nfld = createDoc($this->db_freedom, "DIR");
765  if ((!$nfld) || (!$nfld->fromid)) return "403 Forbidden : $err";
766  $nreptitle = $this->mybasename($path);
767  $nfld->setTitle($nreptitle);
768  $err = $nfld->Add();
769  if ($err == "") {
770  $err = $fld->AddFile($nfld->initid);
771  error_log("NEW FLD:" . $nfld->initid);
772  $this->docpropinfo($nfld, $path, true);
773  }
774  }
775  /*
776  if (!file_exists($parent)) {
777  return "409 Conflict";
778  }
779 
780  if (!is_dir($parent)) {
781  $name = $this->mybasename($path); return "403 Forbidden";
782  }
783 
784  if ( file_exists($parent."/".$name) ) {
785  return "405 Method not allowed";
786  }
787  */
788 
789  if ($err != "") {
790  return "403 Forbidden : $err";
791  }
792 
793  return ("201 Created");
794  }
795  /**
796  * DELETE method handler
797  *
798  * @param array general parameter passing array
799  * @return bool true on success
800  */
801  function DELETE($options)
802  {
803  error_log("---------- >DELETE :" . $options["path"]);
804 
805  if ($this->type == 'freedav') {
806  $err = sprintf("unsupported DELETE method with freedav access.");
807  error_log(sprintf("---------- > %s", $err));
808  return "403 Forbidden: $err";
809  }
810 
811  include_once ("FDL/Class.Doc.php");
812  $fldid = $this->path2id($options["path"]);
813  $doc = new_doc($this->db_freedom, $fldid, true);
814 
815  if (!$doc->isAlive()) {
816  return "404 Not found";
817  }
818  if ($doc->doctype == 'D') {
819  // just rm the folder : is normally empty
820  $err = $doc->delete();
821  if ($err != "") {
822  return "403 Forbidden:$err";
823  }
824  if ($err == "") {
825  $query = sprintf("DELETE FROM dav.properties WHERE path LIKE '%s%%'", pg_escape_string($this->_slashify($options["path"])));
826  pg_query($this->db_res, $query);
827  }
828  } else {
829  if ($doc->isLocked()) {
830  $err = $doc->unlock();
831  }
832 
833  if ($err != "") {
834  return "403 Forbidden:$err";
835  }
836  $err = $doc->delete();
837  if ($err != "") {
838  return "403 Forbidden:$err";
839  }
840  $query = sprintf("DELETE FROM dav.properties WHERE name='fid' and value='%s'", pg_escape_string($doc->initid));
841  error_log($query);
842  pg_query($this->db_res, $query);
843  }
844 
845  return "204 No Content";
846  }
847  /**
848  * MOVE method handler
849  *
850  * @param array general parameter passing array
851  * @return bool true on success
852  */
853  function MOVE($options)
854  {
855  error_log("---------- >MOVE :" . $options["path"] . "->" . $options["dest"]);
856  // no copying to different WebDAV Servers yet
857  if (isset($options["dest_url"])) {
858  return "502 bad gateway";
859  }
860 
861  include_once ("FDL/Class.Doc.php");
862  $psource = $this->_unslashify($options["path"]);
863  $pdirsource = $this->_unslashify(dirname($options["path"]));
864  $bsource = $this->mybasename($psource);
865 
866  $srcid = $this->path2id($psource);
867  $src = new_doc($this->db_freedom, $srcid);
868  //error_log ("SRC : $psource ".$srcid );
869  $err = $src->canEdit();
870  if ($err == "") {
871 
872  $pdest = $this->_unslashify($options["dest"]);
873  $bdest = $this->mybasename($pdest);
874  $destid = $this->path2id($pdest);
875 
876  $pdirdest = $this->_unslashify(dirname($options["dest"]));
877  $dirdestid = $this->path2id($pdirdest);
878  $ppdest = new_doc($this->db_freedom, $dirdestid);
879 
880  if ($destid) {
881  $dest = new_doc($this->db_freedom, $destid);
882  if ($dest->doctype == 'D') {
883  //error_log ("MOVE TO FOLDER : $destid:".$dest->title);
884  return "502 bad gateway";
885  } else {
886 
887  error_log("DELETE FILE : $destid:" . $dest->title);
888  // delete file
889  $err = $dest->delete();
890  if ($err == "") {
891  $query = sprintf("DELETE FROM dav.properties WHERE name='fid' and value='%s'", pg_escape_string($dest->initid));
892  error_log($query);
893  pg_query($this->db_res, $query);
894  // move
895  $err = $ppdest->addFile($srcid);
896  if ($err == "") {
897  // delete ref from source
898  $psrcid = $this->path2id($pdirsource);
899  $psrc = new_doc($this->db_freedom, $psrcid);
900  if ($psrc->isAlive()) {
901  $err = $psrc->delFile($srcid);
902  if ($err == "") {
903 
904  $src->addHistoryEntry(sprintf(_("Move file from %s to %s") , ($psrc->title) , ($ppdest->title)));
905  $query = "DELETE FROM dav.properties WHERE path = '$psource'";
906  }
907  }
908  }
909  }
910 
911  if ($bdest != $bsource) {
912  error_log(" RENAMETO2 : $bdest");
913  $src->setTitle($bdest);
914  $err = $src->modify();
915  $this->docpropinfo($src, $pdest, true);
916  if ($err == "") {
917 
918  $query = sprintf("DELETE FROM dav.properties WHERE path = '%s'", pg_escape_string($psource));
919  error_log($query);
920  pg_query($this->db_res, $query);
921  }
922  error_log(" RENAMETO : $bdest : $err");
923  }
924  }
925  } else {
926  if ($pdirsource != $pdirdest) {
927  // move
928  $err = $ppdest->addFile($srcid);
929  if ($err == "") {
930  $this->docpropinfo($src, $pdest, true);
931  // delete ref from source
932  $psrcid = $this->path2id($pdirsource);
933  $psrc = new_doc($this->db_freedom, $psrcid);
934  if ($psrc->isAlive()) {
935  $err = $psrc->delFile($srcid);
936  if ($err == "") {
937  $src->addHistoryEntry(sprintf(_("Move file from %s to %s") , ($psrc->title) , ($ppdest->title)));
938  $query = sprintf("DELETE FROM dav.properties WHERE path = '%s'", pg_escape_string($psource));
939  pg_query($this->db_res, $query);
940  }
941  }
942  }
943  error_log("MOVE TO PARENT2 FOLDER : $dirdestid:" . $err);
944  }
945  if ($err == "") {
946  if ($bdest != $bsource) {
947  if ($src->doctype == 'D') {
948  $src->setTitle($bdest);
949  } else {
950 
951  $afiles = $this->GetFilesProperties($src);
952  foreach ($afiles as $afile) {
953  $path = $afile["name"];
954  error_log("RENAME SEARCH:" . $bsource . '->' . $path);
955  if ($path == $bsource) {
956  error_log("RENAME FOUND:" . $path . '-' . $afile["path"]);
957  $fspath = $afile["path"];
958 
959  $vf = newFreeVaultFile($this->db_freedom);
960  $vf->Rename($afile["vid"], $bdest);
961  $src->addHistoryEntry(sprintf(_("Rename file as %s") , $bdest));
962  $src->postStore();
963  $err = $src->modify();
964  }
965  }
966  }
967  $err = $src->modify();
968  $this->docpropinfo($src, $pdest, true);
969  if ($err == "") {
970 
971  $query = sprintf("DELETE FROM dav.properties WHERE path = '%s'", pg_escape_string($psource));
972  error_log($query);
973  pg_query($this->db_res, $query);
974  }
975  error_log(" RENAMETO2 : $bdest : $err");
976  }
977  }
978  }
979  if ($src->doctype == 'D') {
980  $query = sprintf("UPDATE dav.properties SET path = REPLACE(path, '%s', '%s') WHERE path LIKE '%s%%'", pg_escape_string($psource) , pg_escape_string($pdest) , pg_escape_string($psource));
981  pg_query($this->db_res, $query);
982  error_log($query);
983  }
984 
985  if ($err == "") return "201 Created";
986  }
987  error_log("DAV MOVE:$err");
988  return "403 Forbidden";
989  }
990  /**
991  * COPY method handler
992  *
993  * @param array general parameter passing array
994  * @return bool true on success
995  */
996  function COPY($options)
997  {
998  error_log("---------- >COPY :" . $options["path"] . "->" . $options["dest"]);
999  // no copying to different WebDAV Servers yet
1000  if (isset($options["dest_url"])) {
1001  return "502 bad gateway";
1002  }
1003 
1004  include_once ("FDL/Class.Doc.php");
1005  $psource = $this->_unslashify($options["path"]);
1006  $pdirsource = $this->_unslashify(dirname($options["path"]));
1007  $bsource = $this->mybasename($psource);
1008 
1009  $srcid = $this->path2id($psource);
1010  $src = new_doc($this->db_freedom, $srcid);
1011  error_log("SRC : $psource " . $srcid);
1012 
1013  $pdest = $this->_unslashify($options["dest"]);
1014  $bdest = $this->mybasename($pdest);
1015  $destid = $this->path2id($pdest);
1016 
1017  $pdirdest = $this->_unslashify(dirname($options["dest"]));
1018  $dirdestid = $this->path2id($pdirdest);
1019  $ppdest = new_doc($this->db_freedom, $dirdestid);
1020 
1021  if ($destid) {
1022  $dest = new_doc($this->db_freedom, $destid);
1023  if ($dest->doctype == 'D') {
1024  error_log("COPY FILE TO REPLACE FOLDER NOT POSSIBLE NORMALLY: $destid:" . $dest->title);
1025  return "502 bad gateway";
1026  } else {
1027  error_log("DELETE FILE : $destid:" . $dest->title);
1028  // delete file
1029  $err = $dest->delete();
1030 
1031  if ($err == "") {
1032 
1033  $query = sprintf("DELETE FROM dav.properties WHERE name='fid' and value='%s'", pg_escape_string($dest->initid));
1034  error_log($query);
1035  pg_query($this->db_res, $query);
1036  }
1037  }
1038  }
1039  if ($err == "") {
1040  // copy
1041  if ($src->doctype == "D") {
1042  // copy of directory
1043  return "501 not implemented";
1044  } else {
1045 
1046  $copy = $src->duplicate();
1047 
1048  error_log("COPY :" . $copy->id);
1049  $afiles = $this->GetFilesProperties($copy);
1050  error_log("# FILE :" . count($afiles));
1051  $ff = $copy->GetFirstFileAttributes();
1052 
1053  $f = $copy->getRawValue($ff->id);
1054  error_log("RENAME SEARCH:" . $f);
1055  if (preg_match(PREGEXPFILE, $f, $reg)) {
1056  $vf = newFreeVaultFile($this->db_freedom);
1057  $vid = $reg[2];
1058 
1059  $vf->Rename($vid, $bdest);
1060  $copy->addHistoryEntry(sprintf(_("Rename file as %s") , $bdest));
1061  $copy->postStore();
1062  $err = $copy->modify();
1063  }
1064 
1065  $err = $ppdest->addFile($copy->id);
1066  if ($err == "") {
1067  $this->docpropinfo($copy, $pdest, true);
1068  }
1069 
1070  error_log("MOVE TO PARENT FOLDER : $dirdestid:" . $err);
1071  if ($bdest != $bsource) {
1072  $copy->setTitle($bdest);
1073  $err = $copy->modify();
1074  $this->docpropinfo($copy, $pdest, true);
1075 
1076  error_log(" RENAMETO : $bdest : $err");
1077  }
1078  }
1079  }
1080 
1081  if ($err == "") return "201 Created";
1082 
1083  error_log("DAV MOVE:$err");
1084  return "403 Forbidden";
1085  }
1086  /**
1087  * PROPPATCH method handler
1088  *
1089  * @param array general parameter passing array
1090  * @return bool true on success
1091  */
1092  function PROPPATCH(&$options)
1093  {
1094  global $prefs, $tab;
1095  error_log("---------- >PROPPATCH :" . $options["path"]);
1096 
1097  $msg = "";
1098 
1099  $path = $options["path"];
1100 
1101  $dir = dirname($path) . "/";
1102  $base = $this->mybasename($path);
1103 
1104  foreach ($options["props"] as $key => $prop) {
1105  if ($prop["ns"] == "DAV:") {
1106  $options["props"][$key]['status'] = "403 Forbidden";
1107  } else {
1108  if (isset($prop["val"])) {
1109  //$query = "REPLACE INTO properties SET path = '$options[path]', name = '$prop[name]', ns= '$prop[ns]', value = '$prop[val]'";
1110  $query = sprintf("delete from dav.properties where path='%s' and name= '%s' and ns='%s'", pg_escape_string($prop['path']) , pg_escape_string($prop['name']) , pg_escape_string($prop['ns']));
1111  pg_query($this->db_res, $query);
1112  $query = sprintf("INSERT INTO dav.properties (path, name, ns, value) values ('%s', '%s', '%s', '%s')", pg_escape_string($prop['path']) , pg_escape_string($prop['name']) , pg_escape_string($prop['ns']) , pg_escape_string($prop['val']));
1113  // pg_query($this->db_res,$query);
1114  // $query = "REPLACE INTO properties SET path = '$options[path]', name = '$prop[name]', ns= '$prop[ns]', value = '$prop[val]'";
1115 
1116  } else {
1117  $query = sprintf("DELETE FROM dav.properties WHERE path = '%s' AND name = '%s' AND ns = '%s'", pg_escape_string($options['path']) , pg_escape_string($prop['name']) , pg_escape_string($prop['ns']));
1118  }
1119  pg_query($this->db_res, $query);
1120  }
1121  }
1122 
1123  return "";
1124  }
1125  /**
1126  * LOCK method handler
1127  *
1128  * @param array general parameter passing array
1129  * @return bool true on success
1130  */
1131  function LOCK(&$options)
1132  {
1133  error_log("---------- >LOCK :" . $options["path"]);
1134  include_once ("FDL/Class.Doc.php");
1135  if (isset($options["update"])) { // Lock Update
1136  $query = sprintf("UPDATE dav.locks SET expires = %s where token='%s'", pg_escape_string((time() + 300)) , pg_escape_string($options["update"]));
1137  $res = pg_query($this->db_res, $query);
1138 
1139  if (pg_affected_rows($res)) {
1140  $options["timeout"] = 300; // 5min hardcoded
1141  error_log("LOCK Update succeed");
1142  return true;
1143  } else {
1144  error_log(print_r($options, true));
1145  error_log($query);
1146  error_log(pg_last_error($this->db_res));
1147  error_log("LOCK Update failed");
1148  return false;
1149  }
1150  }
1151 
1152  $fldid = $this->path2id($options["path"], $vid);
1153  $doc = new_doc($this->db_freedom, $fldid, true);
1154  if ($doc->isAffected()) {
1155  error_log("LOCK " . $doc->title . ":" . $options['locktoken']);
1156 
1157  $err = $doc->lock(true);
1158  if ($err == "") {
1159  $options["timeout"] = time() + 300; // 5min. hardcoded
1160  $query = sprintf("INSERT INTO dav.locks (token,path,owner,expires,exclusivelock) values ('%s', '%s', '%s', '%s', %s)", pg_escape_string($options['locktoken']) , pg_escape_string($options['path']) , pg_escape_string($options['owner']) , pg_escape_string($options['timeout']) , ($options['scope'] === "exclusive" ? "1" : "0"));
1161 
1162  $res = pg_query($this->db_res, $query);
1163  if (pg_affected_rows($res)) {
1164  return "200 OK";
1165  }
1166  } else {
1167  error_log("Cannot lock " . $doc->title . ":$err");
1168  }
1169  } else {
1170  return true;
1171  }
1172  return "409 Conflict";
1173  }
1174  /**
1175  * UNLOCK method handler
1176  *
1177  * @param array general parameter passing array
1178  * @return bool true on success
1179  */
1180  function UNLOCK(&$options)
1181  {
1182 
1183  error_log("---------- >UNLOCK :" . $options["path"]);
1184  include_once ("FDL/Class.Doc.php");
1185  $fldid = $this->path2id($options["path"], $vid);
1186  $doc = new_doc($this->db_freedom, $fldid, true);
1187 
1188  if ($doc->isAffected()) {
1189  $err = $doc->unlock(true);
1190  if ($err == "") {
1191  $query = sprintf("DELETE FROM dav.locks WHERE path = '%s' AND token = '%s'", pg_escape_string($options['path']) , pg_escape_string($options['token']));
1192  $res = pg_query($this->db_res, $query);
1193  if (pg_affected_rows($res)) {
1194  error_log(" unlock success :" . $doc->title . ":" . $options['token']);
1195  return "204 No Content";
1196  }
1197  }
1198  } else {
1199  return "204 No Content";
1200  }
1201  error_log("Cannot unlock " . $doc->title . ":[$err][" . $options['token']) . "]";
1202  return "409 Conflict";
1203  }
1204  /**
1205  * checkLock() helper
1206  *
1207  * @param string resource path to check for locks
1208  * @return bool true on success
1209  */
1210  function checkLock($path)
1211  {
1212  $result = false;
1213  if (!seems_utf8($path)) $path = utf8_encode($path);
1214  $query = sprintf("SELECT owner, token, expires, exclusivelock FROM dav.locks WHERE path = '%s'", pg_escape_string($path));
1215 
1216  $res = pg_query($this->db_res, $query);
1217 
1218  if ($res) {
1219  $row = pg_fetch_array($res);
1220  pg_free_result($res);
1221 
1222  if ($row) {
1223  $result = array(
1224  "type" => "write",
1225  "scope" => $row["exclusivelock"] ? "exclusive" : "shared",
1226  "depth" => 0,
1227  "owner" => $row['owner'],
1228  "token" => $row['token'],
1229  "expires" => $row['expires']
1230  );
1231  }
1232  }
1233  if (!$result) {
1234 
1235  include_once ("FDL/Class.Doc.php");
1236  $fldid = $this->path2id($path, $vid);
1237  $doc = new_doc($this->db_freedom, $fldid);
1238 
1239  if ($doc->isAffected()) {
1240  if ($doc->isLocked(true)) {
1241  $result = array(
1242  "type" => "write",
1243  "scope" => "exclusive",
1244  "depth" => 0,
1245  "owner" => $doc->locked,
1246  "token" => 'opaquelocktoken:' . md5($doc->id) ,
1247  "expires" => time() + 3600
1248  );
1249  error_log("LOCK " . $doc->title);
1250  }
1251  }
1252  }
1253 
1254  return $result;
1255  }
1256  /**
1257  * create database tables for property and lock storage
1258  *
1259  * @param void
1260  * @return bool true on success
1261  */
1262  function create_database()
1263  {
1264  // TODO
1265  return false;
1266  }
1267  /**
1268  * create database tables for property and lock storage
1269  *
1270  * @param void
1271  * @return bool true on success
1272  */
1273  function addsession($sessid, $vid, $docid, $owner, $expire = 0)
1274  {
1275 
1276  $query = sprintf("INSERT INTO dav.sessions (session, vid, fid, owner, expires) VALUES (%s, %s, %s, %s, %s)", pg_escape_literal($sessid) , pg_escape_literal($vid) , pg_escape_literal($docid) , pg_escape_literal($owner) , pg_escape_literal($expire));
1277 
1278  $res = pg_query($this->db_res, $query);
1279 
1280  $err = pg_last_error($this->db_res);
1281  if ($err != "") error_log("$err [$query]");
1282 
1283  if (pg_affected_rows($res)) {
1284  return true;
1285  }
1286  return false;
1287  }
1288  /**
1289  * get login from session
1290  *
1291  * @param void
1292  * @return bool true on success
1293  */
1294  function getLogin($docid, $vid, $sessid)
1295  {
1296  $query = sprintf("SELECT owner FROM dav.sessions WHERE session = %s AND vid = %s AND fid = %s", pg_escape_literal($sessid) , pg_escape_literal($vid) , pg_escape_literal($docid));
1297  //error_log("getLogin $query");
1298  $res = pg_query($this->db_res, $query);
1299  $row = pg_fetch_assoc($res);
1300  $owner = $row["owner"];
1301 
1302  pg_free_result($res);
1303 
1304  return $owner;
1305  }
1306  /**
1307  * get session from login
1308  *
1309  * @param int $docid document identifier
1310  * @param int $vid vault identifier
1311  * @param string $owner user login
1312  * @return string
1313  */
1314  function getSession($docid, $vid, $owner)
1315  {
1316  $query = sprintf("SELECT session FROM dav.sessions WHERE owner = %s AND vid = %s AND fid = %s", pg_escape_literal($owner) , pg_escape_literal($vid) , pg_escape_literal($docid));
1317  //error_log("getSession $query");
1318  $res = pg_query($this->db_res, $query);
1319  $row = pg_fetch_assoc($res);
1320  $sid = $row["session"];
1321 
1322  pg_free_result($res);
1323 
1324  return $sid;
1325  }
1326  function mybasename($p)
1327  {
1328  //return basename($p);
1329  $r = strrpos($p, "/");
1330  return ($r !== false) ? substr($p, $r + 1) : $p;
1331  }
1332 
1333  function cleanDeleted($fid)
1334  {
1335  $fid = intval($fid);
1336  $query = sprintf("delete from dav.properties where value='%s' and name= 'fid'", pg_escape_string($fid));
1337 
1338  pg_query($this->db_res, $query);
1339  }
1340  /**
1341  * Set the maximum number of documents returned when listing
1342  * content of a folder
1343  *
1344  * @param int $limit limit value (value < 0 for no limit)
1345  *
1346  * @return int the current limit
1347  */
1348  function setFolderMaxItem($limit)
1349  {
1350  if (!is_numeric($limit) || $limit < 0) {
1351  $limit = 'ALL';
1352  }
1353  $this->folder_max_item = $limit;
1354  return $this->folder_max_item;
1355  }
1356  /**
1357  * Get the currently applied maximum number
1358  *
1359  * @return int the current limit
1360  */
1361  function getFolderMaxItem()
1362  {
1363  if (!is_numeric($this->folder_max_item) || $this->folder_max_item < 0) {
1364  return 'ALL';
1365  }
1366  return $this->folder_max_item;
1367  }
1368 }
addsession($sessid, $vid, $docid, $owner, $expire=0)
vidpropinfo($path, $docid, $withfile=false)
$dest
Definition: resizeimg.php:231
seems_utf8($Str)
Definition: Lib.Common.php:759
$s type
Definition: dav.php:73
vault_properties($idfile, $teng_name="")
Definition: Lib.Vault.php:114
newFreeVaultFile($dbaccess)
Definition: Lib.Util.php:17
print< H1 > Check Database< i > $dbaccess</i ></H1 > $a
Definition: checklist.php:45
$filename
getSession($docid, $vid, $owner)
const PREGEXPFILE
Definition: Class.Doc.php:54
if($famId) $s
$s db_freedom
Definition: dav.php:72
PROPFIND(&$options, &$files)
$docid
Definition: cleanFamily.php:13
GetDir($fspath, &$options)
check_auth($type, $user, $pass)
createDoc($dbaccess, $fromid, $control=true, $defaultvalues=true, $temporary=false)
_can_execute($name, $path=false)
switch($command) exit
Definition: checkVault.php:46
$dir
Definition: resizeimg.php:144
$vf
Definition: geticon.php:28
$dbaccess
Definition: checkVault.php:17
$info
Definition: geticon.php:30
if(($docid!==0)&&(!is_numeric($docid))) $query
if($file) if($subject==""&&$file) if($subject=="") $err
$sessid
Definition: pack.php:51
$value
getLogin($docid, $vid, $sessid)
readfolder($fspath, $onlyfld=false)
docpropinfo(&$doc, $path, $firstlevel)
path2id($fspath, &$vid=null)
← centre documentaire © anakeen