function fetchTeam($mode = 'fullPage', $page = '', $option = '')
 {
     // fetches team subtab via ajax
     switch ($page) {
         case 'team':
             require_once PATH_FACEBOOK . '/pages/pageTeam.class.php';
             $teamObj = new pageTeam($this);
             $code = $teamObj->fetch($mode, $option);
             break;
         case 'wall':
             require_once PATH_FACEBOOK . '/pages/pageWall.class.php';
             $wallObj = new pageWall($this);
             $code = $wallObj->fetch($mode, $option, $arg3);
             break;
         case 'rewards':
             require_once PATH_FACEBOOK . '/pages/pageRewards.class.php';
             $prizesObj = new pageRewards($this);
             $code = $prizesObj->fetch($mode);
             break;
         case 'winners':
             require_once PATH_FACEBOOK . '/pages/pageRewards.class.php';
             $prizesObj = new pageRewards($this);
             $code = $prizesObj->fetch($mode, 'winners');
             break;
         case 'challenges':
             require_once PATH_FACEBOOK . '/pages/pageChallenges.class.php';
             $challengesObj = new pageChallenges($this);
             $code = $challengesObj->fetch($mode);
             break;
         case 'challengeSubmit':
             require_once PATH_FACEBOOK . '/pages/pageChallengeSubmit.class.php';
             $challengeSubmitObj = new pageChallengeSubmit($this);
             $code = $challengeSubmitObj->fetch($mode);
             break;
         case 'leaders':
             require_once PATH_FACEBOOK . '/pages/pageLeaders.class.php';
             $leadersObj = new pageLeaders($this);
             $code = $leadersObj->fetch($mode, $option);
             break;
         case 'rules':
             require_once PATH_FACEBOOK . '/pages/pageRules.class.php';
             $rulesObj = new pageRules($this);
             $code = $rulesObj->fetch($mode);
             break;
         case 'redeem':
             // check auth for member
             require_once PATH_FACEBOOK . '/pages/pageRedeem.class.php';
             $redeemObj = new pageRedeem($this);
             $code = $redeemObj->fetch($mode);
             break;
         case 'orders':
             // check auth for member
             require_once PATH_FACEBOOK . '/pages/pageOrders.class.php';
             $ordersObj = new pageOrders($this);
             $code = $ordersObj->fetch($mode);
             break;
     }
     return $code;
 }
<?php

// for posting through the callback
// switch on p and o
function smartRedirect($url)
{
    if (headers_sent()) {
        echo '<script type="text/javascript">window.location = "' . $url . '";</script>';
        die;
    } else {
        @header("Location: " . $url);
    }
}
switch ($o) {
    case 'challenge':
        $passback = '';
        require_once PATH_FACEBOOK . '/pages/pageChallengeSubmit.class.php';
        $b = pageChallengeSubmit::processChallengeSubmit($code, $passback);
        $msg = urlencode($code);
        if ($b) {
            smartRedirect(URL_CANVAS . "/?p=profile&memberid={$_POST['fb_sig_user']}&message={$msg}");
        } else {
            smartRedirect(URL_CANVAS . "/?p=challengeSubmit&id={$_POST['challengeid']}&message={$msg}" . $passback);
        }
        break;
    default:
        break;
}