17 require_once SQ_FUDGE_PATH.
'/general/www.inc';
79 var $priority = SQ_MSG_PRIORITY_NORMAL;
85 var $status = SQ_MSG_UNREAD;
97 var $parameters = Array();
104 var $replacements = Array();
128 if (!$messageid)
return false;
133 'messageid' => $messageid,
136 }
catch (Exception $e) {
137 throw new Exception(
'Unable to get message with messageid #'.$messageid.
' due to the following database error:'.$e->getMessage());
141 if (!empty($result_all)) {
142 $result = $result_all[0];
147 $this->
id = $result[
'msgid'];
148 $this->to = Array($result[
'userto']);
149 $this->from = $result[
'userfrom'];
150 $this->subject = $result[
'subject'];
151 $this->body = $result[
'body'];
152 $this->type = $result[
'type'];
153 $this->sent = iso8601_ts($result[
'sent']);
154 $this->priority = $result[
'priority'];
155 $this->status = $result[
'status'];
156 $this->parameters = $result[
'parameters'];
157 $this->assetid = $result[
'assetid'];
173 assert_not_empty(trim($this->type),
'Could not send internal message without a type set');
177 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
178 $lm = $GLOBALS[
'SQ_SYSTEM']->lm;
180 foreach ($ms->getLogTypes($this->type) as $main_type_code => $allow_log) {
181 $$main_type_code = $allow_log;
186 if ($this->from && assert_valid_assetid($this->from,
'', TRUE, FALSE)) {
187 $user_from = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->from);
188 if (!is_null($user_from)) {
189 $from_name = $user_from->name;
191 $from_name =
'Unknown User #'.$this->from;
195 $from_name = SQ_SYSTEM_SHORT_NAME.
' System';
199 foreach ($this->parameters as $key => $value) {
200 $param_string .=
"$key:$value;";
204 if (isset($this->parameters[
'assetid']) === TRUE) {
205 $assetid = $this->parameters[
'assetid'];
208 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
209 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
247 $log_body = preg_replace(
'|<SQ_MSG_LINK[^>]*?>(.*?)</SQ_MSG_LINK>|',
'\\1', $this->body);
249 $log_line =
'['.$this->type.
' - '.$param_string.
'] ('.
250 $lm->getInternalMessageSubject($this->type, $this->replacements, SQ_CONF_DEFAULT_BACKEND_LOCALE).
') - '.
251 $lm->getInternalMessageBody($this->type, $this->replacements, SQ_CONF_DEFAULT_BACKEND_LOCALE);
253 $tagline_reg =
'|<SQ_MSG_TAGLINE[^>]*?>(.*?)</SQ_MSG_TAGLINE>|';
254 if (preg_match($tagline_reg, $log_line, $matches)) {
255 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($matches[1]);
256 $log_line = preg_replace($tagline_reg, $asset->name.
' (#'.$asset->id.
')', $log_line);
257 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
260 log_write($log_line);
264 if ($log_to_db || $send_mail) {
266 $from_email = SQ_CONF_DEFAULT_EMAIL;
268 if ($this->from && !is_null($user_from)) {
269 $from_string = $user_from->name.
' <'.$user_from->attr(
'email').
'>';
270 $from_email = $user_from->attr(
'email');
271 }
else if ($this->from && valid_email($this->from)) {
272 $from_email = $this->from;
275 if (empty($from_email)) {
276 if (isset($_SERVER[
'HOSTNAME']) && isset($_SERVER[
'HTTP_HOST'])) {
277 $from_email =
'webmaster@'.((SQ_PHP_CLI) ? $_SERVER[
'HOSTNAME'] : $_SERVER[
'HTTP_HOST']);
279 $from_email = SQ_CONF_DEFAULT_EMAIL;
282 if (empty($from_string)) {
283 $from_string =
'"'.SQ_SYSTEM_SHORT_NAME.
' System" <'.$from_email.
'>';
292 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
297 $log_body = preg_replace(
'|<SQ_MSG_LINK ([^>]*?)>(.*?)</SQ_MSG_LINK>|',
'<a \\1>\\2</a>', $this->body);
304 MatrixDAL::bindValueToPdo($query,
'subject', (empty($this->subject) ? $lm->getInternalMessageSubject($this->type, $this->replacements, SQ_CONF_DEFAULT_BACKEND_LOCALE) : $this->subject), PDO::PARAM_STR);
305 MatrixDAL::bindValueToPdo($query,
'body', (empty($this->body) ? $lm->getInternalMessageBody($this->type, $this->replacements, SQ_CONF_DEFAULT_BACKEND_LOCALE) : $this->body), PDO::PARAM_LOB);
314 throw new Exception(
'Creation of internal message failed due to database error: '.$e->getMessage());
317 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
324 if ($send_mail || (0 === strpos($this->type,
'inbox'))) {
326 require_once
'Mail.php';
327 require_once
'Mail/mime.php';
330 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
334 $mime =
new Mail_mime($crlf);
339 $mail = $mf->factory(
'mail',
"-f$from_email");
342 foreach ($send_to as $userid) {
344 $reply_to_email = isset($this->parameters[
'reply_to']) ? $this->parameters[
'reply_to'] :
'';
349 $default = SQ_CONF_DEFAULT_EMAIL;
350 $tech = SQ_CONF_TECH_EMAIL;
353 $user_locale = SQ_CONF_DEFAULT_BACKEND_LOCALE;
355 $subject = $this->subject;
356 if (empty($subject)) {
357 $subject = $lm->getInternalMessageSubject($this->type, $this->replacements, $user_locale);
359 $subject = replace_keywords($subject, $this->replacements);
362 'From' => $from_string,
363 'Subject' => $subject,
366 if (!empty($default)) $to_email .= $default;
368 if (!empty($to_email)) $to_email .=
',';
373 if (empty($to_email)) {
379 $owner = SQ_CONF_SYSTEM_OWNER;
380 $log_body = $this->body;
381 if (empty($log_body)) {
382 $log_body = $lm->getInternalMessageBody($this->type, $this->replacements, $user_locale);
384 $log_body = replace_keywords($log_body, $this->replacements);
386 $log_body = preg_replace(
'|<SQ_MSG_LINK ([^>]*?)>(.*?)</SQ_MSG_LINK>|',
'<a \\1>\\2</a>', $log_body);
388 $tagline_reg =
'|<SQ_MSG_TAGLINE[^>]*?>(.*?)</SQ_MSG_TAGLINE>|';
389 if (preg_match($tagline_reg, $log_body, $matches)) {
390 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($matches[1]);
391 $log_body = preg_replace($tagline_reg, $asset->name.
' (#'.$asset->id.
')', $log_body);
392 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
395 $ms->queueEmail($this->from, 0, $subject, $log_body, $reply_to_email);
396 if (!$ms->sending_queue) $ms->sendQueuedEmails();
402 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($userid);
403 if (is_null($user) || !($user instanceof
User) || !$user->canAccessBackend())
continue;
404 $user_locale = $user->attr(
'locale');
405 if (empty($user_locale)) {
406 $user_locale = SQ_CONF_DEFAULT_BACKEND_LOCALE;
409 $this->replacements[
'user_name'] = $user->name;
411 $subject = empty($this->subject) ? $lm->getInternalMessageSubject($this->type, $this->replacements, $user_locale) : replace_keywords($this->subject, $this->replacements);
413 'From' => $from_string,
414 'Subject' => $subject,
417 $log_body = preg_replace(
'|<SQ_MSG_LINK ([^>]*?)>(.*?)</SQ_MSG_LINK>|',
'<a \\1>\\2</a>', $body);
423 }
catch (Exception $e) {
424 throw new Exception(
"Unable to get next internal message ID due to database error:".$e->getMessage());
441 }
catch (Exception $e) {
442 throw new Exception(
'Creation of internal message failed due to database error: '.$e->getMessage());
447 $to_email = trim($user->attr(
'email'));
453 $log_body = preg_replace(
'|<SQ_MSG_LINK ([^>]*?)>(.*?)</SQ_MSG_LINK>|',
'<a \\1>\\2</a>', $body);
455 $tagline_reg =
'|<SQ_MSG_TAGLINE[^>]*?>(.*?)</SQ_MSG_TAGLINE>|';
456 if (preg_match($tagline_reg, $log_body, $matches)) {
457 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($matches[1]);
458 $log_body = preg_replace($tagline_reg, $asset->name.
' (#'.$asset->id.
')', $log_body);
459 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
462 $ms->queueEmail($this->from, $userid, $subject, $log_body, $reply_to_email);
463 if (!$ms->sending_queue) $ms->sendQueuedEmails();
469 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
473 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
487 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
488 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
489 $info = $ms->getMessages($this->to[0], $this->type, Array(), Array($this->
id), $this->from, null,
'name');
495 .sq-message-item, .sq-message-item-msg {
497 font-family: Arial, Verdana, Helvetica, sans-serif;
499 text-decoration: none;
501 .sq-message-item-msg {
503 font-family: courier
new, fixed;
506 text-decoration: none;
510 <body bgcolor=
"#FFFFFF">
511 <table border=
"0" cellspacing=
"1" cellpadding=
"2" width=
"100%" height=
"100%">
513 <td valign=
"top" class=
"sq-message-item"><b><?php strtoupper(translate(
'subject')) ?>:</b></td>
514 <td valign=
"top" class=
"sq-message-item" width=
"100%"><?php echo $info[
'subject']; ?></td>
517 <td valign=
"top" class=
"sq-message-item"><b><?php strtoupper(translate(
'from')) ?>:</b></td>
518 <td valign=
"top" class=
"sq-message-item" width=
"100%"><?php echo $info[
'from_name'] ?></td>
521 <td valign=
"top" class=
"sq-message-item"><b><?php strtoupper(translate(
'date')) ?>:</b></td>
522 <td valign=
"top" class=
"sq-message-item" width=
"100%"><?php echo readable_datetime($info[
'sent']); ?></td>
525 <td valign=
"top" class=
"sq-message-item-msg" bgcolor=
"#FFFFFF" width=
"100%" colspan=
"2"><br/><pre><?php echo $info[
'body']; ?></pre></td>
546 $tmpReplacements = $this->replacements;
547 $lm = $GLOBALS[
'SQ_SYSTEM']->lm;
550 if ($isInternalMessage == TRUE) {
551 if (strpos($this->type,
'asset.workflow.') !== FALSE) {
554 if (isset($tmpReplacements[
'workflow_url'])) {
555 $tmpReplacements[
'workflow_url'] .=
'&SQ_BACKEND_PAGE=main';
557 if (isset($tmpReplacements[
'preview_url'])) {
558 $tmpReplacements[
'preview_url'] .=
'&SQ_BACKEND_PAGE=main';
560 if (isset($tmpReplacements[
'accept_url'])) {
561 $tmpReplacements[
'accept_url'] .=
'&SQ_BACKEND_PAGE=main';
563 if (isset($tmpReplacements[
'reject_url'])) {
564 $tmpReplacements[
'reject_url'] .=
'&SQ_BACKEND_PAGE=main';
569 if (!($user instanceof
User)) {
570 if (trim($this->body) ===
'') {
571 return $lm->getInternalMessageBody($this->type, $tmpReplacements, SQ_CONF_DEFAULT_BACKEND_LOCALE);
574 return replace_keywords($body, $tmpReplacements);
577 require_once SQ_FUDGE_PATH.
'/general/text.inc';
579 $replacements = $tmpReplacements;
580 if (!isset($replacements[
'user_name'])){
581 $replacements[
'user_name'] = $user->name;
584 $user_locale = $user->attr(
'locale');
585 if (empty($user_locale)) {
586 $user_locale = SQ_CONF_DEFAULT_BACKEND_LOCALE;
588 if (trim($this->body) ===
'') {
589 return $lm->getInternalMessageBody($this->type, $replacements, $user_locale);
592 return replace_keywords($body, $replacements);
594 return replace_keywords($body, $replacements);
610 if (empty($this->to)) {
613 $type = explode(
'.', $this->type);
617 if (isset($type[1])) {
620 if (!isset($this->parameters[
'majorid'])) {
621 trigger_localised_error(
'SYS0168', E_USER_WARNING, $this->type);
622 }
else if (!isset($this->parameters[
'minorid'])) {
623 trigger_localised_error(
'SYS0168', E_USER_WARNING, $this->type);
625 $major = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->parameters[
'majorid']);
626 if (is_null($major)) {
627 trigger_localised_error(
'SYS0167', E_USER_WARNING, $this->parameters[
'majorid'], $this->type);
629 $minor = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->parameters[
'minorid']);
630 if (is_null($minor)) {
631 trigger_localised_error(
'SYS0167', E_USER_WARNING, $this->parameters[
'minorid'], $this->type);
637 if (isset($type[2]) && $type[2] ==
'forced') {
638 $this->to += Array($this->parameters[
'former_userid']);
644 if (!isset($this->parameters[
'assetid'])) {
646 trigger_localised_error(
'SYS0168', E_USER_WARNING, $this->type);
648 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($this->parameters[
'assetid']);
649 if (is_null($asset)) {
651 trigger_localised_error(
'SYS0167', E_USER_WARNING, $this->parameters[
'assetid'], $this->type);
654 $this->to += $GLOBALS[
'SQ_SYSTEM']->am->getPermission($asset->id, SQ_PERMISSION_ADMIN,
true,
false);
655 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
662 $root_user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
663 $this->to += Array(0, $root_user->id);
671 if (in_array(
'0', $this->to)) {
677 foreach ($this->to as $assetid) {
679 if ($assetid == 0)
continue;
681 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid);
682 if (is_null($asset))
continue;
685 $send_to = array_merge($send_to, array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($asset->id, Array(
'user'),
false)));
686 }
else if ($asset instanceof
User) {
687 $send_to[] = $assetid;
691 return array_unique($send_to);
705 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
706 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
708 $bind_vars = Array(
'msgid' => $this->
id);
710 }
catch (Exception $e) {
711 throw new Exception(
'Unable to delete this message #'.$this->
id);
713 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
714 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
731 if (!$this->
id)
return false;
733 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
734 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
736 $bind_vars = Array(
'status' => $status,
'msgid' => $this->
id);
739 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
740 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();