/**
   * AJAX entry point for to configure vsibility rule.
   */
  function ajax_access_configure_test($pid = NULL, $id = NULL) {
    if (empty($this->display->content[$pid])) {
      ctools_modal_render(t('Error'), t('Invalid pane id.'));
    }

    $pane = &$this->display->content[$pid];
    $subtype = ctools_content_get_subtype($pane->type, $pane->subtype);

    // Set this up here because $id gets changed later.
    $url = $this->get_url('access-configure-test', $pid, $id);

    // If we're adding a new one, get the stored data from cache and
    // add it. It's stored as a cache so that if this is closed
    // we don't accidentally add an unconfigured plugin.
    if ($id == 'add') {
      $pane->access['plugins'][] = $this->cache->new_plugin;
      $id = max(array_keys($pane->access['plugins']));
    }
    else if (empty($pane->access['plugins'][$id])) {
      ctools_modal_render(t('Error'), t('Invalid test id.'));
    }

    $form_state = array(
      'display' => &$this->display,
      'pane' => &$pane,
      'ajax' => TRUE,
      'title' => t('Configure visibility rule for !subtype_title', array('!subtype_title' => $subtype['title'])),
      'test' => &$pane->access['plugins'][$id],
      'plugin' => ctools_get_access_plugin($pane->access['plugins'][$id]['name']),
      'url' => url($url, array('absolute' => TRUE)),
    );

    $output = ctools_modal_form_wrapper('panels_edit_configure_access_test_form', $form_state);
    if (empty($form_state['executed'])) {
      $this->commands = $output;
      return;
    }

    // Unset the new plugin
    if (isset($this->cache->new_plugin)) {
      unset($this->cache->new_plugin);
    }

    if (!empty($form_state['remove'])) {
      unset($pane->access['plugins'][$id]);
    }

    panels_edit_cache_set($this->cache);
    $this->command_update_pane($pid);
    $this->commands[] = ctools_modal_command_dismiss();
  }
 public function getFormDialog($js, $q)
 {
     $this->useJS = $js;
     $this->questionId = $q;
     if (!$this->useJS()) {
         return drupal_get_form('chgk_db_edit_question_form');
     }
     $modal_style = array('chgkdb_modal' => array('modalOptions' => array('opacity' => 0.5, 'background-color' => '#000'), 'animation' => 'fadeIn', 'modalTheme' => 'CToolsChgkDbModal'));
     drupal_add_js($modal_style, 'setting');
     $form_state = array('title' => 'Редактирование вопроса', 'ajax' => $js, 'question_id' => $this->getQuestionId(), 'question' => &$q);
     $commands = ctools_modal_form_wrapper('chgk_db_edit_question_form', $form_state);
     if (!empty($form_state['executed'])) {
         $commands = array();
         $commands[] = ctools_modal_command_display(t("Sending form"), "Сохраняем...");
         $commands[] = ctools_ajax_command_reload();
     }
     print ctools_ajax_render($commands);
     exit;
 }