layout and class refact
[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 <!--  =========== vertical menu ===========  -->
214 <div class="topmenu">
215 <a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a>
216 <br><br><br>
217 sponsored by:<br><br>'.$altout_carousel.'<br>
218 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" src="img/dynamica.png"></a><br><br>
219 supported by:<br><br>
220 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" src="img/brichi.png"></a><br><br>
221 <div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
222 </div><br><br></div>
223 %s
224 %s
225 </div>';
226     
227   /* Templates. */
228   if ($ACTION == 'login') {
229 ?>
230 <html>
231 <head>
232 <title>Brisk</title>
233 <link rel="shortcut icon" href="img/brisk_ico.png">
234 <script type="text/javascript" src="dnd.js"></script>
235 <script type="text/javascript" src="dom-drag.js"></script>
236 <script type="text/javascript" src="commons.js"></script> 
237 <script type="text/javascript" src="xhr.js"></script>
238 <script type="text/javascript" src="preload_img.js"></script>
239 <script type="text/javascript" src="AC_OETags.js"></script>
240 <link rel="stylesheet" type="text/css" href="brisk.css">
241 <link rel="stylesheet" type="text/css" href="room.css">
242 </head>
243 <body>
244 <SCRIPT type="text/javascript">
245    var g_withflash = false;
246
247    window.onload = function() {
248      g_withflash = DetectFlashVer(6,0,0);
249      if (g_withflash == false) {
250        $("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>';
251      }
252      else
253        $("proflashext").innerHTML = "";
254      $("nameid").focus();
255    }
256 </SCRIPT>
257 <?php
258     printf($brisk_header_form, '', '');
259 ?> 
260
261 <!--  =========== tables ===========  -->
262 <div id="tables" class="tables">
263 <?php echo "$body"; ?>
264 <br>
265 <div style="text-align: center;">
266    <br><br><br>
267 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
268 <form method="post" action="">
269 <input id="nameid" name="name" type="text" size="24" maxlength="12" value="">
270 <input id="sub"    value="entra" type="submit" class="button">
271 </form>
272 </div>
273 </div></div>
274 <br><br><br><br>
275
276 <div id="imgct"></div>
277 <div id="logz"></div>
278 <div id="sandbox"></div>
279 <div id="sandbox2"></div>
280 <div id="response"></div>
281 <div id="xhrstart"></div>
282 <pre>
283 <div id="xhrlog"></div>
284 </pre>
285 <div id="xhrdeltalog"></div>
286 </body>
287 </html>
288 <?php
289   }
290   else if ($ACTION == 'room') {
291   ?>
292 <html>
293 <head>
294 <title>Brisk</title>
295 <link rel="shortcut icon" href="img/brisk_ico.png">
296 <script type="text/javascript" src="dnd.js"></script>
297 <script type="text/javascript" src="dom-drag.js"></script>
298 <script type="text/javascript" src="commons.js"></script> 
299 <script type="text/javascript" src="xhr.js"></script>
300 <script type="text/javascript" src="preload_img.js"></script>
301 <script type="text/javascript" src="AC_OETags.js"></script>
302 <link rel="stylesheet" type="text/css" href="brisk.css">
303 <link rel="stylesheet" type="text/css" href="room.css">
304 </head>
305 <body>
306 <SCRIPT type="text/javascript">
307    var sess;
308    var stat = "";
309    var subst = "";
310    var gst  = new globst();
311
312    var g_withflash = false;
313    var g_imgct= 0;
314    var g_imgtot = g_preload_img_arr.length;
315    var myfrom = "index_php";
316    window.onload = function() {
317 <?php
318 if ($BRISK_SHOWHTML == "debugtable") {
319 ?>
320      room_checkspace(12, <?php echo TABLES_N; ?>, 50);
321 <?php
322 }
323 else {
324 ?>
325      // alert("INDEX START");
326      xhr_rd = createXMLHttpRequest();
327      sess = "<?php echo "$sess"; ?>";
328
329      window.onunload = onunload_cb;
330      g_withflash = DetectFlashVer(6,0,0);
331      if (g_withflash == false) {
332        $("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>';
333      }
334      else
335        $("proflashext").innerHTML = "";
336      setTimeout(xhr_rd_poll, 0, sess); 
337      // alert("ARR LENGTH "+g_preload_img_arr.length);
338      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
339      $("txt_in").focus();
340 <?php
341 }
342 ?>
343    }
344
345 </SCRIPT>
346 <?php
347     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>',
348            $brisk_donate);
349 ?> 
350 <!--  =========== tables ===========  -->
351 <div id="tables" class="tables">
352 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
353 <table class="macro"><tr><td>
354 <?php echo "$tables"; ?>
355 </td></tr><tr><td>
356     <?php echo "$standup"; ?>
357 </td></tr></table>
358 </div>
359
360 <!--  =========== bottom ===========  -->
361     <div id="bottom" class="bottom" style="padding: 6px; /*  background-color: green; */">
362 <b>Chat</b><br>
363 <div id="txt" class="chatt">
364 </div>
365
366     <table style="width: 100%;"><tr><td style="width:13em; text-align: right;">
367     <div id="myname"></div>
368     </td><td>
369     <input id="txt_in" type="text" style="width: 100%;" onkeypress="chatt_checksend(this,event);">
370     </td></tr></table>
371 </div>
372 <div id="heartbit"></div>
373 <div id="sandbox"></div>
374 <div id="imgct"></div>
375 <div id="logz"></div>
376 <div id="sandbox2"></div>
377 <div id="response"></div>
378 <div id="remark"></div>
379 <div id="xhrstart"></div>
380 <div id="xhrlog"></div>
381 <div id="xhrdeltalog"></div>
382 </div>
383 </body>
384 </html>
385 <?php
386    }
387 }
388
389 main();
390
391 ?>