diff --git a/calendar/inc/class.calendar_export_csv.inc.php b/calendar/inc/class.calendar_export_csv.inc.php index 64c988b529..9189adb903 100644 --- a/calendar/inc/class.calendar_export_csv.inc.php +++ b/calendar/inc/class.calendar_export_csv.inc.php @@ -16,6 +16,12 @@ */ class calendar_export_csv implements importexport_iface_export_plugin { + public function __construct() { + translation::add_app('calendar'); + $this->bo = new calendar_bo(); + $this->get_selects(); + } + /** * Exports records as defined in $_definition * @@ -23,78 +29,128 @@ 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(); $limit_exception = bo_merge::is_export_limit_excepted(); if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar'); // Custom fields need to be specifically requested $cfs = array(); - foreach($options['mapping'] as $key => $label) { + foreach($options['mapping'] + (array)$_definition->filter as $key => $label) { if($key[0] == '#') $cfs[] = substr($key,1); } - if($options['selection']['select'] == 'criteria') { - $query = array( - 'start' => $options['selection']['start'], - 'end' => strtotime('+1 day',$options['selection']['end'])-1, - 'categories' => $options['categories'] ? $options['categories'] : $options['selection']['categories'], - //'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(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { - $query['offset'] = 0; - $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 - } - $events =& $this->bo->search($query); - } elseif ($options['selection']['select'] == 'search_results') { - $states = $GLOBALS['egw']->session->appsession('session_data','calendar'); - if($states['view'] == 'listview') { - $query = $GLOBALS['egw']->session->appsession('calendar_list','calendar'); - $query['num_rows'] = -1; // all - $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session - $query['start'] = 0; - $query['cfs'] = $cfs; - + switch($options['selection']) + { + case 'criteria': + $query = array( + 'start' => $options['criteria']['start'], + 'end' => strtotime('+1 day',$options['criteria']['end'])-1, + 'categories' => $options['categories'] ? $options['categories'] : $options['criteria']['categories'], + //'enum_recuring' => false, // we want the recurring events enumerated for csv export + 'daywise' => false, + 'users' => $options['criteria']['owner'], + 'cfs' => $cfs // Otherwise we shouldn't get any custom fields + ); if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { + $query['offset'] = 0; $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 } - $ui = new calendar_uilist(); - $ui->get_rows($query, $events, $unused); - } else { - $query = $GLOBALS['egw']->session->appsession('session_data','calendar'); - $query['users'] = explode(',', $query['owner']); - $query['num_rows'] = -1; - if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { - $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 - } + $events =& $this->bo->search($query); + break; + case 'search_results': + $states = $GLOBALS['egw']->session->appsession('session_data','calendar'); + if($states['view'] == 'listview') { + $query = $GLOBALS['egw']->session->appsession('calendar_list','calendar'); + $query['num_rows'] = -1; // all + $query['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session + $query['start'] = 0; + $query['cfs'] = $cfs; - $events = array(); - switch($states['view']) { - case 'month': - $query += $this->get_query_month($states); - break; - case 'week': - $query += $this->get_query_week($states); - break; - case 'day': - $query += $this->get_query_day($states); - break; - default: - $ui = new calendar_uiviews($query); - $query += array( - 'start' => is_array($ui->first) ? $this->bo->date2ts($ui->first) : $ui->first, - 'end' => is_array($ui->last) ? $this->bo->date2ts($ui->last) : $ui->last - ); + 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); + } else { + $query = $GLOBALS['egw']->session->appsession('session_data','calendar'); + $query['users'] = explode(',', $query['owner']); + $query['num_rows'] = -1; + if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) { + $query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0 + } + + $events = array(); + switch($states['view']) { + case 'month': + $query += $this->get_query_month($states); + break; + case 'week': + $query += $this->get_query_week($states); + break; + case 'day': + $query += $this->get_query_day($states); + break; + default: + // Let UI set the date ranges + $ui = new calendar_uiviews($query); + if(method_exists($ui, $states['view'])) + { + ob_start(); + $ui->$states['view'](); + ob_end_flush(); + } + $query += array( + 'start' => is_array($ui->first) ? $this->bo->date2ts($ui->first) : $ui->first, + 'end' => is_array($ui->last) ? $this->bo->date2ts($ui->last) : $ui->last + ); + + } + $boupdate = new calendar_boupdate(); + $events = $boupdate->search($query + array( + 'offset' => 0, + 'order' => 'cal_start', + )); + } + break; + case 'filter': + $query = array( + 'cfs' => $cfs, // Otherwise we shouldn't get any custom fields + 'num_rows' => -1, + 'csv_export' => true + ); + $fields = importexport_helper_functions::get_filter_fields($_definition->application, $this); + $filter = $_definition->filter; + + // Handle ranges + foreach($filter as $field => $value) + { + if($field == 'filter' && $value) + { + $query['filter'] = $value; + continue; + } + if(!is_array($value) || (!$value['from'] && !$value['to'])) + { + $query['query']["cal_$field"] = $value; + continue; + } + + // Ranges are inclusive, so should be provided that way (from 2 to 10 includes 2 and 10) + if($value['from']) $query['sql_filter'][] = "cal_$field >= " . (int)$value['from']; + if($value['to']) $query['sql_filter'][] = "cal_$field <= " . (int)$value['to']; } - $boupdate = new calendar_boupdate(); - $events = $boupdate->search($query + array( + if($query['sql_filter'] && is_array($query['sql_filter'])) + { + // Set as an extra parameter + $sql_filter = implode(' AND ',$query['sql_filter']); + } + + case 'all': + $events = $this->bo->search($query + array( 'offset' => 0, 'order' => 'cal_start', - )); - } + ),$sql_filter); + break; } $export_object = new importexport_export_csv($_stream, (array)$options); @@ -104,14 +160,6 @@ class calendar_export_csv implements importexport_iface_export_plugin { $recurrence = $this->bo->recur_types; - $lookups = array( - 'priority' => Array( - 0 => '', - 1 => lang('Low'), - 2 => lang('Normal'), - 3 => lang('High') - ), - ); $record = new calendar_egw_record(); foreach ($events as $event) { // 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 @@ -131,7 +179,7 @@ class calendar_export_csv implements importexport_iface_export_plugin { // Standard stuff if($options['convert']) { - importexport_export_csv::convert($record, $convert_fields, 'calendar', $lookups); + importexport_export_csv::convert($record, $convert_fields, 'calendar', $this->selects); } else { // Implode arrays, so they don't say 'Array' foreach($record->get_record_array() as $key => $value) { @@ -204,7 +252,7 @@ class calendar_export_csv implements importexport_iface_export_plugin { // Use UI to get dates $ui = new calendar_uilist(); $list['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session - $ui->get_rows($list); + $ui->get_rows($list,$rows,$readonlys); if($ui->first) $start = $ui->first; if($ui->last) $end = $ui->last; @@ -228,7 +276,7 @@ class calendar_export_csv implements importexport_iface_export_plugin { 'name' => 'calendar.export_csv_select', 'content' => array( 'plugin_override' => true, // Plugin overrides preferences - 'select' => $prefs['selection']['select'] ? $prefs['selection']['select'] : 'criteria', + 'selection' => $prefs['selection'] ? $prefs['selection'] : 'criteria', 'start' => is_object($start) ? $start->format('ts') : $start, 'end' => $end, 'owner' => $states['owner'] @@ -293,4 +341,64 @@ class calendar_export_csv implements importexport_iface_export_plugin { $query['end'] = $query['start']+DAY_s-1; return $query; } + + /** + * Get select options for use in filter + */ + protected function get_selects() + { + $this->selects['priority'] = Array( + 0 => '', + 1 => lang('Low'), + 2 => lang('Normal'), + 3 => lang('High') + ); + $this->selects['filter'] = array( + 'default' => lang('Not rejected'), + 'accepted' => lang('Accepted'), + 'unknown' => lang('Invitations'), + 'tentative' => lang('Tentative'), + 'delegated' => lang('Delegated'), + 'rejected' => lang('Rejected'), + 'owner' => lang('Owner too'), + 'all' => lang('All incl. rejected'), + 'hideprivate' => lang('Hide private infos'), + 'showonlypublic' => lang('Hide private events'), + 'no-enum-groups' => lang('only group-events'), + 'not-unknown' => lang('No meeting requests'), + ); + } + + /** + * Adjust automatically generated field filters + */ + public function get_filter_fields(Array &$filters) + { + + // Calendar SO doesn't support filtering by column, so we have to remove pretty much everything + unset($filters['recur_date']); + + // Add in the status filter at the beginning + $filters = array_reverse($filters, true); + $filters['filter'] = array( + 'type' => 'select', + 'name' => 'filter', + 'label' => lang('Filter'), + ); + $filters = array_reverse($filters, true); + + foreach($filters as $field_name => &$settings) + { + // Can't filter on a custom field + if(strpos($field_name, '#') === 0) + { + unset($filters[$field_name]); + continue; + } + + // Pass on select options + if($this->selects[$field_name]) $settings['values'] = $this->selects[$field_name]; + } + + } } diff --git a/calendar/lang/egw_en.lang b/calendar/lang/egw_en.lang index 2306ac3d7e..3ea94746b9 100644 --- a/calendar/lang/egw_en.lang +++ b/calendar/lang/egw_en.lang @@ -100,6 +100,8 @@ create a new series calendar en Create a new series create an exception for the given date calendar en Create an exception for the given date create exception calendar en Create exception create new links calendar en Create new links +created calendar en Created +creator calendar en Creator csv calendar en CSV csv-fieldname calendar en CSV field name csv-filename calendar en CSV file name @@ -288,6 +290,7 @@ meeting status information calendar en Meeting status information merge document... calendar en Merge document... minutes calendar en Minutes modified calendar en Modified +modifier calendar en Modifier mon calendar en Mon month calendar en Month monthly calendar en Monthly diff --git a/calendar/setup/etemplates.inc.php b/calendar/setup/etemplates.inc.php index 750bb735aa..16eae2c118 100644 --- a/calendar/setup/etemplates.inc.php +++ b/calendar/setup/etemplates.inc.php @@ -2,7 +2,7 @@ /** * EGroupware - eTemplates for Application calendar * http://www.egroupware.org - * generated by soetemplate::dump4setup() 2013-01-14 10:19 + * generated by soetemplate::dump4setup() 2013-01-21 11:29 * * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package calendar @@ -45,7 +45,9 @@ $templ_data[] = array('name' => 'calendar.edit_series','template' => '','lang' = $templ_data[] = array('name' => 'calendar.export','template' => '','lang' => '','group' => '0','version' => '1.0.1.001','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:8:{i:0;a:2:{s:2:"h5";s:2:",1";s:2:"h1";s:6:",!@msg";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:8:",,,start";s:5:"label";s:5:"Start";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:5:"start";s:4:"help";s:23:"Startdate of the export";}}i:3;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:6:",,,end";s:5:"label";s:3:"End";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:3:"end";s:4:"help";s:21:"Enddate of the export";}}i:4;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:7:",,,file";s:5:"label";s:8:"Filename";}s:1:"B";a:3:{s:4:"type";s:4:"text";s:4:"name";s:4:"file";s:4:"help";s:24:"Filename of the download";}}i:5;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:10:",,,version";s:5:"label";s:7:"Version";}s:1:"B";a:2:{s:4:"type";s:6:"select";s:4:"name";s:7:"version";}}i:6;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:3:{s:4:"type";s:6:"button";s:5:"label";s:8:"Download";s:4:"name";s:8:"download";}}i:7;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:4:"span";s:3:"all";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:7;s:4:"cols";i:2;s:5:"align";s:6:"center";s:7:"options";a:0:{}}}','size' => '','style' => '','modified' => '1130738737',); -$templ_data[] = array('name' => 'calendar.export_csv_select','template' => '','lang' => '','group' => '0','version' => '1.9.002','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:8:{i:0;a:1:{s:2:"h1";s:6:",!@msg";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:5:{s:4:"type";s:5:"radio";s:4:"size";s:14:"search_results";s:4:"span";s:3:"all";s:5:"label";s:18:"Use search results";s:4:"name";s:17:"selection[select]";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:5:{s:4:"type";s:5:"radio";s:4:"size";s:8:"criteria";s:4:"span";s:3:"all";s:5:"label";s:19:"Use given criteria:";s:4:"name";s:17:"selection[select]";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:8:",,,start";s:5:"label";s:5:"Start";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:16:"selection[start]";s:4:"help";s:23:"Startdate of the export";}}i:5;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"size";s:6:",,,end";s:5:"label";s:3:"End";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:14:"selection[end]";s:4:"help";s:21:"Enddate of the export";}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:14:"select-account";s:4:"span";s:3:"all";s:4:"name";s:16:"selection[owner]";s:4:"size";s:6:"5,both";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:7;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:7;s:4:"cols";i:2;s:5:"align";s:6:"center";s:7:"options";a:0:{}}}','size' => '','style' => '','modified' => '1300135121',); +$templ_data[] = array('name' => 'calendar.export_csv_select','template' => '','lang' => '','group' => '0','version' => '1.9.003','data' => 'a:1:{i:0;a:6:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:2:{s:2:"h1";s:6:",!@msg";s:1:"A";s:3:"150";}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:11:"all,message";s:4:"name";s:3:"msg";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:2;a:2:{s:1:"A";a:5:{s:4:"type";s:5:"radio";s:4:"size";s:14:"search_results";s:4:"span";s:3:"all";s:5:"label";s:18:"Use search results";s:4:"name";s:9:"selection";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:3;a:2:{s:1:"A";a:6:{s:4:"type";s:5:"radio";s:4:"size";s:6:"filter";s:4:"span";s:3:"all";s:5:"label";s:21:"Use definition filter";s:4:"name";s:9:"selection";s:7:"onclick";s:50:"\\$j(\'div.filters\').show();\\$j(\'.criteria\').hide();";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:4;a:2:{s:1:"A";a:6:{s:4:"type";s:5:"radio";s:4:"size";s:8:"criteria";s:4:"span";s:3:"all";s:5:"label";s:19:"Use given criteria:";s:4:"name";s:9:"selection";s:8:"onchange";s:50:"\\$j(\'.criteria\').show();\\$j(\'div.filters\').hide();";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:5;a:2:{s:1:"A";a:8:{s:4:"type";s:4:"grid";s:4:"name";s:8:"criteria";s:4:"data";a:4:{i:0;a:0:{}i:1;a:2:{s:1:"A";a:4:{s:4:"type";s:5:"label";s:4:"size";s:1:"1";s:5:"label";s:5:"Start";i:1;a:1:{s:4:"type";s:3:"box";}}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:5:"start";s:4:"help";s:23:"Startdate of the export";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:3:"End";}s:1:"B";a:3:{s:4:"type";s:4:"date";s:4:"name";s:3:"end";s:4:"help";s:21:"Enddate of the export";}}i:3;a:2:{s:1:"A";a:4:{s:4:"type";s:14:"select-account";s:4:"span";s:9:"2,shorter";s:4:"name";s:5:"owner";s:4:"size";s:6:"5,both";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:3;s:4:"cols";i:2;s:4:"span";s:3:"all";s:4:"size";s:11:",,,criteria";s:7:"options";a:1:{i:3;s:8:"criteria";}}s:1:"B";a:1:{s:4:"type";s:5:"label";}}i:6;a:2:{s:1:"A";a:1:{s:4:"type";s:5:"label";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:6;s:4:"cols";i:2;s:5:"align";s:6:"center";s:7:"options";a:0:{}}}','size' => '','style' => '.shorter select { + width: 170px; +}','modified' => '1358792945',); $templ_data[] = array('name' => 'calendar.freetimesearch','template' => '','lang' => '','group' => '0','version' => '1.3.001','data' => 'a:1:{i:0;a:4:{s:4:"type";s:4:"grid";s:4:"data";a:7:{i:0;a:0:{}i:1;a:2:{s:1:"A";a:3:{s:4:"type";s:5:"label";s:4:"span";s:9:",size120b";s:5:"label";s:15:"Freetime Search";}s:1:"B";a:4:{s:4:"type";s:5:"label";s:4:"span";s:10:",redItalic";s:7:"no_lang";s:1:"1";s:4:"name";s:3:"msg";}}i:2;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:17:"Startdate / -time";}s:1:"B";a:3:{s:4:"type";s:9:"date-time";s:4:"name";s:5:"start";s:4:"help";s:33:"Startdate and -time of the search";}}i:3;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:8:"Duration";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:6:{s:4:"type";s:6:"select";s:7:"no_lang";s:1:"1";s:4:"name";s:8:"duration";s:4:"help";s:23:"Duration of the meeting";s:8:"onchange";s:92:"set_style_by_class(\'table\',\'end_hide\',\'visibility\',this.value == \'\' ? \'visible\' : \'hidden\');";s:4:"size";s:12:"Use end date";}i:2;a:4:{s:4:"type";s:9:"date-time";s:4:"name";s:3:"end";s:4:"help";s:57:"Enddate / -time of the meeting, eg. for more then one day";s:4:"span";s:9:",end_hide";}}}i:4;a:2:{s:1:"A";a:2:{s:4:"type";s:5:"label";s:5:"label";s:9:"Timeframe";}s:1:"B";a:7:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"5";i:1;a:3:{s:4:"type";s:13:"date-houronly";s:4:"name";s:10:"start_time";s:4:"help";s:19:"Timeframe to search";}i:2;a:2:{s:4:"type";s:5:"label";s:5:"label";s:3:"til";}i:3;a:3:{s:4:"type";s:13:"date-houronly";s:4:"name";s:8:"end_time";s:4:"help";s:19:"Timeframe to search";}i:4;a:2:{s:4:"type";s:5:"label";s:5:"label";s:8:"Weekdays";}i:5;a:4:{s:4:"type";s:10:"select-dow";s:4:"size";s:1:"3";s:4:"name";s:8:"weekdays";s:4:"help";s:25:"Weekdays to use in search";}}}i:5;a:2:{s:1:"A";a:4:{s:4:"type";s:6:"button";s:5:"label";s:10:"New search";s:4:"name";s:6:"search";s:4:"help";s:36:"new search with the above parameters";}s:1:"B";a:4:{s:4:"type";s:4:"hbox";s:4:"size";s:1:"2";i:1;a:4:{s:4:"type";s:6:"select";s:7:"no_lang";s:1:"1";s:4:"name";s:13:"search_window";s:4:"help";s:34:"how far to search (from startdate)";}i:2;a:5:{s:4:"type";s:6:"button";s:4:"name";s:6:"cancel";s:5:"label";s:6:"Cancel";s:4:"help";s:16:"Close the window";s:7:"onclick";s:15:"window.close();";}}}i:6;a:2:{s:1:"A";a:4:{s:4:"type";s:8:"template";s:4:"size";s:8:"freetime";s:4:"span";s:3:"all";s:4:"name";s:4:"rows";}s:1:"B";a:1:{s:4:"type";s:5:"label";}}}s:4:"rows";i:6;s:4:"cols";i:2;}}','size' => '','style' => '.size120b { text-size: 120%; font-weight: bold; } .redItalic { color: red; font-style: italic; }