/**
 * Function to handle the creation or edit of an index
 *
 * @param string    $db    current db
 * @param string    $table current table
 * @param PMA_Index $index current index
 *
 * @return void
 */
function PMA_handleCreateOrEditIndex($db, $table, $index)
{
    $error = false;
    $sql_query = PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, $error);
    // If there is a request for SQL previewing.
    if (isset($_REQUEST['preview_sql'])) {
        PMA_previewSQL($sql_query);
    }
    if (!$error) {
        $GLOBALS['dbi']->query($sql_query);
        $message = PMA_Message::success(__('Table %1$s has been altered successfully.'));
        $message->addParam($table);
        if ($GLOBALS['is_ajax_request'] == true) {
            $response = PMA_Response::getInstance();
            $response->addJSON('message', $message);
            $response->addJSON('index_table', PMA_Index::getView($table, $db));
            $response->addJSON('sql_query', PMA_Util::getMessage(null, $sql_query));
        } else {
            include 'tbl_structure.php';
        }
        exit;
    } else {
        $response = PMA_Response::getInstance();
        $response->isSuccess(false);
        $response->addJSON('message', $error);
        exit;
    }
}
 /**
  * Tests for PMA_getSqlQueryForIndexCreateOrEdit() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetSqlQueryForIndexCreateOrEdit()
 {
     $db = "pma_db";
     $table = "pma_table";
     $index = new PMA_Index();
     $error = false;
     $_REQUEST['old_index'] = "PRIMARY";
     $sql = PMA_getSqlQueryForIndexCreateOrEdit($db, $table, $index, $error);
     $this->assertEquals("ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY, COMMENT '';", $sql);
 }