<?
$rez=include("setup.php");
if (! $rez) //if can't find setup.php or not chmod'ed 
 {
  echo "<font color=red>Check setup.php file !</font>";
	exit;
 }


//countpages - count of products (pages with products)
//perpageis - count of products per page
//fromtostart - num of product we begin to show in current page
//pageis - number of current page


$result=mysql_query("select * from category order by CategoryName") or die (mysql_error(). " : ".mysql_errno());
?>

<!-- Top menu  //-->
<script src="jumptop.js">
//Jump To Top Link Script
//Copyright Dynamicdrive.com
//Visit http://www.dynamicdrive.com for this script, and TOS
</script>


<table width=100% border=0>
<tr>
<td>
       <form action=<?=$PHP_SELF?> method=post name=searchcategory>

       <table border=0>
       <tr>
       <td>
       Select the category
       </td>
       <td>
       Select quantity of products to show per page
       </td>
       </tr>
       
       <tr>
       <td>
       <select name="categoryis">
       <option value='nothing'>--Select one--</option>
       <?
       while($row=mysql_fetch_object($result))
       {
       if (isset($categoryis) && $categoryis==$row->ID)
        echo "<option value='$row->ID' selected>$row->CategoryName</option>";
       else
        echo "<option value='$row->ID' >$row->CategoryName</option>";
       }
       ?>
       </select>
       </td>
       <td>
       <select name="perpageis" >
       <option value='nothing'>--Select one--</option>
       <option value="5">5</option>
       <option value="10">10</option>
       <option value="15">15</option>
       <option value="20">20</option>
       <option value="30">30</option>       
       </select>&nbsp;
       <input type=submit value=Submit onclick="return validate_form_search('searchcategory')">
       </td>
       </tr>
       </table>
       </form>       
</td>
<td align=center width=15%>
OR
</td>
<td>
       <form action=<?=$PHP_SELF ?> method=post name=searchsimple>
<?
//perpage is count of products per page
?>
       <input type=hidden name="perpageis" value=10>
       <table border=0>
       <tr>
       <td>
       Search 
       </td>
       </tr>
       <tr>
       <td>
       <input type=text name=searchis>
       <input type=submit value=Submit onclick="return validate_form_search('searchsimple')">
       </td>
       </tr>
       </table>
       </form>

</td>
</tr>
</table>
<!---------- end of search table //--------------->

<!---------- feedback and cart start //----------->
<?
require "menuindex.php";
?>
       <br><br>
<?
unset($result); //unset it to know if we we entered for the first time
// --------- to both searches -------------------
         if (isset($pageis))
          $fromtostart=$perpageis*$pageis-$perpageis; //to get right start 'label'
         else
          $fromtostart=0;
// ------------- end to both searches ------------

// ------------------ start of category search ------------------
if (isset($categoryis)):
       if (!isset($countpages))
       {
       $result=mysql_query("select * from product where categoryID='$categoryis' ") or die (mysql_error(). " : ".mysql_errno());
       $countpages=mysql_num_rows($result);
         if ($countpages==0)
          {
           echo "There are no results<br>";
           exit;
          }
          else
           echo "Count of products were found: $countpages<br><br>"; 
          $countpages= ceil($countpages/$perpageis);
       }
       $result=mysql_query("select * from product where categoryID='$categoryis'  order by Name ASC limit $fromtostart,$perpageis ") or die (mysql_error(). " : ".mysql_errno());
endif;
// ------------------ end of category search -------------------


//----------------- start of simple search ----------------------
   if (isset($searchis)):
       if (!isset($countpages))
       {
       $result=mysql_query("select * from product where Name like '%$searchis%' or Description like '%$searchis%'  ") or die (mysql_error(). " : ".mysql_errno());
       $countpages=mysql_num_rows($result);
         if ($countpages==0)
          {
           echo "There are no results<br>";
           exit;
          }
          else
           echo "Count of products were found: $countpages<br><br>"; 
          $countpages= ceil($countpages/$perpageis);
       }
      $result=mysql_query("select * from product where Name like '%$searchis%' or Description like '%$searchis%' limit $fromtostart,$perpageis ") or die (mysql_error(). " : ".mysql_errno());
     echo "You search <b><font color=red>$searchis</font></b><br>";
   endif;
