diff -dup /var/www/sites/all/modules/menu_trim_bak/1.2-080407/menu_trim.info /var/www/sites/all/modules/menu_trim_bak/alpha2/menu_trim.info
--- /var/www/sites/all/modules/menu_trim_bak/1.2-080407/menu_trim.info	2007-06-18 20:19:22.000000000 -0400
+++ /var/www/sites/all/modules/menu_trim_bak/alpha2/menu_trim.info	2008-04-18 15:57:09.000000000 -0400
@@ -1,9 +1,8 @@
-; $Id: menu_trim.info,v 1.2 2007/06/18 22:53:49 dww Exp $
+; $Id
 name = Menu Trim
 description = "Allows menu hierarchies to be trimmed when navigated."
 
-; Information added by drupal.org packaging script on 2007-06-19
-version = "5.x-1.x-dev"
+; Information added by drupal.org packaging script on 2008-04-18
+version = "5.x-2.alpha2"
 project = "menu_trim"
-datestamp = "1182212362"
 
diff -dup /var/www/sites/all/modules/menu_trim_bak/1.2-080407/menu_trim.install /var/www/sites/all/modules/menu_trim_bak/alpha2/menu_trim.install
--- /var/www/sites/all/modules/menu_trim_bak/1.2-080407/menu_trim.install	2007-01-12 19:59:05.000000000 -0500
+++ /var/www/sites/all/modules/menu_trim_bak/alpha2/menu_trim.install	2008-04-17 16:50:32.000000000 -0400
@@ -1,10 +1,92 @@
 <?php
-// $Id: menu_trim.install,v 1.1 2007/01/13 00:59:05 davidlesieur Exp $
-
+// $Id: menu_trim.install,v 1.1 2007/01/13 00:59:05 davidlesieur Exp $
+
+define ('MENU_TRIM_DISABLED', 0);
+
+/**
+ * Implementation of hook_install().
+ */
+function menu_trim_install() {
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      db_query("CREATE TABLE {menu_trim} (
+        mid int(10) unsigned NOT NULL default '0',
+        trim tinyint(1) NOT NULL default '0',
+        PRIMARY KEY (mid)
+      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
+      break;
+    case 'pgsql':
+      db_query("CREATE TABLE {menu_trim} (
+        mid int_unsigned NOT NULL default '0',
+        trim smallint NOT NULL default '0',
+        PRIMARY KEY (mid)
+      )");
+      break;
+  }
+}
+
 /**
  * Implementation of hook_uninstall().
  */
 function menu_trim_uninstall() {
-  db_query("DELETE FROM {variable} WHERE name LIKE 'menu_trim_%'");
+  if (db_table_exists('menu_trim')) {
+    db_query("DROP TABLE {menu_trim}");
+  }
+  variable_del('menu_trim');
+
   cache_clear_all('variables', 'cache');
 }
