You are here

function mass_contact_admin_edit_submit in Mass Contact 7

Same name and namespace in other branches
  1. 5.2 mass_contact.module \mass_contact_admin_edit_submit()
  2. 5 mass_contact.module \mass_contact_admin_edit_submit()
  3. 6 mass_contact.module \mass_contact_admin_edit_submit()

Processes the adding or editing of a category.

Parameters

array $form: An associative array containing the structure of the form.

array $form_state: A keyed array containing the current state of the form.

File

./mass_contact.admin.inc, line 179
The administrative settings pages.

Code

function mass_contact_admin_edit_submit(array $form, array &$form_state) {
  if ($form_state['values']['reset_selected']) {

    // Unselect all other contact categories.
    db_update('mass_contact')
      ->fields(array(
      'selected' => 0,
    ))
      ->execute();
  }

  // Collect the recipients.
  ctools_include('plugins');

  // Get the information about all plugins that implemnent this type of plugin.
  $plugins = ctools_get_plugins('mass_contact', 'grouping_method');
  $recipients = array();
  foreach ($plugins as $plugin_name => $plugin) {

    // Get the recipient list function name for this particular implementation.
    $function = ctools_plugin_get_function($plugin, 'mass_contact_admin_edit_submit');

    // Call the plugin function to submit the form data.
    $recipients[$plugin_name] = $function($form, $form_state);
  }
  $recipients = serialize($recipients);
  if (!isset($form_state['values']['reply'])) {
    $form_state['values']['reply'] = '';
  }
  if (!isset($form_state['values']['weight'])) {
    $form_state['values']['weight'] = 0;
  }
  $record = array(
    'category' => $form_state['values']['category'],
    'recipients' => $recipients,
    'reply' => $form_state['values']['reply'],
    'weight' => $form_state['values']['weight'],
    'selected' => $form_state['values']['selected'],
  );
  if (arg(4) == 'add') {
    drupal_write_record('mass_contact', $record);
    drupal_set_message(t('Category %category has been added.', array(
      '%category' => $form_state['values']['category'],
    )));
    watchdog('mass_contact', 'Mass Contact form: category %category added.', array(
      '%category' => $form_state['values']['category'],
    ), WATCHDOG_NOTICE, l(t('view'), 'admin/config/system/mass_contact'));
  }
  else {
    $record['cid'] = $form_state['values']['cid'];
    drupal_write_record('mass_contact', $record, array(
      'cid',
    ));
    drupal_set_message(t('Category %category has been updated.', array(
      '%category' => $form_state['values']['category'],
    )));
    watchdog('mass_contact', 'Mass Contact form: category %category updated.', array(
      '%category' => $form_state['values']['category'],
    ), WATCHDOG_NOTICE, l(t('view'), 'admin/config/system/mass_contact'));
  }
  if (module_exists('adminrole')) {
    adminrole_update_permissions();
  }
  $form_state['redirect'] = 'admin/config/system/mass_contact';
}