View source
<?php
function og_subgroups_prop_confirm_unsubscribe($form_state, $group, $account) {
global $user;
og_subgroups_include('tree');
$form = array();
$groups = array();
$directions = array_filter(variable_get('og_subgroups_propagate_members_unsubscribe', array()));
foreach ($directions as $direction) {
if ($direction) {
foreach (_og_subgroups_prop_groups_by_direction($group, $direction) as $member) {
if (isset($account->og_groups[$member->nid])) {
if (og_subgroups_prop_can_unsubscribe($member, $account)) {
$groups[$member->nid] = l($member->title, "node/{$member->nid}");
}
}
}
}
}
if ($account->uid == $user->uid) {
if (!empty($groups)) {
$sub_message = t('By leaving the group !title, you will also be removed from the following groups: !groups', array(
'!title' => l($group->title, "node/{$group->nid}"),
'!groups' => theme_item_list($groups),
));
}
$message = t('Are you sure you want to leave the group %title?', array(
'%title' => $group->title,
));
$confirm_text = t('Leave');
}
else {
if (!empty($groups)) {
$sub_message = t('By removing !name from the group !title, !name will also be removed from !groups', array(
'!name' => theme('username', $account),
'!title' => l($group->title, "node/{$group->nid}"),
'!groups' => theme_item_list($groups),
));
}
$message = t('Are you sure you want to remove !name from the group %title?', array(
'!name' => theme('username', $account),
'%title' => $group->title,
));
$confirm_text = t('Remove');
}
drupal_set_title($message);
$form['group'] = array(
'#type' => 'value',
'#value' => $group,
);
$form['groups'] = array(
'#type' => 'value',
'#value' => $groups,
);
$form['account'] = array(
'#type' => 'value',
'#value' => $account,
);
$form['sub_message'] = array(
'#prefix' => '<div class="container-inline">',
'#value' => $sub_message,
'#suffix' => '</div>',
'#type' => 'item',
'#access' => !empty($groups),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => $confirm_text,
);
$form['cancel'] = array(
'#type' => 'markup',
'#value' => l(t('Cancel'), "node/{$group->nid}"),
);
$form['#submit'] = array(
'og_subgroups_prop_confirm_unsubscribe_submit',
);
return $form;
}
function og_subgroups_prop_confirm_unsubscribe_submit($form, &$form_state) {
global $user;
$account = $form_state['values']['account'];
$group = $form_state['values']['group'];
$groups = $form_state['values']['groups'];
og_delete_subscription($group->nid, $account->uid);
$groups[$group->nid] = l($group->title, "node/{$group->nid}");
if ($user->uid == $account->uid) {
if (count($groups) > 1) {
drupal_set_message(t('You have left from the following groups: !groups', array(
'!groups' => theme_item_list($groups),
)));
}
else {
drupal_set_message(t('You have left the group !group', array(
'!group' => $groups[$group->nid],
)));
}
}
else {
if (count($groups) > 1) {
drupal_set_message(t('!user has been removed from the following groups: !groups', array(
'!user' => theme('username', $account),
'!groups' => theme_item_list($groups),
)));
}
else {
drupal_set_message(t('!user has been removed from the group !group', array(
'!user' => theme('username', $account),
'!group' => $groups[$group->nid],
)));
}
}
$form_state['redirect'] = node_access('view', $group) ? "node/{$group->nid}" : '<front>';
}