<?php
/*
  $Id: product_listing.php,v 1.7 2007/05/07 07:06:33 ryu Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
  
  modified for Koshoten.net2
  http://www.koshoten.net/
*/
?>
<!-- productsList -->
<?php
  $listing_numrows_sql = $listing_sql;
  $listing_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $listing_sql, $listing_numrows);
  if (isset($option_search_engine_safe)) {
    $listing_split->set_search_engine_safe($option_search_engine_safe);
  }
// fix counted products
  $listing_numrows = tep_db_query($listing_numrows_sql);
  $listing_numrows = tep_db_num_rows($listing_numrows);

  if ( ($listing_numrows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
?>
<div class="listLink">
<p class="listCount"><?php echo $listing_split->display_count($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></p>
<p class="listPrevNext"><?php echo TEXT_RESULT_PAGE; ?> <?php echo $listing_split->display_links($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></p>
</div>
<?php
  }
?>
<?php
  $list_box_contents = array();
  $cur_row = 0;

  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    switch ($column_list[$col]) {
      case 'PRODUCT_LIST_MODEL':
        $lc_text = TABLE_HEADING_MODEL;
        $lc_param = 'pModel';
        break;
      case 'PRODUCT_LIST_NAME':
        $lc_text = TABLE_HEADING_PRODUCTS;
        $lc_param = 'pName';
        break;
      case 'PRODUCT_LIST_SUBTITLE':
        $lc_text = TABLE_HEADING_SUBTITLE;
        $lc_param = 'pSubtitle';
        break;
      case 'PRODUCT_LIST_SERIES_TITLE':
        $lc_text = TABLE_HEADING_SERIES_TITLE;
        $lc_param = 'pSeriesTitle';
        break;
      case 'PRODUCT_LIST_AUTHOR':
        $lc_text = TABLE_HEADING_AUTHOR;
        $lc_param = 'pAuthor';
        break;
      case 'PRODUCT_LIST_PUBLISHED':
        $lc_text = TABLE_HEADING_PUBLISHED;
        $lc_param = 'pPublished';
        break;
      case 'PRODUCT_LIST_VOLUME':
        $lc_text = TABLE_HEADING_VOLUME;
        $lc_param = 'pVolume';
        break;
      case 'PRODUCT_LIST_ISBN':
        $lc_text = TABLE_HEADING_ISBN;
        $lc_param = 'pIsbn';
        break;
      case 'PRODUCT_LIST_DESCRIPTION':
        $lc_text = TABLE_HEADING_DESCRIPTION;
        $lc_param = 'pDescription';
        break;
      case 'PRODUCT_LIST_PUBLISHERS':
        $lc_text = TABLE_HEADING_PUBLISHERS;
        $lc_param = 'pPublishers';
        break;
      case 'PRODUCT_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_param = 'pPrice';
        break;
      case 'PRODUCT_LIST_QUANTITY':
        $lc_text = TABLE_HEADING_QUANTITY;
        $lc_param = 'pQuantity';
        break;
      case 'PRODUCT_LIST_WEIGHT':
        $lc_text = TABLE_HEADING_WEIGHT;
        $lc_param = 'pWeight';
        break;
      case 'PRODUCT_LIST_IMAGE':
        $lc_text = TABLE_HEADING_IMAGE;
        $lc_param = 'pImage';
        break;
      case 'PRODUCT_LIST_BUY_NOW':
        if (defined("KN_CFG_ALLOW_CHECKOUT") && (KN_CFG_ALLOW_CHECKOUT == "false")) {
          $lc_text = '';
          $lc_param = 'pBuyNow';
        } else {
          $lc_text = TABLE_HEADING_BUY_NOW;
          $lc_param = 'pBuyNow';
        }
        break;
    }
    
    if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') && ($column_list[$col] != 'PRODUCT_LIST_DESCRIPTION') ) {
      $lc_text = tep_create_sort_heading($_GET['sort'], $col+1, $lc_text);
    }
    
    if ($lc_text == '') {
      $lc_text = '&nbsp;';
    }

    $list_box_contents[$cur_row][] = array('params' => 'class="' . $lc_param . '"',
                                           'text' => $lc_text);
  }

  if ($listing_numrows > 0) {
    $number_of_products = '0';
    $listing_query = tep_db_query($listing_sql);
    while ($listing = tep_db_fetch_array($listing_query)) {
      $number_of_products++;

      if (($number_of_products/2) == floor($number_of_products/2)) {
        $list_box_contents[] = array('params' => 'class="even"');
      } else {
        $list_box_contents[] = array('params' => 'class="odd"');
      }

      $cur_row = sizeof($list_box_contents) - 1;

      for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
        $lc_param = '';

        switch ($column_list[$col]) {
          case 'PRODUCT_LIST_MODEL':
            $lc_param = 'pModel';
            $lc_text = $listing['products_model'];
            break;
          case 'PRODUCT_LIST_NAME':
            $lc_param = 'pName';
            if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id']) {
              $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $_GET['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
            } else {
              $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';
            }
            break;
          case 'PRODUCT_LIST_SUBTITLE':
            $lc_param = 'pSubtitle';
            $lc_text = $listing['products_subtitle'];
            break;
          case 'PRODUCT_LIST_SERIES_TITLE':
            $lc_param = 'pSeriesTitle';
            $lc_text = $listing['products_series_title'];
            break;
          case 'PRODUCT_LIST_AUTHOR':
            $lc_param = 'pAuthor';
            $lc_text = $listing['products_author'];
            break;
          case 'PRODUCT_LIST_PUBLISHED':
            $lc_param = 'pPublished';
            $lc_text = $listing['products_published'];
            break;
          case 'PRODUCT_LIST_VOLUME':
            $lc_param = 'pVolume';
            $lc_text = $listing['products_volume'];
            break;
          case 'PRODUCT_LIST_ISBN':
            $lc_param = 'pIsbn';
            $lc_text = $listing['products_isbn'];
            break;
          case 'PRODUCT_LIST_PUBLISHERS':
            $lc_param = 'pPublishers';
            $lc_text = $listing['products_publishers'];
            break;
          case 'PRODUCT_LIST_DESCRIPTION':
            $lc_param = 'pDescription';
            if (KN_CFG_PRODUCT_LIST_WITHIN_DESCRIPTION == 'true') {
              $lc_text = '';
              if ((KN_CFG_USE_SUBTITLE == 'true') && ($listing['products_subtitle'])) {
                $lc_text .= $listing['products_subtitle'] . ' ';
              }
              if ((KN_CFG_USE_SERIES_TITLE == 'true') && ($listing['products_series_title'])) {
                $lc_text .= $listing['products_series_title'] . ' ';
              }
              $lc_text .= $listing['products_description'] . ' ';
              if ((KN_CFG_USE_VOLUME == 'true') && ($listing['products_volume'])) {
                $lc_text .= $listing['products_volume'] . ' ';
              }
              if ((KN_CFG_USE_PUBLISHED == 'true') && ($listing['products_published'])) {
                $lc_text .= $listing['products_published'] . ' ';
              }
              if ((KN_CFG_USE_PUBLISHERS == 'true') && ($listing['products_publishers'])) {
                $lc_text .= $listing['products_publishers'];
              }
            } else {
              $lc_text = $listing['products_description'];
            }
            break;
          case 'PRODUCT_LIST_PRICE':
            $lc_param = 'pPrice';
            if (tep_not_null($listing['specials_new_products_price'])) {
              $lc_text = '<del>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del>&nbsp;&nbsp;<span class="specialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span>';
            } else {
              if ((KN_CFG_CONTACT_PRICE != 0) && ($listing['products_price'] == KN_CFG_CONTACT_PRICE)) {
                $lc_text = '-';
              } else {
                $lc_text = $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id']));
              }
            }
            break;
          case 'PRODUCT_LIST_QUANTITY':
            $lc_param = 'pQuantity';
            $lc_text = $listing['products_quantity'];
            break;
          case 'PRODUCT_LIST_WEIGHT':
            $lc_param = 'pWeight';
            $lc_text = $listing['products_weight'];
            break;
          case 'PRODUCT_LIST_IMAGE':
            $lc_param = 'pImage';
            if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id']) {
              $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $_GET['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
            } else {
              $lc_text = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>';
            }
            break;
          case 'PRODUCT_LIST_BUY_NOW':
            $lc_param = 'pBuyNow';
            if (defined("KN_CFG_ALLOW_CHECKOUT") && (KN_CFG_ALLOW_CHECKOUT == "false")) {
              if ((KN_CFG_CONTACT_PRICE != 0) && ($listing['products_price'] == KN_CFG_CONTACT_PRICE)) {
                if (defined("KN_CFG_CONTACT_BY_EMAIL") && (KN_CFG_CONTACT_BY_EMAIL == 'false')) {
                  $lc_text = KN_CFG_CONTACT_PRICE_TEXT;
                } else {
                  $sjis_p_name = mb_convert_encoding($listing['products_name'], "SJIS", "EUC-JP");
                  $sjis_p_email_subject = mb_convert_encoding(KN_CFG_CONTACT_PRICE_EMAIL_SUBJECT, "SJIS", "EUC-JP");
                  $sjis_p_email_body = mb_convert_encoding(KN_CFG_CONTACT_PRICE_EMAIL_BODY, "SJIS", "EUC-JP");
                  $email_subject = rawurlencode($sjis_p_email_subject) . rawurlencode($sjis_p_name);
                  $email_body = rawurlencode($sjis_p_email_body);
                  $lc_text = '<a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '?subject=' . $email_subject . '&body=' . $email_body . '">' . KN_CFG_CONTACT_PRICE_TEXT . '</a>';
                }
              } else {
                $lc_text = '&nbsp;';
              }
            } else {
              if ((KN_CFG_CONTACT_PRICE != 0) && ($listing['products_price'] == KN_CFG_CONTACT_PRICE)) {
                if (KN_CFG_CONTACT_BY_EMAIL == 'true') {
                  $sjis_p_name = mb_convert_encoding($listing['products_name'], "SJIS", "EUC-JP");
                  $sjis_p_email_subject = mb_convert_encoding(KN_CFG_CONTACT_PRICE_EMAIL_SUBJECT, "SJIS", "EUC-JP");
                  $sjis_p_email_body = mb_convert_encoding(KN_CFG_CONTACT_PRICE_EMAIL_BODY, "SJIS", "EUC-JP");
                  $email_subject = rawurlencode($sjis_p_email_subject) . rawurlencode($sjis_p_name);
                  $email_body = rawurlencode($sjis_p_email_body);
                  $lc_text = '<a href="mailto:' . STORE_OWNER_EMAIL_ADDRESS . '?subject=' . $email_subject . '&body=' . $email_body . '">' . KN_CFG_CONTACT_PRICE_TEXT . '</a>';
                } else {
                  $lc_text = KN_CFG_CONTACT_PRICE_TEXT;
                }
              } else {
                $lc_text = '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']) . '">' . tep_image_button('button_buy_now.gif', TEXT_BUY . $listing['products_name'] . TEXT_NOW) . '</a>';
              }
            }
            break;
        }

    if ($lc_text == '') {
      $lc_text = '&nbsp;';
    }

        $list_box_contents[$cur_row][] = array('params' => 'class="' . $lc_param . '"',
                                               'text'  => $lc_text);
      }
    }

    new listingBox($list_box_contents, true, true);
  } else {
?>
  <p class="noData"><?php echo (!empty($_GET['manufacturers_id']) ? TEXT_NO_PRODUCTS2 : TEXT_NO_PRODUCTS); ?></p>
<?php
  }

  if ( ($listing_numrows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) {
?>
<div class="listLink">
<p class="listCount"><?php echo $listing_split->display_count($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></p>
<p class="listPrevNext"><?php echo TEXT_RESULT_PAGE; ?> <?php echo $listing_split->display_links($listing_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_GET['page'], tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></p>
</div>
<?php
  }
?>
<!-- /productsList -->
