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 $this->setError('DocumentManager:: trash not found');
99 * cleanTrash - delete all items in trash for this DocumentManager
101 * @return boolean true on success
103 function cleanTrash() {
104 $trashId = $this->getTrashID();
105 if ($trashId !== -1) {
107 $emptyFile = db_query_params('DELETE FROM doc_data WHERE stateid=$1 and group_id=$2', array('2', $this->Group->getID()));
112 $emptyDir = db_query_params('DELETE FROM doc_groups WHERE stateid=$1 and group_id=$2 and groupname !=$3', array('2', $this->Group->getID(), '.trash'));
124 * getTree - display recursively the content of the doc_group. Only doc_groups within doc_groups.
126 * @param string the type of link in the menu
127 * @param int the doc_group to start: default 0
129 function getTree($linkmenu, $docGroupId = 0) {
130 $dg = new DocumentGroup($this->Group);
132 case "listtrashfile": {
141 $subGroupIdArr = $dg->getSubgroup($docGroupId, $stateId);
142 if (!empty($subGroupIdArr)) {
144 foreach ($subGroupIdArr as $subGroupIdValue) {
145 $localDg = new DocumentGroup($this->Group, $subGroupIdValue);
146 echo '<li><a href="?group_id='.$this->Group->getID().'&view='.$linkmenu.'&dirid='.$localDg->getID().'">'.$localDg->getName().'</a>';
147 $this->getTree($linkmenu, $subGroupIdValue);