rework of bo_merge::getExportLimit, apply to etemplate, importexport, addressbook, calendar

This commit is contained in:
Klaus Leithoff 2011-09-16 13:03:46 +00:00
parent 7f7e84afaa
commit 2d494997ab
14 changed files with 60 additions and 55 deletions

View File

@ -40,7 +40,7 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi
// Addressbook defines its own export imits // Addressbook defines its own export imits
$limit_exception = bo_merge::is_export_limit_excepted(); $limit_exception = bo_merge::is_export_limit_excepted();
$export_limit = $export_object->export_limit = addressbook_hooks::getAppExportLimit($location='addressbook'); $export_limit = $export_object->export_limit = bo_merge::getExportLimit($app='addressbook');
if($export_limit == 'no' && !$limit_exception) { if($export_limit == 'no' && !$limit_exception) {
return; return;
} }

View File

@ -382,7 +382,7 @@ class addressbook_hooks
*/ */
static function getAppExportLimit($location) static function getAppExportLimit($location)
{ {
return bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']); return $GLOBALS['egw_info']['server']['contact_export_limit'];
} }
/** /**

View File

@ -32,7 +32,7 @@ class addressbook_merge extends bo_merge
parent::__construct(); parent::__construct();
// overwrite global export-limit, if an addressbook one is set // overwrite global export-limit, if an addressbook one is set
$this->export_limit = addressbook_hooks::getAppExportLimit($location='addressbook'); $this->export_limit = bo_merge::getExportLimit('addressbook');
} }
/** /**

View File

@ -89,7 +89,7 @@ class addressbook_ui extends addressbook_bo
$this->config =& $GLOBALS['egw_info']['server']; $this->config =& $GLOBALS['egw_info']['server'];
// check if a contact specific export limit is set, if yes use it also for etemplate's csv export // check if a contact specific export limit is set, if yes use it also for etemplate's csv export
$this->config['export_limit'] = $this->config['contact_export_limit'] = addressbook_hooks::getAppExportLimit($location='addressbook'); $this->config['export_limit'] = $this->config['contact_export_limit'] = bo_merge::getExportLimit($app='addressbook');
if ($this->config['copy_fields'] && ($fields = is_array($this->config['copy_fields']) ? if ($this->config['copy_fields'] && ($fields = is_array($this->config['copy_fields']) ?
$this->config['copy_fields'] : unserialize($this->config['copy_fields']))) $this->config['copy_fields'] : unserialize($this->config['copy_fields'])))

View File

@ -26,7 +26,7 @@ class calendar_export_csv implements importexport_iface_export_plugin {
$this->bo = new calendar_bo(); $this->bo = new calendar_bo();
$limit_exception = bo_merge::is_export_limit_excepted(); $limit_exception = bo_merge::is_export_limit_excepted();
if (!$limit_exception) $export_limit = calendar_hooks::getAppExportLimit($location='calendar'); if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar');
// Custom fields need to be specifically requested // Custom fields need to be specifically requested
$cfs = array(); $cfs = array();
foreach($options['mapping'] as $key => $label) { foreach($options['mapping'] as $key => $label) {

View File

@ -33,7 +33,7 @@ class calendar_export_ical extends calendar_export_csv {
} }
$limit_exception = bo_merge::is_export_limit_excepted(); $limit_exception = bo_merge::is_export_limit_excepted();
if (!$limit_exception) $export_limit = calendar_hooks::getAppExportLimit($location='calendar'); if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar');
if($options['selection']['select'] == 'criteria') { if($options['selection']['select'] == 'criteria') {
$query = array( $query = array(

View File

@ -51,7 +51,7 @@ class calendar_hooks
*/ */
static function getAppExportLimit($location) static function getAppExportLimit($location)
{ {
return bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']); return $GLOBALS['egw_info']['server']['calendar_export_limit'];
} }
/** /**

View File

@ -69,7 +69,7 @@ class calendar_merge extends bo_merge
parent::__construct(); parent::__construct();
// overwrite global export-limit, if one is set for calendar/appointments // overwrite global export-limit, if one is set for calendar/appointments
$this->export_limit = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']); $this->export_limit = bo_merge::getExportLimit('calendar');
$this->bo = new calendar_boupdate(); $this->bo = new calendar_boupdate();

View File

@ -799,9 +799,9 @@ class calendar_uilist extends calendar_ui
'hint' => 'Download this event as iCal', 'hint' => 'Download this event as iCal',
'disableClass' => 'rowNoView', 'disableClass' => 'rowNoView',
); );
$actions['documents'] = addressbook_merge::document_action( $actions['documents'] = calendar_merge::document_action(
$this->bo->cal_prefs['document_dir'], ++$group, 'Insert in document', 'document_', $this->bo->cal_prefs['document_dir'], ++$group, 'Insert in document', 'document_',
$this->bo->cal_prefs['default_document'] $this->bo->cal_prefs['default_document'],bo_merge::getExportLimit('calendar')
); );
++$group; ++$group;
$actions['delete'] = array( $actions['delete'] = array(

View File

@ -345,30 +345,40 @@ abstract class bo_merge
* @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction * @return mixed - no if no export is allowed, false if there is no restriction and int as there is a valid restriction
* you may have to cast the returned value to int, if you want to use it as number * you may have to cast the returned value to int, if you want to use it as number
*/ */
public static function getExportLimit($app_limit='') public static function getExportLimit($app='common')
{ {
//error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace()); static $exportLimitStore;
$exportLimit = $GLOBALS['egw_info']['server']['export_limit']; if (is_null($exportLimitStore)) $exportLimitStore=array();
if (!empty($app_limit)) if (empty($app)) $app='common';
//error_log(__METHOD__.__LINE__.' called with app:'.$app);
if (!array_key_exists($app,$exportLimitStore))
{ {
$exportLimit = $app_limit; //error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace());
} $exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit'];
//error_log(__METHOD__.__LINE__.' -> '.$exportLimit); if ($app !='common')
if (empty($exportLimit)) {
{ $app_limit = $GLOBALS['egw']->hooks->single('export_limit',$app);
return false; if ($app_limit) $exportLimitStore[$app] = $app_limit;
} }
//error_log(__METHOD__.__LINE__.' building cache for app:'.$app.' -> '.$exportLimitStore[$app]);
if (empty($exportLimitStore[$app]))
{
$exportLimitStore[$app] = false;
return false;
}
if (is_numeric($exportLimit)) if (is_numeric($exportLimitStore[$app]))
{ {
$exportLimit = (int)$exportLimit; $exportLimitStore[$app] = (int)$exportLimitStore[$app];
}
else
{
$exportLimitStore[$app] = 'no';
}
//error_log(__METHOD__.__LINE__.' -> '.$exportLimit);
} }
else //error_log(__METHOD__.__LINE__.' app:'.$app.' -> '.$exportLimitStore[$app]);
{ return $exportLimitStore[$app];
$exportLimit = $limit = 'no';
}
//error_log(__METHOD__.__LINE__.' -> '.$exportLimit);
return $exportLimit;
} }
/** /**
@ -379,9 +389,8 @@ abstract class bo_merge
* *
* @return bool - true if no export is allowed or a limit is set, false if there is no restriction * @return bool - true if no export is allowed or a limit is set, false if there is no restriction
*/ */
public static function hasExportLimit($app_limit='',$checkas='AND') public static function hasExportLimit($app_limit,$checkas='AND')
{ {
$app_limit = self::getExportLimit($app_limit);
if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) ); if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) );
if (empty($app_limit)) return false; if (empty($app_limit)) return false;
if ($app_limit == 'no') return true; if ($app_limit == 'no') return true;
@ -406,7 +415,7 @@ abstract class bo_merge
return false; return false;
} }
if (self::hasExportLimit() && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit) if (self::hasExportLimit($this->export_limit) && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit)
{ {
$err = lang('No rights to export more than %1 entries!',(int)$this->export_limit); $err = lang('No rights to export more than %1 entries!',(int)$this->export_limit);
return false; return false;
@ -1172,8 +1181,7 @@ abstract class bo_merge
*/ */
public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='') public static function get_documents($dirs, $prefix='document_', $mime_filter=null, $app='')
{ {
$export_limit = null; $export_limit=self::getExportLimit($app);
if (!empty($app)) $export_limit=$GLOBALS['egw']->hooks->single('export_limit',$app);
if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array(); if (!$dirs || (!self::hasExportLimit($export_limit,'ISALLOWED') && !self::is_export_limit_excepted())) return array();
// split multiple comma or whitespace separated directories // split multiple comma or whitespace separated directories
@ -1231,10 +1239,8 @@ abstract class bo_merge
public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='', public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='',
$export_limit=null) $export_limit=null)
{ {
$export_limit = self::getExportLimit($export_limit);
$documents = array(); $documents = array();
if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
if ($default_doc && ($file = egw_vfs::stat($default_doc))) // put default document on top if ($default_doc && ($file = egw_vfs::stat($default_doc))) // put default document on top
{ {
$documents['document'] = array( $documents['document'] = array(

View File

@ -276,8 +276,7 @@ class nextmatch_widget
unset($value['rows']); unset($value['rows']);
$extension_data += $value; $extension_data += $value;
list($app) = explode('.',$tmpl->name); list($app) = explode('.',$tmpl->name);
$export_limit = $GLOBALS['egw_info']['server']['export_limit']; $export_limit = bo_merge::getExportLimit($app);
if (empty($app)) $export_limit = $GLOBALS['egw']->hooks->single('export_limit',$app);
$value['no_csv_export'] = $value['csv_fields'] === false || $value['no_csv_export'] = $value['csv_fields'] === false ||
!bo_merge::hasExportLimit($export_limit,'ISALLOWED') && !bo_merge::hasExportLimit($export_limit,'ISALLOWED') &&
!bo_merge::is_export_limit_excepted(); !bo_merge::is_export_limit_excepted();
@ -1454,8 +1453,7 @@ class nextmatch_widget
{ {
$name = is_object($value['template']) ? $value['template']->name : $value['template']; $name = is_object($value['template']) ? $value['template']->name : $value['template'];
list($app) = explode('.',$name); list($app) = explode('.',$name);
$export_limit = $GLOBALS['egw_info']['server']['export_limit']; $export_limit = bo_merge::getExportLimit($app);
if (!empty($app)) $export_limit = $GLOBALS['egw']->hooks->single('export_limit',$app);
//if (isset($value['export_limit'])) $export_limit = $value['export_limit']; //if (isset($value['export_limit'])) $export_limit = $value['export_limit'];
} }
$charset = $charset_out = translation::charset(); $charset = $charset_out = translation::charset();

View File

@ -37,7 +37,8 @@ class importexport_admin_prefs_sidebox_hooks
'icon' => 'import' 'icon' => 'import'
), ),
); );
$export_limit = bo_merge::getExportLimit(); $export_limit = bo_merge::getExportLimit($appname);
//error_log(__METHOD__.__LINE__.' app:'.$appname.' limit:'.$export_limit);
if(bo_merge::is_export_limit_excepted() || $export_limit !== 'no') if(bo_merge::is_export_limit_excepted() || $export_limit !== 'no')
{ {
$file[] = array( $file[] = array(
@ -121,8 +122,8 @@ class importexport_admin_prefs_sidebox_hooks
$file['Import CSV']['link'] = ''; $file['Import CSV']['link'] = '';
} }
} }
$export_limit = $GLOBALS['egw']->hooks->single('export_limit',$appname); $export_limit = bo_merge::getExportLimit($appname);
//error_log(__METHOD__.__LINE__.$appname.$export_limit); //error_log(__METHOD__.__LINE__.' app:'.$appname.' limit:'.$export_limit);
if ((bo_merge::is_export_limit_excepted() || bo_merge::hasExportLimit($export_limit,'ISALLOWED')) && $cache[$appname]['export']) if ((bo_merge::is_export_limit_excepted() || bo_merge::hasExportLimit($export_limit,'ISALLOWED')) && $cache[$appname]['export'])
{ {
$file['Export CSV'] = array('link' => "javascript:egw_openWindowCentered2('". $file['Export CSV'] = array('link' => "javascript:egw_openWindowCentered2('".

View File

@ -100,9 +100,10 @@ class importexport_export_csv implements importexport_iface_export_record
if ( !empty( $_options ) ) { if ( !empty( $_options ) ) {
$this->csv_options = array_merge( $this->csv_options, $_options ); $this->csv_options = array_merge( $this->csv_options, $_options );
} }
//error_log(__METHOD__.__LINE__.array2string($_options['appname']));
if(!bo_merge::is_export_limit_excepted()) { if(!bo_merge::is_export_limit_excepted()) {
$this->export_limit = bo_merge::getExportLimit(); $this->export_limit = bo_merge::getExportLimit($_options['appname']);
//error_log(__METHOD__.__LINE__.' app:'.$_options['appname'].' limit:'.$this->export_limit);
if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled'); if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled');
} }
} }

View File

@ -48,20 +48,19 @@ class importexport_export_ui {
$readonlys = array(); $readonlys = array();
$preserv = array(); $preserv = array();
// Check global setting
if(!bo_merge::is_export_limit_excepted()) {
$export_limit = bo_merge::getExportLimit();
if($export_limit == 'no') {
die(lang('Admin disabled exporting'));
}
}
$et = new etemplate(self::_appname. '.export_dialog'); $et = new etemplate(self::_appname. '.export_dialog');
$_appname = $_content['appname'] ? $_content['appname'] : $_GET['appname']; $_appname = $_content['appname'] ? $_content['appname'] : $_GET['appname'];
$_definition = $_content['definition'] ? $_content['definition'] : $_GET['definition']; $_definition = $_content['definition'] ? $_content['definition'] : $_GET['definition'];
$_plugin = $_content['plugin'] ? $_content['plugin'] : $_GET['plugin']; $_plugin = $_content['plugin'] ? $_content['plugin'] : $_GET['plugin'];
$_selection = $_content['selection'] ? $_content['selection'] : $_GET['selection']; $_selection = $_content['selection'] ? $_content['selection'] : $_GET['selection'];
// Check global setting
if(!bo_merge::is_export_limit_excepted()) {
$export_limit = bo_merge::getExportLimit($_appname);
if($export_limit == 'no') {
die(lang('Admin disabled exporting'));
}
}
//error_log(__FILE__.__FUNCTION__. '::$_GET[\'appname\']='. $_appname. ',$_GET[\'definition\']='. $_definition. ',$_GET[\'plugin\']='.$_plugin. ',$_GET[\'selection\']='.$_selection); //error_log(__FILE__.__FUNCTION__. '::$_GET[\'appname\']='. $_appname. ',$_GET[\'definition\']='. $_definition. ',$_GET[\'plugin\']='.$_plugin. ',$_GET[\'selection\']='.$_selection);
// if appname is given and valid, list available definitions (if no definition is given) // if appname is given and valid, list available definitions (if no definition is given)
$readonlys['appname'] = (!empty($_appname) && $GLOBALS['egw']->acl->check('run',1,$_appname)); $readonlys['appname'] = (!empty($_appname) && $GLOBALS['egw']->acl->check('run',1,$_appname));