Index: README.txt
=========================================================
--- README.txt	(revision 1.1.2.1)
+++ README.txt	Working Copy
@@ -3,7 +3,7 @@
 ********************************************************************
 Name: Quickbooks Ubercart Integration
 Author: Sarva Bryant <sarva at aliandesign dot com>
-Drupal: 5.0.x
+Drupal: 6.x
 ********************************************************************
 DESCRIPTION:
 
Index: uc_qb.info
=========================================================
--- uc_qb.info	(revision 1.1.2.1)
+++ uc_qb.info	Working Copy
@@ -1,4 +1,6 @@
 name = QuickBooks Ubercart Integration
 description = Uses QuickBooks Web Connector to send and receive Ubercart data to/from QuickBooks
-dependencies = qbwc uc_store
-core = ubercart
+dependencies[] = qbwc
+dependencies[] = uc_store
+core = 6.x
+php = 5
Index: uc_qb.module
=========================================================
--- uc_qb.module	(revision 1.1.2.1)
+++ uc_qb.module	Working Copy
@@ -6,35 +6,31 @@
  *
  * 1. Advanced/separated error system (using QBWC interactive error handling)
  * 2. Import product data from QuickBooks
- * 3. **Important** Update customer email addresses in QuickBooks when the user changes them 
+ * 3. **Important** Update customer email addresses in QuickBooks when the user changes them
  */
 
 /**
  *  Implementation of hook_menu()
  */
