<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
    <table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
<?php
// BOF: Lango Added for template MOD
if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
$header_text = '&nbsp;'
//EOF: Lango Added for template MOD
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
                        <td class="pageHeading">
             <?php 
               if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($subs_category['subscription_categories_heading_title'])) ) {
                 echo $category['subscription_categories_heading_title'];
               } else {
                 echo HEADING_TITLE;
               }
             ?>
            </td>
            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . $subs_category['subscription_categories_image'], $subs_category['subscription_categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
	  <?php if ( (ALLOW_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($subs_category['subscription_categories_description'])) ) { ?>
	  <tr>
            <td align="left" colspan="2" class="category_desc"><?php echo $subs_category['subscription_categories_description']; ?></td>
	  </tr>
	  <?php } ?>
        </table></td>
      </tr>
<?php
// BOF: Lango Added for template MOD
}else{
    // Get the category name and description
    $subs_category_query = tep_db_query("select sucd.subscription_categories_name, sucd.subscription_categories_heading_title, sucd.subscription_categories_description, suc.subscription_categories_image from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.subscription_categories_id = '" . $current_subscription_category_id . "' and sucd.subscription_categories_id = '" . $current_subscription_category_id . "' and sucd.language_id = '" . $languages_id . "'");
	$subs_category = tep_db_fetch_array($subs_category_query);

               if ((tep_not_null($subs_category['subscription_categories_heading_title'])) ) {
                 $header_text= $subs_category['subscription_categories_heading_title'];
               } else {
                 $header_text=HEADING_TITLE;
               }
}
// EOF: Lango Added for template MOD
	if(!isset($hide_row_top)) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php } ?>	  

      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_top(false, false, $header_text);
}
// EOF: Lango Added for template MOD
?>
			<tr>
				<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
    if (isset($sucPath) && strpos('_', $sucPath)) {
// check to see if there are deeper categories within the current category
      $subs_category_links = array_reverse($sucPath_array);
      for($i=0, $n=sizeof($subs_category_links); $i<$n; $i++) {
        $subs_categories_query = tep_db_query("select count(*) as total from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.parent_id = '" . (int)$subs_category_links[$i] . "' and suc.subscription_categories_id = sucd.subscription_categories_id and sucd.language_id = '" . (int)$languages_id . "'");
        $subs_categories = tep_db_fetch_array($subs_categories_query);
        if ($subs_categories['total'] < 1) {
          // do nothing, go through the loop
        } else {
          $subs_categories_query = tep_db_query("select suc.subscription_categories_id, sucd.subscription_categories_name, suc.subscription_categories_image, suc.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.parent_id = '" . (int)$subscription_category_links[$i] . "' and suc.subscription_categories_id = sucd.subscription_categories_id and sucd.language_id = '" . (int)$languages_id . "' order by sort_order, sucd.subscription_categories_name");
          break; // we've found the deepest category the customer is in
        }
      }
    } else {
      $subs_categories_query = tep_db_query("select suc.subscription_categories_id, sucd.subscription_categories_name, suc.subscription_categories_image, suc.parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " suc, " . TABLE_SUBSCRIPTION_CATEGORIES_DESCRIPTION . " sucd where suc.parent_id = '" . (int)$current_subscription_category_id . "' and suc.subscription_categories_id = sucd.subscription_categories_id and sucd.language_id = '" . (int)$languages_id . "' order by sort_order, sucd.subscription_categories_name");
    }

    $number_of_subs_categories = tep_db_num_rows($subs_categories_query);

    $rows = 0;
    while ($subs_categories = tep_db_fetch_array($subs_categories_query)) {
      $rows++;
      $sucPath_new = tep_get_subscription_path($subs_categories['subscription_categories_id']);
      $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
      echo '                <td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $sucPath_new) . '">' . tep_image(DIR_WS_IMAGES . $subs_categories['subscription_categories_image'], $subs_categories['subscription_categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $subs_categories['subscription_categories_name'] . '</a></td>' . "\n";
      if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_subs_categories)) {
        echo '              </tr>' . "\n";
        echo '              <tr>' . "\n";
      }
    }

// needed for the new products module shown below
    $new_subscription_category_id = $current_subscription_category_id;
?>
			</table>
			</td>
              </tr>
<?php
// BOF: Lango Added for template MOD
if (MAIN_TABLE_BORDER == 'yes'){
table_image_border_bottom();
}
// EOF: Lango Added for template MOD
?>
            </table>
			</td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
          </tr>
          <tr>
            <td><?php include(DIR_WS_MODULES . FILENAME_NEW_SUBSCRIPTION); ?></td>
          </tr>
        </table></td>
      </tr>
    </table>
