Guest User

Untitled

a guest
May 26th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. #!/usr/local/bin/php
  2. <?
  3.  
  4. // Classes
  5. require_once("/export/home2/chatten.nl/classes/configuration/class.configuration.php");
  6. require_once("/export/home2/chatten.nl/classes/error/class.error.php");
  7. require_once("/export/home2/chatten.nl/classes/db/class.db.php");
  8.  
  9. // Functions
  10. require_once("/export/home2/chatten.nl/functions/db/functions.db.php");
  11. require_once("/export/home2/chatten.nl/functions/msg/functions.msg.php");
  12. require_once("/export/home2/chatten.nl/functions/member/functions.member.php");
  13. require_once("/export/home2/chatten.nl/functions/mail/functions.mail.php");
  14.  
  15. // Secure
  16. require_once("/export/home2/chatten.nl/includes/secure/db.php");
  17.  
  18. // Constants
  19. require_once("/export/home2/chatten.nl/constants/constants.msg.php");
  20.  
  21. // Get all arguments from STDIN
  22. $args = file("php://stdin", FILE_IGNORE_NEW_LINES);
  23.  
  24. // Easy use variables
  25. $msg_id = intval($args[0]);
  26. $msg_type = trim($args[1]);
  27. $msg_status = intval($args[2]);
  28. $msg_ut_stamp = trim($args[3]);
  29. $member_id_sender = intval($args[4]);
  30. $member_id_receipient = intval($args[5]);
  31. $content = unserialize($args[6]);
  32.  
  33. // Open RW DB connection
  34. list($dbh_rw, $error) = db_open($__DB['chatten']['rw'], $error);
  35.  
  36. // TRANSACTION START
  37. if (DB::autocommit($dbh_rw, FALSE) !== TRUE) {
  38. $error[] = Error::getMessage("DB001");
  39. }
  40.  
  41. if ($member_id_receipient > 0) {
  42.  
  43. // Get member_receipient
  44. list($member_receipient, $error) = member_by_id_get($dbh_rw, $member_id_receipient, $error);
  45.  
  46. }
  47.  
  48. // Create msg_content
  49. list($msg_content_id, $error) = msg_content_create($dbh_rw, $member_id_sender, $content, $error);
  50.  
  51. if (sizeof($error) == 0 && $msg_content_id > 0) {
  52.  
  53. // FROM:TO
  54. if ($msg_type == sprintf("%u:%u", _MSG_TYPE_FROM, _MSG_TYPE_TO)) {
  55.  
  56. // Create msg (sender)
  57. list($msg_id_sender, $error) = msg_create($dbh_rw, $member_id_sender, $member_id_receipient, _MSG_FOLDER_SENT, $msg_content_id,
  58. _MSG_STATUS_READ, _MSG_TYPE_FROM, $error);
  59. // Create msg (receipient)
  60. list($msg_id_receipient, $error) = msg_create($dbh_rw, $member_id_receipient, $member_id_sender, _MSG_FOLDER_INBOX, $msg_content_id,
  61. _MSG_STATUS_UNREAD, _MSG_TYPE_TO, $error);
  62.  
  63. }
  64.  
  65. // DRAFT
  66. if ($msg_type == _MSG_TYPE_DRAFT) {
  67.  
  68. // Create msg
  69. list($msg_id_receipient, $error) = msg_create($dbh_rw, $member_id_receipient, $member_id_sender, _MSG_FOLDER_DRAFT, $msg_content_id,
  70. _MSG_STATUS_UNREAD, _MSG_TYPE_DRAFT, $error);
  71.  
  72. }
  73.  
  74. // SYSTEM
  75. if ($msg_type == _MSG_TYPE_SYSTEM) {
  76.  
  77. // Create msg
  78. list($msg_id_receipient, $error) = msg_create($dbh_rw, $member_id_receipient, $member_id_sender, _MSG_FOLDER_INBOX, $msg_content_id,
  79. _MSG_STATUS_UNREAD, _MSG_TYPE_SYSTEM, $error);
  80.  
  81. }
  82.  
  83. }
  84.  
  85. // Update the status of the original msg when needed
  86. if ($msg_id && $msg_status) {
  87.  
  88. // Update status of msg_id
  89. list($error) = msg_status_update($dbh_rw, $member_id_sender, $msg_id, $msg_status, $error);
  90.  
  91. }
  92.  
  93. // TRANSACTION COMMIT || ROLLBACK
  94. if (sizeof($error) > 0) {
  95. DB::rollback($dbh_rw);
  96. } else {
  97. DB::commit($dbh_rw);
  98. }
  99.  
  100. // Close RW DB connection
  101. db_close($dbh_rw);
  102.  
  103. if (sizeof($error) > 0) {
  104. exit(1);
  105. }
  106.  
  107. // Send notification to member_id_receipient when needed
  108. if ($member_receipient['settings']['notification']['msg']) {
  109.  
  110. // Smarty
  111. require_once("/export/home2/chatten.nl/smarty/chatten/setup.php");
  112.  
  113. // Classes
  114. require_once("/export/home2/chatten.nl/classes/template/class.template.php");
  115.  
  116. // Functions
  117. require_once("/export/home2/chatten.nl/functions/smarty/functions.smarty.php");
  118.  
  119. // Constants
  120. require_once("/export/home2/chatten.nl/constants/constants.smtp.php");
  121.  
  122. // Arrays
  123. $error = array();
  124.  
  125. // Store necessary data in $data
  126. $data = array();
  127. $data['template'] = "mail/notification_msg";
  128. $data['nickname'] = $member_receipient['nickname'];
  129. $data['email'] = $member_receipient['email'];
  130.  
  131. // Send notification mail
  132. list($error_mail) = mail_send("Chatten", "contact@chatten.nl", $data, $error_mail);
  133.  
  134. // Clean up
  135. unset($error_mail);
  136.  
  137. }
  138.  
  139. ?>
Add Comment
Please, Sign In to add comment