<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
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>
<script src="js/jquery.min.js"></script>
<script src="js/captcha.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 class="active"><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>Have you heard/ witnessed of a police killing in your area (give your location)? </h1></p>

<!-- Forms
================================================== -->
<div class="bs-docs-section">
<div class="row">
<div class="col-lg-12">
<div class="well bs-component">
<form enctype='multipart/form-data' class="form-horizontal" method="post" action="">
<?php
//Upload File
if (isset($_POST['submit'])) {

ini_set("post_max_size", "20M");
ini_set("upload_max_filesize", "20M");
ini_set("memory_limit", "20000M");

//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']).'/useruploads';
$upload_url = '/';

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

$file_name=strtolower($file_name);

//add date to the filename
$file_name=date('d-m-Y').'_'.$file_name;

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

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

if(($_FILES["filename"]["type"] != "image/gif")
&& ($_FILES["filename"]["type"] != "image/jpeg")
&& ($_FILES["filename"]["type"] != "image/jpg")
&& ($_FILES["filename"]["type"] != "image/png")
&& ($_FILES["filename"]["type"] != "application/pdf")
&& ($_FILES["filename"]["type"] != "video/mp4")
&& ($_FILES["filename"]["type"] != "video/avi")
&& ($_FILES["filename"]["type"] != "video/3gp")
&& ($_FILES["filename"]["type"] != "video/mkv")
&& ($_FILES["filename"]["type"] != "video/wmv")
&& ($_FILES["filename"]["type"] != "video/flv")
&& ($_FILES["filename"]["type"] != "audio/mp3")
&& ($_FILES["filename"]["type"] != "audio/wma"))
{
echo "<div class=\"alert alert-danger\">Files must be either be images or videos!</div>";
exit;
}

if(($_FILES["filename"]["size"]/1024 > 20480))
{
echo "<div class=\"alert alert-danger\">File size must not exceeed 20MB!</div>";
exit;
}
//check if file exists
if (file_exists("useruploads/"  .$file_name))
{
echo "<div class=\"alert alert-danger\">File ".$_FILES["filename"]["name"] . " already exists on our database!. "."</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>";
}
//insert entries into the user uploads database
$servername = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "deadly_force";



$name=trim($_POST['victim_name']);
$incidentdate=trim($_POST['incident_date']);
$incidentcounty=trim($_POST['incident_county']);
$incidentdetails=trim($_POST['incident_details']);
$biodata=trim($_POST['biodata']);
$relevantlink=trim($_POST['relevant_link']);
$contacts=trim($_POST['contact_info']);
$link=trim($link);
$submitdate=trim(date("Y-m-d"));
//exit();

//check for empty values
if (empty($name) ||   empty($incidentdate) || empty($incidentcounty) || empty($contacts))
{
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>Please go back and fill all required 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);

//check if entry exists in the database
$sthandler = $conn->prepare("select * from police_killings_userfeedback where victim_name = :name and date_of_incident=:incidentdate and incident_county=:incidentcounty");
$sthandler->bindParam(':name', $name);
$sthandler->bindParam(':incidentdate', $incidentdate);
$sthandler->bindParam(':incidentcounty', $incidentcounty);
$sthandler->execute();

if($sthandler->rowCount() > 0){
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>Sorry, we already have that tip in the database!.</strong>";
echo "</div>";
echo "</div>";
exit();
}

//echo $name.$incidentdate.$incidentcounty.$incidentdetails.$biodata.$relevantlink.$contacts.$link;

//try to insert using pdo
$sthandler = $conn->prepare("insert into police_killings_userfeedback (victim_name,date_of_incident,incident_county,incident_summary,victim_biodata,relevant_links,contacts,attachments,date_of_submission) values (:name,:incidentdate,:incidentcounty,:incidentdetails,:biodata,:relevantlink,:contacts,:link,:submitdate)");
$sthandler->bindParam(':name', $name);
$sthandler->bindParam(':incidentdate', $incidentdate);
$sthandler->bindParam(':incidentcounty', $incidentcounty);
$sthandler->bindParam(':incidentdetails', $incidentdetails);
$sthandler->bindParam(':biodata', $biodata);
$sthandler->bindParam(':relevantlink', $relevantlink);
$sthandler->bindParam(':contacts', $contacts);
$sthandler->bindParam(':link', $link);
$sthandler->bindParam(':submitdate', $submitdate);
$sthandler->execute();
}
catch(PDOException $e)
{
echo "error" . "<br>" . $e->getMessage();
}
$conn = null;

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>Your tip has been submitted successfully. Thank you for your tip! We will get in touch.</strong>";
echo "</div>";
echo "</div>";
//view upload form
}
?>
<fieldset>
<div class="form-group">
<label for="textArea" class="col-lg-12 control-label">Name of victim*:</label>
<div class="col-lg-12">
<input type="text" class="form-control" name="victim_name" id="victim_name" placeholder="" required>
</div>
</div>
<div class="form-group">
<label for="input" class="col-lg-12 control-label">Date of incident*:</label>
<div class="col-lg-12">
<input class="form-control" id="incident_date" name="incident_date" type="text" required>
</div>
</div>
<div class="form-group">
<label for="select" class="col-lg-12 control-label">County where the incident happened*:</label>
<div class="col-lg-12">
<select class="form-control" id="incident_county" name="incident_county" >
<option>Baringo</option>
<option>Bomet</option>
<option>Bungoma</option>
<option>Busia</option>
<option>Elgeiyo Marakwet</option>
<option>Embu</option>
<option>Garissa</option>
<option>Homa Bay</option>
<option>lsiolo</option>
<option>Kajiado</option>
<option>Kakamega</option>
<option>Kericho</option>
<option>Kiambu</option>
<option>Kilifi</option>
<option>Kirinyaga</option>
<option>Kisii</option>
<option>Kisumu</option>
<option>Kitui</option>
<option>Kwale</option>
<option>Laikipia</option>
<option>Lamu</option>
<option>Machakos</option>
<option>Makueni</option>
<option>Mandera</option>
<option>Marsabit</option>
<option>Meru</option>
<option>Migori</option>
<option>Mombasa</option>
<option>Murang'a</option>
<option>Nairobi </option>
<option>Nakuru</option>
<option>Nandi</option>
<option>Narok</option>
<option>Nyamira</option>
<option>Nyandarua</option>
<option>Nyeri</option>
<option>Samburu</option>
<option>Siaya</option>
<option>Taita Taveta</option>
<option>Tana River</option>
<option>Tharaka Nithi</option>
<option>Trans Nzoia</option>
<option>Turkana</option>
<option>Uasin Gishu</option>
<option>Vihiga</option>
<option>Wajir</option>
<option>West Pokot</option>
</select>
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-12 control-label">Please share as many details of what happened  as you know including where and when & how the incident occurred:</label>
<div class="col-lg-12">
<textarea class="form-control" rows="6" name="incident_details" id="incident_details" ></textarea>
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-12 control-label">Please share as much information as possible about the person killed (e.g age, gender, occupation):</label>
<div class="col-lg-12">
<input type="text" class="form-control" name="biodata" id="biodata" placeholder="" >
</div>
</div>
<div class="form-group">
<label for="input" class="col-lg-12 control-label">Please submit a link to relevant news reports / social media postings (optional):</label>
<div class="col-lg-12">
<input type="text" class="form-control" name="relevant_link" id="relevant_link" placeholder="">
</div>
</div>
<div class="form-group">
<label for="input" class="col-lg-12 control-label">Please share your contact information for follow-up (email or phone) *: </label>
<div class="col-lg-12">
<input type="text" class="form-control" name="contact_info" id="contact_info" placeholder="" required>
</div>
</div>
<div class="form-group">
<label for="input" class="col-lg-12 control-label">Attachment (photos, videos, etc.): <i>*Upto 20MB of photos or video allowed.</i>  </label>
<div class="col-lg-12">

