Title = 'Jídelníček'; $this->Description = 'Jídleníček jídelny Na kopečku'; $this->ParentClass = 'PagePortal'; } function Show(): string { if (count($this->System->PathItems) > 1) { if ($this->System->PathItems[1] == 'tisk') return $this->ShowPrint(); else if ($this->System->PathItems[1] == 'menuedit.php') return $this->ShowEdit(); else return PAGE_NOT_FOUND; } else return $this->ShowMenu(); } function ShowMenu(): string { $Output = ''; $DbResult = $this->Database->select('Meals', '*, UNIX_TIMESTAMP(Date)','Date >= NOW() ORDER BY Date'); while ($Row = $DbResult->fetch_array()) { if ($Row['Status'] == 1) $Output .= ''; else if (($Row['Status' ] == 2) or ($Row['Status'] == 3)) { $Output .= ''; } } $Output .= '
DenDatumPolévkaHlavní jídlo
'.$this->DayNames[date('w', $Row['UNIX_TIMESTAMP(Date)'])].''.HumanDate($Row['Date']).''.$Row['Soup'].''.$Row['Meal'].'
'.$this->DayNames[date('w', $Row['UNIX_TIMESTAMP(Date)'])].''.HumanDate($Row['Date']).''.$this->Status[$Row['Status']].'

'; $DbResult = $this->Database->select('MealsInfo', '*'); $Row = $DbResult->fetch_array(); $Output .= 'Cena jednoho menu: '.$Row['Price'].' Kč
'; $Output .= $Row['Info']; return $Output; } function ShowPrint(): string { $this->RawPage = true; $Output = ' Tisk jídelníčku '; // onload="print()">'); $Output .= ''; $Date = explode('-', $_GET['date']); $Output .= ''; $Date = explode('-', $_GET['date']); $Time2 = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]); for ($I = 0; $I < 5; $I++) { $Time = $Time2 + $I * 86400; $Date = date('Y-m-d', $Time); $DayOfWeek = date('w', $Time); $DbResult = $this->Database->select('Meals', '*', 'Date="'.$Date.'"'); $Row = $DbResult->fetch_array(); $Output .= ''; } $DbResult = $this->Database->select('MealsInfo','*'); $Row = $DbResult->fetch_array(); $Output .= ''; $Output .= '
DATUM: '.HumanDate($_GET['date']).' - '.HumanDate(date('Y-m-d',mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]) + 4 * 86400)).' CENY SMLUVNÍ
„JÍDELNA NA KOPEČKU”
JÍDELNÍČEK
'.$this->DayNamesShort[$DayOfWeek].''; if ($Row['Status'] == 0) $Output .= ' 

 '; if ($Row['Status'] == 1) $Output .= 'Polévka: '.$Row['Soup'].'

'.$Row['Meal']; else if (($Row['Status'] == 2) or ($Row['Status'] == 3)) { $Output .= '
'.$this->Status[$Row['Status']].'
 '; } $Output .= '
JÍDLA PŘIPRAVILA: Matochová PROVOZOVATEL:

CENA JEDNOHO MENU JE '.$Row['Price'].' Kč
'; $Output .= ''; return $Output; } function PrintTableRow(array $Row): string { global $LastWeekOfYear; $Selected = array('', '', '', ''); $Selected[$Row['Status']] = 'selected '; $Date = explode('-', $Row['Date']); $Week = date('w', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0])); $WeekOfYear = date('W', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0])); if ($WeekOfYear != $LastWeekOfYear) $WeekRowSpan = ''. $WeekOfYear.'
Tisk'; else $WeekRowSpan = ''; if ($Week == 0) $Color = ' style="color: #ff0000;" '; else $Color = ''; $Output = ''.$this->DayNames[$Week].''.HumanDate($Row['Date']).''.$WeekRowSpan.' '; $LastWeekOfYear = $WeekOfYear; return $Output; } function ShowEdit(): string { Header('Cache-Control: no-cache'); $Output = ''; if (array_key_exists('action', $_GET)) { if ($_GET['action'] == 'savemenu') { for ($I = 0; $I < $this->DayCount; $I++) { $Time = time() + $I * 86400; $Date = date('Y-m-d', $Time); $this->Database->replace('Meals', array('Date' => $Date, 'Meal' => $_POST['meal_'.$Date], 'Soup' => $_POST['soup_'.$Date], 'Status' => $_POST['status_'.$Date])); } $Output .= '
Menu uloženo!
'; ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('EatingPlace', 'MenuSave'); } if ($_GET['action'] == 'saveinfo') { $this->Database->delete('MealsInfo', '1'); $this->Database->insert('MealsInfo', array('Info' => $_POST['info'], 'Price' => $_POST['price'])); $Output .= '
Informační údaje uloženy!
'; ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('EatingPlace', 'InfoSave'); } } $Output = '
Jídlo pro jednotlivé dny '; for ($I = 0; $I < $this->DayCount; $I++) { $Time = time() + $I * 86400; $DbResult = $this->Database->select('Meals', '*', 'Date = "'.date('Y-m-d', $Time).'"'); if ($Row = $DbResult->fetch_array()) $Output .= $this->PrintTableRow($Row); else { $Row = array('Status' => 0, 'Meal' => '', 'Soup' => '', 'Date' => date('Y-m-d', $Time)); $Output .= $this->PrintTableRow($Row); } } $Output .= '
DenDatumTýdenPolévkaHlavní jídloStav

'; $Output .= '
Informační údaje'; $DbResult = $this->Database->select('MealsInfo', '*'); $Row = $DbResult->fetch_array(); $Output .= '
'. 'Cena:
'. '
'; return $Output; } } class ModuleMeals extends Module { function __construct(System $System) { parent::__construct($System); $this->Name = 'Meals'; $this->Version = '1.0'; $this->Creator = 'Chronos'; $this->License = 'GNU/GPLv3'; $this->Description = 'Module for management meals. Can print week menu.'; $this->Dependencies = array(ModuleLog::GetName()); $this->Models = array(Meals::GetClassName(), MealsInfo::GetClassName()); } function DoStart(): void { $this->System->RegisterPage(['jidelna'], 'PageEatingPlace'); } } class Meals extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddDate('Date'); $Desc->AddString('Soup'); $Desc->AddString('Meal'); $Desc->AddInteger('Status'); return $Desc; } } class MealsInfo extends Model { static function GetModelDesc(): ModelDesc { $Desc = new ModelDesc(self::GetClassName()); $Desc->AddText('Info'); $Desc->AddInteger('Price'); return $Desc; } }