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

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

  Released under the GNU General Public License

  //----------------------------------------------------------------------------//
  事前に必要な環境
  //----------------------------------------------------------------------------//
  １．GETAのインストール
  ２．CHASEN（形態素分析に使用）のインストール
  ３．ci.conf（GETAの設定ファイル）の編集
      => カテゴリー、商品、テーマのそれぞれのWAMについてのhandle、short-name、datarootの指定
      ※ short-nameを下記の各TEXT_*_HANDLE_IDに設定する。
  ４．WAM格納場所（dataroot）のディレクトリ作成および書き込み権限の付与
  ５．chasenrc（chasenの設定ファイル）の編集
      => 出力フォーマット（",%m"）、EOS文字列（"\n"）、注釈（(ANNOTATION (("[" "]") "%m") (("<" ">")))
      ※ japanese.bashには、別途起動時に同じディレクトリ上のchasenrcを指定してある
  ６．下記のDIR_FS_GETA_WORKディレクトリの作成および書き込み権限の付与
  ７．下記のshellの実行権限の付与
  ８．必要に応じて検索除外文字（$replace_array）設定の追加・修正
  //----------------------------------------------------------------------------//
*/


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

  
  //GETA用設定ファイル
  require('../geta_work/geta_cfg.php');
  
  switch ($_GET['action']) {
    case 'make_products_wam':
      // 商品WAMの生成
      // 形態素分析するデータとタイトルファイルの作成
      $indata = fopen(FILENAME_P_INDATA, "w");
      $titledata = fopen(FILENAME_P_T_INFILE, "w");
      $products_query = tep_db_query("select p.products_id, p.products_model, p.products_image, p.products_isbn, p.products_price, p.manufacturers_id, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, pd.products_name, pd.products_subtitle, pd.products_series_title, pd.products_author, pd.products_publishers, pd.products_published, pd.products_volume, pd.products_description, pd.products_description2, pd.products_keywords from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd) left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . $languages_id . "'");
      while ($products = tep_db_fetch_array($products_query)) {
        $product_contents_id = "<::" . $products['products_id'] . "::>";
        $product_contents = "";
        for ($i = 0, $n = sizeof($mw_products_field); $i < $n; $i++) {
          $mw_products_field[$i]['weight'] = (int)$_POST[$mw_products_field[$i]['field'] . '_weight'];
          if (!empty($_POST[$mw_products_field[$i]['field']])) {
            if ($mw_products_field[$i]['check'] <> 9) {
              $mw_products_field[$i]['check'] = 1;
            }
            // データの抽出（重みの分だけ繰り返す）
            for ($j = 0, $m = $mw_products_field[$i]['weight']; $j < $m; $j++) {
              $product_contents .= ' ' . $products[$mw_products_field[$i]['field']];
            }
          } else {
            $mw_products_field[$i]['check'] = 0;
          }
        }
        if ($_POST['include_category_fields']) {
          // カテゴリー情報も含める場合
          for ($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
            $mw_categories_field[$i]['weight'] = (int)$_POST[$mw_categories_field[$i]['field'] . '_weight'];
            if (!empty($_POST[$mw_categories_field[$i]['field']])) {
              if ($mw_categories_field[$i]['check'] <> 9) {
                $mw_categories_field[$i]['check'] = 1;
              }
              $products_id = $products['products_id'];
              $categories_query = tep_db_query("select cd.categories_name, cd.categories_description, cd.categories_keywords from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p2c.products_id = '" . $products_id . "' and p2c.categories_id = cd.categories_id and cd.language_id='" . $languages_id . "'");
              $categories = tep_db_fetch_array($categories_query);
              // データの抽出（重みの分だけ繰り返す）
              for ($j = 0, $m = $mw_categories_field[$i]['weight']; $j < $m; $j++) {
                $product_contents .= ' ' . $categories[$mw_categories_field[$i]['field']];
              }
            } else {
              $mw_categories_field[$i]['check'] = 0;
            }
          }
        } else {
          for ($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
            $mw_categories_field[$i]['weight'] = (int)$_POST[$mw_categories_field[$i]['field'] . '_weight'];
            if (!empty($_POST[$mw_categories_field[$i]['field']])) {
              if ($mw_categories_field[$i]['check'] <> 9) {
                $mw_categories_field[$i]['check'] = 1;
              }
            } else {
              $mw_categories_field[$i]['check'] = 0;
            }
          }
        }
        if ($_POST['include_manufacturer_fields']) {
          // 追加分類情報も含める場合
          for ($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
            $mw_manufacturers_field[$i]['weight'] = (int)$_POST[$mw_manufacturers_field[$i]['field'] . '_weight'];
            if (!empty($_POST[$mw_manufacturers_field[$i]['field']])) {
              if ($mw_manufacturers_field[$i]['check'] <> 9) {
                $mw_manufacturers_field[$i]['check'] = 1;
              }
              $manufacturers_id = $products['manufacturers_id'];
              $manufacturers_query = tep_db_query("select m.manufacturers_name, mf.manufacturers_keywords from " . TABLE_MANUFACTURERS . " m, " . TABLE_MANUFACTURERS_INFO . " mf where m.manufacturers_id = '" . $manufacturers_id . "' and m.manufacturers_id = mf.manufacturers_id and mf.languages_id = '" . $languages_id . "'");
              $manufacturers = tep_db_fetch_array($manufacturers_query);
              // データの抽出（重みの分だけ繰り返す）
        	     for ($j = 0, $m = $mw_manufacturers_field[$i]['weight']; $j < $m; $j++) {
                $product_contents .= ' ' . $manufacturers[$mw_manufacturers_field[$i]['field']];
              }
            } else {
              $mw_manufacturers_field[$i]['check'] = 0;
            }
          }
        } else {
          for ($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
            $mw_manufacturers_field[$i]['weight'] = (int)$_POST[$mw_manufacturers_field[$i]['field'] . '_weight'];
            if (!empty($_POST[$mw_manufacturers_field[$i]['field']])) {
              if ($mw_manufacturers_field[$i]['check'] <> 9) {
                $mw_manufacturers_field[$i]['check'] = 1;
              }
            } else {
              $mw_manufacturers_field[$i]['check'] = 0;
            }
          }
        }
        if ($_POST['include_review_fields']) {
          // 書評情報も含める場合
          $reviews_products_id = $products['products_id'];
          $reviews_query = tep_db_query("select rd.reviews_text from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.products_id = '" . $reviews_products_id . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . $languages_id . "'");
          while ($reviews = tep_db_fetch_array($reviews_query)) {
            for ($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
              $mw_reviews_field[$i]['weight'] = (int)$_POST[$mw_reviews_field[$i]['field'] . '_weight'];
              if (!empty($_POST[$mw_reviews_field[$i]['field']])) {
                if ($mw_reviews_field[$i]['check'] <> 9) {
                  $mw_reviews_field[$i]['check'] = 1;
                }
                // データの抽出（重みの分だけ繰り返す）
        	       for ($j = 0, $m = $mw_reviews_field[$i]['weight']; $j < $m; $j++) {
                  $product_contents .= ' ' . $reviews[$mw_reviews_field[$i]['field']];
        	       }
              } else {
                $mw_reviews_field[$i]['check'] = 0;
              }
            }
          }
        } else {
          for ($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
            $mw_reviews_field[$i]['weight'] = (int)$_POST[$mw_reviews_field[$i]['field'] . '_weight'];
            if (!empty($_POST[$mw_reviews_field[$i]['field']])) {
              if ($mw_reviews_field[$i]['check'] <> 9) {
                $mw_reviews_field[$i]['check'] = 1;
              }
            } else {
              $mw_reviews_field[$i]['check'] = 0;
            }
          }
        }
        $product_contents = str_replace("\r\n", "\r", $product_contents);
        $product_contents = str_replace("\r", "\n", $product_contents);
        $product_contents = str_replace("\n", "", $product_contents);
        $product_contents = mb_convert_kana($product_contents, "AsK");
        $product_contents = mbereg_replace("[" . $replace_symbol . "]", " ", $product_contents);
        foreach ($replace_array as $value) {
          if ($value) $product_contents = mbereg_replace("[" . $value . "]", " ", $product_contents);
        }
        fwrite($indata, $product_contents_id . $product_contents . "\n");
        // タイトルファイルの作成
        fwrite($titledata, "%" . $products['products_id'] . "\n");
         
        $title_contents = ' products_name<>' . $products['products_name'] . ',';
        if (KN_CFG_USE_SUBTITLE == 'true') {
          $title_contents .= 'products_subtitle<>' . $products['products_subtitle'] . ',';
        }
        if (KN_CFG_USE_SERIES_TITLE == 'true') {
          $title_contents .= 'products_series_title<>' . $products['products_series_title'] . ',';
        }
        if (KN_CFG_USE_AUTHOR == 'true') {
          $title_contents .= 'products_author<>' . $products['products_author'] . ',';
        }
        $title_contents .= 'products_description<>' . $products['products_description'] . ',';
        if (KN_CFG_USE_PUBLISHERS == 'true') {
          $title_contents .= 'products_publishers<>' . $products['products_publishers'] . ',';
        }
        if (KN_CFG_USE_VOLUME == 'true') {
          $title_contents .= 'products_volume<>' . $products['products_volume'] . ',';
        }
        if (KN_CFG_USE_PUBLISHED == 'true') {
          $title_contents .= 'products_published<>' . $products['products_published'] . ',';
        }
        $title_contents .= 'products_price<>' . $products['products_price'] . ',';
        $title_contents .= 'products_tax_class_id<>' . $products['products_tax_class_id'] . ',';
        $title_contents .= 'specials_new_products_price<>' . $products['specials_new_products_price'] . ',';
        $title_contents .= 'products_model<>' . $products['products_model'] . ',';
        $title_contents .= 'products_isbn<>' . $products['products_isbn'] . ',';
        $title_contents .= 'products_image<>' . $products['products_image'];
        $title_contents = str_replace("\r\n", "\r", $title_contents);
        $title_contents = str_replace("\r", "\n", $title_contents);
        $title_contents = str_replace("\n", "", $title_contents);
        fwrite($titledata, $title_contents . "\n");
      }
      fclose($indata);
      fclose($titledata);
        
      // 形態素分析の実行＆頻度ファイルの作成
      exec(FILENAME_MAKEWAM_JP . ' ' . DIR_FS_GETA_WORK . ' ' . FILENAME_P_INDATA . ' ' . FILENAME_P_FREQFILE);
      // WAMの生成
      exec(FILENAME_MKW . ' ' . TEXT_P_HANDLE_ID . ' ' . DIR_FS_GETA_WORK . ' ' . FILENAME_P_FREQFILE);
      exec(FILENAME_MKAUX . ' ' . TEXT_P_HANDLE_ID . ' ' . DIR_FS_GETA_WORK . ' ' . FILENAME_P_T_INFILE);

      // 設定ファイルの書き込み
      $c_mw_cfg_file = @fopen(FILENAME_C_MAKEWAM_CONFIG, 'w');
      for ($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
        fwrite($c_mw_cfg_file, $mw_categories_field[$i]['field'] . ',' . $mw_categories_field[$i]['check'] . ',' . $mw_categories_field[$i]['weight'] . "\n");
      }
      fclose($c_mw_cfg_file);
      $p_mw_cfg_file = @fopen(FILENAME_P_MAKEWAM_CONFIG, 'w');
      for ($i = 0, $n = sizeof($mw_products_field); $i < $n; $i++) {
        fwrite($p_mw_cfg_file, $mw_products_field[$i]['field'] . ',' . $mw_products_field[$i]['check'] . ',' . $mw_products_field[$i]['weight'] . "\n");
      }
      fclose($p_mw_cfg_file);
      $m_mw_cfg_file = @fopen(FILENAME_M_MAKEWAM_CONFIG, 'w');
      for ($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
        fwrite($m_mw_cfg_file, $mw_manufacturers_field[$i]['field'] . ',' . $mw_manufacturers_field[$i]['check'] . ',' . $mw_manufacturers_field[$i]['weight'] . "\n");
      }
      fclose($m_mw_cfg_file);
      $r_mw_cfg_file = @fopen(FILENAME_R_MAKEWAM_CONFIG, 'w');
      for ($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
        fwrite($r_mw_cfg_file, $mw_reviews_field[$i]['field'] . ',' . $mw_reviews_field[$i]['check'] . ',' . $mw_reviews_field[$i]['weight'] . "\n");
      }
      fclose($r_mw_cfg_file);
        
      $messageStack->add_session(SUCCESS_WAM_UPDATE_COMPLETE, 'success');
      tep_redirect(tep_href_link(FILENAME_MAKEWAM));
      break;
    case 'products_wam_dump':
      // 商品WAMの確認
      $result = shell_exec(FILENAME_DUMPWAM . ' ' . TEXT_P_HANDLE_ID);
      break;
    default:
      // 設定ファイルの読み込み
      $c_mw_cfg_file = @fopen(FILENAME_C_MAKEWAM_CONFIG, 'r');
      if ($c_mw_cfg_file) {
        while (!feof($c_mw_cfg_file)) {
          $c_cfg_rec = fgetcsv($c_mw_cfg_file,200);
          if (empty($c_cfg_rec)) {
            continue;								// 空白行は読み飛ばす
          }
          for ($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
            if ($c_cfg_rec[0] == $mw_categories_field[$i]['field']) {
              $mw_categories_field[$i]['check'] = $c_cfg_rec[1];
              $mw_categories_field[$i]['weight'] = (int)$c_cfg_rec[2];
            }
          }
        }
      }
      fclose($c_mw_cfg_file);
      $p_mw_cfg_file = @fopen(FILENAME_P_MAKEWAM_CONFIG, 'r');
      if ($p_mw_cfg_file) {
        while (!feof($p_mw_cfg_file)) {
          $p_cfg_rec = fgetcsv($p_mw_cfg_file,200);
          if (empty($p_cfg_rec)) {
            continue;								// 空白行は読み飛ばす
          }
          for ($i = 0, $n = sizeof($mw_products_field); $i < $n; $i++) {
            if ($p_cfg_rec[0] == $mw_products_field[$i]['field']) {
              $mw_products_field[$i]['check'] = $p_cfg_rec[1];
              $mw_products_field[$i]['weight'] = (int)$p_cfg_rec[2];
            }
          }
        }
      }
      fclose($p_mw_cfg_file);
      $m_mw_cfg_file = @fopen(FILENAME_M_MAKEWAM_CONFIG, 'r');
      if ($m_mw_cfg_file) {
        while (!feof($m_mw_cfg_file)) {
          $m_cfg_rec = fgetcsv($m_mw_cfg_file,200);
          if (empty($m_cfg_rec)) {
            continue;								// 空白行は読み飛ばす
          }
          for ($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
            if ($m_cfg_rec[0] == $mw_manufacturers_field[$i]['field']) {
              $mw_manufacturers_field[$i]['check'] = $m_cfg_rec[1];
              $mw_manufacturers_field[$i]['weight'] = (int)$m_cfg_rec[2];
            }
          }
        }
      }
      fclose($m_mw_cfg_file);
      $r_mw_cfg_file = @fopen(FILENAME_R_MAKEWAM_CONFIG, 'r');
      if ($r_mw_cfg_file) {
        while (!feof($r_mw_cfg_file)) {
          $r_cfg_rec = fgetcsv($r_mw_cfg_file,200);
          if (empty($r_cfg_rec)) {
            continue;								// 空白行は読み飛ばす
          }
          for ($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
            if ($r_cfg_rec[0] == $mw_reviews_field[$i]['field']) {
              $mw_reviews_field[$i]['check'] = $r_cfg_rec[1];
              $mw_reviews_field[$i]['weight'] = (int)$r_cfg_rec[2];
            }
          }
        }
      }
      fclose($r_mw_cfg_file);
  }

// DIR_FS_GETA_WORKの存在＆書き込み可の確認
  if (is_dir(DIR_FS_GETA_WORK)) {
    if (!is_writeable(DIR_FS_GETA_WORK)) {
      $messageStack->add(ERROR_GETA_WORK_DIRECTORY_NOT_WRITEABLE . DIR_FS_GETA_WORK, 'error');
    }
  } else {
    $messageStack->add(ERROR_GETA_WORK_DIRECTORY_DOES_NOT_EXIST . DIR_FS_GETA_WORK, 'error');
  }
// FILENAME_MAKEWAM_JPの存在＆実行可の確認
  if (file_exists(FILENAME_MAKEWAM_JP)) {
    if (!is_executable(FILENAME_MAKEWAM_JP)) {
      $messageStack->add(ERROR_MAKEWAM_JP_NOT_EXECUTABLE . FILENAME_MAKEWAM_JP, 'error');
    }
  } else {
    $messageStack->add(ERROR_MAKEWAM_JP_DOES_NOT_EXIST . FILENAME_MAKEWAM_JP, 'error');
  }
// FILENAME_MKWの存在＆実行可の確認
  if (file_exists(FILENAME_MKW)) {
    if (!is_executable(FILENAME_MKW)) {
      $messageStack->add(ERROR_MKW_NOT_EXECUTABLE . FILENAME_MKW, 'error');
    }
  } else {
    $messageStack->add(ERROR_MKW_DOES_NOT_EXIST . FILENAME_MKW, 'error');
  }
// FILENAME_MKAUXの存在＆実行可の確認
  if (file_exists(FILENAME_MKAUX)) {
    if (!is_executable(FILENAME_MKAUX)) {
      $messageStack->add(ERROR_MKAUX_NOT_EXECUTABLE . FILENAME_MKAUX, 'error');
    }
  } else {
    $messageStack->add(ERROR_MKAUX_DOES_NOT_EXIST . FILENAME_MKAUX, 'error');
  }
// FILENAME_DUMPWAMの存在＆実行可の確認
  if (file_exists(FILENAME_DUMPWAM)) {
    if (!is_executable(FILENAME_DUMPWAM)) {
      $messageStack->add(ERROR_DUMPWAM_NOT_EXECUTABLE . FILENAME_DUMPWAM, 'error');
    }
  } else {
    $messageStack->add(ERROR_DUMPWAM_DOES_NOT_EXIST . FILENAME_DUMPWAM, 'error');
  }
// FILENAME_C_MAKEWAM_CONFIGの存在＆書き込み可の確認
  if (file_exists(FILENAME_C_MAKEWAM_CONFIG)) {
    if (!is_writable(FILENAME_C_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_C_MAKEWAM_NOT_WRITABLE . FILENAME_C_MAKEWAM_CONFIG, 'error');
    }
  } else {
    $c_mw_cfg_file = @fopen(FILENAME_C_MAKEWAM_CONFIG, 'w');
    for ($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
      fwrite($c_mw_cfg_file, $mw_categories_field[$i]['field'] . ',' . $mw_categories_field[$i]['check'] . ',' . $mw_categories_field[$i]['weight'] . "\n");
    }
    fclose($c_mw_cfg_file);
    if (!file_exists(FILENAME_C_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_C_MAKEWAM_DOES_NOT_EXIST . FILENAME_C_MAKEWAM_CONFIG, 'error');
    }
  }
// FILENAME_P_MAKEWAM_CONFIGの存在＆書き込み可の確認
  if (file_exists(FILENAME_P_MAKEWAM_CONFIG)) {
    if (!is_writable(FILENAME_P_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_P_MAKEWAM_NOT_WRITABLE . FILENAME_P_MAKEWAM_CONFIG, 'error');
    }
  } else {
    $p_mw_cfg_file = @fopen(FILENAME_P_MAKEWAM_CONFIG, 'w');
    for ($i = 0, $n = sizeof($mw_products_field); $i < $n; $i++) {
      fwrite($p_mw_cfg_file, $mw_products_field[$i]['field'] . ',' . $mw_products_field[$i]['check'] . ',' . $mw_products_field[$i]['weight'] . "\n");
    }
    fclose($p_mw_cfg_file);
    if (!file_exists(FILENAME_P_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_P_MAKEWAM_DOES_NOT_EXIST . FILENAME_P_MAKEWAM_CONFIG, 'error');
    }
  }
// FILENAME_M_MAKEWAM_CONFIGの存在＆書き込み可の確認
  if (file_exists(FILENAME_M_MAKEWAM_CONFIG)) {
    if (!is_writable(FILENAME_M_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_M_MAKEWAM_NOT_WRITABLE . FILENAME_M_MAKEWAM_CONFIG, 'error');
    }
  } else {
    $m_mw_cfg_file = @fopen(FILENAME_M_MAKEWAM_CONFIG, 'w');
    for ($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
      fwrite($m_mw_cfg_file, $mw_manufacturers_field[$i]['field'] . ',' . $mw_manufacturers_field[$i]['check'] . ',' . $mw_manufacturers_field[$i]['weight'] . "\n");
    }
    fclose($m_mw_cfg_file);
    if (!file_exists(FILENAME_M_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_M_MAKEWAM_DOES_NOT_EXIST . FILENAME_M_MAKEWAM_CONFIG, 'error');
    }
  }
// FILENAME_R_MAKEWAM_CONFIGの存在＆書き込み可の確認
  if (file_exists(FILENAME_R_MAKEWAM_CONFIG)) {
    if (!is_writable(FILENAME_R_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_R_MAKEWAM_NOT_WRITABLE . FILENAME_R_MAKEWAM_CONFIG, 'error');
    }
  } else {
    $r_mw_cfg_file = @fopen(FILENAME_R_MAKEWAM_CONFIG, 'w');
    for ($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
      fwrite($r_mw_cfg_file, $mw_reviews_field[$i]['field'] . ',' . $mw_reviews_field[$i]['check'] . ',' . $mw_reviews_field[$i]['weight'] . "\n");
    }
    fclose($r_mw_cfg_file);
    if (!file_exists(FILENAME_R_MAKEWAM_CONFIG)) {
      $messageStack->add(ERROR_R_MAKEWAM_DOES_NOT_EXIST . FILENAME_R_MAKEWAM_CONFIG, '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']) {
    default:
      // メイン画面（今はこの画面だけ）
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top" class="main">
              <fieldset><?php echo tep_draw_form('make_products_wam', FILENAME_MAKEWAM, 'action=make_products_wam', 'post'); ?>
              <legend class="main"><?php echo TEXT_CREATE_PRODUCTS_WAM ?></legend>
              <table border="0" width="100%" cellspacing="10" cellpadding="0">
                <tr><td valign="top" class="main"><?php echo TEXT_CHECK_INCLUDE_FIELDS; ?></td><td align="right" class="main"><?php echo TEXT_WEIGHT; ?></td></tr>
              </table>
              <table border="0" width="100%" cellspacing="10" cellpadding="0">
                <tr><td valign="top" class="main" colspan="2"><table border="0" width="100%" cellspacing="5" cellpadding="3" class="knBox">
<?php
      for($i = 0, $n = sizeof($mw_products_field); $i < $n; $i++) {
        switch ($mw_products_field[$i]['check']) {
          case 0:
            echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_products_field[$i]['field'], '1', false) . '</td><td class="knMenu">' . $mw_products_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_products_field[$i]['field'] . '_weight', $mw_products_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
            break;
          case 1:
            echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_products_field[$i]['field'], '1', true) . '</td><td class="knMenu">' . $mw_products_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_products_field[$i]['field'] . '_weight', $mw_products_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
            break;
          case 9:
            echo '                  <tr><td width="20">' . tep_draw_hidden_field($mw_products_field[$i]['field'], '9') . '</td><td class="knMenu">' . $mw_products_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_products_field[$i]['field'] . '_weight', $mw_products_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
            break;
        }
      }
?>
                </table></td></tr>
<?php
      $c_inc_flg = false;
      for($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
        if ($mw_categories_field[$i]['check'] == 1) {
          $c_inc_flg = true;
        }
      }
      echo '<tr><td colspan="2" class="main">' . tep_draw_checkbox_field('include_category_fields', '1', $c_inc_flg) . ' ' . TEXT_INCLUDES_CATEGORY_FIELDS . "</td></tr>\n";
?>
                <tr><td width="20"><?php echo tep_draw_separator('pixel_trans.gif', '20', '10'); ?></td>
                <td><table border="0" width="100%" cellspacing="5" cellpadding="3" class="knBox">
<?php
      for($i = 0, $n = sizeof($mw_categories_field); $i < $n; $i++) {
        switch ($mw_categories_field[$i]['check']) {
          case 0:
            echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_categories_field[$i]['field'], '1', false) . '</td><td class="knMenu">' . $mw_categories_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_categories_field[$i]['field'] . '_weight', $mw_categories_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
            break;
          case 1:
            echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_categories_field[$i]['field'], '1', true) . '</td><td class="knMenu">' . $mw_categories_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_categories_field[$i]['field'] . '_weight', $mw_categories_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
            break;
          case 9:
            echo '                  <tr><td width="20">' . tep_draw_hidden_field($mw_categories_field[$i]['field'], '9') . '</td><td class="knMenu">' . $mw_categories_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_categories_field[$i]['field'] . '_weight', $mw_categories_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
            break;
        }
      }
