<?php 
include("../includes/config.php");
include("../includes/function.php");
include("../includes/session.php");

$session = new Session();
$database = new Database();

$getUserDetails = $database->getRecord("manage_users", "num='".$session->get('userAdminID')."'");
$cmsOrgId = $session->get('cmsOrgId');
$adminUserId = $session->get('userAdminID');
if($_REQUEST['event_id']) {
    $cmsEventId = $_REQUEST['event_id'];
} else {
    $cmsEventId = $session->get('cmsEventId');
}

if($getUserDetails['role']=="4") {
    $getEvents = $database->getRecords("manage_events", "user_id='".$adminUserId."'", "created_on ASC");
    if(!empty($cmsEventId)) {
        $getAttendees = $database->getRecords("manage_users", "event_id='".$cmsEventId."' AND role='2'", "created_on ASC");
        $getExibitors = $database->getRecords("manage_users", "event_id='".$cmsEventId."' AND role='1'", "created_on ASC");
        $get2dEx = $database->getRecords("manage_stand_visits", "event_id='".$cmsEventId."' AND type='2d'", "created_on ASC");
        $get3dEx = $database->getRecords("manage_stand_visits", "event_id='".$cmsEventId."' AND type='3d'", "created_on ASC");
        $getVideosCount = $database->getRecords("manage_doc_visit_count", "event_id='".$cmsEventId."' AND video_id!=''", "created_on ASC");
        $getDocCount = $database->getRecords("manage_doc_visit_count", "event_id='".$cmsEventId."' AND doc_id!=''", "created_on ASC");
    } else {
        $getAttendees = $database->getRecords("manage_users", "org_id='".$adminUserId."' AND role='2'", "created_on ASC");
        $getExibitors = $database->getRecords("manage_users", "org_id='".$adminUserId."' AND role='1'", "created_on ASC");
        $get2dEx = $database->getRecords("manage_stand_visits AS msv LEFT JOIN manage_events AS me ON me.num=msv.event_id", "msv.type='2d' AND me.user_id='".$adminUserId."'", "msv.created_on ASC");
        $get3dEx = $database->getRecords("manage_stand_visits AS msv LEFT JOIN manage_events AS me ON me.num=msv.event_id", "msv.type='3d' AND me.user_id='".$adminUserId."'", "msv.created_on ASC");
        $getVideosCount = $database->getRecords("manage_doc_visit_count", "org_id='".$adminUserId."' AND video_id!=''", "created_on ASC");
        $getDocCount = $database->getRecords("manage_doc_visit_count", "org_id='".$adminUserId."' AND doc_id!=''", "created_on ASC");
    }
} else {
    if(!empty($cmsEventId)) {
        $getEvents = $database->getRecords("manage_events", "user_id='".$cmsOrgId."'", "created_on ASC");
        $getAttendees = $database->getRecords("manage_users", "event_id='".$cmsEventId."' AND role='2'", "created_on ASC");
        $getExibitors = $database->getRecords("manage_users", "event_id='".$cmsEventId."' AND role='1'", "created_on ASC");
        $get2dEx = $database->getRecords("manage_stand_visits", "event_id='".$cmsEventId."' AND type='2d'", "created_on ASC");
        $get3dEx = $database->getRecords("manage_stand_visits", "event_id='".$cmsEventId."' AND type='3d'", "created_on ASC");
        $getVideosCount = $database->getRecords("manage_doc_visit_count", "event_id='".$cmsEventId."' AND video_id!=''", "created_on ASC");
        $getDocCount = $database->getRecords("manage_doc_visit_count", "event_id='".$cmsEventId."' AND doc_id!=''", "created_on ASC");
    } else if(!empty($cmsOrgId)) {
        $getEvents = $database->getRecords("manage_events", "1", "created_on ASC");
        $getAttendees = $database->getRecords("manage_users", "org_id='".$cmsOrgId."' AND role='2'", "created_on ASC");
        $getExibitors = $database->getRecords("manage_users", "org_id='".$cmsOrgId."' AND role='1'", "created_on ASC");$get2dEx = $database->getRecords("manage_stand_visits AS msv LEFT JOIN manage_events AS me ON me.num=msv.event_id", "msv.type='2d' AND me.user_id='".$cmsOrgId."'", "msv.created_on ASC");
        $get3dEx = $database->getRecords("manage_stand_visits AS msv LEFT JOIN manage_events AS me ON me.num=msv.event_id", "msv.type='3d' AND me.user_id='".$cmsOrgId."'", "msv.created_on ASC");
        $getVideosCount = $database->getRecords("manage_doc_visit_count", "org_id='".$cmsOrgId."' AND video_id!=''", "created_on ASC");
        $getDocCount = $database->getRecords("manage_doc_visit_count", "org_id='".$cmsOrgId."' AND doc_id!=''", "created_on ASC");
    } else {
        $getEvents = $database->getRecords("manage_events", "1", "created_on ASC");
        $getAttendees = $database->getRecords("manage_users", "role='2'", "created_on ASC");
        $get2dEx = $database->getRecords("manage_stand_visits", "type='2d'", "created_on ASC");
        $get3dEx = $database->getRecords("manage_stand_visits", "type='3d'", "created_on ASC");
        $getExibitors = $database->getRecords("manage_users", "role='1'", "created_on ASC");
        $getVideosCount = $database->getRecords("manage_doc_visit_count", "video_id!=''", "created_on ASC");
        $getDocCount = $database->getRecords("manage_doc_visit_count", "doc_id!=''", "created_on ASC");
    }
}