// -------------------- end of simple search ------------------

//---------------------- to both searches -------------------
if (isset($result)): //if it is no first time entrance (unset ($result) if first time entrance)
        echo "<br>Click on the product to see details about it";
        echo "<table width=100% cellpadding=4 cellspacing=4 border=0 bgcolor=#fffcd0>";
        echo "<tr>
                     <td><b>V</b></td>
                     <td><b>Name</b></td>
                     <td width=30%><b>Description</b></td>
                     <td><b>Price</b></td>
                     <td><b>Price without VAT</b></td>
                     <td><b>Arriving Date</b></td>
                     <td><b>Count in Stock</b></td>
    
              </tr>";
       $i=120;
//     onsubmit=mycart()
/*
<form name="frm" action="bb.html" target="windName" method="get">
<input type="text" name="a">
<input type="submit" ></form>
  */

       echo "<form method=post target='windName' name=addprocuct action='cart_one.php'>
       <input type=hidden name=addme value=addtocart>";
       while($row=mysql_fetch_object($result))
       {
               $col="#808".$i;
               $i=$i+20;
               echo "<tr><td bgcolor=$col><input type=checkbox name=cadd[] value='$row->ID'></td>";
               echo "<td bgcolor=$col>";
              if (isset($cadd_ses[$row->ID]))
                  echo "<img src=tocart.gif  height=12 width=12 border=0 alt=\"Product '$row->Name' was added to Your cart.&#10;To remove it from Your cart select one more time and click 'Add/Remove' button\"> ";
              echo "                 
                     <b><a href=\"javascript:showuserdata('one_index_product.php','$row->ID')\" title=\"Show about $row->Name\">$row->Name</a></b></td>
                     <td bgcolor=$col>$row->Description</td>
                     <td bgcolor=$col>$row->Price</td>
                     <td bgcolor=$col>$row->PriceWithoutVat</td>
                     <td bgcolor=$col>";
                     echo convert_date($row->ArrivingDate);
                     echo "</td>
                     <td bgcolor=$col>$row->Count</td>
                     </tr>";

       }
              echo "</table>";
              echo "<input type=submit value='Add/Remove to/from the cart' onclick='mycart()'></form>";


//<input type="button" OnClick="window.open("where.html","Title","width='200', heigth='200'")"> 

              echo "<hr noshade width=100% align=left>All prices are in $currency";

endif;
// -------------- end table to both search ----------------------------

//--------------------- next page to category search -----------------------------

if (isset($categoryis)):

              echo "<br><br><center>";
       if (empty($pageis))
         $pageis=1;
       for ( $i=1;$i<=$countpages;$i++ )
       {
        echo "<a href=$PHP_SELF?countpages=$countpages&perpageis=$perpageis&categoryis=$categoryis&pageis=$i>";
        if ($i==$pageis)
          echo " <b><u>[$i]</u></b> ";
        else
          echo " [$i] ";     
       }

           echo "</center>";
endif;

// --------------- end next page to category search --------------------------

//--------------------- next page to simple search -----------------------------

if (isset($searchis)):

              echo "<br><br><center>";
       if (empty($pageis))
         $pageis=1;
       for ( $i=1;$i<=$countpages;$i++ )
       {
        echo "<a href=$PHP_SELF?searchis=$searchis&countpages=$countpages&perpageis=$perpageis&pageis=$i>";
        if ($i==$pageis)
          echo " <b><u>[$i]</u></b> ";
        else
          echo " [$i] ";     
       }

           echo "</center>";
endif;

// --------------- end next page to simple search --------------------------

if (empty($countpages))
       echo $YOUR_TEXT;
?>


