You are here

function library_title_js in Library 5.2

Same name and namespace in other branches
  1. 6.2 library.module \library_title_js()
  2. 6 library.module \library_title_js()
1 string reference to 'library_title_js'
library_menu in ./library.module
Implementation of hook_menu().

File

./library.module, line 583

Code

function library_title_js() {
  $title = $_POST['title'];
  $form_state = array(
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $nid = $form['nid']['#value'];
  $type = $form['type']['#value'];
  $title_label = $form['title_wrapper']['title']['#title'];
  unset($form['title_wrapper']['title']);
  $form['title_wrapper']['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($title_label),
    '#required' => TRUE,
    '#default_value' => $title,
    '#maxlength' => 255,
    '#ahah' => array(
      'path' => 'library/title_js',
      'wrapper' => 'title-wrapper',
    ),
    '#weight' => -5,
  );
  form_set_cache($form_build_id, $form, $form_state);
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
  );

  // Rebuild the form.
  $form = form_builder($form['type']['#value'] . '_node_form', $form, $form_state);
  $title_field = $form['title_wrapper']['title'];
  if (is_numeric($nid)) {
    $repeats = db_fetch_object(db_query_range("SELECT nid FROM {node} WHERE title = '%s' AND type = '%s' and nid <> %d", check_plain($title), $type, $nid, 0, 1));
  }
  else {
    $repeats = db_fetch_object(db_query_range("SELECT nid FROM {node} WHERE title = '%s' AND type = '%s'", $title, $type, 0, 1));
  }
  if ($repeats) {
    drupal_json(array(
      'status' => TRUE,
      'data' => drupal_render($title_field) . '<p class="ahah-new-content warning">WARNING: Title is not unique. You may want to add this as a copy to the existing node. ' . l('See Duplicate', 'node/' . $repeats->nid) . '</p>',
    ));
  }
  else {
    drupal_json(array(
      'status' => TRUE,
      'data' => drupal_render($title_field) . '<p class="ahah-new-content ok">Title is unique.</p>',
    ));
  }
}