<?
include "header.php";
if(isset($_POST['task'])) { $task = $_POST['task']; } elseif(isset($_GET['task'])) { $task = $_GET['task']; } else { $task = "add"; }

$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>Create Pricing Plan</b></font><br>
";

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


if($task == "add_plan") {
  $plan = str_replace("'", "&#39;", $_POST['plan']);
  $price = str_replace("$", "", $_POST['price']);
  $plan_description = $_POST['plan_description'];
  $allocated_space = $_POST['allocated_space'];
  $allowed_folders = $_POST['allowed_folders'];
  $max_filesize = $_POST['max_filesize'];
  $bandwidth_allotted = $_POST['bandwidth_allotted'];
  $photo_album = $_POST['photo_album'];

  $ext_list = "";
  $lastext = "no";
  if(isset($_POST['ext_jpg'])) { $ext_list = "jpg"; $lastext = "yes"; }
  if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
  if(isset($_POST['ext_jpeg'])) { $ext_list .= "jpeg"; $lastext = "yes"; }
  if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
  if(isset($_POST['ext_gif'])) { $ext_list .= "gif"; $lastext = "yes"; }
  if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
  if(isset($_POST['ext_bmp'])) { $ext_list .= "bmp"; $lastext = "yes"; }
  if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
  if(isset($_POST['ext_png'])) { $ext_list .= "png"; $lastext = "yes"; }
  if($lastext == "yes") { $ext_list .= ","; $lastext = "no"; }
  if(isset($_POST['ext_pdf'])) { $ext_list .= "pdf"; $lastext = "yes"; }

  if($plan == "" | $price == "" | $plan_description == "" | $allocated_space == "" | $allowed_folders == "" | $bandwidth_allotted == "") {
  $is_error = "yes";
  $error .= "You have omitted the following fields:<br>";
    if($plan == "") { $error .= "  -Plan Name<br>"; }
    if($price == "") { $error .= "  -Price<br>"; }
    if($plan_description == "") { $error .= "  -Description<br>"; }
    if($allocated_space == "") { $error .= "  -Space Available<br>"; }
    if($allowed_folders == "") { $error .= "  -Folders Available<br>"; }
    if($bandwidth_allotted == "") { $error .= "  -Allotted Bandwidth<br>"; }
  }

  if(!is_numeric($price)) {
  $is_error = "yes";
  $error .= "Price must be a numeric value.<br>";
  }

  if(!is_numeric($allocated_space) | $allocated_space <= 0) {
  $is_error = "yes";
  $error .= "Space Available must be a numeric value greater than 0.<br>";
  }

  if((!is_numeric($allowed_folders) | $allowed_folders <= 0 | $allowed_folders != (int)$allowed_folders) & $allowed_folders != "") {
  $is_error = "yes";
  $error .= "Folders Available must be an integer value greater than 0.<br>";
  }

  if(!is_numeric($bandwidth_allotted) | $bandwidth_allotted <= 0) {
  $is_error = "yes";
  $error .= "Allotted Bandwidth must be a numeric value greater than 0.<br>";
  }


  if($is_error == "yes") {
  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>
$error
<br>
<b><font face='verdana'>&#171;</font> <a href=\"javascript:history.go(-1);\">Click here to go back and try again.</a></b>
";
  echo $footer;
  exit;
  }

  mysql_query("INSERT INTO ims_plans (plan, price, status, plan_description, allocated_space, allowed_folders, max_filesize, bandwidth_allotted, ext_list, photo_album) VALUES ('$plan', '$price', 'on', '$plan_description', '$allocated_space', '$allowed_folders', '$max_filesize', '$bandwidth_allotted', '$ext_list', '$photo_album')");
  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 new pricing plan has been created.<br><br>
  <input class='button' type='submit' value='Close Window' onClick=\"redirect()\">
  </center>
</td></tr></table>
  ";
  echo $footer;
  exit;
}
  
echo $header;

echo "
<table cellpadding='0' cellspacing='0' style='margin-top: 5px;'>
<form action='plans_add.php' method='POST'>
<tr>
<td width='420' style='border: 1px solid #AAAAAA; background: #F5F5F5; padding: 10px;'>

Note: Only the plan title and description are displayed on the user-side \"Upgrade!\" page,
so you must include any relevant information within these two fields.
<br><br>

<table cellpadding='0' cellspacing='0'>
<tr><td align='right'>Plan Title &nbsp;</td><td><input type='text' name='plan' size='35' maxlength='60'> </td></tr>
<tr><td align='right' valign='top'>Description &nbsp;</td><td><textarea name='plan_description' rows='4' cols='45'></textarea></td></tr>
<tr><td align='right'>Monthly Price &nbsp;</td><td><input type='text' name='price' size='7' value='\$' maxlength='8'> (For example: $4.95, or $0.00 for free)</td></tr>
<tr><td align='right'>Space Allowed &nbsp;</td><td><input type='text' name='allocated_space' size='7' maxlength='10'> (In MB, for example: 20)</td></tr>
<tr><td align='right'>Bandwidth Allowed &nbsp;</td><td><input type='text' name='bandwidth_allotted' size='7' maxlength='10'> (In MB, for example: 250)</td></tr>
<tr><td align='right'>Max. Folders &nbsp;</td><td><input type='text' name='allowed_folders' size='7' maxlength='10'> (For example: 10)</td></tr>
<tr><td align='right'>Max. Filesize &nbsp;</td><td><select name='max_filesize'>
<option value='10'>10 KB</option>
<option value='25'>25 KB</option>
<option value='50'>50 KB</option>
<option value='100'>100 KB</option>
<option value='200'>200 KB</option>
<option value='500'>500 KB</option>
<option value='1024'>1 MB</option>
</select></td></tr>
<tr><td align='right'>File Extensions&nbsp;</td>
<td>
<input type='checkbox' name='ext_jpg' value='yes' CHECKED>JPG &nbsp;
<input type='checkbox' name='ext_jpeg' value='yes' CHECKED>JPEG &nbsp;
<input type='checkbox' name='ext_gif' value='yes' CHECKED>GIF &nbsp;
<input type='checkbox' name='ext_bmp' value='yes' CHECKED>BMP &nbsp;
<input type='checkbox' name='ext_png' value='yes' CHECKED>PNG &nbsp;
<input type='checkbox' name='ext_pdf' value='yes' CHECKED>PDF &nbsp;
</td></tr>
<tr><td align='right'>Photo Album&nbsp;</td>
<td>
<input type='checkbox' name='photo_album' value='yes' CHECKED>
</td></tr>
</table>

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

<br>

<table cellpadding='0' cellspacing='0'>
<tr>
<td>
<input type='hidden' name='task' value='add_plan'>
<input class='button' type='submit' value='Create Plan'>&nbsp;
</td>
<td>
<input class='button' type='submit' value='Cancel' onClick=\"redirect()\">
</td>
</tr>
</form>
</table>
";

echo $footer;

?>