/**
 * Main Output function for the admin area
 **/
function group_pay_output($vars)
{
    //Check for paypal
    if (!gp_CheckForPaypal()) {
        echo "<p><strong>No Paypal Account</strong></p>\n\t\t\t<p>Group Pay has been configured to use a paypal account.</p>\n\t\t\t<p>Please add a paypal gateway.</p>";
    } else {
        //Do we have to save the settings
        $message = "";
        //$validLic = gp_ValidLicense();
        //Load Current Settins
        $settings = gp_LoadSettings();
        $paypalEmail = gp_LoadPayPayEmail();
        // Run a legacy file check
        group_pay_legacy_file_check();
        echo $message != "" ? "<p><b>{$message}</b></p>" : "";
        echo '<table><tr><td>Enabled:</td><td>' . ($settings['Enabled'] == "on" ? '<span style="color: green; font-weight: bold;">Enabled</span>' : '<span style="color: red; font-weight: bold;">Disabled</span>') . '</td></tr>';
        //	echo '<tr><td>License Key:</td><td>'.$settings['LicenseKey'].'</td></tr>';
        //	if($validLic[0]){
        echo '<tr><td>System Name:</td><td>' . $settings['SystemName'] . '</td></tr>';
        echo "<tr><td>PayPal Account:</td><td>{$paypalEmail}&nbsp;(<i>Loaded from PayPal gateway.</i>)</td></tr>";
        echo '<tr><td>Min Deposit:</td><td>$ ' . formatcurrency($settings['MinPayment']) . '</td></tr>';
        echo '<tr><td>Page Icon:</td><td>' . ($settings['PageIcon'] == "" ? "<i>None Configured</i>" : $settings['PageIcon']) . '</td></tr>';
        //	}else {
        //		echo '<tr valign="top"><td style="color:red">License Error:</td><td>'.$validLic[1].'</tr>';
        //	}
        echo '<tr valign="top"><td>Current Version:</td><td>' . $settings['version'] . '</tr>';
        echo '<tr><td>&nbsp;</td><td>&nbsp;</tr>';
        echo '<tr><td>Settings may be altered in Setup->Addon Modules->Group Pay</td><td>&nbsp;</tr>';
        echo '<tr><td>&nbsp;</td><td>&nbsp;</tr></table>';
        echo "<h3>We would like your support!</h3><p>If you like <a target='_blank' href='http://www.whmcs.com/appstore/304/Group-Pay---Its-Clan-Pay-for-your-WHMCS.html'>GroupPay</a> please <b>let people know!</b>" . "<ul>" . "<li><a target='_blank' href='http://www.whmcs.com/appstore/304/Group-Pay---Its-Clan-Pay-for-your-WHMCS.html'>See GroupPay on WHMCS App Store</a></li>" . "<li><a target='_blank' href='http://www.facebook.com/sharer.php?u=http://kadeo.com.au/'>Share Kadeo's Home Page on Facebook</a></li>" . "<li><a target='_blank' href='http://www.facebook.com/sharer.php?u=http://kadeo.com.au/design-and-development/whmcs-dev/whmcs-modules/72-group-pay.html'>Share Kadeo's Group Pay Page on Facebook</a></li>" . "<li><a target='_blank' href='http://twitter.com/share?url=http://kadeo.com.au/&text=I%27m+using+Group+Pay+for+WHMCS+by+%40craftingtheweb'>Tweet About Group Pay</a></li>" . "</ul>" . "Thanks Heaps!</p>";
    }
}
//Load the gp Config
//Template Setup
$paypal_url = "https://www.paypal.com/cgi-bin/webscr";
//$paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$gpSettings = gp_LoadSettings();
$pagetitle = $gpSettings['SystemName'];
$pageicon = $gpSettings['PageIcon'];
$breadcrumbnav = '<a href="index.php">' . $_LANG['globalsystemname'] . '</a> > <a href="grouppay.php">' . $gpSettings['SystemName'] . '</a>';
initialiseClientArea($pagetitle, $pageicon, $breadcrumbnav);
//require("init.php");
# Define the template filename to be used without the .tpl extension
$templatefile = "grouppay";
$userHash = $_GET['hash'];
$fromPaypal = $_GET['fromPaypal'] == 'true';
//Load the grouppay settings
$gpPayPalEmail = gp_LoadPayPayEmail();
//Define up some smarty vars for the template
$loggedInClientHash = $_SESSION['uid'] ? gp_HashUserId($_SESSION['uid']) : "";
$smartyvalues["loggedInClientHash"] = $loggedInClientHash;
//If we are loading this for a user (other than logged in if applicable)
if (isset($userHash) && ($userHash != "" && $userHash != $loggedInClientHash)) {
    $smartyvalues["anotherClientHash"] = true;
    $clientId = gp_LoadUserFromHash($userHash);
    $result = mysql_query("SELECT * from tblclients where id = {$clientId}");
    $smartyvalues["clientFound"] = $clientInfo = mysql_fetch_assoc($result);
    $smartyvalues["clientInfo"] = $clientInfo;
    $smartyvalues["clientHash"] = $userHash;
} else {
    $smartyvalues["anotherClientHash"] = false;
    // Load the past payments
    $clientId = $_SESSION['uid'];