// No access token found, show the link to generate one
    print "<a class='login' href='{$authUrl}'>Login!</a>";
} else {
    print "<a class='logout' href='?logout'>Logout</a>";
}
if ($client->getAccessToken()) {
    // If the action is set, dispatch the action if supported
    if (isset($_GET['action'])) {
        $action = decodeActionString($_GET['action']);
        if (!isValidAction($action)) {
            die('Unsupported action: ' . $_GET['action'] . "\n");
        }
        displayAction($action);
    } else {
        // Show the list of links to supported actions.
        printExamplesIndex(getSupportedActions());
        printHtmlFooter();
    }
    // Note that we re-store the access_token bundle, just in case anything
    // changed during the request - the main thing that might happen here is the
    // access token itself is refreshed if the application has offline access.
    $_SESSION['access_token'] = $client->getAccessToken();
}
/**
 * Displays the requested action.
 */
function displayAction($action)
{
    global $service;
    // Render the required action.
    include_once 'examples/' . $action[0] . '/' . $action[1] . '.php';
        if (!in_array($action, $actions)) {
            die('Unsupported action:' . $action . "\n");
        }
        // Render the required action.
        require_once 'examples/' . $action . '.php';
        $class = ucfirst($action);
        $example = new $class($service);
        printHtmlHeader($example->getName());
        try {
            $example->execute();
        } catch (apiException $ex) {
            printf('An error as occurred while calling the example:<br/>');
            printf($ex->getMessage());
        }
        printSampleHtmlFooter();
    } else {
        // Show the list of links to supported actions.
        printHtmlHeader('Double Click Bid Manager API PHP usage examples.');
        printExamplesIndex($actions);
        printHtmlFooter();
    }
    // The access token may have been updated.
    $_SESSION['service_token'] = $client->getAccessToken();
}
/**
 * Builds an array containing the supported actions.
 */
function getSupportedActions()
{
    return array('GetLatestReport', 'DownloadLineItems', 'UploadLineItems');
}