source: trunk/Modules/Meals/Meals.php

Last change on this file was 929, checked in by chronos, 3 years ago
  • Modified: Removed commended out print_r and echo commands used only for debugging.
File size: 9.3 KB
Line 
1<?php
2
3class PageEatingPlace extends Page
4{
5 public array $DayNames = array('Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota');
6 public array $DayNamesShort = array('NE', 'PO', 'ÚT', 'ST', 'ČT', 'PÁ', 'SO');
7 public array $Status = array('Nezveřejněno', 'Otevřeno', 'Zavřeno - svátek', 'Zavřeno - dovolená');
8 public int $DayCount = 20; // počet dopředu zobrazených dnů
9
10 function __construct(System $System)
11 {
12 parent::__construct($System);
13 $this->Title = 'Jídelníček';
14 $this->Description = 'Jídleníček jídelny Na kopečku';
15 $this->ParentClass = 'PagePortal';
16 }
17
18 function Show(): string
19 {
20 if (count($this->System->PathItems) > 1)
21 {
22 if ($this->System->PathItems[1] == 'tisk') return $this->ShowPrint();
23 else if ($this->System->PathItems[1] == 'menuedit.php') return $this->ShowEdit();
24 else return PAGE_NOT_FOUND;
25 } else return $this->ShowMenu();
26 }
27
28 function ShowMenu(): string
29 {
30 $Output = '<table align="center" class="WideTable"><tr><th>Den</th><th>Datum</th><th>Polévka</th><th>Hlavní jídlo</th></tr>';
31 $DbResult = $this->Database->select('Meals', '*, UNIX_TIMESTAMP(Date)','Date >= NOW() ORDER BY Date');
32 while ($Row = $DbResult->fetch_array())
33 {
34 if ($Row['Status'] == 1) $Output .= '<tr><td>'.$this->DayNames[date('w', $Row['UNIX_TIMESTAMP(Date)'])].'</td><td align="right">'.HumanDate($Row['Date']).'</td><td>'.$Row['Soup'].'</td><td>'.$Row['Meal'].'</td></tr>';
35 else if (($Row['Status' ] == 2) or ($Row['Status'] == 3))
36 {
37 $Output .= '<tr><td>'.$this->DayNames[date('w', $Row['UNIX_TIMESTAMP(Date)'])].'</td><td align="right">'.HumanDate($Row['Date']).'</td><td colspan="2" align="center">'.$this->Status[$Row['Status']].'</td></tr>';
38 }
39 }
40 $Output .= '</table><br />';
41
42 $DbResult = $this->Database->select('MealsInfo', '*');
43 $Row = $DbResult->fetch_array();
44 $Output .= 'Cena jednoho menu: '.$Row['Price'].' Kč<br />';
45 $Output .= $Row['Info'];
46 return $Output;
47 }
48
49 function ShowPrint(): string
50 {
51 $this->RawPage = true;
52
53 $Output = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
54<html>
55<head>
56<meta http-equiv="Content-Type" content="text/html; charset='.$this->System->Config['Web']['Charset'].'">
57<meta http-equiv="Content-language" content="cs">
58<title>Tisk jídelníčku</title>
59</head><body style="margin: 0px 0px 0px 0px;">'; // onload="print()">');
60
61 $Output .= '<table height="99%" width="100%" align="center" border="0" cellspacing="0" cellpadding="3">';
62 $Date = explode('-', $_GET['date']);
63 $Output .= '<tr><td style="border-bottom-style: solid; border-bottom-color: black; border-bottom-width: 2;" colspan="2">
64<table cellspacing="0" cellpadding="0" width="100%"><tr><td width="50%"><strong>DATUM:</strong> '.HumanDate($_GET['date']).' - '.HumanDate(date('Y-m-d',mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]) + 4 * 86400)).'</td>
65<td align="right">CENY SMLUVNÍ</td></tr></table>
66<div align="center" style="font-size: xx-large;">&bdquo;JÍDELNA NA KOPEČKU&rdquo;</div>
67<div align="center" style="font-size: x-large;">JÍDELNÍČEK</div>
68</td></tr>';
69 $Date = explode('-', $_GET['date']);
70 $Time2 = mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]);
71 for ($I = 0; $I < 5; $I++)
72 {
73 $Time = $Time2 + $I * 86400;
74 $Date = date('Y-m-d', $Time);
75 $DayOfWeek = date('w', $Time);
76 $DbResult = $this->Database->select('Meals', '*', 'Date="'.$Date.'"');
77 $Row = $DbResult->fetch_array();
78 $Output .= '<tr><td style="border-style: solid; border-color: black; border-width: 2; font-size: xx-large;" width="10%">'.$this->DayNamesShort[$DayOfWeek].'</td><td style="font-size: x-large; border-style: solid; border-color: black; border-width: 2;" width="90%">';
79 if ($Row['Status'] == 0) $Output .= '&nbsp;<br><br>&nbsp;';
80 if ($Row['Status'] == 1) $Output .= 'Polévka: '.$Row['Soup'].'<br><br>'.$Row['Meal'];
81 else if (($Row['Status'] == 2) or ($Row['Status'] == 3))
82 {
83 $Output .= '<br>'.$this->Status[$Row['Status']].'<br>&nbsp;';
84 }
85 $Output .= '</td></tr>';
86 }
87 $DbResult = $this->Database->select('MealsInfo','*');
88 $Row = $DbResult->fetch_array();
89 $Output .= '<tr><td style="border-top-style: solid; border-top-color: black; border-top-width: 2;" colspan="2"><table cellspacing="0" cellpadding="0" width="100%"><tr><td width="50%"><strong>JÍDLA PŘIPRAVILA: Matochová</strong></td>
90 <td align="right"><strong>PROVOZOVATEL:</strong></td></tr></table>
91 <br>
92 <strong>CENA JEDNOHO MENU JE '.$Row['Price'].' Kč</strong></td></tr>';
93 $Output .= '</table>';
94
95 $Output .= '</body></html>';
96 return $Output;
97 }
98
99 function PrintTableRow(array $Row): string
100 {
101 global $LastWeekOfYear;
102
103 $Selected = array('', '', '', '');
104 $Selected[$Row['Status']] = 'selected ';
105 $Date = explode('-', $Row['Date']);
106 $Week = date('w', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]));
107 $WeekOfYear = date('W', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]));
108 if ($WeekOfYear != $LastWeekOfYear)
109 $WeekRowSpan = '<td align="center" rowspan="'.(7 - (($Week + 7 - 1) % 7)).'">'.
110 $WeekOfYear.'<br /><a href="tisk/?date='.
111 date('Y-m-d', mktime(0, 0, 0, $Date[1], $Date[2], $Date[0]) - ($Week - 1) * 86400).
112 '">Tisk</a></td>';
113 else $WeekRowSpan = '';
114 if ($Week == 0) $Color = ' style="color: #ff0000;" '; else $Color = '';
115 $Output = '<tr><td'.$Color.'>'.$this->DayNames[$Week].'</td><td>'.HumanDate($Row['Date']).'</td>'.$WeekRowSpan.'
116 <td><input name="soup_'.$Row['Date'].'" size="30" value="'.$Row['Soup'].'"></td>
117 <td><input name="meal_'.$Row['Date'].'" size="30" value="'.$Row['Meal'].'"></td>
118 <td><select name="status_'.$Row['Date'].'">';
119 for ($I = 0; $I < 4; $I++) $Output .= ' <option '.$Selected[$I].'value="'.$I.'">'.$this->Status[$I].'</option>';
120 $Output .= '</select></td></tr>';
121 $LastWeekOfYear = $WeekOfYear;
122 return $Output;
123 }
124
125 function ShowEdit(): string
126 {
127 Header('Cache-Control: no-cache');
128
129 $Output = '';
130 if (array_key_exists('action', $_GET))
131 {
132 if ($_GET['action'] == 'savemenu')
133 {
134 for ($I = 0; $I < $this->DayCount; $I++)
135 {
136 $Time = time() + $I * 86400;
137 $Date = date('Y-m-d', $Time);
138 $this->Database->replace('Meals', array('Date' => $Date, 'Meal' => $_POST['meal_'.$Date], 'Soup' => $_POST['soup_'.$Date], 'Status' => $_POST['status_'.$Date]));
139 }
140 $Output .= '<div style="color: red; font-size: larger;">Menu uloženo!</div>';
141 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('EatingPlace', 'MenuSave');
142 }
143 if ($_GET['action'] == 'saveinfo')
144 {
145 $this->Database->delete('MealsInfo', '1');
146 $this->Database->insert('MealsInfo', array('Info' => $_POST['info'], 'Price' => $_POST['price']));
147 $Output .= '<div style="color: red; font-size: larger;">Informační údaje uloženy!</div>';
148 ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('EatingPlace', 'InfoSave');
149 }
150 }
151 $Output = '<form action="?action=savemenu" method="post">
152<fieldset><legend>Jídlo pro jednotlivé dny</legend>
153<table align="center" class="WideTable"><tr><th>Den</th><th>Datum</th><th>Týden</th><th>Polévka</th><th>Hlavní jídlo</th><th>Stav</th></tr>';
154 for ($I = 0; $I < $this->DayCount; $I++)
155 {
156 $Time = time() + $I * 86400;
157 $DbResult = $this->Database->select('Meals', '*', 'Date = "'.date('Y-m-d', $Time).'"');
158 if ($Row = $DbResult->fetch_array())
159 $Output .= $this->PrintTableRow($Row);
160 else
161 {
162 $Row = array('Status' => 0, 'Meal' => '', 'Soup' => '', 'Date' => date('Y-m-d', $Time));
163 $Output .= $this->PrintTableRow($Row);
164 }
165 }
166 $Output .= '</table><br />
167<div align="center"><input type="submit" value="Uložit menu"></div>
168</fieldset></form>';
169 $Output .= '<form action="?action=saveinfo" method="post">
170<fieldset><legend>Informační údaje</legend>';
171
172 $DbResult = $this->Database->select('MealsInfo', '*');
173 $Row = $DbResult->fetch_array();
174 $Output .= '<textarea name="info" rows="20" cols="80" >'.$Row['Info'].'</textarea><br />'.
175'Cena: <input type="text" name="price" size="5" value="'.$Row['Price'].'"> Kč<br />'.
176'<div align="center"><input type="submit" value="Uložit údaje"></div>
177</fieldset></form>';
178 return $Output;
179 }
180}
181
182class ModuleMeals extends Module
183{
184 function __construct(System $System)
185 {
186 parent::__construct($System);
187 $this->Name = 'Meals';
188 $this->Version = '1.0';
189 $this->Creator = 'Chronos';
190 $this->License = 'GNU/GPLv3';
191 $this->Description = 'Module for management meals. Can print week menu.';
192 $this->Dependencies = array(ModuleLog::GetName());
193 $this->Models = array(Meals::GetClassName(), MealsInfo::GetClassName());
194 }
195
196 function DoStart(): void
197 {
198 $this->System->RegisterPage(['jidelna'], 'PageEatingPlace');
199 }
200}
201
202class Meals extends Model
203{
204 static function GetModelDesc(): ModelDesc
205 {
206 $Desc = new ModelDesc(self::GetClassName());
207 $Desc->AddDate('Date');
208 $Desc->AddString('Soup');
209 $Desc->AddString('Meal');
210 $Desc->AddInteger('Status');
211 return $Desc;
212 }
213}
214
215class MealsInfo extends Model
216{
217 static function GetModelDesc(): ModelDesc
218 {
219 $Desc = new ModelDesc(self::GetClassName());
220 $Desc->AddText('Info');
221 $Desc->AddInteger('Price');
222 return $Desc;
223 }
224}
Note: See TracBrowser for help on using the repository browser.