Changeset 816 for trunk/Modules/Search/Search.php
- Timestamp:
- Feb 22, 2015, 11:20:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/Search/Search.php
r760 r816 3 3 class ModuleSearch extends AppModule 4 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 } 5 var $SearchItems; 18 6 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 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 } 30 18 31 function UnregisterSearch($Name) 32 { 33 unset($this->SearchItems[$Name]); 34 } 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 35 } 36 36 37 37 class PageSearch extends Page 38 38 { 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 } 55 56 57 { 58 59 60 61 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 62 if ($Line <> 0) 63 64 65 66 67 68 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 69 }
Note:
See TracChangeset
for help on using the changeset viewer.