-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_create.php
executable file
·147 lines (127 loc) · 4.12 KB
/
view_create.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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
*
* @version $Id: view_create.php 11343 2008-06-24 14:11:54Z lem9 $
*/
/**
*
*/
require_once './libraries/common.inc.php';
/**
* Runs common work
*/
require './libraries/db_common.inc.php';
$url_params['goto'] = $url_params['back'] = 'view_create.php';
if (isset($_POST['submitoptions'])) {
/**
* Creates the view
*/
$message = '';
$sep = "\r\n";
$create_query = 'CREATE' . $sep;
if (isset($_POST['or_replace'])) {
$create_query .= ' OR REPLACE' . $sep;
}
if (isset($_POST['algorithm'])) {
$create_query .= ' ALGORITHM = ' . $_POST['algorithm'] . $sep;
}
$create_query .= ' VIEW ' . PMA_backquote($_POST['view_name']) . $sep;
if (!empty($_POST['column_names'])) {
$create_query .= ' (' . $_POST['column_names'] . ')' . $sep;
}
$create_query .= ' AS ' . $_POST['sql_statement'] . $sep;
if (isset($_POST['cascaded']) || isset($_POST['local']) || isset($_POST['check_option'])) {
$create_query .= ' WITH ';
}
if (isset($_POST['cascaded'])) {
$create_query .= ' CASCADED ';
}
if (isset($_POST['local'])) {
$create_query .= ' LOCAL ';
}
if (isset($_POST['check_option'])) {
$create_query .= ' CHECK OPTION ';
}
$message .= PMA_DBI_query($create_query) ? $strSuccess : $strError;
// to display the CREATE VIEW query
$sql_query = $create_query;
require './' . $cfg['DefaultTabDatabase'];
exit();
} else {
/**
* 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['goto'] = 'view_create.php';
$url_params['back'] = 'view_create.php';
/**
* Displays the page
*
* @todo js error when view name is empty (strFormEmpty)
* @todo (also validate if js is disabled, after form submission?)
*/
?>
<!-- CREATE VIEW options -->
<div id="div_view_options">
<form method="post" action="view_create.php">
<?php echo PMA_generate_common_hidden_inputs($GLOBALS['db']); ?>
<input type="hidden" name="reload" value="1" />
<fieldset>
<legend>CREATE VIEW</legend>
<table>
<tr><td><label for="or_replace">OR REPLACE</label></td>
<td><input type="checkbox" name="or_replace" id="or_replace"
value="1" />
</td>
</tr>
<tr>
<td><label for="algorithm">ALGORITHM</label></td>
<td><select name="algorithm" id="algorithm">
<option value="UNDEFINED">UNDEFINED</option>
<option value="MERGE">MERGE</option>
<option value="TEMPTABLE">TEMPTABLE</option>
</select>
</td>
</tr>
<tr><td><?php echo $strViewName; ?></td>
<td><input type="text" size="20" name="view_name" onfocus="this.select()"
value="" />
</td>
</tr>
<tr><td><?php echo $strColumnNames; ?></td>
<td><input type="text" maxlength="100" size="50" name="column_names" onfocus="this.select()"
value="" />
</td>
</tr>
<tr><td><?php echo 'AS' ?></td>
<td>
<textarea name="sql_statement" rows="<?php echo $cfg['TextareaRows']; ?>" cols="<?php echo $cfg['TextareaCols']; ?>" dir="<?php echo $text_dir; ?>" onfocus="this.select();"><?php echo htmlspecialchars($sql_query); ?></textarea>
</td>
</tr>
<tr><td>WITH</td>
<td>
<input type="checkbox" name="cascaded" id="cascaded" value="1" />
<label for="cascaded">CASCADED</label>
<input type="checkbox" name="local" id="local" value="1" />
<label for="local">LOCAL</label>
<input type="checkbox" name="check_option" id="check_option" value="1" />
<label for="check_option">CHECK OPTION</label>
</td>
</tr>
</table>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" name="submitoptions" value="<?php echo $strGo; ?>" />
</fieldset>
</form>
</div>
<?php
/**
* Displays the footer
*/
require_once './libraries/footer.inc.php';
} // end if
?>