diff --git a/importexport/inc/class.importexport_definitions_bo.inc.php b/importexport/inc/class.importexport_definitions_bo.inc.php index 4a7a08ce8c..b929af01e6 100644 --- a/importexport/inc/class.importexport_definitions_bo.inc.php +++ b/importexport/inc/class.importexport_definitions_bo.inc.php @@ -83,18 +83,12 @@ class importexport_definitions_bo { * @return bool */ static public function is_permitted($_definition) { - $allowed_user = explode(',',$_definition['allowed_users']); - $this_user_id = $GLOBALS['egw_info']['user']['userid']; - $this_membership = $GLOBALS['egw']->accounts->membership($this_user_id); - $this_membership[] = array('account_id' => $this_user_id); - //echo $this_user_id; - //echo ' '.$this_membership; - foreach ((array)$this_membership as $account) - { - $this_membership_array[] = $account['account_id']; - } - $alluser = array_intersect($allowed_user,$this_membership_array); - return in_array($this_user_id,$alluser) ? true : false; + $allowed_user = is_array($_definition['allowed_users']) ? $_definition['allowed_users'] : explode(',',$_definition['allowed_users']); + $this_user_id = $GLOBALS['egw_info']['user']['account_id']; + $this_membership = $GLOBALS['egw']->accounts->memberships($this_user_id, true); + $this_membership[] = $this_user_id; + $alluser = array_intersect($allowed_user,$this_membership); + return count($alluser) > 0 ? true : false; } /** diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index ceadfd7fae..e40b270699 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -80,7 +80,7 @@ class importexport_export_ui { $content['definition'] = end($sel_options['definition']); } unset($definitions); - $sel_options['definition']['expert'] = lang('Expert options'); + //$sel_options['definition']['expert'] = lang('Expert options'); if(isset($_definition) && array_key_exists($_definition,$sel_options['definition'])) { $content['definition'] = $_definition; diff --git a/importexport/inc/class.importexport_helper_functions.inc.php b/importexport/inc/class.importexport_helper_functions.inc.php index e1a8d05229..0fdeab26a0 100755 --- a/importexport/inc/class.importexport_helper_functions.inc.php +++ b/importexport/inc/class.importexport_helper_functions.inc.php @@ -316,8 +316,8 @@ class importexport_helper_functions { $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; $types = $_type == 'all' ? array('import','export') : (array)$_type; - foreach($plugins as $appname => $types) { - if(!in_array($appname, $appnames)) unset($plugins['appname']); + foreach($plugins as $appname => $_types) { + if(!in_array($appname, $appnames)) unset($plugins[$appname]); } foreach($plugins as $appname => $types) { $plugins[$appname] = array_intersect_key($plugins[$appname], $types); @@ -378,4 +378,45 @@ class importexport_helper_functions { public static function guess_filetype( $_file ) { } + + /** + * returns if the given app has importexport definitions for the current user + * + * @param string $_appname { | all} + * @param string $_type {import | export | all} + * @return boolean + */ + public static function has_definitions( $_appname = 'all', $_type = 'all' ) { + $definitions = egw_cache::getSession( + __CLASS__, + 'has_definitions', + array('importexport_helper_functions','_has_definitions'), + array(array_keys($GLOBALS['egw_info']['apps']), array('import', 'export')), + self::CACHE_EXPIRATION + ); + $appnames = $_appname == 'all' ? array_keys($GLOBALS['egw_info']['apps']) : (array)$_appname; + $types = $_type == 'all' ? array('import','export') : (array)$_type; + + foreach($definitions as $appname => $_types) { + if(!in_array($appname, $appnames)) unset($definitions[$appname]); + } + foreach($definitions as $appname => $_types) { + $definitions[$appname] = array_intersect_key($definitions[$appname], array_flip($types)); + } + return count($definitions[$appname]) > 0; + } + + // egw_cache needs this public + public static function _has_definitions(Array $appnames, Array $types) { + $def = new importexport_definitions_bo(array('application'=>$appnames, 'type' => $types)); + $list = array(); + foreach($def->get_definitions() as $id) { + $definition = new importexport_definition($id); + if($def->is_permitted($definition->get_record_array())) { + $list[$definition->application][$definition->type] = $id; + } + $definition = null; + } + return $list; + } } // end of importexport_helper_functions