C:\xampp\phpMyAdmin\libraries\classes\Controllers\Table\TableIndexesController.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * Holds the PhpMyAdmin\Controllers\Table\TableIndexesController
 *
 * @package PhpMyAdmin\Controllers
 */
namespace PhpMyAdmin\Controllers\Table;

use 
PhpMyAdmin\Controllers\TableController;
use 
PhpMyAdmin\Index;
use 
PhpMyAdmin\Message;
use 
PhpMyAdmin\Response;
use 
PhpMyAdmin\Template;
use 
PhpMyAdmin\Util;

/**
 * Class TableIndexesController
 *
 * @package PhpMyAdmin\Controllers
 */
class TableIndexesController extends TableController
{
    
/**
     * @var Index $index
     */
    
protected $index;

    
/**
     * Constructor
     *
     * @param Index $index Index
     */
    
public function __construct(
        
$response,
        
$dbi,
        
$db,
        
$table,
        
$index
    
) {
        
parent::__construct($response$dbi$db$table);

        
$this->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']);
        
$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,
                    
'create_edit_table' => isset($_REQUEST['create_edit_table'])
                )
            )
        );
    }

    
/**
     * 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);
        }
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586