$searchSQL = "select * from document " . $dateClause . $subjectClause . $classificationClause . $referenceClause . " and ((sending_office='" . $_SESSION['division_code'] . "' and security in ('divSecured','GMsecured')) or (security='unsecured'))";
$searchRS = $db->query($searchSQL);
$searchNM = $searchRS->num_rows;
?>
			<tbody>
			<?php 
for ($i = 0; $i < $searchNM; $i++) {
    $searchRow = $searchRS->fetch_assoc();
    ?>
				<tr>
					<td><?php 
    echo $searchRow['subject'];
    ?>
</td>
					<td><?php 
    echo getOriginatingOffice($db, $searchRow['originating_office']);
    ?>
</td>
					<td><?php 
    echo $searchRow['document_date'];
    ?>
</td>
					<td><?php 
    echo $searchRow['receive_date'];
    ?>
</td>
					<td><?php 
    echo calculateReferenceNumber($db, $searchRow, adjustControlNumber($searchRow['ref_id']));
    ?>
</td>
				</tr>
	<?php 
    for ($i = 0; $i < $nm; $i++) {
        $row = $rs->fetch_assoc();
        ?>
	<tr>
		<td><?php 
        echo $row['subject'];
        ?>
</td>
		<td>Office Order</td>
		<td><?php 
        echo date("Y-m-d h:ia", strtotime($row['document_date']));
        ?>
</td>
		<td><?php 
        echo getOriginatingOffice($db, $row['originating_office']);
        ?>
</td>
		<td><?php 
        echo $row['status'];
        ?>
</td>
	</tr>
	<?php 
    }
    ?>
	</table>
	<select name='ordersDocsFilter'>
	<option value='ALL'>All Office Orders</option>
	<option value='NS'>Office Orders Not Sent</option>
	<option value='IS'>Office Orders Issued and Sent</option>
			$rr[0]="c".$i;
			$rr[1]="d".$i;
			addContent($rr,$excel,"Office Order","true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="e".$i;
			$rr[1]="f".$i;
			addContent($rr,$excel,date("Y-m-d h:ia",strtotime($row['document_date'])),"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="g".$i;
			$rr[1]="h".$i;
			addContent($rr,$excel,getOriginatingOffice($db,$row['originating_office']),"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);

			$rr[0]="i".$i;
			$rr[1]="j".$i;
			addContent($rr,$excel,$row['status'],"true",$ExWs);
			setCellArea($rr,$excel,$ExWs,$excel);
		styleCellArea(setRange($rr[0],$rr[1]),"false","true",$ExWs,$excel);
		
		}
	}
	
	//close the Page
	save($ExWb,$excel,"");