-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy patheditcolumn.php
190 lines (145 loc) · 4.8 KB
/
editcolumn.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
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/*
SQL Buddy - Web based MySQL administration
http://interruptorgeek.com/sql-buddy-ig-review/
editcolumn.php
- edit database table columns
MIT license
Original : 2008 Calvin Lough <http://calv.in>
Reviewed : 2016 Carlos Martín Arnillas <https://interruptorgeek.com>
*/
include "functions.php";
loginCheck();
requireDatabaseAndTableBeDefined();
if (isset($db))
$conn->selectDB($db);
if (isset($db))
$structureSql = $conn->query("SHOW FULL FIELDS FROM `$table`");
if (isset($_POST['editParts']) && $conn->isResultSet($structureSql)) {
$editParts = $_POST['editParts'];
$editParts = explode("; ", $editParts);
$totalParts = count($editParts);
$counter = 0;
$firstField = true;
?>
<script type="text/javascript" authkey="<?php echo $requestKey; ?>">
if ($('EDITCOLUMNFIRSTFIELD')) {
$('EDITCOLUMNFIRSTFIELD').focus();
}
</script>
<?php
while ($structureRow = $conn->fetchAssoc($structureSql)) {
if (in_array($structureRow['Field'], $editParts)) {
echo '<form id="editform' . $counter . '" querypart="' . $structureRow['Field'] . '" onsubmit="saveColumnEdit(\'editform' . $counter . '\'); return false;">';
echo '<div class="editcolumn">';
echo '<div class="errormessage" style="margin: 0 7px 13px; display: none"></div>';
echo '<table class="edit" cellspacing="0" cellpadding="0">';
preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches);
$curtype = $matches[1];
$cursizeQuotes = $matches[2];
$cursize = $matches[3];
$curextra = $matches[4];
?>
<tr>
<td class="secondaryheader">
<?php echo __("Name:"); ?>
</td>
<td class="inputarea">
<input type="text" class="text" name="NAME"<?php if ($firstField) echo ' id="EDITCOLUMNFIRSTFIELD"'; ?> value="<?php echo $structureRow['Field']; ?>" style="width: 125px" />
</td>
<td class="secondaryheader">
<?php echo __("Type:"); ?>
</td>
<td class="inputarea">
<select name="TYPE" onchange="toggleValuesLine(this, 'editform<?php echo $counter; ?>')" style="width: 125px">
<?php
foreach ($typeList as $type) {
echo '<option value="' . $type . '"';
if ($type == $curtype)
echo ' selected';
echo '>' . $type . '</option>';
}
?>
</select>
</td>
</tr>
<?php
echo '<tr class="valueline inputarea"';
if (!($curtype == "enum" || $curtype == "set"))
echo ' style="display: none"';
echo '>';
?>
<td class="secondaryheader">
<?php echo __("Values:"); ?>
</td>
<td class="inputarea">
<input type="text" class="text" name="VALUES" value="<?php if (substr($curextra, 0, 1) == "(" && substr($curextra, -1) == ")") echo $curextra; ?>" style="width: 125px" />
</td>
<td colspan="2">
</td>
</tr>
<tr>
<td class="secondaryheader">
<?php echo __("Size:"); ?>
</td>
<td class="inputarea">
<input type="text" class="text" name="SIZE" value="<?php echo $cursize; ?>" style="width: 125px" />
</td>
<td class="secondaryheader">
<?php echo __("Default:"); ?>
</td>
<td class="inputarea">
<input type="text" class="text" name="DEFAULT" value="<?php echo $structureRow['Default']; ?>" style="width: 125px" />
</td>
</tr>
<?php
if (isset($charsetList) && isset($collationList)) {
echo "<tr>";
echo "<td class=\"secondaryheader\">";
echo __("Charset:");
echo "</td>";
echo "<td class=\"inputarea\" colspan=\"3\">";
echo "<select name=\"CHARSET\" style=\"width: 125px\">";
echo "<option></option>";
if ($structureRow['Collation'] != "NULL" && isset($structureRow['Collation'])) {
$currentCharset = $collationList[$structureRow['Collation']];
}
foreach ($charsetList as $charset) {
echo "<option value=\"" . $charset . "\"";
if (isset($currentCharset) && $charset == $currentCharset) {
echo ' selected="selected"';
}
echo ">" . $charset . "</option>";
}
echo "</select>";
echo "</td>";
echo "</tr>";
}
?>
<tr>
<td class="secondaryheader">
<?php echo __("Other:"); ?>
</td>
<td colspan="3" class="inputarea">
<label><input type="checkbox" name="UNSIGN"<?php if ($curextra == " unsigned") echo " checked"; ?>><?php echo __("Unsigned"); ?></label>
<label><input type="checkbox" name="BINARY"<?php if ($curextra == " binary") echo " checked"; ?>><?php echo __("Binary"); ?></label>
<label><input type="checkbox" name="NOTNULL"<?php if ($structureRow['Null'] != "YES") echo " checked"; ?>><?php echo __("Not Null"); ?></label>
</td>
</tr>
<?php
$firstField = false;
?>
<tr>
<td style="padding: 5px 0 15px" colspan="4">
<input type="submit" class="inputbutton" value="<?php echo __("Submit"); ?>" /> <a onclick="cancelEdit('editform<?php echo $counter; ?>')"><?php echo __("Cancel"); ?></a>
</td>
</tr>
</table>
</div>
</form>
<?php
$counter++;
}
}
}
?>