<?php 
include("header.php");
include("sidebar.php");

$msg="";$name="";$amount="";$dnumber="";$duarion="";$status="";$caption="Add"; $botton="add";
//echo'<pre>';print_r($_POST);exit;
if(isset($_GET['id']))
{
	$sqlcheck1=mysql_query("select * from tbl_package where pid='".$_GET['id']."'");
	$rescheck1=mysql_fetch_assoc($sqlcheck1);
	
	$name=$rescheck1['name'];
	$amount=$rescheck1['amount'];
	$dnumber=$rescheck1['dnumber'];
	$duarion=$rescheck1['duration'];
	$status=$rescheck1['status'];
	
	/*$caption="Update"; $botton="update";
	if(isset($_POST['update']))
	{
		$maincategory=mysql_real_escape_string(ucwords($_POST['maincategory']));
		
		$update=mysql_query("update tbl_maincategory set status='".$_POST['status']."',name='$maincategory' where mcid='".$_GET['id']."'");
		
		$msg="Main category update successfully";
		
		?>
		<script>
        setTimeout(function(){
			window.location="maincategory.php";
			},2000);
        </script>
		<?php
	}*/
	
}


if(isset($_POST['add']))
{
	$package=mysql_real_escape_string(ucwords($_POST['package']));
	$amount=mysql_real_escape_string(ucwords($_POST['amount']));
	$duarion=$_POST['duarion_num']." ".$_POST['duarion'];
	$status=mysql_real_escape_string(ucwords($_POST['status']));
	
	
	$sqlcheck=mysql_query("select * from tbl_package where name='$package'");
	if(mysql_num_rows($sqlcheck)==0)
	{
		$insert=mysql_query("insert into tbl_package(name,amount,dnumber,duration,status) values('$package','$amount','".$_POST['duarion_num']."','".$_POST['duarion']."','$status')");
		
		$msg="Package add successfully";
		?>
		<script>
       setTimeout(function(){
			window.location.href=window.location.href;
			},2000);
        </script>
		<?php
	}
	else
	{
		if(isset($_GET['id']))
		{
			$update=mysql_query("update tbl_package set name='$package',amount='$amount',dnumber='".$_POST['duarion_num']."',duration='".$_POST['duarion']."',status='$status' where pid='".$_GET['id']."'");
			
			$msg="Package update successfully";
			
			?>
		<script>
       setTimeout(function(){
			window.location="packages.php";
			},2000);
        </script>
		<?php
		}
	}
}

