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-2016, 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.
29 /* please do not add require here : use www/docman/index.php to add require */
30 /* global variables used */
31 global $group_id; // id of the group
32 global $g; // the group object
33 global $dirid; // id of doc_group
34 global $HTML; // Layout object
37 $redirect_url = DOCMAN_BASEURL.$group_id;
38 if (!forge_check_perm('docman', $group_id, 'read')) {
39 $warning_msg = _('Document Manager Access Denied');
40 session_redirect($redirect_url);
43 $searchString = trim(getStringFromRequest('textsearch', null));
44 $insideDocuments = getIntFromRequest('insideDocuments', 0);
45 $subprojectsIncluded = getIntFromRequest('includesubprojects', 0);
46 $limitByStartDate = getIntFromRequest('limitByStartDate', 0);
47 $limitByEndDate = getIntFromRequest('limitByEndDate', 0);
48 $received_begin = getStringFromRequest('start_date', 0);
49 $received_end = getStringFromRequest('end_date', 0);
50 $search_type = getStringFromRequest('search_type', 'all');
51 $insideDocumentsCheckbox = '';
52 $attrsInputSearchAll = array('type' => 'radio', 'name' => 'search_type', 'required' => 'required', 'value' => 'all', 'title' => _('All searched words are mandatory.'));
53 $attrsInputSearchOne = array('type' => 'radio', 'name' => 'search_type', 'required' => 'required', 'value' => 'one', 'title' => _('At least one word must be found.'));
54 $date_format_js = _('yy-mm-dd');
55 $date_format = _('Y-m-d');
57 if ($search_type == 'one') {
58 $attrsInputSearchOne['checked'] = 'checked';
61 $attrsInputSearchAll['checked'] = 'checked';
65 echo html_ao('div', array('id' => 'docman_search', 'class' => 'docmanDivIncluded'));
66 echo html_ao('script', array('type' => 'text/javascript'));
71 jQuery(document).ready(function() {
72 controllerSearch = new DocManSearchController({
73 buttonStartDate: jQuery('#limitByStartDate'),
74 buttonEndDate: jQuery('#limitByEndDate'),
75 datePickerStartDate: jQuery('#datepicker_start'),
76 datePickerEndDate: jQuery('#datepicker_end'),
79 jQuery('#datepicker_start').datepicker({
80 dateFormat: "<?php echo $date_format_js ?>"
82 jQuery('#datepicker_end').datepicker({
83 dateFormat: "<?php echo $date_format_js ?>"
89 echo html_ac(html_ap() - 1);
90 echo $HTML->openForm(array('method' => 'post', 'action' => DOCMAN_BASEURL.$group_id.'&view=search'));
91 echo html_e('div', array('id' => 'docman_search_query_words'),
92 html_e('span', array('id' => 'docman_search_query_label'), _('Query').utils_requiredField()._(': ')).
93 html_e('input', array('type' => 'text', 'name' => 'textsearch', 'id' => 'textsearch', 'size' => 48, 'value' => stripslashes(htmlspecialchars($searchString)), 'required' => 'required', 'placeholder' => _('Searched words'))).
94 html_e('input', array('type' => 'submit', 'value' => _('Search'))));
95 echo html_ao('div', array('id' => 'docman_search_query_ckeckbox'));
96 echo html_e('input', $attrsInputSearchAll)._('With all the words');
97 echo html_e('input', $attrsInputSearchOne)._('With at least one of words');
98 if ($g->useDocmanSearch()) {
99 $attrsInputInsideDocs = array('type' => 'checkbox', 'name' => 'insideDocuments', 'value' => 1, 'title' => _('Filename & contents are used to match searched words.'));
100 if ($insideDocuments) {
101 $attrsInputInsideDocs['checked'] = 'checked';
103 echo html_e('input', $attrsInputInsideDocs)._('Inside documents');
105 $attrsFieldSet = array('id' => 'fieldset1_closed', 'class' => 'coolfieldset');
106 if ($limitByStartDate || $limitByEndDate || $subprojectsIncluded) {
107 $attrsFieldSet['id'] = 'fieldset1';
109 echo html_ao('fieldset', $attrsFieldSet);
110 echo html_e('legend', array(), _('Advanced Options'));
112 if ($g->usesPlugin('projects-hierarchy')) {
113 $projectsHierarchy = plugin_get_object('projects-hierarchy');
114 $projectIDsArray = $projectsHierarchy->getFamily($group_id, 'child', true, 'validated');
115 if (is_array($projectIDsArray)) {
116 $attrsInputIncludeSubprojects = array('type' => 'checkbox', 'name' => 'includesubprojects', 'value' => 1, 'title' => _('Search into childs following project hierarchy.'));
117 if ($subprojectsIncluded) {
118 $attrsInputIncludeSubprojects['checked'] = 'checked';
120 echo html_e('p', array(), html_e('input', $attrsInputIncludeSubprojects)._('Include child projects'));
123 $attrsInputLimitByStartDate = array('type' => 'checkbox', 'id' => 'limitByStartDate', 'name' => 'limitByStartDate', 'value' => 1, 'title' => _('Set created start date limitation for this search. If not enable, no limitation.'));
124 $attrsDatePickerLimitByStartDate = array('id' => 'datepicker_start', 'name' => 'start_date', 'size' => 10, 'maxlength' => 10, 'disabled' => 'disabled');
125 if ($limitByStartDate) {
126 $attrsInputLimitByStartDate['checked'] = 'checked';
127 unset($attrsDatePickerLimitByStartDate['disabled']);
128 $attrsDatePickerLimitByStartDate['required'] = 'required';
129 if ($received_begin) {
130 $attrsDatePickerLimitByStartDate['value'] = util_html_encode($received_begin);
133 $attrsInputLimitByEndDate = array('type' => 'checkbox', 'id' => 'limitByEndDate', 'name' => 'limitByEndDate', 'value' => 1, 'title' => _('Set created end date limitation for this search. If not enable, no limitation.'));
134 $attrsDatePickerLimitByEndDate = array('id' => 'datepicker_end', 'name' => 'end_date', 'size' => 10, 'maxlength' => 10, 'disabled' => 'disabled');
135 if ($limitByEndDate) {
136 $attrsInputLimitByEndDate['checked'] = 'checked';
137 unset($attrsDatePickerLimitByEndDate['disabled']);
138 $attrsDatePickerLimitByEndDate['required'] = 'required';
140 $attrsDatePickerLimitByEndDate['value'] = util_html_encode($received_end);
143 echo html_e('p', array(), _('Set dates')._(': ').html_e('br').
144 _('From')._(': ').html_e('input', $attrsInputLimitByStartDate).html_e('input', $attrsDatePickerLimitByStartDate).
145 _('To')._(': ').html_e('input', $attrsInputLimitByEndDate).html_e('input', $attrsDatePickerLimitByEndDate));
146 echo html_ac(html_ap() - 2);
147 echo $HTML->addRequiredFieldsInfoBox();
148 echo $HTML->closeForm();
149 echo html_ac(html_ap() - 1);
150 echo html_ao('div', array('id' => 'docman_search_query_result'));
151 $search_options = array();
152 if ($received_begin) {
153 $arrDateBegin = DateTime::createFromFormat($date_format, $received_begin);
154 $search_options['date_begin'] = $arrDateBegin->getTimestamp();
157 $arrDateEnd = DateTime::createFromFormat($date_format, $received_end);
158 $search_options['date_end'] = $arrDateEnd->getTimestamp();
160 $search_options['includesubprojects'] = $subprojectsIncluded;
161 $search_options['insideDocuments'] = $insideDocuments;
163 if (session_loggedin()) {
164 if (getStringFromRequest('setpaging')) {
165 /* store paging preferences */
166 $paging = getIntFromRequest('nres');
170 $LUSER->setPreference('paging', $paging);
172 /* logged in users get configurable paging */
173 $paging = (int)$LUSER->getPreference('paging');
176 if(!isset($paging) || !$paging) {
181 $docsHtmlSearchRenderer = new DocsHtmlSearchRenderer($searchString, $start, $isExact, $group_id, SEARCH__ALL_SECTIONS, $paging, $search_options);
182 $result = $docsHtmlSearchRenderer->searchQuery->getData($docsHtmlSearchRenderer->searchQuery->getRowsPerPage(),$docsHtmlSearchRenderer->searchQuery->getOffset());
183 $nbDocs = count($result);
184 $max = $docsHtmlSearchRenderer->searchQuery->getRowsTotalCount();
185 echo $HTML->paging_top($start, $paging, $max, $nbDocs, $redirect_url.'&view=search&textsearch='.urlencode($searchString).'&insideDocuments='.$insideDocuments.'&search_type='.$search_type.'&includesubprojects='.$subprojectsIncluded.'&limitByStartDate='.$limitByStartDate.'&limitByEndDate='.$limitByEndDate.'&start_date='.$received_begin.'&end_date='.$received_end);
186 $docsHtmlSearchRenderer->writeBody(false);
187 echo $HTML->paging_bottom($start, $paging, $max, $redirect_url.'&view=search&textsearch='.urlencode($searchString).'&insideDocuments='.$insideDocuments.'&search_type='.$search_type.'&includesubprojects='.$subprojectsIncluded.'&limitByStartDate='.$limitByStartDate.'&limitByEndDate='.$limitByEndDate.'&start_date='.$received_begin.'&end_date='.$received_end);
189 echo html_ac(html_ap() -2);