IE compatibility
[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("brisk.phh");
25 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
26   echo "Debugging time!";
27   exit;
28 }
29
30 log_load((isset($sess) ? $sess : "XXX"), "LOAD: index.php");
31
32 function main()
33 {
34   GLOBAL $sess, $name, $BRISK_SHOWHTML, $BRISK_DEBUG, $_SERVER;
35   
36   $body = "";
37   $tables = "";
38   $standup = "";
39   $ACTION = "login";
40   
41   if (isset($BRISK_SHOWHTML) == FALSE) {
42     $is_table = FALSE;
43     $sem = lock_data();
44     $bri = &load_data();
45     
46     /* Actions */
47     if (validate_sess($sess)) {
48       $bri->garbage_manager(TRUE);
49       if (($user = &$bri->get_user($sess, &$idx)) != FALSE) {
50         if ($user->stat == "table") {
51           header ("Location: table.php");
52           unlock_data($sem);
53           exit;
54         }
55         $ACTION = "room";
56       }
57     }
58     
59     if ($ACTION == "login" && isset($name)) {
60       $bri->garbage_manager(TRUE);
61       /* try login */
62       if (($user = &$bri->add_user(&$sess, &$idx, $name, $_SERVER['REMOTE_ADDR'])) != FALSE) {
63         $ACTION = "room";
64         
65         // setcookie ("sess", "", time() + 180);      
66         $bri->standup_update(&$user);
67         
68         if (save_data(&$bri) == FALSE) {
69           echo "ERRORE SALVATAGGIO\n";
70           exit;
71         }
72       }
73       else {
74         /* Login Rendering */
75         if ($idx == -2)
76           $body .= '<div class="urgmsg"><b>Il nickname deve contenere almeno una lettera o una cifra.</b></div>';
77         else if ($idx == -1) 
78           $body .= '<div class="urgmsg"><b>Spiacenti, non ci sono pi&ugrave; posti liberi. Riprova pi&ugrave; tardi.</b></div>';
79         else
80           $body .= '<div class="urgmsg"><b>Il tuo nickname &egrave; gi&agrave; in uso.</b></div>';
81       }
82     }
83     unlock_data($sem);
84   }
85   /* Rendering. */
86
87   if ($BRISK_SHOWHTML == "debugtable") {
88     $ACTION = "room";
89   }
90   else if ($BRISK_SHOWHTML == "debuglogin") {
91     $ACTION = "login";
92   }
93
94   if ($ACTION == "room") {
95     $tables .= '<div class="room_tab">';
96     $tables .= '<table class="room_tab" align="center">';
97     for ($i = 0 ; $i < TABLES_N ; $i++) {
98       if ($i % 4 == 0)
99         $tables .= '<tr>';
100       $tables .= '<td>';
101       $tables .= '<div class="room_div"><div class="room_tit"><b>Tavolo '.$i.'</b></div>';
102       $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
103       $tables .= sprintf('<div class="table_act" id="table_act%d"></div>', $i);
104       $tables .= '</div>';
105       $tables .= '</td>'."\n";
106       if ($i % 4 == 3)
107         $tables .= '</tr>';
108     }
109     $tables .= '</table></div>';
110
111
112     $standup .= '<table class="room_standup" align="center"><tr><td>';
113     $standup .= '<div class="room_ex_standup">';
114     $standup .= '<div class="room_tit"><b>Giocatori in piedi</b></div>';
115     
116     $standup .= sprintf('<div id="standup" class="room_standup"></div>');
117     $standup .= '<div id="esco" class="esco"></div>';
118     $standup .= '</div></td></tr></table>';
119     
120     // $tables .= '</td></tr></table>';
121
122     /*
123     $tables .= '</td></tr><tr><td>';
124     $tables .= '<table class="room_tab" align="center">';
125     $tables .= '<tr><td>';
126     $tables .= '<div class="room_ex_standup">';
127     $tables .= '<b>Giocatori in piedi</b>';
128     
129     $tables .= sprintf('<div id="standup" class="room_standup"></div>');
130     $tables .= '<div id="esco" class="esco"></div>';
131     */
132     // $tables .= '</td></tr></table>';
133   }
134
135   $altout_propag = array( array ( 'url' => 'http://www.alternativeoutput.it',
136                                   'content' => '<img class="nobo" src="img/altout80x15.png">' ),
137                           array ( 'url' => 'http://virtualsky.alternativeoutput.it',
138                                   'content' => '<img class="nobo" src="img/virtualsky80x15.png">' )
139                           );
140   
141   // seed with microseconds since last "whole" second
142   srand ((double) microtime() * 1000000);
143   $randval = rand(0,count($altout_propag)-1);
144   $altout_carousel = sprintf('<a target="_blank" href="%s">%s</a>',
145                              $altout_propag[$randval]['url'],
146                              $altout_propag[$randval]['content']);
147                          
148
149   $brisk_donate = file_get_contents(FTOK_PATH."/brisk_donate.txt");
150   if ($brisk_donate == FALSE)
151     $brisk_donate = "";
152
153 $brisk_header_form = '<div class="container">
154 <!-- =========== header ===========  -->
155 <div id="header" class="header">
156 <table width="100%%" border="0" cols="3"><tr>
157 <td align="left"><div style="padding-left: 8px;">
158
159
160
161 <script type="text/javascript"><!--
162 google_ad_client = "pub-5246925322544303";
163 google_ad_width = 234;
164 google_ad_height = 60;
165 google_ad_format = "234x60_as";
166 google_ad_type = "text_image";
167 google_ad_channel = "";
168 google_color_border = "808080";
169 google_color_bg = "f6f6f6";
170 google_color_link = "ffae00";
171 google_color_text = "404040";
172 google_color_url = "000000";
173 //-->
174 </script>
175 <script type="text/javascript"
176   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
177 </script>
178
179
180
181 </div></td>
182 <td align="center"><div>
183     <img class="nobo" src="img/brisk_logo64.png">
184     briscola chiamata in salsa ajax<br>
185     </div></td>
186 <td align="right"><div style="padding-right: 8px;">
187
188
189
190 <script type="text/javascript"><!--
191 google_ad_client = "pub-5246925322544303";
192 google_ad_width = 234;
193 google_ad_height = 60;
194 google_ad_format = "234x60_as";
195 google_ad_type = "text_image";
196 google_ad_channel = "";
197 google_color_border = "808080";
198 google_color_bg = "f6f6f6";
199 google_color_link = "ffae00";
200 google_color_text = "404040";
201 google_color_url = "000000";
202 //-->
203 </script>
204 <script type="text/javascript"
205   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
206 </script>
207
208
209
210 </div></td>
211 </td></table>
212 </div>';
213
214 $brisk_vertical_menu = '
215 <!--  =========== vertical menu ===========  -->
216 <div class="topmenu">
217 <a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a>
218 <br><br><br>
219 sponsored by:<br><br>'.$altout_carousel.'<br>
220 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" src="img/dynamica.png"></a><br><br>
221 supported by:<br><br>
222 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" src="img/brichi.png"></a><br><br>
223 <div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
224 </div><br><br></div>
225 %s
226 %s
227 </div>';
228     
229   /* Templates. */
230   if ($ACTION == 'login') {
231 ?>
232 <html>
233 <head>
234 <title>Brisk</title>
235 <link rel="shortcut icon" href="img/brisk_ico.png">
236 <script type="text/javascript" src="dnd.js"></script>
237 <script type="text/javascript" src="dom-drag.js"></script>
238 <script type="text/javascript" src="commons.js"></script> 
239 <script type="text/javascript" src="xhr.js"></script>
240 <script type="text/javascript" src="preload_img.js"></script>
241 <script type="text/javascript" src="AC_OETags.js"></script>
242 <link rel="stylesheet" type="text/css" href="brisk.css">
243 <link rel="stylesheet" type="text/css" href="room.css">
244 </head>
245 <body>
246 <SCRIPT type="text/javascript">
247    var g_withflash = false;
248
249    window.onload = function() {
250      g_withflash = DetectFlashVer(6,0,0);
251      if (g_withflash == false) {
252        $("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>';
253      }
254      else
255        $("proflashext").innerHTML = "";
256      $("nameid").focus();
257    }
258 </SCRIPT>
259 <?php
260     printf($brisk_header_form);
261     printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
262     printf($brisk_vertical_menu, '', '');
263     printf("</td><td>");
264 ?> 
265
266 <!--  =========== tables ===========  -->
267 <?php echo "$body"; ?>
268 <br>
269 <div style="text-align: center;">
270    <br><br><br>
271 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
272 <form method="post" action="">
273 <input id="nameid" name="name" type="text" size="24" maxlength="12" value="">
274 <input id="sub"    value="entra" type="submit" class="button">
275 </form>
276 </div></td></tr></table>
277 <br><br><br><br>
278
279 <div id="imgct"></div>
280 <div id="logz"></div>
281 <div id="sandbox"></div>
282 <div id="sandbox2"></div>
283 <div id="response"></div>
284 <div id="xhrstart"></div>
285 <pre>
286 <div id="xhrlog"></div>
287 </pre>
288 <div id="xhrdeltalog"></div>
289 </body>
290 </html>
291 <?php
292   }
293   else if ($ACTION == 'room') {
294   ?>
295 <html>
296 <head>
297 <title>Brisk</title>
298 <link rel="shortcut icon" href="img/brisk_ico.png">
299 <script type="text/javascript" src="dnd.js"></script>
300 <script type="text/javascript" src="dom-drag.js"></script>
301 <script type="text/javascript" src="commons.js"></script> 
302 <script type="text/javascript" src="xhr.js"></script>
303 <script type="text/javascript" src="preload_img.js"></script>
304 <script type="text/javascript" src="AC_OETags.js"></script>
305 <link rel="stylesheet" type="text/css" href="brisk.css">
306 <link rel="stylesheet" type="text/css" href="room.css">
307 </head>
308 <body>
309 <SCRIPT type="text/javascript">
310    var sess;
311    var stat = "";
312    var subst = "";
313    var gst  = new globst();
314
315    var g_withflash = false;
316    var g_imgct= 0;
317    var g_imgtot = g_preload_img_arr.length;
318    var myfrom = "index_php";
319    window.onload = function() {
320 <?php
321 if ($BRISK_SHOWHTML == "debugtable") {
322 ?>
323      room_checkspace(12, <?php echo TABLES_N; ?>, 50);
324 <?php
325 }
326 else {
327 ?>
328      // alert("INDEX START");
329      xhr_rd = createXMLHttpRequest();
330      sess = "<?php echo "$sess"; ?>";
331
332      window.onunload = onunload_cb;
333      g_withflash = DetectFlashVer(6,0,0);
334      if (g_withflash == false) {
335        $("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>';
336      }
337      else
338        $("proflashext").innerHTML = "";
339      setTimeout(xhr_rd_poll, 0, sess); 
340      // alert("ARR LENGTH "+g_preload_img_arr.length);
341      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
342      $("txt_in").focus();
343 <?php
344 }
345 ?>
346    }
347
348 </SCRIPT>
349 <?php
350    printf($brisk_header_form);
351    printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
352    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>',
353            $brisk_donate);
354    printf("</td><td>");
355 ?> 
356 <!--  =========== tables ===========  -->
357 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
358 <table class="macro"><tr><td>
359 <?php echo "$tables"; ?>
360 </td></tr><tr><td>
361     <?php echo "$standup"; ?>
362 </td></tr></table>
363 </td></tr></table>
364
365 <!--  =========== bottom ===========  -->
366     <div id="bottom" class="bottom" style="/*  background-color: green; */">
367 <b>Chat</b><br>
368 <div id="txt" class="chatt">
369 </div>
370
371     <table style="width: 100%;"><tr><td style="width:13em; text-align: right;">
372     <div id="myname"></div>
373     </td><td>
374     <input id="txt_in" type="text" style="width: 100%;" onkeypress="chatt_checksend(this,event);">
375     </td></tr></table>
376 </div>
377 <div id="heartbit"></div>
378 <div id="sandbox"></div>
379 <div id="imgct"></div>
380 <div id="logz"></div>
381 <div id="sandbox2"></div>
382 <div id="response"></div>
383 <div id="remark"></div>
384 <div id="xhrstart"></div>
385 <div id="xhrlog"></div>
386 <div id="xhrdeltalog"></div>
387 </div>
388 </body>
389 </html>
390 <?php
391    }
392 }
393
394 main();
395
396 ?>