File: add_oclass.php

package info (click to toggle)
phpldapadmin 1.1.0.5-6%2Blenny2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,008 kB
  • ctags: 3,949
  • sloc: php: 17,735; xml: 1,532; sh: 388; makefile: 46
file content (66 lines) | stat: -rw-r--r-- 2,286 bytes parent folder | download
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
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_oclass.php,v 1.19 2007/12/15 07:50:30 wurley Exp $

/**
 * Adds an objectClass to the specified dn.
 *
 * Note, this does not do any schema violation checking. That is
 * performed in add_oclass_form.php.
 *
 * Variables that come in as POST vars:
 *  - dn (rawurlencoded)
 *  - new_oclass
 *  - new_attrs (array, if any)
 *
 * @package phpLDAPadmin
 */
/**
 */

require './common.php';

if ($ldapserver->isReadOnly())
	pla_error(_('You cannot perform updates while server is in read-only mode'));

if ($ldapserver->isAttrReadOnly('objectClass'))
	pla_error(_('ObjectClasses are flagged as read only in the phpLDAPadmin configuration.'));

$entry['dn']['encode'] = get_request('dn');
$entry['dn']['string'] = urldecode($entry['dn']['encode']);

$entry['new']['oclass'] = unserialize(rawurldecode(get_request('new_oclass')));
$entry['new']['attrs'] = get_request('new_attrs');

$new_entry = array();
$new_entry['objectClass'] = $entry['new']['oclass'];

if (is_array($entry['new']['attrs']) && count($entry['new']['attrs']) > 0)
	foreach ($entry['new']['attrs'] as $attr => $val) {

		# 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));

			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']));
		}

		$new_entry[$attr] = $val;
	}

$result = $ldapserver->attrModify($entry['dn']['string'],$new_entry);

if (! $result)
	pla_error(_('Could not perform ldap_mod_add operation.'),$ldapserver->error(),$ldapserver->errno());

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();
}
?>