You are here

function messaging_template_admin_message_form_submit in Messaging 6.4

Process and save message parts

File

messaging_template/messaging_template.admin.inc, line 320
Messaging Framework - Admin UI

Code

function messaging_template_admin_message_form_submit($form, &$form_state) {
  $group = $form_state['values']['group'];
  $language = $form_state['values']['language'];
  $module = $form_state['values']['module'];
  switch ($form_state['values']['op']) {
    case t('Reset to defaults'):
      db_query("DELETE FROM {messaging_message_parts} WHERE type = '%s' AND language = '%s'", $group, $language->language);
      drupal_set_message('The message templates have been reset to default values.');
      break;
    case t('Save'):
      foreach ($form_state['values']['messages'] as $method => $messages) {
        foreach ($messages as $key => $part) {
          if (!empty($part['enabled'])) {
            if (trim($part['message'])) {
              $part += array(
                'type' => $group,
                'msgkey' => $key,
                'method' => $method,
                'language' => $language->language,
                'module' => $module,
              );
              $update = !empty($part['tpid']) ? 'tpid' : array();
              drupal_write_record('messaging_message_parts', $part, $update);
            }
            elseif (!empty($part['tpid'])) {

              // There was a part now empty, delete it
              db_query("DELETE FROM {messaging_message_parts} WHERE tpid = %d", $part['tpid']);
            }
          }
        }
      }
      drupal_set_message('The message templates have been updated.');
      break;
  }
}