-
Notifications
You must be signed in to change notification settings - Fork 30
/
edit.php
172 lines (126 loc) · 4.46 KB
/
edit.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
<?php
/*
SQL Buddy - Web based MySQL administration
http://interruptorgeek.com/sql-buddy-ig-review/
edit.php
- edit specific rows from a database table
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($table))
$structureSql = $conn->describeTable($table);
if (isset($_POST['editParts'])) {
$editParts = $_POST['editParts'];
$editParts = explode("; ", $editParts);
$totalParts = count($editParts);
$counter = 0;
$firstField = true;
?>
<script type="text/javascript" authkey="<?php echo $requestKey; ?>">
if ($('EDITFIRSTFIELD')) {
$('EDITFIRSTFIELD').focus();
}
</script>
<?php
foreach ($editParts as $part) {
$part = trim($part);
if ($part != "" && $part != ";") {
?>
<form id="editform<?php echo $counter; ?>" querypart="<?php echo $part; ?>" onsubmit="saveEdit('editform<?php echo $counter; ?>'); return false;">
<div class="errormessage" style="margin: 6px 12px 10px; width: 338px; display: none"></div>
<table class="insert edit" cellspacing="0" cellpadding="0">
<?php
if ($conn->isResultSet($structureSql)) {
$dataSql = $conn->query("SELECT * FROM `" . $table . "` " . $part);
$dataRow = $conn->fetchAssoc($dataSql);
while ($structureRow = $conn->fetchAssoc($structureSql)) {
preg_match("/^([a-z]+)(.([0-9]+).)?(.*)?$/", $structureRow['Type'], $matches);
$curtype = $matches[1];
$cursizeQuotes = $matches[2];
$cursize = $matches[3];
$curextra = $matches[4];
echo '<tr>';
echo '<td class="fieldheader"><span style="color: steelblue">';
if ($structureRow['Key'] == 'PRI') echo '<u>';
echo $structureRow['Field'];
if ($structureRow['Key'] == 'PRI') echo '</u>';
echo "</span> " . $curtype . $cursizeQuotes . ' ' . $structureRow['Extra'] . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td class="inputarea">';
$showLargeEditor[] = "text";
$showLargeEditor[] = "mediumtext";
$showLargeEditor[] = "longtext";
if (in_array($curtype, $showLargeEditor)) {
echo '<textarea name="' . $structureRow['Field'] . '">' . htmlentities($dataRow[$structureRow['Field']], ENT_QUOTES, 'UTF-8') . '</textarea>';
}
elseif ($curtype == "enum") {
$trimmed = substr($structureRow['Type'], 6, -2);
$listOptions = explode("','", $trimmed);
echo '<select name="' . $structureRow['Field'] . '">';
echo '<option> - - - - - </option>';
foreach ($listOptions as $option) {
echo '<option value="' . $option . '"';
if ($option == $dataRow[$structureRow['Field']]) {
echo ' selected="selected"';
}
echo '>' . $option . '</option>';
}
echo '</select>';
}
elseif ($curtype == "set") {
$trimmed = substr($structureRow['Type'], 5, -2);
$listOptions = explode("','", $trimmed);
foreach ($listOptions as $option) {
$id = $option . rand(1, 1000);
echo '<label for="' . $id . '"><input name="' . $structureRow['Field'] . '[]" value="' . $option . '" id="' . $id . '" type="checkbox"';
if (strpos($dataRow[$structureRow['Field']], $option) > -1)
echo ' checked="checked"';
echo '>' . $option . '</label><br />';
}
} else {
echo '<input type="text"';
if ($firstField)
echo ' id="EDITFIRSTFIELD"';
echo ' name="' . $structureRow['Field'] . '" class="text" value="';
if ($dataRow[$structureRow['Field']] && isset($binaryDTs) && in_array($curtype, $binaryDTs)) {
echo "0x" . bin2hex($dataRow[$structureRow['Field']]);
} else {
echo htmlentities($dataRow[$structureRow['Field']], ENT_QUOTES, 'UTF-8');
}
echo '" />';
}
$firstField = false;
?>
</td>
</tr>
<?php
}
$structureSql = $conn->describeTable($table);
}
?>
<tr>
<td>
<label><input type="radio" name="SB_INSERT_CHOICE" value="SAVE" checked="checked" /><?php echo __("Save changes to original"); ?></label><br />
<label><input type="radio" name="SB_INSERT_CHOICE" value="INSERT" /><?php echo __("Insert as new row"); ?></label>
</td>
</tr>
<tr>
<td style="padding-top: 10px; padding-bottom: 25px">
<input type="submit" class="inputbutton" value="<?php echo __("Submit"); ?>" /> <a onclick="cancelEdit('editform<?php echo $counter; ?>')"><?php echo __("Cancel"); ?></a>
</td>
</tr>
</table>
</form>
<?php
$counter++;
}
}
}
?>