diff options
-rw-r--r-- | muamba.business.inc | 94 |
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.'); } |