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 $gfwww.'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 $perm =& $g->getPermission( session_get_user() );
53 if (!$perm || $perm->isError() || !$perm->isDocEditor()) {
54 exit_permission_denied();
57 $editdoc = getStringFromRequest('editdoc');
58 $docid = getIntFromRequest('docid');
60 $upload_dir = forge_get_config('ftp_upload_dir') . "/" . $g->getUnixName();
64 // Submit the changes to the database
68 if (getStringFromRequest('submit')) {
70 $doc_group = getIntFromRequest('doc_group');
71 $title = getStringFromRequest('title');
72 $description = getStringFromRequest('description');
73 $language_id = getIntFromRequest('language_id');
74 $data = getStringFromRequest('data');
75 $file_url = getStringFromRequest('file_url');
76 //$ftp_filename = getStringFromRequest('ftp_filename');
77 $uploaded_data = getUploadedFile('uploaded_data');
78 $stateid = getIntFromRequest('stateid');
79 $filetype = getStringFromRequest('filetype');
80 $editor = getStringFromRequest('editor');
82 $d= new Document($g,$docid,false,$sys_engine_path);
84 exit_error(_('Error'),$d->getErrorMessage());
87 $sanitizer = new TextSanitizer();
88 $data = $sanitizer->SanitizeHtml($data);
89 if (($editor) && ($d->getFileData()!=$data) && (!$uploaded_data['name'])) {
90 $filename = $d->getFileName();
92 $filetype = $d->getFileType();
94 } elseif ($uploaded_data['name']) {
95 if (!is_uploaded_file($uploaded_data['tmp_name'])) {
96 exit_error(_('Error'),sprintf(_('Invalid file attack attempt %1$s'), $uploaded_data['name']));
98 $data = fread(fopen($uploaded_data['tmp_name'], 'r'), $uploaded_data['size']);
99 $filename=$uploaded_data['name'];
100 $filetype=$uploaded_data['type'];
101 } elseif ($file_url) {
106 } elseif (forge_get_config('use_ftpuploads') && $ftp_filename!=100) { //100==None
107 $filename=$upload_dir.'/'.$ftp_filename;
108 $data = fread(fopen($filename, 'r'), filesize($filename));
109 $filetype=$uploaded_data_type;
110 } elseif (forge_get_config('use_manual_uploads') && $uploaded_filename!=100 && util_is_valid_filename($uploaded_filename)) { //100==None
111 $incoming = forge_get_config('groupdir_prefix')."/".$g->getUnixName()."/incoming" ;
112 $filename = $incoming.'/'.$uploaded_filename;
113 $data = addslashes(fread(fopen($filename, 'r'), filesize($filename)));
114 $finfo = finfo_open (FILEINFO_MIME_TYPE) ;
115 $filetype = finfo_file($finfo, $filename) ;
116 finfo_close ($finfo) ;
119 $filename=$d->getFileName();
120 $filetype=$d->getFileType();
122 if (!$d->update($filename,$filetype,$data,$doc_group,$title,$language_id,$description,$stateid)) {
123 exit_error('Error',$d->getErrorMessage());
125 $feedback = _('Updated successfully');
127 } elseif (getStringFromRequest('editgroup')) {
128 $doc_group = getIntFromRequest('doc_group');
129 $groupname = getStringFromRequest('groupname');
130 $parent_doc_group = getIntFromRequest('parent_doc_group');
132 $dg = new DocumentGroup($g,$doc_group);
133 if ($dg->isError()) {
134 exit_error('Error',$dg->getErrorMessage());
136 if (!$dg->update($groupname,$parent_doc_group)) {
137 exit_error('Error',$dg->getErrorMessage());
139 $feedback = _('Updated successfully');
141 } elseif (getStringFromRequest('deletegroup')) {
142 $doc_group = getIntFromRequest('doc_group');
144 $dg = new DocumentGroup($g,$doc_group);
145 if ($dg->isError()) {
146 exit_error('Error',$dg->getErrorMessage());
148 if (!$dg->delete($doc_group,$group_id)) {
149 exit_error('Error',$dg->getErrorMessage());
151 $feedback = _('Deleted successfully');
152 header('Location: index.php?group_id='.$group_id.'&feedback='.urlencode($feedback));
153 die(); // End parsing file and redirect
155 } elseif (getStringFromRequest('addgroup')) {
156 $groupname = getStringFromRequest('groupname');
157 $parent_doc_group = getIntFromRequest('parent_doc_group');
159 $dg = new DocumentGroup($g);
160 if ($dg->isError()) {
161 exit_error('Error',$dg->getErrorMessage());
163 if (!$dg->create($groupname, $parent_doc_group)) {
164 exit_error('Error',$dg->getErrorMessage());
166 $feedback = _('Created successfully');
168 } elseif (getStringFromRequest('deletedoc') && $docid && getStringFromRequest('sure') && getStringFromRequest('really_sure')) {
169 $d= new Document($g,$docid);
171 exit_error('Error',$d->getErrorMessage());
175 exit_error('Error',$d->getErrorMessage());
178 $feedback = _('Deleted');
179 header('Location: index.php?group_id='.$d->Group->getID().'&feedback='.urlencode($feedback));
180 die(); // End parsing file and redirect
187 // Edit a specific document
190 if ($editdoc && $docid) {
192 $d= new Document($g,$docid);
194 exit_error('Error',$d->getErrorMessage());
197 $dgf = new DocumentGroupFactory($g);
198 if ($dgf->isError()) {
199 exit_error('Error',$dgf->getErrorMessage());
202 $dgh = new DocumentGroupHTML($g);
203 if ($dgh->isError()) {
204 exit_error('Error',$dgh->getErrorMessage());
208 docman_header(_('Document Manager Administration'),_('Edit Docs'),'');
212 <?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.") ?>
215 <form name="editdata" action="index.php?editdoc=1&group_id=<?php echo $group_id; ?>" method="post" enctype="multipart/form-data">
221 <strong><?php echo _('Document Title') ?>: </strong><?php echo utils_requiredField(); ?> <?php printf(_('(at least %1$s characters)'), 5) ?><br />
222 <input type="text" name="title" size="40" maxlength="255" value="<?php echo $d->getName(); ?>" />
228 <strong><?php echo _('Description') ?></strong><?php echo utils_requiredField(); ?> <?php printf(_('(at least %1$s characters)'), 10) ?><br />
229 <input type="text" name="description" size="50" maxlength="255" value="<?php echo $d->getDescription(); ?>" />
235 <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?><br />
236 <?php if ($d->isURL()) {
237 echo '<a href="'.inputSpecialchars($d->getFileName()).'">[View File URL]</a>';
239 <a target="_blank" href="../view.php/<?php echo $group_id.'/'.$d->getID().'/'.urlencode($d->getFileName()) ?>"><?php echo $d->getName(); ?></a>
246 if ((!$d->isURL()) && ($d->isText())) {
250 //echo '<input type="hidden" name="editor" value="editor">';
251 echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
253 $GLOBALS['editor_was_set_up']=false;
255 $params['name'] = 'data';
256 $params['width'] = "800";
257 $params['height'] = "500";
258 $params['group'] = $group_id;
259 $params['body'] = $d->getFileData();
261 // we are displaying with textarea if the document is not html (fckeditor pre-parses the files as html and validates it/changes it)
262 plugin_hook("text_editor",$params);
264 if (!$GLOBALS['editor_was_set_up']) {
266 //if we don't have any plugin for text editor, display a simple textarea edit box
267 echo '<textarea name="data" rows="15" cols="100" wrap="soft">'. $d->getFileData() .'</textarea><br />';
268 echo '<input type="hidden" name="filetype" value="text/plain">';
271 echo '<input type="hidden" name="filetype" value="text/html">'; // the fckeditor creates html docs. this is for filetype
273 unset($GLOBALS['editor_was_set_up']);
283 <strong><?php echo _('Language') ?></strong><br />
286 echo html_get_language_popup('language_id',$d->getLanguageID());
293 <strong><?php echo _('Group that document belongs in') ?></strong><br />
296 //echo display_groups_option($group_id,$d->getDocGroupID());
297 $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $d->getDocGroupID());
304 <br /><strong><?php echo _('State') ?>:</strong><br />
307 doc_get_state_box($d->getStateID());
315 // if this is a text/html doc, display an edit box
316 if (strstr($d->getFileType(),'ext')) {
321 <strong>'._('Document Contents').'</strong><br />
322 <textarea cols="80" rows="20" name="data">'. htmlspecialchars( $d->getFileData() ).'</textarea>
330 <?php if ($d->isURL()) { ?>
331 <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?><br />
332 <input type="text" name="file_url" size="50" value="<?php echo $d->getFileName() ?>" />
334 <strong><?php echo _('OPTIONAL: Upload new file') ?></strong><br />
335 <input type="file" name="uploaded_data" size="30" /><br/><br />
337 if (forge_get_config('use_ftpuploads')) {
339 printf(_('OR choose one form FTP %1$s.'), forge_get_config('ftp_upload_host'));
340 echo '</strong><br />' ;
341 $ftp_files_arr=array_merge($arr,ls($upload_dir,true));
342 echo html_build_select_box_from_arrays($ftp_files_arr,$ftp_files_arr,'ftp_filename','');
346 /* if (forge_get_config('use_manual_uploads') && $u->getUnixStatus() == 'A') {
347 $incoming = forge_get_config('groupdir_prefix')."/".$g->getUnixName()."/incoming" ;
350 printf (_("OR choose one you alrealy uploaded (by SFTP or SCP) to the project's incoming directory ($1$s)."),
352 echo '</strong><br />' ;
353 $manual_files_arr=array_merge($arr,ls($incoming,true));
354 echo html_build_select_box_from_arrays($manual_files_arr,$manual_files_arr,'uploaded_filename','');
363 <input type="hidden" name="docid" value="<?php echo $d->getID(); ?>" />
364 <input type="submit" value="<?php echo _('Submit Edit') ?>" name="submit" /><br /><br />
365 <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>
370 docman_footer(array());
374 // Add a document group / view existing groups list
377 } elseif (getStringFromRequest('admingroup')) {
379 docman_header(_('Document Manager Administration'),_('Admin Document Groups'),'');
381 echo "<h1>"._('Admin Document Groups')."</h1>";
383 $dgf = new DocumentGroupFactory($g);
384 if ($dgf->isError()) {
385 exit_error('Error',$dgf->getErrorMessage());
388 $dgh = new DocumentGroupHTML($g);
389 if ($dgh->isError()) {
390 exit_error('Error',$dgh->getErrorMessage());
393 $nested_groups =& $dgf->getNested();
395 if (count($nested_groups) > 0) {
397 $title_arr[]=_('ID');
398 $title_arr[]=_('Group Name');
399 $title_arr[]=_('Delete Group');
401 echo $GLOBALS['HTML']->listTableTop ($title_arr);
404 $dgh->showTableNestedGroups($nested_groups, $row);
406 echo $GLOBALS['HTML']->listTableBottom();
409 echo "\n<h1>"._('No Document Groups defined')."</h1>";
412 <p><strong><?php echo _('Add a group') ?>:</strong></p>
413 <form name="admingroup" action="index.php?addgroup=1&group_id=<?php echo $group_id; ?>" method="post">
416 <th><?php echo _('New Group Name') ?>:</th>
417 <td><input type="text" name="groupname" /></td>
421 <th><?php echo _('Belongs to') ?>:</th>
423 <?php echo $dgh->showSelectNestedGroups($nested_groups, 'parent_doc_group') ?>
426 <td><input type="submit" value="<?php echo _('Add') ?>" name="submit" /></td>
430 <?php echo _('Group name will be used as a title, so it should be formatted correspondingly.') ?>
435 docman_footer(array());
439 // Edit a specific doc group
442 } elseif (getStringFromRequest('editgroup') && getIntFromRequest('doc_group')) {
443 $doc_group = getIntFromRequest('doc_group');
445 $dg = new DocumentGroup($g,$doc_group);
446 if ($dg->isError()) {
447 exit_error('Error',$dg->getErrorMessage());
450 $dgf = new DocumentGroupFactory($g);
451 if ($dgf->isError()) {
452 exit_error('Error',$dgf->getErrorMessage());
455 $dgh = new DocumentGroupHTML($g);
456 if ($dgh->isError()) {
457 exit_error('Error',$dgh->getErrorMessage());
460 docman_header(_('Document Manager Administration'),_('Edit Groups'),'');
462 <h1><?php echo _('Edit a group') ?></h1>
463 <form name="editgroup" action="index.php?editgroup=1&group_id=<?php echo $group_id; ?>" method="post">
464 <input type="hidden" name="doc_group" value="<?php echo $doc_group; ?>" />
467 <th><?php echo _('Group Name') ?>:</th>
468 <td><input type="text" name="groupname" value="<?php echo $dg->getName(); ?>" /></td>
472 <th><?php echo _('Belongs to') ?>:</th>
475 $dgh->showSelectNestedGroups($dgf->getNested(), "parent_doc_group", true, $dg->getParentId(), array($dg->getID()));
478 <td><input type="submit" value="<?php echo _('Edit') ?>" name="submit" /></td>
482 <?php echo _('Group name will be used as a title, so it should be formatted correspondingly.') ?>
487 docman_footer(array());
488 } else if (getStringFromRequest('deletegroup') && getIntFromRequest('doc_group')) {
489 $doc_group = getIntFromRequest('doc_group');
491 $dg = new DocumentGroup($g,$doc_group);
492 if ($dg->isError()) {
493 exit_error('Error',$dg->getErrorMessage());
496 docman_header(_('Document Manager Administration'),_('Delete Groups'),'');
499 <form action="<?php echo util_make_url('/docman/admin/index.php').'?deletegroup=1&doc_group='.$dg->getID().'&group_id='.$dg->Group->getID() ?>" method="post">
500 <input type="hidden" name="submit" value="1" /><br />
501 <img src="/images/ic/cfolder15.png" /><?php echo $dg->getName(); ?><br />
502 <?php echo _('You are about to permanently delete this document group and its content (documents and subgroups).'); ?>
503 <p><input type="submit" name="post_changes" value="<?php echo _('Delete') ?>" /></p>
506 docman_footer(array());
508 } else if (getStringFromRequest('deletedoc') && $docid) {
509 $d= new Document($g,$docid);
511 exit_error('Error',$d->getErrorMessage());
514 docman_header(_('Document Manager Administration'),_('Edit Groups'),'');
517 <form action="<?php echo util_make_url('/docman/admin/index.php').'?deletedoc=1&docid='.$d->getID().'&group_id='.$d->Group->getID() ?>" method="post">
518 <input type="hidden" name="submit" value="1" /><br />
519 <?php echo _('You are about to permanently delete this document.'); ?>
521 <input type="checkbox" name="sure" value="1"><?php echo _('I\'m Sure.') ?><br />
522 <input type="checkbox" name="really_sure" value="1"><?php echo _('I\'m Really Sure.') ?><br />
524 <input type="submit" name="post_changes" value="<?php echo _('Delete') ?>" /></p>
527 docman_footer(array());
531 // Display the main admin page
536 $df = new DocumentFactory($g);
537 if ($df->isError()) {
538 exit_error(_('Error'),$df->getErrorMessage());
541 $dgf = new DocumentGroupFactory($g);
542 if ($dgf->isError()) {
543 exit_error(_('Error'),$dgf->getErrorMessage());
547 $df->setStateID('ALL');
548 // $df->setSort('stateid');
549 $d_arr =& $df->getDocuments();
551 docman_header(sprintf(_('Project %s'), $g->getPublicName()),_('Document Manager: Administration'),'admin');
554 <h1><?php echo _('Document Manager: Administration') ?></h1>
556 <a href="index.php?group_id=<?php echo $group_id; ?>&admingroup=1"><?php echo _('Add/Edit/Delete Document Groups') ?></a>
560 $selected_stateid = getIntFromRequest('selected_stateid');
561 if (!$d_arr || count($d_arr) < 1) {
562 print "<p><strong>"._('This project has no visible documents').".</strong></p>";
564 // get a list of used document states
565 $states = $df->getUsedStates();
566 $nested_groups =& $dgf->getNested();
568 foreach ($states as $state) {
569 echo "<li><strong>".$state["name"]."</strong>";
570 docman_display_documents($nested_groups, $df, true, $state['stateid'], true);
576 docman_footer(array());
582 // c-file-style: "bsd"