<?php
/*
  products_edit.php
  作成日：2004/12/2
　最終更新日：2005/9/24

　作成者：有限会社セカンドブレーン
　　　　　　青木隆平
　　　　　　ryuhei@secondbrain.co.jp

  Released under the GNU General Public License
*/

  require('includes/application_top.php');
  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  define('MAX_DISPLAY_DATE_ADDED', 10);				// 登録日ごとの件数一覧の表示数
  define('MAX_DISPLAY_LAST_MODIFIED', 10);				// 更新日ごとの件数一覧の表示数

  if ($_GET['action']) {
    switch ($_GET['action']) {
      case 'search':
        // 商品検索
        $where_str = '';
        $offset = 0;
        if ($_GET['subject']) {
          switch ($_GET['subject']) {
            case 'products_date_added':
              // 登録日での検索
              $search_products_date_added = urldecode($_GET['value']);
              break;
            case 'products_last_modified':
              // 更新日での検索
              $search_products_last_modified = urldecode($_GET['value']);
              break;
            case 'categories_id':
              // カテゴリーでの検索
              $search_categories_id = $_GET['value'];
              break;
            case 'post':
              // 検索画面からの検索
              $search_products_status = $_POST['products_status'];
              $search_categories_id = $_POST['categories_id'];
              $search_products_name = $_POST['products_name'];
              $search_products_subtitle = $_POST['products_subtitle'];
              $search_products_series_title = $_POST['products_series_title'];
              $search_products_author = $_POST['products_author'];
              $search_products_model = $_POST['products_model'];
              $search_products_publishers = $_POST['products_publishers'];
              $search_products_memo = $_POST['products_memo'];
              $search_manufacturers_id = $_POST['manufacturers_id'];
              $search_products_isbn = $_POST['products_isbn'];
              break;
          }
        } else {
          // ページ移動
          if ($_GET['page']) {
            $search_products_status = $_GET['products_status'];
            $search_categories_id = $_GET['categories_id'];
            $search_products_name = urldecode($_GET['products_name']);
            $search_products_subtitle = urldecode($_GET['products_subtitle']);
            $search_products_series_title = urldecode($_GET['products_series_title']);
            $search_products_author = urldecode($_GET['products_author']);
            $search_products_model = urldecode($_GET['products_model']);
            $search_products_publishers = urldecode($_GET['products_publishers']);
            $search_products_memo = urldecode($_GET['products_memo']);
            $search_manufacturers_id = $_GET['manufacturers_id'];
            $search_products_isbn = urldecode($_GET['products_isbn']);
            $search_products_date_added = urldecode($_GET['value']);
            $search_products_last_modified = urldecode($_GET['value']);
          }
        }
        // SQL文の生成
        $select_str = "select p.products_id, p.products_model, pd.products_name, pd.products_subtitle, pd.products_series_title, pd.products_author, pd.products_description, pd.products_publishers, p.products_image, p.products_price, p.manufacturers_id, p.products_date_added, p.products_isbn, p.products_last_modified, p.products_status, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id";
        if (!$where_str) {
          $where_str = '';
          $get_params = 'action=search';
          if ($search_products_status != '') {
            $where_str .= " and p.products_status = '" . tep_db_input($search_products_status) . "'";
            $get_params .= '&products_status=' . $search_products_status;
          }
          if ($search_categories_id != '') {
            $where_str .= " and p2c.categories_id = '" . tep_db_input($search_categories_id) . "'";
            $get_params .= '&categories_id=' . $search_categories_id;
          }
          if ($search_products_name != '') {
            $where_str .= " and pd.products_name like '%" . tep_db_input($search_products_name) . "%'";
            $get_params .= '&products_name=' . urlencode($search_products_name);
          }
          if ($search_products_subtitle != '') {
            $where_str .= " and pd.products_subtitle like '%" . tep_db_input($search_products_subtitle) . "%'";
            $get_params .= '&products_subtitle=' . urlencode($search_products_subtitle);
          }
          if ($search_products_series_title != '') {
            $where_str .= " and pd.products_series_title like '%" . tep_db_input($search_products_series_title) . "%'";
            $get_params .= '&products_series_title=' . urlencode($search_products_series_title);
          }
          if ($search_products_author != '') {
            $where_str .= " and pd.products_author like '%" . tep_db_input($search_products_author) . "%'";
            $get_params .= '&products_author=' . urlencode($search_products_author);
          }
          if ($search_products_publishers != '') {
            $where_str .= " and pd.products_publishers like '%" . tep_db_input($search_products_publishers) . "%'";
            $get_params .= '&products_publishers=' . urlencode($search_products_publishers);
          }
          if ($search_products_model != '') {
            $where_str .= " and p.products_model = '" . tep_db_input($search_products_model) . "'";
            $get_params .= '&products_model=' . urlencode($search_products_model);
          }
          if ($search_products_memo != '') {
            $where_str .= " and pd.products_memo like '%" . tep_db_input($search_products_memo) . "%'";
            $get_params .= '&products_memo=' . urlencode($search_products_memo);
          }
          if ($search_manufacturers_id != '') {
            $where_str .= " and p.manufacturers_id = '" . tep_db_input($search_manufacturers_id) . "'";
            $get_params .= '&manufacturers_id=' . $search_manufacturers_id;
          }
          if ($search_products_isbn != '') {
            $where_str .= " and p.products_isbn = '" . tep_db_input($search_products_isbn) . "'";
            $get_params .= '&products_isbn=' . urlencode($search_products_isbn);
          }
          if ($search_products_date_added != '') {
            $where_str .= " and p.products_date_added = '" . tep_db_input($search_products_date_added) . "'";
            $get_params .= '&products_date_added=' . urlencode($search_products_date_added);
          }
          if ($search_products_last_modified != '') {
            $where_str .= " and p.products_last_modified = '" . tep_db_input($search_products_last_modified) . "'";
            $get_params .= '&products_lastmodified=' . urlencode($search_products_last_modified);
          }
        }
        $order_str = " order by p.sort_order, p.products_model, pd.products_name";
        $listing_sql = $select_str . $where_str . $order_str;
        $page_split = new splitPageResults($_GET['page'], MAX_DISPLAY_SEARCH_RESULTS, $listing_sql, $results_numrows);
        $search_products_query = tep_db_query($listing_sql);        
        
        if ($results_numrows < 1) {
        	 // 検索結果が１件もない場合は、エラーメッセージ
          $messageStack->add_session(ERROR_NO_SEARCH_RESULTS, 'error');
          tep_redirect(tep_href_link(FILENAME_PRODUCTS_EDIT));
        }
        break;
      case 'new_product':
        // 商品の新規登録
        $pInfo = new objectInfo(array());
        $action = 'new_product_confirm';
        break;
      case 'edit_product':
        // 商品データの編集
        $edit_product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_description2, pd.products_url, pd.products_subtitle, pd.products_series_title, pd.products_author, pd.products_published, pd.products_publishers, pd.products_volume, pd.products_keywords, pd.products_memo, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_isbn, p.recommendation_order, p.sort_order, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = '" . tep_db_input($_GET['pID']) . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and p.products_id = p2c.products_id");
        $edit_product = tep_db_fetch_array($edit_product_query);
        $pInfo = new objectInfo($edit_product);
        $action = 'edit_product_confirm';
        break;
      case 'new_product_confirm':
        // 商品データの新規登録確認
        $input_error = false;
        
        if ($_POST['categories_id']) {
          $check_category_id = tep_db_input($_POST['categories_id']);
          $category_check_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_id = '" . $check_category_id . "'");
          $category_check = tep_db_fetch_array($category_check_query);
          if ($category_check['total'] < 1) {
        	   // カテゴリーが存在しない場合は、エラーメッセージ
            $messageStack->add(ERROR_CATEGORY_DOES_NOT_EXIST, 'error');
            $input_error = true;
          } else {
            $products_image = tep_get_uploaded_file('products_image');
            $p2c_images_dir = 'c' . $check_category_id . '/';
            $image_directory = tep_get_local_path(DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir);
            if (is_dir($image_directory)) {
              if (is_writeable($image_directory)) {
                // 画像のアップロード（カテゴリーごとにディレクトリを分けて保存）
                if (is_uploaded_file($products_image['tmp_name'])) {
                  $products_image_path = DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . $products_image['name'];
                  tep_copy_uploaded_file($products_image, $image_directory);
                }
              } else {
                $messageStack->add(printf(ERROR_PRODUCTS_IMAGE_DIRECTORY2_NOT_WRITEABLE, $p2c_images_dir), 'error');
                $input_error = true;
              }
            } else {
              // 商品画像用ディレクトリがない場合、作成する。
              @mkdir($image_directory, 0777);
              if (is_dir($image_directory)) {
                // 画像のアップロード（カテゴリーごとにディレクトリを分けて保存）
                if (is_uploaded_file($products_image['tmp_name'])) {
                  $products_image_path = DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . $products_image['name'];
                  tep_copy_uploaded_file($products_image, $image_directory);
                }
              } else {
                $messageStack->add(printf(ERROR_PRODUCTS_IMAGE_DIRECTORY2_DOES_NOT_EXIST, $p2c_images_dir), 'error');
                $input_error = true;
              }
            }
          }
        } else {
          $messageStack->add(ERROR_CATEGORIES_ID_IS_EMPTY, 'error');
        	 $input_error = true;
        }
        
        if (!$_POST['products_name']) {
          $messageStack->add(ERROR_PRODUCTS_NAME_IS_EMPTY, 'error');
        	 $input_error = true;
        }
        
        if ($input_error) {
        	 // 必須項目が未入力のときは編集画面へ
          $edit_product = array();
          $edit_product['categoires_id'] = $_POST['categories_id'];
          $edit_product['products_name'] = $_POST['products_name'];
          $edit_product['products_subtitle'] = $_POST['products_subtitle'];
          $edit_product['products_series_title'] = $_POST['products_series_title'];
          $edit_product['products_author'] = $_POST['products_author'];
          $edit_product['products_status'] = $_POST['products_status'];
          $edit_product['products_model'] = $_POST['products_model'];
          $edit_product['products_image'] = $_POST['products_image'];
          $edit_product['products_volume'] = $_POST['products_volume'];
          $edit_product['products_published'] = $_POST['products_published'];
          $edit_product['products_publishers'] = $_POST['products_publishers'];
          $edit_product['products_price'] = $_POST['products_price'];
          $edit_product['products_quantity'] = $_POST['products_quantity'];
          $edit_product['products_weight'] = $_POST['products_weight'];
          $edit_product['products_description'] = $_POST['products_description'];
          $edit_product['products_description2'] = $_POST['products_description2'];
          $edit_product['products_url'] = $_POST['products_url'];
          $edit_product['products_keywords'] = $_POST['products_keywords'];
          $edit_product['manufacturers_id'] = $_POST['manufacturers_id'];
          $edit_product['products_isbn'] = $_POST['products_isbn'];
          $edit_product['products_date_available'] = $_POST['products_date_available'];
          $edit_product['products_tax_class_id'] = $_POST['products_tax_class_id'];
          $edit_product['products_memo'] = $_POST['products_memo'];
          $edit_product['recommendation_order'] = $_POST['recommendation_order'];
          $edit_product['sort_order'] = $_POST['sort_order'];
          $pInfo = new objectInfo($edit_product);
          $_GET['action'] = 'new_product';
          $action = 'new_product_confirm';
        } else {
          $action = 'insert_product';
        }
        break;
      case 'edit_product_confirm':
        // カテゴリーの編集確認
        $input_error = false;
        
        if ($_POST['categories_id']) {
          $check_category_id = tep_db_input($_POST['categories_id']);
          $category_check_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " where categories_id = '" . $check_category_id . "'");
          $category_check = tep_db_fetch_array($category_check_query);
          if ($category_check['total'] < 1) {
        	   // カテゴリーが存在しない場合は、エラーメッセージ
            $messageStack->add(ERROR_CATEGORY_DOES_NOT_EXIST, 'error');
            $input_error = true;
          } else {
            $products_image = tep_get_uploaded_file('products_image');
            $p2c_images_dir = 'c' . $check_category_id . '/';
            $image_directory = tep_get_local_path(DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir);
            if (is_dir($image_directory)) {
              if (is_writeable($image_directory)) {
                // 画像のアップロード（カテゴリーごとにディレクトリを分けて保存）
                if ($_POST['delete_image']) {
                  $products_image_path = '';
                  if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image'])) {
                    @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image']);
                  }
                } else {
                  if (is_uploaded_file($products_image['tmp_name'])) {
                    // 以前の画像ファイルがあれば削除して、アップロードした画像ファイルを登録
                    if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image'])) {
                      @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image']);
                    }
                    $products_image_path = DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . $products_image['name'];
                    tep_copy_uploaded_file($products_image, $image_directory);
                  } else {
                    if ($_POST['categories_id'] == $_POST['previous_categories_id']) {
                      $products_image_path = $_POST['previous_product_image'];
                    } else {
                      // カテゴリーが変わったので、画像ファイルの格納先を変更する
                      if (@copy(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image'], DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . basename($_POST['previous_product_image']))) {
                        @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image']);
                        $products_image_path = DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . basename($_POST['previous_product_image']);
                      } else {
                        $products_image_path = $_POST['previous_product_image'];
                      }
                    }
                  }
                }
              } else {
                $messageStack->add(printf(ERROR_PRODUCTS_IMAGE_DIRECTORY2_NOT_WRITEABLE, $p2c_images_dir), 'error');
                $input_error = true;
              }
            } else {
              // 商品画像用ディレクトリがない場合、作成する。
              @mkdir($image_directory, 0777);
              if (is_dir($image_directory)) {
                // 画像のアップロード（カテゴリーごとにディレクトリを分けて保存）
                if ($_POST['delete_image']) {
                  $products_image_path = '';
                  if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image'])) {
                    @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image']);
                  }
                } else {
                  if (is_uploaded_file($products_image['tmp_name'])) {
                    // 以前の画像ファイルがあれば削除して、アップロードした画像ファイルを登録
                    if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image'])) {
                      @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image']);
                    }
                    $products_image_path = DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . $products_image['name'];
                    tep_copy_uploaded_file($products_image, $image_directory);
                  } else {
                    if ($_POST['categories_id'] == $_POST['previous_categories_id']) {
                      $products_image_path = $_POST['previous_product_image'];
                    } else {
                      // カテゴリーが変わったので、画像ファイルの格納先を変更する
                      if (@copy(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image'], DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . basename($_POST['previous_product_image']))) {
                        @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_product_image']);
                        $products_image_path = DIR_WS_PRODUCTS_IMAGES . $p2c_images_dir . basename($_POST['previous_product_image']);
                      } else {
                        $products_image_path = $_POST['previous_product_image'];
                      }
                    }
                  }
                }
              } else {
                $messageStack->add(printf(ERROR_PRODUCTS_IMAGE_DIRECTORY2_DOES_NOT_EXIST, $p2c_images_dir), 'error');
                $input_error = true;
              }
            }
          }
        } else {
          $messageStack->add(ERROR_CATEGORIES_ID_IS_EMPTY, 'error');
          $input_error = true;
        }
        
        if (!$_POST['products_name']) {
          $messageStack->add(ERROR_PRODUCTS_NAME_IS_EMPTY, 'error');
        	 $input_error = true;
        }
        
        if ($input_error) {
        	 // 必須項目が未入力のときは編集画面へ
          $edit_product = array();
          $edit_product['products_id'] = $_POST['products_id'];
          $edit_product['categoires_id'] = $_POST['categories_id'];
          $edit_product['products_name'] = $_POST['products_name'];
          $edit_product['products_subtitle'] = $_POST['products_subtitle'];
          $edit_product['products_series_title'] = $_POST['products_series_title'];
          $edit_product['products_author'] = $_POST['products_author'];
          $edit_product['products_status'] = $_POST['products_status'];
          $edit_product['products_model'] = $_POST['products_model'];
          $edit_product['products_image'] = $_POST['products_image'];
          $edit_product['products_volume'] = $_POST['products_volume'];
          $edit_product['products_published'] = $_POST['products_published'];
          $edit_product['products_publishers'] = $_POST['products_publishers'];
          $edit_product['products_price'] = $_POST['products_price'];
          $edit_product['products_quantity'] = $_POST['products_quantity'];
          $edit_product['products_weight'] = $_POST['products_weight'];
          $edit_product['products_description'] = $_POST['products_description'];
          $edit_product['products_description2'] = $_POST['products_description2'];
          $edit_product['products_url'] = $_POST['products_url'];
          $edit_product['products_keywords'] = $_POST['products_keywords'];
          $edit_product['manufacturers_id'] = $_POST['manufacturers_id'];
          $edit_product['products_isbn'] = $_POST['products_isbn'];
          $edit_product['products_date_available'] = $_POST['products_date_available'];
          $edit_product['products_tax_class_id'] = $_POST['products_tax_class_id'];
          $edit_product['products_memo'] = $_POST['products_memo'];
          $edit_product['recommendation_order'] = $_POST['recommendation_order'];
          $edit_product['sort_order'] = $_POST['sort_order'];
          $pInfo = new objectInfo($edit_product);
          $_GET['action'] = 'edit_product';
          $action = 'edit_product_confirm';
        } else {
          $action = 'update_product';
        }
        break;
      case 'insert_product':
      case 'update_product':
        if (($_POST['edit_x']) || ($_POST['edit_y'])) {
        	 // プレビュー画面で戻るボタンを押されたとき
          $edit_product = array();
          $edit_product['products_id'] = $_POST['products_id'];
          $edit_product['categoires_id'] = $_POST['categories_id'];
          $edit_product['products_name'] = $_POST['products_name'];
          $edit_product['products_subtitle'] = $_POST['products_subtitle'];
          $edit_product['products_series_title'] = $_POST['products_series_title'];
          $edit_product['products_author'] = $_POST['products_author'];
          $edit_product['products_status'] = $_POST['products_status'];
          $edit_product['products_model'] = $_POST['products_model'];
          $edit_product['products_image'] = $_POST['products_image_path'];
          $edit_product['products_volume'] = $_POST['products_volume'];
          $edit_product['products_published'] = $_POST['products_published'];
          $edit_product['products_publishers'] = $_POST['products_publishers'];
          $edit_product['products_price'] = $_POST['products_price'];
          $edit_product['products_quantity'] = $_POST['products_quantity'];
          $edit_product['products_weight'] = $_POST['products_weight'];
          $edit_product['products_description'] = $_POST['products_description'];
          $edit_product['products_description2'] = $_POST['products_description2'];
          $edit_product['products_url'] = $_POST['products_url'];
          $edit_product['products_keywords'] = $_POST['products_keywords'];
          $edit_product['manufacturers_id'] = $_POST['manufacturers_id'];
          $edit_product['products_isbn'] = $_POST['products_isbn'];
          $edit_product['products_date_available'] = $_POST['products_date_available'];
          $edit_product['products_tax_class_id'] = $_POST['products_tax_class_id'];
          $edit_product['products_memo'] = $_POST['products_memo'];
          $edit_product['recomendation_order'] = $_POST['recommendation_order'];
          $edit_product['sort_order'] = $_POST['sort_order'];
          $pInfo = new objectInfo($edit_product);
          if ($_GET['action'] == 'insert_product') {
            $_GET['action'] = 'new_product';
            $action = 'new_product_confirm';
          } elseif ($_GET['action'] == 'update_product') {
            $_GET['action'] = 'edit_product';
            $action = 'edit_product_confirm';
          }
        } else {
          // productsテーブルの更新
          $products_id = tep_db_prepare_input($_POST['products_id']);
          $categories_id = tep_db_prepare_input($_POST['categories_id']);
          $previous_categories_id = tep_db_prepare_input($_POST['previous_categories_id']);
          $products_name = tep_db_prepare_input($_POST['products_name']);
          $products_subtitle = tep_db_prepare_input($_POST['products_subtitle']);
          $products_series_title = tep_db_prepare_input($_POST['products_series_title']);
          $products_author = tep_db_prepare_input($_POST['products_author']);
          $products_status = tep_db_prepare_input($_POST['products_status']);
          $products_model = tep_db_prepare_input($_POST['products_model']);
          $products_volume = tep_db_prepare_input($_POST['products_volume']);
          $products_published = tep_db_prepare_input($_POST['products_published']);
          $products_publishers = tep_db_prepare_input($_POST['products_publishers']);
          $products_price = tep_db_prepare_input($_POST['products_price']);
          $products_quantity = tep_db_prepare_input($_POST['products_quantity']);
          $products_weight = tep_db_prepare_input($_POST['products_weight']);
          $products_description = tep_db_prepare_input($_POST['products_description']);
          $products_description2 = tep_db_prepare_input($_POST['products_description2']);
          $products_url = tep_db_prepare_input($_POST['products_url']);
          $products_keywords = tep_db_prepare_input($_POST['products_keywords']);
          $manufacturers_id = tep_db_prepare_input($_POST['manufacturers_id']);
          $products_isbn = tep_db_prepare_input($_POST['products_isbn']);
          $products_date_available = tep_db_prepare_input($_POST['products_date_available']);
          $products_tax_class_id = tep_db_prepare_input($_POST['products_tax_class_id']);
          $products_memo = tep_db_prepare_input($_POST['products_memo']);
          $recommendation_order = tep_db_prepare_input($_POST['recommendation_order']);
          $sort_order = tep_db_prepare_input($_POST['sort_order']);
          $products_image_path = tep_db_prepare_input($_POST['products_image_path']);
          $sql_data_array = array('products_quantity' => $products_quantity,
                                     'products_model' => $products_model,
                                     'products_image' => $products_image_path,
                                     'products_price' => $products_price,
                                     'products_date_available' => $products_date_available,
                                     'products_weight' => $products_weight,
                                     'products_status' => $products_status,
                                     'products_tax_class_id' => $products_tax_class_id,
                                     'manufacturers_id' => $manufacturers_id,
                                     'products_isbn' => $products_isbn,
                                     'recommendation_order' => $recommendation_order,
                                     'sort_order' => $sort_order);
          if ($_GET['action'] == 'insert_product') {
            $insert_sql_data = array('products_date_added' => 'now()');
            $sql_data_array = tep_array_merge($sql_data_array, $insert_sql_data);
            tep_db_perform(TABLE_PRODUCTS, $sql_data_array);
            $products_id = tep_db_insert_id();
            // products_modelを自動採番する場合は、products_idをセット
            if ($_POST['p_model_auto_num']) {
              tep_db_query("update " . TABLE_PRODUCTS . " set products_model = '" . $products_id . "' where products_id = '" . $products_id . "'");
            }
            // products_to_categoriesテーブルの追加
            tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . $products_id . "', '" . tep_db_input($categories_id) . "')");
          } elseif ($_GET['action'] == 'update_product') {
            $update_sql_data = array('products_last_modified' => 'now()');
            $sql_data_array = tep_array_merge($sql_data_array, $update_sql_data);
            tep_db_perform(TABLE_PRODUCTS, $sql_data_array, 'update', 'products_id = \'' . $products_id . '\'');
            if ($previous_categories_id != $categories_id) {
              // カテゴリーが変わった場合、products_to_categoriesテーブルの削除と追加を行なう
              tep_db_query("delete from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "' and categories_id='" . tep_db_input($previous_categories_id) . "'");
              tep_db_query("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . " (products_id, categories_id) values ('" . $products_id . "', '" . tep_db_input($categories_id) . "')");
            }
          }
          // products_descriptionテーブルの更新
          $sql_data_array = array('products_name' => tep_db_prepare_input($_POST['products_name']),
                                        'products_description' => tep_db_prepare_input($_POST['products_description']),
                                        'products_description2' => tep_db_prepare_input($_POST['products_description2']),
                                        'products_url' => tep_db_prepare_input($_POST['products_url']),
                                        'products_author' => tep_db_prepare_input($_POST['products_author']),
                                        'products_subtitle' => tep_db_prepare_input($_POST['products_subtitle']),
                                        'products_series_title' => tep_db_prepare_input($_POST['products_series_title']),
                                        'products_volume' => tep_db_prepare_input($_POST['products_volume']),
                                        'products_published' => tep_db_prepare_input($_POST['products_published']),
                                        'products_publishers' => tep_db_prepare_input($_POST['products_publishers']),
                                        'products_keywords' => tep_db_prepare_input($_POST['products_keywords']),
                                        'products_memo' => tep_db_prepare_input($_POST['products_memo']));
          if ($_GET['action'] == 'insert_product') {
            $insert_sql_data = array('products_id' => $products_id,
                                     'language_id' => $languages_id);
            $sql_data_array = tep_array_merge($sql_data_array, $insert_sql_data);
            tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
          } elseif ($_GET['action'] == 'update_product') {
            tep_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array, 'update', 'products_id = \'' . $products_id . '\' and language_id = \'' . $languages_id . '\'');
          }
          
          if (USE_CACHE == 'true') {
            tep_reset_cache_block('cateogries');
            tep_reset_cache_block('also_purchased');
          }

          tep_redirect(tep_href_link(FILENAME_PRODUCTS_EDIT, tep_get_all_get_params(array('action', 'pID')) . 'action=edit'));
        }
        break;
      case 'delete_product_confirm':
        if ($_GET['pID']) {
          $products_id = tep_db_prepare_input($_GET['pID']);
          $delete_product_query = tep_db_query("select pd.products_name, pd.products_subtitle, pd.products_series_title, pd.products_author, p.products_id, p.products_image, p.products_price, p.products_model from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . tep_db_input($products_id) . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "'");
          if ($delete_count = tep_db_num_rows($delete_product_query)) {
            $delete_product = tep_db_fetch_array($delete_product_query);
          } else {
            $messageStack->add_session(ERROR_DELETE_PRODUCT_DOES_NOT_EXIST, 'error');
            tep_redirect(tep_href_link(FILENAME_PRODUCTS_EDIT));
          }
        }
        break;
      case 'delete_product':
        if ($_GET['pID']) {
          $products_id = tep_db_prepare_input($_GET['pID']);
          tep_remove_product($products_id);
        }

        if (USE_CACHE == 'true') {
          tep_reset_cache_block('categories');
          tep_reset_cache_block('also_purchased');
        }

        tep_redirect(tep_href_link(FILENAME_PRODUCTS_EDIT));
        break;
    }
  }

