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

Last change on this file since 738 was 738, checked in by chronos, 10 years ago
  • Removed: Spaces on end of line.
  • Modified: Tabs converted to spaces.
File size: 2.1 KB
Line 
1<?php
2
3class PageSearch extends Page
4{
5 function __construct($System)
6 {
7 parent::__construct($System);
8 $this->FullTitle = 'Hledání v obsahu';
9 $this->ShortTitle = 'Vyhledávání';
10 $this->ParentClass = 'PagePortal';
11 }
12
13 function Show()
14 {
15 $Output = '';
16 if(array_key_exists('t', $_GET)) $Text = $_GET['t'];
17 else $Text = '';
18 $Output .= '<form action="?" method="get">'.
19 'Hledaný text: <input name="t" value="'.$Text.'"/>'.
20 '<input type="submit" value="Hledat"/>'.
21 '</form>';
22 if($Text != '')
23 foreach($this->System->ModuleManager->Modules['Search']->Items as $Item)
24 {
25 $Columns = '';
26 $Condition = '';
27 foreach($Item['Columns'] as $Column)
28 {
29 $Columns .= ', `'.$Column.'`';
30 $Condition .= ' OR (`'.$Column.'` LIKE "%'.$Text.'%")';
31 }
32 $Columns = substr($Columns, 2);
33 $Condition = substr($Condition, 3);
34 $DbResult = $this->Database->Select($Item['Table'], $Columns, $Condition.' LIMIT '.
35 $this->System->ModuleManager->Modules['Search']->MaxItemCount);
36 if($DbResult->num_rows > 0) $Output .= '<strong>'.$Item['Name'].'</strong><br/>';
37 while($Row = $DbResult->fetch_assoc())
38 {
39 $Output .= '<p>';
40 foreach($Item['Columns'] as $Column)
41 $Output .= $Row[$Column].'<br/>';
42 $Output .= '</p>';
43 }
44 }
45 return($Output);
46 }
47}
48
49class ModuleSearch extends AppModule
50{
51 var $Items;
52 var $MaxItemCount;
53
54 function __construct($System)
55 {
56 parent::__construct($System);
57 $this->Name = 'Search';
58 $this->Version = '1.0';
59 $this->Creator = 'Chronos';
60 $this->License = 'GNU/GPL';
61 $this->Description = 'Allow search through registered content objects';
62 $this->Dependencies = array();
63 $this->MaxItemCount = 10;
64 $this->Items = array();
65 }
66
67 function DoStart()
68 {
69 $this->System->Pages['search'] = 'PageSearch';
70 }
71
72 function DoInstall()
73 {
74 }
75
76 function DoUnInstall()
77 {
78 }
79
80 function RegisterSearch($Title, $TableName, $Columns)
81 {
82 $this->Items[] = array('Name' => $Title, 'Table' => $TableName, 'Columns' => $Columns);
83 }
84}
Note: See TracBrowser for help on using the repository browser.