aggiunto il donate
[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_DEBUG;
35   
36   $body = "";
37   $ACTION = "login";
38   
39   if (isset($BRISK_DEBUG) == 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)) != 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_DEBUG == "debugtable") {
86     $ACTION = "room";
87   }
88   else if ($BRISK_DEBUG == "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 <img class="nobo" src="img/brisk_logo64.png">
137 briscola chiamata in salsa ajax<br><br>
138 </div>
139
140 <!--  =========== vertical menu ===========  -->
141 <div class="topmenu">
142 <a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a>
143 <br><br><br>
144 sponsored by:<br><br>'.$altout_carousel.'<br>
145 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" src="img/dynamica.png"></a><br><br>
146 supported by:<br><br>
147 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" src="img/brichi.png"></a><br><br>
148 <div id="proflashext" class="proflashext"><div id="proflash" class="proflash">
149 </div><br><br></div>
150 %s
151 %s
152 </div>';
153     
154   /* Templates. */
155   if ($ACTION == 'login') {
156 ?>
157 <html>
158 <head>
159 <title>Brisk</title>
160 <link rel="shortcut icon" href="img/brisk_ico.png">
161 <script type="text/javascript" src="dnd.js"></script>
162 <script type="text/javascript" src="dom-drag.js"></script>
163 <script type="text/javascript" src="commons.js"></script> 
164 <script type="text/javascript" src="xhr.js"></script>
165 <script type="text/javascript" src="preload_img.js"></script>
166 <script type="text/javascript" src="AC_OETags.js"></script>
167 <link rel="stylesheet" type="text/css" href="brisk.css">
168 <link rel="stylesheet" type="text/css" href="room.css">
169 </head>
170 <body>
171 <SCRIPT type="text/javascript">
172    var g_withflash = false;
173
174    window.onload = function() {
175      g_withflash = DetectFlashVer(6,0,0);
176      if (g_withflash == false) {
177        $("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>';
178      }
179      else
180        $("proflashext").innerHTML = "";
181      $("nameid").focus();
182    }
183 </SCRIPT>
184 <?php
185     printf($brisk_header_form, '', '');
186 ?> 
187
188 <!--  =========== tables ===========  -->
189 <div id="tables" class="tables">
190 <?php echo "$body"; ?>
191
192 <br>
193 <div style="text-align: center;">
194    <br><br><br>
195 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
196 <form method="post" action="">
197 <input id="nameid" name="name" type="text" size="24" maxlength="12" value="">
198 <input id="sub"    value="entra" type="submit" class="button">
199 </form>
200 </div>
201 </div></div>
202 <br><br><br><br>
203
204 <div id="imgct"></div>
205 <div id="logz"></div>
206 <div id="sandbox"></div>
207 <div id="sandbox2"></div>
208 <div id="response"></div>
209 <div id="xhrstart"></div>
210 <pre>
211 <div id="xhrlog"></div>
212 </pre>
213 <div id="xhrdeltalog"></div>
214 </body>
215 </html>
216 <?php
217   }
218   else if ($ACTION == 'room') {
219   ?>
220 <html>
221 <head>
222 <title>Brisk</title>
223 <link rel="shortcut icon" href="img/brisk_ico.png">
224 <script type="text/javascript" src="dnd.js"></script>
225 <script type="text/javascript" src="dom-drag.js"></script>
226 <script type="text/javascript" src="commons.js"></script> 
227 <script type="text/javascript" src="xhr.js"></script>
228 <script type="text/javascript" src="preload_img.js"></script>
229 <script type="text/javascript" src="AC_OETags.js"></script>
230 <link rel="stylesheet" type="text/css" href="brisk.css">
231 <link rel="stylesheet" type="text/css" href="room.css">
232 </head>
233 <body>
234 <SCRIPT type="text/javascript">
235    var sess;
236    var stat = "";
237    var subst = "";
238    var gst  = new globst();
239
240    var g_withflash = false;
241    var g_imgct= 0;
242    var g_imgtot = g_preload_img_arr.length;
243    var myfrom = "index_php";
244    window.onload = function() {
245 <?php
246 if ($BRISK_DEBUG == "debugtable") {
247 ?>
248      room_checkspace(12,8,50);
249 <?php
250 }
251 else {
252 ?>
253      // alert("INDEX START");
254      xhr_rd = createXMLHttpRequest();
255      sess = "<?php echo "$sess"; ?>";
256
257      window.onunload = onunload_cb;
258      g_withflash = DetectFlashVer(6,0,0);
259      if (g_withflash == false) {
260        $("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>';
261      }
262      else
263        $("proflashext").innerHTML = "";
264      setTimeout(xhr_rd_poll, 0, sess); 
265      // alert("ARR LENGTH "+g_preload_img_arr.length);
266      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
267      $("txt_in").focus();
268 <?php
269 }
270 ?>
271    }
272
273 </SCRIPT>
274 <?php
275     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>',
276            $brisk_donate);
277 ?> 
278 <!--  =========== tables ===========  -->
279 <div id="tables" class="tables">
280 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
281 <?php echo "$tables"; ?>
282 </div>
283
284 <!--  =========== bottom ===========  -->
285 <div id="bottom" class="bottom">
286 <b>Chat</b>
287 <div id="txt" class="chatt">
288 </div>
289 <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>
290 </div>
291 <div id="heartbit"></div>
292 <div id="sandbox"></div>
293 <div id="imgct"></div>
294 <div id="logz"></div>
295 <div id="sandbox2"></div>
296 <div id="response"></div>
297 <div id="remark"></div>
298 <div id="xhrstart"></div>
299 <div id="xhrlog"></div>
300 <div id="xhrdeltalog"></div>
301 </div>
302 </body>
303 </html>
304 <?php
305    }
306 }
307
308 main();
309
310 ?>