function detection_action()
 {
     $detect_system_searchd = $this->detect_program('searchd');
     $detect_system_indexer = $this->detect_program('indexer');
     $detect_installed_searchd = $this->_config->get_option('sphinx_searchd');
     $detect_installed_indexer = $this->_config->get_option('sphinx_indexer');
     if (!file_exists($detect_installed_searchd)) {
         $detect_installed_searchd = '';
     }
     if (!file_exists($detect_installed_indexer)) {
         $detect_installed_indexer = '';
     }
     $this->view->detect_system_searchd = $detect_system_searchd;
     $this->view->detect_system_indexer = $detect_system_indexer;
     $this->view->detect_installed_searchd = $detect_installed_searchd;
     $this->view->detect_installed_indexer = $detect_installed_indexer;
     $this->view->install_path = SPHINXSEARCH_SPHINX_INSTALL_DIR;
     if (!empty($_POST['skip_wizard_detection'])) {
         if (empty($detect_installed_searchd) || empty($detect_installed_indexer)) {
             $this->view->success_message = 'Sphinx is not installed. All step was skipped.';
             return $this->_next_action('config');
             exit;
         } else {
             $this->view->success_message = 'Step was skipped.';
             return $this->_next_action('detection');
         }
     }
     if (!empty($_POST['detection_process'])) {
         if ('install' == $_POST['detected_install']) {
             $sphinxService = new SphinxService($this->_config);
             $sphinxService->stop();
             $sphinxInstall = new SphinxSearch_Install($this->_config);
             $res = $sphinxInstall->install();
             if (true === $res) {
                 $this->view->success_message = 'Sphinx successfully installed.';
                 return $this->_next_action('install');
             } else {
                 $this->view->error_message = $res['err'];
                 $this->view->render('admin/wizard/sphinx_detect.phtml');
                 exit;
             }
         } else {
             if ('detect_system' == $_POST['detected_install']) {
                 if (empty($_POST['detected_system_searchd']) || empty($_POST['detected_system_indexer'])) {
                     $this->view->error_message = 'Path to searchd or indexer can\'t be empty';
                     $this->view->render('admin/wizard/sphinx_detect.phtml');
                     exit;
                 } else {
                     $this->_set_sphinx_detected($_POST['detected_system_searchd'], $_POST['detected_system_indexer']);
                     $this->view->success_message = 'Sphinx binaries are set.';
                     return $this->_next_action('detection');
                 }
             } else {
                 if ('detect_installed' == $_POST['detected_install']) {
                     if (empty($_POST['detected_installed_searchd']) || empty($_POST['detected_installed_indexer'])) {
                         $this->view->error_message = 'Path to searchd or indexer can\'t be empty';
                         $this->view->render('admin/wizard/sphinx_detect.phtml');
                         exit;
                     } else {
                         $this->_set_sphinx_detected($_POST['detected_installed_searchd'], $_POST['detected_installed_indexer']);
                         $this->view->success_message = 'Sphinx binaries are set.';
                         return $this->_next_action('detection');
                     }
                 }
             }
         }
     }
     $this->view->render('admin/wizard/sphinx_detect.phtml');
     exit;
 }
 /**
  * Draw admin page
  *
  */
 function print_admin_page()
 {
     if (!current_user_can('manage_options')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $options = $this->config->get_admin_options();
     $wizard = new WizardController($this->config);
     if (!empty($_POST['start_wizard']) || empty($options['sphinx_conf']) && 'false' == $options['wizard_done']) {
         $this->view->menu = 'wizard';
         $wizard->start_action();
     }
     if (!empty($_GET['menu'])) {
         switch ($_GET['menu']) {
             case 'terms_editor':
                 $terms_editor = new TermsEditorController($this->config);
                 $terms_editor->index_action();
                 $this->view->menu = 'terms_editor';
                 //return;
                 break;
             case 'stats':
                 $stats = new StatsController($this->config);
                 $stats->index_action();
                 $this->view->menu = 'stats';
                 //return;
                 break;
             case 'search_settings':
                 $this->view->menu = 'search_settings';
                 break;
         }
     }
     $sphinxService = new SphinxService($this->config);
     $res = false;
     $error_message = $success_message = '';
     if (!empty($_POST['reindex_sphinx'])) {
         $res = $sphinxService->reindex();
         $success_message = 'Sphinx successfully reindexed.';
     } else {
         if (!empty($_POST['start_sphinx'])) {
             $res = $sphinxService->start();
             $success_message = 'Sphinx successfully started.';
         } elseif (!empty($_POST['stop_sphinx'])) {
             $res = $sphinxService->stop();
             $success_message = 'Sphinx successfully stopped.';
         } elseif (isset($_POST['update_SphinxSearchSettings'])) {
             $this->update_options();
             $success_message = 'Settings updated.';
         }
     }
     if (is_array($res)) {
         $error_message = $res['err'];
     }
     $this->view->assign('index_modify_time', $sphinxService->get_index_modify_time());
     if (!empty($error_message)) {
         $this->view->assign('error_message', $error_message);
     }
     if (!empty($success_message)) {
         $this->view->assign('success_message', $success_message);
     }
     $devOptions = $this->config->get_admin_options();
     //update options
     $this->view->assign('devOptions', $devOptions);
     //load admin panel template
     $this->view->assign('header', 'Sphinx Search for Wordpress');
     $this->view->assign('is_sphinx_path_secure', $this->_isSphinxPathSecure());
     if ('true' != $devOptions['check_stats_table_column_status']) {
         global $table_prefix;
         $this->view->assign('error_message', "{$table_prefix}sph_stats table required an update.<br>\n            Please run the following command in MySQL client to update the table: <br>\n            alter table {$table_prefix}sph_stats add `status` tinyint(1) NOT NULL DEFAULT '0';\n            <br><br>\n            This update will allow to use Sphinx Search for Top/Related and Latest search terms widgets!");
     }
     $this->view->render('admin/layout.phtml');
 }