+
+function menu_trim_update_2() {
+  $ret = array();
+
+  // Clear the variables cache so the data are taken from the variable table and not its cache
+  cache_clear_all('variables', 'cache');
+
+  // Update trimmable items
+  $vars = db_query("SELECT name FROM {variable} WHERE name LIKE 'menu_trim_item_%%'");
+  // Iterate trimmable items
+  while ($var = db_fetch_object($vars)) {
+    $var_id = str_replace('menu_trim_item_', '', $var->name);
+    $var_data = variable_get($var->name, NULL);
+    // Menu item insertion
+    $ret[] = update_sql("INSERT INTO {menu_trim} (mid, trim) VALUES (". $var_id .", ". $var_data .")");
+  }
+
+  // Upon succesful update, delete the corresponding previous version entry 
+  $vars = db_query("SELECT mid FROM {menu_trim}");
+  // Iterate trimmable items
+  while ($var = db_fetch_object($vars)) {
+    if ($var->mid) {
+      variable_del('menu_trim_item_'. $var->mid);
+    }
+  }
+
+  // Update setting items
+  $menu = array();
+  $vars = db_query("SELECT name FROM {variable} WHERE name LIKE 'menu_trim_menu_%%'");
+  // Iterate setting items
+  while ($var = db_fetch_object($vars)) {
+    $var_id = str_replace('menu_trim_menu_', '', $var->name);
+    $var_data = variable_get($var->name, MENU_TRIM_DISABLED);
+    // based on : menu_trim_admin_settings_submit and _menu_trim_settings_set
+    $menu[$var_id] = array('method' => $var_data, 'root_title' => 1, 'min_level' => '', 'min_limit' => 0);
+  }
+  variable_set('menu_trim', $menu);
+
+  // Delete old setting items
+  $vars = variable_get('menu_trim', NULL);
+  // Iterate setting items
+  if (is_array($vars)) {
+    foreach ($vars as $var_id => $var_data) {
+      variable_del('menu_trim_menu_'. $var_id);
+    }
+  }
+
+  // Clear the variables cache as some should've been deleted
+  cache_clear_all('variables', 'cache');
+
+  return $ret;
+}
+
diff -dup /var/www/sites/all/modules/menu_trim_bak/1.2-080407/menu_trim.module /var/www/sites/all/modules/menu_trim_bak/alpha2/menu_trim.module
--- /var/www/sites/all/modules/menu_trim_bak/1.2-080407/menu_trim.module	2007-01-12 19:59:05.000000000 -0500
+++ /var/www/sites/all/modules/menu_trim_bak/alpha2/menu_trim.module	2008-04-17 16:48:42.000000000 -0400
@@ -2,38 +2,54 @@
 // $Id: menu_trim.module,v 1.2 2007/01/13 00:59:05 davidlesieur Exp $
 
 /**
- * @file Allows menu hierarchies to be trimmed when navigated. By trimming, here
- * we mean skipping the display of parent menu items when any of some designated
- * items becomes active.
- *
- * At the simplest level, this module allows to hide a menu until some of its
- * items has become the active item (by reaching the corresponding url). This is
- * easier than configuring the menu's block visibility for each possible path
- * contained in the menu.
- *
- * This module can be used to make a "contextual secondary menu" based on the
- * primary links (e.g. you set the Primary links menu for "Allow trimming for
- * this menu, hide menu when no item is active", activate the "Primary links
- * (menu_trim)" block, then edit the menu's top-level items and check the "Trim
- * parent items" option). After that, when an item is selected in the primary
- * links, the contextual menu will appear, showing only the subitems of the
- * selected item. Drupal already allows contextual "secondary links" based on
- * the primary links, but these secondary links are limited to a depth of one
- * level. Menu Trim, on the other hand, can display complete menu subtrees.
- *
- * This module can also be used in any menu to trim parents when reaching deep
- * menu items.  This can make deep menus more usable, and the breadcrumb will
- * still show the full path.
+ * @file
+ * Add alternative menu blocks that add the possibility of trimming
+ * some of the top of it's hierarchy so it would start displaying from
+ * certain menu items or from a whole level (ex: tertiary).
+ *
+ * @author David Lesieur
+ * @author William Carrier
  */
 
-// TODO: When a menu item is deleted, remove the corresponding menu_trim_item_mid variable, if any.
-
-define ('MENU_TRIM_DISABLED', 0);
+// TODO: When a menu item is deleted, remove the corresponding entries, if any.// TODO: Add a system to reduce the load in the search of other menu items up the menu tree which requires CPU and DB hits.
+// TODO: Look at menu.modules or default menu blocks for the default Root Title.
+
+// Trimming methods
+define ('MENU_TRIM_DISABLED', 0);
 define ('MENU_TRIM_ENABLED_SHOW_MENU_ALWAYS', 1);