include("includes/header.php");
?>
    <body class="top-navbar-fixed">
        <div class="main-wrapper">

            <?php echo include("includes/menu.php");?>

            <!-- ========== WRAPPER FOR BOTH SIDEBARS & MAIN CONTENT ========== -->
            <div class="content-wrapper">
                <div class="content-container">
                    
                    <?php include("includes/sidebar.php");?>

                    <div class="main-page">
                        <div class="container-fluid">
                            <div class="row page-title-div">
                                <div class="col-md-6">
                                    <h4 class="title">Dashboard</h4>
                                    <?php if($getUserDetails['role']=="4") {?>
                                    <p class="sub-title">The Xibitrs virtual event and exhibition platform</p>
                                    <?php } else {?>
                                    <p class="sub-title">The Xibitrs virtual event and exhibition platform</p>
                                    <?php }?>
                                </div>
                                
                            </div>
                            <!-- /.row -->
                            <div class="row breadcrumb-div">
                                <div class="col-md-6">
                                    <ul class="breadcrumb">
            							<li><a href="<?php echo CMS_ROOT;?>dashboard.php"><i class="fa fa-home"></i> Home</a></li>
            							<li class="active">Dashboard</li>
            						</ul>
                                </div>
                                
                            </div>
                            <!-- /.row -->
                        </div>
                        <!-- /.container-fluid -->

                        <section class="section">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
                                        <p>Please select event to view statistics as per events</p>
                                        </div>
                                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
                                        <?php if($getUserDetails['role']=="4") {
                                        ?>
                                        <select name="sel_event" id="selEvent" style="float:right;">
                                            <option value="">Select Event</option>
                                            <?php foreach($getEvents as $record):
                                            if($cmsEventId==$record['num']) {
                                                $selected = "selected";
                                            } else {
                                                $selected = "";
                                            }?>
                                            <option value="<?php echo $record['num'];?>" <?php echo $selected;?>><?php echo $record['event_name'];?></option>
                                            <?php endforeach;?>
                                        </select>
                                        <?php }?>
                                        </div>
                                        <br clear="all">
                                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                        <a class="dashboard-stat-2 bg-danger" href="#">
                                            <div class="stat-content">
                                                <span class="number counter"><?php echo count($getAttendees);?></span>
                                                <span class="name">Attendees</span>
                                            </div>
                                            
                                        </a>
                                        <!-- /.dashboard-stat-2 -->

                                        
                                    </div>
                                    <!-- /.col-lg-3 col-md-3 col-sm-6 col-xs-12 -->

                                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                        <a class="dashboard-stat-2 bg-warning" href="#">
                                            <div class="stat-content">
                                                <span class="number counter"><?php echo count($getExibitors);?></span>
                                                <span class="name">Exibitors</span>
                                            </div>
                                            
                                        </a>
                                        <!-- /.dashboard-stat-2 -->

                                        
                                    </div>
                                    <!-- /.col-lg-3 col-md-3 col-sm-6 col-xs-12 -->
                                    
                                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                        <a class="dashboard-stat-2 bg-warning" href="#">
                                            <div class="stat-content">
                                                <span class="number counter"><?php echo count($get2dEx);?></span>
                                                <span class="name">Total individual 2D exhibition stand visits</span>
                                            </div>
                                            
                                        </a>
                                        <!-- /.dashboard-stat-2 -->

                                        
                                    </div>
                                    <!-- /.col-lg-3 col-md-3 col-sm-6 col-xs-12 -->
                                    
                                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                        <a class="dashboard-stat-2 bg-warning" href="#">
                                            <div class="stat-content">
                                                <span class="number counter"><?php echo count($get3dEx);?></span>
                                                <span class="name">Total individual 3D exhibition stand visits</span>
                                            </div>
                                            
                                        </a>
                                        <!-- /.dashboard-stat-2 -->

                                        
                                    </div>
                                    <!-- /.col-lg-3 col-md-3 col-sm-6 col-xs-12 -->

                                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                        <a class="dashboard-stat-2 bg-success" href="#">
                                            <div class="stat-content">
                                                <span class="number counter"><?php echo count($getDocCount);?></span>
                                                <span class="name">Document Downloads</span>
                                            </div>
                                            
                                        </a>
                                        <!-- /.dashboard-stat-2 -->
                                    </div>
                                    <!-- /.col-lg-3 col-md-3 col-sm-6 col-xs-12 -->
                                    
                                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                        <a class="dashboard-stat-2 bg-primary" href="#">
                                            <div class="stat-content">
                                                <span class="number counter"><?php echo count($getVideosCount);?></span>
                                                <span class="name">Video Views</span>
                                            </div>
                                            
                                        </a>
                                        <!-- /.dashboard-stat-2 -->

                                        
                                    </div>
                                    <!-- /.col-lg-3 col-md-3 col-sm-6 col-xs-12 -->

                                </div>
                                <!-- /.row -->
                            </div>
                            <!-- /.container-fluid -->
                        </section>
                        <!-- /.section -->

                        
                    </div>
                    <!-- /.main-page -->

                    <div class="right-sidebar bg-white fixed-sidebar">
                        <div class="sidebar-content">
                            <div class="container-fluid">
                                <div class="row">
                                    <div class="col-md-12">
                                        <h4>Useful Sidebar <i class="fa fa-times close-icon"></i></h4>
                                        <p>Code for help is added within the main page. Check for code below the example.</p>
                                        <p>You can use this sidebar to help your end-users. You can enter any HTML in this sidebar.</p>
                                        <p>This sidebar can be a 'fixed to top' or you can unpin it to scroll with main page.</p>
                                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
                                    </div>
                                    <!-- /.col-md-12 -->

                                    <div class="text-center mt-20">
                                        <button type="button" class="btn btn-success btn-labeled">Purchase Now<span class="btn-label btn-label-right"><i class="fa fa-check"></i></span></button>
                                    </div>
                                    <!-- /.text-center -->
                                </div>
                                <!-- /.row -->
                            </div>
                            <!-- /.container-fluid -->
                        </div>
                        <!-- /.sidebar-content -->
                    </div>
                    <!-- /.right-sidebar -->

                </div>
                <!-- /.content-container -->
            </div>
            <!-- /.content-wrapper -->

        </div>
        <!-- /.main-wrapper -->

        <!-- ========== COMMON JS FILES ========== -->
        <script src="js/jquery/jquery-2.2.4.min.js"></script>
        <script src="js/jquery-ui/jquery-ui.min.js"></script>
        <script src="js/bootstrap/bootstrap.min.js"></script>
        <script src="js/pace/pace.min.js"></script>
        <script src="js/lobipanel/lobipanel.min.js"></script>
        <script src="js/iscroll/iscroll.js"></script>

        <!-- ========== PAGE JS FILES ========== -->
        <script src="js/prism/prism.js"></script>
        <script src="js/waypoint/waypoints.min.js"></script>
        <script src="js/counterUp/jquery.counterup.min.js"></script>
        <script src="js/amcharts/amcharts.js"></script>
        <script src="js/amcharts/serial.js"></script>
        <script src="js/amcharts/pie.js"></script>
        <script src="js/amcharts/plugins/export/export.min.js"></script>
        <link rel="stylesheet" href="js/amcharts/plugins/export/export.css" type="text/css" media="all" />
        <script src="js/amcharts/themes/light.js"></script>
        <script src="js/icheck/icheck.min.js"></script>

        <!-- ========== THEME JS ========== -->
        <script src="js/main.js"></script>
        <script src="js/bar-chart.js"></script>
        <script src="js/pie-chart.js"></script>
        <script src="js/task-list.js"></script>
        <script>
            $(function(){
                
                $("#close_popup").click(function(){
                   location.reload(); 
                });
                
                $(".close").click(function(){
                   location.reload(); 
                });
                
                $("#add_update_recorda").submit(function() {
                    var dataString = $(this).serialize();
                   $.ajax({
                    type: "POST",
                    url: "/includes/process.php",
                    async: true,
        			contentType: false,
            	    cache: false,
        			processData:false,
                    data: new FormData(this),
                    success: function(data){
                        if(data=="1") {
                            $(".modal-body").append("<div style='color:#fff; background:#5ECFB1; padding:5px;'>Data updated successfully</div>");
                        }
                    }
                  }); 
                  return false;
                });
                <?php if($getUserDetails['role']=="4") {?>
                    $("#selEvent").change(function() {
                        var selEventId = $(this).val();
                        if(selEventId!="") {
                            $(location).attr('href', 'https://platform.xibitrs.net/cms/dashboard.php?event_id='+selEventId); 
                        }
                    });
                <?php } ?>
                
                // Counter for dashboard stats
                $('.counter').counterUp({
                    delay: 10,
                    time: 1000
                });

            });
        </script>

        <!-- ========== ADD custom.js FILE BELOW WITH YOUR CHANGES ========== -->
    </body>
</html>
