11 public $mMailjob =
null;
12 public $mActionForm =
null;
14 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
16 $id = (int)xoops_getrequest(
'mailjob_id');
18 $handler =& xoops_getmodulehandler(
'mailjob');
20 $this->mMailjob =& $handler->get($id);
22 if (is_object($this->mMailjob)) {
24 $this->mActionForm->prepare();
25 $this->mActionForm->load($this->mMailjob);
29 public function getDefaultView(&$controller, &$xoopsUser)
31 if (!is_object($this->mMailjob)) {
32 return USER_FRAME_VIEW_ERROR;
38 $this->mMailjob->loadUser();
40 return USER_FRAME_VIEW_INPUT;
43 public function execute(&$controller, &$xoopsUser)
45 if (!is_object($this->mMailjob)) {
46 return USER_FRAME_VIEW_ERROR;
49 if (
null != xoops_getrequest(
'_form_control_cancel')) {
50 return USER_FRAME_VIEW_CANCEL;
53 $this->mActionForm->fetch();
54 $this->mActionForm->validate();
56 if ($this->mActionForm->hasError()) {
57 return USER_FRAME_VIEW_INPUT;
60 $root =& XCube_Root::getSingleton();
61 if ($this->mMailjob->get(
'is_pm')) {
62 $this->mMailjob->mSend->add([&$this,
'sendPM']);
65 if ($this->mMailjob->get(
'is_mail')) {
66 $this->mMailjob->mSend->add([&$this,
'sendMail']);
69 $this->mMailjob->send($xoopsUser);
71 $this->mMailjob->loadUserCount();
73 return ($this->mMailjob->mUserCount > 0) ? USER_FRAME_VIEW_INPUT : USER_FRAME_VIEW_SUCCESS;
76 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
78 $controller->executeForward(
'./index.php?action=MailjobList');
81 public function executeViewError(&$controller, &$xoopsUser, &$render)
83 $controller->executeRedirect(
'./index.php?action=MailjobList', 1, _AD_USER_ERROR_MAILJOB_SEND_FAIL);
86 public function executeViewInput(&$controller, &$xoopsUser, &$render)
88 $render->setTemplateName(
'mailjob_send.html');
89 $render->setAttribute(
'object', $this->mMailjob);
90 $render->setAttribute(
'actionForm', $this->mActionForm);
93 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
95 $controller->executeForward(
'./index.php?action=MailjobList');
107 public function sendPM(&$link, &$mailjob, &$to_user, &$from_user)
109 $handler =& xoops_gethandler(
'privmessage');
111 $pm =& $handler->create();
113 $pm->set(
'subject', $mailjob->getReplaceTitle($to_user, $from_user));
114 $pm->set(
'msg_text', $mailjob->getReplaceBody($to_user, $from_user));
115 $pm->set(
'from_userid', $from_user->get(
'uid'));
116 $pm->set(
'to_userid', $to_user->get(
'uid'));
118 if (!$handler->insert($pm)) {
119 $link->set(
'message', $link->get(
'message') .
'Cound not send PM.');
123 public function sendMail(&$link, &$mailjob, $to_user, $from_user)
125 $xoopsMailer =& getMailer();
126 $xoopsMailer->useMail();
131 $xoopsMailer->setToUsers($to_user);
136 $xoopsMailer->setFromEmail($mailjob->get(
'from_email'));
137 $xoopsMailer->setFromName($mailjob->get(
'from_name'));
139 $xoopsMailer->setSubject($mailjob->getReplaceTitle($to_user, $from_user));
140 $xoopsMailer->setBody($mailjob->getReplaceBody($to_user, $from_user));
142 if (!$xoopsMailer->send(
true)) {
143 if (
'' == $link->get(
'message') &&
'' == $xoopsMailer->multimailer->ErrorInfo) {
144 $link->set(
'message',
'Could not send mail. ');
146 $link->set(
'message', $link->get(
'message') .
' / ' . $xoopsMailer->multimailer->ErrorInfo);