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