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

Last change on this file since 816 was 816, checked in by chronos, 10 years ago
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File size: 1.9 KB
Line 
1<?php
2
3class ModuleSearch extends AppModule
4{
5 var $SearchItems;
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();
16 $this->SearchItems = array();
17 }
18
19 function Start()
20 {
21 $this->System->RegisterPage('search', 'PageSearch');
22 }
23
24 function RegisterSearch($Name, $Title, $Columns, $Query, $Link)
25 {
26 // Query can be table name or subselect query
27 $this->SearchItems[$Name] = array('Name' => $Title, 'Columns' => $Columns,
28 'Query' => $Query, 'Link' => $Link);
29 }
30
31 function UnregisterSearch($Name)
32 {
33 unset($this->SearchItems[$Name]);
34 }
35}
36
37class PageSearch extends Page
38{
39 function Show()
40 {
41 $this->Title = T('Search');
42 if(array_key_exists('text', $_GET)) $Search = $_GET['text'];
43 else if(array_key_exists('text', $_POST)) $Search = $_POST['text'];
44 else $Search = '';
45 $SearchHTML = urlencode($Search);
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)
49 {
50 $ColumnQuery = array();
51 foreach($SearchItem['Columns'] as $Column)
52 {
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 if ($Line <> 0)
63 $Output .= '<tr><td><a href="'.$SearchItem['Link'].$SearchHTML.'">'.$SearchItem['Name'].'</a></td><td>'.$Line.'</td></tr>';
64 }
65
66 $Output .= '</table>';
67 return($Output);
68 }
69}
Note: See TracBrowser for help on using the repository browser.