1 | <?php
|
---|
2 |
|
---|
3 | class ModuleEvent extends Module
|
---|
4 | {
|
---|
5 | function __construct($System)
|
---|
6 | {
|
---|
7 | parent::__construct($System);
|
---|
8 | $this->Name = 'Event';
|
---|
9 | $this->Version = '1.0';
|
---|
10 | $this->Creator = 'Chronos';
|
---|
11 | $this->License = 'GNU/GPL';
|
---|
12 | $this->Description = 'List of dance events';
|
---|
13 | $this->Dependencies = array();
|
---|
14 | $this->RSSChannels = array();
|
---|
15 | }
|
---|
16 |
|
---|
17 | function Start(): void
|
---|
18 | {
|
---|
19 | $this->System->RegisterPage(['udalosti'], 'PageEventList');
|
---|
20 | $this->System->RegisterPage(['udalosti', 'udalost'], 'PageEventItem');
|
---|
21 | $this->System->RegisterPage(['udalosti', 'aktualizace'], 'PageEventUpdate');
|
---|
22 | $this->System->RegisterPage(['udalosti', 'rss'], 'PageEventRss');
|
---|
23 | Core::Cast($this->System)->RegisterMenuItem('/udalosti', 'Události');
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | class PageEventList extends Page
|
---|
28 | {
|
---|
29 | function __construct($System)
|
---|
30 | {
|
---|
31 | parent::__construct($System);
|
---|
32 | $this->Title = 'Události';
|
---|
33 | $this->Description = 'Taneční události';
|
---|
34 | }
|
---|
35 |
|
---|
36 | function Show(): string
|
---|
37 | {
|
---|
38 | $Filter = new Filter();
|
---|
39 | $Filter->Items = array(
|
---|
40 | array('Name' => 'past', 'Type' => 'Boolean', 'DbName' => '', 'Title' => 'Proběhlé'),
|
---|
41 | array('Name' => 'title', 'Type' => 'String', 'DbName' => 'Title', 'Title' => 'Titulek'),
|
---|
42 | array('Name' => 'description', 'Type' => 'String', 'DbName' => 'Description', 'Title' => 'Popis'),
|
---|
43 | array('Name' => 'price', 'Type' => 'Integer', 'DbName' => 'Price', 'Title' => 'Cena'),
|
---|
44 | array('Name' => 'location', 'Type' => 'String', 'DbName' => 'Location', 'Title' => 'Umístění'),
|
---|
45 | array('Name' => 'source', 'Type' => 'String', 'DbName' => 'SourceName', 'Title' => 'Import'),
|
---|
46 | );
|
---|
47 |
|
---|
48 | $Output = '';
|
---|
49 | if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
|
---|
50 | $this->RawPage = true;
|
---|
51 | else $Output .= '<div class="title">Události</div>';
|
---|
52 |
|
---|
53 | $Output .= $Filter->GetOutput($this->System->Link('/udalosti/'));
|
---|
54 | $Where = $Filter->GetWhere($this->Database);
|
---|
55 | if ($_SESSION['past'] != 1) $Where .= ' AND (TimeFrom > NOW())';
|
---|
56 |
|
---|
57 | $DbResult = $this->Database->query('SELECT COUNT(*) FROM (SELECT *, '.
|
---|
58 | '(SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName FROM `Event`) AS T WHERE '.GetDefaultEventFilter('T').' AND '.$Where);
|
---|
59 | $DbRow = $DbResult->fetch_row();
|
---|
60 | $PageList = GetPageList($DbRow[0]);
|
---|
61 |
|
---|
62 | $Output .= '<div id="list_content">';
|
---|
63 | $Output .= $PageList['Output'];
|
---|
64 | $TableColumns = array(
|
---|
65 | array('Name' => 'TimeFrom', 'Title' => 'Začátek'),
|
---|
66 | array('Name' => 'TimeTo', 'Title' => 'Konec'),
|
---|
67 | array('Name' => 'Title', 'Title' => 'Titulek'),
|
---|
68 | array('Name' => 'Description', 'Title' => 'Popis'),
|
---|
69 | array('Name' => 'Price', 'Title' => 'Cena'),
|
---|
70 | array('Name' => 'Location', 'Title' => 'Umístění'),
|
---|
71 | array('Name' => 'Source', 'Title' => 'Import'),
|
---|
72 | array('Name' => '', 'Title' => 'Detail'),
|
---|
73 | );
|
---|
74 | $Order = GetOrderTableHeader($TableColumns, 'TimeFrom', 0);
|
---|
75 | $Output .= '<table class="WideTable">';
|
---|
76 | $Output .= $Order['Output'];
|
---|
77 | $DbResult = $this->Database->query('SELECT * FROM (SELECT *, (SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName, '.
|
---|
78 | '(SELECT EventSource.URL FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceURL FROM Event) AS T WHERE '.GetDefaultEventFilter('T').' AND '.
|
---|
79 | $Where.$Order['SQL'].$PageList['SQLLimit']);
|
---|
80 | while ($Event = $DbResult->fetch_assoc())
|
---|
81 | {
|
---|
82 | $Output .= '<tr>'.
|
---|
83 | '<td>'.HumanDate(MysqlDateToTime($Event['TimeFrom'])).'</td>'.
|
---|
84 | '<td>'.HumanDate(MysqlDateToTime($Event['TimeTo'])).'</td>'.
|
---|
85 | '<td>'.$Event['Title'].'</td>'.
|
---|
86 | '<td>'.$Event['Description'].'</td>'.
|
---|
87 | '<td>'.$Event['Price'].'</td>'.
|
---|
88 | '<td>'.$Event['Location'].'</td>'.
|
---|
89 | '<td><a href="'.$Event['SourceURL'].'">'.$Event['SourceName'].'</a></td>'.
|
---|
90 | '<td><a href="'.$this->System->Link('/udalosti/udalost/'.$Event['Id']).'">Ukázat</a></td>';
|
---|
91 | $Output .= '</tr>';
|
---|
92 | }
|
---|
93 | $Output .= '</table>';
|
---|
94 | $Output .= $PageList['Output'];
|
---|
95 | $Output .= '</div>';
|
---|
96 | if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
|
---|
97 | {
|
---|
98 | }
|
---|
99 | else
|
---|
100 | {
|
---|
101 | $Output .= '<div><a href="'.$this->System->Link('/udalosti/rss/').'"><img src="'.$this->System->Link('/images/rss20.png').'" alt="rss20"/></a></div>';
|
---|
102 | }
|
---|
103 | return $Output;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | class PageEventUpdate extends Page
|
---|
108 | {
|
---|
109 | function __construct($System)
|
---|
110 | {
|
---|
111 | parent::__construct($System);
|
---|
112 | $this->Title = 'Aktualizace událostí';
|
---|
113 | $this->Description = 'Aktualizace tanečních událostí';
|
---|
114 | }
|
---|
115 |
|
---|
116 | function Show(): string
|
---|
117 | {
|
---|
118 | $EventSources = new EventSources();
|
---|
119 | $EventSources->Database = $this->Database;
|
---|
120 | if (array_key_exists('i', $_GET)) $Output = $EventSources->Parse($_GET['i']);
|
---|
121 | else $Output = $EventSources->Parse();
|
---|
122 | return $Output;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | class PageEventItem extends Page
|
---|
127 | {
|
---|
128 | function __construct($System)
|
---|
129 | {
|
---|
130 | parent::__construct($System);
|
---|
131 | $this->Title = 'Událost';
|
---|
132 | $this->Description = 'Taneční událost';
|
---|
133 | }
|
---|
134 |
|
---|
135 | function Show(): string
|
---|
136 | {
|
---|
137 | $Output = '';
|
---|
138 | if (count($this->System->PathItems) > 2)
|
---|
139 | {
|
---|
140 | $id = $this->System->PathItems[2] * 1;
|
---|
141 | } else return 'Položka nenalezena';
|
---|
142 | if (Core::Cast($this->System)->IsAdmin())
|
---|
143 | {
|
---|
144 | if (array_key_exists('hide', $_GET)) $this->Database->update('Event', 'Id='.$id, array('Hidden' => 1));
|
---|
145 | if (array_key_exists('unhide', $_GET)) $this->Database->update('Event', 'Id='.$id, array('Hidden' => 0));
|
---|
146 | }
|
---|
147 |
|
---|
148 | $Output .= '<div class="title">Události</div>';
|
---|
149 | $DbResult = $this->Database->select('Event', '*, (SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName, '.
|
---|
150 | '(SELECT EventSource.URL FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceURL, '.GetDefaultEventFilter().' AS Filter', 'Id='.$id);
|
---|
151 | if ($DbResult->num_rows > 0)
|
---|
152 | {
|
---|
153 | $Event = $DbResult->fetch_assoc();
|
---|
154 | if (($Event['Filter'] == '0') and !Core::Cast($this->System)->IsAdmin())
|
---|
155 | return 'Položka nenalezena';
|
---|
156 | if ($Event['Link'] != '') $Link = '<a href="'.$Event['Link'].'">Odkaz</a>';
|
---|
157 | else $Link = '';
|
---|
158 | $Output .= '<table class="ItemTable">'.
|
---|
159 | '<tr><th>Začátek</th><td>'.HumanDate(MysqlDateToTime($Event['TimeFrom'])).'</td></tr>'.
|
---|
160 | '<tr><th>Konec</th><td>'.HumanDate(MysqlDateToTime($Event['TimeTo'])).'</td></tr>'.
|
---|
161 | '<tr><th>Titulek</th><td>'.$Event['Title'].'</td></tr>'.
|
---|
162 | '<tr><th>Popis</th><td>'.$Event['Description'].'</td></tr>'.
|
---|
163 | '<tr><th>Cena</th><td>'.$Event['Price'].'</td></tr>'.
|
---|
164 | '<tr><th>Umístění</th><td>'.$Event['Location'].'</td></tr>'.
|
---|
165 | '<tr><th>Původní stránka</th><td>'.$Link.'</td></tr>'.
|
---|
166 | '<tr><th>Zdroj</th><td><a href="'.$Event['SourceURL'].'">'.$Event['SourceName'].'</a></td></tr>';
|
---|
167 | $Output .= '</table>';
|
---|
168 | if (Core::Cast($this->System)->IsAdmin()) {
|
---|
169 | if ($Event['Hidden'] == '1')
|
---|
170 | $Output .= '<div>Skrytá položka <a href="?unhide">Zviditelnit</a></div>';
|
---|
171 | else $Output .= '<div>Viditelná položka <a href="?hide">Skrýt</a></div>';
|
---|
172 | }
|
---|
173 | } else $Output .= 'Položka nenalezena';
|
---|
174 | return $Output;
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | class PageEventRss extends Page
|
---|
179 | {
|
---|
180 | function __construct($System)
|
---|
181 | {
|
---|
182 | parent::__construct($System);
|
---|
183 | $this->Title = 'RSS tanečních událostí';
|
---|
184 | $this->Description = 'RSS kanál tanečních událostí';
|
---|
185 | }
|
---|
186 |
|
---|
187 | function Show(): string
|
---|
188 | {
|
---|
189 | global $Config;
|
---|
190 |
|
---|
191 | $this->RawPage = true;
|
---|
192 | $RSS = new RSS();
|
---|
193 | $RSS->Title = 'Taneční události';
|
---|
194 | $RSS->Description = '';
|
---|
195 | $RSS->Link = $this->System->AbsoluteLink('/udalosti/');
|
---|
196 |
|
---|
197 | $DbResult = $this->Database->select('Event', '*, (SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName, '.
|
---|
198 | '(SELECT EventSource.URL FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceURL', GetDefaultEventFilter().' ORDER BY `TimeFrom` DESC LIMIT 30');
|
---|
199 | while ($Event = $DbResult->fetch_assoc())
|
---|
200 | {
|
---|
201 | $Title = $Event['Title'];
|
---|
202 | $Description = $Event['Description']."<br/>\n";
|
---|
203 | $Description .= '<br/>Zdroj: <a href="'.$Event['SourceURL'].'">'.$Event['SourceName'].'</a>';
|
---|
204 | $Time = MysqlDateTimeToTime($Event['TimeFrom']);
|
---|
205 | $TimeImport = MysqlDateTimeToTime($Event['TimeImport']);
|
---|
206 | // Append time part of TimeImport time to item time so new items will appear in correct time order even if item doesn't have time part specified
|
---|
207 | if (TimeToMysqlTime($Time) == '00:00:00')
|
---|
208 | {
|
---|
209 | $Time = MysqlDateTimeToTime(TimeToMysqlDate($Time).' '.TimeToMysqlTime($TimeImport));
|
---|
210 | }
|
---|
211 | $RSS->Items[] = array(
|
---|
212 | 'Title' => $Title,
|
---|
213 | 'Description' => $Description,
|
---|
214 | 'Time' => $Time,
|
---|
215 | 'Link' => $this->System->AbsoluteLink('/udalosti/udalost/'.$Event['Id'].'/'),
|
---|
216 | );
|
---|
217 | }
|
---|
218 |
|
---|
219 | return $RSS->Generate();
|
---|
220 | }
|
---|
221 | }
|
---|