<?
if(isset($_GET['logout'])){
//Poruka o napustanju cata
$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'><i>Korisnik ". $_SESSION['name'] ." je napustio cat sesiju.</i><br></div>");
header("Location: index.php"); //preusmerava korisnika na pocetnu stranu
}
function loginForm(){
echo'
<div id="loginform">
<form action="index.php" method="post">
<p>Unesite Vas nick da bi otpoceli dopisivanje:</p>
<label for="name">Nick:</label>
<input type="text" name="name" id="name" />
<input type="submit" name="enter" id="enter" value="Enter" />
</form>
</div>
';
}
if(isset($_POST['enter'])){
if($_POST['name'] != ""){
}
else{
echo '<span class="error">Molimo Vas unesite Nick</span>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Chat - Customer Module</title>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<?php
if(!isset($_SESSION['name'])){
loginForm();
}
else{
?>
<div id="wrapper">
<div id="menu">
<p class="welcome">Dobrodosli, <b><?php echo $_SESSION['name']; ?></b></p>
<p class="logout"><a id="exit" href="#">Napusti Chat</a></p>
<div style="clear:both"></div>
</div>
<div id="chatbox"><?php
$handle = fopen("log.html", "r");
echo $contents;
}
?></div>
<form name="message" action="">
<input name="usermsg" type="text" id="usermsg" size="63" />
<input name="submitmsg" type="submit" id="submitmsg" value="Posalji" />
</form>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){
var clientmsg = $("#usermsg").val();
$.post("post.php", {text: clientmsg});
$("#usermsg").attr("value", "");
return false;
});
//Load the file containing the chat log
function loadLog(){
var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
$.ajax({
url: "log.html",
cache: false,
success: function(html){
$("#chatbox").html(html); //Insert chat log into the #chatbox div
var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
},
});
}
setInterval (loadLog, 2500); //Reload file every 2.5 seconds
//Proverava da li korsinik zaista zeli da napusti sesiju
$("#exit").click(function(){
var exit = confirm("Da li ste sigurni da zelite da napustite sesiju?");
if(exit==true){window.location = 'index.php?logout=true';}
});
});
</script>
<?php
}
?>
</body>
</html>