Index: millennium.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/millennium/Attic/millennium.admin.inc,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 millennium.admin.inc
--- millennium.admin.inc	30 Oct 2009 21:47:16 -0000	1.1.2.5
+++ millennium.admin.inc	11 Nov 2009 14:43:06 -0000
@@ -353,22 +353,46 @@ $(document).ready(function () {
       if (choice == "list") {
         $("#range-fieldset").hide();
         $("#list-fieldset").show();
+        $("#edit-offline-refresh-wrapper").hide();
       }
       if (choice == "range") {
         $("#range-fieldset").show();
         $("#list-fieldset").hide();
+        $("#edit-offline-refresh-wrapper").hide();
       }
       if (choice == "existing") {
         $("#range-fieldset").hide();
         $("#list-fieldset").hide();
+        $("#edit-offline-refresh-wrapper").show();
       }
       $(this).blur();
     }
   );
+  $("input[@name=\'offline_refresh\']").change(
+    function() {
+      if ($("input[@name=\'offline_refresh\']:checked").val() == 1) {
+        $("#options-fieldset").hide();
+        $("#edit-using-cron").hide();
+      }
+      else {
+        $("#options-fieldset").show();
+        $("#edit-using-cron").show();
+      }
+    });
   $("input[@name=\'source\']").change();
 });
 </script>',
     );
+
+  $form['offline']['offline_refresh'] = array (
+    '#type' => 'checkbox',
+    '#title' => t('Offline update'),
+    '#description' => t('Choose this if you only want to refresh the internal database tables and taxonomy mappings offline from already stored MARC data.
+The WebOPAC will not be used to fetch the data. Only works in batch mode.'),
+    '#default_value' => 0,
+    '#return_value' => 1
+  );
+
   $form['list'] = array(
     '#type' => 'fieldset',
     '#title' => t('Record number listing'),
@@ -414,6 +438,7 @@ $(document).ready(function () {
     '#title' => t('Advanced options'),
     #'#collapsible' => TRUE,
     #'#collapsed' => TRUE,
+    '#attributes' =>  array('id' => 'options-fieldset'),
   );
   $form['options']['force_update'] = array(
     '#type' => 'radios',
@@ -421,6 +446,7 @@ $(document).ready(function () {
     '#options' => array(0 => t("Skip, leave untouched"), 1 => t("Update with current bibliographic data")),
     '#default_value' => variable_get('millennium_import_form_force_update', 1),
   );
+
     $form['options']['priority'] = array(
     '#type' => 'radios',
     '#title' => t('Cron priority for these items'),
@@ -601,21 +627,20 @@ function millennium_admin_queue_submit($
       }
 
       if (sizeof($item_recnums) > 0) {
-        millennium_batch_import($item_recnums, $form_state['values']['force_update']);
+        millennium_batch_import($item_recnums, $form_state['values']['force_update'], $form_state['values']['offline_refresh']);
        $form["#redirect"] = "admin/settings/millennium/batch_import";
       }
     }
   }
-
 }
 
 /**
  * Batch API implementation
  */
-function millennium_batch_import($item_recnums, $force_update = true) {
+function millennium_batch_import($item_recnums, $force_update = true, $offline_refresh = false) {
   $batch = array(
     'operations' => array(
-      array('millennium_batch_import_process', array($item_recnums, $force_update)),
+       array('millennium_batch_import_process', array($item_recnums, $force_update, $offline_refresh)),
     ),
     'finished' => 'millennium_batch_import_finished',
     'title' => t('Importing items from Millennium site @site', array('@site' => millennium_get_real_baseurl())),
@@ -630,7 +655,7 @@ function millennium_batch_import($item_r
 /**
 * Batch Operation Callback
 */
-function millennium_batch_import_process($item_recnums, $force_update, &$context) {
+function millennium_batch_import_process($item_recnums, $force_update, $offline_refresh, &$context) {
   timer_start("millennium_batch_import_process");
   require_once(drupal_get_path("module", "millennium") . "/millennium.import.inc");
 
@@ -653,10 +678,33 @@ function millennium_batch_import_process
   // Here we actually perform our processing on the current chunk.
   $chunk = $chunks[$context['sandbox']['current_item']];
   $context['sandbox']['tot_attempted'] += sizeof($chunk);
-  $fetched = millennium_mass_fetch($chunk);
-  $context['sandbox']['tot_notfound'] += sizeof($fetched['not_found']);
+
+  if (!$offline_refresh) {
+    $fetched = millennium_mass_fetch($chunk);
+    $context['sandbox']['tot_notfound'] += sizeof($fetched['not_found']);
+    $records = $fetched['found'];
+  }
+  else {
+    // Refresh the metadata from the database.
+    $records = array();
+
+    foreach ($chunk as $current) {
+      $biblio_data = db_result(db_query(
+        "SELECT biblio_data FROM {millennium_node_bib} WHERE bib_recnum = '%s'", $current));
+
+      $biblio_data = unserialize($biblio_data);
+      $marc = $biblio_data['marc'];
+
+      $records[] = array(
+        'bib_recnum' => $current,
+        'marc' => $marc
+      );
+    }
+    $force_update = true;
+  }
+
   // Import successful fetches only
-  foreach ($fetched['found'] as $data) {
+  foreach ($records as $data) {
     $result = millennium_process_record($data, $force_update);
 
     if ($result["success"] !== false) {
