Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 217 lines (200 sloc) 8.056 kB
2c445a8 Extensibility basics
jakubvrana authored
1 <?php
c16c57b E-mail sending
jakubvrana authored
2 /** Name in title and navigation
3 * @return string
4 */
5 function adminer_name() {
6 return call_adminer('name', lang('Adminer'));
7 }
8
9 /** Connection parameters
10 * @return array ($server, $username, $password)
11 */
12 function adminer_credentials() {
13 return call_adminer('credentials', array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]));
14 }
15
16 /** Identifier of selected database
17 * @return string
18 */
19 function adminer_database() {
20 // should be used everywhere instead of $_GET["db"]
21 return call_adminer('database', $_GET["db"]);
22 }
23
2faa08c Customize login and login form
jakubvrana authored
24 /** Print login form
25 * @param string
26 * @return bool whether to display default login form
27 */
28 function adminer_login_form($username) {
29 if (call_adminer('login_form', true, $username)) {
30 ?>
0205440 HTML whitespace
jakubvrana authored
31 <table cellspacing="0">
32 <tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>">
33 <tr><th><?php echo lang('Username'); ?><td><input name="username" value="<?php echo htmlspecialchars($username); ?>">
34 <tr><th><?php echo lang('Password'); ?><td><input type="password" name="password">
35 </table>
2faa08c Customize login and login form
jakubvrana authored
36 <?php
37 }
38 }
39
40 /** Authorize the user
41 * @param string
42 * @param string
43 * @return bool
44 */
45 function adminer_login($login, $password) {
46 return call_adminer('login', true, $login, $password);
47 }
48
c16c57b E-mail sending
jakubvrana authored
49 /** Table caption used in navigation and headings
50 * @param array result of SHOW TABLE STATUS
51 * @return string
52 */
53 function adminer_table_name($row) {
54 return call_adminer('table_name', htmlspecialchars($row["Name"]), $row);
55 }
56
57 /** Field caption used in select and edit
5034123 Apply field name with functions
jakubvrana authored
58 * @param array single field returned from fields()
c16c57b E-mail sending
jakubvrana authored
59 * @return string
60 */
5034123 Apply field name with functions
jakubvrana authored
61 function adminer_field_name($field) {
62 return call_adminer('field_name', ($field ? '<span title="' . htmlspecialchars($field["full_type"]) . '">' . htmlspecialchars($field["field"]) . '</span>' : "*"), $field);
c16c57b E-mail sending
jakubvrana authored
63 }
64
65 /** Links after select heading
66 * @param array result of SHOW TABLE STATUS
67 * @return string
68 */
69 function adminer_select_links($table_status) {
70 global $SELF;
71 return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
72 }
73
e5de7ef Separate backward keys
jakubvrana authored
74 /** Find backward keys for table
75 * @param string
76 * @return array $return[$target_table][$key_name][$target_column] = $source_column;
77 */
78 function adminer_backward_keys($table) {
79 return call_adminer('backward_keys', array(), $table);
80 }
81
c74c06a Don't modify $query by adminer_select_query
jakubvrana authored
82 /** Query printed in select before execution
c16c57b E-mail sending
jakubvrana authored
83 * @param string query to be executed
84 * @return string
85 */
86 function adminer_select_query($query) {
87 global $SELF;
88 // it would be nice if $query can be passed by reference and printed value would be returned but call_user() doesn't allow reference parameters
ace55ed HTML instead of XHTML
jakubvrana authored
89 return call_adminer('select_query', "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n", $query);
c16c57b E-mail sending
jakubvrana authored
90 }
91
1e4d11e Select from foreign keys in Editor
jakubvrana authored
92 /** Description of a row in a table
93 * @param string
94 * @return string SQL expression, empty string for no description
95 */
96 function adminer_row_description($table) {
97 return call_adminer('row_description', "", $table);
98 }
99
100 /** Get descriptions of selected data
228e43a Row descriptions in select
jakubvrana authored
101 * @param array all data to print
1e4d11e Select from foreign keys in Editor
jakubvrana authored
102 * @param array
228e43a Row descriptions in select
jakubvrana authored
103 * @return array
104 */
105 function adminer_row_descriptions($rows, $foreign_keys) {
106 return call_adminer('row_descriptions', $rows, $rows, $foreign_keys);
107 }
108
ba90d60 Introduce adminer_select_val
jakubvrana authored
109 /** Value printed in select table
110 * @param string escaped value to print
791ea4f Comment
jakubvrana authored
111 * @param string link to foreign key
112 * @return string
ba90d60 Introduce adminer_select_val
jakubvrana authored
113 */
114 function adminer_select_val($val, $link) {
1cf500f Type char can be translated to description
jakubvrana authored
115 return call_adminer('select_val', ($link ? "<a href=\"$link\">$val</a>" : $val), $val, $link);
ba90d60 Introduce adminer_select_val
jakubvrana authored
116 }
117
c16c57b E-mail sending
jakubvrana authored
118 /** Query printed after execution in the message
119 * @param string executed query
120 * @return string
121 */
122 function adminer_message_query($query) {
123 global $SELF;
124 $id = "sql-" . count($_SESSION["messages"]);
04a3f5b Save history in adminer_message_query
jakubvrana authored
125 $_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
126 return call_adminer('message_query', " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . htmlspecialchars($query) . '</pre><a href="' . htmlspecialchars($SELF . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>', $query);
c16c57b E-mail sending
jakubvrana authored
127 }
128
4921235 Hide edit functions in Editor
jakubvrana authored
129 /** Functions displayed in edit form
130 * @param array single field from fields()
131 * @return array
132 */
133 function adminer_edit_functions($field) {
134 $return = array("");
135 if (!isset($_GET["default"])) {
136 if (ereg('char|date|time', $field["type"])) {
137 $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength
138 }
139 if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
140 // relative functions
141 if (ereg('int|float|double|decimal', $field["type"])) {
142 $return = array("", "+", "-");
143 }
144 if (ereg('date', $field["type"])) {
145 $return[] = "+ interval";
146 $return[] = "- interval";
147 }
148 if (ereg('time', $field["type"])) {
149 $return[] = "addtime";
150 $return[] = "subtime";
151 }
152 }
153 }
154 if ($field["null"] || isset($_GET["default"])) {
155 array_unshift($return, "NULL");
156 }
1e4d11e Select from foreign keys in Editor
jakubvrana authored
157 return call_adminer('edit_functions', (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $return, $field);
158 }
159
160 /** Get options to display edit field
161 * @param string table name
162 * @param array single field from fields()
163 * @return array options for <select> or empty to display <input>
164 */
165 function adminer_edit_input($table, $field) {
166 return call_adminer('edit_input', false, $table, $field);
4921235 Hide edit functions in Editor
jakubvrana authored
167 }
168
c16c57b E-mail sending
jakubvrana authored
169 /** Prints navigation after Adminer title
170 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
171 * @return bool true if default navigation should be printed
172 */
173 function adminer_navigation($missing) {
174 global $SELF;
175 if (call_adminer('navigation', true, $missing) && $missing != "auth") {
4a014a6 Always flush in navigation because table_status can take long
jakubvrana authored
176 ob_flush();
177 flush();
c16c57b E-mail sending
jakubvrana authored
178 $databases = get_databases();
179 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
180 <form action="" method="post">
181 <p>
182 <a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
183 <a href="<?php echo htmlspecialchars($SELF); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
ace55ed HTML instead of XHTML
jakubvrana authored
184 <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>">
185 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
186 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
187 </form>
188 <form action="">
ace55ed HTML instead of XHTML
jakubvrana authored
189 <p><?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>"><?php } ?>
b95f24e Editor: User friendly data editor
jakubvrana authored
190 <?php if ($databases) { ?>
ace55ed HTML instead of XHTML
jakubvrana authored
191 <select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)<?php echo optionlist($databases, $_GET["db"]); ?></select>
b95f24e Editor: User friendly data editor
jakubvrana authored
192 <?php } else { ?>
ace55ed HTML instead of XHTML
jakubvrana authored
193 <input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>">
b95f24e Editor: User friendly data editor
jakubvrana authored
194 <?php } ?>
ace55ed HTML instead of XHTML
jakubvrana authored
195 <?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
196 <?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
197 <?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
198 <input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?>>
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored
199 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored
200 </form>
201 <?php
c16c57b E-mail sending
jakubvrana authored
202 if ($missing != "db" && strlen($_GET["db"])) {
203 $table_status = table_status();
204 if (!$table_status) {
ace55ed HTML instead of XHTML
jakubvrana authored
205 echo "<p class='message'>" . lang('No tables.') . "\n";
c16c57b E-mail sending
jakubvrana authored
206 } else {
207 echo "<p>\n";
208 foreach ($table_status as $row) {
209 echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
ace55ed HTML instead of XHTML
jakubvrana authored
210 echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . adminer_table_name($row) . "</a><br>\n";
b95f24e Editor: User friendly data editor
jakubvrana authored
211 }
212 }
ace55ed HTML instead of XHTML
jakubvrana authored
213 echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a>\n";
b95f24e Editor: User friendly data editor
jakubvrana authored
214 }
215 }
2c445a8 Extensibility basics
jakubvrana authored
216 }
Something went wrong with that request. Please try again.