<?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 City to Package Assignments</h1>


<ul>

<i><font color="#C11B17" size="0.5px">Click <a href="admin_addcity.php" target="blank">here</a> to add a new city.<br>
Click <a href="admin_addpackage.php" target="blank">here</a> to add a new package.<br>
Click <a href="admin_addcitypackagelink.php" target="blank">here</a> to add a new package to city assignment.<br><br>
</i></font>
<table><tr><td width="300px"><b>Package</b></td><td width="300px"><b>city</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 citiespackagelink cl, cities c, packages p WHERE cl.city_id = c.city_id AND cl.package_id = p.package_id");

$i = 0;

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

while ($citypackage = mysql_fetch_array($result)) {
//print $citypackage['city_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']==$citypackage['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="citypkg_id[]" value="<?php echo $citypackage['citypkg_id'] ?>">
<select name="city_id[]"  />  <option value="disabled" >Select a city:</option> 

 <?php

$dbh = mysql_connect(hostname, username, password)

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

mysql_select_db (dbname, $dbh);



$query = sprintf("SELECT city_name, city_id FROM cities ORDER BY city_name 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['city_id']==$citypackage['city_id']){$selected =  " selected=true ";} else {$selected = "";}
echo "<option value=\"".$row['city_id']. "\"". $selected . ">".$row['city_name']."</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>