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

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


if($searchtext != ""){
  if ($action == "search_items_promo_orders" || $action == "view_promotion_details") {
    $action_next= 'edit_promo_details';
    $action3 = 'edit_promo_details';
      if($searcby=="contains"){
    $queryItems = "SELECT * FROM service_items WHERE (item LIKE '%$searchtext%' or alternate_lookup='$searchtext') AND service_type = 'Optical Consultation' ORDER BY item DESC limit 0,100";
  }else{
   $queryItems = "SELECT * FROM service_items WHERE (item LIKE '$searchtext%' or alternate_lookup='$searchtext') AND service_type = 'Optical Consultation' ORDER BY item DESC limit 0,100";  
 }
 
}else{
  $action_next=$_POST["action_next"];
  $action3 = 'edit_purchase_details';
    if($searcby=="contains"){
    $queryItems = "SELECT * FROM stock_items WHERE (item LIKE '%$searchtext%' or alternate_lookup='$searchtext') $servicetype ORDER BY item DESC limit 0,100";
  }else{
   $queryItems = "SELECT * FROM stock_items WHERE (item LIKE '$searchtext%' or alternate_lookup='$searchtext') $servicetype 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('<?php echo $action_next; ?>','#view_items_response_wrapper_2','<?php echo $arrayItems["id"]; ?>','no_field');" onkeypress="javascript: if(isEnterKey(event)){ searchItemsName('<?php echo $action3 ?>','#view_items_response_wrapper_2','<?php echo $arrayItems["id"]; ?>'); }">
        <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>';}?>





