<?
require_once("../conn.php");
require_once("access.php");

include_once("LeftStyles.php");

?>

<script>
	function CheckNewPrice() {

		if(document.f1.PackageName.value=="")
		{
			window.alert('Enter the new package name, please!');
			document.f1.PackageName.focus();
			return false;
		}

		if(document.f1.NewPrice.value=="")
		{
			window.alert('Enter the new price value, please!');
			document.f1.NewPrice.focus();
			return false;
		}

		if(document.f1.nDuration.value=="")
		{
			window.alert('Select a duration period, please!');
			document.f1.nDuration.focus();
			return false;
		}

		if(document.f1.pLevel.value=="")
		{
			window.alert('Select a priority level, please!');
			document.f1.pLevel.focus();
			return false;
		}

	}

	function CheckDelete() {

		if(confirm('Are you sure you want to delete this price?'))
		{
			return true;
		}
		else
		{
			return false;
		}

	}

</script>
<link rel="stylesheet" href="style.css" type="text/css">


<form method=post name=f1 onsubmit="return CheckNewPrice()">
  &nbsp; 
  <table width="90%" cellspacing="0" cellpadding="10" align="center" class="form">
    <tr> 
      <td> 
        <div align="right"><font face="Arial, Helvetica, sans-serif" size="4"><b><font color="#FFFFFF">CLASSIFIEDS v2.0</font></b></font></div>
      </td>
    </tr>
  </table>
  &nbsp; 
  <table align=center cellpadding="4" cellspacing="1">
    <tr> 
      <td colspan=2><font color=black face=verdana size=2><b><img src="images/admin/settings.jpg" width="21" height="22" align="absmiddle">&nbsp;ADD 
        NEW PRICE</b></font></td>
    </tr>
    <tr> 
      <td class="form_request">Package name:</td>
      <td class="form_answer"> 
        <input type=text name=PackageName maxlength=50>
      </td>
    </tr>
    <tr> 
      <td class="form_request">Price:</td>
      <td class="form_answer"> 
        <input type=text name=NewPrice size=6 maxlength=6>
      </td>
    </tr>
    <tr> 
      <td class="form_request">Duration:</td>
      <td class="form_answer"> 
        <select name=nDuration>
          <option value=""></option>
          <?
			for($i = '1'; $i <= '12'; $i++)
			{
				echo "<option value=\"$i\">$i</option>\n";
			}
			?>
        </select>
        months </td>
    </tr>
    <tr> 
      <td class="form_request">Priority Level:</td>
      <td class="form_answer"> 
        <select name="pLevel">
          <option value=""></option>
          <?
			//create the Priority level select menu
			$q1 = "select * from yellow_priority order by PriorityLevel asc ";
			$r1 = mysql_query($q1) or die(mysql_error());
			while($a1 = mysql_fetch_array($r1))
			{
				echo "<option value=\"$a1[PriorityLevel]\">$a1[PriorityLevel] - $a1[PriorityName]</option>\n\t";
			}
			?>
        </select>
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td> 
        <input type=submit name=s1 value=Save class=sub>
      </td>
    </tr>
  </table>

</form>

<?

if(isset($_POST[s1]))
{
	$q1 = "insert into yellow_prices set
					PackageName = '$_POST[PackageName]',
					PriceValue = '$_POST[NewPrice]',
					Duration = '$_POST[nDuration]',
					PriorityLevel = '$_POST[pLevel]' ";

	mysql_query($q1) or die(mysql_error());
}

//show prices
$q1 = "select * from yellow_prices, yellow_priority where yellow_prices.PriorityLevel = yellow_priority.PriorityLevel order by yellow_prices.PriorityLevel desc";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) == '0')
{
	exit();
}

?>

<table align=center width=650 cellspacing=0 bordercolor=black frame=below>
<tr>
	<td  class=TableHead width=200>Package Name</td>
	<td class=TableHead>Priority Level</td>
	<td class=TableHead align=center>Duration</td>
	<td class=TableHead align=right>Price</td>
	<td class=TableHead align=center>Action</td>

<?
while($a1 = mysql_fetch_array($r1))
{
	$MyPrice = number_format($a1[PriceValue], 2, ".", "");

	if($a1[Duration] > '1')
	{
		$MyDuration = $a1[Duration]." months";
	}
	else
	{
		$MyDuration = $a1[Duration]." month";
	}

	echo "<tr>\n\t<td>$a1[PackageName]</td>\n\t<td>$a1[PriorityName]</td>\n\t<td align=center>$MyDuration</td>\n\t<td align=right>$MyPrice</td>\n\t<td align=center><a class=GreenLink href=\"PriceEdit.php?PriceID=$a1[PriceID]\">edit</a> | <a class=RedLink href=\"PriceDelete.php?PriceID=$a1[PriceID]\" onclick=\"return CheckDelete();\">delete</a></td>\n</tr>\n\n ";
}

echo "</table>\n\n<br><br>";
?>