Skip to content

Commit

Permalink
Chat box update
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GaneshKandu committed Dec 11, 2021
1 parent 16edd65 commit 7279623
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 55 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ box/config/*
!box/config/.htaccess
icon
box/logs/*
box/logs/.gitkeep
box/logs/.htaccess
!box/logs/.gitkeep
!box/logs/.htaccess
logs/*
logs/.gitkeep
logs/.htaccess
!logs/.gitkeep
!logs/.htaccess
19 changes: 18 additions & 1 deletion box/assets/css/kchat.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,21 @@
#KChat_heading_title {
padding: 14px 0px 14px 10px;
font-size: 18px;
}
width: 85%;
float:left;
}

#KChat_close {
padding: 14px 0px 14px 10px;
width: 15%;
float: right;
font-size: 18px;
margin: auto;
}

#xclose {
color: red;
text-decoration: none;
margin: auto;
}

76 changes: 63 additions & 13 deletions box/assets/js/kchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,30 @@ kbox.init = (function(data){
kbox.loadform();
$("#KChat_heading_title").html(global.heading);
var department = '';
for(var i = 0; i < global.dept.length; i++) {
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
if(global.dept.length < 2){
department += '<option value="'+global.dept[0].id+'" selected>'+global.dept[0].dept+'</option>';
$("#kchat_dept").hide();
}else{
for(var i = 0; i < global.dept.length; i++) {
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
}
$("#kchat_dept").show();
}
$("#kchat_dept").html(department);
}
}else{
kbox.loadform();
$("#KChat_heading_title").html(global.heading);
var department = '';
for(var i = 0; i < global.dept.length; i++) {
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
}
if(global.dept.length < 2){
department += '<option value="'+global.dept[0].id+'" selected>'+global.dept[0].dept+'</option>';
$("#kchat_dept").hide();
}else{
for(var i = 0; i < global.dept.length; i++) {
department += '<option value="'+global.dept[i].id+'">'+global.dept[i].dept+'</option>';
$("#kchat_dept").show();
}
}
$("#kchat_dept").html(department);
}

Expand Down Expand Up @@ -122,12 +134,28 @@ kbox.initevent = (function(event){
});
});

// $("#xclose").click(function(){
// alert('band kar ');
// });

$(document).on('click', "#xclose" , function() {
if(kbox.box_Toggle){
$("#KChat_box").css("display", "none");
$("#KChat_btn").css("display", "block");
kbox.box_Toggle = false;
}else{
$("#KChat_btn").css("display", "none");
$("#KChat_box").css("display", "block");
kbox.box_Toggle = true;
}
});

kbox.loadBox = (function(){
html = "<div id=\"KChat_heading\" ><div id=\"KChat_heading_title\" ></div></div>";
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>";
html += "<div id=\"KChat_scroll_panel\" >";
html += "<div id=\"KChat_scroll\" >";
html += "</div></div>";
html += "<div id=\"kchat_copy\" >&nbsp;<a href=\"https://github.com/php-kchat/kchat\" target=\"_blank\" >KChat &copy; 2017</a></div>";
html += "<div id=\"kchat_copy\" >&nbsp;<a href=\"https://github.com/php-kchat/kchat\" target=\"_blank\" >KChat &copy; 2017-2021</a></div>";
html += "<div id=\"KChat_textarea\" >"+
"<textarea class=\"kchatemoji\" autofocus=\"autofocus\" style=\"width:100%;height:100%\" id=\"kchattextarea\" ></textarea>"+
"</div>";
Expand Down Expand Up @@ -155,9 +183,12 @@ kbox.loademoji = (function(){
// to send msg on enter
if (keyCode == 13) {
msg = $(".emojionearea-editor").html();
msg = msg.replace(/(?:\r\n|\r|\n)/g, ' ');
//==============================================================
if(msg == ""){
$(".emojionearea-editor").html('');
msg = msg.replace(/(?:\r\n|\r|\n)/g,'');
msg = msg.replace(/<br\s*\/?>/gi,'');
msg = msg.replace(/<div>/g, '');
msg = msg.replace(/<\/div>/g, '');
if(msg.trim() == ""){
return false;
}
$.post(kbox.url + "kchat.php?msg",
Expand All @@ -178,7 +209,7 @@ kbox.loademoji = (function(){
});

kbox.loadform = (function(){
html = "<div id=\"KChat_heading\" ><div id=\"KChat_heading_title\" ></div></div>";
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>";
html += "<div id=\"KChat_form\" >";
html +="<p type=\"text\"><input id=\"kchat_fname\" placeholder=\"Write your first name here..\"></input></p>";
html +="<p type=\"text\"><input id=\"kchat_lname\" placeholder=\"Write your lastname here..\"></input></p>";
Expand All @@ -195,7 +226,13 @@ kbox.start = (function(){
var kchat_lname = $( "#kchat_lname" ).val();
var kchat_email = $( "#kchat_email" ).val();
var kchat_dept = $( "#kchat_dept" ).val();
var kchat_msg = $( "#kchat_msg" ).val();
var kchat_msg = $( "#kchat_msg" ).val().trim();

if(ifempty(kchat_fname) || ifempty(kchat_lname)|| ifempty(kchat_email)|| ifempty(kchat_msg)){
alert("Please fill in all the fields");
return false;
}

$.post(kbox.url + "kchat.php?start",
{
kchat_start: 'kchat_start',
Expand Down Expand Up @@ -252,6 +289,14 @@ function kchat_json(data){
}
}

function ifempty(str) {
if (str.trim().length == 0) {
return true;
} else {
return false;
}
}

function kchat_init(first){
if(global.guest == false){
return false;
Expand Down Expand Up @@ -290,7 +335,12 @@ function _loadoldmsg() {
}
}


function stripHtml(html)
{
let tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}

function toanchor(text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/i;
Expand Down
24 changes: 0 additions & 24 deletions box/logs/error.log
Original file line number Diff line number Diff line change
@@ -1,24 +0,0 @@
[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
[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
Stack trace:
#0 E:\Ampps\www\kchat\box\core\sandesh.php(103): PDOStatement->execute(Array)
#1 E:\Ampps\www\kchat\box\core\kchat.php(159): KChat->start(Array)
#2 E:\Ampps\www\kchat\box\kchat.php(18): require_once('E:\\Ampps\\www\\kc...')
#3 {main}
thrown in E:\Ampps\www\kchat\box\core\sandesh.php on line 103
[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
[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
Stack trace:
#0 E:\Ampps\www\kchat\box\core\sandesh.php(103): PDOStatement->execute(Array)
#1 E:\Ampps\www\kchat\box\core\kchat.php(159): KChat->start(Array)
#2 E:\Ampps\www\kchat\box\kchat.php(18): require_once('E:\\Ampps\\www\\kc...')
#3 {main}
thrown in E:\Ampps\www\kchat\box\core\sandesh.php on line 103
[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
[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
Stack trace:
#0 E:\Ampps\www\kchat\box\core\sandesh.php(103): PDOStatement->execute(Array)
#1 E:\Ampps\www\kchat\box\core\kchat.php(159): KChat->start(Array)
#2 E:\Ampps\www\kchat\box\kchat.php(18): require_once('E:\\Ampps\\www\\kc...')
#3 {main}
thrown in E:\Ampps\www\kchat\box\core\sandesh.php on line 103
12 changes: 8 additions & 4 deletions kchat/assets/js/kchat.msgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,19 @@ $(".kchatemoji").emojioneArea({
}
// to send msg on enter
if (keyCode == 13) {
msg = $(".emojionearea-editor").html();
//==============================================================
if(msg == ""){
msg = $(".emojionearea-editor").html();
$(".emojionearea-editor").html('');
msg = msg.replace(/(?:\r\n|\r|\n)/g,'');
msg = msg.replace(/<br\s*\/?>/gi,'');
msg = msg.replace(/<div>/g, '');
msg = msg.replace(/<\/div>/g, '');
if(msg.trim() == ""){
return false;
}
$.post(purl + "/ajax/chat/"+posturl,
{
timestamp: chat.timestamp,
msg: toanchor(msg),
msg: toanchor(msg).trim(),
first_run: 'false',
token : token
},
Expand Down
4 changes: 1 addition & 3 deletions kchat/sql/kchat.data.sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
--

INSERT INTO `%dbprefix%department` VALUES
(1, 'Admin', 'Head of Department'),
(2, 'support', 'support people'),
(3, 'IT', 'IT');
(1, 'Admin', 'Head of Department');

--
-- Dumping data for table `%dbprefix%groups`
Expand Down
2 changes: 1 addition & 1 deletion kchat/view/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}
?>
<footer class="pull-left footer">
<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>
<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>
</footer>
<script>
angular.module("myApp", ["ngAlertify"]).controller("myController", function($scope, alertif){});
Expand Down
2 changes: 1 addition & 1 deletion kchat/view/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}
?>
<footer class="pull-left footer">
<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>
<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>
</footer>
<script>
angular.module("myApp", ["ngAlertify"]).controller("myController", function($scope, alertif){});
Expand Down
4 changes: 2 additions & 2 deletions kchat/view/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
</fieldset>
</div>
<div class="panel-footer ">
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
</div>
<?php }else{ ?>
<div class="panel panel-default">
Expand All @@ -122,7 +122,7 @@
</div>
</div>
<div class="panel-footer ">
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
</div>
<?php } ?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion kchat/view/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</fieldset>
</div>
<div class="panel-footer ">
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion kchat/view/verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
</fieldset>
</div>
<div class="panel-footer ">
KChat&nbsp;&copy; 2017 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
KChat&nbsp;&copy; 2017-2021 ,KChat&nbsp;v<?php echo $this->data['config']['version']; ?>
</div>
</div>
</div>
Expand Down

0 comments on commit 7279623

Please sign in to comment.