LDAPAccountManager/lam/templates/3rdParty/pla/htdocs/add_value_form.php

174 lines
6.0 KiB
PHP
Raw Normal View History

2011-06-26 10:44:28 +00:00
<?php
/**
* 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.
*
* @package phpLDAPadmin
* @subpackage Page
*/
/**
*/
require './common.php';
# The DN and ATTR we are working with.
$request = array();
$request['dn'] = get_request('dn','GET',true);
$request['attr'] = get_request('attr','GET',true);
# 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');
$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();
/*
if ($request['attribute']->isReadOnly())
error(sprintf(_('The attribute (%s) is in readonly mode.'),$request['attr']),'error','index.php');
*/
# Render the form
if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST') != 'ajax') {
# Render the form.
2011-07-12 19:23:27 +00:00
$request['page']->drawTitle(sprintf(_('Add new <b>%s</b> value to <b>%s</b>'),$request['attr'],get_rdn($request['dn'])));
2011-06-26 10:44:28 +00:00
$request['page']->drawSubTitle();
if (! strcasecmp($request['attr'],'objectclass')) {
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 {
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" />';
}
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
echo '</div>';
echo '<table class="forminput" border="0" style="margin-left: auto; margin-right: auto;">';
echo '<tr>';
$request['attribute'] = $request['template']->getAttribute($request['attr']);
$request['count'] = $request['attribute']->getValueCount();
if ($request['count']) {
2011-07-13 18:30:14 +00:00
printf('<td class="top">' . _('Current list of <b>%s</b> values for attribute <b>%s</b>:') . '</td>',
$request['count'],$request['attribute']->getFriendlyName());
2011-06-26 10:44:28 +00:00
echo '<td>';
# Display current attribute values
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>';
echo '</td>';
} else {
2011-07-13 18:30:14 +00:00
printf('<td>' . _('No current value for attribute <b>%s</b>.') . '</td>',
$request['attribute']->getFriendlyName());
2011-06-26 10:44:28 +00:00
echo '<td><br /><br /></td>';
}
echo '</tr>';
echo '<tr>';
printf('<td class="top">%s</td>',_('Enter the value(s) you would like to add:'));
echo '<td>';
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
echo '<table border="0">';
echo '<tr><td>';
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));
}
echo '</select>';
echo '</td></tr><tr><td>';
echo '<br />';
printf('<input id="save_button" type="submit" value="%s" %s />',
2011-07-12 19:23:27 +00:00
_('Add new object class'),
2011-06-26 10:44:28 +00:00
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'entry_form\'),\'%s\');"',_('Updating Object')) : ''));
echo '</td></tr></table>';
echo '</td>';
echo '</tr>';
if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints'))
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
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())
2011-07-13 18:30:14 +00:00
printf('<small>' . _('<b>Maximum length:</b> %s characters') . '</small><br />',
number_format($sattr->getMaxLength()));
2011-06-26 10:44:28 +00:00
echo '<br />';
2011-07-12 19:23:27 +00:00
printf('<input type="submit" id="save_button" name="submit" value="%s" />',_('Add value'));
2011-06-26 10:44:28 +00:00
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();
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']);
}
}
?>