@@ -0,0 +1,619 @@
/*
javascript file for manager search ui, adds intuitive functionality
and limited selections (less user error prone)
TO ADD: integrity checking on all fields before submit
TO ADD: delete buttons on conditions
*/

var states = [
{ name: 'ALABAMA', abbreviation: 'AL'},
{ name: 'ALASKA', abbreviation: 'AK'},
{ name: 'ARIZONA', abbreviation: 'AZ'},
{ name: 'ARKANSAS', abbreviation: 'AR'},
{ name: 'CALIFORNIA', abbreviation: 'CA'},
{ name: 'COLORADO', abbreviation: 'CO'},
{ name: 'CONNECTICUT', abbreviation: 'CT'},
{ name: 'DELAWARE', abbreviation: 'DE'},
{ name: 'FLORIDA', abbreviation: 'FL'},
{ name: 'GEORGIA', abbreviation: 'GA'},
{ name: 'HAWAII', abbreviation: 'HI'},
{ name: 'IDAHO', abbreviation: 'ID'},
{ name: 'ILLINOIS', abbreviation: 'IL'},
{ name: 'INDIANA', abbreviation: 'IN'},
{ name: 'IOWA', abbreviation: 'IA'},
{ name: 'KANSAS', abbreviation: 'KS'},
{ name: 'KENTUCKY', abbreviation: 'KY'},
{ name: 'LOUISIANA', abbreviation: 'LA'},
{ name: 'MAINE', abbreviation: 'ME'},
{ name: 'MARYLAND', abbreviation: 'MD'},
{ name: 'MASSACHUSETTS', abbreviation: 'MA'},
{ name: 'MICHIGAN', abbreviation: 'MI'},
{ name: 'MINNESOTA', abbreviation: 'MN'},
{ name: 'MISSISSIPPI', abbreviation: 'MS'},
{ name: 'MISSOURI', abbreviation: 'MO'},
{ name: 'MONTANA', abbreviation: 'MT'},
{ name: 'NEBRASKA', abbreviation: 'NE'},
{ name: 'NEVADA', abbreviation: 'NV'},
{ name: 'NEW HAMPSHIRE', abbreviation: 'NH'},
{ name: 'NEW JERSEY', abbreviation: 'NJ'},
{ name: 'NEW MEXICO', abbreviation: 'NM'},
{ name: 'NEW YORK', abbreviation: 'NY'},
{ name: 'NORTH CAROLINA', abbreviation: 'NC'},
{ name: 'NORTH DAKOTA', abbreviation: 'ND'},
{ name: 'OHIO', abbreviation: 'OH'},
{ name: 'OKLAHOMA', abbreviation: 'OK'},
{ name: 'OREGON', abbreviation: 'OR'},
{ name: 'PENNSYLVANIA', abbreviation: 'PA'},
{ name: 'PUERTO RICO', abbreviation: 'PR'},
{ name: 'RHODE ISLAND', abbreviation: 'RI'},
{ name: 'SOUTH CAROLINA', abbreviation: 'SC'},
{ name: 'SOUTH DAKOTA', abbreviation: 'SD'},
{ name: 'TENNESSEE', abbreviation: 'TN'},
{ name: 'TEXAS', abbreviation: 'TX'},
{ name: 'UTAH', abbreviation: 'UT'},
{ name: 'VERMONT', abbreviation: 'VT'},
{ name: 'VIRGIN ISLANDS', abbreviation: 'VI'},
{ name: 'VIRGINIA', abbreviation: 'VA'},
{ name: 'WASHINGTON', abbreviation: 'WA'},
{ name: 'WEST VIRGINIA', abbreviation: 'WV'},
{ name: 'WISCONSIN', abbreviation: 'WI'},
{ name: 'WYOMING', abbreviation: 'WY' }
];

var months = [
{ name: 'JANUARY'},
{ name: 'FEBRUARY'},
{ name: 'MARCH'},
{ name: 'SEPTEMBER'},
{ name: 'OCTOBER'},
{ name: 'NOVEMBER'},
{ name: 'DECEMBER'},
]

