21 private \MessageForm $mActionForm;
24 public function __construct()
26 parent::__construct();
28 $this->mActionForm->prepare();
31 public function execute()
33 if (!$this->chk_use()) {
34 $this->setUrl(
'index.php?action=settings');
35 $this->setErr(_MD_MESSAGE_SETTINGS_MSG5);
37 $inboxid = (int)$this->root->mContext->mRequest->getRequest(
'res');
38 $to_userid = (int)$this->root->mContext->mRequest->getRequest(
'to_userid');
40 if (
'POST' === $_SERVER[
'REQUEST_METHOD']) {
41 $this->mActionForm->fetch();
42 $this->mActionForm->validate();
43 if ($this->mActionForm->hasError()) {
44 $this->errMsg = $this->mActionForm->getErrorMessages();
45 } elseif (!$this->chk_use($this->mActionForm->fuid) || !$this->chk_deny($this->mActionForm->fuid)) {
46 $this->errMsg = _MD_MESSAGE_SETTINGS_MSG6;
47 } elseif (
'' !== $this->mActionForm->get(
'Legacy_Event_User_Submit')) {
48 $this->isError =
true;
49 $modHand = xoops_getmodulehandler(
'inbox', _MY_DIRNAME);
50 $modObj = $modHand->create();
51 $this->mActionForm->update($modObj);
52 if (!$modHand->insert($modObj)) {
53 $this->errMsg = _MD_MESSAGE_ACTIONMSG5;
56 $modHand->deleteDays($this->root->mContext->mModuleConfig[
'savedays'], $this->root->mContext->mModuleConfig[
'dletype']);
57 if (!$this->update_outbox($modObj)) {
58 $this->errMsg = _MD_MESSAGE_ACTIONMSG6;
60 $this->errMsg = _MD_MESSAGE_ACTIONMSG7;
64 } elseif ($inboxid > 0) {
65 $modHand = xoops_getmodulehandler(
'inbox', _MY_DIRNAME);
66 $modObj = $modHand->get($inboxid);
67 if (is_object($modObj) && $modObj->get(
'from_uid') > 0 && $modObj->get(
'uid') == $this->root->mContext->mXoopsUser->get(
'uid') && !$this->mActionForm->setRes($modObj)) {
68 $this->errMsg = _MD_MESSAGE_ACTIONMSG9;
70 } elseif ($to_userid > 0) {
71 $userhand = xoops_gethandler(
'user');
72 $user = $userhand->get($to_userid);
73 $this->mActionForm->setUser($user);
76 $this->mService = $this->root->mServiceManager->getService(
'UserSearch');
80 private function chk_deny($uid)
82 $fromid = $this->root->mContext->mXoopsUser->get(
'uid');
83 $modObj = $this->getSettings($uid);
84 $blacklist = $modObj->get(
'blacklist');
85 if (
'' === $blacklist) {
89 if (strpos($blacklist,
',') !==
false) {
90 $lists = explode(
',', $blacklist);
91 if (!in_array($fromid, $lists,
true)) {
94 } elseif ($blacklist !== $fromid) {
100 private function usemail()
102 $setting = $this->getSettings($this->mActionForm->fuid);
103 if (1 == $setting->get(
'tomail')) {
104 $userhand = xoops_gethandler(
'user');
105 $user = $userhand->get($this->mActionForm->fuid);
107 $mailer = $this->getMailer();
108 $mailer->setFromName($this->root->mContext->mXoopsConfig[
'sitename']);
109 $mailer->setFromEmail($this->root->mContext->mXoopsConfig[
'adminmail']);
110 $mailer->setToEmails($user->get(
'email'));
111 $mailer->setSubject(_MD_MESSAGE_MAILSUBJECT);
112 $mailer->setBody($this->getMailBody($setting->get(
'viewmsm')));
117 private function getMailBody($body = 0)
125 $tpl->compile_check =
true;
126 $tpl->template_dir = _MY_MODULE_PATH.
'language/'.$this->root->mLanguageManager->mLanguageName.
'/';
127 $tpl->cache_dir = XOOPS_CACHE_PATH;
128 $tpl->compile_dir = XOOPS_COMPILE_PATH;
130 $tpl->assign(
'sitename', $this->root->mContext->mXoopsConfig[
'sitename']);
131 $tpl->assign(
'uname', $this->root->mContext->mXoopsUser->get(
'uname'));
133 $tpl->assign(
'note', $this->mActionForm->get(
'note'));
137 $tpl->assign(
'siteurl', XOOPS_URL.
'/');
138 return $tpl->fetch(_MY_MODULE_PATH.
'language/'.$this->root->mLanguageManager->mLanguageName.
'/invitation.tpl');
141 private function update_outbox(&$obj)
143 $outHand = xoops_getmodulehandler(
'outbox');
144 $outHand->deleteDays($this->root->mContext->mModuleConfig[
'savedays']);
145 $outObj = $outHand->create();
146 $outObj->set(
'uid', $obj->get(
'from_uid'));
147 $outObj->set(
'to_uid', $obj->get(
'uid'));
148 $outObj->set(
'title', $obj->get(
'title'));
149 $outObj->set(
'message', $obj->get(
'message'));
150 $outObj->set(
'utime', $obj->get(
'utime'));
151 return $outHand->insert($outObj);
154 public function executeView(&$render)
156 $render->setTemplateName(
'message_new.html');
157 $render->setAttribute(
'mActionForm', $this->mActionForm);
158 $render->setAttribute(
'errMsg', $this->errMsg);
159 $render->setAttribute(
'UserSearch', $this->mService);
160 $render->setAttribute(
'message_url', XOOPS_URL.
'/modules/message/index.php');