Facebook Application: “Invite Friends Page” code

<?php
// the facebook client library
include_once 'facebook.php';
 
// this defines some of your basic setup
include_once 'config.php';
 
// some basic library functions
include_once 'lib.php';
 
$facebook = new Facebook($api_key, $secret);
$facebook->require_frame();
$user = $facebook->require_login();
 
 
if($_REQUEST['friend_ids'])
{
 $inviteFriends = split(" ", $_REQUEST['friend_ids']);
 foreach($inviteFriends as $key => $inviteFriend)
  $inviteFriends[$key] = intify($inviteFriend);
 
  $goToAddress = $facebook->api_client->notifications_sendRequest($inviteFriends, "Application Name",  "<fb:req-choice url='http://www.facebook.com/add.php?api_key=$api_key' label='Add Application Name' /></fb:req-choice>","http://www.somewhere.com/icon.gif",true);
  if($goToAddress)
   $facebook->redirect($goToAddress);
 
}
 
 
$fql = "SELECT uid, first_name, last_name, pic_small
            FROM user
            WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = {$facebook->user})
            AND has_added_app = 0";
$friends = $facebook->api_client->fql_query($fql);
 
//
$dump = "<div id='friends'>";
$number = 0;
foreach($friends as $friend_info)
{
 if(!$friend_info['pic_small'])
  $friend_info['pic_small'] = "http://static.ak.facebook.com/pics/no_pic.jpg";
 
 $dump .= " <div class='friend_box'>
   <div class='friend_image'>
    <img src='".$friend_info['pic_small']."' onclick=\"toggle($number)\">
   </div>
   <div class='friend_name'><span onclick=\"toggle($number)\">".$friend_info['first_name']." ".$friend_info['last_name']."</span></div>
   <input id='check$number' type='checkbox' checked value='".$friend_info['uid']."'>
 
   </div>";
 $number++;
}
?>
 
<html>
<head>
<title>Application Name</title>
<link rel="stylesheet" href="base.css" type="text/css" />
<style type="text/css">
    #preview {float:right;display:inline;width:180px;overflow:hidden}
        #friends {border:1px solid #ccc;background:white;padding:10px;height:250px;overflow-y:scroll;overflow-x:hidden;}
    .friend_box {width:120px;height:50px;overflow:hidden;float:left;display:inline;margin-right:20px;margin-bottom:10px;}
    .friend_box input {margin-left:5px}
    .friend_image {width:50px;height:50px;overflow:hidden;float:left;display:inline}
    .friend_image img {width:50px;cursor:pointer;}
    .friend_name {width:65px;height:30px;overflow:hidden;margin-left:5px;float:left;display:inline;margin-top:3px;font-weight:bold;color:#555}
    .img_fill_width {width:50px}
    .img_fill_height {height:50px}
    .action {position:relative;height:25px;line-height:25px}
</style>
</head>
<body>
        <div>
            <div id="header">
                <h1>Share Application Name with your friends!</h1>
            </div>
            <div style="clear:both"></div>
        </div>
        <form action="" method="get" onsubmit="return savedone()" target="_parent">
        <div class="action" style="margin-top:10px;margin-bottom:5px;">
            <div style="width:100%;text-align:left;"><a href="javascript:select_all()">Select All</a> | <a href="javascript:deselect_all()">Unselect All</a></div>
            <div style="position:absolute;top:0px;left:250px;">
            </div>
        </div>
 
<?php print $dump; ?>
<input type='hidden' id="friend_ids" name="friend_ids" value=""></div>
        <div class="action" style="margin-top:5px;margin-bottom:10px;">
            <div style="width:620px;text-align:right; line-height: 12px; padding-top: 5px;">
                <input type="submit" value="Invite Friends">
                <div style="padding-top:5px;">Facebook will make you confirm these 10 at a time.</div>
            </div>
        </div>
 <br><br><br>
 <div align=right><a href='<?php print $GLOBALS['URL']; ?>'>Skip Invites</a></div>
    </form>
<script type="text/javascript">
function deselect_all() {
    for (var i=0; i < <?php print $number; ?>; i++) {
        var checkbox = document.getElementById("check"+i);
        if (checkbox) {
            checkbox.checked = false;
        }
    }
}
 
function select_all() {
    for (var i=0; i < <?php print $number; ?>; i++) {
 
 
        var checkbox = document.getElementById("check"+i);
        if (checkbox) {
            checkbox.checked = true;
        }
    }
}
function toggle(index) {
    var checkbox = document.getElementById("check"+index);
    if (checkbox) {
        checkbox.checked = !checkbox.checked;
    }
}
function savedone() {
    var total = 0;
    var friend_ids = "";
    for (var i=0; i < <?php print $number; ?>; i++) {
        var checkbox = document.getElementById("check"+i);
        if (checkbox && checkbox.checked) {
            total++;
            if (total > 1) {
                friend_ids += " ";
            }
            friend_ids += checkbox.value;
        }
    }
    if (total == 0) {
        quitnow = confirm("Are You Sure You Don't Want to Invite Friends?");
        if (quitnow)
        {
            parent.location="<?php print $GLOBALS['URL']; ?>";
            return false;
        }
        else
        {
            select_all();
            return false;
        }
    }
    document.getElementById("friend_ids").value = friend_ids;
    return true;
}
</script>
</body>
</html>

NOTE: The CSS and Javascript was “borrowed” from the X-Me Application.