phpldapadmin/htdocs/export.php

114 lines
3.0 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 11:46:44 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/export.php,v 1.18.2.1 2007/12/26 09:26:32 wurley Exp $
2009-06-30 09:22:30 +00:00
2009-06-30 09:29:51 +00:00
/**
* @package phpLDAPadmin
*/
/**
*/
2009-06-30 10:46:00 +00:00
require './common.php';
2009-06-30 09:29:51 +00:00
# Fix a bug with IE:
ini_set('session.cache_limiter','');
require LIBDIR.'export_functions.php';
2009-06-30 09:22:30 +00:00
2009-06-30 11:46:44 +00:00
if (! $_SESSION[APPCONFIG]->isCommandAvailable('export'))
2009-06-30 10:46:00 +00:00
pla_error(sprintf('%s%s %s',_('This operation is not permitted by the configuration'),_(':'),_('export')));
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$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');
2009-06-30 10:26:08 +00:00
2009-06-30 10:46:00 +00:00
if ($entry['filter']) {
$entry['filter'] = preg_replace('/\s+/','',$entry['filter']);
$attributes = split(',',preg_replace('/\s+/','',$entry['attr']));
2009-06-30 10:26:08 +00:00
} else {
$attributes = array();
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
# Add system attributes if needed
if ($entry['sys_attr']) {
2009-06-30 10:26:08 +00:00
array_push($attributes,'*');
array_push($attributes,'+');
2009-06-30 09:22:30 +00:00
}
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
(! 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'));
2009-06-30 09:22:30 +00:00
2009-06-30 10:26:08 +00:00
# Initialisation of other variables
2009-06-30 10:46:00 +00:00
$friendly_rdn = get_rdn($entry['base_dn'],1);
$extension = $exporters[$entry['exporter_id']]['extension'];
2009-06-30 09:22:30 +00:00
2009-06-30 10:26:08 +00:00
# default case not really needed
2009-06-30 10:46:00 +00:00
switch ($entry['format']) {
2009-06-30 10:26:08 +00:00
case 'win':
$br = "\r\n";
break;
case 'mac':
$br = "\r";
break;
case 'unix':
default:
$br = "\n";
2009-06-30 09:22:30 +00:00
}
2009-06-30 10:26:08 +00:00
# get the decoree,ie the source
2009-06-30 10:46:00 +00:00
$plaLdapExporter = new PlaLdapExporter($ldapserver->server_id,$entry['filter'],$entry['base_dn'],$entry['scope'],$attributes);
2009-06-30 10:26:08 +00:00
# the decorator do it that way for the moment
$exporter = null;
2009-06-30 10:46:00 +00:00
switch ($entry['exporter_id']) {
2009-06-30 10:26:08 +00:00
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.'));
2009-06-30 09:22:30 +00:00
}
2009-06-30 10:26:08 +00:00
# set the CLRN
2009-06-30 09:22:30 +00:00
$exporter->setOutputFormat($br);
2009-06-30 10:26:08 +00:00
if (isset($_REQUEST['compress']) && $_REQUEST['compress'] = 'on')
$exporter->compress(true);
2009-06-30 09:22:30 +00:00
2009-06-30 10:26:08 +00:00
# prevent script from bailing early for long search
@set_time_limit(0);
2009-06-30 09:29:51 +00:00
2009-06-30 10:26:08 +00:00
# send the header
2009-06-30 10:46:00 +00:00
if ($entry['file']) {
if (ob_get_level()) ob_end_clean();
2009-06-30 10:26:08 +00:00
header('Content-type: application/download');
2009-06-30 10:46:00 +00:00
header(sprintf('Content-Disposition: filename="%s.%s"',$friendly_rdn,$exporters[$entry['exporter_id']]['extension'].($exporter->isCompressed()?'.gz':'')));
$exporter->export();
die();
2009-06-30 10:26:08 +00:00
2009-06-30 10:46:00 +00:00
} else {
print '<span style="font-size: 14px; font-family: courier;"><pre>';
$exporter->export();
print '</pre></span>';
}
2009-06-30 09:22:30 +00:00
?>