[Fusionforge-commits] r11100 - in trunk/src: common/docman common/docman/include common/include www/docman
Franck VILLAUME
nerville at libremir.placard.fr.eu.org
Thu Oct 21 09:50:06 CEST 2010
Author: nerville
Date: 2010-10-21 09:50:06 +0200 (Thu, 21 Oct 2010)
New Revision: 11100
Modified:
trunk/src/common/docman/Document.class.php
trunk/src/common/docman/include/webdav.php
trunk/src/common/include/Group.class.php
trunk/src/www/docman/view.php
Log:
docman webdav: implement GET
Modified: trunk/src/common/docman/Document.class.php
===================================================================
--- trunk/src/common/docman/Document.class.php 2010-10-21 06:16:07 UTC (rev 11099)
+++ trunk/src/common/docman/Document.class.php 2010-10-21 07:50:06 UTC (rev 11100)
@@ -149,8 +149,8 @@
db_begin();
$result = db_query_params('INSERT INTO doc_data (group_id,title,description,createdate,doc_group,
- stateid,filename,filetype,filesize,data,data_words,created_by)
- VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)',
+ stateid,filename,filetype,filesize,data_words,created_by)
+ VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)',
array($this->Group->getId(),
htmlspecialchars($title),
htmlspecialchars($description),
@@ -160,15 +160,33 @@
$filename,
$filetype,
$filesize,
- base64_encode($data),
$kwords,
- $user_id));
+ $user_id));
if (!$result) {
- $this->setError(_('Error Adding Document: ').db_error());
+ $this->setError(_('Error Adding Document: ').db_error().$result);
db_rollback();
return false;
}
+
$docid=db_insertid($result,'doc_data','docid');
+
+ switch ($this->Group->getStorageAPI()) {
+ case 'DB':
+ $result = db_query_params('UPDATE doc_data set data = $1 where docid = $2',
+ array(base64_encode($data),
+ $docid));
+ if (!$result) {
+ $this->setError(_('Error Adding Document: ').db_error().$result);
+ db_rollback();
+ return false;
+ }
+ break;
+ default:
+ $this->setError(_('Error Adding Document: No Storage API'));
+ db_rollback();
+ return false;
+ }
+
if (!$this->fetchData($docid)) {
db_rollback();
return false;
@@ -496,9 +514,8 @@
$kwords = '';
}
- $res = db_query_params ('UPDATE doc_data SET data=$1, filesize=$2, data_words=$3 WHERE group_id=$4 AND docid=$5',
- array (base64_encode($data),
- strlen($data),
+ $res = db_query_params ('UPDATE doc_data SET filesize=$1, data_words=$2 WHERE group_id=$3 AND docid=$4',
+ array (strlen($data),
$kwords,
$this->Group->getID(),
$this->getID())) ;
@@ -507,6 +524,23 @@
$this->setOnUpdateError(db_error());
return false;
}
+
+ switch ($this->Group->getStorageAPI()) {
+ case 'DB':
+ $res = db_query_params ('UPDATE doc_data SET data = $1 where group_id = $2 and docid = $3',
+ array(base64_encode($data),
+ $this->Group->getID(),
+ $this->getID()));
+
+ if (!$res || db_affected_rows($res) < 1) {
+ $this->setOnUpdateError(db_error());
+ return false;
+ }
+ break;
+ default:
+ $this->setOnUpdateError(_('No Storage API'));
+ return false;
+ }
}
$this->sendNotice(false);
@@ -550,6 +584,14 @@
return false;
}
+ switch ($this->Group->getStorageAPI()) {
+ case 'DB':
+ break;
+ default:
+ $this->setError(_('Error Deleting Document: No Storage API'));
+ db_rollback();
+ return false;
+ }
return true;
}
}
Modified: trunk/src/common/docman/include/webdav.php
===================================================================
--- trunk/src/common/docman/include/webdav.php 2010-10-21 06:16:07 UTC (rev 11099)
+++ trunk/src/common/docman/include/webdav.php 2010-10-21 07:50:06 UTC (rev 11100)
@@ -27,7 +27,7 @@
require_once "HTTP/WebDAV/Server.php";
-class HTTP_WebDAV_Server_Docman_DB extends HTTP_WebDAV_Server {
+class HTTP_WebDAV_Server_Docman extends HTTP_WebDAV_Server {
function GET(&$options) {
$arr_path = explode('/',$options['path']);
@@ -51,66 +51,104 @@
exit_error($g->getErrorMessage(),'docman');
if ( 4 < count($arr_path)) {
+ $subpath = '';
for ($i=5;$i<count($arr_path);$i++){
$subpath .= '/'.$arr_path[$i];
}
}
- if (!isset($subpath)) {
+ if (empty($subpath)) {
$subpath = '/';
}
- if ( $subpath == '/' ) {
- $doc_group_id = 0;
- $last_path = '/';
- } else {
- $last_path = strrchr($options['path'],'/');
- $doc_group_id = '70';
- }
+ $analysed_path = $this->analyse($subpath,$group_id);
- echo "<html><head><title>Index of ".htmlspecialchars($subpath)."</title></head>\n";
- echo "<h1>Index of ".htmlspecialchars($subpath)."</h1>\n";
- echo "<ul>";
- if ($this->isDir($last_path,$group_id,$doc_group_id)) {
+ if ($analysed_path['isdir']) {
+ echo "<html><head><title>Index of ".htmlspecialchars($subpath)."</title></head>\n";
+ echo "<body>\n";
+ echo "<h1>Index of ".htmlspecialchars($subpath)."</h1>\n";
+ echo "<ul>";
if ( '/' != $subpath ) {
- $back_url = substr($options['path'],0,strrpos($options['path'],strrchr($options['path'],'/')));
+ if ('/' == strrchr($options['path'],'/')) {
+ $lastpath = substr($options['path'],0,-1);
+ } else {
+ $lastpath = $options['path'];
+ }
+ $back_url = substr($options['path'],0,strrpos($options['path'],strrchr($lastpath,'/')));
echo '<a href="'.util_make_url($back_url).'">..</a>';
}
$res = db_query_params('select * from doc_groups where group_id = $1 and parent_doc_group = $2',
- array($group_id,$doc_group_id));
+ array($group_id,$analysed_path['doc_group']));
if (!$res) {
exit_error(_('webdav db error:').' '.db_error(),'docman');
}
+ if ( '/' != substr($subpath,-1)) {
+ $subpath .= '/';
+ }
while ($arr = db_fetch_array($res)) {
- if ( '/' != substr($subpath,-1)) {
- $subpath .= '/';
- }
echo '<li><a href="'.util_make_url('/docman/view.php/'.$group_id.'/webdav'.$subpath.$arr['groupname']).'">'.$arr['groupname'].'</a></li>';
}
- }
+ $res = db_query_params('select filename from doc_data where group_id = $1 and doc_group = $2',
+ array($group_id,$analysed_path['doc_group']));
+ if (!$res) {
+ exit_error(_('webdav db error:').' '.db_error(),'docman');
+ }
+ while ($arr = db_fetch_array($res)) {
+ echo '<li><a href="'.util_make_url('/docman/view.php/'.$group_id.'/webdav'.$subpath.$arr['filename']).'">'.$arr['filename'].'</a></li>';
+ }
+
+ echo "</ul>";
+ echo "</body></html>\n";
+ } else {
+ session_redirect('/docman/view.php/'.$group_id.'/'.$analysed_path['docid'].'/'.$analysed_path['filename']);
+ }
- echo "</ul>";
- echo "</html>\n";
exit;
}
- function isDir($string,$group_id,$doc_group_id = 0) {
- if ( $string == '/') {
- return true;
+ function analyse($path,$group_id) {
+ $analysed_path['isdir'] = true;
+ $analysed_path['doc_group'] = 0;
+ $analysed_path['docid'] = NULL;
+ if ( $path == '/') {
+ return $analysed_path;
}
- $string = substr($string,1);
- $res = db_query_params('select * from doc_groups where group_id = $1 and groupname = $2 and doc_group = $3',
- array($group_id,$string,$doc_group_id));
+
+ $path_arr = explode('/',$path);
+ for ($i = 1; $i < count($path_arr); $i++) {
+ if ($path_arr[$i] == '') {
+ continue;
+ }
+ $analysed_path = $this->whatIsIt($path_arr[$i],$group_id,$analysed_path);
+ }
+ return $analysed_path;
+ }
+
+ function whatIsIt($string,$group_id,$path_array) {
+ $return_path_array['isdir'] = false;
+ $res = db_query_params('select doc_group from doc_groups where group_id = $1 and groupname = $2 and parent_doc_group = $3',
+ array($group_id,$string,$path_array['doc_group']));
if (!$res) {
exit_error(_('webdav db error:').' '.db_error(),'docman');
}
while ($arr = db_fetch_array($res)) {
- return true;
+ $return_path_array['isdir'] = true;
+ $return_path_array['doc_group'] = $arr['doc_group'];
}
- return false;
+ if ($return_path_array['isdir']) {
+ return $return_path_array;
+ }
+
+ $res = db_query_params('select docid from doc_data where group_id = $1 and doc_group = $2 and filename = $3',
+ array($group_id,$path_array['doc_group'],$string));
+ while ($arr = db_fetch_array($res)) {
+ $return_path_array['docid'] = $arr['docid'];
+ $return_path_array['filename'] = $string;
+ }
+
+ return $return_path_array;
}
-
}
?>
Modified: trunk/src/common/include/Group.class.php
===================================================================
--- trunk/src/common/include/Group.class.php 2010-10-21 06:16:07 UTC (rev 11099)
+++ trunk/src/common/include/Group.class.php 2010-10-21 07:50:06 UTC (rev 11100)
@@ -2846,7 +2846,7 @@
}
function getStorageAPI() {
- return 1;
+ return 'DB';
}
}
Modified: trunk/src/www/docman/view.php
===================================================================
--- trunk/src/www/docman/view.php 2010-10-21 06:16:07 UTC (rev 11099)
+++ trunk/src/www/docman/view.php 2010-10-21 07:50:06 UTC (rev 11100)
@@ -119,15 +119,8 @@
}
} else if ( $docid == 'webdav' ) {
$_SERVER['SCRIPT_NAME'] = '';
- switch ($g->getStorageAPI()) {
- case '1':
- $server = new HTTP_WebDAV_Server_Docman_DB;
- break;
- default:
- exit_error(_('Webdav Storage API not implemented'),'docman');
- }
+ $server = new HTTP_WebDAV_Server_Docman;
$server->ServeRequest();
- exit;
} else {
exit_error(_('No document to display - invalid or inactive document number.'),'docman');
}
More information about the Fusionforge-commits
mailing list