--- signup_ecommerce.module	2007-07-25 00:06:46.000000000 -0400
+++ new-signup_ecommerce.module	2008-02-09 15:03:20.000000000 -0500
@@ -1,6 +1,6 @@
 <?php
 
-// $Id: signup_ecommerce.module,v 1.6 2007/07/25 04:06:46 dww Exp $
+// $Id: signup_ecommerce.module,v 1.5 2007/07/25 04:00:38 dww Exp $
 
 /**
  * @defgroup signup_ecommerce_core Core drupal hooks
@@ -12,9 +12,6 @@
  */
 function signup_ecommerce_help($section) {
   switch ($section) {
-    case 'admin/modules#description':
-      return t('Integrates the signup and e-commerce modules.');
-
     case 'admin/help#signup_ecommerce':
       return '<p>'. t('signup_ecommerce provides basic integration between the ecommerce module and the signup module, specifically allowing automatic user signup upon purchase of an enabled product type.') .'</p>'.
         '<p>'. t('To enable the feature, go to the <a href="%url">content types configuration page</a>, and click %configure for the content type you wish to enable. Make sure that the %allow_signups and %signup_ecommerce_integration checkboxes are checked, and save the settings.', array('%url' => url('admin/settings/content-types'), '%configure' => theme('placeholder', t('configure')), '%allow_signups' => theme('placeholder', t('Allow signups by default')), '%signup_ecommerce_integration' => theme('placeholder', t('Signup E-commerce integration')))) .'</p>'.
@@ -32,23 +29,23 @@ function signup_ecommerce_help($section)
  * @ingroup signup_ecommerce_form_alter
 */
 function signup_ecommerce_form_alter($form_id, &$form) {
-  if (isset($form['type']) && $form['type']['#value'] .'_node_settings' == $form_id) {
-    $type = $form['type']['#value'];
+  if ($form_id == 'node_type_form') {
+    $type = $form['old_type']['#value'];
     $form['workflow']['signup_ecommerce'] = array(
       '#type' => 'fieldset',
       '#title' => t('Signup E-commerce integration'),
     );
-    $form['workflow']['signup_ecommerce']['signup_ecommerce_'. $type] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Enabled'),
-      '#return_value' => 1,
-      '#default_value' => variable_get('signup_ecommerce_'. $type, FALSE) == 1,
-      '#description' => t('If selected, users will be automatically signed up for any products of this node type that they purchase.'),
-    );
-    $form['workflow']['signup_ecommerce']['signup_ecommerce_workflow_'. $type] = array(
+	  $form['workflow']['signup_ecommerce']['signup_ecommerce_type'] = array(
+	    '#type' => 'checkbox',
+	    '#title' => t('Enabled'),
+	    '#default_value' => variable_get('signup_ecommerce_type_' . $type, TRUE) == 1,
+	    '#description' => t('If selected, users will be automatically signed up for any products of this node type that they purchase.'),
+	  );
+	
+    $form['workflow']['signup_ecommerce']['signup_ecommerce_workflow'] = array(
       '#type' => 'radios',
       '#title' => t('Workflow'),
-      '#default_value' => variable_get('signup_ecommerce_workflow_'. $type, 0),
+      '#default_value' => variable_get('signup_ecommerce_workflow_'. $type, 1),
       '#options' => array(
         1 => t('Order completion'),
         2 => t('Payment completion'),
@@ -96,20 +93,18 @@ function signup_ecommerce_signup_suppres
 function signup_ecommerce_ecommerceapi($t, $op) {
   switch ($op) {
     case 'on payment completion':
-      if (module_exist('signup')) {
+      if (module_exists('signup')) {
         if (is_array($t['items'])) {
           // Loop through each item. If it's an autosignup node, and user
           // hasn't already signed up, then sign 'em up.
           foreach ($t['items'] as $item) {
             $node = node_load($item->nid);
             $signed_up = db_num_rows(db_query("SELECT nid FROM {signup_log} WHERE nid = %d AND uid = %d", $node->nid, $t['uid']));
-            if (_signup_ecommerce_is_autosignup($node) && !$signed_up && variable_get('signup_ecommerce_workflow_'. $node->type, 0) == 2) {
               $edit['nid'] = $node->nid;
               $edit['uid'] = $t['uid'];
               $edit['signup_form_data']['TransactionID'] = $t['txnid'];
               signup_sign_up_user($edit);
               _signup_ecommerce_watchdog_message($t['uid'], $node);
-            }
           }
         }
       }
@@ -131,7 +126,7 @@ function signup_ecommerce_ec_transaction
 
   switch ($op) {
     case 'insert':
-      if (module_exist('signup')) {
+      if (module_exists('signup')) {
         // load the transaction
         $t = store_transaction_load($txn->txnid);
         if (is_array($t->items)) {
@@ -140,13 +135,12 @@ function signup_ecommerce_ec_transaction
           foreach ($t->items as $item) {
             $node = node_load($item->nid);
             $signed_up = db_num_rows(db_query('SELECT nid FROM {signup_log} WHERE nid = %d AND uid = %d', $node->nid, $t->uid));
-            if (_signup_ecommerce_is_autosignup($node) && !$signed_up && variable_get('signup_ecommerce_workflow_'. $node->type, 0) == 1) {
               $edit['nid'] = $node->nid;
               $edit['uid'] = $t->uid;
               $edit['signup_form_data']['TransactionID'] = $txn->txnid;
               signup_sign_up_user($edit);
               _signup_ecommerce_watchdog_message($t->uid, $node);
-            }
+           
           }
         }
       }
@@ -167,7 +161,7 @@ function signup_ecommerce_ec_transaction
  *   The node to verify.
 */
 function _signup_ecommerce_is_autosignup($node) {
-  return variable_get('signup_form_'. $node->type, FALSE) && variable_get('signup_ecommerce_'. $node->type, FALSE) && product_load($node);
+  return variable_get('signup_form_'. $node->type, FALSE) && variable_get('signup_ecommerce_type_' . $node->type, TRUE) && product_load($node);
 }
 
 /**
