info sulla pass
[brisk.git] / web / index.php
1 <?php
2 /*
3  *  brisk - index.php
4  *
5  *  Copyright (C) 2006-2008 Matteo Nastasi
6  *                          mailto: nastasi@alternativeoutput.it 
7  *                                  matteo.nastasi@milug.org
8  *                          web: http://www.alternativeoutput.it
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details. You should have received a
19  * copy of the GNU General Public License along with this program; if
20  * not, write to the Free Software Foundation, Inc, 59 Temple Place -
21  * Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * $Id$
24  *
25  */
26
27 require_once("Obj/brisk.phh");
28 require_once("Obj/auth.phh");
29 require_once("Obj/proxyscan.phh");
30
31 // Use of proxies isn't allowed.
32 if (!$G_is_local && is_proxy()) 
33    exit;
34
35 require_once("briskin5/Obj/briskin5.phh");
36 if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
37   echo "Debugging time!";
38   exit;
39 }
40
41 log_load("index.php");
42
43 function main()
44 {
45   GLOBAL $G_with_topbanner, $G_topbanner, $G_is_local;
46   GLOBAL $sess, $name, $pass_private, $table_idx, $table_token, $BRISK_SHOWHTML, $BRISK_DEBUG, $_SERVER;
47
48   $body = "";
49   $tables = "";
50   $standup = "";
51   $ACTION = "login";
52   
53   if (isset($BRISK_SHOWHTML) == FALSE) {
54     $is_table = FALSE;
55     $sem = Room::lock_data();
56     log_main("lock Room");
57     $room = &Room::load_data();
58     $curtime = time();
59
60     /* Actions */
61
62     if (validate_sess($sess)) {
63       log_main("pre garbage_manager UNO");
64       $room->garbage_manager(TRUE);
65       log_main("post garbage_manager");
66       if (($user = &$room->get_user($sess, &$idx)) != FALSE) {
67         log_main("user stat: ".$user->stat);
68         if ($user->stat == "table") {
69           if (Room::save_data(&$room) == FALSE) {
70             echo "ERRORE SALVATAGGIO\n";
71             exit;
72           }
73           log_main("unlock Room");
74           Room::unlock_data($sem);
75           setcookie("table_token", $user->table_token, $curtime + 31536000);
76           setcookie("table_idx", $user->table, $curtime + 31536000);
77           header ("Location: briskin5/index.php");
78           exit;
79         }
80         $ACTION = "room";
81       }
82
83       if (Room::save_data(&$room) == FALSE) {
84         echo "ERRORE SALVATAGGIO\n";
85         exit;
86       }
87     }
88     
89     if ($ACTION == "login" && isset($name)) {
90       
91       log_main("pre garbage_manager DUE");
92
93       if (isset($pass_private) == FALSE) {
94         $pass_private = FALSE;
95       }
96
97       $room->garbage_manager(TRUE);
98       /* try login */
99       if (($user = &$room->add_user(&$sess, &$idx, $name, $pass_private, $_SERVER['REMOTE_ADDR'])) != FALSE) {
100         $ACTION = "room";
101         if ($idx < 0) {
102           $idx = -$idx - 1;
103           $login_exists = TRUE;
104         }
105         else
106           $login_exists = FALSE;
107
108         log_legal($curtime, $user->sess, $user->name, "STAT:LOGIN", '');
109
110
111         // setcookie ("sess", "", time() + 180);      
112         $room->standup_update(&$user);
113         
114         if (Room::save_data(&$room) == FALSE) {
115           echo "ERRORE SALVATAGGIO\n";
116           exit;
117         }
118       }
119       else {
120         /* Login Rendering */
121         if ($idx == -3)
122           $body .= '<div class="urgmsg"><b>Utente e/o password errati.</b></div>';
123         else if ($idx == -2)
124           $body .= '<div class="urgmsg"><b>Il nickname deve contenere almeno una lettera o una cifra.</b></div>';
125         else if ($idx == -1) 
126           $body .= '<div class="urgmsg"><b>Spiacenti, non ci sono pi&ugrave; posti liberi. Riprova pi&ugrave; tardi.</b></div>';
127         else
128           $body .= '<div class="urgmsg"><b>Il tuo nickname &egrave; gi&agrave; in uso.</b></div>';
129       }
130     }
131     Room::unlock_data($sem);
132   }
133   /* Rendering. */
134
135   if ($BRISK_SHOWHTML == "debugtable") {
136     $ACTION = "room";
137   }
138   else if ($BRISK_SHOWHTML == "debuglogin") {
139     $ACTION = "login";
140   }
141
142   if ($ACTION == "room") {
143     $tables .= '<div class="room_tab">';
144     $tables .= '<table class="room_tab">';
145     for ($i = 0 ; $i < TABLES_N ; $i++) {
146       if ($i % 4 == 0)
147         $tables .= '<tr>';
148       $tables .= '<td>';
149       $tables .= '<div class="room_div"><div class="room_tit"><b>Tavolo '.$i.'</b></div>';
150       $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
151       $tables .= sprintf('<div class="table_act" id="table_act%d"></div>', $i);
152       $tables .= '</div>';
153       $tables .= '</td>'."\n";
154       if ($i % 4 == 3)
155         $tables .= '</tr>';
156     }
157     $tables .= '</table></div>';
158
159
160     $standup .= '<table class="room_standup"><tr><td><div class="room_standup_orig" id="room_standup_orig"></div>';
161     $standup .= '<div class="room_ex_standup">';
162     $standup .= '<div id="room_tit"><span class="room_titin"><b>Giocatori in piedi</b> - <a target="_blank" href="weboftrust.php">Come ottenere user e password</a> - </span></div>';
163     
164     $standup .= sprintf('<div id="standup" class="room_standup"></div>');
165     $standup .= '<div id="esco" class="esco"></div>';
166     $standup .= '</div></td></tr></table>';
167   }
168
169   $altout_propag = array( array ( 'id' => 'btn_altout',
170                                   'url' => 'http://www.alternativeoutput.it',
171                                   'content' => 'img/altout80x15.png',
172                                   'content_big' => 'img/altout80x15.png'),
173                           array ( 'id' => 'btn_virtualsky',
174                                   'url' => 'http://virtualsky.alternativeoutput.it',
175                                   'content' => 'img/virtualsky80x15a.gif',
176                                   'content_big' => 'img/virtualsky_big.png')
177                           );
178   
179   // seed with microseconds since last "whole" second
180   srand ((double) microtime() * 1000000);
181   // $randval = rand(0,count($altout_propag)-1);
182   $randval = 1;
183   $altout_carousel = sprintf('<a target="_blank" href="%s"><img id="%s" class="nobo" src="%s" onMouseOver="show_bigpict(this, \'over\',100,10);" onMouseOut="show_bigpict(this, \'out\',0,0);"></a>',
184                              $altout_propag[$randval]['url'],
185                              $altout_propag[$randval]['id'],
186                              $altout_propag[$randval]['content']);
187                          
188   $altout_carousel_big = sprintf('<img class="nobohide" id="%s_big" src="%s">',
189                                  $altout_propag[$randval]['id'],
190                                  $altout_propag[$randval]['content_big']);
191                          
192
193   $brisk_donate = file_get_contents(FTOK_PATH."/brisk_donate.txt");
194   if ($brisk_donate == FALSE)
195     $brisk_donate = "";
196
197
198
199
200 $brisk_header_form = '<div class="container">
201 <!-- =========== header ===========  -->
202 <div id="header" class="header">
203 <table width="100%%" border="0" cols="3"><tr>
204 <td align="left"><div style="padding-left: 8px;">'.($G_is_local ? '' :
205 '<script type="text/javascript"><!--
206 google_ad_client = "pub-5246925322544303";
207 google_ad_width = 234;
208 google_ad_height = 60;
209 google_ad_format = "234x60_as";
210 google_ad_type = "text_image";
211 google_ad_channel = "";
212 google_color_border = "808080";
213 google_color_bg = "f6f6f6";
214 google_color_link = "ffae00";
215 google_color_text = "404040";
216 google_color_url = "000000";
217 //-->
218 </script>
219 <script type="text/javascript"
220   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
221 </script>'
222 ).'</div></td>
223 <td align="center">'.($G_with_topbanner ? '<table><tr><td>' : '').'<div style="text-align: center;">
224     <img class="nobo" src="img/brisk_logo64.png">
225     briscola chiamata in salsa ajax<br>
226     </div>'.($G_with_topbanner ? sprintf('</td><td>%s</td></tr></table>', $G_topbanner) : '').'</td>
227 <td align="right"><div style="padding-right: 8px;">
228 '.($G_is_local ? '' :
229 '<script type="text/javascript"><!--
230 google_ad_client = "pub-5246925322544303";
231 google_ad_width = 234;
232 google_ad_height = 60;
233 google_ad_format = "234x60_as";
234 google_ad_type = "text_image";
235 google_ad_channel = "";
236 google_color_border = "808080";
237 google_color_bg = "f6f6f6";
238 google_color_link = "ffae00";
239 google_color_text = "404040";
240 google_color_url = "000000";
241 //-->
242 </script>
243 <script type="text/javascript"
244   src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
245 </script>'
246 ).'</div></td>
247 </td></table>
248 </div>';
249
250 $brisk_vertical_menu = '
251 <!--  =========== vertical menu ===========  -->
252 <div class="topmenu">
253 <!-- <a target="_blank" href="/briskhome.php"></a> -->
254
255 <div class="webstart_hilite">
256 <img class="nobo" src="img/brisk_start.png" onmouseover="menu_show(\'menu_webstart\');">
257 <div class="webstart" id="menu_webstart" onmouseover="menu_over(1,this);" onmouseout="menu_over(-1,this);">
258
259 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php" 
260    onmouseover="menu_hide(0,1);"
261    title="homepage del progetto">homepage</a><br>
262
263 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#cose" 
264    onmouseover="menu_hide(0,1);"
265    title="di cosa si tratta">cos\'&egrave;</a><br>
266
267 <a target="_blank" href="http://it.wikipedia.org/wiki/Briscola#Gioco_a_5" 
268    onmouseover="menu_hide(0,1);"
269    title="come si gioca">regole</a><br>
270
271 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#shots" 
272    onmouseover="menu_hide(0,1);"
273    title="screenshots dell\'applicazione">screenshoots</a><br>
274
275 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#comp" 
276    onmouseover="menu_hide(0,1);"
277    title="compatibilit&agrave; con i browser">compatibilit&agrave;</a><br>
278
279 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#sources" 
280    onmouseover="menu_hide(0,1);"
281    title="sorgenti dell\'applicazione">sorgenti</a><br>
282
283 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#mailing" 
284    onmouseover="menu_hide(0,1);"
285    title="come iscriversi alla mailing list">mailing&nbsp;list</a><br>
286
287 <a target="_blank" href="http://www.alternativeoutput.it/briskhome.php#prop" 
288    onmouseover="menu_hide(0,1);"
289    title="come fare pubblicit&agrave; a brisk!">propaganda</a><br>
290 <a href="#" 
291    onmouseover="menu_hide(0,1);"
292    title="credits" onclick="act_about();">about</a><br>
293
294 <a href="mailto:brisk@alternativeoutput.it" 
295    onmouseover="menu_hide(0,1);"
296    title="contatti">contatti</a><br>
297
298 <hr>
299
300 <!--
301 <a href="#" 
302    onmouseover="menu_hide(0,1);"
303    title="perché supportare brisk?" onclick="act_whysupport();">supportare?</a><br>
304 -->
305 <a href="#" 
306    onmouseover="menu_hide(0,1);"
307    title="prossime funzionalità implementate" onclick="act_roadmap();">roadmap</a><br>
308
309 <a href="#" title="foto dei raduni di briskisti" 
310    onmouseover="menu_show(\'menu_raduni\');">raduni</a><br>
311
312 <div id="menu_raduni" class="webstart">
313 <a href="http://www.anomalia.it/mop/photoo" 
314    target="_blank" onmouseover="menu_hide(0,2);"
315    title="Torneo di Milano del 17/05/2008" >Milano 05/08</a><br>
316
317 <a href="http://www.anomalia.it/mop/photoo?album=brisk_pc0806" 
318    target="_blank" onmouseover="menu_hide(0,2);"
319    title="Raduno di Piacenza del del 15/06/2008" >Piacenza 06/08</a><br>
320 </div>
321 </div>
322 </div>
323 <br><br><br>
324 sponsored by:<br><br>'.$altout_carousel.'<br>
325 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" id="btn_dynamica" src="img/dynamica.png" onMouseOver="show_bigpict(this, \'over\',100,10);" onMouseOut="show_bigpict(this, \'out\',0,0);"></a><br><br>
326 supported by:<br><br>
327 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" id="btn_brichi" src="img/brichi.png" onMouseOver="show_bigpict(this, \'over\',100,10);" onMouseOut="show_bigpict(this, \'out\',0,0);"></a><br>
328 <a target="_blank" href="http://www.forumolimpia.it"><img class="nobo" id="btn_foroli" src="img/forumolimpia.gif" onMouseOver="show_bigpict(this, \'over\',100,10);" onMouseOut="show_bigpict(this, \'out\',0,0);"></a><br><br>
329 <div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
330 </div><br><br></div>
331 %s
332 %s
333 <img class="nobohide" id="btn_dynamica_big" src="img/dynamica_big.png">
334 <img class="nobohide" id="btn_brichi_big" src="img/brichi_big.png">
335 <img class="nobohide" id="btn_foroli_big" src="img/forumolimpia_big.png">
336 '.$altout_carousel_big.'</div>';
337     
338   /* Templates. */
339   if ($ACTION == 'login') {
340     header('Content-type: text/html; charset="utf-8"',true);
341 ?>
342 <html>
343 <head>
344 <title>Brisk</title>
345 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
346 <link rel="shortcut icon" href="img/brisk_ico.png">
347 <script type="text/javascript" src="dnd.js"></script>
348 <script type="text/javascript" src="menu.js"></script>
349 <script type="text/javascript" src="dom-drag.js"></script>
350 <script type="text/javascript" src="commons.js"></script> 
351 <script type="text/javascript" src="xhr.js"></script>
352 <script type="text/javascript" src="preload_img.js"></script>
353 <script type="text/javascript" src="AC_OETags.js"></script>
354 <script type="text/javascript" src="room.js"></script>
355 <script type="text/javascript" src="md5.js"></script>
356 <link rel="stylesheet" type="text/css" href="brisk.css">
357 <link rel="stylesheet" type="text/css" href="room.css">
358
359 <SCRIPT type="text/javascript"><!--
360    var g_withflash = false;
361    var g_is_spawn = 0; 
362    var gst  = new globst();
363    var topbanner_sfx, topbanner_dx;
364
365    var sess = "not_connected";
366   
367    window.onload = function() {
368      // alert(window.onbeforeunload);
369
370      login_init();
371 <?php
372      if ($G_with_topbanner) {
373        printf("     topbanner_init();\n");
374     }
375 ?>
376
377      g_withflash = DetectFlashVer(6,0,0);
378      if (g_withflash == false) {
379        $("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>';
380      }
381      else
382        $("proflashext").innerHTML = "";
383      $("nameid").focus();
384    }
385    //-->
386 </SCRIPT>
387 </head>
388 <body>
389 <?php
390     printf($brisk_header_form);
391     printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
392     printf($brisk_vertical_menu, '', '');
393     printf("</td><td>");
394 ?> 
395
396 <!--  =========== tables ===========  -->
397 <?php echo "$body"; ?>
398 <br>
399 <div style="text-align: center;">
400    <br><br><br>
401 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
402 <form accept-charset="utf-8" method="post" action="" onsubmit="return j_login_manager(this);">
403 <input id="passid_private" name="pass_private" type="hidden" value="">
404 <table class="login">
405 <tr><td>user:</td>
406 <td><input id="nameid" class="input_text" name="name" type="text" size="24" maxlength="12" value=""></td></tr>
407 <tr><td>pwd:</td>
408 <td><input id="passid" class="input_text" name="pass" type="password" size="24" maxlength="64" value=""></td></tr>
409 <tr><td colspan="2"><input id="sub" value="entra" type="submit" class="button"></td></tr>
410 </table>
411 </form><br>
412 <b>Se non hai ancora una password, lascia il campo in bianco ed entra.</b><br><br>
413 (se usi firefox e qualcosa non funziona<br>prova a ricaricare la pagina con <b>Ctrl + F5</b>)<br>
414 </div>
415 <br><br><br><br>
416
417 <div id="imgct"></div>
418 <div id="logz"></div>
419 <div id="sandbox"></div>
420 <div id="sandbox2"></div>
421 <div id="response"></div>
422 <div id="xhrstart"></div>
423 <pre>
424 <div id="xhrlog"></div>
425 </pre>
426 <div id="xhrdeltalog"></div>
427 </body>
428 </html>
429 <?php
430   }
431   else if ($ACTION == 'room') {
432     header('Content-type: text/html; charset="utf-8"',true);
433   ?>
434 <html>
435 <head>
436 <title>Brisk</title>
437 <link rel="shortcut icon" href="img/brisk_ico.png">
438 <script type="text/javascript" src="dnd.js"></script>
439 <script type="text/javascript" src="menu.js"></script>
440 <script type="text/javascript" src="dom-drag.js"></script>
441 <script type="text/javascript" src="commons.js"></script> 
442 <script type="text/javascript" src="ticker.js"></script>
443 <script type="text/javascript" src="xhr.js"></script>
444 <script type="text/javascript" src="room.js"></script>
445 <script type="text/javascript" src="preload_img.js"></script>
446 <script type="text/javascript" src="AC_OETags.js"></script>
447 <link rel="stylesheet" type="text/css" href="brisk.css">
448 <link rel="stylesheet" type="text/css" href="room.css">
449 <SCRIPT type="text/javascript"><!--
450    var sess;
451    var tra = null;
452    var stat = "";
453    var subst = "";
454    var gst  = new globst();
455    var g_is_spawn = 0; 
456    var topbanner_sfx, topbanner_dx;
457    // var nonunload = false;
458    var g_withflash = false;
459    var g_imgct= 0;
460    var g_imgtot = g_preload_img_arr.length;
461    var myfrom = "index_php";
462    window.onload = function() {
463 <?php
464 if ($BRISK_SHOWHTML == "debugtable") {
465 ?>
466      room_checkspace(12, <?php echo TABLES_N; ?>, 50);
467 <?php
468 }
469 else {
470 ?>
471     // alert("INDEX START");
472      menu_init();
473 <?php
474      if ($G_with_topbanner) {
475        printf("     topbanner_init();\n");
476     }
477 ?>
478      xhr_rd = createXMLHttpRequest();
479      // xhr_rd.setRequestHeader("Content-type", "text/html; charset=utf-8");
480      sess = "<?php echo "$sess"; ?>";
481      tra = new train($('room_tit'));
482      window.onunload = onunload_cb;
483      window.onbeforeunload = onbeforeunload_cb;
484      g_withflash = DetectFlashVer(6,0,0);
485      if (g_withflash == false) {
486        $("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>';
487      }
488      else
489        $("proflashext").innerHTML = "";
490
491      setTimeout(xhr_rd_poll, 0, sess); 
492      // alert("ARR LENGTH "+g_preload_img_arr.length);
493      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
494      $("txt_in").focus();
495 <?php
496 if ($login_exists) {
497   echo show_notify("<br><br>Il nickname che stai usando &egrave; gi&agrave; registrato,<br><br>se il suo proprietario si autentificher&agrave;<br><br>verrai rinominato d'ufficio come ghost<i>N</i>.<br><br><br>", 0, "torna ai tavoli", 400, 150);
498 }
499 ?>
500 <?php
501 }
502 ?>
503    }
504    //-->
505 </SCRIPT>
506 </head>
507 <body>
508 <?php
509    printf($brisk_header_form);
510    printf("<table class=\"floaty\"><tr><td class=\"floatyleft\">\n");
511    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>',
512            $brisk_donate);
513    printf("</td><td>");
514 ?> 
515 <!--  =========== tables ===========  -->
516 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
517 <table class="macro"><tr><td>
518 <?php echo "$tables"; ?>
519 </td></tr><tr><td>
520     <?php echo "$standup"; ?>
521 </td></tr></table>
522 </td></tr></table>
523
524 <!--  =========== bottom ===========  -->
525     <div id="bottom" class="bottom">
526 <b>Chat</b><br>
527 <div id="txt" class="chatt">
528 </div>
529 <div style="text-align: center; ">
530     <table style="width: 98%; margin: auto;"><tr><td id="tickbut" class="tickbut"><img class="tickbut" src="img/train.png" onclick="act_tav();" title="scrivi un invito al tavolo e clicca"></td><td style="width:1%; text-align: center;">
531     <div id="myname"></div>
532     </td><td>
533     <input id="txt_in" maxlength="128" type="text" style="width: 100%;" onkeypress="chatt_checksend(this,event);">
534     </td></tr></table>
535 </div>
536 </div>
537 <div id="heartbit"></div>
538 <div id="sandbox"></div>
539 <div id="imgct"></div>
540 <div id="logz"></div>
541 <div id="sandbox2"></div>
542 <div id="response"></div>
543 <div id="remark"></div>
544 <div id="xhrstart"></div>
545 <div id="xhrlog"></div>
546 <div id="xhrdeltalog"></div>
547 </div>
548 </body>
549 </html>
550 <?php
551    }
552 }
553
554 main();
555
556 ?>