<?php
	require 'autoload.php';
	use Parse\ParseClient;
	use Parse\ParseObject;
	use Parse\ParseQuery;
	use Parse\ParseACL;
	use Parse\ParsePush;
	use Parse\ParseUser;
	use Parse\ParseInstallation;
	use Parse\ParseException;
	use Parse\ParseAnalytics;
	use Parse\ParseFile;
	use Parse\ParseCloud;
	
	include 'includes/func.php';
	include 'config.php';
	
	ParseClient::initialize($ApplicationID, $RestAPIKEY, $MasterKey);
	ParseClient::setServerURL($serverURLB4APP, '/');
	
	require 'includes/Url.php';
	require 'includes/Paging.php';
	$objBeacons = new ParseQuery("beacon");										
	$objBeacons->descending('createdAt');
	$result = $objBeacons->find();

	$objPaging = new Paging($result, 50);
	$rows = $objPaging->getRecords();
	
	$objPaging->url = $objPaging->url;
?>

<!DOCTYPE html>
<html lang="en">

<head>

	<title>Manage Beacon Devices</title>
	<?php include 'includes/head.php'; ?>
</head>
<body>
    <div id="wrapper">
        <?php include 'includes/header.php';?>
        <div id="page-wrapper">
            <div class="container-fluid" >
                <div class="row">
					<div class="col-lg-12">
                         <h1 class="page-header">
                            Manage Beacon Devices
							<a href="add-beacon.php" class="btn btn-success pull-right">Add New Beacon</a>
                        </h1>
                        <div class="table-responsive">
                            <table id="listBeacons" class="table table-bordered table-hover table-striped">
                                <thead>
                                    <tr>
                                        <th>Unique ID</th>
                                        <!-- <th>Proximity </th> -->
                                        <th>Proximity UUID</th>
                                        <th>Major</th>
                                        <th>Minor</th>
        								<th>Name Space</th>
                                        <th>Instance</th>
                                        <th>Mac Address</th>
                                        <th>Type</th>
										<th class="text-center actionWidth" >Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    	foreach($rows as $key){
											$updatedDate = json_decode(json_encode($key->getUpdatedAt()));
											$getObjectId = $key->getObjectId();
											/*<td>'.$key->get('proximity').'</td>*/
											echo  '<tr>
														<td>'.$key->get('unique_id').'</td>			
														
														<td>'.$key->get('proximity_uuid').'</td>
														<td>'.$key->get('major').'</td>
														<td>'.$key->get('minor').'</td>
                                                        <td>'.$key->get('name_space_id').'</td>
														<td>'.$key->get('instance_id').'</td>
														<td>'.$key->get('macAddress').'</td>
														<td>'.$key->get('type').'</td>
														<td align="center" class="actionButtons">
															<a data-toggle="tooltip" title="View"  href="view-beacon-device.php?uTp='.$getObjectId.'"><i class="glyphicon glyphicon-eye-open"></i></a>
															<a data-toggle="tooltip" title="Edit"  href="edit-beacon-device.php?uTp='.$getObjectId.'"><i class="glyphicon glyphicon-pencil"></i></a>
															<a data-toggle="tooltip" title="Delete" onclick="return confirm(\'Are you sure you want to delete this beacon?\');" href="delete-beacon-device.php?uTp='.$getObjectId.'"><i class="glyphicon glyphicon-trash"></i></a>		 	
													</td>
													</tr>';
													
													//echo '<pre>';													
													//print_r($);
												}
											?>
                                </tbody>
                            </table>
							<?php  echo $objPaging->getPaging(); ?>
                        </div>
                    </div>
                </div>
                <!-- /.row -->

            </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

   <?php include 'includes/footer.php'; ?>
   
   <script>
		$(function() {
			$(".deleteObject").click(function(){
				element = $(this);
				var del_id = element.attr("id");
				
				alertify.confirm('Deleing Beacon Device', 'Are you sure!.<br>This beacon device is assoicated with buildings.', function(){
					$.ajax({
					type:'POST',
					url:'delete.php',
					data:{'objBeacons':del_id},
					success: function(data){
						 if(data=="deteted"){
							alertify.success('Deleted.');
							window.location = "manage-beacons.php";
						 }else{
							//alertify.error('Cancel');
						 }
					 }

					});
				},
				function(){
					//alertify.error('Cancel');
				});
			});
		});
   </script>

</body>

</html>
