Minahito
minah****@users*****
2006年 5月 24日 (水) 18:44:11 JST
Index: xoops2jp/html/modules/user/admin/actions/MailjobSendAction.class.php diff -u xoops2jp/html/modules/user/admin/actions/MailjobSendAction.class.php:1.1.2.1 xoops2jp/html/modules/user/admin/actions/MailjobSendAction.class.php:1.1.2.2 --- xoops2jp/html/modules/user/admin/actions/MailjobSendAction.class.php:1.1.2.1 Thu Apr 27 19:23:38 2006 +++ xoops2jp/html/modules/user/admin/actions/MailjobSendAction.class.php Wed May 24 18:44:11 2006 @@ -54,12 +54,21 @@ if ($this->mActionForm->hasError()) { return USER_FRAME_VIEW_INPUT; } - + + $root =& XCube_Root::getSingleton(); + if ($this->mMailjob->get('is_pm')) { + $root->mEventManager->add("Module.User.Mailjob.Send", new XCube_InstanceDelegate($this, "sendPM")); + } + + if ($this->mMailjob->get('is_mail')) { + $root->mEventManager->add("Module.User.Mailjob.Send", new XCube_InstanceDelegate($this, "sendMail")); + } + $this->mMailjob->send($xoopsUser); $this->mMailjob->loadUserCount(); - return ($this->mMailjob->mCount > 0) ? USER_FRAME_VIEW_INPUT : USER_FRAME_VIEW_SUCCESS; + return ($this->mMailjob->mUserCount > 0) ? USER_FRAME_VIEW_INPUT : USER_FRAME_VIEW_SUCCESS; } function executeViewSuccess(&$controller, &$xoopsUser, &$render) @@ -82,6 +91,70 @@ $render->setAttribute('object', $this->mMailjob); $render->setAttribute('actionForm', $this->mActionForm); } + + function sendPM(&$sender, &$eventArgs) + { + $root =& XCube_Root::getSingleton(); + $serviceMgr =& $root->getServiceManager(); + $pmService =& $serviceMgr->searchXCubeService('PrivateMessage'); + + $pmClient =& new XCube_ServiceClient($pmService); + + // + // Convert body message. + // + $replaceEventArgs = array(); + $replaceEventArgs['body'] = $eventArgs['mailjob']->get('body'); + $replaceEventArgs['to_user'] =& $eventArgs['to_user']; + $replaceEventArgs['from_user'] =& $eventArgs['from_user']; + $replaceEventArgs['mailjob'] =& $eventArgs['mailjob']; + $root->mEventManager->raiseEvent('Module.User.Mailjob.ReplaceBody', $this, $replaceEventArgs); + + $param = array( + 'to_uid' => $eventArgs['to_user']->get('uid'), + 'from_uid' => $eventArgs['from_user']->get('uid'), + 'subject' => $eventArgs['mailjob']->get('title'), + 'message' => $replaceEventArgs['body'] + ); + + $result =& $pmClient->call('send', $param); + } + + function sendMail(&$sender, &$eventArgs) + { + $xoopsMailer =& getMailer(); + $xoopsMailer->useMail(); + + // + // Set To + // + $xoopsMailer->setToUsers($eventArgs['to_user']); + + // + // Set From + // + $xoopsMailer->setFromEmail($eventArgs['mailjob']->get('from_email')); + $xoopsMailer->setFromName($eventArgs['mailjob']->get('from_name')); + + // + // Convert body message. + // + $replaceEventArgs = array(); + $replaceEventArgs['body'] = $eventArgs['mailjob']->get('body'); + $replaceEventArgs['to_user'] =& $eventArgs['to_user']; + $replaceEventArgs['from_user'] =& $eventArgs['from_user']; + $replaceEventArgs['mailjob'] =& $eventArgs['mailjob']; + + $root =& XCube_Root::getSingleton(); + $root->mEventManager->raiseEvent('Module.User.Mailjob.ReplaceBody', $this, $replaceEventArgs); + + $xoopsMailer->setBody($replaceEventArgs['body']); + + // + // TODO Error handling. + // + $xoopsMailer->send(true); + } } ?>