<?php
ob_start();
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";


if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE); 
} 

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


include "../includes/htmltop.php";

$image_flag = 0;


if(isset($_POST['update']))
{

	$planval =$_POST['chkPeriod'];
	
	$messag='';
	
	 $select_cnt = "SELECT * FROM ".$tableprefix."sellerPlans WHERE plan_Period = '".$planval."' AND plan_Id != ".$_REQUEST['edit_id']." ";
	$result_cnt = mysql_query($select_cnt) or die(mysql_error());
	
	if(mysql_num_rows($result_cnt)>0)
	{
			$message = SEL_PLAN_EXIST;
	}
	
	
	
	/*check whether there is any free plan exists in the database*/	
	$noofFreePlans= mysql_num_rows(mysql_query("SELECT * FROM ".$tableprefix."sellerPlans WHERE plan_Period ='F'"));
	
	/*check whether coupon with the same name exists in the database*/	
 	$select_coupon = "SELECT * FROM ".$tableprefix."sellerPlans WHERE LOWER(plan_Title) = ".GetSQLValueString(strtolower($_POST['ccCode']),"text");
	$result_coupon = mysql_query($select_coupon) or die(mysql_error());
	if(mysql_num_rows($result_coupon)>1)
	{
		$message = PLAN_TITLE_EXIST;
	}	elseif($noofFreePlans>1 && $_POST['chkPeriod']=='F'){
		$message =MULTIPLE_PLANS;
	}
	
	if($message=='')
	{

            if($_POST['chkPeriod']=="F")
                {
                $planAmt = 0;
            }
            else
                {
                $planAmt = $_POST['txtPlanCharge'];
            }
	
	 $update_gift_coupon = "UPDATE ".$tableprefix."sellerPlans
						  	   SET 
							   plan_Title= ".GetSQLValueString($_POST['spPlanTitle'],"text").",
							    plan_Description= ".GetSQLValueString($_POST['spDescription'],"text").",
							    plan_Period= ".GetSQLValueString($_POST['chkPeriod'],"text").",								
							    plan_SubscriptionCharge= ".GetSQLValueString($planAmt,"text")." WHERE plan_Id = ".$_REQUEST['edit_id'];
		
//	echo	$update_gift_coupon .= " WHERE ccID = ".$_REQUEST['edit_id'];								   

		$message = PLANS_UPDATED;
					  
		
		mysql_query($update_gift_coupon) or die(mysql_error());
	
		if($image_flag == 0)
		{	
			header("Location:sellerPlanes.php?".$_GET['qstring']."&txtSearch=".$_GET['txtSearch']."&msg=S");	
		}	
		
				  


	}


}




?>
<body topmargin="0">
<script>
     $(document).ready(function()
{
     var curPlan= $('input[name=chkPeriod]:checked').val();
     if(curPlan=='F')
           {
               $('#spSubCharge').val("0");
               $('#planamt').hide();

           }
           else
               {
                    $('#planamt').show();
           }
});
function checkAddCouponForm()
{

  var form_name = new Array('frmEditCoupon');		
  var display_name = new Array('Coupon Name');
  var count = 2;	

  if(check_fields('frmEditCoupon','ccDiscount'))	
  {
    var curPlan= $('input[name=chkPeriod]:checked').val();

  	 if(trimSpaces(document.frmEditCoupon.spPlanTitle.value==""))
	 {	 
	 	return confirm("<?php echo ENTER_PLAN_TITLE;?>");
		document.frmEditCoupon.spPlanTitle.focus();
		return false;		 	 
	 }
      if(curPlan!='F'){
	 if(!check_numeric(trimSpaces(document.frmEditCoupon.spSubCharge.value)))
	 {
	 
		 return confirm("<?php echo SUB_CHARGE_NUM;?>");
		document.frmEditCoupon.spSubCharge.focus();
		return false;		 
	 
	 }
	 if(trimSpaces(document.frmEditCoupon.spSubCharge.value==""))
	 {	 
		 return confirm("<?php echo ENTER_SUB_CHARGE;?>");
		document.frmEditCoupon.spSubCharge.focus();
		return false;		 	 
	 }
      }
  }
  else
  {
  
  		return false;
  
  }
   
}

