1- <?php
2- $ this ->isRead ();
3- $ helper = $ this ->helper ("Lof\ChatSystem\Helper\Data " );
4- $ current_url = $ this ->getCurrentChat ()->getData ('current_url ' );
5- ?>
6- <p><?php echo __ ('Chat message sent on ' ).' ' .($ current_url ?('<a href=" ' .$ current_url .'" target="_BLANK"> ' .$ current_url .'</a> ' ):"" );?> </p>
7- <input type="hidden" name="chat_id" value="<?php echo $ this ->getCurrentChat ()->getData ('chat_id ' );?> ">
8- <div class="main-chat" id="main-chat">
9- </div>
10- <div class="box-chat">
11- <form method="post" id="formSendMsg" onsubmit="return false;">
12- <input type="hidden" name="form_key" value="<?php echo $ this ->getFormKey (); ?> ">
13- <input type="hidden" name="chat_id" value="<?php echo $ this ->getCurrentChat ()->getData ('chat_id ' );?> ">
14- <input type="hidden" name="user_id" value="<?php echo $ this ->getUser ()->getData ('user_id ' );?> ">
15- <input type="hidden" name="customer_id" value="<?php echo $ this ->getCurrentChat ()->getData ('customer_id ' );?> ">
16- <input type="hidden" name="user_name" value="<?php echo $ this ->getUser ()->getData ('firstname ' ).' ' .$ this ->getUser ()->getData ('lastname ' );?> ">
17- <input type="hidden" name="customer_name" value="<?php echo $ this ->getCurrentChat ()->getData ('customer_name ' );?> ">
18- <input type="hidden" name="customer_email" value="<?php echo $ this ->getCurrentChat ()->getData ('customer_email ' );?> ">
19- <input type="text" name="body_msg" placeholder="<?php echo __ ('Please enter a message ' ); ?> ...">
20- </form>
21- </div>
22-
23- <script type="text/javascript">
24- require([
25- 'jquery'
26- ], function($){
27-
28- function sendMsg() {
29- $body_msg = $('#formSendMsg input[name="body_msg"]').val();
30- $chat_id = $('#formSendMsg input[name="chat_id"]').val();
31- $customer_id = $('#formSendMsg input[name="customer_id"]').val();
32- $user_id = $('#formSendMsg input[name="user_id"]').val();
33- $user_name = $('#formSendMsg input[name="user_name"]').val();
34- $customer_name = $('#formSendMsg input[name="customer_name"]').val();
35- $customer_email = $('#formSendMsg input[name="customer_email"]').val();
36- if($.trim($body_msg)) {
37- $('#formSendMsg input[type="text"]').val('');
38- $('.main-chat').append('<div class="msg-user"><p>'+$body_msg+'</p><div class="info-msg-user"><?php echo __ ("You " );?> </div></div>');
39- $.ajax({
40- url : '<?php echo $ this ->getUrl ('lofchatsystem/chat/sendmsg ' ); ?> ',
41- type : 'post',
42- dataType: 'json',
43- data : {
44- body_msg : $body_msg,
45- chat_id : $chat_id,
46- customer_id : $customer_id,
47- user_id : $user_id,
48- customer_name : $customer_name,
49- customer_email : $customer_email,
50- user_name: $user_name
51-
52- }, success : function() {
53- $('#formSendMsg input[type="text"]').val('');
54- var div = document.getElementById('main-chat')
55- div.scrollTop = div.scrollHeight - div.clientHeight;
56-
57- }
58- });
59- }
60- }
61-
62- $('#formSendMsg input[type="text"]').keypress(function() {
63- var keycode = (event.keyCode ? event.keyCode : event.which);
64- if (keycode == '13') {
65- sendMsg();
66- var div = document.getElementById('main-chat')
67- div.scrollTop = div.scrollHeight - div.clientHeight;
68- }
69- });
70-
71- $('#formSendMsg input[type="text"]').click(function(e) {
72- var div = document.getElementById('main-chat')
73- div.scrollTop = div.scrollHeight - div.clientHeight;
74- });
75- $('.main-chat').load('<?php echo $ this ->getUrl ('lofchatsystem/chat/msglog/chat_id/ ' .$ this ->getCurrentChat ()->getData ('chat_id ' )); ?> ');
76- $.ajaxSetup({cache:false});
77- setInterval(function() {$('.main-chat').load('<?php echo $ this ->getUrl ('lofchatsystem/chat/msglog/chat_id/ ' .$ this ->getCurrentChat ()->getData ('chat_id ' )); ?> '); }, 5000);
78- });
79- </script>
1+ <?php
2+ /**
3+ * @var $block \Lof\ChatSystem\Block\Adminhtml\Chat\Edit\Tab\Main
4+ */
5+ $ this ->isRead ();
6+ $ helper = $ this ->helper ("Lof\ChatSystem\Helper\Data " );
7+ $ current_url = $ block ->escapeUrl ($ this ->getCurrentChat ()->getData ('current_url ' ));
8+ ?>
9+ <p><?= __ ('Chat message sent on ' ) . ' ' . ($ current_url ? ('<a href=" ' . $ current_url . '" target="_BLANK"> ' . $ current_url . '</a> ' ) : "" ); ?> </p>
10+ <input type="hidden" name="chat_id" value="<?= $ this ->getCurrentChat ()->getData ('chat_id ' ); ?> ">
11+ <div class="main-chat" id="main-chat">
12+ </div>
13+ <div class="box-chat">
14+ <form method="post" id="formSendMsg" onsubmit="return false;">
15+ <input type="hidden" name="form_key" value="<?= $ block ->escapeHtmlAttr ($ this ->getFormKey ()); ?> ">
16+ <input type="hidden" name="chat_id" value="<?= $ block ->escapeHtmlAttr ($ this ->getCurrentChat ()->getData ('chat_id ' )); ?> ">
17+ <input type="hidden" name="user_id" value="<?= $ block ->escapeHtmlAttr ($ this ->getUser ()->getData ('user_id ' )); ?> ">
18+ <input type="hidden" name="customer_id" value="<?= $ block ->escapeHtmlAttr ($ this ->getCurrentChat ()->getData ('customer_id ' )); ?> ">
19+ <input type="hidden" name="user_name"
20+ value="<?= $ block ->escapeHtmlAttr ($ this ->getUser ()->getData ('firstname ' ) . ' ' . $ this ->getUser ()->getData ('lastname ' )); ?> ">
21+ <input type="hidden" name="customer_name" value="<?= $ block ->escapeHtmlAttr ($ this ->getCurrentChat ()->getData ('customer_name ' )); ?> ">
22+ <input type="hidden" name="customer_email" value="<?= $ block ->escapeHtmlAttr ($ this ->getCurrentChat ()->getData ('customer_email ' )); ?> ">
23+ <input type="text" name="body_msg" placeholder="<?= __ ('Please enter a message ' ); ?> ...">
24+ </form>
25+ </div>
26+
27+ <script type="text/javascript">
28+ require([
29+ 'jquery'
30+ ], function ($) {
31+
32+ function sendMsg() {
33+ $body_msg = lofescapeHtml($('#formSendMsg input[name="body_msg"]').val());
34+ $chat_id = lofescapeHtml($('#formSendMsg input[name="chat_id"]').val());
35+ $customer_id = lofescapeHtml($('#formSendMsg input[name="customer_id"]').val());
36+ $user_id = lofescapeHtml($('#formSendMsg input[name="user_id"]').val());
37+ $user_name = lofescapeHtml($('#formSendMsg input[name="user_name"]').val());
38+ $customer_name = lofescapeHtml($('#formSendMsg input[name="customer_name"]').val());
39+ $customer_email = lofescapeHtml($('#formSendMsg input[name="customer_email"]').val());
40+ if ($.trim($body_msg)) {
41+ $('#formSendMsg input[type="text"]').val('');
42+ $('.main-chat').append('<div class="msg-user"><p>' + $body_msg + '</p><div class="info-msg-user"><?= __ ("You " );?> </div></div>');
43+ $.ajax({
44+ url: '<?= $ this ->getUrl ('lofchatsystem/chat/sendmsg ' ); ?> ',
45+ type: 'post',
46+ dataType: 'json',
47+ data: {
48+ body_msg: $body_msg,
49+ chat_id: $chat_id,
50+ customer_id: $customer_id,
51+ user_id: $user_id,
52+ customer_name: $customer_name,
53+ customer_email: $customer_email,
54+ user_name: $user_name
55+
56+ }, success: function () {
57+ $('#formSendMsg input[type="text"]').val('');
58+ var div = document.getElementById('main-chat')
59+ div.scrollTop = div.scrollHeight - div.clientHeight;
60+ }
61+ });
62+ }
63+ }
64+
65+ function lofescapeHtml(unsafe) {
66+ return unsafe
67+ .replace(/&/g, "&")
68+ .replace(/</g, "<")
69+ .replace(/>/g, ">")
70+ .replace(/"/g, """)
71+ .replace(/'/g, "'");
72+ }
73+
74+ $('#formSendMsg input[type="text"]').keypress(function () {
75+ var keycode = (event.keyCode ? event.keyCode : event.which);
76+ if (keycode == '13') {
77+ sendMsg();
78+ var div = document.getElementById('main-chat')
79+ div.scrollTop = div.scrollHeight - div.clientHeight;
80+ }
81+ });
82+
83+ $('#formSendMsg input[type="text"]').click(function (e) {
84+ var div = document.getElementById('main-chat')
85+ div.scrollTop = div.scrollHeight - div.clientHeight;
86+ });
87+
88+ $('.main-chat').load('<?= $ this ->getUrl ('lofchatsystem/chat/msglog/chat_id/ ' . $ this ->getCurrentChat ()->getData ('chat_id ' )); ?> ');
89+ $.ajaxSetup({cache: false});
90+ setInterval(function () {
91+ $('.main-chat').load('<?= $ this ->getUrl ('lofchatsystem/chat/msglog/chat_id/ ' . $ this ->getCurrentChat ()->getData ('chat_id ' )); ?> ');
92+ }, 5000);
93+ });
94+ </script>
0 commit comments