/**
  * main entry point for the install wizard
  * input parameters for wizard are in the $_GET buffer
  * @param type $Sender
  */
 public function Controller_InstallWizard($Sender)
 {
     include_once PATH_PLUGINS . DS . 'SphinxSearchLite' . DS . 'class.sphinxsearchinstallwizard.php';
     //include the install wizard
     $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
     //SaveToConfig('Plugin.SphinxSearchLite.SearchdPath', '/usr/bin/sphinx-searchd');
     $Sender->SetData('PluginDescription', $this->GetPluginKey('Description'));
     $Sender->SetData('PluginVersion', $this->GetPluginKey('Version'));
     //create validation
     $Validation = new Gdn_Validation();
     $this->ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $this->ConfigurationModel->SetField(array());
     $Sender->Form->SetModel($this->ConfigurationModel);
     //set model on form
     $Sender->SetData('NextAction', 'Detection');
     $Sender->SetData('InstallSphinx', FALSE);
     $Sender->Form->SetData($this->ConfigurationModel->Data);
     $Sender->Form->InputPrefix = 'Configuration';
     //print_r($_POST); die;
     //Wizard State Machine (SM)
     if (GetIncomingValue('NextAction')) {
         SaveToConfig('Plugin.SphinxSearchLite.Config', TRUE);
         //next action
         $Sender->SetData('NextAction', 'Config');
     }
     if (GetIncomingValue('action') == 'ToggleWizard') {
         if (Gdn::Session()->ValidateTransientKey(GetValue(1, $Sender->RequestArgs))) {
             $SphinxAdmin->ToggleWizard();
             //stop/start wizard
             redirect('plugin/sphinxsearchlite/installwizard');
             //load the wizard page again
         }
     } else {
         if (isset($_POST[$this->PostPrefix . 'NextAction'])) {
             $Background = GetIncomingValue($this->PostPrefix . 'Background');
             switch ($_POST[$this->PostPrefix . 'NextAction']) {
                 case 'Detection':
                     $Sender->SetData('NextAction', 'Detection');
                     //in case it fails
                     // Don't detect anymore
                     // $SphinxAdmin->Detect();
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Prefix', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Port', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Host', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Port', 'Integer');
                     //PORT must be an int
                     if ($Sender->Form->Save()) {
                         //@todo don't check port just yet
                         $Sender->StatusMessage = T("Your changes have been saved.");
                         SaveToConfig('Plugin.SphinxSearchLite.Connection', TRUE);
                         //complete this step
                         $Sender->SetData('NextAction', 'Install');
                         //next step
                     } else {
                         SaveToConfig('Plugin.SphinxSearchLite.Connection', FALSE);
                     }
                     //don't continue
                     break;
                 case 'Install':
                     //Install Sphinx
                     $Sender->SetData('NextAction', 'Install');
                     //in case it fails
                     $InstallAction = GetValue($this->PostPrefix . 'Plugin-dot-SphinxSearch-dot-Detected', $_POST);
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.SearchdPath', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.IndexerPath', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.ConfPath', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.ConfText', 'Required');
                     if ($Sender->Form->Save()) {
                         //refresh settings after save by getting new instance @todo pretty janky
                         $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
                         //check if running in background - if so, requrie that these files are writable for poller
                         $SphinxAdmin->InstallAction($InstallAction, $Background);
                         //install if using package sphinx, if using manual, verify that paths exist and read info from sphinx.conf
                         //manual install requires no polling...simply check if files exist and if sphinx.conf has info we need and move one
                         SaveToConfig('Plugin.SphinxSearchLite.Config', TRUE);
                         //next step
                         $Sender->SetData('NextAction', 'Config');
                         //next step
                         $Sender->StatusMessage = T("Your changes have been saved.");
                     } else {
                         //return FALSE;
                     }
                     break;
                 case 'Config':
                     $SphinxAdmin->InstallConfig();
                     $Sender->SetData('NextAction', 'Finish');
                     SaveToConfig('Plugin.SphinxSearchLite.Installed', TRUE);
                     //complete this step
                     break;
                 default:
                     break;
             }
         }
     }
     if ($this->Settings['Wizard']->Config == TRUE) {
         $Sender->SetData('NextAction', 'Config');
     }
     //get new settings that may have changed
     $Settings = SphinxFactory::BuildSettings();
     $Sender->SetData('Settings', $Settings->GetAllSettings());
     $Sender->Render($this->GetView('wizard.php'));
     //render wizard view
 }
 /**
  * main entry point for the install wizard
  * input parameters for wizard are in the $_GET buffer
  * @param type $Sender
  */
 public function Controller_InstallWizard($Sender)
 {
     include_once PATH_PLUGINS . DS . 'SphinxSearch' . DS . 'class.sphinxsearchinstallwizard.php';
     //include the install wizard
     $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
     //SaveToConfig('Plugin.SphinxSearch.SearchdPath', '/usr/bin/sphinx-searchd');
     $Sender->SetData('PluginDescription', $this->GetPluginKey('Description'));
     $Sender->SetData('PluginVersion', $this->GetPluginKey('Version'));
     //create validation
     $Validation = new Gdn_Validation();
     $this->ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $this->ConfigurationModel->SetField(array());
     $Sender->Form->SetModel($this->ConfigurationModel);
     //set model on form
     $Sender->SetData('NextAction', 'Detection');
     $Sender->SetData('InstallSphinx', FALSE);
     $Sender->Form->SetData($this->ConfigurationModel->Data);
     $Sender->Form->InputPrefix = 'Configuration';
     //Wizard State Machine (SM)
     if (GetIncomingValue('action') == 'ToggleWizard') {
         // The validation transient keys don't work in 2.1b for some reason
         // if (Gdn::Session()->ValidateTransientKey(GetValue(1, $Sender->RequestArgs))) {
         if (true) {
             $SphinxAdmin->ToggleWizard();
             //stop/start wizard
             redirect('plugin/sphinxsearch/installwizard');
             //load the wizard page again
         }
     } else {
         if (isset($_POST[$this->PostPrefix . 'NextAction'])) {
             $Background = GetIncomingValue($this->PostPrefix . 'Background');
             switch ($_POST[$this->PostPrefix . 'NextAction']) {
                 case 'Detection':
                     $Sender->SetData('NextAction', 'Detection');
                     //in case it fails
                     $SphinxAdmin->Detect();
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Prefix', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Port', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Host', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Port', 'Integer');
                     //PORT must be an int
                     $Sender->Form->Save();
                     if (!$Sender->Form->Errors()) {
                         //@todo don't check port just yet
                         $Sender->StatusMessage = T("Your changes have been saved.");
                         SaveToConfig('Plugin.SphinxSearch.Connection', TRUE);
                         //complete this step
                         $Sender->SetData('NextAction', 'Install');
                         //next step
                     } else {
                         SaveToConfig('Plugin.SphinxSearch.Connection', FALSE);
                     }
                     //don't continue
                     break;
                 case 'Install':
                     //Install Sphinx
                     $Sender->SetData('NextAction', 'Install');
                     //in case it fails
                     $InstallAction = GetValue($this->PostPrefix . 'Plugin-dot-SphinxSearch-dot-Detected', $_POST);
                     /*
                      *  The paths are no longer required inputs since only the creation of the cron files require it!
                      */
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.ConfText', 'Required');
                     // This is the only input required!
                     $Sender->Form->Save();
                     if (!$Sender->Form->Errors()) {
                         //refresh settings after save by getting new instance @todo pretty janky
                         $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
                         $SphinxAdmin->InstallAction($InstallAction, $Background);
                         //Read info from the pasted sphinx.conf
                         //refresh settings (PID/log/query/ path) after save by getting new instance @todo pretty janky
                         $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
                         $SphinxAdmin->InstallConfig();
                         // Write the new sphinx.conf file
                         SaveToConfig('Plugin.SphinxSearch.Config', TRUE);
                         //next step
                         $Sender->SetData('NextAction', 'Config');
                         //next step is Cron Config
                         // Sphinx is technically all set. Cron file generation is optional
                         $Sender->StatusMessage = T("Your changes have been saved.");
                     } else {
                         //return FALSE;
                     }
                     break;
                 case 'Config':
                     // AKA cron setup
                     $Sender->SetData('NextAction', 'Config');
                     //in case it fails
                     $this->ConfigurationModel->Validation->AddValidationField('Plugin.SphinxSearch.IndexerPath', $_POST);
                     $this->ConfigurationModel->Validation->AddValidationField('Plugin.SphinxSearch.ConfPath', $_POST);
                     $Sender->Form->Save();
                     if (!$Sender->Form->Errors()) {
                         $SphinxAdmin->InstallCron();
                         SaveToConfig('Plugin.SphinxSearch.Installed', TRUE);
                         // Sphinx is technically all set. Cron file generation is optional
                         $Sender->SetData('NextAction', 'Finish');
                         //complete this step
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     //get new settings that may have changed
     $Settings = SphinxFactory::BuildSettings();
     $Sender->SetData('Settings', $Settings->GetAllSettings());
     $Sender->Render($this->GetView('wizard.php'));
     //render wizard view
 }