function showPlanAmount()
{
     var curPlan= $('input[name=chkPeriod]:checked').val();

     if(curPlan=='F')
           {
               $('#spSubCharge').val("0");
               $('#planamt').hide();
           }
           else
               {
                    $('#planamt').show();
           }
}
</script>

		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo SEL_PLAN_EDIT;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">									
					
					<form name="frmEditCoupon" action="#" method="POST" enctype="multipart/form-data" onSubmit="return checkAddCouponForm();">
					
					<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
																					
					<tr><td colspan="3">&nbsp;</td></tr>
					<tr><td colspan="3" class="message" align="left"><?php echo $message_image;?></td></tr>
					<tr><td colspan="3" align="right"><span class="required">*</span>&nbsp;<?php echo FIELDS_ARE_MANDATORY;?></td></tr>
																											
<?php

	$select_couponCode = "SELECT plan_Id, plan_Title, plan_Description,plan_SubscriptionCharge, plan_Status, plan_Period
								   FROM ".$tableprefix."sellerPlans
								   WHERE plan_Id = ".$_GET['edit_id'];
 	
							   
								   
	$result_couponCode = mysql_query($select_couponCode) or die(mysql_error());
	$result_couponCode_row = mysql_fetch_assoc($result_couponCode);	
	
?>																											
																											
																											
																											
					<tr><td width="26%" align="left" valign=top><?php echo SEL_PLAN_EXIST;?>&nbsp;<span class="required">*</span></td><td width="2%" >&nbsp;</td>
						<td width="72%" align="left" valign=top><input class="textbox" type="text" name="spPlanTitle" value="<?php echo $result_couponCode_row['plan_Title']?>" size="25" maxlength="150"></td>
					</tr>
					<tr>
					  <td align="left" valign=top><?php echo DESCRIPTION;?>&nbsp;</td>
					  <td >&nbsp;</td>
						<td valign=top align="left">
							<textarea name="spDescription" rows="8" cols="60" class="textbox"><?php echo $result_couponCode_row['plan_Description']?></textarea>
							<input type="hidden" name="edit_id" value="<?php echo $_REQUEST['edit_id']?>">
						</td>
					</tr>													
					<tr><td width="26%" align="left" valign=top><?php echo PLAN_PERIOD;?> <span class="required">*</span></td><td width="2%" >&nbsp;</td>
						<td width="72%" align="left" valign=top>
						<input name="chkPeriod" value="M" checked="checked" type="radio"
						<?php
						if($result_couponCode_row['plan_Period']=="M")
						echo 'checked="checked"';
						?> onclick="showPlanAmount();"
						>
						<?php echo MONTHLY;?> <input name="chkPeriod" value="Y" type="radio"
						<?php
						if($result_couponCode_row['plan_Period']=="Y")
						echo 'checked="checked"';
						?> onclick="showPlanAmount();"

						><?php echo YEARLY;?> <input name="chkPeriod" value="F" type="radio"
						<?php
						if($result_couponCode_row['plan_Period']=="F")
						echo 'checked="checked"';
						?> onclick="showPlanAmount();" 

						 ><?php echo FREE_TRIAL;?>
						</td>
					</tr>
                                        <tr id="planamt"><td width="26%" align="left" valign=top><?php echo SUB_CHARGE;?>(<?php echo $adminCurrency['currency_symbol'];?> )&nbsp;<span class="required">*</span></td><td width="2%" >&nbsp;</td>
						<td width="72%" align="left" valign=top><input class="textbox" type="text" name="spSubCharge" value="<?php echo $result_couponCode_row['plan_SubscriptionCharge']?>" size="25" maxlength="150"></td>
					</tr>																
					<tr>
						<td colspan="3" align="center">
							
							<input type="button" class="button" name="back" value="&nbsp;<?php echo BACK;?>&nbsp;" onClick="window.location='sellerPlanes.php'">
                                                        <input type="submit" value="<?php echo UPDATE;?>" name="update" class="button" >
						</td>
					</tr>
					<tr><td colspan="3">&nbsp;</td></tr>
				</table>
				
				</form>
				
				</div>
									
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
		
				
<?php
	include "../includes/footer.php";
	
	ob_end_flush();
?>