Browse Source

switch saloon

AR 11 months ago
parent
commit
0afabc02e8
1 changed files with 17 additions and 9 deletions
  1. 17 9
      index.php

+ 17 - 9
index.php

@@ -7,10 +7,6 @@ function loginForm() {
7 7
 		<p>Please enter your name to continue:</p>
8 8
 		<label for="name">Name:</label>
9 9
 		<input type="text" name="name" id="name" autofocus />
10
-		<p>
11
-		   <label for="saloon">Saloon:</label>
12
-		   <input type="text" name="saloon" id="saloon" />
13
-		</p>
14 10
 		<input type="submit" name="enter" id="enter" value="Enter" />
15 11
 	</form>
16 12
 	</div>
@@ -37,7 +33,6 @@ if (isset($_GET['logout'])) {
37 33
 if (isset($_POST['enter'])) {
38 34
 	if ($_POST['name'] != "") {
39 35
 		$_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
40
-		$_SESSION['saloon'] = stripslashes(htmlspecialchars($_POST['saloon']));
41 36
 	} else {
42 37
 		echo '<span class="error">Please type in a name</span>';
43 38
 	}
@@ -53,7 +48,7 @@ if (isset($_POST['enter'])) {
53 48
     </head>
54 49
 
55 50
 <?php
56
-if (!isset($_SESSION['name']) || !isset($_SESSION['saloon'])) {
51
+if (!isset($_SESSION['name'])) {
57 52
 	loginForm();
58 53
 } else {
59 54
 ?>
@@ -68,11 +63,18 @@ if (!isset($_SESSION['name']) || !isset($_SESSION['saloon'])) {
68 63
 	    <div id="datbox">
69 64
 	    	<div id="chatbox"></div>
70 65
 		<div id="usrlist">
71
-			<b>Fameux connectés dans ce salon (<span id='current_saloon' ></span>):</b>
66
+			<b>Fameux dans ce salon (<span id='current_saloon' ></span>):</b>
72 67
 			<div id="usrs"></div>
73 68
 			<br><br>
74 69
 			<b>Autres Fameux</b>
75 70
 			<div id="usrs_others"></div>
71
+
72
+			<br><br>
73
+			<b>Nouveau saloon</b>
74
+			<div id="div_new_saloon">
75
+				<input type="text" id="text_new_saloon" />
76
+				<input type="submit" id="submit_new_saloon" value="Créer" />
77
+			</div>
76 78
 		</div>
77 79
 	    </div>
78 80
 
@@ -177,8 +179,8 @@ if (!isset($_SESSION['name']) || !isset($_SESSION['saloon'])) {
177 179
 	$(document).ready(function() {
178 180
 		
179 181
 		
180
-		var saloon_id = '<?php echo str_replace("'","''", $_SESSION['saloon']); ?>';
181
-		if(!saloon_id) saloon_id = 'default';
182
+		var saloon_id = '<?php echo isset($_POST['saloon'])?str_replace("'","''", $_SESSION['saloon']):''; ?>';
183
+		if(!saloon_id) saloon_id = 'Bienvenue';
182 184
 		
183 185
 		$('#current_saloon').text(saloon_id);
184 186
 		
@@ -189,6 +191,12 @@ if (!isset($_SESSION['name']) || !isset($_SESSION['saloon'])) {
189 191
 		var last_message = 0;
190 192
 		var audio = new Audio('./front-desk-bell.mp3');
191 193
 		audio.volume = 0.05;
194
+		
195
+		$("#submit_new_saloon").click(function(){
196
+			change_saloon($("#text_new_saloon").val());
197
+			return false;
198
+		});
199
+		
192 200
 		//If user submits the form
193 201
 		$("#submitmsg").click(function() {
194 202
 			var clientmsg = $("#usermsg").val();