aggiunti tasti di help e about, razionalizzati i css
[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       $name = substr($name, 0, 12);
61       $name = str_replace(" ", "_", $name);
62       if (($user = &$bri->add_user(&$sess, &$idx, $name)) != 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 == -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 $brisk_header_form = '<div class="container">
116 <!-- =========== header ===========  -->
117 <div id="header" class="header">
118 <img class="nobo" src="img/brisk_logo64.png">
119 briscola chiamata in salsa ajax<br><br>
120 </div>
121
122 <!--  =========== vertical menu ===========  -->
123 <div class="topmenu">
124 <a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a>
125 <br><br><br>
126 sponsored by:<br><br>
127 <a target="_blank" href="http://www.alternativeoutput.it"><img class="nobo" src="img/altout80x15.png"></a><br>
128 <a target="_blank" href="http://www.dynamica.it"><img class="nobo" src="img/dynamica.png"></a><br><br>
129 supported by:<br><br>
130 <a target="_blank" href="http://www.briscolachiamata.it"><img class="nobo" src="img/brichi.png"></a><br><br><br>
131 %s
132 </div>';
133     
134   /* Templates. */
135   if ($ACTION == 'login') {
136 ?>
137 <html>
138 <head>
139 <title>Brisk</title>
140 <link rel="shortcut icon" href="img/brisk_ico.png">
141 <script type="text/javascript" src="dnd.js"></script>
142 <script type="text/javascript" src="dom-drag.js"></script>
143 <script type="text/javascript" src="commons.js"></script> 
144 <script type="text/javascript" src="xhr.js"></script>
145 <script type="text/javascript" src="preload_img.js"></script>
146 <link rel="stylesheet" type="text/css" href="brisk.css">
147 <link rel="stylesheet" type="text/css" href="room.css">
148 </head>
149 <body>
150 <SCRIPT type="text/javascript">
151    window.onload = function() {
152      $("nameid").focus();
153    }
154 </SCRIPT>
155 <?php
156     printf($brisk_header_form, '');
157 ?> 
158
159 <!--  =========== tables ===========  -->
160 <div id="tables" class="tables">
161 <?php echo "$body"; ?>
162
163 <br>
164 <div style="text-align: center;">
165    <br><br><br>
166 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
167 <form method="post" action="">
168 <input id="nameid" name="name" type="text" size="24" maxlength="12" value="">
169 <input id="sub"    value="entra" type="submit" class="button">
170 </form>
171 </div>
172 </div></div>
173 <br><br><br><br>
174
175 <div id="imgct"></div>
176 <div id="logz"></div>
177 <div id="sandbox"></div>
178 <div id="sandbox2"></div>
179 <div id="response"></div>
180 <div id="xhrstart"></div>
181 <pre>
182 <div id="xhrlog"></div>
183 </pre>
184 <div id="xhrdeltalog"></div>
185 </body>
186 </html>
187 <?php
188   }
189   else if ($ACTION == 'room') {
190   ?>
191 <html>
192 <head>
193 <title>Brisk</title>
194 <link rel="shortcut icon" href="img/brisk_ico.png">
195 <script type="text/javascript" src="dnd.js"></script>
196 <script type="text/javascript" src="dom-drag.js"></script>
197 <script type="text/javascript" src="commons.js"></script> 
198 <script type="text/javascript" src="xhr.js"></script>
199 <script type="text/javascript" src="preload_img.js"></script>
200 <link rel="stylesheet" type="text/css" href="brisk.css">
201 <link rel="stylesheet" type="text/css" href="room.css">
202 </head>
203 <body>
204 <SCRIPT type="text/javascript">
205    var sess;
206    var stat = "";
207    var subst = "";
208    var gst  = new globst();
209
210    var g_imgct= 0;
211    var g_imgtot = g_preload_img_arr.length;
212    var myfrom = "index_php";
213    window.onload = function() {
214 <?php
215 if ($BRISK_DEBUG == "debugtable") {
216 ?>
217      room_checkspace(12,8,50);
218 <?php
219 }
220 else {
221 ?>
222      // alert("INDEX START");
223      xhr_rd = createXMLHttpRequest();
224      sess = "<?php echo "$sess"; ?>";
225
226      window.onunload = onunload_cb;
227
228      setTimeout(xhr_rd_poll, 0, sess); 
229      // alert("ARR LENGTH "+g_preload_img_arr.length);
230      // setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
231      $("txt_in").focus();
232 <?php
233 }
234 ?>
235    }
236
237 </SCRIPT>
238 <?php
239     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();">');
240 ?> 
241 <!--  =========== tables ===========  -->
242 <div id="tables" class="tables">
243 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
244 <?php echo "$tables"; ?>
245 </div>
246
247 <!--  =========== bottom ===========  -->
248 <div id="bottom" class="bottom">
249 <b>Chat</b>
250 <div id="txt" class="chatt">
251 </div>
252 <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>
253 </div>
254 <div id="heartbit"></div>
255 <div id="sandbox"></div>
256 <div id="imgct"></div>
257 <div id="logz"></div>
258 <div id="sandbox2"></div>
259 <div id="response"></div>
260 <div id="remark"></div>
261 <div id="xhrstart"></div>
262 <div id="xhrlog"></div>
263 <div id="xhrdeltalog"></div>
264 </div>
265 </body>
266 </html>
267 <?php
268    }
269 }
270
271 main();
272
273 ?>