18 require_once
"DAV/Class.ServerDav.php";
19 require_once
"System.php";
59 private $folder_max_item =
'ALL';
74 $this->db_res = pg_connect($this->db_webdav) or die(
"connection error");
76 parent::__construct();
89 foreach (apache_request_headers() as $key =>
$value) {
90 if (stristr($key,
"litmus")) {
91 error_log(
"Litmus test $value");
92 header(
"X-Litmus-reply: " .
$value);
98 parent::ServeRequest();
123 $fspath = $options[
"path"];
125 error_log(
" >PROPFIND depth:" . $options[
"depth"]);
128 $files[
"files"] = array();
131 if (!empty($options[
"depth"])) {
133 $options[
"path"] = $this->
_slashify($options[
"path"]);
136 $files[
"files"] = $freefiles;
139 $freefiles = $this->
readfolder($fspath,
true);
140 $files[
"files"] = $freefiles;
143 if (count($files[
"files"]) == 0)
return false;
145 error_log(
"PROPFIND OK");
151 include_once (
'FDL/Class.SearchDoc.php');
156 if (strtolower($fspath) ==
"/freedav") {
158 $info[
"props"] = array();
159 $info[
"props"][] = $this->
mkprop(
"resourcetype",
"collection");
160 $info[
"props"][] = $this->
mkprop(
"getcontenttype",
"httpd/unix-directory");
161 $info[
"props"][] = $this->
mkprop(
"displayname", $fspath);
162 $info[
"path"] = $fspath;
169 if ($fld->isAlive()) {
172 if (($fld->doctype ==
'D') || ($fld->doctype ==
'S')) $dpath = $this->
_slashify($fspath);
173 else $dpath = $fspath;
177 $s->dirid = $fld->initid;
179 $s->setObjectReturn();
181 if (
$s->count() > 0) {
182 while (
$doc =
$s->nextDoc()) {
183 $files = array_merge($files, $this->
docpropinfo(
$doc, $fspath,
false));
193 private static function logArray(
$a, $level = 0)
196 foreach (
$a as $k => $v) {
197 error_log(str_pad(
'.', $level * 3) .
"$k=>" . self::logArray($v, $level + 1));
200 error_log(str_pad(
'.', $level * 3) .
$a);
209 if (preg_match(
'/\/vid-([0-9]+)-([0-9]+)-[a-f0-9]+$/', $fspath, $reg)) {
218 }
else if (preg_match(
'/\/vid-([0-9]+)-([0-9]+)/', $fspath, $reg)) {
219 include_once(
'FDL/Lib.Vault.php');
224 $fsbase = basename($fspath);
225 if ($info->name == $fsbase) {
233 if (!
seems_utf8($fspath)) $fspath = utf8_encode($fspath);
234 $query = sprintf(
"SELECT value FROM dav.properties WHERE name='fid' and path = '%s'", pg_escape_string($fspath));
236 $res = pg_query($this->db_res,
$query);
237 while ($row = pg_fetch_assoc($res)) {
238 $fid = $row[
"value"];
241 pg_free_result($res);
249 $fileAttributes =
$doc->GetFileAttributes();
251 foreach ($fileAttributes as $fileAttribute) {
252 if ($fileAttribute->getOption(
'hideindav') ==
'yes') {
255 $result =
$doc->vault_properties($fileAttribute);
256 if (count($result) > 0 && is_array($result[0])) {
257 foreach ($result as $tmp) {
258 $state = intval($tmp[
"teng_state"]);
259 if ($state == 0 || $state == 1) {
272 $fspath = $this->base .
$path;
278 if (
$doc->id == $this->racine)
$doc->title =
'';
282 if ((
$doc->doctype ==
'D') || (
$doc->doctype ==
'S')) {
285 $info[
"props"] = array();
286 $info[
"props"][] = $this->
mkprop(
"resourcetype",
"collection");
287 $info[
"props"][] = $this->
mkprop(
"getcontenttype",
"httpd/unix-directory");
288 $info[
"props"][] = $this->
mkprop(
"displayname", strtr(
$doc->title,
"/",
"-"));
290 if ($firstlevel) $info[
"path"] =
$path;
291 else $info[
"path"] =
$path . strtr(
$doc->title,
"/",
"-");
293 $info[
"props"][] = $this->
mkprop(
"creationdate",
$doc->revdate);
294 $info[
"props"][] = $this->
mkprop(
"getlastmodified",
$doc->revdate);
297 $query = sprintf(
"SELECT ns, name, value FROM dav.properties WHERE path = '%s'", pg_escape_string(
$path));
298 $res = pg_query($this->db_res,
$query);
299 while ($row = pg_fetch_assoc($res)) {
300 $info[
"props"][] = $this->
mkprop($row[
"ns"], $row[
"name"], $row[
"value"]);
302 pg_free_result($res);
304 if (($firstlevel) || (
$doc->title !=
"")) {
306 $query = sprintf(
"delete from dav.properties where path= '%s' and name= 'fid'", pg_escape_string($this->
_unslashify($info[
"path"])));
308 pg_query($this->db_res,
$query);
309 $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($prop[
'ns']) , pg_escape_string(
$doc->initid));
311 pg_query($this->db_res,
$query);
316 $afiles = $this->GetFilesProperties(
$doc);
322 foreach ($afiles as $afile) {
324 $info[
"props"][] = $this->
mkprop(
"resourcetype",
"");
325 $aname = strtr($afile[
"name"],
"/",
"-");
327 if ((!$firstlevel) || ($aname == $bpath)) {
328 if ($firstlevel) $info[
"path"] = $dpath . $aname;
329 else $info[
"path"] =
$path . $aname;
333 $info[
"props"][] = $this->
mkprop(
"displayname", $aname);
334 $info[
"props"][] = $this->
mkprop(
"creationdate", filectime(
$filename));
335 $info[
"props"][] = $this->
mkprop(
"getlastmodified", filemtime(
$filename));
337 $info[
"props"][] = $this->
mkprop(
"getcontentlength", intval($afile[
"size"]));
339 $query = sprintf(
"SELECT ns, name, value FROM dav.properties WHERE path = '%s'", pg_escape_string($this->
_unslashify($info[
"path"])));
340 $res = pg_query($this->db_res,
$query);
341 while ($row = pg_fetch_assoc($res)) {
342 $info[
"props"][] = $this->
mkprop($row[
"ns"], $row[
"name"], $row[
"value"]);
344 pg_free_result($res);
349 $query = sprintf(
"delete from dav.properties where path= '%s' and name= 'fid'", pg_escape_string($this->
_unslashify($info[
"path"])));
350 pg_query($this->db_res,
$query);
351 $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($prop[
'ns']) , pg_escape_string(
$doc->initid));
352 pg_query($this->db_res,
$query);
380 if (preg_match(
"/\/vid-([^\/]*)\/(.*)/",
$path, $reg)) {
387 $info[
"props"] = array();
388 $info[
"props"][] = $this->
mkprop(
"resourcetype",
"collection");
389 $info[
"props"][] = $this->
mkprop(
"getcontenttype",
"httpd/unix-directory");
390 $info[
"props"][] = $this->
mkprop(
"displayname",
$path);
393 if ($firstlevel) $info[
"path"] =
$path;
394 else $info[
"path"] =
$path;
396 $info[
"props"][] = $this->
mkprop(
"creationdate", time());
397 $info[
"props"][] = $this->
mkprop(
"getlastmodified", time());
402 if ($withfile || $onlyfile) {
406 $afiles = $this->GetFilesProperties(
$doc);
412 foreach ($afiles as $afile) {
413 $aname = $afile[
"name"];
415 if ((!$onlyfile) || ($aname == $onlyfile)) {
418 $info[
"props"][] = $this->
mkprop(
"resourcetype",
"");
420 $info[
"props"][] = $this->
mkprop(
"displayname", $aname);
421 if ($firstlevel) $info[
"path"] = $dpath . $aname;
422 else $info[
"path"] =
$path . $aname;
424 $info[
"props"][] = $this->
mkprop(
"creationdate", filectime(
$filename));
425 $info[
"props"][] = $this->
mkprop(
"getlastmodified", filemtime(
$filename));
427 $info[
"props"][] = $this->
mkprop(
"getcontentlength", intval($afile[
"size"]));
431 $info[
"props"][] = $this->
mkprop(
"urn:schemas-microsoft-com:",
"Win32FileAttributes",
"00000001");
455 if (
$path ===
false) {
456 $path = getenv(
"PATH");
459 if (!strncmp(PHP_OS,
"WIN", 3)) {
465 $check_fn =
"file_exists";
471 $check_fn =
"is_executable";
474 foreach (explode(PATH_SEPARATOR,
$path) as
$dir) {
476 if (!file_exists($dir))
continue;
477 if (!is_dir($dir))
continue;
479 foreach ($exts as $ext) {
480 if ($check_fn(
"$dir/$name" . $ext))
return true;
494 return strtok(trim(shell_exec(sprintf(
"file -ib %s", escapeshellarg($fspath)))) ,
';');
495 if (@is_dir($fspath)) {
497 return "httpd/unix-directory";
498 }
else if (function_exists(
"mime_content_type")) {
500 $mime_type = mime_content_type($fspath);
504 $fp = popen(
"file -i '$fspath' 2>/dev/null",
"r");
511 if (!strncmp($reply,
"$fspath: ", strlen($fspath) + 2)) {
512 $reply = substr($reply, strlen($fspath) + 2);
514 if (preg_match(
'/^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*/', $reply, $matches)) {
515 $mime_type = $matches[0];
520 if (empty($mime_type)) {
534 switch (strtolower(strrchr($this->
mybasename($fspath) ,
"."))) {
536 $mime_type =
"text/html";
540 $mime_type =
"image/gif";
544 $mime_type =
"image/jpeg";
548 $mime_type =
"application/octet-stream";
563 error_log(
"---------->GET :" . $options[
"path"]);
564 include_once (
"FDL/Class.Doc.php");
566 $fspath = $this->base . $options[
"path"];
570 if (!
$doc->isAlive()) {
574 $afiles = $this->GetFilesProperties(
$doc);
576 $bpath = $options[
"path"];
577 if (!
seems_utf8($bpath)) $bpath = utf8_encode($bpath);
580 foreach ($afiles as $afile) {
581 $path = $afile[
"name"];
583 if (($vid == $afile[
"vid"]) || (
$path == $bpath)) {
584 error_log(
"GET FOUND:" .
$path .
'-' . $afile[
"path"]);
585 $fspath = $afile[
"path"];
590 if (!file_exists($fspath))
return false;
592 if (is_dir($fspath)) {
593 return $this->
GetDir($fspath, $options);
596 $options[
'mimetype'] = $this->
_mimetype($fspath);
601 $options[
'mtime'] = filemtime($fspath);
603 $options[
'size'] = filesize($fspath);
605 $options[
'stream'] = fopen($fspath,
"r");
607 header(
"Cache-control: no-cache");
608 header(
"Pragma: no-cache");
609 error_log(
"GET NO CACHE :" . $options[
"path"]);
624 echo
"<html><head><title>Index of " . htmlspecialchars($options[
'path']) .
"</title></head>\n";
626 echo
"<h1>Index of " . htmlspecialchars($options[
'path']) .
"</h1>\n";
628 echo
"<pre>WebDAV Server: HTML view is not implemented yet";
646 error_log(
"---------->PUT :" . $options[
"path"]);
647 include_once (
"FDL/Class.Doc.php");
650 if (!
seems_utf8($bpath)) $bpath = utf8_encode($bpath);
653 $stat =
"204 No Content";
654 $options[
"new"] =
false;
658 if (
$doc->doctype ==
'C') {
662 $doc->saveVaultFile($vid, $options[
"stream"]);
664 $afiles =
$doc->GetFileAttributes();
670 foreach ($afiles as $afile) {
671 if ($afile->getOption(
'hideindav') ==
'yes') {
675 if ($afile->inArray()) {
676 $tval =
$doc->getTValue($afile->id);
677 foreach ($tval as $k => $v) {
678 $fnames[$k] =
$doc->vault_filename($afile->id,
false, $k);
680 }
else $fnames[-1] =
$doc->vault_filename($afile->id);
681 foreach ($fnames as $k => $fname) {
683 if ($fname == $bpath) {
684 error_log(
"PUT FOUND:" .
$path .
'-' . $fname);
687 $doc->saveFile($afile->id, $options[
"stream"], $bpath, $k);
698 error_log(
"PUT " . $this->
type);
699 if ($this->
type ==
'freedav') {
700 error_log(
" CANCEL PUT :" . $options[
"path"]);
704 $options[
"new"] =
true;
705 $stat =
"201 Created";
706 if ($options[
"new"]) {
707 $dir = dirname($options[
"path"]);
710 $err = $fld->canModify();
715 if ($ndoc && $ndoc->fromid) {
716 $fa = $ndoc->GetFirstFileAttributes();
718 $ndoc->saveFile($fa->id, $options[
"stream"], $bpath);
721 $err = $ndoc->postModify();
722 $err = $ndoc->Modify();
723 error_log(
"PUT NEW FILE:" . $fa->id .
"-" . $ndoc->id);
725 $err = $fld->addFile($ndoc->initid);
726 error_log(
"PUT ADD IN FOLDER:" .
$err . $fld->id .
"UID:" . ($fld->userid));
730 $err =
"not allowed";
736 error_log(
" CREATE PUT OK :" . $options[
"path"]);
738 error_log(
" CREATE PUT KO : $err:" . $options[
"path"]);
753 error_log(
"---------- >MKCOL :" . $options[
"path"]);
755 include_once (
"FDL/Class.Doc.php");
757 if (!empty(
$_SERVER[
"CONTENT_LENGTH"])) {
758 return "415 Unsupported media type";
766 if ((!$nfld) || (!$nfld->fromid))
return "403 Forbidden : $err";
768 $nfld->setTitle($nreptitle);
771 $err = $fld->AddFile($nfld->initid);
772 error_log(
"NEW FLD:" . $nfld->initid);
791 return "403 Forbidden : $err";
794 return (
"201 Created");
804 error_log(
"---------- >DELETE :" . $options[
"path"]);
806 if ($this->
type ==
'freedav') {
807 $err = sprintf(
"unsupported DELETE method with freedav access.");
808 error_log(sprintf(
"---------- > %s",
$err));
809 return "403 Forbidden: $err";
812 include_once (
"FDL/Class.Doc.php");
816 if (!
$doc->isAlive()) {
817 return "404 Not found";
819 if (
$doc->doctype ==
'D') {
823 return "403 Forbidden:$err";
826 $query = sprintf(
"DELETE FROM dav.properties WHERE path LIKE '%s%%'", pg_escape_string($this->
_slashify($options[
"path"])));
827 pg_query($this->db_res,
$query);
830 if (
$doc->isLocked()) {
835 return "403 Forbidden:$err";
839 return "403 Forbidden:$err";
841 $query = sprintf(
"DELETE FROM dav.properties WHERE name='fid' and value='%s'", pg_escape_string(
$doc->initid));
843 pg_query($this->db_res,
$query);
846 return "204 No Content";
856 error_log(
"---------- >MOVE :" . $options[
"path"] .
"->" . $options[
"dest"]);
858 if (isset($options[
"dest_url"])) {
859 return "502 bad gateway";
862 include_once (
"FDL/Class.Doc.php");
864 $pdirsource = $this->
_unslashify(dirname($options[
"path"]));
867 $srcid = $this->
path2id($psource);
870 $err = $src->canEdit();
875 $destid = $this->
path2id($pdest);
877 $pdirdest = $this->
_unslashify(dirname($options[
"dest"]));
878 $dirdestid = $this->
path2id($pdirdest);
879 $ppdest = new_doc($this->
db_freedom, $dirdestid);
883 if (
$dest->doctype ==
'D') {
885 return "502 bad gateway";
888 error_log(
"DELETE FILE : $destid:" .
$dest->title);
892 $query = sprintf(
"DELETE FROM dav.properties WHERE name='fid' and value='%s'", pg_escape_string(
$dest->initid));
894 pg_query($this->db_res,
$query);
896 $err = $ppdest->addFile($srcid);
899 $psrcid = $this->
path2id($pdirsource);
901 if ($psrc->isAlive()) {
902 $err = $psrc->delFile($srcid);
905 $src->addComment(sprintf(_(
"Move file from %s to %s") , ($psrc->title) , ($ppdest->title)));
906 $query =
"DELETE FROM dav.properties WHERE path = '$psource'";
912 if ($bdest != $bsource) {
913 error_log(
" RENAMETO2 : $bdest");
914 $src->setTitle($bdest);
915 $err = $src->modify();
919 $query = sprintf(
"DELETE FROM dav.properties WHERE path = '%s'", pg_escape_string($psource));
921 pg_query($this->db_res,
$query);
923 error_log(
" RENAMETO : $bdest : $err");
927 if ($pdirsource != $pdirdest) {
929 $err = $ppdest->addFile($srcid);
933 $psrcid = $this->
path2id($pdirsource);
935 if ($psrc->isAlive()) {
936 $err = $psrc->delFile($srcid);
938 $src->addComment(sprintf(_(
"Move file from %s to %s") , ($psrc->title) , ($ppdest->title)));
939 $query = sprintf(
"DELETE FROM dav.properties WHERE path = '%s'", pg_escape_string($psource));
940 pg_query($this->db_res,
$query);
944 error_log(
"MOVE TO PARENT2 FOLDER : $dirdestid:" .
$err);
947 if ($bdest != $bsource) {
948 if ($src->doctype ==
'D') {
949 $src->setTitle($bdest);
952 $afiles = $this->GetFilesProperties($src);
953 foreach ($afiles as $afile) {
954 $path = $afile[
"name"];
955 error_log(
"RENAME SEARCH:" . $bsource .
'->' .
$path);
956 if ($path == $bsource) {
957 error_log(
"RENAME FOUND:" . $path .
'-' . $afile[
"path"]);
958 $fspath = $afile[
"path"];
961 $vf->Rename($afile[
"vid"], $bdest);
962 $src->addComment(sprintf(_(
"Rename file as %s") , $bdest));
964 $err = $src->modify();
968 $err = $src->modify();
972 $query = sprintf(
"DELETE FROM dav.properties WHERE path = '%s'", pg_escape_string($psource));
974 pg_query($this->db_res,
$query);
976 error_log(
" RENAMETO2 : $bdest : $err");
980 if ($src->doctype ==
'D') {
981 $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));
982 pg_query($this->db_res,
$query);
986 if (
$err ==
"")
return "201 Created";
988 error_log(
"DAV MOVE:$err");
989 return "403 Forbidden";
999 error_log(
"---------- >COPY :" . $options[
"path"] .
"->" . $options[
"dest"]);
1001 if (isset($options[
"dest_url"])) {
1002 return "502 bad gateway";
1005 include_once (
"FDL/Class.Doc.php");
1007 $pdirsource = $this->
_unslashify(dirname($options[
"path"]));
1010 $srcid = $this->
path2id($psource);
1012 error_log(
"SRC : $psource " . $srcid);
1016 $destid = $this->
path2id($pdest);
1018 $pdirdest = $this->
_unslashify(dirname($options[
"dest"]));
1019 $dirdestid = $this->
path2id($pdirdest);
1020 $ppdest = new_doc($this->
db_freedom, $dirdestid);
1024 if (
$dest->doctype ==
'D') {
1025 error_log(
"COPY FILE TO REPLACE FOLDER NOT POSSIBLE NORMALLY: $destid:" .
$dest->title);
1026 return "502 bad gateway";
1028 error_log(
"DELETE FILE : $destid:" .
$dest->title);
1034 $query = sprintf(
"DELETE FROM dav.properties WHERE name='fid' and value='%s'", pg_escape_string(
$dest->initid));
1036 pg_query($this->db_res,
$query);
1042 if ($src->doctype ==
"D") {
1044 return "501 not implemented";
1047 $copy = $src->copy();
1049 error_log(
"COPY :" . $copy->id);
1050 $afiles = $this->GetFilesProperties($copy);
1051 error_log(
"# FILE :" . count($afiles));
1052 $ff = $copy->GetFirstFileAttributes();
1054 $f = $copy->getValue($ff->id);
1055 error_log(
"RENAME SEARCH:" . $f);
1060 $vf->Rename($vid, $bdest);
1061 $copy->addComment(sprintf(_(
"Rename file as %s") , $bdest));
1062 $copy->postModify();
1063 $err = $copy->modify();
1066 $err = $ppdest->addFile($copy->id);
1071 error_log(
"MOVE TO PARENT FOLDER : $dirdestid:" .
$err);
1072 if ($bdest != $bsource) {
1073 $copy->setTitle($bdest);
1074 $err = $copy->modify();
1077 error_log(
" RENAMETO : $bdest : $err");
1082 if (
$err ==
"")
return "201 Created";
1084 error_log(
"DAV MOVE:$err");
1085 return "403 Forbidden";
1095 global $prefs, $tab;
1096 error_log(
"---------- >PROPPATCH :" . $options[
"path"]);
1100 $path = $options[
"path"];
1105 foreach ($options[
"props"] as $key => $prop) {
1106 if ($prop[
"ns"] ==
"DAV:") {
1107 $options[
"props"][$key][
'status'] =
"403 Forbidden";
1109 if (isset($prop[
"val"])) {
1111 $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']));
1112 pg_query($this->db_res,
$query);
1113 $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']));
1118 $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']));
1120 pg_query($this->db_res,
$query);
1134 error_log(
"---------- >LOCK :" . $options[
"path"]);
1135 include_once (
"FDL/Class.Doc.php");
1136 if (isset($options[
"update"])) {
1137 $query = sprintf(
"UPDATE dav.locks SET expires = %s where token='%s'", pg_escape_string((time() + 300)) , pg_escape_string($options[
"update"]));
1138 $res = pg_query($this->db_res,
$query);
1140 if (pg_affected_rows($res)) {
1141 $options[
"timeout"] = 300;
1142 error_log(
"LOCK Update succeed");
1145 error_log(print_r($options,
true));
1147 error_log(pg_last_error($this->db_res));
1148 error_log(
"LOCK Update failed");
1155 if (
$doc->isAffected()) {
1156 error_log(
"LOCK " .
$doc->title .
":" . $options[
'locktoken']);
1160 $options[
"timeout"] = time() + 300;
1161 $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"));
1163 $res = pg_query($this->db_res,
$query);
1164 if (pg_affected_rows($res)) {
1168 error_log(
"Cannot lock " .
$doc->title .
":$err");
1173 return "409 Conflict";
1184 error_log(
"---------- >UNLOCK :" . $options[
"path"]);
1185 include_once (
"FDL/Class.Doc.php");
1189 if (
$doc->isAffected()) {
1192 $query = sprintf(
"DELETE FROM dav.locks WHERE path = '%s' AND token = '%s'", pg_escape_string($options[
'path']) , pg_escape_string($options[
'token']));
1193 $res = pg_query($this->db_res,
$query);
1194 if (pg_affected_rows($res)) {
1195 error_log(
" unlock success :" .
$doc->title .
":" . $options[
'token']);
1196 return "204 No Content";
1200 return "204 No Content";
1202 error_log(
"Cannot unlock " .
$doc->title .
":[$err][" . $options[
'token']) .
"]";
1203 return "409 Conflict";
1215 $query = sprintf(
"SELECT owner, token, expires, exclusivelock FROM dav.locks WHERE path = '%s'", pg_escape_string(
$path));
1217 $res = pg_query($this->db_res,
$query);
1220 $row = pg_fetch_array($res);
1221 pg_free_result($res);
1226 "scope" => $row[
"exclusivelock"] ?
"exclusive" :
"shared",
1228 "owner" => $row[
'owner'],
1229 "token" => $row[
'token'],
1230 "expires" => $row[
'expires']
1236 include_once (
"FDL/Class.Doc.php");
1240 if (
$doc->isAffected()) {
1241 if (
$doc->isLocked(
true)) {
1244 "scope" =>
"exclusive",
1246 "owner" =>
$doc->locked,
1247 "token" =>
'opaquelocktoken:' . md5(
$doc->id) ,
1248 "expires" => time() + 3600
1250 error_log(
"LOCK " .
$doc->title);
1277 $query =
"INSERT INTO dav.sessions (session,vid,fid,owner,expires) values (
1278 '$sessid' , $vid , $docid , '$owner' , '$expire')";
1279 $query = sprintf(
"INSERT INTO dav.sessions (session, vid, fid, owner, expires) values ('%s', %s, %s, '%s', %s)", pg_escape_string($sessid) , pg_escape_string($vid) , pg_escape_string(
$docid) , pg_escape_string($owner) , pg_escape_string($expire));
1281 $res = pg_query($this->db_res,
$query);
1283 $err = pg_last_error($this->db_res);
1284 if (
$err !=
"") error_log(
"$err [$query]");
1286 if (pg_affected_rows($res)) {
1300 $query =
"select owner from dav.sessions where
1301 session = '$sessid' and
1304 $query = sprintf(
"select owner from dav.sessions where session = '%s' and vid = %s and fid = %s", pg_escape_string($sessid) , pg_escape_string($vid) , pg_escape_string(
$docid));
1306 $res = pg_query($this->db_res,
$query);
1307 $row = pg_fetch_assoc($res);
1308 $owner = $row[
"owner"];
1310 pg_free_result($res);
1327 $query =
"select session from dav.sessions where
1328 owner = '$owner' and
1331 $query = sprintf(
"select session from dav.sessions where owner = '%s' and vid = %s and fid = %s", pg_escape_string($owner) , pg_escape_string($vid) , pg_escape_string(
$docid));
1333 $res = pg_query($this->db_res,
$query);
1334 $row = pg_fetch_assoc($res);
1335 $sid = $row[
"session"];
1337 pg_free_result($res);
1344 $r = strrpos($p,
"/");
1345 return (
$r !==
false) ? substr($p,
$r + 1) : $p;
1350 $fid = intval($fid);
1351 $query = sprintf(
"delete from dav.properties where value='%s' and name= 'fid'", pg_escape_string($fid));
1353 pg_query($this->db_res,
$query);
1365 if (!is_numeric($limit) || $limit < 0) {
1368 $this->folder_max_item = $limit;
1369 return $this->folder_max_item;
1378 if (!is_numeric($this->folder_max_item) || $this->folder_max_item < 0) {
1381 return $this->folder_max_item;