phpldapadmin/htdocs/add_attr_form.php

183 lines
5.5 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 10:46:00 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_attr_form.php,v 1.16 2007/12/15 07:50:30 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 09:22:30 +00:00
* Displays a form for adding an attribute/value to an LDAP entry.
*
* Variables that come in as GET vars:
* - dn (rawurlencoded)
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
*/
/**
2009-06-30 09:22:30 +00:00
*/
require './common.php';
2009-06-30 10:41:18 +00:00
if ($ldapserver->isReadOnly())
pla_error(_('You cannot perform updates while server is in read-only mode'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$entry['dn']['string'] = get_request('dn','GET');
$entry['rdn'] = get_rdn($entry['dn']['string']);
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
printf('<h3 class="title">%s <b>%s</b></h3>',_('Add new attribute'),htmlspecialchars($entry['rdn']));
2009-06-30 10:41:18 +00:00
printf('<h3 class="subtitle">%s: <b>%s</b> &nbsp;&nbsp;&nbsp; %s: <b>%s</b></h3>',
2009-06-30 10:46:00 +00:00
_('Server'),$ldapserver->name,_('Distinguished Name'),htmlspecialchars($entry['dn']['string']));
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
$dn['attrs'] = $ldapserver->getDNAttrs($entry['dn']['string']);
$dn['oclasses'] = $ldapserver->getDNAttr($entry['dn']['string'],'objectClass');
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
if (! is_array($dn['oclasses']))
$dn['oclasses'] = array($dn['oclasses']);
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$ldap['attrs']['avail'] = array();
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if (array_search('extensibleObject',$dn['oclasses']) !== false) {
$ldap['attrs']['ldap'] = $ldapserver->SchemaAttributes();
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
foreach ($ldap['attrs']['ldap'] as $attr)
$ldap['attrs']['avail'][] = $attr->getName();
2009-06-30 10:41:18 +00:00
} else {
2009-06-30 10:46:00 +00:00
$ldap['oclasses'] = $ldapserver->SchemaObjectClasses($entry['dn']['string']);
2009-06-30 10:41:18 +00:00
2009-06-30 10:46:00 +00:00
foreach ($dn['oclasses'] as $oclass) {
$ldap['oclass'] = $ldapserver->getSchemaObjectClass($oclass,$entry['dn']['string']);
2009-06-30 10:41:18 +00:00
2009-06-30 10:46:00 +00:00
if ($ldap['oclass'] && strcasecmp('objectclass',get_class($ldap['oclass'])) == 0)
$ldap['attrs']['avail'] = array_merge($ldap['oclass']->getMustAttrNames($ldap['oclasses']),
$ldap['oclass']->getMayAttrNames($ldap['oclasses']),
$ldap['attrs']['avail']);
2009-06-30 10:41:18 +00:00
}
2009-06-30 09:22:30 +00:00
}
2009-06-30 10:46:00 +00:00
$ldap['attrs']['avail'] = array_unique($ldap['attrs']['avail']);
$ldap['attrs']['avail'] = array_filter($ldap['attrs']['avail'],'not_an_attr');
sort($ldap['attrs']['avail']);
2009-06-30 10:41:18 +00:00
2009-06-30 10:46:00 +00:00
$ldap['binattrs']['avail'] = array();
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
foreach ($ldap['attrs']['avail'] as $i => $attr) {
2009-06-30 10:26:08 +00:00
if ($ldapserver->isAttrBinary($attr)) {
2009-06-30 10:46:00 +00:00
$ldap['binattrs']['avail'][] = $attr;
unset($ldap['attrs']['avail'][$i]);
2009-06-30 09:22:30 +00:00
}
}
2009-06-30 10:41:18 +00:00
echo '<center>';
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if (is_array($ldap['attrs']['avail']) && count($ldap['attrs']['avail']) > 0) {
2009-06-30 10:41:18 +00:00
echo '<br />';
echo _('Add new attribute');
echo '<br />';
echo '<br />';
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
echo '<form action="cmd.php" method="post">';
echo '<input type="hidden" name="cmd" value="add_attr" />';
2009-06-30 10:41:18 +00:00
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
2009-06-30 10:46:00 +00:00
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($entry['dn']['string']));
2009-06-30 09:22:30 +00:00
2009-06-30 10:41:18 +00:00
echo '<select name="attr">';
2009-06-30 09:22:30 +00:00
2009-06-30 10:41:18 +00:00
$attr_select_html = '';
2009-06-30 10:46:00 +00:00
usort($ldap['attrs']['avail'],'sortAttrs');
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
foreach ($ldap['attrs']['avail'] as $a) {
2009-06-30 09:22:30 +00:00
2009-06-30 10:41:18 +00:00
# is there a user-friendly translation available for this attribute?
2009-06-30 10:46:00 +00:00
if (isset($_SESSION['plaConfig']->friendly_attrs[strtolower($a)])) {
2009-06-30 10:41:18 +00:00
$attr_display = sprintf('%s (%s)',
2009-06-30 10:46:00 +00:00
htmlspecialchars($_SESSION['plaConfig']->friendly_attrs[strtolower($a)]),
2009-06-30 10:41:18 +00:00
htmlspecialchars($a));
2009-06-30 09:29:51 +00:00
} else {
2009-06-30 10:41:18 +00:00
$attr_display = htmlspecialchars($a);
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:41:18 +00:00
printf('<option value="%s">%s</option>',htmlspecialchars($a),$attr_display);
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '</select>';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '<input type="text" name="val" size="20" />';
printf('<input type="submit" name="submit" value="%s" class="update_dn" />',_('Add'));
echo '</form>';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
} else {
echo '<br />';
printf('<small>(%s)</small>',_('no new attributes available for this entry'));
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if (count($ldap['binattrs']['avail']) > 0) {
2009-06-30 10:41:18 +00:00
echo '<br />';
echo _('Add new binary attribute');
echo '<br />';
echo '<br />';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '<!-- Form to add a new BINARY attribute to this entry -->';
2009-06-30 10:46:00 +00:00
echo '<form action="cmd.php" method="post" enctype="multipart/form-data">';
echo '<input type="hidden" name="cmd" value="add_attr" />';
2009-06-30 10:41:18 +00:00
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
2009-06-30 10:46:00 +00:00
printf('<input type="hidden" name="dn" value="%s" />',$entry['dn']['string']);
2009-06-30 10:41:18 +00:00
echo '<input type="hidden" name="binary" value="true" />';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '<select name="attr">';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
$attr_select_html = '';
2009-06-30 10:46:00 +00:00
usort($ldap['binattrs']['avail'],'sortAttrs');
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
foreach ($ldap['binattrs']['avail'] as $a) {
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
# is there a user-friendly translation available for this attribute?
2009-06-30 10:46:00 +00:00
if (isset($_SESSION['plaConfig']->friendly_attrs[strtolower($a)])) {
2009-06-30 10:41:18 +00:00
$attr_display = sprintf('%s (%s)',
2009-06-30 10:46:00 +00:00
htmlspecialchars($_SESSION['plaConfig']->friendly_attrs[strtolower($a)]),
2009-06-30 10:41:18 +00:00
htmlspecialchars($a));
2009-06-30 09:29:51 +00:00
} else {
2009-06-30 10:41:18 +00:00
$attr_display = htmlspecialchars($a);
2009-06-30 09:29:51 +00:00
}
2009-06-30 10:41:18 +00:00
printf('<option value="%s">%s</option>',htmlspecialchars($a),$attr_display);
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '</select>';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '<input type="file" name="val" size="20" />';
printf('<input type="submit" name="submit" value="%s" class="update_dn" />',_('Add'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
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.'));
2009-06-30 09:29:51 +00:00
else
2009-06-30 10:41:18 +00:00
printf('<br /><small><b>%s: %s</b></small><br />',_('Maximum file size'),ini_get('upload_max_filesize'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
echo '</form>';
2009-06-30 09:29:51 +00:00
2009-06-30 10:41:18 +00:00
} else {
echo '<br />';
printf('<small>(%s)</small>',_('no new binary attributes available for this entry'));
}
2009-06-30 09:22:30 +00:00
2009-06-30 10:41:18 +00:00
echo '</center>';
2009-06-30 09:22:30 +00:00
/**
* Given an attribute $x, this returns true if it is NOT already specified
* in the current entry, returns false otherwise.
2009-06-30 09:29:51 +00:00
*
* @param attr $x
* @return bool
* @ignore
2009-06-30 09:22:30 +00:00
*/
2009-06-30 10:41:18 +00:00
function not_an_attr($x) {
2009-06-30 10:46:00 +00:00
global $dn;
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
foreach ($dn['attrs'] as $attr => $values)
2009-06-30 10:41:18 +00:00
if (strcasecmp($attr,$x) == 0)
2009-06-30 09:22:30 +00:00
return false;
2009-06-30 10:41:18 +00:00
2009-06-30 09:22:30 +00:00
return true;
}
?>