You are here

function biblio_admin_types_edit_form in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 includes/biblio.admin.inc \biblio_admin_types_edit_form()
  2. 7 includes/biblio.admin.inc \biblio_admin_types_edit_form()
  3. 7.2 includes/biblio.admin.inc \biblio_admin_types_edit_form()
1 string reference to 'biblio_admin_types_edit_form'
biblio_menu in ./biblio.module
Implementation of hook_menu().

File

./biblio.admin.inc, line 655

Code

function biblio_admin_types_edit_form() {
  $tid = 0;
  $arg_list = func_get_args();
  $tid = is_numeric($arg_list[1]) ? $arg_list[1] : 0;
  $msg = '<div>' . t('On this page you can set type specific "Titles" and "Hints" which will display on the input form. ');
  if ($tid) {
    $msg .= t('Checking the "Visible" box will add the field to the input form, checking "Required" will force the user to supply a value for this field and the weight value changes the order which it is rendered on the form with smaller values floating to the top of the form.
    <p> Fields which are grayed out on this page have been set to "common" on the !linktobiblioadmin page.</p>', array(
      '!linktobiblioadmin' => l("admin/settings/biblio/fields", "admin/settings/biblio/fields"),
    ));
  }
  else {
    $msg .= t('Checking the "Common" box will add the field to all the different publication types. Checking "Required" will force the user to supply a value for the field, checking "Autocomplete" will enable AJAX type auto complete look up for the field when the user is entering data and the weight value changes the order which it is rendered on the form with smaller values floating to the top of the form. ');
  }
  $msg .= t('Finally, for each author field you can choose a set of author roles. Assigning different roles to authors within the same field, e.g. primary and secondary authors within the authors field, allows to theme them differently.');
  $msg .= '</div>';
  $form['#redirect'] = 'admin/settings/biblio/fields/type';
  $form['help'] = array(
    '#type' => 'fieldset',
    '#title' => t('Help'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['help']['message'] = array(
    '#type' => 'markup',
    '#value' => $msg,
  );
  if (!$tid) {
    $form['options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Options'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['options']['hide_other_fields'] = array(
      '#type' => 'checkbox',
      '#title' => t('Hide "Other Biblio Fields" fieldset'),
      '#description' => t('Fields NOT set as "Common" on this page or "Visible" on one of the Type specific edit pages are normally moved to the "Other Biblio Fields" fieldset, selecting this check box will hide that fieldset completely'),
      '#default_value' => variable_get('biblio_hide_other_fields', 0),
    );
  }

  // get author types
  $result = db_query("SELECT * FROM {biblio_contributor_type_data} b");
  $contrib_options = array();
  while ($contrib_type = db_fetch_object($result)) {
    $contrib_options[$contrib_type->auth_type] = $contrib_type->title;
    $contrib_hints[$contrib_type->auth_type] = $contrib_type->hint;
  }

  // first get all of the field info
  if ($tid) {
    $result = db_query("SELECT bf.*, bftd.*, bft.common, bft.visible, bft.autocomplete, bft.weight, bft.required, bt.name AS type_name\n                        FROM {biblio_fields} AS bf\n                        INNER JOIN {biblio_field_type} AS bft ON bft.fid=bf.fid\n                        INNER JOIN {biblio_field_type_data} AS bftd ON bftd.ftdid=bft.ftdid\n                        INNER JOIN {biblio_types} AS bt ON bt.tid=bft.tid\n                        WHERE bft.tid={$tid}");
  }
  else {
    $result = db_query("SELECT bf.*, bftd.*, bft.common, bft.visible, bft.autocomplete, bft.weight, bft.required\n                        FROM {biblio_fields} AS bf\n                        INNER JOIN {biblio_field_type} AS bft ON bft.fid=bf.fid\n                        INNER JOIN {biblio_field_type_data} AS bftd ON bftd.ftdid=bft.ftdid\n                        WHERE bft.tid={$tid}");
  }
  while ($row = db_fetch_array($result)) {
    $fields[$row['fid']] = $row;
  }
  $form['configured_flds'] = array(
    '#tree' => 1,
  );
  if ($tid) {

    // show an existing type
    $typename = $fields[1]['type_name'];
    $form['type_name'] = array(
      '#title' => t('Publication type name'),
      '#type' => 'textfield',
      '#maxlength' => 64,
      '#default_value' => $typename,
      '#required' => TRUE,
    );
    $form['top_message'] = array(
      '#value' => t('Field settings related to @type publications', array(
        '@type' => $typename,
      )),
    );
    $form['type_id'] = array(
      '#type' => 'value',
      '#title' => 'tid',
      '#value' => $tid,
    );
  }
  else {
    $form['top_message'] = array(
      '#value' => t('Field settings common to all publication types'),
    );
  }
  uasort($fields, "biblio_form_sort");

  // resort the fields since the weight may have changed
  $vis_comm = $tid ? 'visible' : 'common';
  $options["{$vis_comm}"] = '';
  $options['required'] = '';
  if ($tid == 0) {
    $options['autocomplete'] = '';
  }
  foreach ($fields as $key => $fld) {
    $def_values[$fld['name']] = array();
    if ($tid) {
      if ($fld['visible']) {
        array_push($def_values[$fld['name']], 'visible');
      }
      if ($fld['required']) {
        array_push($def_values[$fld['name']], 'required');
      }
    }
    else {
      if ($fld['common']) {
        array_push($def_values[$fld['name']], 'common');
      }
      if ($fld['required']) {
        array_push($def_values[$fld['name']], 'required');
      }
      if ($fld['autocomplete']) {
        array_push($def_values[$fld['name']], 'autocomplete');
      }
    }
    $disabled = $tid ? $fld['common'] ? 1 : 0 : 0;
    $form['configured_flds'][$key]['name'] = array(
      '#type' => 'markup',
      '#value' => check_plain($fld['name']),
      '#weight' => $fld['weight'],
    );
    $form['configured_flds'][$key]['title'] = array(
      '#type' => 'textfield',
      '#default_value' => $fld['title'],
      '#size' => 15,
      '#weight' => $fld['weight'],
      '#disabled' => $disabled,
    );
    $form['configured_flds'][$key]['hint'] = array(
      '#type' => 'textfield',
      '#default_value' => $fld['hint'],
      '#size' => 20,
      '#weight' => $fld['weight'],
      '#disabled' => $disabled,
    );
    $form['configured_flds'][$key]['weight'] = array(
      '#type' => 'textfield',
      '#default_value' => $fld['weight'],
      '#size' => 2,
      '#weight' => $fld['weight'],
    );
    $form['configured_flds'][$key]['checkboxes'] = array(
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => $def_values[$fld['name']],
      '#weight' => $fld['weight'],
    );
    $form['configured_flds'][$key]['ftdid'] = array(
      '#type' => '#value',
      '#value' => $fld['ftdid'],
    );
    if ($fld['type'] == 'contrib_widget') {
      $cur = _biblio_get_auth_types($fld['fid'], $tid ? $tid : $fld['fid']);
      $form['configured_flds'][$key]['auth_type'] = array(
        '#type' => 'select',
        '#options' => $contrib_options,
        '#size' => min(count($contrib_options), 4),
        '#multiple' => TRUE,
        '#default_value' => _biblio_get_auth_types($fld['fid'], $disabled ? 0 : $tid),
        '#disabled' => $disabled,
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}