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