You are here

function messaging_template_edit_form_submit in Messaging 6.3

Process and save message parts

File

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

Code

function messaging_template_edit_form_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  $name = $form_state['values']['name'];
  $language = $form_state['values']['language'];
  switch ($op) {
    case t('Save template'):
      foreach ($form_state['values']['template'] as $method => $templates) {
        foreach ($templates as $key => $text) {
          $text += array(
            'name' => $name,
            'method' => $method,
            'msgkey' => $key,
            'language' => $language,
          );
          if ($text['options'] != MESSAGING_TEMPLATE_DEFAULT) {

            // Save / update, depending on exiting tptid
            drupal_write_record('messaging_template_text', $text, !empty($text['tptid']) ? 'tptid' : array());
          }
          elseif (!empty($text['tptid'])) {

            // We had a row but as it's set to default we don't need it anymore
            db_query('DELETE FROM {messaging_template_text} WHERE tptid = %d', $text['tptid']);
          }
        }
      }
      drupal_set_message('The template elements have been updated');
      break;
    case t('Reset to defaults'):
      db_query("DELETE FROM {messaging_template} WHERE name = '%s'", $name);
      db_query("DELETE FROM {messaging_template_text} WHERE name = '%s'", $name);
      drupal_set_message(t('Your template elements have been restored to their default values.'));
      break;
  }
}