File: add_attr_form.php

package info (click to toggle)
ldap-account-manager 4.7.1-1%2Bdeb8u1
  • links: PTS
  • area: main
  • in suites: jessie
  • size: 42,924 kB
  • sloc: php: 67,802; perl: 379; pascal: 215; xml: 214; sh: 177; makefile: 167
file content (185 lines) | stat: -rw-r--r-- 6,379 bytes parent folder | download | duplicates (2)
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
<?php
/**
 * Displays a form for adding an attribute/value to an LDAP entry.
 *
 * @package phpLDAPadmin
 * @subpackage Page
 */

/**
 */

require './common.php';

# The DN we are working with
$request = array();
$request['dn'] = get_request('dn','GET');

# Check if the entry exists.
if (! $request['dn'] || ! $app['server']->dnExists($request['dn']))
	error(sprintf(_('The entry (%s) does not exist.'),htmlspecialchars($request['dn'])),'error','index.php');

$request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null));
$request['page']->setDN($request['dn']);
$request['page']->accept(true);
$request['template'] = $request['page']->getTemplate();

# Render the form
if (get_request('meth','REQUEST') != 'ajax') {
	$request['page']->drawTitle(sprintf('%s <b>%s</b>',_('Add new attribute'),get_rdn($request['dn'])));
	$request['page']->drawSubTitle();

	echo '<div style="text-align: center;">';
	if (count($request['template']->getAvailAttrs())) {
		# If we have more than the configured entries, we'll separate our input to the old ways.
		if (count($request['template']->getAvailAttrs()) > $_SESSION[APPCONFIG]->getValue('appearance','max_add_attrs')) {
			$attr = array();
			$attr['avail'] = array();
			$attr['binary'] = array();

			foreach ($request['template']->getAvailAttrs() as $attribute)
				if ($app['server']->isAttrBinary($attribute->getName()))
					array_push($attr['binary'],$attribute);
				else
					array_push($attr['avail'],$attribute);

			if (count($attr['avail']) > 0) {
				echo '<br />';
				echo _('Add new attribute');
				echo '<br />';
				echo '<br />';

				echo '<form action="cmd.php" method="post">';
				echo '<div>';

				if ($_SESSION[APPCONFIG]->getValue('confirm','update'))
					echo '<input type="hidden" name="cmd" value="update_confirm" />';
				else
					echo '<input type="hidden" name="cmd" value="update" />';

				printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
				printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));

				echo '<select name="single_item_attr">';

				foreach ($attr['avail'] as $attribute) {
					# Is there a user-friendly translation available for this attribute?
					if ($attribute->haveFriendlyName())
						$attr_display = sprintf('%s (%s)',$attribute->getFriendlyName(),$attribute->getName(false));
					else
						$attr_display = $attribute->getName(false);

					printf('<option value="%s">%s</option>',htmlspecialchars($attribute->getName()),$attr_display);
				}

				echo '</select>';

				echo '<input type="text" name="single_item_value" size="20" />';
				printf('<input type="submit" name="submit" value="%s" class="update_dn" />',_('Add'));
				echo '</div>';
				echo '</form>';

			} else {
				echo '<br />';
				printf('<small>(%s)</small>',_('no new attributes available for this entry'));
			}

			if (count($attr['binary']) > 0) {
				echo '<br />';
				echo _('Add new binary attribute');
				echo '<br />';
				echo '<br />';

				echo '<!-- Form to add a new BINARY attribute to this entry -->';
				echo '<form action="cmd.php" method="post" enctype="multipart/form-data">';
				echo '<div>';

				if ($_SESSION[APPCONFIG]->getValue('confirm','update'))
					echo '<input type="hidden" name="cmd" value="update_confirm" />';
				else
					echo '<input type="hidden" name="cmd" value="update" />';

				printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
				printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
				echo '<input type="hidden" name="binary" value="true" />';

				echo '<select name="single_item_attr">';

				foreach ($attr['binary'] as $attribute) {
					# Is there a user-friendly translation available for this attribute?
					if ($attribute->haveFriendlyName())
						$attr_display = sprintf('%s (%s)',$attribute->getFriendlyName(),$attribute->getName(false));
					else
						$attr_display = $attribute->getName(false);

					printf('<option value="%s">%s</option>',htmlspecialchars($attribute->getName()),$attr_display);
				}

				echo '</select>';

				echo '<input type="file" name="single_item_value" size="20" />';
				printf('<input type="submit" name="submit" value="%s" class="update_dn" />',_('Add'));

				if (! ini_get('file_uploads'))
					printf('<br /><small><b>%s</b></small><br />',
						_('Your PHP configuration has disabled file uploads. Please check php.ini before proceeding.'));

				else
					printf('<br /><small><b>%s: %s</b></small><br />',_('Maximum file size'),ini_get('upload_max_filesize'));

				echo '</div>';
				echo '</form>';

			} else {
				echo '<br />';
				printf('<small>(%s)</small>',_('no new binary attributes available for this entry'));
			}

		} else {
			echo '<br />';

			$request['page']->drawFormStart();
			printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
			printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));

			echo '<table class="entry" cellspacing="0" align="center" border="0">';

			foreach ($request['template']->getAvailAttrs() as $attribute)
				$request['page']->draw('Template',$attribute);

			$request['page']->drawFormSubmitButton();
			echo '</table>';

			$request['page']->drawFormEnd();
		}

	} else {
		printf('<small>(%s)</small>',_('No new attributes available for this entry'));
	}

	echo '</div>';

# The ajax addition (it is going into an existing TemplateRendered page
} else {
	# Put our DIV there for the callback
	echo '<fieldset>';
	printf('<legend>%s</legend>',_('Add new attribute'));
	echo '<div id="ajADDATTR">';
	echo '<table class="entry" cellspacing="0" align="center" border="0">';
	echo '<td valign="top" align="center">';

	printf('<select name="attr" onchange="ajDISPLAY(\'%s\',\'cmd=add_value_form&server_id=%s&dn=%s&attr=\'+this.value,\'%s\',\'append\');">',
		'ADDATTR',$app['server']->getIndex(),$request['template']->getDNEncode(),_('Please wait'));

	printf('<option value="%s">%s</option>','','');
	foreach ($request['template']->getAvailAttrs() as $attribute)
		printf('<option value="%s">%s</option>',htmlspecialchars($attribute->getName()),$attribute->getFriendlyName());

	echo '</select>';

	echo '</td>';
	echo '</table>';
	echo '</div>';
	echo '</fieldset>';
}
?>