You are here

function biblio_admin_author_edit_form_submit in Bibliography Module 6

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

File

./biblio.admin.inc, line 1833

Code

function biblio_admin_author_edit_form_submit($form, &$form_state) {
  $op = $form_state['values']['op'];
  if ($form_state['values']['drupal_uid'] == 0) {
    $uid = $form['drupal_uid']['#default_value'];
    $cid = 0;
  }
  else {
    $uid = $form_state['values']['drupal_uid'];
    $cid = $form_state['values']['cid'];
  }
  db_query("UPDATE {biblio_contributor_data} SET drupal_uid = 0 WHERE drupal_uid = %d", $uid);
  if ($uid) {
    $data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $uid)));
    $data['biblio_contributor_id'] = $cid;
    $v[] = serialize($data);
    db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", array_merge($v, array(
      $uid,
    )));
  }
  drupal_write_record('biblio_contributor_data', $form_state['values'], 'cid');

  // merge authors
  if (isset($form_state['values']['merge_authors']) && $op == t('Merge')) {
    $merge_authors = array_filter($form_state['values']['merge_authors']);
    if (count($merge_authors)) {
      $authors = implode(',', $merge_authors);
      db_query("UPDATE {biblio_contributor} SET cid={$form_state['values']['cid']} WHERE cid IN ({$authors})");
      db_query("DELETE FROM {biblio_contributor_data} WHERE cid IN ({$authors})");
    }
  }
  if (isset($form_state['values']['linked_authors'])) {
    foreach ($form_state['values']['linked_authors'] as $key => $value) {
      if ($value == 0) {
        db_query("UPDATE {biblio_contributor_data} SET aka={$key} WHERE cid={$key}");
      }
    }
  }
  if (isset($form_state['values']['link_authors'])) {

    //db_query("UPDATE {biblio_contributor_data} SET aka=$form_state['values']['cid'] WHERE cid IN ($authors)");
    foreach ($form_state['values']['link_authors'] as $key => $value) {
      db_query("UPDATE {biblio_contributor_data} SET aka={$form_state['values']['cid']} WHERE cid={$key}");
    }
  }
}