3ac70d56bd8b191dbdaebe7b29d92186c0b0b517
[brisk.git] / web / index.php
1 <?php
2 /*
3  *  brisk - index.php
4  *
5  *  Copyright (C) 2006-2007 matteo.nastasi@milug.org
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details. You should have received a
16  * copy of the GNU General Public License along with this program; if
17  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
18  * Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * $Id$
21  *
22  */
23
24 require_once("Obj/brisk.phh");
25 require_once("Obj/proxyscan.phh");
26
27 // Use of proxies isn't allowed.
28 if (is_proxy()) 
29      exit;
30
31 require_once("briskin5/Obj/briskin5.phh");
32 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
33   echo "Debugging time!";
34   exit;
35 }
36
37 log_load("index.php");
38
39 function main()
40 {
41   GLOBAL $sess, $name, $table_idx, $table_token, $BRISK_SHOWHTML, $BRISK_DEBUG, $_SERVER;
42   
43   $body = "";
44   $tables = "";
45   $standup = "";
46   $ACTION = "login";
47   
48   if (isset($BRISK_SHOWHTML) == FALSE) {
49     $is_table = FALSE;
50     $sem = Room::lock_data();
51     log_main("lock Room");
52     $room = &Room::load_data();
53     $curtime = time();
54
55     /* Actions */
56
57     if (validate_sess($sess)) {
58       log_main("pre garbage_manager UNO");
59       $room->garbage_manager(TRUE);
60       log_main("post garbage_manager");
61       if (($user = &$room->get_user($sess, &$idx)) != FALSE) {
62         log_main("user stat: ".$user->stat);
63         if ($user->stat == "table") {
64           if (Room::save_data(&$room) == FALSE) {
65             echo "ERRORE SALVATAGGIO\n";
66             exit;
67           }
68           log_main("unlock Room");
69           Room::unlock_data($sem);
70           setcookie("table_token", $user->table_token, $curtime + 31536000);
71           setcookie("table_idx", $user->table, $curtime + 31536000);
72           header ("Location: briskin5/index.php");
73           exit;
74         }
75         $ACTION = "room";
76       }
77
78       if (Room::save_data(&$room) == FALSE) {
79         echo "ERRORE SALVATAGGIO\n";
80         exit;
81       }
82     }
83     
84     if ($ACTION == "login" && isset($name)) {
85       
86       log_main("pre garbage_manager DUE");
87       $room->garbage_manager(TRUE);
88       /* try login */
89       if (($user = &$room->add_user(&$sess, &$idx, $name, $_SERVER['REMOTE_ADDR'])) != FALSE) {
90         $ACTION = "room";
91         
92         // setcookie ("sess", "", time() + 180);      
93         $room->standup_update(&$user);
94         
95         if (Room::save_data(&$room) == FALSE) {
96           echo "ERRORE SALVATAGGIO\n";
97           exit;
98         }
99       }
100       else {
101         /* Login Rendering */
102         if ($idx == -2)
103           $body .= '<div class="urgmsg"><b>Il nickname deve contenere almeno una lettera o una cifra.</b></div>';
104         else if ($idx == -1) 
105           $body .= '<div class="urgmsg"><b>Spiacenti, non ci sono pi&ugrave; posti liberi. Riprova pi&ugrave; tardi.</b></div>';
106         else
107           $body .= '<div class="urgmsg"><b>Il tuo nickname &egrave; gi&agrave; in uso.</b></div>';
108       }
109     }
110     Room::unlock_data($sem);
111   }
112   /* Rendering. */
113
114   if ($BRISK_SHOWHTML == "debugtable") {
115     $ACTION = "room";
116   }
117   else if ($BRISK_SHOWHTML == "debuglogin") {
118     $ACTION = "login";
119   }
120
121   if ($ACTION == "room") {
122     $tables .= '<div class="room_tab">';
123     $tables .= '<table class="room_tab" align="center">';
124     for ($i = 0 ; $i < TABLES_N ; $i++) {
125       if ($i % 4 == 0)
126         $tables .= '<tr>';
127       $tables .= '<td>';
128       $tables .= '<div class="room_div"><div class="room_tit"><b>Tavolo '.$i.'</b></div>';
129       $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
130       $tables .= sprintf('<div class="table_act" id="table_act%d"></div>', $i);
131       $tables .= '</div>';
132       $tables .= '</td>'."\n";
133       if ($i % 4 == 3)
134         $tables .= '</tr>';
135     }
136     $tables .= '</table></div>';
137
138
139     $standup .= '<table class="room_standup" align="center"><tr><td>';
140     $standup .= '<div class="room_ex_standup">';
141     $standup .= '<div class="room_tit"><b>Giocatori in piedi</b></div>';
142     
143     $standup .= sprintf('<div id="standup" class="room_standup"></div>');
144     $standup .= '<div id="esco" class="esco"></div>';
145     $standup .= '</div></td></tr></table>';
146     
147     // $tables .= '</td></tr></table>';
148
149     /*
150     $tables .= '</td></tr><tr><td>';
151     $tables .= '<table class="room_tab" align="center">';
152     $tables .= '<tr><td>';
153     $tables .= '<div class="room_ex_standup">';
154     $tables .= '<b>Giocatori in piedi</b>';
155     
156     $tables .= sprintf('<div id="standup" class="room_standup"></div>');
157     $tables .= '<div id="esco" class="esco"></div>';
158     */
159     // $tables .= '</td></tr></table>';
160   }
161
162   $altout_propag = array( array ( 'id' => 'btn_altout',
163                                   'url' => 'http://www.alternativeoutput.it',
164                                   'content' => 'img/altout80x15.png',
165                                   'content_big' => 'img/altout80x15.png'),
166                           array ( 'id' => 'btn_virtualsky',
167                                   'url' => 'http://virtualsky.alternativeoutput.it',
168                                   'content' => 'img/virtualsky80x15a.gif',
169                                   'content_big' => 'img/virtualsky_big.png')
170                           );
171   
172   // seed with microseconds since last "whole" second
173   srand ((double) microtime() * 1000000);
174   // $randval = rand(0,count($altout_propag)-1);
175   $randval = 1;
176   $altout_carousel = sprintf('<a target="_blank" href="%s"><img id="%s" class="nobo" src="%s" onMouseOver="show_bigpict(this, \'over\');" onMouseOut="show_bigpict(this, \'out\');"></a>',
177                              $altout_propag[$randval]['url'],
178                              $altout_propag[$randval]['id'],
179                              $altout_propag[$randval]['content']);
180                          
181   $altout_carousel_big = sprintf('<img class="nobohide" id="%s_big" src="%s">',
182                                  $altout_propag[$randval]['id'],
183                                  $altout_propag[$randval]['content_big']);
184                          
185
186   $brisk_donate = file_get_contents(FTOK_PATH."/brisk_donate.txt");
187   if ($brisk_donate == FALSE)
188     $brisk_donate = "";
189
190 $brisk_header_form = '<div class="container">
191 <!-- =========== header ===========  -->
192 <div id="header" class="header">
193 <table width="100%%" border="0" cols="3"><tr>
194 <td align="left"><div style="padding-left: 8px;">
195
196
197
198 <script type="text/javascript"><!--
199 google_ad_client = "pub-5246925322544303";
200 google_ad_width = 234;
201 google_ad_height = 60;
202 google_ad_format = "234x60_as";
203 google_ad_type = "text_image";
204 google_ad_channel = "";
205 google_color_border = "808080";
206 google_color_bg = "f6f6f6";
207 google_color_link = "ffae00";
208 google_color_text = "404040";
209 google_color_url = "000000";
210 //-->
211 </script>
212 <script type="text/javascript"
213   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
214 </script>
215
216
217
218 </div></td>
219 <td align="center">
220 <!-- <table><tr><td>  -->
221 <div>
222     <img class="nobo" src="img/brisk_logo64.png">
223     briscola chiamata in salsa ajax<br>
224     </div>
225 <!-- </td><td><div style="align: center; text-align:center; background-color: #f8f8f8; padding: 2px; border: 1px solid #ffae00;"><a href="http://www.linuxday.it"><img class="nobo" src="img/ld66.png"></a> 27/10/2007<br>OGGI! 
226     </td></tr></table>-->
227 </td>
228 <td align="right"><div style="padding-right: 8px;">
229
230
231
232 <script type="text/javascript"><!--
233 google_ad_client = "pub-5246925322544303";
234 google_ad_width = 234;
235 google_ad_height = 60;
236 google_ad_format = "234x60_as";
237 google_ad_type = "text_image";
238 google_ad_channel = "";
239 google_color_border = "808080";
240 google_color_bg = "f6f6f6";
241 google_color_link = "ffae00";
242 google_color_text = "404040";
243 google_color_url = "000000";
244 //-->
245 </script>
246 <script type="text/javascript"
247   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
248 </script>
249
250
251
252 </div></td>
253 </td></table>
254 </div>';
255
256 $brisk_vertical_menu = '
257 <!--  =========== vertical menu ===========  -->
258 <div class="topmenu">
259 <!-- <a target="_blank" href="/briskhome.php"></a> -->
260 <img class="nobo" src="img/brisk_start.png" onmouseover="$(\'webstart\').style.visibility = \'visible\';">
261 <div class="webstart" id="webstart" onmouseover="this.style.visibility = \'visible\';" onmouseout="this.style.visibility = \'hidden\';">
262 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php" title="homepage del progetto">homepage</a><br>
263 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#cose" title="di cosa si tratta">cos\'&egrave;</a><br>
264 <a target="_blank" href="http://it.wikipedia.org/wiki/Briscola#Gioco_a_5" title="come si gioca">regole</a><br>
265 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#shots" title="screenshots dell\'applicazione">screenshoots</a><br>
266 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#comp" title="compatibilit&agrave; con i browser">compatibilit&agrave;</a><br>
267 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#sources" title="sorgenti dell\'applicazione">sorgenti</a><br>
268 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#mailing" title="come iscriversi alla mailing list">mailing&nbsp;list</a><br>
269
270 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#prop" title="come fare pubblicit&agrave; a brisk!">propaganda</a><br>
271 <a href="#" title="credits" onclick="act_about();">about</a><br>
272 <a href="mailto:brisk@alternativeoutput.it" title="contatti">contatti</a><br>
273
274 </div>
275 <br><br><br>
276 sponsored by:<br><br>'.$altout_carousel.'<br>
277 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" id="btn_dynamica" src="img/dynamica.png" onMouseOver="show_bigpict(this, \'over\');" onMouseOut="show_bigpict(this, \'out\');"></a><br><br>
278 supported by:<br><br>
279 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" id="btn_brichi" src="img/brichi.png" onMouseOver="show_bigpict(this, \'over\');" onMouseOut="show_bigpict(this, \'out\');"></a><br>
280 <a target="_blank" href="http://www.forumolimpia.it"><img class="nobo" id="btn_foroli" src="img/forumolimpia.gif" onMouseOver="show_bigpict(this, \'over\');" onMouseOut="show_bigpict(this, \'out\');"></a><br><br>
281 <div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
282 </div><br><br></div>
283 %s
284 %s
285 <img class="nobohide" id="btn_dynamica_big" src="img/dynamica_big.png">
286 <img class="nobohide" id="btn_brichi_big" src="img/brichi_big.png">
287 <img class="nobohide" id="btn_foroli_big" src="img/forumolimpia_big.png">
288 '.$altout_carousel_big.'</div>';
289     
290   /* Templates. */
291   if ($ACTION == 'login') {
292 ?>
293 <html>
294 <head>
295 <title>Brisk</title>
296 <link rel="shortcut icon" href="img/brisk_ico.png">
297 <script type="text/javascript" src="dnd.js"></script>
298 <script type="text/javascript" src="dom-drag.js"></script>
299 <script type="text/javascript" src="commons.js"></script> 
300 <script type="text/javascript" src="xhr.js"></script>
301 <script type="text/javascript" src="preload_img.js"></script>
302 <script type="text/javascript" src="AC_OETags.js"></script>
303 <link rel="stylesheet" type="text/css" href="brisk.css">
304 <link rel="stylesheet" type="text/css" href="room.css">
305
306 <SCRIPT type="text/javascript"><!--
307    var g_withflash = false;
308    var g_is_spawn = 0; 
309    window.onload = function() {
310      g_withflash = DetectFlashVer(6,0,0);
311      if (g_withflash == false) {
312        $("proflash").innerHTML = 'Audio con Flash.<br><a href="http://www.macromedia.com/"><img class="nobo" style="padding: 4px; width:73; height: 19;" src="img/download_now_flash.gif"></a>';
313      }
314      else
315        $("proflashext").innerHTML = "";
316      $("nameid").focus();
317    }
318    //-->
319 </SCRIPT>
320 </head>
321 <body>
322 <?php
323     printf($brisk_header_form);
324     printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
325     printf($brisk_vertical_menu, '', '');
326     printf("</td><td>");
327 ?> 
328
329 <!--  =========== tables ===========  -->
330 <?php echo "$body"; ?>
331 <br>
332 <div style="text-align: center;">
333    <br><br><br>
334 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
335 <form method="post" action="">
336 <input id="nameid" name="name" type="text" size="24" maxlength="12" value="">
337 <input id="sub"    value="entra" type="submit" class="button">
338 </form>
339 </div></td></tr></table>
340 <br><br><br><br>
341
342 <div id="imgct"></div>
343 <div id="logz"></div>
344 <div id="sandbox"></div>
345 <div id="sandbox2"></div>
346 <div id="response"></div>
347 <div id="xhrstart"></div>
348 <pre>
349 <div id="xhrlog"></div>
350 </pre>
351 <div id="xhrdeltalog"></div>
352 </body>
353 </html>
354 <?php
355   }
356   else if ($ACTION == 'room') {
357   ?>
358 <html>
359 <head>
360 <title>Brisk</title>
361 <link rel="shortcut icon" href="img/brisk_ico.png">
362 <script type="text/javascript" src="dnd.js"></script>
363 <script type="text/javascript" src="dom-drag.js"></script>
364 <script type="text/javascript" src="commons.js"></script> 
365 <script type="text/javascript" src="xhr.js"></script>
366 <script type="text/javascript" src="preload_img.js"></script>
367 <script type="text/javascript" src="AC_OETags.js"></script>
368 <link rel="stylesheet" type="text/css" href="brisk.css">
369 <link rel="stylesheet" type="text/css" href="room.css">
370 <SCRIPT type="text/javascript"><!--
371    var sess;
372    var stat = "";
373    var subst = "";
374    var gst  = new globst();
375    var g_is_spawn = 0; 
376
377    var g_withflash = false;
378    var g_imgct= 0;
379    var g_imgtot = g_preload_img_arr.length;
380    var myfrom = "index_php";
381    window.onload = function() {
382 <?php
383 if ($BRISK_SHOWHTML == "debugtable") {
384 ?>
385      room_checkspace(12, <?php echo TABLES_N; ?>, 50);
386 <?php
387 }
388 else {
389 ?>
390      // alert("INDEX START");
391      xhr_rd = createXMLHttpRequest();
392      sess = "<?php echo "$sess"; ?>";
393
394      window.onunload = onunload_cb;
395      g_withflash = DetectFlashVer(6,0,0);
396      if (g_withflash == false) {
397        $("proflash").innerHTML = 'Audio con Flash.<br><a href="http://www.macromedia.com/"><img class="nobo" style="padding: 4px; width:73; height: 19;" src="img/download_now_flash.gif"></a>';
398      }
399      else
400        $("proflashext").innerHTML = "";
401      setTimeout(xhr_rd_poll, 0, sess); 
402      // alert("ARR LENGTH "+g_preload_img_arr.length);
403      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
404      $("txt_in").focus();
405 <?php
406 }
407 ?>
408    }
409    //-->
410 </SCRIPT>
411 </head>
412 <body>
413 <?php
414    printf($brisk_header_form);
415    printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
416    printf($brisk_vertical_menu, '<input type="button" class="button" name="xhelp"  value="Help." onclick="act_help();"><br><!-- <br><input type="button" class="button" name="xabout"  value="About." onclick="act_about();">--><br><br><br>',
417            $brisk_donate);
418    printf("</td><td>");
419 ?> 
420 <!--  =========== tables ===========  -->
421 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
422 <table class="macro"><tr><td>
423 <?php echo "$tables"; ?>
424 </td></tr><tr><td>
425     <?php echo "$standup"; ?>
426 </td></tr></table>
427 </td></tr></table>
428
429 <!--  =========== bottom ===========  -->
430     <div id="bottom" class="bottom" style="/*  background-color: green; */">
431 <b>Chat</b><br>
432 <div id="txt" class="chatt">
433 </div>
434     <table align=center style="width: 98%; margin: auto;"><tr><td style="width:1%; text-align: right;">
435     <div id="myname"></div>
436     </td><td>
437     <input id="txt_in" type="text" style="width: 100%;" onkeypress="chatt_checksend(this,event);">
438     </td></tr></table>
439 </div>
440 <div id="heartbit"></div>
441 <div id="sandbox"></div>
442 <div id="imgct"></div>
443 <div id="logz"></div>
444 <div id="sandbox2"></div>
445 <div id="response"></div>
446 <div id="remark"></div>
447 <div id="xhrstart"></div>
448 <div id="xhrlog"></div>
449 <div id="xhrdeltalog"></div>
450 </div>
451 </body>
452 </html>
453 <?php
454    }
455 }
456
457 main();
458
459 ?>