* calendar/importexport/addressbook: calendar introduce new config option to set app specific export_limit; calendar csv export: use enumerate for exporting events as csv; bo_merge: introduce new helper functions to get and check export-limit; addressbook: use new helper functions

This commit is contained in:
Klaus Leithoff 2011-09-13 09:05:33 +00:00
parent 55ba753e3c
commit d52c72207c
11 changed files with 134 additions and 72 deletions

View File

@ -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');

View File

@ -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']);
}
/**

View File

@ -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);

View File

@ -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);
}

View File

@ -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',
));

View File

@ -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'];

View File

@ -12,10 +12,10 @@
</tr>
<tr class="row_off">
<td colspan="2"><b>{lang_Calendar} {lang_site_configuration}</b></td>
<td colspan="2">&nbsp;<b>{lang_Calendar} {lang_site_configuration}</b></td>
</tr>
<tr class="row_on">
<td>{lang_Do_you_wish_to_autoload_calendar_holidays_files_dynamically?}</td>
<td>&nbsp;{lang_Do_you_wish_to_autoload_calendar_holidays_files_dynamically?}</td>
<td>
<select name="newsettings[auto_load_holidays]">
<option value=""{selected_auto_load_holidays_False}>{lang_No}</option>
@ -24,7 +24,7 @@
</td>
</tr>
<tr class="row_off">
<td>{lang_Location_to_autoload_from}:</td>
<td>&nbsp;{lang_Location_to_autoload_from}:</td>
<td>
<select name="newsettings[holidays_url_path]">
<option value="localhost"{selected_holidays_url_path_localhost}>localhost</option>
@ -34,11 +34,11 @@
</tr>
<!-- lock setting -->
<tr class="row_on">
<td>{lang_setting_lock_time_calender}:</td>
<td>&nbsp;{lang_setting_lock_time_calender}:</td>
<td><input name="newsettings[Lock_Time_Calender]" value="{value_Lock_Time_Calender}" size="40"></td>
</tr>
<tr class="row_off">
<td>{lang_Deny_Ressources_reservation_for_private_events}:</td>
<td>&nbsp;{lang_Deny_Ressources_reservation_for_private_events}:</td>
<td>
<select name="newsettings[no_ressources_private]">
<option value="">{lang_No}</option>
@ -47,7 +47,7 @@
</td>
</tr>
<tr class="row_on">
<td>{lang_Require_an_ACL_grant_to_invite_other_users_and_groups}:</td>
<td>&nbsp;{lang_Require_an_ACL_grant_to_invite_other_users_and_groups}:</td>
<td>
<select name="newsettings[require_acl_invite]">
<option value="">{lang_No}: {lang_Every_user_can_invite_other_users_and_groups}</option>
@ -57,11 +57,11 @@
</td>
</tr>
<tr class="row_off">
<td>{lang_While_selecting_up_to_X_users_day-_and_weekview_is_not_consolidated_(5_is_used_when_not_set)}:</td>
<td>&nbsp;{lang_While_selecting_up_to_X_users_day-_and_weekview_is_not_consolidated_(5_is_used_when_not_set)}:</td>
<td><input name="newsettings[calview_no_consolidate]" value="{value_calview_no_consolidate}" size="10"></td>
</tr>
<tr class="row_on">
<td>{lang_Allow_users_to_prevent_change_notifications_('Do_not_notify')}:</td>
<td>&nbsp;{lang_Allow_users_to_prevent_change_notifications_('Do_not_notify')}:</td>
<td>
<select name="newsettings[calendar_allow_no_notification]">
<option value=""{selected_calendar_allow_no_notification_False}>{lang_No}</option>
@ -69,6 +69,11 @@
</select>
</td>
</tr>
<tr class="row_off">
<td>&nbsp;<b>{lang_Security}</b>: {lang_How_many_appointments_should_non-admins_be_able_to_export}
{lang_(empty_=_use_global_limit,_no_=_no_export_at_all)}:</td>
<td><input name="newsettings[calendar_export_limit]" value="{value_calendar_export_limit}" size="5"></td>
</tr>
<tr class="th">
<td colspan="2">&nbsp;<b>{lang_History_logging}</b></td>
</tr>
@ -98,10 +103,10 @@
</td>
</tr>
<tr class="th">
<td colspan="2"><b>{lang_Birthdays}</b></td>
<td colspan="2">&nbsp;<b>{lang_Birthdays}</b></td>
</tr>
<tr class="row_off">
<td>{lang_Show_birthdays_from_addressbook}:</td>
<td>&nbsp;{lang_Show_birthdays_from_addressbook}:</td>
<td>
<select name="newsettings[hide_birthdays]">
<option value="">{lang_Yes}</option>
@ -111,7 +116,7 @@
</td>
</tr>
<tr class="row_on">
<td>{lang_Calendar_recurrence_horizont_in_days_(default_1000)}:</td>
<td>&nbsp;{lang_Calendar_recurrence_horizont_in_days_(default_1000)}:</td>
<td><input size="5" name="newsettings[calendar_horizont]" value="{value_calendar_horizont}"></td>
</tr>

View File

@ -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,
);

View File

@ -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(

View File

@ -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.'#');
}
/**

View File

@ -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'));
}
}