<?php 
if (!isset($_SESSION)){
  session_start();
}

require_once("Connections/courier.php");
$searchtext = mysql_real_escape_string(trim($_POST["item_search"]));
$searcby=$_POST["search_by"];

$branch_type = mysql_fetch_assoc(mysql_query("SELECT type FROM branches WHERE id='".$_SESSION['branch_id']."'"));
if($branch_type['type']=='branch'){
    $table = 'service_items';
    $item_id = 'id';
}else{
    $table = 'stock_items';
     $item_id = 'item_id';
}

if($searchtext != ""){
	if($searcby=="contains"){
		$queryItems = "SELECT * FROM $table WHERE (item LIKE '%$searchtext%' or alternate_lookup='$searchtext') ORDER BY item DESC limit 0,100";
	}else{
	$queryItems = "SELECT * FROM $table WHERE (item LIKE '$searchtext%' or alternate_lookup='$searchtext') ORDER BY item DESC limit 0,100";	
	}
		
$resultItems = mysql_query($queryItems) or die(mysql_error());
$arrayItems = mysql_fetch_assoc($resultItems);
$totalRows = mysql_num_rows($resultItems);
}

?>

<table class="table">
                         <?php if ($totalRows> 0) { ?>                    
                    	<tbody>
                                                    <?php
							$i = 0;
                                                    do {
                                                        $i = $i + 1;
                                                        ?>
                            <tr style="cursor: pointer;" id="sell_tr" onclick="searchItemsName('edit_requisition_details','#view_items_response_wrapper_2','<?php echo $arrayItems[$item_id]; ?>','no_field');" onkeypress="javascript: if(isEnterKey(event)){ searchItemsName('edit_requisition_details','#view_items_response_wrapper_2','<?php echo $arrayItems[$item_id]; ?>'); }">
                                                            <td valign="top"><?php echo strtoupper($arrayItems["item"]); ?></td>
                                                            <td valign="top"  style="text-align:center"><?php echo $arrayItems['quantity_available_'.$_SESSION['name_code']]; ?></td>
                                                            <td valign="top"  style="text-align:center"> <i id="plus_<?php echo $arrayItems[$item_id]; ?>" class="icon-plus" style="color:#000;"></i> <i style="display: none;" id="spin_refresh_plus_<?php echo $arrayItems['id']; ?>" class="fa fa-refresh fa-spin fa-fw"></i> </td>
                         </tr>
                                            <?php } while ($arrayItems = mysql_fetch_assoc($resultItems)); ?>
                        </tbody>
                 </table>
				 <?php }else{echo '<tr><td colspan="3"><div class="none">Sorry, No Item Found</div></td></tr></table>';}?>
                 

         
        

