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.
13 * FusionForge is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
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
24 * along with FusionForge; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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>";
140 * docman_display_documents - Recursive function to show the documents inside the groups tree
141 * @todo : remove the css code
142 * @todo : use the javascript controler
145 function docman_display_documents(&$nested_groups, &$document_factory, $is_editor, $stateid = 0, $parent_group = 0) {
147 if (!array_key_exists("$parent_group", $nested_groups) || !is_array($nested_groups["$parent_group"])) {
151 echo '<script type="text/javascript">';
152 echo 'var lockInterval = new Array();';
153 echo 'function EditData(iddiv) {';
154 echo ' if ( "none" == document.getElementById(\'editdata\'+iddiv).style.display ) {';
155 echo ' document.getElementById(\'editdata\'+iddiv).style.display = "block";';
156 echo ' jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id.',action:\'lockfile\',lock:1,fileid:iddiv});';
157 echo ' lockInterval[iddiv] = setInterval("jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id .',action:\'lockfile\',lock:1,fileid:"+iddiv+"})",60000);';
159 echo ' document.getElementById(\'editdata\'+iddiv).style.display = "none";';
160 echo ' jQuery.get(\''. util_make_url('docman') .'\',{group_id:'. $group_id .',action:\'lockfile\',lock:0,fileid:iddiv});';
161 echo ' clearInterval(lockInterval[iddiv]);';
165 echo '<ul style="list-style-type: none">';
166 $child_count = count($nested_groups["$parent_group"]);
168 for ($i=0; $i < $child_count; $i++) {
169 $doc_group =& $nested_groups["$parent_group"][$i];
171 if ($doc_group->hasDocuments($nested_groups, $document_factory, $stateid)) {
172 $icon = 'ofolder15.png';
173 echo '<li>'.html_image('docman/directory.png', '22', '22', array('border'=>'0'))." ".$doc_group->getName()."</li>";
174 docman_display_documents($nested_groups, $document_factory, $is_editor, $stateid, $doc_group->getID());
177 // Display this group's documents
178 // Retrieve all the docs from this category
180 $document_factory->setStateID($stateid);
182 $document_factory->setDocGroupID($doc_group->getID());
183 $docs = $document_factory->getDocuments();
184 if (is_array($docs)) {
185 $docs_count = count($docs);
187 echo "<ul style='list-style-type: none'>";
188 for ($j=0; $j < $docs_count; $j++) {
189 $tooltip = $docs[$j]->getFileName() . " (" .
190 ($docs[$j]->getUpdated() ?
191 date(_('Y-m-d H:i'), $docs[$j]->getUpdated()) :
192 date(_('Y-m-d H:i'),$docs[$j]->getCreated())) .
194 if ($docs[$j]->getFileSize() > 1024) {
195 $tooltip .= floor($docs[$j]->getFileSize()/1024) . "KB";
197 $tooltip .= $docs[$j]->getFileSize() . "B";
199 $tooltip = htmlspecialchars($tooltip);
200 echo '<li>'. html_image('docman/file_type_unknown.png', '22', '22', array("border"=>"0")).
201 $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>';
202 echo "<i>".$docs[$j]->getDescription()."</i><br/>";
203 echo '<div class="docman_div_include" id="editdata'.$docs[$j]->getID().'" style="display:none">';
204 document_editdata($docs[$j]);
214 * @todo - remove the css code
216 function document_editdata(&$document) {
217 global $g, $dirid, $group_id;
218 $dgh = new DocumentGroupHTML($g);
220 exit_error($dgh->getErrorMessage(), 'docman');
222 $dgf = new DocumentGroupFactory($g);
224 exit_error($dgf->getErrorMessage(), 'docman');
227 <div class="docmanDivIncluded">
229 <?php echo _('Document Title:') ?>
231 <?php echo _('Refers to the relatively brief title of the document (e.g. How to use the download server).') ?>
233 <?php echo _('Description:') ?>
235 <?php echo _('A brief description to be placed just under the title.') ?>
238 if ($g->useDocmanSearch())
239 echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
242 <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">
246 <td style="text-align:right;"> <strong><?php echo _('Document Title') ?></strong><?php echo utils_requiredField(); ?>
249 <input type="text" name="title" size="40" maxlength="255" value="<?php echo $document->getName(); ?>" />
250 <?php printf(_('(at least %1$s characters)'), 5) ?>
254 <td style="text-align:right;">
255 <strong><?php echo _('Description') ?></strong><?php echo utils_requiredField(); ?>
258 <input type="text" name="description" size="50" maxlength="255" value="<?php echo $document->getDescription(); ?>" />
259 <?php printf(_('(at least %1$s characters)'), 10) ?>
264 <td style="text-align:right;">
265 <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?>
268 <?php if ($document->isURL()) {
269 echo '<a href="'.inputSpecialchars($d->getFileName()).'">[View File URL]</a>';
271 <a target="_blank" href="../view.php/<?php echo $group_id.'/'.$document->getID().'/'.urlencode($document->getFileName()) ?>"><?php echo $document->getName(); ?></a>
278 if ((!$document->isURL()) && ($document->isText())) {
279 if ($g->useCreateOnline()) {
282 echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
283 switch ($document->getFileType()) {
285 $GLOBALS['editor_was_set_up']=false;
287 /* warning name must be unique */
288 $params['name'] = 'details'.$document->getID();
289 $params['width'] = "800";
290 $params['height'] = "300";
291 $params['body'] = $d->getFileData();
292 $params['group'] = $group_id;
293 plugin_hook("text_editor",$params);
294 if (!$GLOBALS['editor_was_set_up']) {
295 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70" wrap="soft">'. $document->getFileData() .'</textarea><br />';
297 echo '<input type="hidden" name="filetype" value="text/html">';
298 unset($GLOBALS['editor_was_set_up']);
302 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70" wrap="soft">'. $document->getFileData() .'</textarea><br />';
303 echo '<input type="hidden" name="filetype" value="text/plain">';
313 <td style="text-align:right;">
314 <strong><?php echo _('Directory that document belongs in') ?></strong>
317 <?php $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $document->getDocGroupID()); ?>
321 <td style="text-align:right;">
322 <strong><?php echo _('State') ?></strong>
325 <?php doc_get_state_box($document->getStateID()); ?>
329 <td style="text-align:right;">
330 <?php if ($document->isURL()) { ?>
331 <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?>
334 <input type="text" name="file_url" size="50" value="<?php echo $document->getFileName() ?>" />
336 <strong><?php echo _('OPTIONAL: Upload new file') ?></strong>
339 <input type="file" name="uploaded_data" size="30" />
347 <input type="hidden" name="docid" value="<?php echo $document->getID(); ?>" />
348 <input type="submit" id="submiteditdata<?php echo $document->getID(); ?>" value="<?php echo _('Submit Edit') ?>" /><br /><br />