Index: ad_notify.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/ad/notify/Attic/ad_notify.module,v
retrieving revision 1.1.2.2.2.13.2.6.2.2
diff -u -r1.1.2.2.2.13.2.6.2.2 ad_notify.module
--- ad_notify.module	5 Mar 2009 22:29:00 -0000	1.1.2.2.2.13.2.6.2.2
+++ ad_notify.module	6 Mar 2009 13:23:59 -0000
@@ -51,26 +51,26 @@
     'title' => 'My notifications',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('ad_notify_overview_form', 1),
-    'access callback' => 'ad_permission',
+    'access callback' => 'ad_notify_access',
     'access arguments' => array(1, array('manage owners', 'manage own notifications')),
     'type' => MENU_LOCAL_TASK,
     'weight' => 4,
   );
-  $items['node/%node/adowners/%user/notifications'] = array(
+  $items['node/%/adowners/%user/notifications'] = array(
     'title callback' => 'owner_notifications_title',
     'title arguments' => array(3),
     'page callback' => 'drupal_get_form',
     'page arguments' => array('ad_notify_overview_form', 1, 3),
-    'access callback' => 'ad_permission',
+    'access callback' => 'ad_notify_access',
     'access arguments' => array(1, 'manage owners'),
     'type' => MENU_LOCAL_TASK,
     'weight' => 4,
   );
-  $items['node/%/adowners/%/notifications/%ad_notification/delete'] = array(
+  $items['node/%/adowners/%user/notifications/%ad_notification/delete'] = array(
     'title' => 'Delete notification',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('ad_notify_confirm_delete', 1, 3, 5),
-    'access callback' => 'ad_permission',
+    'access callback' => 'ad_notify_access',
     'access arguments' => array(1, array('manage owners', 'manage own notifications')),
     'type' => MENU_CALLBACK,
   );
@@ -88,6 +88,24 @@
 }
 
 /**
+ * Menu item access callback.
+ */
+function ad_notify_access($nid, $permissions) {
+  if (is_array($perm)) {
+    foreach ($permissions as $perm) {
+      $access |= ad_permission($nid, $perm);
+    }
+  }
+  else {
+    $access = ad_permission($nid, $permissions);
+  }
+  if ($access) {
+    return ($node = node_load($nid)) && ($node->type == 'ad');
+  }
+}
+
+
+/**
  * Implementation of hook_cron().
  * Send time based notifications and those, who has negative delay.
  */
@@ -254,17 +272,20 @@
 /**
  * Notification overview form.
  */
-function ad_notify_overview_form($form_state, $node, $owner = NULL, $notid = 0) {
+function ad_notify_overview_form($form_state, $nid = 0, $owner = NULL, $notid = 0) {
   global $user;
-  if (empty($owner)) {
-    $owner = $user;
+
+  if ($owner === 0) {
+    $owner = new stdClass();
+    $owner->uid = 0;
   }
-  if (!is_object($node)) {
-    $node = new stdClass();
-    $node->nid = 0;
+  else {
+    if (empty($owner)) {
+      $owner = $user;
+    }
   }
 
-  $oid = (int)db_result(db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $node->nid, $owner->uid));
+  $oid = (int)db_result(db_query('SELECT oid FROM {ad_owners} WHERE aid = %d AND uid = %d', $nid, $owner->uid));
   $notifications = module_invoke_all('adnotifyapi', 'register');
 
   $header = array(
@@ -295,13 +316,13 @@
       }
     }
 
-    if (!$owner->uid || $list_notification) {
+    if ($list_notification) {
       $row = array();
       $row[] = $notify->sent ? t('!time ago', array('!time' => format_interval(time() - $notify->sent))) : t('Never');
       $row[] = t($notifications[$notify->event], array('@when' => format_interval($notify->delay)));
       $row[] = $notify->status == AD_NOTIFY_ENABLED ? t('enabled') : t('disabled');
       if ($oid) {
-        $row[] = l(t('edit'), 'node/'. $node->nid .'/adowners/'. $owner->uid .'/notifications/' .$notify->notid. '/edit') .' '. l(t('delete'), 'node/'. $node->nid .'/adowners/'. $owner->uid .'/notifications/'. $notify->notid .'/delete');
+        $row[] = l(t('edit'), 'node/'. $nid .'/adowners/'. $owner->uid .'/notifications/' .$notify->notid. '/edit') .' '. l(t('delete'), 'node/'. $nid .'/adowners/'. $owner->uid .'/notifications/'. $notify->notid .'/delete');
       }
       else if (user_access('administer advertisements')) {
         $row[] = l(t('edit'), 'admin/content/ad/notifications/' .$notify->notid. '/edit') .' '. l(t('delete'), 'admin/content/ad/notifications/'. $notify->notid .'/delete');
@@ -359,8 +380,7 @@
     '#default_value' => $notid ? $notification->expire : 0,
   );
 
-  if (ad_permission($node->nid, 'manage owners') && arg(2) == 'adowners' &&
-      $user->uid != arg(3)) {
+  if (ad_permission($nid, 'manage owners') && arg(2) == 'adowners' && $user->uid != arg(3)) {
     $form['create']['locked'] = array(
       '#type' => 'checkbox',
       '#title' => t('Locked'),
@@ -443,7 +463,7 @@
 
   $form['create']['aid'] = array(
     '#type' => 'hidden',
-    '#value' => $node->nid,
+    '#value' => $nid,
   );
 
   $form['create']['uid'] = array(
@@ -519,6 +539,8 @@
  * Save notifications to database.
  */
 function ad_notify_overview_form_submit($form, &$form_state) {
+  global $user;
+
   if (isset($form_state['values']['notid'])) {
     db_query("UPDATE {ad_notify} SET aid = %d, oid = %d, event = '%s', delay = %d, expire = %d, locked = %d, status = %d, address = '%s', subject = '%s', body = '%s', roles = '%s' WHERE notid = %d", $form_state['values']['aid'], $form_state['values']['oid'], $form_state['values']['event'], $form_state['values']['delay'], $form_state['values']['expire'], $form_state['values']['locked'], AD_NOTIFY_ENABLED, isset($form_state['values']['address']) ? $form_state['values']['address'] : '', $form_state['values']['subject'], $form_state['values']['body'], serialize($form_state['values']['roles']), $form_state['values']['notid']);
     drupal_set_message('Notification updated.');
@@ -537,7 +559,7 @@
     drupal_set_message('Notification created.');
   }
 
-  if ($form_state['values']['aid'] && $form_state['values']['uid']) {
+  if ($form_state['values']['aid'] && $form_state['values']['uid'] && $user->uid != $form_state['values']['uid']) {
     $form_state['redirect'] = 'node/'. $form_state['values']['aid'] .'/adowners/'. $form_state['values']['uid'] .'/notifications';
   }
   else if ($form_state['values']['aid']) {
@@ -560,7 +582,8 @@
 /**
  * Confirm deletion of a specified notification from the database.
  */
-function ad_notify_confirm_delete(&$form_state, $nid, $uid, $notification) {
+function ad_notify_confirm_delete(&$form_state, $nid, $owner, $notification) {
+  global $user;
   $form = array();
 
   $form['oid'] = array(
@@ -575,7 +598,7 @@
 
   $form['uid'] = array(
     '#type' => 'hidden',
-    '#value' => $uid,
+    '#value' => $owner->uid,
   );
 
   $form['notid'] = array(
@@ -600,8 +623,8 @@
     '#suffix' => '</div>',
   );
 
-  if ($nid && $uid) {
-   $path = 'node/'. $nid .'/adowners/'. $uid .'/notifications';
+  if ($nid && $owner->uid && $user->uid != $owner->uid) {
+   $path = 'node/'. $nid .'/adowners/'. $owner->uid .'/notifications';
   }
   else if ($nid) {
     $path = 'node/'. $nid .'/notifications';
@@ -635,11 +658,12 @@
  * Delete a specified notification from the database.
  */
 function ad_notify_confirm_delete_submit($form, &$form_state) {
+  global $user;
   db_query('DELETE FROM {ad_notify} WHERE notid = %d', $form_state['values']['notid']);
   drupal_set_message('Notification deleted.');
 
-  if ($form_state['values']['aid'] && $form_state['values']['uid']) {
-   $form_state['redirect'] = 'node/'. $form_state['values']['aid'] .'/adowners/'. $form_state['values']['uid'] .'/notifications';
+  if ($form_state['values']['aid'] && $form_state['values']['uid'] && $user->uid != $form_state['values']['uid']) {
+    $form_state['redirect'] = 'node/'. $form_state['values']['aid'] .'/adowners/'. $form_state['values']['uid'] .'/notifications';
   }
   else if ($form_state['values']['aid']) {
     $form_state['redirect'] = 'node/'. $form_state['values']['aid'] .'/notifications';

