1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
<?php
/**
* Displays a form to allow the user to enter a new value to add
* to the existing list of values for a multi-valued attribute.
*
* @package phpLDAPadmin
* @subpackage Page
*/
/**
*/
require './common.php';
# The DN and ATTR we are working with.
$request = array();
$request['dn'] = get_request('dn','GET',true);
$request['attr'] = get_request('attr','GET',true);
# Check if the entry exists.
if (! $request['dn'] || ! $app['server']->dnExists($request['dn']))
error(sprintf(_('The entry (%s) does not exist.'),htmlspecialchars($request['dn'])),'error','index.php');
$request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null));
$request['page']->setDN($request['dn']);
$request['page']->accept(true);
$request['template'] = $request['page']->getTemplate();
/*
if ($request['attribute']->isReadOnly())
error(sprintf(_('The attribute (%s) is in readonly mode.'),$request['attr']),'error','index.php');
*/
# Render the form
if (! strcasecmp($request['attr'],'objectclass') || get_request('meth','REQUEST') != 'ajax') {
# Render the form.
$request['page']->drawTitle(sprintf(_('Add new <b>%s</b> value to <b>%s</b>'), htmlspecialchars($request['attr']),htmlspecialchars(get_rdn($request['dn']))));
$request['page']->drawSubTitle();
if (! strcasecmp($request['attr'],'objectclass')) {
echo '<form action="cmd.php" method="post" class="new_value" id="entry_form">';
echo '<div>';
echo '<input type="hidden" name="cmd" value="add_oclass_form" />';
} else {
echo '<form action="cmd.php" method="post" class="new_value" id="entry_form" enctype="multipart/form-data" onsubmit="return submitForm(this)">';
echo '<div>';
if ($_SESSION[APPCONFIG]->getValue('confirm','update'))
echo '<input type="hidden" name="cmd" value="update_confirm" />';
else
echo '<input type="hidden" name="cmd" value="update" />';
}
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',htmlspecialchars($request['dn']));
echo '</div>';
echo '<table class="forminput" border="0" style="margin-left: auto; margin-right: auto;">';
echo '<tr>';
$request['attribute'] = $request['template']->getAttribute($request['attr']);
$request['count'] = $request['attribute']->getValueCount();
if ($request['count']) {
printf('<td class="top">' . _('Current list of <b>%s</b> values for attribute <b>%s</b>:') . '</td>',
$request['count'],$request['attribute']->getFriendlyName());
echo '<td>';
# Display current attribute values
echo '<table border="0"><tr><td>';
for ($i=0;$i<$request['count'];$i++) {
if ($i > 0)
echo '<br/>';
$request['page']->draw('CurrentValue',$request['attribute'],$i);
$request['page']->draw('HiddenValue',$request['attribute'],$i);
}
echo '</td></tr></table>';
echo '</td>';
} else {
printf('<td>' . _('No current value for attribute <b>%s</b>.') . '</td>',
$request['attribute']->getFriendlyName());
echo '<td><br /><br /></td>';
}
echo '</tr>';
echo '<tr>';
printf('<td class="top">%s</td>',_('Enter the values you would like to add:'));
echo '<td>';
if (! strcasecmp($request['attr'],'objectclass')) {
# If our attr is an objectClass, fetch all available objectClasses and remove those from the list that are already defined in the entry
$socs = $app['server']->SchemaObjectClasses();
foreach ($request['attribute']->getValues() as $oclass)
unset($socs[strtolower($oclass)]);
# Draw objectClass selection
echo '<table border="0">';
echo '<tr><td>';
echo '<select name="new_values[objectclass][]" multiple="multiple" size="15">';
foreach ($socs as $name => $oclass) {
# Exclude any structural ones, that are not in the heirachy, as they'll only generate an LDAP_OBJECT_CLASS_VIOLATION
if (($oclass->getType() == 'structural') && ! $oclass->isRelated($request['attribute']->getValues()))
continue;
printf('<option value="%s">%s</option>',$oclass->getName(false),$oclass->getName(false));
}
echo '</select>';
echo '</td></tr><tr><td>';
echo '<br />';
printf('<input id="save_button" type="submit" value="%s" %s />',
_('Add new object class'),
(isAjaxEnabled() ? sprintf('onclick="return ajSUBMIT(\'BODY\',document.getElementById(\'entry_form\'),\'%s\');"',_('Updating object')) : ''));
echo '</td></tr></table>';
echo '</td>';
echo '</tr>';
if ($_SESSION[APPCONFIG]->getValue('appearance','show_hints'))
printf('<tr><td colspan="2"><small><br /><img src="%s/light.png" alt="Hint" /><span class="hint">%s</span></small></td></tr>',
IMGDIR,_('Note: You may be required to enter new attributes that these object classes require'));
echo '</table>';
echo '</form>';
} else {
# Draw a blank field
echo '<table border="0"><tr><td>';
$request['page']->draw('FormValue',$request['attribute'],$request['count']);
echo '</td></tr><tr><td>';
$sattr = $app['server']->getSchemaAttribute($request['attr']);
if ($sattr->getDescription())
printf('<small><b>%s:</b> %s</small><br />',_('Description'),$sattr->getDescription());
if ($sattr->getType())
printf('<small><b>%s:</b> %s</small><br />',_('Syntax'),$sattr->getType());
if ($sattr->getMaxLength())
printf('<small>' . _('<b>Maximum length:</b> %s characters') . '</small><br />',
number_format($sattr->getMaxLength()));
echo '<br />';
printf('<input type="submit" id="save_button" name="submit" value="%s" />',_('Add value'));
echo '</td></tr></table>';
echo '</td></tr>';
echo '</table>';
echo '</form>';
}
} else {
if (is_null($attribute = $request['template']->getAttribute($request['attr']))) {
$request['template']->addAttribute($request['attr'],array('values'=>array()));
$attribute = $request['template']->getAttribute($request['attr']);
$attribute->show();
echo '<table class="entry" cellspacing="0" align="center" border="0">';
$request['page']->draw('Template',$attribute);
$request['page']->draw('Javascript',$attribute);
echo '</table>';
} else {
$request['count'] = $attribute->getValueCount();
$request['page']->draw('FormReadWriteValue',$attribute,$request['count']);
}
}
?>
|