You are here

sms_blast.module in SMS Framework 6.2

Allows bulk text messages to be sent to registered users.

File

modules/sms_blast/sms_blast.module
View source
<?php

/**
 * @file
 * Allows bulk text messages to be sent to registered users.
 */

/**
 * Implementation of hook_perm().
 */
function sms_blast_perm() {
  return array(
    'send sms blasts',
  );
}

/**
 * Implementation of hook_menu().
 */
function sms_blast_menu() {
  $items['sms_blast'] = array(
    'title' => 'SMS Blast',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'sms_blast_form',
    ),
    'access arguments' => array(
      'send sms blasts',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

/**
 * Display the sms blast form
 */
function sms_blast_form() {
  $form['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#cols' => 60,
    '#rows' => 5,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),
  );
  return $form;
}

/**
 * Submit handler for the sms blast form
 */
function sms_blast_form_submit(&$form, $form_state) {
  $result = db_query("SELECT uid FROM {sms_user} WHERE status = 2");
  $confirmed_user_qty = db_affected_rows();
  if ($confirmed_user_qty) {
    while ($row = db_fetch_array($result)) {
      sms_user_send($row['uid'], $form_state['values']['message']);
    }
    drupal_set_message(t('The message was sent to %count users.', array(
      '%count' => $confirmed_user_qty,
    )));
  }
  else {
    drupal_set_message(t('There are 0 users with confirmed phone numbers. Message not sent.'));
  }
}

Functions

Namesort descending Description
sms_blast_form Display the sms blast form
sms_blast_form_submit Submit handler for the sms blast form
sms_blast_menu Implementation of hook_menu().
sms_blast_perm Implementation of hook_perm().