source: trunk/index.php@ 7

Last change on this file since 7 was 7, checked in by chronos, 7 years ago
  • Added: Main page footer.
File size: 14.9 KB
Line 
1<?php
2
3include_once('Database.php');
4include_once('Config.php');
5include_once('Meet.php');
6include_once('RSS.php');
7include_once('Global.php');
8
9session_start();
10
11class Application
12{
13 var $NoFullPage = false;
14
15 function Link($URL)
16 {
17 return($this->Config['BaseURL'].$URL);
18 }
19
20 function Run()
21 {
22
23 }
24}
25
26class MyApplication extends Application
27{
28 var $Database;
29 var $Config;
30
31 function __construct()
32 {
33 }
34
35 function ShowMenu()
36 {
37 $Output = '<div>'.
38 '<a href="'.$this->Link('/tance/').'">Tance</a> '.
39 '<a href="'.$this->Link('/skoly/').'">Školy</a> '.
40 '<a href="'.$this->Link('/seznamka/').'">Seznamka</a> '.
41 '</div>';
42 return($Output);
43 }
44
45 function ProcessURL()
46 {
47 if(array_key_exists('REDIRECT_QUERY_STRING', $_SERVER))
48 $PathString = $_SERVER['REDIRECT_QUERY_STRING'];
49 else $PathString = '';
50 if(substr($PathString, -1, 1) == '/') $PathString = substr($PathString, 0, -1);
51 $PathItems = explode('/', $PathString);
52 if(array_key_exists('REQUEST_URI', $_SERVER) and (strpos($_SERVER['REQUEST_URI'], '?') !== false))
53 $_SERVER['QUERY_STRING'] = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?') + 1);
54 else $_SERVER['QUERY_STRING'] = '';
55 parse_str($_SERVER['QUERY_STRING'], $_GET);
56 return($PathItems);
57 }
58
59 function ShowDanceList()
60 {
61 $Output = '<h4 style="text-align: center;">Tance:</h4>';
62 $Output .= '<table class="WideTable">';
63 $Output .= '<tr><th>Název</th><th>Skupina</th>';
64 $DbResult2 = $this->Database->select('ResourceGroup', '*');
65 while($ResourceGroup = $DbResult2->fetch_assoc())
66 {
67 $Output .= '<th>'.$ResourceGroup['Name'].'</th>';
68 }
69 $Output .= '</tr>';
70 $DbResult = $this->Database->select('Dance', '*, (SELECT Name FROM DanceGroup WHERE DanceGroup.Id=Dance.Group) AS GroupName', '1 ORDER BY `Name`');
71 while($Dance = $DbResult->fetch_assoc())
72 {
73 $Output .= '<tr><td>'.$Dance['Name'].'</th><td>'.$Dance['GroupName'].'</td>';
74 $DbResult2 = $this->Database->select('ResourceGroup', '*');
75 while($ResourceGroup = $DbResult2->fetch_assoc())
76 {
77 $Output .= '<td>';
78 $DbResult3 = $this->Database->select('Resource', '*', '(`Dance`='.$Dance['Id'].') AND (`Group`='.$ResourceGroup['Id'].')');
79 while($Resource = $DbResult3->fetch_assoc())
80 {
81 $Output .= '<a href="'.$Resource['URL'].'">'.$Resource['Name'].'</a> ';
82 }
83 $Output .= '</td>';
84 }
85 $Output .= '</tr>';
86 }
87 $Output .= '</table>';
88
89 return($Output);
90 }
91
92 function ShowSchoolList()
93 {
94 $Output = '<h4 style="text-align: center;">Taneční školy:</h4>';
95 $Output .= '<table class="WideTable">';
96 $Output .= '<tr><th>Název</th><th>Adresa</th>';
97 $Output .= '</tr>';
98 $DbResult = $this->Database->select('School', '*', '1 ORDER BY `Name`');
99 while($School = $DbResult->fetch_assoc())
100 {
101 $Output .= '<tr><td><a href="'.$this->Link($School['URL']).'">'.$School['Name'].'</a></th><td>'.$School['Address'].'</td>';
102 $Output .= '</tr>';
103 }
104 $Output .= '</table>';
105
106 return($Output);
107 }
108
109 function ShowMeetUpdate()
110 {
111 $MeetSources = new MeetSources();
112 $MeetSources->Database = $this->Database;
113 $MeetSources->ParseAll();
114 }
115
116 function ShowMeetList()
117 {
118 $Output = '';
119 //print_r($_GET);
120 if (array_key_exists('lvm', $_GET) and ($_GET['lvm'] == 'seznam'))
121 {
122 $this->NoFullPage = true;
123 if (array_key_exists('vekod', $_GET) ) $_SESSION['vekod'] = $_GET['vekod'];
124 if (array_key_exists('vekdo', $_GET) ) $_SESSION['vekdo'] = $_GET['vekdo'];
125 if (array_key_exists('vyskaod', $_GET) ) $_SESSION['vyskaod'] = $_GET['vyskaod'];
126 if (array_key_exists('vyskado', $_GET) ) $_SESSION['vyskado'] = $_GET['vyskado'];
127 if (array_key_exists('vahaod', $_GET) ) $_SESSION['vahaod'] = $_GET['vahaod'];
128 if (array_key_exists('vahado', $_GET) ) $_SESSION['vahado'] = $_GET['vahado'];
129 if (array_key_exists('pohlavi', $_GET) ) {
130 if ($_GET['pohlavi'] > 0) $_SESSION['pohlavi'] = $_GET['pohlavi'];
131 else unset($_SESSION['pohlavi']);
132 }
133 } else {
134 $Output .= '<script>function reloadlist(){ $(\'#meetlist\').load(document.URL + \' #meetlist\');}'.
135 ' var load_timer = 100;
136 var ltimer = null;
137
138 function checkOut(kc,obj){
139 if(kc==13) $(obj).blur();
140 }
141 function initLTimer(tm){
142 if(ltimer) clearTimeout(ltimer);
143 ltimer = setTimeout("freloader()",tm);
144 }
145 function stopLTimer(){
146 if(ltimer) clearTimeout(ltimer);
147 ltimer = null;
148 }
149
150 var cf = {};
151
152 function setupc(key,val){
153 //console.log(\'setup-control-\'+key+\' = \'+val);
154 if(key==\'vekod\' || key==\'vekdo\' || key==\'vyskaod\' || key==\'vyskado\' || key==\'vahaod\' || key==\'vahado\') {
155 var ccv = $(\'#\'+key).val();
156 if(ccv!=val) $(\'#\'+key).val(val==0?\'\':val);
157 }
158 if(key==\'pohlavi\') {
159 $(\'.c\'+key).removeClass(\'active\');
160 $(\'#\'+key+val).addClass(\'active\');
161 }
162 }
163
164 function upf(key,val,lonreload){
165 if(key!=\'first\') cf[\'first\']=0; else st();
166 setupc(key,val);
167 cf[key]=val;
168 if(lonreload) initLTimer(1000); else initLTimer(100);
169 }
170
171 function freloader(){
172 ltimer = null;
173 var qp = jQuery.param( cf );
174 $(\'#list_content\').html(\'\'); $(\'#list_loading\').show();
175 $.get(\'\\seznamka?lvm=seznam&\'+qp,function(data){$(\'#list_loading\').hide();$(\'#list_content\').html(data);htip()})
176 }'.
177 '</script>';
178 $Output .= '<h4 style="text-align: center;">Inzeráty:</h4>';
179 $Output .= '<div class="btn-group ma3">'.
180 '<button class="btn btn-filter cpohlavi btn-ico" onclick="upf(\'pohlavi\',0)" id="pohlavi0" data-toggle="tooltip" '.
181 'data-placement="top" title="Obě pohlaví"><span class="icon-both"></span></button>'.
182 '<button class="btn btn-filter cpohlavi btn-ico" onclick="upf(\'pohlavi\',1)" id="pohlavi1" data-toggle="tooltip" '.
183 'data-placement="top" title="Jen muži"><span class="icon-man"></span></button>'.
184 '<button class="btn btn-filter cpohlavi btn-ico" onclick="upf(\'pohlavi\',2)" id="pohlavi2" data-toggle="tooltip" '.
185 'data-placement="top" title="Jen ženy"><span class="icon-woman"></span></button>'.
186 '</div>';
187 $Output .= '<div class="filter-num-box">'.
188 '<div class="label-box">Věk</div>'.
189 '<input value="'.$_SESSION['vekod'].'" onkeyup="if(event.keyCode!=9) upf(\'vekod\',$(this).val(),(event.keyCode==13?0:1)); '.
190 '" id="vekod" autocomplete="off" type="text">'.
191 '<div class="label-box">-</div>'.
192 '<input value="'.$_SESSION['vekdo'].'" onkeyup="'.
193 'if(event.keyCode!=9) upf(\'vekdo\',$(this).val(),(event.keyCode==13?0:1));" '.
194 'id="vekdo" autocomplete="off" type="text"><div class="label-box">let</div></div>'.
195 '</div> ';
196 $Output .= '<div class="filter-num-box">'.
197 '<div class="label-box">Výška</div>'.
198 '<input value="'.$_SESSION['vyskaod'].'" onkeyup="if(event.keyCode!=9) upf(\'vyskaod\',$(this).val(),(event.keyCode==13?0:1)); '.
199 '" id="vyskaod" autocomplete="off" type="text">'.
200 '<div class="label-box">-</div>'.
201 '<input value="'.$_SESSION['vyskado'].'" onkeyup="'.
202 'if(event.keyCode!=9) upf(\'vyskado\',$(this).val(),(event.keyCode==13?0:1));" '.
203 'id="vyskado" autocomplete="off" type="text"><div class="label-box">cm</div></div>'.
204 '</div> ';
205 $Output .= '<div class="filter-num-box">'.
206 '<div class="label-box">Váha</div>'.
207 '<input value="'.$_SESSION['vahaod'].'" onkeyup="if(event.keyCode!=9) upf(\'vahaod\',$(this).val(),(event.keyCode==13?0:1)); '.
208 '" id="vahaod" autocomplete="off" type="text">'.
209 '<div class="label-box">-</div>'.
210 '<input value="'.$_SESSION['vahado'].'" onkeyup="'.
211 'if(event.keyCode!=9) upf(\'vahado\',$(this).val(),(event.keyCode==13?0:1));" '.
212 'id="vahado" autocomplete="off" type="text"><div class="label-box">cm</div></div>'.
213 '</div>';
214 }
215
216 $Where = '';
217 if (array_key_exists('vekod', $_SESSION) and ($_SESSION['vekod'] != '')) $Where .= ' AND (Age >= '.$_SESSION['vekod'].')';
218 if (array_key_exists('vekdo', $_SESSION) and ($_SESSION['vekdo'] != '')) $Where .= ' AND (Age <= '.$_SESSION['vekdo'].')';
219 if (array_key_exists('vyskaod', $_SESSION) and ($_SESSION['vyskaod'] != '')) $Where .= ' AND (Height >= '.$_SESSION['vyskaod'].')';
220 if (array_key_exists('vyskado', $_SESSION) and ($_SESSION['vyskado'] != '')) $Where .= ' AND (Height <= '.$_SESSION['vyskado'].')';
221 if (array_key_exists('vahaod', $_SESSION) and ($_SESSION['vahaod'] != '')) $Where .= ' AND (Weight >= '.$_SESSION['vahaod'].')';
222 if (array_key_exists('vahado', $_SESSION) and ($_SESSION['vahado'] != '')) $Where .= ' AND (Weight <= '.$_SESSION['vahado'].')';
223 if (array_key_exists('pohlavi', $_SESSION) and ($_SESSION['pohlavi'] != '')) $Where .= ' AND (Gender = '.$_SESSION['pohlavi'].')';
224 if (substr($Where, 0, 4) == ' AND') $Where = substr($Where, 4);
225 if ($Where == '') $Where = '1';
226
227 $DbResult = $this->Database->query('SELECT COUNT(*) FROM `MeetItem` WHERE '.$Where);
228 $DbRow = $DbResult->fetch_row();
229 $PageList = GetPageList($DbRow[0]);
230
231 $Gender = array('', 'Muž', 'Žena');
232 $Output .= '<div id="list_content">';
233 $Output .= $PageList['Output'];
234 $TableColumns = array(
235 array('Name' => 'Date', 'Title' => 'Datum'),
236 array('Name' => 'Name', 'Title' => 'Jméno'),
237 array('Name' => 'Height', 'Title' => 'Výška'),
238 array('Name' => 'Age', 'Title' => 'Věk'),
239 array('Name' => 'Weight', 'Title' => 'Váha'),
240 array('Name' => 'Gender', 'Title' => 'Pohlaví'),
241 array('Name' => 'Message', 'Title' => 'Zpráva'),
242 array('Name' => 'Source', 'Title' => 'Zdroj'),
243 );
244 $Order = GetOrderTableHeader($TableColumns, 'Date', 1);
245 $Output .= '<table class="WideTable">';
246 $Output .= $Order['Output'];
247 $DbResult = $this->Database->select('MeetItem', '*, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
248 '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', $Where.$Order['SQL'].$PageList['SQLLimit']);
249 while($MeetItem = $DbResult->fetch_assoc())
250 {
251 $Output .= '<tr>'.
252 '<td>'.HumanDate(MysqlDateToTime($MeetItem['Date'])).'</td>'.
253 '<td>'.$MeetItem['Name'].'</td>'.
254 '<td>'.$MeetItem['Height'].'</td>'.
255 '<td>'.$MeetItem['Age'].'</td>'.
256 '<td>'.$MeetItem['Weight'].'</td>'.
257 //'<td>'.$MeetItem['Email'].'</td>'.
258 //'<td>'.$MeetItem['Phone'].'</td>'.
259 '<td>'.$Gender[$MeetItem['Gender']].'</td>'.
260 '<td>'.$MeetItem['Message'].'</td>'.
261 '<td><a href="'.$this->Link($MeetItem['SourceURL']).'">'.$MeetItem['SourceName'].'</a></td>';
262 $Output .= '</tr>';
263 }
264 $Output .= '</table>';
265 $Output .= $PageList['Output'];
266 $Output .= '</div>';
267
268 return($Output);
269 }
270
271 function ShowMeetListRss()
272 {
273 global $Config;
274
275 $this->NoFullPage = true;
276 $RSS = new RSS();
277 $RSS->Title = 'Taneční seznamka';
278 $RSS->Description = '';
279 $RSS->Link = $this->Link('/seznamka/');
280
281 $DbResult = $this->Database->select('MeetItem', '*, (SELECT MeetSource.Name FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceName, '.
282 '(SELECT MeetSource.URL FROM MeetSource WHERE MeetSource.Id = MeetItem.Source) AS SourceURL', '1 ORDER BY `Date` DESC LIMIT 30');
283 while($MeetItem = $DbResult->fetch_assoc())
284 {
285 $Title = $MeetItem['Name'];
286 if ($MeetItem['Age'] != '') $Title .= ', '.$MeetItem['Age'].' let';
287 if ($MeetItem['Weight'] != '') $Title .= ', '.$MeetItem['Height'].' cm';
288 $Description = $MeetItem['Message'];
289 if ($MeetItem['Email'] != '') $Description .= '<br/>Email: '.$MeetItem['Email'];
290 if ($MeetItem['Phone'] != '') $Description .= '<br/>Telefon: '.$MeetItem['Phone'];
291 $Description .= '<br/>Škola: <a href="'.$this->Link($MeetItem['SourceURL']).'">'.$MeetItem['SourceName'].'</a>';
292 $RSS->Items[] = array(
293 'Title' => $Title,
294 'Description' => $Description,
295 'Time' => MysqlDateTimeToTime($MeetItem['Date']),
296 'Link' => $this->Link('/seznamka/'),
297 );
298 $Output .= '<tr>'.
299 '<td>'.HumanDate(MysqlDateToTime($MeetItem['Date'])).'</td>'.
300 '<td>'.$MeetItem['Name'].'</td>'.
301 '<td>'.$MeetItem['Height'].'</td>'.
302 '<td>'.$MeetItem['Age'].'</td>'.
303 '<td>'.$MeetItem['Weight'].'</td>'.
304 //'<td>'.$MeetItem['Email'].'</td>'.
305 //'<td>'.$MeetItem['Phone'].'</td>'.
306 '<td>'.$Gender[$MeetItem['Gender']].'</td>'.
307 '<td>'.$MeetItem['Message'].'</td>'.
308 '<td></td>';
309 $Output .= '</tr>';
310 }
311
312 return $RSS->Generate();
313 }
314
315 function ShowPage($Content)
316 {
317 global $Config;
318
319 $Output = '<?xml version="1.0" encoding="'.$this->Config['Encoding'].'"?>'."\n".
320 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.
321 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">'.
322 '<head>'.
323 '<link rel="stylesheet" href="'.$this->Link('/style.css').'" type="text/css" media="all" />'.
324 '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->Config['Encoding'].'" />'.
325 '<script src="'.$this->Link('/jquery.js').'"></script>';
326 $Output .= '<link rel="alternate" title="Taneční seznamka" href="'.
327 $this->Link('/seznamka-rss/').'" type="application/rss+xml" />';
328 $Output .= '<title>Tance</title>'.
329 '</head><body>';
330 $Output .= $Content;
331 $Output .= '<div class="footer">Kontakt: <a href="mailto:'.$Config['Contact'].'">'.$Config['Contact'].'</a> '.
332 '<a href="https://svn.zdechov.net/trac/tanec/">Zdrojový kód</a></div>';
333 $Output .= '</body></html>';
334 return($Output);
335 }
336
337 function Run()
338 {
339 global $Config;
340
341 $this->Config = $Config;
342 $this->Database = new Database();
343 $this->Database->Connect($this->Config['Database']['Host'], $this->Config['Database']['User'],
344 $this->Config['Database']['Password'], $this->Config['Database']['Database']);
345 $this->Database->Prefix = $this->Config['Database']['Prefix'];
346 $this->Database->charset($this->Config['Database']['Charset']);
347 $this->PathItems = $this->ProcessURL();
348
349 $Output = '';
350
351 if(count($this->PathItems) > 0)
352 {
353 if($this->PathItems[0] == 'skoly') $Output .= $this->ShowSchoolList();
354 else if($this->PathItems[0] == 'tance') $Output .= $this->ShowDanceList();
355 else if($this->PathItems[0] == 'seznamka') $Output .= $this->ShowMeetList();
356 else if($this->PathItems[0] == 'seznamka-rss') $Output .= $this->ShowMeetListRss();
357 else if($this->PathItems[0] == 'seznamka-aktualizace') $Output .= $this->ShowMeetUpdate();
358 else $Output .= $this->ShowDanceList();
359 } else $Output .= $this->ShowDanceList();
360 if (!$this->NoFullPage)
361 {
362 $Output = $this->ShowMenu().$Output;
363 echo($this->ShowPage($Output));
364 } else echo($Output);
365 }
366}
367
368$Application = new MyApplication();
369$Application->Run();
Note: See TracBrowser for help on using the repository browser.