ticket_notify db what msg_id subject body { excluded_users " " }What it does:
send mail to people who should know about this change. what -- new_ticket updated_ticket copied_ticket status_change etc (so we don;t notify submitter on new ticket for example)Defined in: /web/philip/tcl/ticket-defs.tcl
Source code:
set precedence {watcher admin assignee submitter}
# Currently watches unimplemented
foreach who $precedence {
switch $who {
watcher {
# set all admins
set query 1
set selection [ns_db select $db "select
u.email as notify_email, u.first_names || ' ' || u.last_name as user_name,
u.user_id as notify_user_id
from users_alertable u, ticket_email_alerts tea, ticket_issues ti
where u.user_id = tea.user_id
and ti.msg_id = $msg_id
and (tea.msg_id = ti.msg_id
or (tea.domain_id = ti.domain_id and tea.project_id is null)
or (tea.domain_id is null and tea.project_id = ti.project_id)
or (tea.domain_id = ti.domain_id and tea.project_id = ti.project_id))"]
set is_a "watcher"
}
admin {
# set all admins -- do not spam if notify_admin_p is false.
set query 1
set selection [ns_db select $db "select
u.email as notify_email,
u.first_names || ' ' || u.last_name as user_name,
u.user_id as notify_user_id
from users_alertable u,
ticket_issues t,
ticket_domains td,
ticket_projects tp,
user_group_map ugm
where u.user_id = ugm.user_id
and t.msg_id = $msg_id
and td.domain_id = t.domain_id
and ugm.group_id = td.group_id
and ugm.role = 'administrator'
and td.notify_admin_p = 't'"]
set is_a "admin"
}
assignee {
# set all assigned users
set query 1
set selection [ns_db select $db "select
u.email as notify_email, u.first_names || ' ' || u.last_name as user_name,
u.user_id as notify_user_id
from users_alertable u, ticket_issue_assignments tia, ticket_issues t
where tia.msg_id = $msg_id
and u.user_id = tia.user_id and t.msg_id = $msg_id and tia.msg_id = t.msg_id"]
set is_a "assignee"
}
submitter {
if {[lsearch -exact {new_ticket} $what] < 0} {
set query 1
set selection [ns_db select $db "select
u.email as notify_email, u.first_names || ' ' || u.last_name as user_name,
u.user_id as notify_user_id
from users_alertable u, ticket_issues t where t.user_id = u.user_id and t.msg_id = $msg_id"]
set is_a submitter
} else {
set query 0
}
}
default {
set query 0
}
}
if { $query } {
while { [ns_db getrow $db $selection] } {
set_variables_after_query
if {[lsearch -exact $excluded_users $notify_user_id] < 0} {
# not on the exclude list...
set mail_name($notify_email) "$user_name"
set mail_user_id($notify_email) "$notify_user_id"
set mail_is_a($notify_email) "$is_a"
}
}
}
}
set pretty_is_a(watcher) "Has watches set:"
set pretty_is_a(admin) "Administrator:"
set pretty_is_a(submitter) "Original submitter:"
set pretty_is_a(assignee) "Assigned to Ticket:"
set send_to {}
set send_to_html {The following people have been notified:<ul>}
foreach user_is_a $precedence {
set i 0
foreach who [array names mail_is_a] {
if { $mail_is_a($who) == "$user_is_a"} {
if {$i == 0} {
append send_to " $pretty_is_a($user_is_a)\n"
}
append send_to " $mail_name($who) - $who\n"
append send_to_html "<li> <a href=\"mailto:$who\">$mail_name($who)</a> <em>($user_is_a)</em><br>\n"
incr i
}
}
}
append send_to_html {</ul><p>}
set extra_headers [ns_set create]
foreach who [array names mail_is_a] {
ns_set update $extra_headers "Reply-To" [ticket_reply_email_addr $msg_id $mail_user_id($who)]
if {[catch {ns_sendmail [ticket_mail_send $who] [ticket_reply_email_addr] $subject [ticket_mail_send_body $who "$body\n\n$send_to\nManage via [ad_url]/ticket/issue-view.tcl?msg_id=$msg_id"] $extra_headers} errmsg]} {
append send_to_html "Error for $who<pre>$errmsg</pre>"
}
}
append send_to_html "Subject: <strong>[ns_quotehtml $subject]</strong><pre>[ns_quotehtml $body]</pre>\nManage via <a href=\"[ad_url]/ticket/issue-view?msg_id=$msg_id\">/ticket/issue-view.tcl?msg_id=$msg_id</a>"
return $send_to_html