aggiunti banner google
[brisk.git] / web / index.php
1 <?php
2 /*
3  *  brisk - index.php
4  *
5  *  Copyright (C) 2006 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   $NOGOOGLE = BRISK_DEBUG;
37
38   $body = "";
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 .= '<table class="room_tab" align="center">';
96     for ($i = 0 ; $i < TABLES_N ; $i++) {
97       if ($i % 4 == 0)
98         $tables .= '<tr>';
99       $tables .= '<td valign="top" align="center" class="room_td"><div class="room_div"><b>Tavolo '.$i.'</b><br><br>';
100       $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
101       $tables .= sprintf('<div class="table_act" id="table_act%d"></div>', $i);
102       $tables .= '</div></td>'."\n";
103       if ($i % 4 == 3)
104         $tables .= '</tr>';
105     }
106     $tables .= '<tr><td colspan="4">';
107     $tables .= '<div class="room_ex_standup">';
108     $tables .= '<b>Giocatori in piedi</b><br><br>';
109     
110     $tables .= sprintf('<div id="standup" class="room_standup"></div>');
111     $tables .= '<div id="esco" class="esco"></div>';
112     $tables .= '</td></tr>';
113     
114     $tables .= '</table>';
115   }
116
117   $altout_propag = array( array ( 'url' => 'http://www.alternativeoutput.it',
118                                   'content' => '<img class="nobo" src="img/altout80x15.png">' ),
119                           array ( 'url' => 'http://virtualsky.alternativeoutput.it',
120                                   'content' => '<img class="nobo" src="img/virtualsky80x15.png">' )
121                           );
122   
123   // seed with microseconds since last "whole" second
124   srand ((double) microtime() * 1000000);
125   $randval = rand(0,count($altout_propag)-1);
126   $altout_carousel = sprintf('<a target="_blank" href="%s">%s</a>',
127                              $altout_propag[$randval]['url'],
128                              $altout_propag[$randval]['content']);
129                          
130
131   $brisk_donate = file_get_contents(FTOK_PATH."/brisk_donate.txt");
132   if ($brisk_donate == FALSE)
133     $brisk_donate = "";
134
135 $brisk_header_form = '<div class="container">
136 <!-- =========== header ===========  -->
137 <div id="header" class="header">
138 <table width="100%%" border="0" cols="3"><tr>
139 <td align="left"><div style="padding-left: 8px;">'.($NOGOOGLE == 'y' ? '' : 
140 '<script type="text/javascript"><!--
141 google_ad_client = "pub-5246925322544303";
142 google_ad_width = 234;
143 google_ad_height = 60;
144 google_ad_format = "234x60_as";
145 google_ad_type = "text_image";
146 google_ad_channel = "";
147 google_color_border = "808080";
148 google_color_bg = "f6f6f6";
149 google_color_link = "ffae00";
150 google_color_text = "404040";
151 google_color_url = "000000";
152 //-->
153 </script>
154 <script type="text/javascript"
155   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
156 </script>').'</div></td>
157 <td align="center"><div>
158     <img class="nobo" src="img/brisk_logo64.png">
159     briscola chiamata in salsa ajax<br><br>
160     </div></td>
161 <td align="right"><div style="padding-right: 8px;">'.($NOGOOGLE == 'y' ? '' : 
162 '<script type="text/javascript"><!--
163 google_ad_client = "pub-5246925322544303";
164 google_ad_width = 234;
165 google_ad_height = 60;
166 google_ad_format = "234x60_as";
167 google_ad_type = "text_image";
168 google_ad_channel = "";
169 google_color_border = "808080";
170 google_color_bg = "f6f6f6";
171 google_color_link = "ffae00";
172 google_color_text = "404040";
173 google_color_url = "000000";
174 //-->
175 </script>
176 <script type="text/javascript"
177   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
178 </script>').'</div></td>
179 </td></table>
180 </div>
181 <!--  =========== vertical menu ===========  -->
182 <div class="topmenu">
183 <a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a>
184 <br><br><br>
185 sponsored by:<br><br>'.$altout_carousel.'<br>
186 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" src="img/dynamica.png"></a><br><br>
187 supported by:<br><br>
188 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" src="img/brichi.png"></a><br><br>
189 <div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
190 </div><br><br></div>
191 %s
192 %s
193 </div>';
194     
195   /* Templates. */
196   if ($ACTION == 'login') {
197 ?>
198 <html>
199 <head>
200 <title>Brisk</title>
201 <link rel="shortcut icon" href="img/brisk_ico.png">
202 <script type="text/javascript" src="dnd.js"></script>
203 <script type="text/javascript" src="dom-drag.js"></script>
204 <script type="text/javascript" src="commons.js"></script> 
205 <script type="text/javascript" src="xhr.js"></script>
206 <script type="text/javascript" src="preload_img.js"></script>
207 <script type="text/javascript" src="AC_OETags.js"></script>
208 <link rel="stylesheet" type="text/css" href="brisk.css">
209 <link rel="stylesheet" type="text/css" href="room.css">
210 </head>
211 <body>
212 <SCRIPT type="text/javascript">
213    var g_withflash = false;
214
215    window.onload = function() {
216      g_withflash = DetectFlashVer(6,0,0);
217      if (g_withflash == false) {
218        $("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>';
219      }
220      else
221        $("proflashext").innerHTML = "";
222      $("nameid").focus();
223    }
224 </SCRIPT>
225 <?php
226     printf($brisk_header_form, '', '');
227 ?> 
228
229 <!--  =========== tables ===========  -->
230 <div id="tables" class="tables">
231 <?php echo "$body"; ?>
232
233 <br>
234 <div style="text-align: center;">
235    <br><br><br>
236 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
237 <form method="post" action="">
238 <input id="nameid" name="name" type="text" size="24" maxlength="12" value="">
239 <input id="sub"    value="entra" type="submit" class="button">
240 </form>
241 </div>
242 </div></div>
243 <br><br><br><br>
244
245 <div id="imgct"></div>
246 <div id="logz"></div>
247 <div id="sandbox"></div>
248 <div id="sandbox2"></div>
249 <div id="response"></div>
250 <div id="xhrstart"></div>
251 <pre>
252 <div id="xhrlog"></div>
253 </pre>
254 <div id="xhrdeltalog"></div>
255 </body>
256 </html>
257 <?php
258   }
259   else if ($ACTION == 'room') {
260   ?>
261 <html>
262 <head>
263 <title>Brisk</title>
264 <link rel="shortcut icon" href="img/brisk_ico.png">
265 <script type="text/javascript" src="dnd.js"></script>
266 <script type="text/javascript" src="dom-drag.js"></script>
267 <script type="text/javascript" src="commons.js"></script> 
268 <script type="text/javascript" src="xhr.js"></script>
269 <script type="text/javascript" src="preload_img.js"></script>
270 <script type="text/javascript" src="AC_OETags.js"></script>
271 <link rel="stylesheet" type="text/css" href="brisk.css">
272 <link rel="stylesheet" type="text/css" href="room.css">
273 </head>
274 <body>
275 <SCRIPT type="text/javascript">
276    var sess;
277    var stat = "";
278    var subst = "";
279    var gst  = new globst();
280
281    var g_withflash = false;
282    var g_imgct= 0;
283    var g_imgtot = g_preload_img_arr.length;
284    var myfrom = "index_php";
285    window.onload = function() {
286 <?php
287 if ($BRISK_SHOWHTML == "debugtable") {
288 ?>
289      room_checkspace(12,8,50);
290 <?php
291 }
292 else {
293 ?>
294      // alert("INDEX START");
295      xhr_rd = createXMLHttpRequest();
296      sess = "<?php echo "$sess"; ?>";
297
298      window.onunload = onunload_cb;
299      g_withflash = DetectFlashVer(6,0,0);
300      if (g_withflash == false) {
301        $("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>';
302      }
303      else
304        $("proflashext").innerHTML = "";
305      setTimeout(xhr_rd_poll, 0, sess); 
306      // alert("ARR LENGTH "+g_preload_img_arr.length);
307      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
308      $("txt_in").focus();
309 <?php
310 }
311 ?>
312    }
313
314 </SCRIPT>
315 <?php
316     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>',
317            $brisk_donate);
318 ?> 
319 <!--  =========== tables ===========  -->
320 <div id="tables" class="tables">
321 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
322 <?php echo "$tables"; ?>
323 </div>
324
325 <!--  =========== bottom ===========  -->
326 <div id="bottom" class="bottom">
327 <b>Chat</b>
328 <div id="txt" class="chatt">
329 </div>
330 <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>
331 </div>
332 <div id="heartbit"></div>
333 <div id="sandbox"></div>
334 <div id="imgct"></div>
335 <div id="logz"></div>
336 <div id="sandbox2"></div>
337 <div id="response"></div>
338 <div id="remark"></div>
339 <div id="xhrstart"></div>
340 <div id="xhrlog"></div>
341 <div id="xhrdeltalog"></div>
342 </div>
343 </body>
344 </html>
345 <?php
346    }
347 }
348
349 main();
350
351 ?>