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

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

  Released under the GNU General Public License

  //----------------------------------------------------------------------------//
  事前に必要な環境
  //----------------------------------------------------------------------------//
  このモジュールはGETAの使用を前提としているため、makewam.phpに記載された
  手順およびmakewam.phpでのWAMの生成が必要です。
  //----------------------------------------------------------------------------//
*/

  require('includes/application_top.php');

  //GETA用設定ファイル
  require('../geta_work/geta_cfg.php');
  define('FILENAME_SEARCH_DATA', DIR_FS_GETA_WORK . 'gt_s_data.txt');			// 検索文ファイル

  if ($_GET['action']) {
    switch ($_GET['action']) {
      case 'insert':
        // テーマの登録
        if (($_POST['edit_x']) || ($_POST['edit_y'])) {
        	 // プレビュー画面で戻るボタンを押されたとき
          $geta_themes = array();
          $geta_themes['geta_themes_title'] = $_POST['geta_themes_title'];
          $geta_themes['geta_themes_description'] = $_POST['geta_themes_description'];
          $geta_themes['geta_themes_keywords'] = $_POST['geta_themes_keywords'];
          $geta_themes['geta_themes_image1'] = $_POST['geta_themes_image1_path'];
          $geta_themes['geta_themes_image2'] = $_POST['geta_themes_image2_path'];
          $geta_themes['geta_themes_image3'] = $_POST['geta_themes_image3_path'];
          $geta_themes['geta_themes_image4'] = $_POST['geta_themes_image4_path'];
          $geta_themes['geta_themes_image5'] = $_POST['geta_themes_image5_path'];
          $gtInfo = new objectInfo($geta_themes);
          $_GET['action'] = 'new_theme';
        } else {
          if (!$_POST['geta_themes_title']) {
            // テーマ名がない場合はエラー
            $messageStack->add(ERROR_GETA_THEMES_TITLE_IS_EMPTY, 'error');
            $geta_themes = array();
            $geta_themes['geta_themes_title'] = $_POST['geta_themes_title'];
            $geta_themes['geta_themes_description'] = $_POST['geta_themes_description'];
            $geta_themes['geta_themes_keywords'] = $_POST['geta_themes_keywords'];
            $geta_themes['geta_themes_image1'] = $_POST['geta_themes_image1_path'];
            $geta_themes['geta_themes_image2'] = $_POST['geta_themes_image2_path'];
            $geta_themes['geta_themes_image3'] = $_POST['geta_themes_image3_path'];
            $geta_themes['geta_themes_image4'] = $_POST['geta_themes_image4_path'];
            $geta_themes['geta_themes_image5'] = $_POST['geta_themes_image5_path'];
            $gtInfo = new objectInfo($geta_themes);
            $_GET['action'] = 'new_theme';
          } else {
            $geta_themes_title = tep_db_prepare_input($_POST['geta_themes_title']);
            $geta_themes_description = tep_db_prepare_input($_POST['geta_themes_description']);
            $geta_themes_keywords = tep_db_prepare_input($_POST['geta_themes_keywords']);
            $geta_themes_image1 = tep_db_prepare_input($_POST['geta_themes_image1_path']);
            $geta_themes_image2 = tep_db_prepare_input($_POST['geta_themes_image2_path']);
            $geta_themes_image3 = tep_db_prepare_input($_POST['geta_themes_image3_path']);
            $geta_themes_image4 = tep_db_prepare_input($_POST['geta_themes_image4_path']);
            $geta_themes_image5 = tep_db_prepare_input($_POST['geta_themes_image5_path']);
            $sql_data_array = array('geta_themes_title' => $geta_themes_title,
                                        'geta_themes_description' => $geta_themes_description,
                                        'geta_themes_keywords' => $geta_themes_keywords,
                                        'geta_themes_image1' => $geta_themes_image1,
                                        'geta_themes_image2' => $geta_themes_image2,
                                        'geta_themes_image3' => $geta_themes_image3,
                                        'geta_themes_image4' => $geta_themes_image4,
                                        'geta_themes_image5' => $geta_themes_image5,
                                        'date_added' =>  'now()');
            tep_db_perform(TABLE_GETA_THEMES, $sql_data_array);
            $messageStack->add_session(SUCCESS_GETA_THEME_INSERT_COMPLETE, 'success');
            tep_redirect(tep_href_link(FILENAME_GETA_THEMES));
          }
        }
        break;
      case 'update':
        // テーマ内容の更新
        if (($_POST['edit_x']) || ($_POST['edit_y'])) {
        	 // プレビュー画面で戻るボタンを押されたとき
          $gtID = $_POST['geta_themes_id'];
          $geta_themes = array();
          $geta_themes['geta_themes_title'] = $_POST['geta_themes_title'];
          $geta_themes['geta_themes_description'] = $_POST['geta_themes_description'];
          $geta_themes['geta_themes_keywords'] = $_POST['geta_themes_keywords'];
          $geta_themes['geta_themes_image1'] = $_POST['geta_themes_image1_path'];
          $geta_themes['geta_themes_image2'] = $_POST['geta_themes_image2_path'];
          $geta_themes['geta_themes_image3'] = $_POST['geta_themes_image3_path'];
          $geta_themes['geta_themes_image4'] = $_POST['geta_themes_image4_path'];
          $geta_themes['geta_themes_image5'] = $_POST['geta_themes_image5_path'];
          $geta_themes['last_modified'] = $_POST['last_modified'];
          $geta_themes['date_added'] = $_POST['date_added'];
          $gtInfo = new objectInfo($geta_themes);
          $_GET['action'] = 'edit_theme';
        } else {
          if (!$_POST['geta_themes_title']) {
            // テーマ名がない場合はエラー
            $messageStack->add(ERROR_GETA_THEMES_TITLE_IS_EMPTY, 'error');
            $gtID = $_POST['geta_themes_id'];
            $geta_themes = array();
            $geta_themes['geta_themes_title'] = $_POST['geta_themes_title'];
            $geta_themes['geta_themes_description'] = $_POST['geta_themes_description'];
            $geta_themes['geta_themes_keywords'] = $_POST['geta_themes_keywords'];
            $geta_themes['geta_themes_image1'] = $_POST['geta_themes_image1_path'];
            $geta_themes['geta_themes_image2'] = $_POST['geta_themes_image2_path'];
            $geta_themes['geta_themes_image3'] = $_POST['geta_themes_image3_path'];
            $geta_themes['geta_themes_image4'] = $_POST['geta_themes_image4_path'];
            $geta_themes['geta_themes_image5'] = $_POST['geta_themes_image5_path'];
            $geta_themes['last_modified'] = $_POST['last_modified'];
            $geta_themes['date_added'] = $_POST['date_added'];
            $gtInfo = new objectInfo($geta_themes);
            $_GET['action'] = 'edit_theme';
          } else {
            $geta_themes_id = tep_db_prepare_input($_POST['geta_themes_id']);
            $geta_themes_title = tep_db_prepare_input($_POST['geta_themes_title']);
            $geta_themes_description = tep_db_prepare_input($_POST['geta_themes_description']);
            $geta_themes_keywords = tep_db_prepare_input($_POST['geta_themes_keywords']);
            $geta_themes_image1 = tep_db_prepare_input($_POST['geta_themes_image1_path']);
            $geta_themes_image2 = tep_db_prepare_input($_POST['geta_themes_image2_path']);
            $geta_themes_image3 = tep_db_prepare_input($_POST['geta_themes_image3_path']);
            $geta_themes_image4 = tep_db_prepare_input($_POST['geta_themes_image4_path']);
            $geta_themes_image5 = tep_db_prepare_input($_POST['geta_themes_image5_path']);
            $sql_data_array = array('geta_themes_title' => $geta_themes_title,
                                        'geta_themes_description' => $geta_themes_description,
                                        'geta_themes_keywords' => $geta_themes_keywords,
                                        'geta_themes_image1' => $geta_themes_image1,
                                        'geta_themes_image2' => $geta_themes_image2,
                                        'geta_themes_image3' => $geta_themes_image3,
                                        'geta_themes_image4' => $geta_themes_image4,
                                        'geta_themes_image5' => $geta_themes_image5,
                                        'last_modified' =>  'now()');
            tep_db_perform(TABLE_GETA_THEMES, $sql_data_array, 'update', 'geta_themes_id = \'' . tep_db_input($geta_themes_id) . '\'');
            $messageStack->add_session(SUCCESS_GETA_THEME_UPDATE_COMPLETE, 'success');
            tep_redirect(tep_href_link(FILENAME_GETA_THEMES));
          }
        }
        break;
      case 'delete':
        // テーマの削除
        $geta_themes_id = tep_db_prepare_input($_POST['geta_themes_id']);
        tep_db_query("delete from " . TABLE_GETA_THEMES . " where geta_themes_id = '" . tep_db_input($geta_themes_id) . "'");
        $messageStack->add_session(SUCCESS_GETA_THEME_DELETE_COMPLETE, 'success');
        tep_redirect(tep_href_link(FILENAME_GETA_THEMES));
        break;
      case 'edit_theme':
        // テーマ内容の修正画面
        $gtID = tep_db_prepare_input($_GET['gtID']);
        $geta_themes_query = tep_db_query("select geta_themes_title, geta_themes_description, geta_themes_image1, geta_themes_image2, geta_themes_image3, geta_themes_image4, geta_themes_image5, geta_themes_keywords, last_modified, date_added from " . TABLE_GETA_THEMES . " where geta_themes_id = '" . tep_db_input($gtID) . "'");
        $geta_themes = tep_db_fetch_array($geta_themes_query);
        $gtInfo = new objectInfo($geta_themes);
        break;
      case 'insert_confirm':
      case 'update_confirm':
        // 編集内容の確認
        $gtID = $_POST['gtID'];
        $geta_themes_title = $_POST['geta_themes_title'];
        $geta_themes_description = $_POST['geta_themes_description'];
        $geta_themes_keywords = $_POST['geta_themes_keywords'];
        $geta_themes_description = str_replace("\r", "", $geta_themes_description);
        $last_modified = $_POST['last_modified'];
        $date_added = $_POST['date_added'];
        // 画像のアップロード
        $image_directory = tep_get_local_path(DIR_FS_CATALOG_IMAGES . DIR_WS_GETA_THEMES_IMAGES);
        if (is_dir($image_directory)) {
          if (is_writeable($image_directory)) {
            // 画像1
            if ($_POST['geta_themes_image1_delete']) {
              $geta_themes_image1_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1']);
              }
            } else {
              $geta_themes_image1 = tep_get_uploaded_file('geta_themes_image1');
              if (is_uploaded_file($geta_themes_image1['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1']);
                }
                $geta_themes_image1_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image1['name'];
                tep_copy_uploaded_file($geta_themes_image1, $image_directory);
              } else {
                $geta_themes_image1_path = $_POST['previous_geta_themes_image1'];
              }
            }
            // 画像2
            if ($_POST['geta_themes_image2_delete']) {
              $geta_themes_image2_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2']);
              }
            } else {
              $geta_themes_image2 = tep_get_uploaded_file('geta_themes_image2');
              if (is_uploaded_file($geta_themes_image2['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2']);
                }
                $geta_themes_image2_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image2['name'];
                tep_copy_uploaded_file($geta_themes_image2, $image_directory);
              } else {
                $geta_themes_image2_path = $_POST['previous_geta_themes_image2'];
              }
            }
            // 画像3
            if ($_POST['geta_themes_image3_delete']) {
              $geta_themes_image3_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3']);
              }
            } else {
              $geta_themes_image3 = tep_get_uploaded_file('geta_themes_image3');
              if (is_uploaded_file($geta_themes_image3['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3']);
                }
                $geta_themes_image3_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image3['name'];
                tep_copy_uploaded_file($geta_themes_image3, $image_directory);
              } else {
                $geta_themes_image3_path = $_POST['previous_geta_themes_image3'];
              }
            }
            // 画像4
            if ($_POST['geta_themes_image4_delete']) {
              $geta_themes_image4_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4']);
              }
            } else {
              $geta_themes_image4 = tep_get_uploaded_file('geta_themes_image4');
              if (is_uploaded_file($geta_themes_image4['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4']);
                }
                $geta_themes_image4_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image4['name'];
                tep_copy_uploaded_file($geta_themes_image4, $image_directory);
              } else {
                $geta_themes_image4_path = $_POST['previous_geta_themes_image4'];
              }
            }
            // 画像5
            if ($_POST['geta_themes_image5_delete']) {
              $geta_themes_image5_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5']);
              }
            } else {
              $geta_themes_image5 = tep_get_uploaded_file('geta_themes_image5');
              if (is_uploaded_file($geta_themes_image5['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5']);
                }
                $geta_themes_image5_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image5['name'];
                tep_copy_uploaded_file($geta_themes_image5, $image_directory);
              } else {
                $geta_themes_image5_path = $_POST['previous_geta_themes_image5'];
              }
            }
          } else {
            $messageStack->add(ERROR_GETA_THEMES_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
          }
        } else {
          // GETAテーマ用画像ディレクトリがない場合、作成する。
          @mkdir($image_directory, 0777);
          if (is_dir($image_directory)) {
            // 画像1
            if ($_POST['geta_themes_image1_delete']) {
              $geta_themes_image1_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1']);
              }
            } else {
              $geta_themes_image1 = tep_get_uploaded_file('geta_themes_image1');
              if (is_uploaded_file($geta_themes_image1['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image1']);
                }
                $geta_themes_image1_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image1['name'];
                tep_copy_uploaded_file($geta_themes_image1, $image_directory);
              } else {
                $geta_themes_image1_path = $_POST['previous_geta_themes_image1'];
              }
            }
            // 画像2
            if ($_POST['geta_themes_image2_delete']) {
              $geta_themes_image2_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2']);
              }
            } else {
              $geta_themes_image2 = tep_get_uploaded_file('geta_themes_image2');
              if (is_uploaded_file($geta_themes_image2['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image2']);
                }
                $geta_themes_image2_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image2['name'];
                tep_copy_uploaded_file($geta_themes_image2, $image_directory);
              } else {
                $geta_themes_image2_path = $_POST['previous_geta_themes_image2'];
              }
            }
            // 画像3
            if ($_POST['geta_themes_image3_delete']) {
              $geta_themes_image3_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3']);
              }
            } else {
              $geta_themes_image3 = tep_get_uploaded_file('geta_themes_image3');
              if (is_uploaded_file($geta_themes_image3['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image3']);
                }
                $geta_themes_image3_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image3['name'];
                tep_copy_uploaded_file($geta_themes_image3, $image_directory);
              } else {
                $geta_themes_image3_path = $_POST['previous_geta_themes_image3'];
              }
            }
            // 画像4
            if ($_POST['geta_themes_image4_delete']) {
              $geta_themes_image4_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4']);
              }
            } else {
              $geta_themes_image4 = tep_get_uploaded_file('geta_themes_image4');
              if (is_uploaded_file($geta_themes_image4['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image4']);
                }
                $geta_themes_image4_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image4['name'];
                tep_copy_uploaded_file($geta_themes_image4, $image_directory);
              } else {
                $geta_themes_image4_path = $_POST['previous_geta_themes_image4'];
              }
            }
            // 画像5
            if ($_POST['geta_themes_image5_delete']) {
              $geta_themes_image5_path = '';
              if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5'])) {
                 @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5']);
              }
            } else {
              $geta_themes_image5 = tep_get_uploaded_file('geta_themes_image5');
              if (is_uploaded_file($geta_themes_image5['tmp_name'])) {
                if (file_exists(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5'])) {
                  @unlink(DIR_FS_CATALOG_IMAGES . $_POST['previous_geta_themes_image5']);
                }
                $geta_themes_image5_path = DIR_WS_GETA_THEMES_IMAGES . $geta_themes_image5['name'];
                tep_copy_uploaded_file($geta_themes_image5, $image_directory);
              } else {
                $geta_themes_image5_path = $_POST['previous_geta_themes_image5'];
              }
            }
          } else {
            $messageStack->add(ERROR_GETA_THEMES_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
          }
        }
        break;
      case 'delete_confirm':
        // テーマの削除確認画面
        $gtID = tep_db_prepare_input($_GET['gtID']);
        $geta_themes_query = tep_db_query("select geta_themes_title, geta_themes_description, geta_themes_image1, geta_themes_image2, geta_themes_image3, geta_themes_image4, geta_themes_image5, geta_themes_keywords, last_modified, date_added from " . TABLE_GETA_THEMES . " where geta_themes_id = '" . tep_db_input($gtID) . "'");
        $geta_themes = tep_db_fetch_array($geta_themes_query);
        $geta_themes_title = $geta_themes['geta_themes_title'];
        $geta_themes_description = $geta_themes['geta_themes_description'];
        $geta_themes_keywords = $geta_themes['geta_themes_keywords'];
        break;
    }
  }
  // 連想検索
  if ($_GET['action'] == 'edit_theme') {
    // 検索文ファイルの作成
    $search_text = $geta_themes['geta_themes_title'] . ' ' . strip_tags($geta_themes['geta_themes_description']) . ' ' . $geta_themes['geta_themes_keywords'];
    $search_text = str_replace("\n", "", $search_text);
    $search_text = mb_convert_kana($search_text, "AsK");
    $search_text = mbereg_replace("[" . $replace_symbol . "]", " ", $search_text);
    foreach ($replace_array as $value) {
      if ($value) $search_text = mbereg_replace("[" . $value . "]", " ", $search_text);
    }
    $search_data = fopen(FILENAME_SEARCH_DATA, "w");
    fwrite($search_data, $search_text);
    fclose($search_data);
    // 商品WAMのフレーズ検索
    $max = KN_CFG_GETA_SEARCH_RESULTS_MAX;
    $start = 1;
    $s_result_products = array();
    $s_result = popen("perl " . FILENAME_S_GETA_THEMES . " " . FILENAME_SEARCH_DATA . " " . TEXT_P_HANDLE_ID . " " . FILENAME_SEARCH_JP . " " . $max . " " . $start . " 2>&1", "r");
    while ( !feof($s_result) ) {
      $s_result_data = fgetcsv($s_result, 1000, "\t");
      if (empty($s_result_data[0])) {
        break;
      }
      $search_pID = $s_result_data[0];
      $search_products = array();
      $search_products['pID'] = $search_pID;
      $search_products_array = explode(',', $s_result_data[2]);
      foreach ($search_products_array as $value) {
        if ($value) {
          list($item, $content) = explode('<>', $value);
          $search_products[$item] = $content;
        }
      }
      $list_num = $start + $results_count;
      $search_products['list_num'] = $list_num;
      
      $s_result_products[] = $search_products;
      $no_results = false;
      $results_count++;
    }
    pclose($s_result);
    // 検索テーマの文書要約
    $max = 30;
    $start = 1;
    $s_topicword_text = '';
    $s_topicword = popen("perl " . FILENAME_TW_GETA_THEMES . " " . FILENAME_SEARCH_DATA . " " . TEXT_P_HANDLE_ID . " " . FILENAME_SEARCH_JP . " " . $max . " " . $start . " 2>&1", "r");
    while ( !feof($s_topicword) ) {
      $s_topicword_text .= fgets($s_topicword, 100) . "<br>";
    }
    pclose($s_topicword);
  }
    
  // テーマ一覧用
  $geta_themes_query = tep_db_query("select geta_themes_id, geta_themes_title from " . TABLE_GETA_THEMES);
  $num_geta_themes = tep_db_num_rows($geta_themes_query);

  // イメージディレクトリの確認
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $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">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
<!-- 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 //-->
<?php
  if ($_GET['action'] == 'insert_confirm' || $_GET['action'] == 'update_confirm' || $_GET['action'] == 'delete_confirm') {
    //確認画面
?>
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo TEXT_GETA_THEMES_PREVIEW; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
<?php
    if ($_GET['action'] == 'update_confirm') {
      echo '      <tr>' . tep_draw_form('geta_themes', FILENAME_GETA_THEMES, 'action=update') . tep_draw_hidden_field('geta_themes_id', $gtID) . tep_draw_hidden_field('date_added', $date_added) . tep_draw_hidden_field('last_modified', $last_modified) . "\n";
      echo '        <td class="main">' . TEXT_UPDATE_CONFIRM_NOTE . "</td>\n";
      echo "      </tr>\n";
    } elseif ($_GET['action'] == 'delete_confirm') {
      echo '      <tr>' . tep_draw_form('geta_themes', FILENAME_GETA_THEMES, 'action=delete') . tep_draw_hidden_field('geta_themes_id', $gtID) . tep_draw_hidden_field('date_added', $date_added) . tep_draw_hidden_field('last_modified', $last_modified) . "\n";
      echo '        <td class="main">' . TEXT_DELETE_CONFIRM_NOTE . "</td>\n";
      echo "      </tr>\n";
    } else {
      echo tep_draw_form('geta_themes', FILENAME_GETA_THEMES, 'action=insert');
      echo '        <td class="main">' . TEXT_INSERT_CONFIRM_NOTE . "</td>\n";
      echo "      </tr>\n";
    }
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_TITLE; ?></td>
            <td class="main"><b><?php echo $geta_themes_title . tep_draw_hidden_field('geta_themes_title', $geta_themes_title); ?></b></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_DESCRIPTION; ?></td>
            <td class="main"><?php echo $geta_themes_description . tep_draw_hidden_field('geta_themes_description', $geta_themes_description); ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_KEYWORDS; ?></td>
            <td class="main"><?php echo $geta_themes_keywords . tep_draw_hidden_field('geta_themes_keywords', $geta_themes_keywords); ?></td>
          </tr>
<?php
    if ($geta_themes_image1_path) {
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_IMAGE_01; ?></td>
            <td class="main"><?php echo tep_draw_hidden_field('geta_themes_image1_path', $geta_themes_image1_path) . '&nbsp;' . tep_image(DIR_WS_CATALOG_IMAGES . $geta_themes_image1_path, $geta_themes_title, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . $geta_themes_image1_path; ?></td>
          </tr>
<?php
    }
    if ($geta_themes_image2_path) {
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_IMAGE_02; ?></td>
            <td class="main"><?php echo tep_draw_hidden_field('geta_themes_image2_path', $geta_themes_image2_path) . '&nbsp;' . tep_image(DIR_WS_CATALOG_IMAGES . $geta_themes_image2_path, $geta_themes_title, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . $geta_themes_image2_path; ?></td>
          </tr>
<?php
    }
    if ($geta_themes_image3_path) {
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_IMAGE_03; ?></td>
            <td class="main"><?php echo tep_draw_hidden_field('geta_themes_image3_path', $geta_themes_image3_path) . '&nbsp;' . tep_image(DIR_WS_CATALOG_IMAGES . $geta_themes_image3_path, $geta_themes_title, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . $geta_themes_image3_path; ?></td>
          </tr>
<?php
    }
    if ($geta_themes_image4_path) {
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_IMAGE_04; ?></td>
            <td class="main"><?php echo tep_draw_hidden_field('geta_themes_image4_path', $geta_themes_image4_path) . '&nbsp;' . tep_image(DIR_WS_CATALOG_IMAGES . $geta_themes_image4_path, $geta_themes_title, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . $geta_themes_image4_path; ?></td>
          </tr>
<?php
    }
    if ($geta_themes_image5_path) {
?>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_IMAGE_05; ?></td>
            <td class="main"><?php echo tep_draw_hidden_field('geta_themes_image5_path', $geta_themes_image5_path) . '&nbsp;' . tep_image(DIR_WS_CATALOG_IMAGES . $geta_themes_image5_path, $geta_themes_title, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"') . $geta_themes_image5_path; ?></td>
          </tr>
<?php
    }
?>
        </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="2">
          <tr>
            <td class="main" align="right">
<?php
    if ($_GET['action'] == 'update_confirm' || $_GET['action'] == 'insert_confirm') {
      echo tep_image_submit('button_save.gif', IMAGE_SAVE) . ' ' . tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"');
    } elseif ($_GET['action'] == 'delete_confirm') {
      echo tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_GETA_THEMES) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
    }
?>
            </td>
          </tr>
        </table></td>
      </form></tr>
<?php
  } else {
  // 通常画面
?>
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo TEXT_EDIT_GETA_THEMES; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
<?php
    if ($_GET['action'] == 'edit_theme') {
      echo tep_draw_form('geta_themes', FILENAME_GETA_THEMES, 'action=update_confirm', 'post', 'enctype="multipart/form-data"') . tep_draw_hidden_field('geta_themes_id', $gtID) . tep_draw_hidden_field('date_added', $gtInfo->date_added) . tep_draw_hidden_field('last_modified', $gtInfo->last_modified);
?>
        <td><table border="0" width="100%" cellspacing="2" cellpadding="2" class="knBox">
          <tr>
            <td class="knMenu" align="right">
<?php
      if ($gtInfo->last_modified) {
        echo TEXT_LAST_MODIFIED . ' ' . $gtInfo->last_modified;
      } else {
        echo TEXT_DATE_ADDED . ' ' . $gtInfo->date_added;
      }
?>
            </td>
          </tr>
        </table></td>
      </tr>
      <tr>
<?php
    } else {
      echo tep_draw_form('geta_themes', FILENAME_GETA_THEMES, 'action=insert_confirm', 'post', 'enctype="multipart/form-data"');
    }
?>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_TITLE; ?></td>
            <td class="main" valign="top"><?php echo tep_draw_input_field('geta_themes_title', $gtInfo->geta_themes_title, 'size="30"'); ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_DESCRIPTION; ?></td>
            <td class="main"><?php echo tep_draw_textarea_field('geta_themes_description', 'soft', '70', '15', $gtInfo->geta_themes_description); ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main" nowrap valign="top"><?php echo TEXT_GETA_THEMES_KEYWORDS; ?></td>
            <td class="main"><?php echo tep_draw_textarea_field('geta_themes_keywords', 'soft', '70', '5', $gtInfo->geta_themes_keywords) . '<br>' . TEXT_GETA_THEMES_KEYWORDS_NOTE; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_GETA_THEMES_IMAGE_01; ?></td>
            <td class="main">
<?php
      echo tep_draw_file_field('geta_themes_image1');
      if ($gtInfo->geta_themes_image1) {
        // 画像の変更確認用に既存の画像パスをとっておく
        echo '<br>' . $gtInfo->geta_themes_image1;
        // 画像削除用チェックボックス
        echo tep_draw_hidden_field('previous_geta_themes_image1', $gtInfo->geta_themes_image1);
        echo '&nbsp;&nbsp;' . tep_draw_checkbox_field('geta_themes_image1_delete') . '&nbsp;' . TEXT_DELETE;
      }
?>
            </td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_GETA_THEMES_IMAGE_02; ?></td>
            <td class="main">
<?php
      echo tep_draw_file_field('geta_themes_image2');
      if ($gtInfo->geta_themes_image2) {
        // 画像の変更確認用に既存の画像パスをとっておく
        echo '<br>' . $gtInfo->geta_themes_image2;
        // 画像削除用チェックボックス
        echo tep_draw_hidden_field('previous_geta_themes_image2', $gtInfo->geta_themes_image2);
        echo '&nbsp;&nbsp;' . tep_draw_checkbox_field('geta_themes_image2_delete') . '&nbsp;' . TEXT_DELETE;
      }
?>
            </td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_GETA_THEMES_IMAGE_03; ?></td>
            <td class="main">
<?php
      echo tep_draw_file_field('geta_themes_image3');
      if ($gtInfo->geta_themes_image3) {
        // 画像の変更確認用に既存の画像パスをとっておく
        echo '<br>' . $gtInfo->geta_themes_image3;
        // 画像削除用チェックボックス
        echo tep_draw_hidden_field('previous_geta_themes_image3', $gtInfo->geta_themes_image3);
        echo '&nbsp;&nbsp;' . tep_draw_checkbox_field('geta_themes_image3_delete') . '&nbsp;' . TEXT_DELETE;
      }
?>
            </td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_GETA_THEMES_IMAGE_04; ?></td>
            <td class="main">
<?php
      echo tep_draw_file_field('geta_themes_image4');
      if ($gtInfo->geta_themes_image4) {
        // 画像の変更確認用に既存の画像パスをとっておく
        echo '<br>' . $gtInfo->geta_themes_image4;
        // 画像削除用チェックボックス
        echo tep_draw_hidden_field('previous_geta_themes_image4', $gtInfo->geta_themes_image4);
        echo '&nbsp;&nbsp;' . tep_draw_checkbox_field('geta_themes_image4_delete') . '&nbsp;' . TEXT_DELETE;
      }
?>
            </td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '3'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo TEXT_GETA_THEMES_IMAGE_05; ?></td>
            <td class="main">
<?php
      echo tep_draw_file_field('geta_themes_image5');
      if ($gtInfo->geta_themes_image5) {
        // 画像の変更確認用に既存の画像パスをとっておく
        echo '<br>' . $gtInfo->geta_themes_image5;
        // 画像削除用チェックボックス
        echo tep_draw_hidden_field('previous_geta_themes_image5', $gtInfo->geta_themes_image5);
        echo '&nbsp;&nbsp;' . tep_draw_checkbox_field('geta_themes_image5_delete') . '&nbsp;' . TEXT_DELETE;
      }
?>
            </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="2">
          <tr>
            <td class="main" align="right">
<?php
    if ($_GET['action'] == 'edit_theme') {
      echo tep_image_submit('button_update.gif', IMAGE_UPDATE) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_GETA_THEMES) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_GETA_THEMES, 'action=delete_confirm&gtID=' . $gtID) . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>';
    } else {
      echo tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_GETA_THEMES) . '">' . tep_image_button('button_reset.gif', IMAGE_RESET) . '</a>';
    }
?>
            </td>
          </tr>
        </table></td>
      </form></tr>
<?php
    if ($_GET['action'] == 'edit_theme') {
?>
      <tr>
        <td valign="top" align="center"><table border="0" width="100%" cellspacing="0" cellpadding="0"><tr>
        <td width="80%" valign="top"><table border="0" width="100%" cellspacing="2" cellpadding="2" class="knBox2">
          <tr>
            <td class="knMenu2"><?php echo TEXT_GETA_SEARCH_RESULTS; ?></td>
          </tr>
          <tr>
            <td class="knMenu2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td><table border="0" width="100%" cellspacing="0" cellpadding="0" class="knMenu2">
<?php
      require(DIR_WS_CLASSES . 'currencies.php');
      $currencies = new currencies();

      for ($i=0, $n=sizeof($s_result_products); $i<$n; $i++) {
        echo "              <tr>\n";
        echo '                <td valign="top">' . $s_result_products[$i]['list_num'] . '</td>' . "\n";
        echo '                <td valign="top"><a href="' . tep_href_link(FILENAME_PRODUCTS_EDIT, 'action=edit_product&pID=' . $s_result_products[$i]['pID']) . '"><span class="knMenu2"><b>' . $s_result_products[$i]['products_name'] . '</span></b></a><br>';
        echo (($s_result_products[$i]['products_subtitle']) ? $s_result_products[$i]['products_subtitle'] . '&nbsp;' : '') . 
               (($s_result_products[$i]['products_series_title']) ? $s_result_products[$i]['products_series_title'] . '&nbsp;' : '') . 
               (($s_result_products[$i]['products_author']) ? $s_result_products[$i]['products_author'] . '&nbsp;' : '') . 
               (($s_result_products[$i]['products_volume']) ? $s_result_products[$i]['products_volume'] . '&nbsp;' : '') . 
               (($s_result_products[$i]['products_published']) ? $s_result_products[$i]['products_published'] . '&nbsp;' : '') . 
               (($s_result_products[$i]['products_publishers']) ? $s_result_products[$i]['products_publishers'] . '&nbsp;' : '') . 
               (($s_result_products[$i]['products_isbn']) ? '(' . $s_result_products[$i]['products_isbn'] . ');' : '') . 
               '</td>' . "\n";
        echo '                <td class="main" valign="top" align="right">';
        if (tep_not_null($s_result_products[$i]['specials_new_products_price'])) {
          echo '<s>' .  $currencies->display_price($s_result_products[$i]['products_price'], tep_get_tax_rate($s_result_products[$i]['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($s_result_products[$i]['specials_new_products_price'], tep_get_tax_rate($s_result_products[$i]['products_tax_class_id'])) . '</span>';
        } else {
          echo $currencies->display_price($s_result_products[$i]['products_price'], tep_get_tax_rate($s_result_products[$i]['products_tax_class_id']));
        }
        echo "</td>\n";
        echo "              </tr>\n";
        echo '              <tr><td>' . tep_draw_separator('pixel_trans.gif', '1', '5') . "</td></tr>\n";
      }
?>
            </table></td>
          </tr>
        </table>
        </td>
        <td width="20%" valign="top"><table border="0" width="100%" cellspacing="2" cellpadding="2" class="knBox">
          <tr>
            <td class="knMenu"><?php echo TEXT_GETA_TOPIC_WORDS; ?></td>
          </tr>
          <tr>
            <td class="knMenu"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="knMenu"><?php echo $s_topicword_text; ?></td>
          </tr>
        </table>
        </td>
        </tr></table></td>
      </tr>
<?php
    }
  }
?>
    </table></td>
<!-- body_text_eof //-->
<!-- right_column //-->
    <td width="200" valign="top">
      <table border="0" width="200" cellspacing="0" cellpadding="2">
        <tr>
          <td class="smalltext"><?php echo tep_draw_separator('pixel_trans.gif', '50', '50'); ?></td>
        </tr>
      </table>
      <table border="0" width="200" cellspacing="1" cellpadding="1" class="columnRight">
        <tr>
          <td class="knMain"><?php echo TEXT_GETA_THEMES_LIST; ?></td>
          <td align="right" class="knMain"><?php echo '<a href="' . tep_href_link(FILENAME_GETA_THEMES) . '">' . TEXT_GETA_THEMES_NEW . '</a>'; ?></td>
        </tr>
        <tr>
          <td colspan="2" class="knMain"><hr noshade></td>
        </tr>
        <tr>
          <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
        </tr>
<?php
  if ($num_geta_themes < 1) {
?>
        <tr>
          <td colspan="2" class="knMain"><?php echo TEXT_NO_GETA_THEMES; ?></a></td>
        </tr>
        <tr>
          <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
        </tr>
<?php
  } else {
    while($geta_themes = tep_db_fetch_array($geta_themes_query)) {
?>
        <tr>
          <td colspan="2" class="knMain"><?php echo '<a href="' . tep_href_link(FILENAME_GETA_THEMES, 'action=edit_theme&gtID=' . $geta_themes['geta_themes_id']) . '">' . $geta_themes['geta_themes_title']; ?></a></td>
        </tr>
        <tr>
          <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
        </tr>
<?php
    }
  }
?>
      </table>
<!-- 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'); ?>