phpldapadmin/add_oclass.php

71 lines
2.0 KiB
PHP
Raw Normal View History

2009-06-30 08:05:37 +00:00
<?php
2009-06-30 09:24:29 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/add_oclass.php,v 1.14 2005/03/20 04:43:36 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:24:29 +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:24:29 +00:00
* Variables that come in as POST vars:
2009-06-30 08:05:37 +00:00
* - dn (rawurlencoded)
* - server_id
* - new_oclass
* - new_attrs (array, if any)
2009-06-30 09:24:29 +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:24:29 +00:00
$server_id = (isset($_POST['server_id']) ? $_POST['server_id'] : '');
$ldapserver = new LDAPServer($server_id);
if( $ldapserver->isReadOnly() )
pla_error( $lang['no_updates_in_read_only_mode'] );
if( ! $ldapserver->haveAuthInfo())
pla_error( $lang['not_enough_login_info'] );
2009-06-30 08:07:14 +00:00
$dn = rawurldecode( $_POST['dn'] );
$new_oclass = $_POST['new_oclass'];
2009-06-30 08:05:37 +00:00
$new_attrs = $_POST['new_attrs'];
2009-06-30 09:24:29 +00:00
$encoded_dn = rawurlencode( $dn );
2009-06-30 08:07:14 +00:00
2009-06-30 09:24:29 +00:00
if( is_attr_read_only( $ldapserver, 'objectClass' ) )
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 09:24:29 +00:00
if( $badattr = checkUniqueAttr( $ldapserver, $dn, $attr, array($val) ) ) {
$search_href = sprintf('search.php?search=true&form=advanced&server_id=%s&filter=%s=%s',$server_id,$attr,$badattr);
pla_error(sprintf( $lang['unique_attr_failed'],$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 09:24:29 +00:00
//echo "<pre>";
2009-06-30 08:05:37 +00:00
//print_r( $new_entry );
//exit;
2009-06-30 09:24:29 +00:00
$add_res = @ldap_mod_add( $ldapserver->connect(), $dn, $new_entry );
2009-06-30 08:05:37 +00:00
2009-06-30 09:24:29 +00:00
if( ! $add_res ) {
pla_error( $lang['could_not_perform_ldap_mod_add'],ldap_error($ldapserver->connect()),ldap_errno($ldapserver->connect()) );
} else {
2009-06-30 09:22:30 +00:00
header( "Location: edit.php?server_id=$server_id&dn=$encoded_dn&modified_attrs[]=objectclass" );
2009-06-30 08:05:37 +00:00
}
?>