aggiunta cvs var id.
[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     if (($user = &add_user(&$bri, &$sess, &$idx, $name)) != FALSE) {
62       $ACTION = "table";
63
64       setcookie ("sess", "", time() + 180);      
65       standup_update(&$bri,&$user);
66
67       if (save_data(&$bri) == FALSE) {
68         echo "ERRORE SALVATAGGIO\n";
69         exit;
70       }
71     }
72     else {
73       /* Login Rendering */
74       if ($idx == -1) 
75         $body .= '<div class="urgmsg"><b>Spiacenti, non ci sono pi&ugrave; posti liberi. Riprova pi&ugrave; tardi.</b></div>';
76       else
77         $body .= '<div class="urgmsg"><b>Il tuo nickname &egrave; gi&agrave; in uso.</b></div>';
78     }
79   }
80   unlock_data($sem);
81
82   /* Rendering. */
83
84   if ($ACTION == "table") {
85     $tables .= '<table align="center" valign="center" border=1 cellpadding="12" cellspacing="0">';
86     for ($i = 0 ; $i < TABLES_N ; $i++) {
87       if ($i % 4 == 0)
88         $tables .= '<tr>';
89       $tables .= '<td valign="top" align="center" class="room_td"><b>Tavolo '.$i.'</b><br><br>';
90       $tables .= sprintf('<div class="proxhr" id="table%d"></div>', $i);
91       $tables .= sprintf('<div class="proxhr" id="table_act%d"></div>', $i);
92       $tables .= '</td>';
93       if ($i % 4 == 3)
94         $tables .= '</tr>';
95     }
96     $tables .= '<tr><td colspan="4">';
97     $tables .= '<div class="room_ex_standup">';
98     $tables .= '<b>Giocatori in piedi</b><br><br>';
99     
100     $tables .= sprintf('<div id="standup"></div>');
101     $tables .= '</div>';
102     $tables .= '</td></tr>';
103     
104     $tables .= '</table>';
105   }
106     
107   /* Templates. */
108   if ($ACTION == 'login') {
109 ?>
110 <html>
111 <head>
112 <title>Brisk</title>
113 <link rel="shortcut icon" href="img/brisk_ico.png">
114 <script type="text/javascript" src="dnd.js"></script>
115 <script type="text/javascript" src="dom-drag.js"></script>
116 <script type="text/javascript" src="commons.js"></script> 
117 <script type="text/javascript" src="xhr.js"></script>
118 <script type="text/javascript" src="preload_img.js"></script>
119 <link rel="stylesheet" type="text/css" href="brisk.css">
120 </head>
121 <body>
122 <SCRIPT type="text/javascript">
123    window.onload = function() {
124      $("nameid").focus();
125    }
126 </SCRIPT>
127 <img class="nobo" src="img/brisk_logo64.png">
128 <div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div>
129 <br><a href="/briskhome.php">homepage</a>
130 <br>
131 <?php echo "$body"; ?>
132
133 <br>
134 <div style="text-align: center;">
135 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
136 <form method="post" action="">
137 <input id="nameid" name="name" type="text" maxlength="12" value="">
138 </form>
139 </div>
140 <br><br>
141 <hr>
142 <div id="imgct"></div>
143 <div id="logz"></div>
144 <div id="sandbox"></div>
145 <div id="sandbox2"></div>
146 <div id="response"></div>
147 <div id="xhrstart"></div>
148 <pre>
149 <div id="xhrlog"></div>
150 </pre>
151 <div id="xhrdeltalog"></div>
152 </body>
153 </html>
154 <?php
155   }
156   else if ($ACTION == 'table') {
157   ?>
158 <html>
159 <head>
160 <title>Brisk</title>
161 <link rel="shortcut icon" href="img/brisk_ico.png">
162 <script type="text/javascript" src="dnd.js"></script>
163 <script type="text/javascript" src="dom-drag.js"></script>
164 <script type="text/javascript" src="commons.js"></script> 
165 <script type="text/javascript" src="xhr.js"></script>
166 <script type="text/javascript" src="preload_img.js"></script>
167 <link rel="stylesheet" type="text/css" href="brisk.css">
168 </head>
169 <body>
170 <SCRIPT type="text/javascript">
171    var sess;
172    var stat = "";
173    var subst = "";
174    var gst  = new globst();
175
176    var g_imgct= 0;
177    var g_imgtot = g_preload_img_arr.length;
178    var myfrom = "index_php";
179    window.onload = function() {
180      // alert("INDEX START");
181      xhr_rd = createXMLHttpRequest();
182      sess = "<?php echo "$sess"; ?>";
183
184      setTimeout(xhr_rd_poll, 0, sess); 
185      // alert("ARR LENGTH "+g_preload_img_arr.length);
186      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
187    }
188 </SCRIPT>
189 <img class="nobo" src="img/brisk_logo64.png">
190 <div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div><br>
191 <a href="/briskhome.php">homepage</a>
192 <!-- <div><input name="logout" value="Esco." onclick="act_logout();" type="button"></div> -->
193 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
194 <?php echo "$tables"; ?>
195
196 <b>Chat</b>
197 <div id="txt" class="chatt"></div>
198
199 <!-- onchange="act_chatt();"  -->
200 <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>
201
202 <hr>
203 <div id="imgct"></div>
204 <div id="logz"></div>
205 <div id="sandbox"></div>
206 <div id="sandbox2"></div>
207 <div id="response"></div>
208 <div id="xhrstart"></div>
209 <pre>
210 <div id="xhrlog"></div>
211 </pre>
212 <div id="xhrdeltalog"></div>
213 </body>
214 </html>
215 <?php
216    }
217 }
218
219 main();
220
221 ?>