3 * FusionForge Documentation Manager
5 * Copyright 2000, Quentin Cregan/Sourceforge
6 * Copyright 2002-2003, Tim Perdue/GForge, LLC
7 * Copyright 2005, Fabio Bertagnin
8 * Copyright 2010-2011, Franck Villaume - Capgemini
9 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
10 * Copyright 2012, Franck Villaume - TrivialDev
11 * http://fusionforge.org
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 if (!forge_check_perm('docman', $group_id, 'read')) {
34 $return_msg= _('Document Manager Access Denied');
35 session_redirect('/docman/?group_id='.$group_id.'&warning_msg='.urlencode($return_msg));
38 $is_editor = forge_check_perm('docman', $g->getID(), 'approve');
39 $searchString = trim(getStringFromPost("textsearch"));
40 $subprojectsIncluded = getStringFromPost('includesubprojects');
41 $insideDocuments = getStringFromPost('insideDocuments');
44 $includesubprojects = "";
45 $insideDocumentsCheckbox = "";
46 if (getStringFromPost('search_type') == "one") {
47 $onechecked = 'checked="checked"';
49 $allchecked = 'checked="checked"';
52 if ($subprojectsIncluded)
53 $includesubprojects = 'checked="checked"';
56 $insideDocumentsCheckbox = 'checked="checked"';
58 echo '<div class="docmanDivIncluded">';
59 echo '<form method="post" action="?group_id='.$group_id.'&view=search" >';
60 echo '<table width="98%" cellpadding="2" cellspacing="0" border="0">';
61 echo '<tr><td><b>'._('Query: ').'</b>';
62 echo '<input type="text" name="textsearch" id="textsearch" size="48" value="'.$searchString.'" required="required" />';
63 echo '<input type="submit" value="'._('Search').'" />';
64 echo '</td></tr><tr><td>';
65 echo '<input type="radio" name="search_type" required="required" value="all" '.$allchecked.' class="tabtitle-nw" title="'._('All searched words are mandatory').'" />'._('With all the words');
66 echo '<input type="radio" name="search_type" required="required" value="one" '.$onechecked.' class="tabtitle" title="'._('At least one word must be found').'" />'._('With at least one of words');
67 if ($g->useDocmanSearch()) {
68 echo '<input type="checkbox" name="insideDocuments" value="1" '.$insideDocumentsCheckbox.' class="tabtitle" title="'._('Filename and contents are used to match searched words').'" />'._('Inside documents');
70 if ($g->usesPlugin('projects-hierarchy')) {
71 $projectsHierarchy = plugin_get_object('projects-hierarchy');
72 $projectIDsArray = $projectsHierarchy->getFamily($group_id, 'child', true, 'validated');
74 if (isset($projectIDsArray) && is_array($projectIDsArray))
75 echo '<input type="checkbox" name="includesubprojects" value="1" '.$includesubprojects.' class="tabtitle" title="'._('search into childs following project hierarchy').'" />'._('Include child projects');
81 $mots = preg_split("/[\s,]+/",$searchString);
82 $qpa = db_construct_qpa(false, 'SELECT filename, filetype, docid, doc_data.stateid as stateid, doc_states.name as statename, title, description, createdate, updatedate, doc_group, group_id FROM doc_data, doc_states WHERE doc_data.stateid = doc_states.stateid');
83 if (getStringFromPost('search_type') == "one") {
84 if (count($mots) > 0) {
85 $qpa = db_construct_qpa($qpa, ' AND (FALSE');
86 foreach ($mots as $mot) {
87 $mot = strtolower($mot);
88 $qpa = db_construct_qpa($qpa, ' OR title LIKE $1 OR description LIKE $1 ',
91 $qpa = db_construct_qpa($qpa, ' OR data_words LIKE $1 ', array("%$mot%"));
93 $qpa = db_construct_qpa($qpa, ')');
97 if (count($mots) > 0) {
98 $qpa = db_construct_qpa($qpa, ' AND (TRUE');
99 foreach ($mots as $mot) {
100 $mot = strtolower($mot);
101 $qpa = db_construct_qpa($qpa, ' AND (title LIKE $1 OR description LIKE $1 ',
103 if ($insideDocuments)
104 $qpa = db_construct_qpa($qpa, ' OR data_words LIKE $1 ', array("%$mot%"));
105 $qpa = db_construct_qpa($qpa, ' ) ', array());
107 $qpa = db_construct_qpa($qpa, ')');
112 $qpa = db_construct_qpa($qpa, ' AND doc_data.stateid = 1');
114 $qpa = db_construct_qpa($qpa, ' AND doc_data.stateid != 2');
117 $qpa = db_construct_qpa($qpa, ' AND ( group_id = $1', array($group_id));
118 $params['group_id'] = $group_id;
119 $params['qpa'] = &$qpa;
120 $params['includesubprojects'] = $subprojectsIncluded;
121 plugin_hook('docmansearch_has_hierarchy', $params);
122 $qpa = db_construct_qpa($qpa, ' ) ', array());
123 $qpa = db_construct_qpa($qpa, ' ORDER BY updatedate, createdate');
124 $result = db_query_qpa($qpa);
126 echo '<p class="error">'._('Database query error').'</p>';
127 db_free_result($result);
128 } elseif (db_numrows($result) < 1) {
129 echo '<p class="warning_msg">'._('Your search did not match any documents.').'</p>';
130 db_free_result($result);
133 while ($arr = db_fetch_array($result)) {
136 db_free_result($result);
138 echo '<table width="98%" cellpadding="0" cellspacing="0" border="0">';
139 foreach ($resarr as $item) {
141 if ($item['filetype'] == 'URL') {
142 $fileurl = $item["filename"];
144 $fileurl = '/docman/view.php/'.$item["group_id"].'/'.$item["docid"].'/'.urlencode($item["filename"]);
146 echo '<tr><td width="20px" align="right"><b>'.$count.'.</b></td><td><b>'.$item["title"].'</b> (<a href="'.$fileurl.'">'.$item["filename"].'</a>)</td></tr>';
147 echo '<tr><td colspan="2">'.$item["description"].'</td></tr>';
148 $localProject = group_get_object($item['group_id']);
149 $docGroupObject = new DocumentGroup($localProject, $item['doc_group']);
150 echo '<tr><td colspan="2">'._('Status:').'<b>'.$item["statename"].'</b></td></tr>';
151 echo '<tr><td colspan="2">'._('Path:');
152 if ($localProject->getUnixName() != $g->getUnixName()) {
153 $browselink = '/docman/?group_id='.$localProject->getID();
154 echo util_make_link($browselink, $localProject->getPublicName(), array('title' => _('Browse document manager for this project.'), 'class' => 'tabtitle-nw')).'::';
156 echo '<i>'.$docGroupObject->getPath(true, true).'</i></td></tr>';
157 echo '<tr><td colspan="2"> </td></tr>';
162 echo '<p class="warning_msg">'._('Your search is empty.').'</p>';