<?php
	require_once ('authorize1.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">

<head>
<title>Moreno Travel</title>
<script src="sorttable.js"></script>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <meta http-equiv="content-type"
        content="text/html; charset=utf-8" />

<style>

tr.order { border-bottom: 1px solid }</style>

</head>




<?php include 'admin_header.php'; ?>

<h1>Manage Category to Package Assignments</h1>


<ul>

<i><font color="#C11B17" size="0.5px">Click <a href="admin_addcategory.php" target="blank">here</a> to add a new category.<br>
Click <a href="admin_addpackage.php" target="blank">here</a> to add a new package.<br>
Click <a href="admin_addcategorypackagelink.php" target="blank">here</a> to add a new package to category assignment.<br><br>
</i></font>
<table><tr><td width="300px"><b>Package</b></td><td width="300px"><b>Category</b></td></tr>


<?php
require_once('connectvars.php');

$dbh = mysql_connect(hostname, username, password)

	or die("Unable to connect to MySQL");

mysql_select_db (dbname, $dbh);

$result = mysql_query("SELECT * FROM categorypackagelink cl, category c, packages p WHERE cl.category_id = c.category_id AND cl.package_id = p.package_id ORDER BY p.package_name");

$i = 0;

print "<form name='managecategorypackage' method='post' action='admin_updatecategorypackagelink.php'>\n";

while ($categorypackage = mysql_fetch_array($result)) {
//print $categorypackage['category_id'];
//die();
print"<tr><td>"
?>
<select name="package_id[]"  />  <option value="disabled" >Select a Package:</option> 

 <?php

$dbh = mysql_connect(hostname, username, password)

	or die("Unable to connect to MySQL");

mysql_select_db (dbname, $dbh);



$query = sprintf("SELECT package_name, package_id FROM packages ORDER BY package_name ASC");




$resultp = mysql_query($query);


if (!$resultp) {

    $message  = 'Invalid query: ' . mysql_error() . "\n";

    $message .= 'Whole query: ' . $query;

    die($message);

}


while ($row = mysql_fetch_assoc($resultp)) {

if ($row['package_id']==$categorypackage['package_id']){$selected =  " selected=true ";} else {$selected = "";}
echo "<option value=\"".$row['package_id']. "\"". $selected . ">".$row['package_name']."</option>";

}
?>
</select><br><br>


</td>

<td>
<input type="hidden" name="catpkg_id[]" value="<?php echo $categorypackage['catpkg_id'] ?>">
<select name="category_id[]"  />  <option value="disabled" >Select a Category:</option> 

 <?php

$dbh = mysql_connect(hostname, username, password)

	or die("Unable to connect to MySQL");

mysql_select_db (dbname, $dbh);



$query = sprintf("SELECT category, category_id FROM category ORDER BY category ASC");




$resultc = mysql_query($query);


if (!$resultc) {

    $message  = 'Invalid query: ' . mysql_error() . "\n";

    $message .= 'Whole query: ' . $query;

    die($message);

}


while ($row = mysql_fetch_assoc($resultc)) {

if ($row['category_id']==$categorypackage['category_id']){$selected =  " selected=true ";} else {$selected = "";}
echo "<option value=\"".$row['category_id']. "\"". $selected . ">".$row['category']."</option>";

}
?>
</select><br><br>

</td></tr>

<?php

++$i;
}
print "<tr><td><input type='submit' value='submit' /></td></tr>";
print "</form>";
mysql_close();
?>



</table>
<br><br>




</ul><br><br><br>
</div>

</div>

</body>

</html>