You are here

function jquery_countdown_block_add_block_form_submit in jQuery Countdown 6

Form submission handler for jquery_countdown_block_add_block_form().

File

jquery_countdown_block/jquery_countdown_block.module, line 61
Provides configurable blocks of countdown timers.

Code

function jquery_countdown_block_add_block_form_submit($form, &$form_state) {

  // Determine the delta of the new block.
  $block_ids = variable_get('jquery_countdown_block_ids', array());
  $delta = empty($block_ids) ? 1 : max($block_ids) + 1;

  // Save the new array of blocks IDs.
  $block_ids[] = $delta;
  variable_set('jquery_countdown_block_ids', $block_ids);

  // Save the block configuration.
  _jquery_countdown_block_block_save($delta, $form_state['values']);

  // Run the normal new block submission (borrowed from block_add_block_form_submit).
  foreach (list_themes() as $key => $theme) {
    if ($theme->status) {
      db_query("INSERT INTO {blocks} (visibility, pages, custom, title, module, theme, status, weight, delta, cache) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, %d, %d)", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $theme->name, 0, 0, $delta, BLOCK_CACHE_GLOBAL);
    }
  }
  foreach (array_filter($form_state['values']['roles']) as $rid) {
    db_query("INSERT INTO {blocks_roles} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
  }
  drupal_set_message(t('The block has been created.'));
  cache_clear_all();
  $form_state['redirect'] = 'admin/build/block';
  return;
}