diff --git a/sources/index.php b/sources/index.php index 44109f4..f1b38f1 100644 --- a/sources/index.php +++ b/sources/index.php @@ -79,7 +79,9 @@ if ($name.$room=="") {

Welcome to the room,

+
+
@@ -101,9 +103,9 @@ function lienurl(s){ } $(document).ready(function() { - var id = 'undefined'; var pos = 0; var lastdate = 0; + var lastday=''; var oldscrollHeight = $("#chatbox")[0].scrollHeight; $("#submitmsg").click(function() { @@ -136,6 +138,7 @@ function lienurl(s){ var html=''; var date; var heure=''; + var day=''; for (var k in data.data) { lastdate = data.data[k][0]; date = new Date(parseInt(lastdate)*1000); @@ -147,16 +150,29 @@ function lienurl(s){ html=lienurl(html); - if (pos==0 && heure!=''){ - html='----- '+date.toLocaleDateString()+' -----
'+html; - } - pos = data.pos; - - $("#chatbox").append(html); + if (html!=""){ + if (pos==0){ + day = date.toLocaleDateString(); + if (day!=lastday){ + $("#chatbox").append('----- '+day+' -----
'); + if (data.pos==0) { + $("#chatbox").append('No message yet. Enter yours!
'); + } + lastday=day; + } + if (data.pos>0) { + $("#nomsg").remove(); + } else { + html=""; + } + } + $("#chatbox").append(html); + } var newscrollHeight = $("#chatbox")[0].scrollHeight; if (newscrollHeight > oldscrollHeight) { - $("#chatbox").scrollTop($("#chatbox")[0].scrollHeight); + $("#chatbox").scrollTop(newscrollHeight); } + pos = data.pos; }, }); } diff --git a/sources/server.php b/sources/server.php index d36ea7d..7bb56f1 100644 --- a/sources/server.php +++ b/sources/server.php @@ -3,26 +3,30 @@ $pos = isset($_REQUEST['pos']) ? $_REQUEST['pos'] : ''; $lastdate = isset($_REQUEST['lastdate']) ? $_REQUEST['lastdate'] : ''; $room = isset($_REQUEST['room']) ? $_REQUEST['room'] : ''; -$date = date('Y-m-d'); +$time = time(); +$date = date('Y-m-d', $time); $file = './history/'.$room.$date; -if (!ctype_digit($pos) || !file_exists($file)) return; +if (!ctype_digit($pos)) return; settype($pos, "integer"); settype($lastdate, "integer"); $data = array(); - -if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) { - $pos=0; -} else { - $fh =fopen($file, "r"); - - if (fseek($fh, $pos)==0) { - $i=0; - while($lig=fgets($fh)){ $data[$i++] = explode('>', $lig); } - $pos =ftell($fh); +if (file_exists($file)) { + if ($pos!=0 && $date!=date('Y-m-d',$lastdate)) { + $pos=0; + } else { + $fh =fopen($file, "r"); + + if (fseek($fh, $pos)==0) { + $i=0; + while($lig=fgets($fh)){ $data[$i++] = explode('>', $lig); } + $pos =ftell($fh); + } } +} else if ($date!=date('Y-m-d',$lastdate)) { + $data[0]=array($time,"",""); } echo json_encode(array('pos' => $pos, 'data' => $data)); diff --git a/sources/style.css b/sources/style.css index fcd659a..0d0196b 100644 --- a/sources/style.css +++ b/sources/style.css @@ -46,13 +46,13 @@ a:hover { text-decoration: underline; } #loginform p { margin: 5px; } #chatbox { - text-align: left; - margin: 0 50px; - padding: 0.5em 1ex 0.1em; - background: #FEFFF4; - height: calc(100% - 120px); - border: 1px solid #C7C7C7; - overflow: auto; } + background: #FEFFF4; + position: absolute; + bottom: 80px; + right: 50px; + left: 50px; overflow-y: scroll; + max-height: calc(100% - 140px); + padding: .5em; } #usermsg { width: calc(100% - 100px); @@ -73,4 +73,5 @@ a:hover { text-decoration: underline; } .tform p { display: table-row; } .tform label { display: table-cell; } .tform input { display: table-cell; } -em {color:red;} \ No newline at end of file +em {color:red;} +#content{height: calc(100% - 120px); } \ No newline at end of file