--- job_head.module	2010-05-24 22:24:34.000000000 -0400
+++ job.module	2010-05-27 13:30:36.000000000 -0400
@@ -53,7 +53,8 @@ function job_menu() {
   $items['job/apply'] = array(
 	'page callback' => 'job_apply',
 	'type' => MENU_CALLBACK,
-	'access arguments' => array('access content'),
+	'access callback' => "_job_perm_apply_node",
+	'access arguments' => array(2),
   );
   
   $items['job/clear'] = array(
@@ -91,6 +92,22 @@ function _job_perm_clear($nid, $uid) {
 }
 
 
+function _job_perm_apply_node($nid) {
+  global $user;
+  $uid = $user-> uid;
+  
+  // find who posted the job
+  $node = node_load($nid);
+  $nuid = $node->uid;
+  
+  // Can't apply for own job
+  if (user_access(JOB_PERM_APPLY) && $nuid != $uid && !_job_check($node->nid, $uid)) {
+	return true;
+  }
+  
+  return false;
+}
+
 function job_admin_settings() {
   $set = 'job';
   $form[$set] = array(
@@ -116,39 +133,50 @@ function job_admin_settings() {
 function job_link($type, $node = NULL, $teaser = FALSE) {
   global $user;
   $links = array();
-  if ($type == 'node') {
-    // We are viewing a node
-    if (variable_get(JOB_NODE_TYPE . $node->type, 0)) {
-      // Node type is enabled for job apply
-      if (!$user->uid) {
-        // User is not logged in
-        $links['job_apply'] = array(
-          'title' => t('Please login or register to apply'),
-          'href'  => 'user/login',
-          );
-      }
-      else {
-        // User is logged in
-        if (_job_check($node->nid, $user->uid)) {
-          // User has applied for this job
-          $links['job_apply'] = array(
-            'title' => t('You applied for this job'),
-          );
-          return $links;
-        }
-        else {
-          // User has not applied for this job
-          $links['job_apply'] =  array(
-            'title' => t('Apply for this job'),
-            'href' => "job/apply/$node->nid",
-            );
-        }
-      }
+  
+  // If not a job node, don't bother
+  if ($type != 'node' || variable_get(JOB_NODE_TYPE . $node->type, 0) == 0) {
+    return $links;
+  }
+  
+  if (_job_perm_apply_node($node->nid)) {
+	// OK to apply
+	$links['job_apply'] = array(
+	  'title' => t('Apply for this job'),
+	  'href' => "job/apply/$node->nid",
+	);
+  }
+  else {
+    // Now, determine why the user was denied
+    
+    if (!$user->uid) {
+	  // User is not logged in
+	  // NOTE: consider an admin-defined message here
+	  $links['job_apply'] = array(
+	  'title' => t('Please !login or !register to apply',
+		array(
+		  '!login' => l(t('login'), 'user/login'),
+		  '!register' => l(t('register'), 'user/register')
+		)),
+	  'html' => true,
+	  );
+    }
+    else if (_job_check($node->nid, $user->uid)) {
+	  // User has applied for this job
+	  // NOTE: consider a link to withdraw application here, if permitted
+	  $links['job_apply'] = array(
+		'title' => t('You applied for this job'),
+	  );
+    }
+    else {
+	  // Catch-all for authenticated users without permissions
+	  // NOTE: consider an admin-defined message here
+	  // for now, show nothing;
     }
   }
+  
   return $links;
 }
-
 /**
  * Implementation of hook_user().
  */
