﻿Index: nodegoto.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/nodegoto/Attic/nodegoto.module,v
retrieving revision 1.1.2.1.2.4.2.1
diff -u -r1.1.2.1.2.4.2.1 nodegoto.module
--- nodegoto.module	30 Jan 2007 11:36:01 -0000	1.1.2.1.2.4.2.1
+++ nodegoto.module	9 May 2007 11:21:07 -0000
@@ -26,43 +26,49 @@
   }
 }
 /**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_form_alter().
  */
-function nodegoto_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {  
-    
-	$nodetype=$node->type;
-	$nid=$node->nid;
-	$nodeto= variable_get('nodegoto_'.$op.'_'.$nodetype,'');
-	
-	if (variable_get('nodegoto_camefrom',0)==1){
-  $camefrom='camefrom='.urlencode('node/'.$nid);  
-     if ( $op == 'insert' && $nodeto!=''){             
-        drupal_goto($nodeto,$camefrom);
-           }
-     if ( $op == 'update' && $nodeto!=''){             
-        drupal_goto($nodeto,$camefrom);
-           }
-     if ( $op == 'delete' && $nodeto!=''){             
-        drupal_goto($nodeto);
-           } }                        
-  else{
-  if ( $op == 'insert' && $nodeto!=''){             
-        drupal_goto($nodeto);
-           }
-     if ( $op == 'update' && $nodeto!=''){             
-        drupal_goto($nodeto);
-           }
-     if ( $op == 'delete' && $nodeto!=''){             
-        drupal_goto($nodeto);
-           }
+function nodegoto_form_alter($form_id, &$form) {  
+  if (isset($form['type']) && $form['type']['#value'].'_node_form' == $form_id) {
+    $form['#submit']['nodegoto_node_form_submit'] = array(); 
   }
-  	
-       
+  if ($form_id == 'node_delete_confirm') {
+    $form['#submit']['nodegoto_node_delete_confirm'] = array(); 
+  }      
 }
 /**
- * Implementation of hook_footer() to insert Javascript at the end of the page
+ * Additional submit handlers
  */
- 
+function nodegoto_node_form_submit($form_id, $form_values) {
+  //insert
+  if (empty($form_values['nid'])) {
+    $nodeto = variable_get('nodegoto_insert_'. $form_values['type'], '');
+  }
+  //update
+  else {
+    $nodeto = variable_get('nodegoto_update_'. $form_values['type'], '');
+  }
+  if (variable_get('nodegoto_camefrom', 0) == 1) {
+    if($form_values['nid']) {
+      $nid = $form_values['nid']; 
+    }
+    else {
+      $name = db_prefix_tables('{node}_nid');
+      $nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s'", $name));
+    }
+    $camefrom = 'camefrom=node/'. $nid;
+    return array($nodeto, $camefrom);
+  }
+  else {
+    return $nodeto;
+  }
+}
+
+function nodegoto_node_delete_confirm ($form_id, $form_values) {
+  $node = node_load($form_values['nid']);
+  $nodeto = variable_get('nodegoto_delete_'. $node->type, '');
+  return $nodeto;
+}
  
 function nodegoto_menu($may_cache) {
   $items = array();
