File: template_engine.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 (69 lines) | stat: -rw-r--r-- 2,467 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
67
68
69
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/template_engine.php,v 1.45.2.1 2007/12/26 09:26:32 wurley Exp $

/**
 * Template render engine.
 * @param dn $dn DN of the object being edited. (For editing existing entries)
 * @param dn $container DN where the new object will be created. (For creating new entries)
 * @param string $template to use for new entry. (For creating new entries)
 * @todo schema attr keys should be in lowercase.
 * @package phpLDAPadmin
 * @author The phpLDAPadmin development team
 */
/**
 */

require_once './common.php';

$entry['dn']['encode'] = get_request('dn','REQUEST');
$entry['dn']['string'] = rawurldecode($entry['dn']['encode']);
$entry['template'] = get_request('template','REQUEST',false,'');

# If we have a DN, then this is to edit the entry.
if ($entry['dn']['string']) {
	$ldapserver->dnExists($entry['dn']['string'])
		or pla_error(sprintf(_('No such entry: %s'),pretty_print_dn($entry['dn']['string'])));

	$tree = get_cached_item($ldapserver->server_id,'tree');

	if ($tree) {
		$entry['dn']['tree'] = $tree->getEntry($entry['dn']['string']);

		if (! $entry['dn']['tree']) {
			/*
			 * The entry doesn't exists in the tree because it
			 * may be filtered ; as we ask for its display, we
			 * add all the same the entry in the tree
			 */
			$tree->addEntry($entry['dn']['string']);
			$entry['dn']['tree'] = $tree->getEntry($entry['dn']['string']);

		}

		if ($entry['dn']['tree']) {
			eval('$reader = new '.$_SESSION[APPCONFIG]->GetValue('appearance', 'entry_reader').'($ldapserver);');
			$entry['dn']['tree']->accept($reader);

			eval('$writer = new '.$_SESSION[APPCONFIG]->GetValue('appearance', 'entry_writer').'($ldapserver);');
			$entry['dn']['tree']->accept($writer);
		}
	}

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

	# Create a new empty entry
	$entryfactoryclass = $_SESSION[APPCONFIG]->GetValue('appearance','entry_factory');
	eval('$entry_factory = new '.$entryfactoryclass.'();');
	$entry['dn']['tree'] = $entry_factory->newCreatingEntry('');

	# Init the entry with incoming data
	eval('$reader = new '.$_SESSION[APPCONFIG]->GetValue('appearance', 'entry_reader').'($ldapserver);');
	$entry['dn']['tree']->accept($reader);

	# Display the creating entry
	eval('$writer = new '.$_SESSION[APPCONFIG]->GetValue('appearance', 'entry_writer').'($ldapserver);');
	$entry['dn']['tree']->accept($writer);
}
?>