You are here

function biblio_admin_author_edit_form in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 includes/biblio.admin.inc \biblio_admin_author_edit_form()
  2. 6 biblio.admin.inc \biblio_admin_author_edit_form()
  3. 7.2 includes/biblio.admin.inc \biblio_admin_author_edit_form()

_state

Parameters

$form:

$author_id:

Return value

void|multitype:string NULL

1 string reference to 'biblio_admin_author_edit_form'
biblio_menu in ./biblio.module
Implements hook_menu().

File

includes/biblio.admin.inc, line 2148
biblio.admin.inc

Code

function biblio_admin_author_edit_form($form, &$form_state, $author_id) {
  module_load_include('inc', 'biblio', 'includes/biblio.contributors');
  $merge_options = $linked = array();
  if (!isset($form_state['biblio_add_merge_author'])) {
    $form_state['biblio_add_merge_author'] = array();
  }
  $base = variable_get('biblio_base', 'biblio');
  $author = db_query('SELECT * FROM {biblio_contributor_data} b WHERE b.cid = :aid ', array(
    ':aid' => $author_id,
  ))
    ->fetchObject();
  if (!$author) {
    drupal_not_found();
    return;
  }
  $base = variable_get('biblio_base', 'biblio');
  $menu = menu_get_active_title();
  $path = strpos($_GET['q'], 'config') ? 'admin/config/content/biblio/author/' : $base . '/authors/';

  // $form['#tree'] = TRUE;.
  $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)');
  foreach ($users as $user) {
    $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,
    '#description' => t('If this author has a an account (Drupal User ID) on this web site, you may select it here.  This will help to link the authors publications with other content.'),
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Complete Name'),
    '#default_value' => $author->name,
    '#size' => 100,
    '#weight' => 1,
    '#required' => TRUE,
    '#disabled' => TRUE,
    '#maxlength' => 255,
    '#description' => t('The value in this box will be constructed from the individual name parts fields above.'),
  );
  $form_state['current_name'] = $author->name;
  $form['literal'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not reformat'),
    '#default_value' => $author->literal,
    '#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' => FALSE,
    '#maxlength' => 255,
  );
  $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,
    '#description' => t('University, Company or Organization that the author is affiliated with.'),
  );
  $query = db_select('biblio_contributor_data', 'bcd');
  $authors = $query
    ->fields('bcd')
    ->condition('cid', $author_id, '<>')
    ->orderBy('lastname')
    ->execute();
  $query = db_select('biblio_contributor', 'bc');
  $merged_authors = $query
    ->fields('bc')
    ->condition('merge_cid', 0, '>')
    ->execute();
  foreach ($merged_authors as $auth) {
    $merged[$auth->merge_cid] = $auth->cid;
  }
  $linked = biblio_get_linked_contributors($author->cid);
  $radio_options = array(
    'link' => '',
    'merge' => '',
  );
  $candidate = FALSE;
  $candidates = array();
  $this_soundx = soundex($author->lastname);
  foreach ($authors as $other_author) {
    $merge_def = $link_def = 0;
    $link_disable = $merge_disable = $retain_disable = FALSE;
    if (soundex($other_author->lastname) == $this_soundx || isset($merged[$other_author->cid]) && $merged[$other_author->cid] == $author->cid || in_array($other_author->cid, $form_state['biblio_add_merge_author'])) {
      $candidate = TRUE;
      $merge_def = $other_author->alt_form && $other_author->aka == $author->cid ? $author->cid : FALSE;
      $retain_def = $other_author->alt_form ? $author->cid : FALSE;
      $retain_disable = $other_author->alt_form ? TRUE : FALSE;
    }
    if (in_array($other_author->cid, $linked)) {
      $candidate = TRUE;
      $link_def = $author->cid;
      $retain_def = 0;
    }
    if ($candidate) {
      $candidate = FALSE;
      $form_state['biblio_add_merge_author'][$other_author->cid] = $other_author->cid;
      $candidates[$other_author->cid]['name'] = array(
        '#markup' => l($other_author->lastname . ($other_author->firstname ? ', ' . $other_author->firstname : ($other_author->initials ? ', ' . $other_author->initials : '')), $path . $other_author->cid . '/edit/'),
        '#markup' => l($other_author->name, $path . $other_author->cid . '/edit/'),
      );
      $candidates[$other_author->cid]['link'] = array(
        '#type' => 'checkbox',
        '#return_value' => $author->cid,
        '#default_value' => $link_def,
        '#disabled' => $link_disable,
        '#parents' => array(
          'candidates',
          $other_author->cid,
          'link',
        ),
        '#states' => array(
          'disabled' => array(
            ':input[name="candidates[' . $other_author->cid . '][merge]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $candidates[$other_author->cid]['merge'] = array(
        '#type' => 'checkbox',
        '#return_value' => $author->cid,
        '#default_value' => $merge_def,
        '#disabled' => $merge_disable,
        '#parents' => array(
          'candidates',
          $other_author->cid,
          'merge',
        ),
        '#states' => array(
          'disabled' => array(
            ':input[name="candidates[' . $other_author->cid . '][link]"]' => array(
              'checked' => TRUE,
            ),
          ),
        ),
      );
      $candidates[$other_author->cid]['retain'] = array(
        '#type' => 'checkbox',
        '#return_value' => $author->cid,
        '#default_value' => $retain_def,
        '#disabled' => $retain_disable,
        '#parents' => array(
          'candidates',
          $other_author->cid,
          'retain',
        ),
        '#states' => array(
          'enabled' => array(
            ':input[name="candidates[' . $other_author->cid . '][merge]"]' => array(
              'checked' => TRUE,
            ),
          ),
          'unchecked' => array(
            ':input[name="candidates[' . $other_author->cid . '][merge]"]' => array(
              'unchecked' => TRUE,
            ),
          ),
        ),
      );
    }
  }
  $form['merge'] = array(
    '#type' => 'fieldset',
    '#theme' => 'biblio_admin_author_edit_merge_table',
    '#title' => t('Author Link / Merge'),
    '#description' => t('Select other author names which will be linked or 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>IF you do not select "Retain as alternate form" then THIS CANNOT BE UNDONE!</b>'),
    '#weight' => 5,
    '#collapsible' => TRUE,
    '#collapsed' => !count($candidates),
    '#header' => array(
      t('Author name'),
      t('Link'),
      t('Merge'),
      t('Retain as "alternate form"'),
    ),
    'candidates' => $candidates,
    '#prefix' => '<div id="biblio-author-edit-merge-table">',
    '#suffix' => '</div>',
  );
  $form['merge']['more_authors_search'] = array(
    '#type' => 'textfield',
    '#title' => t('Other authors which could be linked to this author'),
    '#autocomplete_path' => 'biblio/autocomplete/contributor',
    '#weight' => 12,
    '#required' => FALSE,
  );
  $form['merge']['more_authors_add'] = array(
    '#type' => 'submit',
    '#value' => t('Add author'),
    '#weight' => 15,
    '#submit' => array(
      'biblio_admin_author_edit_add_candidate',
    ),
    '#ajax' => array(
      'callback' => 'biblio_admin_author_edit_add_candidate_callback',
      'wrapper' => 'biblio-author-edit-merge-table',
    ),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  return $form;
}