2006-11-10 16:30:01 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <nelius@cwtech.de>
|
|
|
|
* @copyright Cornelius Weiss <nelius@cwtech.de>
|
2006-11-10 16:38:31 +01:00
|
|
|
* @version $Id$
|
2006-11-10 16:30:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
require_once(EGW_INCLUDE_ROOT. '/etemplate/inc/class.etemplate.inc.php');
|
|
|
|
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.import_export_helper_functions.inc.php');
|
|
|
|
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.bodefinitions.inc.php');
|
|
|
|
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.definition.inc.php');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* userinterface for exports
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class uiexport {
|
|
|
|
const _appname = 'importexport';
|
|
|
|
|
|
|
|
public $public_functions = array(
|
|
|
|
'export_dialog' => true,
|
|
|
|
'download' => true,
|
|
|
|
);
|
|
|
|
|
|
|
|
private $js;
|
|
|
|
private $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* holds all export plugins from all apps
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $export_plugins;
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->js = $GLOBALS['egw']->js = is_object($GLOBALS['egw']->js) ? $GLOBALS['egw']->js : CreateObject('phpgwapi.javascript');
|
2006-11-16 12:04:09 +01:00
|
|
|
$this->js->validate_file('.','export_dialog','importexport');
|
2006-11-10 16:30:01 +01:00
|
|
|
$this->user = $GLOBALS['egw_info']['user']['user_id'];
|
|
|
|
$this->export_plugins = import_export_helper_functions::get_plugins('all','export');
|
|
|
|
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function export_dialog($_content=array()) {
|
2006-11-16 12:04:09 +01:00
|
|
|
$tabs = 'general_tab|selection_tab|options_tab';
|
2006-11-10 16:30:01 +01:00
|
|
|
$content = array();
|
|
|
|
$sel_options = array();
|
|
|
|
$readonlys = array();
|
|
|
|
$preserv = array();
|
|
|
|
|
|
|
|
if(empty($_content)) {
|
|
|
|
$et = new etemplate(self::_appname. '.export_dialog');
|
|
|
|
$_appname = $_GET['appname'];
|
2010-02-26 00:13:18 +01:00
|
|
|
//$_definition = $_GET['definition'] = 'expert';
|
|
|
|
$_definition = $_GET['definition'];
|
2006-11-16 12:04:09 +01:00
|
|
|
$_plugin = $_GET['plugin']; // NOTE: definition _must_ be 'expert' if for plugin to be used!
|
2006-11-10 16:30:01 +01:00
|
|
|
$_selection = $_GET['selection'];
|
2007-06-08 00:08:38 +02:00
|
|
|
|
|
|
|
error_log(__FILE__.__FUNCTION__. '::$_GET[\'appname\']='. $_appname. ',$_GET[\'definition\']='. $_definition. ',$_GET[\'plugin\']='.$_plugin. ',$_GET[\'selection\']='.$_selection);
|
2006-11-16 12:04:09 +01:00
|
|
|
// if appname is given and valid, list available definitions (if no definition is given)
|
2006-11-10 16:30:01 +01:00
|
|
|
if (!empty($_appname) && $GLOBALS['egw']->acl->check('run',1,$_appname)) {
|
|
|
|
$content['appname'] = $_appname;
|
|
|
|
$preserv['appname'] = $_appname;
|
|
|
|
$readonlys['appname'] = true;
|
2010-02-26 00:13:18 +01:00
|
|
|
$this->js->set_onload("export_dialog.appname = '$_appname';");
|
2006-11-10 16:30:01 +01:00
|
|
|
$this->js->set_onload("set_style_by_class('tr','select_appname','display','none');");
|
|
|
|
|
2006-11-16 12:04:09 +01:00
|
|
|
// fill definitions
|
|
|
|
$sel_options['definition'] = array();
|
|
|
|
$definitions = new bodefinitions(array(
|
|
|
|
'type' => 'export',
|
|
|
|
'application' => isset($content['appname']) ? $content['appname'] : '%'
|
|
|
|
));
|
|
|
|
foreach ((array)$definitions->get_definitions() as $identifier) {
|
|
|
|
$definition = new definition($identifier);
|
|
|
|
if ($title = $definition->get_title()) {
|
|
|
|
$sel_options['definition'][$title] = $title;
|
|
|
|
}
|
|
|
|
unset($definition);
|
|
|
|
}
|
|
|
|
unset($definitions);
|
|
|
|
$sel_options['definition']['expert'] = lang('Expert options');
|
2010-02-26 00:13:18 +01:00
|
|
|
|
2006-11-16 12:04:09 +01:00
|
|
|
|
2010-02-26 00:13:18 +01:00
|
|
|
if(isset($_definition) && array_key_exists($_definition,$sel_options['definition'])) {
|
2006-11-16 12:04:09 +01:00
|
|
|
$content['definition'] = $_definition;
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else {
|
2006-11-16 12:04:09 +01:00
|
|
|
$defdescs = array_keys($sel_options['definition']);
|
|
|
|
$content['definition'] = $sel_options['definition'][$defdescs[0]];
|
|
|
|
unset($defdescs);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2006-11-16 12:04:09 +01:00
|
|
|
// fill plugins
|
|
|
|
$sel_options['plugin'] = $this->export_plugins[$_appname]['export'];
|
|
|
|
|
|
|
|
// show definitions or plugins in ui?
|
2010-02-26 00:13:18 +01:00
|
|
|
if($content['definition'] == 'expert') {
|
2006-11-16 12:04:09 +01:00
|
|
|
if(isset($_plugin) && array_key_exists($_plugin,$sel_options['plugin'])) {
|
|
|
|
$content['plugin'] = $_plugin;
|
|
|
|
$selected_plugin = $_plugin;
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else {
|
2010-02-26 00:13:18 +01:00
|
|
|
/*
|
|
|
|
$plugins_classnames = array_keys($sel_options['plugin']);
|
2006-11-16 12:04:09 +01:00
|
|
|
$selected_plugin = $plugins_classnames[0];
|
|
|
|
$sel_options['plugin'] = $plugins;
|
2010-02-26 00:13:18 +01:00
|
|
|
*/
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2006-11-16 12:04:09 +01:00
|
|
|
$this->js->set_onload("set_style_by_class('tr','select_definition','display','none');");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->js->set_onload("set_style_by_class('tr','select_plugin','display','none');");
|
|
|
|
$this->js->set_onload("set_style_by_class('tr','save_definition','display','none');");
|
|
|
|
|
|
|
|
$definition = new definition($content['definition']);
|
|
|
|
$content['description'] = $definition->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle selector
|
2010-02-26 00:13:18 +01:00
|
|
|
if($selected_plugin) {
|
|
|
|
$plugin_object = new $selected_plugin;
|
|
|
|
|
|
|
|
$content['description'] = $plugin_object->get_description();
|
|
|
|
|
|
|
|
// fill options tab
|
|
|
|
// TODO: do we need all options templates online?
|
|
|
|
// NO, we can manipulate the session array of template id on xajax request
|
|
|
|
// however, there might be other solutions... we solve this in 1.3
|
|
|
|
$content['plugin_options_html'] = $plugin_object->get_options_etpl();
|
|
|
|
}
|
2006-11-16 12:04:09 +01:00
|
|
|
|
|
|
|
// fill selection tab
|
|
|
|
if ($_selection) {
|
|
|
|
$readonlys[$tabs]['selection_tab'] = true;
|
|
|
|
$content['selection'] = $_selection;
|
|
|
|
$preserv['selection'] = $_selection;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// ToDo: I need to think abaout it...
|
|
|
|
// are selectors abstracted in the iface_egw_record_entity ?
|
|
|
|
// if so, we might not want to have html here ?
|
|
|
|
//$content['plugin_selectors_html'] = $plugin_object->get_selectors_html();
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2006-11-16 12:04:09 +01:00
|
|
|
//unset ($plugin_object);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
// if no appname is supplied, list apps which can export
|
|
|
|
else {
|
|
|
|
(array)$apps = import_export_helper_functions::get_apps('export');
|
|
|
|
$sel_options['appname'] = array('' => lang('Select one')) + array_combine($apps,$apps);
|
|
|
|
$this->js->set_onload("set_style_by_class('tr','select_plugin','display','none');");
|
|
|
|
$content['plugin_selectors_html'] = $content['plugin_options_html'] =
|
|
|
|
lang('You need to select an app and format first!');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$_selection) {
|
|
|
|
$this->js->set_onload("
|
|
|
|
disable_button('exec[preview]');
|
|
|
|
disable_button('exec[export]');
|
|
|
|
");
|
|
|
|
}
|
|
|
|
|
|
|
|
// disable preview box
|
|
|
|
$this->js->set_onload("set_style_by_class('tr','preview-box','display','none');");
|
|
|
|
}
|
|
|
|
//xajax_eT_wrapper submit
|
|
|
|
elseif(class_exists('xajaxResponse'))
|
|
|
|
{
|
|
|
|
//error_log(__LINE__.__FILE__.'$_content: '.print_r($_content,true));
|
2009-06-08 18:21:14 +02:00
|
|
|
$response = new xajaxResponse();
|
2006-11-10 16:30:01 +01:00
|
|
|
|
2010-02-26 00:13:18 +01:00
|
|
|
if ($_content['definition'] == 'expert') {
|
2006-11-16 12:04:09 +01:00
|
|
|
$definition = new definition();
|
|
|
|
$definition->definition_id = $_content['definition_id'] ? $_content['definition_id'] : '';
|
|
|
|
$definition->name = $_content['name'] ? $_content['name'] : '';
|
|
|
|
$definition->application = $_content['appname'];
|
|
|
|
$definition->plugin = $_content['plugin'];
|
|
|
|
$definition->type = 'export';
|
|
|
|
$definition->allowed_users = $_content['allowed_users'] ? $_content['allowed_users'] : $this->user;
|
|
|
|
$definition->owner = $_content['owner'] ? $_content['owner'] : $this->user;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$definition = new definition($_content['definition']);
|
|
|
|
}
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
if (isset($definition->plugin_options['selection'])) {
|
|
|
|
//$definition->plugin_options = parse(...)
|
2006-11-16 12:04:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2007-06-08 00:08:38 +02:00
|
|
|
$definition->plugin_options = array_merge(
|
|
|
|
$definition->plugin_options,
|
2006-11-16 12:04:09 +01:00
|
|
|
array('selection' => $_content['selection'])
|
|
|
|
);
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
$tmpfname = tempnam('/tmp','export');
|
|
|
|
$file = fopen($tmpfname, "w+");
|
2007-06-08 00:08:38 +02:00
|
|
|
if (! $charset = $definition->plugin_options['charset']) {
|
2006-11-10 16:30:01 +01:00
|
|
|
$charset = $GLOBALS['egw']->translation->charset();
|
|
|
|
}
|
2006-11-16 12:04:09 +01:00
|
|
|
$plugin_object = new $definition->plugin;
|
2007-06-09 17:36:30 +02:00
|
|
|
$plugin_object->export( $file, $definition );
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
if($_content['export'] == 'pressed') {
|
|
|
|
fclose($file);
|
|
|
|
$response->addScript("xajax_eT_wrapper();");
|
|
|
|
$response->addScript("opener.location.href='". $GLOBALS['egw']->link('/index.php','menuaction=importexport.uiexport.download&_filename='. $tmpfname.'&_appname='. $definition->application). "&_suffix=". $plugin_object->get_filesuffix(). "';");
|
|
|
|
$response->addScript('window.setTimeout("window.close();", 100);');
|
|
|
|
return $response->getXML();
|
|
|
|
}
|
|
|
|
elseif($_content['preview'] == 'pressed') {
|
|
|
|
fseek($file, 0);
|
|
|
|
$item_count = 1;
|
|
|
|
$preview = '';
|
|
|
|
$search = array('[\016]','[\017]',
|
|
|
|
'[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]',
|
|
|
|
'[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]');
|
|
|
|
$replace = $preview = '';
|
|
|
|
|
|
|
|
while(!feof($file) && $item_count < 10) {
|
|
|
|
$preview .= preg_replace($search,$replace,fgets($file,1024));
|
|
|
|
$item_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose($file);
|
|
|
|
unlink($tmpfname);
|
2007-06-09 17:36:30 +02:00
|
|
|
|
|
|
|
// NOTE: $definition->plugin_options['charset'] may not be set,
|
|
|
|
// but it's the best guess atm.
|
|
|
|
$preview = $GLOBALS['egw']->translation->convert( $preview,
|
|
|
|
$definition->plugin_options['charset'],
|
|
|
|
$GLOBALS['egw']->translation->charset()
|
|
|
|
);
|
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
$response->addAssign('exec[preview-box]','innerHTML',$preview);
|
2007-06-09 17:36:30 +02:00
|
|
|
//$response->addAssign('divPoweredBy','style.display','none');
|
2006-11-10 16:30:01 +01:00
|
|
|
$response->addAssign('exec[preview-box]','style.display','inline');
|
|
|
|
$response->addAssign('exec[preview-box-buttons]','style.display','inline');
|
|
|
|
|
|
|
|
$response->addScript("xajax_eT_wrapper();");
|
|
|
|
return $response->getXML();
|
|
|
|
}
|
|
|
|
//nothing else expected!
|
|
|
|
throw new Exception('Error: unexpected submit in export_dialog!');
|
|
|
|
}
|
2007-06-08 00:08:38 +02:00
|
|
|
//error_log(print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
return $et->exec(self::_appname. '.uiexport.export_dialog',$content,$sel_options,$readonlys,$preserv,2);
|
|
|
|
}
|
|
|
|
|
2010-02-26 00:13:18 +01:00
|
|
|
public function ajax_get_definitions($_appname, xajaxResponse &$response = null) {
|
|
|
|
if(is_null($response)) {
|
|
|
|
$response = new xajaxResponse();
|
|
|
|
} else {
|
|
|
|
$no_return = true;
|
|
|
|
}
|
|
|
|
if (!$_appname) {
|
|
|
|
$response->addScript("set_style_by_class('tr','select_definition','display','none');");
|
|
|
|
return $no_return ? '' : $response->getXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
$definitions = new bodefinitions(array(
|
|
|
|
'type' => 'export',
|
|
|
|
'application' => $_appname
|
|
|
|
));
|
|
|
|
foreach ((array)$definitions->get_definitions() as $identifier) {
|
|
|
|
$definition = new definition($identifier);
|
|
|
|
if ($title = $definition->get_title()) {
|
|
|
|
if (!$selected_plugin) $selected_plugin = $plugin;
|
|
|
|
$sel_options['definition'] .= '<option value="'. $title. '" >'. $title. '</option>';
|
|
|
|
}
|
|
|
|
unset($definition);
|
|
|
|
}
|
|
|
|
unset($definitions);
|
|
|
|
$sel_options['definition'] .= '<option value="expert">' . lang('Expert options') . '</option';
|
|
|
|
|
|
|
|
if($selected_plugin == 'expert') {
|
|
|
|
$this->ajax_get_plugins($_appname, $response);
|
|
|
|
} else {
|
|
|
|
$response->addScript("set_style_by_class('tr','select_plugin','display','none');");
|
|
|
|
}
|
|
|
|
$response->addScript('export_dialog.change_definition(document.getElementId(\'exec[definition]\'));');
|
|
|
|
$response->addAssign('exec[definition]','innerHTML',$sel_options['definition']);
|
|
|
|
$response->addScript("set_style_by_class('tr','select_definition','display','table-row');");
|
|
|
|
return $no_return ? '' : $response->getXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_get_plugins($_appname, xajaxResponse &$response = null) {
|
|
|
|
if(!is_null($response)) {
|
|
|
|
$no_return = true;
|
|
|
|
} else {
|
|
|
|
$response = new xajaxResponse();
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
if (!$_appname) {
|
|
|
|
$response->addScript("set_style_by_class('tr','select_plugin','display','none');");
|
2010-02-26 00:13:18 +01:00
|
|
|
return $no_return ? '' : $response->getXML();
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
(array)$plugins = import_export_helper_functions::get_plugins($_appname,'export');
|
|
|
|
$sel_options['plugin'] = '';
|
|
|
|
foreach ($plugins[$_appname]['export'] as $plugin => $plugin_name) {
|
|
|
|
if (!$selected_plugin) $selected_plugin = $plugin;
|
|
|
|
$sel_options['plugin'] .= '<option value="'. $plugin. '" >'. $plugin_name. '</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->ajax_get_plugin_description($selected_plugin,$response);
|
|
|
|
$response->addAssign('exec[plugin]','innerHTML',$sel_options['plugin']);
|
|
|
|
$response->addScript("set_style_by_class('tr','select_plugin','display','table-row');");
|
2010-02-26 00:13:18 +01:00
|
|
|
return $no_return ? '' : $response->getXML();
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2010-02-26 00:13:18 +01:00
|
|
|
public function ajax_get_definition_description($_definition, xajaxResponse &$response=null) {
|
|
|
|
$no_return = !is_null($response);
|
|
|
|
if(is_null($response)) {
|
|
|
|
$response = new xajaxResponse();
|
|
|
|
}
|
|
|
|
if (!$_definition) return $response->getXML();
|
|
|
|
$_object = new definition($_definition);
|
|
|
|
if (is_a($_object, 'definition')) {
|
|
|
|
$description = $_object->description;
|
|
|
|
$response->assign('exec[plugin_description]','innerHTML',$description);
|
|
|
|
}
|
|
|
|
unset ($_object);
|
|
|
|
|
|
|
|
return $no_return ? '' : $response->getXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_get_plugin_description($_plugin,&$_response=false) {
|
|
|
|
$no_return = !is_null($response);
|
|
|
|
if(is_null($response)) {
|
|
|
|
$response = new xajaxResponse();
|
|
|
|
}
|
|
|
|
if (!$_plugin) return $no_return ? '' : $response->getXML();
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
$plugin_object = new $_plugin;
|
|
|
|
if (is_a($plugin_object, 'iface_export_plugin')) {
|
|
|
|
$description = $plugin_object->get_description();
|
2010-02-26 00:13:18 +01:00
|
|
|
$_response->addAssign('exec[plugin_description]','innerHTML',$description);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
unset ($plugin_object);
|
|
|
|
|
2010-02-26 00:13:18 +01:00
|
|
|
return $no_return ? '' : $response->getXML();
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_get_plugin_options($_plugin,$_response=false) {
|
2010-02-26 00:13:18 +01:00
|
|
|
$no_return = !is_null($response);
|
|
|
|
if(is_null($response)) {
|
|
|
|
$response = new xajaxResponse();
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
$response = $_response ? $_response : new xajaxResponse();
|
2010-02-26 00:13:18 +01:00
|
|
|
if (!$_plugin) return $no_return ? '' : $response->getXML();
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
$plugin_object = new $_plugin;
|
|
|
|
if (is_a($plugin_object, 'iface_export_plugin')) {
|
|
|
|
$options = $plugin_object->get_options_etpl();
|
|
|
|
}
|
|
|
|
unset ($plugin_object);
|
|
|
|
|
|
|
|
return $_response ? '' : $response->getXML();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* downloads file to client and deletes it.
|
|
|
|
*
|
|
|
|
* @param sting $_tmpfname
|
|
|
|
* @todo we need a suffix atibute in plugins e.g. .csv
|
|
|
|
*/
|
|
|
|
public function download($_tmpfname = '') {
|
|
|
|
$tmpfname = $_tmpfname ? $_tmpfname : $_GET['_filename'];
|
|
|
|
if (!is_readable($tmpfname)) die();
|
|
|
|
|
|
|
|
$appname = $_GET['_appname'];
|
|
|
|
$nicefname = 'egw_export_'.$appname.'-'.date('y-m-d');
|
|
|
|
|
|
|
|
header('Content-type: application/text');
|
|
|
|
header('Content-Disposition: attachment; filename="'.$nicefname.'.'.$_GET['_suffix'].'"');
|
|
|
|
$file = fopen($tmpfname,'r');
|
|
|
|
while(!feof($file))
|
|
|
|
echo fgets($file,1024);
|
|
|
|
fclose($file);
|
|
|
|
|
|
|
|
unlink($tmpfname);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_get_plugin_selectors() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_get_template($_name) {
|
|
|
|
|
|
|
|
}
|
2010-02-26 00:13:18 +01:00
|
|
|
} // end class uiexport
|