diff options
Diffstat (limited to 'mod/messages/actions')
-rw-r--r-- | mod/messages/actions/messages/delete.php | 20 | ||||
-rw-r--r-- | mod/messages/actions/messages/process.php | 35 | ||||
-rw-r--r-- | mod/messages/actions/messages/send.php | 46 |
3 files changed, 101 insertions, 0 deletions
diff --git a/mod/messages/actions/messages/delete.php b/mod/messages/actions/messages/delete.php new file mode 100644 index 000000000..ffdb3b3a3 --- /dev/null +++ b/mod/messages/actions/messages/delete.php @@ -0,0 +1,20 @@ +<?php +/** + * Delete message + */ + +$guid = (int) get_input('guid'); + +$message = get_entity($guid); +if (!$message || !$message->canEdit()) { + register_error(elgg_echo('messages:error:delete:single')); + forward(REFERER); +} + +if (!$message->delete()) { + register_error(elgg_echo('messages:error:delete:single')); +} else { + system_message(elgg_echo('messages:success:delete:single')); +} + +forward(REFERER); diff --git a/mod/messages/actions/messages/process.php b/mod/messages/actions/messages/process.php new file mode 100644 index 000000000..d929ae190 --- /dev/null +++ b/mod/messages/actions/messages/process.php @@ -0,0 +1,35 @@ +<?php +/** + * Process a set of messages + */ + +$message_ids = get_input('message_id', array()); + +if (!$message_ids) { + register_error(elgg_echo('messages:error:messages_not_selected')); + forward(REFERER); +} + +$delete_flag = get_input('delete', false); +$read_flag = get_input('read', false); + +if ($delete_flag) { + $success_msg = elgg_echo('messages:success:delete'); + foreach ($message_ids as $guid) { + $message = get_entity($guid); + if ($message && $message->getSubtype() == 'messages' && $message->canEdit()) { + $message->delete(); + } + } +} else { + $success_msg = elgg_echo('messages:success:read'); + foreach ($message_ids as $guid) { + $message = get_entity($guid); + if ($message && $message->getSubtype() == 'messages' && $message->canEdit()) { + $message->readYet = 1; + } + } +} + +system_message($success_msg); +forward(REFERER); diff --git a/mod/messages/actions/messages/send.php b/mod/messages/actions/messages/send.php new file mode 100644 index 000000000..16a971ad2 --- /dev/null +++ b/mod/messages/actions/messages/send.php @@ -0,0 +1,46 @@ +<?php +/** +* Ssend a message action +* +* @package ElggMessages +*/ + +$subject = strip_tags(get_input('subject')); +$body = get_input('body'); +$recipient_guid = get_input('recipient_guid'); + +elgg_make_sticky_form('messages'); + +$reply = get_input('reply',0); // this is the guid of the message replying to + +if (!$recipient_guid) { + register_error(elgg_echo("messages:user:blank")); + forward("messages/compose"); +} + +$user = get_user($recipient_guid); +if (!$user) { + register_error(elgg_echo("messages:user:nonexist")); + forward("messages/compose"); +} + +// Make sure the message field, send to field and title are not blank +if (!$body || !$subject) { + register_error(elgg_echo("messages:blank")); + forward("messages/compose"); +} + +// Otherwise, 'send' the message +$result = messages_send($subject, $body, $recipient_guid, 0, $reply); + +// Save 'send' the message +if (!$result) { + register_error(elgg_echo("messages:error")); + forward("messages/compose"); +} + +elgg_clear_sticky_form('messages'); + +system_message(elgg_echo("messages:posted")); + +forward('messages/inbox/' . elgg_get_logged_in_user_entity()->username); |