<?php
//ini_set('session.gc_maxlifetime', 86400);

//session_set_cookie_params(86400);
session_start();
include_once('../config/#Config.php');
if(!$_SESSION['UserName']){
die('<script>window.location.href=\''.$config['site']['url'].'index.php\';</script>');
}
$get_AD = mysqli_query($conn, "Select * From config_admin WHERE Account = '".$_SESSION['UserName']."'");
if(!mysqli_num_rows($get_AD)){
	die('Không đủ quyền.');
}
mysqli_query($conn, "UPDATE config_admin Set TimerOnline = '".date('d/m/Y H:i:s')."' WHERE Account = '".$_SESSION['UserName']."'");
?>
<!doctype html>
<html lang="en">


<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Content-Language" content="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Quản lý GiftCode - <?=$config['site']['Domain']?></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no" />
    <meta name="description" content="This is an example dashboard created using build-in elements and components.">
    <meta name="msapplication-tap-highlight" content="no">
    <!--
    =========================================================
    * ArchitectUI HTML Theme Dashboard - v1.0.0
    =========================================================
    * Product Page: https://dashboardpack.com
    * Copyright 2019 DashboardPack (https://dashboardpack.com)
    * Licensed under MIT (https://github.com/DashboardPack/architectui-html-theme-free/blob/master/LICENSE)
    =========================================================
    * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    -->
    <script src="https://code.jquery.com/jquery-1.9.1.js"></script>

<link href="main.css" rel="stylesheet"></head>
<body>
    <div class="app-container app-theme-white body-tabs-shadow fixed-sidebar fixed-header">
        <div class="app-header header-shadow">
            <div class="app-header__logo">
                <div class="logo-src"></div>
                <div class="header__pane ml-auto">
                    <div>
                        <button type="button" class="hamburger close-sidebar-btn hamburger--elastic" data-class="closed-sidebar">
                            <span class="hamburger-box">
                                <span class="hamburger-inner"></span>
                            </span>
                        </button>
                    </div>
                </div>
            </div>
            <div class="app-header__mobile-menu">
                <div>
                    <button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
                        <span class="hamburger-box">
                            <span class="hamburger-inner"></span>
                        </span>
                    </button>
                </div>
            </div>
            <div class="app-header__menu">
                <span>
                    <button type="button" class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
                        <span class="btn-icon-wrapper">
                            <i class="fa fa-ellipsis-v fa-w-6"></i>
                        </span>
                    </button>
                </span>
            </div>    <div class="app-header__content">
                <div class="app-header-left">
                    <div class="search-wrapper">
                        <div class="input-holder">
                            <input type="text" class="search-input" placeholder="Type to search">
                            <button class="search-icon"><span></span></button>
                        </div>
                        <button class="close"></button>
                    </div>
                    <ul class="header-menu nav">
                        <li class="nav-item">
                            <a href="javascript:void(0);" class="nav-link">
                                <i class="nav-link-icon fa fa-database"> </i>
                                Statistics
                            </a>
                        </li>
                        <li class="btn-group nav-item">
                            <a href="javascript:void(0);" class="nav-link">
                                <i class="nav-link-icon fa fa-edit"></i>
                                Projects
                            </a>
                        </li>
                        <li class="dropdown nav-item">
                            <a href="javascript:void(0);" class="nav-link">
                                <i class="nav-link-icon fa fa-cog"></i>
                                Settings
                            </a>
                        </li>
                    </ul>        </div>
                <div class="app-header-right">
                    <div class="header-btn-lg pr-0">
                        <div class="widget-content p-0">
                            <div class="widget-content-wrapper">
                                <div class="widget-content-left  ml-3 header-user-info">
                                    <div class="widget-heading">
                                        Alina Mclourd
                                    </div>
                                    <div class="widget-subheading">
                                        VP People Manager
                                    </div>
                                </div>
                                <div class="widget-content-right header-user-info ml-3">
                                    <button type="button" class="btn-shadow p-1 btn btn-primary btn-sm show-toastr-example">
                                        <i class="fa text-white fa-calendar pr-1 pl-1"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>        </div>
            </div>
        </div>        <div class="ui-theme-settings">
            <button type="button" id="TooltipDemo" class="btn-open-options btn btn-warning">
                <i class="fa fa-cog fa-w-16 fa-spin fa-2x"></i>
            </button>
<?php include_once('temp_setting.php');?>
        </div>
        <div class="app-main">
                <div class="app-sidebar sidebar-shadow">
                    <div class="app-header__logo">
                        <div class="logo-src"></div>
                        <div class="header__pane ml-auto">
                            <div>
                                <button type="button" class="hamburger close-sidebar-btn hamburger--elastic" data-class="closed-sidebar">
                                    <span class="hamburger-box">
                                        <span class="hamburger-inner"></span>
                                    </span>
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="app-header__mobile-menu">
                        <div>
                            <button type="button" class="hamburger hamburger--elastic mobile-toggle-nav">
                                <span class="hamburger-box">
                                    <span class="hamburger-inner"></span>
                                </span>
                            </button>
                        </div>
                    </div>
                    <div class="app-header__menu">
                        <span>
                            <button type="button" class="btn-icon btn-icon-only btn btn-primary btn-sm mobile-toggle-header-nav">
                                <span class="btn-icon-wrapper">
                                    <i class="fa fa-ellipsis-v fa-w-6"></i>
                                </span>
                            </button>
                        </span>
                    </div>
                    <div class="scrollbar-sidebar">
                        <div class="app-sidebar__inner">
                           <?php include_once('temp_menu.php'); ?>
                        </div>
                    </div>
                </div>
                <div class="app-main__outer">
                <div class="app-main__inner">
                        <div class="app-page-title">
                            <div class="page-title-wrapper">
                                <div class="page-title-heading">
                                    <div class="page-title-icon">
                                        <i class="pe-7s-phone icon-gradient bg-premium-dark">
                                        </i>
                                    </div>
                                    <div>
                                       Quản Lý GiftCode - Sự Kiện
                                        <div class="page-title-subheading">Hãy chú ý trước khi sử dụng bất kỳ Chức Năng nào.
                                        </div>
                                    </div>
                                </div>
                                <div class="page-title-actions">
                                    <button type="button" data-toggle="tooltip" title="" data-placement="bottom" class="btn-shadow mr-3 btn btn-dark" data-original-title="Example Tooltip">
                                        <i class="fa fa-star"></i>
                                    </button>
                                    <div class="d-inline-block dropdown" onClick="TaoEventCode();">
                                        <button type="button" aria-expanded="false" class="btn-shadow btn btn-info">
                                            <span class="btn-icon-wrapper pr-2 opacity-7">
                                                <i class="fa fa-business-time fa-w-20"></i>
                                            </span>
                                            Tạo Event
                                        </button>

                                    </div>
                                </div>
                            </div>
                        </div>           
                        <div class="row">
                            <div class="col-md-12">
                                <div class="main-card mb-3 card">
                                    <div class="card-body">
                                        <script>
                                              function texttimkiem(){
                                               $.post('ajax/ajax-search-eventcode.php', {keyword:$('#timkiemevent').val()},function(data){
                                                $('#tableevent').html(data);
                                               });
                                        }
                                        function TimKiemQueryEvent(caulenh){
                                               $.post('ajax/ajax-search-eventcode.php', {query:caulenh,keyword:$('#texttimkiem').val()},function(data){
                                                $('.table-responsive').html(data);
                                               });
                                        }
                                        </script>
                                    <div class="input-group">
                                                        <div class="input-group-prepend">
                                                            <button class="btn btn-outline-secondary">Tìm Kiếm</button>
                                                            <button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="dropdown-toggle dropdown-toggle-split btn btn-outline-secondary"><span class="sr-only">Toggle Dropdown</span></button>
                                                        </div>
                                                        <input placeholder="and..." id="timkiemevent" onkeyup="texttimkiem();" type="text" class="form-control">
                                                        <div class="input-group-append">
                                                            <button class="btn btn-secondary">Tìm Kiếm</button>
                                                        </div>
                                                    </div>
                                                    <br/>
                                    <div class="table-responsive" id="tableevent">
                                        
                                        <table class="align-middle mb-0 table table-borderless table-striped table-hover">
                                            <thead>
                                            <tr>
                                                <th class="text-center">#</th>
                                                <th>Tên Sự Kiện</th>
                                                <th class="text-center">Giới hạn Nhập</th>
                                                <th class="text-center">Bắt Đầu</th>
                                                <th class="text-center">Kết Thúc</th>
                                                <th class="text-center">Chức Năng</th>
                                            </tr>
                                            </thead>
                                            <tbody>
      <?php
       $_GET['CauQuery'] = 'TimKiemQuery';
          include_once('paginator.class.php'); 
		$condition		=	"";
        $qryStr		=	"SELECT * from giftcode ORDER BY ID ASC";      
		$country	=	mysqli_query($conn,$qryStr);
		$count		=	mysqli_num_rows($country);
		
        $pages = new Paginator($count,9);
		echo '<nav class="" aria-label="Page navigation example"> <ul class="pagination">';
		echo $pages->display_pages();
		echo '</ul></nav>';
		echo '</div>';
		echo '<div class="clearfix"></div>';
		$limit	= $pages->limit_start.','.$pages->limit_end;
        $qry 	=	mysqli_query($conn, $qryStr.' LIMIT '.$limit);
        if($count>0){
            $n	=	1;
            while($val	=	mysqli_fetch_array($qry, MYSQLI_ASSOC)){ 
                echo ' <tr>
                <td class="text-center text-muted">#'.$n.'</td>
                <td>
                    <div class="widget-content p-0">
                        <div class="widget-content-wrapper">
                            <div class="widget-content-left mr-3">
                                <div class="widget-content-left">
                                    <img width="40" class="rounded-circle" src="assets/images/giftcode.png" alt="">
                                </div>
                            </div>
                            <div class="widget-content-left flex2">
                                <div class="widget-heading">'.$val['EventName'].'</div>
                                <div class="widget-subheading opacity-7">ID Event : '.$val['IDEvent'].'</div>
                            </div>
                        </div>
                    </div>
                </td>
                <td class="text-center">'.number_format($val['Count_Click']).'</td>
                <td class="text-center">
                    <div class="badge badge-warning">'.date('d/m/Y H:i',$val['TimerStart']).'</div>
                </td>
                <td class="text-center">
                <div class="badge badge-warning">'.date('d/m/Y H:i',$val['TimerEnd']).'</div>
            </td>               
                <td class="text-center">
                <div class="dropdown d-inline-block">
                <button type="button" aria-haspopup="true" aria-expanded="false" data-toggle="dropdown" class="mb-2 mr-2 dropdown-toggle btn btn-primary">Quản Lý</button>
                <div tabindex="-1" role="menu" aria-hidden="true" class="dropdown-menu">
                    <button type="button" tabindex="0" class="dropdown-item" onClick="showpupuweb(\'editcode\',\''.$val['IDEvent'].'\',\''.$val['EventName'].'\');">Quản Lý Quà</button>
                    <button type="button" tabindex="0" class="dropdown-item" onClick="showpupuweb(\'quanlycode\',\''.$val['IDEvent'].'\',\''.$val['EventName'].'\');">Quản lý Code</button>
                    <button type="button" tabindex="0" class="dropdown-item" onClick="showpupuweb(\'xoaevent\',\''.$val['IDEvent'].'\',\''.$val['EventName'].'\');">Xóa Event</button>
                    <button type="button" tabindex="0" class="dropdown-item" onClick="showpupuweb(\'renewevent\',\''.$val['IDEvent'].'\',\''.$val['EventName'].'\');">Renew Event</button>
                    <button type="button" tabindex="0" class="dropdown-item" onClick="showpupuweb(\'xoacode\',\''.$val['IDEvent'].'\',\''.$val['EventName'].'\');">Xóa CODE</button>
                </div>
            </div>
                </td>
            </tr>';
            $n++;
            }
        }
    ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="app-wrapper-footer">
                        <div class="app-footer">
                            <div class="app-footer__inner">
                                <div class="app-footer-left">
                                    <ul class="nav">
                                        <li class="nav-item">
                                            <a href="javascript:void(0);" class="nav-link">
                                                Footer Link 1
                                            </a>
                                        </li>
                                        <li class="nav-item">
                                            <a href="javascript:void(0);" class="nav-link">
                                                Footer Link 2
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                                <div class="app-footer-right">
                                    <ul class="nav">
                                        <li class="nav-item">
                                            <a href="javascript:void(0);" class="nav-link">
                                                Footer Link 3
                                            </a>
                                        </li>
                                        <li class="nav-item">
                                            <a href="javascript:void(0);" class="nav-link">
                                                <div class="badge badge-success mr-1 ml-0">
                                                    <small>NEW</small>
                                                </div>
                                                Footer Link 4
                                            </a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>    </div>
        </div>
    </div>
 <!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>   
<script type="text/javascript" src="assets/scripts/main.js"></script>
<link href="assets/scripts/toastr.css" rel="stylesheet" />
<script src="assets/scripts/toastr.js"></script>
<script src="assets/scripts/script.js"></script> 
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<script type="text/javascript">
function ConfirmDialog(message, data, idevent) {
    $('<div></div>').appendTo('body')
        .html('<div><h6>' + message + '?</h6></div>')
        .dialog({
            modal: true,
            title: 'Xác Nhận Trước Khi làm',
            zIndex: 10000,
            autoOpen: true,
            width: 'auto',
            resizable: false,
            buttons: {
                Yes: function() {
                    // $(obj).removeAttr('onclick');                                
                    // $(obj).parents('.Parent').remove();

                    if (data == "renewevent") {
                        $.post('ajax/del_codengay.php', {
                            idevent: idevent
                        }, function(data) {
                            if (data == "0") {
                                toastr.success("Renew hoàn tất.", 'Chú ý', {
                                    timeOut: 5000
                                });
                            } else {
                                toastr.info(data, 'Chú ý', {
                                    timeOut: 5000
                                });
                            }
                        });
                    } else if (data == "xoaevent") {
                        $.post('ajax/del_eventcode.php', {
                            idevent: idevent
                        }, function(data) {
                            if (data == "0") {
                                toastr.success("Xóa Event hoàn tất.", 'Chú ý', {
                                    timeOut: 5000
                                });
                            } else {
                                toastr.info(data, 'Chú ý', {
                                    timeOut: 5000
                                });
                            }
                        });
                    } else if (data == "xoacode") {
                        $.post('ajax/del_coderandom.php', {
                            idevent: idevent
                        }, function(data) {
                            if (data == "0") {
                                toastr.success("Xóa CODE hoàn tất.", 'Chú ý', {
                                    timeOut: 5000
                                });
                            } else {
                                toastr.info(data, 'Chú ý', {
                                    timeOut: 5000
                                });
                            }
                        });
                    }

                    $(this).dialog("close");
                },
                No: function() {

                    $(this).dialog("close");
                }
            },
            close: function(event, ui) {
                $(this).remove();
            }
        });
};

function showpupuweb(data, idevent, name) {
    toastr.info('Đang tải dữ liệu đợi ít giây', 'Chú ý', {
        timeOut: 5000
    });
    if (data == "editcode") {
        $('#exampleModalLongTitle').html('Quản lý & Chỉnh Sửa Code [' + name + ']');
        $('#card-title1').html('[' + name + ']');
        $.post('from/form_editcode.php', {
            idevent: idevent
        }, function(data) {
            $('#infoUser').html(data);
        });
        $.post('from/form_itemcode.php', {
            idevent: idevent
        }, function(data) {
            $('#infoUserLogs').html(data);
        });
        $('#exampleModalLongTitle').html('Chỉnh sửa & Quản lý [' + name + ']');
        $("#popupuserweb").modal('show');
    } else if (data == "quanlycode") {
        $.post('from/panel_taocode.php', {
            idevent: idevent
        }, function(data) {
            $('#infoUser').html(data);
        });
        $.post('from/panel_code.php', {
            idevent: idevent
        }, function(data) {
            $('#infoUserLogs').html(data);
        });
        $('#exampleModalLongTitle').html('Quản lý nhân vật [' + name + ']');
        $("#popupuserweb").modal('show');
    } else if (data == "renewevent") {
        ConfirmDialog('Bạn có thực sự muốn Renew Sự Kiện [' + name + '] này không.', data, idevent);
    } else if (data == "xoaevent") {
        ConfirmDialog('Bạn có thực sự muốn Xóa Sự Kiện [' + name + '] này không.', data, idevent);
    } else if (data == "xoacode") {
        ConfirmDialog('Bạn có thực sự muốn Xóa Danh Sách Code SỰ KIỆN [' + name + '] này không.', data, idevent);
    }
}

function TaoEventCode() {
    toastr.info('Đang tải dữ liệu đợi ít giây', 'Chú ý', {
        timeOut: 5000
    });
    $.post('from/panel_taoevent.php', function(data) {
        $('#taocodepopupform').html(data);
    });
    $("#taocodepopup").modal('show');
}
</script>
<style>
    .modal-fullscreen{
  width: 100%;
  height: 100%;
  margin: 0;
  top: 0;
  left: 0;
}
</style>
<div class="modal bd-example-modal-lg" id="popupuserweb" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true" style="ope">
    <div class="modal-fullscreen" style="max-width:100%;margin:1.75rem auto" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Chỉnh Sửa & Quản Lý </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
            <div class="tab-content">
                            <div class="tab-pane tabs-animation fade active show" id="tab-content-0" role="tabpanel">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="main-card mb-3 card">
                                            <div class="card-body"><h5 class="card-title" id="card-title1">Thông Tin Tài Khoản</h5>
                                                <div id="infoUser">
                                                    Loading.....
</div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-6">
                                        <div class="main-card mb-3 card">
                                            <div class="card-body"><h5 class="card-title" id="card-title2">Quản Lý</h5>
                                            <div id="infoUserLogs">
                                                    Loading.....
</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            
                        </div>            </div>
        </div>
    </div>
</div>
<!--- Tạo Code --->

<!-- Modal -->
<div class="modal" id="taocodepopup" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Tạo Sự Kiện Code</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body" id="taocodepopupform">
                Loading...</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Tắt</button>
                <button type="button" class="btn btn-primary" onClick="saveInfo();">Tạo Event</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script>
function saveInfo() {
    if ($('#code_name').val() != "" || $('#code_count').val() != "" || $('#coder_timestart').val() != "" || $('#coder_timerend').val() != "") {
        $.post('ajax/ajax_giftcode.php', {
            name: $('#code_name').val(),
            count: $('#code_count').val(),
            timestart: $('#coder_timestart').val(),
            timeend: $('#coder_timerend').val()
        }, function(data) {
            if (data['code'] == 0) {
                toastr.success(data['text'], 'Thông Báo');
            } else {
                toastr.info(data['text'], 'Chú ý');
            }
        }, 'json');
    } else {
        toastr.info('Vui lòng nhập đầy đủ Yêu cầu để tạo Event.', 'Chú ý');
    }
}
</script>
