<?php 
 
class SendSimpleSMS {
 
    
 
    private static $REQUEST_URL = "http://www.afilnet.com/http/sms/?email={EMAIL}&pass={PASSWORD}&mobile={MOBILE_TARGET}&id={SENDER}&country={COUNTRY_PREFIX}&sms={SMS}";
 
 
    private $message;
 
    private $credentials;
 
    private $params;
 
    
 
    public function __construct() {
 
        $params = func_get_args();
 
        $num_params = func_num_args();
 
        if($num_params == 2) {
 
            call_user_func_array(array($this, "__construct_credentials"), $params);
 
        } else if($num_params == 6) {
 
            call_user_func_array(array($this, "__construct_credentials_params"), $params);
 
        }
 
    }
 
    
 
    private function __construct_credentials($email, $password) {
 
        $this->credentials = array("email" => $email, "password" => $password);
 
    }
 
    
 
    private function __construct_credentials_params($email, $password, $mobile_target, $sender, $country_prefix, $sms) {
 
        $this->credentials = array("email" => $email, "password" => $password);
 
        $this->params = array("mobile_target" => $mobile_target, "sender" => $sender, "country_prefix" => $country_prefix, "sms" => $sms);
 
    }
 
    
 
    public function send() {
 
        $search = array("{EMAIL}", "{PASSWORD}", "{MOBILE_TARGET}", "{SENDER}", "{COUNTRY_PREFIX}", "{SMS}");
 
        $replace = array($this->credentials['email'], $this->credentials['password'], $this->params['mobile_target'], urlencode($this->params['sender']), $this->params['country_prefix'], urlencode($this->params['sms']));
 
        $url = str_replace($search, $replace, self::$REQUEST_URL);
 
        
 
        $response = file_get_contents($url);
 
        if($response) { 
 
            switch($response) { 
 
                case "OK": 
 
                    $this->message = "SMS sent successfully";  
 
                    return true;
 
                case "-1":  
 
                    $this->message = "Error in login, email or password is wrong"; 
 
                    break; 
 
                default:  
 
                    $this->message = "You have no credits for sending"; 
 
            } 
 
        } else { 
 
            $this->message = "Error in request. Check parameters"; 
 
        } 
 
        return false;
 
    }
 
    
 
    public function setCredentials($email, $password) {
 
        $this->credentials = array("email" => $email, "password" => $password);
 
    }
 
    
 
    public function getEmail() {
 
        return $this->credentials["email"];
 
    }
 
    
 
    public function setParams($mobile_target, $sender, $country_prefix, $sms) {
 
        $this->params = array("mobile_target" => $mobile_target, "sender" => $sender, "country_prefix" => $country_prefix, "sms" => $sms);
 
    }
 
    
 
    public function setMobileTarget($mobile_target) {
 
        $this->params["mobile_target"] = $mobile_target;
 
    }
 
    
 
    public function setSender($sender) {
 
        $this->params["sender"] = $sender;
 
    }
 
    
 
    public function setCountryPrefix($country_prefix) {
 
        $this->params["country_prefix"] = $country_prefix;
 
    }
 
    
 
    public function setSMS($sms) {
 
        $this->params["sms"] = $sms;
 
    }
 
    
 
    public function getSendingParams() {
 
        return $this->params;
 
    }
 
    
 
    public function getReturnMessage() {
 
        return $this->message;
 
    }
 
}
 
?>
 
 |