1: <?php
2: if (!defined('XOOPS_ROOT_PATH')) exit();
3:
4: require _MY_MODULE_PATH.'forms/MessageForm.class.php';
5:
6: class newAction extends AbstractAction
7: {
8: private $mActionForm;
9:
10: public function __construct()
11: {
12: parent::__construct();
13: $this->mActionForm = new MessageForm();
14: $this->mActionForm->prepare();
15: }
16:
17: public function execute()
18: {
19: if ( !$this->chk_use() ) {
20: $this->setUrl('index.php?action=settings');
21: $this->setErr(_MD_MESSAGE_SETTINGS_MSG5);
22: } else {
23: $inboxid = intval($this->root->mContext->mRequest->getRequest('res'));
24: $to_userid = intval($this->root->mContext->mRequest->getRequest('to_userid'));
25:
26: if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
27: $this->mActionForm->fetch();
28: $this->mActionForm->validate();
29: if ($this->mActionForm->hasError()) {
30: $this->errMsg = $this->mActionForm->getErrorMessages();
31: } elseif ( !$this->chk_use($this->mActionForm->fuid) || !$this->chk_deny($this->mActionForm->fuid) ) {
32: $this->errMsg = _MD_MESSAGE_SETTINGS_MSG6;
33: } elseif ( $this->mActionForm->get('Legacy_Event_User_Submit') != "" ) {
34: $this->isError = true;
35: $modHand = xoops_getmodulehandler('inbox', _MY_DIRNAME);
36: $modObj = $modHand->create();
37: $this->mActionForm->update($modObj);
38: if ( !$modHand->insert($modObj) ) {
39: $this->errMsg = _MD_MESSAGE_ACTIONMSG5;
40: } else {
41: $this->usemail();
42: $modHand->deleteDays($this->root->mContext->mModuleConfig['savedays'], $this->root->mContext->mModuleConfig['dletype']);
43: if ( !$this->update_outbox($modObj) ) {
44: $this->errMsg = _MD_MESSAGE_ACTIONMSG6;
45: } else {
46: $this->errMsg = _MD_MESSAGE_ACTIONMSG7;
47: }
48: }
49: }
50: } elseif ( $inboxid > 0 ) {
51: $modHand = xoops_getmodulehandler('inbox', _MY_DIRNAME);
52: $modObj = $modHand->get($inboxid);
53: if ( is_object($modObj) && $modObj->get('from_uid') > 0 && $modObj->get('uid') == $this->root->mContext->mXoopsUser->get('uid') ) {
54: if ( !$this->mActionForm->setRes($modObj) ) {
55: $this->errMsg = _MD_MESSAGE_ACTIONMSG9;
56: }
57: }
58: } elseif ( $to_userid > 0 ) {
59: $userhand = xoops_gethandler('user');
60: $user = $userhand->get($to_userid);
61: $this->mActionForm->setUser($user);
62: }
63: }
64: }
65:
66: private function chk_deny($uid)
67: {
68: $fromid = $this->root->mContext->mXoopsUser->get('uid');
69: $modObj = $this->getSettings($uid);
70: $blacklist = $modObj->get('blacklist');
71: if ( $blacklist == "" ) {
72: return true;
73: } elseif ( strpos($blacklist, ',') !== false ) {
74: $lists = explode(',', $blacklist);
75: if ( !in_array($fromid, $lists) ) {
76: return true;
77: }
78: } elseif ( $blacklist != $fromid ) {
79: return true;
80: }
81: return false;
82: }
83:
84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105:
106:
107: private function usemail()
108: {
109: $setting = $this->getSettings($this->mActionForm->fuid);
110: if ( $setting->get('tomail') == 1 ) {
111: $userhand = xoops_gethandler('user');
112: $user = $userhand->get($this->mActionForm->fuid);
113:
114: $mailer = $this->getMailer();
115: $mailer->setFromName($this->root->mContext->mXoopsConfig['sitename']);
116: $mailer->setFromEmail($this->root->mContext->mXoopsConfig['adminmail']);
117: $mailer->setToEmails($user->get('email'));
118: $mailer->setSubject(_MD_MESSAGE_MAILSUBJECT);
119: $mailer->setBody($this->getMailBody($setting->get('viewmsm')));
120: $mailer->send();
121: }
122: }
123:
124: private function getMailBody($body = 0)
125: {
126: $tpl = new Smarty();
127: $tpl->_canUpdateFromFile = true;
128: $tpl->compile_check = true;
129: $tpl->template_dir = _MY_MODULE_PATH.'language/'.$this->root->mLanguageManager->mLanguageName.'/';
130: $tpl->cache_dir = XOOPS_CACHE_PATH;
131: $tpl->compile_dir = XOOPS_COMPILE_PATH;
132:
133: $tpl->assign('sitename', $this->root->mContext->mXoopsConfig['sitename']);
134: $tpl->assign('uname', $this->root->mContext->mXoopsUser->get('uname'));
135: if ( $body == 1 ) {
136: $tpl->assign('note', $this->mActionForm->get('note'));
137: } else {
138: $tpl->assign('note', XCube_Utils::formatString(_MD_MESSAGE_MAILBODY, XOOPS_URL.'/'));
139: }
140: $tpl->assign('siteurl', XOOPS_URL.'/');
141: return $tpl->fetch(_MY_MODULE_PATH.'language/'.$this->root->mLanguageManager->mLanguageName.'/invitation.tpl');
142: }
143:
144: private function update_outbox(&$obj)
145: {
146: $outHand = xoops_getmodulehandler('outbox');
147: $outHand->deleteDays($this->root->mContext->mModuleConfig['savedays']);
148: $outObj = $outHand->create();
149: $outObj->set('uid', $obj->get('from_uid'));
150: $outObj->set('to_uid', $obj->get('uid'));
151: $outObj->set('title', $obj->get('title'));
152: $outObj->set('message', $obj->get('message'));
153: $outObj->set('utime', $obj->get('utime'));
154: return $outHand->insert($outObj);
155: }
156:
157: public function executeView(&$render)
158: {
159: $render->setTemplateName('message_new.html');
160: $render->setAttribute('mActionForm', $this->mActionForm);
161: $render->setAttribute('errMsg', $this->errMsg);
162: }
163: }
164: ?>
165: