Skip to content
Jakub Vrána edited this page Aug 30, 2021 · 30 revisions

Welcome to the adminer Technical wiki!

Best project EVER.

The example.php can be used to limit the tables displayed to a specific list with:

		function tableName($tableStatus) {
			// tables without comments would return empty string and will be ignored by Adminer
			$allowed_tables = Array('mytable1', 'mytable2');
			if (in_array($tableStatus["Name"], $allowed_tables))
				return h($tableStatus["Comment"]);
			else 
				return '';
		}

Different possibilities with columns to be displayed in the table initial listing:

		function fieldName($field, $order = 0) {
/*
$field = Array
(
    [field] => stock_id
    [full_type] => varchar(20)
    [type] => varchar
    [length] => 20
    [unsigned] => 
    [default] => 
    [null] => 
    [auto_increment] => 
    [on_update] => 
    [collation] => utf8_general_ci
    [privileges] => Array
        (
            [select] => 0
            [insert] => 1
            [update] => 2
            [references] => 3
        )

    [comment] => Part#
    [primary] => 1
)
*/
			if ($order && preg_match('~_(md5|sha1)$~', $field["field"])) {
				return ""; // hide hashes in select
			}
			// display only column with comments, first two of them plus searched columns and specific columns
			if ($order < 2) {
				return h($field["comment"]);
			} else if ($order) {
				if (preg_match('~^(ItemDesc|category_id|UPC)$~', $field["field"])) {
					return h($field["comment"]); // chosen fields ItemDesc,category_id,UPC in select
				}
				if (preg_match('~(Price)$~', $field["field"])) {
					return h($field["comment"]); // chosen field names in select ending with Price
				}
				if (preg_match('~^(Product#)$~', $field["comment"])) {
					return h($field["comment"]); // chosen field label Product# in select
				}
			}
			foreach ((array) $_GET["where"] as $key => $where) {
				if ($where["col"] == $field["field"] && ($key >= 0 || $where["val"] != "")) {
					return h($field["comment"]);
				}
			}
			return "";
		}
  • Different number of records in listing and select choices:
		function selectLimitProcess() {
			return (isset($_GET["limit"]) ? $_GET["limit"] : "20");
		}

		function selectLimitPrint($limit) {
			echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
			echo html_select("limit", array("", "20", "50", "100"), $limit);
			echo "</div></fieldset>\n";
		}
  • Enable Record View beside Edit link:
--- adminer/include/functions.inc.php	Mon Jan 25 04:02:41 2016
+++ adminer/include/functions.inc.php	Tue Feb 02 12:34:43 2016
@@ -864,6 +864,7 @@
 	}
 	$functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
 	$attrs = " name='fields[$name]'";
+	$attrs .= isset($_GET['viewonly']) ? " disabled='true'" : "";
 	if ($field["type"] == "enum") {
 		echo nbsp($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
 	} else {
@@ -1369,20 +1370,22 @@
 		echo "</table>\n";
 	}
 	echo "<p>\n";
-	if ($fields) {
-		echo "<input type='submit' value='" . lang('Save') . "'>\n";
-		if (!isset($_GET["select"])) {
-			echo "<input type='submit' name='insert' value='" . ($update
-				? lang('Save and continue edit') . "' onclick='return !ajaxForm(this.form, \"" . lang('Saving') . '...", this)'
-				: lang('Save and insert next')
-			) . "' title='Ctrl+Shift+Enter'>\n";
+	if (!isset($_GET['viewonly'])) {
+		if ($fields)  {
+			echo "<input type='submit' value='" . lang('Save') . "'>\n";
+			if (!isset($_GET["select"])) {
+				echo "<input type='submit' name='insert' value='" . ($update
+					? lang('Save and continue edit') . "' onclick='return !ajaxForm(this.form, \"" . lang('Saving') . '...", this)'
+					: lang('Save and insert next')
+				) . "' title='Ctrl+Shift+Enter'>\n";
+			}
+		}
+		echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "'" . confirm() . ">\n"
+			: ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(document.getElementById('form').getElementsByTagName('td')[1].firstChild);</script>\n")
+		);
+		if (isset($_GET["select"])) {
+			hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
 		}
-	}
-	echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "'" . confirm() . ">\n"
-		: ($_POST || !$fields ? "" : "<script type='text/javascript'>focus(document.getElementById('form').getElementsByTagName('td')[1].firstChild);</script>\n")
-	);
-	if (isset($_GET["select"])) {
-		hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
 	}
 	?>
 <input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
--- adminer/select.inc.php	Mon Jan 25 04:02:41 2016
+++ adminer/select.inc.php	Tue Feb 02 14:17:32 2016
@@ -366,7 +366,10 @@
 					}
 					$unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
 				}
-				echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . ($is_group || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>"));
+				$edit_link_part = " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>";
+				$view_link_part = " | <a href='" . h(ME . "viewonly=&edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('view') . "</a>";
+				
+				echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . ($is_group || information_schema(DB) ? "" : $edit_link_part . $view_link_part));
 
 				foreach ($row as $key => $val) {
 					if (isset($names[$key])) {
  • Hide Auto-increment Primary Key in New Record Form (populate $hidePKfields as needed). Alternatively, just the table names would suffice where the primary key can be ascertained from the $field['primary'] == 1 taking the field name from $field['field'] element.
    function fieldName($field, $order = 0) {
		if ($order && preg_match('~_(md5|sha1)$~', $field["field"])) {
			return ""; // hide hashes in select
		}

		// Hide AutoInc Primary keys during Insert
		if (isset($_GET['edit'])) {
			$hidePKfields = Array(
				Array('htable' => 'employees', 'hfield' => 'EmployeeID')
			  , Array('htable' => 'leaves', 'hfield' => 'LeaveID')
			);
			foreach ($hidePKfields as $val) {
			if ($_GET['edit'] == $val['htable'] && $field['field'] == $val['hfield'] && !isset($_GET['where'][$val['hfield']]))
				return "";
			}
		}

		// display only column with comments, first 60 of them plus searched columns
		if ($order < 60) {
			return h($field["comment"]);
		}
		foreach ((array) $_GET["where"] as $key => $where) {
			if ($where["col"] == $field["field"] && ($key >= 0 || $where["val"] != "")) {
				return h($field["comment"]);
			}
		}
		return "";
	}
  • To link a table's (chq_batches) displayed field (ORID) value to an external file as a link with it's value in the url using a $_GET variable (orid):
		function selectLink($val, $field) {
			if ($field['field'] == 'ORID' && $_GET['select'] == 'chq_batches' && $val !== NULL)
				return 'orslip.php?select=chq_batches&orid='.$val;
		}