	<?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");
	//get entry number
	$entryno=$_GET['entryno'];
	?>
	<!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">
	<!-- Bootstrap theme -->
	<link href="../css/bootswatch_min.css" rel="stylesheet">
	
	<link href="../css/zebra_datepicker_metallic.css" rel="stylesheet">

	<!-- Custom styles for this template -->
	<link href="../theme.css" rel="stylesheet">

	<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
	<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
	<script src="../../assets/js/ie-emulation-modes-warning.js"></script>

	<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
	<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
	<![endif]-->
	
	</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>
    <?php
	$servername = "localhost";
	$dbuser = "root";
	$dbpass = "root";
	$dbname = "deadly_force";
	
	try {
	$conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbuser, $dbpass,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
	// set the PDO error mode to exception
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	//load victim details from the database
	$sthandler = $conn->prepare("select * from police_killings_userfeedback where entry_no = :entryno");
	$sthandler->bindParam(':entryno', $entryno);
	$sthandler->execute();
	$feedbackdetails = $sthandler->fetch();
	$feedbackentryno=$feedbackdetails[0];
	$victimname=$feedbackdetails[1];
	$incidentdate=$feedbackdetails[2];
	$incidentcounty=$feedbackdetails[3];
	$incidentsummary=$feedbackdetails[4];
	$biodata=$feedbackdetails[5];
	$relevantlinks=$feedbackdetails[6];
	$contacts=$feedbackdetails[7];
	$attachments=$feedbackdetails[8];
	$submissiondate=$feedbackdetails[9];
	$checked=$feedbackdetails[10];
	
	}
	catch(PDOException $e)
	{
	echo "error" . "<br>" . $e->getMessage();
	}
    $conn = null;
	
	?>
	<div class="container main">
	<!-- Forms
	================================================== -->
	<div class="bs-docs-section">
	<div class="row">
	<div class="col-lg-12">
	<h1>View user feedback details</h1>
	</div>
	</div>
	<div class="row">
	<div class="col-lg-12">
	<div class="well bs-component">
	<form class="form-horizontal" method="post" action="">
	<fieldset>
	<?php

	if(isset($_POST['submit']))
	{ 
	$servername = "localhost";
	$dbuser = "root";
	$dbpass = "root";
	$dbname = "deadly_force";
	$feedbackentryno=trim($_POST['entry_no']);
	$victimname=trim($_POST['victim_name']);
	$incidentdate=trim($_POST['incident_date']);
	$incidentcounty=trim($_POST['incident_county']);
	$incidentsummary=trim($_POST['incident_summary']);
	$biodata=trim($_POST['biodata']);
	$relevantlinks=trim($_POST['relevant_links']);
	$contacts=trim($_POST['contacts']);
	$attachments=trim($_POST['attachments']);
	$submissiondate=trim($_POST['submission_date']);
	$checked=trim($_POST['checked']);
	//exit();

	//check for empty values
	if (empty($victimname) ||   empty($incidentdate) || empty($incidentcounty)  || empty($incidentsummary)  || empty($biodata)  || empty($relevantlinks)  || empty($contacts)  || empty($attachments)  || empty($submissiondate) || empty($checked))
	{
	echo "<div class=\"bs-component\">";
	echo "<div class=\"alert alert-dismissable alert-warning\">";
	echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>";
	echo "<strong>Go back and fill all empty fields!.</strong>";
	echo "</div>";
	echo "</div>";
	exit();
	}


	try {
	$conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbuser, $dbpass);
	// set the PDO error mode to exception
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    //try to insert using pdo
	$sthandler = $conn->prepare("update police_killings_userfeedback set victim_name=:victimname,date_of_incident=:incidentdate,incident_county=:incidentcounty,incident_summary=:incidentsummary,victim_biodata=:biodata,relevant_links=:relevantlinks,contacts=:contacts,attachments=:attachments,date_of_submission=:submissiondate,checked=:checked where entry_no=:entryno");
	$sthandler->bindParam(':entryno', $entryno);
	$sthandler->bindParam(':victimname', $victimname);
	$sthandler->bindParam(':incidentdate', $incidentdate);
	$sthandler->bindParam(':incidentcounty', $incidentcounty);
	$sthandler->bindParam(':incidentsummary', $incidentsummary);
	$sthandler->bindParam(':biodata', $biodata);
	$sthandler->bindParam(':relevantlinks', $relevantlinks);
	$sthandler->bindParam(':contacts', $contacts);
	$sthandler->bindParam(':attachments', $attachments);
	$sthandler->bindParam(':submissiondate', $submissiondate);
	$sthandler->bindParam(':checked', $checked);
	$sthandler->execute();
	
	
	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>Feedback details updated successfully!.</strong>";
	echo "</div>";
	echo "</div>";
	}
	catch(PDOException $e)
	{
	echo "error" . "<br>" . $e->getMessage();
	}
    $conn = null;
	}
	if(isset($_POST['cancel']))
	{ 
	header('Location:../index.php');
	}
	?>
	<legend>View/edit the details below and update</legend>
	<input type="hidden" class="form-control" id="entry_no" name="entry_no" value="<?php echo $feedbackentryno;?>">
	<div class="form-group">
	<label for="inputnames" class="col-lg-2 control-label">Victim name:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="victim_name" name="victim_name" value="<?php echo $victimname;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="victim_age" class="col-lg-2 control-label">Incident date:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="incident_date" name="incident_date" value="<?php echo $incidentdate;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="victimoccupation" class="col-lg-2 control-label">County:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="incident_county" name="incident_county" value="<?php echo $incidentcounty;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="textArea" class="col-lg-2 control-label">Incident summary:</label>
	<div class="col-lg-10">
	<textarea class="form-control" rows="6" id="incident_summary" name="incident_summary" readonly><?php echo $incidentsummary;?></textarea>
	<span class="help-block">Summary of the incident</span>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Biodata:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="biodata" name="biodata" value="<?php echo $biodata;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Relevant links:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="relevant_links" name="relevant_links" value="<?php echo $relevantlinks;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Contacts:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="contacts" name="contacts" value="<?php echo $contacts;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Attachments:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="attachments" name="attachments" value="<?php echo $attachments;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Date of submission:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="submission_date" name="submission_date" value="<?php echo $submissiondate;?>" readonly>
	</div>
	</div>
	<div class="form-group">
	<label for="gender" class="col-lg-2 control-label">Checked:</label>
	<div class="col-lg-10">
	<select class="form-control" id="checked" name="checked">
	<option value="No" <?php if($checked=="No") echo 'selected="selected"'; ?>>No</option>
	<option value="Yes" <?php if($checked=="Yes") echo 'selected="selected"'; ?>>Yes</option>
	</select>
	</div>
	</div>
	<div class="form-group">
	<div class="col-lg-10 col-lg-offset-2">
	<button type="submit" name="submit" id="submit" class="btn btn-primary">Update</button>
	<a class= "btn btn-default" href="viewuserfeedback.php">Cancel</a>
	<a class= "btn btn-warning" href="logout.php">Logout</a>

	</div>
	</div>
	</fieldset>
	</form>
	</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/bootswatch.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>
	</body>
	</html>