?>
                </table>
                </td></tr>
<?php
      if (KN_CFG_USE_MANUFACTURERS) {
        $m_inc_flg = false;
        for($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
          if ($mw_manufacturers_field[$i]['check'] == 1) {
            $m_inc_flg = true;
          }
        }
        echo '<tr><td colspan="2" class="main">' . tep_draw_checkbox_field('include_manufacturer_fields', '1', $m_inc_flg) . ' ' . TEXT_INCLUDES_MANUFACTURER_FIELDS . "</td></tr>\n";
?>
                <tr><td width="20"><?php echo tep_draw_separator('pixel_trans.gif', '20', '10'); ?></td>
                <td><table border="0" width="100%" cellspacing="5" cellpadding="3" class="knBox">
<?php
        for($i = 0, $n = sizeof($mw_manufacturers_field); $i < $n; $i++) {
          switch ($mw_manufacturers_field[$i]['check']) {
            case 0:
              echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_manufacturers_field[$i]['field'], '1', false) . '</td><td class="knMenu">' . $mw_manufacturers_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_manufacturers_field[$i]['field'] . '_weight', $mw_manufacturers_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
              break;
            case 1:
              echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_manufacturers_field[$i]['field'], '1', true) . '</td><td class="knMenu">' . $mw_manufacturers_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_manufacturers_field[$i]['field'] . '_weight', $mw_manufacturers_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
              break;
            case 9:
              echo '                  <tr><td width="20">' . tep_draw_hidden_field($mw_manufacturers_field[$i]['field'], '9') . '</td><td class="knMenu">' . $mw_manufacturers_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_manufacturers_field[$i]['field'] . '_weight', $mw_manufacturers_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
              break;
          }
        }
