<?php

if (!isset($_SESSION)) {
    session_start();
}
if (!isset($_SESSION["email"]) || !isset($_SESSION["registration"])) {
    http_response_code(403);
    // forbidden
    die;
}
include_once '../db_functions.php';
$db = new DB_Functions();
$regId = $_SESSION["registration"];
$rowid = $_SESSION["rowid"];
$dataVersion = $db->getDataVersion($regId, $rowid);
$mdVersion = $db->getMDVersion($regId, $rowid);
if ($mdVersion != $dataVersion) {
    $db->clearDeviceData($regId);
    $db->setDataVersion($regId, $mdVersion);
    echo $mdVersion . " Updated";
} else {
    echo $mdVersion;
}
                      });
                      </script>
                      <li role="presentation"><a role="menuitem" style="cursor:pointer" tabindex="-1" id="SD_<?php 
    echo $rowid;
    ?>
"><?php 
    echo $name;
    ?>
</a></li>
                      <?php 
}
if (!isset($_SESSION['registration'])) {
    $_SESSION["registration"] = $registration;
    $_SESSION["name"] = $name;
    $_SESSION["rowid"] = $rowid;
    $deviceDataVersion = $db->getDataVersion($registration, $rowid);
    ?>
                          <script type="text/javascript">
                          $(document).ready(function(){
                            $("#device-choice-dropdown-txt").text("<?php 
    echo $name;
    ?>
");
                            if (Cookies.get('options_autoRefreshPages') != "false") {
                              refreshAll("<?php 
    echo $registration;
    ?>
");
                            }
                          });
                          </script>