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' => '*');
|
|
|
|
|
2011-02-24 00:44:20 +01:00
|
|
|
if($GLOBALS['egw_info']['user']['apps']['admin']) {
|
|
|
|
// Any public definition
|
2011-04-11 17:45:29 +02:00
|
|
|
$filter[] = '(owner=0 OR owner IS NULL OR allowed_users IS NOT NULL OR owner = ' . $GLOBALS['egw_info']['user']['account_id'] . ')';
|
2011-02-24 00:44:20 +01:00
|
|
|
} else {
|
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-24 16:47:43 +01:00
|
|
|
$config = config::read('phpgwapi');
|
2011-08-29 17:02:00 +02:00
|
|
|
if($config['export_limit'] == 'no' && !bo_merge::is_export_limit_excepted()) {
|
2011-02-24 16:47:43 +01:00
|
|
|
$filter['type'] = 'import';
|
|
|
|
}
|
2011-02-23 17:45:19 +01:00
|
|
|
}
|
2011-02-22 18:43:33 +01:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
if (is_array($content))
|
|
|
|
{
|
2011-06-02 18:50:41 +02:00
|
|
|
// Handle legacy actions
|
|
|
|
if (isset($content['nm']['rows']['delete']))
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2011-06-02 18:50:41 +02:00
|
|
|
$content['nm']['action'] = 'delete';
|
|
|
|
$content['nm']['selected'] = array_keys($content['nm']['rows']['delete'],'pressed');
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2011-04-19 18:00:43 +02:00
|
|
|
elseif(($button = array_search('pressed',$content['nm']['rows'])) !== false)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2011-06-01 15:56:24 +02:00
|
|
|
$selected = $content['nm']['rows']['selected'];
|
2011-06-02 18:50:41 +02:00
|
|
|
if(count($selected) < 1 || !is_array($selected)) common::egw_exit();
|
2006-11-10 16:30:01 +01:00
|
|
|
switch ($button)
|
|
|
|
{
|
|
|
|
case 'delete_selected' :
|
2011-06-02 18:50:41 +02:00
|
|
|
$content['nm']['selected'] = $selected;
|
|
|
|
$content['nm']['action'] = 'delete';
|
2006-11-10 16:30:01 +01:00
|
|
|
break;
|
2011-06-02 18:50:41 +02:00
|
|
|
case 'export_selected':
|
|
|
|
$content['nm']['selected'] = $selected;
|
|
|
|
$content['nm']['action'] = 'export';
|
2006-11-10 16:30:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-02 18:50:41 +02:00
|
|
|
if ($content['nm']['action'])
|
|
|
|
{
|
|
|
|
if (!count($content['nm']['selected']) && !$content['nm']['select_all'])
|
|
|
|
{
|
|
|
|
$msg = lang('You need to select some entries first!');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Action has an additional parameter
|
|
|
|
if(in_array($content['nm']['action'], array('owner', 'allowed')))
|
|
|
|
{
|
2012-06-20 19:34:03 +02:00
|
|
|
if($content['nm']['action'] == 'allowed')
|
2011-06-02 18:50:41 +02:00
|
|
|
{
|
2012-06-20 19:34:03 +02:00
|
|
|
$content['allowed'] = $content['allowed_private'] ? null : ($content['all_users'] ? 'all' : implode(',',$content['allowed']));
|
2011-06-02 18:50:41 +02:00
|
|
|
}
|
|
|
|
if(is_array($content[$content['nm']['action']]))
|
|
|
|
{
|
|
|
|
$content[$content['nm']['action']] = implode(',',$content[$content['nm']['action']]);
|
|
|
|
}
|
|
|
|
$content['nm']['action'] .= '_' . $content[$content['nm']['action']];
|
|
|
|
}
|
|
|
|
if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'],
|
|
|
|
$success,$failed,$action_msg,'index',$msg))
|
|
|
|
{
|
|
|
|
$msg .= lang('%1 definition(s) %2',$success,$action_msg);
|
|
|
|
}
|
|
|
|
elseif(empty($msg))
|
|
|
|
{
|
|
|
|
$msg .= lang('%1 definition(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2011-04-19 18:00:43 +02:00
|
|
|
if(!is_array($content['nm'])) {
|
|
|
|
$content['nm'] = array(
|
|
|
|
'get_rows' => 'importexport.importexport_definitions_ui.get_rows',
|
|
|
|
'no_cat' => true,
|
|
|
|
'no_filter' => true,
|
|
|
|
'no_filter2' => true,
|
|
|
|
'header_right' => 'importexport.definition_index.add',
|
|
|
|
'csv_fields' => false, // Disable CSV export, uses own export
|
2011-06-02 18:50:41 +02:00
|
|
|
'default_cols' => '!actions', // switch legacy actions column and row off by default
|
|
|
|
'row_id' => 'definition_id',
|
2011-04-19 18:00:43 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if(egw_session::appsession('index', 'importexport')) {
|
|
|
|
$content['nm'] = array_merge($content['nm'], egw_session::appsession('index', 'importexport'));
|
|
|
|
}
|
2011-06-02 18:50:41 +02:00
|
|
|
$content['nm']['actions'] = $this->get_actions();
|
2011-04-19 18:00:43 +02:00
|
|
|
$sel_options = array(
|
|
|
|
'type' => array(
|
|
|
|
'import' => lang('import'),
|
|
|
|
'export' => lang('export'),
|
|
|
|
),
|
2012-06-05 23:50:34 +02:00
|
|
|
'allowed_users' => array(null => lang('Private'), 'all' => lang('all'))
|
2011-04-19 18:00:43 +02: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);
|
2011-02-14 16:54:28 +01:00
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2011-06-02 18:50:41 +02:00
|
|
|
if($msg) $content['msg'] = $msg;
|
2011-04-19 18:00:43 +02:00
|
|
|
|
|
|
|
$etpl = new etemplate(self::_appname.'.definition_index');
|
|
|
|
return $etpl->exec( self::_appname.'.importexport_definitions_ui.index', $content, $sel_options, $readonlys, $preserv );
|
|
|
|
}
|
|
|
|
|
2011-05-24 19:04:16 +02:00
|
|
|
private function get_actions() {
|
2011-06-02 18:50:41 +02:00
|
|
|
$group = 0;
|
2011-05-24 19:04:16 +02:00
|
|
|
$actions = array(
|
|
|
|
'edit' => array(
|
2011-06-02 18:50:41 +02:00
|
|
|
'caption' => 'Open',
|
|
|
|
'default' => true,
|
2011-05-24 19:04:16 +02:00
|
|
|
'allowOnMultiple' => false,
|
2011-06-02 18:50:41 +02:00
|
|
|
'url' => 'menuaction=importexport.importexport_definitions_ui.edit&definition=$id',
|
2011-06-02 22:10:20 +02:00
|
|
|
'popup' => '500x500',
|
2011-05-24 19:04:16 +02:00
|
|
|
'group' => $group,
|
|
|
|
),
|
2011-06-02 18:50:41 +02:00
|
|
|
'add' => array(
|
2011-06-02 20:41:51 +02:00
|
|
|
'caption' => 'Add',
|
|
|
|
'url' => 'menuaction=importexport.importexport_definitions_ui.edit',
|
2011-06-02 22:10:20 +02:00
|
|
|
'popup' => '500x500',
|
2011-06-02 20:41:51 +02:00
|
|
|
'group' => $group,
|
|
|
|
),
|
2011-06-02 18:50:41 +02:00
|
|
|
'execute' => array(
|
|
|
|
'caption' => 'Execute',
|
|
|
|
'icon' => 'importexport/navbar',
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'group' => $group,
|
|
|
|
),
|
|
|
|
'schedule' => array(
|
|
|
|
'caption' => 'Schedule',
|
2011-06-02 20:41:51 +02:00
|
|
|
'icon' => 'timesheet/navbar',
|
2011-06-02 18:50:41 +02:00
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'url' => 'menuaction=importexport.importexport_schedule_ui.edit&definition=$id',
|
2011-06-02 22:10:20 +02:00
|
|
|
'popup' => '500x500',
|
2011-06-02 18:50:41 +02:00
|
|
|
'group' => $group,
|
|
|
|
),
|
|
|
|
'change' => array(
|
|
|
|
'caption' => 'Change',
|
|
|
|
'icon' => 'edit',
|
|
|
|
'children' => array(
|
|
|
|
'owner' => array(
|
|
|
|
'caption' => 'Owner',
|
|
|
|
'group' => 1,
|
2011-06-02 20:41:51 +02:00
|
|
|
'icon' => 'addressbook/accounts',
|
2011-06-02 18:50:41 +02:00
|
|
|
'nm_action' => 'open_popup',
|
|
|
|
),
|
|
|
|
'allowed' => array(
|
|
|
|
'caption' => 'Allowed users',
|
|
|
|
'group' => 1,
|
2011-06-02 20:41:51 +02:00
|
|
|
'icon' => 'addressbook/group',
|
2011-06-02 18:50:41 +02:00
|
|
|
'nm_action' => 'open_popup',
|
|
|
|
)
|
|
|
|
),
|
2011-10-26 21:54:15 +02:00
|
|
|
'disableClass' => 'rowNoEdit',
|
2011-06-02 18:50:41 +02:00
|
|
|
),
|
|
|
|
'select_all' => array(
|
|
|
|
'caption' => 'Whole query',
|
|
|
|
'checkbox' => true,
|
2011-06-06 18:08:57 +02:00
|
|
|
'hint' => 'Apply the action on the whole query, NOT only the shown definitions!!!',
|
2011-06-02 18:50:41 +02:00
|
|
|
'group' => ++$group,
|
|
|
|
),
|
|
|
|
'copy' => array(
|
2011-06-02 20:41:51 +02:00
|
|
|
'caption' => 'Copy',
|
|
|
|
'group' => ++$group,
|
2011-06-02 18:50:41 +02:00
|
|
|
),
|
2011-12-01 19:49:42 +01:00
|
|
|
'createexport' => array(
|
|
|
|
'caption' => 'Create export',
|
|
|
|
'hint' => 'Create a matching export definition based on this import definition',
|
|
|
|
'icon' => 'export',
|
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'disableClass' => 'export'
|
|
|
|
),
|
|
|
|
|
2011-06-02 18:50:41 +02:00
|
|
|
'export' => array(
|
2011-06-02 20:41:51 +02:00
|
|
|
'caption' => 'Export',
|
|
|
|
'group' => $group,
|
|
|
|
'icon' => 'filesave'
|
|
|
|
),
|
|
|
|
'delete' => array(
|
|
|
|
'caption' => 'Delete',
|
|
|
|
'confirm' => 'Delete this entry',
|
|
|
|
'confirm_multiple' => 'Delete these entries',
|
|
|
|
'group' => ++$group,
|
|
|
|
'disableClass' => 'rowNoDelete',
|
2011-06-02 18:50:41 +02:00
|
|
|
),
|
2011-05-24 19:04:16 +02:00
|
|
|
);
|
2011-06-02 18:50:41 +02:00
|
|
|
|
|
|
|
// Unset admin actions
|
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['admin'])
|
|
|
|
{
|
|
|
|
unset($actions['schedule']);
|
|
|
|
}
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* apply an action to multiple entries
|
|
|
|
*
|
|
|
|
* @param string/int $action 'delete', 'export', etc.
|
|
|
|
* @param array $selected id's to use if !$use_all
|
|
|
|
* @param boolean $use_all if true use all entries of the current selection (in the session)
|
|
|
|
* @param int &$success number of succeded actions
|
|
|
|
* @param int &$failed number of failed actions (not enought permissions)
|
2011-06-06 18:08:57 +02:00
|
|
|
* @param string &$action_msg translated verb for the actions, to be used in a message like %1 entries 'deleted'
|
2011-06-02 18:50:41 +02:00
|
|
|
* @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
|
|
|
|
* @return boolean true if all actions succeded, false otherwise
|
|
|
|
*/
|
|
|
|
function action($action,$selected,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg)
|
|
|
|
{
|
|
|
|
//echo __METHOD__."('$action', ".array2string($selected).', '.array2string($use_all).",,, '$session_name')";
|
|
|
|
if ($use_all)
|
2012-03-29 12:43:21 +02:00
|
|
|
{
|
|
|
|
// get the whole selection
|
|
|
|
$old_query = $query = is_array($session_name) ? $session_name : egw_session::appsession($session_name,'importexport');
|
2011-06-02 18:50:41 +02:00
|
|
|
|
2012-03-29 12:43:21 +02:00
|
|
|
@set_time_limit(0); // switch off the execution time limit, as it's for big selections to small
|
|
|
|
$query['num_rows'] = -1; // all
|
|
|
|
$query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
|
2011-06-02 18:50:41 +02:00
|
|
|
$this->get_rows($query,$rows,$readonlys);
|
|
|
|
|
|
|
|
$selected = array();
|
|
|
|
foreach($rows as $row) {
|
|
|
|
$selected[] = $row['definition_id'];
|
|
|
|
}
|
|
|
|
if(!is_array($session_name))
|
|
|
|
{
|
|
|
|
// Restore old query
|
|
|
|
egw_session::appsession($session_name, 'importexport',$old_query);
|
|
|
|
}
|
2012-03-29 12:43:21 +02:00
|
|
|
}
|
2011-06-02 18:50:41 +02:00
|
|
|
|
|
|
|
// Dialogs to get options
|
|
|
|
list($action, $settings) = explode('_', $action, 2);
|
|
|
|
|
|
|
|
$bodefinitions = new importexport_definitions_bo(false, true);
|
|
|
|
|
|
|
|
switch($action) {
|
|
|
|
case 'execute':
|
|
|
|
// There's probably a way to do this in just JS, all the info should be there...
|
|
|
|
foreach($selected as $id) {
|
|
|
|
$definition = $bodefinitions->read((int)$id);
|
|
|
|
$link = egw::link('/index.php', array(
|
|
|
|
'menuaction' => 'importexport.importexport_'.$definition['type'].'_ui.'.$definition['type'].'_dialog',
|
|
|
|
'appname' => $definition['application'],
|
|
|
|
'definition' => $definition['name']
|
|
|
|
));
|
|
|
|
egw_framework::set_onload("egw_openWindowCentered2('$link','_blank',850,440,'yes');");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'allowed':
|
|
|
|
$action = 'allowed_users';// Field is allowed_users, popup doesn't like _
|
|
|
|
case 'owner':
|
|
|
|
$action_msg = lang('changed'. ' ' . $action);
|
|
|
|
foreach($selected as $id) {
|
|
|
|
$definition = $bodefinitions->read((int)$id);
|
|
|
|
if($definition['definition_id']) {
|
|
|
|
// Prevent private with no owner
|
|
|
|
if(!$definition['owner'] && !$settings) $definition['owner'] = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
|
|
|
|
$definition[$action] = $settings;
|
|
|
|
$bodefinitions->save($definition);
|
|
|
|
$success++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'delete':
|
|
|
|
$bodefinitions->delete($selected);
|
|
|
|
$action_msg = lang('deleted');
|
|
|
|
break;
|
2011-06-17 16:07:10 +02:00
|
|
|
|
2011-06-02 18:50:41 +02:00
|
|
|
case 'export' :
|
|
|
|
$action_msg = lang('exported');
|
|
|
|
$mime_type = ($GLOBALS['egw']->html->user_agent == 'msie' || $GLOBALS['egw']->html->user_agent == 'opera') ?
|
|
|
|
'application/octetstream' : 'application/octet-stream';
|
|
|
|
$name = 'importexport_definition.xml';
|
|
|
|
header('Content-Type: ' . $mime_type);
|
|
|
|
header('Content-Disposition: attachment; filename="'.$name.'"');
|
|
|
|
echo $bodefinitions->export($selected);
|
|
|
|
common::egw_exit();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'copy':
|
|
|
|
$action_msg = lang('copied');
|
|
|
|
// Should only be one selected
|
|
|
|
foreach($selected as $id) {
|
|
|
|
$definition = $bodefinitions->read((int)$id);
|
|
|
|
if($definition['definition_id']) {
|
|
|
|
unset($definition['definition_id']);
|
|
|
|
$definition['name'] = $settings ? $settings : $definition['name'] . ' copy';
|
2011-06-06 18:08:57 +02:00
|
|
|
try {
|
|
|
|
$bodefinitions->save($definition);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
try {
|
|
|
|
$definition['name'] .= ' ' . $GLOBALS['egw_info']['user']['account_lid'];
|
|
|
|
$bodefinitions->save($definition);
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$failed++;
|
2011-08-06 00:04:05 +02:00
|
|
|
$msg .= lang('Duplicate name, please choose another.');
|
2011-06-06 18:08:57 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2011-06-02 18:50:41 +02:00
|
|
|
$success++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-12-01 19:49:42 +01:00
|
|
|
case 'createexport':
|
|
|
|
$action_msg = lang('created');
|
|
|
|
// Should only be one selected
|
|
|
|
foreach($selected as $id) {
|
|
|
|
$definition = new importexport_definition($id);
|
|
|
|
try {
|
2011-12-05 12:12:07 +01:00
|
|
|
$export = $bodefinitions->export_from_import($definition);
|
2011-12-01 19:49:42 +01:00
|
|
|
$export->save();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
if($export)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$export->name = $export->name.' ' . $GLOBALS['egw_info']['user']['account_lid'];
|
|
|
|
$export->save();
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$failed++;
|
|
|
|
$msg .= lang('Duplicate name, please choose another.');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$failed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$success++;
|
|
|
|
}
|
|
|
|
break;
|
2011-06-02 18:50:41 +02:00
|
|
|
}
|
|
|
|
return !$failed;
|
2011-05-24 19:04:16 +02:00
|
|
|
}
|
|
|
|
|
2011-04-19 18:00:43 +02:00
|
|
|
public function get_rows(&$query, &$rows, &$readonlys) {
|
|
|
|
$rows = array();
|
|
|
|
egw_session::appsession('index','importexport',$query);
|
|
|
|
$bodefinitions = new importexport_definitions_bo($query['col_filter'], true);
|
|
|
|
return $bodefinitions->get_rows($query, $rows, $readonlys);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2012-09-06 23:50:58 +02:00
|
|
|
/**
|
|
|
|
* Edit a definition
|
|
|
|
*
|
|
|
|
* To jump to a certain step, pass the previous step in the URL step=wizard_stepXX
|
|
|
|
* The wizard will validate that step, then display the _next_ step..
|
|
|
|
*/
|
2006-11-10 16:30:01 +01:00
|
|
|
function edit()
|
|
|
|
{
|
|
|
|
if(!$_definition = $_GET['definition'])
|
|
|
|
{
|
2012-09-06 23:50:58 +02:00
|
|
|
$content = array(
|
|
|
|
'edit' => true,
|
|
|
|
'application' => $_GET['application'],
|
|
|
|
'plugin' => $_GET['plugin']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Jump to a step
|
|
|
|
if($_GET['step'])
|
|
|
|
{
|
|
|
|
$content['edit'] = false;
|
|
|
|
// Wizard will process previous step, then advance
|
|
|
|
$content['step'] = $this->get_step($_GET['step'],-1);
|
|
|
|
$content['button']['next'] = 'pressed';
|
|
|
|
$this->wizard($content);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Initial form
|
|
|
|
$this->wizard($content);
|
|
|
|
}
|
|
|
|
return;
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2011-12-01 19:49:42 +01:00
|
|
|
if(is_numeric($_GET['definition']))
|
|
|
|
{
|
|
|
|
$definition = (int)$_GET['definition'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$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);
|
2006-11-10 16:30:01 +01:00
|
|
|
$definition['edit'] = true;
|
2012-09-06 23:50:58 +02:00
|
|
|
// Jump to a step
|
|
|
|
if($_GET['step'])
|
|
|
|
{
|
|
|
|
$definition['edit'] = false;
|
|
|
|
// Wizard will process previous step, then advance
|
|
|
|
$definition['step'] = $_GET['step'];;
|
|
|
|
$definition['button'] = array('next' => 'pressed');
|
|
|
|
}
|
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']);
|
2011-04-11 17:45:29 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
// 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
|
|
|
}
|
2011-12-05 20:33:29 +01:00
|
|
|
// App translations
|
|
|
|
if($content['application']) translation::add_app($content['application']);
|
|
|
|
|
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
|
2011-04-11 17:45:29 +02:00
|
|
|
if(!is_object($GLOBALS['egw']->importexport_definitions_ui) || $GLOBALS['egw']->importexport_definitions_ui !== $this)
|
2010-03-22 16:09:26 +01:00
|
|
|
$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');
|
|
|
|
}
|
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']) {
|
2011-10-26 21:54:15 +02:00
|
|
|
if(!$this->can_edit($content))
|
|
|
|
{
|
|
|
|
// Each step changes definition, reload it
|
|
|
|
$bodefinitions = new importexport_definitions_bo();
|
|
|
|
$definition = $bodefinitions->read($content);
|
|
|
|
$content = $definition + array('step' => $content['step'], 'button' => $content['button']);
|
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
if(!key_exists($content['step'],$this->steps))
|
2011-11-03 21:23:04 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$next_step = $this->plugin->$content['step']($content);
|
2011-11-03 21:23:04 +01:00
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
else
|
2012-10-29 19:29:40 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$next_step = $this->$content['step']($content);
|
2012-10-29 19:29:40 +01:00
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
} 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
|
|
|
|
2012-09-12 18:43:20 +02:00
|
|
|
// Override next button on step 30, to do a regular submit for the file upload
|
|
|
|
if($next_step == 'wizard_step30')
|
|
|
|
{
|
|
|
|
$this->etpl->set_cell_attribute('button[next]', 'onclick', '');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2011-10-26 21:54:15 +02:00
|
|
|
if(!$this->can_edit($content))
|
2011-10-25 23:55:55 +02:00
|
|
|
{
|
|
|
|
$readonlys[$this->wizard_content_template] = true;
|
|
|
|
$preserve = $content;
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][finish]');");
|
|
|
|
}
|
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);
|
2011-10-25 23:55:55 +02:00
|
|
|
|
2011-10-26 21:54:15 +02:00
|
|
|
if(!$this->can_edit($content))
|
2011-10-25 23:55:55 +02:00
|
|
|
{
|
|
|
|
$readonlys[$this->wizard_content_template] = true;
|
|
|
|
$preserve = $content;
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][finish]');");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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'])
|
|
|
|
{
|
2012-09-12 19:55:13 +02:00
|
|
|
$this->response->addScript("opener.location.reload();");
|
2006-11-10 16:30:01 +01:00
|
|
|
$this->response->addScript("window.close();");
|
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);
|
2011-04-11 17:45:29 +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');
|
2011-02-24 01:13:42 +01:00
|
|
|
$this->response->addScript("set_style_by_class('div','popupManual','display','inline');
|
|
|
|
popup_resize();
|
|
|
|
");
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
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
|
2012-10-29 19:29:40 +01:00
|
|
|
if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv || strpos(get_class($this->plugin), 'import') !== false) {
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['type'] = 'import';
|
2012-10-29 19:29:40 +01:00
|
|
|
} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv || strpos(get_class($this->plugin),'export') !== false) {
|
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
|
|
|
|
2011-05-24 17:33:00 +02:00
|
|
|
// Check for duplicate name
|
|
|
|
$duplicate = isset($content['duplicate_error']);
|
|
|
|
if($content['name'] && !$duplicate)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$check_definition = new importexport_definition($content['name']);
|
2011-06-02 18:50:41 +02:00
|
|
|
if($check_definition && $check_definition->definition_id && $check_definition->definition_id != $content['definition_id'])
|
2011-05-24 17:33:00 +02:00
|
|
|
{
|
|
|
|
throw new Exception('Already exists');
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// throw new Exception('Already exists');
|
|
|
|
$content['duplicate_error'] = lang('Duplicate name, please choose another.');
|
2011-06-17 16:07:10 +02:00
|
|
|
|
2011-05-24 17:33:00 +02:00
|
|
|
// Try some suggestions
|
|
|
|
$suggestions = array(
|
|
|
|
$content['name'] .'-'. $GLOBALS['egw_info']['user']['account_lid'],
|
|
|
|
$content['name'] .'-'. $GLOBALS['egw_info']['user']['account_id'],
|
|
|
|
$content['name'] .'-'. egw_time::to('now', true),
|
|
|
|
//$content['name'] .'-'. rand(0,100),
|
|
|
|
);
|
|
|
|
foreach($suggestions as $key => $suggestion) {
|
|
|
|
$sug_definition = new importexport_definition($suggestion);
|
|
|
|
if($sug_definition->definition_id) {
|
|
|
|
unset($suggestions[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($suggestions) {
|
|
|
|
$content['duplicate_error'] .= ' '. lang('Try')." \n" . implode("\n", $suggestions);
|
|
|
|
}
|
|
|
|
return $this->get_step($content['step'],0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 18:30:53 +01:00
|
|
|
// return from step21
|
2011-05-24 17:33:00 +02:00
|
|
|
if ($content['step'] == 'wizard_step21' && !$duplicate)
|
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
|
|
|
|
{
|
2011-05-24 17:33:00 +02:00
|
|
|
$content['msg'] = $this->steps['wizard_step21'] . ($duplicate ? "\n".$content['duplicate_error'] : '');
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['step'] = 'wizard_step21';
|
2011-05-24 17:33:00 +02:00
|
|
|
unset($content['duplicate_error']);
|
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
|
|
|
{
|
2011-10-26 21:54:15 +02:00
|
|
|
if($this->can_edit($content))
|
|
|
|
{
|
|
|
|
$content['owner'] = $content['just_me'] || !$GLOBALS['egw']->acl->check('share_definitions', EGW_ACL_READ,'importexport') ?
|
|
|
|
($content['owner'] ? $content['owner'] : $GLOBALS['egw_info']['user']['account_id']) :
|
|
|
|
null;
|
2012-06-05 23:50:34 +02:00
|
|
|
$content['allowed_users'] = $content['just_me'] ? '' : ($content['all_users'] ? 'all' : implode(',',$content['allowed_users']));
|
2011-10-26 21:54:15 +02:00
|
|
|
unset($content['just_me']);
|
|
|
|
}
|
2010-03-01 18:30:53 +01:00
|
|
|
|
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;
|
2011-02-24 00:44:20 +01:00
|
|
|
|
|
|
|
// Set owner for non-admins
|
|
|
|
$content['just_me'] = ((!$content['allowed_users'] || !$content['allowed_users'][0] && count($content['allowed_users']) ==1) && $content['owner']);
|
|
|
|
//if(!$GLOBALS['egw_info']['user']['apps']['admin'] && !$GLOBALS['egw']->acl->check('share_definition', EGW_ACL_READ, 'importexport')) {
|
|
|
|
if(!$GLOBALS['egw']->acl->check('share_definition', EGW_ACL_READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin']) {
|
|
|
|
$content['allowed_users'] = array();
|
|
|
|
$readonlys['allowed_users'] = true;
|
|
|
|
$readonlys['just_me'] = true;
|
2012-06-05 23:50:34 +02:00
|
|
|
$readonlys['all_users'] = true;
|
2011-02-24 00:44:20 +01:00
|
|
|
$content['just_me'] = true;
|
|
|
|
}
|
|
|
|
|
2011-10-26 21:54:15 +02:00
|
|
|
// Hide 'just me' checkbox, users get confused by read-only
|
|
|
|
if($readonlys['just_me'] || !$this->can_edit($content))
|
|
|
|
{
|
|
|
|
$content['no_just_me'] = true;
|
|
|
|
}
|
2012-06-05 23:50:34 +02:00
|
|
|
if($readonlys['all_users'] || !$this->can_edit($content))
|
|
|
|
{
|
|
|
|
$content['no_all_users'] = true;
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
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();
|
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))
|
|
|
|
{
|
2011-05-24 18:13:51 +02:00
|
|
|
if($content['import_file']['tmp_name'])
|
|
|
|
{
|
2012-01-20 19:39:50 +01:00
|
|
|
$result = $bodefinitions->import($content['import_file']['tmp_name']);
|
|
|
|
$msg = lang('%1 definitions %2', count($result), lang('imported')) ."\n". implode("\n", array_keys($result));
|
|
|
|
return $this->index(null, $msg);
|
2011-05-24 18:13:51 +02:00
|
|
|
}
|
|
|
|
if($content['update'])
|
|
|
|
{
|
|
|
|
$applist = importexport_helper_functions::get_apps('all', true);
|
|
|
|
foreach($applist as $appname) {
|
|
|
|
importexport_helper_functions::load_defaults($appname);
|
|
|
|
}
|
2012-01-20 19:39:50 +01:00
|
|
|
return $this->index();
|
2011-05-24 18:13:51 +02:00
|
|
|
}
|
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
|
|
|
{
|
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
|
|
|
|
2011-10-26 21:54:15 +02:00
|
|
|
/**
|
|
|
|
* Determine if the user is allowed to edit the definition
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
protected function can_edit(Array $definition)
|
|
|
|
{
|
|
|
|
if($definition['owner'] && $definition['owner'] == $GLOBALS['egw_info']['user']['account_id'])
|
|
|
|
{
|
|
|
|
// Definition belongs to user
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elseif($definition['definition_id'] && !$definition['owner'] && $GLOBALS['egw_info']['user']['apps']['admin'])
|
|
|
|
{
|
|
|
|
// Definition is unowned, and user is an admin
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
elseif(!$definition['definition_id'])
|
|
|
|
{
|
|
|
|
// Definition is in-progress, not saved yet
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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);
|
2011-02-24 00:44:20 +01:00
|
|
|
$GLOBALS['egw']->acl->delete_repository(self::_appname, 'share_definition',false);
|
2011-10-31 20:36:21 +01:00
|
|
|
|
|
|
|
foreach($content['share_definition'] as $group)
|
2011-02-22 18:13:03 +01:00
|
|
|
{
|
2011-10-31 20:36:21 +01:00
|
|
|
$GLOBALS['egw']->acl->add_repository(self::_appname, 'share_definition', $group,EGW_ACL_READ);
|
2011-02-22 18:13:03 +01:00
|
|
|
}
|
2011-02-24 00:44:20 +01:00
|
|
|
unset($content['share_definition']);
|
2011-02-22 18:13:03 +01:00
|
|
|
|
|
|
|
// 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);
|
2011-02-24 00:44:20 +01:00
|
|
|
$data['share_definition'] = $GLOBALS['egw']->acl->get_ids_for_location('share_definition', EGW_ACL_READ, self::_appname);
|
2011-12-05 18:27:04 +01:00
|
|
|
$sel_options['import_charsets'] = array_combine(mb_list_encodings(),mb_list_encodings());
|
2012-03-29 12:43:21 +02:00
|
|
|
|
2011-12-07 01:12:18 +01:00
|
|
|
// Remove 'standard' encodings to prevent doubles
|
|
|
|
foreach($GLOBALS['egw']->translation->get_installed_charsets() as $charset => $label)
|
|
|
|
{
|
|
|
|
unset($sel_options['import_charsets'][strtoupper($charset)]);
|
|
|
|
}
|
2011-02-22 18:13:03 +01:00
|
|
|
|
2011-05-24 18:13:51 +02:00
|
|
|
if(!$data['update']) $data['update'] = 'request';
|
2011-04-19 18:00:43 +02:00
|
|
|
|
2011-02-22 18:13:03 +01:00
|
|
|
$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
|
|
|
}
|