index = $index; } /** * Index * * @return void */ public function indexAction() { if (isset($_REQUEST['do_save_data'])) { $this->doSaveDataAction(); return; } // end builds the new index $this->displayFormAction(); } /** * Display the form to edit/create an index * * @return void */ public function displayFormAction() { $GLOBALS['dbi']->selectDb($GLOBALS['db']); $table_class_object = $GLOBALS['dbi']->getTable( $GLOBALS['db'], $GLOBALS['table'] ); $GLOBALS['showtable'] = $table_class_object->getStatusInfo(null, true); if ($table_class_object->isView()) { $tbl_is_view = true; $tbl_storage_engine = __('View'); $show_comment = null; } else { $tbl_is_view = false; $tbl_storage_engine = $table_class_object->getStorageEngine(); $show_comment = $table_class_object->getComment(); } $tbl_collation = $table_class_object->getCollation(); $table_info_num_rows = $table_class_object->getNumRows(); $row_format = $table_class_object->getRowFormat(); $auto_increment = $table_class_object->getAutoIncrement(); $create_options = $table_class_object->getCreateOptions(); $add_fields = 0; if (isset($_REQUEST['index']) && is_array($_REQUEST['index'])) { // coming already from form if (isset($_REQUEST['index']['columns']['names'])) { $add_fields = count($_REQUEST['index']['columns']['names']) - $this->index->getColumnCount(); } if (isset($_REQUEST['add_fields'])) { $add_fields += $_REQUEST['added_fields']; } } elseif (isset($_REQUEST['create_index'])) { $add_fields = $_REQUEST['added_fields']; } // end preparing form values // Get fields and stores their name/type if (isset($_REQUEST['create_edit_table'])) { $fields = json_decode($_REQUEST['columns'], true); $index_params = array( 'Non_unique' => ($_REQUEST['index']['Index_choice'] == 'UNIQUE') ? '0' : '1', ); $this->index->set($index_params); $add_fields = count($fields); } else { $fields = $this->dbi->getTable($this->db, $this->table) ->getNameAndTypeOfTheColumns(); } $form_params = array( 'db' => $this->db, 'table' => $this->table, ); if (isset($_REQUEST['create_index'])) { $form_params['create_index'] = 1; } elseif (isset($_REQUEST['old_index'])) { $form_params['old_index'] = $_REQUEST['old_index']; } elseif (isset($_REQUEST['index'])) { $form_params['old_index'] = $_REQUEST['index']; } $this->response->getHeader()->getScripts()->addFile('indexes.js'); $this->response->addHTML( Template::get('table/index_form')->render( array( 'fields' => $fields, 'index' => $this->index, 'form_params' => $form_params, 'add_fields' => $add_fields ) ) ); } /** * Process the data from the edit/create index form, * run the query to build the new index * and moves back to "tbl_sql.php" * * @return void */ public function doSaveDataAction() { $error = false; $sql_query = $this->dbi->getTable($this->db, $this->table) ->getSqlQueryForIndexCreateOrEdit($this->index, $error); // If there is a request for SQL previewing. if (isset($_REQUEST['preview_sql'])) { $this->response->addJSON( 'sql_data', Template::get('preview_sql') ->render( array( 'query_data' => $sql_query ) ) ); } elseif (!$error) { $this->dbi->query($sql_query); $response = Response::getInstance(); if ($response->isAjax()) { $message = Message::success( __('Table %1$s has been altered successfully.') ); $message->addParam($this->table); $this->response->addJSON( 'message', Util::getMessage($message, $sql_query, 'success') ); $this->response->addJSON( 'index_table', Index::getHtmlForIndexes( $this->table, $this->db ) ); } else { include 'tbl_structure.php'; } } else { $this->response->setRequestStatus(false); $this->response->addJSON('message', $error); } } }