--- sites/all/modules/menu_stp/menu_stp.module.orginal	2008-07-23 15:35:27.000000000 -0500
+++ sites/all/modules/menu_stp/menu_stp.module	2008-07-23 15:57:23.000000000 -0500
@@ -1,5 +1,5 @@
 <?php
-// $Id: menu_stp.module,v 1.1.2.2 2007/07/24 09:45:52 ray007 Exp $
+// $Id: menu_stp.module,v 1.4 2007/07/24 09:39:43 ray007 Exp $
 
 /**
  * @file
@@ -42,6 +42,21 @@ function menu_stp_form_alter($form_id, &
         '#options' => user_roles(1),
         '#default_value' => _menu_stp_roles($form['mid']['#value'])
       );
+	  if (module_exists('acl')) {
+	    $form['menu_stp']['acl'] = array(
+	      '#type' => 'fieldset',
+	      '#title' => t('User access control lists'),
+	      '#description' => t('These settings allow you to grant access to specific users.'),
+	      '#collapsible' => TRUE,
+	      '#tree' => TRUE,
+	    );
+		$acl_id = acl_get_id_by_name('menu_stp', $form['mid']['#value']);
+		if (!$acl_id) { // create one
+			$acl_id = acl_create_new_acl('menu_stp', $form['mid']['#value']);
+		}
+		$form['menu_stp']['acl']['access'] = acl_edit_form($acl_id, 'Grant menu access');
+		$form['menu_stp']['acl']['access']['#collapsed'] = !isset($_POST['menu_stp']['acl']['access']['add_button']) && !isset($_POST['menu_stp']['acl']['access']['delete_button']);
+      }
 
       // TODO: more options for other auth-methods like ACL and organic groups
       // probably only links to forms here, so this form doesn't get too big
@@ -70,11 +85,11 @@ function _menu_stp_alter_node_edit_form(
   if (!$rids) return; // no roles -> no menu-editing
 
   $mid = $form['menu']['mid']['#value'];
-  if ($mid) { // we already have a menu-item for here
-  	$item = menu_get_item($mid);
-  	//$pid = $mid = $form['menu']['pid']['#value'];
-  	if(!_menu_stp_has_perms_roles($item['pid'], $rids)) return; // menu-item not in editable part of menu
-  }
+  // if ($mid) { // we already have a menu-item for here
+  	// $item = menu_get_item($mid);
+  	// $pid = $mid = $form['menu']['pid']['#value'];
+  	// if(!_menu_stp_has_perms_roles($item['pid'], $rids)) return; // menu-item not in editable part of menu
+  // }
 
   // clean up the possible parent array
   $mids = _menu_stp_editable_mids_by_roles($rids);
@@ -118,11 +133,20 @@ function _menu_stp_full_title($mid) {
  * @returns array with the menu-ids as keys, values: 1 for subtree-roots, 2 for editable items below
  */
 function _menu_stp_editable_mids_by_roles(&$rids) {
+  global $user;
   $mids = array();
   $res = db_query("SELECT DISTINCT mid FROM {menu_stp_roles} WHERE rid IN (".implode(',',$rids).");");
   while($row = db_fetch_array($res)) {
     $mids["{$row['mid']}"] = 1; // for the roots of the editable parts
   }
+  if (module_exists('acl')) {
+  	$result = db_query("SELECT acl_id, name FROM {acl} WHERE module = 'menu_stp'");
+  	while ($acl = db_fetch_object($result)) {
+  	  if (db_result(db_query("SELECT uid FROM {acl_user} aclu WHERE uid={$user->uid} AND acl_id = %d", $acl->acl_id))) {
+	    $mids[$acl->name] = 1;
+  	  }
+  	}
+  }
   // and now start adding the children
   $new_mids = array_keys($mids);
   while ($new_mids) {
@@ -162,13 +186,15 @@ function _menu_stp_has_perms_roles($mid,
       if($mi['pid']) {
       	$mids[] = $mi['pid'];
       }
-      $mid = $mi['pid'];
+			$mid = $mi['pid'];
+      // $mid = $row['pid'];
     } while($mid);
   }
   $ridstr = implode(',', $rids);
-  $midstr = implode(',', $mids);
+  $midstr = implode(',', $mids);		
   $res = db_query("SELECT count(*) AS pnum FROM {menu_stp_roles} WHERE rid IN ($ridstr) AND mid IN ($midstr);");
   $perms = db_fetch_array($res);
+	
   return ($perms['pnum'] > 0);
 }
 
@@ -274,6 +300,9 @@ function menu_stp_form_submission($form_
       }
       // else no change in permission for this role
     }
+    if (module_exists('acl') && isset($form['acl']['access'])) {
+      acl_save_form($form['acl']['access']);
+    }
     break;
   }
 }
@@ -286,4 +315,4 @@ function menu_stp_delete_confirm($form_i
   db_query("DELETE FROM {menu_stp_roles} WHERE mid = '$form[mid]';");
 }
 
-?>
+?>
\ No newline at end of file
