# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/millennium/millennium.admin.inc
--- contributions/modules/millennium/millennium.admin.inc Base (1.1.2.32)
+++ contributions/modules/millennium/millennium.admin.inc Locally Modified (Based On 1.1.2.32)
@@ -273,6 +273,25 @@
 function millennium_admin_display() {
   $form = array();
 
+  $form['general'] = array(
+    '#type' => 'fieldset',
+    '#collapsible' => false,
+    '#title' => t("General"),
+  );
+  $form['general']['millennium_display_biblio_data'] = array(
+    '#type' => 'radios',
+    '#title' => t('Display bibiographic data table in node'),
+    '#options' => array(0 => "No", "full" => "Full view only", "teaser" => "Teaser & Full view"),
+    '#default_value' => variable_get('millennium_display_biblio_data', "teaser"),
+    '#description' => t('You might want to switch this off if you are mapping values into CCK fields. Recommended setting is "Teaser & Full view".'),
+  );
+  $form['general']['millennium_coverimage_baseurl'] = array(
+    '#type' => 'textfield',
+    '#title' => '('. t('Optional') .') '. t('URL for displaying cover images'),
+    '#default_value' => variable_get('millennium_coverimage_baseurl', ''),
+    '#description' => t('Use the placeholder !id in the URL where the ISBN or ISBN will be placed. You can also specify: !type (Biblio Type number), !tit (Title), !aut (Author(s))') .' '. t('For example') .': http://example.com/getimage?isbn=!id&type=!type',
+  );
+
   $form['holdings'] = array(
     '#type' => 'fieldset',
     '#collapsible' => false,
@@ -301,13 +320,6 @@
     '#description' => t('Comma-separated location names, as they appear on the WebOpac, that will be given priority over other locations. For example, entering "CSU" will match locations like "CSU General stacks" and "CSU Storage", showing only those in teasers and showing those above others in full record views.'),
   );
 
-  $form['millennium_coverimage_baseurl'] = array(
-    '#type' => 'textfield',
-    '#title' => '('. t('Optional') .') '. t('URL for displaying cover images'),
-    '#default_value' => variable_get('millennium_coverimage_baseurl', ''),
-    '#description' => t('Use the placeholder !id in the URL where the ISBN or ISBN will be placed. You can also specify: !type (Biblio Type number), !tit (Title), !aut (Author(s))') .' '. t('For example') .': http://example.com/getimage?isbn=!id&type=!type',
-  );
-
   $form['gbooks'] = array(
     '#type' => 'fieldset',
     '#collapsible' => false,
@@ -339,6 +351,37 @@
 }
 
 /**
+ * Callback for drupal_get_form for cck mapping settings form.
+ */
+function millennium_admin_cck_mapping() {
+  global $_millennium_field_labels;
+  $form = array();
+
+  // Get destination content type
+  $content_types = content_types();
+  $content_type = $content_types[variable_get('millennium_marc_node_type', 'page')];
+
+  // Build mapping destionation field options
+  $options = array(0 => t('<None>'));
+  foreach ($content_type['fields'] as $fieldname => $field) {
+    if ($field['type'] == 'text') {
+      $options[$fieldname] = $field['widget']['label'];
+    }
+  }
+
+  // Build form
+  foreach ($_millennium_field_labels as $biblio_name => $biblio_label) {
+    $form["millennium_cck_mapping_{$biblio_name}"] = array(
+      '#type' => 'select',
+      '#title' => $biblio_label,
+      '#options' => $options,
+      '#default_value' => variable_get("millennium_cck_mapping_{$biblio_name}", 0),
+    );
+  }
+  return system_settings_form($form);
+}
+
+/**
  * Callback for drupal_get_form for mapping settings form.
  */
 function millennium_admin_mapping() {
Index: contributions/modules/millennium/millennium.module
--- contributions/modules/millennium/millennium.module Base (1.13.2.33.2.2.2.88)
+++ contributions/modules/millennium/millennium.module Locally Modified (Based On 1.13.2.33.2.2.2.88)
@@ -606,6 +606,16 @@
     'access arguments' => array('administer millennium'),
     'file' => 'millennium.admin.inc',
   );
+  $items[MILLENNIUM_SETTINGS_PATH . '/fieldmap'] = array(
+    'title' => 'CCK field mapping',
+    'description' => 'Configure MARC import mapping settings.',
+    'type' => MENU_LOCAL_TASK,
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('millennium_admin_cck_mapping'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer millennium'),
+    'file' => 'millennium.admin.inc',
+  );
   $items[MILLENNIUM_SETTINGS_PATH . '/display'] = array(
     'title' => 'Display',
     'description' => 'Configure node view settings: cover images, holdings information, etc.',
@@ -817,7 +827,7 @@
       $gbooks_flag = variable_get('millennium_googlebooks', false);
       if ($gbooks_flag !== false) {
         if (
-            (!$page && $gbooks_flag == "teaser") || ($page && $gbooks_flag != "No")
+            (!$page && $gbooks_flag == "teaser") || ($page && $gbooks_flag !== "0")
           ) {
           drupal_add_js( drupal_get_path('module', 'millennium') .'/millennium_googlebooks.js');
           drupal_add_js(array('millennium' => array('gbooks' => array($search_isbn => $search_isbn))), 'setting');
@@ -859,10 +869,16 @@
         );
       }
 
+      // Show biblio data table
+      $biblio_table_flag = variable_get('millennium_display_biblio_data', 'teaser');
+      if (
+            (!$page && $biblio_table_flag == "teaser") || ($page && $biblio_table_flag !== "0")
+          ) {
       $node->content['millennium_biblio_data'] = array(
         '#value' => theme("millennium_biblio_data", $node->millennium_biblio_data, $page ? "full" : "teaser"),
         '#weight' => 0,
       );
+      }
 
       break;
   }
@@ -912,6 +928,7 @@
       return array(
         'marc' => array('info' => t('Millennium: MARC')),
         //'citation' => array('info' => t('Millennium: APA citation')),
+        'biblio_data' => array('info' => t('Millennium: bibliographic data table')),
       );
 
     case 'view':
@@ -937,6 +954,13 @@
             'content' => '<pre class="millennium marc">'. $marc_text .'</pre>',
           );
           break;
+        case 'biblio_data':
+          $table = theme("millennium_biblio_data", $node->millennium_biblio_data);
+          return array(
+            'subject' => t('Millennium: bibliographic data table'),
+            'content' => $table,
+          );
+          break;
       }
       return $blocks;
 
