5 * Copyright 2004 (c) Dominik Haas, GForge Team
6 * http://fusionforge.org
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 require_once $gfcommon.'include/pre.php';
26 require_once $gfwww.'search/include/renderers/HtmlGroupSearchRenderer.class.php';
28 class AdvancedSearchHtmlSearchRenderer extends HtmlGroupSearchRenderer {
38 * the words to search for
45 * flag to define whether the result must contain all words or only one of them
47 * @var boolean $isExact
52 * selected parents sections
54 * @var array $selectedParentSections
56 var $selectedParentSections = array();
61 * @param string $words words we are searching for
62 * @param int $offset offset
63 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
64 * @param int $groupId group id
67 function AdvancedSearchHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
68 $this->groupId = $groupId;
69 $this->words = $words;
70 $this->isExact = $isExact;
71 $searchQuery =& $this->searchQuery;
73 $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, $searchQuery, $groupId);
77 * flush - overwrites the flush method from htmlrenderer
86 * writeHeader - write the header of the output
88 function writeHeader() {
89 site_project_header(array('title' => _('Advanced search'), 'group' => $this->groupId, 'toptab'=>'none'));
90 $sectionarray = $this->getSectionArray();
91 $this->handleTransferInformation($sectionarray);
93 echo $this->getAdvancedSearchBox($sectionarray, $this->groupId, $this->words, $this->isExact);
97 * writeBody - write the Body of the output
99 function writeBody() {
100 if (strlen($this->words) < 3) {
101 echo '<div class="error">'._('Error: Under min length search').'</div>';
103 echo $this->getResult();
108 * getResult - returns the Body of the output
110 * @return string result of all selected searches
112 function getResult() {
115 if (in_array('short_forum', $this->selectedParentSections)) {
116 $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_forum'));
117 $html .= $this->getPartResult($renderer, 'short_forum', _('Forum Search Results'));
120 if (in_array('short_tracker', $this->selectedParentSections)) {
121 $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_tracker'));
122 $html .= $this->getPartResult($renderer, 'short_tracker', _('Tracker Search Results'));
125 if (in_array('short_pm', $this->selectedParentSections)) {
126 $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_pm'));
127 $html .= $this->getPartResult($renderer, 'short_pm', _('Task Search Results'));
130 if (in_array('short_docman', $this->selectedParentSections)) {
131 $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_docman'));
132 $html .= $this->getPartResult($renderer, 'short_docman', _('Documentation Search Results'));
135 if (in_array('short_files', $this->selectedParentSections)) {
136 $renderer = new FilesHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_files'));
137 $html .= $this->getPartResult($renderer, 'short_files', _('Files Search Results'));
140 if (in_array('short_news', $this->selectedParentSections)) {
141 $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
142 $html .= $this->getPartResult($renderer, 'short_news', _('News Search Results'));
145 // This is quite complex but the goal is to extract all the
146 // registered plugins to the hook 'search_engines' and call
148 $pluginManager = plugin_manager_get_object();
149 $searchManager = getSearchManager();
150 $engines = $searchManager->getAvailableSearchEngines();
152 if (isset($pluginManager->hooks_to_plugins['search_engines'])) {
153 $p_list = $pluginManager->hooks_to_plugins['search_engines'];
154 foreach ($p_list as $p_name) {
155 $p_obj = $pluginManager->GetPluginObject($p_name);
156 $name = $p_obj->text;
157 if (in_array($p_name, $this->selectedParentSections)) {
159 foreach($engines as $e) {
160 if ($e->type == $p_name) {
161 $renderer = $e->getSearchRenderer($this->words,
162 $this->offset, $this->isExact, $this->groupId);
163 $html .= $this->getPartResult($renderer, 'short_'.$p_name, $name);
170 return $html.'<br />';
174 * getPartResult - returns the result of the given renderer
176 * @return string result of the renderer
178 function getPartResult($renderer, $section, $title='') {
180 $renderer->searchQuery->executeQuery();
186 $result .= '<h2><a name="'.$section.'"></a>'.$title.'</h2>';
188 if ($renderer->searchQuery->getRowsCount() > 0) {
189 if ($renderer->searchQuery->getRowsTotalCount() >= $renderer->searchQuery->getRowsPerPage())
190 $result .= '<i>' . sprintf(_('Note: only the first %d results for this category are displayed.'), $renderer->searchQuery->getRowsPerPage()) . '</i>';
191 $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
192 $result .= $renderer->getRows();
193 $result .= $GLOBALS['HTML']->listTableBottom();
194 } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
195 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em> - No sections available (check your permissions)'), $query['words']).'</p>';
197 $result .= '<p>'.sprintf(_('No matches found for <em>%s</em>'), $query['words']).'</p>';
203 * getSectionArray - creates an array of sections in which the user can search
205 * @return array sections
207 function getSectionArray() {
208 global $gfwww, $gfcommon;
211 $group =& group_get_object($this->groupId);
213 if ($group->usesForum()) {
214 require_once $gfwww.'search/include/renderers/ForumsHtmlSearchRenderer.class.php';
215 $undersections = ForumsHtmlSearchRenderer::getSections($this->groupId);
216 if (count($undersections) > 0) {
217 $sections['short_forum'] = $undersections;
221 if ($group->usesTracker()) {
222 require_once $gfwww.'search/include/renderers/TrackersHtmlSearchRenderer.class.php';
223 $undersections = TrackersHtmlSearchRenderer::getSections($this->groupId);
224 if (count($undersections) > 0) {
225 $sections['short_tracker'] = $undersections;
229 if ($group->usesPM()) {
230 require_once $gfwww.'search/include/renderers/TasksHtmlSearchRenderer.class.php';
231 $undersections = TasksHtmlSearchRenderer::getSections($this->groupId);
232 if (count($undersections) > 0) {
233 $sections['short_pm'] = $undersections;
238 if ($group->usesDocman()) {
239 require_once $gfwww.'search/include/renderers/DocsHtmlSearchRenderer.class.php';
240 $undersections = DocsHtmlSearchRenderer::getSections($this->groupId);
241 if (count($undersections) > 0) {
242 $sections['short_docman'] = $undersections;
246 if ($group->usesNews()) {
247 require_once $gfwww.'search/include/renderers/NewsHtmlSearchRenderer.class.php';
248 $sections['short_news'] = true;
251 if ($group->usesFRS()) {
252 require_once $gfwww.'search/include/renderers/FrsHtmlSearchRenderer.class.php';
253 $undersections = FrsHtmlSearchRenderer::getSections($this->groupId);
254 if (count($undersections) > 0) {
255 $sections['short_files'] = $undersections;
259 $pluginManager = plugin_manager_get_object();
260 if (isset($pluginManager->hooks_to_plugins['search_engines'])) {
261 $p_list = $pluginManager->hooks_to_plugins['search_engines'];
262 foreach ($p_list as $p_name) {
263 if ($group->usesPlugin($p_name)) {
264 $p_obj = $pluginManager->GetPluginObject($p_name);
265 $sections[$p_obj->name] = true;
274 * handleTransferInformation - marks parentsections if child is marked and processes cookie information
277 function handleTransferInformation(&$sectionarray) {
278 //get through all sections
279 //if a childsection is marked to search in, mark the parent too
281 $postArray = _getPostArray();
283 foreach($sectionarray as $key => $section) {
284 if(is_array($section)) {
285 foreach ($postArray as $postkey => $postvalue) {
286 if (substr($postkey, 0, strlen($key)) == $key) {
287 $this->selectedParentSections[] = $key;
291 } elseif(isset($postArray[$key])) {
292 $this->selectedParentSections[] = $key;
299 * getSelectedChildSections - gets all selected child sections from the given parentsection
301 * @param string $parentsection the parentsection
303 * @return array all child sections from the parent section the user wants to search in
305 function getSelectedChildSections($parentsection) {
307 $postArray = _getPostArray();
309 foreach($postArray as $key => $value) {
310 if (substr($key, 0, strlen($parentsection)) == $parentsection) {
311 if (strlen(substr($key, strlen($parentsection) , strlen($key))) > 0) {
312 array_push($sections, urldecode(substr($key, strlen($parentsection), strlen($key))));
319 function getAdvancedSearchBox($sectionsArray, $group_id, $words, $isExact) {
321 // display the searchmask
323 <form class="ff" name="advancedsearch" action="'.getStringFromServer('PHP_SELF').'" method="post">
324 <input class="ff" type="hidden" name="search" value="1"/>
325 <input class="ff" type="hidden" name="group_id" value="'.$group_id.'"/>
326 <div align="center"><br />
329 <td class="ff" colspan ="2">
330 <input class="ff" type="text" size="60" name="words" value="'.stripslashes(htmlspecialchars($words)).'" />
331 <input class="ff" type="submit" name="submitbutton" value="'._('Search').'" />
335 <td class="ff" valign="top">
336 <input class="ff" type="radio" name="mode" value="'.SEARCH__MODE_AND.'" '.($isExact ? 'checked="checked"' : '').' />'._('with all words').'
339 <input class="ff" type="radio" name="mode" value="'.SEARCH__MODE_OR.'" '.(!$isExact ? 'checked="checked"' : '').' />'._('with one word').'
342 </table><br /></div>'
343 . $this->createSubSections($sectionsArray) .'
347 //create javascript methods for select none/all
349 <script type="text/javascript">
350 <!-- method for disable/enable checkboxes
351 function setCheckBoxes(parent, checked) {
354 for (var i = 0; i < document.advancedsearch.elements.length; i++)
355 if (document.advancedsearch.elements[i].type == "checkbox")
356 if (document.advancedsearch.elements[i].name.substr(0, parent.length) == parent)
357 document.advancedsearch.elements[i].checked = checked;
365 function createSubSections($sectionsArray) {
366 global $group_subsection_names;
369 foreach ($sectionsArray as $section) {
370 if(is_array($section)) {
371 $countLines += (3 + count ($section));
373 //2 lines one for section name and one for checkbox
379 $breakLimit = ceil($countLines/$maxCol);
380 $break = $breakLimit;
385 <table width="100%" border="0" cellspacing="0" cellpadding="1">
386 <tr class="tableheader">
388 <table width="100%" cellspacing="0" border="0">
389 <tr class="tablecontent">
390 <!--<td colspan="2">'._('Search in').':</td-->
391 <td align="right">'._('Select').' <a href="javascript:setCheckBoxes(\'\', true)">'._('all').'</a> / <a href="javascript:setCheckBoxes(\'\', false)">'._('none').'</a></td>
393 <tr class="tablecontent">
394 <td colspan="3"> </td>
396 <tr valign="top" class="tablecontent align-center">
398 foreach($sectionsArray as $key => $section) {
399 $oldcountlines = $countLines;
400 if (is_array($section)) {
401 $countLines += (3 + count ($section));
406 if ($countLines >= $break) {
407 // if we are closer to the limit with this one included, then
408 // it's better to include it.
409 if (($countCol < $maxCol) && ($countLines - $break) >= ($break - $oldcountlines)) {
410 $return .= '</td><td>';
412 $break += $breakLimit;
416 $return .= '<table width="90%" border="0" cellpadding="1" cellspacing="0">
417 <tr><td><table width="100%" border="0" cellspacing="0" cellpadding="3">
420 <a href="#'.$key.'">'.$group_subsection_names[$key].'</a>'
423 ._('Select').' <a href="javascript:setCheckBoxes(\''.$key.'\', true)">'._('all').'</a> / <a href="javascript:setCheckBoxes(\''.$key.'\', false)">'._('none').'</a>
426 <tr class="tablecontent">
429 if (!is_array($section)) {
430 $return .= ' <input type="checkbox" name="'.urlencode($key).'"';
431 if (isset($GLOBALS[urlencode($key)]))
432 $return .= ' checked="checked" ';
433 $return .= ' /></input>'.$group_subsection_names[$key].'<br />';
436 foreach($section as $underkey => $undersection) {
437 $return .= ' <input type="checkbox" name="'.urlencode($key.$underkey).'"';
438 if (isset($GLOBALS[urlencode($key.$underkey)]))
439 $return .= ' checked="checked" ';
440 $return .= ' />'.$undersection.'<br />';
446 </table></td></tr></table><br />';
448 if ($countLines >= $break) {
449 if (($countLines - $break) < ($break - $countLines)) {
450 $return .= '</td><td width="33%">';
451 $break += $breakLimit;
456 return $return.' </td>
458 </table></td></tr></table>';
466 // c-file-style: "bsd"