You are here

function biblio_admin_author_edit_form in Bibliography Module 6

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

File

./biblio.admin.inc, line 1653

Code

function biblio_admin_author_edit_form($form_state, $author_id) {
  $merge_options = $linked = array();
  $author = db_fetch_object(db_query('SELECT * FROM {biblio_contributor_data} b WHERE b.cid = %d ', $author_id));
  if (!$author) {
    drupal_not_found();
    return;
  }
  $base = variable_get('biblio_base', 'biblio');
  $menu = menu_get_active_title();
  $path = strpos($_GET['q'], 'settings') ? 'admin/settings/biblio/author' : $base . '/authors';
  $form['#redirect'] = $path;
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => $author_id,
  );
  $users = db_query('SELECT uid,name FROM {users} WHERE uid>0 ORDER BY name');
  $options[0] = t('(None)');
  while ($user = db_fetch_array($users)) {
    $options[$user['uid']] = $user['name'];
  }
  $form['drupal_uid'] = array(
    '#type' => 'select',
    '#title' => t('Drupal User ID'),
    '#options' => $options,
    '#default_value' => $author->drupal_uid,
    '#weight' => 12,
    '#required' => FALSE,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Complete Name'),
    '#default_value' => $author->name,
    '#size' => 100,
    '#weight' => 1,
    '#required' => TRUE,
    '#maxlength' => 128,
  );
  $form['no_format'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not reformat'),
    '#default_value' => 0,
    '#weight' => 1.5,
    '#required' => false,
    '#description' => t('Selecting this will prevent the styles from trying to reformat the contributor name.  The text in the "Complete Name" field will be used as is.'),
  );
  $form['prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Prefix'),
    '#default_value' => $author->prefix,
    '#size' => 20,
    '#weight' => 2,
    '#required' => FALSE,
    '#maxlength' => 128,
  );
  $form['firstname'] = array(
    '#type' => 'textfield',
    '#title' => t('First Name'),
    '#default_value' => $author->firstname,
    '#size' => 20,
    '#weight' => 3,
    '#required' => FALSE,
    '#maxlength' => 128,
  );
  $form['initials'] = array(
    '#type' => 'textfield',
    '#title' => t('Initials'),
    '#default_value' => $author->initials,
    '#size' => 20,
    '#weight' => 4,
    '#required' => FALSE,
    '#maxlength' => 10,
  );
  $form['lastname'] = array(
    '#type' => 'textfield',
    '#title' => t('Last Name'),
    '#default_value' => $author->lastname,
    '#size' => 20,
    '#weight' => 5,
    '#required' => TRUE,
    '#maxlength' => 128,
  );
  $form['suffix'] = array(
    '#type' => 'textfield',
    '#title' => t('Suffix'),
    '#default_value' => $author->suffix,
    '#size' => 20,
    '#weight' => 6,
    '#required' => FALSE,
    '#maxlength' => 128,
  );
  $form['affiliation'] = array(
    '#type' => 'textfield',
    '#title' => t('Affiliation'),
    '#default_value' => $author->affiliation,
    '#size' => 100,
    '#weight' => 7,
    '#required' => FALSE,
    '#maxlength' => 256,
  );
  $authors = db_query("SELECT * FROM {biblio_contributor_data} cd WHERE cid != %d ORDER BY lastname", $author_id);
  $base = variable_get('biblio_base', 'biblio');
  while ($other_author = db_fetch_array($authors)) {
    if (stripos($other_author['name'], $author->lastname) !== FALSE && $author->aka != $other_author['cid']) {
      $merge_options[$other_author['cid']] = l($other_author['name'], $base . '/authors/' . $other_author['cid'] . '/edit/');
      if ($other_author['affiliation']) {
        $merge_options[$other_author['cid']] .= ' (' . $other_author['affiliation'] . ')';
      }
    }
    if ($author->aka == $other_author['aka']) {
      $linked[$other_author['cid']] = l($other_author['lastname'] . ($other_author['firstname'] ? ', ' . $other_author['firstname'] : ($other_author['initials'] ? ', ' . $other_author['initials'] : '')), $base . '/authors/' . $other_author['cid'] . '/edit/');
      if ($other_author['affiliation']) {
        $linked[$other_author['cid']] .= ' (' . $other_author['affiliation'] . ')';
      }
      $linked_default_values[] = $other_author['cid'];
    }
    else {
      $link_options[$other_author['cid']] = $other_author['lastname'] . ($other_author['firstname'] ? ', ' . $other_author['firstname'] : ($other_author['initials'] ? ', ' . $other_author['initials'] : ''));
      if ($other_author['affiliation']) {
        $link_options[$other_author['cid']] .= ' (' . $other_author['affiliation'] . ')';
      }
    }
  }
  if (count($merge_options)) {
    $form['merge'] = array(
      '#type' => 'fieldset',
      '#title' => t('Author Merge'),
      '#description' => t('Select other author names which will be merged.  Merging removes all the selected authors, then replaces any references to these authors with the author being edited above.  You should only do this if you are sure the other authors represent the same author as the one being edited. <B>THIS CANNOT BE UNDONE!</B>'),
      '#weight' => 5,
      '#collapsible' => TRUE,
      '#collapsed' => !count($merge_options),
    );
    $form['merge']['merge_authors'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Similar authors'),
      '#options' => $merge_options,
      '#weight' => 12,
      '#required' => FALSE,
    );
    $form['merge']['merge'] = array(
      '#type' => 'submit',
      '#value' => t('Merge'),
    );
  }
  $form['link'] = array(
    '#type' => 'fieldset',
    '#title' => t('Author Link'),
    '#description' => t('Select other author names which will be linked.  Linking relates all the selected authors to the author being edited above, and and keeps each instance in the database.  You should only do this if you are sure the other authors represent the same author as the one being edited. '),
    '#weight' => 5,
    '#collapsible' => TRUE,
    '#collapsed' => !count($linked),
  );
  if (count($linked)) {
    $form['link']['linked_authors'] = array(
      '#type' => 'checkboxes',
      '#title' => t('This author has already been linked to these authors'),
      '#default_value' => $linked_default_values,
      '#options' => $linked,
      '#weight' => 12,
      '#required' => FALSE,
    );
  }
  $form['link']['link_authors'] = array(
    '#type' => 'select',
    '#title' => t('Other authors which could be linked to this author'),
    //'#default_value' => $link_default_values,
    '#options' => $link_options,
    '#weight' => 12,
    '#required' => FALSE,
    '#multiple' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}