@@ -1518,6 +1542,9 @@
   // Store custom data in node
   $node["millennium_biblio_data"] = $biblio;
 
+  // Handle CCK mappings
+  millennium_cck_biblio_to_node($node, $biblio);
+
   // Return the node
   $nodeobject = (object)$node;
 
@@ -2791,3 +2818,48 @@
     'api' => 2,
   );
 }
+
+/**
+ * Map biblio data into CCK fields according to configuration
+ */
+function millennium_cck_biblio_to_node(&$node, $biblio_values) {
+  global $_millennium_field_labels;
+
+  // Get destination content type
+  $content_types = content_types();
+  $content_type = $content_types[variable_get('millennium_marc_node_type', 'page')];
+  
+  foreach ($_millennium_field_labels as $biblio_fieldname => $dummy) {
+    // Get mapping. Skip if none assigned
+    $dest_field = variable_get("millennium_cck_mapping_{$biblio_fieldname}", 0);
+    if (!$dest_field) {
+      continue;
+    }
+
+    // Get value to add to CCK field's values
+    $value = $biblio_values[$biblio_fieldname];
+    // Get max num. of values this field can hold.
+    $num_allowed_values = $content_type["fields"][$dest_field]["multiple"];
+    if ($num_allowed_values == 0) {
+      $num_allowed_values = 1;
+    }
+
+    if (is_array($value) && sizeof($value) > 0) {
+      // Handle multi-valued (array) biblio data values
+      // map into multiple CCK values up to that field's # of values limit
+      foreach ($biblio_values[$biblio_fieldname] as $count => $value) {
+        if (sizeof($node[$dest_field]) < $num_allowed_values) {
+          // Add to CCK field
+          $node[$dest_field][]['value'] = $value;
+        }
+      }
+    }
+    else {
+      // Handle single-valued (string) biblio data value
+      if ($value && sizeof($node[$dest_field]) < $num_allowed_values) {
+        // Add to CCK field
+        $node[$dest_field][]['value'] = $value;
+      }
+    }
+  }
+}
