<?php
// $Id: nodegoto.module,v 1.1.2.1.2.2 2006/06/18 00:53:19 introfini Exp $
/*
 * Drupal Module: NodeGoTo
 * Allows to set a destination page for nodes after creation
 * 
 *
 * @author: introfini <introfini@gmail.com>
 */


function nodegoto_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('Allows to define any page or URL as the target after creating a node.');
    case 'admin/settings/googleanalytics':
      return t('Allows to define any page or URL as the target after creating a node.');
  }
}

/**
 * Implementation of hook_nodeapi().
 */
function nodegoto_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {  
    $nodetype=$node->type;      
	$nodeto= variable_get('nodegoto_'.$nodetype,'');
	
     if ( $op == 'insert' && $nodeto!=''){             
        drupal_goto($nodeto);
           }
}

/**
 * Implementation of hook_footer() to insert Javascript at the end of the page
 */
function nodegoto_settings() {
  $form['nodespage'] = array(
        '#type' => 'fieldset',
        '#title' => t('Set the path to redirect for'),
        '#collapsible' => FALSE,
        '#description' => t('You can set a path like \'node/1\' or like a full URL \'http://www.example.com\''),
      );

  
  $nodetypes = node_get_types();
  foreach ($nodetypes as $ntype => $displaytype) {  
     
  	$form['nodespage']['nodegoto_'.$ntype] = array(
      '#type' => 'textfield',
      '#title' => "Insert the path for $displaytype",
      '#default_value' => variable_get('nodegoto_'.$ntype,''),
      '#size' => 75,
      '#maxlength' => 200,
      '#required' => FALSE,
     );    
     }
  return $form;
}
