<?php
/*

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

  Copyright (c) 2003 osCommerce
  
  

  Released under the GNU General Public License
  
  Freeway eCommerce from ZacWare
  http://www.openfreeway.org

Copyright 2007 ZacWare Pty. Ltd
Released under the GNU General Public License
*/
 // 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,$FSESSION;
	  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 . $FSESSION->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,$order_id,$customer_name) {
	    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,$order_id,$customer_name);
        }
      }
    }
//italy new functions, return false if not found to retain backward compatability with existing sms modules
	function send_order_success(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && method_exists($GLOBALS[$this->selected_module], 'send_order_success') && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->send_order_success();
        }else{
			return false;}
      }
	}
		function create_sms_text(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && method_exists($GLOBALS[$this->selected_module], 'create_sms_text') && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->create_sms_text();
        }else{
			return false;}
      }
	}
	
	function send_order_reminder(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && method_exists($GLOBALS[$this->selected_module], 'send_order_reminder') && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->send_order_reminder();
        }else{
			return false;}
      }
	}	
	function send_order_extension(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && method_exists($GLOBALS[$this->selected_module], 'send_order_extension') && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->send_order_extension();
        }else{
			return false;}
      }
	}	
	function send_order_expired(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && method_exists($GLOBALS[$this->selected_module], 'send_order_expired') && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->send_order_expired();
        }else{
			return false;}
      }
	}
	function get_sent_messages(){
      if (is_array($this->modules)) {
        if (is_object($GLOBALS[$this->selected_module]) && method_exists($GLOBALS[$this->selected_module], 'get_sent_messages') && ($GLOBALS[$this->selected_module]->enabled) ) {
          return $GLOBALS[$this->selected_module]->get_sent_messages();
        }else{
			return false;}
      }
	}
	
  }
?>