<?php
/*
  moneyorder2.php
  作成日：2004/11/1
　最終更新日：

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

  Released under the GNU General Public License
  
  moneyorder（銀行振込み）をmoneyorder2（郵便振替）にしたもの
*/

  class moneyorder2 {
    var $code, $title, $description, $enabled;

// class constructor
    function moneyorder2() {
      global $order;

      $this->code = 'moneyorder2';
      $this->title = MODULE_PAYMENT_MONEYORDER2_TEXT_TITLE;
      $this->description = MODULE_PAYMENT_MONEYORDER2_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_PAYMENT_MONEYORDER2_SORT_ORDER;
      $this->enabled = ((MODULE_PAYMENT_MONEYORDER2_STATUS == 'True') ? true : false);

      if ((int)MODULE_PAYMENT_MONEYORDER2_ORDER_STATUS_ID > 0) {
        $this->order_status = MODULE_PAYMENT_MONEYORDER2_ORDER_STATUS_ID;
      }

      if (is_object($order)) $this->update_status();
    
      $this->email_footer = MODULE_PAYMENT_MONEYORDER2_TEXT_EMAIL_FOOTER;
    }

// class methods
    function update_status() {
      global $order;

      if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_MONEYORDER2_ZONE > 0) ) {
        $check_flag = false;
        $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_MONEYORDER2_ZONE . "' and zone_country_id = '" . (int)$order->billing['country']['id'] . "' order by zone_id");
        while ($check = tep_db_fetch_array($check_query)) {
          if ($check['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check['zone_id'] == $order->billing['zone_id']) {
            $check_flag = true;
            break;
          }
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }
    }

    function javascript_validation() {
      return false;
    }

    function selection() {
      return array('id' => $this->code,
                   'module' => $this->title,
                   'fields' => array(array('title' => nl2br(MODULE_PAYMENT_MONEYORDER2_TEXT_PROCESS), 'field' => '')));
    }

    function pre_confirmation_check() {
      return false;
    }

    function confirmation() {
      return array('title' => nl2br(MODULE_PAYMENT_MONEYORDER2_TEXT_PROCESS));
    }

    function process_button() {
      return false;
    }

    function before_process() {
      return false;
    }

    function after_process() {
      return false;
    }

    function get_error() {
      return false;
    }

    function check() {
      if (!isset($this->_check)) {
        $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_MONEYORDER2_STATUS'");
        $this->_check = tep_db_num_rows($check_query);
      }
      return $this->_check;
    }

    function install() {
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('支払い方法', 'MODULE_PAYMENT_MONEYORDER2_TEXT_TITLE', '郵便振替', '支払い方法の名前', '6', '11' , now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('郵便振替を有効にする', 'MODULE_PAYMENT_MONEYORDER2_STATUS', 'True', '郵便振替による支払いを受け付けますか?', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now());");
//      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('お振替先:', 'MODULE_PAYMENT_MONEYORDER2_PAYTO', '', 'お振替先名義を設定してください.', '6', '1', now());");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('表示の整列順', 'MODULE_PAYMENT_MONEYORDER2_SORT_ORDER', '0', '表示の整列順を設定できます。数字が小さいほど上位に表示されます.', '6', '0', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('適用地域', 'MODULE_PAYMENT_MONEYORDER2_ZONE', '0', '適用地域を選択すると、選択した地域のみで利用可能となります.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('初期注文ステータス', 'MODULE_PAYMENT_MONEYORDER2_ORDER_STATUS_ID', '0', '設定したステータスが受注時に適用されます.', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('支払い方法選択時の注釈', 'MODULE_PAYMENT_MONEYORDER2_TEXT_PROCESS', '送金先:\n00000-0-000000 ○○○○\n恐れ入りますが、送金手数料はご負担ください。', 'レジの支払い方法選択画面で表示する注釈です。', '6', '12' , 'tep_cfg_textarea(', now())");
      tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('メールへの注釈', 'MODULE_PAYMENT_MONEYORDER2_TEXT_EMAIL_FOOTER', '送金先:\n00000-0-000000 ○○○○\n\n恐れ入りますが、送金手数料はご負担ください。', '注文確認メールに追記する文面です。', '6', '13', 'tep_cfg_textarea(', now())");
    }

    function remove() {
      tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
      return array('MODULE_PAYMENT_MONEYORDER2_TEXT_TITLE', 'MODULE_PAYMENT_MONEYORDER2_STATUS', 'MODULE_PAYMENT_MONEYORDER2_ZONE', 'MODULE_PAYMENT_MONEYORDER2_ORDER_STATUS_ID', 'MODULE_PAYMENT_MONEYORDER2_SORT_ORDER', 'MODULE_PAYMENT_MONEYORDER2_TEXT_PROCESS', 'MODULE_PAYMENT_MONEYORDER2_TEXT_EMAIL_FOOTER');
    }
  }
?>
