1 | <?php
|
---|
2 |
|
---|
3 | class 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 |
|
---|
37 | class 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 = htmlentities($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 | $Output .= '<tr><td><a href="'.$SearchItem['Link'].$SearchHTML.'">'.$SearchItem['Name'].'</a></td><td>'.$Line.'</td></tr>';
|
---|
63 | }
|
---|
64 |
|
---|
65 | $Output .= '</table>';
|
---|
66 | return($Output);
|
---|
67 | }
|
---|
68 | }
|
---|