phpldapadmin/htdocs/add_oclass.php

71 lines
2.4 KiB
PHP
Raw Normal View History

2009-06-30 08:05:37 +00:00
<?php
2009-06-30 11:52:55 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_oclass.php,v 1.19.2.1 2008/12/12 12:20:22 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())
2009-06-30 11:52:55 +00:00
error(_('You cannot perform updates while server is in read-only mode'),'error','index.php');
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
if ($ldapserver->isAttrReadOnly('objectClass'))
2009-06-30 11:52:55 +00:00
error(_('ObjectClasses are flagged as read only in the phpLDAPadmin configuration.'),'error','index.php');
2009-06-30 08:05:37 +00:00
2009-06-30 11:52:55 +00:00
$entry = array();
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 11:52:55 +00:00
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']),'error','index.php');
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 11:52:55 +00:00
system_message(array(
'title'=>_('Could not perform ldap_mod_add operation.'),
'body'=>ldap_error_msg($ldapserver->error(),$ldapserver->errno()),
'type'=>'error'));
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
?>