You are here

function certificate_settings_form in Certificate 6

Same name and namespace in other branches
  1. 8.3 certificate.admin.inc \certificate_settings_form()
  2. 6.2 certificate.admin.inc \certificate_settings_form()
  3. 7.3 certificate.admin.inc \certificate_settings_form()
  4. 7.2 certificate.admin.inc \certificate_settings_form()
  5. 3.x certificate.admin.inc \certificate_settings_form()

Form for field mapping allowed values to certificate templates.

1 string reference to 'certificate_settings_form'
certificate_menu in ./certificate.module
Implementation of hook_menu().

File

./certificate.admin.inc, line 354
Administrative pages for the module.

Code

function certificate_settings_form(&$form_state) {
  drupal_set_title('Certificate field mapping');
  $form['certificate_settings']['#tree'] = TRUE;

  // Certificate types.
  $types = variable_get('certificate_field_certificate_type', '');
  $form['certificate_settings']['types'] = array(
    '#type' => 'fieldset',
    '#title' => t('Profile fields'),
    '#collapsible' => TRUE,
    '#collapsed' => $types != '',
    '#description' => "Using this mapping will award certificates solely based on a field in the user's content profile.",
  );
  if (module_exists('content')) {
    $field_options = certificate_fields();
    $form['certificate_settings']['types']['certificate_field_certificate_type'] = array(
      '#type' => 'select',
      '#options' => $field_options,
      '#default_value' => variable_get('certificate_field_certificate_type', 0),
      '#description' => t("Select which field should be used to generate certificate types. <b>WARNING:</b> changing this may cause undesired effects."),
    );
  }
  else {
    $form['certificate_settings']['no_cck_message'] = array(
      '#value' => variable_get('no_cck_message', t('You must enable the <a href="!cck_url">cck module</a> to use this feature.', array(
        '!cck_url' => url('http://drupal.org/project/cck'),
      ))),
    );
  }

  // Set course defaults.
  // Add template-mapping form.
  module_load_include('inc', 'certificate', 'certificate.admin');
  $form['certificate_settings']['map'] = certificate_type_mapping_form(array());
  $form['certificate_settings']['types']['nogroups'] = $form['certificate_settings']['map']['nogroups'];
  unset($form['certificate_settings']['map']['nogroups']);

  // Custom (module-provided) mappings.
  $mappings = module_invoke_all('certificate_map_options');
  $options = array(
    '',
  );
  foreach (certificate_certificate_load_all() as $cert) {
    $options[$cert['nid']] = $cert['title'];
  }
  foreach ($mappings as $map_type => $map) {
    $stored = variable_get("certificate_map_{$map_type}", array());
    $form['certificate_settings']['map'][$map_type] = array(
      '#title' => $map['title'],
      '#type' => 'fieldset',
      '#group' => TRUE,
      '#description' => $map['description'],
    );
    if (count($map['options'])) {
      foreach ($map['options'] as $key => $value) {
        $form['certificate_settings']['map'][$map_type][$key] = array(
          '#type' => 'select',
          '#title' => $value,
          '#options' => $options,
          '#default_value' => $stored[$key],
        );
      }
    }
    else {
      $form['certificate_settings']['map'][$map_type]['empty'] = array(
        '#value' => 'There are no mappings available for ' . $map['title'],
      );
    }
  }
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}