<?php
/*

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce
  
  osCommRes, Services Online
  http://www.oscommres.com

  Copyright (c) 2005 osCommRes

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
http://www.zac-ware.com/freeway

Copyright 2007 ZacWare Pty. Ltd
*/
 // Check to ensure this file is included in Freeway!
defined('_FEXEC') or die(); 

if (class_exists("sms")) return;
  class sms {
    var $modules, $selected_module;

// class constructor
    function sms($module = '') {
      global $sms,$language, $PHP_SELF;
	  if (defined('MODULE_SMS_GATEWAYS_INSTALLED') && tep_not_null(MODULE_SMS_GATEWAYS_INSTALLED)) {
        $this->modules = explode(';', MODULE_SMS_GATEWAYS_INSTALLED);
        $include_modules = array();

        if ( (tep_not_null($module)) && (in_array($module . '.' . substr($PHP_SELF, (strrpos($PHP_SELF, '.')+1)), $this->modules)) ) {
          $this->selected_module = $module;
          $include_modules[] = array('class' => $module, 'file' => $module . '.php');
        } else {
			reset($this->modules);
			// All Other sms Modules
			while (list(, $value) = each($this->modules)) {
				$class = substr($value, 0, strrpos($value, '.'));
				$include_modules[] = array('class' => $class, 'file' => $value);
			}
		}
		for ($i=0, $n=sizeof($include_modules); $i<$n; $i++) {
			include(DIR_WS_LANGUAGES . $language . '/modules/sms/' . $include_modules[$i]['file']);
			include(DIR_WS_MODULES . 'sms/' . $include_modules[$i]['file']);
			
			$GLOBALS[$include_modules[$i]['class']] = new $include_modules[$i]['class'];
		}

	}
}
    function connecthost() { 
      if (is_array($this->modules)) { 
        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
		  return $GLOBALS[$this->selected_module]->connecthost();
        }
      }
    }

    function get_failed_messages() {
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->get_failed_messages();
        }
      }
    }
	function set_option($name,$value){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->set_option($name,$value);
        }
      }
	}
	function get_error(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->get_error();
        }
      }
	}

    function send_sms($to,$from,$contents,$country) {
	    if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->send_sms($to,$from,$contents,$country);
        }
      }
    }

  }
?>