<?php

include_once '../lib/client/facebook.php';
include_once '../lib/AppConfig.class.php';
include_once '../lib/HelloWorld.class.php';
// Create a new Facebook client object
$facebook = new Facebook(AppConfig::$api_key, AppConfig::$secret);
// Prevent this page from being viewed outside the context of app.facebook.com/appname/
$facebook->require_frame();
// Prevent this page from being viewed without a valid logged in user
// -- NOTE: This does not mean that the logged in user has added the application
$user = $facebook->require_login();
// Require the viewing user to have added the application.
$facebook->require_add();
$app = new HelloWorld($facebook);
// Create a var to represent the target user, default it to null
$target_user = null;
if (isset($_POST['friend_sel'])) {
    // If the friend_sel var is set in the POST vars, typecast it to an
    // integer and set the target_user
    $target_user = (int) $_POST['friend_sel'];
}
// By default we show the form, and the action_wave and wave_success are
// set to false.
$wave_success = false;
$action_wave = false;
$show_form = true;
if ($target_user) {
    $action_wave = true;
    $show_form = false;
    // The target_user is set, send them a greeting