File: export.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 (113 lines) | stat: -rwxr-xr-x 3,043 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
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
<?php
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/export.php,v 1.18.2.1 2007/12/26 09:26:32 wurley Exp $

/**
 * @package phpLDAPadmin
 */
/**
 */

require './common.php';

# Fix a bug with IE:
ini_set('session.cache_limiter','');

require LIBDIR.'export_functions.php';

if (! $_SESSION[APPCONFIG]->isCommandAvailable('export'))
	pla_error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('export')));

$entry['base_dn'] = get_request('dn');
$entry['format'] = get_request('format','POST',false,'unix');
$entry['scope'] = get_request('scope','POST',false,'base');
$entry['filter'] = get_request('filter','POST',false,'objectclass=*');
$entry['attr'] = get_request('attributes');
$entry['sys_attr'] = get_request('sys_attr');
$entry['file'] = get_request('save_as_file') ? true : false;
$entry['exporter_id'] = get_request('exporter_id');

if ($entry['filter']) {
	$entry['filter'] = preg_replace('/\s+/','',$entry['filter']);
	$attributes = split(',',preg_replace('/\s+/','',$entry['attr']));

} else {
	$attributes = array();
}

# Add system attributes if needed
if ($entry['sys_attr']) {
	array_push($attributes,'*');
	array_push($attributes,'+');
}

(! is_null($entry['exporter_id'])) or pla_error(_('You must choose an export format.'));
isset($exporters[$entry['exporter_id']]) or pla_error(_('Invalid export format'));

# Initialisation of other variables
$friendly_rdn = get_rdn($entry['base_dn'],1);
$extension = $exporters[$entry['exporter_id']]['extension'];

# default case not really needed
switch ($entry['format']) {
	case 'win':
		$br = "\r\n";
		break;
	case 'mac':
		$br = "\r";
		break;
	case 'unix':
	default:
		$br = "\n";
}

# get the decoree,ie the source
$plaLdapExporter = new PlaLdapExporter($ldapserver->server_id,$entry['filter'],$entry['base_dn'],$entry['scope'],$attributes);

# the decorator do it that way for the moment
$exporter = null;

switch ($entry['exporter_id']) {
	case 0:
		$exporter = new PlaLdifExporter($plaLdapExporter);
		break;

	case 1:
		$exporter = new PlaDsmlExporter($plaLdapExporter);
		break;

	case 2:
		$exporter = new PlaVcardExporter($plaLdapExporter);
		break;

	case 3:
		$exporter = new PlaCSVExporter($plaLdapExporter);
		break;

	default:
		# truly speaking,this default case will never be reached. See check at the bottom.
		pla_error(_('No available exporter found.'));
}

# set the CLRN
$exporter->setOutputFormat($br);

if (isset($_REQUEST['compress']) && $_REQUEST['compress'] = 'on')
	$exporter->compress(true);

# prevent script from bailing early for long search
@set_time_limit(0);

# send the header
if ($entry['file']) {
	if (ob_get_level()) ob_end_clean();
	header('Content-type: application/download');
	header(sprintf('Content-Disposition: filename="%s.%s"',$friendly_rdn,$exporters[$entry['exporter_id']]['extension'].($exporter->isCompressed()?'.gz':'')));
	$exporter->export();
	die();

} else {
	print '<span style="font-size: 14px; font-family: courier;"><pre>';
	$exporter->export();
	print '</pre></span>';
}
?>