--- C:/Web S/see.asso.fr/modules/helpinject-6.x-1.x-dev/helpinject/helpinject.module.bak.php	Thu Aug 06 15:49:00 2015
+++ C:/Web S/see.asso.fr/modules/helpinject-6.x-1.x-dev/helpinject/helpinject.module	Mon Aug 31 20:54:04 2015
@@ -16,10 +16,35 @@
           $help_link = theme('helpinject_topic', $value['nid']);
         }
       }
+// JV https://www.drupal.org/node/1022912
+      if (arg((0) == 'node' && is_numeric(arg(1)))) {
+        // TODO make special keys for node/%/edit/etcetc
+        // could be advanced like node/%/devel is the same for all nodetypes
+        $node = node_load(arg(1));
+        if ($values = helpinject_get_from_key('nodetype', 'node/['. $node->type . ']')) {
+          foreach ($values as $value) {
+            $help_link .= theme('helpinject_topic', $value['nid']);
+          }
+        }
+      }
+      if (arg(0) == 'node' && arg(1) == "add") {
+        if ($values = helpinject_get_from_key('nodetype', 'node/['. arg(2) . ']')) {
+          foreach ($values as $value) {
+            $help_link .= theme('helpinject_topic', $value['nid']);
+          }
+        }
+      }
+      
+// end JV
     }
     // If the user is allowed, show the injection icon.
-    if (user_access('inject help')) {
+// JV https://www.drupal.org/node/1022912          
+//    if (user_access('inject help')) {
+    if ((user_access('inject help')) && ($inject_link == '')) {      
       $inject_link = _helpinject_admin_link('path', $_GET['q'], t('this page'));
+//      $inject_link .= _helpinject_admin_link('nodetype', $_GET['q'], t('this page'));
+// end JV
+
     }
     return $help_link . $inject_link;
   }
@@ -202,8 +227,27 @@
 
   // Get the whole rest of the path
   $q_paths = explode('/', $_GET['q'], 4);
-  $key = $q_paths[3];
-  if ($type == 'path' && empty($form_state['storage']['helpkey'])) {
+// JV https://www.drupal.org/node/1022912
+//  $key = $q_paths[3];
+  $myargs = explode ('/', $q_paths[3]);
+  if ($myargs[0] == 'node') {
+    $nid = $myargs[1];
+    if (is_numeric($nid)){
+      $node = node_load ($nid);
+      $key = 'node/['. $node->type . ']'; // The format of the key in the database is node/[nodetype] the [ ] are used later to identify this key as a nodetype key      
+    }
+    if ($nid == "add"){
+      $key = 'node/['. $myargs[2] . ']'; // The format of the key in the database is node/[nodetype] the [ ] are used later to identify this key as a nodetype key      
+    }
+  }
+  else {
+    $key = $q_paths[3];
+  }    
+// end JV  
+// JV https://www.drupal.org/node/1022912
+//  if ($type == 'path' && empty($form_state['storage']['helpkey'])) {
+  if ((($type == 'path') || ($type == 'nodetype')) && empty($form_state['storage']['helpkey'])) {    
+// end JV
     $ancestors = drupal_map_assoc(helpinject_get_path_ancestors($key));
     $existing = helpinject_get_from_key($type, $ancestors);
     $default_helpkey = NULL;
@@ -217,6 +261,32 @@
         $ancestors[$key] .= ' (' . t('Currently %title [nid !nid]', array('%title' => check_plain($title), '!nid' => $match['nid'])) . ')';
       }
     }
