<?php
/*
###################################################################################
  Bigware Shop 2.3
  Release Datum: 23.08.2015
  
  Bigware Shop
  http://www.bigware.de

  Copyright (c) 2015 Bigware LTD
  (c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
  (c) 2015	Bigware LTD

  Copyrightvermerke duerfen nicht entfernt werden.
  ------------------------------------------------------------------------
  Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
  der GNU General Public License, wie von der Free Software Foundation
  veroeffentlicht, weitergeben und/oder modifizieren, entweder gemaess Version 2 
  der Lizenz oder (nach Ihrer Option) jeder spaeteren Version.
  Die Veroeffentlichung dieses Programms erfolgt in der Hoffnung, dass es Ihnen
  von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne die
  implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FUER EINEN
  BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.
  
  Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
  Programm erhalten haben. Falls nicht, schreiben Sie an die Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

  Infos:
  ------------------------------------------------------------------------
  Der Bigware Shop wurde vor vielen Jahren bereits aus dem bekannten Shopsystem osCommerce
  weiter- und neuentwickelt.
  Der Bigware Shop legt im hohen Masse Wert auf Bedienerfreundlichkeit, beinhaltet eine leichte
  Installation, viele neue professionelle Werkzeuge und zeichnet sich aus durch eine grosse 
  Community, die bei Problemen weiterhelfen kann.
  
  Der Bigware Shop ist auf jedem System lauffaehig, welches eine PHP Umgebung
  (ab PHP 4.1.3) und mySQL zur Verfuegung stellt und auf Linux basiert.
 
  Hilfe erhalten Sie im Forum auf www.bigware.de 
  
  -----------------------------------------------------------------------
  
 ##################################################################################




*/
?>
<?php


  class worldpay {
    var $code, $title, $description, $enabled, $get_variables;

// class constructor
    function worldpay() {
      $this->code = 'worldpay';
      $this->title = MODULE_PAYMENT_WORLDPAY_TEXT_TITLE;
      $this->description = MODULE_PAYMENT_WORLDPAY_TEXT_DESCRIPTION;
			$this->sort_order = MODULE_PAYMENT_WORLDPAY_SORT_ORDER;
			$this->enabled = ((MODULE_PAYMENT_WORLDPAY_STATUS == 'True') ? true : false);
      $this->form_action_url = 'https://select.worldpay.com/wcc/purchase';
      $this->email_footer = MODULE_PAYMENT_WORLDPAY_TEXT_EMAIL_FOOTER;
    }

// class methods
    function javascript_validation() {
      return false;
    }

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

    function pre_confirmation_check() {
      return false;
    }

    function confirmation() {
      return false;
    }

    function process_button() {
      global $_POST, $shipping_cost, $total_cost, $shipping_selected, $shipping_method, $currencies, $currency, $attendee_id , $order;

			
	if(!function_exists('http_build_query')) {
   function http_build_query( $formdata, $numeric_prefix = null, $key = null ) {
       $res = array();
       foreach ((array)$formdata as $k=>$v) {
           $tmp_key = urlencode(is_int($k) ? $numeric_prefix.$k : $k);
           if ($key) $tmp_key = $key.'['.$tmp_key.']';
           if ( is_array($v) || is_object($v) ) {
               $res[] = http_build_query($v, null /* or $numeric_prefix if you want to add numeric_prefix to all indexes in array*/, $tmp_key);
           } else {
               $res[] = $tmp_key."=".urlencode($v);
           }
           /*
           If you want, you can write this as one string:
           $res[] = ( ( is_array($v) || is_object($v) ) ? http_build_query($v, null, $tmp_key) : $tmp_key."=".urlencode($v) );
           */
       }
       $separator = ini_get('arg_separator.output');
       return implode($separator, $res);
   }
}
		
      $worldpay_fail = go_session_name() . '=' . go_session_id() . '&shipping_selected=' . $shipping_selected;
	    $worldpay_success = go_session_name() . '=' . go_session_id() . '&shipping_selected=' . $shipping_selected . '&shipping_cost=' . $shipping_cost . '&shipping_method=' . urlencode($shipping_method);

			/*echo number_format($order->info['total'],2,'.','');
			echo "<br>".$currencies->format($order->info['total']);*/
			$cur_amount =  number_format($order->info['total'] * $currencies->get_value($currency), $currencies->get_decimal_places($currency));
			
    $process_button_string = 
													 	go_fetch_hidden_field('instId', MODULE_PAYMENT_WORLDPAY_ID) .
														go_fetch_hidden_field('cartId', SHOP_NAME.' : '.$order->attendee['firstname'].' '.$order->attendee['lastname']) .
														go_fetch_hidden_field('amount', $cur_amount).
														go_fetch_hidden_field('currency', $currency) .
														go_fetch_hidden_field('desc', 'Purchase from '.SHOP_NAME) ;
		$this->get_variables = http_build_query(array('instId'=> MODULE_PAYMENT_WORLDPAY_ID,'cartId' => SHOP_NAME.' : '.$order->attendee['firstname'].' '.$order->attendee['lastname'],'amount'=> $cur_amount,'currency'=> $currency,'desc'=> 'Purchase from '.SHOP_NAME));
		//$this->get_variables = 'instId='.MODULE_PAYMENT_WORLDPAY_ID.'&cartId='.SHOP_NAME.' : '.$order->attendee['firstname'].' '.$order->attendee['lastname'].'&amount='.number_format($order->info['total'],2,'.','').'&currency='.$currency.'&desc='.'Purchase from '.SHOP_NAME;
		
// Begin Optional Fields
// The Following lines check if you want to use PreAuth (Check WorldPay for details).  This setting is specified in Admin.  If PreAuth is on, it adds the required fields, otherwise these lines get ignored.
 	if (MODULE_PAYMENT_WORLDPAY_USEPREAUTH == 'True')  {
	 $process_button_string .= go_fetch_hidden_field('authMode', MODULE_PAYMENT_WORLDPAY_PREAUTH);
	 $this->get_variables .= '&authMode='.MODULE_PAYMENT_WORLDPAY_PREAUTH;
	 }				
	if (MODULE_PAYMENT_WORLDPAY_USEPREAUTH == 'True') {
	 $process_button_string .= go_fetch_hidden_field(MODULE_PAYMENT_WORLDPAY_PREAUTHACCID, MODULE_PAYMENT_WORLDPAY_PREAUTHID);
	 $this->get_variables .= '&'.MODULE_PAYMENT_WORLDPAY_PREAUTHACCID.'='.MODULE_PAYMENT_WORLDPAY_PREAUTHID;
	}			
	//$address = isohtmlspecialchars($order->attendee['street_address'] . '&#10;' . $order->attendee['suburb'] . '&#10;' . $order->attendee['city'] . '&#10;' . $order->attendee['state'], ENT_QUOTES);
	$address = $order->attendee['street_address'] . ', ' . $order->attendee['suburb'] . ', ' . $order->attendee['city'] . ', ' . $order->attendee['state'];

	$process_button_string .=	
	go_fetch_hidden_field('testMode', MODULE_PAYMENT_WORLDPAY_MODE) .
	go_fetch_hidden_field('name', $order->attendee['firstname'] . ' ' . $order->attendee['lastname']) .
	go_fetch_hidden_field('address', $address) .
	go_fetch_hidden_field('postcode', $order->attendee['postcode']) .
	go_fetch_hidden_field('country', $order->attendee['country']['iso_code_2']) .
	go_fetch_hidden_field('tel', $order->attendee['telephone']) .
  go_fetch_hidden_field('fax', $order->attendee['fax']) .
	go_fetch_hidden_field('email', $order->attendee['email_address']) .
	go_fetch_hidden_field(go_session_name(), go_session_id());
	
	
	

	$data1 = array('testMode'=> MODULE_PAYMENT_WORLDPAY_MODE,'name'=> $order->attendee['firstname'] . ' ' . $order->attendee['lastname'],'address'=> $address,'postcode'=> $order->attendee['postcode'],'country'=> $order->attendee['country']['iso_code_2'],'tel'=> $order->attendee['telephone'],'fax'=> $order->attendee['fax'],'email'=> $order->attendee['email_address']);
	$this->get_variables .= '&'.http_build_query($data1);
	//echo $this->get_variables;
	//$this->get_variables .= '&testMode='.MODULE_PAYMENT_WORLDPAY_MODE.'&name='.$order->attendee['firstname'] . ' ' . $order->attendee['lastname'].'&address='.$address.'&postcode='.$order->attendee['postcode'].'&country='.$order->attendee['country']['iso_code_2'].'&tel='.$order->attendee['telephone'].'&fax='.$order->attendee['fax'].'&email='.$order->attendee['email_address'];
    return $process_button_string;
    }

  function before_process() {
	 return false;
      /*global $_POST;
      if ($_POST['transStatus'] != 'Y') {
        tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(MODULE_PAYMENT_WORLDPAY_TEXT_ERROR_MESSAGE), 'SSL', true, false));
      }*/
    }

    function after_process() {
      return false;
    }

    function output_error() {
      return false;
    }
	
	function check() {
      if (!isset($this->_check)) {
        $check_query = go_db_query("select set_it_up_value from " . DB_TBL_SET_IT_UP . " where set_it_up_key = 'MODULE_PAYMENT_WORLDPAY_STATUS'");
        $this->_check = go_db_num_rows($check_query);
      }
      return $this->_check;
    }
    function install() {

			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_STATUS_TITEL', 'MODULE_PAYMENT_WORLDPAY_STATUS', 'True', 'MODULE_PAYMENT_WORLDPAY_STATUS_DESCRIPTION', '6', '1', '', 'go_cfg_select_option(array(\'True\', \'False\'),', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_ID_TITEL', 'MODULE_PAYMENT_WORLDPAY_ID', '00000', 'MODULE_PAYMENT_WORLDPAY_ID_DESCRIPTION', '6', '2', '', '', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_MODE_TITEL', 'MODULE_PAYMENT_WORLDPAY_MODE', '100', 'MODULE_PAYMENT_WORLDPAY_MODE_DESCRIPTION', '6', '3', '', '', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_USEPREAUTH_TITEL', 'MODULE_PAYMENT_WORLDPAY_USEPREAUTH', 'False', 'MODULE_PAYMENT_WORLDPAY_USEPREAUTH_DESCRIPTION', '6', '4', '', 'go_cfg_select_option(array(\'True\', \'False\'),', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_PREAUTH_TITEL', 'MODULE_PAYMENT_WORLDPAY_PREAUTH', 'A', 'MODULE_PAYMENT_WORLDPAY_PREAUTH_DESCRIPTION', '6', '5', '', '', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_PREAUTHID_TITEL', 'MODULE_PAYMENT_WORLDPAY_PREAUTHID', '000000', 'MODULE_PAYMENT_WORLDPAY_PREAUTHID_DESCRIPTION', '6', '6', '', '', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_PREAUTHACCID_TITEL', 'MODULE_PAYMENT_WORLDPAY_PREAUTHACCID', 'accId1', 'MODULE_PAYMENT_WORLDPAY_PREAUTHACCID_DESCRIPTION', '6', '7', '', '', now())");
			go_db_query("insert into " . DB_TBL_SET_IT_UP . " (set_it_up_title, set_it_up_key, set_it_up_value, set_it_up_description, set_it_up_group_id, sort_order, use_function, set_function, date_added) values ('MODULE_PAYMENT_WORLDPAY_SORT_ORDER_TITEL', 'MODULE_PAYMENT_WORLDPAY_SORT_ORDER', '0', 'MODULE_PAYMENT_WORLDPAY_SORT_ORDER_DESCRIPTION', '6', '0', '', '', now())");


	  }

    function remove() {
      go_db_query("delete from " . DB_TBL_SET_IT_UP . " where set_it_up_key in ('" . implode("', '", $this->keys()) . "')");
    }

    function keys() {
  		return array('MODULE_PAYMENT_WORLDPAY_STATUS', 'MODULE_PAYMENT_WORLDPAY_ID','MODULE_PAYMENT_WORLDPAY_MODE', 'MODULE_PAYMENT_WORLDPAY_USEPREAUTH', 'MODULE_PAYMENT_WORLDPAY_PREAUTH','MODULE_PAYMENT_WORLDPAY_PREAUTHID','MODULE_PAYMENT_WORLDPAY_PREAUTHACCID','MODULE_PAYMENT_WORLDPAY_SORT_ORDER');
    }
  }
?>
