3 * FusionForge Documentation Manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2010, Franck Villaume - Capgemini
8 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
9 * Copyright 2012, Franck Villaume - TrivialDev
10 * http://fusionforge.org
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 require_once('../env.inc.php');
31 require_once $gfcommon.'include/pre.php';
32 require_once $gfcommon.'docman/Document.class.php';
33 require_once $gfcommon.'docman/DocumentFactory.class.php';
34 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
35 require_once $gfcommon.'docman/include/utils.php';
37 $arr=explode('/',getStringFromServer('REQUEST_URI'));
41 $g = group_get_object($group_id);
42 if (!$g || !is_object($g)) {
44 } elseif ($g->isError()) {
45 exit_error($g->getErrorMessage(),'docman');
48 if ($docid != 'backup' && $docid != 'webdav' ) {
49 session_require_perm ('docman', $group_id, 'read') ;
50 $docname=urldecode($arr[5]);
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()).'"');
73 header("Content-type: ".$d->getFileType());
75 echo $d->getFileData();
77 } else if ( $docid == 'backup' ) {
78 session_require_perm ('docman', $group_id, 'admin') ;
80 $df = new DocumentFactory($g);
82 exit_error($df->getErrorMessage(),'docman');
84 $dgf = new DocumentGroupFactory($g);
86 exit_error($dgf->getErrorMessage(),'docman');
87 $nested_groups = $dgf->getNested();
89 $d_arr =& $df->getDocuments();
90 if (!$d_arr || count($d_arr) <1)
91 $d_arr = &$df->getDocuments();
93 if ( $nested_groups != NULL ) {
94 $filename = 'docman-'.$g->getUnixName().'-'.$docid.'.zip';
95 $file = forge_get_config('data_path').'/'.$filename;
96 $zip = new ZipArchive;
97 if ( !$zip->open($file, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)) {
98 exit_error(_('Unable to open zip archive for backup'),'docman');
101 if ( !docman_fill_zip($zip,$nested_groups,$df))
102 exit_error(_('Unable to fill zip archive for backup'),'docman');
105 exit_error(_('Unable to close zip archive for backup'),'docman');
107 Header ('Content-disposition: filename="'.$filename.'"');
108 Header ('Content-type: application/binary');
113 $warning_msg = _('No documents to backup.');
114 session_redirect('/docman/?group_id='.$group_id.'&view=admin&warning_msg='.urlencode($warning_msg));
116 } else if ( $docid == 'webdav' ) {
117 if (forge_get_config('use_webdav') && $g->useWebDav()) {
118 require_once $gfcommon.'docman/include/webdav.php';
119 $_SERVER['SCRIPT_NAME'] = '';
120 /* we need the group id for check authentification. */
121 $_SERVER["AUTH_TYPE"] = $group_id;
122 if (!isset($_SERVER['PHP_AUTH_USER'])) {
123 header('WWW-Authenticate: Basic realm="Webdav Access" (For anonymous access : click enter)');
124 header('HTTP/1.0 401 Unauthorized');
125 echo _('Webdav Access Canceled by user');
128 $server = new HTTP_WebDAV_Server_Docman;
129 $server->ServeRequest();
131 $warning_msg = _('No webdav interface enabled.');
132 session_redirect('/docman/?group_id='.$group_id.'&warning_msg='.urlencode($warning_msg));
135 exit_error(_('No document to display - invalid or inactive document number.'),'docman');
140 // c-file-style: "bsd"