Hi
I was wondering if it was possible for someone to help me utilise the sms gateway module. I think that once I get an example going I'd be okay.

The first thing I wanted to look at was storing members telephone numbers so I looked at profile.module and created a new field called profile_mobile that holds the number.

Then I looked at the remindme.module and the bit that sends out the email is here:

function remindme_mail($node) {
  $from = variable_get('site_mail', ini_get('sendmail_from'));
  $subject = strtr(t('Reminder for %title'), array ('%title' => $node->title));
  $to = "$node->name <". $node->mail .'>';
    $body = strtr(t("Greetings %name,\n\nYou wanted to get a reminder for the event %title. It starts at %time, you can see more details at %url , thanks for using the Walkers Talk Remind Me service.") , array('%name' => $node->name, '%title' => $node->title, '%time' => format_date($node->event_start, 'medium'), '%url' => url("node/$node->nid", NULL, NULL, 1))) ;

  return user_mail($to, $subject, $body, "From: $from\nReply-to: $from\nX-Mailer: Drupal (remindme.module)\nReturn-path: <$from>\nErrors-to: $from\n");
}

I know what I want to do but I'm stuck at the implementation bit! I'd like a shorter message to be sent out to the members mobile, I think this is identified by this bit: $to = "$node->name <". $node->mail .'>'; but I'm unsure how to get the telephone number in there instead and put it into the variable $destination_number...so that's the first hurdle.

I think I could get it to send once I have the number by using the code that is in the gateway module as a test page but I'm unsure what I need to do in the remindme.module to get it to do this, how do you call a function fropm one module into another? :

function smsgateway_sendmessage( $destination_number, $message_body) {
  $destination_number = trim($destination_number);
  if ($destination_number == null || strlen($destination_number) == 0) {
    return array('connectstring' => 'Not used', 'response' => 'No telephone number specified');
    }

Any pointers or help would be much appreciated thanks.

Comments

Cromicon’s picture

Title: Using with Remind Me. » Using with Remind Me or Private Message - How to get the members telephone number and use it in those modules?

Another example is the Private Message module. It has all the functionality and I imagine it just needs a tweak or two to get it to work. Here's the bit the actually sends the message:

function _privatemsg_mailalert() {
  global $locale;
  $initial_locale = $locale;
  if (function_exists('locale')) {
    $languages = locale_supported_languages();
    $languages = $languages['name'];
  }

  $from = variable_get('site_mail', ini_get('sendmail_from'));
  $result = db_query('SELECT COUNT(*) AS c, recipient FROM {privatemsg} WHERE newmsg = 1 AND recipient_del = 0 GROUP BY recipient');

  while ($alert = db_fetch_object($result)) {
    $user = user_load(array('uid' => $alert->recipient));

    if ((isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1) && (isset($user->privatemsg_mailalert) ? $user->privatemsg_mailalert : 1)) {
      // use each user's individual locale
      if (function_exists('locale') && $languages[$user->language]) {
        $locale = $user->language;
      }

      $subject = t('New private messages at %site.', array('%site' => variable_get('site_name', 'drupal')));
      $message = t('Hi %name,
This is an automatic reminder from the site %site. You have %new unread private messages.

To read your messages, follow this link:
%link1

If you don\'t want to receive these email again, change your preferences here:
%link2', array('%name' => $user->name, '%site' => variable_get('site_name', 'drupal'), '%new' => $alert->c, '%link1' => url('privatemsg', NULL, NULL, 1), '%link2' => url('user/'. $user->uid .'/edit', NULL, NULL, 1)));

      user_mail($user->mail, $subject, $message, "From: $from\nReply-to: $from\nX-Mailer: Drupal\nReturn-path: $from\nErrors-to: $from");

      // revert to previous (site default) locale
      $locale = $initial_locale;
    }
  }
}

This bit seems to identify the user but how on earth do I get the number if stored in their user profile as profile_mobile?

  $user = user_load(array('uid' => $alert->recipient));

    if ((isset($user->privatemsg_allow) ? $user->privatemsg_allow : 1) && (isset($user->privatemsg_mailalert) ? $user->privatemsg_mailalert : 1)) {

And then again, how do I pass variables to smsgateway module?

Again, any help or pointers would be eagerly accepted! :-)

Cromicon’s picture

Ok...

global $user;
$sql = "SELECT value FROM profile_values WHERE (uid = $user->uid) AND (fid = 10)"; 
$result = db_query($sql);
$number = db_fetch_object($result);

That's the number sorted... what if the number isn't there though?