aggiunto topmenu con link alla home
[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 <div class="topmenu"><a href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a></div>
130 <?php echo "$body"; ?>
131
132 <br>
133 <div style="text-align: center;">
134 Digita il tuo nickname per accedere ai tavoli della briscola.<br><br>
135 <form method="post" action="">
136 <input id="nameid" name="name" type="text" maxlength="12" value="">
137 </form>
138 </div>
139 <br><br>
140 <hr>
141 <div id="imgct"></div>
142 <div id="logz"></div>
143 <div id="sandbox"></div>
144 <div id="sandbox2"></div>
145 <div id="response"></div>
146 <div id="xhrstart"></div>
147 <pre>
148 <div id="xhrlog"></div>
149 </pre>
150 <div id="xhrdeltalog"></div>
151 </body>
152 </html>
153 <?php
154   }
155   else if ($ACTION == 'table') {
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 <link rel="stylesheet" type="text/css" href="brisk.css">
167 </head>
168 <body>
169 <SCRIPT type="text/javascript">
170    var sess;
171    var stat = "";
172    var subst = "";
173    var gst  = new globst();
174
175    var g_imgct= 0;
176    var g_imgtot = g_preload_img_arr.length;
177    var myfrom = "index_php";
178    window.onload = function() {
179      // alert("INDEX START");
180      xhr_rd = createXMLHttpRequest();
181      sess = "<?php echo "$sess"; ?>";
182
183      setTimeout(xhr_rd_poll, 0, sess); 
184      // alert("ARR LENGTH "+g_preload_img_arr.length);
185      setTimeout(preload_images, 0, g_preload_img_arr, g_imgct); 
186    }
187 </SCRIPT>
188 <img class="nobo" src="img/brisk_logo64.png">
189 <div style="text-align: center; font-size: 12px;">briscola chiamata in salsa ajax</div><br>
190 <div class="topmenu"><a href="/briskhome.php"><img class="nobo" src="img/brisk_homebutt.png"></a></div>
191 <!-- <div><input name="logout" value="Esco." onclick="act_logout();" type="button"></div> -->
192 <input name="sess" type="hidden" value="<?php echo "$user->sess"; ?>">
193 <?php echo "$tables"; ?>
194
195 <b>Chat</b>
196 <div id="txt" class="chatt"></div>
197
198 <!-- onchange="act_chatt();"  -->
199 <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>
200
201 <hr>
202 <div id="imgct"></div>
203 <div id="logz"></div>
204 <div id="sandbox"></div>
205 <div id="sandbox2"></div>
206 <div id="response"></div>
207 <div id="xhrstart"></div>
208 <pre>
209 <div id="xhrlog"></div>
210 </pre>
211 <div id="xhrdeltalog"></div>
212 </body>
213 </html>
214 <?php
215    }
216 }
217
218 main();
219
220 ?>