File: compare.php

package info (click to toggle)
phpldapadmin 1.2.6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,528 kB
  • sloc: php: 17,684; javascript: 5,299; xml: 1,498; sh: 379; python: 148; makefile: 23
file content (188 lines) | stat: -rw-r--r-- 5,727 bytes parent folder | download | duplicates (5)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
 * Compares two DN entries side by side.
 *
 * @package phpLDAPadmin
 * @subpackage Page
 */

/**
 */

require './common.php';

# The DNs we are working with
$request = array();
$request['dnSRC'] = get_request('dn_src');
$request['dnDST'] = get_request('dn_dst');

$ldap = array();
$ldap['SRC'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_src'));
$ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst'));

if (! $ldap['SRC']->dnExists($request['dnSRC']))
	error(sprintf('%s (%s)',_('No such entry.'),pretty_print_dn($request['dnSRC'])),'error','index.php');

if (! $ldap['DST']->dnExists($request['dnDST']))
	error(sprintf('%s (%s)',_('No such entry.'),pretty_print_dn($request['dnDST'])),'error','index.php');

$request['pageSRC'] = new PageRender($ldap['SRC']->getIndex(),get_request('template','REQUEST',false,'none'));
$request['pageSRC']->setDN($request['dnSRC']);
$request['pageSRC']->accept();
$request['templateSRC'] = $request['pageSRC']->getTemplate();

$request['pageDST'] = new PageRender($ldap['DST']->getIndex(),get_request('template','REQUEST',false,'none'));
$request['pageDST']->setDN($request['dnDST']);
$request['pageDST']->accept();
$request['templateDST'] = $request['pageDST']->getTemplate();

# Get a list of all attributes.
$attrs_all = array_unique(array_merge($request['templateSRC']->getAttributeNames(),$request['templateDST']->getAttributeNames()));

$request['pageSRC']->drawTitle(_('Comparing the following DNs'));

echo '<br/>';

echo '<table class="entry" width="100%" border="0">';
echo '<tr class="heading">';

$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',
	$ldap['SRC']->getIndex(),rawurlencode($request['dnSRC']));
printf('<td colspan="2" style="width: 40%%;">%s: <b>%s</b><br />%s: <b><a href="%s">%s</a></b></td>',
	_('Server'),$ldap['SRC']->getName(),_('Distinguished Name'),
	htmlspecialchars($href),$request['dnSRC']);

$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s',
	$ldap['DST']->getIndex(),rawurlencode($request['dnDST']));
printf('<td colspan="2" style="width: 40%%;">%s: <b>%s</b><br />%s: <b><a href="%s">%s</a></b></td>',
	_('Server'),$ldap['DST']->getName(),_('Distinguished Name'),
	htmlspecialchars($href),$request['dnDST']);

echo '</tr>';

echo '<tr>';
echo '<td colspan="4" style="text-align: right;">';
echo '<form action="cmd.php?cmd=compare" method="post">';
echo '<div>';
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="server_id_src" value="%s" />',$ldap['DST']->getIndex());
printf('<input type="hidden" name="server_id_dst" value="%s" />',$ldap['SRC']->getIndex());
printf('<input type="hidden" name="dn_src" value="%s" />',htmlspecialchars($request['dnDST']));
printf('<input type="hidden" name="dn_dst" value="%s" />',htmlspecialchars($request['dnSRC']));
printf('<input type="submit" value="%s" />',_('Switch Entry'));
echo '</div>';
echo '</form>';
echo '</td>';
echo '</tr>';

if (! is_array($attrs_all) || ! count($attrs_all)) {
	printf('<tr><td colspan="4">(%s)</td></tr>',_('This entry has no attributes'));
	print '</table>';

	return;
}

sort($attrs_all);

# Work through each of the attributes.
foreach ($attrs_all as $attr) {
	# Has the config.php specified that this attribute is to be hidden or shown?
	if ($ldap['SRC']->isAttrHidden($attr) || $ldap['DST']->isAttrHidden($attr))
		continue;

	$attributeSRC = $request['templateSRC']->getAttribute($attr);
	$attributeDST = $request['templateDST']->getAttribute($attr);

	# Get the values and see if they are the same.
	if ($attributeSRC && $attributeDST && ($attributeSRC->getValues() == $attributeDST->getValues()))
		echo '<tr>';
	else
		echo '<tr>';

	foreach (array('src','dst') as $side) {
		# If we are on the source side, show the attribute name.
		switch ($side) {
			case 'src':
				if ($attributeSRC) {
					echo '<td class="title">';
					$request['pageSRC']->draw('Name',$attributeSRC);
					echo '</td>';

					if ($request['pageSRC']->getServerID() == $request['pageDST']->getServerID())
						echo '<td class="title">&nbsp;</td>';

					else {
						echo '<td class="note" style="text-align: right;">';
						$request['pageSRC']->draw('Notes',$attributeSRC);
						echo '</td>';
					}

				} else {
					echo '<td colspan="2">&nbsp;</td>';
				}

				break;

			case 'dst':
				if ($attributeDST) {
					if ($attributeSRC && ($request['pageSRC']->getServerID() == $request['pageDST']->getServerID()))
						echo '<td class="title">&nbsp;</td>';

					else {
						echo '<td class="title" >';
						$request['pageDST']->draw('Name',$attributeDST);
						echo '</td>';
					}

					echo '<td class="note" style="text-align: right;">';
					$request['pageDST']->draw('Notes',$attributeDST);
					echo '</td>';

				} else {
					echo '<td colspan="2">&nbsp;</td>';
				}

				break;
		}
	}

	echo '</tr>';
	echo "\n\n";

	# Get the values and see if they are the same.
	if ($attributeSRC && $attributeDST && ($attributeSRC->getValues() == $attributeDST->getValues()))
		echo '<tr style="background-color: #F0F0F0;">';
	else
		echo '<tr>';

	foreach (array('src','dst') as $side) {
		echo '<td class="value" colspan="2"><table border="0">';
		echo '<tr><td>';

		switch ($side) {
			case 'src':

				if ($attributeSRC && count($attributeSRC->getValues()))
					$request['pageSRC']->draw('CurrentValues',$attributeSRC);
				else
					echo '&nbsp;';

				break;

			case 'dst':
				if ($attributeDST && count($attributeDST->getValues()))
					$request['pageDST']->draw('CurrentValues',$attributeDST);
				else
					echo '&nbsp;';

				break;
		}

		echo '</td></tr>';
		echo '</table></td>';
	}

	echo '</tr>';
}
echo '</table>';
?>