You are here

function biblio_form_types_edit in Bibliography Module 5

1 string reference to 'biblio_form_types_edit'
biblio_menu in ./biblio.module
Implementation of hook_menu().

File

./biblio.module, line 1132

Code

function biblio_form_types_edit() {
  if ($arg_list = func_get_args()) {

    // show an existing type
    $tid = $arg_list[0];
  }

  // first get all of the field info
  $result = db_query('SELECT * FROM {biblio_fields} as b  ORDER BY b.weight ASC');
  while ($row = db_fetch_array($result)) {
    if ($tid) {
      if ($row['common']) {
        $fields[$row['fid']] = $row;
      }
      else {
        $other_fields[$row['fid']] = $row;
      }
    }
    else {
      $fields[$row['fid']] = $row;
    }
  }
  $form['configured_flds'] = array(
    '#tree' => 1,
  );
  $form['cust'] = array(
    '#tree' => 1,
  );
  if ($tid) {

    // show an existing type
    $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid = %d', $tid);
    $row = db_fetch_array($result);
    $form['type_name'] = array(
      '#type' => 'value',
      '#title' => 'tid',
      '#value' => check_plain($row['name']),
    );

    // now get any type specific customizations
    $result = db_query('SELECT d.*, f.name FROM {biblio_type_details} as d INNER JOIN {biblio_fields} as f on d.fid=f.fid where d.tid=%d  ORDER BY d.weight ASC', $tid);
    while ($row = db_fetch_array($result)) {
      $type_fields[$row['fid']] = $row;
      $form['cust'][$row['fid']] = array(
        '#type' => 'value',
        '#value' => $row['fid'],
      );
      unset($other_fields[$row['fid']]);
    }
    if (count($type_fields)) {

      // now merge the customizations with the main field array
      foreach ($type_fields as $key => $value) {
        $fields[$key] = isset($fields[$key]) ? array_merge($fields[$key], $value) : $value;
      }
    }
    $form['tid'] = array(
      '#type' => 'value',
      '#value' => $tid,
    );
  }
  uasort($fields, "_biblio_form_sort");

  // resort the fields since the weight may have changed
  $vis_comm = $tid ? 'visible' : 'common';
  if (!$tid) {
    $options["{$vis_comm}"] = '';
  }
  $options['required'] = '';
  if (!$tid) {
    $options['autocomplete'] = '';
  }
  foreach ($fields as $key => $fld) {
    if ($fld['common']) {
      $def_values[$fld['name']][] = 'common';
    }
    if ($fld['required']) {
      $def_values[$fld['name']][] = 'required';
    }
    if ($fld['autocomplete']) {
      $def_values[$fld['name']][] = 'autocomplete';
    }
    $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'],
    );
    $form['configured_flds'][$key]['weight'] = array(
      '#type' => 'textfield',
      '#default_value' => $fld['weight'],
      '#size' => 2,
      '#weight' => $fld['weight'],
    );
    $form['configured_flds'][$key]['hint'] = array(
      '#type' => 'textfield',
      '#default_value' => $fld['hint'],
      '#size' => 10,
      '#maxlength' => 255,
      '#weight' => $fld['weight'],
    );

    //if (!$tid) {

    //  $form['configured_flds'][$key]['hint']['#type']= 'markup';
    //  $form['configured_flds'][$key]['title']['#type']= 'markup';

    //}
    $form['configured_flds'][$key]['checkboxes'] = array(
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => $def_values[$fld['name']],
      '#weight' => $fld['weight'],
    );
  }
  if ($tid) {
    foreach ($other_fields as $key => $fld) {
      $form['avail_flds'][$key]['name'] = array(
        '#type' => 'markup',
        '#value' => check_plain($fld['name']),
        '#weight' => $fld['weight'],
      );
      $form['avail_flds'][$key]['title'] = array(
        '#type' => 'markup',
        '#value' => check_plain($fld['title']),
        '#weight' => $fld['weight'],
      );
      $form['avail_flds'][$key]['size'] = array(
        '#type' => 'markup',
        '#value' => check_plain($fld['maxsize']),
        '#weight' => $fld['weight'],
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}