menu a sx, richiesta della conferma d'uscita
[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;
35   
36   $body = "";
37   $ACTION = "login";
38   
39   $is_table = false;
40   $sem = lock_data();
41   $bri = &load_data();
42   
43   /* Actions */
44   if (isset($sess)) {
45     $bri->garbage_manager(TRUE);
46     if (($user = &get_user(&$bri, $sess, &$idx)) != FALSE) {
47       if ($user->stat == "table") {
48         header ("Location: table.php");
49         unlock_data($sem);
50         exit;
51       }
52       $ACTION = "table";
53     }
54     else {
55       setcookie ("sess", "", time() - 3600);
56     }
57   }
58   else if (isset($name)) {
59     $bri->garbage_manager(TRUE);
60     /* try login */
61     $name = substr($name, 0, 12);
62     if (($user = &add_user(&$bri, &$sess, &$idx, $name)) != FALSE) {
63       $ACTION = "table";
64
65       setcookie ("sess", "", time() + 180);      
66       standup_update(&$bri,&$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 ($ACTION == "table") {
86     $tables .= '<table align="center" valign="center" border=1 cellpadding="12" cellspacing="0">';
87     for ($i = 0 ; $i < TABLES_N ; $i++) {
88       if ($i % 4 == 0)
89         $tables .= '<tr>';
90       $tables .= '<td valign="top" align="center" class="room_td"><b>Tavolo '.$i.'</b><br><br>';
91       $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
92       $tables .= sprintf('<div class="proxhr" id="table_act%d"></div>', $i);
93       $tables .= '</td>';
94       if ($i % 4 == 3)
95         $tables .= '</tr>';
96     }
97     $tables .= '<tr><td colspan="4">';
98     $tables .= '<div class="room_ex_standup">';
99     $tables .= '<b>Giocatori in piedi</b><br><br>';
100     
101     $tables .= sprintf('<div id="standup"></div>');
102     $tables .= '</div>';
103     $tables .= '</td></tr>';
104     
105     $tables .= '</table>';
106   }
107     
108   /* Templates. */
109   if ($ACTION == 'login') {
110 ?>
111 <html>
112 <head>
113 <title>Brisk</title>
114 <link rel="shortcut icon" href="img/brisk_ico.png">
115 <script type="text/javascript" src="dnd.js"></script>
116 <script type="text/javascript" src="dom-drag.js"></script>
117 <script type="text/javascript" src="commons.js"></script> 
118 <script type="text/javascript" src="xhr.js"></script>
119 <script type="text/javascript" src="preload_img.js"></script>
120 <link rel="stylesheet" type="text/css" href="brisk.css">
121 </head>
122 <body>
123 <SCRIPT type="text/javascript">
124    window.onload = function() {
125      $("nameid").focus();
126    }
127 </SCRIPT>
128 <img class="nobo" src="img/brisk_logo64.png">
129 <div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div>
130 <div class="topmenu"><a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a></div>
131 <?php echo "$body"; ?>
132
133 <br>
134 <div style="text-align: center;">
135    <br><br><br>
136 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
137 <form method="post" action="">
138 <input id="nameid" name="name" type="text" maxlength="12" value="">
139 </form>
140 </div>
141 <br><br><br><br>
142
143 <div id="imgct"></div>
144 <div id="logz"></div>
145 <div id="sandbox"></div>
146 <div id="sandbox2"></div>
147 <div id="response"></div>
148 <div id="xhrstart"></div>
149 <pre>
150 <div id="xhrlog"></div>
151 </pre>
152 <div id="xhrdeltalog"></div>
153 </body>
154 </html>
155 <?php
156   }
157   else if ($ACTION == 'table') {
158   ?>
159 <html>
160 <head>
161 <title>Brisk</title>
162 <link rel="shortcut icon" href="img/brisk_ico.png">
163 <script type="text/javascript" src="dnd.js"></script>
164 <script type="text/javascript" src="dom-drag.js"></script>
165 <script type="text/javascript" src="commons.js"></script> 
166 <script type="text/javascript" src="xhr.js"></script>
167 <script type="text/javascript" src="preload_img.js"></script>
168 <link rel="stylesheet" type="text/css" href="brisk.css">
169 </head>
170 <body>
171 <SCRIPT type="text/javascript">
172    var sess;
173    var stat = "";
174    var subst = "";
175    var gst  = new globst();
176
177    var g_imgct= 0;
178    var g_imgtot = g_preload_img_arr.length;
179    var myfrom = "index_php";
180    window.onload = function() {
181      // alert("INDEX START");
182      xhr_rd = createXMLHttpRequest();
183      sess = "<?php echo "$sess"; ?>";
184
185      window.onunload = onunload_cb;
186
187      setTimeout(xhr_rd_poll, 0, sess); 
188      // alert("ARR LENGTH "+g_preload_img_arr.length);
189      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
190    }
191
192 </SCRIPT>
193 <img class="nobo" src="img/brisk_logo64.png">
194 <div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div><br>
195 <div class="topmenu"><a target="_blank" href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a></div>
196 <!-- <div><input name="logout" value="Esco." onclick="window.onunload = null; act_logout();" type="button"></div> -->
197 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
198 <?php echo "$tables"; ?>
199
200 <b>Chat</b>
201 <div id="txt" class="chatt"></div>
202
203 <!-- onchange="act_chatt();"  -->
204 <table><tr><td><div id="myname" class="txtt"></div></td><td><input id="txt_in" type="text" size="80" maxlength="256" onkeypress="chatt_checksend(this,event);" class="txtt"></td></tr></table>
205
206 <hr>
207 <div id="heartbit"></div>
208 <hr>
209 <div id="imgct"></div>
210 <div id="logz"></div>
211 <div id="sandbox"></div>
212 <div id="sandbox2"></div>
213 <div id="response"></div>
214 <div id="remark"></div>
215 <div id="xhrstart"></div>
216 <pre>
217 <div id="xhrlog"></div>
218 </pre>
219 <div id="xhrdeltalog"></div>
220 </body>
221 </html>
222 <?php
223    }
224 }
225
226 main();
227
228 ?>