5 * Copyright 2004 (c) Dominik Haas, GForge Team
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/pre.php';
25 require_once $gfwww.'search/include/renderers/HtmlGroupSearchRenderer.class.php';
27 class AdvancedSearchHtmlSearchRenderer extends HtmlGroupSearchRenderer {
37 * the words to search for
44 * flag to define whether the result must contain all words or only one of them
46 * @var boolean $isExact
51 * selected parents sections
53 * @var array $selectedParentSections
55 var $selectedParentSections = array();
60 * @param string $words words we are searching for
61 * @param int $offset offset
62 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
63 * @param int $groupId group id
66 function AdvancedSearchHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
67 $this->groupId = $groupId;
68 $this->words = $words;
69 $this->isExact = $isExact;
70 $searchQuery =& $this->searchQuery;
72 $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, $searchQuery, $groupId);
76 * flush - overwrites the flush method from htmlrenderer
85 * writeHeader - write the header of the output
87 function writeHeader() {
88 site_project_header(array('title' => _('Advanced search'), 'group' => $this->groupId, 'toptab'=>'none'));
89 $sectionarray = $this->getSectionArray();
90 $this->handleTransferInformation($sectionarray);
92 echo $this->getAdvancedSearchBox($sectionarray, $this->groupId, $this->words, $this->isExact);
96 * writeBody - write the Body of the output
98 function writeBody() {
99 if (strlen($this->words) < 3) {
100 echo '<div class="error">'._('Error: Under min length search').'</div>';
102 echo $this->getResult();
107 * getResult - returns the Body of the output
109 * @return string result of all selected searches
111 function getResult() {
114 if (in_array('short_forum', $this->selectedParentSections)) {
115 $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_forum'));
116 $html .= $this->getPartResult($renderer, 'short_forum', _('Forum Search Results'));
119 if (in_array('short_tracker', $this->selectedParentSections)) {
120 $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_tracker'));
121 $html .= $this->getPartResult($renderer, 'short_tracker', _('Tracker Search Results'));
124 if (in_array('short_pm', $this->selectedParentSections)) {
125 $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_pm'));
126 $html .= $this->getPartResult($renderer, 'short_pm', _('Task Search Results'));
129 if (in_array('short_docman', $this->selectedParentSections)) {
130 $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_docman'));
131 $html .= $this->getPartResult($renderer, 'short_docman', _('Documentation Search Results'));
134 if (in_array('short_files', $this->selectedParentSections)) {
135 $renderer = new FilesHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_files'));
136 $html .= $this->getPartResult($renderer, 'short_files', _('Files Search Results'));
139 if (in_array('short_news', $this->selectedParentSections)) {
140 $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
141 $html .= $this->getPartResult($renderer, 'short_news', _('News Search Results'));
144 // This is quite complex but the goal is to extract all the
145 // registered plugins to the hook 'search_engines' and call
147 $pluginManager = plugin_manager_get_object();
148 $searchManager = getSearchManager();
149 $engines = $searchManager->getAvailableSearchEngines();
151 if (isset($pluginManager->hooks_to_plugins['search_engines'])) {
152 $p_list = $pluginManager->hooks_to_plugins['search_engines'];
153 foreach ($p_list as $p_name) {
154 $p_obj = $pluginManager->GetPluginObject($p_name);
155 $name = $p_obj->text;
156 if (in_array($p_name, $this->selectedParentSections)) {
158 foreach($engines as $e) {
159 if ($e->type == $p_name) {
160 $renderer = $e->getSearchRenderer($this->words,
161 $this->offset, $this->isExact, $this->groupId);
162 $html .= $this->getPartResult($renderer, 'short_'.$p_name, $name);
169 return $html.'<br />';
173 * getPartResult - returns the result of the given renderer
175 * @return string result of the renderer
177 function getPartResult($renderer, $section, $title='') {
179 $renderer->searchQuery->executeQuery();
185 $result .= '<h2><a name="'.$section.'"></a>'.$title.'</h2>';
187 if ($renderer->searchQuery->getRowsCount() > 0) {
188 if ($renderer->searchQuery->getRowsTotalCount() >= $renderer->searchQuery->getRowsPerPage())
189 $result .= '<i>' . sprintf(_('Note: only the first %d results for this category are displayed.'), $renderer->searchQuery->getRowsPerPage()) . '</i>';
190 $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
191 $result .= $renderer->getRows();
192 $result .= $GLOBALS['HTML']->listTableBottom();
193 } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
194 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em> - No sections available (check your permissions)'), $query['words']).'</p>';
196 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em>'), $query['words']).'</p>';
202 * getSectionArray - creates an array of sections in which the user can search
204 * @return array sections
206 function getSectionArray() {
207 global $gfwww, $gfcommon;
210 $group = group_get_object($this->groupId);
212 if ($group->usesForum()) {
213 require_once $gfwww.'search/include/renderers/ForumsHtmlSearchRenderer.class.php';
214 $undersections = ForumsHtmlSearchRenderer::getSections($this->groupId);
215 if (count($undersections) > 0) {
216 $sections['short_forum'] = $undersections;
220 if ($group->usesTracker()) {
221 require_once $gfwww.'search/include/renderers/TrackersHtmlSearchRenderer.class.php';
222 $undersections = TrackersHtmlSearchRenderer::getSections($this->groupId);
223 if (count($undersections) > 0) {
224 $sections['short_tracker'] = $undersections;
228 if ($group->usesPM()) {
229 require_once $gfwww.'search/include/renderers/TasksHtmlSearchRenderer.class.php';
230 $undersections = TasksHtmlSearchRenderer::getSections($this->groupId);
231 if (count($undersections) > 0) {
232 $sections['short_pm'] = $undersections;
237 if ($group->usesDocman()) {
238 require_once $gfwww.'search/include/renderers/DocsHtmlSearchRenderer.class.php';
239 $undersections = DocsHtmlSearchRenderer::getSections($this->groupId);
240 if (count($undersections) > 0) {
241 $sections['short_docman'] = $undersections;
245 if ($group->usesNews()) {
246 require_once $gfwww.'search/include/renderers/NewsHtmlSearchRenderer.class.php';
247 $sections['short_news'] = true;
250 if ($group->usesFRS()) {
251 require_once $gfwww.'search/include/renderers/FrsHtmlSearchRenderer.class.php';
252 $undersections = FrsHtmlSearchRenderer::getSections($this->groupId);
253 if (count($undersections) > 0) {
254 $sections['short_files'] = $undersections;
258 $pluginManager = plugin_manager_get_object();
259 if (isset($pluginManager->hooks_to_plugins['search_engines'])) {
260 $p_list = $pluginManager->hooks_to_plugins['search_engines'];
261 foreach ($p_list as $p_name) {
262 if ($group->usesPlugin($p_name)) {
263 $p_obj = $pluginManager->GetPluginObject($p_name);
264 $sections[$p_obj->name] = true;
273 * handleTransferInformation - marks parentsections if child is marked and processes cookie information
276 function handleTransferInformation(&$sectionarray) {
277 //get through all sections
278 //if a childsection is marked to search in, mark the parent too
280 $postArray = _getPostArray();
282 foreach($sectionarray as $key => $section) {
283 if(is_array($section)) {
284 foreach ($postArray as $postkey => $postvalue) {
285 if (substr($postkey, 0, strlen($key)) == $key) {
286 $this->selectedParentSections[] = $key;
290 } elseif(isset($postArray[$key])) {
291 $this->selectedParentSections[] = $key;
298 * getSelectedChildSections - gets all selected child sections from the given parentsection
300 * @param string $parentsection the parentsection
302 * @return array all child sections from the parent section the user wants to search in
304 function getSelectedChildSections($parentsection) {
306 $postArray = _getPostArray();
308 foreach($postArray as $key => $value) {
309 if (substr($key, 0, strlen($parentsection)) == $parentsection) {
310 if (strlen(substr($key, strlen($parentsection) , strlen($key))) > 0) {
311 array_push($sections, urldecode(substr($key, strlen($parentsection), strlen($key))));
318 function getAdvancedSearchBox($sectionsArray, $group_id, $words, $isExact) {
320 // display the searchmask
322 <form class="ff" name="advancedsearch" action="'.getStringFromServer('PHP_SELF').'" method="post">
323 <input class="ff" type="hidden" name="search" value="1"/>
324 <input class="ff" type="hidden" name="group_id" value="'.$group_id.'"/>
325 <div align="center"><br />
328 <td class="ff" colspan ="2">
329 <input class="ff" type="text" size="60" name="words" value="'.stripslashes(htmlspecialchars($words)).'" />
330 <input class="ff" type="submit" name="submitbutton" value="'._('Search').'" />
334 <td class="ff" valign="top">
335 <input class="ff" type="radio" name="mode" value="'.SEARCH__MODE_AND.'" '.($isExact ? 'checked="checked"' : '').' />'._('with all words').'
338 <input class="ff" type="radio" name="mode" value="'.SEARCH__MODE_OR.'" '.(!$isExact ? 'checked="checked"' : '').' />'._('with one word').'
341 </table><br /></div>'
342 . $this->createSubSections($sectionsArray) .'
346 //create javascript methods for select none/all
348 <script type="text/javascript">
349 <!-- method for disable/enable checkboxes
350 function setCheckBoxes(parent, checked) {
353 for (var i = 0; i < document.advancedsearch.elements.length; i++)
354 if (document.advancedsearch.elements[i].type == "checkbox")
355 if (document.advancedsearch.elements[i].name.substr(0, parent.length) == parent)
356 document.advancedsearch.elements[i].checked = checked;
364 function createSubSections($sectionsArray) {
365 global $group_subsection_names;
368 foreach ($sectionsArray as $section) {
369 if(is_array($section)) {
370 $countLines += (3 + count ($section));
372 //2 lines one for section name and one for checkbox
378 $breakLimit = ceil($countLines/$maxCol);
379 $break = $breakLimit;
384 <table width="100%" border="0" cellspacing="0" cellpadding="1">
385 <tr class="tableheader">
387 <table width="100%" cellspacing="0" border="0">
388 <tr class="tablecontent">
389 <!--<td colspan="2">'._('Search in').':</td-->
390 <td align="right">'._('Select').' <a href="javascript:setCheckBoxes(\'\', true)">'._('all').'</a> / <a href="javascript:setCheckBoxes(\'\', false)">'._('none').'</a></td>
392 <tr class="tablecontent">
393 <td colspan="3"> </td>
395 <tr valign="top" class="tablecontent align-center">
397 foreach($sectionsArray as $key => $section) {
398 $oldcountlines = $countLines;
399 if (is_array($section)) {
400 $countLines += (3 + count ($section));
405 if ($countLines >= $break) {
406 // if we are closer to the limit with this one included, then
407 // it's better to include it.
408 if (($countCol < $maxCol) && ($countLines - $break) >= ($break - $oldcountlines)) {
409 $return .= '</td><td>';
411 $break += $breakLimit;
415 $return .= '<table width="90%" border="0" cellpadding="1" cellspacing="0">
416 <tr><td><table width="100%" border="0" cellspacing="0" cellpadding="3">
419 <a href="#'.$key.'">'.$group_subsection_names[$key].'</a>'
422 ._('Select').' <a href="javascript:setCheckBoxes(\''.$key.'\', true)">'._('all').'</a> / <a href="javascript:setCheckBoxes(\''.$key.'\', false)">'._('none').'</a>
425 <tr class="tablecontent">
428 if (!is_array($section)) {
429 $return .= ' <input type="checkbox" name="'.urlencode($key).'"';
430 if (isset($GLOBALS[urlencode($key)]))
431 $return .= ' checked="checked" ';
432 $return .= ' /></input>'.$group_subsection_names[$key].'<br />';
435 foreach($section as $underkey => $undersection) {
436 $return .= ' <input type="checkbox" name="'.urlencode($key.$underkey).'"';
437 if (isset($GLOBALS[urlencode($key.$underkey)]))
438 $return .= ' checked="checked" ';
439 $return .= ' />'.$undersection.'<br />';
445 </table></td></tr></table><br />';
447 if ($countLines >= $break) {
448 if (($countLines - $break) < ($break - $countLines)) {
449 $return .= '</td><td width="33%">';
450 $break += $breakLimit;
455 return $return.' </td>
457 </table></td></tr></table>';
465 // c-file-style: "bsd"