25 if (
'in' == $this->root->mContext->mRequest->getRequest(
'inout')) {
26 $this->inout =
'inbox';
28 $this->inout =
'outbox';
31 $boxid = (int)$this->root->mContext->mRequest->getRequest($this->inout);
32 $modHand = xoops_getmodulehandler($this->inout);
33 $modObj = $modHand->get($boxid);
34 if (!is_object($modObj)) {
35 if ($this->root->mContext->mRequest->getRequest(
'ajax') == 1) {
36 header(
'Content-Type: application/json');
37 echo json_encode([
'error' => _MD_MESSAGE_ACTIONMSG1]);
40 $this->setErr(_MD_MESSAGE_ACTIONMSG1);
43 if ($modObj->get(
'uid') != $this->root->mContext->mXoopsUser->get(
'uid')) {
44 if ($this->root->mContext->mRequest->getRequest(
'ajax') == 1) {
45 header(
'Content-Type: application/json');
46 echo json_encode([
'error' => _MD_MESSAGE_ACTIONMSG8]);
49 $this->setErr(_MD_MESSAGE_ACTIONMSG8);
54 $uid = $this->root->mContext->mXoopsUser->get(
'uid');
55 $inboxTable = $modHand->mTable;
57 $key = ($this->inout ===
'inbox') ?
'inbox_id' :
'outbox_id';
58 $this->msgdata[
'param'] = ($this->inout ===
'inbox') ?
'inbox' :
'outbox';
59 $this->msgdata[
'inout_short'] = ($this->inout ===
'inbox') ?
'in' :
'out';
60 $currentId = $modObj->get($key);
63 $sqlPrev =
"SELECT $key FROM $inboxTable WHERE uid=$uid AND $key < $currentId ORDER BY $key DESC LIMIT 1";
64 $resultPrev = $modHand->db->query($sqlPrev);
65 $prevId = ($row = $modHand->db->fetchArray($resultPrev)) ? $row[$key] :
null;
68 $sqlNext =
"SELECT $key FROM $inboxTable WHERE uid=$uid AND $key > $currentId ORDER BY $key ASC LIMIT 1";
69 $resultNext = $modHand->db->query($sqlNext);
70 $nextId = ($row = $modHand->db->fetchArray($resultNext)) ? $row[$key] :
null;
73 foreach (array_keys($modObj->gets()) as $var_name) {
74 $this->msgdata[$var_name] = $modObj->getShow($var_name);
76 if (
'inbox' == $this->inout) {
77 $this->msgdata[
'fromname'] = $this->getLinkUnameFromId($this->msgdata[
'from_uid'], $this->msgdata[
'uname']);
79 $this->msgdata[
'toname'] = $this->getLinkUnameFromId($this->msgdata[
'to_uid'], $this->root->mContext->mXoopsConfig[
'anonymous']);
81 $this->msgdata[
'prev_id'] = $prevId;
82 $this->msgdata[
'next_id'] = $nextId;
83 $this->msgdata[
'key'] = $key;
84 $this->msgdata[
'utime'] = $modObj->get(
'utime');
87 if ($this->root->mContext->mRequest->getRequest(
'ajax') == 1) {
88 header(
'Content-Type: application/json');
91 if (
'inbox' == $this->inout &&
'POST' == $_SERVER[
'REQUEST_METHOD'] &&
92 'lock' == $this->root->mContext->mRequest->getRequest(
'cmd')) {
94 if (1 == (
int)$this->root->mContext->mRequest->getRequest(
'lock')) {
95 $modObj->set(
'is_read', 2);
97 $modObj->set(
'is_read', 1);
99 $modHand->insert($modObj);
102 $this->msgdata[
'is_read'] = $modObj->get(
'is_read');
105 elseif (
'inbox' == $this->inout && 0 == $modObj->get(
'is_read')) {
106 $modObj->set(
'is_read', 1);
107 $modHand->insert($modObj,
true);
109 $this->msgdata[
'is_read'] = 1;
114 if (
'inbox' == $this->inout && isset($this->msgdata[
'from_uid'])) {
115 $handler = xoops_gethandler(
'user');
116 $user = $handler->get(intval($this->msgdata[
'from_uid']));
117 if (is_object($user) && $user->isActive() && ($user->get(
'user_avatar') !=
"blank.gif") && file_exists(XOOPS_UPLOAD_PATH .
"/" . $user->get(
'user_avatar'))) {
118 $avatarUrl = XOOPS_UPLOAD_URL .
"/" . $user->getShow(
'user_avatar');
120 $avatarUrl = XOOPS_URL .
"/modules/user/images/no_avatar.gif";
125 'subject' => $this->msgdata[
'title'],
126 'body' => $this->msgdata[
'message'],
127 'from' => $this->msgdata[
'fromname'] ??
'',
128 'to' => $this->msgdata[
'toname'] ??
'',
129 'date' => isset($this->msgdata[
'utime']) ? date(
'Y-m-d H:i', $this->msgdata[
'utime']) :
'',
130 'prev_id' => $this->msgdata[
'prev_id'],
131 'next_id' => $this->msgdata[
'next_id'],
132 'key' => $this->msgdata[
'key'],
133 'inout' => $this->inout,
134 'param' => $this->msgdata[
'param'],
135 'inout_short' => $this->msgdata[
'inout_short'],
136 'avatar_url' => $avatarUrl,
137 'from_uid' => $this->msgdata[
'from_uid'] ?? 0,
138 'is_read' => $this->msgdata[
'is_read'] ?? 1,
140 'message' =>
'lock' == $this->root->mContext->mRequest->getRequest(
'cmd') ?
141 ($this->msgdata[
'is_read'] == 2 ?
'Message locked' :
'Message unlocked') :
147 if (
'inbox' == $this->inout) {
148 if (
'POST' == $_SERVER[
'REQUEST_METHOD']) {
149 if (
'lock' == $this->root->mContext->mRequest->getRequest(
'cmd')) {
150 if (1 == (
int)$this->root->mContext->mRequest->getRequest(
'lock')) {
151 $modObj->set(
'is_read', 2);
153 $modObj->set(
'is_read', 1);
155 $modHand->insert($modObj);
156 } elseif (
'mail' == $this->root->mContext->mRequest->getRequest(
'cmd')) {
157 $this->send_mail($modObj);
159 } elseif (0 == $modObj->get(
'is_read')) {
160 $modObj->set(
'is_read', 1);
161 $modHand->insert($modObj,
true);
168 if (
'outbox' == $this->inout) {
169 if (
'POST' == $_SERVER[
'REQUEST_METHOD']) {
170 if (
'mail' == $this->root->mContext->mRequest->getRequest(
'cmd')) {
171 $this->send_mail($modObj);
177 $this->mService = $this->root->mServiceManager->getService(
'UserSearch');