<?php
/*
  www.oscGold.com (C) Kamelia-Net Jacek Krysiak
  modul oscGold wer 4.0
*/
?>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
    <tr>
        <td>

            <!-- Naglowek BOF -->
            <?php
            if (ALLOW_HEADER_TAGS_CONTROLLER=='true') {
                // Header Tag Controller BOF
                $info_box_contents = array();
                if (tep_not_null($category['categories_htc_title_tag'])) {
                    $info_box_contents[] = array('text' => sprintf($category['categories_htc_title_tag']));   // jezeli wypelnione jest pole tytul kategori w HTC
                } else {
                    $info_box_contents[] = array('text' => sprintf($category['categories_name']));
                }
                new contentBoxHeading($info_box_contents);
            } else {
                $info_box_contents = array();
                $info_box_contents[] = array('text' => sprintf($category['categories_name']));
                new contentBoxHeading($info_box_contents);
                // Header Tag Controller EOF
            }
            ?>
            <!-- Naglowek BOF -->
        </td>
    </tr>

    <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '1'); ?></td>
    </tr>

   <!-- Opis kategorii BOF -->
   <?php
    if ((int)strlen($category['categories_htc_description']) > 10) {
    ?>
    <tr>
        <td>
            <table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBox">
                <tr class="infoBoxContents">
                    <td>
                        <table border="0" width="100%" cellspacing="0" cellpadding="3">
                            <tr>
                                <?php
                                 if ($category['categories_image'] != '') {
                                    $szerokosc = SMALL_IMAGE_WIDTH+10;
                                    $wysokosc = SMALL_IMAGE_HEIGHT+10;
                                    echo '<td align="center" valign="top" width="'.$szerokosc.'">';
									if ($category['categories_image'] != '') {
                                    echo tep_image(DIR_WS_IMAGES.$category['categories_image'], $category['categories_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT,'','','','','',true);
									}
                                    echo '</td>';
                                }
                                ?>
                                <td class="main" valign="top" align="left"><?php echo $category['categories_htc_description']; ?></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '5'); ?></td>
    </tr>
    <?php
    }
    ?>
    <!-- Opis kategorii EOF -->

    <!-- Naglowek BOF -->
    <tr>
     <td>
      <?php
       $info_box_contents = array();
       $info_box_contents[] = array('text' => sprintf(CAT_HEADING_TITLE));
       new contentBoxHeading($info_box_contents);
      ?>
     </td>
    </tr>
    <tr>
     <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '1'); ?></td>
    </tr>
    <!-- Naglowek EOF -->
    <tr>
        <td class="main">
            <table border="0" width="100%" cellspacing="3" cellpadding="1" align="center">

                <tr>
                        <?php
                        $szerokosc = SUBCATEGORY_IMAGE_WIDTH+10;
                        $wysokosc = SUBCATEGORY_IMAGE_HEIGHT+10;
						$ilosc_col = MAX_DISPLAY_CATEGORIES_PER_ROW;
                        $szer_tab = 100/$ilosc_col ;
                        $ilosc_col = $ilosc_col - 1;
                        $info_box_contents = array();
                        if (isset($cPath) && strpos('_', $cPath)) {
                            // check to see if there are deeper categories within the current category
                            $category_links = array_reverse($cPath_array);
                            for($i=0, $n=sizeof($category_links); $i<$n; $i++) {
                                $categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status = '1' and c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
                                $categories = tep_db_fetch_array($categories_query);
                                if ($categories['total'] < 1) {
                                    // do nothing, go through the loop
                                } else {
                                    $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, pcategories.parent_id as grand_parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES . " AS pcategories, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status = '1' and c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and pcategories.categories_id = '" . (int)$category_links[$i] . "' order by c.sort_order, cd.categories_name");
                                   break; // we've found the deepest category the customer is in
                                }
                            }
                        } else {
                            $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, pcategories.parent_id as grand_parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES . " AS pcategories, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_status = '1' and c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and pcategories.categories_id = '" . (int)$current_category_id . "' order by c.sort_order, cd.categories_name");
                        }

                             ########## START CODE ##########
                             $number_of_categories = tep_db_num_rows($categories_query);
                             //New Optimisation Mod to reduce products_name query to just 1
                             while ($categories = tep_db_fetch_array($categories_query)) {
                                 $list_of_categories[] = (int)$categories['categories_id'];
                                 $categories_info[] = array (
                                                   'categories_id'           => (int)$categories['categories_id'],
                                                   'categories_image'        => $categories['categories_image'],
                                                   'categories_name'         => $categories['categories_name'],
                                                   'parent_id'               => $categories['parent_id']);
                             }
                             tep_db_free_result($categories_query); // Housekeeping
                             if (sizeof($list_of_categories) > 0 ) {
                                $select_list_of_categories = implode(",", $list_of_categories);
                                $multiple_categories = tep_get_multiple_paths($select_list_of_categories);
                             }
                             $rows = 0;
                             $counted = count($categories_info);
                             for($i=0; $i<$counted; $i++) {
                                $rows++;
                                $cPath_new = $multiple_categories[$categories_info[$i]['categories_id']];
                                $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
								echo '
								<td align="center" style="height:100%" width="' . $width . '" valign="middle" class="TableFrame">
                                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                   <td align="center" valign="middle">
                                    <table border="0" cellspacing="0" cellpadding="0">
                                     <tr>
                                      <td align="center" valign="top" style="padding-top:5px;padding-bottom:5px">'.
                                        (($categories_info[$i]['categories_image'] != '') ? tep_image(DIR_WS_IMAGES . $categories_info[$i]['categories_image'], $categories_info[$i]['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT,'','','','',tep_href_link(FILENAME_DEFAULT, $multiple_categories[$categories_info[$i]['categories_id']]),true) : '').'
                                      </td>
									 </tr>
									 <tr>
									  <td align="center" valign="middle" style="padding-bottom:5px"><a class="ProductTile" href="' . tep_href_link(FILENAME_DEFAULT, $multiple_categories[$categories_info[$i]['categories_id']]) . '">' . $categories_info[$i]['categories_name'] . '</a></td>
									 </tr>
								    </table>
								   </td>
								  </tr>
								 </table>
								</td>' . "\n";
                                if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories)) {
                                echo '</tr>' . "\n";
                                echo '<tr>' . "\n";
                                }
                             }
                             //End Optimisation Mod
                             // needed for the new products module shown below
                             $new_products_category_id = $current_category_id;
                             ########## END CODE ##########
                        ?>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
    </tr>
    <!-- Naglowek BOF -->
    <tr>
     <td>
      <?php
       $info_box_contents = array();
       $info_box_contents[] = array('text' => sprintf(BOTH_HEADING_TITLE));
       new contentBoxHeading($info_box_contents);
      ?>
     </td>
    </tr>
    <tr>
     <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
    </tr>
    <!-- Naglowek EOF -->
    <tr>
      <td>
       <?php 
       echo tep_draw_form('filter', FILENAME_DEFAULT.'?cPath='.(int)$current_category_id, 'post'); 
       ?>
       <table border="0" width="100%" cellspacing="0" cellpadding="2">
    	<?php
    	// optional Product List Filter
    	if (PRODUCT_LIST_FILTER > 0) {
    	  $filterlist_sql= "select distinct m.manufacturers_id as id, m.manufacturers_name as name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and p.manufacturers_id = m.manufacturers_id and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by m.manufacturers_name";
    	  $filterlist_query = tep_db_query($filterlist_sql);
    	  if (tep_db_num_rows($filterlist_query) > 0) {
    	   echo '<tr><td align="left" class="main" width="40%">'. TEXT_SHOW . '</td><td align="left" width="60%">';
           echo '<select name="filter_id" style="width:90%" onChange="document.location=this.value">';
           $link = str_replace('&amp;','&',tep_get_all_get_params(array('filter_id')));       
    	   echo '<option value="index.php?'.$link.'">'.TEXT_ALL_MANUFACTURERS.'</option>';         
           while ($filterlist = tep_db_fetch_array($filterlist_query)) {
            if (isset($_GET['filter_id']) && $_GET['filter_id'] == $filterlist['id']) { $check = 'selected'; } else { $check = ''; }                 
            echo '<option value="index.php?'.$link.'filter_id='.$filterlist['id'].'" '.$check.'>'.$filterlist['name'].'</option>';
           } 
           echo '</select><br>';       
    	   echo tep_hide_session_id() . '</td></tr>' . "\n";
    	  }
    	}
        
        if (CZY_DISPLAY_SORT == '1') {
            echo '<tr><td align="left" class="main" width="40%">'.TEXT_SHOW_SORT.'</td><td align="left" width="60%">';
            echo '<select name="sort" style="width:90%" onChange="document.location=this.value">';
            $link = str_replace('&amp;','&',tep_get_all_get_params(array('sort'))); 
            if ($_GET['sort'] == '') {
                echo '<option value="index.php?'.$link.'" selected>'.TEXT_SHOW_SORT_DOM.' </option>';
            }            
            for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
              if ($column_list[$i] != 'PRODUCT_LIST_BUY_NOW' && $column_list[$i] != 'PRODUCT_LIST_IMAGE' && $column_list[$i] != 'PRODUCT_LIST_DESCRIPTION' && $column_list[$i] != 'PRODUCT_LIST_SAVE' && $column_list[$i] != 'PRODUCT_LIST_DESCRIPTION') {
                //
                $check_wl = ''; $check_wy = '';
                if (isset($_GET['sort']) && (int)$_GET['sort'] > 0) {
                    if ((int)$_GET['sort'] == ($i+1) && strpos($_GET['sort'],'d') > 0) {
                        $check_wl = 'selected'; $check_wy = '';
                    } else if ((int)$_GET['sort'] == ($i+1) && strpos($_GET['sort'],'a') > 0) {
                        $check_wl = ''; $check_wy = 'selected';
                    }
                }
                //
                switch ($column_list[$i]) {
                  case 'PRODUCT_LIST_MODEL':$nazwa = TABLE_HEADING_MODEL;break;
                  case 'PRODUCT_LIST_NAME':$nazwa = TABLE_HEADING_PRODUCTS;break;
                  case 'PRODUCT_LIST_MANUFACTURER':$nazwa = TABLE_HEADING_MANUFACTURER;break;
                  case 'PRODUCT_LIST_RETAIL_PRICE':$nazwa = TABLE_HEADING_RETAIL_PRICE;break;
                  case 'PRODUCT_LIST_PRICE':$nazwa = TABLE_HEADING_PRICE;break;
                  case 'PRODUCT_LIST_QUANTITY':$nazwa = TABLE_HEADING_QUANTITY;break;
                  case 'PRODUCT_LIST_MAXORDER':$nazwa = TABLE_HEADING_MAXORDER;break;
                  case 'PRODUCT_LIST_WEIGHT':$nazwa = TABLE_HEADING_WEIGHT;break;
                  case 'PRODUCT_LIST_PRODUCTS_AVAILABILITY':$nazwa = TABLE_HEADING_PRODUCTS_AVAILABILITY;break;
                }
                //
                echo '<option value="index.php?'.$link.'sort='.($i+1).'a" '.$check_wy.'>'.$nazwa.' ('.TEXT_ASCENDINGLY.') </option>';
                echo '<option value="index.php?'.$link.'sort='.($i+1).'d" '.$check_wl.'>'.$nazwa.' ('.TEXT_DESCENDINGLY.') </option>';
              }
            }
            echo '</select></td></tr>';
        }

        if ( CZY_DISPLAY_DOSTEPNE == '1' ) {
        	echo '<tr><td align="left" width="40%" class="main">'.TEXT_SHOW_PROD.'</td><td width="60%" align="left">';
        	echo '<select name="dostepny" style="width:90%" onChange="document.location=this.value">';
            $link = str_replace('&amp;','&',tep_get_all_get_params(array('dostepny')));
        	//
        	if (isset($_GET['dostepny']) && $_GET['dostepny'] == 'tak') {
        		$check_wl = 'selected'; $check_wy = '';
        		} else {
        		$check_wl = ''; $check_wy = 'selected';
        	}
        	//
        	echo '<option value="index.php?'.$link.'dostepny=nie" '.$check_wy.'>'.TEXT_SHOW_ALL_PROD.'</option>';
        	echo '<option value="index.php?'.$link.'dostepny=tak" '.$check_wl.'>'.TEXT_SHOW_ONLY_AVA.'</option>';
        	echo '</select></td></tr>';
        }

        if ( CZY_DISPLAY_PROMOCJE == '1' ) {
            if ( SPECIAL_PRICES_HIDE == 'false' ) {
            	echo '<tr><td align="left" class="main" width="40%">'.TEXT_SHOW_PROM.'</td><td align="left" width="60%">';
            	echo '<select name="promocja" style="width:90%" onChange="document.location=this.value">';
                $link = str_replace('&amp;','&',tep_get_all_get_params(array('promocja')));
            	//
            	if (isset($_GET['promocja']) && $_GET['promocja'] == 'tak') {
            		$check_wl = 'selected'; $check_wy = '';
            		} else {
            		$check_wl = ''; $check_wy = 'selected';
            	}
            	//
            	echo '<option value="index.php?'.$link.'promocja=nie" '.$check_wy.'>'.TEXT_SHOW_ALL_PROD.'</option>';
            	echo '<option value="index.php?'.$link.'promocja=tak" '.$check_wl.'>'.TEXT_SHOW_ONLY_PROM.'</option>';
            	echo '</select></td></tr>';
            }
        }
        
        if ( CZY_DISPLAY_CENA == '1' ) {
            $link = str_replace('&amp;','&',tep_get_all_get_params(array('cena')));
            // zakres cenowy
            $tablica_liczb = array();   // cena brutto
            $tablica_id = array();      // id produktow
            $tablica_liczb_netto = array();   // cena netto
            $filterlist_sql = tep_db_query($listing_sql);
            while ($produkt = tep_db_fetch_array($filterlist_sql)) {
                $tablica_liczb[] = tep_add_tax($produkt['final_price'],tep_get_tax_rate($produkt['products_tax_class_id']));
                $tablica_id[] = $produkt['products_id'];
            }     
            if (!isset($HTTP_GET_VARS['cena'])) {  
                // tworzy przedzialy cenowe
                sort($tablica_liczb);
                $max = (int)$tablica_liczb[sizeof($tablica_liczb)-1];          
                $przedzial = floor(zaokr($max)/20);
                $tekst = '';        
                for ($x=0;$x<20;$x++) {
                    // sprawdza czy dla danego przedzialu sa pozycje
                    $licznik = 0;
                    foreach ($tablica_liczb as $tablica) {
                        if ($tablica >= ($x*$przedzial) && $tablica <= (($x+1)*$przedzial)) { $licznik++; }
                    }
                    if ($licznik > 0) {
                        $zakres = ($x*$przedzial).'|'.(($x+1)*$przedzial);
                        //
                    	if (isset($_GET['cena']) && $zakres == $_GET['cena']) {
                    		$check = 'selected'; } else { $check = '';
                    	}
                    	//             
                        $tekst .= '<option value="index.php?'.$link.'cena='.$zakres.'" '.$check.'>'.($x*$przedzial).' - '.(($x+1)*$przedzial).'</option>';
                    }
                } 
              } else {
                $przedzial_cenowy = explode('|',$_GET['cena']);
                if (sizeof($przedzial_cenowy) == 2) {
                    $tekst .= '<option value="index.php?'.$link.'cena='.$_GET['cena'].'" selected>'.$przedzial_cenowy[0].' - '.$przedzial_cenowy[1].'</option>';
                }
            }
        	echo '<tr><td align="left" width="40%" class="main"><b>'.TEXT_SHOW_PRZED_CEN.'</b></td><td width="60%" align="left">';
        	echo '<select name="cena" style="width:90%" onChange="document.location=this.value">';        
            echo '<option value="index.php?'.$link.'">'.TEXT_SHOW_PRZED_CEN_OPTION.'</option>';
        	echo $tekst;
        	echo '</select></td></tr>'; 
        }
        
        //
        if ( CZY_DISPLAY_SPOSOB == '1' ) {
            if (isset($_GET['dis'])) {
                if ($_GET['dis'] == '1') {
                    $sposob_wyswietlania = 'true';
                  } else {
                    $sposob_wyswietlania = 'false';
                }
              } else {
                $sposob_wyswietlania = PRODUCTS_LISTING_DISPLAY_MODE;
            }
            $link = str_replace('&amp;','&',tep_get_all_get_params(array('dis')));
            ?>    
            <tr>
                <td class="smallText" width="40%"><b><?php echo TEXT_SHOW_DISPLAY; ?></b></td>
                <td class="smallText" align="left" width="60%">
                    <select name="display" onChange="document.location=this.value">
                    <option value="index.php?<?php echo $link; ?>dis=1" <?php echo (($sposob_wyswietlania=='true') ? 'selected' : ''); ?>><?php echo TEXT_SHOW_DISPLAY_LIST; ?></option>
                    <option value="index.php?<?php echo $link; ?>dis=0" <?php echo (($sposob_wyswietlania=='false') ? 'selected' : ''); ?>><?php echo TEXT_SHOW_DISPLAY_BOX; ?></option>       
                    </select>
                </td>
            </tr>
        <?php } 
        if ( CZY_DISPLAY_WYNIKI == '1' ) {
            if (isset($_GET['str'])) {
             if ((int)$_GET['str'] > 0) {
                if ((int)$_GET['str'] > 50) {
                    $wyswietlen = 50;
                   } else {
                    $wyswietlen = (int)$_GET['str'];
                }
              }
            } else {
              $wyswietlen = MAX_DISPLAY_SEARCH_RESULTS;
            }
            $link = str_replace('&amp;','&',tep_get_all_get_params(array('str')));
            ?>    
            <tr>
                <td class="smallText" colspan="2" align="right"><?php echo TEXT_SHOW_ILE_NA_STR; ?>&nbsp;
                    <select name="str" onChange="document.location=this.value">
                    <option value="index.php?<?php echo $link; ?>str=5" <?php echo (($wyswietlen==5) ? 'selected' : ''); ?>>5</option>
                    <option value="index.php?<?php echo $link; ?>str=10" <?php echo (($wyswietlen==10) ? 'selected' : ''); ?>>10</option>
                    <option value="index.php?<?php echo $link; ?>str=20" <?php echo (($wyswietlen==20) ? 'selected' : ''); ?>>20</option>
                    <option value="index.php?<?php echo $link; ?>str=30" <?php echo (($wyswietlen==30) ? 'selected' : ''); ?>>30</option>
                    <option value="index.php?<?php echo $link; ?>str=50" <?php echo (($wyswietlen==50) ? 'selected' : ''); ?>>50</option>        
                    </select>
                </td>
            </tr>     
        <?php
        }        
        ?>
        </table>
        </form>
       </td>
     </tr>
    <tr>
     <td><?php include($modules_folder . FILENAME_PRODUCT_LISTING); ?></td>
    </tr>
    <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
    </tr>

  <?php
  if (CZY_PROMOCJE != '0' || !defined('CZY_PROMOCJE')) {
    if (SPECIAL_PRICES_HIDE=='false') {
      $modules_query = tep_db_query("select configuration_id, configuration_description, configuration_title, configuration_value, location, max_display, info_id, header from " . TABLE_MODULES_CONFIGURATION . "  where configuration_title = '".substr(FILENAME_SPECIALS_DEFAULT,0,-4)."'");
      while ($modul = tep_db_fetch_array($modules_query)) {
        if ($modul['configuration_value'] == 'yes') {
          $ilosc_maksymalna = (int)$modul['max_display'];
        }
      }
      ?>
      <tr>
          <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
      </tr>
      <tr>
          <td><?php include($modules_folder . FILENAME_SPECIALS_DEFAULT); ?></td>
      </tr>
      <?php
    }
  }
  ?>

  <?php
  if (CZY_NOWE_PRODUKTY != '0' || !defined('CZY_NOWE_PRODUKTY')) {
    $modules_query = tep_db_query("select configuration_id, configuration_description, configuration_title, configuration_value, location, max_display, info_id, header from " . TABLE_MODULES_CONFIGURATION . "  where configuration_title = '".substr(FILENAME_NEW_PRODUCTS,0,-4)."'");
    while ($modul = tep_db_fetch_array($modules_query)) {
      if ($modul['configuration_value'] == 'yes') {
        $ilosc_maksymalna = (int)$modul['max_display'];
      }
    }
    ?>
    <tr>
      <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
    </tr>
    <tr>
      <td><?php include($modules_folder . FILENAME_NEW_PRODUCTS); ?></td>
    </tr>
    <?php
  }
  ?>

  <?php
  if (CZY_POLECANE_PRODUKTY != '0' || !defined('CZY_POLECANE_PRODUKTY')) {
    $modules_query = tep_db_query("select configuration_id, configuration_description, configuration_title, configuration_value, location, max_display, info_id, header from " . TABLE_MODULES_CONFIGURATION . "  where configuration_title = '".substr(FILENAME_FEATURED,0,-4)."'");
    while ($modul = tep_db_fetch_array($modules_query)) {
      if ($modul['configuration_value'] == 'yes') {
        $ilosc_maksymalna = (int)$modul['max_display'];
      }
    }
    ?>
    <tr>
      <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '3'); ?></td>
    </tr>
    <tr>
      <td><?php include($modules_folder . FILENAME_FEATURED); ?></td>
    </tr>
    <?php
  }
  ?>
</table>