	<?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">

	<!-- 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>

	<div class="container main">

	<p><h1>Change titles on charts &raquo;</h1></p>
	<!-- Forms
	================================================== -->
	<div class="bs-docs-section">
	<div class="row">
	<div class="col-lg-12">
	<div class="well bs-component">
	<form class="form-horizontal" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
	<fieldset>
	<?php

	if(isset($_POST['submit']))
	{ 
	$servername = "localhost";
	$dbuser = "root";
	$dbpass = "root";
	$dbname = "deadly_force";

	$shortcharttitle=trim($_POST['short_title']);
	$longercharttitle=trim($_POST['longer_chart_title']);
	$maptitle=trim($_POST['map_title']);
	$linecharttitle=trim($_POST['line_chart_title']);
	$linechartsubtitle=trim($_POST['line_chart_subtitle']);
	$modified_by=$loggedinuser;
	$entry_no='1';
	//exit();

	//check for empty values
	if (empty($shortcharttitle) ||   empty($longercharttitle) || empty($maptitle) || empty($linecharttitle) || empty($linechartsubtitle))
	{
	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>";
	}


	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 update using pdo
	$sthandler = $conn->prepare("update police_killings_chart_titles set short_chart_titles=:shortcharttitle,longer_chart_titles=:longercharttitle,map_title=:maptitle,line_chart_title=:linecharttitle,line_chart_subtitle=:linechartsubtitle,modified_by=:modified_by");
	$sthandler->bindParam(':shortcharttitle', $shortcharttitle);
	$sthandler->bindParam(':longercharttitle', $longercharttitle);
	$sthandler->bindParam(':maptitle', $maptitle);
	$sthandler->bindParam(':linecharttitle', $linecharttitle);
	$sthandler->bindParam(':linechartsubtitle', $linechartsubtitle);
	$sthandler->bindParam(':modified_by', $modified_by);
	$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>Chart titles updated!.</strong>";
	echo "</div>";
	echo "</div>";
	}
	catch(PDOException $e)
	{
	echo "error" . "<br>" . $e->getMessage();
	}
    $conn = null;
	}
	if(isset($_POST['cancel']))
	{ 
	header('Location:cpanel.php');
	}
	?>
	<?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_chart_titles");
	$sthandler->execute();
	$chartdetails = $sthandler->fetch();
	$shortcharttitle=$chartdetails[1];
	$longercharttitle=$chartdetails[2];
	$maptitle=$chartdetails[3];
	$linecharttitle=$chartdetails[4];
	$linechartsubtitle=$chartdetails[5];
	}
	catch(PDOException $e)
	{
	echo "error" . "<br>" . $e->getMessage();
	}
    $conn = null;
	
	?>
	<legend>Use the form below to update titles on the charts</legend>
	<div class="form-group">
	<label for="input" class="col-lg-12 control-label">Short title at the top charts:</label>
	<div class="col-lg-12">
	<input type="text" class="form-control" name="short_title" id="short_title" placeholder="" value="<?php echo $shortcharttitle;?>" required>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-12 control-label">Longer title at the middle search:</label>
	<div class="col-lg-12">
	<input type="text" class="form-control" id="longer_chart_title" name="longer_chart_title" placeholder="" value="<?php echo $longercharttitle;?>" required>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-12 control-label">Map title:</label>
	<div class="col-lg-12">
	<input type="text" class="form-control" id="map_title" name="map_title" placeholder="" value="<?php echo $maptitle;?>" required>
	</div>
	</div>
	<div class="form-group">
	<label for="input" class="col-lg-12 control-label">Line chart title:</label>
	<div class="col-lg-12">
	<input type="text" class="form-control" id="line_chart_title" name="line_chart_title" placeholder="" value="<?php echo $linecharttitle;?>" required>
	</div>
	</div>
	<div class="form-group">
	<label for="textarea" class="col-lg-12 control-label">Line chart subtitle:</label>
	<div class="col-lg-10">
	<textarea class="form-control" rows="3" id="line_chart_subtitle" name="line_chart_subtitle"><?php echo $linechartsubtitle;?></textarea>
	<span class="help-block">Give a line chart subtitle</span>
	</div>
	</div>
	
	<div class="form-group">
	<div class="col-lg-10 col-lg-offset">
	<button type="submit" name="submit" id="submit" class="btn btn-primary">Update</button>
	<button type="submit" name="cancel" id="cancel" class="btn btn-default">Cancel</button>
	<a class= "btn btn-warning" href="logout.php">Logout</a>
	</div>
	</div>
	</fieldset>
	</form>
	 	
	</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>
	
	</body>
	</html>
