Browse Source

delete saloon messages

AR 7 months ago
parent
commit
e1b63f426a
4 changed files with 76 additions and 1 deletions
  1. 14 0
      delete_saloon.php
  2. 13 0
      functions.php
  3. 44 1
      index.php
  4. 5 0
      server.php

+ 14 - 0
delete_saloon.php

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+include 'functions.php';
4
+
5
+session_start();
6
+
7
+$saloon = get_post_var("saloon");
8
+
9
+$json_msgs = file_lock_and_destroy(get_msg_file_path($saloon));
10
+
11
+echo json_encode('done');
12
+
13
+
14
+?>

+ 13 - 0
functions.php

@@ -47,6 +47,19 @@ function file_lock_and_get_json($file_path)
47 47
 	return $json;
48 48
 }
49 49
 
50
+// destroy file and lock
51
+function file_lock_and_destroy($file_path)
52
+{
53
+	$hFile = get_file_to_lock($file_path);
54
+	@flock($hFile, LOCK_SH);
55
+	@unlink($file_path);
56
+	@flock($hFile, LOCK_UN);
57
+	fclose($hFile);
58
+
59
+	@unlink(get_file_to_lock($file_path));
60
+	
61
+	return true;
62
+}
50 63
 function json_encode_for_save($data)
51 64
 {
52 65
 	$json_pretty_option = getSetup('pretty_json', false);

+ 44 - 1
index.php

@@ -65,6 +65,7 @@ if (!isset($_SESSION['name'])) {
65 65
 		<div id="usrlist">
66 66
 			<b>Fameux dans ce salon (<span id='current_saloon' ></span>):</b>
67 67
 			<div id="usrs"></div>
68
+			<input type="submit" id="delete_saloon" value="Supprimer tous les messages" />
68 69
 			<br><br>
69 70
 			<b>Autres Fameux</b>
70 71
 			<div id="usrs_others"></div>
@@ -180,7 +181,42 @@ if (!isset($_SESSION['name'])) {
180 181
 		
181 182
 		
182 183
 		var saloon_id = '<?php echo isset($_POST['saloon'])?str_replace("'","''", $_SESSION['saloon']):''; ?>';
183
-		if(!saloon_id) saloon_id = 'Bienvenue';
184
+		if(!saloon_id) 
185
+		{
186
+			// do we have a hash ?
187
+			saloon_id = $(location).attr('hash');
188
+			if(!saloon_id) 
189
+			{
190
+				saloon_id = 'Bienvenue';
191
+			}
192
+		}	
193
+		
194
+		
195
+		$('#delete_saloon').click(function() 
196
+		{
197
+			if (!confirm("Tous les messages seront définitivement supprimés à vie. OK ?"))
198
+			{
199
+				return false;
200
+			}
201
+			
202
+			$.ajax({
203
+			type: 'POST',
204
+				url: 'delete_saloon.php',
205
+				data: {saloon: saloon_id },
206
+				//cache: false,
207
+				async: true,
208
+				success: function(data) {
209
+					loadLog();
210
+				},
211
+				error: function(request, status, error) {
212
+					$("#usermsg").val(clientmsg);
213
+				},
214
+			});
215
+			
216
+				
217
+			
218
+			return false;
219
+		});
184 220
 		
185 221
 		$('#current_saloon').text(saloon_id);
186 222
 		
@@ -273,6 +309,13 @@ if (!isset($_SESSION['name'])) {
273 309
 				async: true,
274 310
 				success: function(data) {
275 311
 					last_message = data.last_message;
312
+					
313
+					if(data['reset'])
314
+					{
315
+						$("#chatbox").html('');
316
+					}
317
+					
318
+					
276 319
 					$(window).focus(function() {
277 320
 						document.title = "Chat FAME";
278 321
 					});

+ 5 - 0
server.php

@@ -17,6 +17,11 @@ if($from == $count_msgs)
17 17
 	// no new message
18 18
 	return;
19 19
 }
20
+else if($from > $count_msgs)
21
+{
22
+	// client has more messages -> content has been deleted
23
+	$msg_to_send['reset'] = true;
24
+}
20 25
 
21 26
 $msg_to_send['last_message'] = $count_msgs;
22 27