<?php
include("../dbConnect.php");

$result=mysqli_query($hookup, "SELECT * FROM Users");
$grid="";
$cnt=1;
//$row = mysqli_fetch_assoc($result);
while($row = mysqli_fetch_assoc($result)) {
    $id=$row['ID'];
    $formatted_date = date('m/d/Y', strtotime($row['last_login']));
        $grid.='<tr>';
        $grid.='<td>'.$row['cfirst_name'].' '.$row['cmiddle_name'].' '.$row['clast_name'].'</td>';
        $grid.="<td>".$row['user_name']."</td>";
        $grid.="<td>".$row['email']."</td>";
        $grid.="<td>".$formatted_date."</td>";
        $grid.="<td>".$row['daily_hits']."</td>";
        if($row['subscribed']==0){
            $grid.='<td><div class="checkbox checkbox-replace"><input type="checkbox" id="chk-'.$id.'"></div></td>';
        }else{
            $grid.='<td><div class="checkbox checkbox-replace"><input type="checkbox" id="chk-'.$id.'" checked></div></td>';
        }
        $grid.='<td class="btn btn-default btn-sm btn-icon icon-left" onclick="SaveRow('.$id.')"><a href="#" ><i class="entypo-pencil"></i>Save</a></td></tr>';
        $cnt++;
}

$result=mysqli_query($hookup, "SELECT * FROM Accounts");
$agrid="";
$cnt=1;
//$row = mysqli_fetch_assoc($result);
while($row = mysqli_fetch_assoc($result)) {
        $formatted_date = date('m/d/Y', strtotime($row['register_date']));
        $agrid.='<tr>';
        $agrid.='<td>'.$cnt.'</td>';
        $agrid.="<td>".$row['email']."</td>";
        $agrid.="<td>".$row['password']."</td>";
        $agrid.="<td>".$formatted_date."</td></tr>";
        $cnt++;
}



?>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">

	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta name="description" content="Neon Admin Panel" />
	<meta name="author" content="" />

	<title>World Numerology | User Tables</title>


	<link rel="stylesheet" href="assets/js/jquery-ui/css/no-theme/jquery-ui-1.10.3.custom.min.css">
	<link rel="stylesheet" href="assets/css/font-icons/entypo/css/entypo.css">
	<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic">
	<link rel="stylesheet" href="assets/css/bootstrap.css">
	<link rel="stylesheet" href="assets/css/neon-core.css">
	<link rel="stylesheet" href="assets/css/neon-theme.css">
	<link rel="stylesheet" href="assets/css/neon-forms.css">
	<link rel="stylesheet" href="assets/css/custom.css">
	<link rel="stylesheet" href="assets/css/skins/white.css">

	<script src="assets/js/jquery-1.11.0.min.js"></script>

	<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

	<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
		<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
		<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->


</head>
<body class="page-body skin-white" data-url="http://neon.dev">

<div class="page-container"><!-- add class "sidebar-collapsed" to close sidebar by default, "chat-visible" to make chat appear always -->

	<div class="sidebar-menu">


		<header class="logo-env">

			<!-- logo -->
			<div class="logo">
				<a href="index.php">
					<img src="assets/images/logo@2x.png" width="100" alt="" />
				</a>
			</div>

						<!-- logo collapse icon -->

			<div class="sidebar-collapse">
				<a href="#" class="sidebar-collapse-icon with-animation"><!-- add class "with-animation" if you want sidebar to have animation during expanding/collapsing transition -->
					<i class="entypo-menu"></i>
				</a>
			</div>



			<!-- open/close menu icon (do not remove if you want to enable menu on mobile devices) -->
			<div class="sidebar-mobile-menu visible-xs">
				<a href="#" class="with-animation"><!-- add class "with-animation" to support animation -->
					<i class="entypo-menu"></i>
				</a>
			</div>

		</header>






		<ul id="main-menu" class="">
			<!-- add class "multiple-expanded" to allow multiple submenus to open -->
			<!-- class "auto-inherit-active-class" will automatically add "active" class for parent elements who are marked already with class "active" -->
			<!-- Search Bar -->
			<!--<li id="search">
				<form method="get" action="">
					<input type="text" name="q" class="search-input" placeholder="Search something..."/>
					<button type="submit">
						<i class="entypo-search"></i>
					</button>
				</form>
			</li>-->
			<li>
				<a href="index.php">
					<i class="entypo-gauge"></i>
					<span>Dashboard</span>
				</a>
			</li>
			<li class="active opened active">
				<a href="users.php">
					<i class="entypo-users"></i>
					<span>Users</span>
				</a>

			</li>
			<li>
				<a href="admin_extras.php">
					<i class="entypo-users"></i>
					<span>Admin Extras</span>
				</a>

			</li>
			<li>
				<a href="blog_posts.php">
					<i class="entypo-users"></i>
					<span>Blog Posts</span>
				</a>
			</li>
			<li>
				<a href="admin_links.php">
					<i class="entypo-users"></i>
					<span>Admin Links</span>
				</a>
			</li>
		</ul>

	</div>
<div class="main-content">

