diff --git a/library.actions.inc b/library.actions.inc
index 1488f50..64bcd7f 100644
--- a/library.actions.inc
+++ b/library.actions.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: library.actions.inc,v 1.7 2009/11/23 19:06:53 jastraat Exp $
+// $Id: library.actions.inc,v 1.1.2.1.2.5 2009/11/23 19:37:39 jastraat Exp $
 
 /**
  * @file
@@ -7,14 +7,14 @@
  */
 
 /**
- * Implementation of hook_hook_info()
+ * Implementation of hook_hook_info().
  */
 function library_hook_info() {
   $op = array();
   foreach (library_actions() as $aid => $action) {
     $op['after_'. library_clean_action_name($action['name'])] = array('runs when' => t('After a '. $action['name']));
   }
-  
+
   return array(
     'library' => array(
       'library' => $op
@@ -66,15 +66,16 @@ function library_action_info() {
 }
 
 /**
-* Implementation of a Drupal action.
-* Renews a library item if it is checked out and due dates are enabled.
-*/
+ * Implementation of a Drupal action.
+ * Renews a library item if it is checked out and due dates are enabled.
+ */
 
 function library_renew_action(&$object, $context = array()) {
+  #TODO: recheck context
   $patron = $context['patron'];
   $item = $context['item'];
   $item_obj = library_load($item['id']);
-  if ($item_obj && !empty($item_obj->last_transaction_id) && !empty($item_obj->last_transaction_name) && !empty($item_obj->last_patron_id) && !empty($item_obj->last_due_date) && 
+  if ($item_obj && !empty($item_obj->last_transaction_id) && !empty($item_obj->last_transaction_name) && !empty($item_obj->last_patron_id) && !empty($item_obj->last_due_date) &&
       $item_obj->last_patron_id == $patron['nid'] && $item_obj->in_circulation == LIBRARY_CIRCULATION && $item_obj->library_status == LIBRARY_ITEM_UNAVAILABLE) {
 
     $type = $item_obj->type;
@@ -91,7 +92,7 @@ function library_renew_action(&$object, $context = array()) {
 }
 
 /**
- * Implementation of hook_mail()
+ * Implementation of hook_mail().
  */
 function library_mail($key, &$message, $params) {
   $language = $message['language'];
@@ -107,13 +108,13 @@ function library_mail($key, &$message, $params) {
         '%site_name' => variable_get('site_name', 'Drupal'),
         '%patron_name' => $context['patron']['name'],
         '%patron_email' => $context['patron']['email'],
-        '%patron_id' => $context['patron']['nid'], 
-        '%node_url' => url('node/'. $context['item']['nid'], array('absolute' => TRUE)),  
+        '%patron_id' => $context['patron']['nid'],
+        '%node_url' => url('node/'. $context['item']['nid'], array('absolute' => TRUE)),
         '%node_type' => $context['item']['node_type'],
         '%title' => $context['item']['title'],
-        '%item_id' => $context['item']['id'],    
-        '%barcode' => $context['item']['barcode'], 
-        '%transaction_name' => $context['transaction']['action_name'], 
+        '%item_id' => $context['item']['id'],
+        '%barcode' => $context['item']['barcode'],
+        '%transaction_name' => $context['transaction']['action_name'],
         '%notes' => $context['transaction']['notes'],
       );
       $subject = strtr($context['subject'], $variables);
@@ -215,7 +216,7 @@ function library_send_email_action(&$object, $context) {
   if ($recipient == '%patron_email') {
       $recipient = $context['patron']['email'];
   }
-  
+
   $params = array('context' => $context);
 
   if (drupal_mail('library', 'action_send_email', $recipient, $language, $params)) {
@@ -229,7 +230,7 @@ function library_send_email_action(&$object, $context) {
 function library_mail_tokens($params, $language) {
   $items = '';
   foreach ($params['items'] as $id => $values) {
-    $items .= $values['item_name'] .' (Due '. format_date($values['due_date'], 'short') .') '; 
+    $items .= $values['item_name'] .' (Due '. format_date($values['due_date'], 'short') .') ';
   }
   $tokens = array(
     '!patronname' => $params['patron']['patron_name'],
@@ -243,7 +244,7 @@ function library_mail_tokens($params, $language) {
  */
 function library_email_form_submit($form, &$form_state) {
   if ($form_state['values']['op'] == t('Send E-mail')) {
-    
+
     drupal_set_message(t('The email has been sent.'));
   }
   $form_state['redirect'] = 'library-items';
diff --git a/library.admin.inc b/library.admin.inc
index ceab47f..b3d7095 100644
--- a/library.admin.inc
+++ b/library.admin.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: library.admin.inc,v 1.6 2009/11/23 19:06:53 jastraat Exp $
+// $Id: library.admin.inc,v 1.1.2.1.2.4 2009/11/23 19:37:39 jastraat Exp $
 
 /**
  * @file
@@ -50,7 +50,7 @@ function library_admin_settings() {
   $when_reference = array();
   foreach (library_actions() as $aid => $action) {
     switch ($action['status_change']) {
-      case LIBRARY_ACTION_NO_CHANGE: 
+      case LIBRARY_ACTION_NO_CHANGE:
         $when_available[$aid] = $action['name'];
         $when_unavailable[$aid] = $action['name'];
         $when_reference[$aid] = $action['name'];
@@ -107,7 +107,7 @@ function library_admin_settings() {
       '#title' => t('Display Associated Taxonomy Terms in Library View'),
       '#default_value' => variable_get('library_taxonomy_display', array()),
       '#options' => $vocabularies,
-      '#description' => t('Select the vocabularies from which you would like to display taxonomy terms. If no vocabularies are selected, terms will not be displayed.'),
+      '#description' => t('Choose the vocabularies from which you would like to display taxonomy terms. If no vocabularies are selected, terms will not be displayed.'),
     );
   }
   $form['library_text_display'] = array(
@@ -138,6 +138,48 @@ function library_admin_settings() {
     '#size' => 20,
     '#maxlength' => 20,
   );
+
+  if (module_exists('content_profile')) {
+    $form['library_content_profile'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('content profile for library actions'),
+      '#description' => t('select these fields to be queried when you are querying for a patron.'),
+    );
+    $f=db_query("select field_name,label from {content_node_field_instance} where type_name='profile' and widget_module='text'");
+    while ($i=db_fetch_object($f)) {
+      $form['library_content_profile']['library_content_profile_' . $i->field_name] = array(
+        '#type' => 'checkbox',
+        '#title' => t($i->label . ' (' . $i->field_name . ')'),
+        '#default_value' => variable_get('library_content_profile_' . $i->field_name, 0),
+      );
+    }
+    $form['library_content_profile']['library_content_profile_nodetitle'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('node title field'),
+      '#default_value' => variable_get('library_content_profile_nodetitle', 0),
+    );
+  }
+
+  if (module_exists('profile')) {
+    $form['library_profile'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('profile for library actions'),
+      '#description' => t('select these fields to be queried when you are querying for a patron.'),
+    );
+    $f=db_query("select title,name from {profile_fields} where type='textfield'");
+    while ($i=db_fetch_object($f)) {
+      $form['library_profile']['library_profile_' . $i->name] = array(
+        '#type' => 'checkbox',
+        '#title' => t($i->title . ' (' . $i->name . ')'),
+        '#default_value' => variable_get('library_profile_' . $i->name, 0),
+      );
+    }
+  }
+
+  if (module_exists('profile') && module_exists('content_profile')) {
+    drupal_set_message(t('You have the Profile module and the Content Profile module activated. This is not supported by the library module!'), 'error');
+  }
+
   return system_settings_form($form);
 }
 
@@ -202,7 +244,7 @@ function library_admin_settings_overdue() {
     '#default_value' => _library_mail_text('notify_overdue_body'),
     '#rows' => 15,
   );
-  
+
   return system_settings_form($form);
 }
 
@@ -254,7 +296,7 @@ function library_admin_action() {
         $show_delete = FALSE;
       }
     }
-  
+
     $form['name'] = array(
       '#type' => 'textfield',
       '#title' => t('Action name'),
diff --git a/library.info b/library.info
index 2b5f738..e5c5a34 100644
--- a/library.info
+++ b/library.info
@@ -1,7 +1,6 @@
-; $Id: library.info,v 1.4 2008/09/12 20:25:01 jastraat Exp $
+; $Id: library.info,v 1.1.2.1.2.2 2008/09/12 20:21:08 jastraat Exp $
 name 		= "Library"
 description 	= "Include content types in a library. CCK, Trigger, and Views are recommended."
-dependencies[] = patron
 package 	= Library
 core 		= "6.x"
 
diff --git a/library.install b/library.install
index 1aa8086..b28aff2 100644
--- a/library.install
+++ b/library.install
@@ -1,13 +1,12 @@
 <?php
-// $Id: library.install,v 1.5 2009/11/23 19:06:53 jastraat Exp $
+// $Id: library.install,v 1.1.2.1.2.3 2009/11/23 19:37:39 jastraat Exp $
 
 /**
  * @author Jess Straatmann
- * @file library.install
- * Install and uninstall all required databases.
- * Also do incremental database updates.
+ * @file
+ * Install, update and uninstall functions for the library module.
  */
- 
+
 function library_schema() {
   $schema['library'] = array(
     'description' => t('Determines if a library item may be checked out.'),
@@ -49,10 +48,10 @@ function library_schema() {
         'description' => t('Timestamp for when the item was created.'),
         'not null' => TRUE,
         'default' => 0),
-     ),
+      ),
      'indexes' => array(
       'nid'     => array('nid'),
-     ),
+      ),
     'primary key' => array('id'),
   );
   $schema['library_transactions'] = array(
@@ -73,7 +72,7 @@ function library_schema() {
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE),
-      'patron_id' => array(
+      'uid' => array(
         'description' => t('The associated customer.'),
         'type' => 'int',
         'unsigned' => TRUE,
@@ -102,12 +101,12 @@ function library_schema() {
     ),
     'indexes' => array(
       'item_id'     => array('item_id'),
-      'patron_id'     => array('patron_id'),
+      'uid'     => array('uid'),
       'action_aid'  => array('action_aid'),
       ),
     'primary key' => array('tid'),
     );
- $schema['library_actions'] = array(
+  $schema['library_actions'] = array(
     'description' => t('The table where library transactions are stored.'),
     'fields' => array(
       'aid' => array(
@@ -134,7 +133,7 @@ function library_schema() {
 }
 
 /**
- * Implementation of hook_install()
+ * Implementation of hook_install().
  */
 function library_install() {
   drupal_install_schema('library');
@@ -142,7 +141,7 @@ function library_install() {
   db_query("INSERT INTO {library_actions} (name, status_change) VALUES ('%s', %d)", 'Check In', 2);
   global $base_url;
   // Notify of changes
-  drupal_set_message(t('Library module successfully installed. You can configure library settings <a href="@link">here</a>. To start creating library items, edit one or more content types to be included in the library.', array('@link' => $base_url .'/admin/settings/library')));
+  drupal_set_message(st('Library module successfully installed. You can configure library settings <a href="@link">here</a>. To start creating library items, edit one or more content types to be included in the library.', array('@link' => $base_url .'/admin/settings/library')));
 
 }
 
@@ -191,6 +190,48 @@ function library_uninstall() {
   cache_clear_all(null, 'cache_menu');
   cache_clear_all(null, 'cache_page');
 
-  drupal_set_message(t('Library module successfully uninstalled'));
+  drupal_set_message(st('Library module successfully uninstalled'));
 }
 
+
+function library_update_6201() {
+  if (module_exists('patron')) {
+    if (variable_get('patron_is_user', FALSE)) {
+      $items = array();
+      $items[] = update_sql("UPDATE {library_transactions} lt JOIN {library_patrons} lp on lt.patron_id=lp.nid SET lt.patron_id=lp.patron_uid");
+      $items[] = update_sql("ALTER TABLE {library_transactions} CHANGE patron_id  uid int(10)");
+      drupal_set_message(st('The table library_patrons is not removed on purpose, to give you the option of migrating over name or ID fields.', 'warning'));
+      return $items;
+    }
+    else {
+      drupal_set_message(st('We cannot automatically update your library module. You have to convert your patrons to users by hand.'), 'error');
+    }
+  }
+}
+
+function library_update_6202() {
+//Copied from patron/patron.install and added dropping the library_patrons table
+  variable_del('patron_is_user');
+  variable_del('patron_use_barcodes');
+  variable_del('patron_autocreate');
+
+  $result = db_query("SELECT nid FROM {node} WHERE type = 'patron'");
+
+  if ($result) {
+    while ($row = db_fetch_object($result)) {
+      set_time_limit(5);
+      node_delete($row->nid);
+    }
+  }
+
+  drupal_uninstall_schema('patron');
+  db_query("DROP TABLE {library_patrons}");
+
+  // Clear the cache tables.
+  cache_clear_all(null, 'cache');
+  cache_clear_all(null, 'cache_filter');
+  cache_clear_all(null, 'cache_menu');
+  cache_clear_all(null, 'cache_page');
+
+  drupal_set_message(t('Library patron module successfully uninstalled'));
+}
diff --git a/library.module b/library.module
index 17bc31c..c005643 100644
--- a/library.module
+++ b/library.module
@@ -68,13 +68,14 @@ define('LIBRARY_ACTION_TYPE_AVAILABLE', 2);
 define('LIBRARY_RESULTS_PER_PAGE', 50);
 
 /**
-* Valid permissions for this module
-* @return array An array of valid permissions for this module
-*/
+ * Valid permissions for this module
+ * @return array An array of valid permissions for this module
+ */
 function library_perm() {
   $permissions = array(
-    'administer library', 
+    'administer library',
     'administer transactions',
+    'search library patrons',
     'view library history',
     'view own library history',
   );
@@ -84,25 +85,14 @@ function library_perm() {
   return $permissions;
 }
 
-/* 
+/*
  * Determine whether a user may perform any library action
  */
 function library_action_access($aid) {
-  $may_view_patron = FALSE;
-  if (user_access('view patron content')) {
-    $may_view_patron = TRUE;
-  }
-  else {
-    global $user;
-    $user_patron = patron_load_by_uid($user->uid);
-    if (is_object($user_patron)) {
-      $may_view_patron = TRUE;
-    }
-  }
-  if (user_access('administer transactions') && $may_view_patron) {
+  if (user_access('administer transactions')) {
     return TRUE;
   }
-  elseif ($aid && $may_view_patron) {
+  elseif ($aid) {
     $action = library_get_action($aid);
     if ($action->name) {
       return user_access('submit library '. $action->name);
@@ -111,14 +101,14 @@ function library_action_access($aid) {
   return FALSE;
 }
 
-function library_history_access($node) {
+function library_history_user_access() {
   if (user_access('view library history')) {
     return TRUE;
   }
   elseif (user_access('view own library history')) {
     global $user;
-    $user_patron = patron_load_by_uid($user->uid);
-    if (is_object($user_patron) && $user_patron->nid == $node->nid) {
+    $user_page=user_load(arg(1));
+    if (is_object($user_page) && $user_page->uid == $user->uid) {
       return TRUE;
     }
   }
@@ -126,11 +116,11 @@ function library_history_access($node) {
 }
 
 /**
- * Implementation of hook_help()
+ * Implementation of hook_help().
  */
 function library_help($path, $arg) {
   global $user;
-  
+
   switch ($path) {
     case 'admin/settings/library':
       return t('<p>Below are display options for library items and lists. </p>');
@@ -147,12 +137,12 @@ function library_content_extra_fields($type_name) {
   $extra = array();
   if (module_exists('content') && variable_get('library_'. $type_name, LIBRARY_ITEM_NOT_IN_LIBRARY) == LIBRARY_ITEM_IN_LIBRARY) {
     $extra['item_wrapper'] = array('label' => 'Library', 'weight' => -4);
-  }  
+  }
   return $extra;
 }
 
 /**
- * Implementation of hook_form_alter()
+ * Implementation of hook_form_alter().
  */
 function library_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'node_type_form' && isset($form['identity']['type']) && $form['#node_type']->type <> 'patron') {
@@ -186,8 +176,8 @@ function library_form_alter(&$form, $form_state, $form_id) {
         '#tree' => FALSE,
         '#prefix' => '<div class="clear-block" id="title-wrapper">',
         '#suffix' => '</div>',
-        '#weight' => -5,     
-      ); 
+        '#weight' => -5,
+      );
       $form['title_wrapper']['title'] = array(
         '#type' => 'textfield',
         '#title' => check_plain($type->title_label),
@@ -200,7 +190,7 @@ function library_form_alter(&$form, $form_state, $form_id) {
         ),
         '#weight' => -5,
       );
-    } 
+    }
 
       // Add a wrapper for the items and more button.
       $form['item_wrapper'] = array(
@@ -218,7 +208,7 @@ function library_form_alter(&$form, $form_state, $form_id) {
       // Add the current choices to the form.
       for ($delta = 0; $delta < $item_count; $delta++) {
         $form['item_wrapper']['items'][$delta] = _library_item_form($delta, $node->items[$delta]);
-      }      
+      }
 
       // We name our button 'library_more' to avoid conflicts with other modules using
       // AHAH-enabled buttons with the id 'more'.
@@ -232,7 +222,7 @@ function library_form_alter(&$form, $form_state, $form_id) {
           'wrapper' => 'library-items',
           'method' => 'replace',
           'effect' => 'fade',
-         ),
+        ),
       );
       $form['#submit'][] = 'library_node_form_submit';
     }
@@ -330,8 +320,8 @@ function library_form_alter(&$form, $form_state, $form_id) {
 }
 
 function library_field_submit($form_id, &$form_values) {
-   $values = $form_values['values'];
-   variable_set('library_display_field_'. $values['field_name'], $values['library_display_field_'. $values['field_name']]);
+  $values = $form_values['values'];
+  variable_set('library_display_field_'. $values['field_name'], $values['library_display_field_'. $values['field_name']]);
 }
 
 function library_search_box_form_submit($form, &$form_state) {
@@ -391,22 +381,22 @@ function _library_item_form($delta, $item = array()) {
   );
   if (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES) {
     $form['barcode'] = array(
-      '#type' => 'textfield', 
+      '#type' => 'textfield',
       '#title' => t('Barcode'),
       '#default_value' => isset($item['barcode']) ? $item['barcode'] : '',
       '#required' => TRUE,
       '#parents' => array('items', $delta, 'barcode'),
-    ); 
+    );
   }
   $form['in_circulation'] = array(
-    '#type' => 'checkbox', 
+    '#type' => 'checkbox',
     '#title' => t('Reference Only'),
     '#default_value' => isset($item['in_circulation']) ? $item['in_circulation'] : LIBRARY_CIRCULATION,
     '#return_value' => LIBRARY_REFERENCE_ONLY,
     '#parents' => array('items', $delta, 'in_circulation'),
-  ); 
+  );
   $form['notes'] = array(
-    '#type' => 'textfield', 
+    '#type' => 'textfield',
     '#title' => t('Notes'),
     '#size' => 20,
     '#maxlength' => 128,
@@ -438,8 +428,8 @@ function library_init() {
 }
 
 /**
-* Menu callback; loads a library object
-*/
+ * Menu callback; loads a library object
+ */
 function library_load($item_id) {
   if (!is_numeric($item_id)) {
     return FALSE;
@@ -450,7 +440,7 @@ function library_load($item_id) {
     if ($item->in_circulation == LIBRARY_CIRCULATION && $item->library_status == LIBRARY_ITEM_UNAVAILABLE) {
       $last = library_get_last_transaction_by_item($item, LIBRARY_ACTION_TYPE_UNAVAILABLE);
       if ($last) {
-        $item->last_patron_id = $last->patron_id;
+        $item->last_patron_id = $last->uid;
         $item->last_transaction_id = $last->tid;
         $item->last_transaction_name = $last->action_name;
         if (!empty($last->duedate)) {
@@ -477,8 +467,16 @@ function library_menu() {
     'title' => 'History',
     'page callback' => 'library_history',
     'page arguments' => array(1),
-    'access callback' => 'library_history_access',
-    'access arguments' => array(1),
+    'access arguments' => array('view library history'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2,
+    'file' => 'library.pages.inc',
+  );
+  $items['user/%user/library/history'] = array(
+    'title' => 'History',
+    'page callback' => 'library_history',
+    'page arguments' => array(1),
+    'access callback' => 'library_history_user_access',
     'type' => MENU_LOCAL_TASK,
     'weight' => 2,
     'file' => 'library.pages.inc',
@@ -501,7 +499,7 @@ function library_menu() {
     'file' => 'library.pages.inc',
   );
   $items['library-items/overdue'] = array(
-    'title' => 'Overdue Items', 
+    'title' => 'Overdue Items',
     'page callback' => 'library_overdue_items',
     'access arguments' => array('administer transactions'),
     'type' => MENU_SUGGESTED_ITEM,
@@ -554,9 +552,9 @@ function library_menu() {
     'file' => 'library.admin.inc',
   );
   $items['library-items/autocomplete'] = array(
-    'title' => t('Library Autocomplete'),
-    'page callback' => 'library_autocomplete', 
-    'access arguments' => array('access content'), 
+    'title' => 'Library Autocomplete',
+    'page callback' => 'library_autocomplete',
+    'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
     'file' => 'library.admin.inc',
   );
@@ -572,6 +570,12 @@ function library_menu() {
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,
   );
+  $items['patrons/autocomplete'] = array(
+    'title' => 'Patron Autocomplete',
+    'page callback' => 'library_patron_autocomplete',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK
+  );
   return $items;
 }
 
@@ -650,7 +654,7 @@ function library_title_js() {
     ),
     '#weight' => -5,
   );
-  
+
   form_set_cache($form_build_id, $form, $form_state);
 
   $form += array(
@@ -677,7 +681,7 @@ function library_title_js() {
 }
 
 /**
- * Implementation of hook_search()
+ * Implementation of hook_search().
  */
 function library_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
   switch ($op) {
@@ -743,10 +747,10 @@ function library_search($op = 'search', $keys = NULL, $skip_access_check = FALSE
         $join2 .= ' LEFT JOIN {node_counter} nc ON nc.nid = i.sid';
         $total += $weight;
       }
-      
-      // When all search factors are disabled (ie they have a weight of zero), 
-      // the default score is based only on keyword relevance and there is no need to 
-      // adjust the score of each item. 
+
+      // When all search factors are disabled (ie they have a weight of zero),
+      // the default score is based only on keyword relevance and there is no need to
+      // adjust the score of each item.
       if ($total == 0) {
         $select2 = 'i.relevance AS score';
         $total = 1;
@@ -754,7 +758,7 @@ function library_search($op = 'search', $keys = NULL, $skip_access_check = FALSE
       else {
         $select2 = implode(' + ', $ranking) .' AS score';
       }
-      
+
       // Do search.
       $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join1, $conditions1 . (empty($where1) ? '' : ' AND '. $where1), $arguments1, $select2, $join2, $arguments2, 'ORDER BY n.title, score DESC');
 
@@ -766,7 +770,7 @@ function library_search($op = 'search', $keys = NULL, $skip_access_check = FALSE
         // Build the node body.
         $node = node_load($item->sid);
         $node_rows = array();
-    
+
         $node_rows = library_get_table_row($node, $var);
         foreach ($node_rows as $row) {
           $results[] = $row;
@@ -778,7 +782,7 @@ function library_search($op = 'search', $keys = NULL, $skip_access_check = FALSE
 }
 
 /**
- * Implementation of hook_search_page()
+ * Implementation of hook_search_page().
  */
 function library_search_page($results) {
   $var = library_get_table_header();
@@ -792,7 +796,7 @@ function library_search_page($results) {
 }
 
 /**
- * Implementation of hook_nodeapi()
+ * Implementation of hook_nodeapi().
  */
 function library_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
   if (library_item_in_library($node)) {
@@ -852,7 +856,7 @@ function library_load_items($node) {
       $items[$row]['barcode'] = check_plain($library_item->barcode);
       $items[$row]['notes'] = check_plain($library_item->notes);
       $row++;
-    } 
+    }
   }
   else {
     db_query('INSERT INTO {library} (nid, in_circulation, library_status, created) VALUES (%d, %d, %d, %d)', $node->nid, LIBRARY_CIRCULATION, LIBRARY_ITEM_AVAILABLE, time());
@@ -896,8 +900,9 @@ function library_validate_items($node) {
     $items = $node->items;
     if ($items) {
       global $base_path;
+
       //Check that each barcode is unique
-      foreach ($items as $key => $item) {	           
+      foreach ($items as $key => $item) {
         $result = db_result(db_query("SELECT COUNT(*) FROM {library} WHERE barcode = '%s' AND barcode <> ''", $item['barcode']));
         if ((empty($item['id']) && $result) || (!empty($item['id']) && $result > 1)) {
           form_set_error('items]['. $key .'][barcode', t('The barcode %barcode already exists. Please enter a different barcode.', array('%barcode' => $item['barcode'])));
@@ -908,7 +913,7 @@ function library_validate_items($node) {
       form_set_error('items', t('You must enter information for at least one item.'));
     }
   }
-} 
+}
 
 /**
  * Check whether a given item (based on its item type) is part of the library
@@ -928,18 +933,18 @@ function library_item_in_library($node = NULL, $item_id = NULL) {
 
 /**
  * Returns a list of overdue library items
- */ 
+ */
 function library_get_overdue_items() {
   //Select all the nodes that have ever had an item made unavailable
-  $items = db_query("SELECT id FROM {library} WHERE library_status = %d", LIBRARY_ITEM_UNAVAILABLE); 
+  $items = db_query("SELECT id FROM {library} WHERE library_status = %d", LIBRARY_ITEM_UNAVAILABLE);
   $overdueitems = array();
   while ($result = db_fetch_object($items)) {
     $item = library_load($result->id);
     if (!empty($item->last_patron_id) && !empty($item->last_due_date) && (time() > $item->last_due_date)) {
-      $patron = node_load($item->last_patron_id);
+      $patron = user_load($item->last_patron_id);
       if (!isset($overdueitems[$item->last_patron_id]['patron']['patron_email'])) {
-        $overdueitems[$item->last_patron_id]['patron']['patron_email'] = $patron->email;
-        $overdueitems[$item->last_patron_id]['patron']['patron_name'] = $patron->name_first .' '. $patron->name_last;
+        $overdueitems[$item->last_patron_id]['patron']['patron_email'] = $patron->mail;
+        $overdueitems[$item->last_patron_id]['patron']['patron_name'] = $patron->name;
       }
       $overdueitems[$item->last_patron_id]['items'][$item->id] = array('item_name' => $item->title, 'nid' => $item->nid, 'due_date' => $item->last_due_date, 'in_circulation' => $item->in_circulation);
     }
@@ -953,11 +958,11 @@ function library_get_overdue_items() {
  * @param $checkout_date
  *   The date an item was made unavailable
  * @param $action
- *   The clean name of the action performed 
+ *   The clean name of the action performed
  * @param $type
  *   The node type
  * @returns a UNIX TIMESTAMP if due dates are enabled else it returns NULL
- */ 
+ */
 function library_get_due_date($checkout_date = NULL, $action, $type) {
   if (empty($checkout_date)) {
     $checkout_date = time();
@@ -975,7 +980,7 @@ function library_get_due_date($checkout_date = NULL, $action, $type) {
  * Check to see if due dates are enabled for any actions
  *
  * @returns BOOLEAN
- */ 
+ */
 function library_duedates_enabled($type = NULL) {
   if (is_null($type)) {
     $duedates = 0;
@@ -999,10 +1004,10 @@ function library_duedates_enabled($type = NULL) {
 }
 
 function library_get_transactions_by_item($item) {
-  $result = db_query('SELECT lt.created, lt.tid, la.aid, la.name as "action_name", 
-                      la.status_change, lt.patron_id, lt.item_id, lt.duedate, lt.notes, l.in_circulation, l.barcode, n.title as "item_name", n.nid
-                      FROM {library_transactions} lt, {library_actions} la, {library} l, {node} n 
-                      WHERE la.aid = lt.action_aid AND n.nid = l.nid AND lt.item_id = l.id AND l.id = %d 
+  $result = db_query('SELECT lt.created, lt.tid, la.aid, la.name as "action_name",
+                      la.status_change, lt.uid, lt.item_id, lt.duedate, lt.notes, l.in_circulation, l.barcode, n.title as "item_name", n.nid
+                      FROM {library_transactions} lt, {library_actions} la, {library} l, {node} n
+                      WHERE la.aid = lt.action_aid AND n.nid = l.nid AND lt.item_id = l.id AND l.id = %d
                       ORDER BY lt.created DESC', $item->id);
   while ($transaction = db_fetch_object($result)) {
     $transaction->library_status = isset($item->library_status) ? $item->library_status : LIBRARY_ITEM_AVAILABLE;
@@ -1017,28 +1022,19 @@ function library_get_transactions_by_item($item) {
 }
 
 function library_get_transactions_by_node($node) {
-  if ($node->type == 'patron') {
-    $temp_transactions = library_get_transactions_by_patron($node);
+  foreach ($node->items as $instance) {
+    $item = (object) $instance;
+    $temp_transactions = library_get_transactions_by_item($item);
     if (!empty($temp_transactions)) {
-      $transactions[] = $temp_transactions;
-    }
-  }
-  else {
-    foreach ($node->items as $instance) {
-      $item = (object) $instance;
-      $temp_transactions = library_get_transactions_by_item($item);
-      if (!empty($temp_transactions)) { 
-        $transactions[] = library_get_transactions_by_item($item);
-      }
+      $transactions[] = library_get_transactions_by_item($item);
     }
   }
   return $transactions;
 }
 
-function library_get_transactions_by_patron($node) {
-  $result = db_query('SELECT lt.created, lt.tid, la.aid, la.name as "action_name", la.status_change, lt.patron_id, lt.item_id, lt.duedate, lt.notes, n.title as "item_name", n.nid FROM {library_transactions} lt, {library_actions} la, {node} n WHERE la.aid = lt.action_aid AND n.nid = lt.nid AND lt.patron_id = %d ORDER BY lt.created DESC', $node->nid);
-  
-  $items_result = db_query('SELECT DISTINCT item_id FROM {library_transactions} WHERE patron_id = %d', $node->nid);
+function library_get_transactions_by_patron($user_page) {
+  $result = db_query('SELECT lt.created, lt.tid, la.aid, la.name as "action_name", la.status_change, lt.uid, lt.item_id, lt.duedate, lt.notes, n.title as "item_name", n.nid FROM {library_transactions} lt, {library_actions} la, {node} n WHERE la.aid = lt.action_aid AND n.nid = lt.nid AND lt.uid = %d ORDER BY lt.created DESC', $user_page->uid);
+  $items_result = db_query('SELECT DISTINCT item_id FROM {library_transactions} WHERE uid = %d', $user_page->uid);
   $statuses = array();
   $barcodes = array();
   $circulation = array();
@@ -1065,7 +1061,7 @@ function library_get_transactions_by_patron($node) {
 
 function library_get_transaction_by_tid($tid) {
   if (isset($tid) && is_numeric($tid)) {
-    $result = db_fetch_object(db_query('SELECT lt.created, la.name as "action_name", la.status_change, lp.nid as "patron_id", lp.name_last, lp.name_first, n.title as "item_name", n.type as "item_type", lt.item_id as "item_id", lt.nid as "nid", lt.duedate, lt.notes FROM {library_transactions} lt, {library_actions} la, {library_patrons} lp, {node} n WHERE la.aid = lt.action_aid AND lp.nid = lt.patron_id AND n.nid = lt.nid AND lt.tid = %d', $tid));
+    $result = db_fetch_object(db_query('SELECT lt.created, la.name as "action_name", la.status_change, lt.uid,  n.title as "item_name", n.type as "item_type", lt.item_id as "item_id", lt.nid as "nid", lt.duedate, lt.notes FROM {library_transactions} lt, {library_actions} la, {node} n WHERE la.aid = lt.action_aid AND n.nid = lt.nid AND lt.tid = %d', $tid));
     return $result;
   }
   else {
@@ -1074,13 +1070,13 @@ function library_get_transaction_by_tid($tid) {
 }
 
 /**
- * @param $node 
+ * @param $node
  *   Node object or array
  * @param $transaction_type
  *   (optional) Type of transaction to return
- * @return 
- *   Transaction array or NULL if none found 
- */ 
+ * @return
+ *   Transaction array or NULL if none found
+ */
 function library_get_last_transaction_by_item($item, $type = NULL) {
   $transactions = library_get_transactions_by_item($item);
   if (isset($transactions)) {
@@ -1107,9 +1103,9 @@ function library_get_last_transaction_by_item($item, $type = NULL) {
 /**
  * @param $excluded
  *   (optional) Numeric status change type of actions to exclude
- * @return 
+ * @return
  *   Array of actions
- */ 
+ */
 function library_actions($actions = NULL, $account = NULL) {
   if (is_array($actions) && !empty($actions)) {
     $result = db_query("SELECT name, aid, status_change from {library_actions} WHERE aid IN('%s') ORDER BY name, aid, status_change", implode(', ', $actions));
@@ -1175,13 +1171,10 @@ function library_get_action_links($item) {
   }
   $actions = library_actions($aids, $user);
   $action_links = array();
-  
+  #TODO: replaced view patron permissions with new one, proper solution?
   $patron_id = '';
-  if (!user_access('view patron content')) {
-    $user_patron = patron_load_by_uid($user->uid);
-    if (is_object($user_patron)) {
-      $patron_id = $user_patron->nid;
-    }
+  if (!user_access('search library patrons')) {
+      $patron_id = $user->uid;
   }
 
   foreach ($actions as $aid => $action) {
@@ -1201,7 +1194,7 @@ function library_get_action_links($item) {
  * Get a list of all library item nodes
  * @return
  *   An array of library items
- */ 
+ */
 function library_get_items_group_by_node() {
   $count_select = "SELECT COUNT(*) FROM {node} WHERE status = 1 AND nid IN (SELECT nid from {library}) ORDER BY title";
   $result = pager_query("SELECT nid FROM {node} WHERE status = 1 AND nid IN (SELECT nid from {library}) ORDER BY title", LIBRARY_RESULTS_PER_PAGE, 0, $count_select);
@@ -1247,12 +1240,12 @@ function library_get_item_types($op = 'types') {
 
 /**
  * Implementation of hook_cron().
- */ 
+ */
 
 function library_cron() {
   $last_update = variable_get('library_cron', 0);
   $next_update = $last_update + (24 * 60 * 60);
-  
+
   if (time() > $next_update && library_duedates_enabled()) {
     $records = library_get_overdue_items();
     if (!empty($records)) {
@@ -1331,7 +1324,7 @@ function library_get_table_header() {
   if (module_exists('content')) {
     $content_fields = library_get_content_fields();
   }
-  
+
   foreach ($content_fields as $type) {
     foreach ($type as $field) {
       if (!isset($fields[$field['field_name']]) && variable_get('library_display_field_'. $field['field_name'], 0) == 1) {
@@ -1350,7 +1343,7 @@ function library_get_table_header() {
       $header[]['data'] = $field['widget']['label'];
     }
   }
-  
+
   if ($results['display_quantity']) {
     $header[]['data'] = t('Quantity');
   }
@@ -1373,7 +1366,7 @@ function library_get_table_row($node, $var) {
 
   $row[] = l($node->title, 'node/'. $node->nid);
   if ($var['display_categories']) {
-    $categories = array(); 
+    $categories = array();
 
     foreach (variable_get('library_taxonomy_display', array()) as $key => $vocab) {
       if ($vocab) {
@@ -1395,7 +1388,7 @@ function library_get_table_row($node, $var) {
   if (!empty($var['fields'])) {
     foreach ($var['fields'] as $name => $field) {
       $return = '';
-      if (isset($node->content[$field['field_name']])) { 
+      if (isset($node->content[$field['field_name']])) {
         $return = drupal_render($node->content[$field['field_name']]);
       }
       $row[] = $return;
@@ -1425,8 +1418,8 @@ function library_views_api() {
 }
 
 /**
- * Implementation of hook_theme()
- */ 
+ * Implementation of hook_theme().
+ */
 function library_theme() {
   return array(
     'library_admin_new_action' => array(
@@ -1524,4 +1517,107 @@ function library_get_status_text($item) {
     $text = variable_get('library_unavailable_noduedates_text', 'UNAVAILABLE');
   }
   return $text;
-}
\ No newline at end of file
+}
+
+/**
+ * Retrieve a pipe delimited string of autocomplete suggestions for existing patron.
+ */
+function library_patron_autocomplete($string) {
+  $matches = array();
+  if (module_exists('content_profile')) {
+    $passedstring=array();
+    $passedstring[]=check_plain($string);
+    $f=db_query("SELECT field_name FROM {content_node_field_instance} WHERE type_name='profile' AND widget_module='text'");
+    while ($a=db_fetch_object($f)) {
+      if (variable_get('library_content_profile_' . $a->field_name, FALSE)) {
+          if ($concat)
+            $concat .= ",', '," . $a->field_name . "_value";
+          else
+            $concat=$a->field_name . "_value";
+          $or .= " OR LOWER(" . $a->field_name . "_value) LIKE LOWER('%%%s%%')";
+          $passedstring[]=check_plain($string);
+      }
+    }
+    if ($concat) {
+      if (variable_get('library_content_profile_nodetitle', FALSE)) {
+        $passedstring[]=check_plain($string);
+        $result = db_query_range("SELECT n.uid,CONCAT(u.name,' (',n.title,', '," . $concat . ",')') as name FROM {node} n JOIN {content_type_profile} c ON c.vid=n.vid JOIN {users} u ON n.uid=u.uid WHERE (LOWER(n.title) LIKE LOWER('%%%s%%') OR LOWER(u.name) LIKE LOWER('%%%s%%')  " . $or .") AND n.type='profile'", $passedstring, 0, 10);
+      }
+      else {
+        $result = db_query_range("SELECT n.uid,CONCAT(u.name,' ('," . $concat . ",')') as name FROM {node} n JOIN {content_type_profile} c ON c.vid=n.vid JOIN {users} u ON n.uid=u.uid WHERE (LOWER(u.name) LIKE LOWER('%%%s%%') " . $or .") AND n.type='profile'", $passedstring, 0, 10);
+      }
+    }
+    else {
+      $result = db_query_range("SELECT uid,name FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", check_plain($string), 0, 10);
+    }
+
+  }
+  elseif (module_exists('profile')) {
+    /*
+     * Support for profile module
+     */
+    $f=db_query("SELECT fid,name FROM {profile_fields} WHERE type='textfield'"); #meh
+    while ($a=db_fetch_object($f)) {
+      if (variable_get('library_profile_' . $a->name, FALSE)) {
+          if ($fids)
+                  $fids .= "OR fid='" . $a->fid . "'";
+          else
+                  $fids .= "fid='" . $a->fid . "'";
+      }
+    }
+    if ($fids) {
+      $result = db_query_range("SELECT u.uid,CONCAT(u.name,' (',value,')') as name FROM {users} u LEFT JOIN {profile_values} v ON u.uid=v.uid WHERE (LOWER(name) LIKE LOWER('%%%s%%') or LOWER(value) LIKE LOWER('%%%s%%')) AND ( " . $fids . " OR fid IS NULL)", check_plain($string), check_plain($string), 0, 10);
+    }
+    else {
+      $result = db_query_range("SELECT uid,name FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", check_plain($string), 0, 10);
+    }
+
+  }
+  else {
+    $result = db_query_range("SELECT uid,name FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", check_plain($string), 0, 10);
+  }
+
+
+  while ($patron = db_fetch_object($result)) {
+        $matches[$patron->name .' [uid:'. $patron->uid .']'] = check_plain($patron->name);
+  }
+
+  print drupal_to_js($matches);
+  exit();
+}
+
+
+
+
+/**
+ * Implementation of hook_rules_event_info().
+ * @ingroup rules
+ */
+function library_rules_event_info() {
+  return array(
+    'library_checkout' => array(
+      'label' => t('An item is checked out'),
+      'module' => 'Library',
+      'arguments' => array(
+        'user' => array('type' => 'number', 'label' => t('User to whom item is checked out.')),
+        'item' => array('type' => 'number', 'label' => t('Item which is checked out.')),
+      ),
+    ),
+    'library_checkin' => array(
+      'label' => t('An item is checked in'),
+      'module' => 'Library',
+      'arguments' => array(
+        'user' => array('type' => 'number', 'label' => t('User who had item checked out.')),
+        'item' => array('type' => 'number', 'label' => t('Item which is checked in.')),
+       ),
+    ),
+    'library_nochange' => array(
+      'label' => t('An item status was updated but remains unchanged'),
+      'module' => 'Library',
+      'arguments' => array(
+        'user' => array('type' => 'number', 'label' => t('User who had item checked out.')),
+        'item' => array('type' => 'number', 'label' => t('Item which is checked in.')),
+      ),
+    ),
+  );
+}
diff --git a/library.pages.inc b/library.pages.inc
index 8b9ee5c..39461a3 100644
--- a/library.pages.inc
+++ b/library.pages.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: library.pages.inc,v 1.9 2009/11/23 19:06:53 jastraat Exp $
+// $Id: library.pages.inc,v 1.1.2.1.2.7 2009/11/23 19:37:39 jastraat Exp $
 
 /**
  * @file
@@ -7,35 +7,37 @@
  */
 
 function library_transaction_form(&$form_state, $aid, $item = NULL) {
+   
   $patron_id = arg(4);
 
   if ($patron_id) {
-    $patron = node_load($patron_id);
+    $patron = user_load($patron_id);
   }
-  elseif (!user_access('view patron content')) {
-    global $user;
-    $user_patron = patron_load_by_uid($user->uid);
+  elseif (!user_access('search library patrons')) {
+    global $user;      
+    $user_patron = user_load($user->uid);
     if (is_object($user_patron)) {
       $patron = $user_patron;
     }
     else {
-      drupal_set_message('You do not have sufficient permissions.', 'error');
+      drupal_set_message(t('You do not have sufficient permissions.'), 'error');
       drupal_goto('/');
     }
+
   }
-  
+
   if ($aid) {
     $action = library_get_action($aid);
     if ($action->name) {
       drupal_set_title($action->name);
     }
     else {
-      drupal_set_message('Invalid action.', 'error');
+      drupal_set_message(t('Invalid action.'), 'error');
       drupal_goto('');
     }
   }
   else {
-    drupal_set_message('No action was selected.', 'error');
+    drupal_set_message(t('No action was selected.'), 'error');
     drupal_goto('');
   }
 
@@ -53,7 +55,7 @@ function library_transaction_form(&$form_state, $aid, $item = NULL) {
     '#type' => 'value',
     '#value' => $action->status_change,
   );
-  
+
   if ($item) {
     $form['item_id'] = array(
       '#type' => 'value',
@@ -72,19 +74,19 @@ function library_transaction_form(&$form_state, $aid, $item = NULL) {
   else {
     $form['item_id'] = library_autocomplete_input($item);
   }
-  
+
   if ($patron) {
     $form['patron_id'] = array(
       '#type' => 'value',
-      '#value' => $patron->nid,
+      '#value' => $patron->uid,
     );
     $form['patron_id_set'] = array(
       '#type' => 'value',
-      '#value' => $patron->nid,
+      '#value' => $patron->uid,
     );
     $form['patron_display'] = array(
       '#type' => 'item',
-      '#value' => $patron->name_first .' '. $patron->name_last,
+      '#value' => $patron->name,
       '#title' => t('Patron'),
     );
     if (user_access('view patron content') && $action->status_change == LIBRARY_ACTION_NO_CHANGE) {
@@ -104,7 +106,7 @@ function library_transaction_form(&$form_state, $aid, $item = NULL) {
     $form['patron_id'] = array(
       '#type' => 'textfield',
       '#title' => t('Patron'),
-      '#default_value' => ($patron ? $patron->title .' [nid:'. $patron->nid .']' : ''),
+      '#default_value' => ($patron ? $patron->name .' [uid:'. $patron->uid .']' : ''),
       '#autocomplete_path' => 'patrons/autocomplete',
       '#required' => TRUE
     );
@@ -114,7 +116,7 @@ function library_transaction_form(&$form_state, $aid, $item = NULL) {
     '#type' => 'textarea',
     '#title' => t('Message'),
     '#required' => FALSE,
-    '#maxlength' => 250, 
+    '#maxlength' => 250,
     '#default_value' => '',
     '#description' => t('If you are reserving an item, make sure to include the date and time you would like it to be ready.'),
   );
@@ -124,7 +126,7 @@ function library_transaction_form(&$form_state, $aid, $item = NULL) {
   );
   $form['#validate'][] = 'library_transaction_form_validate';
   $form['#submit'][] = 'library_transaction_form_submit';
-  
+
   return $form;
 }
 
@@ -139,31 +141,27 @@ function library_transaction_form_validate($form, &$form_state) {
   //Validate patron information
   if ($form_state['values']['patron_id']) {
     if ($form_state['values']['patron_id_set'] && is_numeric($form_state['values']['patron_id'])) {
-      $nid = $form_state['values']['patron_id'];
-      $n_patron = node_load($nid);
-      if (empty($n_patron)) {
-        form_set_error('patron_id', t('Invalid Patron ID.'));
+      $user = $form_state['values']['patron_id'];
+      $u_patron = user_load($user);
+      if (empty($u_patron)) {
+        form_set_error('patron_id', t('Invalid Patron user ID.'));
       }
     }
     else {
-      preg_match('/^(?:\s*|(.*) )?\[\s*nid\s*:\s*(\d+)\s*\]$/', $form_state['values']['patron_id'], $matches);
+      preg_match('/^(?:\s*|(.*) )?\[\s*uid\s*:\s*(\d+)\s*\]$/', $form_state['values']['patron_id'], $matches);
       if (!empty($matches)) {
-        // explicit nid
-        list($temp, $title, $nid) = $matches;
-        if (!empty($title) && ($n_patron = node_load($nid))) {
-          if ($title != $n_patron->title) {
-            form_set_error('patron_id', t('Library Patron: Name mismatch. Please check your selection.'));
-          }
+        // explicit uid
+        list($temp, $name, $uidp) = $matches;
+        if (!($u_patron = user_load($uidp))) {
+          form_set_error('patron_id', t('Library Patron: Something went wrong when loading the user.'));
         }
       }
     }
-    if (!empty($n_patron)) {
-      $form_state['values']['patron_email'] = $n_patron->email;
-      $form_state['values']['patron_uid'] = $n_patron->patron_uid;
-      $form_state['values']['patron_id'] = $n_patron->nid;
-      $form_state['values']['patron_name'] = $n_patron->title;
-      $form_state['values']['patron_name_last'] = $n_patron->name_last;
-      $form_state['values']['patron_name_first'] = $n_patron->name_first;
+    if (!empty($u_patron)) {
+      $form_state['values']['patron_email'] = $u_patron->mail;
+      $form_state['values']['patron_id'] = $u_patron->uid;
+      $form_state['values']['patron_name'] = $u_patron->name;
+
     }
     else {
       form_set_error('patron_id', t('You must specify a library patron.'));
@@ -172,7 +170,7 @@ function library_transaction_form_validate($form, &$form_state) {
   else {
     form_set_error('patron_id', t('You must specify a library patron.'));
   }
-  
+
   if ($form_state['values']['item_id']) {
     if ($form_state['values']['item_id_set'] && is_numeric($form_state['values']['item_id'])) {
       $item = library_load($form_state['values']['item_id']);
@@ -203,17 +201,17 @@ function library_transaction_form_validate($form, &$form_state) {
     if ($form_state['values']['action_aid']) {
       if ($item->in_circulation == LIBRARY_REFERENCE_ONLY && $action->status_change <> LIBRARY_ACTION_NO_CHANGE) {
         form_set_error('action_aid', t('This item is not in circulation.'));
-      } 
+      }
       elseif ($item->library_status == LIBRARY_ITEM_AVAILABLE && $action->status_change == LIBRARY_ITEM_TYPE_AVAILABLE) {
         form_set_error('action_aid', t('This item is already available.'));
       }
       elseif ($item->library_status == LIBRARY_ITEM_UNAVAILABLE &&  $action->status_change == LIBRARY_ITEM_TYPE_UNAVAILABLE) {
         form_set_error('action_aid', t('This item is not currently available.'));
       }
-      elseif ($item->library_status == LIBRARY_ITEM_UNAVAILABLE && $n_patron->nid <> $item->last_patron_id) {
+      elseif ($item->library_status == LIBRARY_ITEM_UNAVAILABLE && $u_patron->uid <> $item->last_patron_id) {
         form_set_error('patron_id', t('This item was made unavailable by a different patron.  Only that patron can perform actions on it.'));
       }
-    }  
+    }
   }
 }
 
@@ -232,14 +230,17 @@ function library_transaction_form_submit($form, &$form_state) {
     if ($period > 0) {
       $duedate = library_get_due_date($now, $clean, $type);
     }
+    rules_invoke_event('library_checkout', $form_state['values']['patron_id'], $form_state['values']['item_id']);
     $new_status = LIBRARY_ITEM_UNAVAILABLE;
   }
   elseif ($form_state['values']['action_status_change'] == LIBRARY_ACTION_TYPE_AVAILABLE) {
-    $new_status = LIBRARY_ITEM_AVAILABLE;   
+    rules_invoke_event('library_checkin', $form_state['values']['patron_id'], $form_state['values']['item_id']);
+    $new_status = LIBRARY_ITEM_AVAILABLE;
   }
-  db_query("INSERT {library_transactions} (nid, item_id, patron_id, action_aid, duedate, notes, created) VALUES (%d, %d, %d, %d, %d, '%s', %d)", $form_state['values']['nid'], $form_state['values']['item_id'], $form_state['values']['patron_id'], $form_state['values']['action_aid'], $duedate, check_plain($form_state['values']['notes']), $now);
+  db_query("INSERT {library_transactions} (nid, item_id, uid, action_aid, duedate, notes, created) VALUES (%d, %d, %d, %d, %d, '%s', %d)", $form_state['values']['nid'], $form_state['values']['item_id'], $form_state['values']['patron_id'], $form_state['values']['action_aid'], $duedate, check_plain($form_state['values']['notes']), $now);
   if ($form_state['values']['action_status_change'] > LIBRARY_ACTION_NO_CHANGE) {
     db_query("UPDATE {library} set library_status = %d WHERE id = %d", $new_status, $form_state['values']['item_id']);
+    rules_invoke_event('library_nochange', $form_state['values']['patron_id'], $form_state['values']['item_id']);
   }
 
   drupal_set_message(t('The '. $form_state['values']['action_name'] .' was successful.'));
@@ -267,7 +268,8 @@ function library_transaction_view($tid) {
     $list[] = t("Date: @action_date", array('@action_date' => format_date($transaction->created, 'custom', 'M j, Y')));
     $list[] = t("Item: ". l($transaction->item_name, 'node/'. $transaction->nid));
     $list[] = t("Action: @action", array('@action' => $transaction->action_name));
-    $list[] = t("Patron: ". l($transaction->name_first .' '. $transaction->name_last, 'node/'. $transaction->patron_id));
+    $patron=user_load($transaction->uid);
+    $list[] = t("Patron: ". l($patron->name, 'user/'. $transaction->uid));
     if (!empty($transaction->duedate)) {
       $list[] = t('Due Date: @due_date', array('@due_date' => format_date($transaction->duedate, 'custom', 'M j, Y')));
     }
@@ -284,11 +286,13 @@ function library_transaction_view($tid) {
 /**
  * Menu callback; show the transaction history of a single node.
  */
-function library_history($node) { 
-  $duedate_enabled = library_duedates_enabled($node->type);  
+function library_history($node) {
+  $duedate_enabled = library_duedates_enabled($node->type);
   global $user;
 
-  if ($node->type == 'patron') {
+  $user_page=user_load(arg(1));
+
+  if (is_object($user_page)) {
     $is_patron = TRUE;
   }
   else {
@@ -302,9 +306,13 @@ function library_history($node) {
     }
     $header[] = t('Actions');
     $rows = array();
-
-    $transactions = library_get_transactions_by_node($node);
-
+    if ($is_patron) {
+      $transactions = array();
+      $transactions[] = library_get_transactions_by_patron($user_page);
+    }
+    else {
+      $transactions = library_get_transactions_by_node($node);
+    }
     if (!empty($transactions[0])) {
       foreach ($transactions as $value) {
         $last_item = '';
@@ -320,18 +328,18 @@ function library_history($node) {
             $duedate = '';
           }
           if (user_access('administer transactions')) {
-            $detail_link = l('View Details', 'library-items/transaction/view/'. $transaction->tid);
+            $detail_link = l(t('View Details'), 'library-items/transaction/view/'. $transaction->tid);
           }
           if ($cur_item <> $last_item) {
-            $item = array('id' => $transaction->item_id, 'library_status' => $transaction->library_status, 'last_patron_id' => $transaction->patron_id, 'in_circulation' => $transaction->in_circulation);
+            $item = array('id' => $transaction->item_id, 'library_status' => $transaction->library_status, 'last_patron_id' => $transaction->uid, 'in_circulation' => $transaction->in_circulation);
             $links = library_get_action_links($item);
             if (!empty($links)) {
               $action_link = implode(" | ", $links);
             }
-          } 
+          }
           $temp_array = array($created, $transaction->action_name, $transaction->notes);
-          if (isset($duedate)) { 
-            $temp_array[] = $duedate; 
+          if (isset($duedate)) {
+            $temp_array[] = $duedate;
           }
           if (!empty($detail_link) && !empty($action_link)) {
             $temp_array[] = $detail_link .' | '. $action_link;
@@ -368,7 +376,6 @@ function library_history($node) {
 function library_display_items() {
   $var = library_get_table_header();
   $header = $var['header'];
-
   $nodes = library_get_items_group_by_node();
   $rows = array();
   foreach ($nodes as $node) {
@@ -398,7 +405,7 @@ function library_overdue_items() {
           $item = array('library_status' => LIBRARY_ITEM_UNAVAILABLE, 'id' => $id, 'last_patron_id' => $patron_id, 'in_circulation' => $values['in_circulation']);
           $links = implode(" | ", library_get_action_links($item));
 
-          $rows[] = array($values['item_name'], $patron_name, format_date($values['due_date'], 'small'), l('Item Details', 'node/'. $values['nid']) .' | '. $links);
+          $rows[] = array($values['item_name'], $patron_name, format_date($values['due_date'], 'small'), l(t('Item Details'), 'node/'. $values['nid']) .' | '. $links);
           $item = array();
         }
       }
diff --git a/library.theme.inc b/library.theme.inc
index f8e7590..e2b2639 100644
--- a/library.theme.inc
+++ b/library.theme.inc
@@ -1,5 +1,5 @@
 <?php
-// $Id: library.theme.inc,v 1.5 2009/11/23 19:06:53 jastraat Exp $
+// $Id: library.theme.inc,v 1.1.2.1.2.3 2009/11/23 19:37:39 jastraat Exp $
 
 /**
  * @file
@@ -41,7 +41,7 @@ function theme_library_admin_new_action($form) {
 function theme_library_items($node) {
   $barcodes = (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES);
   $display_status = (variable_get(library_status_display, 0) == 1);
-  
+
   $items = $node->items;
   $header = array(t('Copy'));
   if ($barcodes) {
@@ -130,4 +130,4 @@ function theme_library_items_field($form) {
   $output = theme('table', $headers, $rows);
   $output .= drupal_render($form);
   return $output;
-}
\ No newline at end of file
+}
diff --git a/patron/patron.info b/patron/patron.info
deleted file mode 100644
index d764b1b..0000000
--- a/patron/patron.info
+++ /dev/null
@@ -1,7 +0,0 @@
-; $Id: patron.info,v 1.3 2008/08/13 23:20:16 jastraat Exp $
-name 		= "Patron"
-description 	= "Create a patron content type for use with the library module.  This module must be enabled if you wish to use library."
-package 	= Library
-core 		= "6.x"
-
-
diff --git a/patron/patron.install b/patron/patron.install
deleted file mode 100644
index 928233a..0000000
--- a/patron/patron.install
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-// $Id: patron.install,v 1.3 2010/05/24 17:07:33 jastraat Exp $
-
-/**
- * @author Jess Straatmann
- * @file patron.install
- * Install and uninstall all required databases.
- * Also do incremental database updates.
- */
- 
-function patron_schema() {
- $schema['library_patrons'] = array(
-    'description' => t('The table where patron information is stored.'),
-    'fields' => array(
-      'nid' => array(
-        'description' => t('The primary identifier for a node.'),
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE),
-      'name_last' => array(
-        'description' => t('The patron last name.'),
-        'type' => 'varchar',
-        'length' => 60,
-        'not null' => TRUE,
-        'default' => ''),
-      'name_first' => array(
-        'description' => t('The patron first name.'),
-        'type' => 'varchar',
-        'length' => 60,
-        'not null' => TRUE,
-        'default' => ''),
-      'email' => array(
-        'description' => t('The patron email.'),
-        'type' => 'varchar',
-        'length' => 60,
-        'not null' => TRUE,
-        'default' => ''),
-      'patron_uid' => array(
-        'description' => t('Drupal user id of the user corresponding to this patron.'),
-        'type' => 'int',
-        'not null' => FALSE,
-        'unsigned' => TRUE,
-        'default' => NULL),
-      'barcode' => array(
-        'description' => t('Card number for this patron.'),
-        'type' => 'varchar',
-        'length' => 60,
-        'not null' => FALSE,
-        'default' => ''),
-      'disabled' => array(
-        'description' => t('Boolean indicating whether the patron account is disabled.'),
-        'type' => 'int',
-        'not null' => TRUE,
-        'default' => 0),
-      ),
-    'indexes' => array(
-      ),
-    'unique keys' => array(
-      'email'     => array('email'),
-      'patron_uid'     => array('patron_uid'),
-      ),
-    'primary key' => array('nid'),
-    );
-  return $schema;
-}
-
-/**
- * Implementation of hook_install()
- */
-function patron_install() {
-  drupal_install_schema('patron');
-
-  // Notify of changes
-  drupal_set_message(t("Library patron module successfully installed."));
-
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function patron_uninstall() {
-  variable_del('patron_is_user');
-  variable_del('patron_use_barcodes');
-  variable_del('patron_autocreate');
-  
-  $result = db_query("SELECT nid FROM {node} WHERE type = 'patron'");
-  
-  if ($result) {
-    while ($row = db_fetch_object($result)) {
-      set_time_limit(5);
-      node_delete($row->nid);
-    }
-  }
-  
-  drupal_uninstall_schema('patron');
-  
-  // Clear the cache tables.
-  cache_clear_all(null, 'cache');
-  cache_clear_all(null, 'cache_filter');
-  cache_clear_all(null, 'cache_menu');
-  cache_clear_all(null, 'cache_page');
-
-  drupal_set_message(t('Library patron module successfully uninstalled'));
-}
-
-function patron_update_1() {
-  $ret = array();
-  $ret[] = update_sql("UPDATE {library_patrons} SET patron_uid = NULL WHERE patron_uid = 0");
-  return $ret;
-}
diff --git a/patron/patron.module b/patron/patron.module
deleted file mode 100644
index d7600b4..0000000
--- a/patron/patron.module
+++ /dev/null
@@ -1,619 +0,0 @@
-<?php
-// $Id: patron.module,v 1.8 2010/05/24 17:07:33 jastraat Exp $ 
-
-/**
- * Library patrons do not have barcodes.
- */
-define('PATRON_NO_BARCODES', 0);
-
-/**
- * Library Patrons have barcodes.
- */
-define('PATRON_BARCODES', 1);
-
-/**
- * Library Patrons are not users.
- */
-define('PATRON_NOT_USER', 0);
-
-/**
- * Library Patrons may be users.
- */
-define('PATRON_USER', 1);
-
-/**
- * Patron may use the library
- */
-define('PATRON_ENABLED', 0);
-
-/**
- * Patron may not currently use the library
- */
-define('PATRON_DISABLED', 1);
-
-/**
-* Valid permissions for this module
-* @return array An array of valid permissions for this module
-*/
-function patron_perm() {
-  return array(
-    'create patron content', 
-    'edit own patron content', 
-    'edit any patron content',
-    'delete patron content',
-    'view patron content',
-    'administer patrons');
-}
-
-/**
- * Implementation of hook_help()
- */
-function patron_help($path, $arg) {
-  switch ($path) {
-    case 'patrons/email':
-      if ($arg[2]) {
-        return t('<p>The form below will send an email to the patron specified. If no patron is specified, the email will be sent to all active patrons.</p>', array());
-      }
-      else {
-        return t('<p>The form below will send an email to all active patrons.</p>', array());
-      }
-  }
-}
-
-/**
- * Implementation of hook_node_info().
- */
-function patron_node_info() {
-  return array(
-    'patron' => array(
-      'name' => t('Library Patron'),
-      'module' => 'patron',
-      'description' => t('Library patrons are individuals with whom library items may be associated.'),
-      'has_title' => TRUE,
-      'title_label' => t('Complete Name'),
-      'has_body' => FALSE,
-    )
-  );
-}
-
-/**
- * Implemenation of hook_access().
- */
-function patron_access($op, $node, $account) {
-  if ($op == 'view') {
-    //Come back and change this to change patron_uid
-    if (user_access('view patron content', $account) || ((variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER) && ($account->uid == $node->patron_uid))) {
-      return TRUE;
-    }
-    else {
-      return FALSE;
-    }
-  }
-  if ($op == 'create') {
-    return user_access('create patron content', $account);
-  }
-
-  if ($op == 'update') {
-    if (user_access('edit any patron content', $account) || (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER && user_access('edit own patron content', $account) && ($account->uid == $node->patron_uid))) {
-      return TRUE;
-    }
-  }
-  if ($op == 'delete') {
-    return user_access('delete patron content', $account);
-  }
-}
-
-/** 
- * Implementation of hook_db_rewrite_sql().
- */
-function patron_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
-  if ($query == '' && $primary_table == 'n' && $primary_field = 'nid' && empty($args)) {
-    $excluded_types = array('patron');
-    if (!empty($excluded_types)) {
-      $where = " n.type NOT IN ('". join("','", $excluded_types) ."') ";
-      return array('where' => $where);
-    }
-  }
-}
-
-/**
- * Implemenation of hook_insert().
- */
-function patron_insert($node) {
-  if (empty($node->patron_uid)) {
-    db_query("INSERT INTO {library_patrons} (nid, name_last, name_first, email, patron_uid, barcode, disabled) VALUES (%d, '%s', '%s', '%s', NULL, '%s', %d)", $node->nid, $node->name_last, $node->name_first, $node->email, $node->barcode, $node->disabled);
-  }
-  else {
-    db_query("INSERT INTO {library_patrons} (nid, name_last, name_first, email, patron_uid, barcode, disabled) VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)", $node->nid, $node->name_last, $node->name_first, $node->email, $node->patron_uid, $node->barcode, $node->disabled);
-  }
-}
-
-/**
- * Implemenation of hook_update().
- */
-function patron_update($node) {
-  if (empty($node->patron_uid)) {
-    db_query("UPDATE {library_patrons} SET name_last = '%s', name_first = '%s', email = '%s', patron_uid = NULL, barcode = '%s', disabled = %d WHERE nid = %d", $node->name_last, $node->name_first, $node->email, $node->barcode, $node->disabled, $node->nid); 
-  }
-  else {
-    db_query("UPDATE {library_patrons} SET name_last = '%s', name_first = '%s', email = '%s', patron_uid = %d, barcode = '%s', disabled = %d WHERE nid = %d", $node->name_last, $node->name_first, $node->email, $node->patron_uid, $node->barcode, $node->disabled, $node->nid); 
-  }
-}
-
-/**
- * Implemenation of hook_delete().
- */
-function patron_delete($node) {
-  if (module_exists('library')) {
-    db_query("DELETE FROM {library_transactions} WHERE patron_id = %d", $node->nid); 
-  }
-  db_query("DELETE FROM {library_patrons} WHERE nid = %d", $node->nid); 
-}
-
-/**
- * Implemenation of hook_nodeapi().
- */
-function patron_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
-  if ($node->type == 'patron') {
-    switch ($op) {
-      case 'view':
-        $node->title = $node->name_first .' '. $node->name_last;
-        if (user_access('view patron content')) {
-          $node->content['email'] = array(
-            '#value' => '<div class="field-patron-email">'. patron_email_link($node) .'</div>',
-            '#weight' => 0,
-          );
-        }
-        if ($node->disabled == PATRON_DISABLED) {
-          $node->content['disabled'] = array(
-            '#value' => '<div class="field-patron-disabled">Disabled</div>',
-            '#weight' => 2,
-          );
-        }
-        if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER && !empty($node->patron_uid) && user_access('access user profiles')) {
-          $patron_user = user_load($node->patron_uid);
-          if ($patron_user) {
-            $node->content['patron_uid'] = array(
-              '#value' => '<div class="field-patron-user"><label>Drupal User: </label>'. l($patron_user->name, 'user/'. $patron_user->uid) .'</div>',
-              '#weight' => -3,
-            );
-          }
-        }
-        if (variable_get('patron_use_barcodes', PATRON_NO_BARCODES) == PATRON_BARCODES) {
-          $node->content['barcode'] = array(
-            '#value' => '<div class="field-patron-barcode"><label>Card Number: </label>'. $node->barcode .'</div>',
-            '#weight' => -1,
-          );
-        }
-        global $user;
-        watchdog('library', '%user viewed patron %name', array('%user' => $user->name, '%name' => $node->title));
-        break;
-
-      case 'presave':
-        if (!empty($node->email) && variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER) {
-          $patron_uid = db_result(db_query_range("SELECT uid from {users} where mail= '%s'", $node->email, 0, 1));
-          if ($patron_uid) {
-            $node->patron_uid = $patron_uid;
-            $node->uid = $patron_uid;   
-          }
-          else {
-            $node->patron_uid = NULL;
-          }
-        } 
-        break;
-    }
-  }
-}
-
-/**
- * Implemenation of hook_load().
- */
-
-function patron_load($node) {
-  $additions = db_fetch_object(db_query("SELECT * FROM {library_patrons} WHERE nid = %d", $node->nid));
-  return $additions;
-}
-
-/**
- * Implementation of hook_form().
- */
-function patron_form(&$node) {
-  $type = node_get_types('type', $node);
-  $patrons_are_users = variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER;
-  $patron_uid = NULL;
-  if ($patrons_are_users && !empty($node->email)) {
-    $exists = db_result(db_query_range("SELECT uid from {users} where mail= '%s'", $node->email, 0, 1));
-    if ($exists) {
-      $patron_uid = $exists;
-    }
-  }
-
-  // We need to define form elements for the node's title and body.
-  if ($type->has_title) {
-    $form['title'] = array(
-      '#type' => 'textfield',
-      '#title' => 'Patron Identifier (ID or Complete Name)',
-      '#required' => TRUE,
-      '#default_value' => $node->title,
-      '#description' => t('This must be unique.'),
-      '#weight' => -5
-    );
-  }
-  if ($type->has_body) {
-    $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
-  }
-
-  $form['required_for_library'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Required Library Fields'),
-    '#collapsed' => FALSE,
-    '#weight' => -3
-  );
-  // Now we define the form elements specific to our node type.
-  $form['required_for_library']['name_first'] = array(
-    '#type' => 'textfield',
-    '#title' => t('First Name'),
-    '#default_value' => $node->name_first,
-    '#size' => 10,
-    '#maxlength' => 30,
-    '#weight' => -4,
-    '#required' => TRUE
-  );
-  $form['required_for_library']['name_last'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Last Name'),
-    '#default_value' => $node->name_last,
-    '#size' => 10,
-    '#maxlength' => 30,
-    '#weight' => -3,
-    '#required' => TRUE
-  );
-  $form['required_for_library']['email'] = array(
-    '#type' => 'textfield',
-    '#title' => t('E-mail'),
-    '#default_value' => $node->email,
-    '#size' => 20,
-    '#maxlength' => 30,
-    '#weight' => -1,
-    '#required' => TRUE,
-  );
-  if ($patrons_are_users) {
-    $form['required_for_library']['email']['#autocomplete_path'] = 'patrons/js/email';
-    if (!user_access('administer patrons') || !user_access('access user profiles')) {
-      $form['required_for_library']['email']['#access'] = FALSE;
-    }
-    $form['required_for_library']['email']['#description'] = t('If this email address matches an existing Drupal user, that user will be associated with this patron. Similar user emails will be suggested when you begin entering a value.');
-    $form['required_for_library']['patron_uid'] = array(
-      '#type' => 'value',
-      '#value' => $patron_uid,
-    );
-  }
-  if (variable_get('patron_use_barcodes', PATRON_NO_BARCODES) == PATRON_BARCODES) {
-    $form['required_for_library']['barcode'] = array(
-      '#type' => 'textfield',
-      '#size' => 30,
-      '#maxlength' => 60,
-      '#title' => t('Patron Card Number/Barcode'),
-      '#default_value' => $node->barcode,
-      '#weight' => 0,
-      '#required' => TRUE
-    );
-  }
-  $form['required_for_library']['disabled'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Disabled'),
-    '#default_value' => $node->disabled,
-    '#return_value' => PATRON_DISABLED,
-    '#description' => t('Disabled patrons will not appear in patron lists and may not use the library'),
-    '#weight' => 6,
-  );
-  return $form;
-}
-
-/**
- * Implementation of hook_validate().
- */
-function patron_validate(&$node) {
-  //Validate email
-  if (!empty($node->email)) {
-    if (!valid_email_address($node->email)) {
-      form_set_error('email', t('Invalid email address.'));
-    }
-    else {
-      $result = db_result(db_query_range("SELECT nid from {library_patrons} where email= '%s' and nid <> '%d'", $node->email, $node->nid, 0, 1));
-      if ($result) {
-        form_set_error('email', t("Duplicate email address. ". l('View existing entry with this email address.', 'node/'. $result)));
-      }
-    }
-  }
-  //Validate identifier
-  $dup_result = db_result(db_query_range("SELECT nid FROM {node} WHERE title= '%s' AND nid <> %d AND type='patron'", $node->title, $node->nid, 0, 1));
-  if ($dup_result) {
-    form_set_error('title', t("A Patron with that identifier already exists. ". l('View existing entry.', 'node/'. $dup_result)));
-  }
-  //Validate that barcode is unique
-  if (variable_get('patron_use_barcodes', PATRON_NO_BARCODES) == PATRON_BARCODES) {
-    if (!empty($node->barcode)) {
-      $node->barcode = check_plain($node->barcode);
-      $not_unique = db_result(db_query("SELECT COUNT(*) FROM {library_patrons} WHERE barcode = '%s' AND barcode <> '' AND nid <> %d", $node->barcode, $node->nid));
-      if ($result) {
-        form_set_error('barcode', t('The barcode %barcode already exists. Please enter a different barcode.', array('%barcode' => $node->barcode)));
-      }
-    }
-  }
-}
-
-/**
-* Retrieve a pipe delimited string of autocomplete suggestions for existing patron
-*/
-function patron_autocomplete($string) {
-  $matches = array();
-  $result = db_query_range("SELECT n.nid, lp.barcode, n.title FROM {node} n, {library_patrons} lp WHERE lp.nid = n.nid AND n.type = 'patron' AND lp.disabled = %d AND (LOWER(n.title) LIKE LOWER('%%%s%%') OR lp.barcode = '%s')", PATRON_ENABLED, check_plain($string), check_plain($string), 0, 10);
-  $barcodes = variable_get('patron_use_barcodes', PATRON_NO_BARCODES);
-  while ($patron = db_fetch_object($result)) {
-    if ($barcodes == PATRON_BARCODES && !empty($patron->barcode)) {
-      $matches[$patron->title .' [nid:'. $patron->nid .']'] = check_plain($patron->barcode) .' ('. check_plain($patron->title) .')';
-    }
-    else {
-      $matches[$patron->title .' [nid:'. $patron->nid .']'] = check_plain($patron->title);
-    }
-  }
-  print drupal_to_js($matches);
-  exit();
-}
-
-/**
-* Retrieve a pipe delimited string of autocomplete suggestions for existing patron
-*/
-function patron_email_autocomplete($string) {
-  $matches = array();
-  $result = db_query_range("SELECT mail from {users} where status = 1 AND LOWER(mail) LIKE LOWER('%s%%')", check_plain($string), 0, 10);
-  while ($patron = db_fetch_object($result)) {
-    $matches[$patron->mail] = check_plain($patron->mail);
-  }
-  print drupal_to_js($matches);
-  exit();
-}
-
-/**
- * Retrieve a list of patrons
- * @param $nid 
- *  If this is blank, only active patrons are returned.  If 'all', all are returned.  If a number, a specific patron is returned. 
- */
-function patron_get_patrons($nid = NULL) {
-  if (!$nid) {
-    $result = db_query("SELECT * FROM {node} n, {library_patrons} lp WHERE lp.nid = n.nid AND n.type = 'patron' AND lp.disabled = %d ORDER BY lp.name_last, lp.name_first", PATRON_ENABLED);
-  }
-  elseif (is_numeric($nid)) {
-    $result = db_query_range("SELECT * FROM {node} n, {library_patrons} lp WHERE lp.nid = n.nid AND n.type = 'patron' AND n.nid = %d ORDER BY lp.name_last, lp.name_first", $nid, 0, 1);
-  }
-  else {
-     $result = db_query("SELECT * FROM {node} n, {library_patrons} lp WHERE lp.nid = n.nid AND n.type = 'patron' ORDER BY lp.name_last, lp.name_first");
-  }
-  $patrons = array();
-  while ($patron = db_fetch_object($result)) {
-    $patrons[] = $patron;
-  }
-  return empty($patrons) ? FALSE : $patrons;
-}
-
-/**
- * Implementation of hook_menu()
- */
-function patron_menu() {
-  $items = array();
-  $items['patrons/autocomplete'] = array(
-    'title' => t('Patron Autocomplete'),
-    'page callback' => 'patron_autocomplete', 
-    'access arguments' => array('access content'), 
-    'type' => MENU_CALLBACK
-  );
-  $items['patrons'] = array(
-    'title' => 'Patrons',
-    'page callback' => 'patron_list_patrons',
-    'access arguments' => array('view patron content'),
-    'file' => 'patron.pages.inc',
-  );
-  $items['patrons/email'] = array(
-    'title' => 'Send Email',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('patron_email_form'),
-    'access arguments' => array('edit any patron content'),
-    'file' => 'patron.pages.inc',
-  );
-  $items['admin/settings/library/patrons'] = array(
-    'title' => 'Patron Settings',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('patron_admin_settings'),
-    'access arguments' => array('administer patrons'),
-  );
-  $items['patrons/js/email'] = array(
-    'page callback' => 'patron_email_autocomplete',
-    'type' => MENU_CALLBACK,
-    'access arguments' => array('access content'), 
-  );
-  return $items;
-}
-
-function patron_email_js() {
-  $email = $_POST['email'];
-  if ($email != '' && !is_null($email)) {
-    $exists = db_query_range("SELECT uid, name from {users} where mail= '%s'", $node->email, 0, 1);
-    if ($exists) {
-      while ($patron = db_fetch_object($exists)) {
-        // Build the new form.
-        $form_state = array('submitted' => FALSE);
-        $form_build_id = $_POST['form_build_id'];
-        
-        // We retreive the cached form, change the value, and resave.
-        $form = form_get_cache($form_build_id, $form_state);
-        form_set_value($form['required_for_library']['patron_uid'], $patron->uid, $form_state);
-        
-        $output = 'Matching Drupal user found. Username: '. $patron->name;
-        print drupal_json(array('data' => $output));
-      }
-    }
-  }
-}
-
-/**
- * Menu callback: Edit Patron Settings.
- */
-function patron_admin_settings() {
-  $form = array();
-  $form['patron_use_barcodes'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Use Library Cards (with Barcodes) for Library Patrons'),
-    '#default_value' => variable_get('patron_use_barcodes', 0),
-    '#return_value' => 1,
-    '#description' => t('This will allow you to use library cards.  However, you must have a unique barcode for every patron.'),
-  );
-  $form['user_settings'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('User Settings'),
-  );
-  $form['user_settings']['patron_is_user'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Associate Library Patrons with Drupal Users'),
-    '#default_value' => variable_get('patron_is_user', 0),
-    '#return_value' => 1,
-    '#description' => t('You must create the user account first, and the Drupal user and library patron must have the same email address.'),
-  );
-  /* Only allow if patrons do NOT have library cards!! */
-  if (variable_get('patron_use_barcodes', PATRON_NO_BARCODES) == PATRON_NO_BARCODES) {
-    $form['user_settings']['patron_autocreate'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Autocreate Library Patron on User Registration and Delete on User Deletion'),
-      '#default_value' => variable_get('patron_autocreate', 0),
-      '#return_value' => 1,
-      '#description' => t('You must associate library patrons with drupal users first.'),
-    );
-  }
-  return system_settings_form($form);
-}
-
-/**
- * Implementation of hook_mail()
- */
-function patron_mail($key, &$message, $params) {
-  $language = $message['language'];
-  switch ($key) {
-    case 'email_form':
-      $message['subject'] .= $params['subject'];
-      $message['body'][] = $params['message'];
-      break;
-  } 
-}
-
-function patron_email_link($patron) {
-  $output = '';
-  if ($patron->email) {
-    $output = l('E-mail', 'patrons/email/'. $patron->nid);
-  }
-  return $output;
-}
-
-/**
- * Implementation of hook_user().
- */
-function patron_user($op, &$edit, &$user, $category = NULL) {
-  if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER) {
-    switch ($op) {
-      case 'load':
-        $user->patron = patron_load_by_uid($user->uid);
-        break;
-      case 'after_update':
-        //If the user email has changed, update the patron email to match
-        $node = patron_load_by_uid($user->uid);
-        if (!empty($node) && $node->email != $user->mail) {
-          $node->email = $user->mail;
-          node_save($node);
-        }
-        break;
-      case 'view':
-        $patron = patron_load_by_uid($user->uid);
-        $cur_user = $GLOBALS['user'];
-
-        if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER && !empty($patron) && (node_access('view', 'patron') || $cur_user->uid == $user->uid)) {
-          $user->content['patron_name'] = array(
-            '#type' => 'user_profile_item',
-            '#title' => 'Patron Name',
-            '#value' => l($patron->name_first .' '. $patron->name_last, 'node/'. $patron->nid),
-            '#attributes' => array('class' => 'profile-patron'),
-          );
-        }
-        break;
-      case 'register':
-        if (variable_get('patron_autocreate', 0) == 1) {
-          return patron_register_form();
-        }
-        break;
-      case 'insert':
-        if (variable_get('patron_autocreate', 0) == 1 && isset($edit['name_last'])) {
-          return patron_create_patron($edit, $user);
-        }
-        break;
-      case 'delete':
-        //$patron = patron_load_by_uid($user->uid);
-        //if (variable_get('patron_autocreate', 0) == 1 && !empty($patron) && is_numeric($patron->nid)) {
-          //node_delete($patron->nid);
-        //}
-        break;
-    }
-  }
-}
-
-function patron_load_by_uid($uid) {
-  if (variable_get('patron_is_user', PATRON_NOT_USER) == PATRON_USER && is_numeric($uid)) {
-    $nid = db_result(db_query_range("SELECT nid FROM {library_patrons} WHERE patron_uid = %d", $uid, 0, 1));
-    if ($nid) {
-      $node = node_load($nid);
-      return $node;
-    }
-  }
-  return '';
-}
-
-function patron_register_form() {
-  $form = array();
-  $form['required_for_library'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Required Patron Fields'),
-    '#collapsed' => FALSE,
-    '#weight' => -3
-  );
-  $form['required_for_library']['name_first'] = array(
-    '#type' => 'textfield',
-    '#title' => t('First Name'),
-    '#default_value' => '',
-    '#size' => 10,
-    '#maxlength' => 30,
-    '#weight' => -4,
-    '#required' => TRUE
-  );
-  $form['required_for_library']['name_last'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Last Name'),
-    '#default_value' => '',
-    '#size' => 10,
-    '#maxlength' => 30,
-    '#weight' => -3,
-    '#required' => TRUE
-  );
-
-  return $form;
-}
-
-function patron_create_patron(&$edit, $user) {
-  $node = (object) array(
-    'type' => 'patron',
-    'title' => check_plain($edit['name_last']) .', '. check_plain($edit['name_first']),
-    'name' => $user->name,
-    'uid' => $user->uid,
-    'email' => $user->mail,
-    'name_last' => check_plain($edit['name_last']),
-    'name_first' => check_plain($edit['name_first']),
-    'patron_uid' => $user->uid,
-  );
-  node_save($node);
-}
\ No newline at end of file
diff --git a/patron/patron.pages.inc b/patron/patron.pages.inc
deleted file mode 100644
index 941715b..0000000
--- a/patron/patron.pages.inc
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-// $Id: patron.pages.inc,v 1.3 2009/11/23 19:06:53 jastraat Exp $
-
-/**
- * @file
- * Functions for generating page displays related to the patron module
- */
-
-
-function patron_list_patrons() {
-  $patrons = patron_get_patrons('all');
-  if ($patrons) {
-    $header = array(t('Name'), t('Status'));
-    $header[] = t('Actions');
-    $rows = array();
-    foreach ($patrons as $patron) {
-      if ($patron->disabled == PATRON_DISABLED) {
-        $patron->disabled = 'Disabled';
-      }
-      else {
-        $patron->disabled = 'Active';
-      }
-      $rows[] = array($patron->name_last .', '. $patron->name_first, $patron->disabled, l('View', 'node/'. $patron->nid) .' | '. patron_email_link($patron));
-    }
-    return theme('table', $header, $rows); 
-  }
-  else {
-    return "<p>No patrons found.</p>";
-  }
-}
-
-function patron_email_form(&$form_state) {
-  $form = array();
-
-  $patron_id = arg(2);
-  if ($patron_id) {
-    $patron = patron_get_patrons($patron_id);
-    $to = $patron[0]->email;
-    $name = $patron[0]->name_first .' '. $patron[0]->name_last;
-    if ($patron) {
-      $form['to'] = array(
-        '#type' => 'value',
-        '#value' => ($to ? $to : ''),
-        '#required' => FALSE,
-      );
-      $form['patron_name'] = array(
-        '#type' => 'item',
-        '#title' => t('To'),
-        '#value' => $name,
-        '#required' => FALSE,
-      );
-      $form['patron'] = array(
-        '#type' => 'value',
-        '#value' => $name,
-        '#required' => FALSE,
-      );
-    }
-  }
-
-  $form['subject'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Subject'),
-    '#maxlength' => 255,
-    '#required' => TRUE
-  );
-  $form['message'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Message'),
-    '#required' => TRUE,
-  );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Send E-mail'),
-  );
-  
-  return $form;
-}
-
-function patron_email_form_validate($form, &$form_state) {
-  if ($form_state['values']['to'] && !valid_email_address($form_state['values']['to'])) {
-    form_set_error('to', t('Invalid patron email.'));
-  }
-}
-
-function patron_email_form_submit($form, &$form_state) {
-  $values = $form_state['values']; 
-  if ($values['to']) {
-    $to = $values['to'];
-    $recipients = $values['patron'];
-  }
-  else { 
-    $patrons = patron_get_patrons();
-
-    $to_array = array();
-    $recipient_array = array();
-    foreach ($patrons as $patron) {
-      $to_array[] = $patron->email;
-      $recipient_array[] = $patron->name_first .' '. $patron->name_last;
-    }
-    $to = implode(',', $to_array);
-    $recipients = implode(', ', $recipient_array);
-  }
-  if (drupal_mail('patron', 'email_form', $to, language_default(), $values)) {
-    watchdog('library', 'Sent email to %recipient', array('%recipient' => $recipients));
-    drupal_set_message(t('Your message has been sent to '. $recipients));
-  }
-  else {
-    watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipients));
-  }
-  return;
-}
\ No newline at end of file
