mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
Calendar: Update merge to use changes introduced with 707c57e
This commit is contained in:
parent
68a79dce6a
commit
86c9b97e47
@ -129,6 +129,106 @@ class calendar_merge extends Api\Storage\Merge
|
|||||||
return parent::merge_string($content, $ids, $err, $mimetype, $fix, $charset);
|
return parent::merge_string($content, $ids, $err, $mimetype, $fix, $charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function merge_entries(array $ids = null, \EGroupware\Api\Storage\Merge &$document_merge = null, $pdf = null)
|
||||||
|
{
|
||||||
|
$document_merge = new calendar_merge();
|
||||||
|
|
||||||
|
if(is_null(($ids)))
|
||||||
|
{
|
||||||
|
$ids = json_decode($_REQUEST['id'], true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to make time span into appropriate ranges to match
|
||||||
|
$template = $ids['view'] ?: '';
|
||||||
|
if(stripos($_REQUEST['document'], 'month') !== false || stripos($_REQUEST['document'], lang('month')) !== false)
|
||||||
|
{
|
||||||
|
$template = 'month';
|
||||||
|
}
|
||||||
|
if(stripos($_REQUEST['document'], 'week') !== false || stripos($_REQUEST['document'], lang('week')) !== false)
|
||||||
|
{
|
||||||
|
$template = 'week';
|
||||||
|
}
|
||||||
|
|
||||||
|
//error_log("Detected template $template");
|
||||||
|
$date = $ids['date'];
|
||||||
|
$first = $ids['first'];
|
||||||
|
$last = $ids['last'];
|
||||||
|
|
||||||
|
// Pull dates from session if they're not in the request
|
||||||
|
if(!array_key_exists('first', $ids))
|
||||||
|
{
|
||||||
|
$ui = new calendar_ui();
|
||||||
|
$date = $ui->date;
|
||||||
|
$first = $ui->first;
|
||||||
|
$last = $ui->last;
|
||||||
|
}
|
||||||
|
switch($template)
|
||||||
|
{
|
||||||
|
case 'month':
|
||||||
|
// Trim to _only_ the month, do not pad to week start / end
|
||||||
|
$time = new Api\DateTime($date);
|
||||||
|
$timespan = array(array(
|
||||||
|
'start' => Api\DateTime::to($time->format('Y-m-01 00:00:00'), 'ts'),
|
||||||
|
'end' => Api\DateTime::to($time->format('Y-m-t 23:59:59'), 'ts')
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
case 'week':
|
||||||
|
$timespan = array();
|
||||||
|
$start = new Api\DateTime($first);
|
||||||
|
$end = new Api\DateTime($last);
|
||||||
|
$t = clone $start;
|
||||||
|
$t->modify('+1 week')->modify('-1 second');
|
||||||
|
if($t < $end)
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
$timespan[] = array(
|
||||||
|
'start' => $start->format('ts'),
|
||||||
|
'end' => $t->format('ts')
|
||||||
|
);
|
||||||
|
$start->modify('+1 week');
|
||||||
|
$t->modify('+1 week');
|
||||||
|
}
|
||||||
|
while($start < $end);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Fall through
|
||||||
|
default:
|
||||||
|
$timespan = array(array(
|
||||||
|
'start' => $first,
|
||||||
|
'end' => $last
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add path into document
|
||||||
|
static::check_document($_REQUEST['document'], $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']);
|
||||||
|
|
||||||
|
return \EGroupware\Api\Storage\Merge::merge_entries(array_key_exists('0', $ids) ? $ids : $timespan, $document_merge);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_filename_placeholders($document, $ids)
|
||||||
|
{
|
||||||
|
$placeholders = parent::get_filename_placeholders($document, $ids);
|
||||||
|
|
||||||
|
$request = json_decode($_REQUEST['id'], true) ?: [];
|
||||||
|
$template = $ids['view'] ?: '';
|
||||||
|
if(stripos($document, 'month') !== false || stripos($document, lang('month')) !== false)
|
||||||
|
{
|
||||||
|
$template = 'month';
|
||||||
|
}
|
||||||
|
if(stripos($document, 'week') !== false || stripos($document, lang('week')) !== false)
|
||||||
|
{
|
||||||
|
$template = 'week';
|
||||||
|
}
|
||||||
|
|
||||||
|
$placeholders['$$span$$'] = lang($template);
|
||||||
|
$placeholders['$$first$$'] = Api\DateTime::to($ids['first'] ?: $request['first'], true);
|
||||||
|
$placeholders['$$last$$'] = Api\DateTime::to($ids['last'] ?: $request['last'], true);
|
||||||
|
$placeholders['$$date$$'] = Api\DateTime::to($ids['date'] ?: $request['date'], true);
|
||||||
|
|
||||||
|
return $placeholders;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get replacements
|
* Get replacements
|
||||||
*
|
*
|
||||||
@ -182,7 +282,7 @@ class calendar_merge extends Api\Storage\Merge
|
|||||||
{
|
{
|
||||||
foreach(self::$range_tags as $key => $format)
|
foreach(self::$range_tags as $key => $format)
|
||||||
{
|
{
|
||||||
$value = date($format, $key == 'end' ? $id['end'] : $id['start']);
|
$value = Api\DateTime::to($key == 'end' ? $id['end'] : $id['start'], $format);
|
||||||
if($key == 'month') $value = lang($value);
|
if($key == 'month') $value = lang($value);
|
||||||
$values["$\$range/$key$$"] = $value;
|
$values["$\$range/$key$$"] = $value;
|
||||||
}
|
}
|
||||||
@ -440,8 +540,11 @@ class calendar_merge extends Api\Storage\Merge
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$_date = $date['start'] ? $date['start'] : $date;
|
$_date = new Api\DateTime(['start'] ? $date['start'] : $date);
|
||||||
if($days[date('Ymd',$_date)][$plugin]) return $days[date('Ymd',$_date)][$plugin][$n];
|
if($days[$_date->format('Ymd')][$plugin])
|
||||||
|
{
|
||||||
|
return $days[$_date->format('Ymd')][$plugin][$n];
|
||||||
|
}
|
||||||
|
|
||||||
$events = $this->bo->search($this->query + array(
|
$events = $this->bo->search($this->query + array(
|
||||||
'start' => $date['end'] ? $date['start'] : mktime(0, 0, 0, date('m', $_date), date('d', $_date), date('Y', $_date)),
|
'start' => $date['end'] ? $date['start'] : mktime(0, 0, 0, date('m', $_date), date('d', $_date), date('Y', $_date)),
|
||||||
@ -481,7 +584,7 @@ class calendar_merge extends Api\Storage\Merge
|
|||||||
$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23, 59, 59, 0, 0, 0));
|
$replacements['$$calendar_endtime$$'] = date($time_format, $day == date('Ymd', $event['end']) ? $event['end'] : mktime(23, 59, 59, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
$days[date('Ymd', $_date)][$dow][] = $replacements;
|
$days[$_date->format('Ymd')][$dow][] = $replacements;
|
||||||
}
|
}
|
||||||
if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false)
|
if(strpos($repeat, 'day/date') !== false || strpos($repeat, 'day/name') !== false)
|
||||||
{
|
{
|
||||||
@ -489,24 +592,24 @@ class calendar_merge extends Api\Storage\Merge
|
|||||||
'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
|
'$$day/date$$' => date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], strtotime($day)),
|
||||||
'$$day/name$$' => lang(date('l', strtotime($day)))
|
'$$day/name$$' => lang(date('l', strtotime($day)))
|
||||||
);
|
);
|
||||||
if(!is_array($days[date('Ymd', $_date)][date('l', strtotime($day))]))
|
if(!is_array($days[$_date->format('Ymd')][date('l', strtotime($day))]))
|
||||||
{
|
{
|
||||||
$blank = $this->calendar_replacements(array());
|
$blank = $this->calendar_replacements(array());
|
||||||
foreach($blank as &$value)
|
foreach($blank as &$value)
|
||||||
{
|
{
|
||||||
$value = '';
|
$value = '';
|
||||||
}
|
}
|
||||||
$days[date('Ymd', $_date)][date('l', strtotime($day))][] = $blank;
|
$days[$_date->format('Ymd')][date('l', strtotime($day))][] = $blank;
|
||||||
}
|
}
|
||||||
$days[date('Ymd', $_date)][date('l', strtotime($day))][0] += $date_marker;
|
$days[$_date->format('Ymd')][date('l', strtotime($day))][0] += $date_marker;
|
||||||
}
|
}
|
||||||
// Add in birthdays
|
// Add in birthdays
|
||||||
if(strpos($repeat, 'day/birthdays') !== false)
|
if(strpos($repeat, 'day/birthdays') !== false)
|
||||||
{
|
{
|
||||||
$days[date('Ymd', $_date)][date('l', strtotime($day))][0]['$$day/birthdays$$'] = $this->get_birthdays($day);
|
$days[$_date->format('Ymd')][date('l', strtotime($day))][0]['$$day/birthdays$$'] = $this->get_birthdays($day);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $days[date('Ymd', $_date)][$plugin][0];
|
return $days[$_date->format('Ymd')][$plugin][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -534,28 +534,6 @@ class calendar_ui
|
|||||||
*/
|
*/
|
||||||
function sidebox_etemplate($content = array())
|
function sidebox_etemplate($content = array())
|
||||||
{
|
{
|
||||||
if($content['merge'])
|
|
||||||
{
|
|
||||||
// View from sidebox is JSON encoded
|
|
||||||
$this->manage_states(array_merge($content,(array)json_decode($content['view'],true)));
|
|
||||||
if($content['first'])
|
|
||||||
{
|
|
||||||
$this->first = Api\DateTime::to($content['first'],'ts');
|
|
||||||
}
|
|
||||||
if($content['last'])
|
|
||||||
{
|
|
||||||
$this->last = new Api\DateTime($content['last']);
|
|
||||||
$this->last->setTime(23, 59, 59);
|
|
||||||
$this->last = $this->last->format('ts');
|
|
||||||
}
|
|
||||||
|
|
||||||
$_GET['merge'] = $content['merge'];
|
|
||||||
if($this->merge())
|
|
||||||
{
|
|
||||||
Framework::redirect('/index.php');//, array('menuaction' => 'calendar.calendar_uiviews.index'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Etemplate::reset_request();
|
Etemplate::reset_request();
|
||||||
$sidebox = new Etemplate('calendar.sidebox');
|
$sidebox = new Etemplate('calendar.sidebox');
|
||||||
|
|
||||||
@ -857,129 +835,4 @@ class calendar_ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge calendar events into a document
|
|
||||||
*
|
|
||||||
* Checks $_GET['merge'] for the document, and $timespan for the date range.
|
|
||||||
* If timespan is not provided, we try to guess based on the document name.
|
|
||||||
*
|
|
||||||
* @param Array $timespan
|
|
||||||
*
|
|
||||||
* @return boolean stop execution
|
|
||||||
*/
|
|
||||||
public function merge($timespan = array())
|
|
||||||
{
|
|
||||||
// Merge print
|
|
||||||
if($_GET['merge'])
|
|
||||||
{
|
|
||||||
if(!$timespan)
|
|
||||||
{
|
|
||||||
// Try to make time span into appropriate ranges to match
|
|
||||||
if(stripos($_GET['merge'],'month') !== false || stripos($_GET['merge'],lang('month')) !== false) $template = 'month';
|
|
||||||
if(stripos($_GET['merge'],'week') !== false || stripos($_GET['merge'],lang('week')) !== false) $template = 'week';
|
|
||||||
//error_log("Detected template $template");
|
|
||||||
switch ($template)
|
|
||||||
{
|
|
||||||
case 'month':
|
|
||||||
// Trim to _only_ the month, do not pad to week start / end
|
|
||||||
$time = new Api\DateTime($this->date);
|
|
||||||
$timespan = array(array(
|
|
||||||
'start' => Api\DateTime::to($time->format('Y-m-01 00:00:00'),'ts'),
|
|
||||||
'end' => Api\DateTime::to($time->format('Y-m-t 23:59:59'),'ts')
|
|
||||||
));
|
|
||||||
break;
|
|
||||||
case 'week':
|
|
||||||
$timespan = array();
|
|
||||||
$start = new Api\DateTime($this->first);
|
|
||||||
$t = clone $start;
|
|
||||||
$t->modify('+1 week')->modify('-1 second');
|
|
||||||
if($t->format('ts') < Api\DateTime::to($this->last,'ts'))
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
$timespan[] = array(
|
|
||||||
'start' => $start->format('ts'),
|
|
||||||
'end' => $t->format('ts')
|
|
||||||
);
|
|
||||||
$start->modify('+1 week');
|
|
||||||
$t->modify('+1 week');
|
|
||||||
} while( $start->format('ts') < $this->last);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Fall through
|
|
||||||
default:
|
|
||||||
$timespan = array(array(
|
|
||||||
'start' => is_array($this->first) ? $this->bo->date2ts($this->first) : $this->first,
|
|
||||||
'end' => is_array($this->last) ? $this->bo->date2ts($this->last) : $this->last
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$document = $_GET['merge'];
|
|
||||||
$merge = new calendar_merge();
|
|
||||||
if($error = $merge->check_document($document, $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']))
|
|
||||||
{
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
if(!$error && $this->merge_collabora($document, $timespan))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (!$error)
|
|
||||||
{
|
|
||||||
//error_log($_GET['merge'] . ' Timespan: ');foreach($timespan as $t) error_log(Api\DateTime::to($t['start']) . ' - ' . Api\DateTime::to($t['end']));
|
|
||||||
$error = $merge->download($document, $timespan, '', $GLOBALS['egw_info']['user']['preferences']['calendar']['document_dir']);
|
|
||||||
}
|
|
||||||
// Here? Doesn't actually give the message
|
|
||||||
Framework::refresh_opener($error, 'calendar');
|
|
||||||
}
|
|
||||||
unset($_GET['merge']);
|
|
||||||
if($error)
|
|
||||||
{
|
|
||||||
// This doesn't give message either, but at least it doesn't give a blank screen
|
|
||||||
Framework::redirect_link('/index.php', array(
|
|
||||||
'msg' => $error,
|
|
||||||
'cd' => 'yes'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function merge_collabora($document, $timespan)
|
|
||||||
{
|
|
||||||
$file = Api\Vfs::stat($document);
|
|
||||||
if(!$file['mime'])
|
|
||||||
{
|
|
||||||
$file['mime'] = Api\Vfs::mime_content_type($document);
|
|
||||||
}
|
|
||||||
|
|
||||||
$editable_mimes = array();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (class_exists('EGroupware\\collabora\\Bo') &&
|
|
||||||
$GLOBALS['egw_info']['user']['apps']['collabora'] &&
|
|
||||||
$discovery = \EGroupware\collabora\Bo::discover()
|
|
||||||
)
|
|
||||||
{
|
|
||||||
$editable_mimes = $discovery;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$timespan = json_encode($timespan);
|
|
||||||
|
|
||||||
if ($editable_mimes[$file['mime']])
|
|
||||||
{
|
|
||||||
Framework::popup(Framework::link('/index.php', array(
|
|
||||||
'menuaction' => 'collabora.EGroupware\\collabora\\Ui.merge_edit',
|
|
||||||
'document' => $document,
|
|
||||||
'merge' => 'calendar_merge',
|
|
||||||
'id' => $timespan
|
|
||||||
)),'_blank',false);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -191,23 +191,6 @@ class calendar_uiviews extends calendar_ui
|
|||||||
*/
|
*/
|
||||||
function index($content=array())
|
function index($content=array())
|
||||||
{
|
{
|
||||||
if($content['merge'])
|
|
||||||
{
|
|
||||||
// View from sidebox is JSON encoded
|
|
||||||
$this->manage_states(array_merge($content,json_decode($content['view'],true)));
|
|
||||||
if($content['first'])
|
|
||||||
{
|
|
||||||
$this->first = Api\DateTime::to($content['first'],'ts');
|
|
||||||
}
|
|
||||||
if($content['last'])
|
|
||||||
{
|
|
||||||
$this->last = Api\DateTime::to($content['last'],'ts');
|
|
||||||
}
|
|
||||||
$_GET['merge'] = $content['merge'];
|
|
||||||
$this->merge();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle views in other files
|
// handle views in other files
|
||||||
if (!isset($this->public_functions[$this->view]) && $this->view !== 'listview')
|
if (!isset($this->public_functions[$this->view]) && $this->view !== 'listview')
|
||||||
{
|
{
|
||||||
@ -499,16 +482,6 @@ class calendar_uiviews extends calendar_ui
|
|||||||
$this->last = $this->bo->date2ts($this->last);
|
$this->last = $this->bo->date2ts($this->last);
|
||||||
}
|
}
|
||||||
|
|
||||||
$merge = $this->merge();
|
|
||||||
if($merge)
|
|
||||||
{
|
|
||||||
Egw::redirect_link('/index.php',array(
|
|
||||||
'menuaction' => 'calendar.calendar_uiviews.index',
|
|
||||||
'msg' => $merge,
|
|
||||||
'ajax' => 'true'
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$search_params = $this->search_params;
|
$search_params = $this->search_params;
|
||||||
$search_params['daywise'] = false;
|
$search_params['daywise'] = false;
|
||||||
$search_params['start'] = $this->first;
|
$search_params['start'] = $this->first;
|
||||||
|
@ -2533,7 +2533,7 @@ export class CalendarApp extends EgwApp
|
|||||||
}
|
}
|
||||||
if(action && selected)
|
if(action && selected)
|
||||||
{
|
{
|
||||||
action.execute(selected);
|
super.merge(action, selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2541,16 +2541,23 @@ export class CalendarApp extends EgwApp
|
|||||||
// Set the hidden inputs to the current time span & submit
|
// Set the hidden inputs to the current time span & submit
|
||||||
widget.getRoot().getWidgetById('first').set_value(app.calendar.state.first);
|
widget.getRoot().getWidgetById('first').set_value(app.calendar.state.first);
|
||||||
widget.getRoot().getWidgetById('last').set_value(app.calendar.state.last);
|
widget.getRoot().getWidgetById('last').set_value(app.calendar.state.last);
|
||||||
if(widget.getRoot().getArrayMgr('content').getEntry('collabora_enabled'))
|
|
||||||
{
|
let vars = {
|
||||||
widget.getInstanceManager().submit();
|
menuaction: 'calendar.calendar_merge.merge_entries',
|
||||||
}
|
document: widget.getValue(),
|
||||||
else
|
merge: 'calendar_merge',
|
||||||
{
|
pdf: false,
|
||||||
widget.getInstanceManager().postSubmit();
|
select_all: false,
|
||||||
window.setTimeout(function() {widget.set_value('');},100);
|
id: JSON.stringify({
|
||||||
}
|
first: app.calendar.state.first,
|
||||||
|
last: app.calendar.state.last,
|
||||||
|
date: app.calendar.state.first,
|
||||||
|
view: app.calendar.state.view
|
||||||
|
})
|
||||||
|
};
|
||||||
|
egw.open_link(egw.link('/index.php', vars), '_blank');
|
||||||
}
|
}
|
||||||
|
widget.set_value('');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user