You are here

function notifications_multiple_delete_confirm in Notifications 7

Same name and namespace in other branches
  1. 6.4 notifications.manage.inc \notifications_multiple_delete_confirm()
  2. 6 notifications.manage.inc \notifications_multiple_delete_confirm()
  3. 6.2 notifications.manage.inc \notifications_multiple_delete_confirm()
  4. 6.3 notifications.manage.inc \notifications_multiple_delete_confirm()

Form for multiple delete. When account passed check that all subscriptions belong to the user account

File

./notifications.pages.inc, line 388
User pages for Notifications

Code

function notifications_multiple_delete_confirm(&$form_state, $items, $destination = NULL) {
  $destination = $destination ? $destination : $_GET['q'];
  $sids = array_keys($items);
  if (notifications_manage_subscriptions_access(array_keys($items))) {
    $form['items'] = array(
      '#prefix' => '<ul>',
      '#suffix' => '</ul>',
      '#tree' => TRUE,
    );

    // array_filter returns only elements with TRUE values
    foreach ($items as $id => $value) {

      // Load the subscription to display a friendly name
      $subscription = notifications_subscription_load($id);
      $form['items'][$id] = array(
        '#type' => 'hidden',
        '#value' => $id,
        '#prefix' => '<li>',
        '#suffix' => $subscription
          ->format_long() . "</li>\n",
      );
    }
    $form['operation'] = array(
      '#type' => 'hidden',
      '#value' => 'delete',
    );
    $form['#submit'][] = 'notifications_multiple_delete_confirm_submit';
    $form['#validate'][] = 'notifications_multiple_delete_confirm_validate';
    $form['#redirect'] = $destination;
    return confirm_form($form, t('Are you sure you want to delete these items?'), $destination, t('This action cannot be undone.'), t('Delete all'), t('Cancel'));
  }
  else {
    drupal_set_message(t('Validation error. You don\'t have permission to delete some of these subscriptions'), 'error');
    drupal_access_denied();
  }
}