aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2011-10-06 17:52:10 -0300
committerSilvio Rhatto <rhatto@riseup.net>2011-10-06 17:52:10 -0300
commitc0f1a1f2c04f84ac4e5b2d1c86e0663de886bbf2 (patch)
tree429a393af6dc7e0551332a4d4ec52ee198553485
parent4654eb2a446f64c66233b7bc38cc2a9b7bf151cc (diff)
downloadmuamba-c0f1a1f2c04f84ac4e5b2d1c86e0663de886bbf2.tar.gz
muamba-c0f1a1f2c04f84ac4e5b2d1c86e0663de886bbf2.tar.bz2
Coding remaining actions
-rw-r--r--muamba.business.inc94
1 files changed, 87 insertions, 7 deletions
diff --git a/muamba.business.inc b/muamba.business.inc
index 852add6..8ca7648 100644
--- a/muamba.business.inc
+++ b/muamba.business.inc
@@ -247,10 +247,36 @@ function muamba_reject($mid) {
*
* @param $mid
* Transaction id.
- *
- * @todo
*/
function muamba_cancel($mid) {
+ global $user;
+ $mid = (int) $mid;
+ $transaction = muamba_get_transaction($mid);
+ $node = node_load($transaction['nid']);
+
+ // Access check
+ if ($transaction['uid'] != $user->uid) {
+ drupal_not_found();
+ }
+
+ // Status check
+ if ($transaction['status'] != MUAMBA_REQUESTED) {
+ drupal_not_found();
+ }
+
+ // Update database
+ $update = db_update('muamba')
+ ->fields(array(
+ 'status' => MUAMBA_CANCELLED,
+ ))
+ ->condition('mid', $mid, '=')
+ ->execute();
+
+ // Notify item owner
+ $message = theme('muamba_cancel_message', array('transaction' => $transaction));
+ $reply = privatemsg_reply($transaction['thread_id'], $message);
+
+ return t('Cancelled item request.');
}
/**
@@ -258,10 +284,37 @@ function muamba_cancel($mid) {
*
* @param $mid
* Transaction id.
- *
- * @todo
*/
function muamba_return($mid) {
+ global $user;
+ $mid = (int) $mid;
+ $transaction = muamba_get_transaction($mid);
+ $node = node_load($transaction['nid']);
+
+ // Access check
+ if ($transaction['uid'] != $user->uid) {
+ drupal_not_found();
+ }
+
+ // Status check
+ if ($transaction['status'] != MUAMBA_ACCEPTED ||
+ $transaction['status'] != MUAMBA_LOST) {
+ drupal_not_found();
+ }
+
+ // Update database
+ $update = db_update('muamba')
+ ->fields(array(
+ 'status' => MUAMBA_RETURNED,
+ ))
+ ->condition('mid', $mid, '=')
+ ->execute();
+
+ // Notify item owner
+ $message = theme('muamba_return_message', array('transaction' => $transaction));
+ $reply = privatemsg_reply($transaction['thread_id'], $message);
+
+ return t('Cancelled item request.');
}
/**
@@ -300,7 +353,7 @@ function muamba_recover($mid) {
$message = theme('muamba_recover_message', array('transaction' => $transaction));
$reply = privatemsg_reply($transaction['thread_id'], $message);
- return t('Recovered item.');
+ return t('Item recovered.');
}
/**
@@ -308,8 +361,35 @@ function muamba_recover($mid) {
*
* @param $mid
* Transaction id.
- *
- * @todo
*/
function muamba_lost($mid) {
+ global $user;
+ $mid = (int) $mid;
+ $transaction = muamba_get_transaction($mid);
+ $node = node_load($transaction['nid']);
+
+ // Access check
+ if (!muamba_has_management_access($node)) {
+ drupal_not_found();
+ }
+
+ // Status check
+ if ($transaction['status'] != MUAMBA_ACCEPTED ||
+ $transaction['status'] != MUAMBA_RETURNED) {
+ drupal_not_found();
+ }
+
+ // Update database
+ $update = db_update('muamba')
+ ->fields(array(
+ 'status' => MUAMBA_LOST,
+ ))
+ ->condition('mid', $mid, '=')
+ ->execute();
+
+ // Notify item owner
+ $message = theme('muamba_lost_message', array('transaction' => $transaction));
+ $reply = privatemsg_reply($transaction['thread_id'], $message);
+
+ return t('Item lost.');
}