source: trunk/Modules/Search/Search.php@ 636

Last change on this file since 636 was 636, checked in by chronos, 12 years ago
  • Added: Pages should have set title which is used in HTML header to show title in web browser title bar.
File size: 1.9 KB
RevLine 
[595]1<?php
[577]2
3class ModuleSearch extends AppModule
[595]4{
5 var $SearchItems;
[577]6
7 function __construct($System)
8 {
9 parent::__construct($System);
10 $this->Name = 'Search';
11 $this->Version = '1.0';
12 $this->Creator = 'Chronos';
13 $this->License = 'GNU/GPL';
14 $this->Description = 'Allow test search in other modules content.';
15 $this->Dependencies = array();
[626]16 $this->SearchItems = array();
[577]17 }
18
19 function Start()
20 {
21 $this->System->RegisterPage('search', 'PageSearch');
22 }
[595]23
[626]24 function RegisterSearch($Name, $Title, $Columns, $Query, $Link)
[595]25 {
[626]26 // Query can be table name or subselect query
27 $this->SearchItems[$Name] = array('Name' => $Title, 'Columns' => $Columns,
28 'Query' => $Query, 'Link' => $Link);
[595]29 }
30
[626]31 function UnregisterSearch($Name)
[595]32 {
33 unset($this->SearchItems[$Name]);
34 }
[577]35}
36
37class PageSearch extends Page
38{
39 function Show()
40 {
[636]41 $this->Title = T('Search');
[577]42 if(array_key_exists('text', $_GET)) $Search = $_GET['text'];
43 else if(array_key_exists('text', $_POST)) $Search = $_POST['text'];
[595]44 else $Search = '';
[586]45 $SearchHTML = htmlentities($Search);
[626]46
47 $Output = '<table class="BaseTable"><tr><th>'.T('Section').'</th><th>'.T('Found count').'</th></tr>';
48 foreach($this->System->ModuleManager->Modules['Search']->SearchItems as $SearchItem)
[577]49 {
[626]50 $ColumnQuery = array();
51 foreach($SearchItem['Columns'] as $Column)
[577]52 {
[626]53 $ColumnQuery[] = '(`'.$Column.'` LIKE "%'.$Search.'%")';
54 }
55 $ColumnQuery = implode(' OR ', $ColumnQuery);
56 if($SearchItem['Query'] != '')
57 {
58 $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$SearchItem['Query'].' WHERE '.$ColumnQuery);
59 $Line = $DbResult->fetch_row();
60 $Line = $Line[0];
61 } else $Line = '';
62 $Output .= '<tr><td><a href="'.$SearchItem['Link'].$SearchHTML.'">'.$SearchItem['Name'].'</a></td><td>'.$Line.'</td></tr>';
[577]63 }
[626]64
65 $Output .= '</table>';
[577]66 return($Output);
67 }
68}
Note: See TracBrowser for help on using the repository browser.