<?php
include_once 'includes/header.inc.php';
if(!$session->getRole() == 1 or !$session->getRole() == 2){
header("location: login.php");
}
$id = $database->escape($_GET['id']);
$query = $database->query("SELECT `cal_contacts`.*, DATE_FORMAT(`cal_contacts`.`birthday`, '%d-%m-%Y') as `date_trans` FROM `cal_contacts` WHERE `id` = '$id'");
while($row = mysql_fetch_assoc($query)){
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$email = $row['email'];
$phone_home = $row['phone_home'];
$phone_cell = $row['phone_cell'];
$address = $row['address'];
$zipcode = $row['zipcode'];
$city = $row['city'];
$birthday = $row['date_trans'];
}
?>
<legend>Detailed view</legend>
<div class="span6">
<table class="table table-striped">
<tr>
<th>Firstname</th>
<td><?php echo $firstname; ?></td>
</tr>
<tr>
<th>Lastname</th>
<td><?php echo $lastname; ?></td>
</tr>
<tr>
<th>E-Mail</th>
<td><?php echo $email; ?></td>
</tr>
<tr>
<th>Phone (home)</th>
<td><?php echo $phone_home; ?></td>
</tr>
<tr>
<th>Phone (cell)</th>
<td><?php echo $phone_cell; ?></td>
</tr>
<tr>
<th>Address</th>
<td><?php echo $address; ?></td>
</tr>
<tr>
<th>Zipcode</th>
<td><?php echo $zipcode; ?></td>
</tr>
<tr>
<th>City</th>
<td><?php echo $city; ?></td>
</tr>
<tr>
<th>Date of birth</th>
<td><?php echo $birthday; ?></td>
</tr>
</table>
<a href="<?php echo $url; ?>edit.php?id=<?php echo $id; ?>" class="btn">Edit</a>
<a href="<?php echo $url; ?>delete.php?id=<?php echo $id; ?>" class="btn">Delete</a>
</div>
<div class="span4">
<input type="text" id="address" value="<?php echo $address . ", " . $city; ?>" style="display: none;"/>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize(address) {
var geoCoder = new google.maps.Geocoder(address)
var request = {address:address};
geoCoder.geocode(request, function(result, status){
var latlng = new google.maps.LatLng(result[0].geometry.location.lat(), result[0].geometry.location.lng());
var myOptions = {
zoom: 17,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
var marker = new google.maps.Marker({position:latlng,map:map,title:'title'});
})
}
$(document).ready(function(){
var addr = $("#address").val();
initialize(addr);
})
</script>
<div id="map_canvas"></div>
</div>
<?php include_once 'includes/footer.inc.php'; ?>