<?
echo "<center><b><h2>".ucfirst($view)."s</b></center><br>";
if($searchfor) {
$where = "AND $searchby";
if($startswith) {
$where = $where . " LIKE \"$searchfor%\"";
} else {
$where = $where . " LIKE \"%$searchfor%\"";
}
}
if($orderby) {
$order = "ORDER BY $orderby $dir";
}
if(!$limit) {
$limit = 10;
}
if(!$start) {
$start = 0;
}
$next = $start + $limit;
$previous = $start - $limit;
if($limit != 1000) {
$limitby = "LIMIT $start,$limit";
}
$query = "SELECT maindata.ID, maindata.dataType, maindata.Name, contacts.Name AS 'Contact', phone.Number, contacts.Extention, ";
$query = $query . "maindata.Address, maindata.City, maindata.State, maindata.Status, maindata.URL ";
$query = $query . "FROM maindata LEFT JOIN phone ON maindata.ID = phone.linkID LEFT JOIN contacts ON phone.ID = contacts.ID ";
$query = $query . "GROUP BY maindata.ID HAVING maindata.dataType=\"$view\" $where $order";
$result = mysql_query($query);
$tnum = mysql_num_rows($result);
// need to fix this query so it selects the phone number and subsequent contact information sorted by phone.Main
$query = "SELECT maindata.ID, maindata.dataType, maindata.Name, contacts.Name AS 'Contact', phone.Number, contacts.Extention, ";
$query = $query . "maindata.Address, maindata.City, maindata.State, maindata.Status, maindata.URL ";
$query = $query . "FROM maindata LEFT JOIN phone ON maindata.ID = phone.linkID LEFT JOIN contacts ON phone.ID = contacts.ID ";
$query = $query . "GROUP BY maindata.ID HAVING maindata.dataType=\"$view\" $where $order $limitby";
$result = mysql_query($query);
$num = mysql_num_rows($result);
echo "<form name='filter' method='post' action='index.php?view=$view'>";
echo "<table bgcolor='000000' cellpadding=0 border=0 cellspacing=0 align='center' width='80%'>\n";
echo "\t<tr>\n";
echo "\t\t<td>\n";
echo "\t\t\t<table cellpadding=0 border=0 cellspacing=1 width='100%'>\n";
echo "\t\t\t\t<tr>\n";
echo "\t\t\t\t\t<td colspan=2 bgcolor='#FFFFFF'> Search by:<input type='radio' name='searchby' value='maindata.Name' ";
if(($searchby == "maindata.Name") || ($searchby == "")) { echo "checked"; }
echo ">".ucfirst($view)." Name";
echo " Starts with : <input type='checkbox' name='startswith' value='true' ";
if($startswith) { echo "checked"; }
echo "> <input type='text' name='searchfor' class='frmStyle' value='$searchfor'> <input type='button' value='Search' class='frmStyle' onClick='filter.submit();'> <input type='button' value='Reset' class='frmStyle' onClick=\"location.href='index.php?view=$view'\"></td>";
echo "\t\t\t\t</tr>";
echo "\t\t\t\t<tr>\n";
echo "\t\t\t\t\t<td bgcolor='#FFFFFF'> Order by: <select name='orderby' onChange='filter.submit();'";
echo "<option value='maindata.Name' ";
if($orderby == "maindata.Name") { echo "selected"; }
echo ">".ucfirst($view)." Name</option>";
echo "<option value='contacts.Name' ";
if($orderby == "contacts.Name") { echo "selected"; }
echo ">Contact Name</option>";
echo "<option value='maindata.City' ";
if($orderby == "maindata.City") { echo "selected"; }
echo ">City</option>";
echo "<option value='maindata.State' ";
if($orderby == "maindata.State") { echo "selected"; }
echo ">State</option>";
echo "<option value='maindata.Status' ";
if($orderby == "maindata.Status") { echo "selected"; }
echo ">Status</option>";
echo "</select> <select name='dir' onChange='filter.submit();'";
echo "<option value='ASC' ";
if($dir == "ASC") { echo "selected"; }
echo ">Ascending</option>";
echo "<option value='DESC' ";
if($dir == "DESC") { echo "selected"; }
echo ">Descending</option>";
echo "</select>";
echo "</td><td bgcolor='#FFFFFF' align='right' width='50%'>";
echo " Show <select name='limit' onChange='filter.submit();'>";
echo "<option value=10 ";
if($limit == 10) { echo "selected"; }
echo ">10</option>";
echo "<option value=20 ";
if($limit == 20) { echo "selected"; }
echo ">20</option>";
echo "<option value=50 ";
if($limit == 50) { echo "selected"; }
echo ">50</option>";
echo "<option value=1000 ";
if($limit == 1000) { echo "selected"; }
echo ">All</option>";
echo "</select> per page</td>";
echo "\t\t\t\t</tr>";
echo "\t\t\t</table>\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "<tr><td><table bgcolor='#ffffff' cellpadding=0 border=0 cellspacing=1 width='100%'>";
echo "<tr><td ";
if($start) {
echo "bgcolor='#cccccc' width='10%' align=center style='cursor : pointer;' onClick=\"location.href='index.php?page=$page&view=$view&start=$previous'\">previous";
} else {
echo "> ";
}
echo "</td><td> </td><td ";
if($start +1 < $tnum) {
echo "bgcolor='#cccccc' width='10%' align=center style='cursor : pointer;' onClick=\"location.href='index.php?page=$page&view=$view&start=$next'\">next";
} else {
echo "> ";
}
echo "</td></tr></table></td></tr>";
echo "\t<tr>\n";
echo "<td align='right' bgcolor='#ffffff'><input type='button' class='frmStyle' name='add' value='Add ".ucfirst($view)."' onClick=\"NewWindow('index.php?page=add.php&view=$view&nonav=1','popped','400','320','yes');return false\"></td>";
echo "\t</tr>\n";
echo "</table>\n";
echo "</form>";
if(mysql_num_rows($result)) {
echo "<table bgcolor='000000' cellpadding=0 border=0 cellspacing=0 align='center' width='80%'>\n";
echo "\t<tr>\n";
echo "\t\t<td>\n";
echo "\t\t\t<table cellpadding=0 border=0 cellspacing=1 width='100%'>\n";
$num = mysql_num_fields($result);
echo "\t\t\t\t<tr>\n";
while($rnum != $num) {
$col_value = mysql_field_name($result, $rnum);
if(($col_value != "ID") && ($col_value != "dataType") && ($col_value != "Main")) {
echo "\t\t\t\t\t<td bgcolor='D3DCE3' align='center'><b>$col_value</b></td>\n";
}
$rnum++;
}
echo "\t\t\t\t</tr>\n";
echo "\t\t\t\t<tr>\n";
echo "\t\t\t\t\t<td colspan=$num bgcolor='cccccc' height='1'><img src='' height=1 width=1></td>\n";
echo "\t\t\t\t</tr>\n";
$color = 'FFFFFF';
$num = 0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$key = array_search('Inactive', $line);
$strike = "";
$strikelink = "";
if($key) {
$strike = "class='inactive'";
$strikelink = "class='ilink'";
}
echo "\t\t\t\t<tr bgcolor='#$color' $strike style=\"cursor: pointer;\" onMouseover=\"this.bgColor='#FFADAE';\" onMouseout=\"this.bgColor='#$color';\">\n";
foreach ($line as $col_value) {
$findhttp = array_search($col_value, $line);
$findID = array_search($col_value, $line);
if(($findID != "ID") && ($findID != "dataType") && ($findID != "Main")) {
if($findhttp != "URL") {
echo "\t\t\t\t\t<td align='center'onClick=\"location.href='index.php?page=edit.php&view=$view&ID=$line[ID]';\">$col_value</td>\n";
} else {
echo "\t\t\t\t\t<td align='center' bgcolor='#$color'><a href='$col_value' target='blank' $strikelink>$col_value</a></td>\n";
}
}
}
echo "\t\t\t\t</tr>\n";
if($color == 'FFFFFF') {
$color = 'CCCCCC';
} else {
$color = 'FFFFFF';
}
}
echo "\t\t\t</table>\n";
echo "\t\t</td>\n";
echo "\t</tr>\n";
echo "</table>\n";
} else {
echo "<center><font color='red' size=2>No ".ucfirst($view)."s found</font>";
}
mysql_free_result($result);
mysql_close($link);
?>