<?php session_start();
// Turn off all error reporting
error_reporting(0);
require_once "db_conn.php";
require_once "header.php";
//do_header();
$table_name = "items";
$id_col_name = "itemID";
$key_title_pairs = array(
'itemID' => 'Item ID',
'title' => 'Title',
'subtitle' => 'Subtitle',
'URL' => 'URL',
'numberOfBids' => 'Bids',
'bidPrice' => 'Bid Price',
'binPrice' => 'BIN Price',
'boPrice' => 'BestOff Price',
'endTime' => 'End Date',
);
$bool_pairs = array(
'auctionB' => 'Auction',
'NauctionB' => 'Not Auction',
'buy_it_nowB' => 'Buy It Now',
'Nbuy_it_nowB' => 'Not Buy It Now',
'best_offerB' => 'Best Offer',
'Nbest_offerB' => 'Not Best Offer',
'soldB' => 'Sold',
'NsoldB' => 'Not Sold',
'NpaypalB' => 'Not Paypal',
'paypalB' => 'Paypal',
'free_shippingB' => 'Free Shipping',
'Nfree_shippingB' => 'Not Free Shipping',
);
$important_keys = array(
'id_limit_type',
'id_limit_value',
'order_time',
'end_date',
'distinct',
'distinct_count',
'min_count',
'max_count',
'display',
'EmpID',
'expire_in_days',
'expire_days'
);
$session_save_keys = array(
'ua',
'display_name',
'justsetname',
'pwhash',
'loggedemail',
'firstlogin',
'secondlogin',
'loginerror'
);
$no_sort_keys = array(
'Telephone',
'Address',
'DOHHalfsheet',
'NYSCert',
'Physical',
'Fitness'
);
foreach ( $session_save_keys as $key ) {
$SESSION_BACKUP[$key] = $_SESSION[$key];
}
if ( $_POST['Update'] ) {
// Make sure the old data from other options isn't lost
$_GET['field'] = $_SESSION['field'];
$_GET['direction'] = $_SESSION['direction'];
$_GET['debug'] = $_SESSION['debug'];
$_SESSION = array(); // clear previous session data
$_SESSION = $_POST; // turn all posted information into session information
}
$init = TRUE;
foreach ( $key_title_pairs as $key => $title ) {
if( $_SESSION[$key] ) {
$init = FALSE;
}
}
if ( $_GET ) {
foreach ( $key_title_pairs as $key => $title ) {
if ( $_GET[$key] && !$_GET['noinit'] ) {
$init = TRUE;
}
}
foreach ( $bool_pairs as $key => $title ) {
if ( $_GET[$key] && !$_GET['noinit'] ) {
$init = TRUE;
}
}
if ( $_GET['offset'] ) {
$_SESSION['offset'] = $_GET['offset'];
}
if ( $_GET['distinct'] ) {
$_SESSION['distinct'] = $_GET['distinct'];
}
if ( $_GET['distinct_count'] ) {
$_SESSION['distinct_count'] = $_GET['distinct_count'];
}
if ( $_GET['expire_in_days'] ) {
$_SESSION['expire_in_days'] = $_GET['expire_in_days'];
}
if ( $_GET['expire_days'] ) {
$_SESSION['expire_days'] = $_GET['expire_days'];
}
if ( $_GET['debug'] ) {
$_SESSION['debug'] = $_GET['debug'];
}
}
if ( $init OR $_POST['reset'] or $_GET['reset'] ) { // Initialzing default values
$_SESSION = array();
$_SESSION['item_id'] = "yes";
$_SESSION['title'] = "yes";
$_SESSION['subtitle'] = "yes";
$_SESSION['display'] = "table";
$_SESSION['num_records'] = "50";
$_SESSION['expire_days'] = "00";
$_SESSION['expire_in_days'] = "00";
}
if ( $_GET['resetWorkers'] ) {
$_SESSION['expire_days'] = "00";
$_SESSION['expire_in_days'] = "00";
foreach ( $bool_pairs as $key => $title ) {
unset( $_SESSION[$key] );
}
}
if ( $_GET ) {
foreach ( $key_title_pairs as $key => $title ) {
if ( $_GET['resetothers'] ) {
unset( $_SESSION[$key] );
}
if ( $_GET[$key] ) {
$_SESSION[$key] = $_GET[$key];
}
}
foreach ( $bool_pairs as $key => $title ) {
if ( $_GET['resetothers'] ) {
unset( $_SESSION[$key] );
}
if ( $_GET[$key] ) {
$_SESSION[$key] = $_GET[$key];
}
}
foreach ( $important_keys as $key ) {
if ( $_GET['resetothers'] ) {
unset( $_SESSION[$key] );
}
if ( $_GET[$key] ) {
$_SESSION[$key] = $_GET[$key];
}
}
}
$valid_halfsheet = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN fedhalfsheet ON employee.EmpID = fedhalfsheet.EmpID
WHERE DATE_ADD( fedhalfsheet.Issue_Date, INTERVAL 1 YEAR )
>= DATE_ADD( NOW(), INTERVAL $_SESSION[expire_days] DAY ) )";
$valid_hardcard = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN hardcard ON employee.EmpID = hardcard.EmpID
WHERE Expire_Date
>= DATE_ADD( NOW(), INTERVAL $_SESSION[expire_days] DAY ) )";
$valid_physical = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN physfit ON employee.EmpID = physfit.EmpID
WHERE DATE_ADD( physfit.Issue_Date, INTERVAL 1 YEAR )
>= DATE_ADD( NOW(), INTERVAL $_SESSION[expire_days] DAY )
AND FType='Physical' )";
$valid_fitness = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN physfit ON employee.EmpID = physfit.EmpID
WHERE DATE_ADD( physfit.Issue_Date, INTERVAL 1 YEAR )
>= DATE_ADD( NOW(), INTERVAL $_SESSION[expire_days] DAY )
AND FType='Fitness' )";
$invalid_halfsheet = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN fedhalfsheet ON employee.EmpID = fedhalfsheet.EmpID
WHERE DATE_ADD( fedhalfsheet.Issue_Date, INTERVAL 1 YEAR )
< DATE_ADD( NOW(), INTERVAL $_SESSION[expire_in_days] DAY )
AND Issue_Date IN
( SELECT MAX(Issue_Date) FROM fedhalfsheet
WHERE EmpID = employee.EmpID
)
)";
$invalid_hardcard = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN hardcard ON employee.EmpID = hardcard.EmpID
WHERE Expire_Date
< DATE_ADD( NOW(), INTERVAL $_SESSION[expire_in_days] DAY )
AND Expire_Date IN
( SELECT MAX(Expire_Date) FROM hardcard
WHERE EmpID = employee.EmpID
)
)";
$invalid_physical = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN physfit ON employee.EmpID = physfit.EmpID
WHERE DATE_ADD( physfit.Issue_Date, INTERVAL 1 YEAR )
< DATE_ADD( NOW(), INTERVAL $_SESSION[expire_in_days] DAY )
AND FType='Physical'
AND Issue_Date IN
( SELECT MAX(Issue_Date) FROM physfit
WHERE EmpID = employee.EmpID
AND FType='Physical'
)
)";
$invalid_fitness = "EmpID IN
( SELECT employee.EmpID FROM employee
LEFT JOIN physfit ON employee.EmpID = physfit.EmpID
WHERE DATE_ADD( physfit.Issue_Date, INTERVAL 1 YEAR )
< DATE_ADD( NOW(), INTERVAL $_SESSION[expire_in_days] DAY )
AND FType='Fitness'
AND Issue_Date IN
( SELECT MAX(Issue_Date) FROM physfit
WHERE EmpID = employee.EmpID
AND FType='Fitness'
)
)";
$where_clause_here = FALSE;
foreach ( $bool_pairs as $key => $title ) {
if ( $_SESSION[$key] ) {
if ( $key == "all_valid_certB" ) {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " ( $valid_halfsheet AND $valid_hardcard AND $valid_physical AND $valid_fitness )";
} elseif ( $key == "at_least_one_invalidB" ) {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " ( $invalid_halfsheet OR $invalid_hardcard OR $invalid_physical OR $invalid_fitness )";
} elseif ( $key == "missing_certB" ) {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " (
EmpID NOT IN ( SELECT EmpID FROM fedhalfsheet )
OR EmpID NOT IN ( SELECT EmpID FROM hardcard )
OR EmpID NOT IN ( SELECT EmpID FROM physfit WHERE FType='Physical')
OR EmpID NOT IN ( SELECT EmpID FROM physfit WHERE FType='Fitness' )
)";
} elseif ( $key == "no_missing_certB" ) {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " (
EmpID IN ( SELECT EmpID FROM fedhalfsheet )
AND EmpID IN ( SELECT EmpID FROM hardcard )
AND EmpID IN ( SELECT EmpID FROM physfit WHERE FType='Physical' )
AND EmpID IN ( SELECT EmpID FROM physfit WHERE FType='Fitness' )
)";
} elseif ( $key == "halfsheet_validB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $valid_halfsheet";
} elseif ( $key == "hardcard_validB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $valid_hardcard";
} elseif ( $key == "physical_validB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $valid_physical";
} elseif ( $key == "fittest_validB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $valid_fitness";
} elseif ( $key == "halfsheet_invalidB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $invalid_halfsheet";
} elseif ( $key == "hardcard_invalidB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $invalid_hardcard";
} elseif ( $key == "physical_invalidB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $invalid_physical";
} elseif ( $key == "fittest_invalidB") {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause .= " $invalid_fitness";
}
else {
$real_key = preg_replace( '/(.*)B$/', '$1', $key );
if ( preg_match( '/^N/', $real_key ) ) {
$value = '0';
$real_key = preg_replace( '/^N(.*)/', '$1', $real_key );
} else {
$value = '1';
}
if ( !$where_clause_here ) {
$where_clause = "WHERE";
$where_clause_here = TRUE;
} else {
$where_clause = "$where_clause AND";
}
$where_clause = "$where_clause $real_key = '$value'";
}
}
}
if ( $_SESSION['id_limit_value'] ) {
if ( !$where_clause_here ) {
$where_clause = "WHERE";
} else {
$where_clause = "$where_clause AND";
}
if ( !preg_match( "/%/", $_SESSION['id_limit_value'] ) ) {
$id_limit_value = "%$_SESSION[id_limit_value]%";
} else {
$id_limit_value = "$_SESSION[id_limit_value]";
}
$where_clause = "$where_clause $_SESSION[id_limit_type] ILIKE '$id_limit_value'";
}
// Converting $_GET values to $_SESSION values
if ( ( !$_GET['field'] and !$_SESSION['field'] ) or $_POST['reset']) {
// Initializing sort values to order_time
$_GET['field'] = "end_time";
$_GET['direction'] = "ASC";
}
if ( $_GET['field'] ) {
if ( $_GET['field'] == "image_links" )
$_GET['field'] = "order_time";
$_SESSION['field'] = $_GET['field'];
}
if ( $_GET['direction'] ) {
$_SESSION['direction'] = $_GET['direction'];
}
$dist_sort_reset = TRUE;
if ( $_SESSION['distinct'] ) {
foreach ( $_SESSION as $key => $title ) {
if( $_SESSION['field'] == $key OR $_SESSION['field'] == "count" ) {
$dist_sort_reset = FALSE;
}
}
}
if ( $dist_sort_reset and $_SESSION['distinct'] ) {
foreach ( $key_title_pairs as $key => $title ) {
if ( $_SESSION[$key] ) {
$_SESSION['field'] = $key;
break;
}
}
}
/*
if ( $_POST['Submit'] ) {
$_SESSION['start_date'] = $_POST['start_date'];
$_SESSION['end_date'] = $_POST['end_date'];
}
*/
if ($_POST['delete'] ) {
foreach ( $_POST['to_delete'] as $item ) {
mysql_query("DELETE FROM $table_name WHERE $id_col_name='$item'");
}
}
?>
<table style="margin-left: auto; margin-right: auto; padding-bottom: 10px;">
<tr>
<td style="padding-right: 40px;">
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post">
<table style="margin-right:"> <!-- Column Select Area -->
<tr>
<td colspan="6" style="text-align: center;"><h2>Columns To Be Displayed</h2></td>
</tr>
<tr>
<?php
$i=1;
foreach ( $key_title_pairs as $key => $title ) {
if ( $_SESSION[$key] ) {
$checked = 'checked="checked" ';
} else {
$checked = '';
}
print <<<EndOfHTML
<td>
<input type="checkbox" name="$key" id="$key" value="yes" $checked/>
</td>
<td>$title</td>
EndOfHTML;
if ( $i % 3 == 0 ) {
print " </tr>\n <tr>\n";
}
$i++;
}
?>
</tr>
</table>
<!--
<table>
<tr>
<td colspan="2" style="text-align: center;"><h2>Order Date/Time Range</h2></td>
</tr>
<tr>
<td>Start Order Date (dd/mm/yyyy)</td>
<td><input type="text" name="start_order_time" id="start_order_time" value="<?php echo $_SESSION['start_order_time'] ?>" /></td>
</tr>
<tr>
<td>End Order Date (dd/mm/yyyy)</td><td><input type="text" name="end_order_time" id="end_order_time" value="<?php echo $_SESSION['end_order_time']; ?>" /></td>
</tr>
</table>
-->
<table style="width: 100%; text-align: center;">
<tr>
<td><h2>Records Per Page</h2></td>
</tr>
<tr>
<td>Number of Records: <select name="num_records">
<option value="5"<?php if ( $_SESSION['num_records'] == "5" ) echo 'selected="selected" ';?>>5</option>
<option value="10"<?php if ( $_SESSION['num_records'] == "10" ) echo 'selected="selected" ';?>>10</option>
<option value="15"<?php if ( $_SESSION['num_records'] == "15" ) echo 'selected="selected" ';?>>15</option>
<option value="20"<?php if ( $_SESSION['num_records'] == "20" ) echo 'selected="selected" ';?>>20</option>
<option value="25"<?php if ( $_SESSION['num_records'] == "25" ) echo 'selected="selected" ';?>>25</option>
<option value="30"<?php if ( $_SESSION['num_records'] == "30" ) echo 'selected="selected" ';?>>30</option>
<option value="40"<?php if ( $_SESSION['num_records'] == "40" ) echo 'selected="selected" ';?>>40</option>
<option value="50"<?php if ( $_SESSION['num_records'] == "50" ) echo 'selected="selected" ';?>>50</option>
<option value="75"<?php if ( $_SESSION['num_records'] == "75" ) echo 'selected="selected" ';?>>75</option>
<option value="100"<?php if ( $_SESSION['num_records'] == "100" ) echo 'selected="selected" ';?>>100</option>
<option value="500"<?php if ( $_SESSION['num_records'] == "500" ) echo 'selected="selected" ';?>>500</option>
<option value="1000"<?php if ( $_SESSION['num_records'] == "1000" ) echo 'selected="selected" ';?>>1000</option>
</select>
</td>
</tr>
</table>
</td> <!-- End Of Column Select Area -->
<td>
<!--
<table>
<tr>
<td colspan="6" style="text-align: center;"><h2>Distinct Records Only</h2></td>
</tr>
<tr>
<td>Display distinct records only: <input type="checkbox" name="distinct" value="DISTINCT" <?php if ( $_SESSION['distinct'] ) echo 'checked="checked"' ?>/></td>
</tr>
<tr>
<td>Display count column: <input type="checkbox" name="distinct_count" value="yes" <?php if ( $_SESSION['distinct_count'] ) echo 'checked="checked"' ?>/></td>
</tr>
<tr>
<td>Only display records with at least this count (>=) <input type="text" size="2" name="min_count" value="<?php echo $_SESSION['min_count']; ?>" /></td>
</tr>
<tr>
<td>Only display records with at most this count (<=) <input type="text" size="2" name="max_count" value="<?php echo $_SESSION['max_count']; ?>" /></td>
</tr>
</table> -->
<table>
<tr>
<td colspan="6" style="text-align: center;"><h2>Only Display from These Groups</h2></td>
</tr>
<tr>
<?php
$i=1;
foreach ( $bool_pairs as $key => $title ) {
if ( $_SESSION[$key] ) {
$checked = 'checked="checked" ';
} else {
$checked = '';
}
print <<<EndOfHTML
<td>
<input type="checkbox" name="$key" id="$key" value="yes" $checked/>
</td>
<td>$title</td>
EndOfHTML;
if ( $i % 3 == 0 ) {
print " </tr>\n <tr>\n";
}
$i++;
}
?>
</tr>
<!-- <tr>
<td colspan="12" align="right"><input type="submit" name="group" id="Show Groups" value="Show Groups" /></td>
</tr> -->
</table>
<table style="width: 100%; text-align: center;">
<tr>
<td colspan="6" style="text-align: center;"><h2>Expired By</h2></td>
</tr>
<tr>
<td>Expired by days: <select name="expire_days">
<option value="00"<?php if ( $_SESSION['expire_days'] == "00" ) echo 'selected="selected" ';?>>today</option>
<option value="10"<?php if ( $_SESSION['expire_days'] == "10" ) echo 'selected="selected" ';?>>10</option>
<option value="15"<?php if ( $_SESSION['expire_days'] == "15" ) echo 'selected="selected" ';?>>15</option>
<option value="30"<?php if ( $_SESSION['expire_days'] == "30" ) echo 'selected="selected" ';?>>30</option>
<option value="60"<?php if ( $_SESSION['expire_days'] == "60" ) echo 'selected="selected" ';?>>60</option>
<option value="90"<?php if ( $_SESSION['expire_days'] == "90" ) echo 'selected="selected" ';?>>90</option>
</select>
</td>
</tr>
</table>
<table style="width: 100%; text-align: center;">
<tr>
<td colspan="6" style="text-align: center;"><h2>Expiring In</h2></td>
</tr>
<tr>
<td>Expiring in days: <select name="expire_in_days">
<option value="00"<?php if ( $_SESSION['expire_in_days'] == "00" ) echo 'selected="selected" ';?>>don't use</option>
<option value="10"<?php if ( $_SESSION['expire_in_days'] == "10" ) echo 'selected="selected" ';?>>10</option>
<option value="15"<?php if ( $_SESSION['expire_in_days'] == "15" ) echo 'selected="selected" ';?>>15</option>
<option value="30"<?php if ( $_SESSION['expire_in_days'] == "30" ) echo 'selected="selected" ';?>>30</option>
<option value="60"<?php if ( $_SESSION['expire_in_days'] == "60" ) echo 'selected="selected" ';?>>60</option>
<option value="90"<?php if ( $_SESSION['expire_in_days'] == "90" ) echo 'selected="selected" ';?>>90</option>
</select>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="12" align="right"><input type="submit" name="reset" value="Reset" /> <input type="submit" name="Update" id="Update" value="Update" /></td>
</tr>
</table>
</form>
</td> <!-- End Of Date Range Select Area -->
</tr>
</table>
<?php
if ( true /* $_SESSION['display'] == "table" */ ) {
print <<<EndOfHTML
<form action="$_SERVER[PHP_SELF]" method="post">
<table border="0">
<tr>
EndOfHTML;
// This section tests for the presents of the 10 different column checkboxes
// It then: (1) adds the appropriate column heading the to top of the page
// (2) builds on $selected_columns for the mySQL query
// (3) if necessary it builds on $join_statements
// (4) inrements $column_count by one
//
// A problem with the display algorithm surfaces at the end where employee
// records have 2 entries per cell and invoice information has 4.
// So $multi_element_offset needs to be set when either of those 3 colums
// are seleted for display. This will be used to find out how many columns
// can be displayed normally ($column_count - $multi_element_offset).
$selected_columns = "";
$join_statements = "";
$column_count = '0';
$multi_element_offset = '0';
$id_offset = '0'; // This will be 1 if the ID column is selected - which is
// a special case becuase it has edit links associated
// with it.
foreach ( $key_title_pairs as $key => $title ) {
if ( $_SESSION[$key] ) {
list( $first_word, $rest ) = split( " ", $title, 2 );
if ( $rest ) {
$title = "$first_word <br /> $rest";
}
print <<<EndOfHTML
<td class="outputTableHeaders">
<h3>$title
EndOfHTML;
if ( !in_array( $key, $no_sort_keys ) ) {
print <<<EndOfHTML
<a href="$_SERVER[PHP_SELF]?field=$key&direction=ASC"><!--
--><img src="images/ic_sort_a.gif" alt="Ascending" /><!--
--></a><!--
--><a href="$_SERVER[PHP_SELF]?field=$key&direction=DESC"><!--
--><img src="images/ic_sort_d.gif" alt="Descending" /><!--
--></a>
EndOfHTML;
}
print <<<EndOfHTML
</h3>
</td>
EndOfHTML;
if ( $key == "image_links" ) {
$selected_columns = "$selected_columns, order_id";
$column_count += 1;
$multi_element_offset +=1;
}
elseif ( $key == "SSN" ) {
$selected_columns = "$selected_columns, aes_decrypt(SSN, CONCAT(FName, LName, CDate))";
$column_count++;
}
elseif ( $key == "DOHHalfsheet" ) {
}
elseif ( $key == "NYSCert" ) {
}
elseif ( $key == "Physical" ) {
}
elseif ( $key == "Fitness" ) {
}
elseif ( $key == "Telephone" ) {
}
elseif ( $key == "Address" ) {
}
elseif ( $key == "order_time" ) {
$selected_columns = "$selected_columns, to_char( order_time, 'mm/dd/yyyy @ FMHH:MI a.m.' )";
$column_count++;
}
else {
$selected_columns = "$selected_columns, $key";
$column_count++;
}
if ( $key == $id_col_name ) {
$id_offset++;
}
}
}
$selected_columns = ereg_replace ( '(^, )([a-z,]*)', '\2', $selected_columns );
// If the ID field is not selected the $selected_columns variable will start
// with a ', ' which will cause the query to fail. This regex replace fixes
// that by delteing the ', ' if it exsists at the begining of the line
if ( $_SESSION['distinct_count'] AND $_SESSION['distinct'] ) {
print <<<EndOfHTML
<td class="outputTableHeaders">
<h3> Group Count <a href="$_SERVER[PHP_SELF]?field=count&direction=ASC">
<img src="images/ic_sort_a.gif" alt="Ascending" />
</a>
<a href="$_SERVER[PHP_SELF]?field=count&direction=DESC">
<img src="images/ic_sort_d.gif" alt="Descending" />
</a>
</h3>
</td>
EndOfHTML;
$columns = split( ",", $selected_columns );
$first_column = $columns[0];
$group_by = "GROUP BY $selected_columns";
if ( $_SESSION['min_count'] ) {
$having = "HAVING COUNT($first_column) >= $_SESSION[min_count]";
}
if ( $_SESSION['max_count'] ) {
if ( $having ) {
$having .= " AND ";
} else {
$having .= "HAVING ";
}
$having .= "COUNT($first_column) <= $_SESSION[max_count]";
}
$selected_columns = "$selected_columns, COUNT($first_column) AS count";
$column_count++;
}
if ( $_SESSION[$id_col_name] ) {
print <<<EndOfHTML
<td class="outputTableHeaders">
<h3> Select </h3>
</td>
</tr>
EndOfHTML;
}
$total_records_query_code = "SELECT $_SESSION[distinct] $selected_columns FROM $table_name $where_clause $group_by $having ORDER BY $_SESSION[field] $_SESSION[direction]";
$total_records_query = mysql_query( $total_records_query_code );
$number_of_records = mysql_num_rows( $total_records_query );
$page_up = false;
$page_down = false;
if ( ( $number_of_records - $_SESSION['offset'] ) > ( $_SESSION['num_records'] - 1 ) and $_SESSION['num_records'] != "All" ) {
$end_record = $_SESSION['offset'] + $_SESSION['num_records'] ;
$page_up = true;
} else {
$end_record = $number_of_records;
}
if ( $_SESSION['offset'] and $_SESSION['offset'] != "00" and $_SESSION['num_records'] != "All" ) {
$start_record = $_SESSION['offset'];
$page_down = true;
} else {
$start_record = "0";
}
$all_records_query_code = "SELECT $_SESSION[distinct] $selected_columns FROM $table_name $where_clause $group_by $having ORDER BY $_SESSION[field] $_SESSION[direction] LIMIT $start_record, $end_record";
if ( $_SESSION['debug'] == 'on' ) {
print "<br />total_records_query_code: $total_records_query_code<br /><br />";
print "all_records_query_code: $all_records_query_code<br /><br />";
}
if ( $number_of_records == 0 ) {
$print_start_record = '1';
} else {
$print_start_record = $start_record;
}
print "<br />Displaying records <b>$print_start_record</b> to <b>$end_record</b>. <br /> <br />";
$all_records_query = mysql_query($all_records_query_code);
$loop_count = 0;
while ( $all_records = mysql_fetch_row( $all_records_query ) ) {
for ( $i=0; $i<$column_count; $i++ ) {
if ( !$all_records[$i] ) {
$all_records[$i] = "---"; // replaces blank records with --- so the table borders generate correctly
}
if ( $all_records[$i] == 't' ) {
$all_records[$i] = 'yes';
}
if ( $all_records[$i] == 'f' ) {
$all_records[$i] = 'no';
}
$all_records[$i] = htmlentities( $all_records[$i] );
$all_records[$i] = preg_replace( "/\n/", "<br />", $all_records[$i] );
}
if ( $loop_count % 2 ) {
$classInfo = ' class="altBackground"';
}
else {
$classInfo = '';
}
echo " <tr>\n";
if ( $_SESSION[$id_col_name] ) {
print " <td" . $classInfo . "><a href=\"edit_record.php?id=$all_records[0]\">$all_records[0]</a></td>\n";
}
for ( $i=$id_offset; $i < ( $column_count - $multi_element_offset ); $i++ ) {
print " <td" . $classInfo . ">$all_records[$i]</td>\n";
}
if ( $_SESSION['Telephone'] ) {
$telephone_query_code = "SELECT ContactID, CType, Number FROM contacts WHERE $id_col_name = $all_records[0] AND Prime = 1 LIMIT 1";
$telephone_query = mysql_query( $telephone_query_code );
$num_telephone = mysql_num_rows( $telephone_query );
print "<td" . $classInfo . ">";
if ( $num_telephone > 0 ) {
while ( $telephone = mysql_fetch_array( $telephone_query ) ) {
print "<a href=\"edit_contact.php?id=$telephone[ContactID]\">$telephone[CType]: $telephone[Number]</a>";
}
} else {
print "<a href=\"add_contact.php?id=$all_records[0]\">Add Phone</a>";
}
print "</td>";
}
if ( $_SESSION['Address'] ) {
$address_query_code = "SELECT AddressID, AType, Line1, Line2, City, State, ZipCode FROM address WHERE $id_col_name = $all_records[0] AND Prime = 1 LIMIT 1";
$address_query = mysql_query( $address_query_code );
$num_address = mysql_num_rows( $address_query );
print "<td" . $classInfo . ">";
if ( $num_address > 0 ) {
while ( $address = mysql_fetch_array( $address_query ) ) {
print "<a href=\"edit_address.php?id=$address[AddressID]\">$address[AType]: <br /> $address[Line1] <br /> $address[Line2] <br /> $address[City], $address[State] $address[ZipCode] </a>";
}
} else {
print "<a href=\"edit_address.php?id=$all_records[0]\">Add Address</a>";
}
print "</td>";
}
if ( $_SESSION['DOHHalfsheet'] ) {
/* for ($i = ($column_count - $multi_element_offset); $i < ($column_count - 4); $i += 1 ) {
$j = $i + 1;
$k = $j + 1;
$l = $k + 1;
$m = $l + 1;
$n = $m + 1;
$o = $n + 1; */
$fedhalfsheet_query_code = "SELECT FedhalfID,DATE_ADD( Issue_Date, INTERVAL 1 YEAR ) AS Expire_Date FROM fedhalfsheet WHERE $id_col_name = $all_records[0] ORDER BY Expire_Date DESC LIMIT 1";
$fedhalfsheet_query = mysql_query( $fedhalfsheet_query_code );
$num_fedhalfsheet = mysql_num_rows( $fedhalfsheet_query );
print "<td" . $classInfo . ">";
if ( $num_fedhalfsheet > 0 ) {
while ( $fedhalfsheet = mysql_fetch_array( $fedhalfsheet_query ) ) {
print "<a href=\"edit_halfsheet.php?Picid=$fedhalfsheet[FedhalfID]&Empid=$all_records[0]\">Expire: $fedhalfsheet[Expire_Date]</a>";
}
} else {
print "<a href=\"add_fedhalfsheet.php?id=$all_records[0]\">Add DOH Halfsheet</a>";
}
print "</td>";
// print " <td" . $classInfo . "><a href=\"view_files.php?id=$all_records[$i]\">click for images</a></td>\n";
/* } */
}
if ( $_SESSION['NYSCert'] ) {
$hardcard_query_code = "SELECT HardCardID, Expire_Date FROM hardcard WHERE EmpID = $all_records[0] ORDER BY Expire_Date DESC LIMIT 1";
$hardcard_query = mysql_query( $hardcard_query_code );
$num_hardcard = mysql_num_rows( $hardcard_query );
print "<td" . $classInfo . ">";
if ( $num_hardcard > 0 ) {
while ( $hardcard = mysql_fetch_array( $hardcard_query ) ) {
print "<a href=\"edit_hardcard.php?Picid=$hardcard[HardCardID]&Empid=$all_records[0]\">Expire: $hardcard[Expire_Date]</a>";
}
} else {
print "<a href=\"add_hardcard.php?id=$all_records[0]\">Add NYS Cert</a>";
}
print "</td>";
}
if ( $_SESSION['Physical'] ) {
$physical_query_code = "SELECT PhysfitID, DATE_ADD( Issue_Date, INTERVAL 1 YEAR ) AS Expire_Date FROM physfit WHERE EmpID = $all_records[0] AND FType = 'Physical' ORDER BY Expire_Date DESC LIMIT 1";
$physical_query = mysql_query( $physical_query_code );
$num_physical = mysql_num_rows( $physical_query );
print "<td" . $classInfo . ">";
if ( $num_physical > 0 ) {
while ( $physical = mysql_fetch_array( $physical_query ) ) {
print "<a href=\"edit_physical.php?Picid=$physical[PhysfitID]&Empid=$all_records[0]\">Expire: $physical[Expire_Date]</a>";
}
} else {
print "<a href=\"add_physical.php?id=$all_records[0]\">Add Physical</a>";
}
print "</td>";
}
if ( $_SESSION['Fitness'] ) {
$physical_query_code = "SELECT PhysfitID, DATE_ADD( Issue_Date, INTERVAL 1 YEAR ) AS Expire_Date FROM physfit WHERE EmpID = $all_records[0] AND FType = 'Fitness' ORDER BY Expire_Date DESC LIMIT 1";
$physical_query = mysql_query( $physical_query_code );
$num_physical = mysql_num_rows( $physical_query );
print "<td" . $classInfo . ">";
if ( $num_physical > 0 ) {
while ( $physical = mysql_fetch_array( $physical_query ) ) {
print "<a href=\"edit_fitness.php?Picid=$physical[PhysfitID]&Empid=$all_records[0]\">Expire: $physical[Expire_Date]</a>";
}
} else {
print "<a href=\"add_fittest.php?id=$all_records[0]\">Add Fitness Test</a>";
}
print "</td>";
}
if ( $_SESSION[$id_col_name] ) {
print <<<EndOfHTML
<td$classInfo style="text-align:center"><input type="checkbox" id="to_delete$counter" name="to_delete[]" value="$all_records[0]" /></td>
EndOfHTML;
}
echo " </tr>\n";
$loop_count++;
}
if ( $_SESSION[$id_col_name] ) {
print <<<EndOfHTML
<tr>
<td colspan="100" style="text-align: right"><input type="submit" name="makedocbook" value="Make Docbook" /><input type="submit" name="delete" value="Delete Selected" onclick="return confirm('Are you sure you want to delete these entries?');"/></td>
</tr>
EndOfHTML;
}
print <<<EndOfHTML
<tr>
<td colspan="100" style="text-align: right">Query returned <b>$number_of_records</b> rows!</td>
</tr>
EndOfHTML;
if ( $page_up or $page_down ) {
if ( $page_down ) {
$begining = true;
$new_offset = $_SESSION['offset'] - $_SESSION['num_records'];
if ( $new_offset == 0 ) {
$new_offset = "00";
$begining = false;
}
if ( $begining ) {
$down_page_html = "<a style=\"text-decoration:none\" href=\"$_SERVER[PHP_SELF]?offset=00\"><</a> ";
if ( ( $_SESSION['offset'] - ( $_SESSION['num_records'] * 10 ) ) > 0 ) {
$less_10_offset = $_SESSION['offset'] - ( $_SESSION['num_records'] * 10 );
$down_page_html .= "<a href=\"$_SERVER[PHP_SELF]?offset=$less_10_offset\">Prev 10</a> ";
}
}
$down_page_html .= "<a href=\"$_SERVER[PHP_SELF]?offset=$new_offset\">Prev</a>";
}
if ( $page_down and $page_up ) {
$bar_html = " | ";
}
if ( $page_up ) {
$new_offset = $_SESSION['offset'] + $_SESSION['num_records'];
$up_page_html = "<a href=\"$_SERVER[PHP_SELF]?offset=$new_offset\">Next</a>";
if ( ( $_SESSION['offset'] + ( $_SESSION['num_records'] * 10 ) ) < $number_of_records ) {
$more_10_offset = $_SESSION['offset'] + ( $_SESSION['num_records'] * 10 );
$up_page_html .= " <a href=\"$_SERVER[PHP_SELF]?offset=$more_10_offset\">Next 10</a> ";
}
if ( $_SESSION['offset'] + $_SESSION['num_records'] < $number_of_records ) {
$max_page = floor( ( $number_of_records - 1 ) / $_SESSION['num_records'] );
$final_page_offset = $max_page * $_SESSION['num_records'];
$up_page_html .= " <a style=\"text-decoration:none\" href=\"$_SERVER[PHP_SELF]?offset=$final_page_offset\">></a>";
}
}
print <<<EndOfHTML
<tr>
<td colspan="100" style="text-align: right"> $down_page_html$bar_html$up_page_html </td>
</tr>
EndOfHTML;
}
print <<<EndOfHTML
</table>
</form>
EndOfHTML;
} elseif ( $_SESSION['display'] == "CSVSrn" ) {
foreach ( $key_title_pairs as $key => $title ) {
if ( $_SESSION[$key] and $key != "image_links" ) {
print <<<EndOfHTML
<h3>$title <a href="$_SERVER[PHP_SELF]?field=$key&direction=ASC">
<img src="images/ic_sort_a.gif" alt="Ascending" />
</a>
<a href="$_SERVER[PHP_SELF]?field=$key&direction=DESC">
<img src="images/ic_sort_d.gif" alt="Descending" />
</a>
</h3>
EndOfHTML;
$records_query_code = "SELECT $_SESSION[distinct] $key FROM $table_name $where_clause ORDER BY $_SESSION[field] $_SESSION[direction]";
$records_query = mysql_query( $records_query_code );
while( $records = mysql_fetch_row( $records_query ) ) {
if ( !$records[0] ) {
$records[0] = "---"; // replaces blank records with --- so the table borders generate correctly
}
if ( $records[0] == 't' ) {
$records[0] = 'yes';
}
if ( $records[0] == 'f' ) {
$records[0] = 'no';
}
$records[0] = htmlentities( $records[0] );
print "$records[0], ";
}
print "<br /><br />";
}
}
}
if ( $_SESSION['debug'] == "on" ) {
print "<br /><br />Perm Link: $_SERVER[PHP_SELF]?";
foreach ( $_SESSION as $key => $title ) {
if ( $key != "debug" and $key != "ua" ) {
print "$key=$title&";
}
}
}
foreach ( $session_save_keys as $key ) {
$_SESSION[$key] = $SESSION_BACKUP[$key];
}
?>