<?php
print "<input size='50' type='file' name='filename' required>&nbsp;&nbsp;&nbsp;";

?>

</div>
</div>

<div class="form-group">
<div class="col-lg-12">
<!--captcha-->
<span style="color:#000">What is <span id="no1"></span> plus <span id="no2"></span>?</span>
<input type="text" class="form-control" name="answer" id="answer"   placeholder="Please answer the question to prove you are human" placeholder="your answer" required data-validation-required-message="Please answer to prove that you are human!">
<p class="help-block text-danger"></p>
<span id="status" style="display:none">Unsubmitted</span>
<script>placenumber();</script>
<!--end captcha-->
</div>
</div>
<div class="row">
<div class="col-lg-12">
<p>
<i>*We may contact you for additional details, but we will not share your contact information without your permission. Your tips may be used for stories that appear on the Nation Media Group's websites and newspapers.</i>
</p>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset">
<input type='submit' name='submit' value='Submit' class='btn btn-primary'>
<a class="btn btn-default" href="index.php">Cancel</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/jqBootstrapValidation.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/captcha.js"></script>
<script src="js/zebra_datepicker.js"></script>
<script>
$('#incident_date').Zebra_DatePicker();
</script>
<script src="js/bootstrap.file-input.js"></script>
<script>
$('input[type=file]').bootstrapFileInput();
$('.file-inputs').bootstrapFileInput();
</script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