?>
                </table>
                </td></tr>
<?php
      }
      if (KN_CFG_USE_REVIEWS == 'true') {
        $r_inc_flg = false;
        for($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
          if ($mw_reviews_field[$i]['check'] == 1) {
            $r_inc_flg = true;
          }
        }
        echo '<tr><td colspan="2" class="main">' . tep_draw_checkbox_field('include_review_fields', '1', $r_inc_flg) . ' ' . TEXT_INCLUDES_REVIEW_FIELDS . "</td></tr>\n";
?>
                <tr><td width="20"><?php echo tep_draw_separator('pixel_trans.gif', '20', '10'); ?></td>
                <td><table border="0" width="100%" cellspacing="5" cellpadding="3" class="knBox">
<?php
        for($i = 0, $n = sizeof($mw_reviews_field); $i < $n; $i++) {
          switch ($mw_reviews_field[$i]['check']) {
            case 0:
              echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_reviews_field[$i]['field'], '1', false) . '</td><td class="knMenu">' . $mw_reviews_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_reviews_field[$i]['field'] . '_weight', $mw_reviews_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
              break;
            case 1:
              echo '                  <tr><td width="20">' . tep_draw_checkbox_field($mw_reviews_field[$i]['field'], '1', true) . '</td><td class="knMenu">' . $mw_reviews_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_reviews_field[$i]['field'] . '_weight', $mw_reviews_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
              break;
            case 9:
              echo '                  <tr><td width="20">' . tep_draw_hidden_field($mw_reviews_field[$i]['field'], '9') . '</td><td class="knMenu">' . $mw_reviews_field[$i]['title'] . '</td><td align="right" class="knMenu">' . tep_draw_input_field($mw_reviews_field[$i]['field'] . '_weight', $mw_reviews_field[$i]['weight'], 'size="3"') . "</td></tr>\n";
              break;
          }
        }
