? usernodes-jjeff.patch
Index: usernodes.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/usernodes/usernodes.module,v
retrieving revision 1.3
diff -u -F^f -r1.3 usernodes.module
--- usernodes.module	27 Feb 2006 06:53:42 -0000	1.3
+++ usernodes.module	30 May 2006 02:33:51 -0000
@@ -85,7 +85,7 @@ function usernodes_view_profile($theuser
   global $user;
   foreach ($proflists as $type => $listlength) {
   	$cat = variable_get('usernodes_profilecat_'.$type, 'User Content');
-  	(function_exists('flexinode_node_name') && substr($type, 0, 10) == 'flexinode-') ? $typename = flexinode_node_name($type) : $typename = $type;
+  	$typename = node_get_name($type);
     if (variable_get('usernodes_profaddlink_'.$type, 'User Content') && !_usernodes_at_max($type, $userid) && ($userid == $user->uid or user_access('administer users'))) {
       $newlink = "<div>".l(t('[add '.$typename.']'), 'node/add/'.$type)."</div>";
     } else
@@ -109,7 +109,12 @@ function usernodes_form_alter($form_id, 
 
   switch ($form_id) {
     case $type .'_node_settings':
-      $form['usernodes'] = array('#type' => 'fieldset', '#title' => t('User Node Settings'));
+      $form['usernodes'] = array(
+      '#type' => 'fieldset', 
+      '#title' => t('User Node Settings'),
+      '#weight' => 0,
+      );
+      
 	  $form['usernodes']['usernodes_limit_'. $type] = array(
 		'#type' => 'textfield',
 		'#title' => t('User Node Max'),
@@ -176,9 +181,17 @@ function usernodes_form_alter($form_id, 
 
       break;
     case $type .'_node_form':
-      if (!$node->nid && _usernodes_at_max($node->type, $node->uid)) {
-	   drupal_set_message("You cannot create any more nodes of this type.");
-	   $form = NULL;
+      if (!$node->nid && _usernodes_at_max($node->type, $user->uid)) {
+       if(variable_get('usernodes_limit_'. $node->type, 0) == 1 && node_access('edit', $node)){
+         // if there's only one node of this type, go to it.
+         drupal_set_message(t('You cannot create another %type, but you can edit your current one.', array('%type' => node_get_name($node))));
+         $n = node_load(array('type' => $node->type, 'uid' => $user->uid));
+         drupal_goto('node/'. $n->nid .'/edit');
+       }
+       else {
+    	   drupal_set_message(t("You cannot create any more %type items.", array('%type' => node_get_name($node))));
+    	   $form = NULL;
+       }
 	  }
       
       break;
@@ -201,6 +214,29 @@ function usernodes_link($type, $node = N
   return $links; 
 }
 
+/**
+ * Get a list of nodes of a certain type for a user
+ *
+ * @param $type
+ *   the node type
+ * @param $uid
+ *   user id - if omitted, use current user id
+ * @return
+ *   array of node ids
+ */
+function usernodes_list_for_user($type, $uid = NULL){
+  if (is_null($uid)){
+    global $user;
+    $uid = $user->uid;
+  }
+  $result = db_query('SELECT DISTINCT nid FROM {node} WHERE uid = %d and type = "%s" ORDER BY created DESC', $uid, $type);
+  $return = array();
+  while($r = db_fetch_object($result)){
+    $return[] = $r->nid;
+  }
+  return $return;
+}
+
 function _usernodes_at_max($type, $uid = NULL) {
   if (is_null($uid)){
     global $user;
