isReadOnly()) error(_('You cannot perform updates while server is in read-only mode'),'error','index.php'); if (! $entry['oclass']['new']) error(_('You did not select any ObjectClasses for this object. Please go back and do so.'),'error','index.php'); /* 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. */ $entry['dn']['attrs'] = $ldapserver->getDNAttrs($entry['dn']['string'],true); $entry['attrs']['current'] = array(); foreach ($entry['dn']['attrs'] as $attr => $junk) $entry['attrs']['current'][] = strtolower($attr); # Grab the required attributes for the new objectClass $ldap['oclasses'] = $ldapserver->SchemaObjectClasses(); $ldap['attrs']['must'] = array(); foreach ($entry['oclass']['new'] as $oclass_name) { $ldap['oclass'] = $ldapserver->getSchemaObjectClass($oclass_name); if ($ldap['oclass']) $ldap['attrs']['must'] = array_merge($ldap['attrs']['must'],$ldap['oclass']->getMustAttrNames($ldap['oclasses'])); } $ldap['attrs']['must'] = array_unique($ldap['attrs']['must']); /* Build a list of the attributes that this new objectClass requires, * but that the object does not currently contain */ $ldap['attrs']['need'] = array(); foreach ($ldap['attrs']['must'] as $attr) { $attr = $ldapserver->getSchemaAttribute($attr); # 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),$entry['attrs']['current'])) continue; if (in_array(strtolower($attr->getName()),$entry['attrs']['current'])) continue; /* We made it this far, so the attribute needs to be added to this entry in order * to add this objectClass */ $ldap['attrs']['need'][] = $attr; } if (count($ldap['attrs']['need']) > 0) { printf('

%s

',_('New Required Attributes')); printf('

%s %s %s

',_('This action requires you to add'),count($ldap['attrs']['need']),_('new attributes')); printf('%s: %s %s %s %s', _('Instructions'), _('In order to add these objectClass(es) to this entry, you must specify'), count($ldap['attrs']['need']),_('new attributes'), _('that this objectClass requires.')); echo '

'; echo '
'; echo ''; printf('',rawurlencode(serialize($entry['oclass']['new']))); printf('',rawurlencode($entry['dn']['string'])); printf('',$ldapserver->server_id); echo ''; printf('',_('New Required Attributes')); foreach ($ldap['attrs']['need'] as $count => $attr) { printf('',htmlspecialchars($attr->getName())); printf('',htmlspecialchars($attr->getName())); } echo '
%s
%s
'; echo '

'; printf('
',_('Add ObjectClass and Attributes')); echo '
'; } else { $result = $ldapserver->attrModify($entry['dn']['string'],array('objectClass'=>$entry['oclass']['new'])); if (! $result) system_message(array( 'title'=>_('Could not perform ldap_mod_add operation.'), 'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()), 'type'=>'error')); else { $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs[]=objectClass', $ldapserver->server_id,rawurlencode($entry['dn']['string'])); header(sprintf('Location: %s',$href)); die(); } } ?>