<?php
require_once('../config/config.php');
require_once(CLASS_DIR.'dbClass.php');
$obj = new DBClass();
$obj1 = new DBClass();
$dat = date('Y-m-d');
$headin = 'Add New Package';
$buton = 'Add Package';
$cupage = 'Package';
$sql1 = "SELECT * FROM ".TBL_PACKAGE;
$rs1 = $obj->executeQry($sql1,$link);
$row1 = $obj->fetchrow();	 

if(isset($_GET['action']) && $_GET['action'] == 'edit'){
	$headin = 'Edit Package';
	$buton = 'Edit Package';
	$obj2 = new DBClass();
	$sql = "SELECT * FROM ".TBL_PACKAGE." WHERE id = '".$_GET['id']."' ";
	$rs = $obj2->executeQry($sql,$link);
	$row = $obj2->fetchrow();
}

if(isset($_POST['submit'])){
	
	if($error == ''){
		if($_POST['submit'] == 'Add Package'){
			$sqll = "INSERT INTO ".TBL_PACKAGE." (package_name,package_type,package_amount,package_days,package_desc) VALUES ('".trim($_POST['package_name'])."','".trim($_POST['package_type'])."','".trim($_POST['package_amount'])."','".trim($_POST['package_days'])."','".trim($_POST['package_desc'])."') ";
			$rs2 = $obj->executeQry($sqll,$link);
				if($rs2){
					@header('Location: packages.php?msg=add');
					exit;
				}
		}
	
		if($_POST['submit'] == 'Edit Package'){
			$sqll = "UPDATE ".TBL_PACKAGE." SET package_name = '".trim($_POST['package_name'])."',package_type = '".trim($_POST['package_type'])."',package_amount = '".trim($_POST['package_amount'])."', package_days = '".trim($_POST['package_days'])."', package_desc = '".trim($_POST['package_desc'])."' WHERE id = '".$_GET['id']."'";
			$rs2 = $obj->executeQry($sqll,$link);
			if($rs2){
				@header('Location: packages.php?msg=edit');
				exit;
			}
		}
	}	
}

require_once(INCLUDES_DIR.ADMHEADER); 
?>
<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="29" align="center" class="submenu"><a href="packages.php">Manage Packages</a></td>
    <td align="center" class="submenu">Add New Packages</td>
  </tr>
</table>
<table width="1000" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="17"></td>
  </tr>
  <tr>
    <td><table width="910" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td class="pagehead"><table width="900" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="315" height="35"><?php echo $headin;?></td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#FFFFFF" class="innermain"><table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td height="25"><?php ShowError($error); ShowInfo($info);?></td>
          </tr>
	<form name="pageform" id="pageform" method="post" action="">
          <tr>
            <td valign="top" class="bdr4"><table width="800" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td bgcolor="#990066" class="form_head">Package Details</td>
                </tr>
              <tr>
                <td valign="top" class="form_bg"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="form_txt1">
                  <tr>
                    <td align="right" width="30%">Package Name : </td>
                    <td align="left" width="70%"><input type="text" name="package_name" id="package_name" value="<?php echo ($_POST['package_name'] == '') ? $row['package_name'] : $_POST['package_name']; ?>" /></td>
                  </tr>
                  <tr>
                    <td align="right" width="30%">Package Type : </td>
                    <td align="left" width="70%"><input type="text" name="package_type" id="package_type" value="<?php echo ($_POST['package_type'] == '') ? $row['package_type'] : $_POST['package_type']; ?>" /></td>
                  </tr>
				   <tr>
                    <td align="right" width="30%">Package Amount : </td>
                    <td align="left" width="70%"><input type="text" name="package_amount" id="package_amount" value="<?php echo ($_POST['package_amount'] == '') ? $row['package_amount'] : $_POST['package_amount']; ?>" /></td>
                  </tr>
				   <tr>
                    <td align="right" width="30%">Package Days : </td>
                    <td align="left" width="70%"><input type="text" name="package_days" id="package_days" value="<?php echo ($_POST['package_days'] == '') ? $row['package_days'] : $_POST['package_days']; ?>" /></td>
                  </tr>
				   <tr>
                    <td align="right" width="30%">Package Details : </td>
                    <td align="left" width="70%"><textarea name="package_desc" id="package_desc" cols="30" rows="3"><?php echo ($_POST['package_desc'] == '') ? $row['package_desc'] : $_POST['package_desc']; ?></textarea></td>
                  </tr>
               </table>
			  </td>
              </tr>
              
                  <tr>
                    <td align="center"><input name="submit" type="submit" class="bg_bt" id="button" value="<?=$buton?>" /></td>
                  </tr>
                  </table></td>
              </tr>
</form>
              </table></td>
          </tr>
          </table></td>
      </tr>
      </table></td>
  </tr>
  <tr>
    <td height="40">&nbsp;</td>
  </tr>
</table>

<?php require_once(INCLUDES_DIR.ADMFOOTER); ?>