Name = 'Search'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPL'; $this->Description = 'Allow test search in other modules content.'; $this->Dependencies = array(); $this->SearchItems = array(); } function DoStart(): void { $this->System->RegisterPage(['search'], 'PageSearch'); Core::Cast($this->System)->RegisterPageBarItem('Left', 'Search', array($this, 'ShowSearchBox')); } function RegisterSearch($Name, $Title, $Columns, $Query, $Link) { // Query can be table name or subselect query $this->SearchItems[$Name] = array('Name' => $Title, 'Columns' => $Columns, 'Query' => $Query, 'Link' => $Link); } function UnregisterSearch($Name) { unset($this->SearchItems[$Name]); } function ShowSearchBox() { $Output = ''.T('Search').':'. '
'. ''. ''. ''. ''. ''. ''. ''. '
'. '
'; return $Output; } } class PageSearch extends Page { function Show(): string { $this->Title = T('Search'); if (array_key_exists('text', $_GET)) $Search = $_GET['text']; else if (array_key_exists('text', $_POST)) $Search = $_POST['text']; else $Search = ''; $SearchHTML = urlencode($Search); $Output = ''; foreach ($this->System->ModuleManager->Modules['Search']->SearchItems as $SearchItem) { $ColumnQuery = array(); foreach ($SearchItem['Columns'] as $Column) { $ColumnQuery[] = '(`'.$Column.'` LIKE "%'.$Search.'%")'; } $ColumnQuery = implode(' OR ', $ColumnQuery); if ($SearchItem['Query'] != '') { $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$SearchItem['Query'].' WHERE '.$ColumnQuery); $Line = $DbResult->fetch_row(); $Line = $Line[0]; } else $Line = ''; if ($Line <> 0) $Output .= ''; } $Output .= '
'.T('Section').''.T('Found count').'
'.$SearchItem['Name'].''.$Line.'
'; return $Output; } }