3 * FusionForge Documentation Manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2010, Franck Villaume - Capgemini
9 * This file is part of FusionForge.
11 * FusionForge is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with FusionForge; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 require_once('../env.inc.php');
29 require_once $gfcommon.'include/pre.php';
30 require_once $gfcommon.'docman/Document.class.php';
31 require_once $gfcommon.'docman/DocumentFactory.class.php';
32 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
33 require_once $gfcommon.'docman/include/utils.php';
34 require_once $gfcommon.'docman/include/webdav.php';
36 session_require_perm ('project_read', $group_id) ;
38 $arr=explode('/',getStringFromServer('REQUEST_URI'));
42 if ($docid != 'backup' && $docid != 'webdav' ) {
43 $docname=urldecode($arr[5]);
45 $g =& group_get_object($group_id);
46 if (!$g || !is_object($g)) {
48 } elseif ($g->isError()) {
49 exit_error($g->getErrorMessage(),'docman');
52 $d = new Document($g,$docid);
53 if (!$d || !is_object($d)) {
54 exit_error(_('Document is not available.'),'docman');
55 } elseif ($d->isError()) {
56 exit_error($d->getErrorMessage(),'docman');
60 * If the served document has wrong relative links, then
61 * theses links may redirect to the same document with another
62 * name, this way a search engine may loop and stress the
65 * A workaround is to serve only the document if the given
68 if ($d->getFileName() != $docname) {
69 exit_error(_('No document to display - invalid or inactive document number'),'docman');
72 Header ('Content-disposition: filename="'.str_replace('"', '', $d->getFileName()).'"');
74 if (strstr($d->getFileType(),'app')) {
75 Header ("Content-type: application/binary");
77 Header ("Content-type: ".$d->getFileType());
80 echo $d->getFileData();
82 } else if ( $docid == 'backup' ) {
83 $g =& group_get_object($group_id);
84 if (!$g || !is_object($g)) {
86 } elseif ($g->isError()) {
87 exit_error($g->getErrorMessage(),'docman');
90 $df = new DocumentFactory($g);
92 exit_error($df->getErrorMessage(),'docman');
94 $dgf = new DocumentGroupFactory($g);
96 exit_error($dgf->getErrorMessage(),'docman');
97 $nested_groups = $dgf->getNested();
99 $d_arr =& $df->getDocuments();
100 if (!$d_arr || count($d_arr) <1)
101 $d_arr = &$df->getDocuments();
103 if ( $nested_groups != NULL ) {
104 $filename = 'docman-'.$g->getUnixName().'-'.$docid.'.zip';
105 $file = forge_get_config('data_path').'/'.$filename;
106 $zip = new ZipArchive;
107 if ( !$zip->open($file, ZIPARCHIVE::OVERWRITE)) {
108 exit_error(_('Unable to open zip archive for backup'),'docman');
111 docman_fill_zip($zip,$nested_groups,$df);
113 if ( !$zip->close()) {
114 exit_error(_('Unable to close zip archive for backup'),'docman');
117 Header ('Content-disposition: filename="'.$filename.'"');
118 Header ('Content-type: application/binary');
123 $warning_msg = _('No documents to backup.');
124 session_redirect('/docman/?group_id='.$group_id.'&view=admin&warning_msg='.urlencode($warning_msg));
126 } else if ( $docid == 'webdav' ) {
127 $_SERVER['REQUEST_URI'] = '';
128 $_SERVER['SCRIPT_NAME'] = '';
129 $server = new HTTP_WebDAV_Server_Docman;
130 $server->ServeRequest();
133 exit_error(_('No document to display - invalid or inactive document number.'),'docman');
138 // c-file-style: "bsd"