array(), 'not_found' => array()); foreach ($chunks as $chunk) { $result = millennium_fetch_records_via_bookcart($chunk); $results['found'] = array_merge($results['found'], $result['found']); $results['not_found'] = array_merge($results['not_found'], $result['not_found']); #dpm($chunk); #dpm($result); #break; // Break if max_time has been reached. if (timer_read("millennium_fetch_recordpage_preload") / 1000 > $max_time) { break; } } dpm($results); // Read timer. $elapsed = round(timer_read("millennium_fetch_recordpage_preload") / 1000, 3); drupal_set_message("Tried to fetch:" . sizeof($item_numbers) . ". Found: " . sizeof($results['found']) . ". Elapsed time: {$elapsed}s"); } /** * Recieves an array of item numbers and returns an array of found item data including bib number and MARC keyed by item number, and an unkeyed array of not found items. * @param array $item_numbers An array of item numbers (i100000, i100002, ...) */ function millennium_fetch_records_via_bookcart($item_numbers) { static $headers = array(); $baseurl = millennium_get_real_baseurl(); if (sizeof($headers) == 0 ) { // Get a session cookie $result = drupal_http_request("{$baseurl}/record=i100000"); $session_cookie = preg_replace( '/.*(III_SESSION_ID=[a-zA-Z0-9\.]+).*/', '\1', $result->headers["Set-Cookie"] ); $headers = array('Cookie' => $session_cookie); } // Add items from $item_numbers array to the cart $path = '/search?/Xtest&searchscope=0&SORT=D/Xtest&searchscope=0&SORT=D&SUBKEY=test/1%2C7175%2C7175%2CE/2browse'; $post = "jumpref=Xtest&save=" . implode("&save=", $item_numbers) . "&save_func=save_marked"; $result = drupal_http_request("{$baseurl}{$path}", $headers, 'POST', $post); #dpm($result); #return; // Get cart contents: only item and bib numbers // From matches in list we can determine if some item numbers do not actually exist in the database. $path = "/search/?/++export/1,-1,-1,B/export"; $result = drupal_http_request("{$baseurl}{$path}", $headers, 'GET'); $ok = preg_match_all( '/name="save" value="(b[0-9]+)".*?browseEntryData.*?record=(i[0-9]+)/si', $result->data, $matches, PREG_SET_ORDER ); #dpm($matches); #return; // Start off assuming no items have been found foreach ($item_numbers as $num) { $not_found_items[$num] = $num; } // Store each found item's item <=> bib relationship $found_items = array(); foreach ($matches as $match) { $found_bib_number = $match[1]; $found_item_number = $match[2]; // Remove found items off $not_found_items list unset($not_found_items[$found_item_number]); $found_items[$found_item_number] = array( 'item_number' => $found_item_number, 'bib_number' => $found_bib_number ); } #dpm($item_to_bib); // Get MARC for all! $path = "/search/?.i100000/++export/1%2C-1%2C-1%2CB/export/"; $post = "email_addx=&email_subj=&ex_device=43&ex_format=50"; $result = drupal_http_request("{$baseurl}{$path}", $headers, 'POST', $post); #dpm($result->data); $ok = preg_match_all( '/
(.*?)<\/pre>/s',
    $result->data,
    $matches,
    PREG_SET_ORDER
  );
  #dpm($matches);
  // Assign marc to item numbers
  $index = 0;
  foreach ($found_items as $item => $dummy) {
    $found_items[$item]['marc'] = $matches[$index][1];
    $index++;
  }
  #dpm($found_items);

  // Clear the cart
  $path = "/search?/X/X/1,-1,-1,B/browse?clear_saves=1";
  $result = drupal_http_request("{$baseurl}{$path}", $headers, 'GET');

  // Return results
  return array('found' => $found_items, 'not_found' => $not_found_items);
}