You are here

function mass_contact_admin_edit_submit in Mass Contact 6

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. 7 mass_contact.admin.inc \mass_contact_admin_edit_submit()

Processes the adding or editing of a category.

Parameters

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

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

File

./mass_contact.module, line 528
This is the main code file for the Mass Contact module. This module enables users to contact multiple users through selected roles.

Code

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

    // Unselect all other contact categories.
    db_query("UPDATE {mass_contact} SET selected = %d", 0);
  }

  // Remove 0s for unselected roles, convert to csv.
  $recipients = $form_state['values']['recipients'];

  // If all authenticated users are already added, remove all roles.
  if ($recipients[2] == 2) {
    foreach ($recipients as $checkr) {
      if ($checkr > 2) {
        $recipients[$checkr] = 0;
      }
    }
  }

  // Remove roles that were not selected.
  foreach ($recipients as $recip) {
    if ($recip != 0) {
      $newformrec[] = $recip;
    }
  }
  $form_state['values']['recipients'] = implode(',', $newformrec);
  if (!isset($form_state['values']['reply'])) {
    $form_state['values']['reply'] = '';
  }
  if (!isset($form_state['values']['weight'])) {
    $form_state['values']['weight'] = 0;
  }
  if (arg(3) == 'add') {
    db_query("INSERT INTO {mass_contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $form_state['values']['category'], $form_state['values']['recipients'], $form_state['values']['reply'], $form_state['values']['weight'], $form_state['values']['selected']);
    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/build/mass_contact'));
  }
  else {
    db_query("UPDATE {mass_contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid = %d", $form_state['values']['category'], $form_state['values']['recipients'], $form_state['values']['reply'], $form_state['values']['weight'], $form_state['values']['selected'], $form_state['values']['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/build/mass_contact'));
  }
  if (module_exists('adminrole')) {
    adminrole_update_permissions();
  }
  $form_state['redirect'] = 'admin/build/mass_contact';
}