?>


  <!-- Page -->
  <div class="page animsition">
    <div class="page-header">
      <h1 class="page-title">Category</h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php">Home</a></li>
        <li><a href="maincategory.php">Category</a></li>
      </ol>
      <!-- <div class="page-header-actions">
        
        <button type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round"
        data-toggle="tooltip" data-original-title="Refresh">
          <i class="icon wb-refresh" aria-hidden="true"></i>
        </button>
        <button type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round"
        data-toggle="tooltip" data-original-title="Setting">
          <i class="icon wb-settings" aria-hidden="true"></i>
        </button>
      </div>-->
    </div>
    <?php if($msg==!"")
	{
		
		?>
			<div class="alert alert-info alert-dismissible" role="alert">
                  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
                  <?php echo $msg;?>
                </div>
		<?php
	}
    ?>
    <div class="page-content container-fluid">
      <div class="row">
        <div class="col-sm-12">
          <!-- Panel Static Lables -->
          <div class="panel">
            <div class="panel-heading">
              <h3 class="panel-title">Add Main Category</h3>
            </div>
            <div class="panel-body container-fluid">
              <form method="post">
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Package Title</label>
                  <input type="text" class="form-control" id="inputText" name="package" required value="<?php echo $name;?>" placeholder="Enter Package Title"
                  />
                </div>
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Package Amount</label>
                  <input type="number" class="form-control" id="inputText" name="amount" required value="<?php echo $amount;?>" placeholder="Enter Package Amount"
                  />
                </div>
                
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Package Duration</label>
                  <select name="duarion_num" class="form-control" required>
                  	<option value="">Select Please</option>
                    <option <?php if($dnumber=="1") { echo "selected";} ?> value="1">1</option>
                    <option <?php if($dnumber=="2") { echo "selected";} ?> value="2">2</option>
                    <option <?php if($dnumber=="3") { echo "selected";} ?> value="3">3</option>
                    <option <?php if($dnumber=="4") { echo "selected";} ?> value="4">4</option>
                    <option <?php if($dnumber=="5") { echo "selected";} ?> value="5">5</option>
                    <option <?php if($dnumber=="6") { echo "selected";} ?> value="6">6</option>
                    <option <?php if($dnumber=="7") { echo "selected";} ?> value="7">7</option>
                    <option <?php if($dnumber=="8") { echo "selected";} ?> value="8">8</option>
                    <option <?php if($dnumber=="9") { echo "selected";} ?> value="9">9</option>
                    <option <?php if($dnumber=="10") { echo "selected";} ?> value="10">10</option>
                    <option <?php if($dnumber=="11") { echo "selected";} ?> value="11">11</option>
                    <option <?php if($dnumber=="12") { echo "selected";} ?> value="12">12</option>
                  </select>
                  
                  <select name="duarion" class="form-control" required>
                  	<option value="">Select Please</option>
                    <option <?php if($duarion=="days") { echo "selected";} ?> value="days">Days</option>
                    <option <?php if($duarion=="weeks") { echo "selected";} ?> value="weeks">Weeks</option>
                    <option <?php if($duarion=="months") { echo "selected";} ?> value="months">Months</option>
                    <option <?php if($duarion=="years") { echo "selected";} ?> value="years">Years</option>
                  </select>
                </div>
              
                <div class="form-group form-material">
                  <label class="control-label" for="inputText">Status</label>
                    <select name="status" class="form-control" required>
                        <option value="">Please Select</option>
                        <option <?php if($status=="Enable") { echo "selected";}?> value="Enable">Enable</option>
                        <option <?php if($status=="Disable") { echo "selected";}?> value="Disable">Disable</option>
                    
                    </select>
                </div>
				
               
                
                <div class="form-group form-material row">
                  <div class="col-xs-12 col-sm-4 col-lg-2">
                  <button type="submit" name="<?php echo $botton?>" class="btn btn-block btn-primary"><?php echo $caption?></button>
                  </div>
                </div>
              </form>
            </div>
          </div>
          <!-- End Panel Static Lables -->
        </div>

        
      </div>
    </div>
    
    <div class="page-content">
      <!-- Panel Basic -->
      <div class="panel">
        <header class="panel-heading">
          <div class="panel-actions"></div>
          <h3 class="panel-title">Main Category Details</h3>
        </header>
        <div class="panel-body">
          <table class="table table-hover dataTable table-striped width-full" data-plugin="dataTable">
            <thead>
              <tr>
                <th>Name</th>
                <th>Amount</th>
                <th>Duration</th>
                <th>Status</th>
                <th>Action</th>
               
              </tr>
            </thead>
           
            <tbody>
              
              <?php
			  
			  $sqlmaincat=mysql_query("select * from tbl_package");
			  if(mysql_num_rows($sqlmaincat))
			  {
			  while($resmaincat=mysql_fetch_assoc($sqlmaincat))
			  {?>
              <tr>
                <td><?php echo $resmaincat['name']?></td>
                <td><?php echo $resmaincat['amount']?></td>
                <td><?php echo $resmaincat['dnumber']." ".$resmaincat['duration']?></td>
                <td><?php echo $resmaincat['status']?></td>
                <td><a href="packages.php?id=<?php echo $resmaincat['pid']?>" type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round" data-toggle="tooltip"  data-original-title="Edit"><i class="icon wb-pencil" aria-hidden="true"></i></a>
               <a id="<?php echo $resmaincat['pid']?>" type="button" class="btn btn-sm btn-icon btn-default btn-outline btn-round delete" data-toggle="tooltip"  data-original-title="Delete"><i class="icon wb-trash" aria-hidden="true"></i></a></td>
              </tr>
              <?php } }?>
            
             
            </tbody>
          </table>
        </div>
      </div>
    
    </div>
    
    
  </div>
  
 
  <!-- End Page -->


  <!-- Footer -->
<?php 
include("footer.php");
?>
<script>
$(".delete").click(function(){
var id=$(this).attr('id');

$(this).closest('tr').fadeOut();

$.post("ajax/ajax_delete_packege.php",{id:id},function(data){
	//alert(data);
	
	});
});
</script>