Latest SANDPIT - MERGE from CVS (MERGE-GIT)

This commit is contained in:
Deon George
2009-07-01 16:09:17 +10:00
parent 388783fc84
commit ea17aadef4
210 changed files with 37284 additions and 52716 deletions

View File

@@ -1,184 +1,183 @@
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_attr_form.php,v 1.16.2.4 2008/12/12 12:20:22 wurley Exp $
// $Header$
/**
* Displays a form for adding an attribute/value to an LDAP entry.
*
* Variables that come in as GET vars:
* - dn (rawurlencoded)
*
* @package phpLDAPadmin
* @subpackage Page
*/
/**
*/
require './common.php';
if ($ldapserver->isReadOnly())
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
# The DN we are working with
$request = array();
$request['dn'] = get_request('dn','GET');
$entry = array();
$entry['dn']['string'] = get_request('dn','GET');
$entry['rdn'] = get_rdn($entry['dn']['string']);
# Check if the entry exists.
if (! $request['dn'] || ! $app['server']->dnExists($request['dn']))
error(sprintf(_('The entry (%s) does not exist.'),$request['dn']),'error','index.php');
printf('<h3 class="title">%s <b>%s</b></h3>',_('Add new attribute'),htmlspecialchars($entry['rdn']));
printf('<h3 class="subtitle">%s: <b>%s</b> &nbsp;&nbsp;&nbsp; %s: <b>%s</b></h3>',
_('Server'),$ldapserver->name,_('Distinguished Name'),htmlspecialchars($entry['dn']['string']));
$request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,'none'));
$request['page']->setDN($request['dn']);
$request['page']->accept(true);
$request['template'] = $request['page']->getTemplate();
$dn = array();
$dn['attrs'] = $ldapserver->getDNAttrs($entry['dn']['string']);
$dn['oclasses'] = $ldapserver->getDNAttr($entry['dn']['string'],'objectClass');
# 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();
if (! is_array($dn['oclasses']))
$dn['oclasses'] = array($dn['oclasses']);
echo '<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();
$ldap['attrs']['avail'] = 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 (array_search('extensibleObject',$dn['oclasses']) !== false) {
$ldap['attrs']['ldap'] = $ldapserver->SchemaAttributes();
if (count($attr['avail']) > 0) {
echo '<br />';
echo _('Add new attribute');
echo '<br />';
echo '<br />';
foreach ($ldap['attrs']['ldap'] as $attr)
$ldap['attrs']['avail'][] = $attr->getName();
echo '<form action="cmd.php" method="post">';
} else {
$ldap['oclasses'] = $ldapserver->SchemaObjectClasses($entry['dn']['string']);
if ($_SESSION[APPCONFIG]->getValue('confirm','update'))
echo '<input type="hidden" name="cmd" value="update_confirm" />';
else
echo '<input type="hidden" name="cmd" value="update" />';
foreach ($dn['oclasses'] as $oclass) {
$ldap['oclass'] = $ldapserver->getSchemaObjectClass($oclass,$entry['dn']['string']);
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
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']);
}
}
echo '<select name="single_item_attr">';
$ldap['attrs']['avail'] = array_unique($ldap['attrs']['avail']);
$ldap['attrs']['avail'] = array_filter($ldap['attrs']['avail'],'not_an_attr');
sort($ldap['attrs']['avail']);
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);
$ldap['binattrs']['avail'] = array();
printf('<option value="%s">%s</option>',htmlspecialchars($attribute->getName()),$attr_display);
}
foreach ($ldap['attrs']['avail'] as $i => $attr) {
if ($ldapserver->isAttrBinary($attr)) {
$ldap['binattrs']['avail'][] = $attr;
unset($ldap['attrs']['avail'][$i]);
}
}
echo '</select>';
echo '<center>';
echo '<input type="text" name="single_item_value" size="20" />';
printf('<input type="submit" name="submit" value="%s" class="update_dn" />',_('Add'));
echo '</form>';
if (is_array($ldap['attrs']['avail']) && count($ldap['attrs']['avail']) > 0) {
echo '<br />';
echo _('Add new attribute');
echo '<br />';
echo '<br />';
} else {
echo '<br />';
printf('<small>(%s)</small>',_('no new attributes available for this entry'));
}
echo '<form action="cmd.php" method="post">';
echo '<input type="hidden" name="cmd" value="add_attr" />';
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($entry['dn']['string']));
if (count($attr['binary']) > 0) {
echo '<br />';
echo _('Add new binary attribute');
echo '<br />';
echo '<br />';
echo '<select name="attr">';
echo '<!-- Form to add a new BINARY attribute to this entry -->';
echo '<form action="cmd.php" method="post" enctype="multipart/form-data">';
$attr_select_html = '';
usort($ldap['attrs']['avail'],'sortAttrs');
if ($_SESSION[APPCONFIG]->getValue('confirm','update'))
echo '<input type="hidden" name="cmd" value="update_confirm" />';
else
echo '<input type="hidden" name="cmd" value="update" />';
foreach ($ldap['attrs']['avail'] as $a) {
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',$request['dn']);
echo '<input type="hidden" name="binary" value="true" />';
# is there a user-friendly translation available for this attribute?
if ($_SESSION[APPCONFIG]->haveFriendlyName($a)) {
$attr_display = sprintf('%s (%s)',
htmlspecialchars($_SESSION[APPCONFIG]->getFriendlyName($a)),
htmlspecialchars($a));
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 '</form>';
} else {
echo '<br />';
printf('<small>(%s)</small>',_('no new binary attributes available for this entry'));
}
} else {
$attr_display = htmlspecialchars($a);
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();
}
printf('<option value="%s">%s</option>',htmlspecialchars($a),$attr_display);
} else {
printf('<small>(%s)</small>',_('no new attributes available for this entry'));
}
echo '</center>';
# 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 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="displayAJ(\'%s\',\'cmd=add_value_form&server_id=%s&dn=%s&meth=ajax&attr=\'+this.value,\'%s\',\'append\');">',
'ADDATTR',$app['server']->getIndex(),rawurlencode(get_request('dn','REQUEST')),_('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 '<input type="text" name="val" size="20" />';
printf('<input type="submit" name="submit" value="%s" class="update_dn" />',_('Add'));
echo '</form>';
} else {
echo '<br />';
printf('<small>(%s)</small>',_('no new attributes available for this entry'));
}
if (count($ldap['binattrs']['avail']) > 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 '<input type="hidden" name="cmd" value="add_attr" />';
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
printf('<input type="hidden" name="dn" value="%s" />',$entry['dn']['string']);
echo '<input type="hidden" name="binary" value="true" />';
echo '<select name="attr">';
$attr_select_html = '';
usort($ldap['binattrs']['avail'],'sortAttrs');
foreach ($ldap['binattrs']['avail'] as $a) {
# is there a user-friendly translation available for this attribute?
if ($_SESSION[APPCONFIG]->haveFriendlyName($a)) {
$attr_display = sprintf('%s (%s)',
htmlspecialchars($_SESSION[APPCONFIG]->getFriendlyName($a)),
htmlspecialchars($a));
} else {
$attr_display = htmlspecialchars($a);
}
printf('<option value="%s">%s</option>',htmlspecialchars($a),$attr_display);
}
echo '</select>';
echo '<input type="file" name="val" 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 '</form>';
} else {
echo '<br />';
printf('<small>(%s)</small>',_('no new binary attributes available for this entry'));
}
echo '</center>';
/**
* Given an attribute $x, this returns true if it is NOT already specified
* in the current entry, returns false otherwise.
*
* @param attr $x
* @return bool
* @ignore
*/
function not_an_attr($x) {
global $dn;
foreach ($dn['attrs'] as $attr => $values)
if (strcasecmp($attr,$x) == 0)
return false;
return true;
echo '</td>';
echo '</table>';
echo '</div>';
echo '</fieldset>';
}
?>