var condCount = 0;
function increment() {
condCount += 1;
document.getElementById("condition_number").value = "" + condCount;
}

function preparePage() {
if (document.getElementById("searchTable").options[0].value === "")
document.getElementById("searchTable").options[0] = null;

// change the attributes depending on selection of searchtable
/* document.getElementById("searchTable").onchange = function() {
var choice = document.getElementById("searchTable").value;
document.getElementById("searchOperand").disabled = true;
document.getElementById("searchAttribute").disabled = false;
removeFormElement("searchField","searchValue");
if (document.getElementById("searchTable").options[0].value === "")
document.getElementById("searchTable").options[0] = null;
if (choice === "customers")
{
removeSelectElements("searchAttribute");
var def = document.createElement("option");
def.setAttribute("value","");
def.innerHTML = "attribute";
var a = document.createElement("option");
a.setAttribute("value","email");
a.innerHTML = "email";
var b = document.createElement("option");
b.setAttribute("value","first_name");
b.innerHTML = "first name";
var c = document.createElement("option");
c.setAttribute("value","last_name");
c.innerHTML = "last name";
document.getElementById("searchAttribute").appendChild(def);
document.getElementById("searchAttribute").appendChild(a);
document.getElementById("searchAttribute").appendChild(b);
document.getElementById("searchAttribute").appendChild(c);
}
else if (choice === "flights")
{
removeSelectElements("searchAttribute");
var def = document.createElement("option");
def.setAttribute("value","");
def.innerHTML = "attribute";
var a = document.createElement("option");
a.setAttribute("value","flight_id_flights");
a.innerHTML = "flight id";
var b = document.createElement("option");
b.setAttribute("value","arrival_code");
b.innerHTML = "arrival airport";
var c = document.createElement("option");
c.setAttribute("value","departure_code");
c.innerHTML = "departure airport";
var d = document.createElement("option");
d.setAttribute("value","distance");
d.innerHTML = "distance";
var e = document.createElement("option");
e.setAttribute("value","arrival_city");
e.innerHTML = "arrival city";
var f = document.createElement("option");
f.setAttribute("value","departure_city");
f.innerHTML = "departure city";
var g = document.createElement("option");
g.setAttribute("value","departure_state");
g.innerHTML = "departure state";
var h = document.createElement("option");
h.setAttribute("value","arrival_state");
h.innerHTML = "arrival state";
document.getElementById("searchAttribute").appendChild(def);
document.getElementById("searchAttribute").appendChild(a);
document.getElementById("searchAttribute").appendChild(b);
document.getElementById("searchAttribute").appendChild(c);
document.getElementById("searchAttribute").appendChild(d);
document.getElementById("searchAttribute").appendChild(e);
document.getElementById("searchAttribute").appendChild(f);
document.getElementById("searchAttribute").appendChild(g);
document.getElementById("searchAttribute").appendChild(h);
}
else if (choice === "orders")
{
removeSelectElements("searchAttribute");
var def = document.createElement("option");
def.setAttribute("value","");
def.innerHTML = "attribute";
var a = document.createElement("option");
a.setAttribute("value","customer_id");
a.innerHTML = "customer id";
var b = document.createElement("option");
b.setAttribute("value","flight_id_orders");
b.innerHTML = "flight id";
document.getElementById("searchAttribute").appendChild(def);
document.getElementById("searchAttribute").appendChild(a);
document.getElementById("searchAttribute").appendChild(b);
}
};
// change attributes based on the selection of search attribute
document.getElementById("searchAttribute").onchange = function () {
var choice = document.getElementById("searchAttribute").value;
document.getElementById("searchOperand").disabled = false;
removeFormElement("searchField","searchValue");
if (document.getElementById("searchAttribute").options[0].value === "")
document.getElementById("searchAttribute").options[0] = null;
if (choice === "email" || choice === "first_name" || choice === "last_name" ||
choice === "arrival_city" || choice === "departure_city" ||
choice === "arrival_code" || choice === "departure_code")
{
removeSelectElements("searchOperand");
var a = document.createElement("option");
a.setAttribute("value","is");
a.innerHTML = "is ";
document.getElementById("searchOperand").appendChild(a);
var b = document.createElement("input");
b.setAttribute("type","text");
b.setAttribute("name","searchValue");
b.setAttribute("id","searchValue");
// limit to 3 characters if airport code
if (choice === "arrival_code" || choice === "departure_code")
{
b.setAttribute("maxlength","3");
}
document.getElementById("searchField").appendChild(b);
}
else if (choice === "flight_id_orders" || choice === "flight_id_flights" ||
choice === "customer_id" || choice === "distance")
{
removeSelectElements("searchOperand");
var a = document.createElement("option");
a.setAttribute("value","less_than");
a.innerHTML = "<";
var b = document.createElement("option");
b.setAttribute("value","equals");
b.innerHTML = "=";
var c = document.createElement("option");
c.setAttribute("value","greater_than");
c.innerHTML = ">";
document.getElementById("searchOperand").appendChild(a);
document.getElementById("searchOperand").appendChild(b);
document.getElementById("searchOperand").appendChild(c);
var d = document.createElement("input");
d.setAttribute("type","number");
d.setAttribute("name","searchValue");
d.setAttribute("id","searchValue");
document.getElementById("searchField").appendChild(d);
}
else if (choice === "departure_state" || choice === "arrival_state")
{
removeSelectElements("searchOperand");
var a = document.createElement("option");
a.setAttribute("value","is");
a.innerHTML = "is ";
document.getElementById("searchOperand").appendChild(a);
var b = document.createElement("select");
b.setAttribute("id","searchValue");
b.setAttribute("name","searchValue");
for (var i = 0; i < states.length; i++)
{
var option = document.createElement("option");
option.text = states[i].name;
option.value = states[i].abbreviation;
b.appendChild(option);
}
document.getElementById("searchField").appendChild(b);
}
}; */
}

