3 * FusionForge document manager
5 * Copyright 2011, Franck Villaume - TrivialDev
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once $gfcommon.'include/Error.class.php';
25 require_once $gfcommon.'docman/DocumentGroup.class.php';
27 class DocumentManager extends Error {
30 * Associative array of data from db.
32 * @var array $data_array.
46 * @param object The Group object to which this document is associated.
47 * @return boolean success.
49 function DocumentManager(&$Group) {
51 if (!$Group || !is_object($Group)) {
52 $this->setNotValidGroupObjectError();
55 if ($Group->isError()) {
56 $this->setError('DocumentManager:: '. $Group->getErrorMessage());
59 $this->Group =& $Group;
65 * getGroup - get the Group object this Document is associated with.
67 * @return Object The Group object.
69 function &getGroup() {
75 * getTrashID - the trash doc_group id for this DocumentManager.
77 * @return integer The trash doc_group id.
79 function getTrashID() {
80 if (isset($this->data_array['trashid']))
81 return $this->data_array['trashid'];
83 $res = db_query_params('SELECT doc_group from doc_groups
87 array('.trash', $this->Group->getID(), '2'));
88 if (db_numrows($res) == 1) {
89 $arr = db_fetch_array($res);
90 $this->data_array['trashid'] = $arr['doc_group'];
91 return $this->data_array['trashid'];
93 $dg = new DocumentGroup($this->Group);
94 $dg->create('.trash');
102 * cleanTrash - delete all items in trash for this DocumentManager
104 * @return boolean true on success
106 function cleanTrash() {
107 $trashId = $this->getTrashID();
108 if ($trashId !== -1) {
110 $emptyFile = db_query_params('DELETE FROM doc_data WHERE stateid=$1 and group_id=$2', array('2', $this->Group->getID()));
115 $emptyDir = db_query_params('DELETE FROM doc_groups WHERE stateid=$1 and group_id=$2 and groupname !=$3', array('2', $this->Group->getID(), '.trash'));
127 * getTree - display recursively the content of the doc_group. Only doc_groups within doc_groups.
129 * @param integer the selected directory
130 * @param string the type of link in the menu
131 * @param integer the doc_group to start: default 0
133 function getTree($selecteddir, $linkmenu, $docGroupId = 0) {
134 global $g; // the master group of all the groups .... anyway.
135 $dg = new DocumentGroup($this->Group);
137 case "listtrashfile": {
146 $subGroupIdArr = $dg->getSubgroup($docGroupId, $stateId);
147 if (sizeof($subGroupIdArr)) {
149 foreach ($subGroupIdArr as $subGroupIdValue) {
150 $localDg = new DocumentGroup($this->Group, $subGroupIdValue);
151 $liclass = 'docman_li_treecontent';
152 if ($selecteddir == $localDg->getID()) {
153 $liclass = 'docman_li_treecontent_selected';
155 if ($this->Group->getID() != $g->getID()) {
156 $link = '/docman/?group_id='.$g->getID().'&view='.$linkmenu.'&dirid='.$localDg->getID().'&childgroup_id='.$this->Group->getID();
158 $link = '/docman/?group_id='.$this->Group->getID().'&view='.$linkmenu.'&dirid='.$localDg->getID();
161 $nbDocs = $localDg->getNumberOfDocuments($stateId);
162 if ($stateId == 1 && forge_check_perm('docman', $this->Group->getID(), 'approve'))
163 $nbDocsPending = $localDg->getNumberOfDocuments(3);
165 if ($nbDocs && (!isset($nbDocsPending) || $nbDocsPending == 0)) {
166 $nbDocsLabel = '('.$nbDocs.')';
167 } elseif (isset($nbDocsPending) && $nbDocsPending) {
168 $nbDocsLabel = '('.$nbDocs.'/'.$nbDocsPending.')';
170 echo '<li class="'.$liclass.'">'.util_make_link($link, $localDg->getName()).$nbDocsLabel.'</li>';
171 $this->getTree($selecteddir, $linkmenu, $subGroupIdValue);