	<?php session_start();
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);
	$_SESSION['loggedinuser'];
	$loggedinuser=$_SESSION['loggedinuser'];
	//check if the user is logged in
	if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
	} else {
	header('Location: index.php');
	}
	date_default_timezone_set("Africa/Nairobi");
	?>
	<!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">
	<meta name="description" content="">
	<meta name="author" content="">
	<link rel="icon" href="../images/favicon.png">

	<title>Deadly Force::People killed by the police in Kenya</title>
	<!-- Bootstrap core CSS -->
	<link href="css/bootstrap.css" rel="stylesheet">
	<link href="css/zebra_datepicker_metallic.css" rel="stylesheet">
	<!-- Bootstrap theme -->
	<link href="css/bootswatch_min.css" rel="stylesheet">

	</head>

	<body role="document">
	<!-- Fixed navbar -->
	<div class="navbar navbar-default navbar-fixed-top" role="navigation">
	<div class="container">
	<div class="navbar-header">
	<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
	<span class="sr-only">Toggle navigation</span>
	<span class="icon-bar"></span>
	<span class="icon-bar"></span>
	<span class="icon-bar"></span>
	</button>
	<a class="navbar-brand" href="index.php">
	<img src="../images/newsplex_logo.png" width="145" height="70" alt="nation newsplex"/>
	<div class="header-slogan">
	<span class="big-slogan">Deadly force</span><br>
	<span class="slogan">People killed by the police in Kenya</span>
	</div>
	</a>
	</div>
	<div class="navbar-collapse collapse">
	<ul class="nav navbar-nav">
	<li><a href="../tip.php">Submit tip</a></li>
	<li><a href="../index.php#database">Database</a></li>
	<li><a href="../about.php">About</a></li>
	<li><a href="../articles.php">Read articles</a></li>
	</ul>
	</li>
	</ul>
	</div><!--/.nav-collapse -->
	</div>
	</div>
	<div class="container main">

	<!-- Containers
	================================================== -->
	<div class="bs-docs-section">

	<div class="row">
	<div class="col-lg-12">
	<p><h1>Import police killing victims data &raquo;</h1></p>
	<div class="bs-component">
	<div class="jumbotron">
	<div id="form">


	<?php

	//Upload File
	if (isset($_POST['submit'])) {
	
	//upload the file to tmp directory for conversion
	$main_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
	$upload_dir = $_SERVER['DOCUMENT_ROOT'] .  dirname($_SERVER['PHP_SELF']).'/tmp';
	$upload_url = '/';

	$temp_name = $_FILES['filename']['tmp_name'];
	$file_name = $_FILES['filename']['name'];

	$file_name=strtolower($file_name);

	$file_name = preg_replace('/\s+/', '_', $file_name);	

	$file_path = $upload_dir.$upload_url.$file_name;
	$mydir = '/'.'tmp/'.$file_name;
	//echo $mydir."</br>";
	$link=$main_dir.$mydir;

	if(($_FILES["filename"]["type"] != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
	&& ($_FILES["filename"]["type"] != "application/vnd.ms-excel"))
	{
	echo "<div class=\"alert alert-danger\">Files must be either be in Excel format!</div>";
	exit;
	}

	if(($_FILES["filename"]["size"]/1024 > 8000))
	{
	echo "<div class=\"alert alert-danger\">File size must not exceeed 7MB!</div>";
	exit;
	}

	if(move_uploaded_file($temp_name, $file_path))
	{
	echo "<div class=\"alert alert-success\">File upload successful !</div>"."<br>";
	echo "Link: "."<a href=\"#\" onclick=\"document.getElementById('txtpath').value='$link';\">$link</a>"."<br/>";
	echo "File: " . $file_name . "<br>";
	echo "Type: " . $_FILES["filename"]["type"] . "<br>";
	echo "Size: " . ($_FILES["filename"]["size"] / 1024) . " kB<br>";
    }
	//end of file upload

	if (is_uploaded_file($link)) {
	echo "<h1>" . "File: ". $link ." uploaded successfully." . "</h1>";
	}
    echo "<div class=\"bs-component\">";
	echo "<div class=\"alert alert-dismissable alert-success\">";
	echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>";
	echo "<strong>Victim details successfully added!.</strong>";
	echo "</div>";
	echo "</div>";
	//fclose($handle);
	//delete the temporary file
	//$filetodelete='tmp/'.$file_name;
	//unlink($filetodelete);
	//unlink($fileoutput);
	//print "Import done";

	//view upload form
	}else {

	print "<h3>Upload victims data excel sheet by browsing to file and clicking on Upload</h3><br />\n";

	print "<form enctype='multipart/form-data' action='' method='post'>";
	
	?>
    
	<?php
	print "<input size='50' type='file' name='filename' required>&nbsp;&nbsp;&nbsp;";

	print "<input type='submit' name='submit' value='Upload' class='btn btn-primary'>";
	
	
	
	
	print "</form>";

	}

	?>
	</div>
	</div>

	</div>
	</div>
	</div> 
	</div> <!-- /container -->

	<!-- Bootstrap core JavaScript
	================================================== -->
	<!-- Placed at the end of the document so the pages load faster -->
	<script src="js/jquery.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/bootstrapValidator.js"></script>
	<script src="js/bootswatch.js"></script>
	<script src="js/docs.min.js"></script>
	<script src="js/zebra_datepicker.js"></script>
	<script>
	$('#incident_date').Zebra_DatePicker();
	</script>
	<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
	<script src="js/ie10-viewport-bug-workaround.js"></script>
	<!--file input-->
	<script src="js/bootstrap.file-input.js"></script>
	<script>
	$('input[type=file]').bootstrapFileInput();
	$('.file-inputs').bootstrapFileInput();
	</script>
	</body>
	</html>