<?
include "header.php";
if(isset($_POST['p_id'])) { $p_id = $_POST['p_id']; } elseif(isset($_GET['p_id'])) { $p_id = $_GET['p_id']; } else { exit; }
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "main"; }
$plan_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_plans WHERE p_id='$p_id'"));

$header = "
<html>
<head>
<title>Image Management System - Administration Panel</title>
<META HTTP-EQUIV='Pragma' CONTENT='no-cache'>
<link rel='STYLESHEET' type='text/css' href='../styles.css'>
<script language='javascript'>
<!--
function redirect() {
window.opener.location.href('plans.php');
window.close();
}
// -->
</script>
</head>
<body>

<font style='font-size: 13pt;'><b>Pricing Plan Info</b></font><br>
";

$footer = "
</body>
</html>
";




if($task == "delete") {
  if(mysql_num_rows(mysql_query("SELECT * FROM ims WHERE plan='$p_id'")) == 0) {
    mysql_query("DELETE FROM ims_plans WHERE p_id='$p_id'");
    echo $header;
    echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
<center>
The plan <b>\"$plan_info[plan]\"</b> has been deleted.
<br><br>
<input class='button' type='submit' value='Close Window' onClick=\"redirect()\">
</center>
</td></tr></table>
    ";
    echo $footer;
    exit;
  } else {
    echo $header;
    echo "

<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
<b>An Error Has Occurred:</b><br>
You cannot delete this plan because there are currently users on it.<br>
If you want to prevent new users from signing up with this plan, simply<br>
turn it off.
<br><br>
<a href=\"javascript:history.go(-1);\">Click here to go back and try again.</a>
</td></tr></table>
";
    echo $footer;
    exit;
  }
}





if($task == "edit") {
$status = $_POST['status'];
mysql_query("UPDATE ims_plans SET status='$status' WHERE p_id='$p_id'");
echo $header;
echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
<center>
The plan <b>\"$plan_info[plan]\"</b> has been saved.<br><br>
<input class='button' type='submit' value='Close Window' onClick=\"redirect()\">
</center>

</td></tr></table>
";
echo $footer;
exit;
}







$extensions = explode(",", $plan_info[ext_list]);
$users_on_plan = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE plan='$p_id' AND is_approved='yes'"));
$pend_users_on_plan = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE plan='$p_id' AND is_approved<>'yes'"));
echo $header;

echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<form action='plan_info.php' method='POST'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>
<b>Plan Name:</b>&nbsp; $plan_info[plan]<br>
<b>Price:</b>&nbsp; $$plan_info[price]/month<br>
<b>Users On Plan:</b>&nbsp; $users_on_plan users<br>
"; if($admin_info[approve_deny] == "yes") { echo "
<b>Pending Users On Plan:</b>&nbsp; $pend_users_on_plan users<br>
"; } echo "
<b>Space:</b>&nbsp; $plan_info[allocated_space] MB<br>
<b>Folders:</b>&nbsp; $plan_info[allowed_folders]<br>
<b>Max Filesize:</b>&nbsp; $plan_info[max_filesize] KB<br>
<b>Bandwidth:</b>&nbsp; $plan_info[bandwidth_allotted] MB<br>
<b>Extentions:</b>&nbsp;";
if(in_array("jpg", $extensions)) { echo " jpg"; }
if(in_array("jpeg", $extensions)) { echo " jpeg"; }
if(in_array("gif", $extensions)) { echo " gif"; }
if(in_array("bmp", $extensions)) { echo " bmp"; }
if(in_array("png", $extensions)) { echo " png"; }
if(in_array("pdf", $extensions)) { echo " pdf"; }
echo "<br>
<b>Photo Album:</b>&nbsp; "; if($plan_info[photo_album] == "yes") { echo "Yes"; } else { echo "No"; } echo "<br>
<br>
<b>Plan Status:</b>&nbsp; <select name='status'><option value='on'"; if($plan_info[status] == "on") { echo " SELECTED"; } echo ">ON</option><option value='off'"; if($plan_info[status] == "off") { echo " SELECTED"; } echo ">OFF</option></select><br>
<br>
Note: You can only delete a plan that is in use by 0 users. If you want to prevent
users from upgrading/signing up for a plan, simply change its \"Plan Status\" to \"OFF\".

</td></tr></table>

<br>

<table cellpadding='0' cellspacing='0'>
<tr><td>
<input type='hidden' name='p_id' value='$p_id'>
<input type='hidden' name='task' value='edit'>
<input class='button' type='submit' value='Save Changes'>&nbsp;
</td>
</form>
<form action='plan_info.php' method='POST'>
<td>
<input type='hidden' name='p_id' value='$p_id'>
<input type='hidden' name='task' value='delete'>
<input class='button' type='submit' value='Delete Plan'"; if($users_on_plan != 0 | ($admin_info[approve_deny] == "yes" & $pend_users_on_plan != 0)) { echo " DISABLED"; } echo ">&nbsp;
</td>
</form>
<td>
<input class='button' type='submit' value='Cancel' onClick=\"redirect()\">
</td>
</tr>
</table>
";
echo $footer;

?>