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 * http://fusionforge.org
11 * This file is part of FusionForge. FusionForge is free software;
12 * you can redistribute it and/or modify it under the terms of the
13 * GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the Licence, or (at your option)
17 * FusionForge is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 function getNameDocGroup($id, $group) {
30 $group_object = group_get_object($group);
31 $res = db_query_params('SELECT groupname FROM doc_groups WHERE doc_group=$1 AND group_id=$2',
33 if (!$res || db_numrows($res) < 1) {
34 $group_object->setError('DocumentGroup::'. _('Invalid DocumentGroup ID'));
37 return (db_result($res, 0, 'groupname'));
41 function getStateDocGroup($id, $group) {
42 $group_object = group_get_object($group);
43 $res = db_query_params ('SELECT stateid FROM doc_groups WHERE doc_group=$1 AND group_id=$2',
45 if (!$res || db_numrows($res) < 1) {
46 $group_object->setError('DocumentGroup:: '. _('Invalid DocumentGroup ID'));
49 return (db_result($res, 0, 'stateid'));
53 function doc_get_state_box($checkedval = 'xzxz') {
54 $res_states=db_query_params ('select * from doc_states', array());
55 echo html_build_select_box ($res_states, 'stateid', $checkedval, false);
59 * docman_recursive_display - Recursive function to show the documents inside the groups tree : javascript enabled function
61 function docman_recursive_display($docgroup) {
62 global $nested_groups, $group_id;
63 global $idExposeTreeIndex, $dirid,$idhtml;
65 if (is_array(@$nested_groups[$docgroup])) {
66 foreach ($nested_groups[$docgroup] as $dg) {
69 if ($dirid == $dg->getID())
70 $idExposeTreeIndex = $idhtml;
73 ['".'<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()."', '', '',";
74 docman_recursive_display($dg->getID());
82 * docman_fill_zip - Recursive function to add docgroup and documents inside zip for backup
85 * @param $array nested groups
86 * @param $object documentfactory
87 * @param $int documentgroup id : default value = 0
88 * @param $string documentgroup parent name : default value = empty
90 function docman_fill_zip($zip, $nested_groups, $document_factory, $docgroup = 0, $parent_docname = '') {
91 if (is_array(@$nested_groups[$docgroup])) {
92 foreach ($nested_groups[$docgroup] as $dg) {
93 if (!$zip->addEmptyDir($parent_docname.'/'.$dg->getName()))
96 $document_factory->setDocGroupID($dg->getID());
97 $docs = $document_factory->getDocuments();
98 if (is_array($docs) && count($docs) > 0) { // this group has documents
99 foreach ($docs as $doc) {
100 if ( !$zip->addFromString($parent_docname.'/'.$dg->getName().'/'.$doc->getFileName(),$doc->getFileData()))
104 docman_fill_zip($zip, $nested_groups, $document_factory, $dg->getID(), $parent_docname.'/'.$dg->getName());
110 function docman_recursive_stateid($docgroup, $nested_groups, $nested_docs, $stateid = 2) {
111 if (is_array(@$nested_groups[$docgroup])) {
112 foreach ($nested_groups[$docgroup] as $dg) {
113 $dg->setStateID($stateid);
116 if (isset($nested_docs[$docgroup]) && is_array($nested_docs[$docgroup])) {
117 foreach ($nested_docs[$docgroup] as $d) {
118 $d->setStateID($stateid);
124 * docman_display_trash - function to show the documents inside the groups tree with specific status : 2 = deleted
125 *@todo: remove css code
127 function docman_display_trash(&$document_factory, $parent_group = 0) {
128 $nested_groups =& $document_factory->getNested(2);
129 $child_count = count($nested_groups["$parent_group"]);
130 echo "<ul style='list-style-type: none'>\n";
131 for ($i=0; $i < $child_count; $i++) {
132 $doc_group =& $nested_groups["$parent_group"][$i];
133 echo "<li>".$doc_group->getName()."</li>";
139 * docman_display_documents - Recursive function to show the documents inside the groups tree
140 * @todo : remove the css code
141 * @todo : use the javascript controler
144 function docman_display_documents(&$nested_groups, &$document_factory, $is_editor, $stateid = 0, $parent_group = 0) {
146 if (!array_key_exists("$parent_group", $nested_groups) || !is_array($nested_groups["$parent_group"])) {
150 echo '<script type="text/javascript">';
151 echo 'var lockInterval = new Array();';
152 echo 'function EditData(iddiv) {';
153 echo ' if ( "none" == document.getElementById(\'editdata\'+iddiv).style.display ) {';
154 echo ' document.getElementById(\'editdata\'+iddiv).style.display = "block";';
155 echo ' jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id.',action:\'lockfile\',lock:1,fileid:iddiv});';
156 echo ' lockInterval[iddiv] = setInterval("jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id .',action:\'lockfile\',lock:1,fileid:"+iddiv+"})",60000);';
158 echo ' document.getElementById(\'editdata\'+iddiv).style.display = "none";';
159 echo ' jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id .',action:\'lockfile\',lock:0,fileid:iddiv});';
160 echo ' clearInterval(lockInterval[iddiv]);';
164 echo '<ul style="list-style-type: none">';
165 $child_count = count($nested_groups["$parent_group"]);
167 for ($i=0; $i < $child_count; $i++) {
168 $doc_group =& $nested_groups["$parent_group"][$i];
170 if ($doc_group->hasDocuments($nested_groups, $document_factory, $stateid)) {
171 $icon = 'ofolder15.png';
172 echo '<li>'.html_image('docman/directory.png', '22', '22', array('border'=>'0'))." ".$doc_group->getName()."</li>";
173 docman_display_documents($nested_groups, $document_factory, $is_editor, $stateid, $doc_group->getID());
176 // Display this group's documents
177 // Retrieve all the docs from this category
179 $document_factory->setStateID($stateid);
181 $document_factory->setDocGroupID($doc_group->getID());
182 $docs = $document_factory->getDocuments();
183 if (is_array($docs)) {
184 $docs_count = count($docs);
186 echo "<ul style='list-style-type: none'>";
187 for ($j=0; $j < $docs_count; $j++) {
188 $tooltip = $docs[$j]->getFileName() . " (" .
189 ($docs[$j]->getUpdated() ?
190 date(_('Y-m-d H:i'), $docs[$j]->getUpdated()) :
191 date(_('Y-m-d H:i'),$docs[$j]->getCreated())) .
193 if ($docs[$j]->getFileSize() > 1024) {
194 $tooltip .= floor($docs[$j]->getFileSize()/1024) . "KB";
196 $tooltip .= $docs[$j]->getFileSize() . "B";
198 $tooltip = htmlspecialchars($tooltip);
199 echo '<li>'. html_image('docman/file_type_unknown.png', '22', '22', array("border"=>"0")).
200 $docs[$j]->getName(). ' - ' . $tooltip . ' <a href="#" onclick="javascript:EditData(\''.$docs[$j]->getID().'\')" >'. html_image('docman/edit-file.png', '22', '22', array('alt'=>'editfile')) .'</a></li>';
201 echo "<i>".$docs[$j]->getDescription()."</i><br/>";
202 echo '<div class="docman_div_include" id="editdata'.$docs[$j]->getID().'" style="display:none">';
203 document_editdata($docs[$j]);
213 * @todo - remove the css code
215 function document_editdata(&$document) {
216 global $g, $dirid, $group_id;
217 $dgh = new DocumentGroupHTML($g);
219 exit_error($dgh->getErrorMessage(), 'docman');
221 $dgf = new DocumentGroupFactory($g);
223 exit_error($dgf->getErrorMessage(), 'docman');
226 <div class="docmanDivIncluded">
228 <?php echo _('Document Title:') ?>
230 <?php echo _('Refers to the relatively brief title of the document (e.g. How to use the download server).') ?>
232 <?php echo _('Description:') ?>
234 <?php echo _('A brief description to be placed just under the title.') ?>
237 if ($g->useDocmanSearch())
238 echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
241 <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">
245 <td style="text-align:right;"> <strong><?php echo _('Document Title') ?></strong><?php echo utils_requiredField(); ?>
248 <input type="text" name="title" size="40" maxlength="255" value="<?php echo $document->getName(); ?>" />
249 <?php printf(_('(at least %1$s characters)'), 5) ?>
253 <td style="text-align:right;">
254 <strong><?php echo _('Description') ?></strong><?php echo utils_requiredField(); ?>
257 <input type="text" name="description" size="50" maxlength="255" value="<?php echo $document->getDescription(); ?>" />
258 <?php printf(_('(at least %1$s characters)'), 10) ?>
263 <td style="text-align:right;">
264 <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?>
267 <?php if ($document->isURL()) {
268 echo '<a href="'.inputSpecialchars($d->getFileName()).'">[View File URL]</a>';
270 <a target="_blank" href="/docman/view.php/<?php echo $group_id.'/'.$document->getID().'/'.urlencode($document->getFileName()) ?>"><?php echo $document->getName(); ?></a>
277 if ((!$document->isURL()) && ($document->isText())) {
278 if ($g->useCreateOnline()) {
281 echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
282 switch ($document->getFileType()) {
284 $GLOBALS['editor_was_set_up']=false;
286 /* warning name must be unique */
287 $params['name'] = 'details'.$document->getID();
288 $params['width'] = "800";
289 $params['height'] = "300";
290 $params['body'] = $d->getFileData();
291 $params['group'] = $group_id;
292 plugin_hook("text_editor",$params);
293 if (!$GLOBALS['editor_was_set_up']) {
294 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70" wrap="soft">'. $document->getFileData() .'</textarea><br />';
296 echo '<input type="hidden" name="filetype" value="text/html">';
297 unset($GLOBALS['editor_was_set_up']);
301 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70" wrap="soft">'. $document->getFileData() .'</textarea><br />';
302 echo '<input type="hidden" name="filetype" value="text/plain">';
312 <td style="text-align:right;">
313 <strong><?php echo _('Directory that document belongs in') ?></strong>
316 <?php $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $document->getDocGroupID()); ?>
320 <td style="text-align:right;">
321 <strong><?php echo _('State') ?></strong>
324 <?php doc_get_state_box($document->getStateID()); ?>
328 <td style="text-align:right;">
329 <?php if ($document->isURL()) { ?>
330 <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?>
333 <input type="text" name="file_url" size="50" value="<?php echo $document->getFileName() ?>" />
335 <strong><?php echo _('OPTIONAL: Upload new file') ?></strong>
338 <input type="file" name="uploaded_data" size="30" />
346 <input type="hidden" name="docid" value="<?php echo $document->getID(); ?>" />
347 <input type="submit" id="submiteditdata<?php echo $document->getID(); ?>" value="<?php echo _('Submit Edit') ?>" /><br /><br />