21
Modules / Re: ProCalendar - EventList
« Last post by hgs on June 08, 2025, 09:56:15 AM »Also rein theoretisch, wenn das Droplet Datum und Titel anzeigen kann, dann sicher auch (nur) die Beschreibung.
Kann jemand das Droplet mal hier als Code posten?
Unklar ist welche Beschreibunbg von welchem Event du eigentlich willst.
So ist es im Modul mitgeliefert und dann auch unter "AdminTools--->Droplets" zu finden
Quote
<?php
//:Shows an event list from ProCalendar
//:usage: [[eventlist?section_id=xx&flags=xx&max=xx&dateformat=xxxxxx&year=xx&month=xx]]
//:parameters:
//:- section_id : Section id from procalendar module
//:- on default all events of the current month are shown but you can custumize by using flags:
//:- max (integer) : limits event list to max items (if no other limit is reached already)
//:- year (integer) : year of start date
//:- month (integer): month of start date
//:- Set dateformat to suit your needs, add timeformat if needed
//:- dateformat (string): format of date representation as described in
//:- http:www.php.net/manual/en/function.date.php#refsect1-function.date-parameters
//:- flags (integer): kein flag = 0, startnow=1, bTimeEnd=2, bMonthHeading=4
//:- (standard=1) flags can be combine
$oReg = bin\WbAdaptor::getInstance();
$database = $oDb = $oReg->getDatabase();
$wb = $oReg->getApplication();
$oTrans = $oReg->getTranslate();
$oTrans->enableAddon('modules\\\procalendar');
if (!defined('PHP_TAB')){define("PHP_TAB", "\t");}
if (!defined('PHP_TAB2')){define("PHP_TAB2", "\t\t");}
if (!defined('PHP_TAB3')){define("PHP_TAB3", "\t\t\t");}
if (!function_exists('fillActionArray')){require(WB_PATH."/modules/procalendar/functions.php");}
$page_id = 0;
$page_link = '';
$eventlist = '';
$sOldMonth = 0;
$sNewMonth = 0;
$year = ((isset($year) && $year) ? intval($year) : date('Y'));
$month = (int)($month ?? 1);
$days = (int)($days ?? 0);
$flags = (int)($flags ?? 1);
// Set dateformat to suit your needs, add timeformat if needed
$dateformat = ($dateformat ?? 'd.m H:i'); // Standard php date formats 'd-m-Y'
$startnow = $flags & 1; // BIT #0 = 1
$bTimeEnd = $flags & 2; // BIT #1 = 2
$bMonthHeading = $flags & 4; // BIT #2 = 4
$iDateWidth = ($bTimeEnd ? 140 : 90);
if (isset($year) && $year) {
// $month = ((isset($month) && empty($month)) ? '1' : $month);
$t1 = (($year > date('Y')) ? strtotime($year.'-'.$month.'-01') : time());
// $t1 = strtotime($year.'-'.$month.'-01');
$t2 = strtotime($year.'-12-31');
$diff = (floor(abs($t2-$t1)));
$divisor = 86400; # a day has 24*60*60 sec
$days = isset($days) && $days ? $days : (floor($diff / $divisor));
// $time = time (); date('Y-n-j',$t2)
// $part = $time - $time % $divisor;
$aTimeDiff = [
'year'=> $year,
'month'=> $month,
'act_year'=> date('Y'),
'start_date'=> date('Y-m-d',$t1),
'end_date'=> date('Y-m-d',$t2),
'days'=> $days,
];
}
$fixdays = isset($days);
//$startnow = isset($startnow) ? intval($startnow) : 0;
$max = isset($max) && $max ? intval($max) : 1000;
//$section_id = isset($section_id) ? intval($section_id) : 0 ;
// Fetch base page link
if ($section_id != 0) {
$sql = 'SELECT `p`.`link` FROM `'.TABLE_PREFIX.'sections` `s` '
. 'INNER JOIN `'.TABLE_PREFIX.'pages` `p` ON (`s`.`page_id` = `p`.`page_id`) '
. 'WHERE `s`.`section_id` = '.$section_id.' ';
if (($link = $oDb->get_one($sql))){
$page_link = $wb->page_link($link);
}
}
// Set start- and end date for query
$datestart = ($startnow ? date('Y-m-d') : $year.'-'.$month.'-1');
$sParm1 = date('Y-m-d', strtotime("+".($days-1)." day"));
$sParm2 = date('Y-n-j', strtotime($datestart." + ".($days-1)." day"));
$sRequest1 = ("$year-$month-".($days < cal_days_in_month(CAL_GREGORIAN, $month,$year)));
$sParam3 = cal_days_in_month(CAL_GREGORIAN, $month,$year);
$dateend = ($startnow ? $sParm1 : ($fixdays ? $sParm2 : ($sRequest1 ? $days : $sParam3)));
/* */
if (isset($archive)) {
$dateend = date('Y-n-j');
$datestart = date('Y-n-j', strtotime(" ".($days-1)." day"));
}
$aDebug = [
'year' => $year,
'month' => $month,
'days' => $days,
'datestart' => $datestart,
'dateend' => $dateend,
'date_start' => date('Y-n-j', strtotime(" ".($days-1)." day")),
'date_end' => date('Y-n-j'),
];
$eventlist .= '<div class="info_body" style="text-align:left;font-family:sans-serif,monospace;">';
// Fetch the items
if (!isset($actions) || (isset($actions) && empty($actions))){
$actions = fillActionArray($datestart, $dateend, $section_id);
}
if (is_array($actions) && sizeof($actions)){
$eventlist .= '<ul class="event-list w3-ul" style="margin-left:0;padding-left:0;list-style-type: none !important;">'.PHP_EOL;
$sOldMonth = strtotime($datestart);
$sNewMonth = 0;
if ($bMonthHeading && ($year) || ($bMonthHeading && (date('m',$sNewMonth) != date('m',$sOldMonth)))){
$iMonth = date('n',$sOldMonth);
$sTmpMonat = "monthnames_".$iMonth;
$sMonthName = $oTrans->$sTmpMonat;
$eventlist .= '<li class="event-header"><h4>'.$sMonthName.' '.date('Y',$sOldMonth).'</h4></li>'.PHP_EOL;
}
foreach($actions as $row){
if ($max > 0) {
if (!isset($kat) || (isset($kat) && in_array($row["acttype"], explode(',',$kat)))) {
$max--;
$ds = ($row['date_start'].' '.$row['time_start']);
$de = ($row['date_end'] .' '.$row['time_end']);
$sNewMonth = strtotime($ds);
if ($bMonthHeading && (date('m',$sNewMonth) != date('m',$sOldMonth))){
$sOldMonth = strtotime($ds);
$iMonth = date('n',$sOldMonth);
$sTmpMonat = "monthnames_".$iMonth;
$sMonthName = $oTrans->$sTmpMonat;
$eventlist .= '<li class="event-header"><h4>'.$sMonthName.' '.date('Y',$sOldMonth).'</h4></li>'.PHP_EOL;
}
// Build url like : pages/kalendar.php?year=1900&month=01&day=03&id=2&detail=1
$page_url = $page_link.'?year='.(substr($ds,0,4)).'&month='.(substr($ds,5,2)).'&day='.(substr($ds,8,2)).'&id='.$row['id'].'&detail=1';
$datetime_start = mktime(substr($ds,11,2),substr($ds,14,2),0,substr($ds,5,2),substr($ds,8,2),substr($ds,0,4));
$datetime_end = mktime(substr($de,11,2),substr($de,14,2),0,substr($de,5,2),substr($de,8,2),substr($de,0,4));
$time_end = ($bTimeEnd ? ' - '.(substr($de,11,2).':'.substr($de,14,2)) : '');
$eventlist .= '<li class="eventlist" style="padding:4px 0;">'.PHP_EOL;
$eventlist .= PHP_TAB.'<div class="w3-display-container">'.PHP_EOL;
if ($bTimeEnd && ($datetime_start != $datetime_end)) {
$eventlist .= PHP_TAB2.'<span style="width:'.$iDateWidth.'px;" class="c_date1 w3-display-topleft" >'.date($dateformat,$datetime_start).' -'.date('H:i',$datetime_end).'</span>'.PHP_EOL;
} else {
$eventlist .= PHP_TAB2.'<span style="width:'.$iDateWidth.'px;" class="c_date2 w3-display-topleft" >'.date($dateformat,$datetime_start).$time_end.'</span>'.PHP_EOL;
}
$eventlist .= PHP_TAB.'<span style="margin:0px;display:inline-block;">'.PHP_EOL.PHP_TAB2.'<a href="'.$page_url.'">'.PHP_EOL.PHP_TAB3.'<span class="c_name"><b>'.$row["name"].'</b></span>'.PHP_EOL.PHP_TAB2.'</a>'.PHP_EOL.PHP_TAB.'</span>'.PHP_EOL;
$eventlist .= PHP_TAB.'</div>'.PHP_EOL;
if ($row["custom1"]) {
$eventlist .= PHP_TAB.'<div class="c_desc">'.$row["custom1"].'</div>'.PHP_EOL;
}
$eventlist .= '</li>'.PHP_EOL;
}
}
} // end for
$eventlist .= '</ul>';
}
return $eventlist .= "</div>";