You are here

function flag_lists_ops_form_submit in Flag Lists 7

Same name and namespace in other branches
  1. 7.3 flag_lists.module \flag_lists_ops_form_submit()
1 call to flag_lists_ops_form_submit()
flag_lists_ops_form_ajax_callback in ./flag_lists.module
1 string reference to 'flag_lists_ops_form_submit'
flag_lists_form_alter in ./flag_lists.module
Implementation of hook_form_alter().

File

./flag_lists.module, line 534
The Flag Lists module.

Code

function flag_lists_ops_form_submit(&$form, &$form_state) {

  // Get the $ops from the originating form.
  $ops = $_REQUEST['flag_lists_ops'];
  $success_count = 0;

  // Get the operation, or set it
  switch ($form_state['values']['flag_lists_' . $form_state['flo_operation']]['operation']) {
    case 'unflag':
      $operation = 'unflag';
      $message = 'removed from';
      foreach ($ops as $op) {

        // Process the ID into 2 parts
        list($nid, $fid) = explode('-', $op);
        if (empty($nid) || empty($fid)) {
          return;
        }
        if (($flag = flag_lists_get_flag($fid)) && ($node = node_load($nid))) {
          if (flag_lists_do_flag($flag, $operation, $nid)) {
            $success_count++;
          }
        }
      }
      break;
    default:
      $operation = 'flag';
      $message = 'added to';
      if ($flag = flag_lists_get_flag($form_state['values']['flag_lists_' . $form_state['flo_operation']]['list'])) {
        foreach ($ops as $nid) {
          if (flag_lists_do_flag($flag, $operation, $nid)) {
            $success_count++;
          }
        }
      }
      break;
  }
  $message = t('@count item(s) ' . $message . ' !title', array(
    '@count' => $success_count,
    '!title' => $flag->title,
  ));
  if ($_GET['q'] != 'system/ajax') {
    drupal_set_message($message);
  }
  else {
    return $message;
  }
}