function ajax_set_layout($layout)
 {
     ctools_include('context');
     ctools_include('display-layout', 'panels');
     $form_state = array('layout' => $layout, 'display' => $this->display, 'finish' => t('Save'), 'no_redirect' => TRUE);
     // Reset the $_POST['ajax_html_ids'] values to preserve
     // proper IDs on form elements when they are rebuilt
     // by the Panels IPE without refreshing the page
     $_POST['ajax_html_ids'] = array();
     $output = drupal_build_form('panels_change_layout', $form_state);
     $output = drupal_render($output);
     if (!empty($form_state['executed'])) {
         if (isset($form_state['back'])) {
             return $this->ajax_change_layout();
         }
         if (!empty($form_state['clicked_button']['#save-display'])) {
             // Saved. Save the cache.
             panels_edit_cache_save($this->cache);
             $this->display->skip_cache;
             // Since the layout changed, we have to update these things in the
             // renderer in order to get the right settings.
             $layout = panels_get_layout($this->display->layout);
             $this->plugins['layout'] = $layout;
             if (!isset($layout['regions'])) {
                 $this->plugins['layout']['regions'] = panels_get_regions($layout, $this->display);
             }
             $this->meta_location = 'inline';
             $this->commands[] = ajax_command_replace("#panels-ipe-display-{$this->clean_key}", panels_render_display($this->display, $this));
             $this->commands[] = ctools_modal_command_dismiss();
             return;
         }
     }
     $this->commands[] = ctools_modal_command_display(t('Change layout'), $output);
 }
 /**
  * AJAX entry point to create the controller form for an IPE.
  */
 function ajax_save_form($break = NULL)
 {
     ctools_include('form');
     if (!empty($this->cache->locked)) {
         if ($break != 'break') {
             $account = user_load($this->cache->locked->uid);
             $name = theme('username', $account);
             $lock_age = format_interval(time() - $this->cache->locked->updated);
             $message = t("This panel is being edited by user !user, and is therefore locked from editing by others. This lock is !age old.\n\nClick OK to break this lock and discard any changes made by !user.", array('!user' => $name, '!age' => $lock_age));
             $this->commands[] = array('command' => 'unlockIPE', 'message' => $message, 'break_path' => url($this->get_url('save-form', 'break')));
             return;
         }
         // Break the lock.
         panels_edit_cache_break_lock($this->cache);
     }
     $form_state = array('display' => &$this->display, 'content_types' => $this->cache->content_types, 'rerender' => FALSE, 'no_redirect' => TRUE, 'layout' => $this->plugins['layout']);
     $output = ctools_build_form('panels_ipe_edit_control_form', $form_state);
     if ($output) {
         // At this point, we want to save the cache to ensure that we have a lock.
         panels_edit_cache_set($this->cache);
         $this->commands[] = array('command' => 'initIPE', 'key' => $this->clean_key, 'data' => $output);
         return;
     }
     // no output == submit
     if (!empty($form_state['clicked_button']['#save-display'])) {
         // Saved. Save the cache.
         panels_edit_cache_save($this->cache);
     } else {
         // Cancelled. Clear the cache.
         panels_edit_cache_clear($this->cache);
     }
     $this->commands[] = array('command' => 'endIPE', 'key' => $this->clean_key, 'data' => $output);
 }