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
|
|
|
*/
|
|
|
|
|
2016-05-10 00:49:20 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Egw;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
use EGroupware\Api\Etemplate;
|
|
|
|
|
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
|
|
|
|
2013-01-09 20:42:21 +01:00
|
|
|
// To skip a step, step returns this
|
|
|
|
const SKIP = '-skip-';
|
|
|
|
|
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
|
|
|
|
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);
|
2016-05-10 00:49:20 +02:00
|
|
|
Api\Translation::add_app(self::_appname);
|
2007-06-08 00:08:38 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['currentapp'] = self::_appname;
|
2016-07-07 20:25:32 +02:00
|
|
|
|
2016-05-10 00:49:20 +02:00
|
|
|
$this->etpl = new Etemplate();
|
|
|
|
$this->clock = Api\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'];
|
2016-05-10 00:49:20 +02:00
|
|
|
$config = Api\Config::read('phpgwapi');
|
|
|
|
if($config['export_limit'] == 'no' && !Api\Storage\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'];
|
2016-05-10 00:49:20 +02:00
|
|
|
if(count($selected) < 1 || !is_array($selected)) 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-12-03 23:43:47 +01:00
|
|
|
$action = $content['nm']['action'];
|
2012-06-20 19:34:03 +02:00
|
|
|
if($content['nm']['action'] == 'allowed')
|
2011-06-02 18:50:41 +02:00
|
|
|
{
|
2014-02-19 23:37:30 +01:00
|
|
|
$content['allowed'] = $content['allowed_popup']['allowed_private'] == 'true' ? null : (
|
|
|
|
$content['allowed_popup']['all_users']=='true' ? 'all' : implode(',',$content['allowed_popup']['allowed'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content['owner'] = $content['owner_popup']['owner'];
|
2011-06-02 18:50:41 +02:00
|
|
|
}
|
|
|
|
if(is_array($content[$content['nm']['action']]))
|
|
|
|
{
|
|
|
|
$content[$content['nm']['action']] = implode(',',$content[$content['nm']['action']]);
|
|
|
|
}
|
2014-02-19 23:37:30 +01:00
|
|
|
$content['nm']['action'] .= '_' . $content[$action];
|
2012-12-03 23:43:47 +01:00
|
|
|
unset($content[$action]);
|
2014-02-19 23:37:30 +01:00
|
|
|
unset($content['allowed_popup']);
|
2011-06-02 18:50:41 +02:00
|
|
|
}
|
|
|
|
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,
|
|
|
|
'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',
|
2014-07-15 20:09:20 +02:00
|
|
|
'placeholder_actions' => array('add')
|
2011-04-19 18:00:43 +02:00
|
|
|
);
|
2012-12-03 22:55:52 +01:00
|
|
|
if($_GET['application']) $content['nm']['col_filter']['application'] = $_GET['application'];
|
2011-04-19 18:00:43 +02:00
|
|
|
}
|
2016-05-10 00:49:20 +02:00
|
|
|
if(Api\Cache::getSession('importexport', 'index'))
|
2014-07-15 20:09:20 +02:00
|
|
|
{
|
2016-05-10 00:49:20 +02:00
|
|
|
$content['nm'] = array_merge($content['nm'], Api\Cache::getSession('importexport', 'index'));
|
2011-04-19 18:00:43 +02:00
|
|
|
}
|
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'),
|
|
|
|
),
|
2014-07-15 20:09:20 +02:00
|
|
|
'allowed_users' => array(
|
|
|
|
array('value' => 'private', 'label' => lang('Private')),
|
|
|
|
array('value' => 'all', 'label' => 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
|
|
|
|
2016-05-10 00:49:20 +02:00
|
|
|
$etpl = new Etemplate(self::_appname.'.definition_index');
|
2011-04-19 18:00:43 +02:00
|
|
|
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,
|
2014-05-13 23:21:56 +02:00
|
|
|
'onExecute' => 'javaScript:app.importexport.run_definition'
|
2011-06-02 18:50:41 +02:00
|
|
|
),
|
|
|
|
'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,
|
2013-12-03 00:31:00 +01:00
|
|
|
'icon' => 'filesave',
|
|
|
|
'postSubmit' => true
|
2011-06-02 20:41:51 +02:00
|
|
|
),
|
|
|
|
'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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-19 23:37:30 +01:00
|
|
|
* 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)
|
|
|
|
* @param string &$action_msg translated verb for the actions, to be used in a message like %1 entries 'deleted'
|
|
|
|
* @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)
|
|
|
|
{
|
|
|
|
//error_log( __METHOD__."('$action', ".array2string($selected).', '.array2string($use_all).",,, '$session_name')");
|
2011-06-02 18:50:41 +02:00
|
|
|
if ($use_all)
|
2012-03-29 12:43:21 +02:00
|
|
|
{
|
|
|
|
// get the whole selection
|
2016-05-10 00:49:20 +02:00
|
|
|
$old_query = $query = is_array($session_name) ? $session_name : Api\Cache::getSession('importexport', $session_name);
|
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
|
2016-05-10 00:49:20 +02:00
|
|
|
Api\Cache::setSession('importexport', $session_name, $old_query);
|
2011-06-02 18:50:41 +02:00
|
|
|
}
|
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 'allowed':
|
2016-06-07 22:14:02 +02:00
|
|
|
// Field is allowed_users, popup doesn't like _
|
|
|
|
$action = 'allowed_users';
|
|
|
|
// Fall through
|
2011-06-02 18:50:41 +02:00
|
|
|
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);
|
2016-05-10 00:49:20 +02:00
|
|
|
exit();
|
2011-06-02 18:50:41 +02:00
|
|
|
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();
|
2016-05-10 00:49:20 +02:00
|
|
|
Api\Cache::setSession('importexport', 'index', $query);
|
2014-07-15 20:09:20 +02:00
|
|
|
|
|
|
|
// Special handling for allowed users 'private'
|
|
|
|
if($query['col_filter']['allowed_users'] == 'private')
|
|
|
|
{
|
|
|
|
unset($query['col_filter']['allowed_users']);
|
|
|
|
$query['col_filter'][] = 'allowed_users = ' . $GLOBALS['egw']->db->quote(',,');
|
|
|
|
}
|
2011-04-19 18:00:43 +02:00
|
|
|
$bodefinitions = new importexport_definitions_bo($query['col_filter'], true);
|
2014-02-27 22:27:14 +01:00
|
|
|
// We don't care about readonlys for the UI
|
|
|
|
return $bodefinitions->get_rows($query, $rows, $discard);
|
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
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->etpl->read('importexport.wizardbox');
|
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));
|
2014-10-14 18:11:56 +02:00
|
|
|
//foreach($content as $key => $val) error_log(" $key : ".array2string($val));
|
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
|
2013-11-01 23:04:43 +01:00
|
|
|
if (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
|
2016-05-10 00:49:20 +02:00
|
|
|
if($content['application']) Api\Translation::add_app($content['application']);
|
2011-12-05 20:33:29 +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
|
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
|
2013-11-01 23:04:43 +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
|
|
|
{
|
2016-07-07 20:25:32 +02:00
|
|
|
$next_step = $this->plugin->{$content['step']}($content,$sel_options,$readonlys,$preserv);
|
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
|
|
|
{
|
2016-07-07 20:25:32 +02:00
|
|
|
$next_step = $this->{$content['step']}($content,$sel_options,$readonlys,$preserv);
|
2012-10-29 19:29:40 +01:00
|
|
|
}
|
2013-11-01 23:04:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
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
|
2013-11-01 23:04:43 +01:00
|
|
|
if(!$content['name'] || !$content['type'] || !$content['plugin'])
|
|
|
|
{
|
|
|
|
$readonlys['button[finish]'] = true;
|
2010-03-01 18:30:53 +01:00
|
|
|
}
|
2013-11-01 23:04:43 +01:00
|
|
|
do
|
|
|
|
{
|
2013-01-09 20:42:21 +01:00
|
|
|
if(!key_exists($next_step,$this->steps))
|
|
|
|
{
|
|
|
|
$this->wizard_content_template = $this->plugin->$next_step($content,$sel_options,$readonlys,$preserv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->wizard_content_template = $this->$next_step($content,$sel_options,$readonlys,$preserv);
|
|
|
|
}
|
|
|
|
if($this->wizard_content_template == self::SKIP)
|
|
|
|
{
|
|
|
|
if(!key_exists($content['step'],$this->steps))
|
|
|
|
{
|
2016-07-07 20:25:32 +02:00
|
|
|
$next_step = $this->plugin->{$content['step']}($content);
|
2013-01-09 20:42:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-07-07 20:25:32 +02:00
|
|
|
$next_step = $this->{$content['step']}($content);
|
2013-01-09 20:42:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} while($this->wizard_content_template == self::SKIP);
|
2016-07-07 20:25:32 +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;
|
2013-11-01 23:04:43 +01:00
|
|
|
$readonlys['button[finish]'] = true;
|
2011-10-25 23:55:55 +02:00
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
|
2013-11-01 23:04:43 +01:00
|
|
|
unset($content['button']);
|
|
|
|
$content['wizard_content'] = $this->wizard_content_template;
|
2015-12-01 00:23:51 +01:00
|
|
|
$this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,2);
|
2019-01-15 17:39:13 +01:00
|
|
|
|
|
|
|
// Make sure JS is loaded - Framework won't send it
|
|
|
|
Api\Framework::include_css_js_response();
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// initial content
|
|
|
|
$sel_options = $readonlys = $preserv = array();
|
2013-11-01 23:04:43 +01:00
|
|
|
$readonlys['button[previous]'] = true;
|
2006-11-10 16:30:01 +01:00
|
|
|
if($content['edit'])
|
2013-11-01 23:04:43 +01:00
|
|
|
{
|
2006-11-10 16:30:01 +01:00
|
|
|
unset ($content['edit']);
|
2013-11-01 23:04:43 +01:00
|
|
|
}
|
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;
|
2013-11-01 23:04:43 +01:00
|
|
|
$readonlys['button[finish]'] = true;
|
2011-10-25 23:55:55 +02:00
|
|
|
}
|
|
|
|
|
2013-11-01 23:04:43 +01:00
|
|
|
$content['wizard_content'] = $this->wizard_content_template;
|
2013-11-15 20:58:50 +01:00
|
|
|
$this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,2);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
{
|
2014-02-19 00:29:30 +01:00
|
|
|
$content['text'] = $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);
|
|
|
|
}
|
|
|
|
}
|
2013-11-01 23:04:43 +01:00
|
|
|
$readonlys['button[previous]'] = true;
|
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 {
|
2016-05-10 00:49:20 +02:00
|
|
|
throw new Api\Exception('Invalid plugin');
|
2010-03-22 16:09:26 +01:00
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
return $this->get_step($content['step'],1);
|
|
|
|
case 'previous' :
|
2013-11-01 23:04:43 +01:00
|
|
|
$readonlys['button[previous]'] = true;
|
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
|
|
|
|
{
|
2014-02-19 00:29:30 +01:00
|
|
|
$content['text'] = $this->steps['wizard_step20'];
|
2016-05-10 00:49:20 +02:00
|
|
|
$config = Api\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'],
|
2016-05-10 00:49:20 +02:00
|
|
|
$content['name'] .'-'. Api\DateTime::to('now', true),
|
2011-05-24 17:33:00 +02:00
|
|
|
//$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
|
|
|
|
{
|
2014-02-19 00:29:30 +01:00
|
|
|
$content['text'] = $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))
|
|
|
|
{
|
2016-05-10 00:49:20 +02:00
|
|
|
$content['owner'] = $content['just_me'] || !$GLOBALS['egw']->acl->check('share_definitions', Acl::READ,'importexport') ?
|
2011-10-26 21:54:15 +02:00
|
|
|
($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
|
|
|
|
{
|
2014-02-19 00:29:30 +01:00
|
|
|
$content['text'] = $this->steps['wizard_step90'];
|
2010-03-22 16:09:26 +01:00
|
|
|
$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']);
|
2014-02-19 00:38:51 +01:00
|
|
|
$content['all_users'] = is_array($content['allowed_users']) && array_key_exists('0',$content['allowed_users']) && $content['allowed_users'][0] == 'all' ||
|
2014-07-15 20:09:20 +02:00
|
|
|
$content['allowed_users'] == 'all';
|
2016-05-10 00:49:20 +02:00
|
|
|
if(!$GLOBALS['egw']->acl->check('share_definition', Acl::READ, 'importexport') && !$GLOBALS['egw_info']['user']['apps']['admin'])
|
2013-11-01 23:04:43 +01:00
|
|
|
{
|
2011-02-24 00:44:20 +01:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2014-07-15 20:09:20 +02:00
|
|
|
$sel_options = array(
|
|
|
|
'allowed_users' => array(
|
|
|
|
array('value' => null, 'label' => lang('Just me')),
|
|
|
|
array('value' => 'all', 'label' => lang('all users'))
|
|
|
|
)
|
|
|
|
);
|
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']);
|
2016-07-07 20:25:32 +02:00
|
|
|
|
2013-11-01 23:04:43 +01:00
|
|
|
$readonlys['button[next]'] = true;
|
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
|
2014-02-19 00:29:30 +01:00
|
|
|
unset($content['text']);
|
2010-02-26 00:13:18 +01:00
|
|
|
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!');
|
2016-05-10 00:49:20 +02:00
|
|
|
Framework::refresh_opener('','importexport');
|
|
|
|
Framework::window_close();
|
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
|
|
|
{
|
2013-06-24 19:40:44 +02:00
|
|
|
$content = array();
|
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;
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|