<?php session_start();  //Developed by ITechScripts
   $mode=$_GET['mode'];
   $id=$_GET['id'];
   require 'include/configurations.php'; // ITECHBIDS Configuration File
   require 'include/header.php';
?>


<br />

>
<?
$default_currency="select * from genaralsettings where set_id=55";
$default_res=mysql_query($default_currency);
$default_row=mysql_fetch_array($default_res);
$default_cur=$default_row[set_value];

if(isset($_POST['btn_delete']))
{	
	$id=$_POST['id'];
	$pid=$_POST['chkSub'];
	foreach($pid as $plan_id)
	{
	$sql="delete from plan where plan_id=$plan_id";
	$res=mysql_query($sql);
	$message="Plan(s) were deleted Sucessfully";
	}
}
	if($mode=="edit" || $mode=="new") {
	
	 $canSave=$_POST['canSave'];
	 if($canSave==1) {
	 	$plan=$_POST['txtPlan'];
		$scheme=$_POST['txtScheme'];
            $amount=$_POST['txtAmount'];
            $items=$_POST['txtItems'];
            $status=$_POST['cboStatus'];

		if($mode=="edit")
		 $sql="update plan set scheme='$scheme',amount=$amount,items=$items,status='$status' where plan_id=$id";
		else 
		 $sql="insert into plan(scheme,amount,items,status) values ('$scheme',$amount,$items,'$status')";
		$result=mysql_query($sql);
		
		echo '<meta http-equiv="refresh" content="0;url=plan.php">';
		exit();
	 }
		if($mode=="edit") {
			$sql="select * from plan where plan_id=$id";
			$result=mysql_query($sql);
			$row=mysql_fetch_array($result);
		}
?>
<table border="0" align="center" cellpadding="5" cellspacing="2" width="70%" class="ft">
<form name="frmPlan" action="<? $_SERVER['PHP_SELF']?>" method="post" onSubmit="this.canSave.value=1;">
<tr><td colspan="2" class="ct"><b><?=ucwords($mode)?>  Plan</b></td></tr>
<tr>
<td>Plan Name</td>
<td><input type="text" class="bluetext"name="txtScheme" value="<?=$row['scheme']?>"></td>
</tr>
<tr>
<td> Amount</td>
<td><? echo "$default_cur" ?><input type="text" class="bluetext"name="txtAmount" value="<?=$row['amount']?>"></td>
</tr>
<tr>
<td>No. of Bids</td>
<td><input type="text" class="bluetext"name="txtItems" value="<?=$row['items']?>"></td>
</tr>
<tr>
<td>Status</td>
<td><select name="cboStatus">
<option value="">Select</option>
<option value="active" <?  if($row['status']=='active') echo 'Selected'; ?>>Active</option>
<option value="inactive" <?  if($row['status']=='Inactive') echo 'Selected'; ?>>Inactive</option>
</select></td>
</tr>
<tr><td colspan="2" align="center"><input type="hidden" name="canSave" value="0"><input type="submit" class="button"   name="btn_Add" value="<? 
if($mode=='new') echo ' Add ';else if($mode=='edit') echo ' Modify '?>" ></td></tr>
</form>
</table>
<?
	}
	else {
?>
<form name="frm1" method="post">
<table border="0" align="center" cellpadding="5" cellspacing="2" width="100%" class="ft">
<tr><td style="color:#FF0000 "><?=$message; ?></td></tr>
<tr><td>
<table border="0" align="center" cellpadding="5" cellspacing="2" width="100%">
<tr>
  <td class="ct" colspan="7"><B>You Can Manage the Bid Packages</b></td>
  </tr>
<tr >
<td width="19%"><input type="checkbox" name="chkMain" onClick="chkall();" class="check" value=1></td>
   <td width="30%"><strong>Plan name </strong></td>
  <td width="10%"><strong>Amount(<? echo "$default_cur" ?>)</strong></td>
  <td width="15%"><strong>No. Of Bids</strong></td>
  <td width="15%"><strong>Status</strong></td>
    <td width="11%"><strong>Edit</strong></td>
  </tr>
<?
	$sql="select * from plan where status!='Featured'";
	$result=mysql_query($sql);
	$i=1;
	while($row=mysql_fetch_array($result)) {
		if($row['period_type']==1) $p_type='Day';
		if($row['period_type']==2) $p_type='Month';
		if($row['period_type']==3) $p_type='Year';
		?>
<tr >
<td><input name="chkSub[]" id="chkSub" type="checkbox" class="check" value="<?=$row['plan_id']; ?>">
 <input type="hidden" name="id[]" value="<?php echo $row['plan_id']; ?>"> </td>
  <td><?=$row['scheme'];?></td>
  <td><? echo "$default_cur" ?><?=$row['amount'];?></td>
<td> <?= $row[items]; ?>   </td>
  <td> <?= $row[status]; ?>   </td>
  <td>
  <a href="plan.php?mode=edit&id=<?=$row['plan_id']?>">Edit</a> </td>
  </tr>
<?
$i++;
	}
?>
<tr><td>
<input type="submit" class="button"   name="btn_delete" value=" Delete " >
</td>
  <td colspan="6" align="left"><a href="plan.php?mode=new">
   Add New
  </a></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?
	}

?>
<script language="javascript">
function chkall() {
	len=document.frm1.chkSub.length;
	if(len > 1) {
	for(i=0;i<len;i++) {
		if(document.frm1.chkMain.checked==true) {
			document.frm1.chkSub[i].checked=true;
		}
		else {
			document.frm1.chkSub[i].checked=false;
		}
	}
	}
	else {
		if(document.frm1.chkMain.checked==true) {
			document.frm1.chkSub.checked=true;
		}
		else {
			document.frm1.chkSub.checked=false;
		}
	
	}
	}

</script>
<? require 'include/footer.php'?>