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

require_once("Connections/courier.php");
$searchtext = mysql_real_escape_string(trim($_POST["item_search"]));
$searcby=$_POST["search_by"];
$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" <?php if($arrayItems['quantity_available']>0){ ?> onclick="searchItemsName('edit_transfer_details','#view_items_response_wrapper_2','<?php echo $arrayItems[$item_id]; ?>','no_field');" onkeypress="javascript: if(isEnterKey(event)){ searchItemsName('edit_transfer_details','#view_items_response_wrapper_2','<?php echo $arrayItems[$item_id]; ?>'); }" <?php }else{ ?> onclick="Materialize.toast('Sorry, <?php echo strtoupper($arrayItems["item"]); ?> is Out of Stock.',4000,'error');" <?php } ?>>
                                                            <td valign="top"><?php echo strtoupper($arrayItems["item"]); ?></td>
                                                            <td valign="top"  style="text-align:center"><?php echo $arrayItems['quantity_available']; ?></td>
                                                            <td valign="top"  style="text-align:center"> <i id="plus_<?php echo $arrayItems["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>'; } ?>
                 

         
        

