~ubuntu-branches/ubuntu/trusty/phpmyadmin/trusty

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
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * handles creation of VIEWs
 *
 * @todo js error when view name is empty (strFormEmpty)
 * @todo (also validate if js is disabled, after form submission?)
 * @version $Id: view_create.php 11075 2008-01-21 21:17:23Z lem9 $
 */

/**
 * do not import request variable into global scope
 */
if (! defined('PMA_NO_VARIABLES_IMPORT')) {
    define('PMA_NO_VARIABLES_IMPORT', true);
}

/**
 *
 */
require_once './libraries/common.inc.php';

/**
 * Runs common work
 */
require './libraries/db_common.inc.php';
$url_params['goto'] = $cfg['DefaultTabDatabase'];
$url_params['back'] = 'view_create.php';

$view_algorithm_options = array(
    'UNDEFINED',
    'MERGE',
    'TEMPTABLE',
);

$view_with_options = array(
    'CASCADED CHECK OPTION',
    'LOCAL CHECK OPTION'
);

if (isset($_REQUEST['createview'])) {
    /**
     * Creates the view
     */
    $sep = "\r\n";

    $sql_query = 'CREATE';

    if (isset($_REQUEST['view']['or_replace'])) {
        $sql_query .= ' OR REPLACE';
    }

    if (PMA_isValid($_REQUEST['view']['algorithm'], $view_algorithm_options)) {
        $sql_query .= $sep . ' ALGORITHM = ' . $_REQUEST['view']['algorithm'];
    }

    $sql_query .= $sep . ' VIEW ' . PMA_backquote($_REQUEST['view']['name']);

    if (! empty($_REQUEST['view']['column_names'])) {
        $sql_query .= $sep . ' (' . $_REQUEST['view']['column_names'] . ')';
    }

    $sql_query .= $sep . ' AS ' . $_REQUEST['view']['as'];

    if (isset($_REQUEST['view']['with'])) {
        $options = array_intersect($_REQUEST['view']['with'], $view_with_options);
        if (count($options)) {
            $sql_query .= $sep . ' WITH ' . implode(' ', $options);
        }
    }

    if (PMA_DBI_try_query($sql_query)) {
        $message = PMA_Message::success();
        require './' . $cfg['DefaultTabDatabase'];
        exit();
    } else {
        $message = PMA_Message::rawError(PMA_DBI_getError());
    }
}

// prefill values if not already filled from former submission
$view = array(
    'or_replace' => '',
    'algorithm' => '',
    'name' => '',
    'column_names' => '',
    'as' => $sql_query,
    'with' => array(),
);

if (PMA_isValid($_REQUEST['view'], 'array')) {
    $view = array_merge($view, $_REQUEST['view']);
}

/**
 * Displays top menu links
 * We use db links because a VIEW is not necessarily on a single table
 */
$num_tables = 0;
require_once './libraries/db_links.inc.php';

$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;

/**
 * Displays the page
 */
?>
<!-- CREATE VIEW options -->
<div id="div_view_options">
<form method="post" action="view_create.php">
<?php echo PMA_generate_common_hidden_inputs($url_params); ?>
<fieldset>
    <legend>CREATE VIEW</legend>

    <table>
    <tr><td><label for="or_replace">OR REPLACE</label></td>
        <td><input type="checkbox" name="view[or_replace]" id="or_replace"
                <?php if ($view['or_replace']) { ?>
                checked="checked"
                <?php } ?>
                value="1" />
        </td>
    </tr>
    <tr>
        <td><label for="algorithm">ALGORITHM</label></td>
        <td><select name="view[algorithm]" id="algorithm">
            <?php
            foreach ($view_algorithm_options as $option) {
                echo '<option value="' . htmlspecialchars($option) . '"';
                if ($view['algorithm'] === $option) {
                    echo 'selected="selected"';
                }
                echo '>' . htmlspecialchars($option) . '</option>';
            }
            ?>
            </select>
        </td>
    </tr>
    <tr><td><?php echo $strViewName; ?></td>
        <td><input type="text" size="20" name="view[name]" onfocus="this.select()"
                value="<?php echo htmlspecialchars($view['name']); ?>" />
        </td>
    </tr>

    <tr><td><?php echo $strColumnNames; ?></td>
        <td><input type="text" maxlength="100" size="50" name="view[column_names]"
                onfocus="this.select()"
                value="<?php echo htmlspecialchars($view['column_names']); ?>" />
        </td>
    </tr>

    <tr><td>AS</td>
        <td>
            <textarea name="view[as]" rows="<?php echo $cfg['TextareaRows']; ?>"
                cols="<?php echo $cfg['TextareaCols']; ?>"
                dir="<?php echo $text_dir; ?>" onfocus="this.select();"
                ><?php echo htmlspecialchars($view['as']); ?></textarea>
        </td>
    </tr>
    <tr><td>WITH</td>
        <td>
            <?php
            foreach ($view_with_options as $option) {
                echo '<input type="checkbox" name="view[with][]"';
                if (in_array($option, $view['with'])) {
                    echo ' checked="checked"';
                }
                echo ' id="view_with_' . htmlspecialchars($option) . '"';
                echo ' value="' . htmlspecialchars($option) . '" />';
                echo '<label for="view_with_' . htmlspecialchars($option) . '">';
                echo htmlspecialchars($option) . '</label>';
            }
            ?>
        </td>
    </tr>
    </table>
</fieldset>
<fieldset class="tblFooters">
    <input type="submit" name="createview" value="<?php echo $strGo; ?>" />
</fieldset>
</form>
</div>
<?php
/**
 * Displays the footer
 */
require_once './libraries/footer.inc.php';

?>