Ruairi - 2007-11-23

Hi,
  Works well for me....This adds 2 new functions.

    $my_batch = $mysms->start_batch ($from, $_msg);
which sets up the message template and returns a batch id, and
    $sms_results =  $mysms->quicksend_batch ($my_batch, $sms_numbers);
where $sms_numbers is a comma delimited list of numbers to send the message to... 

I use an sql query / loop to build the sms_numbers string...  it should be trivial for someone to add support for individualized  messages which is supported by the clickatell api...  (in fairness this patch is fairly trivial also...)

Ruairi

--- /usr/share/php5/sms_api.php-original        2007-11-16 16:49:32.000000000 +0000
+++ /usr/share/php5/sms_api.php 2007-11-22 17:02:12.000000000 +0000
@@ -124,9 +124,11 @@
     function sms () {
         if ($this->use_ssl) {
             $this->base   = "http://api.clickatell.com/http";
+            $this->base_batch  = "http://api.clickatell.com/http_batch";
             $this->base_s = "https://api.clickatell.com/http";
         } else {
             $this->base   = "http://api.clickatell.com/http";
+            $this->base_batch = "http://api.clickatell.com/http_batch";
             $this->base_s = $this->base;
         }

@@ -218,6 +220,108 @@
         return $this->_parse_send ($this->_execgw($comm));
     }

+
+    /**
+    * Start SMS batch message
+    * @param to mixed  The destination address.
+    * @param from mixed  The source/sender address
+    * @param text mixed  The text content of the message
+    * @return mixed  "OK" or script die
+    * @access public
+    */
+    function start_batch($from=null, $text=null) {
+
+       /* Check SMS credits balance */
+       if ($this->getbalance() < $this->balace_limit) {
+           die ("You have reach the SMS credit limit!");
+       };
+
+       /* Check SMS $text length */
+        if ($this->unicode == true) {
+            $this->_chk_mbstring();
+            if (mb_strlen ($text) > 210) {
+                   die ("Your unicode message is too long! (Current lenght=".mb_strlen ($text).")");
+               }
+               /* Does message need to be concatenate */
+            if (mb_strlen ($text) > 70) {
+                $concat = "&concat=3";
+               } else {
+                $concat = "";
+            }
+        } else {
+            if (strlen ($text) > 459) {
+               die ("Your message is too long! (Current lenght=".strlen ($text).")");
+           }
+               /* Does message need to be concatenate */
+            if (strlen ($text) > 160) {
+                $concat = "&concat=3";
+               } else {
+                $concat = "";
+            }
+        }
+
+       /* Check $from is not empty */
+        if (empty ($from)) {
+           die ("You not specify source address (FROM)!");
+       }
+
+       /* Send SMS now */
+       $comm = sprintf ("%s/startbatch?session_id=%s&from=%s&callback=%s&unicode=%s%s&template=%s",
+            $this->base_batch,
+            $this->session,
+            rawurlencode($from),
+            $this->callback,
+            $this->unicode,
+            $concat,
+            $this->encode_message($text)
+        );
+        return $this->_parse_batch ($this->_execgw($comm));
+    }
+
+
+
+    /**
+    * QuickSend SMS batch message
+    * @param to mixed  The destination address.
+    * @param from mixed  The source/sender address
+    * @param text mixed  The text content of the message
+    * @return mixed  "OK" or script die
+    * @access public
+    */
+    function quicksend_batch($batch_id=null, $to=null) {
+        /* Check $to and $from is not empty */
+        if (empty ($to)) {
+            die ("You did not specify destination address (TO)!");
+        }
+        if (empty ($batch_id)) {
+            die ("You not specify a batch ID !");
+        }
+
+        /* Reformat $to number */
+        $cleanup_chr = array ("+", " ", "(", ")", "\r", "\n", "\r\n");
+        $to = str_replace($cleanup_chr, "", $to);
+
+       /* Check SMS credits balance */
+       if ($this->getbalance() < $this->balace_limit) {
+           die ("You have reach the SMS credit limit!");
+       };
+
+       /* Check $to is not empty */
+        if (empty ($to)) {
+           die ("You not specify destination address (TO)!");
+       }
+
+       /* Send SMS now */
+       $comm = sprintf ("%s/quicksend?session_id=%s&batch_id=%s&to=%s",
+            $this->base_batch,
+            $this->session,
+            $batch_id,
+            $to
+        );
+        return $this->_parse_send ($this->_execgw($comm));
+    }
+
+
     /**
     * Encode message text according to required standard
     * @param text mixed  Input text of message.
@@ -344,6 +448,21 @@
         return $session;
     }

+
+    /**
+    * Parse batch start command response text
+    * @access private
+    */
+    function _parse_batch ($result) {
+       $batch = substr($result, 4);
+        $code = substr($result, 0, 2);
+        if ($code!="ID") {
+            die ("Error in SMS batch setup! ($result)");
+        }
+        return $batch;
+    }
+
+
     /**
     * Parse send command response text
     * @access private