phpldapadmin/htdocs/add_oclass_form.php

118 lines
4.1 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 09:29:51 +00:00
/**
* This page will allow the adding of additional ObjectClasses to an item.
* + If the ObjectClass to be added requires additional MUST attributes to be
* defined, then they will be prompted for.
* + If the ObjectClass doesnt need any additional MUST attributes, then it
* will be silently added to the object.
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 08:07:14 +00:00
require './common.php';
2009-06-30 09:40:37 +00:00
# The DN and OBJECTCLASS we are working with.
$request = array();
$request['dn'] = get_request('dn','REQUEST',true);
2009-06-30 08:05:37 +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 08:05:37 +00:00
$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();
2009-06-30 09:29:51 +00:00
$attribute_factory = new AttributeFactory();
2009-06-30 08:09:20 +00:00
2009-06-30 10:46:00 +00:00
# Grab the required attributes for the new objectClass
$ldap = array();
2009-06-30 10:46:00 +00:00
$ldap['attrs']['must'] = array();
2009-06-30 08:09:20 +00:00
foreach ($request['template']->getAttribute('objectclass')->getValues() as $oclass_name) {
# Exclude "top" if its there.
if (! strcasecmp('top',$oclass_name))
continue;
if ($soc = $app['server']->getSchemaObjectClass($oclass_name))
$ldap['attrs']['must'] = array_merge($ldap['attrs']['must'],$soc->getMustAttrNames(true));
2009-06-30 10:46:00 +00:00
}
2009-06-30 10:46:00 +00:00
$ldap['attrs']['must'] = array_unique($ldap['attrs']['must']);
2009-06-30 08:09:20 +00:00
2009-06-30 10:46:00 +00:00
/* Build a list of the attributes that this new objectClass requires,
* but that the object does not currently contain */
2009-06-30 10:46:00 +00:00
$ldap['attrs']['need'] = array();
foreach ($ldap['attrs']['must'] as $attr)
if (is_null($request['template']->getAttribute($attr)))
array_push($ldap['attrs']['need'],$attribute_factory->newAttribute($attr,array('values'=>array()),$app['server']->getIndex()));
2009-06-30 09:29:51 +00:00
# Mark all the need attributes as shown
foreach ($ldap['attrs']['need'] as $index => $values)
$ldap['attrs']['need'][$index]->show();
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (count($ldap['attrs']['need']) > 0) {
$request['page']->drawTitle(sprintf('%s <b>%s</b>',_('Add new objectClass to'),get_rdn($request['dn'])));
$request['page']->drawSubTitle();
2009-06-30 09:29:51 +00:00
2010-02-24 15:03:10 +00:00
echo '<div style="text-align: center">';
2009-06-30 10:46:00 +00:00
printf('<small><b>%s: </b>%s <b>%s</b> %s %s</small>',
_('Instructions'),
_('In order to add these objectClass(es) to this entry, you must specify'),
count($ldap['attrs']['need']),_('new attributes'),
_('that this objectClass requires.'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
echo '<br /><br />';
2009-06-30 08:05:37 +00:00
2010-02-24 15:03:10 +00:00
echo '<form action="cmd.php" method="post" id="entry_form">';
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']));
2010-02-24 15:03:10 +00:00
echo '</div>';
2009-06-30 09:29:51 +00:00
2010-02-24 15:03:10 +00:00
echo '<table class="entry" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto;">';
2009-06-30 10:46:00 +00:00
printf('<tr><th colspan="2">%s</th></tr>',_('New Required Attributes'));
2009-06-30 09:29:51 +00:00
$counter = 0;
2010-02-24 15:03:10 +00:00
echo '<tr><td colspan="2">';
foreach ($request['template']->getAttribute('objectclass')->getValues() as $value)
$request['page']->draw('HiddenValue',$request['template']->getAttribute('objectclass'),$counter++);
2010-02-24 15:03:10 +00:00
echo '</td></tr>';
2009-06-30 08:05:37 +00:00
foreach ($ldap['attrs']['need'] as $count => $attr)
$request['page']->draw('Template',$attr);
2009-06-30 10:46:00 +00:00
echo '</table>';
2009-06-30 09:29:51 +00:00
2010-02-24 15:03:10 +00:00
printf('<div style="text-align: center;"><br /><input type="submit" value="%s" /></div>',_('Add ObjectClass and Attributes'));
2009-06-30 10:46:00 +00:00
echo '</form>';
2010-02-24 15:03:10 +00:00
echo '</div>';
2009-06-30 08:05:37 +00:00
# There are no other required attributes, so we just need to add the objectclass to the DN.
2009-06-30 10:46:00 +00:00
} else {
$result = $app['server']->modify($request['dn'],$request['template']->getLDAPmodify());
2009-06-30 09:29:51 +00:00
if ($result) {
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs[]=objectclass',
$app['server']->getIndex(),rawurlencode($request['dn']));
2009-06-30 08:05:37 +00:00
2010-03-13 09:45:40 +00:00
if (get_request('meth','REQUEST') == 'ajax')
$href .= '&meth=ajax';
2009-06-30 10:46:00 +00:00
header(sprintf('Location: %s',$href));
die();
}
2009-06-30 08:05:37 +00:00
}
?>