6 * Copyright 2004 (c) Dominik Haas, GForge Team
12 require_once $gfwww.'include/pre.php';
13 require_once $gfwww.'search/include/renderers/HtmlGroupSearchRenderer.class.php';
15 class AdvancedSearchHtmlSearchRenderer extends HtmlGroupSearchRenderer {
25 * the words to search for
32 * flag to define whether the result must contain all words or only one of them
34 * @var boolean $isExact
39 * selected parents sections
41 * @var array $selectedParentSections
43 var $selectedParentSections = array();
48 * @param string $words words we are searching for
49 * @param int $offset offset
50 * @param boolean $isExact if we want to search for all the words or if only one matching the query is sufficient
51 * @param int $groupId group id
54 function AdvancedSearchHtmlSearchRenderer($words, $offset, $isExact, $groupId) {
55 $this->groupId = $groupId;
56 $this->words = $words;
57 $this->isExact = $isExact;
58 $searchQuery =& $this->searchQuery;
60 $this->HtmlGroupSearchRenderer(SEARCH__TYPE_IS_ADVANCED, $words, $isExact, $searchQuery, $groupId);
64 * flush - overwrites the flush method from htmlrenderer
73 * writeHeader - write the header of the output
75 function writeHeader() {
76 site_project_header(array('title' => _('Advanced search'), 'group' => $this->groupId, 'toptab'=>'none'));
77 $sectionarray = $this->getSectionArray();
78 $this->handleTransferInformation($sectionarray);
80 echo $this->getAdvancedSearchBox($sectionarray, $this->groupId, $this->words, $this->isExact);
84 * writeBody - write the Body of the output
86 function writeBody() {
87 if (strlen($this->words) < 3) {
88 echo '<br><h1>'._('Error: Under min length search').'</h1><br />';
90 echo $this->getResult();
95 * getResult - returns the Body of the output
97 * @return string result of all selected searches
99 function getResult() {
102 if (in_array('short_forum', $this->selectedParentSections)) {
103 $renderer = new ForumsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_forum'));
104 $html .= $this->getPartResult($renderer, 'short_forum', _('Forum Search Results'));
107 if (in_array('short_tracker', $this->selectedParentSections)) {
108 $renderer = new TrackersHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_tracker'));
109 $html .= $this->getPartResult($renderer, 'short_tracker', _('Tracker Search Results'));
112 if (in_array('short_pm', $this->selectedParentSections)) {
113 $renderer = new TasksHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_pm'));
114 $html .= $this->getPartResult($renderer, 'short_pm', _('Task Search Results'));
117 if (in_array('short_docman', $this->selectedParentSections)) {
118 $renderer = new DocsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_docman'));
119 $html .= $this->getPartResult($renderer, 'short_docman', _('Documentation Search Results'));
122 if (in_array('short_files', $this->selectedParentSections)) {
123 $renderer = new FilesHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId, $this->getSelectedChildSections('short_files'));
124 $html .= $this->getPartResult($renderer, 'short_files', _('Files Search Results'));
127 if (in_array('short_news', $this->selectedParentSections)) {
128 $renderer = new NewsHtmlSearchRenderer($this->words, $this->offset, $this->isExact, $this->groupId);
129 $html .= $this->getPartResult($renderer, 'short_news', _('News Search Results'));
132 // This is quite complex but the goal is to extract all the
133 // registered plugins to the hook 'search_engines' and call
135 $pluginManager = plugin_manager_get_object();
136 $searchManager = getSearchManager();
137 $engines = $searchManager->getAvailableSearchEngines();
139 if (isset($pluginManager->hooks_to_plugins['search_engines'])) {
140 $p_list = $pluginManager->hooks_to_plugins['search_engines'];
141 foreach ($p_list as $p_name) {
142 $p_obj = $pluginManager->GetPluginObject($p_name);
143 $name = $p_obj->text;
144 if (in_array($p_name, $this->selectedParentSections)) {
146 foreach($engines as $e) {
147 if ($e->type == $p_name) {
148 $renderer = $e->getSearchRenderer($this->words,
149 $this->offset, $this->isExact, $this->groupId);
150 $html .= $this->getPartResult($renderer, 'short_'.$p_name, $name);
157 return $html.'<br />';
161 * getPartResult - returns the result of the given renderer
163 * @return string result of the renderer
165 function getPartResult($renderer, $section, $title='') {
167 $renderer->searchQuery->executeQuery();
173 $result .= '<h3><a name="'.$section.'"></a>'.$title.'</h3>';
175 if ($renderer->searchQuery->getRowsCount() > 0) {
176 if ($renderer->searchQuery->getRowsTotalCount() >= $renderer->searchQuery->getRowsPerPage())
177 $result .= '<i>' . sprintf(_('Note: only the first %d results for this category are displayed.'), $renderer->searchQuery->getRowsPerPage()) . '</i>';
178 $result .= $GLOBALS['HTML']->listTabletop($renderer->tableHeaders);
179 $result .= $renderer->getRows();
180 $result .= $GLOBALS['HTML']->listTableBottom();
181 } elseif(method_exists($renderer, 'getSections') && (count($renderer->getSections($this->groupId)) == 0)) {
182 $result .= '<p>'.sprintf(_('No matches found - No sections available (check your permissions)'), htmlspecialchars($query['words'])).'</p>';
184 $result .= '<p>'.sprintf(_('No matches found'), htmlspecialchars($query['words'])).'</p>';
190 * getSectionArray - creates an array of sections in which the user can search
192 * @return array sections
194 function getSectionArray() {
195 global $gfwww, $gfcommon;
198 $group =& group_get_object($this->groupId);
200 if ($group->usesForum()) {
201 require_once $gfwww.'search/include/renderers/ForumsHtmlSearchRenderer.class.php';
202 $undersections = ForumsHtmlSearchRenderer::getSections($this->groupId);
203 if (count($undersections) > 0) {
204 $sections['short_forum'] = $undersections;
208 if ($group->usesTracker()) {
209 require_once $gfwww.'search/include/renderers/TrackersHtmlSearchRenderer.class.php';
210 $undersections = TrackersHtmlSearchRenderer::getSections($this->groupId);
211 if (count($undersections) > 0) {
212 $sections['short_tracker'] = $undersections;
216 if ($group->usesPM()) {
217 require_once $gfwww.'search/include/renderers/TasksHtmlSearchRenderer.class.php';
218 $undersections = TasksHtmlSearchRenderer::getSections($this->groupId);
219 if (count($undersections) > 0) {
220 $sections['short_pm'] = $undersections;
225 if ($group->usesDocman()) {
226 require_once $gfwww.'search/include/renderers/DocsHtmlSearchRenderer.class.php';
227 $undersections = DocsHtmlSearchRenderer::getSections($this->groupId);
228 if (count($undersections) > 0) {
229 $sections['short_docman'] = $undersections;
233 if ($group->usesNews()) {
234 require_once $gfwww.'search/include/renderers/NewsHtmlSearchRenderer.class.php';
235 $sections['short_news'] = true;
238 if ($group->usesFRS()) {
239 require_once $gfwww.'search/include/renderers/FrsHtmlSearchRenderer.class.php';
240 $undersections = FrsHtmlSearchRenderer::getSections($this->groupId);
241 if (count($undersections) > 0) {
242 $sections['short_files'] = $undersections;
246 $pluginManager = plugin_manager_get_object();
247 if (isset($pluginManager->hooks_to_plugins['search_engines'])) {
248 $p_list = $pluginManager->hooks_to_plugins['search_engines'];
249 foreach ($p_list as $p_name) {
250 if ($group->usesPlugin($p_name)) {
251 $p_obj = $pluginManager->GetPluginObject($p_name);
252 $sections[$p_obj->name] = true;
261 * handleTransferInformation - marks parentsections if child is marked and processes cookie information
264 function handleTransferInformation(&$sectionarray) {
265 //get through all sections
266 //if a childsection is marked to search in, mark the parent too
268 $postArray = _getPostArray();
270 foreach($sectionarray as $key => $section) {
271 if(is_array($section)) {
272 foreach ($postArray as $postkey => $postvalue) {
273 if (substr($postkey, 0, strlen($key)) == $key) {
274 $this->selectedParentSections[] = $key;
278 } elseif(isset($postArray[$key])) {
279 $this->selectedParentSections[] = $key;
286 * getSelectedChildSections - gets all selected child sections from the given parentsection
288 * @param string $parentsection the parentsection
290 * @return array all child sections from the parent section the user wants to search in
292 function getSelectedChildSections($parentsection) {
294 $postArray = _getPostArray();
296 foreach($postArray as $key => $value) {
297 if (substr($key, 0, strlen($parentsection)) == $parentsection) {
298 if (strlen(substr($key, strlen($parentsection) , strlen($key))) > 0) {
299 array_push($sections, urldecode(substr($key, strlen($parentsection), strlen($key))));
306 function getAdvancedSearchBox($sectionsArray, $group_id, $words, $isExact) {
308 // display the searchmask
310 <form class="ff" name="advancedsearch" action="'.getStringFromServer('PHP_SELF').'" method="post">
311 <input class="ff" type="hidden" name="search" value="1"/>
312 <input class="ff" type="hidden" name="group_id" value="'.$group_id.'"/>
313 <div align="center"><br />
316 <td class="ff" colspan ="2">
317 <input class="ff" type="text" size="60" name="words" value="'.stripslashes(htmlspecialchars($words)).'" />
318 <input class="ff" type="submit" name="submitbutton" value="'._('Search').'" />
322 <td class="ff" valign="top">
323 <input class="ff" type="radio" name="mode" value="'.SEARCH__MODE_AND.'" '.($isExact ? 'checked="checked"' : '').' />'._('with all words').'
326 <input class="ff" type="radio" name="mode" value="'.SEARCH__MODE_OR.'" '.(!$isExact ? 'checked="checked"' : '').' />'._('with one word').'
329 </table><br /></div>'
330 . $this->createSubSections($sectionsArray) .'
334 //create javascript methods for select none/all
336 <script type="text/javascript">
337 <!-- method for disable/enable checkboxes
338 function setCheckBoxes(parent, checked) {
341 for (var i = 0; i < document.advancedsearch.elements.length; i++)
342 if (document.advancedsearch.elements[i].type == "checkbox")
343 if (document.advancedsearch.elements[i].name.substr(0, parent.length) == parent)
344 document.advancedsearch.elements[i].checked = checked;
352 function createSubSections($sectionsArray) {
353 global $group_subsection_names;
356 foreach ($sectionsArray as $section) {
357 if(is_array($section)) {
358 $countLines += (3 + count ($section));
360 //2 lines one for section name and one for checkbox
366 $breakLimit = ceil($countLines/$maxCol);
367 $break = $breakLimit;
372 <table width="100%" border="0" cellspacing="0" cellpadding="1">
373 <tr class="tableheader">
375 <table width="100%" cellspacing="0" border="0">
376 <tr class="tablecontent">
377 <!--<td colspan="2">'._('Search in').':</td-->
378 <td align="right">'._('Select').' <a href="javascript:setCheckBoxes(\'\', true)">'._('all').'</a> / <a href="javascript:setCheckBoxes(\'\', false)">'._('none').'</a></td>
380 <tr class="tablecontent">
381 <td colspan="3"> </td>
383 <tr valign="top" class="tablecontent align-center">
385 foreach($sectionsArray as $key => $section) {
386 $oldcountlines = $countLines;
387 if (is_array($section)) {
388 $countLines += (3 + count ($section));
393 if ($countLines >= $break) {
394 // if we are closer to the limit with this one included, then
395 // it's better to include it.
396 if (($countCol < $maxCol) && ($countLines - $break) >= ($break - $oldcountlines)) {
397 $return .= '</td><td>';
399 $break += $breakLimit;
403 $return .= '<table width="90%" border="0" cellpadding="1" cellspacing="0">
404 <tr><td><table width="100%" border="0" cellspacing="0" cellpadding="3">
407 <a href="#'.$key.'">'.$group_subsection_names[$key].'</a>'
410 ._('Select').' <a href="javascript:setCheckBoxes(\''.$key.'\', true)">'._('all').'</a> / <a href="javascript:setCheckBoxes(\''.$key.'\', false)">'._('none').'</a>
413 <tr class="tablecontent">
416 if (!is_array($section)) {
417 $return .= ' <input type="checkbox" name="'.urlencode($key).'"';
418 if (isset($GLOBALS[urlencode($key)]))
419 $return .= ' checked="checked" ';
420 $return .= ' /></input>'.$group_subsection_names[$key].'<br />';
423 foreach($section as $underkey => $undersection) {
424 $return .= ' <input type="checkbox" name="'.urlencode($key.$underkey).'"';
425 if (isset($GLOBALS[urlencode($key.$underkey)]))
426 $return .= ' checked="checked" ';
427 $return .= ' />'.$undersection.'<br />';
433 </table></td></tr></table><br />';
435 if ($countLines >= $break) {
436 if (($countLines - $break) < ($break - $countLines)) {
437 $return .= '</td><td width="33%">';
438 $break += $breakLimit;
443 return $return.' </td>
445 </table></td></tr></table>';
453 // c-file-style: "bsd"