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