<?php
/*
  shop_info.php
  作成日：2004/12/2
　最終更新日：2005/6/1

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

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  if ($_GET['action']) {
    switch ($_GET['action']) {
      case 'insert':
        // 文面の登録
        if (($_POST['edit_x']) || ($_POST['edit_y'])) {
          // プレビュー画面で戻るボタンを押されたとき
          $shop_info = array();
          $shop_info['shop_info_title'] = $_POST['shop_info_title'];
          $shop_info['shop_info_value'] = $_POST['shop_info_value'];
          $shop_info['shop_info_value2'] = $_POST['shop_info_value2'];
          $shop_info['shop_info_note'] = $_POST['shop_info_note'];
          $shop_info['allow_edit_title'] = $_POST['allow_edit_title'];
          $shop_info['allow_edit_value2'] = $_POST['allow_edit_value2'];
          $shop_info['allow_tags'] = $_POST['allow_tags'];
          $shop_info['last_modified'] = '';
          $siInfo = new objectInfo($shop_info);
          $_GET['action'] = 'add_value';
        } else {
          $shop_info_title = tep_db_prepare_input($_POST['shop_info_title']);
          $shop_info_value = tep_db_prepare_input($_POST['shop_info_value']);
          $shop_info_value2 = tep_db_prepare_input($_POST['shop_info_value2']);
          $shop_info_note = tep_db_prepare_input($_POST['shop_info_note']);
          $allow_edit_title = tep_db_prepare_input($_POST['allow_edit_title']);
          $allow_edit_value2 = tep_db_prepare_input($_POST['allow_edit_value2']);
          $allow_tags = tep_db_prepare_input($_POST['allow_tags']);
          $sql_data_array = array('shop_info_key' => 'SHOP_INFO_OPTIONAL',
                                      'shop_info_title' => $shop_info_title,
                                      'shop_info_value' => $shop_info_value,
                                      'shop_info_value2' => $shop_info_value2,
                                      'shop_info_note' => $shop_info_note,
                                      'allow_edit_title' => $allow_edit_title,
                                      'allow_edit_value2' => $allow_edit_value2,
                                      'allow_tags' => $allow_tags,
                                      'shop_info_type' => 1,
                                      'date_added' =>  'now()');
          tep_db_perform(TABLE_SHOP_INFO, $sql_data_array);
          tep_redirect(tep_href_link(FILENAME_SHOP_INFO));
        }
        break;
      case 'update':
        // 文面の更新
        if (($_POST['edit_x']) || ($_POST['edit_y'])) {
          // プレビュー画面で戻るボタンを押されたとき
          $siID = $_POST['shop_info_id'];
          $shop_info = array();
          $shop_info['shop_info_title'] = $_POST['shop_info_title'];
          $shop_info['shop_info_value'] = $_POST['shop_info_value'];
          $shop_info['shop_info_value2'] = $_POST['shop_info_value2'];
          $shop_info['shop_info_note'] = $_POST['shop_info_note'];
          $shop_info['allow_edit_title'] = $_POST['allow_edit_title'];
          $shop_info['allow_edit_value2'] = $_POST['allow_edit_value2'];
          $shop_info['allow_tags'] = $_POST['allow_tags'];
          $shop_info['last_modified'] = $_POST['last_modified'];
          $siInfo = new objectInfo($shop_info);
          $_GET['action'] = 'edit_value';
        } else {
          $shop_info_id = $_POST['shop_info_id'];
          $shop_info_title = tep_db_prepare_input($_POST['shop_info_title']);
          $shop_info_value = tep_db_prepare_input($_POST['shop_info_value']);
          $shop_info_value2 = tep_db_prepare_input($_POST['shop_info_value2']);
          $allow_tags = tep_db_prepare_input($_POST['allow_tags']);
          $sql_data_array = array('shop_info_title' => $shop_info_title,
                                      'shop_info_value' => $shop_info_value,
                                      'shop_info_value2' => $shop_info_value2,
                                      'allow_tags' => $allow_tags,
                                      'last_modified' =>  'now()');
          tep_db_perform(TABLE_SHOP_INFO, $sql_data_array, 'update', 'shop_info_id = \'' . tep_db_input($shop_info_id) . '\'');
          tep_redirect(tep_href_link(FILENAME_SHOP_INFO));
        }
        break;
      case 'add_value':
        // 文面の登録画面
        $page_title = TEXT_ADD_SHOP_INFO;
        $siID = '';
        $shop_info = array();
        $shop_info['shop_info_title'] = '';
        $shop_info['shop_info_value'] = '';
        $shop_info['shop_info_value2'] = '';
        $shop_info['shop_info_note'] = TEXT_OPTIONAL_SHOP_INFO_NOTE;
        $shop_info['allow_edit_title'] = 1;
        $shop_info['allow_edit_value2'] = '';
        $shop_info['allow_tags'] = 0;
        $shop_info['last_modified'] = '';
        $siInfo = new objectInfo($shop_info);
        break;
      case 'edit_value':
        // 文面の編集画面
        $page_title = TEXT_EDIT_SHOP_INFO;
        $siID = ((get_magic_quotes_gpc()) ? stripslashes($_GET['siID']) : $_GET['siID']);
        $shop_info_query = tep_db_query("select shop_info_title, shop_info_key, shop_info_value, shop_info_value2, shop_info_note, allow_edit_title, allow_edit_value2, allow_tags, last_modified from " . TABLE_SHOP_INFO . " where shop_info_id = '" . tep_db_input($siID) . "'");
        $shop_info = tep_db_fetch_array($shop_info_query);
        $siInfo = new objectInfo($shop_info);
        break;
      case 'confirm':
        // 編集内容の確認
        $siID = $_POST['shop_info_id'];
        $shop_info = array();
        $shop_info['shop_info_title'] = $_POST['shop_info_title'];
        $shop_info['shop_info_value'] = $_POST['shop_info_value'];
        $shop_info['shop_info_value2'] = $_POST['shop_info_value2'];
        $shop_info['shop_info_value'] = str_replace("\r\n", "\r", $shop_info['shop_info_value']);
        $shop_info['shop_info_value'] = str_replace("\r", "\n", $shop_info['shop_info_value']);
        $shop_info['shop_info_value2'] = str_replace("\r\n", "\r", $shop_info['shop_info_value2']);
        $shop_info['shop_info_value2'] = str_replace("\r", "\n", $shop_info['shop_info_value2']);
        $shop_info['shop_info_note'] = $_POST['shop_info_note'];
        $shop_info['allow_edit_title'] = $_POST['allow_edit_title'];
        $shop_info['allow_edit_value2'] = $_POST['allow_edit_value2'];
        $shop_info['allow_tags'] = $_POST['allow_tags'];
        $shop_info['last_modified'] = $_POST['last_modified'];
        $siInfo = new objectInfo($shop_info);
        break;
      case 'delete_confirm':
        // 削除の確認
        $siID = $_GET['shop_info_id'];
        $shop_info_query = tep_db_query("select shop_info_title, shop_info_value, shop_info_value2, shop_info_note, allow_edit_title, allow_edit_value2, allow_tags, last_modified from " . TABLE_SHOP_INFO . " where shop_info_id = '" . tep_db_input($siID) . "'");
        $shop_info = tep_db_fetch_array($shop_info_query);
        $siInfo = new objectInfo($shop_info);
        break;
      case 'delete':
        // 削除の確認
        $siID = $_POST['shop_info_id'];
        tep_db_query("delete from " . TABLE_SHOP_INFO . " where shop_info_id = '" . tep_db_input($siID) . "'");
        tep_redirect(tep_href_link(FILENAME_SHOP_INFO));
        break;
    }
  } else {
    // 初期処理
    // 常設のお知らせ項目
    $shop_info_query = tep_db_query("select shop_info_id, shop_info_title, shop_info_note from " . TABLE_SHOP_INFO . " where shop_info_type < 2 and shop_info_key <> 'SHOP_INFO_OPTIONAL' order by shop_info_id");
    // 任意のお知らせ項目
    $shop_info2_query = tep_db_query("select shop_info_id, shop_info_title, shop_info_note from " . TABLE_SHOP_INFO . " where shop_info_key = 'SHOP_INFO_OPTIONAL' order by shop_info_id");
  }
?>
<!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']) {
    switch ($_GET['action']) {
      case 'add_value':
      case 'edit_value':
      // 編集画面
?>
    <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 $page_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="2" cellpadding="2" class="knBox">
          <tr>
            <td class="knMenu"><?php echo $siInfo->shop_info_note; ?></td>
          </tr>
          <tr>
            <td class="knMenu" align="right"><?php echo (($siInfo->last_modified) ? TEXT_LAST_MODIFIED . ' ' . $siInfo->last_modified : ''); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form('shop_info', FILENAME_SHOP_INFO, 'action=confirm') . tep_draw_hidden_field('shop_info_id', $siID); ?>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main" valign="top">
<?php
         if ($siInfo->allow_edit_title) {
           echo tep_draw_input_field('shop_info_title', $siInfo->shop_info_title, 'size="40"', '', false);
         } else {
           echo $siInfo->shop_info_title . tep_draw_hidden_field('shop_info_title', $siInfo->shop_info_title);
         }
?>
            </td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo tep_draw_textarea_field('shop_info_value', 'soft', '100%', '20', $siInfo->shop_info_value, '', false); ?></td>
          </tr>
<?php
         if ($siInfo->allow_edit_value2) {
?>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main"><?php echo tep_draw_textarea_field('shop_info_value2', 'soft', '100%', '20', $siInfo->shop_info_value2, '', false); ?></td>
          </tr>
<?php
         } else {
           echo tep_draw_hidden_field('shop_info_value2', $siInfo->shop_info_value2);
         }
?>
          <tr>
            <td class="main" align="right">
<?php
        switch ($siInfo->allow_tags) {
          case '0': $is_valid = false; $is_invalid = true; break;
          case '1':
          default: $is_valid = true; $is_invalid = false;
        }
        echo tep_draw_radio_field('allow_tags', '1', $is_valid) . TEXT_HTML_IS_VALID . '&nbsp;&nbsp;&nbsp;' . tep_draw_radio_field('allow_tags', '0', $is_invalid) . TEXT_HTML_IS_INVALID; 
?></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 ($siInfo->shop_info_key == 'SHOP_INFO_OPTIONAL') {
          echo '<a href="' . tep_href_link(FILENAME_SHOP_INFO, 'action=delete_confirm&shop_info_id=' . $siID) . '">' . tep_image_button('button_delete.gif', IMAGE_DELETE) . '</a>&nbsp;&nbsp;';
        }
        echo tep_draw_hidden_field('shop_info_note', $siInfo->shop_info_note) . tep_draw_hidden_field('allow_edit_title', $siInfo->allow_edit_title) . tep_draw_hidden_field('allow_edit_value2', $siInfo->allow_edit_value2) . tep_draw_hidden_field('last_modified', $siInfo->last_modified) . tep_image_submit('button_preview.gif', IMAGE_PREVIEW) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_SHOP_INFO) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
?></td>
          </tr>
        </table></td>
      </form></tr>
<?php
        break;
      case 'confirm':
      // 確認画面
      if ($siID) {
        $action = 'update';
      } else {
        $action = 'insert';
      }
?>
    <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_SHOP_INFO_PREVIEW; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><?php echo TEXT_UPDATE_CONFIRM_NOTE; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form('shop_info', FILENAME_SHOP_INFO, 'action=' . $action) . tep_draw_hidden_field('shop_info_id', $siID); ?>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><b>
<?php
         if ($siInfo->allow_tags) {
           echo  $siInfo->shop_info_title . tep_draw_hidden_field('shop_info_title', htmlspecialchars($siInfo->shop_info_title));
         } else {
           echo nl2br(htmlspecialchars($siInfo->shop_info_title)) . tep_draw_hidden_field('shop_info_title', htmlspecialchars($siInfo->shop_info_title));
         }
?></b></td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main">
<?php
         if ($siInfo->allow_tags) {
           echo  $siInfo->shop_info_value . tep_draw_hidden_field('shop_info_value', htmlspecialchars($siInfo->shop_info_value));
         } else {
           echo nl2br(htmlspecialchars($siInfo->shop_info_value)) . tep_draw_hidden_field('shop_info_value', htmlspecialchars($siInfo->shop_info_value));
         }
?>
            </td>
          </tr>
<?php
         if ($siInfo->allow_edit_value2) {
?>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main">
<?php
         if ($siInfo->allow_tags) {
           echo $siInfo->shop_info_value2 . tep_draw_hidden_field('shop_info_value2', htmlspecialchars($siInfo->shop_info_value2));
         } else {
           echo nl2br(htmlspecialchars($siInfo->shop_info_value2)) . tep_draw_hidden_field('shop_info_value2', htmlspecialchars($siInfo->shop_info_value2));
         }
?>
            </td>
          </tr>
<?php
         } else {
           echo tep_draw_hidden_field('shop_info_value2', htmlspecialchars($siInfo->shop_info_value2));
         }
?>
        </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 echo tep_draw_hidden_field('shop_info_note', $siInfo->shop_info_note) . tep_draw_hidden_field('allow_edit_title', $siInfo->allow_edit_title) . tep_draw_hidden_field('allow_edit_value2', $siInfo->allow_edit_value2) . tep_draw_hidden_field('allow_tags', $siInfo->allow_tags) . tep_draw_hidden_field('last_modified', $siInfo->last_modified) . tep_image_submit('button_save.gif', IMAGE_SAVE) . ' ' . tep_image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . ' <a href="' . tep_href_link(FILENAME_SHOP_INFO) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>'; ?></td>
          </tr>
        </table></td>
      </form></tr>
<?php
        break;
      case '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_DELETE_SHOP_INFO_CONFIRM; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr>
        <td><?php echo TEXT_DELETE_CONFIRM_NOTE; ?></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
      <tr><?php echo tep_draw_form('shop_info', FILENAME_SHOP_INFO, 'action=delete') . tep_draw_hidden_field('shop_info_id', $siID); ?>
        <td><table border="0" cellspacing="0" cellpadding="2">
          <tr>
            <td class="main"><b>
<?php
         if ($siInfo->allow_tags) {
           echo  $siInfo->shop_info_title;
         } else {
           echo nl2br(htmlspecialchars($siInfo->shop_info_title));
         }
?></b></td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main">
<?php
         if ($siInfo->allow_tags) {
           echo  $siInfo->shop_info_value;
         } else {
           echo nl2br(htmlspecialchars($siInfo->shop_info_value));
         }
?>
            </td>
          </tr>
<?php
         if ($siInfo->allow_edit_value2) {
?>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
          <tr>
            <td class="main">
<?php
         if ($siInfo->allow_tags) {
           echo $siInfo->shop_info_value2;
         } else {
           echo nl2br(htmlspecialchars($siInfo->shop_info_value2));
         }
?>
            </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 echo tep_image_submit('button_delete.gif', IMAGE_DELETE) . ' <a href="' . tep_href_link(FILENAME_SHOP_INFO) . '">' . 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 HEADING_TITLE; ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td align="center"><table border="0" width="100%" cellspacing="0" cellpadding="0" class="knBox">
        <tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '5'); ?></td></tr>
        <tr><td width="50%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td colspan="2"><?php echo TEXT_STANDING_SHOP_INFO; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<?php
    while($shop_info = tep_db_fetch_array($shop_info_query)) {
      $siInfo = new objectInfo($shop_info);
?>
          <tr>
            <td valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_SHOP_INFO, 'action=edit_value&siID=' . $siInfo->shop_info_id) . '" class="knMenu"><b>' . $siInfo->shop_info_title . '</b></a>'; ?></td>
            <td class="knMenu"><?php echo $siInfo->shop_info_note; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<?php
    }
?>
        </table></td>
        <td width="50%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td colspan="2"><?php echo TEXT_OPTIONAL_SHOP_INFO; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<?php
    while($shop_info2 = tep_db_fetch_array($shop_info2_query)) {
      $siInfo2 = new objectInfo($shop_info2);
?>
          <tr>
            <td valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_SHOP_INFO, 'action=edit_value&siID=' . $siInfo2->shop_info_id) . '" class="knMenu"><b>' . $siInfo2->shop_info_title . '</b></a>'; ?></td>
            <td class="knMenu"><?php echo $siInfo2->shop_info_note; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
<?php
    }
?>
          <tr>
            <td valign="top">&nbsp;</td>
            <td class="knMenu"><?php echo '<a href="' . tep_href_link(FILENAME_SHOP_INFO, 'action=add_value') . '" class="knMenu">' . tep_image_button('button_insert.gif', IMAGE_INSERT) . '</a>'; ?></td>
          </tr>
          <tr>
            <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
          </tr>
        </table></td></tr>
        </table></td>
      </tr>
<?php
  }
?>
    </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'); ?>