haveAuthInfo())
pla_error(_('Not enough information to login to server. Please check your configuration.'));
if ($step == 1) {
$oclasses = $ldapserver->SchemaObjectClasses();
if (! $oclasses || ! is_array($oclasses))
pla_error("Unable to retrieve the schema from your LDAP server. Cannot continue with creation.");
printf('
%s
',_('Step 1 of 2: Name and ObjectClass(es)'));
echo '';
} elseif ($step == 2) {
strlen(trim($rdn)) != 0 or
pla_error(_('You left the RDN field blank.'));
if (strlen(trim($container)) == 0 or
(! $ldapserver->dnExists($container) && ! in_array("$rdn,$container",$ldapserver->getBaseDN())))
pla_error(sprintf(_('The container you specified (%s) does not exist. Please try again.'),htmlspecialchars($container)));
$friendly_attrs = process_friendly_attr_table();
$oclasses = isset($_POST['object_classes']) ? $_POST['object_classes'] : null;
if (count($oclasses) == 0)
pla_error(_('You did not select any ObjectClasses for this object. Please go back and do so.'));
$dn = trim($container) ? $rdn.','.$container : $rdn;
# incrementally build up the all_attrs and required_attrs arrays
$schema_oclasses = $ldapserver->SchemaObjectClasses();
$required_attrs = array();
$all_attrs = array();
foreach ($oclasses as $oclass_name) {
$oclass = $ldapserver->getSchemaObjectClass($oclass_name);
if ($oclass) {
$required_attrs = array_merge($required_attrs,$oclass->getMustAttrNames($schema_oclasses));
$all_attrs = array_merge($all_attrs,$oclass->getMustAttrNames($schema_oclasses),$oclass->getMayAttrNames($schema_oclasses));
}
}
$required_attrs = array_unique($required_attrs);
$all_attrs = array_unique($all_attrs);
remove_aliases($required_attrs,$ldapserver);
remove_aliases($all_attrs,$ldapserver);
sort($required_attrs);
sort($all_attrs);
# remove required attrs from optional attrs
foreach ($required_attrs as $i => $attr_name) {
$key = array_search($attr_name,$all_attrs);
if (is_numeric($key))
unset($all_attrs[$key]);
}
# remove binary attributes and add them to the binary_attrs array
$binary_attrs = array();
foreach ($all_attrs as $i => $attr_name) {
if ($ldapserver->isAttrBinary($attr_name)) {
unset($all_attrs[$i]);
$binary_attrs[] = $attr_name;
}
}
/* If we trim any attrs out above, then we will have a gap in the index
sequence and will get an "undefined index" error below. This prevents
that from happening. */
$all_attrs = array_values($all_attrs);
/* add the required attribute based on the RDN provided by the user
(ie, if the user specifies "cn=Bob" for their RDN, make sure "cn" is
in the list of required attributes. */
$rdn_attr = trim(substr($rdn,0,strpos($rdn,'=')));
$rdn_value = trim(substr($rdn,strpos($rdn,'=')+1));
$rdn_value = @pla_explode_dn($rdn);
$rdn_value = @explode('=',$rdn_value[0],2);
$rdn_value = @$rdn_value[1];
if (in_array($rdn_attr,$all_attrs) && ! in_array($rdn_attr,$required_attrs))
$required_attrs[] = $rdn_attr;
printf('
%s
',_('Step 2 of 2: Specify attributes and values'));
echo '';
}
function get_attr_select_html($all_attrs,$friendly_attrs,$highlight_attr=null) {
$attr_select_html = "\n\n";
if (! is_array($all_attrs))
return null;
foreach ($all_attrs as $a) {
# is there a user-friendly translation available for this attribute?
if (isset($friendly_attrs[strtolower($a)]))
$attr_display = sprintf('%s (%s)',htmlspecialchars($friendly_attrs[strtolower($a)]),htmlspecialchars($a));
else
$attr_display = htmlspecialchars($a);
$a = htmlspecialchars($a);
$attr_select_html .= sprintf('',$attr_display);
}
return $attr_select_html;
}
function get_binary_attr_select_html($binary_attrs,$friendly_attrs,$highlight_attr=null) {
$binary_attr_select_html = '';
if (! is_array($binary_attrs))
return null;
if (count($binary_attrs) == 0)
return null;
foreach ($binary_attrs as $a) {
# is there a user-friendly translation available for this attribute?
if (isset($friendly_attrs[strtolower($a)]))
$attr_display = sprintf('%s (%s)',htmlspecialchars($friendly_attrs[strtolower($a)]),htmlspecialchars($a));
else
$attr_display = htmlspecialchars($a);
$binary_attr_select_html .= '',$attr_display);
}
return $binary_attr_select_html;
}
/**
* Removes attributes from the array that are aliases for eachother
* (just removes the second instance of the aliased attr)
*/
function remove_aliases(&$attribute_list,$ldapserver) {
# remove aliases from the attribute_list array
for ($i=0;$igetSchemaAttribute($attr_name1);
if (is_null($attr1))
continue;
for ($k=0;$kisAliasFor($attr_name2))
unset($attribute_list[$k]);
}
}
$attribute_list = array_values($attribute_list);
}
?>