You are here

function notifications_send_intervals_form in Notifications 6

Same name and namespace in other branches
  1. 5 notifications.admin.inc \notifications_send_intervals_form()
  2. 6.4 notifications.admin.inc \notifications_send_intervals_form()
  3. 6.2 notifications.admin.inc \notifications_send_intervals_form()
  4. 6.3 notifications.admin.inc \notifications_send_intervals_form()

Send intervals administration

1 string reference to 'notifications_send_intervals_form'
notifications_menu in ./notifications.module
Implementation of hook_menu().

File

./notifications.admin.inc, line 96

Code

function notifications_send_intervals_form() {

  // Collect information about digesting methods and print out some help
  $form['digest'] = array(
    '#title' => t('Digest formats'),
    '#type' => 'fieldset',
    '#description' => t('These are the digest formats available for each interval.'),
  );
  $digest_methods[''] = t('None');
  foreach (notifications_digest_method() as $type => $method) {
    $digest_methods[$type] = $method['name'];
    $rows[] = array(
      $method['name'],
      $method['description'],
    );
  }
  $form['digest']['info'] = array(
    '#value' => theme('table', array(), $rows),
  );

  // Build options
  $units = array(
    60 => t('Minutes'),
    60 * 60 => t('Hours'),
    24 * 60 * 60 => t('Days'),
  );
  $form['intervals'] = array(
    '#type' => 'fieldset',
    '#title' => t('Send intervals'),
    '#tree' => TRUE,
    '#theme' => 'notifications_send_intervals',
    '#description' => t('To delete an interval, set the time unit and the name empty.'),
  );
  $intervals = _notifications_send_intervals() + array(
    'new1' => '',
    'new2' => '',
  );
  $index = 0;
  foreach ($intervals as $time => $name) {

    // Calculate value and unit
    $current = $number = 0;
    if (!is_numeric($time)) {
      $number = $unit = '';
    }
    elseif ($time >= 0) {
      foreach (array_reverse(array_keys($units)) as $unit) {
        if ($time % $unit == 0) {
          $current = $unit;
          $number = $time / $unit;
          break;
        }
      }
    }
    else {

      // May be -1 for 'Never'
      $number = $time;
      $unit = '';
    }
    $form['intervals'][$index]['time'] = array(
      '#default_value' => $number,
      '#type' => 'textfield',
      '#size' => 2,
    );
    $form['intervals'][$index]['unit'] = array(
      '#type' => 'select',
      '#options' => array(
        '' => '',
      ) + $units,
      '#default_value' => $unit,
    );
    $form['intervals'][$index]['name'] = array(
      '#type' => 'textfield',
      '#default_value' => $name,
      '#size' => 40,
    );
    $digest = notifications_digest_method($time);
    $form['intervals'][$index]['digest'] = array(
      '#type' => 'select',
      '#disabled' => $number < 0,
      '#default_value' => $digest ? $digest['type'] : '',
      '#options' => $digest_methods,
    );
    $index++;
  }

  // New row
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );
  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
  );
  return $form;
}