3 * FusionForge Documentation Manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2010, Franck Villaume
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
26 require_once('../env.inc.php');
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfcommon.'docman/Document.class.php';
29 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
30 require_once $gfwww.'docman/include/doc_utils.php';
31 require_once $gfwww.'docman/include/DocumentGroupHTML.class.php';
32 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
34 $group_id = getIntFromRequest('group_id');
38 $g = group_get_object($group_id);
39 if (!$g || !is_object($g)) {
41 } elseif ($g->isError()) {
42 exit_error('Error',$g->getErrorMessage());
45 session_require_perm ('docman', $group_id, 'submit') ;
47 $upload_dir = forge_get_config('ftp_upload_dir') . "/" . $g->getUnixName();
49 if (getStringFromRequest('submit')) {
50 $doc_group = getIntFromRequest('doc_group');
51 $title = getStringFromRequest('title');
52 $description = getStringFromRequest('description');
53 $file_url = getStringFromRequest('file_url');
54 //$ftp_filename = getStringFromRequest('ftp_filename');
55 $uploaded_data = getUploadedFile('uploaded_data');
56 $type = getStringFromRequest('type');
57 $name = getStringFromRequest('name');
59 if (!$doc_group || $doc_group == 100) {
60 //cannot add a doc unless an appropriate group is provided
61 exit_error(_('Error'),_('No valid Document Group was selected.'));
64 if (!$title || !$description || (!$uploaded_data && !$file_url && (!$editor && !$name ) )) {
68 $d = new Document($g, false, false,$gfcommon.'docman/engine');
69 if (!$d || !is_object($d)) {
70 exit_error(_('Error'),_('Error getting blank document.'));
71 } elseif ($d->isError()) {
72 exit_error(_('Error'),$d->getErrorMessage());
77 $data = getStringFromRequest('data');
78 $uploaded_data_name = $name;
79 $sanitizer = new TextSanitizer();
80 $data = $sanitizer->SanitizeHtml($data);
81 if (strlen($data)<1) {
82 exit_error(_('Error'),_('Error getting blank document.'));
84 $uploaded_data_type='text/html';
89 $uploaded_data_name=$file_url;
90 $uploaded_data_type='URL';
94 if (!is_uploaded_file($uploaded_data['tmp_name'])) {
95 exit_error(_('Error'),_('Invalid file name.'));
97 $data = fread(fopen($uploaded_data['tmp_name'], 'r'), $uploaded_data['size']);
99 $uploaded_data_name=$uploaded_data['name'];
100 $uploaded_data_type=$uploaded_data['type'];
105 $uploaded_data_name=$upload_dir.'/'.$ftp_filename;
106 $data = fread(fopen($uploaded_data_name, 'r'), filesize($uploaded_data_name));
111 if (!$d->create($uploaded_data_name,$uploaded_data_type,$data,$doc_group,$title,$description)) {
112 exit_error(_('Error'),$d->getErrorMessage());
114 if ($type == 'editor') {
115 //release the cookie for the document contents (should expire at the end of the session anyway)
116 setcookie ("gforgecurrentdocdata", "", time() - 3600);
118 // check if the user is docman's admin
119 if (forge_check_perm ('docman', $group_id, 'approve')) {
120 Header('Location: '.util_make_url('/docman/?group_id='.$group_id.'&feedback='._('Document submitted sucessfully')));
123 Header('Location: '.util_make_url('/docman/?group_id='.$group_id.'&feedback='._('Document submitted sucessfully : pending state (need validation)')));
130 //if (getStringFromRequest('Option')) {
131 //option was selected, proceed to show each one
132 $option_selected = getStringFromRequest('option_selected');
133 docman_header(_('Document Manager: Submit New Documentation'),_('Project: %1$s'));
134 echo'<p>'. _('<strong>Document Title</strong>: Refers to the relatively brief title of the document (e.g. How to use the download server)<br /><strong>Description:</strong> A brief description to be placed just under the title.') .'</p>
135 <form name="adddata" action="'. getStringFromServer('PHP_SELF').'?group_id='.$group_id.'" method="post" enctype="multipart/form-data">
136 <table border="0" width="75%">
139 <strong>'. _('Document Title').' :</strong>'. utils_requiredField(). sprintf(_('(at least %1$s characters)'), 5).'<br />
140 <input type="text" name="title" size="40" maxlength="255" />
146 <strong>'. _('Description') .' :</strong>'. utils_requiredField() . sprintf(_('(at least %1$s characters)'), 10).'<br />
147 <input type="text" name="description" size="50" maxlength="255" />
153 <strong>'. _('Upload File') .' :</strong>'. utils_requiredField() .'<br />
154 <input type="file" name="uploaded_data" size="30" /><br /><br />
155 <input type="hidden" name="type" value="httpupload">
159 switch ($option_selected) {
160 case 'httpupload' : {
164 <strong>'. _('Upload File') .' :</strong>'. utils_requiredField() .'<br />
165 <input type="file" name="uploaded_data" size="30" /><br /><br />
166 <input type="hidden" name="type" value="httpupload">
172 if (forge_get_config('use_ftp_uploads')) {
176 <strong>'.sprintf(_('You can use FTP to upload a new file at %1$s'), forge_get_config('ftp_upload_host')).'<br />';
177 echo _('Choose an FTP file instead of uploading:').'</strong>'. utils_requiredField() .'<br />';
178 $ftp_files_arr=array_merge($arr,ls($upload_dir,true));
179 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','');
180 echo '</td></tr><input type="hidden" name="type" value="ftpupload" />';
183 exit_error(_('You must enable ftp uploads first'));
191 <strong>'. _('Specify an outside URL where the file will be referenced').' :</strong>'. utils_requiredField() .'<br />
192 <input type="text" name="file_url" size="50" />
193 <input type="hidden" name="type" value="pasteurl">
199 echo '<SCRIPT LANGUAGE="JavaScript">';
200 echo 'function openEditor(group) {
201 newwin=window.open("doceditor.php?group_id=" + group, "dispwin", "width=850,height=550,scrollbars=yes,menubar=no");
208 echo "<strong>" . _('Name your file :') . '</strong>'.utils_requiredField().'<input type="text" name="name" ><br>';
209 echo '<a href="javascript:openEditor('.$group_id.');">'._('Edit').'</a>';
210 echo '<input type="hidden" name="data">';
211 echo '<input type="hidden" name="type" value="editor">';
222 <strong>'. _('Group that document belongs in').' :</strong><br />';
223 $dgf = new DocumentGroupFactory($g);
224 if ($dgf->isError()) {
225 exit_error('Error',$dgf->getErrorMessage());
227 $dgh = new DocumentGroupHTML($g);
228 if ($dgh->isError()) {
229 exit_error('Error',$dgh->getErrorMessage());
231 //display_groups_option($group_id);
232 $selected_doc_group=getIntFromRequest('selected_doc_group');
233 $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $selected_doc_group);
238 <input type="submit" name="submit" value="'. _('Submit Information').' " />
240 docman_footer(array());
243 docman_header(_('Document Manager: Submit New Documentation'),_('Project: %1$s'));
247 echo '<form name="select_opt" action="'. getStringFromServer('PHP_SELF').'?group_id='.$group_id.'" method="post">';
248 $vals['httpupload'] = _('Http Upload');
249 //$vals['ftpupload'] = _('Ftp Upload');
250 $vals['pasteurl'] = _('Url Paste');
251 $vals['editor'] = _('Create and edit the file manually');
252 echo _('First select the upload type you wish to use');
253 echo html_build_select_box_from_assoc($vals,'option_selected');
254 echo ' <input type="submit" value="'. _('Select Option') .'" name="Option">';
256 docman_footer(array());
263 // c-file-style: "bsd"