4 * @file Sends mails upon commenting assigned Case Tracker cases.
8 * Implementation of hook_menu().
10 function ctmail_menu() {
12 $items['admin/settings/casetracker/ctmail'] = array(
13 'title' => t('CT Mail'),
14 'page callback' => 'drupal_get_form',
15 'page arguments' => array('ctmail_settings'),
16 'access arguments' => array('administer case tracker'),
17 'type' => MENU_LOCAL_TASK,
23 * Administrative settings form.
25 function ctmail_settings() {
26 $form['ctmail_subject'] = array(
27 '#type' => 'textfield',
28 '#title' => t('Subject of the email'),
29 '#default_value' => variable_get('ctmail_subject', t('Comment of !commenter_name at !site')),
31 $form['ctmail_body'] = array(
32 '#type' => 'textarea',
33 '#title' => t('Body of the email'),
34 '#default_value' => variable_get('ctmail_body', t("Dear !recipient_name,\n!commenter_name wrote a comment: !subject\n\n!comment\n\nMore information: !link")),
36 $form['ctmail_author'] = array(
37 '#type' => 'checkbox',
38 '#title' => t('Send email to the case author (if it differs from assignee).'),
39 '#default_value' => variable_get('ctmail_author', 0),
43 t('Replacement value'),
46 array('!site', t('The name of this website')),
47 array('!nid', t('ID of the case the comment is submitted to.')),
48 array('!title', t('Title of the case the comment is submitted to.')),
49 array('!assignee_name', t('User\'s name the case is assigned to.')),
50 array('!assignee_mail', t('User\'s mail the case is assigned to.')),
51 array('!author_name', t('Case author\'s name the comment is submitted to.')),
52 array('!author_mail', t('Case author\'s mail the comment is submitted to.')),
53 array('!commenter_name', t('User\'s name who submitted the comment.')),
54 array('!commenter_mail', t('User\'s mail who submitted the comment.')),
55 array('!subject', t('Comment\'s subject.')),
56 array('!comment', t('Comment\'s body.')),
57 array('!link', t('Absolute link pointing to the comment.')),
58 array('!project_name', t('Name of the project the commented case belongs to.')),
59 array('!project_link', t('Absolute link pointing to the project.')),
60 array('!status', t('Status of the commented case.')),
61 array('!priority', t('Priority of the commented case.')),
62 array('!type', t('Type of the commented case.')),
63 array('!recipient_name', t('Recipient\'s name.')),
64 array('!recipient_mail', t('Recipient\'s mail.')),
66 $form['ctmail_tokens'] = array(
67 '#type' => 'fieldset',
68 '#title' => t('Available variables'),
69 '#collapsible' => TRUE,
71 '#description' => theme('table', $header, $rows),
73 return system_settings_form($form);
77 * Implementation of hook_form_FORM_ID_alter().
79 function ctmail_form_comment_form_alter(&$form, &$form_state) {
80 if (casetracker_is_case($form['#node']->type)) {
81 $form['#submit'][] = 'ctmail_form_comment_form_submit';
86 * Additional _submit() handler for comment forms.
88 function ctmail_form_comment_form_submit($form, &$form_state) {
89 $v = $form_state['values'];
90 if ($v['casetracker']['assign_to'] != t('Unassigned')) {
91 // Send a mail to the given address for approving the customer.
92 global $language, $user;
93 $node = node_load($v['nid']);
94 $project = node_load($node->casetracker->pid);
95 $assignee = user_load(array('name' => $v['casetracker']['assign_to'], 'status' => 1));
96 $author = user_load($node->uid);
97 $ct_status = casetracker_case_state_load(NULL, 'status');
98 $ct_priority = casetracker_case_state_load(NULL, 'priority');
99 $ct_type = casetracker_case_state_load(NULL, 'type');
101 '!site' => variable_get('site_name', 'Drupal'),
103 '!title' => $node->title,
104 '!assignee_name' => $assignee->name,
105 '!assignee_mail' => $assignee->mail,
106 '!author_name' => $author->name,
107 '!author_mail' => $author->mail,
108 '!commenter_name' => $user->name,
109 '!commenter_mail' => $user->mail,
110 '!subject' => $v['subject'],
111 '!comment' => $v['comment'],
112 '!link' => url('node/'. $v['nid'], array('absolute' => TRUE, 'fragment' => $form_state['redirect'][2])),
113 '!project_name' => $project->title,
114 '!project_link' => url('node/'. $project->nid, array('absolute' => TRUE)),
115 '!status' => $ct_status[$v['casetracker']['case_status_id']],
116 '!priority' => $ct_priority[$v['casetracker']['case_priority_id']],
117 '!type' => $ct_type[$v['casetracker']['case_type_id']],
118 '!recipient_name' => $assignee->name,
119 '!recipient_mail' => $assignee->mail,
121 drupal_mail('ctmail', 'assigned_case', $assignee->mail, $language, $params, $user->mail);
122 if (variable_get('ctmail_author', 0) && ($assignee->mail != $author->mail)) {
123 $params['!recipient_name'] = $author->name;
124 $params['!recipient_mail'] = $author->mail;
125 drupal_mail('ctmail', 'assigned_case', $author->mail, $language, $params, $user->mail);
131 * Implementation of hook_mail().
133 function ctmail_mail($key, &$message, $params) {
135 case 'assigned_case':
136 $subject = variable_get('ctmail_subject', t('Comment of !commenter_name at !site'));
137 $body = variable_get('ctmail_body', t("Dear !recipient_name,\n!commenter_name wrote a comment: !subject\n\n!comment\n\nMore information: !link"));
140 $message['subject'] = strtr($subject, $params);
141 $message['body'][] = strtr($body, $params);
144 // vim: set ft=php syntax=php expandtab ts=2 sw=2 autoindent smartindent: