IOPLEX
Communications Software
Plexcel for PHP - Active Directory PHP Integration
plexcel_new
plexcel_status
plexcel_find_authorities_by_domain
plexcel_get_authority
plexcel_get_domain
plexcel_log
plexcel_preamble
plexcel_authenticate
plexcel_sso
plexcel_logon
plexcel_logoff
plexcel_accept_token
plexcel_is_member_of
plexcel_set_password
plexcel_change_password
plexcel_gen_service_keytab
plexcel_search_objects
plexcel_get_account
plexcel_add_object
plexcel_modify_object
plexcel_delete_object
plexcel_rename_object
plexcel_set_attrdefs
plexcel_get_attrdefs
plexcel_set_conv_attrdefs

plexcel_modify_object

Printer Friendly Format

Synopsis

bool plexcel_modify_object(resource $px, array $obj, array $attrs)

Description

The plexcel_modify_object function can add, delete and replace attributes of an object in the directory. Multiple attribute modifications of different types can be performed with a single call.

The $px parameter is the Plexcel context resource representing the directory binding and context specific options.

The $obj parameter is an array of attribute names and values representing the attributes being added, replaced or deleted. All modifications are performed on the object identified by the distinguishedName attribute in the $obj parameter and therefore it must be present.

The $attrs parameter is an array of attribute names and corresponding modification types. The modification types are described in the following table.

Flag Description
PLEXCEL_MOD_ADD This indicates that the value of the named attribute in the $obj array is to be added to the target object. If the attribute is multivalued, the value in $obj must be an array in which case all values will be added to the target object.
PLEXCEL_MOD_DELETE This indicates that the value of the named attribute in the $obj array is to be deleted from the target object. If the attribute is multivalued, the value in $obj must be an array in which case all values will be deleted from the target object. If no value for the named attribute is supplied in the $obj array, all attributes with that attribute name will be deleted in the target object.
PLEXCEL_MOD_REPLACE This indicates that the named attribute is to be replaced with the corresponding value in the $obj parameter. If the attribute does not exist, it will be created. IMPORANT: If the attribute is multivalued, all existing values are deleted and replaced with the values in the $obj parameter. For example, when setting a member attribute in a group object, if PLEXCEL_MOD_REPLACE is used, all existing members of the group will be deleted and completely replaced with only those members supplied through $obj which is probably not the desired behavior. Use PLEXCEL_MOD_ADD to add members to a group – see example below.

An $attrs element may also be only an attribute name with no modification type. In this case, the modification type will default to PLEXCEL_MOD_REPLACE . Meaning array('sn' => PLEXCEL_MOD_REPLACE) and array('sn') are equivalent.

Returns

The plexcel_modify_object function returns TRUE if the directory successfully processed all modifications. Otherwise, FALSE is returned in which case the plexcel_status function should be consulted.

Example

The following PHP fragment illustrates how to add a member to a group using plexcel_modify_object .

$gacct = array('distinguishedName' => 'CN=Managers,OU=Europe,DC=example,DC=com',
        'member' => array('CN=Hans Müller,CN=Users,DC=example,DC=com'));
$attrs = array('member' => PLEXCEL_MOD_ADD);

        if (plexcel_modify_object($px, $gacct, $attrs) == FALSE) {
      
    die('<pre>' . plexcel_status($px) . '</pre>');
}
Adding a user to a group with plexcel_modify_object

The following somewhat unrealistic PHP fragment demonstrates adding, replacing and deleting multiple attributes with one call to plexcel_modify_object .

$acct = array('distinguishedName' => 'CN=fs1,OU=Linux Servers,DC=example,DC=com');
$acct['servicePrincipalName'] = array(
            'host/fs1.example.com',
            'FTP/fs1.example.com',
            'cifs/fs1.example.com');
$acct['info'] = 'Storage for infrastructure and developers';
//
// add SPNs, replace info field and delete description field
//
$attrs = array('servicePrincipalName' => PLEXCEL_MOD_ADD,
               'info' => PLEXCEL_MOD_REPLACE,
               'description' => PLEXCEL_MOD_DELETE);

        if (plexcel_modify_object($px, $acct, $attrs) == FALSE) {
      
    $err = die('<pre>' . plexcel_status($px) . '</pre>');
}
Adding, replacing and deleting multiple attributes with one call to plexcel_modify_object

See also

plexcel_add_object | plexcel_delete_object | plexcel_rename_object

© 2008 IOPLEX Software | Contact Us | Policies