	<?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 where entry_no = :entryno");
	$sthandler->bindParam(':entryno', $entryno);
	$sthandler->execute();
	$victimdetails = $sthandler->fetch();
	$victimentryno=$victimdetails[0];
	$victimnames=$victimdetails[1];
	$victimgender=$victimdetails[2];
	$victimage=$victimdetails[3];
	$victimoccupation=$victimdetails[4];
	$victimdate=$victimdetails[5];
	$victimcounty=$victimdetails[6];
	$victimofficer=$victimdetails[7];
	$victimarmed=$victimdetails[8];
	$victimweapon=$victimdetails[9];
	$victimentry=$victimdetails[10];
	$victimstatus=$victimdetails[11];
	$victimsummary=$victimdetails[12];
	$victimsource=$victimdetails[13];
	$keywords=$victimdetails[14];
	
	}
	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>Edit victim 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";
	$entryno=trim($_POST['entryno']);
	$names=trim($_POST['victim_names']);
	$gender=trim($_POST['gender']);
	$age=trim($_POST['victim_age']);
	$occupation=trim($_POST['victim_occupation']);
	$incident_date=trim($_POST['incident_date']);
	$incident_town=trim($_POST['incident_town']);
	$officer_involved=trim($_POST['officer_involved']);
	$victim_armed=trim($_POST['victim_armed']);
	$police_weapon=trim($_POST['police_weapon']);
	$occurence_book=trim($_POST['occurence_book']);
	$case_status=trim($_POST['case_status']);
	$summary=trim($_POST['summary']);
	$source=trim($_POST['source']);
	$keywords=trim($_POST['keywords']);
	$savedate=trim(date("Y-m-d H:i:s"));
	$date_modified=trim(date("Y-m-d H:i:s"));
	$modified_by=$loggedinuser;
	//exit();

	//check for empty values
	if (empty($names) ||   empty($gender) ||empty($summary))
	{
	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 set victim_names=:names,victim_gender=:gender,victim_age=:age,victim_occupation=:occupation,date_of_incident=:incident_date,incident_county_or_town=:incident_town,officer_involved=:officer_involved,victim_armed_unarmed=:victim_armed,police_weapon=:police_weapon,entry_in_occurence_book=:occurence_book,status_of_case=:case_status,incident_summary=:summary,source=:source,keywords=:keywords,date_modified=:date_modified,modified_by=:modified_by where entry_no=:entryno");
	$sthandler->bindParam(':entryno', $entryno);
	$sthandler->bindParam(':names', $names);
	$sthandler->bindParam(':gender', $gender);
	$sthandler->bindParam(':age', $age);
	$sthandler->bindParam(':occupation', $occupation);
	$sthandler->bindParam(':incident_date', $incident_date);
	$sthandler->bindParam(':incident_town', $incident_town);
	$sthandler->bindParam(':officer_involved', $officer_involved);
	$sthandler->bindParam(':victim_armed', $victim_armed);
	$sthandler->bindParam(':police_weapon', $police_weapon);
	$sthandler->bindParam(':occurence_book', $occurence_book);
	$sthandler->bindParam(':case_status', $case_status);
	$sthandler->bindParam(':summary', $summary);
	$sthandler->bindParam(':source', $source);
	$sthandler->bindParam(':keywords', $keywords);
	$sthandler->bindParam(':date_modified', $date_modified);
	$sthandler->bindParam(':modified_by', $modified_by);
	$sthandler->execute();
	
	//insert into activity log table
	//try to insert using pdo
	$sthandler = $conn->prepare("insert into police_killings_user_activity (users_name,edit_date,record_edited) values (:users_name,:edit_date,:record_edited)");
	$sthandler->bindParam(':users_name', $modified_by);
	$sthandler->bindParam(':edit_date', $date_modified);
	$sthandler->bindParam(':record_edited', $names);
	$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>Victim 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="entryno" name="entryno" value="<?php echo $victimentryno;?>">
	<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_names" name="victim_names" value="<?php echo $victimnames;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="gender" class="col-lg-2 control-label">Gender:</label>
	<div class="col-lg-10">
	<select class="form-control" id="gender" name="gender">
	<option value="M" <?php if($victimgender=="M") echo 'selected="selected"'; ?>>M</option>
	<option value="F" <?php if($victimgender=="F") echo 'selected="selected"'; ?>>F</option>
	</select>
	</div>
	</div>

	<div class="form-group">
	<label for="victim_age" class="col-lg-2 control-label">Age:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="victim_age" name="victim_age" value="<?php echo $victimage;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="victimoccupation" class="col-lg-2 control-label">Occupation:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="victim_occupation" name="victim_occupation" value="<?php echo $victimoccupation;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Date of incident:</label>
	<div class="col-lg-10">
	<input class="form-control" id="incident_date" name="incident_date" type="text" value="<?php echo $victimdate;?>">
	</div>
	</div>
     <div class="form-group">
	<label for="select" class="col-lg-2 control-label">County where the incident happened:</label>
	<div class="col-lg-10">
	<select class="form-control" id="incident_town" name="incident_town" required>
	<option value="Baringo" <?php if($victimcounty=="Baringo") echo 'selected="selected"'; ?>>Baringo</option>
	<option value="Bomet" <?php if($victimcounty=="Bomet") echo 'selected="selected"'; ?>>Bomet</option>
	<option value="Bungoma" <?php if($victimcounty=="Bungoma") echo 'selected="selected"'; ?>>Bungoma</option>
	<option value="Busia" <?php if($victimcounty=="Busia") echo 'selected="selected"'; ?>>Busia</option>
	<option value="Elgeiyo Marakwet" <?php if($victimcounty=="Elgeiyo Marakwet") echo 'selected="selected"'; ?>>Elgeiyo Marakwet</option>
	<option value="Embu" <?php if($victimcounty=="Embu") echo 'selected="selected"'; ?>>Embu</option>
	<option value="Garissa" <?php if($victimcounty=="Garissa") echo 'selected="selected"'; ?>>Garissa</option>
	<option value="Homa Bay" <?php if($victimcounty=="Homa Bay") echo 'selected="selected"'; ?>>Homa Bay</option>
	<option value="lsiolo" <?php if($victimcounty=="Isiolo") echo 'selected="selected"'; ?>>lsiolo</option>
	<option value="Kajiado" <?php if($victimcounty=="Kajiado") echo 'selected="selected"'; ?>>Kajiado</option>
	<option value="Kakamega" <?php if($victimcounty=="Kakamega") echo 'selected="selected"'; ?>>Kakamega</option>
	<option value="Kericho" <?php if($victimcounty=="Kericho") echo 'selected="selected"'; ?>>Kericho</option>
	<option value="Kiambu" <?php if($victimcounty=="Kiambu") echo 'selected="selected"'; ?>>Kiambu</option>
	<option value="Kilifi" <?php if($victimcounty=="Kilifi") echo 'selected="selected"'; ?>>Kilifi</option>
	<option value="Kirinyaga" <?php if($victimcounty=="Kirinyaga") echo 'selected="selected"'; ?>>Kirinyaga</option>
	<option value="Kisii" <?php if($victimcounty=="Kisii") echo 'selected="selected"'; ?>>Kisii</option>
	<option value="Kisumu" <?php if($victimcounty=="Kisumu") echo 'selected="selected"'; ?>>Kisumu</option>
	<option value="Kitui" <?php if($victimcounty=="Kitui") echo 'selected="selected"'; ?>>Kitui</option>
	<option value="Kwale" <?php if($victimcounty=="Kwale") echo 'selected="selected"'; ?>>Kwale</option>
	<option value="Laikipia" <?php if($victimcounty=="Laikipia") echo 'selected="selected"'; ?>>Laikipia</option>
	<option value="Lamu" <?php if($victimcounty=="Lamu") echo 'selected="selected"'; ?>>Lamu</option>
	<option value="Machakos" <?php if($victimcounty=="Machakos") echo 'selected="selected"'; ?>>Machakos</option>
	<option value="Makueni" <?php if($victimcounty=="Makueni") echo 'selected="selected"'; ?>>Makueni</option>
	<option value="Mandera" <?php if($victimcounty=="Mandera") echo 'selected="selected"'; ?>>Mandera</option>
	<option value="Marsabit" <?php if($victimcounty=="Marsabit") echo 'selected="selected"'; ?>>Marsabit</option>
	<option value="Meru" <?php if($victimcounty=="Meru") echo 'selected="selected"'; ?>>Meru</option>
	<option value="Migori" <?php if($victimcounty=="Migori") echo 'selected="selected"'; ?>>Migori</option>
	<option value="Mombasa" <?php if($victimcounty=="Mombasa") echo 'selected="selected"'; ?>>Mombasa</option>
	<option value="Murang'a" <?php if($victimcounty=="Murang'a") echo 'selected="selected"'; ?>>Murang'a</option>
	<option value="Nairobi" <?php if($victimcounty=="Nairobi") echo 'selected="selected"'; ?>>Nairobi </option>
	<option value="Nakuru" <?php if($victimcounty=="Nakuru") echo 'selected="selected"'; ?>>Nakuru</option>
	<option value="Nandi" <?php if($victimcounty=="Nandi") echo 'selected="selected"'; ?>>Nandi</option>
	<option value="Narok" <?php if($victimcounty=="Narok") echo 'selected="selected"'; ?>>Narok</option>
	<option value="Nyamira" <?php if($victimcounty=="Nyamira") echo 'selected="selected"'; ?>>Nyamira</option>
	<option value="Nyandarua" <?php if($victimcounty=="Nyandarua") echo 'selected="selected"'; ?>>Nyandarua</option>
	<option value="Nyeri" <?php if($victimcounty=="Nyeri") echo 'selected="selected"'; ?>>Nyeri</option>
	<option value="Samburu" <?php if($victimcounty=="Samburu") echo 'selected="selected"'; ?>>Samburu</option>
	<option value="Siaya" <?php if($victimcounty=="Siaya") echo 'selected="selected"'; ?>>Siaya</option>
	<option value="Taita Taveta" <?php if($victimcounty=="Taita Taveta") echo 'selected="selected"'; ?>>Taita Taveta</option>
	<option value="Tana River" <?php if($victimcounty=="Tana River") echo 'selected="selected"'; ?>>Tana River</option>
	<option value="Tharaka Nithi" <?php if($victimcounty=="Tharaka Nithi") echo 'selected="selected"'; ?>>Tharaka Nithi</option>
	<option value="Trans Nzoia" <?php if($victimcounty=="Trans Nzoia") echo 'selected="selected"'; ?>>Trans Nzoia</option>
	<option value="Turkana" <?php if($victimcounty=="Turkana") echo 'selected="selected"'; ?>>Turkana</option>
	<option value="Uasin Gishu" <?php if($victimcounty=="Uasin Gishu") echo 'selected="selected"'; ?>>Uasin Gishu</option>
	<option value="Vihiga" <?php if($victimcounty=="Vihiga") echo 'selected="selected"'; ?>>Vihiga</option>
	<option value="Wajir" <?php if($victimcounty=="Wajir") echo 'selected="selected"'; ?>>Wajir</option>
	<option value="West Pokot" <?php if($victimcounty=="West Pokot") echo 'selected="selected"'; ?>>West Pokot</option>
	</select>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Officer(s) identified:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="officer_involved" name="officer_involved" value="<?php echo $victimofficer;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Victim armed or unarmed:</label>
	<div class="col-lg-10">
	<select class="form-control" id="victim_armed" name="victim_armed" required>
	<option value="Armed" <?php if($victimarmed=="Armed") echo 'selected="selected"'; ?>>Armed</option>
	<option value="Unarmed" <?php if($victimarmed=="Unarmed") echo 'selected="selected"'; ?>>Unarmed</option>
	<option value="Not known" <?php if($victimarmed=="Not known") echo 'selected="selected"'; ?>>Not known</option>
	</select>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Police weapon:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="police_weapon" name="police_weapon" value="<?php echo $victimweapon;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Entry in police occurence book:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="occurence_book" name="occurence_book" value="<?php echo $victimentry;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Status of case:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="case_status" name="case_status" value="<?php echo $victimstatus;?>">
	</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="3" id="summary" name="summary"><?php echo $victimsummary;?></textarea>
	<span class="help-block">Give a summary of the incident</span>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Keywords:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="keywords" name="keywords" value="<?php echo $keywords;?>">
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-2 control-label">Source:</label>
	<div class="col-lg-10">
	<input type="text" class="form-control" id="source" name="source" value="<?php echo $victimsource;?>">
	</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="viewvictimsdetails.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>
