You are here

function quickbar_help_configure_form_submit in Quickbar 7.2

Submission handler for quickbar_help_form_alter().

1 string reference to 'quickbar_help_configure_form_submit'
quickbar_help_form_alter in modules/quickbar_help/quickbar_help.module
Implements hook_form_alter().

File

modules/quickbar_help/quickbar_help.module, line 98

Code

function quickbar_help_configure_form_submit(&$form, &$form_state) {
  $rid = $form_state['build_info']['args'][0];
  $result = db_query("SELECT path FROM {quickbar_help} WHERE rid = :rid", array(
    ':rid' => $rid,
  ));
  $current_paths = array();
  while ($record = $result
    ->fetchField()) {
    $current_paths[] = $record;
  }
  foreach ($form_state['values']['help'] as $path => $help) {
    $text = $help['text']['value'];
    $format = $help['text']['format'];

    // If we need to update the db record since this path is already in the db...
    if (in_array($path, $current_paths)) {
      if ($text != '') {
        db_update('quickbar_help')
          ->fields(array(
          'text' => $text,
          'format' => $format,
        ))
          ->condition('path', $path)
          ->condition('rid', $rid)
          ->execute();
      }
      else {
        db_delete('quickbar_help')
          ->condition('path', $path)
          ->condition('rid', $rid)
          ->execute();
      }
    }
    else {

      // We don't want to add a blank entry
      if ($text != '') {
        db_insert('quickbar_help')
          ->fields(array(
          'rid' => $rid,
          'text' => $text,
          'path' => $path,
          'format' => 0,
          'format' => $format,
        ))
          ->execute();
      }
    }
  }
}