<?php
include('../includes/functions.php');
session_start();
make_connection();
if(is_loggedin());
else
	redirect_to('index.php');
$user=get_user();
if(!$user)
	redirect_to('index.php');
$user_id=$user['regno'];
if($user_id!='15BCE0329')
	redirect_to('index.php');
$user_male_percent=user_male_percent();
$user_female_percent=user_female_percent();
$no_books_borrowed=no_books_borrowed();
$no_books_sold=no_books_sold();
$overdue_percent=overdue_percent();
$timely_return_percent=timely_return_percent();
$money_received_by_male_user=money_received_by_male_user();
$money_received_by_female_user=money_received_by_female_user();
$max_books=max_books();
$max_requests=max_requests();
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<?php include('../includes/head.php');?>
	<title>Utopia- Transactions</title>
	<link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.min.css">
	<link rel="stylesheet" type="text/css" href="materialize/css/materialize.css">
	<link rel="stylesheet" type="text/css" href="css/home.css">
	<style type="text/css">
		.color-red{
			color: red;
		}
		#createnew{
			cursor: pointer;
		}
	</style>
</head>
<body>
	<div class="body container">
		<h1 class="center">Data Analysis</h1>
		<ol>
			<li>
				<h6>Male % of users are: <b><?php echo $user_male_percent;?>%</b></h6>
				<h6>Female % of users are: <b><?php echo $user_female_percent;?>%</b></h6>
			</li>
			<li>
				<h6>Percentage of books borrowed are: <b><?php echo $no_books_borrowed;?>%</b></h6>
				<h6>Percentage of books sold are: <b><?php echo $no_books_sold;?>%</b></h6>
			</li>
			<li>
				<h6>Percentage of books which were returned after the due date: <b><?php echo $overdue_percent;?>%</b></h6>
				<h6>Percentage of books which were returned on or before the due date: <b><?php echo $timely_return_percent;?>%</b></h6>
			</li>
			<li>
				<h6>Money received by male users on the expected prices of books: <b><?php echo $money_received_by_male_user;?>%</b></h6>
				<h6>Money received by female users on the expected prices of books: <b><?php echo $money_received_by_female_user;?>%</b></h6>
			</li>
			<li>
				<h6>User Who has uploaded maximum no. of books is 
					<?php
					while($row=mysqli_fetch_assoc($max_books))
					{
						echo "<b>".$row['uname']."</b> with <b>".$row['count_rid']."</b>";
						break;
					}
					?>
					books
				</h6>
			</li>
			<li>
				<h6>User Who has send maximum no of requests is
					<?php
					while($row=mysqli_fetch_assoc($max_requests))
					{
						echo "<b>".$row['uname']."</b> with <b>".$row['count_rid']."</b>";
						break;
					}
					?>
					books
				</h6>
			</li>
		</ol>
	</div>
	<script src="js/jquery.js"></script>
	<script src="materialize/js/materialize.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			Materialize.updateTextFields();
		});
	</script>
</body>
</html>