phpldapadmin/htdocs/add_oclass_form.php

126 lines
4.6 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 11:52:55 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_oclass_form.php,v 1.25.2.2 2008/12/12 12:20:22 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* This page may simply add the objectClass and take you back to the edit page,
* but, in one condition it may prompt the user for input. That condition is this:
*
* If the user has requested to add an objectClass that requires a set of
* attributes with 1 or more not defined by the object. In that case, we will
* present a form for the user to add those attributes to the object.
*
2009-06-30 09:29:51 +00:00
* Variables that come in as REQUEST vars:
* - dn (rawurlencoded)
2009-06-30 08:05:37 +00:00
* - new_oclass
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
2009-06-30 09:40:37 +00:00
* @todo If an attribute expects a DN, show the dn browser.
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 11:52:55 +00:00
$entry = array();
2009-06-30 10:46:00 +00:00
$entry['oclass']['new'] = get_request('new_oclass','REQUEST');
$entry['dn']['string'] = get_request('dn','REQUEST');
2009-06-30 08:07:14 +00:00
2009-06-30 10:46:00 +00:00
if ($ldapserver->isReadOnly())
2009-06-30 11:52:55 +00:00
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
2009-06-30 09:40:37 +00:00
2009-06-30 10:46:00 +00:00
if (! $entry['oclass']['new'])
2009-06-30 11:52:55 +00:00
error(_('You did not select any ObjectClasses for this object. Please go back and do so.'),'error','index.php');
2009-06-30 08:05:37 +00:00
/* Ensure that the object has defined all MUST attrs for this objectClass.
* If it hasn't, present a form to have the user enter values for all the
2009-06-30 10:46:00 +00:00
* newly required attrs.
*/
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
$entry['dn']['attrs'] = $ldapserver->getDNAttrs($entry['dn']['string'],true);
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$entry['attrs']['current'] = array();
foreach ($entry['dn']['attrs'] as $attr => $junk)
$entry['attrs']['current'][] = strtolower($attr);
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['oclasses'] = $ldapserver->SchemaObjectClasses();
$ldap['attrs']['must'] = array();
foreach ($entry['oclass']['new'] as $oclass_name) {
$ldap['oclass'] = $ldapserver->getSchemaObjectClass($oclass_name);
2009-06-30 08:09:20 +00:00
2009-06-30 10:46:00 +00:00
if ($ldap['oclass'])
$ldap['attrs']['must'] = array_merge($ldap['attrs']['must'],$ldap['oclass']->getMustAttrNames($ldap['oclasses']));
}
$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
*/
$ldap['attrs']['need'] = array();
foreach ($ldap['attrs']['must'] as $attr) {
2009-06-30 09:40:37 +00:00
$attr = $ldapserver->getSchemaAttribute($attr);
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
# First, check if one of this attr's aliases is already an attribute of this entry
foreach ($attr->getAliases() as $alias_attr_name)
if (in_array(strtolower($alias_attr_name),$entry['attrs']['current']))
2009-06-30 09:29:51 +00:00
continue;
2009-06-30 10:46:00 +00:00
if (in_array(strtolower($attr->getName()),$entry['attrs']['current']))
2009-06-30 09:29:51 +00:00
continue;
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
/* We made it this far, so the attribute needs to be added to this entry in order
* to add this objectClass */
$ldap['attrs']['need'][] = $attr;
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (count($ldap['attrs']['need']) > 0) {
printf('<h3 class="title">%s</h3>',_('New Required Attributes'));
printf('<h3 class="subtitle">%s %s %s</h3>',_('This action requires you to add'),count($ldap['attrs']['need']),_('new attributes'));
2009-06-30 09:29:51 +00:00
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
2009-06-30 10:46:00 +00:00
echo '<form action="cmd.php" method="post">';
echo '<input type="hidden" name="cmd" value="add_oclass" />';
printf('<input type="hidden" name="new_oclass" value="%s" />',rawurlencode(serialize($entry['oclass']['new'])));
printf('<input type="hidden" name="dn" value="%s" />',rawurlencode($entry['dn']['string']));
printf('<input type="hidden" name="server_id" value="%s" />',$ldapserver->server_id);
2009-06-30 09:29:51 +00:00
2009-06-30 11:51:50 +00:00
echo '<table class="entry" cellspacing="0">';
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
2009-06-30 10:46:00 +00:00
foreach ($ldap['attrs']['need'] as $count => $attr) {
2009-06-30 11:51:50 +00:00
printf('<tr><td class="title">%s</td></tr>',htmlspecialchars($attr->getName()));
printf('<tr><td class="value"><input type="text" name="new_attrs[%s]" value="" size="40" /></td></tr>',htmlspecialchars($attr->getName()));
2009-06-30 10:46:00 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
echo '</table>';
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
2009-06-30 10:46:00 +00:00
printf('<center><input type="submit" value="%s" /></center>',_('Add ObjectClass and Attributes'));
echo '</form>';
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
} else {
$result = $ldapserver->attrModify($entry['dn']['string'],array('objectClass'=>$entry['oclass']['new']));
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (! $result)
2009-06-30 11:52:55 +00:00
system_message(array(
'title'=>_('Could not perform ldap_mod_add operation.'),
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
'type'=>'error'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
else {
$href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs[]=objectClass',
$ldapserver->server_id,rawurlencode($entry['dn']['string']));
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
header(sprintf('Location: %s',$href));
die();
}
2009-06-30 08:05:37 +00:00
}
?>