function auto_checkout_by_location($location_id)
{
    $query = <<<SQL
SELECT
    t.`id`,
    t.`registration_id`,
    t.`checked_in`,
    t.`checked_out`,
    t.`created`,
    t.`modified`
FROM
    `tracking` t
    INNER JOIN `registration` r ON t.`registration_id` = r.`id`
WHERE
    r.`location_id` = :location_id
    AND t.`checked_out` IS NULL
SQL;
    $dbaccess = new db_access();
    $dbaccess->open_connection();
    $checkins = $dbaccess->fetch_all($query, array(get_db_param(':location_id', $location_id, PDO::PARAM_INT)), true);
    $query = <<<SQL
UPDATE `tracking`
SET
    `checked_out` = :now,
    `modified` = :now
WHERE `id` = :tracking_id;
SQL;
    foreach ($checkins as $checkin) {
        $dbaccess->update($query, array(get_db_param(':tracking_id', $checkin['id'], PDO::PARAM_INT), get_db_param(':now', get_db_now(), PDO::PARAM_STR)), true);
    }
    $dbaccess->close_connection();
    return json_decode(json_encode($data), FALSE);
}