summaryrefslogtreecommitdiff
path: root/transactions.php
blob: c155caffa9b8558b7b4c3a2732ff392ed11bd6ec (plain)
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
<?php

///////////////////////////////////////////////////////////////////////////////
//
// pgPhoneHome - Postgres Monitor for iPhone
// Copyright 2008, EnterpriseDB UK Ltd.
// Dave Page (dave.page@enterprisedb.com)
//
// transactions.php - Prepared Transaction info
//
///////////////////////////////////////////////////////////////////////////////

require "global.php";

// Get the server number
if (isset($_GET['s']))
	$server = intval($_GET['s']);
else
	$server = -1;

// Set the panel name
$panel = "transactions" . $server; 

if ($server == -1 || $servers[$server]["description"] == "" || $servers[$server]["connstr"] == "")
        www_error("Invalid server", "The specified server number ($server) does not have a valid configuration.");

// Connect the database
$db = @pg_connect($servers[$server]["connstr"]);

if ($db === FALSE)
	www_error("Couldn't connect to the database.", html_entity_decode($php_errormsg, ENT_QUOTES));

// Get the connections
$sql = "SELECT * FROM pg_prepared_xacts;";
$res = @pg_query($db, $sql);

if ($res === false)
		www_error("Query execution error", $php_errormsg);

// Set the message for the top of the page
$rows = pg_num_rows($res);
if ($rows == 0)
	        $message = $servers[$server]["description"] . ": no transactions";
else if ($rows == 1)
	        $message = $servers[$server]["description"] . ": 1 transaction";
else
	        $message = $servers[$server]["description"] . ": $rows transactions";

$message2 = "Server: " . $servers[$server]["description"];

$list = "";
$divs = "";
$rownum = 0;

while ($row = pg_fetch_assoc($res)) {
	
	// Set the sub-panel ID
	$subpanel = $panel . "row" . $rownum++;

	$list .= "	<li class=\"d\"><a href=\"#" . $subpanel . "\">XID: <span class=\"cv\">" . www_clean($row['transaction']) . "</span><br />User: <span class=\"cv\">" . www_clean($row['owner']) . "</span> DB: <span class=\"cv\">" . www_clean($row['database']) . "</span></a></li>";

	$divs .= "<div id=\"" . $subpanel . "\" class=\"panel\" title=\"Transaction\">";
	$divs .= "<div class=\"dh\">$message2</div>";
	$divs .= "<h2>XID</h2><div class=\"vb\">" . www_clean($row['transaction']) . "</div>";
	$divs .= "<h2>Global ID</h2><div class=\"vb\">" . www_clean($row['gid']) . "</div>";
	$divs .= "<h2>Time</h2><div class=\"vb\">" . www_clean($row['prepared']) . "</div>";
	$divs .= "<h2>Owner</h2><div class=\"vb\">" . www_clean($row['owner']) . "</div>";
	$divs .= "<h2>Database</h2><div class=\"vb\">" . www_clean($row['database']) . "</div>";
	$divs .= "</div>";
}

pg_free_result($res);


// Output just the HTML snippet to be loaded via AJAX
$text = <<<EOT
<ul id="$panel" title="Transactions"> 
<li class="group">$message</li>
$list
</ul>
$divs
EOT;

echo $text;
exit();

?>