$_REQUEST['id'],
':token' => drupal_get_token($_REQUEST['id']))
)->fetchField();
$batch = unserialize($batch);
// Register database update for end of processing.
register_shutdown_function('_batch_shutdown');
// Add batch-specific css.
foreach ($batch['sets'] as $batch_set) {
foreach ($batch_set['css'] as $css) {
drupal_add_css($css);
}
}
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
$output = NULL;
switch ($op) {
case 'start':
$output = _batch_start();
break;
case 'do':
// JS-version AJAX callback.
_batch_do();
break;
case 'do_nojs':
// Non-JS progress page.
$output = _batch_progress_page_nojs();
break;
case 'finished':
$output = _batch_finished();
break;
}
return $output;
}
/**
* Initiate the batch processing
*/
function _batch_start() {
// Choose between the JS and non-JS version.
// JS-enabled users are identified through the 'has_js' cookie set in drupal.js.
// If the user did not visit any JS enabled page during his browser session,
// he gets the non-JS version...
if (isset($_COOKIE['has_js']) && $_COOKIE['has_js']) {
return _batch_progress_page_js();
}
else {
return _batch_progress_page_nojs();
}
}
/**
* Batch processing page with JavaScript support.
*/
function _batch_progress_page_js() {
$batch = batch_get();
// The first batch set gets to set the page title and the initialization and
// error messages. Only safe strings should be passed in to batch_set().
$current_set = _batch_current_set();
drupal_set_title($current_set['title'], PASS_THROUGH);
drupal_add_js('misc/progress.js', array('cache' => FALSE));
$url = url($batch['url'], array('query' => array('id' => $batch['id'])));
$js_setting = array(
'batch' => array(
'errorMessage' => $current_set['error_message'] . '
' . $batch['error_message'],
'initMessage' => $current_set['init_message'],
'uri' => $url,
),
);
drupal_add_js($js_setting, 'setting');
drupal_add_js('misc/batch.js', array('cache' => FALSE));
$output = '