source: trunk/Modules/Event/EventPage.php@ 52

Last change on this file since 52 was 52, checked in by chronos, 6 years ago
  • Added: New filter data type Boolean for representing on/off switches.
  • Added: Show only upcoming events. Allow to show also past events.
File size: 8.7 KB
Line 
1<?php
2
3class ModuleEvent extends AppModule
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()
18 {
19 $this->System->RegisterPage('udalosti', 'PageEventList');
20 $this->System->RegisterPage(array('udalosti', 'udalost'), 'PageEventItem');
21 $this->System->RegisterPage(array('udalosti', 'aktualizace'), 'PageEventUpdate');
22 $this->System->RegisterPage(array('udalosti', 'rss'), 'PageEventRss');
23 $this->System->RegisterMenuItem('/udalosti', 'Události');
24 }
25}
26
27class PageEventList extends Page
28{
29 function __construct($System)
30 {
31 parent::__construct($System);
32 $this->FullTitle = 'Taneční události';
33 $this->ShortTitle = 'Události';
34 }
35
36 function Show()
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 $this->Title = 'Události - '.$this->Title;
50 if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
51 $this->ClearPage = true;
52 else $Output .= '<div class="title">Události</div>';
53
54 $Output .= $Filter->GetOutput($this->System->Link('/udalosti/'));
55 $Where = $Filter->GetWhere($this->Database);
56 if ($_SESSION['past'] != 1) $Where .= ' AND (TimeFrom > NOW())';
57
58 $DbResult = $this->Database->query('SELECT COUNT(*) FROM (SELECT *, '.
59 '(SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName FROM `Event`) AS T WHERE (T.Hidden=0) AND '.$Where);
60 $DbRow = $DbResult->fetch_row();
61 $PageList = GetPageList($DbRow[0]);
62
63 $Output .= '<div id="list_content">';
64 $Output .= $PageList['Output'];
65 $TableColumns = array(
66 array('Name' => 'TimeFrom', 'Title' => 'Začátek'),
67 array('Name' => 'TimeTo', 'Title' => 'Konec'),
68 array('Name' => 'Title', 'Title' => 'Titulek'),
69 array('Name' => 'Description', 'Title' => 'Popis'),
70 array('Name' => 'Price', 'Title' => 'Cena'),
71 array('Name' => 'Location', 'Title' => 'Umístění'),
72 array('Name' => 'Source', 'Title' => 'Import'),
73 array('Name' => '', 'Title' => 'Detail'),
74 );
75 $Order = GetOrderTableHeader($TableColumns, 'TimeFrom', 0);
76 $Output .= '<table class="WideTable">';
77 $Output .= $Order['Output'];
78 $DbResult = $this->Database->query('SELECT * FROM (SELECT *, (SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName, '.
79 '(SELECT EventSource.URL FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceURL FROM Event) AS T WHERE (T.Hidden=0) AND '.
80 $Where.$Order['SQL'].$PageList['SQLLimit']);
81 while($Event = $DbResult->fetch_assoc())
82 {
83 $Output .= '<tr>'.
84 '<td>'.HumanDate(MysqlDateToTime($Event['TimeFrom'])).'</td>'.
85 '<td>'.HumanDate(MysqlDateToTime($Event['TimeTo'])).'</td>'.
86 '<td>'.$Event['Title'].'</td>'.
87 '<td>'.$Event['Description'].'</td>'.
88 '<td>'.$Event['Price'].'</td>'.
89 '<td>'.$Event['Location'].'</td>'.
90 '<td><a href="'.$Event['SourceURL'].'">'.$Event['SourceName'].'</a></td>'.
91 '<td><a href="'.$this->System->Link('/udalosti/udalost/'.$Event['Id']).'">Ukázat</a></td>';
92 $Output .= '</tr>';
93 }
94 $Output .= '</table>';
95 $Output .= $PageList['Output'];
96 $Output .= '</div>';
97 if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
98 {
99 }
100 else
101 {
102 $Output .= '<div><a href="'.$this->System->Link('/udalosti/rss/').'"><img src="'.$this->System->Link('/images/rss20.png').'" alt="rss20"/></a></div>';
103 }
104 return($Output);
105 }
106}
107
108class PageEventUpdate extends Page
109{
110 function __construct($System)
111 {
112 parent::__construct($System);
113 $this->FullTitle = 'Aktualizace tanečních událostí';
114 $this->ShortTitle = 'Aktualizace událostí';
115 }
116
117 function Show()
118 {
119 $EventSources = new EventSources();
120 $EventSources->Database = $this->Database;
121 if (array_key_exists('i', $_GET)) $Output = $EventSources->Parse($_GET['i']);
122 else $Output = $EventSources->Parse();
123 return $Output;
124 }
125}
126
127class PageEventItem extends Page
128{
129 function __construct($System)
130 {
131 parent::__construct($System);
132 $this->FullTitle = 'Taneční událost';
133 $this->ShortTitle = 'Událost';
134 }
135
136 function Show()
137 {
138 $this->Title = 'Událost - Události - '.$this->Title;
139 $Output = '';
140 if(count($this->System->PathItems) > 2)
141 {
142 $id = $this->System->PathItems[2] * 1;
143 } else return 'Položka nenalezena';
144 if ($this->System->IsAdmin())
145 {
146 if (array_key_exists('hide', $_GET)) $this->Database->update('Event', 'Id='.$id, array('Hidden' => 1));
147 if (array_key_exists('unhide', $_GET)) $this->Database->update('Event', 'Id='.$id, array('Hidden' => 0));
148 }
149
150 $Output .= '<div class="title">Události</div>';
151 $DbResult = $this->Database->select('Event', '*, (SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName, '.
152 '(SELECT EventSource.URL FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceURL', 'Id='.$id);
153 if ($DbResult->num_rows > 0)
154 {
155 $Event = $DbResult->fetch_assoc();
156 if (($Event['Hidden'] == '1') and !$this->System->IsAdmin())
157 return 'Položka nenalezena';
158 if ($Event['Link'] != '') $Link = '<a href="'.$Event['Link'].'">Odkaz</a>';
159 else $Link = '';
160 $Output .= '<table class="ItemTable">'.
161 '<tr><th>Začátek</th><td>'.HumanDate(MysqlDateToTime($Event['TimeFrom'])).'</td></tr>'.
162 '<tr><th>Konec</th><td>'.HumanDate(MysqlDateToTime($Event['TimeTo'])).'</td></tr>'.
163 '<tr><th>Titulek</th><td>'.$Event['Title'].'</td></tr>'.
164 '<tr><th>Popis</th><td>'.$Event['Description'].'</td></tr>'.
165 '<tr><th>Cena</th><td>'.$Event['Price'].'</td></tr>'.
166 '<tr><th>Umístění</th><td>'.$Event['Location'].'</td></tr>'.
167 '<tr><th>Původní web</th><td>'.$Link.'</td></tr>'.
168 '<tr><th>Zdroj importu</th><td><a href="'.$Event['SourceURL'].'">'.$Event['SourceName'].'</a></td></tr>';
169 $Output .= '</table>';
170 if ($this->System->IsAdmin()) {
171 if ($Event['Hidden'] == '1')
172 $Output .= '<div>Skrytá položka <a href="?unhide">Zviditelnit</a></div>';
173 else $Output .= '<div>Viditelná položka <a href="?hide">Skrýt</a></div>';
174 }
175 } else $Output .= 'Položka nenalezena';
176 return $Output;
177 }
178}
179
180class PageEventRss extends Page
181{
182 function __construct($System)
183 {
184 parent::__construct($System);
185 $this->FullTitle = 'RSS kanál tanečních událostí';
186 $this->ShortTitle = 'RSS taneční událostí';
187 }
188
189 function Show()
190 {
191 global $Config;
192
193 $this->ClearPage = true;
194 $RSS = new RSS();
195 $RSS->Title = 'Taneční události';
196 $RSS->Description = '';
197 $RSS->Link = $this->System->AbsoluteLink('/udalosti/');
198
199 $DbResult = $this->Database->select('Event', '*, (SELECT EventSource.Name FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceName, '.
200 '(SELECT EventSource.URL FROM EventSource WHERE EventSource.Id = Event.Source) AS SourceURL', '`Hidden`=0 ORDER BY `TimeFrom` DESC LIMIT 30');
201 while($Event = $DbResult->fetch_assoc())
202 {
203 $Title = $Event['Title'];
204 $Description = $Event['Description']."<br/>\n";
205 $Description .= '<br/>Zdroj importu: <a href="'.$Event['SourceURL'].'">'.$Event['SourceName'].'</a>';
206 $Time = MysqlDateTimeToTime($Event['TimeFrom']);
207 $TimeImport = MysqlDateTimeToTime($Event['TimeImport']);
208 // 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
209 if (TimeToMysqlTime($Time) == '00:00:00')
210 {
211 $Time = MysqlDateTimeToTime(TimeToMysqlDate($Time).' '.TimeToMysqlTime($TimeImport));
212 }
213 $RSS->Items[] = array(
214 'Title' => $Title,
215 'Description' => $Description,
216 'Time' => $Time,
217 'Link' => $this->System->AbsoluteLink('/udalosti/udalost/'.$Event['Id'].'/'),
218 );
219 }
220
221 return $RSS->Generate();
222 }
223}
Note: See TracBrowser for help on using the repository browser.