<div class="row">

	<!-- Profile Info and Notifications -->
	<div class="col-md-6 col-sm-8 clearfix">

		<ul class="user-info pull-left pull-none-xsm">

						<!-- Profile Info -->
			<li class="profile-info dropdown"><!-- add class "pull-right" if you want to place this from right -->


					<img src="assets/images/thumb-1@2x.png" alt="" class="img-circle" width="44" />
					Hans Decoz
			</li>

		</ul>

	</div>

</div>

<hr />
			<ol class="breadcrumb bc-3">
						<li>
				<a href="index.php"><i class="entypo-home"></i>Home</a>
			</li>

				<li class="active">

							<strong>Users</strong>
					</li>
					</ol>

<h2>Accounts</h2>

<table class="table table-bordered table-striped datatable" id="table-3" style="color:#303030">
	<thead>
		<tr>
			<th>#</th>
			<th>Email</th>
			<th>Password</th>
			<th>Join Date</th>
		</tr>
	</thead>

	<tbody>
		<?php echo $agrid ?>
	</tbody>
</table>
<br />
<br />
<h2>Users</h2>

<table class="table table-bordered table-striped datatable" id="table-2" style="color:#303030">
	<thead>
		<tr>
			<th>Full Name</th>
			<th>User Name</th>
			<th>Email</th>
			<th>Last Login</th>
			<th>Daily Hits</th>
			<th>Subscribed</th>
			<th>Actions</th>
		</tr>
	</thead>

	<tbody>
		<?php echo $grid ?>
	</tbody>
</table>



<script type="text/javascript">
jQuery(window).load(function()
{
	var $ = jQuery;

	var table = $("#table-2").dataTable({
			"sPaginationType": "bootstrap",
			"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
			"bStateSave": true
		});

	$(".dataTables_wrapper select").select2({
		minimumResultsForSearch: -1
	});

	// Highlighted rows
	$("#table-2 tbody input[type=checkbox]").each(function(i, el)
	{
		var $this = $(el),
			$p = $this.closest('tr');

		$(el).on('change', function()
		{
			var is_checked = $this.is(':checked');

			$p[is_checked ? 'addClass' : 'removeClass']('highlight');
		});
	});

	var table2 = $("#table-3").dataTable({
			"sPaginationType": "bootstrap",
			"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
			"bStateSave": true
		});

	$(".dataTables_wrapper select").select2({
		minimumResultsForSearch: -1
	});


	// Replace Checboxes
	$(".pagination a").click(function(ev)
	{
		replaceCheckboxes();
	});
});

// Sample Function to add new row
var giCount = 1;

function fnClickAddRow()
{
	$('#table-2').dataTable().fnAddData(['<div class="checkbox checkbox-replace"><input type="checkbox" /></div>', giCount+".2", giCount+".3", giCount+".4", giCount+".5" ]);

	replaceCheckboxes(); // because there is checkbox, replace it

	giCount++;
}

function SaveRow(n)
{
    check = document.getElementById('chk-' + n).checked;
    if(check){
        sub=1;
    }else{
        sub=0;
    }
   // alert(n+" "+sub);
        var xmlhttp;

        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
         }


           xmlhttp.onreadystatechange=function()
          {
              //alert("Change "+xmlhttp.readyState);
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                   //  alert(xmlhttp.responseText);
                     if(xmlhttp.responseText=="success"){
                         alert("Save Successfull");
                     }else{
                         alert(xmlhttp.responseText);
                     }
                }
          }
          ui="updatesub";
          xmlhttp.open("POST","graphbuilder.php",true);
          xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          xmlhttp.send("id="+n+"&subscribed="+sub+"&ui="+ui);
}

</script>



<br />
<br />

<br /><!-- Footer --><footer class="main">
	&copy; 2014 <strong>World Numerology</strong>
</footer>	</div>



	<link rel="stylesheet" href="assets/js/datatables/responsive/css/datatables.responsive.css">
	<link rel="stylesheet" href="assets/js/select2/select2-bootstrap.css">
	<link rel="stylesheet" href="assets/js/select2/select2.css">

	<!-- Bottom Scripts -->
	<script src="assets/js/gsap/main-gsap.js"></script>
	<script src="assets/js/jquery-ui/js/jquery-ui-1.10.3.minimal.min.js"></script>
	<script src="assets/js/bootstrap.js"></script>
	<script src="assets/js/joinable.js"></script>
	<script src="assets/js/resizeable.js"></script>
	<script src="assets/js/neon-api.js"></script>
	<script src="assets/js/jquery.dataTables.min.js"></script>
	<script src="assets/js/datatables/TableTools.min.js"></script>
	<script src="assets/js/dataTables.bootstrap.js"></script>
	<script src="assets/js/datatables/jquery.dataTables.columnFilter.js"></script>
	<script src="assets/js/datatables/lodash.min.js"></script>
	<script src="assets/js/datatables/responsive/js/datatables.responsive.js"></script>
	<script src="assets/js/select2/select2.min.js"></script>
	<script src="assets/js/neon-chat.js"></script>
	<script src="assets/js/neon-custom.js"></script>
	<script src="assets/js/neon-demo.js"></script>

</body>
</html>