?>
                </table>
                </td></tr>
<?php
      }
?>
              </table>
              <table border="0" width="100%" cellspacing="10" cellpadding="0">
                <tr><td valign="top" class="main"><?php echo  tep_image_submit('button_update.gif', IMAGE_UPDATE); ?></td><td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_MAKEWAM, 'action=products_wam_dump', 'NONSSL') . '" class="knInput">' . TEXT_PRODUCTS_WAM_DUMP_LINK . '</a>'; ?></td></tr>
              </table>
              </form></fieldset>
<?php
      if ($_GET['action'] == 'products_wam_dump') {
?>
              <fieldset>
              <legend class="main"><?php echo TEXT_WAM_DUMP ?></legend>
              <table border="0" width="100%" cellspacing="5" cellpadding="3" class="knBox">
                <tr><td valign="top" class="main"><?php echo $result; ?></td></tr>
              </table>
              </fieldset>
<?php
      }
?>
            </td>
          </tr>
        </table></td>
      </tr>
<?php
      break;
  }
?>
      </table></td>
<!-- body_text_eof //-->
<!-- right_column //-->
    <td width="300" valign="top">
      <table border="0" width="300" cellspacing="1" cellpadding="1" class="columnRight">
        <tr>
          <td class="knMain"><?php echo TEXT_MAKEWAM_NOTE01; ?></td>
        </tr>
        <tr>
          <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
        </tr>
        <tr>
          <td class="knMain"><?php echo TEXT_MAKEWAM_NOTE02; ?></td>
        </tr>
        <tr>
          <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
        </tr>
        <tr>
          <td class="knMain"><?php echo TEXT_MAKEWAM_NOTE03; ?></td>
        </tr>
      </table>
    </td>
<!-- right_column_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'); ?>
