Skip to content

Commit 7279623

Browse files
committed
Chat box update
1. Added Close button to chatbox 2. Name, Email Message fields can not be empty 3. empty message can not be send 4. no department option when only single department exist
1 parent 16edd65 commit 7279623

File tree

11 files changed

+100
-55
lines changed

11 files changed

+100
-55
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ box/config/*
6161
!box/config/.htaccess
6262
icon
6363
box/logs/*
64-
box/logs/.gitkeep
65-
box/logs/.htaccess
64+
!box/logs/.gitkeep
65+
!box/logs/.htaccess
6666
logs/*
67-
logs/.gitkeep
68-
logs/.htaccess
67+
!logs/.gitkeep
68+
!logs/.htaccess

box/assets/css/kchat.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,21 @@
120120
#KChat_heading_title {
121121
padding: 14px 0px 14px 10px;
122122
font-size: 18px;
123-
}
123+
width: 85%;
124+
float:left;
125+
}
126+
127+
#KChat_close {
128+
padding: 14px 0px 14px 10px;
129+
width: 15%;
130+
float: right;
131+
font-size: 18px;
132+
margin: auto;
133+
}
134+
135+
#xclose {
136+
color: red;
137+
text-decoration: none;
138+
margin: auto;
139+
}
140+

box/assets/js/kchat.js

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,30 @@ kbox.init = (function(data){
2626
kbox.loadform();
2727
$("#KChat_heading_title").html(global.heading);
2828
var department = '';
29-
for(var i = 0; i < global.dept.length; i++) {
30-
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
29+
if(global.dept.length < 2){
30+
department += '<option value="'+global.dept[0].id+'" selected>'+global.dept[0].dept+'</option>';
31+
$("#kchat_dept").hide();
32+
}else{
33+
for(var i = 0; i < global.dept.length; i++) {
34+
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
35+
}
36+
$("#kchat_dept").show();
3137
}
3238
$("#kchat_dept").html(department);
3339
}
3440
}else{
3541
kbox.loadform();
3642
$("#KChat_heading_title").html(global.heading);
3743
var department = '';
38-
for(var i = 0; i < global.dept.length; i++) {
39-
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
40-
}
44+
if(global.dept.length < 2){
45+
department += '<option value="'+global.dept[0].id+'" selected>'+global.dept[0].dept+'</option>';
46+
$("#kchat_dept").hide();
47+
}else{
48+
for(var i = 0; i < global.dept.length; i++) {
49+
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
50+
$("#kchat_dept").show();
51+
}
52+
}
4153
$("#kchat_dept").html(department);
4254
}
4355

@@ -122,12 +134,28 @@ kbox.initevent = (function(event){
122134
});
123135
});
124136

137+
// $("#xclose").click(function(){
138+
// alert('band kar ');
139+
// });
140+
141+
$(document).on('click', "#xclose" , function() {
142+
if(kbox.box_Toggle){
143+
$("#KChat_box").css("display", "none");
144+
$("#KChat_btn").css("display", "block");
145+
kbox.box_Toggle = false;
146+
}else{
147+
$("#KChat_btn").css("display", "none");
148+
$("#KChat_box").css("display", "block");
149+
kbox.box_Toggle = true;
150+
}
151+
});
152+
125153
kbox.loadBox = (function(){
126-
html = "<div id=\"KChat_heading\" ><div id=\"KChat_heading_title\" ></div></div>";
154+
html = "<div id=\"KChat_heading\" ><div id=\"KChat_heading_title\" ></div><div id=\"KChat_close\" ><a id=\"xclose\" href=\"javascript:void(0);\">X<a/></div></div>";
127155
html += "<div id=\"KChat_scroll_panel\" >";
128156
html += "<div id=\"KChat_scroll\" >";
129157
html += "</div></div>";
130-
html += "<div id=\"kchat_copy\" >&nbsp;<a href=\"https://github.com/php-kchat/kchat\" target=\"_blank\" >KChat &copy; 2017</a></div>";
158+
html += "<div id=\"kchat_copy\" >&nbsp;<a href=\"https://github.com/php-kchat/kchat\" target=\"_blank\" >KChat &copy; 2017-2021</a></div>";
131159
html += "<div id=\"KChat_textarea\" >"+
132160
"<textarea class=\"kchatemoji\" autofocus=\"autofocus\" style=\"width:100%;height:100%\" id=\"kchattextarea\" ></textarea>"+
133161
"</div>";
@@ -155,9 +183,12 @@ kbox.loademoji = (function(){
155183
// to send msg on enter
156184
if (keyCode == 13) {
157185
msg = $(".emojionearea-editor").html();
158-
msg = msg.replace(/(?:\r\n|\r|\n)/g, ' ');
159-
//==============================================================
160-
if(msg == ""){
186+
$(".emojionearea-editor").html('');
187+
msg = msg.replace(/(?:\r\n|\r|\n)/g,'');
188+
msg = msg.replace(/<br\s*\/?>/gi,'');
189+
msg = msg.replace(/<div>/g, '');
190+
msg = msg.replace(/<\/div>/g, '');
191+
if(msg.trim() == ""){
161192
return false;
162193
}
163194
$.post(kbox.url + "kchat.php?msg",
@@ -178,7 +209,7 @@ kbox.loademoji = (function(){
178209
});
179210

180211
kbox.loadform = (function(){
181-
html = "<div id=\"KChat_heading\" ><div id=\"KChat_heading_title\" ></div></div>";
212+
html = "<div id=\"KChat_heading\" ><div id=\"KChat_heading_title\" ></div><div id=\"KChat_close\" ><a id=\"xclose\" href=\"javascript:void()\">X<a/></div></div>";
182213
html += "<div id=\"KChat_form\" >";
183214
html +="<p type=\"text\"><input id=\"kchat_fname\" placeholder=\"Write your first name here..\"></input></p>";
184215
html +="<p type=\"text\"><input id=\"kchat_lname\" placeholder=\"Write your lastname here..\"></input></p>";
@@ -195,7 +226,13 @@ kbox.start = (function(){
195226
var kchat_lname = $( "#kchat_lname" ).val();
196227
var kchat_email = $( "#kchat_email" ).val();
197228
var kchat_dept = $( "#kchat_dept" ).val();
198-
var kchat_msg = $( "#kchat_msg" ).val();
229+
var kchat_msg = $( "#kchat_msg" ).val().trim();
230+
231+
if(ifempty(kchat_fname) || ifempty(kchat_lname)|| ifempty(kchat_email)|| ifempty(kchat_msg)){
232+
alert("Please fill in all the fields");
233+
return false;
234+
}
235+
199236
$.post(kbox.url + "kchat.php?start",
200237
{
201238
kchat_start: 'kchat_start',
@@ -252,6 +289,14 @@ function kchat_json(data){
252289
}
253290
}
254291

292+
function ifempty(str) {
293+
if (str.trim().length == 0) {
294+
return true;
295+
} else {
296+
return false;
297+
}
298+
}
299+
255300
function kchat_init(first){
256301
if(global.guest == false){
257302
return false;
@@ -290,7 +335,12 @@ function _loadoldmsg() {
290335
}
291336
}
292337

293-
338+
function stripHtml(html)
339+
{
340+
let tmp = document.createElement("DIV");
341+
tmp.innerHTML = html;
342+
return tmp.textContent || tmp.innerText || "";
343+
}
294344

295345
function toanchor(text) {
296346
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;

box/logs/error.log

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +0,0 @@
1-
[09-Dec-2021 14:21:23 UTC] PHP Warning: min(): Array must contain at least one element in E:\Ampps\www\kchat\box\core\sandesh.php on line 407
2-
[09-Dec-2021 14:21:23 UTC] PHP Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`kchat`.`kcso_group_users`, CONSTRAINT `group_users_ibfk_2` FOREIGN KEY (`users`) REFERENCES `kcso_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) in E:\Ampps\www\kchat\box\core\sandesh.php:103
3-
Stack trace:
4-
#0 E:\Ampps\www\kchat\box\core\sandesh.php(103): PDOStatement->execute(Array)
5-
#1 E:\Ampps\www\kchat\box\core\kchat.php(159): KChat->start(Array)
6-
#2 E:\Ampps\www\kchat\box\kchat.php(18): require_once('E:\\Ampps\\www\\kc...')
7-
#3 {main}
8-
thrown in E:\Ampps\www\kchat\box\core\sandesh.php on line 103
9-
[09-Dec-2021 14:22:27 UTC] PHP Warning: min(): Array must contain at least one element in E:\Ampps\www\kchat\box\core\sandesh.php on line 407
10-
[09-Dec-2021 14:22:27 UTC] PHP Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`kchat`.`kcso_group_users`, CONSTRAINT `group_users_ibfk_2` FOREIGN KEY (`users`) REFERENCES `kcso_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) in E:\Ampps\www\kchat\box\core\sandesh.php:103
11-
Stack trace:
12-
#0 E:\Ampps\www\kchat\box\core\sandesh.php(103): PDOStatement->execute(Array)
13-
#1 E:\Ampps\www\kchat\box\core\kchat.php(159): KChat->start(Array)
14-
#2 E:\Ampps\www\kchat\box\kchat.php(18): require_once('E:\\Ampps\\www\\kc...')
15-
#3 {main}
16-
thrown in E:\Ampps\www\kchat\box\core\sandesh.php on line 103
17-
[09-Dec-2021 14:22:55 UTC] PHP Warning: min(): Array must contain at least one element in E:\Ampps\www\kchat\box\core\sandesh.php on line 407
18-
[09-Dec-2021 14:22:56 UTC] PHP Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`kchat`.`kcso_group_users`, CONSTRAINT `group_users_ibfk_2` FOREIGN KEY (`users`) REFERENCES `kcso_users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) in E:\Ampps\www\kchat\box\core\sandesh.php:103
19-
Stack trace:
20-
#0 E:\Ampps\www\kchat\box\core\sandesh.php(103): PDOStatement->execute(Array)
21-
#1 E:\Ampps\www\kchat\box\core\kchat.php(159): KChat->start(Array)
22-
#2 E:\Ampps\www\kchat\box\kchat.php(18): require_once('E:\\Ampps\\www\\kc...')
23-
#3 {main}
24-
thrown in E:\Ampps\www\kchat\box\core\sandesh.php on line 103

kchat/assets/js/kchat.msgs.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,19 @@ $(".kchatemoji").emojioneArea({
331331
}
332332
// to send msg on enter
333333
if (keyCode == 13) {
334-
msg = $(".emojionearea-editor").html();
335-
//==============================================================
336-
if(msg == ""){
334+
msg = $(".emojionearea-editor").html();
335+
$(".emojionearea-editor").html('');
336+
msg = msg.replace(/(?:\r\n|\r|\n)/g,'');
337+
msg = msg.replace(/<br\s*\/?>/gi,'');
338+
msg = msg.replace(/<div>/g, '');
339+
msg = msg.replace(/<\/div>/g, '');
340+
if(msg.trim() == ""){
337341
return false;
338342
}
339343
$.post(purl + "/ajax/chat/"+posturl,
340344
{
341345
timestamp: chat.timestamp,
342-
msg: toanchor(msg),
346+
msg: toanchor(msg).trim(),
343347
first_run: 'false',
344348
token : token
345349
},

kchat/sql/kchat.data.sql.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
--
1010

1111
INSERT INTO `%dbprefix%department` VALUES
12-
(1, 'Admin', 'Head of Department'),
13-
(2, 'support', 'support people'),
14-
(3, 'IT', 'IT');
12+
(1, 'Admin', 'Head of Department');
1513

1614
--
1715
-- Dumping data for table `%dbprefix%groups`

kchat/view/example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
}
3030
?>
3131
<footer class="pull-left footer">
32-
<p class="col-md-12"><hr class="divider"/>&nbsp;&nbsp;&nbsp;&nbsp;KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?></p>
32+
<p class="col-md-12"><hr class="divider"/>&nbsp;&nbsp;&nbsp;&nbsp;KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?></p>
3333
</footer>
3434
<script>
3535
angular.module("myApp", ["ngAlertify"]).controller("myController", function($scope, alertif){});

kchat/view/footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
}
88
?>
99
<footer class="pull-left footer">
10-
<p class="col-md-12"><hr class="divider"/>&nbsp;&nbsp;&nbsp;&nbsp;KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>,&nbsp;Processed in&nbsp;<?php echo round((microtime(true) - $this->data['_start']), 3); ?>&nbsp;s,&nbsp;Ajax Process&nbsp;-&nbsp;<span class="dynamicsparkline"></span>&nbsp;<span id="rq_time">undefined</span>&nbsp;s,&nbsp;<span id="qfired">undefined</span>-SQL Query(s),&nbsp;<!--span id="reqps">undefined</span>&nbsp;-&nbsp;requests/s--></p>
10+
<p class="col-md-12"><hr class="divider"/>&nbsp;&nbsp;&nbsp;&nbsp;KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>,&nbsp;Processed in&nbsp;<?php echo round((microtime(true) - $this->data['_start']), 3); ?>&nbsp;s,&nbsp;Ajax Process&nbsp;-&nbsp;<span class="dynamicsparkline"></span>&nbsp;<span id="rq_time">undefined</span>&nbsp;s,&nbsp;<span id="qfired">undefined</span>-SQL Query(s),&nbsp;<!--span id="reqps">undefined</span>&nbsp;-&nbsp;requests/s--></p>
1111
</footer>
1212
<script>
1313
angular.module("myApp", ["ngAlertify"]).controller("myController", function($scope, alertif){});

kchat/view/install.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
</fieldset>
104104
</div>
105105
<div class="panel-footer ">
106-
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
106+
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
107107
</div>
108108
<?php }else{ ?>
109109
<div class="panel panel-default">
@@ -122,7 +122,7 @@
122122
</div>
123123
</div>
124124
<div class="panel-footer ">
125-
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
125+
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
126126
</div>
127127
<?php } ?>
128128
</div>

kchat/view/login.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</fieldset>
5959
</div>
6060
<div class="panel-footer ">
61-
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
61+
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
6262
</div>
6363
</div>
6464
</div>

0 commit comments

Comments
 (0)