-function uc_qb_menu($may_cache = false) {
+function uc_qb_menu() {
   $items = array();
 
-  if ($may_cache) {
-  	$items[] = array(
-      'path' => 'admin/store/settings/qb',
-      'title' => t('QB import/export'),
-      'description' => t('Import/Export store data to QuickBooks using Web Connector'),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('uc_qb_settings'),
-      'access' => user_access('administer quickbooks import/export'),
+  $items['admin/store/settings/qb'] = array(
+    'title' => 'QB import/export',
+    'description' => 'Import/Export store data to QuickBooks using Web Connector',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('uc_qb_settings'),
+    'access arguments' => array('administer quickbooks import/export'),
-      'type' => MENU_NORMAL_ITEM,
-    );
-    // TODO: Write help page that also can display the latest errors
+    'type' => MENU_NORMAL_ITEM,
+  );
+  // TODO: Write help page that also can display the latest errors
-    $items[] = array(
-      'path' => 'admin/store/settings/qb/help',
-      'title' => t('QuickBooks Import/Export Help'),
-      'description' => t('Detailed information for importing and exporting to QuickBooks using the Web Connector.'),
-      'callback' => 'uc_qb_admin_help',
-      'access' => user_access('administer quickbooks import/export'),
+  $items['admin/store/settings/qb/help'] = array(
+    'title' => 'QuickBooks Import/Export Help',
+    'description' => 'Detailed information for importing and exporting to QuickBooks using the Web Connector.',
+    'page callback' => 'uc_qb_admin_help',
+    'access arguments' => array('administer quickbooks import/export'),
-      'type' => MENU_CALLBACK,
-    );
+    'type' => MENU_CALLBACK,
+  );
-  }
 
   return $items;
 }
@@ -43,7 +39,7 @@
  * Menu callback for settings related to QB import
  */
 function uc_qb_settings() {
-	$form = array();
+  $form = array();
 
   $form['uc_qb_start_order'] = array(
     '#type' => 'textfield',
@@ -72,7 +68,7 @@
  * Implementation of hook_qbwc_authenticate()
  */
 function uc_qb_qbwc_authenticate($ticket, $user) {
-	  // Make sure this is defined and set to an array to avoid errors
+    // Make sure this is defined and set to an array to avoid errors
   if (!is_array($_SESSION['qb_orders'])) {
     $_SESSION['qb_orders'] = array();
   }
@@ -103,13 +99,13 @@
 
   // Return true if orders need processing signaling we have work for QB
   if (!empty($_SESSION['qb_orders'])) {
-  	return true;
+    return true;
   }
 }
 
 /**
  * Implementation of hook_qbwc_response()
- * 
+ *
  * @Description: Receive queries for QB data and set appropriate session variables for use in hook_qbwc_request()
  */
 function uc_qb_qbwc_response($response, $hresult, $message, $saved) {
@@ -121,13 +117,13 @@
     $returnCnt = $element->getAttribute('retCount');
     $statusCode = $element->getAttribute('statusCode');
     $statusMessage = $element->getAttribute('statusMessage');
-    
+
     if ($statusCode > 0) {
-    	watchdog('uc_qb', t('QB responded to a request with error #%code (%message)', array('%code' => $statusCode, '%message' => $statusMessage)), WATCHDOG_ERROR);
+      watchdog('uc_qb', t('QB responded to a request with error #%code (%message)', array('%code' => $statusCode, '%message' => $statusMessage)), WATCHDOG_ERROR);
     }
     if ($statusCode == 3231) {
       // This element was not processed, so skip it
-    	continue;
+      continue;
     }
 
     switch($element->tagName) {
@@ -139,24 +135,24 @@
         }
 
         if ($statusCode == 0) {
-        	$_SESSION['qb_shipping_methods'][$saved[$requestId]['method']] = true;
+          $_SESSION['qb_shipping_methods'][$saved[$requestId]['method']] = true;
         }
         else {
-        	$error = true;
+          $error = true;
           break;
         }
       break;
-    	case 'ShipMethodQueryRs':
+      case 'ShipMethodQueryRs':
         if (!isset($saved[$requestId])) {
           $error = true;
           break;
         }
 
         if ($returnCnt > 0) {
-        	$_SESSION['qb_shipping_methods'][$saved[$requestId]['method']] = true;
+          $_SESSION['qb_shipping_methods'][$saved[$requestId]['method']] = true;
         }
         else {
-        	$new[] = array(
+          $new[] = array(
             'name' => 'ShipMethodAddRq',
             'request' => array('ShipMethodAdd' => array(
               'Name' => $saved[$requestId]['method'],
@@ -173,10 +169,10 @@
         }
 
         if ($statusCode == 0) {
-        	$_SESSION['qb_services'][$saved[$requestId]] = true;
+          $_SESSION['qb_services'][$saved[$requestId]] = true;
         }
         else {
-        	$error = true;
+          $error = true;
           break;
         }
       break;
@@ -286,7 +282,7 @@
         }
         // If this is an anonymous user and already exists, get the ListID for it, any other situation should not happen and is an error
         else if ($data->uid == 0 && $statusCode == 3100) {
-        	$new[] = array(
+          $new[] = array(
               'name' => 'CustomerQueryRq',
               'request' => array(
                 'FullName' => $data->primary_email,
@@ -328,7 +324,7 @@
           );
         }
         else {
-        	$_SESSION['qb_failed_orders'][] = $saved[$requestId];
+          $_SESSION['qb_failed_orders'][] = $saved[$requestId];
           $_SESSION['qb_orders_count']--;
           watchdog('uc_qb', t('Failed to export the order #%order with error code %code (%message) to QB', array('%order' => $saved[$requestId]->order_id, '%code' => $statusCode, '%message' => $statusMessage)), WATCHDOG_ERROR);
         }
@@ -336,10 +332,10 @@
       case 'SalesReceiptModRs':
         //Successfully changed the receipt to pending. Mark this as done.
         if ($statusCode == 0) {
-        	$_SESSION['qb_orders_count']--;
+          $_SESSION['qb_orders_count']--;
         }
         else {
-          watchdog('uc_qb', t('Failed to change the ', array('%order' => $saved[$requestId]->order_id, '%code' => $statusCode, '%message' => $statusMessage)), WATCHDOG_ERROR);        	
+          watchdog('uc_qb', t('Failed to change the ', array('%order' => $saved[$requestId]->order_id, '%code' => $statusCode, '%message' => $statusMessage)), WATCHDOG_ERROR);
         }
       break;
       // Response to a product search query
@@ -363,7 +359,7 @@
         }
         // Create the product if it was not there
         else {
-        	$new[] = array(
+          $new[] = array(
             'name' => 'ItemInventoryAddRq',
             'request' => array(
               'ItemInventoryAdd' => array(
@@ -410,7 +406,7 @@
           }
         }
         else {
-        	// Failed to add the product
+          // Failed to add the product
           watchdog('uc_qb', t('Failed to export the product %product in order #%order with error code %code (%message) to QB', array('%product' => $saved[$requestId]->title, '%order' => $saved[$requestId]->order_id, '%code' => $statusCode, '%message' => $statusMessage)), WATCHDOG_ERROR);
         }
       break;
@@ -464,13 +460,13 @@
         $taxes = $element->getElementsByTagName('SalesTaxPreferences');
         $inventory = $element->getElementsByTagName('IsUsingInventory');
         if ($taxes->length == 0) {
-        	// Taxes are not turned on. Will fail
+          // Taxes are not turned on. Will fail
           watchdog('uc_qb', t('Failed to start QB export as taxes are not turned on in the company preferences.'), WATCHDOG_ERROR);
           $error = true;
           break;
         }
         if (!($inventory = $inventory->item(0)) || $inventory->nodeValue == 'false') {
-        	// Taxes are not turned on. Will fail
+          // Taxes are not turned on. Will fail
           watchdog('uc_qb', t('Failed to start QB export as inventory is not turned on in the company preferences.'), WATCHDOG_ERROR);
           $error = true;
           break;
@@ -478,40 +474,40 @@
       break;
     }
   }
-  
+
   // Stop processing on errors
   if ($error) {
     return -1;
   }
 
   if (!empty($new)) {
-  	$_SESSION['qb_pending_requests'][] = $new;
+    $_SESSION['qb_pending_requests'][] = $new;
   }
-  
+
   if ($_SESSION['qb_orders_count'] == 0) {
-  	return 100;
+    return 100;
   }
 
-	return ($done / $_SESSION['qb_orders_count']) * 100;
+  return ($done / $_SESSION['qb_orders_count']) * 100;
 }
 
 /**
  * Implementation of hook_qbwc_request()
- * 
+ *
  * @Description: Send requests for data from quickbooks (existing customers/orders)
  *    or requests for additions into Quickbooks
  */
 function uc_qb_qbwc_request() {
   // Check if we have any pending requests to make as a response to QB returned data
   if (!empty($_SESSION['qb_pending_requests'])) {
-  	return array_shift($_SESSION['qb_pending_requests']);
+    return array_shift($_SESSION['qb_pending_requests']);
   }
 
   // Get a list of orders needing exported
   if (!isset($_SESSION['qb_started_processing'])) {
     $_SESSION['qb_started_processing'] = true;
     $checked_users = $products  = array();
-    
+
     // Checks for accounts/settings to exist that need to happen on first connect
     if (count($_SESSION['qb_orders'])) {
       // Check that certain required service accounts exist
@@ -539,7 +535,7 @@
     $products = &$_SESSION['QBProducts'];
     foreach($_SESSION['qb_orders'] as &$copy) {
       // Check that all of the products exist in QB and if not create them
-    	$product_result = db_query('SELECT uop.nid, uop.title, uop.model, uop.order_id, up.sell_price FROM {uc_order_products} uop INNER JOIN {uc_products} up ON uop.nid = up.nid WHERE uop.order_id = "%d"', $copy->order_id);
+      $product_result = db_query('SELECT uop.nid, uop.title, uop.model, uop.order_id, up.sell_price FROM {uc_order_products} uop INNER JOIN {uc_products} up ON uop.nid = up.nid WHERE uop.order_id = "%d"', $copy->order_id);
       while ($product = db_fetch_object($product_result)) {
         if (!array_key_exists($product->model, $products)) {
           $product->order_id = array($product->order_id);
@@ -555,7 +551,7 @@
           $products[$product->model] = $product;
         }
         else {
-        	$products[$product->model]->order_id[] = $product->order_id;
+          $products[$product->model]->order_id[] = $product->order_id;
         }
       }
 
@@ -568,7 +564,7 @@
           $copy->qb_user_id = $copy->order_data['QBListID'];
         }
         else if (!$copy->primary_email) {
-        	watchdog('uc_qb', t('Order #%order could not be exported to QB because anonymous user did not provide an email address.', array('%order' => $copy->order_id)), WATCHDOG_ERROR);
+          watchdog('uc_qb', t('Order #%order could not be exported to QB because anonymous user did not provide an email address.', array('%order' => $copy->order_id)), WATCHDOG_ERROR);
         }
         else {
           $check[] = array(
@@ -589,7 +585,7 @@
     }
   }
   else if (empty($_SESSION['qb_orders'])) {
-  	return;
+    return;
   }
 
   $requests = array();
@@ -597,7 +593,7 @@
   foreach($_SESSION['qb_orders'] as &$item) {
     if ($item->order_data['QBProcessed']) {
       // This order was already processed
-    	continue;
+      continue;
     }
 
     $receipt = array();
@@ -632,7 +628,7 @@
         'data' => $order->payment_method
       );
     }
-    
+
     // Make various checks on line items
     foreach((array)$order->line_items as $line) {
       $line = (object)$line;
@@ -641,7 +637,7 @@
       }
 
       if (!array_key_exists($line->type, (array)$_SESSION['qb_services'])) {
-      	$check[] = array(
+        $check[] = array(
           'name' => 'ItemServiceQueryRq',
           'request' => array(
             'FullName' => $line->type,
@@ -653,7 +649,7 @@
     }
 
     if (!$item->qb_user_id_pending && !$item->qb_user_id) {
-    	// This should never happen. If it does, make a log entry for this order saying that it failed to get exported
+      // This should never happen. If it does, make a log entry for this order saying that it failed to get exported
       $item->order_data['QBProcessed'] = true;
       $_SESSION['qb_orders_count']--;
       $_SESSION['qb_failed_orders'][] = $item;
@@ -663,7 +659,7 @@
 
     // If any check items were marked, send them all at once
     if (!empty($check)) {
-    	return $check;
+      return $check;
     }
 
     // Set the available info to get imported into QB
@@ -700,10 +696,10 @@
     );
     $receipt['IsPending'] = 'false';
     if ($order->payment_method) {
-    	$receipt['PaymentMethodRef']['FullName'] = $order->payment_method;
+      $receipt['PaymentMethodRef']['FullName'] = $order->payment_method;
     }
     if ($order->quote['method']) {
-    	$receipt['ShipMethodRef']['FullName'] = $order->quote['method'];
+      $receipt['ShipMethodRef']['FullName'] = $order->quote['method'];
     }
     $receipt['Memo'] = substr($message, 0, 101);
     $receipt['DepositToAccountRef']['FullName'] = variable_get('uc_qb1_income_account', 'Undeposited Funds');
@@ -735,11 +731,11 @@
             $description .= $key .': '. $value;
           }
         }
-        
+
         if ($item->order_data['QBProducts'][$product->model]['price'] != $product->price) {
           // TODO: Change the price in QB of the product if it had been changed for this product
-        	$requests[] = array(
-          
+          $requests[] = array(
+
           );
         }
 
@@ -754,13 +750,13 @@
         $total += $product->qty * $product->price;
         $lineItems[] = $product_line;
       }
-      
+
       if (!$added_products) {
         // Make sure to keep total orders to be processed up to date
         $item->order_data['QBProcessed'] = true;
         $_SESSION['qb_orders_count']--;
         $_SESSION['qb_failed_orders'][] = $item;
-      	watchdog('uc_qb', t('Failed to export order #%order because some or all of the purchased products could not be created/found in QB.', array('%order' => $item->order_id)), WATCHDOG_ERROR);
+        watchdog('uc_qb', t('Failed to export order #%order because some or all of the purchased products could not be created/found in QB.', array('%order' => $item->order_id)), WATCHDOG_ERROR);
         continue;
       }
     }
@@ -769,7 +765,7 @@
       $item->order_data['QBProcessed'] = true;
       $_SESSION['qb_orders_count']--;
       $_SESSION['qb_failed_orders'][] = $item;
-    	watchdog('uc_qb', t('Failed to export order #%order because no products were purchased.', array('%order' => $item->order_id)), WATCHDOG_ERROR);
+      watchdog('uc_qb', t('Failed to export order #%order because no products were purchased.', array('%order' => $item->order_id)), WATCHDOG_ERROR);
       continue;
     }
 
@@ -777,7 +773,7 @@
     foreach((array)$order->line_items as $line) {
       // Only look at calculated line items
       if (_line_item_data($line['type'], 'calculated') != TRUE) {
-      	continue;
+        continue;
       }
       $lineItems = &$receipt['SalesReceiptLineAdd'];
 
@@ -790,20 +786,20 @@
       $total += $line['amount'];
       $lineItems[] = $line_item;
     }
-    
+
     // Add any customer messages as a blank line item
     if ($message && variable_get('uc_qb_include_messages', true)) {
       // Add two blank lines in front
       $receipt['SalesReceiptLineAdd'][] = array('Desc' => ' ');
       $receipt['SalesReceiptLineAdd'][] = array('Desc' => ' ');
-    	$receipt['SalesReceiptLineAdd'][] = array(
+      $receipt['SalesReceiptLineAdd'][] = array(
         'Desc' => substr($message, 0, 4000)
       );
     }
 
     // Only add items if we are calculating the total properly
     if (round($total, 2) == round($order->order_total, 2)) {
-    	$requests[] = array(
+      $requests[] = array(
         'name' => 'SalesReceiptAddRq',
         'request' => array(
           'SalesReceiptAdd' => $receipt,
@@ -812,13 +808,13 @@
       );
     }
     else {
-    	$item->order_data['QBProcessed'] = true;
+      $item->order_data['QBProcessed'] = true;
       $_SESSION['qb_orders_count']--;
       $_SESSION['qb_failed_orders'][] = $item;
       watchdog('uc_qb', t('Failed to export order #%order the calculated total meant for QB did not match the order total.', array('%order' => $item->order_id)), WATCHDOG_ERROR);
       continue;
     }
-    
+
     $first = false;
   }
 
@@ -827,19 +823,19 @@
 
 /**
  * Implementation of hook qbwc_close()
- * 
+ *
  * Send email alerts on failed orders
  */
 function uc_qb_qbwc_close($ticket) {
-	if (!empty($_SESSION['qb_failed_orders']) && ($mail = variable_get('uc_qb_failed_orders_email', ''))) {
+  if (!empty($_SESSION['qb_failed_orders']) && ($mail = variable_get('uc_qb_failed_orders_email', ''))) {
     foreach($_SESSION['qb_failed_orders'] as $order) {
-    	$orders[] = t('#%order (@link)', array('%order' => $order->order_id, '@link' => url('fleurville/admin/store/orders/'. $order->order_id, null, null, true)));
+      $orders[] = t('#%order (@link)', array('%order' => $order->order_id, '@link' => url('fleurville/admin/store/orders/'. $order->order_id, null, null, true)));
     }
-    
+
     $output = t('There were errors exporting the following orders to QB via Web Connector: ') . "\n\n";
     $output .= implode("\n", $orders) . "\n\n";
     $output .= t('To find more details about the errors, view the error logs at %url and filter by "uc_qb"', array('%url' => url('admin/logs/watchdog', null, null, true)));
 
-		drupal_mail('uc_qb_failed_exports', $mail, t('Errors exporting orders to QB'), $output, uc_store_email_from());
-	}
+    drupal_mail('uc_qb_failed_exports', $mail, t('Errors exporting orders to QB'), $output, uc_store_email_from());
+  }
 }
