Can someone please take a look at this and tell me where I'm going wrong. I'm trying to create a custom module to send sms using Clickatell and I've added a logic hook on before_save to add the code for sending the message before saving so that I can save the message id from the sms gateway. The Problem is it seems to skip the part for sending the sms and retrieving response from sms gateway. The is the the logic hook I'm trying to fire:
logic_hooks.php
SendSMS.phpCode:<?php $hook_version = 1; $hook_array = Array(); // position, file, class, function $hook_array['before_save'] = Array(); $hook_array['before_save'][] = Array(1, 'before_save', 'custom/modules/sms/SendSMS.php','SendSMS', 'SendSMS'); ?>
and the settings.phpCode:<?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); require_once('data/SugarBean.php'); require_once('modules/sms/sms.php'); require_once('include/utils.php'); require_once('custom/modules/sms/settings.php'); class SendSMS { function GetSQLValueString($theValue) { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; return $theValue; } function SendSMS(&$bean, $event, $arguments){ $sender = 'GEP'; $parent = $bean->parent_id; $message = $bean->sms_msg; if ($bean->cell_no != '') { $to = $bean->cell_no; } else if ($bean->parent_type == 'Leads') { $query = 'SELECT phone_mobile from leads where id = $parent'; } elseif ($bean->parent_type == 'Contacts') { $query = 'SELECT phone_mobile from contacts where id = $parent'; } elseif ($bean->parent_type == 'Accounts') { $query = 'SELECT phone_alternate as phone_mobile from accounts where id = $parent'; } elseif ($bean->parent_type == 'sp_ServiceProvider') { $query = 'SELECT phone_alternate as phone_mobile from sp_serviceprovider where id = $parent'; } $result = $GLOBALS['db']->query($query); $row = $GLOBALS['db']->fetchByAssoc($result); if($row != null) { $to = $row_result['phone_mobile']; } //get magic quotes $message = GetSQLValueString($message); //url encode message $message = urlencode($message); //authenticating user $url = "$baseurl/http/auth?user=$user&password=$password&api_id=$api_id&from=$from&concat=2"; $ret = file($url); // split our response. return string is on first line of the data returned $sess = split(":",$ret[0]); if ($sess[0] == "OK") { $sess_id = trim($sess[1]); // remove any whitespace // url for sending message $url = "$baseurl/http/sendmsg?session_id=$sess_id&to=$to&text=$message&from=$from&callback=3&deliv_ack=1&concat=2"; // send message $ret = file($url); $send = split(":",$ret[0]); if ($send[0] == "ID"){ // apimsgid $apimsgid = trim($send[1]); // insert message with its corresponding apimsgid into the table $bean->apimsgid = $apimsgid; $bean->status = 'sent'; } else $bean->apimsgid = $apimsgid; $bean->status = 'failed'; } } } ?>
Please helpCode:<?php $baseurl ="http://api.clickatell.com"; //User details @ CLickatell $user = "xyz"; $password = "password"; $api_id = "xxxxxx"; ?>


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks