3 * FusionForge document manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2009, Roland Mas
8 * Copyright 2010, Franck Villaume
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published
14 * by the Free Software Foundation; either version 2 of the License,
15 * or (at your option) any later version.
17 * FusionForge is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with FusionForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 Ftp upload option is commented-out
33 require_once('../../env.inc.php');
34 require_once $gfcommon.'include/pre.php';
35 require_once $gfwww.'docman/include/doc_utils.php';
36 require_once $gfwww.'docman/include/DocumentGroupHTML.class.php';
37 require_once $gfcommon.'docman/DocumentFactory.class.php';
38 require_once $gfcommon.'docman/DocumentGroup.class.php';
39 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
40 require_once $gfcommon.'include/TextSanitizer.class.php'; // to make the HTML input by the user safe to store
42 $group_id = getIntFromRequest('group_id');
47 $g =& group_get_object($group_id);
48 if (!$g || !is_object($g) || $g->isError()) {
52 session_require_perm ('docman', $g->getID(), 'admin') ;
54 $editdoc = getStringFromRequest('editdoc');
55 $docid = getIntFromRequest('docid');
57 $upload_dir = forge_get_config('ftp_upload_dir') . "/" . $g->getUnixName();
61 // Submit the changes to the database
65 if (getStringFromRequest('submit')) {
67 $doc_group = getIntFromRequest('doc_group');
68 $title = getStringFromRequest('title');
69 $description = getStringFromRequest('description');
70 $data = getStringFromRequest('data');
71 $file_url = getStringFromRequest('file_url');
72 //$ftp_filename = getStringFromRequest('ftp_filename');
73 $uploaded_data = getUploadedFile('uploaded_data');
74 $stateid = getIntFromRequest('stateid');
75 $filetype = getStringFromRequest('filetype');
76 $editor = getStringFromRequest('editor');
78 $d= new Document($g,$docid,false,$sys_engine_path);
80 exit_error(_('Error'),$d->getErrorMessage());
83 $sanitizer = new TextSanitizer();
84 $data = $sanitizer->SanitizeHtml($data);
85 if (($editor) && ($d->getFileData()!=$data) && (!$uploaded_data['name'])) {
86 $filename = $d->getFileName();
88 $filetype = $d->getFileType();
90 } elseif ($uploaded_data['name']) {
91 if (!is_uploaded_file($uploaded_data['tmp_name'])) {
92 exit_error(_('Error'),sprintf(_('Invalid file attack attempt %1$s'), $uploaded_data['name']));
94 $data = fread(fopen($uploaded_data['tmp_name'], 'r'), $uploaded_data['size']);
95 $filename=$uploaded_data['name'];
96 $filetype=$uploaded_data['type'];
97 } elseif ($file_url) {
102 } elseif (forge_get_config('use_ftp_uploads') && $ftp_filename!=100) { //100==None
103 $filename=$upload_dir.'/'.$ftp_filename;
104 $data = fread(fopen($filename, 'r'), filesize($filename));
105 $filetype=$uploaded_data_type;
106 } elseif (forge_get_config('use_manual_uploads') && $uploaded_filename!=100 && util_is_valid_filename($uploaded_filename)) { //100==None
107 $incoming = forge_get_config('groupdir_prefix')."/".$g->getUnixName()."/incoming" ;
108 $filename = $incoming.'/'.$uploaded_filename;
109 $data = addslashes(fread(fopen($filename, 'r'), filesize($filename)));
110 $finfo = finfo_open (FILEINFO_MIME_TYPE) ;
111 $filetype = finfo_file($finfo, $filename) ;
112 finfo_close ($finfo) ;
115 $filename=$d->getFileName();
116 $filetype=$d->getFileType();
118 if (!$d->update($filename,$filetype,$data,$doc_group,$title,$description,$stateid)) {
119 exit_error('Error',$d->getErrorMessage());
121 $feedback = _('Updated successfully');
123 } elseif (getStringFromRequest('editgroup')) {
124 $doc_group = getIntFromRequest('doc_group');
125 $groupname = getStringFromRequest('groupname');
126 $parent_doc_group = getIntFromRequest('parent_doc_group');
128 $dg = new DocumentGroup($g,$doc_group);
129 if ($dg->isError()) {
130 exit_error('Error',$dg->getErrorMessage());
132 if (!$dg->update($groupname,$parent_doc_group)) {
133 exit_error('Error',$dg->getErrorMessage());
135 $feedback = _('Updated successfully');
137 } elseif (getStringFromRequest('deletegroup')) {
138 $doc_group = getIntFromRequest('doc_group');
140 $dg = new DocumentGroup($g,$doc_group);
141 if ($dg->isError()) {
142 exit_error('Error',$dg->getErrorMessage());
144 if (!$dg->delete($doc_group,$group_id)) {
145 exit_error('Error',$dg->getErrorMessage());
147 $feedback = _('Deleted successfully');
148 header('Location: index.php?group_id='.$group_id.'&feedback='.urlencode($feedback));
149 die(); // End parsing file and redirect
151 } elseif (getStringFromRequest('addgroup')) {
152 $groupname = getStringFromRequest('groupname');
153 $parent_doc_group = getIntFromRequest('parent_doc_group');
155 $dg = new DocumentGroup($g);
156 if ($dg->isError()) {
157 exit_error('Error',$dg->getErrorMessage());
159 if (!$dg->create($groupname, $parent_doc_group)) {
160 exit_error('Error',$dg->getErrorMessage());
162 $feedback = _('Created successfully');
164 } elseif (getStringFromRequest('deletedoc') && $docid && getStringFromRequest('sure') && getStringFromRequest('really_sure')) {
165 $d= new Document($g,$docid);
167 exit_error('Error',$d->getErrorMessage());
171 exit_error('Error',$d->getErrorMessage());
174 $feedback = _('Deleted');
175 header('Location: index.php?group_id='.$d->Group->getID().'&feedback='.urlencode($feedback));
176 die(); // End parsing file and redirect
183 // Edit a specific document
186 if ($editdoc && $docid) {
188 $d= new Document($g,$docid);
190 exit_error('Error',$d->getErrorMessage());
193 $dgf = new DocumentGroupFactory($g);
194 if ($dgf->isError()) {
195 exit_error('Error',$dgf->getErrorMessage());
198 $dgh = new DocumentGroupHTML($g);
199 if ($dgh->isError()) {
200 exit_error('Error',$dgh->getErrorMessage());
204 docman_header(_('Document Manager Administration'),_('Edit Docs'),'');
208 <?php echo _("<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.") ?>
211 <form name="editdata" action="index.php?editdoc=1&group_id=<?php echo $group_id; ?>" method="post" enctype="multipart/form-data">
217 <strong><?php echo _('Document Title') ?>: </strong><?php echo utils_requiredField(); ?> <?php printf(_('(at least %1$s characters)'), 5) ?><br />
218 <input type="text" name="title" size="40" maxlength="255" value="<?php echo $d->getName(); ?>" />
224 <strong><?php echo _('Description') ?></strong><?php echo utils_requiredField(); ?> <?php printf(_('(at least %1$s characters)'), 10) ?><br />
225 <input type="text" name="description" size="50" maxlength="255" value="<?php echo $d->getDescription(); ?>" />
231 <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?><br />
232 <?php if ($d->isURL()) {
233 echo '<a href="'.inputSpecialchars($d->getFileName()).'">[View File URL]</a>';
235 <a target="_blank" href="../view.php/<?php echo $group_id.'/'.$d->getID().'/'.urlencode($d->getFileName()) ?>"><?php echo $d->getName(); ?></a>
242 if ((!$d->isURL()) && ($d->isText())) {
246 //echo '<input type="hidden" name="editor" value="editor">';
247 echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
249 $GLOBALS['editor_was_set_up']=false;
251 $params['name'] = 'data';
252 $params['width'] = "800";
253 $params['height'] = "500";
254 $params['group'] = $group_id;
255 $params['body'] = $d->getFileData();
257 // we are displaying with textarea if the document is not html (fckeditor pre-parses the files as html and validates it/changes it)
258 plugin_hook("text_editor",$params);
260 if (!$GLOBALS['editor_was_set_up']) {
262 //if we don't have any plugin for text editor, display a simple textarea edit box
263 echo '<textarea name="data" rows="15" cols="100" wrap="soft">'. $d->getFileData() .'</textarea><br />';
264 echo '<input type="hidden" name="filetype" value="text/plain">';
267 echo '<input type="hidden" name="filetype" value="text/html">'; // the fckeditor creates html docs. this is for filetype
269 unset($GLOBALS['editor_was_set_up']);
279 <strong><?php echo _('Group that document belongs in') ?></strong><br />
282 //echo display_groups_option($group_id,$d->getDocGroupID());
283 $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $d->getDocGroupID());
290 <br /><strong><?php echo _('State') ?>:</strong><br />
293 doc_get_state_box($d->getStateID());
301 // if this is a text/html doc, display an edit box
302 if (strstr($d->getFileType(),'ext')) {
307 <strong>'._('Document Contents').'</strong><br />
308 <textarea cols="80" rows="20" name="data">'. htmlspecialchars( $d->getFileData() ).'</textarea>
316 <?php if ($d->isURL()) { ?>
317 <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?><br />
318 <input type="text" name="file_url" size="50" value="<?php echo $d->getFileName() ?>" />
320 <strong><?php echo _('OPTIONAL: Upload new file') ?></strong><br />
321 <input type="file" name="uploaded_data" size="30" /><br/><br />
323 if (forge_get_config('use_ftp_uploads')) {
325 printf(_('OR choose one form FTP %1$s.'), forge_get_config('ftp_upload_host'));
326 echo '</strong><br />' ;
327 $ftp_files_arr=array_merge($arr,ls($upload_dir,true));
328 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','');
332 /* if (forge_get_config('use_manual_uploads') && $u->getUnixStatus() == 'A') {
333 $incoming = forge_get_config('groupdir_prefix')."/".$g->getUnixName()."/incoming" ;
336 printf (_("OR choose one you alrealy uploaded (by SFTP or SCP) to the project's incoming directory ($1$s)."),
338 echo '</strong><br />' ;
339 $manual_files_arr=array_merge($arr,ls($incoming,true));
340 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'uploaded_filename','');
349 <input type="hidden" name="docid" value="<?php echo $d->getID(); ?>" />
350 <input type="submit" value="<?php echo _('Submit Edit') ?>" name="submit" /><br /><br />
351 <a href="index.php?deletedoc=1&docid=<?php echo $d->getID() ?>&group_id=<?php echo $d->Group->getID() ?>"><?php echo _('Permanently delete this document') ?></a>
356 docman_footer(array());
360 // Add a document group / view existing groups list
363 } elseif (getStringFromRequest('admingroup')) {
365 docman_header(_('Document Manager Administration'),_('Admin Document Groups'),'');
367 echo "<h1>"._('Admin Document Groups')."</h1>";
369 $dgf = new DocumentGroupFactory($g);
370 if ($dgf->isError()) {
371 exit_error('Error',$dgf->getErrorMessage());
374 $dgh = new DocumentGroupHTML($g);
375 if ($dgh->isError()) {
376 exit_error('Error',$dgh->getErrorMessage());
379 $nested_groups =& $dgf->getNested();
381 if (count($nested_groups) > 0) {
383 $title_arr[]=_('ID');
384 $title_arr[]=_('Group Name');
385 $title_arr[]=_('Delete Group');
387 echo $GLOBALS['HTML']->listTableTop ($title_arr);
390 $dgh->showTableNestedGroups($nested_groups, $row);
392 echo $GLOBALS['HTML']->listTableBottom();
395 echo "\n<h1>"._('No Document Groups defined')."</h1>";
398 <p><strong><?php echo _('Add a group') ?>:</strong></p>
399 <form name="admingroup" action="index.php?addgroup=1&group_id=<?php echo $group_id; ?>" method="post">
402 <th><?php echo _('New Group Name') ?>:</th>
403 <td><input type="text" name="groupname" /></td>
407 <th><?php echo _('Belongs to') ?>:</th>
409 <?php echo $dgh->showSelectNestedGroups($nested_groups, 'parent_doc_group') ?>
412 <td><input type="submit" value="<?php echo _('Add') ?>" name="submit" /></td>
416 <?php echo _('Group name will be used as a title, so it should be formatted correspondingly.') ?>
421 docman_footer(array());
425 // Edit a specific doc group
428 } elseif (getStringFromRequest('editgroup') && getIntFromRequest('doc_group')) {
429 $doc_group = getIntFromRequest('doc_group');
431 $dg = new DocumentGroup($g,$doc_group);
432 if ($dg->isError()) {
433 exit_error('Error',$dg->getErrorMessage());
436 $dgf = new DocumentGroupFactory($g);
437 if ($dgf->isError()) {
438 exit_error('Error',$dgf->getErrorMessage());
441 $dgh = new DocumentGroupHTML($g);
442 if ($dgh->isError()) {
443 exit_error('Error',$dgh->getErrorMessage());
446 docman_header(_('Document Manager Administration'),_('Edit Groups'),'');
448 <h1><?php echo _('Edit a group') ?></h1>
449 <form name="editgroup" action="index.php?editgroup=1&group_id=<?php echo $group_id; ?>" method="post">
450 <input type="hidden" name="doc_group" value="<?php echo $doc_group; ?>" />
453 <th><?php echo _('Group Name') ?>:</th>
454 <td><input type="text" name="groupname" value="<?php echo $dg->getName(); ?>" /></td>
458 <th><?php echo _('Belongs to') ?>:</th>
461 $dgh->showSelectNestedGroups($dgf->getNested(), "parent_doc_group", true, $dg->getParentId(), array($dg->getID()));
464 <td><input type="submit" value="<?php echo _('Edit') ?>" name="submit" /></td>
468 <?php echo _('Group name will be used as a title, so it should be formatted correspondingly.') ?>
473 docman_footer(array());
474 } else if (getStringFromRequest('deletegroup') && getIntFromRequest('doc_group')) {
475 $doc_group = getIntFromRequest('doc_group');
477 $dg = new DocumentGroup($g,$doc_group);
478 if ($dg->isError()) {
479 exit_error('Error',$dg->getErrorMessage());
482 docman_header(_('Document Manager Administration'),_('Delete Groups'),'');
485 <form action="<?php echo util_make_url('/docman/admin/index.php').'?deletegroup=1&doc_group='.$dg->getID().'&group_id='.$dg->Group->getID() ?>" method="post">
486 <input type="hidden" name="submit" value="1" /><br />
487 <img src="/images/ic/cfolder15.png" /><?php echo $dg->getName(); ?><br />
488 <?php echo _('You are about to permanently delete this document group and its content (documents and subgroups).'); ?>
489 <p><input type="submit" name="post_changes" value="<?php echo _('Delete') ?>" /></p>
492 docman_footer(array());
494 } else if (getStringFromRequest('deletedoc') && $docid) {
495 $d= new Document($g,$docid);
497 exit_error('Error',$d->getErrorMessage());
500 docman_header(_('Document Manager Administration'),_('Edit Groups'),'');
503 <form action="<?php echo util_make_url('/docman/admin/index.php').'?deletedoc=1&docid='.$d->getID().'&group_id='.$d->Group->getID() ?>" method="post">
504 <input type="hidden" name="submit" value="1" /><br />
505 <?php echo _('You are about to permanently delete this document.'); ?>
507 <input type="checkbox" name="sure" value="1"><?php echo _('I\'m Sure.') ?><br />
508 <input type="checkbox" name="really_sure" value="1"><?php echo _('I\'m Really Sure.') ?><br />
510 <input type="submit" name="post_changes" value="<?php echo _('Delete') ?>" /></p>
513 docman_footer(array());
517 // Display the main admin page
522 $df = new DocumentFactory($g);
523 if ($df->isError()) {
524 exit_error(_('Error'),$df->getErrorMessage());
527 $dgf = new DocumentGroupFactory($g);
528 if ($dgf->isError()) {
529 exit_error(_('Error'),$dgf->getErrorMessage());
533 $df->setStateID('ALL');
534 // $df->setSort('stateid');
535 $d_arr =& $df->getDocuments();
537 docman_header(sprintf(_('Project %s'), $g->getPublicName()),_('Document Manager: Administration'),'admin');
540 <h1><?php echo _('Document Manager: Administration') ?></h1>
542 <a href="index.php?group_id=<?php echo $group_id; ?>&admingroup=1"><?php echo _('Add/Edit/Delete Document Groups') ?></a>
546 $selected_stateid = getIntFromRequest('selected_stateid');
547 if (!$d_arr || count($d_arr) < 1) {
548 print "<p><strong>"._('This project has no visible documents').".</strong></p>";
550 // get a list of used document states
551 $states = $df->getUsedStates();
552 $nested_groups =& $dgf->getNested();
554 foreach ($states as $state) {
555 echo "<li><strong>".$state["name"]."</strong>";
556 docman_display_documents($nested_groups, $df, true, $state['stateid'], true);
562 docman_footer(array());
568 // c-file-style: "bsd"