3 * FusionForge Documentation Manager
5 * Copyright 1999-2001, VA Linux Systems
6 * Copyright 2000, Quentin Cregan/SourceForge
7 * Copyright 2002-2004, GForge Team
8 * Copyright 2010, Franck Villaume - Capgemini
9 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
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 function getNameDocGroup($id, $group) {
31 $group_object = group_get_object($group);
32 $res = db_query_params('SELECT groupname FROM doc_groups WHERE doc_group=$1 AND group_id=$2',
34 if (!$res || db_numrows($res) < 1) {
35 $group_object->setError('DocumentGroup::'. _('Invalid DocumentGroup ID'));
38 return (db_result($res, 0, 'groupname'));
42 function getStateDocGroup($id, $group) {
43 $group_object = group_get_object($group);
44 $res = db_query_params ('SELECT stateid FROM doc_groups WHERE doc_group=$1 AND group_id=$2',
46 if (!$res || db_numrows($res) < 1) {
47 $group_object->setError('DocumentGroup:: '. _('Invalid DocumentGroup ID'));
50 return (db_result($res, 0, 'stateid'));
54 function doc_get_state_box($checkedval = 'xzxz') {
55 $res_states=db_query_params ('select * from doc_states', array());
56 echo html_build_select_box ($res_states, 'stateid', $checkedval, false);
60 * docman_recursive_display - Recursive function to show the documents inside the groups tree : javascript enabled function
62 function docman_recursive_display($docgroup) {
63 global $nested_groups, $group_id;
64 global $idExposeTreeIndex, $dirid,$idhtml;
66 if (is_array(@$nested_groups[$docgroup])) {
67 foreach ($nested_groups[$docgroup] as $dg) {
70 if ($dirid == $dg->getID())
71 $idExposeTreeIndex = $idhtml;
74 ['".'<span class="JSCookTreeFolderClosed"><i><img alt="" src="\' + ctThemeXPBase + \'folder1.gif" /></i></span><span class="JSCookTreeFolderOpen"><i><img alt="" src="\' + ctThemeXPBase + \'folderopen1.gif" /></i></span>'."', '".addslashes($dg->getName())."', '?group_id=".$group_id."&view=listfile&dirid=".$dg->getID()."', '', '',";
75 docman_recursive_display($dg->getID());
83 * docman_fill_zip - Recursive function to add docgroup and documents inside zip for backup
86 * @param $array nested groups
87 * @param $object documentfactory
88 * @param $int documentgroup id : default value = 0
89 * @param $string documentgroup parent name : default value = empty
91 function docman_fill_zip($zip, $nested_groups, $document_factory, $docgroup = 0, $parent_docname = '') {
92 if (is_array(@$nested_groups[$docgroup])) {
93 foreach ($nested_groups[$docgroup] as $dg) {
94 if (!$zip->addEmptyDir($parent_docname.'/'.$dg->getName()))
97 $document_factory->setDocGroupID($dg->getID());
98 $docs = $document_factory->getDocuments();
99 if (is_array($docs) && count($docs) > 0) { // this group has documents
100 foreach ($docs as $doc) {
101 if ( !$zip->addFromString($parent_docname.'/'.$dg->getName().'/'.$doc->getFileName(),$doc->getFileData()))
105 docman_fill_zip($zip, $nested_groups, $document_factory, $dg->getID(), $parent_docname.'/'.$dg->getName());
111 function docman_recursive_stateid($docgroup, $nested_groups, $nested_docs, $stateid = 2) {
112 if (is_array(@$nested_groups[$docgroup])) {
113 foreach ($nested_groups[$docgroup] as $dg) {
114 $dg->setStateID($stateid);
117 if (isset($nested_docs[$docgroup]) && is_array($nested_docs[$docgroup])) {
118 foreach ($nested_docs[$docgroup] as $d) {
119 $d->setStateID($stateid);
125 * docman_display_trash - function to show the documents inside the groups tree with specific status : 2 = deleted
126 *@todo: remove css code
128 function docman_display_trash(&$document_factory, $parent_group = 0) {
129 $nested_groups =& $document_factory->getNested(2);
130 $child_count = count($nested_groups["$parent_group"]);
131 echo "<ul style='list-style-type: none'>\n";
132 for ($i=0; $i < $child_count; $i++) {
133 $doc_group =& $nested_groups["$parent_group"][$i];
134 echo "<li>".$doc_group->getName()."</li>";
139 function docman_editdata_js() {
142 echo '<script language="JavaScript" type="text/javascript">/* <![CDATA[ */';
143 echo 'var lockInterval = new Array();';
144 echo 'function EditData(iddiv) {';
145 echo ' if ( "none" == document.getElementById(\'editdata\'+iddiv).style.display ) {';
146 echo ' document.getElementById(\'editdata\'+iddiv).style.display = "block";';
147 echo ' jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id.',action:\'lockfile\',lock:1,fileid:iddiv});';
148 echo ' lockInterval[iddiv] = setInterval("jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id .',action:\'lockfile\',lock:1,fileid:"+iddiv+"})",60000);';
150 echo ' document.getElementById(\'editdata\'+iddiv).style.display = "none";';
151 echo ' jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id .',action:\'lockfile\',lock:0,fileid:iddiv});';
152 echo ' clearInterval(lockInterval[iddiv]);';
155 echo '/* ]]> */</script>'."\n";
159 * docman_display_documents - Recursive function to show the documents inside the groups tree
160 * @todo : remove the css code
161 * @todo : use the javascript controler
164 function docman_display_documents(&$nested_groups, &$document_factory, $is_editor, $stateid = 0, $parent_group = 0) {
166 if (!array_key_exists("$parent_group", $nested_groups) || !is_array($nested_groups["$parent_group"])) {
170 echo "\n".'<ul style="list-style-type: none">';
171 $child_count = count($nested_groups["$parent_group"]);
173 for ($i=0; $i < $child_count; $i++) {
174 $doc_group =& $nested_groups["$parent_group"][$i];
176 if ($doc_group->hasDocuments($nested_groups, $document_factory, $stateid)) {
177 $icon = 'ofolder15.png';
178 echo '<li>'.html_image('docman/directory.png', '22', '22', array('border'=>'0'))." ".$doc_group->getName();
179 docman_display_documents($nested_groups, $document_factory, $is_editor, $stateid, $doc_group->getID());
182 // Display this group's documents
183 // Retrieve all the docs from this category
185 $document_factory->setStateID($stateid);
187 $document_factory->setDocGroupID($doc_group->getID());
188 $docs = $document_factory->getDocuments();
189 if (is_array($docs)) {
190 $docs_count = count($docs);
192 echo "\n<ul style='list-style-type: none'>";
193 for ($j=0; $j < $docs_count; $j++) {
194 $tooltip = $docs[$j]->getFileName() . " (" .
195 ($docs[$j]->getUpdated() ?
196 date(_('Y-m-d H:i'), $docs[$j]->getUpdated()) :
197 date(_('Y-m-d H:i'),$docs[$j]->getCreated())) .
199 $tooltip .= human_readable_bytes($docs[$j]->getFileSize());
200 $tooltip = htmlspecialchars($tooltip);
201 echo '<li>'. html_image('docman/file_type_unknown.png', '22', '22', array("border"=>"0")).
202 $docs[$j]->getName(). ' - ' . $tooltip . ' <a href="#" onclick="javascript:EditData(\''.$docs[$j]->getID().'\')" >'. html_image('docman/edit-file.png', '22', '22', array('alt'=>'editfile')) .'</a>';
203 echo "<br /><i>".$docs[$j]->getDescription()."</i><br/>";
204 echo '<div class="docman_div_include" id="editdata'.$docs[$j]->getID().'" style="display:none">';
205 document_editdata($docs[$j]);
206 echo '</div></li>'."\n";
210 if ($doc_group->hasDocuments($nested_groups, $document_factory, $stateid)) {
218 * @todo - remove the css code
220 function document_editdata(&$document) {
221 global $g, $dirid, $group_id;
222 $dgh = new DocumentGroupHTML($g);
224 exit_error($dgh->getErrorMessage(), 'docman');
226 $dgf = new DocumentGroupFactory($g);
228 exit_error($dgf->getErrorMessage(), 'docman');
231 <div class="docmanDivIncluded">
233 <?php echo _('Document Title:') ?>
235 <?php echo _('Refers to the relatively brief title of the document (e.g. How to use the download server).') ?>
237 <?php echo _('Description:') ?>
239 <?php echo _('A brief description to be placed just under the title.') ?>
242 if ($g->useDocmanSearch())
243 echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
246 <form id="editdata<?php echo $document->getID(); ?>" name="editdata<?php echo $document->getID(); ?>" action="?group_id=<?php echo $group_id; ?>&action=editfile&fromview=admin&dirid=<?php echo $dirid; ?>" method="post" enctype="multipart/form-data">
250 <td style="text-align:right;"> <strong><?php echo _('Document Title') ?></strong><?php echo utils_requiredField(); ?>
253 <input type="text" name="title" size="40" maxlength="255" value="<?php echo $document->getName(); ?>" />
254 <?php printf(_('(at least %1$s characters)'), 5) ?>
258 <td style="text-align:right;">
259 <strong><?php echo _('Description') ?></strong><?php echo utils_requiredField(); ?>
262 <input type="text" name="description" size="50" maxlength="255" value="<?php echo $document->getDescription(); ?>" />
263 <?php printf(_('(at least %1$s characters)'), 10) ?>
268 <td style="text-align:right;">
269 <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?>
272 <?php if ($document->isURL()) {
273 echo '<a href="'.inputSpecialchars($document->getFileName()).'">[View File URL]</a>';
275 <a target="_blank" href="/docman/view.php/<?php echo $group_id.'/'.$document->getID().'/'.urlencode($document->getFileName()) ?>"><?php echo $document->getName(); ?></a>
282 if ((!$document->isURL()) && ($document->isText())) {
283 if ($g->useCreateOnline()) {
286 echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
287 switch ($document->getFileType()) {
289 $GLOBALS['editor_was_set_up']=false;
291 /* warning name must be unique */
292 $params['name'] = 'details'.$document->getID();
293 $params['width'] = "800";
294 $params['height'] = "300";
295 $params['body'] = $document->getFileData();
296 $params['group'] = $group_id;
297 plugin_hook("text_editor",$params);
298 if (!$GLOBALS['editor_was_set_up']) {
299 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70">'. $document->getFileData() .'</textarea><br />';
301 echo '<input type="hidden" name="filetype" value="text/html" />';
302 unset($GLOBALS['editor_was_set_up']);
306 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70">'. $document->getFileData() .'</textarea><br />';
307 echo '<input type="hidden" name="filetype" value="text/plain" />';
317 <td style="text-align:right;">
318 <strong><?php echo _('Folder that document belongs in') ?></strong>
321 <?php $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $document->getDocGroupID()); ?>
325 <td style="text-align:right;">
326 <strong><?php echo _('State') ?></strong>
329 <?php doc_get_state_box($document->getStateID()); ?>
333 <td style="text-align:right;">
334 <?php if ($document->isURL()) { ?>
335 <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?>
338 <input type="text" name="file_url" size="50" value="<?php echo $document->getFileName() ?>" />
340 <strong><?php echo _('OPTIONAL: Upload new file') ?></strong>
343 <input type="file" name="uploaded_data" size="30" />
351 <input type="hidden" name="docid" value="<?php echo $document->getID(); ?>" />
352 <input type="submit" id="submiteditdata<?php echo $document->getID(); ?>" value="<?php echo _('Submit Edit') ?>" /><br /><br />