// adds a condition clause
function addCondition() {

// create a span clause to house each condition (comprised of table, attribute...)
var condSpan = document.createElement("span");

// create the individual elements that are put into each span (not value yet)
var condLabel = document.createElement("label");
var condTable = document.createElement("select");
var condAttribute = document.createElement("select");
var condOperand = document.createElement("select");

// increment the counter for dynamic ids and
increment();

// set all individual select condition fields to proper ids and names
condLabel.setAttribute("for","conditionTable_" + condCount);
condLabel.innerHTML = "Condition " + condCount + ": ";

condTable.setAttribute("name","conditionTable_" + condCount);
condTable.setAttribute("id","conditionTable_" + condCount);

condAttribute.setAttribute("name","conditionAttribute_" + condCount);
condAttribute.setAttribute("id","conditionAttribute_" + condCount);
condAttribute.disabled = true;

condOperand.setAttribute("name","conditionOperand_" + condCount);
condOperand.setAttribute("id","conditionOperand_" + condCount);
condOperand.disabled = true;

// add default options to all select condition fields
var a = document.createElement("option");
a.setAttribute("value","");
a.innerHTML = "Table";
var b = document.createElement("option");
b.setAttribute("value","customers");
b.innerHTML = "Customers";
var c = document.createElement("option");
c.setAttribute("value","flights");
c.innerHTML = "Flights";
var d = document.createElement("option");
d.setAttribute("value","orders");
d.innerHTML = "Orders";

var e = document.createElement("option");
e.setAttribute("value","");
e.innerHTML = "attribute";

var f = document.createElement("option");
f.setAttribute("value","");
f.innerHTML = "operand";

// append all static options to respective fields
condTable.appendChild(a);
condTable.appendChild(b);
condTable.appendChild(c);
condTable.appendChild(d);

condAttribute.appendChild(e);

condOperand.appendChild(f);

// set the attributes of the condition span and append condition fields
condSpan.setAttribute("id","condition_" + condCount);
condSpan.appendChild(condLabel);
condSpan.appendChild(condTable);
condSpan.appendChild(condAttribute);
condSpan.appendChild(condOperand);

// add the condition to the DOM under conditionField
document.getElementById("conditionField").appendChild(condSpan);
document.getElementById("conditionField").appendChild(document.createElement("br"));
document.getElementById("conditionField").appendChild(document.createElement("br"));

// hold a variable for this specific iteration of condCount
var thisCond = condCount;

// add eventlistener for value change in conditionTable
document.getElementById("conditionTable_" + thisCond).onchange = function() {
var choice = document.getElementById("conditionTable_" + thisCond).value;
document.getElementById("conditionOperand_" + thisCond).disabled = true;
document.getElementById("conditionAttribute_" + thisCond).disabled = false;
removeFormElement("condition_" + thisCond,"conditionValue_" + thisCond);

if (document.getElementById("conditionTable_" + thisCond).options[0].value === "")
document.getElementById("conditionTable_" + thisCond).options[0] = null;

if (choice === "customers")
{
removeSelectElements("conditionAttribute_" + thisCond);
var def = document.createElement("option");
def.setAttribute("value","");
def.innerHTML = "attribute";
var a = document.createElement("option");
a.setAttribute("value","email");
a.innerHTML = "email";
var b = document.createElement("option");
b.setAttribute("value","first_name");
b.innerHTML = "first name";
var c = document.createElement("option");
c.setAttribute("value","last_name");
c.innerHTML = "last name";
document.getElementById("conditionAttribute_" + thisCond).appendChild(def);
document.getElementById("conditionAttribute_" + thisCond).appendChild(a);
document.getElementById("conditionAttribute_" + thisCond).appendChild(b);
document.getElementById("conditionAttribute_" + thisCond).appendChild(c);
}

else if (choice === "flights")
{
removeSelectElements("conditionAttribute_" + thisCond);
var def = document.createElement("option");
def.setAttribute("value","");
def.innerHTML = "attribute";
var a = document.createElement("option");
a.setAttribute("value","flight_id");
a.innerHTML = "flight id";
var b = document.createElement("option");
b.setAttribute("value","arrival_airport");
b.innerHTML = "arrival airport";
var c = document.createElement("option");
c.setAttribute("value","departure_airport");
c.innerHTML = "departure airport";
var d = document.createElement("option");
d.setAttribute("value","distance");
d.innerHTML = "distance";
var e = document.createElement("option");
e.setAttribute("value","arrival_city_state");
e.innerHTML = "arrival city";
var f = document.createElement("option");
f.setAttribute("value","departure_city_state");
f.innerHTML = "departure city";
var g = document.createElement("option");
g.setAttribute("value","departure_state");
g.innerHTML = "departure state";
var h = document.createElement("option");
h.setAttribute("value","arrival_state");
h.innerHTML = "arrival state";
var i = document.createElement("option");
i.setAttribute("value","date");
i.innerHTML = "departure date";
document.getElementById("conditionAttribute_" + thisCond).appendChild(def);
document.getElementById("conditionAttribute_" + thisCond).appendChild(a);
document.getElementById("conditionAttribute_" + thisCond).appendChild(b);
document.getElementById("conditionAttribute_" + thisCond).appendChild(c);
document.getElementById("conditionAttribute_" + thisCond).appendChild(d);
document.getElementById("conditionAttribute_" + thisCond).appendChild(e);
document.getElementById("conditionAttribute_" + thisCond).appendChild(f);
document.getElementById("conditionAttribute_" + thisCond).appendChild(g);
document.getElementById("conditionAttribute_" + thisCond).appendChild(h);
document.getElementById("conditionAttribute_" + thisCond).appendChild(i);
}

else if (choice === "orders")
{
removeSelectElements("conditionAttribute_" + thisCond);
var def = document.createElement("option");
def.setAttribute("value","");
def.innerHTML = "attribute";
var a = document.createElement("option");
a.setAttribute("value","distance");
a.innerHTML = "distance";
var b = document.createElement("option");
b.setAttribute("value","price");
b.innerHTML = "spent";
var c = document.createElement("option");
c.setAttribute("value","flight_count");
c.innerHTML = "flight count";
document.getElementById("conditionAttribute_" + thisCond).appendChild(def);
document.getElementById("conditionAttribute_" + thisCond).appendChild(a);
document.getElementById("conditionAttribute_" + thisCond).appendChild(b);
document.getElementById("conditionAttribute_" + thisCond).appendChild(c);
}
};

// add eventlistener for value change in conditionAttribute and create condValue
document.getElementById("conditionAttribute_" + thisCond).onchange = function () {
var choice = document.getElementById("conditionAttribute_" + thisCond).value;
document.getElementById("conditionOperand_" + thisCond).disabled = false;
removeFormElement("condition_" + thisCond,"conditionValue_" + thisCond);

if (document.getElementById("conditionAttribute_" + thisCond).options[0].value === "")
document.getElementById("conditionAttribute_" + thisCond).options[0] = null;

if (choice === "email" || choice === "first_name" || choice === "last_name" ||
choice === "arrival_city_state" || choice === "departure_city_state" ||
choice === "arrival_airport" || choice === "departure_airport")
{

removeSelectElements("conditionOperand_" + thisCond);
var a = document.createElement("option");
a.setAttribute("value","=");
a.innerHTML = "is ";
document.getElementById("conditionOperand_" + thisCond).appendChild(a);

var b = document.createElement("input");
b.setAttribute("type","text");
b.setAttribute("name","conditionValue_" + thisCond);
b.setAttribute("id","conditionValue_" + thisCond);

// limit to 3 characters if airport code
if (choice === "arrival_airport" || choice === "departure_airport")
{
b.setAttribute("maxlength","3");
}

document.getElementById("condition_" + thisCond).appendChild(b);
}

else if (choice === "flight_id" || choice === "distance" ||
choice === "price" || choice === "spent" ||
choice === "flight_count")
{
if (!document.getElementById("conditionOperand_" + thisCond))
{
document.createElement("conditionOperand_" + thisCond);
}

removeSelectElements("conditionOperand_" + thisCond);
var a = document.createElement("option");
a.setAttribute("value","<");
a.innerHTML = "<";
var b = document.createElement("option");
b.setAttribute("value","=");
b.innerHTML = "=";
var c = document.createElement("option");
c.setAttribute("value",">");
c.innerHTML = ">";
document.getElementById("conditionOperand_" + thisCond).appendChild(a);
document.getElementById("conditionOperand_" + thisCond).appendChild(b);
document.getElementById("conditionOperand_" + thisCond).appendChild(c);

var d = document.createElement("input");
d.setAttribute("type","number");
d.setAttribute("name","conditionValue_" + thisCond);
d.setAttribute("id","conditionValue_" + thisCond);
document.getElementById("condition_" + thisCond).appendChild(d);
}

else if (choice === "departure_state" || choice === "arrival_state")
{
if (!document.getElementById("conditionOperand_" + thisCond))
{
document.createElement("conditionOperand_" + thisCond);
}

removeSelectElements("conditionOperand_" + thisCond);
var a = document.createElement("option");
a.setAttribute("value","=");
a.innerHTML = "is ";
document.getElementById("conditionOperand_" + thisCond).appendChild(a);

var b = document.createElement("select");
b.setAttribute("id","conditionValue_" + thisCond);
b.setAttribute("name","conditionValue_" + thisCond);
for (var i = 0; i < states.length; i++)
{
var option = document.createElement("option");
option.text = states[i].name;
option.value = states[i].name;
b.appendChild(option);
}
document.getElementById("condition_" + thisCond).appendChild(b);
}
else if (choice === "date")
{
removeFormElement("condition_" + thisCond,"conditionOperand_" + thisCond);

var a = document.createElement("select");
a.setAttribute("id","condition_month_" + thisCond);
a.setAttribute("name","condition_month_" + thisCond);

// update options for selection month
for (var i = 0; i<months.length; i++)
{
var option = document.createElement("option");
option.text = months[i].name;
option.value = months[i].name;
a.appendChild(option);
}

document.getElementById("condition_" + thisCond).appendChild(a);

// event listener to change number of days according to selection of month
document.getElementById("condition_month_" + thisCond).onchange = function() {

var choice = document.getElementById("condition_month_" + thisCond).value;

var b = document.createElement("select");
b.setAttribute("id","condition_day_" + thisCond);
b.setAttribute("name","condition_day_" + thisCond);

if (choice === "JANUARY" || choice === "MARCH" || choice === "MAY" ||
choice === "JULY" || choice === "AUGUST" || choice === "OCTOBER" ||
choice === "DECEMBER")
{
for (var i=1; i<32; i++)
{
var dayOption = document.createElement("option");
dayOption.text = i;
dayOption.value = i;
b.appendChild(dayOption);
}
}
else if (choice === "APRIL" || choice === "JUNE" || choice === "SEPTEMBER" ||
choice === "NOVEMBER")
{
for (var i=1; i<31; i++)
{
var dayOption = document.createElement("option");
dayOption.text = i;
dayOption.value = i;
b.appendChild(dayOption);
}
}
else
{
for (var i = 1; i<29; i++)
{
var dayOption = document.createElement("option");
dayOption.text = i;
dayOption.value = i;
b.appendChild(dayOption);
}
}

document.getElementById("condition_" + thisCond).appendChild(b);
}
}
};
}

