phpldapadmin/htdocs/add_oclass_form.php

138 lines
4.6 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 10:40:03 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_oclass_form.php,v 1.24 2005/12/10 10:34:54 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 via common.php
2009-06-30 08:05:37 +00:00
* - server_id
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 09:29:51 +00:00
if( $ldapserver->isReadOnly() )
2009-06-30 10:26:08 +00:00
pla_error( _('You cannot perform updates while server is in read-only mode') );
2009-06-30 09:29:51 +00:00
if( ! $ldapserver->haveAuthInfo())
2009-06-30 10:26:08 +00:00
pla_error( _('Not enough information to login to server. Please check your configuration.') );
2009-06-30 08:07:14 +00:00
2009-06-30 10:26:08 +00:00
if (! isset($_REQUEST['new_oclass']))
pla_error( _('You did not select any ObjectClasses for this object. Please go back and do so.'));
2009-06-30 09:40:37 +00:00
2009-06-30 09:29:51 +00:00
$new_oclass = $_REQUEST['new_oclass'];
$dn = rawurldecode( $_REQUEST['dn'] );
$encoded_dn = rawurlencode( $dn );
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
* newly required attrs. */
2009-06-30 10:26:08 +00:00
$entry = $ldapserver->getDNAttrs($dn,true);
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
$current_attrs = array();
foreach( $entry as $attr => $junk )
$current_attrs[] = strtolower($attr);
2009-06-30 08:09:20 +00:00
2009-06-30 08:05:37 +00:00
// grab the required attributes for the new objectClass
2009-06-30 09:40:37 +00:00
$schema_oclasses = $ldapserver->SchemaObjectClasses();
2009-06-30 09:29:51 +00:00
$must_attrs = array();
foreach( $new_oclass as $oclass_name ) {
2009-06-30 09:40:37 +00:00
$oclass = $ldapserver->getSchemaObjectClass($oclass_name);
2009-06-30 09:29:51 +00:00
if( $oclass )
$must_attrs = array_merge( $must_attrs, $oclass->getMustAttrNames( $schema_oclasses ) );
}
$must_attrs = array_unique( $must_attrs );
2009-06-30 08:09:20 +00:00
// We don't want any of the attr meta-data, just the string
2009-06-30 09:22:30 +00:00
//foreach( $must_attrs as $i => $attr )
//$must_attrs[$i] = $attr->getName();
2009-06-30 08:09:20 +00:00
2009-06-30 08:05:37 +00:00
// build a list of the attributes that this new objectClass requires,
// but that the object does not currently contain
$needed_attrs = array();
2009-06-30 09:22:30 +00:00
foreach( $must_attrs as $attr ) {
2009-06-30 09:40:37 +00:00
$attr = $ldapserver->getSchemaAttribute($attr);
2009-06-30 09:29:51 +00:00
//echo "<pre>"; var_dump( $attr ); echo "</pre>";
// 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 ), $current_attrs ) )
// Skip this attribute since it's already in the entry
continue;
2009-06-30 09:22:30 +00:00
if( in_array( strtolower($attr->getName()), $current_attrs ) )
2009-06-30 09:29:51 +00:00
continue;
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
// We made it this far, so the attribute needs to be added to this entry in order
// to add this objectClass
$needed_attrs[] = $attr;
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if( count( $needed_attrs ) > 0 ) {
2009-06-30 09:22:30 +00:00
include './header.php'; ?>
2009-06-30 08:05:37 +00:00
<body>
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
<h3 class="title"><?php echo _('New Required Attributes'); ?></h3>
<h3 class="subtitle"><?php echo _('This action requires you to add') . ' ' . count($needed_attrs) .
' ' . _('new attributes'); ?></h3>
2009-06-30 08:05:37 +00:00
<small>
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
<?php echo _('Instructions: In order to add these objectClass(es) to this entry, you must specify');
echo ' ' . count( $needed_attrs ) . ' ' . _('new attributes') . ' ';
echo _('that this objectClass requires. You can do so in this form.'); ?>
2009-06-30 09:29:51 +00:00
2009-06-30 08:07:14 +00:00
</small>
2009-06-30 08:05:37 +00:00
<br />
<br />
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
<form action="add_oclass.php" method="post">
2009-06-30 09:29:51 +00:00
<input type="hidden" name="new_oclass" value="<?php echo rawurlencode( serialize( $new_oclass ) ); ?>" />
2009-06-30 08:05:37 +00:00
<input type="hidden" name="dn" value="<?php echo $encoded_dn; ?>" />
2009-06-30 09:29:51 +00:00
<input type="hidden" name="server_id" value="<?php echo $ldapserver->server_id; ?>" />
2009-06-30 08:05:37 +00:00
<table class="edit_dn" cellspacing="0">
2009-06-30 10:26:08 +00:00
<tr><th colspan="2"><?php echo _('New Required Attributes'); ?></th></tr>
2009-06-30 08:05:37 +00:00
<?php foreach( $needed_attrs as $count => $attr ) { ?>
2009-06-30 09:29:51 +00:00
2009-06-30 09:22:30 +00:00
<tr><td class="attr"><b><?php echo htmlspecialchars($attr->getName()); ?></b></td></tr>
2009-06-30 09:29:51 +00:00
<tr><td class="val"><input type="text" name="new_attrs[<?php echo htmlspecialchars($attr->getName()); ?>]" value="" size="40" /></tr>
<?php } ?>
2009-06-30 08:05:37 +00:00
</table>
<br />
<br />
2009-06-30 10:26:08 +00:00
<center><input type="submit" value="<?php echo _('Add ObjectClass and Attributes'); ?>" /></center>
2009-06-30 08:05:37 +00:00
</form>
</body>
</html>
2009-06-30 09:29:51 +00:00
<?php } else {
2009-06-30 10:26:08 +00:00
$add_res = $ldapserver->attrModify($dn,array('objectClass'=>$new_oclass));
2009-06-30 09:29:51 +00:00
if (! $add_res)
pla_error("Could not perform ldap_mod_add operation.",
2009-06-30 09:40:37 +00:00
$ldapserver->error(),$ldapserver->errno());
2009-06-30 08:05:37 +00:00
else
2009-06-30 10:26:08 +00:00
header(sprintf('Location: template_engine.php?server_id=%s&dn=%s&modified_attrs[]=objectClass',
2009-06-30 09:29:51 +00:00
$ldapserver->server_id,$encoded_dn));
2009-06-30 08:05:37 +00:00
}
?>