phpldapadmin/htdocs/add_oclass.php

65 lines
2.1 KiB
PHP
Raw Normal View History

2009-06-30 08:05:37 +00:00
<?php
2009-06-30 10:26:08 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_oclass.php,v 1.17.2.5 2005/12/09 23:32:37 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* Adds an objectClass to the specified dn.
*
* Note, this does not do any schema violation checking. That is
* performed in add_oclass_form.php.
*
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 POST vars:
* - dn (rawurlencoded)
2009-06-30 08:05:37 +00:00
* - new_oclass
* - new_attrs (array, if any)
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
*/
/**
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 09:29:51 +00:00
2009-06-30 08:07:14 +00:00
$dn = rawurldecode( $_POST['dn'] );
2009-06-30 09:29:51 +00:00
$new_oclass = unserialize( rawurldecode( $_POST['new_oclass'] ) );
2009-06-30 08:05:37 +00:00
$new_attrs = $_POST['new_attrs'];
2009-06-30 09:29:51 +00:00
$encoded_dn = rawurlencode( $dn );
2009-06-30 08:07:14 +00:00
2009-06-30 10:26:08 +00:00
if ($ldapserver->isAttrReadOnly('objectClass'))
2009-06-30 09:29:51 +00:00
pla_error( "ObjectClasses are flagged as read only in the phpLDAPadmin configuration." );
2009-06-30 08:05:37 +00:00
$new_entry = array();
$new_entry['objectClass'] = $new_oclass;
$new_attrs_entry = array();
$new_oclass_entry = array( 'objectClass' => $new_oclass );
if( is_array( $new_attrs ) && count( $new_attrs ) > 0 )
2009-06-30 09:22:30 +00:00
foreach( $new_attrs as $attr => $val ) {
// Check to see if this is a unique Attribute
2009-06-30 10:26:08 +00:00
if ($badattr = $ldapserver->checkUniqueAttr($dn,$attr,array($val))) {
2009-06-30 09:29:51 +00:00
$search_href = sprintf('search.php?search=true&form=advanced&server_id=%s&filter=%s=%s',
$ldapserver->server_id,$attr,$badattr);
2009-06-30 10:26:08 +00:00
pla_error(sprintf( _('Your attempt to add <b>%s</b> (<i>%s</i>) to <br><b>%s</b><br> is NOT allowed. That attribute/value belongs to another entry.<p>You might like to <a href=\'%s\'>search</a> for that entry.'),$attr,$badattr,$dn,$search_href ) );
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
$new_entry[ $attr ] = $val;
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
$add_res = $ldapserver->attrModify($dn,$new_entry);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if (! $add_res)
2009-06-30 10:26:08 +00:00
pla_error(_('Could not perform ldap_mod_add operation.'),$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',$ldapserver->server_id,$encoded_dn));
2009-06-30 08:05:37 +00:00
?>