phpldapadmin/htdocs/add_value_form.php

200 lines
6.7 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 10:40:03 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_value_form.php,v 1.36 2005/12/17 00:00:11 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* Displays a form to allow the user to enter a new value to add
* to the existing list of values for a multi-valued attribute.
2009-06-30 09:29:51 +00:00
*
* Variables that come in via common.php
* - server_id
2009-06-30 08:05:37 +00:00
* Variables that come in as GET vars:
* - dn (rawurlencoded)
2009-06-30 09:29:51 +00:00
* - attr (rawurlencoded) the attribute to which we are adding a value
2009-06-30 08:05:37 +00:00
*
2009-06-30 09:29:51 +00:00
* @package phpLDAPadmin
*/
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:22:30 +00:00
require './common.php';
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
if ($ldapserver->isReadOnly())
pla_error(_('You cannot perform updates while server is in read-only mode'));
if (! $ldapserver->haveAuthInfo())
pla_error(_('Not enough information to login to server. Please check your configuration.'));
2009-06-30 09:29:51 +00:00
$attr = $_GET['attr'];
2009-06-30 10:26:08 +00:00
$dn = isset($_GET['dn']) ? $_GET['dn'] : null;
$encoded_dn = rawurlencode($dn);
$encoded_attr = rawurlencode($attr);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if (! is_null($dn))
2009-06-30 10:26:08 +00:00
$rdn = get_rdn($dn);
2009-06-30 09:29:51 +00:00
else
$rdn = null;
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
$current_values = $ldapserver->getDNAttr($dn,$attr);
2009-06-30 10:40:03 +00:00
if ($current_values)
$num_current_values = (is_array($current_values) ? count($current_values) : 1);
else
2009-06-30 10:26:08 +00:00
$num_current_values = 0;
$is_object_class = (strcasecmp($attr, 'objectClass') == 0) ? true : false;
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($is_object_class) {
# fetch all available objectClasses and remove those from the list that are already defined in the entry
2009-06-30 09:40:37 +00:00
$schema_oclasses = $ldapserver->SchemaObjectClasses();
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
foreach($current_values as $oclass)
unset($schema_oclasses[strtolower($oclass)]);
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
} else {
2009-06-30 09:40:37 +00:00
$schema_attr = $ldapserver->getSchemaAttribute($attr);
2009-06-30 08:05:37 +00:00
}
2009-06-30 10:26:08 +00:00
include './header.php';
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
echo '<body>';
printf('<h3 class="title">%s <b>%s</b> %s <b>%s</b></h3>',
_('Add new'),htmlspecialchars($attr),_('value to'),htmlspecialchars($rdn));
printf('<h3 class="subtitle">%s <b>%s</b> &nbsp;&nbsp;&nbsp; %s: <b>%s</b></h3>',
_('Server'),$ldapserver->name,_('Distinguished Name'),htmlspecialchars($dn));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf('%s <b>%s</b> %s <b>%s</b>:',
_('Current list of'),$num_current_values,_('values for attribute'),htmlspecialchars($attr));
2009-06-30 08:07:14 +00:00
2009-06-30 10:26:08 +00:00
if ($num_current_values) {
if ($ldapserver->isJpegPhoto($attr)) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<table><tr><td>';
draw_jpeg_photos($ldapserver, $dn, $attr, false);
echo '</td></tr></table>';
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
# <!-- Temporary warning until we find a way to add jpegPhoto values without an INAPROPRIATE_MATCHING error -->
printf('<p><small>%s</small></p>',
_('Note: You will get an "inappropriate matching" error if you have not setup an EQUALITY rule on your LDAP server for this attribute.'));
# <!-- End of temporary warning -->
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} elseif ($ldapserver->isAttrBinary($attr)) {
echo '<ul>';
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if (is_array($vals)) {
for ($i=1; $i<=count($vals); $i++) {
$href = sprintf('download_binary_attr.php?server_id=%s&amp;dn=%s&amp;attr=%s&amp;value_num=%s',
$ldapserver->server_id,$encoded_dn,$attr,$i-1);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf('<li><a href="%s"><img src="images/save.png" />%s (%s)</a></li>',
$href,_('download value'),$i);
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
$href = sprintf('download_binary_attr.php?server_id=%s&amp;dn=%s&amp;attr=%s',
$ldapserver->server_id,$encoded_dn,$attr);
printf('<li><a href="%s"><img src="images/save.png" />%s</a></li>',
$href,_('download value'));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '</ul>';
# <!-- Temporary warning until we find a way to add jpegPhoto values without an INAPROPRIATE_MATCHING error -->
printf('<p><small>%s</small></p>',
_('Note: You will get an "inappropriate matching" error if you have not setup an EQUALITY rule on your LDAP server for this attribute.'));
# <!-- End of temporary warning -->
2009-06-30 09:29:51 +00:00
} else {
2009-06-30 10:26:08 +00:00
echo '<ul class="current_values">';
if (is_array($current_values)) {
if (strcasecmp($attr,'userPassword') == 0) {
foreach ($current_values as $key => $value) {
if (obfuscate_password_display(get_enc_type($value)))
2009-06-30 10:40:03 +00:00
echo '<li><nobr>'.preg_replace('/./','*',$value).'<br /></li>';
2009-06-30 10:26:08 +00:00
else
2009-06-30 10:40:03 +00:00
echo '<li><nobr>'.htmlspecialchars($value).'<br /></li>';
2009-06-30 10:26:08 +00:00
}
} else {
foreach ($current_values as $val)
2009-06-30 10:40:03 +00:00
printf('<li><nobr>%s</nobr></li>',htmlspecialchars($val));
2009-06-30 10:26:08 +00:00
}
} else {
2009-06-30 10:40:03 +00:00
printf('<li><nobr>%s</nobr></li>',htmlspecialchars($current_values));
2009-06-30 10:26:08 +00:00
}
echo '</ul>';
}
} else {
echo '<br /><br />';
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo _('Enter the value you would like to add:');
echo '<br /><br />';
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
if ($is_object_class) {
echo '<form action="add_oclass_form.php" method="post" class="new_value">';
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
printf('<input type="hidden" name="dn" value="%s" />',$encoded_dn);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
echo '<select name="new_oclass[]" multiple="true" size="15">';
foreach ($schema_oclasses as $name => $oclass) {
# exclude any structural ones, as they'll only generate an LDAP_OBJECT_CLASS_VIOLATION
if ($oclass->getType() == 'structural')
continue;
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
printf('<option value="%s">%s</option>',$oclass->getName(),$oclass->getName());
}
echo '</select>';
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
echo '<br />';
printf('<input type="submit" value="%s" />',_('Add new ObjectClass'));
echo '<br />';
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($config->GetValue('appearance','show_hints'))
printf('<small><br /><img src="images/light.png" /><span class="hint">%s</span></small>',
_('Note: You may be required to enter new attributes that these objectClass(es) require'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
} else {
echo '<form action="add_value.php" method="post" class="new_value" name="new_value_form">';
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($ldapserver->isAttrBinary($attr))
echo 'enctype="multipart/form-data"';
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
printf('<input type="hidden" name="dn" value="%s" />',$encoded_dn);
printf('<input type="hidden" name="attr" value="%s" />',$encoded_attr);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
if ($ldapserver->isAttrBinary($attr)) {
echo '<input type="file" name="new_value" />';
echo '<input type="hidden" name="binary" value="true" />';
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
} else {
if ($ldapserver->isMultiLineAttr($attr)) {
echo '<textarea name="new_value" rows="3" cols="30"></textarea>';
} else {
printf('<input type="text"%s name="new_value" size="40" value="" />',
($schema_attr->getMaxLength() ? sprintf(' maxlength="%s"',$schema_attr->getMaxLength()) : ''));
2009-06-30 08:09:20 +00:00
2009-06-30 10:26:08 +00:00
# draw the "browse" button next to this input box if this attr houses DNs:
if ($ldapserver->isDNAttr($attr))
draw_chooser_link("new_value_form.new_value", false);
}
}
2009-06-30 08:09:20 +00:00
2009-06-30 10:26:08 +00:00
printf('<input type="submit" name="submit" value="%s" />',_('Add New Value'));
echo '<br />';
2009-06-30 08:09:20 +00:00
2009-06-30 10:26:08 +00:00
if ($schema_attr->getDescription())
printf('<small><b>%s:</b> %s</small><br />',_('Description'),$schema_attr->getDescription());
2009-06-30 08:07:14 +00:00
2009-06-30 10:26:08 +00:00
if ($schema_attr->getType())
printf('<small><b>%s:</b> %s</small><br />',_('Syntax'),$schema_attr->getType());
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
if ($schema_attr->getMaxLength())
printf('<small><b>%s:</b> %s %s</small><br />',
_('Maximum Length'),number_format($schema_attr->getMaxLength()),_('characters'));
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
echo '</form>';
}
echo '</body></html>';
?>