
<table width="100%"  border="0" cellspacing="4" cellpadding="4">
  <tr>
    <td width="100%"><form action="index.php?g=pencarian&i=index" method="get" enctype="multipart/form-data" name="form1">
        <table width="100%"  border="0" cellspacing="4" cellpadding="4">
          <tr>
            <td width="11%">Cari Surat </td>
            <td width="2%">:</td>
            <td width="26%"><input name="query" class="baca1" id="query" onFocus="if(this.value=='CARI SURAT') this.value='';" onBlur="if(this.value=='') this.value='CARI SURAT';" onKeyUp="showUser(this.value)" size="40" type="text" maxlength="255"/></td>
            <td width="13%">Dalam Database </td>
            <td width="2%">:</td>
            <td width="9%"><select name="db" id="db">
                    <option value=0 selected>- Pilih Tahun Surat -</option>
                    <?php
mysql_connect("$server", "$username", "$password");
mysql_select_db("$database");
$sql=mysql_query("select * from tab_surat");
while ($data=mysql_fetch_array($sql)){
print('<option value="'.$data["s_nama"].'">'.$data["s_tahun"].'</option>');
}
?>
                  </select></td>
            <td width="37%"><input type="submit" name="Submit" value="Search">
              Klik Perihal untuk Melihat Arsip Digital </td>
          </tr>
        </table>
      </form>
                 <?php
mysql_connect("$server", "$username", "$password") or die("Error connecting to database: ".mysql_error());
mysql_select_db("$database") or die(mysql_error());
?>

        <?php
			
			$db = $_GET['db'];
    $query = $_GET['query'];
	
    $min_length = 3;
    if(strlen($query) >= $min_length){
        $query = htmlspecialchars($query);
        $query = mysql_real_escape_string($query);
        $raw_results = mysql_query("SELECT * FROM $db WHERE (`tu_perihal` LIKE '%".$query."%') OR (`tu_asalsrt` LIKE '%".$query."%')") or die(mysql_error());
	
        if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
             print ('<table width="100%"  border="0" cellspacing="2" cellpadding="2">
  <tr bgcolor="#FF9900">
 <td width="5%"><span class="style1"><strong>N.A.</strong></span></td>
<td width="10%"><span class="style1"><strong>TGL SURAT</strong></span></td>
<td width="20%"><span class="style1"><strong>NO SURAT</strong></span></td>
<td width="10%"><span class="style1"><strong>ASAL SURAT</strong></span></td>
<td width="5%"><span class="style1"><strong>LAMP</strong></span></td>
<td width="30%"><span class="style1"><strong>PERIHAL / ISI SURAT</strong></span></td>
<td width="20%"><span class="style1"><strong>EKPEDISI</strong></span></td>
  </tr>');
            while($results = mysql_fetch_array($raw_results)){
             
    
	  print ('
  <tr bgcolor="#FFF1BB">');
  print ('<td>'.$results['tu_noagenda'].'</td>');
print ('<td>'.$results['tu_tglsrt'].'</td>');
print ('<td>'.$results['tu_nosrt'].'</td>');
print ('<td>'.$results['tu_asalsrt'].'</td>');
print ('<td>'.$results['tu_lamp'].'</td>');
print ('<td><a href="digilib/'.$db.'/'.$results['tu_noagenda'].'.pdf" target="_blank">'.$results['tu_perihal'].'</a></td>');
print ('<td><b>');
if ($results['tu_ekspedisi'] == "0") {echo "ERROR";} 
elseif ($results['tu_ekspedisi'] == "1") {echo "PEMBINAAN";} 
elseif ($results['tu_ekspedisi'] == "2") {echo "INTELIJEN";} 
elseif ($results['tu_ekspedisi'] == "3") {echo "PIDANA UMUM";} 
elseif ($results['tu_ekspedisi'] == "4") {echo "PIDANA KHUSUS";} 
elseif ($results['tu_ekspedisi'] == "5") {echo "DATUN";} 
elseif ($results['tu_ekspedisi'] == "6") {echo "KEUANGAN";} 
elseif ($results['tu_ekspedisi'] == "7") {echo "LAINNYA";} 
print (':</b><br>'.$results['tu_disposisi'].'</td>');
  print('</tr>');
            }
             print ('</table>');
        }
        else{ 
            echo "Tidak ditemukan surat tersebut dalam database";
        }
         
    }
    else{ // if query length is less than minimum
        echo "Minimum length is ".$min_length;
    }
?>
    </td>
  </tr>
</table>
<? } ?>