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) {
146 if (!array_key_exists("$parent_group", $nested_groups) || !is_array($nested_groups["$parent_group"])) {
150 echo '<script type="text/javascript">';
151 echo 'function EditData(iddiv) {';
152 echo ' if ( "none" == document.getElementById(iddiv).style.display ) {';
153 echo ' document.getElementById(iddiv).style.display = "block";';
155 echo ' document.getElementById(iddiv).style.display = "none";';
159 echo '<ul style="list-style-type: none">';
160 $child_count = count($nested_groups["$parent_group"]);
162 for ($i=0; $i < $child_count; $i++) {
163 $doc_group =& $nested_groups["$parent_group"][$i];
165 if ($doc_group->hasDocuments($nested_groups, $document_factory, $stateid)) {
166 $icon = 'ofolder15.png';
167 echo '<li>'.html_image('docman/directory.png', '22', '22', array('border'=>'0'))." ".$doc_group->getName()."</li>";
168 docman_display_documents($nested_groups, $document_factory, $is_editor, $stateid, $doc_group->getID());
171 // Display this group's documents
172 // Retrieve all the docs from this category
174 $document_factory->setStateID($stateid);
176 $document_factory->setDocGroupID($doc_group->getID());
177 $docs = $document_factory->getDocuments();
178 if (is_array($docs)) {
179 $docs_count = count($docs);
181 echo "<ul style='list-style-type: none'>";
182 for ($j=0; $j < $docs_count; $j++) {
183 $tooltip = $docs[$j]->getFileName() . " (" .
184 ($docs[$j]->getUpdated() ?
185 date(_('Y-m-d H:i'), $docs[$j]->getUpdated()) :
186 date(_('Y-m-d H:i'),$docs[$j]->getCreated())) .
188 if ($docs[$j]->getFileSize() > 1024) {
189 $tooltip .= floor($docs[$j]->getFileSize()/1024) . "KB";
191 $tooltip .= $docs[$j]->getFileSize() . "B";
193 $tooltip = htmlspecialchars($tooltip);
194 echo '<li>'. html_image('docman/file_type_unknown.png', '22', '22', array("border"=>"0")).
195 $docs[$j]->getName(). ' - ' . $tooltip . ' <a href="#" onclick="javascript:EditData(\'editdata'.$docs[$j]->getID().'\')" >'. html_image('docman/edit-file.png', '22', '22', array('alt'=>'editfile')) .'</a></li>';
196 echo "<i>".$docs[$j]->getDescription()."</i><br/>";
197 echo '<div class="docman_div_include" id="editdata'.$docs[$j]->getID().'" style="display:none">';
198 document_editdata($docs[$j]);
208 * @todo - remove the css code
210 function document_editdata(&$document) {
211 global $g, $dirid, $group_id;
212 $dgh = new DocumentGroupHTML($g);
214 exit_error($dgh->getErrorMessage(), 'docman');
216 $dgf = new DocumentGroupFactory($g);
218 exit_error($dgf->getErrorMessage(), 'docman');
221 <div class="docmanDivIncluded">
223 <?php echo _('Document Title:') ?>
225 <?php echo _(' Refers to the relatively brief title of the document (e.g. How to use the download server).') ?>
227 <?php echo _('Description:') ?>
229 <?php echo _(' A brief description to be placed just under the title.') ?>
232 if ($g->useDocmanSearch())
233 echo '<p>'. _('Both fields are used by document search engine.'). '</p>';
236 <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">
240 <td style="text-align:right;"> <strong><?php echo _('Document Title') ?></strong><?php echo utils_requiredField(); ?>
243 <input type="text" name="title" size="40" maxlength="255" value="<?php echo $document->getName(); ?>" />
244 <?php printf(_('(at least %1$s characters)'), 5) ?>
248 <td style="text-align:right;">
249 <strong><?php echo _('Description') ?></strong><?php echo utils_requiredField(); ?>
252 <input type="text" name="description" size="50" maxlength="255" value="<?php echo $document->getDescription(); ?>" />
253 <?php printf(_('(at least %1$s characters)'), 10) ?>
258 <td style="text-align:right;">
259 <strong><?php echo _('File')?></strong><?php echo utils_requiredField(); ?>
262 <?php if ($document->isURL()) {
263 echo '<a href="'.inputSpecialchars($d->getFileName()).'">[View File URL]</a>';
265 <a target="_blank" href="../view.php/<?php echo $group_id.'/'.$document->getID().'/'.urlencode($document->getFileName()) ?>"><?php echo $document->getName(); ?></a>
272 if ((!$document->isURL()) && ($document->isText())) {
273 if ($g->useCreateOnline()) {
276 echo _('Edit the contents to your desire or leave them as they are to remain unmodified.');
277 switch ($document->getFileType()) {
279 $GLOBALS['editor_was_set_up']=false;
281 /* warning name must be unique */
282 $params['name'] = 'details'.$document->getID();
283 $params['width'] = "800";
284 $params['height'] = "300";
285 $params['body'] = $d->getFileData();
286 $params['group'] = $group_id;
287 plugin_hook("text_editor",$params);
288 if (!$GLOBALS['editor_was_set_up']) {
289 echo '<textarea name="details'.$document->getID().'" rows="15" cols="70" wrap="soft">'. $document->getFileData() .'</textarea><br />';
291 echo '<input type="hidden" name="filetype" value="text/html">';
292 unset($GLOBALS['editor_was_set_up']);
296 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/plain">';
307 <td style="text-align:right;">
308 <strong><?php echo _('Directory that document belongs in') ?></strong>
311 <?php $dgh->showSelectNestedGroups($dgf->getNested(), 'doc_group', false, $document->getDocGroupID()); ?>
315 <td style="text-align:right;">
316 <strong><?php echo _('State') ?></strong>
319 <?php doc_get_state_box($document->getStateID()); ?>
323 <td style="text-align:right;">
324 <?php if ($document->isURL()) { ?>
325 <strong><?php echo _('Specify an outside URL where the file will be referenced') ?> :</strong><?php echo utils_requiredField(); ?>
328 <input type="text" name="file_url" size="50" value="<?php echo $document->getFileName() ?>" />
330 <strong><?php echo _('OPTIONAL: Upload new file') ?></strong>
333 <input type="file" name="uploaded_data" size="30" />
341 <input type="hidden" name="docid" value="<?php echo $document->getID(); ?>" />
342 <input type="submit" id="submiteditdata<?php echo $document->getID(); ?>" value="<?php echo _('Submit Edit') ?>" /><br /><br />