phpldapadmin/htdocs/add_oclass.php

67 lines
2.2 KiB
PHP
Raw Normal View History

2009-06-30 08:05:37 +00:00
<?php
2009-06-30 10:46:00 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_oclass.php,v 1.19 2007/12/15 07:50:30 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* Adds an objectClass to the specified dn.
*
* Note, this does not do any schema violation checking. That is
* performed in add_oclass_form.php.
*
2009-06-30 09:29:51 +00:00
* Variables that come in as POST vars:
* - dn (rawurlencoded)
2009-06-30 08:05:37 +00:00
* - new_oclass
* - new_attrs (array, if any)
2009-06-30 09:29:51 +00:00
*
* @package phpLDAPadmin
*/
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:22:30 +00:00
require './common.php';
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if ($ldapserver->isReadOnly())
pla_error(_('You cannot perform updates while server is in read-only mode'));
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if ($ldapserver->isAttrReadOnly('objectClass'))
pla_error(_('ObjectClasses are flagged as read only in the phpLDAPadmin configuration.'));
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
$entry['dn']['encode'] = get_request('dn');
$entry['dn']['string'] = urldecode($entry['dn']['encode']);
2009-06-30 08:07:14 +00:00
2009-06-30 10:46:00 +00:00
$entry['new']['oclass'] = unserialize(rawurldecode(get_request('new_oclass')));
$entry['new']['attrs'] = get_request('new_attrs');
2009-06-30 08:05:37 +00:00
$new_entry = array();
2009-06-30 10:46:00 +00:00
$new_entry['objectClass'] = $entry['new']['oclass'];
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (is_array($entry['new']['attrs']) && count($entry['new']['attrs']) > 0)
foreach ($entry['new']['attrs'] as $attr => $val) {
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
# Check to see if this is a unique Attribute
if ($badattr = $ldapserver->checkUniqueAttr($entry['dn']['string'],$attr,array($val))) {
$href['search'] = htmlspecialchars(sprintf('cmd.php?cmd=search&search=true&form=advanced&server_id=%s&filter=%s=%s',
$ldapserver->server_id,$attr,$badattr));
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
pla_error(sprintf(_('Your attempt to add <b>%s</b> (<i>%s</i>) to <br><b>%s</b><br> is NOT allowed. That attribute/value belongs to another entry.<p>You might like to <a href=\'%s\'>search</a> for that entry.'),$attr,$badattr,$entry['dn']['string'],$href['search']));
2009-06-30 09:22:30 +00:00
}
2009-06-30 10:46:00 +00:00
$new_entry[$attr] = $val;
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
$result = $ldapserver->attrModify($entry['dn']['string'],$new_entry);
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if (! $result)
2009-06-30 10:26:08 +00:00
pla_error(_('Could not perform ldap_mod_add operation.'),$ldapserver->error(),$ldapserver->errno());
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
else {
$modified_attrs = array_keys($entry['new']['attrs']);
$modified_attrs[] = 'objectclass';
$href['complete'] = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs=%s',
$ldapserver->server_id,$entry['dn']['encode'],serialize($modified_attrs));
header(sprintf('Location: %s',$href['complete']));
die();
}
2009-06-30 08:05:37 +00:00
?>