// remove any generic form element
function removeFormElement(parentDiv,childDiv)
{
if (document.getElementById(childDiv))
{
var child = document.getElementById(childDiv);
var parent = document.getElementById(parentDiv);
parent.removeChild(child);
}
}

// removes all attribute elements of a certain select field form
function removeSelectElements(outerDiv) {
var outer = document.getElementById(outerDiv);
while (outer.options[0])
{
outer.options[0] = null;
}
}

// removes everything related to date fields in conditions
function removeDateStuff() {
var mon = document.getElementById("condition_month_" + thisCond);
var day = document.getElementById("condition_day_" + thisCond);

var cond = document.getElementById("condition_" + thisCond);

removeFormElement(cond,mon);
removeFormElement(cond,day);
}

window.onload = function() {
preparePage();
};
@@ -0,0 +1,138 @@
<!--
file to handle the search request from manager search interface.
Should take in all variables passed through POST, and construct an appropriate
query for the POSTed variables.
-->

<?php

// handle the searchField and condition_number since they are the only assured values
if ($_POST['searchTable'] == "customers")
$search = "customer_id";
else
$search = "flight_id";

$condition_number = $_POST['condition_number'];
$finalSqlQuery = "";
$partSqlQuery = "";
$tablename = 1;
$conditions_togo = $condition_number;

