XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
MailjobSendAction.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7require_once XOOPS_MODULE_PATH . '/user/admin/forms/MailjobAdminSendForm.class.php';
8
9class User_MailjobSendAction extends User_Action
10{
11 public $mMailjob = null;
12 public $mActionForm = null;
13
14 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
15 {
16 $id = (int)xoops_getrequest('mailjob_id');
17
18 $handler =& xoops_getmodulehandler('mailjob');
19
20 $this->mMailjob =& $handler->get($id);
21
22 if (is_object($this->mMailjob)) {
23 $this->mActionForm =new User_MailjobAdminSendForm();
24 $this->mActionForm->prepare();
25 $this->mActionForm->load($this->mMailjob);
26 }
27 }
28
29 public function getDefaultView(&$controller, &$xoopsUser)
30 {
31 if (!is_object($this->mMailjob)) {
32 return USER_FRAME_VIEW_ERROR;
33 }
34
35 //
36 // lazy load
37 //
38 $this->mMailjob->loadUser();
39
40 return USER_FRAME_VIEW_INPUT;
41 }
42
43 public function execute(&$controller, &$xoopsUser)
44 {
45 if (!is_object($this->mMailjob)) {
46 return USER_FRAME_VIEW_ERROR;
47 }
48
49 if (null != xoops_getrequest('_form_control_cancel')) {
50 return USER_FRAME_VIEW_CANCEL;
51 }
52
53 $this->mActionForm->fetch();
54 $this->mActionForm->validate();
55
56 if ($this->mActionForm->hasError()) {
57 return USER_FRAME_VIEW_INPUT;
58 }
59
60 $root =& XCube_Root::getSingleton();
61 if ($this->mMailjob->get('is_pm')) {
62 $this->mMailjob->mSend->add([&$this, 'sendPM']);
63 }
64
65 if ($this->mMailjob->get('is_mail')) {
66 $this->mMailjob->mSend->add([&$this, 'sendMail']);
67 }
68
69 $this->mMailjob->send($xoopsUser);
70
71 $this->mMailjob->loadUserCount();
72
73 return ($this->mMailjob->mUserCount > 0) ? USER_FRAME_VIEW_INPUT : USER_FRAME_VIEW_SUCCESS;
74 }
75
76 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
77 {
78 $controller->executeForward('./index.php?action=MailjobList');
79 }
80
81 public function executeViewError(&$controller, &$xoopsUser, &$render)
82 {
83 $controller->executeRedirect('./index.php?action=MailjobList', 1, _AD_USER_ERROR_MAILJOB_SEND_FAIL);
84 }
85
86 public function executeViewInput(&$controller, &$xoopsUser, &$render)
87 {
88 $render->setTemplateName('mailjob_send.html');
89 $render->setAttribute('object', $this->mMailjob);
90 $render->setAttribute('actionForm', $this->mActionForm);
91 }
92
93 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
94 {
95 $controller->executeForward('./index.php?action=MailjobList');
96 }
97
107 public function sendPM(&$link, &$mailjob, &$to_user, &$from_user)
108 {
109 $handler =& xoops_gethandler('privmessage');
110
111 $pm =& $handler->create();
112
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'));
117
118 if (!$handler->insert($pm)) {
119 $link->set('message', $link->get('message') . 'Cound not send PM.');
120 }
121 }
122
123 public function sendMail(&$link, &$mailjob, $to_user, $from_user)
124 {
125 $xoopsMailer =& getMailer();
126 $xoopsMailer->useMail();
127
128 //
129 // Set To
130 //
131 $xoopsMailer->setToUsers($to_user);
132
133 //
134 // Set From
135 //
136 $xoopsMailer->setFromEmail($mailjob->get('from_email'));
137 $xoopsMailer->setFromName($mailjob->get('from_name'));
138
139 $xoopsMailer->setSubject($mailjob->getReplaceTitle($to_user, $from_user));
140 $xoopsMailer->setBody($mailjob->getReplaceBody($to_user, $from_user));
141
142 if (!$xoopsMailer->send(true)) {
143 if ('' == $link->get('message') && '' == $xoopsMailer->multimailer->ErrorInfo) {
144 $link->set('message', 'Could not send mail. ');
145 } else {
146 $link->set('message', $link->get('message') . ' / ' . $xoopsMailer->multimailer->ErrorInfo);
147 }
148 }
149 }
150}
sendPM(&$link, &$mailjob, &$to_user, &$from_user)