imerfanrajabee commited on
Commit
55e04d7
1 Parent(s): 7954e1d

Upload 4 files

Browse files
Files changed (4) hide show
  1. index.php +111 -0
  2. log.html +1 -0
  3. post.php +10 -0
  4. style.css +59 -0
index.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ session_start();
3
+
4
+ if(isset($_GET['logout'])){
5
+
6
+ //Simple exit message
7
+ $fp = fopen("log.html", 'a');
8
+ fwrite($fp, "<div class='msgln'><i>User ". $_SESSION['name'] ." has left the chat session.</i><br></div>");
9
+ fclose($fp);
10
+
11
+ session_destroy();
12
+ header("Location: index.php"); //Redirect the user
13
+ }
14
+
15
+ function loginForm(){
16
+ echo'
17
+ <div id="loginform">
18
+ <form action="index.php" method="post">
19
+ <p>Please enter your name to continue:</p>
20
+ <label for="name">Name:</label>
21
+ <input type="text" name="name" id="name" />
22
+ <input type="submit" name="enter" id="enter" value="Enter" />
23
+ </form>
24
+ </div>
25
+ ';
26
+ }
27
+
28
+ if(isset($_POST['enter'])){
29
+ if($_POST['name'] != ""){
30
+ $_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
31
+ }
32
+ else{
33
+ echo '<span class="error">Please type in a name</span>';
34
+ }
35
+ }
36
+ ?>
37
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
38
+ <html xmlns="http://www.w3.org/1999/xhtml">
39
+ <head>
40
+ <title>Chat - Customer Module</title>
41
+ <link type="text/css" rel="stylesheet" href="style.css" />
42
+ </head>
43
+
44
+ <?php
45
+ if(!isset($_SESSION['name'])){
46
+ loginForm();
47
+ }
48
+ else{
49
+ ?>
50
+ <div id="wrapper">
51
+ <div id="menu">
52
+ <p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?></b></p>
53
+ <p class="logout"><a id="exit" href="#">Exit Chat</a></p>
54
+ <div style="clear:both"></div>
55
+ </div>
56
+ <div id="chatbox"><?php
57
+ if(file_exists("log.html") && filesize("log.html") > 0){
58
+ $handle = fopen("log.html", "r");
59
+ $contents = fread($handle, filesize("log.html"));
60
+ fclose($handle);
61
+
62
+ echo $contents;
63
+ }
64
+ ?></div>
65
+
66
+ <form name="message" action="">
67
+ <input name="usermsg" type="text" id="usermsg" size="63" />
68
+ <input name="submitmsg" type="submit" id="submitmsg" value="Send" />
69
+ </form>
70
+ </div>
71
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
72
+ <script type="text/javascript">
73
+ // jQuery Document
74
+ $(document).ready(function(){
75
+ //If user submits the form
76
+ $("#submitmsg").click(function(){
77
+ var clientmsg = $("#usermsg").val();
78
+ $.post("post.php", {text: clientmsg});
79
+ $("#usermsg").attr("value", "");
80
+ return false;
81
+ });
82
+
83
+ //Load the file containing the chat log
84
+ function loadLog(){
85
+ var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
86
+ $.ajax({
87
+ url: "log.html",
88
+ cache: false,
89
+ success: function(html){
90
+ $("#chatbox").html(html); //Insert chat log into the #chatbox div
91
+ var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
92
+ if(newscrollHeight > oldscrollHeight){
93
+ $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
94
+ }
95
+ },
96
+ });
97
+ }
98
+ setInterval (loadLog, 2500); //Reload file every 2.5 seconds
99
+
100
+ //If user wants to end session
101
+ $("#exit").click(function(){
102
+ var exit = confirm("Are you sure you want to end the session?");
103
+ if(exit==true){window.location = 'index.php?logout=true';}
104
+ });
105
+ });
106
+ </script>
107
+ <?php
108
+ }
109
+ ?>
110
+ </body>
111
+ </html>
log.html ADDED
@@ -0,0 +1 @@
 
 
1
+ <div class='msgln'>(12:02 PM) <b>uprozhe</b>: salam<br></div><div class='msgln'>(12:02 PM) <b>uprozhe</b>: test pm<br></div><div class='msgln'><i>User uprozhe has left the chat session.</i><br></div>
post.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ session_start();
3
+ if(isset($_SESSION['name'])){
4
+ $text = $_POST['text'];
5
+
6
+ $fp = fopen("log.html", 'a');
7
+ fwrite($fp, "<div class='msgln'>(".date("g:i A").") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
8
+ fclose($fp);
9
+ }
10
+ ?>
style.css ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /* CSS Document */
3
+ body {
4
+ font:12px arial;
5
+ color: #222;
6
+ text-align:center;
7
+ padding:35px; }
8
+
9
+ form, p, span {
10
+ margin:0;
11
+ padding:0; }
12
+
13
+ input { font:12px arial; }
14
+
15
+ a {
16
+ color:#0000FF;
17
+ text-decoration:none; }
18
+
19
+ a:hover { text-decoration:underline; }
20
+
21
+ #wrapper, #loginform {
22
+ margin:0 auto;
23
+ padding-bottom:25px;
24
+ background:#EBF4FB;
25
+ width:504px;
26
+ border:1px solid #ACD8F0; }
27
+
28
+ #loginform { padding-top:18px; }
29
+
30
+ #loginform p { margin: 5px; }
31
+
32
+ #chatbox {
33
+ text-align:left;
34
+ margin:0 auto;
35
+ margin-bottom:25px;
36
+ padding:10px;
37
+ background:#fff;
38
+ height:270px;
39
+ width:430px;
40
+ border:1px solid #ACD8F0;
41
+ overflow:auto; }
42
+
43
+ #usermsg {
44
+ width:395px;
45
+ border:1px solid #ACD8F0; }
46
+
47
+ #submit { width: 60px; }
48
+
49
+ .error { color: #ff0000; }
50
+
51
+ #menu { padding:12.5px 25px 12.5px 25px; }
52
+
53
+ .welcome { float:left; }
54
+
55
+ .logout { float:right; }
56
+
57
+ .msgln { margin:0 0 2px 0; }
58
+
59
+