2c2
< // $Id: views_bulk_operations.module,v 1.17 2007/09/09 20:31:42 hlslaughter Exp $
---
> // $Id: views_bulk_operations.module,v 1.14 2007/08/23 23:53:36 kratib Exp $
13d12
< define('VIEWS_BULK_OPS_STEP_ALL', 5);
79a79
>   $form['#multistep'] = TRUE;
90,105d89
<   if (count($all_operations) > 1) {
<     $form['#multistep'] = TRUE;
<     // Calculate next step. Take into consideration whether the action is configurable or not.
<     $step = isset($form_values) ? (int) $form_values['step'] + 1: VIEWS_BULK_OPS_STEP_VIEW;
<     if ($step == VIEWS_BULK_OPS_STEP_CONFIG) {
<       $action = $form_values['action'];
<       if (!isset($all_operations[$action]) || !$all_operations[$action]['configurable']) {
<         $step = VIEWS_BULK_OPS_STEP_CONFIRM;
<       }
<     }
<   } else {
<     $form['#multistep'] = FALSE; 
<     $form['#redirect'] = FALSE;	
<     $form['#after_build'] = array('views_bulk_operations_form_preview');
<     $step = VIEWS_BULK_OPS_STEP_ALL;
<   }  
106a91,98
>   // Calculate next step. Take into consideration whether the action is configurable or not.
>   $step = isset($form_values) ? (int) $form_values['step'] + 1: VIEWS_BULK_OPS_STEP_VIEW;
>   if ($step == VIEWS_BULK_OPS_STEP_CONFIG) {
>     $action = $form_values['action'];
>     if (!isset($all_operations[$action]) || !$all_operations[$action]['configurable']) {
>       $step = VIEWS_BULK_OPS_STEP_CONFIRM;
>     }
>   }
112,158d103
<   case VIEWS_BULK_OPS_STEP_ALL: // All in one  
< 	if ($step == VIEWS_BULK_OPS_STEP_VIEW) {  
<       $options[0] = t('- Choose an operation -');
<       foreach ($all_operations as $operation => $values) {
<         $options[$operation] = $values['label'];
<       }
<       $form['select'] = array(
<         '#type' => 'fieldset',
<         '#title' => t('Bulk operations'),
<         //'#description' => t('Please select the operation to perform on the selected nodes.'),
<         '#options' => $options,
<         '#prefix' => '<div id="views-bulk-operations-select">',
<         '#suffix' => '</div>',
<       );
<       $form['select']['action'] = array(
<         '#type' => 'select',
<         '#title' => '',
<         //'#description' => t('Please select the operation to perform on the selected nodes.'),
<         '#options' => $options,
<         '#prefix' => '<div id="views-bulk-operations-dropdown">',
<         '#suffix' => '</div>',
<       );
<       $form['select']['submit'] = array(
<         '#type' => 'submit',
<         '#value' => t('Execute'),
<         '#prefix' => '<div id="views-bulk-operations-submit">',
<         '#suffix' => '</div>',
<       );
<  	} else if ($step == VIEWS_BULK_OPS_STEP_ALL) {
<  	  $keys   = array_keys($all_operations);
<        $action = $keys[0];
<        $form['action'] = array(
<          '#type' => 'hidden',
<          '#value' => $action,
<        );	  
<        $form_action = call_user_func($action, 'form', array(), array());
<        $form = array_merge($form, $form_action);
<        $form['preview'] = array(
<          '#prefix' => '<br />',
<          '#type' => 'submit',
<          '#value' => t('Preview'),
<        );
<        $form['submit'] = array(
<          '#type' => 'submit',
<          '#value' => $all_operations[$action]['label'],
<        );	  
<  	}
160c105
<       $form['select']['configure'] = array(
---
>       $form['configure'] = array(
163c108
<         '#prefix' => '<div id="views-bulk-operations-admin">',
---
>         '#prefix' => '<div id="allowed_operations_link">',
166a112,127
>     $options[0] = t('- Choose an action -');
>     foreach ($all_operations as $operation => $values) {
>       $options[$operation] = $values['label'];
>     }
>     $form['action'] = array(
>       '#type' => 'select',
>       '#title' => '',
>       '#description' => t('Please select the action to perform on the selected nodes.'),
>       '#options' => $options,
>       '#prefix' => '<div id="views_bulk_operations_action">',
>       '#suffix' => '</div>',
>     );
>     $form['submit'] = array(
>       '#type' => 'submit',
>       '#value' => t('Execute'),
>     );
170,171c131
<       '#view' => $view,
<       '#view_nodes' => $nodes,
---
>       '#view' => $view->name,
173,174c133,134
< 	  '#weight'   => 10,	  
<       '#prefix' => '<div class="views-node-selector">',
---
>       '#embedded' => TRUE,
>       '#prefix' => '<div class="views_node_selector">',
242c202
<         theme('views_bulk_operations_confirmation', $selected));
---
>         theme('views_bulk_operations_confirmation', $selected['selected']));
248,276d207
< function views_bulk_operations_form_preview($form) {
<   global $form_values;
< 
<   $op = isset($form_values['op']) ? $form_values['op'] : '';
<   if ($op == t('Preview')) {
<     // Invoke full validation for the form, to protect against cross site
<     // request forgeries (CSRF) and setting arbitrary values for fields such as
<     // the input format. Preview the node only when form validation does not
<     // set any errors.
<     drupal_validate_form($form['form_id']['#value'], $form);
<     if (!form_get_errors()) {
<       // Preview the values here
< 	  $form['fs_preview'] = array(
<         '#type'   => 'fieldset',
< 		'#attributes' => array('class' => 'preview'),
<         '#tree'   => true,
< 	    '#weight' => -5,
< 	    '#collapsible' => false,
< 	  );
<       $elements = module_invoke_all('views_bulk_operations_preview', $form_values['nodes']['selected']);
< 	  $form['fs_preview'] = array_merge($form['fs_preview'], $elements);	  
< 	}
<   }
<   if (form_get_errors() || $op != t('Preview')) {
<     unset($form['submit']);
<   }	  
<   return $form;
< }
< 
290,303c221,227
<   switch ($form_values['step']) {
<     case VIEWS_BULK_OPS_STEP_VIEW:
<       if (!array_sum($form_values['nodes'])) { // If all 0, no node selected
<         form_set_error('nodes', t('No nodes selected. Please select one or more nodes.'));
<       }
<       if (!$form_values['action']) { // No action selected
<         form_set_error('action', t('No action selected. Please select an action to perform.'));
<       }	  
< 	  break;
< 	case VIEWS_BULK_OPS_STEP_ALL:
<       if (!array_sum($form_values['nodes']['selected'])) { // If all 0, no node selected
<         form_set_error('nodes', t('No nodes selected. Please select one or more nodes.'));
<       }	
< 	  break;
---
>   if ($form_values['step'] == VIEWS_BULK_OPS_STEP_VIEW) {
>     if (!array_sum($form_values['nodes']['selected'])) { // If all 0, no node selected
>       form_set_error('nodes', t('No nodes selected. Please select one or more nodes.'));
>     }
>     if (!$form_values['action']) { // No action selected
>       form_set_error('action', t('No action selected. Please select an action to perform.'));
>     }
308,323c232,235
<   switch ($form_values['step']) {
<     case VIEWS_BULK_OPS_STEP_CONFIRM:
<       $nodes = unserialize($form_values['nodes']);
<   	  break;
<     case VIEWS_BULK_OPS_STEP_ALL:  
<       $op = isset($form_values['op']) ? $form_values['op'] : '';
<       if ($op == t('Preview')) {
< 	    return;
< 	  }
< 	  $nodes = $form_values['nodes'];
<       break;	
< 	default:
< 	  return;
<   }
<   
<   if (!is_array($nodes)) return;
---
>   if ($form_values['step'] < VIEWS_BULK_OPS_STEP_CONFIRM) return;
> 
>   $nodes = unserialize($form_values['nodes']);
>   if (!is_array($nodes['selected'])) return;
333c245
<       $nodes = array_filter($nodes);
---
>       $nodes = array_filter($nodes['selected']);
340a253
>       drupal_set_message(t('Executed node operation %action on nodes %nids.', array('%action' => $operations[$action]['label'], '%nids' => implode($nodes, ', '))));
344c257
<       foreach ($nodes as $value) {
---
>       foreach ($nodes['selected'] as $value) {
346,348c259,260
<           $node = node_load($value);
<           call_user_func($action, 'do', $form_values, $node);
<           //drupal_set_message(t('Performed %action on node %nid.', array('%action' => $operations[$action]['label'], '%nid' => $node->title)));
---
>           call_user_func($action, 'do', $form_values, node_load($value));
>           drupal_set_message(t('Executed action %action on node %nid.', array('%action' => $operations[$action]['label'], '%nid' => $value)));
351d262
< 	  call_user_func($action, 'done', $form_values, NULL);
392c303
< 
---
>   
414c325
< 
---
>   
446c357
< 
---
>   
479c390
<   return str_replace(array('$RCSf'.'ile:', ',v', '$Re'.'vision: ', '$Da'.'te: ', '$'), '', '<p style="font-size:x-small">$RCSfile: views_bulk_operations.module,v $ version: <b>$Revision: 1.17 $</b>, $Date: 2007/09/09 20:31:42 $</p>');
---
>   return str_replace(array('$RCSf'.'ile:', ',v', '$Re'.'vision: ', '$Da'.'te: ', '$'), '', '<p style="font-size:x-small">$RCSfile: views_bulk_operations.module,v $ version: <b>$Revision: 1.14 $</b>, $Date: 2007/08/23 23:53:36 $</p>');
654c565
<       'label' => t('Delete'),
---
>       'label' => t('Delete node'),
765,768d675
< 	  if (arg(0) != 'admin') {
< 		$return_operations = $stored_operations;
< 	    break;
< 	  }	
852a760
> 
