--- C:/Documents and Settings/jmelnik/Desktop/mynodetemplate.module	Mon Sep 03 15:59:56 2007
+++ C:/Documents and Settings/jmelnik/Desktop/nodetemplate.module	Tue Jul 31 18:22:59 2007
@@ -441,44 +441,49 @@
 	$yes = t('yes');
 	$no = t('no');
 	$shared_mark = t('*');
-	while ($row = db_fetch_object($result)) {
 
+	while ($row = db_fetch_object($result)) {
+		// it's a node
 		if ($row->node == 1) {
-
-			//determine user access to template node
-			$shared = db_result(db_query('SELECT shared FROM {node_template} WHERE nid = %d', $row->nid));
-			if (($row->uid == $user->uid) || ($user->uid == 1)) {
-				$access = true;
+			// Duplicate permissions are set by the nodetype's access hook.
+			// This approach is part of Drupal's core design.
+			$can_duplicate = FALSE;
+			$can_delete = ($user->uid == $row->uid)? TRUE : FALSE;
+			if (user_access('delete node template of others')) $can_delete = TRUE;
+
+			$can_share = user_access('share node template');
+
+			//Check the nodetype's access hook.
+			$function = $row->type. '_access';
+			if ($flexinode_enabled && strstr($function, 'flexinode-')) {
+				$function = 'flexinode_access';
 			}
-			else {
-				$access = (filter_access($row->format) && node_access('create',$row->type) && node_access('view', $row) && $shared);
+			elseif ($cck_enabled && strstr($function, 'content_')) {
+				$function = 'content_access';
 			}
 
-			//only list node if user has access
-			if ($access) {
-
-				$can_delete = ($user->uid == $row->uid)? TRUE : FALSE;
-				if (user_access('delete node template of others')) $can_delete = TRUE;
-				$can_share = user_access('share node template') && ($row->uid == $user->uid);
-				if ($user->uid == 1) $can_share = TRUE;
-
-				$owner = ($user->uid == $row->uid) ? $user->name : db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $row->uid));
-				$sharetitle = ($shared == 0)? t('share'):t('unshare');
+			if (function_exists($function)) {
+				$can_duplicate = $function('create', $row) ? TRUE : FALSE;
+			}
 
-				$rows[] = array(
-					node_get_types('name', $row->type),
-					l($row->title, "node/$row->nid"),
-					$owner,
-					$row->status ? $yes : $no,
-					format_date($row->changed, 'small'),
-					$row->shared ? $shared_mark : '',
-					l(t('duplicate'), "node/$row->nid/template/clone"),
-					$can_delete? l(t('delete'), "nodetemplates/delete/$row->nid") : '',
-					$can_share? l($sharetitle, "nodetemplates/share/$row->nid") : ''
-				);
-			} //end if access
-		} //end if node
-	} // end while
+			// the name of the owner of this node
+			$name = ($user->uid == $row->uid) ? $user->name : db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $row->uid));
+			$shared = db_result(db_query('SELECT shared FROM {node_template} WHERE nid = %d', $nid));
+		  	$sharetitle = ($shared == 0)? t('share'):t('unshare');
+			$rows[] = array(
+			//node_get_name($row->type),
+			node_get_types('name', $row->type),
+			l($row->title, "node/$row->nid"),
+			$name,
+			$row->status ? $yes : $no,
+			format_date($row->changed, 'small'),
+			$row->shared ? $shared_mark : '',
+			$can_duplicate ? l(t('duplicate'), "node/$row->nid/template/clone") : '',
+			$can_delete? l(t('delete'), "nodetemplates/delete/$row->nid") : '',
+			$can_share? l($sharetitle, "nodetemplates/share/$row->nid") : ''
+			);
+		}
+	}
 
 	if ($rows) {
 		$pager = theme('pager', NULL, $maxnodes, 0);