-define ('MENU_TRIM_ENABLED_SHOW_MENU_ACTIVE', 2);
+define ('MENU_TRIM_ENABLED_SHOW_MENU_ACTIVE', 2);
+
+/**
+ * Implementation of hook_help().
+ */
+function menu_trim_help($section) {
+  switch ($section) {
+    case 'admin/help#menu_trim':
+      $output = '<p>'. t('The menu trim module create copies of menu blocks allowing user with menu modification permissions to trim its parent menus.') .'</p>';
+      $output .= '<p>'. t('To make trimmed menus, you must first select the module behavior for each menus in the <a href="@settings">module settings</a>.  Then you need to select appropriately the <em>Trim parent items</em> option in the menus to enable trimming its parents.  At last, you need to display the menu trim blocks.  Now when reaching the enabled menu items, its parents should be trimmed.', array('@settings' => 'admin/settings/menu_trim')) .'</p>';
+      $output .= '<p>'. t('For more information please refer to the <a href="@project">project page</a>.', array('@project' => 'http://drupal.org/project/menu_trim')) .'</p>';
+      return $output;
+    case 'admin/settings/menu_trim':
+      $output = '<p>'. t('Choose the menus that need to be trimmed. Each of the menus where trimming is allowed will get a corresponding <em>Menu trim</em> block with appropriate options. You should then <a href="@enable">enable those blocks</a>, and <a href="@edit">edit the menu items</a> to <em>Trim parent items</em>.', array('@enable' => url('admin/build/block')), array('@edit' => url('admin/build/menu'))) .'</p>';
+      $output .= '<p>'. t('For example, if you want to show items in its trimmable menu only starting at secondary links, you show edit the primary links with it\'s level at <em>2</em> and having its limit checked.') .'</p>';
+      $output .= '<dl>'. t('Options definitions :');
+      $output .= '<dt>'. t('Trim Method') .'</dt>';
+      $output .= '<dd>'. t('<em>Allow trimming</em> will display a root menu by default.') .'</dd>';
+      $output .= '<dt>'. t('Root Title') .'</dt>';
+      $output .= '<dd>'. t('Enables a title when displaying a root menu.') .'</dd>';
+      $output .= '<dt>'. t('Min. Level') .'</dt>';
+      $output .= '<dd>'. t('A minimum level from which starting displaying a menu by default.') .'</dd>';
+      $output .= '<dt>'. t('Limit') .'</dt>';
+      $output .= '<dd>'. t('Won\'t allow trimmable items to trim under its menu minimum level.') .'</dd>';
+      $output .= '</dl>';
+      return $output;
+  }
+}
 
 /**
- * Implementation for hook_menu().
+ * Implementation for hook_menu().
+ *
+ * @see menu_trim_admin_settings
  */
 function menu_trim_menu($may_cache) {
   $items = array();
@@ -41,126 +57,269 @@ function menu_trim_menu($may_cache) {
   if ($may_cache) {
     $items[] = array(
       'path' => 'admin/settings/menu_trim',
-      'title' => t('Menu trim'),
+      'title' => t('Menu Trim'),
       'description' => t('Choose what menus need trimming.'),
       'callback' => 'drupal_get_form',
       'callback arguments' => array('menu_trim_admin_settings'),
-      'access' => user_access('administer site configuration'),
+      'access' => user_access('administer menu trim'),
       'type' => MENU_NORMAL_ITEM,
     );
   }
-
   return $items;   
 }
+
+/**
+ * Implementation of hook_perm().
+ */
+function menu_trim_perm() {
+  return array('administer menu trim');
+}
 
 /**
- * Administration page callback.
+ * Administration page callback.
+ *
+ * @see theme_menu_trim_admin_settings
+ * @see menu_trim_admin_settings_validate
+ * @see menu_trim_admin_settings_submit
  */
 function menu_trim_admin_settings() {
-  $form['menu_trim'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Trim menus'),
-    '#description' => t('Choose the menus that need to be trimmed. Each of the menus where trimming is allowed will get a corresponding <em>Menu trim</em> block. You should then !enable, and !edit that need to have their parents trimmed.', array('!enable' => l(t('enable those blocks'), 'admin/build/block'), '!edit' => l(t('edit the menu items'), 'admin/build/menu'))),
-  );
-    
-  $menus = menu_get_root_menus();
-  foreach ($menus as $mid => $title) {
-    $form['menu_trim']['menu_trim_menu_'. $mid] = array(
-      '#type' => 'select',
+  $menu_list = menu_get_root_menus();
+  $menu_fetched = variable_get('menu_trim', NULL);
+  $menu = is_array($menu_fetched) ? $menu_fetched : array();
+
+  foreach ($menu_list as $mid => $title) {
+    $form[$mid] = array(
+      '#tree' => TRUE,
+    );
+    $form[$mid]['title'] = array(
+      '#type' => 'item',
       '#title' => check_plain($title),
+    );
+    $form[$mid]['method'] = array(
+      '#type' => 'select',
       '#options' => array(
-        MENU_TRIM_DISABLED => t('Never trim this menu'),
-        MENU_TRIM_ENABLED_SHOW_MENU_ALWAYS => t('Allow trimming of this menu'),
-        MENU_TRIM_ENABLED_SHOW_MENU_ACTIVE => t('Allow trimming of this menu, hide menu when no item is active'),
+        MENU_TRIM_DISABLED => t('Never trim'),
+        MENU_TRIM_ENABLED_SHOW_MENU_ALWAYS => t('Allow trimming'),
+        MENU_TRIM_ENABLED_SHOW_MENU_ACTIVE => t('Allow trimming, hide when inactive'),
       ),
-      '#default_value' => variable_get('menu_trim_menu_'. $mid, MENU_TRIM_DISABLED),
-    );
+      '#default_value' => $menu[$mid]['method'] ? $menu[$mid]['method'] : MENU_TRIM_DISABLED,
+    );
+    $form[$mid]['root_title'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => $menu[$mid]['root_title'] ? $menu[$mid]['root_title'] : FALSE,
+    );
+    $form[$mid]['min_level'] = array(
+      '#type' => 'textfield',
+      '#default_value' => $menu[$mid]['min_level'],
+      '#size' => 2,
+      '#maxlength' => 2,
+    );
+    $form[$mid]['min_level_limit'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => $menu[$mid]['min_level_limit'] ? $menu[$mid]['min_level_limit'] : FALSE,
+    );
   }
-
   return system_settings_form($form);
 }
-
+
+/**
+ * Format the settings form.
+ *
+ * Makes a table separating each menu by row.
+ */
+function theme_menu_trim_admin_settings($form) {
+  $rows = array();
+  foreach ($form as $key => $element) {
+    $title1 = $element['title'];
+    if (is_array($title1) && $title1['#type'] == 'item') {
+      $rows[] = array(drupal_render($form[$key]['title']), drupal_render($form[$key]['method']), drupal_render($form[$key]['root_title']), drupal_render($form[$key]['min_level']), drupal_render($form[$key]['min_level_limit']));
+    }
+  }
+  // First item must have colspan to include hidden items
+  $header = array(array('data' => t('Menu')), array('data' => t('Trim Method')), array('data' => t('Root Title')), array('data' => t('Min. Level')), array('data' => t('Limit')));
+  $output = theme('table', $header, $rows);
+  $output .= drupal_render($form);
+  return $output;
+}
+
+/**
+ * Form API callback to validate the settings form.
+ *
+ * Validate the textfield min_level.
+ */
+function menu_trim_admin_settings_validate($form_id, $form_values) {
+  foreach ($form_values as $key => $element) {
+    // Validate minimum level field
+    if (is_array($element)) {
+      // Validation must be made in 2 steps or it might skip 0
+      if (is_numeric($element['min_level'])) {
+        if ($element['min_level'] <= 0) {
+        form_set_error($key .'][min_level', t('The minimum level must be an integer greater than zero.'));
+        }
+      }
+      elseif ($element['min_level']) {
+        form_set_error($key .'][min_level', t('The minimum level must be an integer greater than zero.'));
+      }
+    }
+  }
+}
+
+/**
+ * Form API callback to submit the settings form.
+ *
+ * Save language settings in variable
+ */
+function menu_trim_admin_settings_submit($form_id, $form_values) {
+  $menu = array();
+  foreach ($form_values as $key => $element) {
+    // Find appropriate element
+    if (is_array($element)) {
+      $menu[$key] = array('method' => $element['method'], 'root_title' => $element['root_title'], 'min_level' => $element['min_level'], 'min_level_limit' => $element['min_level_limit']);
+    }
+  }
+  variable_set('menu_trim', $menu);
+  $menu_set = !db_error();
+  if (!$menu_set) {
+    drupal_set_message(t('The settings did not save properly.'), 'error');
+  }
+}
+
 /**
  * Implementation of hook_block().
  */
-function menu_trim_block($op = 'list', $delta = 0, $edit = array()) {
+function menu_trim_block($op = 'list', $delta = 0, $edit = array()) {
   switch ($op) {
     case 'list':
       $blocks = array();
-      $menus = menu_get_root_menus();
-      foreach ($menus as $mid => $title) {
-        if (variable_get('menu_trim_menu_'. $mid, MENU_TRIM_DISABLED) != MENU_TRIM_DISABLED) {
-          $blocks[$mid]['info'] = check_plain($title) .' ('. t('Menu trim') .')';
+      $menu = variable_get('menu_trim', NULL);
+      if (is_array($menu)) {
+        $root_menus = menu_get_root_menus();
+        foreach ($root_menus as $mid => $title) {
+          if ($menu[$mid] && $menu[$mid]['method'] != MENU_TRIM_DISABLED) {
+            $blocks[$mid]['info'] = check_plain($title) .' ('. t('Menu Trim') .')';
+          }
         }
       }
       return $blocks;
-      
-    case 'view':
-      if (($mode = variable_get('menu_trim_menu_'. $delta, MENU_TRIM_DISABLED)) != MENU_TRIM_DISABLED) {
-        // Get the trail of the active item in the $delta menu. If the active
-        // item is not in that menu, the menu won't be shown at all.
-        $trail = _menu_get_active_trail_in_submenu($delta);
-        if (is_array($trail)) {
-          // The active item is child of this menu, check for trimming
-          while ($mid = array_pop($trail)) {
-            if (variable_get('menu_trim_item_'. $mid, FALSE)) {
-              // Show the menu using the item as root
-              $item = menu_get_item($mid);
-              $data['subject'] = check_plain($item['title']);
-              $data['content'] = theme('menu_tree', $mid);
-              break;
-            }
-          }
-          if (!$data) {
-            // No trim flag found in the trail, show the full menu
+    case 'view':
+      $data = array();
+      $menu = variable_get('menu_trim', NULL);
+      if (is_array($menu)) {
+        $mode = $menu[$delta]['method'];
+        if ($mode != MENU_TRIM_DISABLED) {
+          $trail = _menu_get_active_trail_in_submenu($delta);
+          // Active inclusion verification
+          if (is_array($trail)) {
+            $level = isset($menu, $delta, $menu[$delta]['min_level']) ? $menu[$delta]['min_level'] : NULL;
+            // Level validation
+            if ($level) {
+              $limit = isset($menu, $delta) && $menu[$delta]['min_level_limit'];
+              // Limit verification
+              if (!$limit || (count($trail) > $level)) { // Will only evaluate second part if it's a limit ; the trail count includes the root so has an extra level
+                // Trail verification : looking for an item marked trimmable or the level limit                while ($mid = array_pop($trail)) {
+                  // Level verification                  if (count($trail) == $level) {
+                    if ($limit) {
+                      // Show the menu using the item as base                      $item = menu_get_item($mid);
+                      $data['subject'] = $item['title'];
+                      $data['content'] = theme('menu_tree', $mid);
+                      break;                    }
+                    else {
+                      $limit_mid = $mid;
+                      $limit_item = menu_get_item($mid);
+                    }
+                  }
+                  elseif (db_result(db_query("SELECT trim FROM {menu_trim} WHERE mid=%d", $mid))) {
+                    // Show the menu using the item as base                    $item = menu_get_item($mid);
+                    $data['subject'] = $item['title'];
+                    $data['content'] = theme('menu_tree', $mid);
+                    break;                  }
+                }
+                // Apply minimum level if it wasn't a limit ; verify that no trailing items was marked and a level has been reached
+                if (!$data && isset($limit_mid, $limit_item)) { // Should have data if there was a limit so skip !$limit
+                  // Show the menu using minimum level item as base
+                  $data['subject'] = $limit_item['title'];
+                  $data['content'] = theme('menu_tree', $limit_mid);
+                }
+              }
+            }
+            else {
+              // Trail verification : looking for an item marked trimmable or the level limit              while ($mid = array_pop($trail)) {                if (db_result(db_query("SELECT trim FROM {menu_trim} WHERE mid=%d", $mid))) {
+                  // Show the menu using the item as base                  $item = menu_get_item($mid);
+                  $data['subject'] = $item['title'];
+                  $data['content'] = theme('menu_tree', $mid);
+                  break;
+                }
+              }
+            }
+          }
+          // Verify if is supposed to always show a menu and none has been set          if ($mode == MENU_TRIM_ENABLED_SHOW_MENU_ALWAYS && !$data) { 
+            // Show the menu using root item as base
             $item = menu_get_item($delta);
-            $data['subject'] = check_plain($item['title']);
+            $data['subject'] = $menu[$delta]['root_title'] ? $item['title'] : '';
             $data['content'] = theme('menu_tree', $delta);
           }
         }
-        elseif ($mode == MENU_TRIM_ENABLED_SHOW_MENU_ALWAYS) {
-          // The active item is not child of this menu, show the plain menu
-          $item = menu_get_item($delta);
-          $data['subject'] = check_plain($item['title']);
-          $data['content'] = theme('menu_tree', $delta);
-        }
-        // Otherwise, $mode == MENU_TRIM_ENABLED_MENU_SHOW_ACTIVE, do not show
-        // the menu since it has to be shown only when it contains an active
-        // item
       }
       return $data;
   }
 }
 
 /**
- * Implementation of hook_form_alter().
+ * Implementation of hook_form_alter().
+ *
+ * @param $form need to be passed by referrence
+ *
+ * @see menu_trim_edit_item_form_submit
  */
 function menu_trim_form_alter($form_id, &$form) {
   if ($form_id == 'menu_edit_item_form') {
+    $menu = variable_get('menu_trim', NULL);
     $mid = $form['mid']['#value'];
-    $item = menu_get_item($mid);
-    // Check if this item is in a menu that is set for trimming
-    while ($item['pid']) {
-      $root_mid = $item['pid'];
-      $item = menu_get_item($item['pid']);
-    }
-    if (variable_get('menu_trim_menu_'. $root_mid, MENU_TRIM_DISABLED) != MENU_TRIM_DISABLED) {
-      $form['trim_item'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Trim parent items.'),
-        '#description' => t('Check this option to trim the parent items when this item or any of its children becomes active.') .'<br />'. t('Trimming applies only to the menu\'s corresponding <em>Menu trim</em> !block, not to its normal block. When trimming occurs, this item\'s title will become the menu\'s title. Note also that if this item has no children, has its parents trimmed, and becomes active, then no menu will be displayed at all since such menu would be empty.', array('!block' => l(t('block'), 'admin/build/block'))),
-        '#default_value' => variable_get('menu_trim_item_'. $mid, FALSE),
-        '#weight' => 1,
-      );
-      $form['#submit']['menu_trim_edit_item_form_submit'] = current($form['#submit']);
-
-      // Make sure the button remains at the form's bottom
-      $form['submit']['#weight'] = 10;
+    // Initialisation verification    if (isset($menu, $mid)) {
+      $item = menu_get_item($mid);
+      // Retreive root menu, based on _menu_get_active_trail()      while ($item['pid']) {
+        $root = $item['pid'];
+        $item = menu_get_item($item['pid']);
+      }
+      // Verify if current item root has trimming enabled
+      if ($menu[$root]['method'] != MENU_TRIM_DISABLED) {
+        $form['trim'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Trim parent items'),
+          '#description' => t('Check this option to trim the parent items when this item or any of its children becomes active in its menu <em>Menu trim</em> corresponding <a href="@block">block</a>, not its default one.', array('@block' => url('admin/build/block'))) . theme_more_help_link('admin/help/menu_trim'),
+          '#default_value' => db_result(db_query("SELECT trim FROM {menu_trim} WHERE mid=%d", $mid)),
+          '#weight' => 1,
+        );
+        $form['#submit']['menu_trim_edit_item_form_submit'] = current($form['#submit']);
+        // Make sure the button remains at the form's bottom        $form['submit']['#weight'] = 10;
+      }
     }
   }
 }
 
-function menu_trim_edit_item_form_submit($form_id, $form_values) {
-  variable_set('menu_trim_item_'. $form_values['mid'], $form_values['trim_item']);
-}
-
+/**
+ * Form submittion customization for edit_item_form.
+ * The parameters are the same of the calling function menu_trim_form_alter.
+ */
+function menu_trim_edit_item_form_submit($form_id, $form_values) {
+  // Form validation
+  if (isset($form_values['trim'])) {
+    // Menu trimming option saving and verification
+    db_lock_table('menu_trim');
+    $db_result_1 = db_result(db_query("SELECT mid FROM {menu_trim} WHERE mid=%d", $form_values['mid']));
+    // Entry verification
+    if ($db_result_1) {
+      // Update a menu
+      $db_result_2 = db_query("UPDATE {menu_trim} SET trim=%d WHERE mid=%d", $form_values['trim'], $form_values['mid']);
+    }
+    else {
+      // Insert a menu
+      $db_result_2 = db_query("INSERT INTO {menu_trim} (mid, trim) VALUES (%d, %d)", $form_values['mid'], $form_values['trim']);
+    }
+    if (db_error() || !$db_result_2) { 
+      drupal_set_message(t('A database issue prevented Menu trim to modify its status for the menu %menu.', array('%menu' => $form_values['mid'])), 'error');
+    }
+    db_unlock_tables();
+  }
+}
+
diff -dup /var/www/sites/all/modules/menu_trim_bak/1.2-080407/README.txt /var/www/sites/all/modules/menu_trim_bak/alpha2/README.txt
--- /var/www/sites/all/modules/menu_trim_bak/1.2-080407/README.txt	2007-01-12 19:59:05.000000000 -0500
+++ /var/www/sites/all/modules/menu_trim_bak/alpha2/README.txt	2008-04-18 15:12:32.000000000 -0400
@@ -1,64 +1,80 @@
-README file for the Menu Trim Drupal module.
-
-
-Description
-***********
-
-The Menu Trim module allows menu hierarchies to be trimmed when navigated. By
-trimming, here we mean skipping the display of parent menu items when any of
-some designated items becomes active.
-
-At the simplest level, this module allows to hide a menu until some of its items
-has become the active item (by reaching the corresponding url). This is easier
-than configuring the menu's block visibility for each possible path contained in
-the menu.
-
-This module can be used to make a "contextual secondary menu" based on the
-primary links (e.g. you set the Primary links menu for "Allow trimming for this
-menu, hide menu when no item is active", activate the "Primary links
-(Menu trim)" block, then edit the menu's top-level items and check the "Trim
-parent items" option). After that, when an item is selected in the primary
-links, the contextual menu will appear, showing only the subitems of the
-selected item. Drupal already allows contextual "secondary links" based on the
-primary links, but these secondary links are limited to a depth of one
-level. Menu Trim, on the other hand, can display complete menu subtrees.
-
-This module can also be used in any menu to trim parents when reaching deep menu
-items. This can make deep menus more usable, and the breadcrumb will still show
-the full path.
-
-
-Compatibility
-*************
-
-This module has been tested on Drupal 4.7.4 and 5.0 RC2.
-
-
-Installation
-************
-
-1. Extract the 'menu_trim' module directory into your Drupal modules directory.
-
-2. Enable the Menu Trim module on your site's Administer > Site building >
-   Modules page.
-
-3. Go to Administer > Site configuration > Menu trim, and configure some menus
-   to allow trimming. Select "Allow trimming for this menu, hide menu when no
-   item is active" if you not only want a menu to be trimmed on some designated
-   items, but to also make it "contextual" (appearing only when url matching
-   some of its items is requested).
-
-4. Go to Administer > Site building > Blocks, and enable the "Menu trim" blocks
-   for each of the menus for which trimming was allowed.
-
-5. Go to Administer > Site building > Menus, and edit each item that needs its
-   parents to be trimmed by checking "Trim parent items" in the item's edit
-   form.
-
-
+README file for the Menu Trim Drupal module.
+
+
+Description
+***********
+
+The Menu Trim module allows menu hierarchies to be trimmed when navigated. By
+trimming, here we mean skipping the display of parent menu items when any of
+some designated items becomes active.
+
+At the simplest level, this module allows to hide a menu until some of its items
+has become the active item (by reaching the corresponding url). This is easier
+than configuring the menu's block visibility for each possible path contained in
+the menu.
+
+This module can be used to make a "contextual secondary menu" based on the
+primary links (e.g. you set the Primary links menu for "Allow trimming for this
+menu, hide menu when no item is active", activate the "Primary links
+(Menu trim)" block, then edit the menu's top-level items and check the "Trim
+parent items" option). After that, when an item is selected in the primary
+links, the contextual menu will appear, showing only the subitems of the
+selected item. Drupal already allows contextual "secondary links" based on the
+primary links, but these secondary links are limited to a depth of one
+level. Menu Trim, on the other hand, can display complete menu subtrees.
+
+A new feature for version 2.0 has been the automation of trimming a menu dept so
+instead of choosing a specific dept, let's say the third, instead of going to
+the menu and selecting each menu item on the third level, you simply need to go
+to Menu Trim settings and at the menu row enter "3" in the Min. Level column ;
+this also save you the hassle of selecting the third level items of added menu
+branches. The minimum level also has the ability of being a trimming limit so if
+an item is selected with a dept lower than it, it won't be displayed as trimmed.
+Another feature is to toggle the display of the title for the default root menu
+with the option Root Title.
+
+This module can also be used in any menu to trim parents when reaching deep menu
+items. This can make deep menus more usable, and the breadcrumb will still show
+the full path.
+
+
+Installation
+************
+
+1. Extract the 'menu_trim' module directory into your Drupal modules directory.
+
+2. Enable the Menu Trim module on your site's Administer > Site building >
+   Modules page.
+
+3. Go to Administer > Site configuration > Menu trim, and configure some menus
+   to allow trimming. Select "Allow trimming, hide when inactive" if you not
+   only want a menu to be trimmed on some designated items, but to also make it
+   "contextual" (appearing only when the url is matching some of its items is
+   requested).  If you desire a different title behavior for root menus, un/check
+   the Root Title box. If desired, choose a minimum level from which trimming
+   start and if you don't want any item to trim before it, check the Limit box.
+
+4. Go to Administer > Site building > Blocks, and enable the "Menu trim" blocks
+   for each of the menus for which trimming was allowed.
+
+5. Go to Administer > Site building > Menus, and edit each item that needs its
+   parents to be trimmed by checking "Trim parent items" in the item's edit
+   form.
+
 Credits
 *******
+
+Version 1.0
+-----------
 
 David Lesieur, http://davidlesieur.com.
 
-This module was developed for a client of Koumbit.org (http://koumbit.org).
+Initially developed on behalf of Koumbit.org (http://koumbit.org).
+
+Version 2.0
+-----------
+
+William Carrier, http://www.williamcarrier.com.
+
+Upgrade slighty sponsored by Koumbit.org (http://koumbit.org).
+
