phpldapadmin/htdocs/add_value_form.php

172 lines
5.8 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
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
*
* @package phpLDAPadmin
* @subpackage Page
2009-06-30 09:29:51 +00:00
*/
2009-06-30 09:29:51 +00:00
/**
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:46:00 +00:00
# The DN and ATTR we are working with.
$request = array();
$request['dn'] = get_request('dn','GET',true);
$request['attr'] = get_request('attr','GET',true);
2009-06-30 10:26:08 +00:00
# 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');
2009-06-30 09:29:51 +00:00
$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();
2009-06-30 09:29:51 +00:00
/*
if ($request['attribute']->isReadOnly())
error(sprintf(_('The attribute (%s) is in readonly mode.'),$request['attr']),'error','index.php');
*/
# Render the form
if (get_request('meth','REQUEST') != 'ajax') {
# Render the form.
$request['page']->drawTitle(sprintf('%s <b>%s</b> %s <b>%s</b>',_('Add new'),$request['attr'],_('value to'),get_rdn($request['dn'])));
$request['page']->drawSubTitle();
if (! strcasecmp($request['attr'],'objectclass')) {
2010-02-24 15:03:10 +00:00
echo '<form action="cmd.php" method="post" class="new_value" id="entry_form">';
echo '<div>';
echo '<input type="hidden" name="cmd" value="add_oclass_form" />';
} else {
2010-02-24 15:03:10 +00:00
echo '<form action="cmd.php" method="post" class="new_value" id="entry_form" enctype="multipart/form-data" onsubmit="return submitForm(this)">';
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" />';
}
2009-06-30 11:52:55 +00:00
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
2010-02-24 15:03:10 +00:00
echo '</div>';
2009-06-30 08:05:37 +00:00
2010-02-24 15:03:10 +00:00
echo '<table class="forminput" border="0" style="margin-left: auto; margin-right: auto;">';
echo '<tr>';
2009-06-30 10:46:00 +00:00
$request['attribute'] = $request['template']->getAttribute($request['attr']);
$request['count'] = $request['attribute']->getValueCount();
2009-06-30 10:46:00 +00:00
if ($request['count']) {
printf('<td class="top">%s <b>%s</b> %s <b>%s</b>:</td>',
_('Current list of'),$request['count'],_('values for attribute'),$request['attribute']->getFriendlyName());
2009-06-30 08:05:37 +00:00
echo '<td>';
2009-06-30 09:29:51 +00:00
# Display current attribute values
2010-02-24 15:03:10 +00:00
echo '<table border="0"><tr><td>';
for ($i=0;$i<$request['count'];$i++) {
if ($i > 0)
echo '<br/>';
$request['page']->draw('CurrentValue',$request['attribute'],$i);
$request['page']->draw('HiddenValue',$request['attribute'],$i);
}
echo '</td></tr></table>';
2009-06-30 11:51:50 +00:00
echo '</td>';
2009-06-30 11:51:50 +00:00
} else {
printf('<td>%s <b>%s</b>.</td>',
_('No current value for attribute'),$request['attribute']->getFriendlyName());
echo '<td><br /><br /></td>';
2009-06-30 10:26:08 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 11:51:50 +00:00
echo '</tr>';
2009-06-30 09:29:51 +00:00
echo '<tr>';
printf('<td class="top">%s</td>',_('Enter the value(s) you would like to add:'));
echo '<td>';
2009-06-30 09:29:51 +00:00
if (! strcasecmp($request['attr'],'objectclass')) {
# If our attr is an objectClass, fetch all available objectClasses and remove those from the list that are already defined in the entry
$socs = $app['server']->SchemaObjectClasses();
foreach ($request['attribute']->getValues() as $oclass)
unset($socs[strtolower($oclass)]);
# Draw objectClass selection
2010-02-24 15:03:10 +00:00
echo '<table border="0">';
echo '<tr><td>';
2010-02-24 15:03:10 +00:00
echo '<select name="new_values[objectclass][]" multiple="multiple" size="15">';
foreach ($socs as $name => $oclass) {
# Exclude any structural ones, that are not in the heirachy, as they'll only generate an LDAP_OBJECT_CLASS_VIOLATION
if (($oclass->getType() == 'structural') && ! $oclass->isRelated($request['attribute']->getValues()))
continue;
printf('<option value="%s">%s</option>',$oclass->getName(false),$oclass->getName(false));
2009-06-30 10:46:00 +00:00
}
echo '</select>';
echo '</td></tr><tr><td>';
echo '<br />';
printf('<input id="save_button" type="submit" value="%s" />',_('Add new ObjectClass'));
echo '</td></tr></table>';
echo '</td>';
echo '</tr>';
if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints'))
2010-02-24 15:03:10 +00:00
printf('<tr><td colspan="2"><small><br /><img src="%s/light.png" alt="Hint" /><span class="hint">%s</span></small></td></tr>',
IMGDIR,_('Note: You may be required to enter new attributes that these objectClass(es) require'));
echo '</table>';
echo '</form>';
} else {
# Draw a blank field
2010-02-24 15:03:10 +00:00
echo '<table border="0"><tr><td>';
$request['page']->draw('FormValue',$request['attribute'],$request['count']);
echo '</td></tr><tr><td>';
$sattr = $app['server']->getSchemaAttribute($request['attr']);
if ($sattr->getDescription())
printf('<small><b>%s:</b> %s</small><br />',_('Description'),$sattr->getDescription());
if ($sattr->getType())
printf('<small><b>%s:</b> %s</small><br />',_('Syntax'),$sattr->getType());
if ($sattr->getMaxLength())
printf('<small><b>%s:</b> %s %s</small><br />',
_('Maximum Length'),number_format($sattr->getMaxLength()),_('characters'));
echo '<br />';
printf('<input type="submit" id="save_button" name="submit" value="%s" />',_('Add New Value'));
echo '</td></tr></table>';
echo '</td></tr>';
echo '</table>';
echo '</form>';
}
} else {
if (is_null($attribute = $request['template']->getAttribute($request['attr']))) {
$request['template']->addAttribute($request['attr'],array('values'=>array()));
$attribute = $request['template']->getAttribute($request['attr']);
$attribute->show();
2010-02-24 15:03:10 +00:00
echo '<table class="entry" cellspacing="0" align="center" border="0">';
$request['page']->draw('Template',$attribute);
$request['page']->draw('Javascript',$attribute);
echo '</table>';
} else {
$request['count'] = $attribute->getValueCount();
$request['page']->draw('FormReadWriteValue',$attribute,$request['count']);
}
2009-06-30 10:26:08 +00:00
}
?>