seeddms-code/views/bootstrap/class.Calendar.php

515 lines
16 KiB
PHP
Raw Normal View History

2012-12-14 07:53:13 +00:00
<?php
/**
* Implementation of Calendar view
*
* @category DMS
* @package SeedDMS
2012-12-14 07:53:13 +00:00
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2002-2005 Markus Westphal,
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
* 2010-2012 Uwe Steinmann
* @version Release: @package_version@
*/
/**
* Include parent class
*/
//require_once("class.Bootstrap.php");
2012-12-14 07:53:13 +00:00
/**
* Class which outputs the html page for Calendar view
*
* @category DMS
* @package SeedDMS
2012-12-14 07:53:13 +00:00
* @author Markus Westphal, Malcolm Cowe, Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2002-2005 Markus Westphal,
* 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli,
* 2010-2012 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_View_Calendar extends SeedDMS_Theme_Style {
2012-12-14 07:53:13 +00:00
2017-02-16 14:02:46 +00:00
function iteminfo() { /* {{{ */
$dms = $this->params['dms'];
$document = $this->params['document'];
$version = $this->params['version'];
$event = $this->params['event'];
$strictformcheck = $this->params['strictformcheck'];
$cachedir = $this->params['cachedir'];
2022-09-09 04:56:56 +00:00
$conversionmgr = $this->params['conversionmgr'];
$previewconverters = $this->params['previewConverters'];
2017-02-16 14:02:46 +00:00
$previewwidthlist = $this->params['previewWidthList'];
$previewwidthdetail = $this->params['previewWidthDetail'];
$timeout = $this->params['timeout'];
2019-01-18 12:07:39 +00:00
$xsendfile = $this->params['xsendfile'];
2017-02-16 14:02:46 +00:00
if($document) {
2022-01-03 18:14:13 +00:00
print $this->folderListHeader();
print "<tbody>\n";
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout, $xsendfile);
2022-09-09 04:56:56 +00:00
if($conversionmgr)
$previewer->setConversionMgr($conversionmgr);
else
$previewer->setConverters($previewconverters);
$document->verifyLastestContentExpriry();
$txt = $this->callHook('documentListItem', $document, $previewer, false, 'calendar');
if(is_string($txt))
echo $txt;
else {
$extracontent = array();
$extracontent['below_title'] = $this->getListRowPath($document);
echo $this->documentListRow($document, $previewer, 0, false, $extracontent);
}
2022-01-03 18:14:13 +00:00
echo "</tbody>\n</table>\n";
2017-02-16 14:02:46 +00:00
}
if($event) {
// print_r($event);
$this->contentHeading(getMLText('edit_event'));
?>
2018-04-23 13:50:46 +00:00
<form class="form-horizontal" action="../op/op.EditEvent.php" id="form1" name="form1" method="post">
2017-02-16 14:02:46 +00:00
<?php echo createHiddenFieldWithKey('editevent'); ?>
<input type="hidden" name="eventid" value="<?php echo (int) $event["id"]; ?>">
2018-04-23 13:50:46 +00:00
<?php
$this->contentContainerStart();
2018-04-23 13:50:46 +00:00
$this->formField(
getMLText("from"),
$this->getDateChooser(getReadableDate($event["start"]), "from")
2018-04-23 13:50:46 +00:00
);
$this->formField(
getMLText("to"),
$this->getDateChooser(getReadableDate($event["stop"]-86400), "to")
2018-04-23 13:50:46 +00:00
);
$this->formField(
getMLText("name"),
array(
'element'=>'input',
'type'=>'text',
'name'=>'name',
'value'=>htmlspecialchars($event["name"])
)
2018-04-23 13:50:46 +00:00
);
$this->formField(
getMLText("comment"),
array(
'element'=>'textarea',
'name'=>'comment',
'rows'=>4,
'cols'=>80,
'value'=>htmlspecialchars($event["comment"]),
'required'=>$strictformcheck
)
2018-04-23 13:50:46 +00:00
);
2022-03-28 17:10:03 +00:00
if($euser = $dms->getUser($event['userID'])) {
$this->formField(
getMLText("user"),
array(
'element'=>'plain',
'value'=>htmlspecialchars($euser->getFullName())
)
);
}
$this->contentContainerEnd();
2020-08-27 05:52:52 +00:00
$this->formSubmit("<i class=\"fa fa-save\"></i> ".getMLText('save'));
2018-04-23 13:50:46 +00:00
?>
2017-02-16 14:02:46 +00:00
</form>
<?php
$this->contentHeading(getMLText('rm_event'));
$this->contentContainerStart();
?>
<form action="../op/op.RemoveEvent.php" name="form2" method="post">
<?php echo createHiddenFieldWithKey('removeevent'); ?>
<input type="hidden" name="eventid" value="<?php echo intval($event["id"]); ?>">
<p><?php printMLText("confirm_rm_event", array ("name" => htmlspecialchars($event["name"])));?></p>
<?php $this->formSubmit("<i class=\"fa fa-remove\"></i> ".getMLText('delete'),'','','danger'); ?>
2017-02-16 14:02:46 +00:00
</form>
<?php
$this->contentContainerEnd();
}
2012-12-14 07:53:13 +00:00
} /* }}} */
2017-02-16 14:02:46 +00:00
function itemsperday() { /* {{{ */
$dms = $this->params['dms'];
$start = explode('-', $this->params['start']);
$cachedir = $this->params['cachedir'];
2022-09-09 04:56:56 +00:00
$conversionmgr = $this->params['conversionmgr'];
$previewconverters = $this->params['previewConverters'];
2017-02-16 14:02:46 +00:00
$previewwidthlist = $this->params['previewWidthList'];
$previewwidthdetail = $this->params['previewWidthDetail'];
$timeout = $this->params['timeout'];
2019-01-18 12:07:39 +00:00
$xsendfile = $this->params['xsendfile'];
2017-02-16 14:02:46 +00:00
if($this->params['start']) {
$from = makeTsFromLongDate($this->params['start'].' 00:00:00');
} else {
$from = time();
}
2017-02-16 14:02:46 +00:00
if($data = $dms->getTimeline($from)) {
$this->contentHeading(getReadableDate($from));
print "<table id=\"viewfolder-table\" class=\"table table-condensed\">";
print "<thead>\n<tr>\n";
print "<th></th>\n";
print "<th>".getMLText("name")."</th>\n";
print "<th>".getMLText("status")."</th>\n";
print "<th>".getMLText("action")."</th>\n";
print "</tr>\n</thead>\n<tbody>\n";
2019-01-18 12:07:39 +00:00
$previewer = new SeedDMS_Preview_Previewer($cachedir, $previewwidthdetail, $timeout, $xsendfile);
2022-09-09 04:56:56 +00:00
if($conversionmgr)
$previewer->setConversionMgr($conversionmgr);
else
$previewer->setConverters($previewconverters);
2017-02-16 14:02:46 +00:00
foreach($data as $i=>$item) {
/* Filter out timeline events for the documents not happened on the
* selected day
*/
if(substr($item['date'], 0, 10) == $this->params['start'])
if($item['document']) {
echo $this->documentListRow($item['document'], $previewer);
2012-12-14 07:53:13 +00:00
}
}
2017-02-16 14:02:46 +00:00
echo "</tbody>\n</table>\n";
2012-12-14 07:53:13 +00:00
}
} /* }}} */
2017-02-16 14:02:46 +00:00
function events() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
2017-02-21 16:26:16 +00:00
$calendar = $this->params['calendar'];
2017-02-16 14:02:46 +00:00
$eventtype = $this->params['eventtype'];
$start = explode('-', $this->params['start']);
$end = explode('-', $this->params['end']);
$arr = array();
switch($eventtype) {
case 'regular':
2017-02-21 16:26:16 +00:00
$events = $calendar->getEventsInInterval(mktime(0,0,0, $start[1], $start[2], $start[0]), mktime(23,59,59, $end[1], $end[2], $end[0]));
2017-02-16 14:02:46 +00:00
foreach ($events as $event){
2022-04-08 04:51:40 +00:00
$arr[] = array(
'start'=>date('Y-m-d', $event["start"]),
'end'=>date('Y-m-d', $event["stop"]),
'title'=>$event["name"].($event['comment'] ? "\n".$event['comment'] : ''),
'eventid'=>$event["id"],
'eventtype'=> $eventtype,
);
2017-02-16 14:02:46 +00:00
}
break;
2022-04-07 16:18:09 +00:00
case 'expires':
if(mktime(23,59,59, $end[1], $end[2], $end[0]) > time()) {
$documents = $dms->getDocumentsExpired($this->params['end']);
foreach ($documents as $document){
2023-04-03 13:50:40 +00:00
if($document->getAccessMode($user) >= M_READ) {
$arr[] = array(
'start'=>date('Y-m-d', $document->getExpires()),
'allDay'=>true,
'color'=>'#ff4455',
'title'=>$document->getName()."\nexpires",
'documentid'=> $document->getID(),
'eventtype'=> $eventtype,
);
}
2022-04-07 16:18:09 +00:00
}
2017-02-16 14:02:46 +00:00
}
break;
case 'attrdate':
if(mktime(23,59,59, $end[1], $end[2], $end[0]) > time()) {
$attrdefs = $dms->getAllAttributeDefinitions(\SeedDMS_Core_AttributeDefinition::objtype_document);
foreach($attrdefs as $attrdef) {
if($attrdef->getType() == \SeedDMS_Core_AttributeDefinition::type_date) {
$documents = $attrdef->getObjects($this->params['start'], 0, O_GTEQ);
foreach ($documents['docs'] as $document){
2023-04-03 13:50:40 +00:00
if($document->getAccessMode($user) >= M_READ) {
$arr[] = array(
'start'=>$document->getAttribute($attrdef)->getValue(),
'allDay'=>true,
'color'=>'#4455ff',
'title'=>$document->getName()."\n".$attrdef->getName(),
'documentid'=> $document->getID(),
'eventtype'=> $eventtype,
);
}
}
}
}
}
break;
2017-02-16 14:02:46 +00:00
case 'action':
/* These are all operations which added a new version, an attachment
* or any kind of status change
*/
2017-02-16 14:02:46 +00:00
if($this->params['start']) {
$from = makeTsFromLongDate($this->params['start'].' 00:00:00');
} else {
$from = time()-7*86400;
}
2012-12-14 07:53:13 +00:00
2017-02-16 14:02:46 +00:00
if($this->params['end']) {
$to = makeTsFromLongDate($this->params['end'].' 23:59:59');
} else {
$to = time();
}
2017-02-16 14:02:46 +00:00
if($data = $dms->getTimeline($from, $to)) {
foreach($data as $i=>$item) {
switch($item['type']) {
case 'add_version':
$color = '#20a820';
break;
case 'add_file':
2022-03-28 17:10:45 +00:00
$color = '#c3bf00';
2017-02-16 14:02:46 +00:00
break;
case 'status_change':
2022-03-28 17:10:45 +00:00
if($item['status'] == S_RELEASED)
$color = '#129a02';
else
$color = '#a8a8a8';
2017-02-16 14:02:46 +00:00
break;
default:
$color = '#20a8a8';
}
if ($item['document']->getAccessMode($user) >= M_READ)
2017-02-16 14:02:46 +00:00
$arr[] = array(
'start'=>$item['date'],
'title'=>$item['document']->getName().(isset($item['version']) ? " (".$item['version'].")" : "").(isset($item['status']) ? "\n".getOverallStatusText($item['status']) : ''),
2017-12-19 07:27:10 +00:00
'allDay'=>isset($item['allday']) ? $item['allday'] : false,
2017-02-16 14:02:46 +00:00
'color'=>$color,
'type'=>$item['type'],
'documentid'=> (int) $item['document']->getID(),
'version'=> isset($item['version']) ? (int) $item['version'] : '',
'statusid'=> isset($item['statusid']) ? (int) $item['statusid'] : '',
'statuslogid'=> isset($item['statuslogid']) ? (int) $item['statuslogid'] : '',
2022-04-08 04:51:40 +00:00
'fileid'=> isset($item['fileid']) ? (int) $item['fileid'] : '',
'eventtype'=> $eventtype,
2017-02-16 14:02:46 +00:00
);
}
2012-12-14 07:53:13 +00:00
}
2017-02-16 14:02:46 +00:00
break;
2012-12-14 07:53:13 +00:00
}
2017-02-16 14:02:46 +00:00
header('Content-Type: application/json');
echo json_encode($arr);
2012-12-14 07:53:13 +00:00
} /* }}} */
2016-03-16 14:11:33 +00:00
function js() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
2017-02-16 14:02:46 +00:00
$strictformcheck = $this->params['strictformcheck'];
2022-03-28 17:11:00 +00:00
$day = $this->params['day'];
$year = $this->params['year'];
$month = $this->params['month'];
header('Content-Type: application/javascript; charset=UTF-8');
2021-05-27 19:57:12 +00:00
parent::jsTranslations(array('js_form_error', 'js_form_errors'));
2022-03-28 17:11:00 +00:00
$query = '';
if($day && $year && $month)
$query = http_build_query(['day'=>$day, 'year'=>$year, 'month'=>$month]);
2017-02-16 14:02:46 +00:00
?>
$(document).ready(function() {
$('#calendar').fullCalendar({
height: $(window).height()-210,
locale: '<?php echo substr($this->params['session']->getLanguage(), 0, 2); ?>',
<?php if(!$user->isGuest()) { ?>
2017-02-16 14:02:46 +00:00
customButtons: {
addEventButton: {
text: '<?php printMLText('add_event'); ?>',
click: function() {
// alert('clicked the custom button!');
2022-03-28 17:11:00 +00:00
document.location.href = '../out/out.AddEvent.php<?= $query ? '?'.$query : ''?>';
2017-02-16 14:02:46 +00:00
}
}
},
<?php } ?>
2017-02-16 14:02:46 +00:00
header: {
left: 'prev,next today addEventButton',
center: 'title',
right: 'month,agendaWeek,agendaDay,listWeek'
},
defaultDate: '<?php echo date('Y-m-d'); ?>',
navLinks: true, // can click day/week names to navigate views
editable: false,
weekNumbers: true,
eventLimit: true, // allow "more" link when too many events
eventDrop: function(event, delta, revertFunc) {
// if (!confirm("Are you sure about this change?")) {
// revertFunc();
// }
2022-04-08 04:51:40 +00:00
var fd = new FormData();
fd.append('formtoken', '<?php echo createFormKey('editevent'); ?>');
fd.append('eventid', event.eventid);
fd.append('documentid', event.documentid);
fd.append('from', event.start.format());
fd.append('ajax', 1);
fd.append('eventtype', event.eventtype);
$.post("../op/op.EditEvent.php",
// fd,
"formtoken=<?php echo createFormKey('editevent'); ?>&eventid="+event.eventid+"&documentid="+event.documentid+"&from="+event.start.format()+"&ajax=1&eventtype="+event.eventtype,
function(response) {
noty({
text: response.message,
type: response.success === true ? 'success' : 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500,
});
$('#calendar').fullCalendar('refetchEvents');
}, "json");
2017-02-16 14:02:46 +00:00
},
eventSources: [
{
url: 'out.Calendar.php?action=events',
editable: true,
eventStartEditable: false
},
{
url: 'out.Calendar.php?action=events&eventtype=action',
editable: false
2022-04-07 16:18:09 +00:00
},
{
url: 'out.Calendar.php?action=events&eventtype=attrdate',
editable: false
},
2022-04-07 16:18:09 +00:00
{
url: 'out.Calendar.php?action=events&eventtype=expires',
2022-04-08 04:51:40 +00:00
editable: true
2017-02-16 14:02:46 +00:00
}
],
eventClick: function(event, element) {
$('div.ajax.iteminfo').trigger('update', {
documentid: event.documentid,
version: event.version,
eventid: event.eventid,
statusid: event.statusid,
statuslogid: event.statuslogid,
fileid: event.fileid,
callback: function() {
$("#form1").validate({
debug: false,
submitHandler: function(form) {
$.post("../op/op.EditEvent.php", $(form).serialize()+"&ajax=1", function(response) {
noty({
text: response.message,
type: response.success === true ? 'success' : 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
timeout: 1500,
});
$('#calendar').fullCalendar('refetchEvents');
}, "json");
},
messages: {
name: "<?php printMLText("js_no_name");?>",
comment: "<?php printMLText("js_no_comment");?>"
},
});
$('#fromdate, #todate')
.datepicker()
.on('changeDate', function(ev){
$(ev.currentTarget).datepicker('hide');
});
}
});
$('div.ajax.itemsperday').html('');
},
dayClick: function(date, jsEvent, view) {
$('div.ajax.itemsperday').trigger('update', {start: date.format()});
$('div.ajax.iteminfo').html('');
}
});
});
/*
function checkForm()
{
msg = new Array()
if (document.form1.name.value == "") msg.push("<?php printMLText("js_no_name");?>");
<?php
if ($strictformcheck) {
?>
if (document.form1.comment.value == "") msg.push("<?php printMLText("js_no_comment");?>");
<?php
}
?>
if (msg != "") {
noty({
text: msg.join('<br />'),
type: 'error',
dismissQueue: true,
layout: 'topRight',
theme: 'defaultTheme',
_timeout: 1500,
});
return false;
}
else
return true;
}
$(document).ready(function() {
$('body').on('submit', '#form1', function(ev){
if(checkForm()) return;
ev.preventDefault();
});
});
*/
<?php
2020-03-04 21:26:05 +00:00
$this->printClickDocumentJs();
2016-03-16 14:11:33 +00:00
} /* }}} */
2012-12-14 07:53:13 +00:00
function show() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
2020-08-27 05:52:52 +00:00
$this->htmlAddHeader('<script type="text/javascript" src="../views/'.$this->theme.'/vendors/jquery-validation/jquery.validate.js"></script>'."\n", 'js');
2021-05-27 19:57:12 +00:00
$this->htmlAddHeader('<script type="text/javascript" src="../views/'.$this->theme.'/styles/validation-default.js"></script>'."\n", 'js');
2020-08-27 05:52:52 +00:00
$this->htmlAddHeader('<script type="text/javascript" src="../views/'.$this->theme.'/vendors/moment/moment.min.js"></script>'."\n", 'js');
$this->htmlAddHeader('<script type="text/javascript" src="../views/'.$this->theme.'/vendors/fullcalendar/fullcalendar.min.js"></script>'."\n", 'js');
$this->htmlAddHeader('<script type="text/javascript" src="../views/'.$this->theme.'/vendors/fullcalendar/locale-all.js"></script>'."\n", 'js');
$this->htmlAddHeader('<link href="../views/'.$this->theme.'/vendors/fullcalendar/fullcalendar.min.css" rel="stylesheet"></link>'."\n", 'css');
$this->htmlAddHeader('<link href="../views/'.$this->theme.'/vendors/fullcalendar/fullcalendar.print.min.css" rel="stylesheet" media="print"></link>'."\n", 'css');
2012-12-14 07:53:13 +00:00
$this->htmlStartPage(getMLText("calendar"));
$this->globalNavigation();
$this->contentStart();
// $this->pageNavigation("", "calendar", array());
$this->rowStart();
$this->columnStart(8);
2017-02-16 14:02:46 +00:00
?>
<div id="calendar" style="margin-bottom: 20px;"></div>
<div id="cal_legend">
<?php
$legend = [];
$legend[] = ['color'=>'ff4455', 'text'=>'expired'];
$legend[] = ['color'=>'20a820', 'text'=>'updated'];
$legend[] = ['color'=>'c3bf00', 'text'=>'timeline_add_file'];
$legend[] = ['color'=>'129a02', 'text'=>'released'];
$legend[] = ['color'=>'a8a8a8', 'text'=>'status_change'];
$legend[] = ['color'=>'20a8a8', 'text'=>'undefined'];
$legend[] = ['color'=>'3a87ad', 'text'=>'event'];
foreach($legend as $item) {
echo "<span style='margin-right: 1em;'><i class='fa fa-circle' style='color: #".$item['color'].";'></i> ".getMLText($item['text'])."</span>";
}
?>
</div>
<?php
$this->columnEnd();
$this->columnStart(4);
?>
<div id="docinfo">
2017-02-16 14:02:46 +00:00
<div class="ajax iteminfo" data-view="Calendar" data-action="iteminfo" ></div>
<div class="ajax itemsperday" data-view="Calendar" data-action="itemsperday" ></div>
</div>
<?php
$this->columnEnd();
$this->rowEnd();
$this->contentEnd();
2012-12-14 07:53:13 +00:00
$this->htmlEndPage();
} /* }}} */
2017-02-16 14:02:46 +00:00
2012-12-14 07:53:13 +00:00
}
?>