<?
include "header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "step_one"; }
if($admin_info[plan_upgrade] != "yes") { exit(); }

$server_array = explode("/", $_SERVER['PHP_SELF']);
$server_array_mod = array_pop($server_array);
$server_info = implode("/", $server_array);
$server = "http://".$_SERVER['HTTP_HOST'].$server_info;

if($user_info[paypal_email] == "") { $paypal_email = $admin_info[paypal_email]; } else { $paypal_email = $user_info[paypal_email]; }


if($task == "step_one") {
  echo $header;
  echo "
  <table width='520' cellpadding='0' cellspacing='0'>
  <tr><td>
  <b>Upgrade Your Account</b><br>
  Upgrading your account is easy and takes effect instantly! First, select
  a new package below. PayPal will ask you to update your existing subscription.
  Note: If you have more than one hosting account, be sure to update the correct subscription or
  the changes will not take effect.
  <br><br>
  </td></tr></table>
  ";

  $highest_plan = mysql_fetch_assoc(mysql_query("SELECT max(price) AS price FROM ims_plans WHERE status='on'"));
  if($user_info[price] >= round($highest_plan[price], 2)) {
    echo "
    <table cellpadding='0' cellspacing='0' width='520'>
    <tr><td>
    <b>
    You currently have the best account available.<br>
    Please <a href='support_contact.php'>contact support</a> if you wish to arrange for a custom account.
    </b>
    </td></tr>
    </table>
    ";
    echo $footer;
    exit();

  } else {

    $plans = mysql_query("SELECT * FROM ims_plans WHERE price > '$user_info[price]' AND status='on' ORDER BY price, plan");
    $numofplans = mysql_num_rows($plans);
    $thiscount = 0;

    while($plan_info = mysql_fetch_assoc($plans)) {
    $thiscount++;
    if($thiscount == $numofplans) { $bottomspace = ""; } else { $bottomspace = "margin-bottom: 7px;"; }
    echo "
    <table width='518' cellspacing='0' cellpadding='0' style='background: #FFFFFF; border: 1px solid #AAAAAA;$bottomspace'>
    <tr>
    <form action='https://www.paypal.com/cgi-bin/webscr' method='POST'>
    <td style='padding: 7px; padding-left: 8px;'>
    <b>$plan_info[plan]</b><br>
    <table cellpadding='0' cellspacing='0' style='margin-bottom: 4px;'>
    <tr><td style='padding-top: 2px;'>$plan_info[plan_description]</td></tr>
    </table>
  <input type='hidden' name='cmd' value='_xclick-subscriptions'>
  <input type='hidden' name='business' value='$paypal_email'>
  <input type='hidden' name='item_name' value='$plan_info[plan]'>
  <input type='hidden' name='item_number' value='$plan_info[p_id]'>
  <input type='hidden' name='return' value='$server/upgrade.php?task=success'>
  <input type='hidden' name='rm' value='2'>
  <input type='hidden' name='cancel_return' value='$server/upgrade.php'>
  <input type='hidden' name='a3' value='$plan_info[price]'>
  <input type='hidden' name='p3' value='1'>
  <input type='hidden' name='t3' value='M'>
  <input type='hidden' name='src' value='1'>
  <input type='hidden' name='no_shipping' value='1'>
  <input type='hidden' name='no_note' value='1'>
  <input type='hidden' name='custom' value='$user_info[u_id]'>
  <input type='hidden' name='modify' value='1'>
  <input type='hidden' name='notify_url' value='$server/paypal.php'>
  <input type='submit' class='button' value='Update Subscription'"; if($admin_info[demo_feature] == "on" & $user_info[email] == $admin_info[demo_email]) { echo " DISABLED"; } echo ">
    </td>
    </form>
    </tr>
    </table>
    ";
    }
echo $footer;
  }
}




if($task == "success") {
include "vars.php";
echo $header;
echo "
<table cellspacing='0' cellpadding='0' width='520'>
<tr>
<form action='index.php' method='POST'>
<td>
<b>Upgrade Complete</b><br>
You have successfully upgraded your account! Changes will take place immediately.
<br><br>
<input type='submit' class='button' value='Return to Home'>
</td></form></tr>
</table>
";
echo $footer;
exit;
}

?>