2010-10-13 19:25:40 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2015-06-22 11:17:00 +02:00
|
|
|
* EGroupware: iCal export plugin of calendar
|
2010-10-13 19:25:40 +02:00
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package calendar
|
|
|
|
* @subpackage importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Nathan Gray
|
|
|
|
* @copyright Nathan Gray
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-06-22 11:17:00 +02:00
|
|
|
* iCal export plugin of calendar
|
2010-10-13 19:25:40 +02:00
|
|
|
*/
|
|
|
|
class calendar_export_ical extends calendar_export_csv {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports records as defined in $_definition
|
|
|
|
*
|
|
|
|
* @param egw_record $_definition
|
|
|
|
*/
|
|
|
|
public function export( $_stream, importexport_definition $_definition) {
|
|
|
|
$options = $_definition->plugin_options;
|
|
|
|
$this->bo = new calendar_bo();
|
|
|
|
$boical = new calendar_ical();
|
2011-05-30 19:23:46 +02:00
|
|
|
|
|
|
|
// Custom fields need to be specifically requested
|
|
|
|
$cfs = array();
|
|
|
|
|
2011-08-30 16:49:49 +02:00
|
|
|
$limit_exception = bo_merge::is_export_limit_excepted();
|
2011-09-16 15:03:46 +02:00
|
|
|
if (!$limit_exception) $export_limit = bo_merge::getExportLimit('calendar');
|
2011-08-17 17:38:56 +02:00
|
|
|
|
2013-01-23 17:10:17 +01:00
|
|
|
if($options['selection'] == 'criteria')
|
|
|
|
{
|
2011-05-30 19:23:46 +02:00
|
|
|
$query = array(
|
2013-01-23 17:10:17 +01:00
|
|
|
'start' => $options['criteria']['start'],
|
|
|
|
'end' => strtotime('+1 day',$options['criteria']['end'])-1,
|
|
|
|
'categories' => $options['categories'],
|
2011-05-30 19:23:46 +02:00
|
|
|
'daywise' => false,
|
2013-01-23 17:10:17 +01:00
|
|
|
'users' => $options['criteria']['owner'],
|
2011-05-30 19:23:46 +02:00
|
|
|
'cfs' => $cfs // Otherwise we shouldn't get any custom fields
|
|
|
|
);
|
2011-09-13 11:05:33 +02:00
|
|
|
if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) {
|
2011-05-30 19:23:46 +02:00
|
|
|
$query['offset'] = 0;
|
2011-09-13 11:05:33 +02:00
|
|
|
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
|
2011-05-30 19:23:46 +02:00
|
|
|
}
|
|
|
|
$events =& $this->bo->search($query);
|
2013-01-23 17:10:17 +01:00
|
|
|
}
|
2013-01-30 16:45:48 +01:00
|
|
|
// Scheduled export will use 'all', which we don't allow through UI
|
|
|
|
elseif ($options['selection'] == 'search_results' || $options['selection'] == 'all')
|
2013-01-23 17:10:17 +01:00
|
|
|
{
|
2011-05-30 19:23:46 +02:00
|
|
|
$states = $GLOBALS['egw']->session->appsession('session_data','calendar');
|
2013-01-23 17:10:17 +01:00
|
|
|
if($states['view'] == 'listview')
|
|
|
|
{
|
2011-05-30 19:23:46 +02:00
|
|
|
$query = $GLOBALS['egw']->session->appsession('calendar_list','calendar');
|
|
|
|
$query['num_rows'] = -1; // all
|
|
|
|
$query['start'] = 0;
|
|
|
|
$query['cfs'] = $cfs;
|
|
|
|
|
2011-09-13 11:05:33 +02:00
|
|
|
if(bo_merge::hasExportLimit($export_limit) && !$limit_exception) {
|
|
|
|
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
|
2011-05-30 19:23:46 +02:00
|
|
|
}
|
|
|
|
$ui = new calendar_uilist();
|
2015-06-22 11:17:00 +02:00
|
|
|
$unused = null;
|
2011-09-05 09:12:57 +02:00
|
|
|
$ui->get_rows($query, $events, $unused);
|
2013-01-23 17:10:17 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-30 19:23:46 +02:00
|
|
|
$query = $GLOBALS['egw']->session->appsession('session_data','calendar');
|
|
|
|
$query['users'] = explode(',', $query['owner']);
|
|
|
|
$query['num_rows'] = -1;
|
2013-01-23 17:10:17 +01:00
|
|
|
if(bo_merge::hasExportLimit($export_limit) && !$limit_exception)
|
|
|
|
{
|
2011-09-13 11:05:33 +02:00
|
|
|
$query['num_rows'] = (int)$export_limit; // ! int of 'no' is 0
|
2011-05-30 19:23:46 +02:00
|
|
|
}
|
|
|
|
|
2013-01-23 17:10:17 +01:00
|
|
|
switch($states['view'])
|
|
|
|
{
|
2011-05-30 19:23:46 +02:00
|
|
|
case 'month':
|
|
|
|
$query += calendar_export_csv::get_query_month($states);
|
|
|
|
break;
|
|
|
|
case 'week':
|
|
|
|
$query += calendar_export_csv::get_query_week($states);
|
|
|
|
break;
|
|
|
|
case 'day':
|
|
|
|
$query += calendar_export_csv::get_query_day($states);
|
|
|
|
break;
|
|
|
|
default:
|
2013-01-21 17:17:56 +01:00
|
|
|
// Let UI set the date ranges
|
2011-05-30 19:23:46 +02:00
|
|
|
$ui = new calendar_uiviews($query);
|
2013-01-21 17:17:56 +01:00
|
|
|
if(method_exists($ui, $states['view']))
|
|
|
|
{
|
|
|
|
ob_start();
|
|
|
|
$ui->$states['view']();
|
|
|
|
ob_end_clean();
|
|
|
|
}
|
2011-05-30 19:23:46 +02:00
|
|
|
$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
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2011-09-13 11:05:33 +02:00
|
|
|
$boupdate = new calendar_boupdate();
|
|
|
|
$events = $boupdate->search($query + array(
|
2011-05-30 19:23:46 +02:00
|
|
|
'offset' => 0,
|
|
|
|
'order' => 'cal_start',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
2015-06-22 11:17:00 +02:00
|
|
|
// compile list of unique cal_id's, as iCal should contain whole series, not recurrences
|
|
|
|
// calendar_ical->exportVCal needs to read events again, to get them in server-time
|
|
|
|
$ids = array();
|
|
|
|
foreach($events as $event)
|
|
|
|
{
|
|
|
|
$id = is_array($event) ? $event['id'] : $event;
|
|
|
|
if (($id = (int)$id)) $ids[$id] = $id;
|
|
|
|
}
|
2011-05-30 19:23:46 +02:00
|
|
|
|
2015-06-22 11:17:00 +02:00
|
|
|
$ical =& $boical->exportVCal($ids,'2.0','PUBLISH',false);
|
2010-10-13 19:25:40 +02:00
|
|
|
fwrite($_stream, $ical);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated name of plugin
|
|
|
|
*
|
|
|
|
* @return string name
|
|
|
|
*/
|
|
|
|
public static function get_name() {
|
|
|
|
return lang('Calendar iCal export');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns translated (user) description of plugin
|
|
|
|
*
|
|
|
|
* @return string descriprion
|
|
|
|
*/
|
|
|
|
public static function get_description() {
|
|
|
|
return lang("Exports events from your Calendar in iCal format.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retruns file suffix for exported file
|
|
|
|
*
|
|
|
|
* @return string suffix
|
|
|
|
*/
|
|
|
|
public static function get_filesuffix() {
|
|
|
|
return 'ics';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_mimetype() {
|
|
|
|
return 'text/calendar';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return html for options.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function get_options_etpl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns selectors of this plugin
|
|
|
|
*
|
|
|
|
*/
|
2013-01-21 19:59:33 +01:00
|
|
|
public function get_selectors_etpl($definition = null) {
|
|
|
|
$data = parent::get_selectors_etpl($definition);
|
|
|
|
return $data;
|
2010-10-13 19:25:40 +02:00
|
|
|
}
|
|
|
|
}
|