3 * FusionForge Documentation Manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2010-2011, Franck Villaume - Capgemini
8 * Copyright 2011, Roland Mas
9 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
10 * Copyright 2012, Thorsten Glaser - tarent solutions GmbH
11 * Copyright 2012, Franck Villaume - TrivialDev
12 * http://fusionforge.org
14 * This file is part of FusionForge. FusionForge is free software;
15 * you can redistribute it and/or modify it under the terms of the
16 * GNU General Public License as published by the Free Software
17 * Foundation; either version 2 of the Licence, or (at your option)
20 * FusionForge is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 /* please do not add require here : use www/docman/index.php to add require */
31 /* global variables used */
32 global $g; //group object
33 global $group_id; // id of group
36 $doc_group = getIntFromRequest('doc_group');
37 $title = trim(getStringFromRequest('title'));
38 $description = getStringFromRequest('description');
39 $file_url = getStringFromRequest('file_url');
40 $uploaded_data = getUploadedFile('uploaded_data');
41 $manual_path = getStringFromRequest('manual_path');
42 $type = getStringFromRequest('type');
43 $name = getStringFromRequest('name');
44 $stateid = getIntFromRequest('stateid');
50 $baseurl = '/docman/?group_id='.$group_id;
51 $redirecturl = $baseurl.'&view=listfile&dirid='.$doc_group;
53 // plugin projects-hierarchy handler
54 $childgroup_id = getIntFromRequest('childgroup_id');
56 $redirecturl .= '&childgroup_id='.$childgroup_id;
57 if (!forge_check_perm('docman', $childgroup_id, 'submit')) {
58 $return_msg = _('Document Manager Action Denied.');
59 session_redirect($redirecturl.'&warning_msg='.urlencode($return_msg));
61 $g = group_get_object($childgroup_id);
64 if (!forge_check_perm('docman', $g->getID(), 'submit')) {
65 $return_msg = _('Document Manager Action Denied.');
66 session_redirect($redirecturl.'&warning_msg='.urlencode($return_msg));
70 session_redirect($baseurl.'&error_msg='.urlencode($error_msg));
74 //cannot add a doc unless an appropriate group is provided
75 $return_msg = _('No valid folder was selected.');
76 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
79 if (!$title || !$description || (!$uploaded_data && !$file_url && !$manual_path && (!$editor && !$name))) {
80 $missing_params = array();
82 $missing_params[] = 'title';
85 $missing_params[] = 'description';
87 exit_missing_param($_SERVER['HTTP_REFERER'], $missing_params, 'docman');
90 $d = new Document($g);
92 if (!$d || !is_object($d)) {
93 $return_msg= _('Error getting blank document.');
94 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
95 } elseif ($d->isError()) {
96 session_redirect($baseurl.'&error_msg='.urlencode($d->getErrorMessage()));
101 $filecontent = getStringFromRequest('details');
102 $uploaded_data_name = $name;
103 $sanitizer = new TextSanitizer();
104 $filecontent = $sanitizer->SanitizeHtml($filecontent);
105 if (strlen($filecontent) < 1) {
106 $return_msg = _('Error getting blank document.');
107 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
109 $data = tempnam("/tmp", "docman");
110 $fh = fopen($data, 'w');
111 fwrite($fh, $filecontent);
113 $uploaded_data_type = 'text/html';
118 $uploaded_data_name = $file_url;
119 $uploaded_data_type = 'URL';
122 case 'httpupload' : {
123 if (!is_uploaded_file($uploaded_data['tmp_name'])) {
124 $return_msg = _('Invalid file name.');
125 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
128 if (function_exists('finfo_open')) {
129 $finfo = finfo_open(FILEINFO_MIME_TYPE);
130 $uploaded_data_type = finfo_file($finfo, $uploaded_data['tmp_name']);
131 if( $uploaded_data_type === 'application/msword') {
132 $ext = pathinfo($uploaded_data['name'], PATHINFO_EXTENSION);
133 if ( $ext === 'ppt' ) {
134 $uploaded_data_type = 'application/vnd.ms-powerpoint';
135 } elseif ( $ext === 'xls' ) {
136 $uploaded_data_type = 'application/vnd.ms-excel';
140 $uploaded_data_type = $uploaded_data['type'];
142 if ($uploaded_data_type == 'application/octet-stream' && $uploaded_data_type != $uploaded_data['type']) {
143 $uploaded_data_type = $uploaded_data['type'];
145 $data = $uploaded_data['tmp_name'];
147 $uploaded_data_name = $uploaded_data['name'];
150 case 'manualupload' : {
151 if (!forge_get_config('use_manual_uploads')) {
152 $return_msg = _('Manual uploads disabled.');
153 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
156 $incoming = forge_get_config('groupdir_prefix')."/".$g->getUnixName()."/incoming";
157 $filename = $incoming.'/'.$manual_path;
159 if (!util_is_valid_filename($manual_path) || !is_file($filename)) {
160 $return_msg = _('Invalid file name.');
161 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
164 if (function_exists('finfo_open')) {
165 $finfo = finfo_open(FILEINFO_MIME_TYPE);
166 $uploaded_data_type = finfo_file($finfo, $filename);
168 $uploaded_data_type = 'application/binary';
172 $uploaded_data_name = $manual_path;
176 $return_msg = _('Unknown type submission.');
177 session_redirect($baseurl.'&error_msg='.urlencode($return_msg));
181 if (!$d->create($uploaded_data_name, $uploaded_data_type, $data, $doc_group, $title, $description, $stateid)) {
182 if (forge_check_perm('docman', $group_id, 'approve')) {
183 session_redirect($redirecturl.'&error_msg='.urlencode($d->getErrorMessage()));
185 session_redirect($baseurl.'&error_msg='.urlencode($d->getErrorMessage()));
188 if ($type == 'editor') {
189 //release the cookie for the document contents (should expire at the end of the session anyway)
190 setcookie("gforgecurrentdocdata", "", time() - 3600);
192 if (forge_check_perm('docman', $group_id, 'approve')) {
193 $return_msg = sprintf(_('Document %s submitted successfully.'), $d->getFilename());
194 session_redirect($redirecturl.'&feedback='.urlencode($return_msg));
196 $return_msg = sprintf(_('Document %s has been successfully uploaded and is waiting to be approved.'),$d->getFilename());
197 session_redirect($baseurl.'&feedback='.urlencode($return_msg));