コード例 #1
0
ファイル: Object.php プロジェクト: LeeGlendenning/formulize
 /**
  * Send a notification message to the user
  *
  * @param  string  $template_dir  Template directory
  * @param  string  $template      Template name
  * @param  string  $subject       Subject line for notification message
  * @param  array   $tags Array of substitutions for template variables
  *
  * @return  bool	true if success, false if error
  **/
 public function notifyUser($template_dir, $template, $subject, $tags)
 {
     global $icmsConfigMailer;
     // Check the user's notification preference.
     $member_handler = icms::handler('icms_member');
     $user =& $member_handler->getUser($this->getVar('not_uid'));
     if (!is_object($user)) {
         return true;
     }
     $method = $user->getVar('notify_method');
     $xoopsMailer = new icms_messaging_Handler();
     include_once ICMS_ROOT_PATH . '/include/notification_constants.php';
     switch ($method) {
         case XOOPS_NOTIFICATION_METHOD_PM:
             $xoopsMailer->usePM();
             $xoopsMailer->setFromUser($member_handler->getUser($icmsConfigMailer['fromuid']));
             foreach ($tags as $k => $v) {
                 $xoopsMailer->assign($k, $v);
             }
             break;
         case XOOPS_NOTIFICATION_METHOD_EMAIL:
             $xoopsMailer->useMail();
             foreach ($tags as $k => $v) {
                 $xoopsMailer->assign($k, preg_replace("/&/i", '&', $v));
             }
             break;
         default:
             return true;
             // report error in user's profile??
             break;
     }
     // Set up the mailer
     $xoopsMailer->setTemplateDir($template_dir);
     $xoopsMailer->setTemplate($template);
     $xoopsMailer->setToUsers($user);
     //global $icmsConfig;
     //$xoopsMailer->setFromEmail($icmsConfig['adminmail']);
     //$xoopsMailer->setFromName($icmsConfig['sitename']);
     $xoopsMailer->setSubject($subject);
     $success = $xoopsMailer->send();
     // If send-once-then-delete, delete notification
     // If send-once-then-wait, disable notification
     include_once ICMS_ROOT_PATH . '/include/notification_constants.php';
     $notification_handler = icms::handler('icms_data_notification');
     if ($this->getVar('not_mode') == XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE) {
         $notification_handler->delete($this);
         return $success;
     }
     if ($this->getVar('not_mode') == XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT) {
         $this->setVar('not_mode', XOOPS_NOTIFICATION_MODE_WAITFORLOGIN);
         $notification_handler->insert($this);
     }
     return $success;
 }