diff --git a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php index 807599ebe8..427a657e6e 100644 --- a/addressbook/inc/class.addressbook_export_contacts_csv.inc.php +++ b/addressbook/inc/class.addressbook_export_contacts_csv.inc.php @@ -40,7 +40,11 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi // Addressbook defines its own export imits $limit_exception = bo_merge::is_export_limit_excepted(); - if($GLOBALS['egw_info']['server']['contact_export_limit'] == 'no' && !$limit_exception) { +error_log(__METHOD__.__LINE__.'#'.$GLOBALS['egw_info']['server']['contact_export_limit'].'#'); +error_log(__METHOD__.__LINE__.'#'.bo_merge::getExportLimit().'#'); + $export_limit = $export_object->export_limit = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']); +error_log(__METHOD__.__LINE__.'#'.$export_limit.'#'); + if($export_limit == 'no' && !$limit_exception) { return; } @@ -65,8 +69,8 @@ class addressbook_export_contacts_csv implements importexport_iface_export_plugi } $GLOBALS['egw_info']['flags']['currentapp'] = $old_app; - if($GLOBALS['egw_info']['server']['contact_export_limit'] && !$limit_exception) { - $selection = array_slice($selection, 0, $GLOBALS['egw_info']['server']['contact_export_limit']); + if(bo_merge::hasExportLimit($export_limit,'ISALLOWED') && !$limit_exception) { + $selection = array_slice($selection, 0, $export_limit); } if($options['explode_multiselects']) { $customfields = config::get_customfields('addressbook'); diff --git a/addressbook/inc/class.addressbook_merge.inc.php b/addressbook/inc/class.addressbook_merge.inc.php index 9c5de48f7a..b175edee2a 100644 --- a/addressbook/inc/class.addressbook_merge.inc.php +++ b/addressbook/inc/class.addressbook_merge.inc.php @@ -32,10 +32,7 @@ class addressbook_merge extends bo_merge parent::__construct(); // overwrite global export-limit, if an addressbook one is set - if ($GLOBALS['egw_info']['server']['contact_export_limit']) - { - $this->export_limit = $GLOBALS['egw_info']['server']['contact_export_limit']; - } + $this->export_limit = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['contact_export_limit']); } /** diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index edf45ec72e..183033acf9 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -1491,7 +1491,7 @@ class calendar_bo { //_debug_array($event); $names = array(); - foreach($event['participants'] as $id => $status) + foreach((array)$event['participants'] as $id => $status) { calendar_so::split_status($status,$quantity,$role); diff --git a/calendar/inc/class.calendar_export_csv.inc.php b/calendar/inc/class.calendar_export_csv.inc.php index 7829b55580..04619bed9d 100644 --- a/calendar/inc/class.calendar_export_csv.inc.php +++ b/calendar/inc/class.calendar_export_csv.inc.php @@ -24,10 +24,9 @@ class calendar_export_csv implements importexport_iface_export_plugin { public function export( $_stream, importexport_definition $_definition) { $options = $_definition->plugin_options; $this->bo = new calendar_bo(); - $config = config::read('phpgwapi'); $limit_exception = bo_merge::is_export_limit_excepted(); - + if (!$limit_exception) $export_limit = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']); // Custom fields need to be specifically requested $cfs = array(); foreach($options['mapping'] as $key => $label) { @@ -39,14 +38,14 @@ class calendar_export_csv implements importexport_iface_export_plugin { 'start' => $options['selection']['start'], 'end' => $options['selection']['end'], 'categories' => $options['categories'] ? $options['categories'] : $options['selection']['categories'], - 'enum_recuring' => false, + //'enum_recuring' => false, // we want the recurring events enumerated for csv export 'daywise' => false, 'users' => $options['selection']['owner'], 'cfs' => $cfs // Otherwise we shouldn't get any custom fields ); - if($config['export_limit'] && !$limit_exception) { + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { $query['offset'] = 0; - $query['num_rows'] = (int)$config['export_limit']; + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } $events =& $this->bo->search($query); } elseif ($options['selection']['select'] == 'search_results') { @@ -57,8 +56,8 @@ class calendar_export_csv implements importexport_iface_export_plugin { $query['start'] = 0; $query['cfs'] = $cfs; - if($config['export_limit'] && !$limit_exception) { - $query['num_rows'] = (int)$config['export_limit']; + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } $ui = new calendar_uilist(); $ui->get_rows($query, $events, $unused); @@ -66,8 +65,8 @@ class calendar_export_csv implements importexport_iface_export_plugin { $query = $GLOBALS['egw']->session->appsession('session_data','calendar'); $query['users'] = explode(',', $query['owner']); $query['num_rows'] = -1; - if($config['export_limit'] && !$limit_exception) { - $query['num_rows'] = (int)$config['export_limit']; + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } $events = array(); @@ -89,8 +88,8 @@ class calendar_export_csv implements importexport_iface_export_plugin { ); } - $bo = new calendar_boupdate(); - $events = $bo->search($query + array( + $boupdate = new calendar_boupdate(); + $events = $boupdate->search($query + array( 'offset' => 0, 'order' => 'cal_start', )); @@ -98,6 +97,7 @@ class calendar_export_csv implements importexport_iface_export_plugin { } $export_object = new importexport_export_csv($_stream, (array)$options); + if (!$limit_exception) $export_object->export_limit = $export_limit; $export_object->set_mapping($options['mapping']); $convert_fields = calendar_egw_record::$types; @@ -111,33 +111,34 @@ class calendar_export_csv implements importexport_iface_export_plugin { 3 => lang('High') ), ); - $record = new calendar_egw_record(); foreach ($events as $event) { - // Get rid of yearly recurring events that don't belong - if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue; - + // the condition below (2 lines) may only work on enum_recuring=false and using the iterator to test an recurring event on the given timerange + // Get rid of yearly recurring events that don't belong + //if($options['selection']['select'] == 'criteria' && ($event['start'] > $query['end'] || $event['end'] < $query['start'])) continue; // Add in participants if($options['mapping']['participants']) { $event['participants'] = implode(", ",$this->bo->participants($event,true)); } - - $record->set_record($event); - if($options['mapping']['recurrence']) { - $record->recurrence = $recurrence[$record->recur_type]; - if($record->recur_type != MCAL_RECUR_NONE) $record->recurrence .= ' / '. $record->recur_interval; - } - - // Standard stuff - if($options['convert']) { - importexport_export_csv::convert($record, $convert_fields, 'calendar', $lookups); - } else { - // Implode arrays, so they don't say 'Array' - foreach($record->get_record_array() as $key => $value) { - if(is_array($value)) $record->$key = implode(',', $value); + if (is_array($event)) + { + $record->set_record($event); + if($options['mapping']['recurrence']) { + $record->recurrence = $recurrence[$record->recur_type]; + if($record->recur_type != MCAL_RECUR_NONE) $record->recurrence .= ' / '. $record->recur_interval; } - } - $export_object->export_record($record); + + // Standard stuff + if($options['convert']) { + importexport_export_csv::convert($record, $convert_fields, 'calendar', $lookups); + } else { + // Implode arrays, so they don't say 'Array' + foreach($record->get_record_array() as $key => $value) { + if(is_array($value)) $record->$key = implode(',', $value); + } + } + $export_object->export_record($record); + } } unset($record); } diff --git a/calendar/inc/class.calendar_export_ical.inc.php b/calendar/inc/class.calendar_export_ical.inc.php index 63a01b8f68..0d6bb96f36 100644 --- a/calendar/inc/class.calendar_export_ical.inc.php +++ b/calendar/inc/class.calendar_export_ical.inc.php @@ -33,6 +33,7 @@ class calendar_export_ical extends calendar_export_csv { } $limit_exception = bo_merge::is_export_limit_excepted(); + if (!$limit_exception) $export_limit = bo_merge::getExportLimit($GLOBALS['egw_info']['server']['calendar_export_limit']); if($options['selection']['select'] == 'criteria') { $query = array( @@ -44,9 +45,9 @@ class calendar_export_ical extends calendar_export_csv { 'users' => $options['selection']['owner'], 'cfs' => $cfs // Otherwise we shouldn't get any custom fields ); - if($config['export_limit'] && !$limit_exception) { + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { $query['offset'] = 0; - $query['num_rows'] = (int)$config['export_limit']; + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } $events =& $this->bo->search($query); } elseif ($options['selection']['select'] == 'search_results') { @@ -57,8 +58,8 @@ class calendar_export_ical extends calendar_export_csv { $query['start'] = 0; $query['cfs'] = $cfs; - if($config['export_limit'] && !$limit_exception) { - $query['num_rows'] = (int)$config['export_limit']; + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } $ui = new calendar_uilist(); $ui->get_rows($query, $events, $unused); @@ -66,8 +67,8 @@ class calendar_export_ical extends calendar_export_csv { $query = $GLOBALS['egw']->session->appsession('session_data','calendar'); $query['users'] = explode(',', $query['owner']); $query['num_rows'] = -1; - if($config['export_limit'] && !$limit_exception) { - $query['num_rows'] = (int)$config['export_limit']; + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } $events = array(); @@ -89,8 +90,8 @@ class calendar_export_ical extends calendar_export_csv { ); } - $bo = new calendar_boupdate(); - $events = $bo->search($query + array( + $boupdate = new calendar_boupdate(); + $events = $boupdate->search($query + array( 'offset' => 0, 'order' => 'cal_start', )); diff --git a/calendar/inc/class.calendar_merge.inc.php b/calendar/inc/class.calendar_merge.inc.php index 89289cc77a..c5f02fd163 100644 --- a/calendar/inc/class.calendar_merge.inc.php +++ b/calendar/inc/class.calendar_merge.inc.php @@ -68,6 +68,9 @@ class calendar_merge extends bo_merge { parent::__construct(); + // 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->bo = new calendar_boupdate(); self::$range_tags['start'] = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; diff --git a/calendar/templates/default/config.tpl b/calendar/templates/default/config.tpl index 93386ffe95..c90ae3c133 100644 --- a/calendar/templates/default/config.tpl +++ b/calendar/templates/default/config.tpl @@ -12,10 +12,10 @@ - {lang_Calendar} {lang_site_configuration} +  {lang_Calendar} {lang_site_configuration} - {lang_Do_you_wish_to_autoload_calendar_holidays_files_dynamically?} +  {lang_Do_you_wish_to_autoload_calendar_holidays_files_dynamically?} @@ -34,11 +34,11 @@ - {lang_setting_lock_time_calender}: +  {lang_setting_lock_time_calender}: - {lang_Deny_Ressources_reservation_for_private_events}: +  {lang_Deny_Ressources_reservation_for_private_events}: @@ -57,11 +57,11 @@ - {lang_While_selecting_up_to_X_users_day-_and_weekview_is_not_consolidated_(5_is_used_when_not_set)}: +  {lang_While_selecting_up_to_X_users_day-_and_weekview_is_not_consolidated_(5_is_used_when_not_set)}: - {lang_Allow_users_to_prevent_change_notifications_('Do_not_notify')}: +  {lang_Allow_users_to_prevent_change_notifications_('Do_not_notify')}: + +  {lang_Security}: {lang_How_many_appointments_should_non-admins_be_able_to_export} + {lang_(empty_=_use_global_limit,_no_=_no_export_at_all)}: + +  {lang_History_logging} @@ -98,10 +103,10 @@ - {lang_Birthdays} +  {lang_Birthdays} - {lang_Show_birthdays_from_addressbook}: +  {lang_Show_birthdays_from_addressbook}: diff --git a/etemplate/inc/class.bo_merge.inc.php b/etemplate/inc/class.bo_merge.inc.php index 62758e6028..d0a35a65cf 100644 --- a/etemplate/inc/class.bo_merge.inc.php +++ b/etemplate/inc/class.bo_merge.inc.php @@ -88,7 +88,7 @@ abstract class bo_merge $this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '. ($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']==12 ? 'h:i a' : 'H:i'); - $this->export_limit = $GLOBALS['egw_info']['server']['export_limit']; + $this->export_limit = self::getExportLimit(); } /** @@ -337,6 +337,57 @@ abstract class bo_merge return $is_excepted; } + /** + * getExportLimit + * checks if there is an exportlimit set, and returns + * @param mixed $app_limit checks and validates app_limit, if not set returns the global limit + * + * @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 + */ + public static function getExportLimit($app_limit='') + { + //error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace()); + $exportLimit = $GLOBALS['egw_info']['server']['export_limit']; + if (!empty($app_limit)) + { + $exportLimit = $app_limit; + } + //error_log(__METHOD__.__LINE__.' -> '.$exportLimit); + if (empty($exportLimit)) + { + return false; + } + + if (is_numeric($exportLimit)) + { + $exportLimit = (int)$exportLimit; + } + else + { + $exportLimit = $limit = 'no'; + } + //error_log(__METHOD__.__LINE__.' -> '.$exportLimit); + return $exportLimit; + } + + /** + * hasExportLimit + * checks wether there is an exportlimit set, and returns true or false + * @param mixed $app_limit app_limit, if not set checks the global limit + * @param string $checkas [AND|ISALLOWED], AND default; if set to ISALLOWED it is checked if Export is allowed + * + * @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') + { + $app_limit = self::getExportLimit($app_limit); + if (strtoupper($checkas) == 'ISALLOWED') return (empty($app_limit) || ($app_limit !='no' && $app_limit > 0) ); + if (empty($app_limit)) return false; + if ($app_limit == 'no') return true; + if ($app_limit > 0) return true; + } + /** * Merges a given document with contact data * @@ -355,7 +406,7 @@ abstract class bo_merge return false; } - if ($this->export_limit && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit) + if (self::hasExportLimit() && !self::is_export_limit_excepted() && count($ids) > (int)$this->export_limit) { $err = lang('No rights to export more then %1 entries!',(int)$this->export_limit); return false; @@ -1168,7 +1219,7 @@ abstract class bo_merge public static function document_action($dirs, $group=0, $caption='Insert in document', $prefix='document_', $default_doc='', $export_limit=null) { - if (is_null($export_limit)) $export_limit = $GLOBALS['egw_info']['server']['export_limit']; + $export_limit = self::getExportLimit($export_limit); $documents = array(); @@ -1252,7 +1303,7 @@ abstract class bo_merge 'caption' => $caption, 'children' => $documents, // disable action if no document or export completly forbidden for non-admins - 'enabled' => (boolean)$documents && (empty($export_limit) || (int)$export_limit > 0 || self::is_export_limit_excepted()), + 'enabled' => (boolean)$documents && (self::hasExportLimit($export_limit,'ISALLOWED') || self::is_export_limit_excepted()), 'hideOnDisabled' => true, // do not show 'Insert in document', if no documents defined or no export allowed 'group' => $group, ); diff --git a/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php b/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php index 0caa859780..cd53c1250e 100644 --- a/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php +++ b/importexport/inc/class.importexport_admin_prefs_sidebox_hooks.inc.php @@ -37,8 +37,8 @@ class importexport_admin_prefs_sidebox_hooks 'icon' => 'import' ), ); - $config = config::read('phpgwapi'); - if(bo_merge::is_export_limit_excepted() || $config['export_limit'] !== 'no') + $export_limit = bo_merge::getExportLimit(); + if(bo_merge::is_export_limit_excepted() || $export_limit !== 'no') { $file[] = array( 'text' => 'Export', @@ -121,8 +121,8 @@ class importexport_admin_prefs_sidebox_hooks $file['Import CSV']['link'] = ''; } } - $config = config::read('phpgwapi'); - if ((bo_merge::is_export_limit_excepted() || !$config['export_limit'] || $config['export_limit'] > 0) && $cache[$appname]['export']) + $export_limit = bo_merge::getExportLimit(); + if ((bo_merge::is_export_limit_excepted() || bo_merge::hasExportLimit($export_limit,'ISALLOWED')) && $cache[$appname]['export']) { $file['Export CSV'] = array('link' => "javascript:egw_openWindowCentered2('". egw::link('/index.php',array( diff --git a/importexport/inc/class.importexport_export_csv.inc.php b/importexport/inc/class.importexport_export_csv.inc.php index 0a58a5e121..7a7cde2374 100644 --- a/importexport/inc/class.importexport_export_csv.inc.php +++ b/importexport/inc/class.importexport_export_csv.inc.php @@ -52,7 +52,7 @@ class importexport_export_csv implements importexport_iface_export_record /** * @var int holds max. number of records allowed to be exported */ - protected $export_limit = 0; + public $export_limit = 0; /** * @var stream stream resource of csv file @@ -102,10 +102,10 @@ class importexport_export_csv implements importexport_iface_export_record } if(!bo_merge::is_export_limit_excepted()) { - $config = config::read('phpgwapi'); - if($config['export_limit'] == 'no') throw new egw_exception_no_permission_admin('Export disabled'); - $this->export_limit = (int)$config['export_limit']; + $this->export_limit = bo_merge::getExportLimit(); + if($this->export_limit == 'no') throw new egw_exception_no_permission_admin('Export disabled'); } +error_log(__METHOD__.__LINE__.'#'.$this->export_limit.'#'); } /** diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index 117f67dbb5..395a0086fd 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -50,8 +50,8 @@ class importexport_export_ui { // Check global setting if(!bo_merge::is_export_limit_excepted()) { - $config = config::read('phpgwapi'); - if($config['export_limit'] == 'no') { + $export_limit = bo_merge::getExportLimit(); + if($export_limit == 'no') { die(lang('Admin disabled exporting')); } }