You are here

function sms_blast_form_submit in SMS Framework 7

Same name and namespace in other branches
  1. 5 modules/sms_blast/sms_blast.module \sms_blast_form_submit()
  2. 6.2 modules/sms_blast/sms_blast.module \sms_blast_form_submit()
  3. 6 modules/sms_blast/sms_blast.module \sms_blast_form_submit()

Submit handler for the sms blast form.

File

modules/sms_blast/sms_blast.module, line 56
Allows bulk text messages to be sent to registered users.

Code

function sms_blast_form_submit(&$form, $form_state) {
  $result = db_query("SELECT uid FROM {sms_user} WHERE status = :status", array(
    ':status' => SMS_USER_CONFIRMED,
  ));
  $num_passed = $num_failed = 0;
  if ($result
    ->rowCount() != 0) {
    $errors = array();
    foreach ($result as $row) {
      try {
        if (sms_user_send($row->uid, $form_state['values']['message'])) {
          $num_passed++;
        }
        else {
          $num_failed++;
        }
      } catch (Exception $e) {
        $errors[] = $e
          ->getMessage();
        $num_failed++;
      }
    }
    if ($num_passed) {
      drupal_set_message(t('The message was sent to %count users.', array(
        '%count' => $num_passed,
      )));
    }
    if ($num_failed) {
      drupal_set_message(t('The message could not be sent to %count users.', array(
        '%count' => $num_failed,
      )), 'warning');
    }
  }
  else {
    drupal_set_message(t('There are 0 users with confirmed phone numbers. The message was not sent.'));
  }
}