<script language="javascript">
$(document).ready( function() {
	$("#btnalertdel").click(function(){
		var id = $('#delid').val();
		var mod = 'contact';
		var act =  'delete';
		var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
		$.ajax({
			type: "POST",
			url: "po-component/po-contact/proses.php",
			data: dataString,
			cache: false,
			success: function(){
				$('#del'+id).slideUp('slow', function() {$(this).remove();});
				$('#alertdel').modal('hide');
			}
		});
		return false;
	});
});
</script>

<?php
//Author  	= 'Jenuar Dwi Putra Dalapang';
//Contact 	= 'mailto:djenuar@gmail.com';

session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{

$aksi="po-component/po-contact/proses.php";
switch($_GET[act]){
	default:
?>
<script language="javascript">
$(document).ready( function() {
var oTable = $('#tableboot').dataTable();
	oTable.$(".alertdel").click(function(){
		var id = $(this).attr("id");
		$('#alertdel').modal('show');
		$('#delid').val(id);
	});
});
</script>

<script type="text/javascript">
$(document).ready(function () {
var oTable = $('#tableboot').dataTable();
    oTable.$('.view').click(function(){
        var idisi = $(this).attr('id');
		$('#message'+idisi).modal('show');
    });
});
</script>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-phone'></span>
		</div>
		<h1>Contact Management<small><span class='text-info'>View and delete contact management</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablecontact = new PoTable('contact');
				$contacts = $tablecontact->findAll(id_contact, DESC);
				echo "<div class='data-fluid'>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>Sender Name</th>
							<th>Email</th>
							<th>Subjek</th>
							<th>Action</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($contacts as $contact){
						echo "<tr class='gradeA' id='del$contact->id_contact'>
							<td>$no</td>
							<td>$contact->name_contact</td>
							<td>$contact->email_contact</td>
							<td>$contact->subjek_contact</td>
							<td>
								<a href='#message$contact->id_contact' class='view' id='$contact->id_contact'><span class='label label-info'><i class='icon-envelope icon-white'></i> View Contact</span></a>
								<a href='#delete$contact->id_contact' class='alertdel' id='$contact->id_contact'><span class='label label-important'><i class='icon-remove icon-white'></i>Delete</span></a>
							</td>
						</tr>
						<div id='message$contact->id_contact' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel2' aria-hidden='true'>
							<div class='modal-header'>
								<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
								<h3 id='myModalLabel2'>Contact Content</h3>
							</div>
							<div class='modal-body'>
								<p>$contact->message_contact</p>
							</div>
							<div class='modal-footer'>
								<button class='btn' data-dismiss='modal' aria-hidden='true'>Close</button>
							</div>
						</div>";
						$no++;
						}
					echo "</tbody></table>
				</div>
			</div>
			<div style='width:100%; height:500px;'>&nbsp;</div>
		</div>
	</div>

	<div id='alertdel' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel3' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel3'>Confirmation Deletion</h3>
		</div>
		<div class='modal-body'>
			<input type='hidden' id='delid' name='delid'>
			<span class='ico-warning'></span> Are you sure want to delete this data?
		</div>
		<div class='modal-footer'>
			<button id='btnalertdel' class='btn btn-danger'>Yes</button>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>No</button>
		</div>
	</div>";
    break;
}
}
?>