include "../inc/classes/IbeaconImage.php";
include "../inc/classes/Helpers.php";
if (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'sort') {
    $objIbeaconImage = new IbeaconImage();
    $objIbeaconImage->SortValues(substr($_REQUEST['action'], 1), substr($_REQUEST['action'], 0, 1));
    unset($objIbeaconImage);
} elseif (isset($_REQUEST['dragsort'])) {
    // handle drag sort ajax request:
    $objIbeaconImage = new IbeaconImage($_REQUEST['id']);
    $new_sort_order = $_REQUEST['idx'] * 10 + 5;
    if ($new_sort_order > $objIbeaconImage->SortOrder) {
        $new_sort_order += 10;
        // increasing sort order so must add another 10
    }
    $objIbeaconImage->SortOrder = $new_sort_order;
    $objIbeaconImage->update();
    echo "success";
    exit;
    // just exit since this is an ajax request
}
$objIbeacon = new Ibeacon($_REQUEST['ibeacon']);
include "includes/pagetemplate.php";
function PageContent()
{
    global $objIbeacon;
    ?>
    
        <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
}
if ($_POST['commit'] == "Save iBeacon Image") {
    if ($id == 0) {
        // insert
        $obj = new IbeaconImage();
        $obj->IbeaconId = $_REQUEST["ibeacon"];
        $obj->create();
        $obj->handleFileUploads();
        $obj->handleDropFileUploads($aDropFields[0], 'ImageFile');
        // redirect to listing list
        header("Location:ibeaconimage_list.php?cat=" . $_REQUEST['cat'] . "&ibeacon=" . $_REQUEST['ibeacon']);
        exit;
    } else {
        // update
        $obj = new IbeaconImage($id);
        $obj->update();
        $obj->handleFileUploads();
        $obj->handleDropFileUploads($aDropFields[0], 'ImageFile');
        // redirect to listing list
        header("Location:ibeaconimage_list.php?cat=" . $_REQUEST['cat'] . "&ibeacon=" . $_REQUEST['ibeacon']);
        exit;
    }
} else {
    if ($_REQUEST['mode'] == 'e') {
        //listing
        $objIbeaconImage = new IbeaconImage($id);
        $ibeacon_id = $objIbeaconImage->IbeaconId;
        $image_file = $objIbeaconImage->ImageFile;
        $path = $objIbeaconImage->GetPath();
    } else {
        if ($_REQUEST['mode'] == 'a') {