0 ) pla_error( "You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)" ); check_server_id( $server_id ) or pla_error( "Bad server_id: " . htmlspecialchars( $server_id ) ); have_auth_info( $server_id ) or pla_error( "Not enough information to login to server. Please check your configuration." ); $ds = pla_ldap_connect( $server_id ) or pla_error( "Could not connect to LDAP sever" ); $container = get_container( $dn ); $new_dn = $new_rdn . ',' . $container; if( $new_dn == $dn ) pla_error( "You did not change the RDN" ); $dn_attr = explode( '=', $dn ); $dn_attr = $dn_attr[0]; $old_dn_value = pla_explode_dn( $dn ); $old_dn_value = explode( '=', $old_dn_value[0], 2 ); $old_dn_value = $old_dn_value[1]; $new_dn_value = explode( '=', $new_rdn, 2 ); $new_dn_value = $new_dn_value[1]; // Add the new DN attr value to the DN attr (ie, add newName to cn) $add_new_dn_attr = array( $dn_attr => $new_dn_value ); // Remove the old DN attr value $remove_old_dn_attr = array( $dn_attr => $old_dn_value ); // attempt to add the new DN attr value (if we can't, die a silent death) $add_dn_attr_success = @ldap_mod_add( $ds, $dn, $add_new_dn_attr ); if( ! @ldap_rename( $ds, $dn, $new_rdn, $container, false ) ) { pla_error( "Could not rename the object.", ldap_error( $ds ), ldap_errno( $ds ), false ); // attempt to undo our changes to the DN attr if( $add_dn_attr_success ) @ldap_mod_del( $ds, $dn, $add_new_dn_attr ); } else { // attempt to remove the old DN attr value (if we can't, die a silent death) @ldap_mod_del( $ds, $new_dn, $remove_old_dn_attr ); // update the session tree to reflect the name change session_start(); if( session_is_registered( 'tree' ) ) { $tree = $_SESSION['tree']; $tree_icons = $_SESSION['tree_icons']; $old_dn = $dn; // gotta search the whole tree for the entry (must be a leaf node since RDN changes // cannot occur on parents) foreach( $tree[$server_id] as $parent_dn => $children ) { foreach( $children as $i => $child_dn ) { if( 0 == strcasecmp( $child_dn, $old_dn ) ) { $tree[$server_id][$parent_dn][$i] = $new_dn; } } } // Update the icon tree to reflect the change (remove the old DN and add the new one) $tree_icons[ $server_id ][ $new_dn ] = $tree_icons[ $server_id ][ $old_dn ]; unset( $tree_icons[ $server_id ][ $old_dn ] ); $_SESSION['tree'] = $tree; $_SESSION['tree_icons'] = $tree_icons; session_write_close(); $edit_url="edit.php?server_id=$server_id&dn=" . rawurlencode( "$new_rdn,$container" ); ?>
Redirecting... click here if you're impatient.