// check if the catalog image directory exists
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (is_writeable(DIR_FS_CATALOG_IMAGES)) {
      if (is_dir(DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES)) {
        if (!is_writeable(DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES)) {
        	 $messageStack->add(ERROR_PRODUCTS_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
        }
      } else {
        // 商品画像用ディレクトリがない場合、作成する。
        @mkdir(DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES, 0777);
        if (!is_dir(DIR_FS_CATALOG_IMAGES . DIR_WS_PRODUCTS_IMAGES)) {
          $messageStack->add(ERROR_PRODUCTS_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
        }
      }
    } else {
      $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
    }
  } else {
    $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/kn_stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table width="<?php echo BOX_WIDTH; ?>" class="knMenuBar">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
<?php
  switch ($_GET['action']) {
    case 'search':
      // 検索結果一覧表示
      
?>
      <tr>
        <td class="pageHeading"><?php echo TEXT_SEARCH_RESULTS; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="90%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="smallText" valign="top"><?php echo $page_split->display_count($results_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
            <td class="smallText" align="right"><?php echo $page_split->display_links($results_numrows, MAX_DISPLAY_SEARCH_RESULTS, '', $_GET['page'], $get_params); ?></td>
          </tr>
          <tr>
            <td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_PRODUCTS_IMAGES; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_CONTENTS; ?></td>
                <td class="dataTableHeadingContent" align="center"><?php echo TABLE_HEADING_ACTION; ?></td>
              </tr>
<?php
      $list_count = 0;
      while ($search_products = tep_db_fetch_array($search_products_query)) {
        $list_count++;

        if (($list_count/2) == floor($list_count/2)) {
          $list_row_class = ' class="knDataTableEven"';
        } else {
          $list_row_class = ' class="knDataTableOdd"';
        }
        echo '              <tr' . $list_row_class . '>' . "\n";
        echo '                <td class="dataTableContent" align="center" width="' . SMALL_IMAGE_WIDTH . '">';
        if ($search_products['products_image']) {
          echo tep_image(DIR_WS_CATALOG_IMAGES . $search_products['products_image'], $search_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"');
        } else {
          echo TEXT_NO_IMAGES;
        }
        echo "</td>\n";
        echo '                <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0" class="knMain">' . "\n";
        echo '                  <tr><td> No. ' . $search_products['products_model'] . '</td><td align="right">' . tep_get_category_name($search_products['categories_id'], $languages_id) . '</td></tr>' . "\n";
        echo '                  <tr><td colspan="2"><big><b>' . $search_products['products_name'] . '</b>' . ((KN_CFG_USE_SUBTITLE == "true") ? $search_products['products_subtitle'] . ' ' : '') . ((KN_CFG_USE_SERIES_TITLE == "true") ? $search_products['products_series_title'] . ' ' : '') . '</big></td></tr>' . "\n";
        echo '                  <tr><td> </td><td>' . ((KN_CFG_USE_AUTHOR == "true") ? $search_products['products_author'] : '') . ((KN_CFG_USE_PUBLISHERS == "true") ? ' ' . $search_products['products_publishers'] : '') . ((KN_CFG_USE_VOLUME == "true") ? ' ' . $search_products['products_volume'] : '') . ((KN_CFG_USE_PUBLISHED == "true") ? ' ' . $search_products['products_published'] : '') . $search_products['products_description'] . '</td></tr>' . "\n";
        echo '                  <tr><td>'. ((KN_CFG_USE_ISBN == 'true') ? '(' . $search_products['products_isbn'] . ')' : '') . '</td><td align="right"><font color="ff0000">' . $currencies->format($search_products['products_price']) . '</font></td></tr>' . "\n";
        echo "               </table></td>\n";
        echo '                <td class="dataTableContent" valign="top" align="right">' . "\n" . 
               '                  <a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=edit_product&pID=' . $search_products['products_id']) . '">' . tep_image_button('button_edit.gif', IMAGE_EDIT) . '</a>' . "\n" . 
               '                  <a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=delete_product_confirm&pID=' . $search_products['products_id']) . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a><br>' . "\n";
        if (KN_CFG_USE_REVIEWS == 'true') {
          echo '                  <a href="' . tep_href_link(FILENAME_REVIEWS, 'pID=' . $search_products['products_id']) . '">' . tep_image_button('button_reviews.gif', IMAGE_REVIEWS) . '</a>' . "\n";
        }
        echo '                  <a href="' . tep_href_link(FILENAME_SPECIALS, 'specials_pID=' . $search_products['products_id']) . '">' . tep_image_button('button_specials.gif', IMAGE_SPECIALS) . '</a></td>' . "\n";
        echo "              </tr>\n";
      }
?>
            </table></td>
          </tr>
          <tr>
            <td class="smallText" valign="top"><?php echo $page_split->display_count($results_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_GET['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
            <td class="smallText" align="right"><?php echo $page_split->display_links($results_numrows, MAX_DISPLAY_SEARCH_RESULTS, '', $_GET['page'], $get_params); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
      </tr>
<?php
      break;
    case 'new_product':
    case 'edit_product':
      // 商品データの編集（新規登録、修正）
?>
<link rel="stylesheet" type="text/css" href="includes/javascript/spiffyCal/spiffyCal_v2_1.css">
<script language="JavaScript" src="includes/javascript/spiffyCal/spiffyCal_v2_1.js"></script>
<script language="javascript">
  var dateAvailable = new ctlSpiffyCalendarBox("dateAvailable", "<?php echo $_GET['action']; ?>", "products_date_available","btnDate1","<?php echo $pInfo->products_date_available; ?>",scBTNMODE_CUSTOMBLUE);
</script>
      <tr>
        <td class="pageHeading"><?php echo TEXT_EDIT_PRODUCT; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form($_GET['action'], FILENAME_PRODUCTS_EDIT, 'action=' . $action, 'post', 'enctype="multipart/form-data"'); ?>
        <td><?php echo tep_draw_hidden_field('products_id', $pInfo->products_id); ?><table class="knEditTable">
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
            <td><?php echo tep_draw_input_field('products_model', $pInfo->products_model, '', false, 'text', false) . ($_GET['action'] == 'new_product' ? '&nbsp;&nbsp;' . tep_draw_checkbox_field('p_model_auto_num', '1', true) . '&nbsp;&nbsp;' . TEXT_AUTO_NUM : ''); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_CATEGORIES; ?></td>
            <td><?php echo tep_draw_pull_down_menu('categories_id', tep_get_category_tree(0, ' ', ' ', array(array('id' => '', 'text' => TEXT_FILLER))), $pInfo->categories_id) . tep_draw_hidden_field('previous_categories_id', $pInfo->categories_id); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_NAME; ?></td>
            <td><?php echo tep_draw_input_field('products_name', $pInfo->products_name, 'size="40"', false, 'text', false); ?></td>
          </tr>
<?php
      if (KN_CFG_USE_SUBTITLE == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_SUBTITLE; ?></td>
            <td><?php echo tep_draw_input_field('products_subtitle', $pInfo->products_subtitle, 'size="40"', false, 'text', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_SERIES_TITLE =="true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_SERIES_TITLE; ?></td>
            <td><?php echo tep_draw_input_field('products_series_title', $pInfo->products_series_title, 'size="40"', false, 'text', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_AUTHOR == "true") {
?>
           <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_AUTHOR; ?></td>
            <td><?php echo tep_draw_input_field('products_author', $pInfo->products_author, 'size="40"', false, 'text', false); ?></td>
          </tr>
<?php
      }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_DESCRIPTION; ?></td>
            <td><?php echo tep_draw_textarea_field('products_description', 'soft', '70', '10', $pInfo->products_description, '', false); ?></td>
          </tr>
<?php
      if (KN_CFG_USE_DESCRIPTION2 == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_DESCRIPTION2; ?></td>
            <td><?php echo tep_draw_textarea_field('products_description2', 'soft', '70', '10', $pInfo->products_description2, '', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_KEYWORDS == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_KEYWORDS; ?></td>
            <td><?php echo tep_draw_textarea_field('products_keywords', 'soft', '70', '10', $pInfo->products_keywords, '', false) . '<br>' . TEXT_PRODUCTS_KEYWORDS_NOTE; ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_ISBN == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_ISBN; ?></td>
            <td><?php echo tep_draw_input_field('products_isbn', $pInfo->products_isbn, 'size="40"', false, 'text', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_VOLUME == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_VOLUME; ?></td>
            <td><?php echo tep_draw_input_field('products_volume', $pInfo->products_volume, '', false, 'text', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_MANUFACTURERS != '') {
        $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
        $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by sort_order");
        while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
          $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
                                         'text' => $manufacturers['manufacturers_name']);
        }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_MANUFACTURER; ?></td>
            <td><?php echo tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, $pInfo->manufacturers_id); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_PUBLISHED == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_PUBLISHED; ?></td>
            <td><?php echo tep_draw_input_field('products_published', $pInfo->products_published, '', false, 'text', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_PUBLISHERS == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_PUBLISHERS; ?></td>
            <td><?php echo tep_draw_input_field('products_publishers', $pInfo->products_publishers, '', false, 'text', false); ?></td>
          </tr>
<?php
      }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_IMAGE; ?></td>
            <td>
<?php
      echo tep_draw_file_field('products_image');
      if ($pInfo->products_image) {
        // 画像の変更確認用に既存の画像パスをとっておく
        echo '<br>' . $pInfo->products_image;
        // 画像削除用チェックボックス
        echo tep_draw_hidden_field('previous_product_image', $pInfo->products_image);
        echo '&nbsp;&nbsp;' . tep_draw_checkbox_field('delete_image') . '&nbsp;' . TEXT_DELETE;
      }
?>
            </td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
            <td><?php echo tep_draw_input_field('products_quantity', ($_GET['action'] == 'new_product' ? 1 : $pInfo->products_quantity), '', false, 'text', false); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_STATUS; ?></td>
            <td>
<?php
      if ($_GET['action'] == 'edit_product') {
        switch ($pInfo->products_status) {
          case '0': $in_status = false; $out_status = true; break;
          case '1':
          default: $in_status = true; $out_status = false;
        }
        echo tep_draw_radio_field('products_status', '1', $in_status) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', $out_status) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE;
      } else {
        echo tep_draw_radio_field('products_status', '1', true) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', false) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE;
      }
?>
            </td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_PRICE; ?></td>
            <td><?php echo tep_draw_input_field('products_price', $pInfo->products_price, '', false, 'text', false); ?></td>
          </tr>
<?php
      if (KN_CFG_USE_WEIGHT == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_WEIGHT; ?></td>
            <td><?php echo tep_draw_input_field('products_weight', $pInfo->products_weight, '', false, 'text', false); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_DATE_AVAILABLE == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?><br><small>(YYYY-MM-DD)</small></td>
            <td><script language="javascript">dateAvailable.writeControl(); dateAvailable.dateFormat="yyyy-MM-dd";</script></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_URL == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_URL; ?></td>
            <td><?php echo tep_draw_input_field('products_url', $pInfo->products_url, '', false, 'text', false); ?></td>
          </tr>
<?php
      }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_RECOMMENDATION_ORDER; ?></td>
            <td><?php echo tep_draw_input_field('recommendation_order', $pInfo->recommendation_order, 'size="5"', false, 'text', false) . ' ' . TEXT_RECOMMENDATION_ORDER_NOTE; ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_SORT_ORDER; ?></td>
            <td><?php echo tep_draw_input_field('sort_order', $pInfo->sort_order, '', false, 'text', false) . ' ' . TEXT_SORT_ORDER_NOTE; ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_MEMO; ?></td>
            <td><?php echo tep_draw_input_field('products_memo', $pInfo->products_memo, 'size="40"', false, 'text', false); ?></td>
          </tr>
          <tr>
<?php
      $tax_class_array = array(array('id' => '0', 'text' => TEXT_NONE));
      $tax_class_query = tep_db_query("select tax_class_id, tax_class_title from " . TABLE_TAX_CLASS . " order by tax_class_title");
      while ($tax_class = tep_db_fetch_array($tax_class_query)) {
        $tax_class_array[] = array('id' => $tax_class['tax_class_id'],
                                   'text' => $tax_class['tax_class_title']);
      }
      if ($_GET['action'] == 'edit_product') {
        $p_tax_class_id = $pInfo->products_tax_class_id;
      } else {
        // 新しい商品の税種別初期値は１（一般消費税）にする
        $p_tax_class_id = 1;
      }
?>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_TAX_CLASS_ID; ?></td>
            <td><?php echo tep_draw_pull_down_menu('products_tax_class_id', $tax_class_array, $p_tax_class_id); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td class="main"><?php echo tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>' . ($_GET['action'] == 'edit_product' ? '&nbsp;&nbsp;&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=delete_product_confirm&pID=' . $pInfo->products_id) . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>' : '') . '&nbsp;&nbsp;' . (KN_CFG_USE_REVIEWS == 'true' ? '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_REVIEWS, 'pID=' . $pInfo->products_id) . '">' . tep_image_button('button_reviews.gif', IMAGE_REVIEWS) . '</a>' : '') . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SPECIALS, 'specials_pID=' . $pInfo->products_id) . '">' . tep_image_button('button_specials.gif', IMAGE_SPECIALS) . '</a>'; ?></td>
      </form></tr>
<?php
      break;
    case 'new_product_confirm':
    case 'edit_product_confirm':
      // 商品データの編集確認（新規登録、修正）
?>
      <tr>
        <td class="pageHeading"><?php echo TEXT_EDIT_PRODUCT_CONFIRM; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form('submit', FILENAME_PRODUCTS_EDIT, 'action=' . $action, 'post'); ?>
        <td><?php echo tep_draw_hidden_field('products_id', $_POST['products_id']) .  tep_draw_hidden_field('products_tax_class_id', $_POST['products_tax_class_id']); ?><table class="knEditTable" width="80%">
          <tr>
            <td class="knEditTableHeading" width="20%"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
            <td><?php echo ($_POST['p_model_auto_num'] ? TEXT_AUTO_NUM : $_POST['products_model']) . tep_draw_hidden_field('products_model', $_POST['products_model']) . tep_draw_hidden_field('p_model_auto_num', $_POST['p_model_auto_num']); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_CATEGORIES; ?></td>
            <td><?php echo $_POST['categories_id'] . '&nbsp;:&nbsp;' . tep_get_category_name($_POST['categories_id'], $languages_id) . tep_draw_hidden_field('categories_id', $_POST['categories_id']) . tep_draw_hidden_field('previous_categories_id', $_POST['previous_categories_id']); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_NAME; ?></td>
            <td><?php echo $_POST['products_name'] . tep_draw_hidden_field('products_name', htmlspecialchars(stripslashes($_POST['products_name']))); ?></td>
          </tr>
<?php
      if (KN_CFG_USE_SUBTITLE == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_SUBTITLE; ?></td>
            <td><?php echo $_POST['products_subtitle'] . tep_draw_hidden_field('products_subtitle', htmlspecialchars(stripslashes($_POST['products_subtitle']))); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_SERIES_TITLE == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_SERIES_TITLE; ?></td>
            <td><?php echo $_POST['products_series_title'] . tep_draw_hidden_field('products_series_title', htmlspecialchars(stripslashes($_POST['products_series_title']))); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_AUTHOR == "true") {
?>
           <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_AUTHOR; ?></td>
            <td><?php echo $_POST['products_author'] . tep_draw_hidden_field('products_author', htmlspecialchars(stripslashes($_POST['products_author']))); ?></td>
          </tr>
<?php
      }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_DESCRIPTION; ?></td>
            <td><?php echo $_POST['products_description'] . tep_draw_hidden_field('products_description', htmlspecialchars(stripslashes($_POST['products_description']))); ?></td>
          </tr>
<?php
      if (KN_CFG_USE_DESCRIPTION2 == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_DESCRIPTION2; ?></td>
            <td><?php echo $_POST['products_description2'] . tep_draw_hidden_field('products_description2', htmlspecialchars(stripslashes($_POST['products_description2']))); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_KEYWORDS == "true") {
        $_POST['products_keywords'] = str_replace("　", " ", $_POST['products_keywords']);
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_KEYWORDS; ?></td>
            <td><?php echo $_POST['products_keywords'] . tep_draw_hidden_field('products_keywords', htmlspecialchars(stripslashes($_POST['products_keywords']))); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_ISBN == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_ISBN; ?></td>
            <td><?php echo $_POST['products_isbn'] . tep_draw_hidden_field('products_isbn', $_POST['products_isbn']); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_VOLUME == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_VOLUME; ?></td>
            <td><?php echo $_POST['products_volume'] . tep_draw_hidden_field('products_volume', $_POST['products_volume']); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_MANUFACTURERS != '') {
        $manufacturers_query = tep_db_query("select manufacturers_name from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$_POST['manufacturers_id'] . "'");
        $manufacturers = tep_db_fetch_array($manufacturers_query);
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_MANUFACTURER; ?></td>
            <td><?php echo $_POST['manufacturers_id'] . '&nbsp;:&nbsp;' . $manufacturers['manufacturers_name'] . tep_draw_hidden_field('manufacturers_id', $_POST['manufacturers_id']); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_PUBLISHED == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_PUBLISHED; ?></td>
            <td><?php echo $_POST['products_published'] . tep_draw_hidden_field('products_published', $_POST['products_published']); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_PUBLISHERS == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_PUBLISHERS; ?></td>
            <td><?php echo $_POST['products_publishers'] . tep_draw_hidden_field('products_publishers', htmlspecialchars(stripslashes($_POST['products_publishers']))); ?></td>
          </tr>
<?php
      }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_IMAGE; ?></td>
            <td><?php echo tep_draw_hidden_field('products_image_path', $products_image_path) . '&nbsp;' . (($products_image_path) ? tep_image(DIR_WS_CATALOG_IMAGES . $products_image_path, $_POST['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . $products_image_path : TEXT_NO_IMAGES); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_QUANTITY; ?></td>
            <td><?php echo $_POST['products_quantity'] . tep_draw_hidden_field('products_quantity', $_POST['products_quantity']); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_STATUS; ?></td>
            <td><?php echo ($_POST['products_status'] ? TEXT_PRODUCT_AVAILABLE : TEXT_PRODUCT_NOT_AVAILABLE) . tep_draw_hidden_field('products_status', $_POST['products_status']); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_PRICE; ?></td>
            <td><?php echo $currencies->format($_POST['products_price']) . tep_draw_hidden_field('products_price', $_POST['products_price']); ?></td>
          </tr>
<?php
      if (KN_CFG_USE_WEIGHT == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_WEIGHT; ?></td>
            <td><?php echo $_POST['products_weight'] . tep_draw_hidden_field('products_weight', $_POST['products_weight']); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_DATE_AVAILABLE == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?></td>
            <td><?php echo $_POST['products_date_available'] . tep_draw_hidden_field('products_date_available', $_POST['products_date_available']); ?></td>
          </tr>
<?php
      }
      if (KN_CFG_USE_URL == "true") {
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_URL; ?></td>
            <td><?php echo $_POST['products_url'] . tep_draw_hidden_field('products_url', htmlspecialchars(stripslashes($_POST['products_url']))); ?></td>
          </tr>
<?php
      }
?>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_RECOMMENDATION_ORDER; ?></td>
            <td><?php echo $_POST['recommendation_order'] . tep_draw_hidden_field('recommendation_order', $_POST['recommendation_order']); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_SORT_ORDER; ?></td>
            <td><?php echo $_POST['sort_order'] . tep_draw_hidden_field('sort_order', $_POST['sort_order']); ?></td>
          </tr>
          <tr>
            <td class="knEditTableHeading"><?php echo TEXT_PRODUCTS_MEMO; ?></td>
            <td><?php echo $_POST['products_memo'] . tep_draw_hidden_field('products_memo', htmlspecialchars(stripslashes($_POST['products_memo']))); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main">
<?php
      echo tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';
      
      if ($action == 'update_product') {
        echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
      } else {
        echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
      }

      echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
?>
        </td>
      </form></tr>
<?php
      break;
    case 'delete_product_confirm':
      // 商品の削除確認
?>
      <tr>
        <td class="pageHeading"><?php echo TEXT_DELETE_PRODUCT_CONFIRM; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form('delete_product', FILENAME_PRODUCTS_EDIT, 'pID=' . $products_id . '&action=delete_product', 'post'); ?>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main" valign="top"><?php echo TEXT_DELETE_PRODUCT; ?></td>
            <td class="main"><?php echo '[' . $delete_product['products_model'] . '] ' . $delete_product['products_name'] . ' : ' . $currencies->format($delete_product['products_price']); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo tep_image_submit('button_delete.gif', IMAGE_DELETE) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?>
        </td>
      </form></tr>
<?php
      break;

    default:
      // トップ画面（検索画面）
      // 商品数の獲得
      $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS);
      $check = tep_db_fetch_array($check_query);
      $count_all = $check['total'];
      $check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " where products_status = 1");
      $check = tep_db_fetch_array($check_query);
      $count_on_sale = $check['total'];
      $count_sold_out = $count_all - $count_on_sale;
?>
      <tr>
        <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2" width="100%">
          <tr>
            <td class="main"><?php echo TEXT_ALL_PRODUCTS_COUNT . ' : ' . $count_all . '&nbsp;&nbsp;' . TEXT_PRODUCTS_ON_SALE_COUNT . ' : ' . $count_on_sale . '&nbsp;&nbsp;' . TEXT_PRODUCTS_SOLD_OUT_COUNT . ' : ' . $count_sold_out; ?></td>
            <td class="main" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=new_product') . '">' . tep_image_button('button_new_product.gif', IMAGE_NEW_PRODUCT) . '</a>'; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td class="main"><?php echo TEXT_PRODUCTS_SEARCH; ?></td>
      </tr>
      <tr><?php echo tep_draw_form('search', FILENAME_PRODUCTS_EDIT, 'action=search&subject=post', 'post'); ?>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td align="center"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_STATUS; ?></td>
                <td class="dataTableRow"><span class="main"><?php echo tep_draw_radio_field('products_status', '1', true) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', false) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE; ?></span></td>
              </tr>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_CATEGORIES; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_pull_down_menu('categories_id', tep_get_category_tree(0, ' ', ' ', array(array('id' => '', 'text' => TEXT_FILLER)))); ?></td>
              </tr>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_NAME; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_name', '', 'size="40"'); ?></td>
              </tr>
<?php
      if (KN_CFG_USE_SUBTITLE == "true") {
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_SUBTITLE; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_subtitle', '', 'size="40"'); ?></td>
              </tr>
<?php
      }
      if (KN_CFG_USE_SERIES_TITLE == "true") {
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_SERIES_TITLE; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_series_title', '', 'size="40"'); ?></td>
              </tr>
<?php
      }
      if (KN_CFG_USE_AUTHOR == "true") {
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_AUTHOR; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_author', '', 'size="40"'); ?></td>
              </tr>
<?php
      }
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_MODEL; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_model'); ?></td>
              </tr>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_MEMO; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_memo', '', 'size="40"'); ?></td>
              </tr>
<?php
      if (KN_CFG_USE_MANUFACTURERS != '') {
        $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
        $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by sort_order");
        while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
          $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
                                         'text' => $manufacturers['manufacturers_name']);
        }
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_MANUFACTURER; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_pull_down_menu('manufacturers_id', $manufacturers_array, 'size="40"'); ?></td>
              </tr>
<?php
      }
      if (KN_CFG_USE_PUBLISHERS == "true") {
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_PUBLISHERS; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_publishers', '', 'size="40"'); ?></td>
              </tr>
<?php
      }
      if (KN_CFG_USE_ISBN == "true") {
?>
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TEXT_PRODUCTS_ISBN; ?></td>
                <td class="dataTableRow"><?php echo tep_draw_input_field('products_isbn', '', 'size="40"'); ?></td>
              </tr>
<?php
      }
?>
            </table></td>
          </tr>
          <tr>
            <td><?php echo tep_image_submit('button_search.gif', IMAGE_SEARCH) ?></td>
          </tr>
        </table></td>
      </form></tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="3" cellpadding="0">
          <tr>
            <td width="50%" class="main"><?php echo TEXT_LAST_ADDED_LIST; ?></td>
            <td width="50%" class="main"><?php echo TEXT_LAST_MODIFIED_LIST; ?></td>
          </tr>
          <tr>
            <td width="50%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_DATE_ADDED; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
              </tr>
<?php
      $products_query = tep_db_query("select products_date_added, count(*) as total from " . TABLE_PRODUCTS . " group by products_date_added order by products_date_added desc limit " . MAX_DISPLAY_DATE_ADDED);
      $num_products = tep_db_num_rows($products_query);
      if (0 < $num_products) {
        while ($products = tep_db_fetch_array($products_query)) {
          if ($products['total'] == 1) {
            $products_added_query = tep_db_query("select p.products_id, pd.products_name, p.products_date_added from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_date_added = '" . $products['products_date_added'] . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "'");
            $products_added = tep_db_fetch_array($products_added_query);
            echo '                  <tr>' . "\n";
            echo '                    <td class="dataTableContent">' . $products_added['products_date_added'] . "</td>\n";
            echo '                    <td class="dataTableContent"><a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=edit_product&pID=' . $products_added['products_id']) . '">' . $products_added['products_name'] . "</a></td>\n";
            echo "                 </tr>\n";
          } else {
            echo '                  <tr>' . "\n";
            echo '                    <td class="dataTableContent">' . $products['products_date_added'] . "</td>\n";
            echo '                    <td class="dataTableContent" align="right">' . ' <a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=search&subject=products_date_added&value=' . urlencode($products['products_date_added'])) . '">' . $products['total'] . "</a></td>\n";
            echo "</td>\n";
            echo "                 </tr>\n";
          }
        }
      } else {
        echo '                  <tr>' . "\n";
        echo '                    <td class="dataTableContent" colspan="2" align="center">' . TEXT_NO_PRODUCTS . "</td>\n";
        echo "                 </tr>\n";
      }
?>
            </table></td>
            <td width="50%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_LAST_MODIFIED; ?></td>
                <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
              </tr>
<?php
      $products_query = tep_db_query("select products_last_modified, count(*) as total from " . TABLE_PRODUCTS . " group by products_last_modified having products_last_modified <> '' order by products_last_modified desc limit " . MAX_DISPLAY_LAST_MODIFIED);
      $num_products = tep_db_num_rows($products_query);
      if (0 < $num_products) {
        while ($products = tep_db_fetch_array($products_query)) {
          if ($products['total'] == 1) {
            $products_modified_query = tep_db_query("select p.products_id, pd.products_name, p.products_last_modified from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_last_modified = '" . $products['products_last_modified'] . "' and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "'");
            $products_modified = tep_db_fetch_array($products_modified_query);
            echo '                  <tr>' . "\n";
            echo '                    <td class="dataTableContent">' . $products_modified['products_last_modified'] . "</td>\n";
            echo '                    <td class="dataTableContent"><a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=edit_product&pID=' . $products_modified['products_id']) . '">' . $products_modified['products_name'] . "</a></td>\n";
            echo "                 </tr>\n";
          } else {
            echo '                  <tr>' . "\n";
            echo '                    <td class="dataTableContent">' . $products['products_last_modified'] . "</td>\n";
            echo '                    <td class="dataTableContent" align="right"><a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=search&subject=products_last_modified&value=' . urlencode($products['products_last_modified'])) . '">' . $products['total'] . "</a></td>\n";
            echo "                 </tr>\n";
          }
        }
      } else {
        echo '                  <tr>' . "\n";
        echo '                    <td class="dataTableContent" colspan="2" align="center">' . TEXT_NO_PRODUCTS . "</td>\n";
        echo "                 </tr>\n";
      }
?>
            </table></td>
          </tr>
        </table></td>
      </tr>
<?php
      break;
  }
?>
      </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
