Index: CHANGELOG.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_edi/CHANGELOG.txt,v
retrieving revision 1.1
diff -u -p -r1.1 CHANGELOG.txt
--- CHANGELOG.txt	15 Oct 2010 08:31:57 -0000	1.1
+++ CHANGELOG.txt	15 Oct 2010 22:30:50 -0000
@@ -3,3 +3,5 @@ $Id: CHANGELOG.txt,v 1.1 2010/10/15 08:3
 Journal 6.x-1.x, 2010-10-14
 ---------------------------
 task #354696 by AntoineSolutions: Updated the head branch to Drupal 6.x-1.x.
+by AntoineSolutions: Added CHANGELOG.txt and README.txt files.
+bug #942844 by AntoineSolutions: Fixed validation of Conditional Actions being configured correctly.
Index: uc_edi.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uc_edi/uc_edi.module,v
retrieving revision 1.2
diff -u -p -r1.2 uc_edi.module
--- uc_edi.module	15 Oct 2010 08:28:04 -0000	1.2
+++ uc_edi.module	15 Oct 2010 22:30:50 -0000
@@ -14,11 +14,39 @@
  ******************************************************************************/
 
 /**
+ * Implements hook_help().
+ */
+function uc_edi_help($path, $arg) {
+  switch ($path) {
+    case 'admin/store/settings/edi':
+      return t('The Ubercart EDI module provides import and export functionality for Ubercart orders. Use the form below to customize import and export settings.');
+    
+    case 'admin/help#uc_edi':
+      $output = '';
+      $output .= '<a name="export-configuration"><h2>' . t('Export Configuration') . '</h2></a>';
+      $output .= '<p>' . t('You must perform the following actions as a minimum for orders to export.') . '</p>';
+      $output .= '<ol>';
+      $output .= '<li>' . t('From the <a href="!url">Conditional Actions configuration</a> page:', array('!url' => url('admin/store/ca')));
+      $output .= '<ol>';
+      $output .= '<li>' . t('Create or edit a predicate with the "Update the order status" action and set the "Order status" field to the order status of orders to be exported. See the Ubercart <a href="!url">Configuring Conditional Actions</a> users guide.', array('!url' => 'http://www.ubercart.org/docs/user/7657/configuring_conditional_actions')) . '</li>';
+      $output .= '</ol>';
+      $output .= '<li>' . t('From the <a href="!url">Ubercart EDI setting</a> page:', array('!url' => url('admin/store/settings/edi')));
+      $output .= '<ol>';
+      $output .= '<li>' . t('Set the "Export directory" and "Export archive directory" fields to directories where export files will be written too, preferably outside the Drupal root folder.') . '</li>';
+      $output .= '<li>' . t('Set the "Ready for export order status" to the order status specified in the predicate that was configured above.') . '</li>';
+      $output .= '</ol>';
+      $output .= '</li>';
+      $output .= '</ol>';
+      return $output;
+  }
+}
+
+/**
  * Implements hook_menu().
  */
 function uc_edi_menu() {
   $items['admin/store/settings/edi'] = array(
-    'title' => 'EDI import/export',
+    'title' => 'Import/Export Settings',
     'description' => 'Adjust the settings for EDI import and export.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('uc_edi_settings_form'),
@@ -34,14 +62,14 @@ function uc_edi_menu() {
   );
 
   $items['admin/store/orders/edi'] = array(
-    'title' => 'EDI import/export',
+    'title' => 'Manualy Import/Export Orders',
     'description' => 'Manually import or export an order EDI file.',
     'page callback' => 'uc_edi_order_admin',
     'access arguments' => array('administer edi orders'),
     'type' => MENU_NORMAL_ITEM,
   );
   $items['admin/store/orders/edi/download'] = array(
-    'title' => 'Download Export Files',
+    'title' => 'Download & Archive Export Files',
     'description' => 'Download and archive exported order EDI files.',
     'page callback' => 'uc_edi_export_download',
     'access arguments' => array('download edi orders'),
@@ -349,6 +377,13 @@ function uc_edi_settings_form_validate($
       !is_dir($form_state['values']['uc_edi_order_export_archive_dir'])) {
     form_set_error('uc_edi_order_export_archive_dir', t('You have specified a non-existent order export archive directory.'));
   }
+
+  // Validate Conditional Actions is configured correctly for the specified
+  // order export status.
+  if (!uc_edi_order_export_status_validate($form_state['values']['uc_edi_order_export_status'])) {
+    form_set_error('uc_edi_order_export_status', t('A predicate must exist that sets the order status to that which is defined by the <strong>Ready for export order status</strong> field. See the <a href="!url">Export Configuration documentation</a>.', array('!url' => url('admin/help/uc_edi', array('fragment' => 'export-configuration')))));
+  }
+
   if (!valid_email_address($form_state['values']['uc_edi_order_export_mail_to']) &&
       !empty($form_state['values']['uc_edi_order_export_mail_to']) &&
       module_exists('mimemail')) {
@@ -362,6 +397,60 @@ function uc_edi_settings_form_validate($
 }
 
 /**
+ * Verify a Conditional Actions predicate exists that will set the order status
+ * to the value passed in vie the $status parameter.
+ *
+ * @param $status
+ *   A valid Ubercart order status.
+ *
+ * @return boolean
+ *   TRUE if a Conditional Actions predicate is found that will set an orders
+ *   status to the value of the $status variable passed in, otherwise FALSE.
+ */
+function uc_edi_order_export_status_validate($status) {
+  // Load all the module defined predicates into a temporary array.
+  $temp = module_invoke_all('ca_predicate');
+
+  // Assign a default weight if need be.
+  foreach ($temp as $key => $value) {
+    $temp[$key]['#pid'] = $key;
+    if (!isset($value['#weight'])) {
+      $temp[$key]['#weight'] = 0;
+    }
+  }
+
+  // Load and loop through all the database stored predicates.
+  $result = db_query("SELECT * FROM {ca_predicates}");
+  while ($predicate = db_fetch_array($result)) {
+    // Prepare the database data into a predicate.
+    $predicate = ca_prepare_db_predicate($predicate);
+
+    // Overrides the module defined predicate if it's been modified by a user.
+    $temp[$predicate['#pid']] = $predicate;
+  }
+
+  usort($temp, 'ca_weight_sort');
+
+  // Copy the temporary array of predicates into a keyed array.
+  $predicates = array();
+  foreach ($temp as $predicate) {
+    $predicates[$predicate['#pid']] = $predicate;
+  }
+
+  // Load and loop through all the database stored predicates.
+  foreach ($predicates as $predicate) {
+    // Loop through all predicate actions.
+    foreach ($predicate['#actions'] as $action) {
+      if ($action['#settings']['order_status'] == $status) {
+        return TRUE;
+      }
+    }
+  }
+
+  return FALSE;
+}
+
+/**
  * Displays the help page for select EDI topics.
  */
 function uc_edi_admin_help() {
