<?php
session_start();
include_once "../config.php";
require_once '../database1.php';
require_once "../check_admin.php";

class product extends database
{

	public function GetCategory()
    {
		return $this->fetchAll('tb_product_category');
	}
	public function GetBrand()
    {
		return $this->fetchAll('tb_brands');
	}
}	
$obj = new product();
$productCategories = $obj->GetCategory();

$brands=$obj->GetBrand();
$templateType = 'add';
include '../header.php';
?>

<script src="<?php echo MAIN_DOMAIN ?>/ckeditor/ckeditor.js"></script>
            <!-- MAIN CONTENT-->
            <div class="main-content">
                <div class="section__content section__content--p30">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="overview-wrap">
                                    <h2 class="title-1">Chatroom</h2>
                                    
                                </div>
								<?php if($msg !=''){echo '<span class="col-md-6 alert alert-danger pull-left">' . $msg .  '</span>';}?>
                            </div>
                        </div>
                        
                        <div class="row m-t-25 m-row">
					
                            <div class="col-lg-10">
                                <div class="card">
                                    
                                    <div class="card-body card-block">
    									<form method="post" class="form" cluster-url="../ajax/mailbox/send_email" cluster-redirect="list" >
                                            <div class="row">
                                                <!--<div class="col-xs-12 col-sm-9">
                                                        <textarea class="form-control"></textarea>
                                                        <button type="submit" class="btn btn-success">Submit</button>
                                                </div>-->
                                                <div class="col-xs-12 col-sm-12" id="chat_list">
                                                     <div class="col-xs-12" id="unfinished_chats">
                                                        
                                                    </div>
                                                    <div class="col-xs-12" id="unattended_chats">
                                                        
                                                    </div>

                                                   
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                          
                        </div>
                        
                    <script>
							$(document).ready(function(){
								$('.active').removeClass('active');
								$('#chat-menu').addClass('active');

                                
							}); 

                            
						</script>   

                     

                        <SCRIPT>
                            function setChatList(htmlUnattended, htmlUnFinished)
                            {   
                                
                                    jQuery('#unattended_chats').html('<div class="col-sm-12 " style="padding: 15px;margin-bottom:15px;border-bottom:1px solid gray">Unattended Chats</div>' + htmlUnattended);
                                     jQuery('#unfinished_chats').html('<div class="col-sm-12 " style="padding: 15px;margin-bottom:15px;border-bottom:1px solid gray">Current Chats</div>' + htmlUnFinished);
                            }

                            function getChats()
                            {
                                var htmlUnattended = '';
                                var htmlUnFinished = ''
                                jQuery.get('ajax/get_chats', function(res){
                                    
                                    jQuery(res.unattendedChats).each(function(i, value){
                                        htmlUnattended+= '<a href="chat?id=' + value.cl_id + '" class="col-12 alert alert-primary each_chat" style="display:block">' + value.cl_message + ' - on ' + value.cl_created_at + ' (Product - ' + value.cl_name +')<br/>Email : <b>' + value.cl_email + '</b><br/>IP : <b>' + value.cl_ip + '</b></a>';

                                        
                                    });

                                    jQuery(res.unfinishedChats).each(function(i, value){
                                        htmlUnFinished+= '<a href="chat?id=' + value.cl_id + '" class="col-12 alert alert-primary each_chat" style="display:block">' + value.cl_message + ' - on ' + value.cl_created_at + ' (Product - ' + value.cl_name +')<br/>Email : <b>' + value.cl_email + '</b><br/>IP : <b>' + value.cl_ip + '</b></a>';
                                    });

                                    setChatList(htmlUnattended, htmlUnFinished);
                                },'json');
                                
                                
                            }

                            jQuery(document).ready(function(){
                                getChats();
                                setInterval(function() {
                                        getChats();
                                }, 5000);
                            });
                        </SCRIPT> 
                       

  <?php
  include '../footer.php';
  ?>