function engagements_email_settings_form

7.x engagements.module engagements_email_settings_form()

Configure the email (reception) settings used by Engagements

File

modules/engagements/engagements.module, line 1220
This is the primary module file for the engagements module.

Code

function engagements_email_settings_form() 
 {
  $form = array();


  $form ['mark_top'] = array(
    'value' => '<p>Configure the connection to check & receive emails.</p>
                <p><b>Important:</b> If you are <b>not</b> using IMAP to check & receive emails, leave this section <b>blank</b>.
                    <br>If you are instead using a Webhook or similar, see below.</p>',
  );


  $form ['engagements_send_email_method'] = array(
    'type' => 'radios',
    'label' => t("Method to send emails"),
    'options' => array('smtp' => 'SMTP'),
    'value' => variable_get('engagements_send_email_method', 'smtp'),
    'required' => TRUE,
    'description' => t("What method will FlightPath use to send emails?  If unsure, select SMTP (the default) and configure 
                        the SMTP settings from the Admin Console link."),
  );


  $form ['engagements_receive_email_method'] = array(
    'type' => 'select',
    'label' => t("Method to receive emails"),
    'options' => array('none' => 'None', 'mailgun' => 'MailGun Webhook/Route', 'imap' => 'IMAP'),
    'value' => variable_get('engagements_receive_email_method', 'none'),
    'required' => TRUE,
    'hide_please_select' => TRUE,
    'description' => t("What method will FlightPath use to <b>receive</b> emails?  If unsure, or
                          if you do not wish to receive emails in FlightPath, select None."),
  );



  $form ['mark_based_on_receive_method'] = array(
    'value' => '<br><br><hr><p>' . t("Based on your <b>receive method</b> selected above, please expand the correct section below
                   and continue configuration:") . '</p><br><br>',
  );


  // Set up fieldsets for our different receive methods...

  $e = array();
  $e []['imap_host'] = array(
    'type' => 'textfield',
    'label' => t('Host'),
    'value' => variable_get('imap_host', ''),
    'description' => 'Ex: mail.example.com',
  );

  $e []['imap_port'] = array(
    'type' => 'textfield',
    'label' => t('Port'),
    'value' => variable_get('imap_port', ''),
    'size' => 10,
    'description' => 'Ex: 143, 993',
  );

  $e []['imap_secure'] = array(
    'type' => 'select',
    'label' => t('Security'),
    'value' => variable_get('imap_secure', ''),
    'options' => array('none' => 'none', 'tls' => 'TLS', 'ssl' => 'SSL'),
    'description' => 'Ex: TLS',
  );

  $e []['imap_username'] = array(
    'type' => 'textfield',
    'label' => t('Username'),
    'value' => variable_get('imap_username', ''),
    'description' => '',
  );

  $e []['imap_password'] = array(
    'type' => 'textfield',
    'label' => t('Password'),
    'value' => variable_get('imap_password', ''),
    'description' => t('Note:  The password will be stored within the database, in the Variables table.
                        Make sure you take the necessary precautions to ensure the security of your database.'),
  );

  // TODO:  folder names to look in?
  // TODO:  other settings on deleting messages once read, etc?


  $bool_start_closed = TRUE;
  if (variable_get('engagements_receive_email_method', 'none') == 'imap') {
    $bool_start_closed = FALSE;
  }


  // Add imap elements to a fieldset.
  $form ['imap_settings_fs'] = array(
    'type' => 'cfieldset',
    'label' => 'IMAP Settings',
    'start_closed' => $bool_start_closed,
    'elements' => $e,
  );




  $e = array();
  $e []['engagements_mailgun_markup'] = array(
    'value' => t("To use this feature, make sure your MailGun account (which is not in any way affiliated with FlightPath, and is a 3rd party service)
                  has a webhook or 'Route' set up to forward emails to this FlightPath installation.") . "
                  <br><br>
                  " . t("The URL to forward the emails to is:") . " " . base_url() . "/engagements-handle-incoming-mailgun-email
                  <br><br>",
  );

  $e []['engagements_mailgun_api_key'] = array(
    'type' => 'textfield',
    'label' => t('Enter your MailGun API Key for Webhooks'),
    'value' => variable_get('engagements_mailgun_api_key', ''),
    'description' => 'This is a value found in your MailGun account, under API Keys.  It may be called something like "HTTP Webhook Signing Key" or similar.',
  );

  $bool_start_closed = TRUE;
  if (variable_get('engagements_receive_email_method', 'none') == 'mailgun') {
    $bool_start_closed = FALSE;
  }


  // Add imap elements to a fieldset.
  $form ['engagements_mailgun_settings_fs'] = array(
    'type' => 'cfieldset',
    'label' => 'MailGun Webhook Settings',
    'start_closed' => $bool_start_closed,
    'elements' => $e,
  );







  return $form;
}