2006-11-10 16:30:01 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare - importexport
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Userinterface to define {im|ex}ports
|
|
|
|
*
|
|
|
|
* @package importexport
|
|
|
|
*/
|
2010-03-22 16:09:26 +01:00
|
|
|
class importexport_definitions_ui
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-02-26 00:13:18 +01:00
|
|
|
const _debug = false;
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
const _appname = 'importexport';
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
public $public_functions = array(
|
|
|
|
'edit' => true,
|
|
|
|
'index' => true,
|
2010-03-22 16:09:26 +01:00
|
|
|
'wizard' => true,
|
2006-11-10 16:30:01 +01:00
|
|
|
'import_definition' => true,
|
2011-02-22 18:13:03 +01:00
|
|
|
'site_config' => true,
|
2006-11-10 16:30:01 +01:00
|
|
|
);
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
/**
|
|
|
|
* holds all available plugins
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
var $plugins;
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
/**
|
|
|
|
* holds user chosen plugin after step20
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
var $plugin;
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
/**
|
|
|
|
* xajax response object
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
var $response = true;
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
function __construct()
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
// we cant deal with notice and warnings, as we are on ajax!
|
|
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
2007-06-08 00:08:38 +02:00
|
|
|
$GLOBALS['egw']->translation->add_app(self::_appname);
|
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = self::_appname;
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
|
2009-06-08 18:21:14 +02:00
|
|
|
$this->etpl = new etemplate();
|
2008-05-10 14:06:15 +02:00
|
|
|
$this->clock = html::image(self::_appname,'clock');
|
2006-11-10 16:30:01 +01:00
|
|
|
$this->steps = array(
|
2010-03-22 16:09:26 +01:00
|
|
|
'wizard_step10' => lang('Choose an application'),
|
|
|
|
'wizard_step20' => lang('Choose a plugin'),
|
|
|
|
'wizard_step21' => lang('Choose a name for this definition'),
|
|
|
|
'wizard_step90' => lang('Which users are allowed to use this definition'),
|
|
|
|
'wizard_finish' => '',
|
2006-11-10 16:30:01 +01:00
|
|
|
);
|
2010-02-26 00:13:18 +01:00
|
|
|
//register plugins
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->plugins = importexport_helper_functions::get_plugins();
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
/**
|
|
|
|
* List defined {im|ex}ports
|
|
|
|
*
|
|
|
|
* @param array $content=null
|
|
|
|
*/
|
|
|
|
function index($content = null,$msg='')
|
|
|
|
{
|
2011-02-22 18:13:03 +01:00
|
|
|
$filter = array('name' => '*');
|
|
|
|
|
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['admin']) {
|
2011-02-22 18:43:33 +01:00
|
|
|
// Filter private definitions
|
2011-02-22 18:13:03 +01:00
|
|
|
$filter['owner'] = $GLOBALS['egw_info']['user']['account_id'];
|
2011-02-22 18:43:33 +01:00
|
|
|
|
|
|
|
$config = config::read('phpgwapi');
|
|
|
|
if($config['export_limit'] == 'no') {
|
|
|
|
$filter['type'] = 'import';
|
|
|
|
}
|
2011-02-22 18:13:03 +01:00
|
|
|
} else {
|
|
|
|
$filter[] = '!owner || owner IS NULL';
|
|
|
|
}
|
|
|
|
|
2011-02-22 18:43:33 +01:00
|
|
|
|
|
|
|
|
2011-02-22 18:13:03 +01:00
|
|
|
$bodefinitions = new importexport_definitions_bo($filter, true);
|
2006-11-10 16:30:01 +01:00
|
|
|
if (is_array($content))
|
|
|
|
{
|
|
|
|
if (isset($content['delete']))
|
|
|
|
{
|
|
|
|
$bodefinitions->delete(array_keys($content['delete'],'pressed'));
|
|
|
|
}
|
|
|
|
elseif(($button = array_search('pressed',$content)) !== false)
|
|
|
|
{
|
|
|
|
$selected = array_keys($content['selected'],1);
|
|
|
|
if(count($selected) < 1 || !is_array($selected)) exit();
|
|
|
|
switch ($button)
|
|
|
|
{
|
|
|
|
case 'delete_selected' :
|
|
|
|
$bodefinitions->delete($selected);
|
|
|
|
break;
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
case 'export_selected' :
|
|
|
|
$mime_type = ($GLOBALS['egw']->html->user_agent == 'msie' || $GLOBALS['egw']->html->user_agent == 'opera') ?
|
|
|
|
'application/octetstream' : 'application/octet-stream';
|
2007-06-08 00:08:38 +02:00
|
|
|
$name = 'importexport_definition.xml';
|
2006-11-10 16:30:01 +01:00
|
|
|
header('Content-Type: ' . $mime_type);
|
|
|
|
header('Content-Disposition: attachment; filename="'.$name.'"');
|
|
|
|
echo $bodefinitions->export($selected);
|
|
|
|
exit();
|
|
|
|
|
|
|
|
break;
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2009-06-08 18:21:14 +02:00
|
|
|
$etpl = new etemplate(self::_appname.'.definition_index');
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
// we need an offset because of autocontinued rows in etemplate ...
|
|
|
|
$definitions = array('row0');
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
foreach ($bodefinitions->get_definitions() as $identifier) {
|
2011-02-14 16:54:28 +01:00
|
|
|
try {
|
|
|
|
$definition = new importexport_definition($identifier);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// permission error
|
|
|
|
continue;
|
|
|
|
}
|
2010-11-23 21:15:51 +01:00
|
|
|
$array = $definition->get_record_array();
|
|
|
|
$array['menuaction'] = $array['type'] == 'import' ? 'importexport.importexport_import_ui.import_dialog':'importexport.importexport_export_ui.export_dialog';
|
|
|
|
$definitions[] = $array;
|
2006-11-10 16:30:01 +01:00
|
|
|
unset($definition);
|
|
|
|
}
|
|
|
|
$content = $definitions;
|
2010-03-22 16:09:26 +01:00
|
|
|
return $etpl->exec( self::_appname.'.importexport_definitions_ui.index', $content, array(), $readonlys, $preserv );
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
function edit()
|
|
|
|
{
|
|
|
|
if(!$_definition = $_GET['definition'])
|
|
|
|
{
|
|
|
|
//close window
|
|
|
|
}
|
|
|
|
$definition = array('name' => $_definition);
|
2010-03-22 16:09:26 +01:00
|
|
|
$bodefinitions = new importexport_definitions_bo();
|
2010-02-26 00:13:18 +01:00
|
|
|
$definition = $bodefinitions->read($definition);
|
2011-02-22 18:13:03 +01:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
$definition['edit'] = true;
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard($definition);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard($content = null, $msg='')
|
2008-10-07 15:15:53 +02:00
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .=
|
2010-06-13 09:46:51 +02:00
|
|
|
"<script type='text/javascript'>
|
2006-11-10 16:30:01 +01:00
|
|
|
function xajax_eT_wrapper_init() {
|
2010-03-02 00:26:38 +01:00
|
|
|
//window.resizeTo(document.documentElement.scrollWidth+20,document.documentElement.offsetHeight+40);
|
2006-11-10 16:30:01 +01:00
|
|
|
window.moveTo(screen.availWidth/2 - window.outerWidth/2,
|
|
|
|
screen.availHeight/2 - window.outerHeight/2);
|
|
|
|
}
|
|
|
|
</script>";
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->etpl->read('importexport.wizardbox');
|
|
|
|
$this->wizard_content_template =& $this->etpl->children[0]['data'][1]['A'][2][1]['name'];
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
if(is_array($content) &&! $content['edit'])
|
2008-10-07 15:15:53 +02:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.wizard->$content '. print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
// fetch plugin object
|
|
|
|
if($content['plugin'] && $content['application'])
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$wizard_name = $content['application'] . '_wizard_' . str_replace($content['application'] . '_', '', $content['plugin']);
|
|
|
|
|
|
|
|
// we need to deal with the wizard object if exists
|
|
|
|
if (file_exists(EGW_SERVER_ROOT . '/'. $content['application'].'/importexport/class.wizard_'. $content['plugin'].'.inc.php'))
|
|
|
|
{
|
|
|
|
error_log('Deprecated location for importexport wizard. Please move it to app/inc/ and rename it to follow new conventions');
|
|
|
|
}
|
|
|
|
elseif (file_exists(EGW_SERVER_ROOT . '/'. $content['application']."/inc/class.$wizard_name.inc.php"))
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$wizard_plugin = $wizard_name;
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
else
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$wizard_plugin = $content['plugin'];
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->plugin = is_object($GLOBALS['egw']->$wizard_plugin) ? $GLOBALS['egw']->$wizard_plugin : new $wizard_plugin;
|
2010-02-26 00:13:18 +01:00
|
|
|
|
|
|
|
// Global object needs to be the same, or references to plugin don't work
|
2010-03-22 16:09:26 +01:00
|
|
|
if(!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this)
|
|
|
|
$GLOBALS['egw']->importexport_definitions_ui =& $this;
|
2008-10-07 15:15:53 +02:00
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
// deal with buttons even if we are not on ajax
|
|
|
|
if(isset($content['button']) && array_search('pressed',$content['button']) === false && count($content['button']) == 1)
|
|
|
|
{
|
|
|
|
$button = array_keys($content['button']);
|
|
|
|
$content['button'] = array($button[0] => 'pressed');
|
|
|
|
}
|
2010-06-13 09:46:51 +02:00
|
|
|
// Override next button on step 21, to do a regular submit for the file upload
|
|
|
|
if($content['step'] == 'wizard_step21') {
|
2010-06-11 17:44:36 +02:00
|
|
|
$this->etpl->set_cell_attribute('button[next]', 'onclick', '');
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
// post process submitted step
|
2010-03-22 16:09:26 +01:00
|
|
|
if($content['step']) {
|
|
|
|
if(!key_exists($content['step'],$this->steps))
|
|
|
|
$next_step = $this->plugin->$content['step']($content);
|
|
|
|
else
|
|
|
|
$next_step = $this->$content['step']($content);
|
|
|
|
} else {
|
|
|
|
die('Cannot find next step');
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
// pre precess next step
|
|
|
|
$sel_options = $readonlys = $preserv = array();
|
2010-03-01 18:30:53 +01:00
|
|
|
|
|
|
|
// Disable finish button if required fields are missing
|
|
|
|
if(!$content['name'] || !$content['type'] || !$content['plugin']) {
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][finish]');");
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
if(!key_exists($next_step,$this->steps))
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard_content_template = $this->plugin->$next_step($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard_content_template = $this->$next_step($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$html = $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,1);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// initial content
|
|
|
|
$GLOBALS['egw']->js->set_onload("xajax_eT_wrapper_init();");
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][previous]');");
|
|
|
|
|
|
|
|
$sel_options = $readonlys = $preserv = array();
|
|
|
|
if($content['edit'])
|
|
|
|
unset ($content['edit']);
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard_content_template = $this->wizard_step10($content, $sel_options, $readonlys, $preserv);
|
|
|
|
$html = $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,1);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(class_exists('xajaxResponse'))
|
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$this->response = new xajaxResponse();
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
if ($content['closewindow'])
|
|
|
|
{
|
|
|
|
$this->response->addScript("window.close();");
|
|
|
|
$this->response->addScript("opener.location.reload();");
|
2008-10-07 15:15:53 +02:00
|
|
|
// If Browser can't close window we display a "close" buuton and
|
2006-11-10 16:30:01 +01:00
|
|
|
// need to disable normal buttons
|
|
|
|
$this->response->addAssign('exec[button][previous]','style.display', 'none');
|
|
|
|
$this->response->addAssign('exec[button][next]','style.display', 'none');
|
|
|
|
$this->response->addAssign('exec[button][finish]','style.display', 'none');
|
|
|
|
$this->response->addAssign('exec[button][cancel]','style.display', 'none');
|
|
|
|
}
|
|
|
|
$this->response->addAssign('contentbox', 'innerHTML', $html);
|
2010-06-13 09:46:51 +02:00
|
|
|
if (($onload = $GLOBALS['egw']->js->set_onload('')))
|
|
|
|
{
|
|
|
|
$this->response->addScript($onload);
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
$this->response->addAssign('picturebox', 'style.display', 'none');
|
|
|
|
$this->response->addScript("set_style_by_class('div','popupManual','display','inline');");
|
|
|
|
|
|
|
|
return $this->response->getXML();
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
else
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
$GLOBALS['egw']->js->set_onload("document.getElementById('picturebox').style.display = 'none';");
|
2010-06-14 09:45:54 +02:00
|
|
|
egw_framework::validate_file('.', 'etemplate', 'etemplate');
|
2010-11-05 20:31:53 +01:00
|
|
|
common::egw_header();
|
2006-11-10 16:30:01 +01:00
|
|
|
echo '<div id="divMain">'."\n";
|
2010-03-22 16:09:26 +01:00
|
|
|
echo '<div><h3>{Im|Ex}port Wizard</h3></div>';
|
2006-11-10 16:30:01 +01:00
|
|
|
// adding a manual icon to every popup
|
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['manual'])
|
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$manual = new etemplate('etemplate.popup.manual');
|
2010-03-22 16:09:26 +01:00
|
|
|
echo $manual->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,1);
|
2006-11-10 16:30:01 +01:00
|
|
|
unset($manual);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<div id="contentbox">';
|
|
|
|
echo $html;
|
|
|
|
echo '</div></div>'."\n";
|
|
|
|
echo '<style type="text/css">#picturebox { position: absolute; right: 27px; top: 24px; }</style>'."\n";
|
|
|
|
echo '<div id="picturebox">'. $this->clock. '</div>';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-07 15:15:53 +02:00
|
|
|
* gets name of next step
|
2006-11-10 16:30:01 +01:00
|
|
|
*
|
|
|
|
* @param string $curr_step
|
|
|
|
* @param int $step_width
|
2008-10-07 15:15:53 +02:00
|
|
|
* @return string containing function name of next step
|
2006-11-10 16:30:01 +01:00
|
|
|
*/
|
|
|
|
function get_step ($curr_step, $step_width)
|
|
|
|
{
|
2008-10-07 15:15:53 +02:00
|
|
|
/*if($content['plugin'] && $content['application']&& !is_object($this->plugin))
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
$plugin_definition = $this->plugins[$content['application']][$content['plugin']]['definition'];
|
2009-06-08 18:21:14 +02:00
|
|
|
if($plugin_definition) $this->plugin = new $plugin_definition;
|
2006-11-10 16:30:01 +01:00
|
|
|
}*/
|
2010-02-26 00:13:18 +01:00
|
|
|
if(is_object($this->plugin) && is_array($this->plugin->steps))
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
$steps = array_merge($this->steps,$this->plugin->steps);
|
|
|
|
$steps = array_flip($steps); asort($steps); $steps = array_flip($steps);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$steps = $this->steps;
|
|
|
|
}
|
|
|
|
$step_keys = array_keys($steps);
|
|
|
|
$nn = array_search($curr_step,$step_keys)+(int)$step_width;
|
2010-03-22 16:09:26 +01:00
|
|
|
return (key_exists($nn,$step_keys)) ? $step_keys[$nn] : 'wizard_finish';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard_step10(&$content, &$sel_options, &$readonlys, &$preserv)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step10->$content '.print_r($content,true));
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
// return from step10
|
2010-03-22 16:09:26 +01:00
|
|
|
if ($content['step'] == 'wizard_step10')
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
switch (array_search('pressed', $content['button']))
|
|
|
|
{
|
|
|
|
case 'next':
|
|
|
|
return $this->get_step($content['step'],1);
|
|
|
|
case 'finish':
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'wizard_finish';
|
2006-11-10 16:30:01 +01:00
|
|
|
default :
|
2010-03-22 16:09:26 +01:00
|
|
|
return $this->wizard_step10($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
// init step10
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['msg'] = $this->steps['wizard_step10'];
|
2011-02-22 18:13:03 +01:00
|
|
|
foreach ($this->plugins as $appname => $options)
|
|
|
|
{
|
|
|
|
if($GLOBALS['egw_info']['user']['apps'][$appname] || $GLOBALS['egw_info']['user']['apps']['admin']) {
|
|
|
|
$sel_options['application'][$appname] = lang($appname);
|
|
|
|
}
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][previous]');");
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['step'] = 'wizard_step10';
|
2006-11-10 16:30:01 +01:00
|
|
|
$preserv = $content;
|
|
|
|
unset ($preserv['button']);
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'importexport.wizard_chooseapp';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
// get plugin
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard_step20(&$content, &$sel_options, &$readonlys, &$preserv)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.' . get_class($this) . '::wizard_step20->$content '.print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
// return from step20
|
2010-03-22 16:09:26 +01:00
|
|
|
if ($content['step'] == 'wizard_step20')
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
switch (array_search('pressed', $content['button']))
|
|
|
|
{
|
|
|
|
case 'next':
|
2010-03-22 16:09:26 +01:00
|
|
|
// There's no real reason the plugin has to come from any of these, as long as it has a $steps variable
|
|
|
|
if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv) {
|
|
|
|
$content['type'] = 'import';
|
2010-10-08 01:05:25 +02:00
|
|
|
} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv) {
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['type'] = 'export';
|
|
|
|
} else {
|
|
|
|
throw new egw_exception('Invalid plugin');
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
return $this->get_step($content['step'],1);
|
|
|
|
case 'previous' :
|
|
|
|
unset ($content['plugin']);
|
2010-03-01 18:30:53 +01:00
|
|
|
if(is_object($this->response)) {
|
|
|
|
$this->response->addScript("disable_button('exec[button][previous]');");
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
return $this->get_step($content['step'],-1);
|
|
|
|
case 'finish':
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'wizard_finish';
|
2006-11-10 16:30:01 +01:00
|
|
|
default :
|
2010-03-22 16:09:26 +01:00
|
|
|
return $this->wizard_step20($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// init step20
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['msg'] = $this->steps['wizard_step20'];
|
2011-02-22 18:43:33 +01:00
|
|
|
$config = config::read('phpgwapi');
|
2010-02-26 00:13:18 +01:00
|
|
|
foreach ($this->plugins[$content['application']] as $type => $plugins) {
|
2011-02-22 18:43:33 +01:00
|
|
|
if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue;
|
2010-02-26 00:13:18 +01:00
|
|
|
foreach($plugins as $plugin => $name) {
|
|
|
|
$sel_options['plugin'][$plugin] = $name;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['step'] = 'wizard_step20';
|
2006-11-10 16:30:01 +01:00
|
|
|
$preserv = $content;
|
|
|
|
unset ($preserv['button']);
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'importexport.wizard_chooseplugin';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-01 18:30:53 +01:00
|
|
|
// name
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard_step21(&$content, &$sel_options, &$readonlys, &$preserv)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
|
2010-03-01 18:30:53 +01:00
|
|
|
// return from step21
|
2010-03-22 16:09:26 +01:00
|
|
|
if ($content['step'] == 'wizard_step21')
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
|
|
|
switch (array_search('pressed', $content['button']))
|
|
|
|
{
|
|
|
|
case 'next':
|
|
|
|
return $this->get_step($content['step'],1);
|
|
|
|
case 'previous' :
|
|
|
|
return $this->get_step($content['step'],-1);
|
|
|
|
case 'finish':
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'wizard_finish';
|
2006-11-10 16:30:01 +01:00
|
|
|
default :
|
2010-03-22 16:09:26 +01:00
|
|
|
return $this->wizard_step21($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-01 18:30:53 +01:00
|
|
|
// init step21
|
2006-11-10 16:30:01 +01:00
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['msg'] = $this->steps['wizard_step21'];
|
|
|
|
$content['step'] = 'wizard_step21';
|
2006-11-10 16:30:01 +01:00
|
|
|
$preserv = $content;
|
|
|
|
unset ($preserv['button']);
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'importexport.wizard_choosename';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-01 18:30:53 +01:00
|
|
|
// allowed users
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard_step90(&$content, &$sel_options, &$readonlys, &$preserv)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step90->$content '.print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
// return from step90
|
2010-03-22 16:09:26 +01:00
|
|
|
if ($content['step'] == 'wizard_step90')
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-01 18:30:53 +01:00
|
|
|
$content['allowed_users'] = implode(',',$content['allowed_users']);
|
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
// workaround for some ugly bug related to readonlys;
|
|
|
|
switch (array_search('pressed', $content['button']))
|
|
|
|
{
|
|
|
|
case 'previous' :
|
|
|
|
return $this->get_step($content['step'],-1);
|
2010-03-01 18:30:53 +01:00
|
|
|
case 'next':
|
2006-11-10 16:30:01 +01:00
|
|
|
case 'finish':
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'wizard_finish';
|
2006-11-10 16:30:01 +01:00
|
|
|
default :
|
2010-03-22 16:09:26 +01:00
|
|
|
return $this->wizard_step90($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// init step90
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['msg'] = $this->steps['wizard_step90'];
|
|
|
|
$content['step'] = 'wizard_step90';
|
2006-11-10 16:30:01 +01:00
|
|
|
$preserv = $content;
|
|
|
|
unset ($preserv['button']);
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][next]');");
|
2010-03-01 18:30:53 +01:00
|
|
|
if(is_object($this->response)) {
|
|
|
|
$this->response->addAssign('exec[button][next]','style.display', 'none');
|
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'importexport.wizard_chooseallowedusers';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard_finish(&$content)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_finish->$content '.print_r($content,true));
|
2010-02-26 00:13:18 +01:00
|
|
|
// Take out some UI leavings
|
|
|
|
unset($content['msg']);
|
|
|
|
unset($content['step']);
|
|
|
|
unset($content['button']);
|
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$bodefinitions = new importexport_definitions_bo();
|
2011-02-22 18:13:03 +01:00
|
|
|
// Set owner for non-admins
|
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['admin']) {
|
|
|
|
$content['owner'] = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
$bodefinitions->save($content);
|
|
|
|
// This message is displayed if browser cant close window
|
|
|
|
$content['msg'] = lang('ImportExport wizard finished successfully!');
|
|
|
|
$content['closewindow'] = true;
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'importexport.wizard_close';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function import_definition($content='')
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$bodefinitions = new importexport_definitions_bo();
|
2006-11-10 16:30:01 +01:00
|
|
|
if (is_array($content))
|
|
|
|
{
|
2007-06-08 00:08:38 +02:00
|
|
|
$bodefinitions->import($content['import_file']['tmp_name']);
|
2006-11-10 16:30:01 +01:00
|
|
|
// TODO make redirect here!
|
|
|
|
return $this->index();
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
else
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$etpl = new etemplate(self::_appname.'.import_definition');
|
2010-03-22 16:09:26 +01:00
|
|
|
return $etpl->exec(self::_appname.'.importexport_definitions_ui.import_definition',$content,array(),$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-22 18:13:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Site configuration
|
|
|
|
*/
|
|
|
|
public function site_config($content = array())
|
|
|
|
{
|
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['admin'])
|
|
|
|
{
|
|
|
|
egw::redirect_link('/home');
|
|
|
|
}
|
|
|
|
if($content['save'])
|
|
|
|
{
|
|
|
|
unset($content['save']);
|
|
|
|
|
|
|
|
// ACL
|
|
|
|
$GLOBALS['egw']->acl->delete_repository(self::_appname, 'definition',false);
|
|
|
|
if($content['create_definition_users'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->acl->add_repository(self::_appname, 'definition', $content['create_definition_users'],
|
|
|
|
EGW_ACL_ADD | EGW_ACL_EDIT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
unset($content['create_definition_users']);
|
|
|
|
|
|
|
|
// Other config
|
|
|
|
foreach($content as $key=>$value)
|
|
|
|
{
|
|
|
|
config::save_value($key, $value, 'importexport');
|
|
|
|
}
|
|
|
|
} elseif (isset($content['cancel'])) {
|
|
|
|
$GLOBALS['egw']->redirect_link('/admin/index.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = config::read(self::_appname);
|
|
|
|
$data['create_definition_users'] = $GLOBALS['egw']->acl->get_ids_for_location('definition', EGW_ACL_ADD | EGW_ACL_EDIT, self::_appname);
|
|
|
|
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('Site configuration') . ' - ' . lang(self::_appname);
|
|
|
|
$etpl = new etemplate(self::_appname.'.config');
|
|
|
|
$etpl->exec(self::_appname.'.importexport_definitions_ui.site_config',$data,$sel_options,$readonlys,$preserv);
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|