+// JV https://www.drupal.org/node/1022912
+    /* if we are on a node page, we would also like to include the nodetype as an optional 'path'
+     * TODO make special keys for /edit/blabla etc
+     * could be advanced like node/%/devel is the same for all nodetypes
+     */
+    $myargs = explode ('/', $q_paths[3]);
+    if ($myargs[0] == 'node') {
+      $nid = $myargs[1];
+      if (is_numeric ($nid)){    
+        $node = node_load ($nid);
+        $key = 'node/['. $node->type . ']'; // The format of the key in the database is node/[nodetype] the [ ] are used later to identify this key as a nodetype key
+        $ancestors[$key] = 'node/['. $node->type . ']'; 
+      }
+      if ($nid == "add"){
+        $key = 'node/['. $myargs[2] . ']'; // The format of the key in the database is node/[nodetype] the [ ] are used later to identify this key as a nodetype key
+        $ancestors[$key] = 'node/['. $myargs[2] . ']';        
+      }
+      $existing = helpinject_get_from_key($type, $ancestors);
+      foreach ($ancestors as $key => $value) {
+        if ($match = $existing[$key]) {
+          $title = db_result(db_query("SELECT r.title FROM {node_revisions} r INNER JOIN {node} n ON n.vid = r.vid WHERE r.nid = %d", $match['nid']));
+          $ancestors[$key] .= ' (' . t('Currently %title [nid !nid]', array('%title' => check_plain($title), '!nid' => $match['nid'])) . ')';
+        }
+      }
+    }
+// end JV
     // This prevents it from going to the theme function for the injection form.
     $form['#theme'] = 'theme_form';
     $form['helpkey'] = array(
@@ -238,6 +308,19 @@
       // In this case we're injecting into something other than a path, so we
       // pack the helpkey into the form for later use.
       $form['helpkey'] = array('#type' => 'value', '#value' => $key);
+// JV https://www.drupal.org/node/1022912
+    }
+    if ($type == 'path') {
+      if ((!(strpos($form_state['storage']['helpkey'], 'node/', 0) === FALSE) == 1) &&  //holy crap! this looks like Visual Basic where true = -1 
+          (strpos($form_state['storage']['helpkey'], '[') > 0) && 
+          (strpos($form_state['storage']['helpkey'], ']') > 0)
+         ) {
+        // $type has [] set so we are looking at a node path
+        $form['type'] = array('#type' => 'value', '#value' => 'nodetype');
+        $type = 'nodetype';
+        $key = $form_state['storage']['helpkey'];
+      }    
+// end JV
     }
     else {
       $key = $form_state['storage']['helpkey'];
@@ -255,7 +338,11 @@
     $form['book_trees'] = array('#type' => 'value', '#value' => $trees);
 
     // Find out if a help topic has already been selected.
+
     $defaults = helpinject_get_from_key($type, $key);
+// JV https://www.drupal.org/node/1022912
+    $default =  $defaults[$key]; // this is very inconsistently used throughout the module it seems, sometimes with a foreach, array_pop is used and now this
+// end JV
     // Build the options. It's simply a list of nids from the {book} table.
     $options = array();
     // Make sure there's an option for NONE (to remove a mapping, for example).
@@ -275,7 +362,10 @@
       '#title' => t('Available book pages'),
       '#description' => t('Choose the book page that should be used for this item, or !create a new one.', array('!create' => $book_add_link)),
       '#options' => $options,
-      '#default_value' => empty($defaults) ? 'none' : $defaults[$key]['nid'],
+// JV https://www.drupal.org/node/1022912
+//      '#default_value' => empty($defaults) ? 'none' : $defaults[$key]['nid'],
+      '#default_value' => empty($default) ? 'none' : $default['nid'] ,  // Ok, this just does not work. Even hardcoding the nid will not set the radio to the right default. Beats me      
+// end JV
     );
     $form['submit'] = array(
       '#title' => t('Submit'),
@@ -290,7 +380,10 @@
 function helpinject_injection_form_submit($form, &$form_state) {
   // It's important that we only go into this first block if we're dealing with
   // 'path' types, and if the helpkey hasn't yet been chosen.
-  if (empty($form_state['storage']['helpkey']) && $form_state['values']['type'] == 'path') {
+// JV https://www.drupal.org/node/1022912  
+//  if (empty($form_state['storage']['helpkey']) && $form_state['values']['type'] == 'path') {
+  if (empty($form_state['storage']['helpkey']) && (($form_state['values']['type'] == 'path') || ($form_state['values']['type'] == 'nodetype'))) {
+// end JV
     $form_state['storage']['helpkey'] = $form_state['values']['helpkey'];
     $form_state['storage']['type'] = $form_state['values']['type'];
     $form_state['rebuild'] = TRUE;
@@ -729,8 +822,12 @@
   }
   $values = array();
   $params = array_merge(array($type), $key);
-  $result = db_query("SELECT h.*, n.title FROM {helpinject} h INNER JOIN {node} n ON h.nid = n.nid WHERE h.type = '%s' AND h.helpkey in (" . implode(',', $s) . ")", $params);
+// JV https://www.drupal.org/node/1022912  
+  $result = db_query("SELECT h.*, n.title FROM {helpinject} h INNER JOIN {node} n ON h.nid = n.nid WHERE h.type = '%s' AND h.helpkey = '%s'", $params[0], $params[1]);
+// $result = db_query("SELECT h.*, n.title FROM {helpinject} h INNER JOIN {node} n ON h.nid = n.nid WHERE h.type = '%s' AND h.helpkey in (" . implode(',', $s) . ")", $params);
+// end JV
   while ($row = db_fetch_array($result)) {
+    
     $row['title'] = helpinject_munge_title($row['title']);
     $values[$row['helpkey']] = $row;
   }
