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');
|
|
|
|
if($config['export_limit'] == 'no') {
|
|
|
|
$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')))
|
|
|
|
{
|
|
|
|
if($content['nm']['action'] == 'allowed' && $content['allowed_private'])
|
|
|
|
{
|
|
|
|
$content['allowed'] = null;
|
|
|
|
}
|
|
|
|
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'),
|
|
|
|
),
|
|
|
|
'allowed_users' => array(null => lang('Private'))
|
|
|
|
);
|
|
|
|
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,
|
|
|
|
'disableClass' => 'rowNoEdit',
|
|
|
|
),
|
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',
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'select_all' => array(
|
|
|
|
'caption' => 'Whole query',
|
|
|
|
'checkbox' => true,
|
|
|
|
'hint' => 'Apply the action on the whole query, NOT only the shown contacts!!!',
|
|
|
|
'group' => ++$group,
|
|
|
|
),
|
|
|
|
'copy' => array(
|
2011-06-02 20:41:51 +02:00
|
|
|
'caption' => 'Copy',
|
|
|
|
'group' => ++$group,
|
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)
|
|
|
|
* @param string &$action_msg translated verb for the actions, to be used in a message like %1 contacts '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)
|
|
|
|
{
|
|
|
|
//echo __METHOD__."('$action', ".array2string($selected).', '.array2string($use_all).",,, '$session_name')";
|
|
|
|
if ($use_all)
|
|
|
|
{
|
|
|
|
// get the whole selection
|
|
|
|
$old_query = $query = is_array($session_name) ? $session_name : egw_session::appsession($session_name,'importexport');
|
|
|
|
|
|
|
|
@set_time_limit(0); // switch off the execution time limit, as it's for big selections to small
|
|
|
|
$query['num_rows'] = -1; // all
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
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';
|
|
|
|
$bodefinitions->save($definition);
|
|
|
|
$success++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
function edit()
|
|
|
|
{
|
|
|
|
if(!$_definition = $_GET['definition'])
|
|
|
|
{
|
|
|
|
//close window
|
|
|
|
}
|
|
|
|
$definition = array('name' => $_definition);
|
2010-03-22 16:09:26 +01:00
|
|
|
$bodefinitions = new importexport_definitions_bo();
|
2010-02-26 00:13:18 +01:00
|
|
|
$definition = $bodefinitions->read($definition);
|
2006-11-10 16:30:01 +01:00
|
|
|
$definition['edit'] = true;
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard($definition);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard($content = null, $msg='')
|
2008-10-07 15:15:53 +02:00
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .=
|
2010-06-13 09:46:51 +02:00
|
|
|
"<script type='text/javascript'>
|
2006-11-10 16:30:01 +01:00
|
|
|
function xajax_eT_wrapper_init() {
|
2010-03-02 00:26:38 +01:00
|
|
|
//window.resizeTo(document.documentElement.scrollWidth+20,document.documentElement.offsetHeight+40);
|
2006-11-10 16:30:01 +01:00
|
|
|
window.moveTo(screen.availWidth/2 - window.outerWidth/2,
|
|
|
|
screen.availHeight/2 - window.outerHeight/2);
|
|
|
|
}
|
|
|
|
</script>";
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->etpl->read('importexport.wizardbox');
|
|
|
|
$this->wizard_content_template =& $this->etpl->children[0]['data'][1]['A'][2][1]['name'];
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
if(is_array($content) &&! $content['edit'])
|
2008-10-07 15:15:53 +02:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.wizard->$content '. print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
// fetch plugin object
|
|
|
|
if($content['plugin'] && $content['application'])
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$wizard_name = $content['application'] . '_wizard_' . str_replace($content['application'] . '_', '', $content['plugin']);
|
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
|
|
|
}
|
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');
|
|
|
|
}
|
2010-06-13 09:46:51 +02:00
|
|
|
// Override next button on step 21, to do a regular submit for the file upload
|
|
|
|
if($content['step'] == 'wizard_step21') {
|
2010-06-11 17:44:36 +02:00
|
|
|
$this->etpl->set_cell_attribute('button[next]', 'onclick', '');
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
// post process submitted step
|
2010-03-22 16:09:26 +01:00
|
|
|
if($content['step']) {
|
|
|
|
if(!key_exists($content['step'],$this->steps))
|
|
|
|
$next_step = $this->plugin->$content['step']($content);
|
|
|
|
else
|
|
|
|
$next_step = $this->$content['step']($content);
|
|
|
|
} else {
|
|
|
|
die('Cannot find next step');
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
|
|
|
|
// pre precess next step
|
|
|
|
$sel_options = $readonlys = $preserv = array();
|
2010-03-01 18:30:53 +01:00
|
|
|
|
|
|
|
// Disable finish button if required fields are missing
|
|
|
|
if(!$content['name'] || !$content['type'] || !$content['plugin']) {
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][finish]');");
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
if(!key_exists($next_step,$this->steps))
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard_content_template = $this->plugin->$next_step($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard_content_template = $this->$next_step($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$html = $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,1);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// initial content
|
|
|
|
$GLOBALS['egw']->js->set_onload("xajax_eT_wrapper_init();");
|
|
|
|
$GLOBALS['egw']->js->set_onload("disable_button('exec[button][previous]');");
|
|
|
|
|
|
|
|
$sel_options = $readonlys = $preserv = array();
|
|
|
|
if($content['edit'])
|
|
|
|
unset ($content['edit']);
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-22 16:09:26 +01:00
|
|
|
$this->wizard_content_template = $this->wizard_step10($content, $sel_options, $readonlys, $preserv);
|
|
|
|
$html = $this->etpl->exec(self::_appname.'.importexport_definitions_ui.wizard',$content,$sel_options,$readonlys,$preserv,1);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(class_exists('xajaxResponse'))
|
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$this->response = new xajaxResponse();
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
if ($content['closewindow'])
|
|
|
|
{
|
|
|
|
$this->response->addScript("window.close();");
|
|
|
|
$this->response->addScript("opener.location.reload();");
|
2008-10-07 15:15:53 +02:00
|
|
|
// If Browser can't close window we display a "close" buuton and
|
2006-11-10 16:30:01 +01:00
|
|
|
// need to disable normal buttons
|
|
|
|
$this->response->addAssign('exec[button][previous]','style.display', 'none');
|
|
|
|
$this->response->addAssign('exec[button][next]','style.display', 'none');
|
|
|
|
$this->response->addAssign('exec[button][finish]','style.display', 'none');
|
|
|
|
$this->response->addAssign('exec[button][cancel]','style.display', 'none');
|
|
|
|
}
|
|
|
|
$this->response->addAssign('contentbox', 'innerHTML', $html);
|
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
|
|
|
|
if($this->plugin instanceof importexport_iface_import_plugin || $this->plugin instanceof importexport_wizard_basic_import_csv) {
|
|
|
|
$content['type'] = 'import';
|
2010-10-08 01:05:25 +02:00
|
|
|
} elseif($this->plugin instanceof importexport_iface_export_plugin || $this->plugin instanceof importexport_wizard_basic_export_csv) {
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['type'] = 'export';
|
|
|
|
} else {
|
|
|
|
throw new egw_exception('Invalid plugin');
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
return $this->get_step($content['step'],1);
|
|
|
|
case 'previous' :
|
|
|
|
unset ($content['plugin']);
|
2010-03-01 18:30:53 +01:00
|
|
|
if(is_object($this->response)) {
|
|
|
|
$this->response->addScript("disable_button('exec[button][previous]');");
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
return $this->get_step($content['step'],-1);
|
|
|
|
case 'finish':
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'wizard_finish';
|
2006-11-10 16:30:01 +01:00
|
|
|
default :
|
2010-03-22 16:09:26 +01:00
|
|
|
return $this->wizard_step20($content,$sel_options,$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// init step20
|
|
|
|
else
|
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['msg'] = $this->steps['wizard_step20'];
|
2011-02-22 18:43:33 +01:00
|
|
|
$config = config::read('phpgwapi');
|
2010-02-26 00:13:18 +01:00
|
|
|
foreach ($this->plugins[$content['application']] as $type => $plugins) {
|
2011-02-22 18:43:33 +01:00
|
|
|
if($config['export_limit'] == 'no' && !$GLOBALS['egw_info']['user']['apps']['admin'] && $type == 'export') continue;
|
2010-02-26 00:13:18 +01:00
|
|
|
foreach($plugins as $plugin => $name) {
|
|
|
|
$sel_options['plugin'][$plugin] = $name;
|
|
|
|
}
|
|
|
|
}
|
2010-03-22 16:09:26 +01:00
|
|
|
$content['step'] = 'wizard_step20';
|
2006-11-10 16:30:01 +01:00
|
|
|
$preserv = $content;
|
|
|
|
unset ($preserv['button']);
|
2010-03-22 16:09:26 +01:00
|
|
|
return 'importexport.wizard_chooseplugin';
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
|
2010-03-01 18:30:53 +01:00
|
|
|
// name
|
2010-03-22 16:09:26 +01:00
|
|
|
function wizard_step21(&$content, &$sel_options, &$readonlys, &$preserv)
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2010-03-22 16:09:26 +01:00
|
|
|
if(self::_debug) error_log('importexport.importexport_definitions_ui::wizard_step21->$content '.print_r($content,true));
|
2006-11-10 16:30:01 +01:00
|
|
|
|
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.');
|
|
|
|
|
|
|
|
// 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-04-11 17:45:29 +02:00
|
|
|
$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']) :
|
2011-02-24 00:44:20 +01:00
|
|
|
null;
|
|
|
|
$content['allowed_users'] = $content['just_me'] ? '' : implode(',',$content['allowed_users']);
|
|
|
|
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;
|
|
|
|
$content['just_me'] = 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'])
|
|
|
|
{
|
|
|
|
$bodefinitions->import($content['import_file']['tmp_name']);
|
|
|
|
// TODO make redirect here!
|
|
|
|
}
|
|
|
|
if($content['update'])
|
|
|
|
{
|
|
|
|
$applist = importexport_helper_functions::get_apps('all', true);
|
|
|
|
foreach($applist as $appname) {
|
|
|
|
importexport_helper_functions::load_defaults($appname);
|
|
|
|
}
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
return $this->index();
|
|
|
|
}
|
2008-10-07 15:15:53 +02:00
|
|
|
else
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2009-06-08 18:21:14 +02:00
|
|
|
$etpl = new etemplate(self::_appname.'.import_definition');
|
2010-03-22 16:09:26 +01:00
|
|
|
return $etpl->exec(self::_appname.'.importexport_definitions_ui.import_definition',$content,array(),$readonlys,$preserv);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-22 18:13:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Site configuration
|
|
|
|
*/
|
|
|
|
public function site_config($content = array())
|
|
|
|
{
|
|
|
|
if(!$GLOBALS['egw_info']['user']['apps']['admin'])
|
|
|
|
{
|
|
|
|
egw::redirect_link('/home');
|
|
|
|
}
|
|
|
|
if($content['save'])
|
|
|
|
{
|
|
|
|
unset($content['save']);
|
|
|
|
|
|
|
|
// ACL
|
|
|
|
$GLOBALS['egw']->acl->delete_repository(self::_appname, 'definition',false);
|
2011-02-24 00:44:20 +01:00
|
|
|
$GLOBALS['egw']->acl->delete_repository(self::_appname, 'share_definition',false);
|
|
|
|
if($content['share_definition'])
|
2011-02-22 18:13:03 +01:00
|
|
|
{
|
2011-04-11 17:45:29 +02:00
|
|
|
$GLOBALS['egw']->acl->add_repository(self::_appname, 'share_definition', $content['share_definition'],
|
2011-02-24 00:44:20 +01:00
|
|
|
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-02-22 18:13:03 +01:00
|
|
|
|
2011-04-19 18:00:43 +02:00
|
|
|
// Folder stuff should really be part of etemplate (merge base is in there)
|
|
|
|
// but the sidebox link works best if they're together
|
|
|
|
if(!array_key_exists('export_spreadsheet_folder', $data)) $data['export_spreadsheet_folder'] = 'user,stylite';
|
|
|
|
$sel_options = array(
|
|
|
|
'export_spreadsheet_folder' => array(
|
|
|
|
'user' => lang('User template folder'),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
if($GLOBALS['egw_info']['apps']['stylite']) {
|
|
|
|
$sel_options['export_spreadsheet_folder'] += array(
|
|
|
|
'stylite' => lang('Stylite template folder'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|