function _support_subscribe_form_attach in Support Ticketing System 7
Provide option to subscribe/unsubscribe from ticket notification emails.
2 calls to _support_subscribe_form_attach()
- support_form in ./
support.module - Implementation of hook_form().
- support_form_alter in ./
support.module - Customize comment form for ticket followups.
File
- ./
support.module, line 2845 - support.module
Code
function _support_subscribe_form_attach(&$form, &$form_state, $node) {
global $user;
if (variable_get('support_notifications', TRUE)) {
$form['subscribe'] = array(
'#type' => 'fieldset',
'#title' => t('Notifications'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
if (variable_get('support_autosubscribe_creator', FALSE)) {
$notification = TRUE;
}
else {
if (!empty($node->nid)) {
$notification = db_query('SELECT 1 FROM {support_assigned} WHERE nid = :nid AND uid = :uid', array(
':nid' => $node->nid,
':uid' => $user->uid,
))
->fetchField();
}
else {
$notification = TRUE;
}
}
$form['subscribe']['notification'] = array(
'#type' => 'checkbox',
'#title' => t('Subscribe'),
'#description' => t('Receive email notifications when this ticket is updated.'),
'#default_value' => $notification,
'#disabled' => variable_get('support_autosubscribe_creator', FALSE) || variable_get('support_autosubscribe_assigned', FALSE) && isset($node->assigned) && $node->assigned == $user->uid,
);
if (user_access('can suppress notification')) {
$form['subscribe']['suppress'] = array(
'#type' => 'checkbox',
'#title' => t('Suppress notification'),
'#description' => t('By checking this box you will prevent notification emails from being sent for this ticket update. It is recommended that you check this box if you are adding sensitive information such as passwords which should not be mailed out in plain text.%admin', array(
'%admin' => user_access('administer support') ? t(' Users with "administer support" permission will still receive email notifications telling them the ticket was updated but with the body text suppressed; no notifications will be sent to users without "administer support" permissions.') : '',
)),
'#default_value' => 0,
);
}
if (user_access('administer support') || user_access('can subscribe other users to notifications')) {
$form['subscribe']['subscribed'] = array(
'#type' => 'fieldset',
'#title' => t('Subscribed'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$available = _support_assigned(0, $node, variable_get('support_autocomplete_limit', 15));
if ($available === FALSE) {
$account = user_load($node->assigned);
$accounts = array();
if (isset($node->nid)) {
$result = db_query('SELECT uid FROM {support_assigned} WHERE nid = :nid', array(
':nid' => $node->nid,
));
foreach ($result as $a) {
$account = user_load($a->uid);
$accounts[] = $account->name;
}
}
if (!empty($accounts)) {
$default = implode(', ', $accounts);
}
else {
$default = '';
}
$form['subscribe']['subscribed']['subscribed_users'] = array(
'#type' => 'textfield',
'#autocomplete_path' => 'support/autocomplete/autosubscribe/' . $node->client,
'#default_value' => $default,
'#description' => t('Enter a comma separated list of users that should receive notifications when this ticket is updated.'),
);
}
else {
$notifications = array();
if (!empty($node->nid)) {
$assigned = array_flip(db_query('SELECT uid FROM {support_assigned} WHERE nid = :nid', array(
':nid' => $node->nid,
))
->fetchCol());
}
foreach ($available as $uid => $name) {
if (!$uid) {
continue;
}
if (isset($node->nid) && $node->nid) {
if (isset($assigned[$uid])) {
$enabled = TRUE;
}
else {
$enabled = _support_enabled($node->client, $uid);
}
}
else {
if ($uid == $user->uid) {
$enabled = TRUE;
}
else {
$autoassign = _support_autoassign($node->client, $node->uid);
if ($autoassign && $autoassign != $user->uid) {
$enabled = TRUE;
}
else {
$enabled = _support_enabled($node->client, $uid);
}
}
}
if (variable_get('support_autosubscribe_force', FALSE)) {
$autosubscribed = _support_autosubscribe($node->nid, $node->client, FALSE);
}
else {
$autosubscribed = array();
}
if (variable_get('support_autosubscribe_assigned', FALSE) && isset($node->assigned) && $node->assigned == $uid) {
$enabled = TRUE;
$disabled = TRUE;
}
else {
$disabled = FALSE;
}
$notifications[] = $uid;
$form['subscribe']['subscribed']["notify-{$uid}"] = array(
'#type' => 'checkbox',
'#title' => check_plain($name),
'#default_value' => $enabled,
'#disabled' => ($uid == $user->uid || isset($autosubscribed[$uid]) || $disabled) && $enabled ? TRUE : FALSE,
);
}
$form['subscribe']['subscribed']['notifications'] = array(
'#type' => 'hidden',
'#value' => implode(',', $notifications),
);
}
}
}
}