From 372faab01fa21107d2358d84ad0e2e0d20846528 Mon Sep 17 00:00:00 2001
From: Sascha Grossenbacher <saschagros@gmail.com>
Date: Sun, 24 Apr 2011 13:30:21 +0200
Subject: [PATCH] Issue #1127904 by Berdir: Create points local task for other users, fix details link.

---
 userpoints.module    |  119 ++++++++++++++++++++++++++++++++++++++++----------
 userpoints.pages.inc |    8 +++-
 userpoints.theme.inc |    5 ++-
 3 files changed, 105 insertions(+), 27 deletions(-)

diff --git a/userpoints.module b/userpoints.module
index 88fba97..7c8d1ef 100644
--- a/userpoints.module
+++ b/userpoints.module
@@ -268,29 +268,88 @@ function userpoints_menu() {
       'type' => MENU_CALLBACK,
   );
 
-  $items['userpoints/view/%userpoints_transaction'] = array(
-      'title' => '!Point transaction',
-      'title callback' => 'userpoints_view_transaction_title',
-      'title arguments' => array(2),
-      'page callback' => 'userpoints_view_transaction',
-      'page arguments' => array(2),
-      'access callback' => 'userpoints_access_view_transaction',
-      'access arguments' => array(2),
-      'file' => 'userpoints.pages.inc',
-      'type' => MENU_NORMAL_ITEM,
+  $items['myuserpoints'] = array(
+    'title' => 'My !points',
+    'title arguments' => userpoints_translation(),
+    'page callback' => 'userpoints_list_my_userpoints',
+    'access callback' => 'userpoints_access_my_points',
+    'file' => 'userpoints.pages.inc',
+    'type' => MENU_NORMAL_ITEM,
+    'menu_name' => 'user-menu',
+  );
+
+  $items['myuserpoints/view/%userpoints_transaction'] = array(
+    'title' => '!Point transaction',
+    'title callback' => 'userpoints_view_transaction_title',
+    'title arguments' => array(2),
+    'page callback' => 'userpoints_view_transaction',
+    'page arguments' => array(2),
+    'access callback' => 'userpoints_access_view_transaction',
+    'access arguments' => array(2),
+    'file' => 'userpoints.pages.inc',
+    'type' => MENU_NORMAL_ITEM,
+  );
+
+  $items['user/%user/points'] = array(
+    'title' => '!Points',
+    'title arguments' => userpoints_translation(),
+    'page callback' => 'userpoints_list_my_userpoints',
+    'page arguments' => array(1),
+    'access callback' => 'userpoints_access_my_points',
+    'access arguments' => array(1),
+    'file' => 'userpoints.pages.inc',
+    'type' => MENU_LOCAL_TASK,
+  );
+
+  $items['user/%user/points/list'] = array(
+    'title' => 'List',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -15,
+  );
+
+  $items['user/%user/points/%userpoints_transaction/view'] = array(
+    'title' => 'View',
+    'page callback' => 'userpoints_view_transaction',
+    'page arguments' => array(3),
+    'access callback' => 'userpoints_access_view_transaction',
+    'access arguments' => array(3),
+    'file' => 'userpoints.pages.inc',
+    'type' => MENU_LOCAL_TASK,
+    'weight' => -10,
+  );
+
+  $items['user/%user/points/%userpoints_transaction/edit'] = array(
+      'title' => 'Edit',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('userpoints_admin_txn', 4, 3),
+      'access callback' => 'userpoints_admin_access',
+      'access arguments' => array('edit'),
+      'file' => 'userpoints.admin.inc',
+      'type' => MENU_LOCAL_TASK,
+      'weight' => -5,
   );
 
-  $items['myuserpoints/%user_uid_optional'] = array(
-      'title' => 'My !points',
+  $items['user/%user/points/%userpoints_transaction/approve'] = array(
+      'title' => 'Approve',
       'title arguments' => userpoints_translation(),
-      'page callback' => 'userpoints_list_my_userpoints',
-      'page arguments' => array(1),
-      'access callback' => 'userpoints_access_my_points',
-      'access arguments' => array(1),
-      'file' => 'userpoints.pages.inc',
-      'type' => MENU_NORMAL_ITEM,
-      'menu_name' => 'user-menu',
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('userpoints_confirm_approve', 4, 3),
+      'access callback' => 'userpoints_admin_access_transaction_pending',
+      'access arguments' => array(3),
+      'file' => 'userpoints.admin.inc',
+      'type' => MENU_LOCAL_TASK,
+  );
+  $items['user/%user/points/%userpoints_transaction/decline'] = array(
+      'title' => 'Decline',
+      'title arguments' => userpoints_translation(),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('userpoints_confirm_approve', 4, 3),
+      'access callback' => 'userpoints_admin_access_transaction_pending',
+      'access arguments' => array(3),
+      'file' => 'userpoints.admin.inc',
+      'type' => MENU_LOCAL_TASK,
   );
+
   return $items;
 }
 
@@ -346,6 +405,7 @@ function userpoints_admin_access_transaction_pending($transaction) {
  */
 function userpoints_access_my_points($account = NULL) {
   global $user;
+
   if ($account && $user->uid != $account->uid) {
     return userpoints_admin_access('edit');
   }
@@ -1789,19 +1849,30 @@ function userpoints_get_transaction_actions($transaction, $show_view = TRUE) {
   $url_options = array('query' => drupal_get_destination());
 
   if ($show_view && userpoints_access_view_transaction($transaction)) {
-    $url = 'userpoints/view/' . $transaction->txn_id;
-    if ($transaction->uid != $user->uid || strpos($_GET['q'], 'admin/config/people/userpoints') !== FALSE) {
+    $url = 'myuserpoints/view/' . $transaction->txn_id;
+    if (strpos($_GET['q'], 'admin/config/people/userpoints') !== FALSE) {
       $url = 'admin/config/people/userpoints/transaction/' . $transaction->txn_id . '/view';
     }
+    elseif ($transaction->uid != $user->uid) {
+      $url = 'user/' . $transaction->uid . '/points/' . $transaction->txn_id . '/view';
+    }
     $actions[] = l('view', $url);
   }
 
+  if ($transaction->uid == $user->uid || strpos($_GET['q'], 'admin/config/people/userpoints') !== FALSE) {
+    $url_prefix = "admin/config/people/userpoints/transaction/$transaction->txn_id/";
+  }
+  else {
+    $url_prefix = "user/$transaction->uid/points/$transaction->txn_id/";
+  }
+
   if (userpoints_admin_access('edit')) {
-    $actions[] = l('edit', "admin/config/people/userpoints/transaction/$transaction->txn_id/edit", $url_options);
+    $actions[] = l('edit', $url_prefix . 'edit', $url_options);
+
   }
   if (userpoints_admin_access('moderate') && $transaction->status == USERPOINTS_TXN_STATUS_PENDING) {
-    $actions[] = l('approve', "admin/config/people/userpoints/transaction/$transaction->txn_id/approve", $url_options);
-    $actions[] = l('decline', "admin/config/people/userpoints/transaction/$transaction->txn_id/decline", $url_options);
+    $actions[] = l('approve', $url_prefix . 'approve', $url_options);
+    $actions[] = l('decline', $url_prefix . 'decline', $url_options);
   }
   return implode(' ', $actions);
 }
diff --git a/userpoints.pages.inc b/userpoints.pages.inc
index 262e673..a86f6b5 100644
--- a/userpoints.pages.inc
+++ b/userpoints.pages.inc
@@ -10,9 +10,13 @@
  * Displays a detailed transaction report for an individual user.
  *
  * @param $account
- *   For which account to display.
+ *   For which account to display. Defaults to the current user.
  */
-function userpoints_list_my_userpoints($account, $tid = NULL) {
+function userpoints_list_my_userpoints($account = NULL, $tid = NULL) {
+  if (empty($account)) {
+    global $user;
+    $account = $user;
+  }
 
   // Load the categories and check if there are multiples or only a single one.
   $categories = userpoints_get_categories();
diff --git a/userpoints.theme.inc b/userpoints.theme.inc
index 8310a2b..669b50b 100644
--- a/userpoints.theme.inc
+++ b/userpoints.theme.inc
@@ -63,7 +63,10 @@ function theme_userpoints_list_users_row($attributes) {
 
   $details = '';
   if ($user->uid == $row->uid) {
-    $details = "&nbsp;&nbsp;" . l(t("(details)"), "myuserpoints");
+    $details = "&nbsp;&nbsp;" . l(t("(details)"), 'myuserpoints');
+  }
+  else if (userpoints_admin_access('edit')) {
+    $details = "&nbsp;&nbsp;" . l(t("(details)"), 'user/' . $row->uid . '/points');
   }
 
   return array(
-- 
1.7.4.1

