Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/php
- <?
- // Classes
- require_once("/export/home2/chatten.nl/classes/configuration/class.configuration.php");
- require_once("/export/home2/chatten.nl/classes/error/class.error.php");
- require_once("/export/home2/chatten.nl/classes/db/class.db.php");
- // Functions
- require_once("/export/home2/chatten.nl/functions/db/functions.db.php");
- require_once("/export/home2/chatten.nl/functions/msg/functions.msg.php");
- require_once("/export/home2/chatten.nl/functions/member/functions.member.php");
- require_once("/export/home2/chatten.nl/functions/mail/functions.mail.php");
- // Secure
- require_once("/export/home2/chatten.nl/includes/secure/db.php");
- // Constants
- require_once("/export/home2/chatten.nl/constants/constants.msg.php");
- // Get all arguments from STDIN
- $args = file("php://stdin", FILE_IGNORE_NEW_LINES);
- // Easy use variables
- $msg_id = intval($args[0]);
- $msg_type = trim($args[1]);
- $msg_status = intval($args[2]);
- $msg_ut_stamp = trim($args[3]);
- $member_id_sender = intval($args[4]);
- $member_id_receipient = intval($args[5]);
- $content = unserialize($args[6]);
- // Open RW DB connection
- list($dbh_rw, $error) = db_open($__DB['chatten']['rw'], $error);
- // TRANSACTION START
- if (DB::autocommit($dbh_rw, FALSE) !== TRUE) {
- $error[] = Error::getMessage("DB001");
- }
- if ($member_id_receipient > 0) {
- // Get member_receipient
- list($member_receipient, $error) = member_by_id_get($dbh_rw, $member_id_receipient, $error);
- }
- // Create msg_content
- list($msg_content_id, $error) = msg_content_create($dbh_rw, $member_id_sender, $content, $error);
- if (sizeof($error) == 0 && $msg_content_id > 0) {
- // FROM:TO
- if ($msg_type == sprintf("%u:%u", _MSG_TYPE_FROM, _MSG_TYPE_TO)) {
- // Create msg (sender)
- list($msg_id_sender, $error) = msg_create($dbh_rw, $member_id_sender, $member_id_receipient, _MSG_FOLDER_SENT, $msg_content_id,
- _MSG_STATUS_READ, _MSG_TYPE_FROM, $error);
- // Create msg (receipient)
- list($msg_id_receipient, $error) = msg_create($dbh_rw, $member_id_receipient, $member_id_sender, _MSG_FOLDER_INBOX, $msg_content_id,
- _MSG_STATUS_UNREAD, _MSG_TYPE_TO, $error);
- }
- // DRAFT
- if ($msg_type == _MSG_TYPE_DRAFT) {
- // Create msg
- list($msg_id_receipient, $error) = msg_create($dbh_rw, $member_id_receipient, $member_id_sender, _MSG_FOLDER_DRAFT, $msg_content_id,
- _MSG_STATUS_UNREAD, _MSG_TYPE_DRAFT, $error);
- }
- // SYSTEM
- if ($msg_type == _MSG_TYPE_SYSTEM) {
- // Create msg
- list($msg_id_receipient, $error) = msg_create($dbh_rw, $member_id_receipient, $member_id_sender, _MSG_FOLDER_INBOX, $msg_content_id,
- _MSG_STATUS_UNREAD, _MSG_TYPE_SYSTEM, $error);
- }
- }
- // Update the status of the original msg when needed
- if ($msg_id && $msg_status) {
- // Update status of msg_id
- list($error) = msg_status_update($dbh_rw, $member_id_sender, $msg_id, $msg_status, $error);
- }
- // TRANSACTION COMMIT || ROLLBACK
- if (sizeof($error) > 0) {
- DB::rollback($dbh_rw);
- } else {
- DB::commit($dbh_rw);
- }
- // Close RW DB connection
- db_close($dbh_rw);
- if (sizeof($error) > 0) {
- exit(1);
- }
- // Send notification to member_id_receipient when needed
- if ($member_receipient['settings']['notification']['msg']) {
- // Smarty
- require_once("/export/home2/chatten.nl/smarty/chatten/setup.php");
- // Classes
- require_once("/export/home2/chatten.nl/classes/template/class.template.php");
- // Functions
- require_once("/export/home2/chatten.nl/functions/smarty/functions.smarty.php");
- // Constants
- require_once("/export/home2/chatten.nl/constants/constants.smtp.php");
- // Arrays
- $error = array();
- // Store necessary data in $data
- $data = array();
- $data['template'] = "mail/notification_msg";
- $data['nickname'] = $member_receipient['nickname'];
- $data['email'] = $member_receipient['email'];
- // Send notification mail
- list($error_mail) = mail_send("Chatten", "contact@chatten.nl", $data, $error_mail);
- // Clean up
- unset($error_mail);
- }
- ?>
Add Comment
Please, Sign In to add comment