<?php

class ModuleSchool extends Module
{
  function __construct($System)
  {
    parent::__construct($System);
    $this->Name = 'School';
    $this->Version = '1.0';
    $this->Creator = 'Chronos';
    $this->License = 'GNU/GPL';
    $this->Description = 'List of dance schools';
    $this->Dependencies = array();
    $this->RSSChannels = array();
  }

  function Start(): void
  {
    $this->System->RegisterPage(['skoly'], 'PageSchoolList');
    Core::Cast($this->System)->RegisterMenuItem('/skoly', 'Školy');
  }
}

class PageSchoolList extends Page
{
  function __construct($System)
  {
    parent::__construct($System);
    $this->Title = 'Školy';
    $this->Description = 'Taneční školy';
  }

  function Show(): string
  {
    $Output = '<div class="title">Taneční školy</div>';
    $Output .= '<table class="WideTable">';
    $Output .= '<tr><th>Název</th><th>Webové stránky</th><th>Adresa</th>';
    $Output .= '</tr>';
    $DbResult = $this->Database->select('School', '*', '1 ORDER BY `Name`');
    while ($School = $DbResult->fetch_assoc())
    {
      $Output .= '<tr>'.
        '<td>'.$School['Name'].'</td>'.
        '<td><a href="'.$this->System->Link($School['URL']).'">'.$School['URL'].'</a></td>'.
        '<td>'.$School['Address'].'</td>'.
        '</tr>';
    }
    $Output .= '</table>';

    return $Output;
  }
}
