Skip to content
Newer
Older
100644 201 lines (186 sloc) 7.39 KB
2c445a8 Extensibility basics
jakubvrana authored Jul 3, 2009
1 <?php
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
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 Jul 21, 2009
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 Jul 21, 2009
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 Jul 21, 2009
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 Jul 11, 2009
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
58 * @param array all fields in table, result of fields()
59 * @param string column identifier, function calls are not contained in $fields
60 * @return string
61 */
62 function adminer_field_name($fields, $key) {
cb2c957 Show type by field name (thanks to Jakub Sochor)
jakubvrana authored Jul 13, 2009
63 return call_adminer('field_name', '<span title="' . htmlspecialchars($fields[$key]["full_type"]) . '">' . htmlspecialchars($key) . '</span>', $fields, $key);
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
64 }
65
66 /** Links after select heading
67 * @param array result of SHOW TABLE STATUS
68 * @return string
69 */
70 function adminer_select_links($table_status) {
71 global $SELF;
72 return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
73 }
74
e5de7ef Separate backward keys
jakubvrana authored Jul 22, 2009
75 /** Find backward keys for table
76 * @param string
77 * @return array $return[$target_table][$key_name][$target_column] = $source_column;
78 */
79 function adminer_backward_keys($table) {
80 return call_adminer('backward_keys', array(), $table);
81 }
82
c74c06a Don't modify $query by adminer_select_query
jakubvrana authored Jul 11, 2009
83 /** Query printed in select before execution
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
84 * @param string query to be executed
85 * @return string
86 */
87 function adminer_select_query($query) {
88 global $SELF;
89 // 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 Jul 11, 2009
90 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 Jul 11, 2009
91 }
92
228e43a Row descriptions in select
jakubvrana authored Jul 20, 2009
93 /** Descriptions of selected data
94 * @param array all data to print
95 * @param array foreign keys
96 * @return array
97 */
98 function adminer_row_descriptions($rows, $foreign_keys) {
99 return call_adminer('row_descriptions', $rows, $rows, $foreign_keys);
100 }
101
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
102 /** Value printed in select table
103 * @param string escaped value to print
791ea4f Comment
jakubvrana authored Jul 15, 2009
104 * @param string link to foreign key
105 * @return string
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
106 */
107 function adminer_select_val($val, $link) {
1cf500f Type char can be translated to description
jakubvrana authored Jul 22, 2009
108 return call_adminer('select_val', ($link ? "<a href=\"$link\">$val</a>" : $val), $val, $link);
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
109 }
110
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
111 /** Query printed after execution in the message
112 * @param string executed query
113 * @return string
114 */
115 function adminer_message_query($query) {
116 global $SELF;
117 $id = "sql-" . count($_SESSION["messages"]);
04a3f5b Save history in adminer_message_query
jakubvrana authored Jul 16, 2009
118 $_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
119 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 Jul 11, 2009
120 }
121
4921235 Hide edit functions in Editor
jakubvrana authored Jul 23, 2009
122 /** Functions displayed in edit form
123 * @param array single field from fields()
124 * @return array
125 */
126 function adminer_edit_functions($field) {
127 $return = array("");
128 if (!isset($_GET["default"])) {
129 if (ereg('char|date|time', $field["type"])) {
130 $return = (ereg('char', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now")); //! JavaScript for disabling maxlength
131 }
132 if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
133 // relative functions
134 if (ereg('int|float|double|decimal', $field["type"])) {
135 $return = array("", "+", "-");
136 }
137 if (ereg('date', $field["type"])) {
138 $return[] = "+ interval";
139 $return[] = "- interval";
140 }
141 if (ereg('time', $field["type"])) {
142 $return[] = "addtime";
143 $return[] = "subtime";
144 }
145 }
146 }
147 if ($field["null"] || isset($_GET["default"])) {
148 array_unshift($return, "NULL");
149 }
150 return call_adminer('edit_functions', $return, $field);
151 }
152
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
153 /** Prints navigation after Adminer title
154 * @param string can be "auth" if there is no database connection or "db" if there is no database selected
155 * @return bool true if default navigation should be printed
156 */
157 function adminer_navigation($missing) {
158 global $SELF;
159 if (call_adminer('navigation', true, $missing) && $missing != "auth") {
4a014a6 Always flush in navigation because table_status can take long
jakubvrana authored Jul 16, 2009
160 ob_flush();
161 flush();
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
162 $databases = get_databases();
163 ?>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
164 <form action="" method="post">
165 <p>
166 <a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
167 <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 Jul 11, 2009
168 <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>">
169 <input type="submit" name="logout" value="<?php echo lang('Logout'); ?>">
d2ba593 Browsers interpret <form><p></form> as <form><p></form></p>
jakubvrana authored Jul 14, 2009
170 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
171 </form>
172 <form action="">
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
173 <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 Jul 3, 2009
174 <?php if ($databases) { ?>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
175 <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 Jul 3, 2009
176 <?php } else { ?>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
177 <input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>">
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
178 <?php } ?>
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
179 <?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value=""><?php } ?>
180 <?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value=""><?php } ?>
181 <?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value=""><?php } ?>
182 <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 Jul 14, 2009
183 </p>
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
184 </form>
185 <?php
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
186 if ($missing != "db" && strlen($_GET["db"])) {
187 $table_status = table_status();
188 if (!$table_status) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
189 echo "<p class='message'>" . lang('No tables.') . "\n";
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
190 } else {
191 echo "<p>\n";
192 foreach ($table_status as $row) {
193 echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
194 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 Jul 3, 2009
195 }
196 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
197 echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a>\n";
b95f24e Editor: User friendly data editor
jakubvrana authored Jul 3, 2009
198 }
199 }
2c445a8 Extensibility basics
jakubvrana authored Jul 3, 2009
200 }
Something went wrong with that request. Please try again.