// if condition_number has a value
if ($condition_number)
{
// loop through the conditions
for ($i=1; $i<$condition_number + 1; $i++)
{
$newdata = array();

$newdata['table'] = $_POST['conditionTable_' . $i];
$newdata['attribute'] = $_POST['conditionAttribute_' . $i];

// check if the condition attribute is date (it will have different condition fields)
if ($newdata['attribute'] == "date")
{
$newdata['month'] = $_POST['condition_month_' . $i];
$newdata['day'] = $_POST['condition_day_' . $i];
}
// else, extract values from operand and value
else
{
$newdata['operand'] = $_POST['conditionOperand_' . $i];
$newdata['value'] = $_POST['conditionValue_' . $i];
}

$conditions[$i] = $newdata;

unset($newdata);
}

foreach ($conditions as $j => $values)
{
print "$j {\n";
foreach ($values as $key => $value)
{
print " $key=>$value \n";
}
print "}\n";
print "<br>";
}
print "<br><br><br>";

$partSqlQuery .= "with ";

foreach ($conditions as $j => $values)
{
$conditions_togo -= 1;

// if the table is from orders, create the aggregate sql query
if ($values['table'] == "orders")
{
// handle flight count attribute in orders
if ($values['attribute'] == "orders")
{

}
// hardcoded flights since managers would not add orders condition if searching for flight
$partSqlQuery = $partSqlQuery . "tablename" . $tablename . " as (select orders." . $search . " from orders, flights where orders.flight_id = flights.flight_id group by " . $search . " having sum(" . $values['attribute'] . ") " . $values['operand'] . " " . $values['value'] . " order by " . $search . ")";
}
// else the partial sql query simply has where clauses
else
{
if ($values['table'] == "flights")
$tableid = "flight_id";
else
$tableid = "customer_id";

$partSqlQuery = $partSqlQuery . "tablename" . $tablename . " as (select orders." . $search . " from orders, " . $values['table'] . " where orders." . $tableid . " = " . $values['table'] . "." . $tableid . " and " . $values['table'] . "." . $values['attribute'] . " " . $values['operand'] . " ";

// if the attribute of the condition is text it requires quotes around value
if ($values['attribute'] == "email" || $values['attribute'] == "first_name" ||
$values['attribute'] == "last_name" || $values['attribute'] == "arrival_city_state"
|| $values['attribute'] == "departure_city_state" || $values['attribute'] == "arrival_airport" || $values['attribute'] == "departure_airport" || $values['attribute'] == "departure_state" || $values['attribute'] == "arrival_state")
{
$partSqlQuery = $partSqlQuery . "'" . $values['value'] . "')";
}
else
{
$partSqlQuery = $partSqlQuery . $values['value'] . ")";
}
}
if ($conditions_togo != 0)
$partSqlQuery = $partSqlQuery . ", ";

$finalSqlQuery = $finalSqlQuery . $partSqlQuery;
$tablename += 1;

$partSqlQuery = "";
}

// join all the conditions together (select from part)
$partSqlQuery .= "select tablename1." . $search . " from ";

for ($i=1; $i<$condition_number+1; $i++)
{
if ($i != $condition_number)
$partSqlQuery .= "tablename" . $i . ", ";
else
$partSqlQuery .= "tablename" . $i ." ";
}

$partSqlQuery .= "where ";

// put where clause of join condition
for ($i=1; $i<$condition_number; $i++)
{
if ($i != 1)
$partSqlQuery .= "and ";

$partSqlQuery .= "tablename" . $i . "." . $search . " = " . "tablename" . ($i+1) . "." . $search . " ";
}

$finalSqlQuery .= $partSqlQuery . ";";
print $finalSqlQuery;
}



?>
@@ -0,0 +1,40 @@
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<h2 id="man-search-page-head">Manager Search Interface</h2>
<p class="warning">All items need a value</p>
<form method="post" action="manQueryHandle.php">
<div id="searchField">
<h3>Describe object to search</h3>
<label for="searchTable">Search for: </label>
<select name="searchTable" id="searchTable">
<option value="">Table</option>
<option value="customers">Customers</option>
<option value="flights">Flights</option>
</select>
</div>
<br>
<div id="conditionField">
<h3>Describe conditions that the search object must have</h3>
</div>
<br>
<div id="submitField">
<input type="hidden" name="condition_number" id="condition_number" value="">
<input type="button" value="Add a Condition" id="addConditionButton" onclick="addCondition();">
<input type="submit" value="Search" id="submitButton">
</div>
</form>
<pre>
<?php
if ($_POST) {
echo 'POST array content: <br><br>';
print_r($_POST);
}
?>
</pre>
<script src="./manAddElements.js" language="Javascript" type="text/javascript"></script>
</body>
</html>