<?php
global $wpdb,$price_db_table_name;
if($_POST['priceact'] == 'addprice')
{
	$id = $_POST['id'];
	$title = $_POST['title'];
	$amount = $_POST['amount'];
	$days = $_POST['days'];
	$status = $_POST['status'];
	$cat = $_POST['cat'];

	if($id)
	{
		$wpdb->query("update $price_db_table_name set title=\"$title\", amount=\"$amount\", days=\"$days\", status=\"$status\",cat=\"$cat\" where pid=\"$id\"");
	}else
	{
		$wpdb->query("insert into $price_db_table_name (title,amount,days,status,cat) values (\"$title\",\"$amount\",\"$days\",\"$status\",\"$cat\")");
	}
	$location = get_option('siteurl')."/wp-admin/admin.php";
	echo '<form action="'.$location.'" method=get name="price_success">
	<input type=hidden name="page" value="price"><input type=hidden name="msg" value="success"></form>';
	echo '<script>document.price_success.submit();</script>';
	exit;
}
if($_REQUEST['id']!='')
{
	$pid = $_REQUEST['id'];
	$pricesql = "select * from $price_db_table_name where pid=\"$pid\"";
	$priceinfo = $wpdb->get_results($pricesql);
}
?>

<form action="<?php echo get_option('siteurl')?>/wp-admin/admin.php?page=price&pagetype=addedit&pid=<?php echo $_REQUEST['id'];?>" method="post" name="price_frm">
  <input type="hidden" name="priceact" value="addprice">
  <input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>">
  <style>
h2 { color:#464646;font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif;
font-size:24px;
font-size-adjust:none;
font-stretch:normal;
font-style:italic;
font-variant:normal;
font-weight:normal;
line-height:35px;
margin:0;
padding:14px 15px 3px 0;
text-shadow:0 1px 0 #FFFFFF;  }
</style>
  <h2>
    <?php
if($_REQUEST['id']!='')
{
	_e('Edit Price');
}else
{
	_e('Add Price');
}
?>
  </h2>
  <table width="75%" cellpadding="3" cellspacing="3" class="widefat post fixed" >
    <tr>
      <td width="14%"><?php _e('Price Title');?></td>
      <td width="86%">:
        <input type="text" name="title" id="title" value="<?php echo $priceinfo[0]->title;?>"></td>
    </tr>
    <tr>
      <td><?php _e('Price Amount');?> (<?php echo get_option('site_paypal_currency_code');?>)</td>
      <td>:
        <input type="text" name="amount" value="<?php echo $priceinfo[0]->amount;?>">
       </td>
    </tr>
    <tr>
      <td><?php _e('Number of Days');?></td>
      <td>:
         <input type="text" name="days" value="<?php echo $priceinfo[0]->days;?>">
      </td>
    </tr>
     <tr>
      <td><?php _e('Select Category');?></td>
      <td>:
      <select name="cat">
      <option value=""><?php _e('Select Category');?></option>
       <?php $cat_info = get_eventcategory_array();
	  for($i=0;$i<count($cat_info);$i++){?>
      <option value="<?php echo $cat_info[$i]['id'];?>" <?php if($cat_info[$i]['id']==$priceinfo[0]->cat){ echo 'selected="selected"';}?> ><?php echo $cat_info[$i]['title'];?>
      <?php }?>
      </option>
      </select>
      </td>
    </tr>
    <tr>
      <td><?php _e('Status');?></td>
      <td>:
      <select name="status" >
      <option value="1" <?php if($priceinfo[0]->status=='1'){ echo 'selected="selected"';}?> ><?php _e("Active");?></option>
      <option value="0" <?php if($priceinfo[0]->status=='0'){ echo 'selected="selected"';}?> ><?php _e("Inactive");?></option>
      </select>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="submit" value="<?php _e('Submit');?>" onclick="return check_frm();" class="button-secondary action" >
        &nbsp;
        <input type="button" name="cancel" value="<?php _e('Cancel');?>" onClick="window.location.href='<?php echo get_option('siteurl')?>/wp-admin/admin.php?page=price'" class="button-secondary action" ></td>
    </tr>
  </table>
</form>
<script>
function check_frm()
{
	if(document.getElementById('title').value=='')
	{
		alert("<?php _e('Please enter Title');?>");
		return false;
	}
	return true;
}
</script>