3 * FusionForge Documentation Manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2010-2011, Franck Villaume - Capgemini
8 * Copyright 2013, Franck Villaume - TrivialDev
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.
27 /* please do not add require here : use www/docman/index.php to add require */
28 /* global variables used */
29 global $g; //group object
30 global $dirid; //id of doc_group
31 global $group_id; // id of group
33 $redirecturl = '/docman/?group_id='.$group_id.'&view=listfile';
34 if (!forge_check_perm('docman', $group_id, 'approve')) {
35 $return_msg = _('Document Manager Action Denied.');
36 session_redirect($redirecturl.'&dirid='.$dirid.'&warning_msg='.urlencode($return_msg));
39 // plugin projects-hierarchy handler
40 $childgroup_id = getIntFromRequest('childgroup_id');
42 if (!forge_check_perm('docman', $childgroup_id, 'approve')) {
43 $return_msg = _('Document Manager Action Denied.');
44 session_redirect($redirecturl.'&dirid='.$dirid.'&warning_msg='.urlencode($return_msg));
46 $redirecturl .= '&childgroup_id='.$childgroup_id;
47 $g = group_get_object($childgroup_id);
50 /* when moving a document group to trash, it's recursive and it's applied to documents that belong to these document groups */
51 /* Get the document groups info */
52 $df = new DocumentFactory($g);
54 exit_error($df->getErrorMessage(), 'docman');
56 $dgf = new DocumentGroupFactory($g);
58 exit_error($dgf->getErrorMessage(), 'docman');
60 $trashnested_groups =& $dgf->getNested();
62 $df->setDocGroupID($dirid);
63 $d_arr =& $df->getDocuments();
65 $trashnested_docs = array();
66 /* put the doc objects into an array keyed of the docgroup */
67 if (is_array($d_arr)) {
68 foreach ($d_arr as $doc) {
69 $trashnested_docs[$doc->getDocGroupID()][] = $doc;
73 if (is_array($trashnested_groups[$dirid])) {
74 foreach ($trashnested_groups[$dirid] as $dg) {
75 $localdf = new DocumentFactory($g);
76 $localdf->setDocGroupID($dg->getID());
77 $d_arr =& $localdf->getDocuments();
78 if (is_array($d_arr)) {
79 foreach ($d_arr as $doc) {
80 $trashnested_docs[$doc->getDocGroupID()][] = $doc;
86 /* set to trash content of this dirid */
87 docman_recursive_stateid($dirid, $trashnested_groups, $trashnested_docs, 2);
89 /* set this dirid to trash */
90 $dg = new DocumentGroup($g, $dirid);
91 $currentParent = $dg->getParentID();
92 if (!$dg->setStateID('2'))
93 session_redirect($redirecturl.'&error_msg='.urlencode($dg->getErrorMessage()));
95 $dm = new DocumentManager($g);
96 if (!$dg->setParentDocGroupId($dm->getTrashID()))
97 session_redirect($redirecturl.'&dirid='.$currentParent.'&error_msg='.urlencode($dg->getErrorMessage()));
99 $return_msg = sprintf(_('Documents folder %s moved to trash successfully.'),$dg->getName());
100 session_redirect($redirecturl.'&dirid='.$currentParent.'&feedback='.urlencode($return_msg));