<?php
namespace CityMountain\CourseManagementBundle\Module\Frontend;
use CityMountain\CourseManagementBundle\Utils\OperationCM;
use CityMountain\ToolBundle\Utils\OperationTool;
use Contao\Input;
class InterfaceModule extends \Module
{
protected $strTemplate = 'fe_modInterface';
protected $parmTest = false;
protected $paramUnitId;
protected $parmId;
protected $parmAct;
protected $paramDayNow;
protected $ActMod;
protected $ActAct;
protected $paramNoPrinterIcon = false;
protected $paramNoHorizontaleLine = false;
protected $paramSortOut = array();
protected $paramInterfaceConfig = array();
protected $paramVLSGroup = false;
protected $ResMember = array();
protected $tempSaveVLSKursarten = array();
protected $tempSaveMemPos = array();
//Datum, Zeit, Thema, Ort, Info, Veranstalter -> Sicht für Verbände
protected $field_1_1 = Array ( 'eveId' =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'tl_calendar_events.id AS eveId')
,'fkEventType' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'fkUnit' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'title' =>array('sql'=>1,'noout'=>0,'lang'=>'','link'=>1)
,'cmEventCanceled' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'fkEventSector1' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'fkEventSector2' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'startDate' =>array('sql'=>1,'noout'=>0,'lang'=>'','css'=>'style="width:55px"')
,'addTime' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'startTime' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'cmLocation' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'iconInfoBlock' =>array('sql'=>0,'noout'=>0,'lang'=>' ')
,'cmEventHybrid' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'eveType' =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'fkEventType AS eveType')
);
//Datum, Zeit, Thema, Ort, Info -> Sicht für einzelen Veranstalter
protected $field_1_2 = Array ( 'eveId' =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'tl_calendar_events.id AS eveId')
,'fkEventType' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'title' =>array('sql'=>1,'noout'=>0,'lang'=>'','link'=>1)
,'cmEventCanceled' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'fkEventSector1' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'fkEventSector2' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'startDate' =>array('sql'=>1,'noout'=>0,'lang'=>'','css'=>'style="width:55px"')
,'addTime' =>array('sql'=>1,'noout'=>1,'lang'=>'')
,'startTime' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'cmLocation' =>array('sql'=>1,'noout'=>0,'lang'=>'')
,'eveType' =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'fkEventType AS eveType')
);
//Standardfelder für die Selektion des Interface
protected $fieldK_1 = Array ( 'eveId' =>array('sql'=>1,'noout'=>1,'lang'=>'','sql_spz'=>'tl_calendar_events.id AS eveId')
);
protected $tab_header = array();
public function generate()
{
$request = \System::getContainer()->get('request_stack')->getCurrentRequest();
if ($request && \System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . $GLOBALS['TL_LANG']['FMD']['zCMInterface'][0] . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = \StringUtil::specialcharsUrl(\System::getContainer()->get('router')->generate('contao_backend', array('do'=>'themes', 'table'=>'tl_module', 'act'=>'edit', 'id'=>$this->id)));
return $objTemplate->parse();
}
return parent::generate();
}
protected function compile()
{
//Parameter setzen
unset($paramUnitId,$parmId,$parmAct);
$this->parmTest = \Input::get('test');
$this->paramUnitId = \Input::get('organizerId');
if($this->paramUnitId==''&&\Input::get('anbieter_id')<>'')$this->paramUnitId = \Input::get('anbieter_id');
$this->parmId = \Input::get('id');
$this->parmAct = \Input::get('act');
$this->paramDayNow = mktime(0, 0, 0, date("n"), date("j"), date("Y"));
list($this->ActMod, $this->ActAct) = explode('_', $this->parmAct);
//Daten auslesen
if($this->paramUnitId) //Standardausgabe für einen Anbieter
{
if($this->ActMod==1) //Eventverarbeitung
{
$eventType = array();
$eventSector = array(); //Sparte
$eventSectorSub = array(); //Rubrik
$isHierarchy = 0;
$units = array();
switch($this->ActAct)
{
case 1:
case 2:
//Kurse alle
//Veranstaltungs Art
$tmpEventType = \Input::get('eventType');
if($tmpEventType==''&&\Input::get('kurs_art')<>''){
$tmpEventType = array_key_first(OperationTool::getMasterdataValues(0,"eventType",0,array("AND mvValueMapping=".\Input::get('kurs_art'))));
}
if($tmpEventType)
{
$eventType = explode(',',$tmpEventType);
}else
{
$eventType = array_keys(OperationTool::getMasterdataValues(0,"eventType"));
}
//Spart bzw. Sector
$tmpEventSector = \Input::get('eventSector');
if($tmpEventSector==''&&\Input::get('kurs_sparte')<>''){
$tmpEventSector = array_key_first(OperationTool::getMasterdataValues(0,"eventSector",0,array("AND mvValueMapping=".\Input::get('kurs_sparte'))));
}
if($tmpEventSector)
{
$eventSector = explode(',',$tmpEventSector);
}
//laden der Rubrik aus dem Sektor, wenn dieser gefüllt wird
if(count($eventSector)>0)
{
foreach($eventSector as $idSector)
{
$tmpEventSectorSub = array_keys(OperationTool::getMasterdataValues(0,"eventSectorSub",0,array("AND fkEventSector=".$idSector)));
$eventSectorSub = array_merge($eventSectorSub,$tmpEventSectorSub);
}
}
//Rubrik bzw. SectorSub
$tmpEventSectorSub = \Input::get('eventSectorSub');
if($tmpEventSectorSub==''&&\Input::get('kurs_rubrik')<>''){
$tmpEventSectorSub = array_key_first(OperationTool::getMasterdataValues(0,"eventSectorSub",0,array("AND mvValueMapping=".\Input::get('kurs_rubrik'))));
}
if($tmpEventSectorSub)
{
$eventSectorSub = array_merge($eventSectorSub,explode(',', $tmpEventSectorSub));
}else
{
//Wenn Rubrik leer und keine Sparte, werden alle Rubriken geladen
if(count($eventSectorSub)==0)
{
$eventSectorSub = array_key_first(OperationTool::getMasterdataValues(0,"eventSectorSub",0));
}
}
//Hierarchie prüfen
$isHierarchy = \Input::get('organizerH');
if(\Input::get('anbieter_h')<>''){
$isHierarchy = \Input::get('anbieter_h');
}
//Units Laden
if(strpos($this->paramUnitId,',')){//Mehrere Vereine
$units = array($this->paramUnitId);
if($isHierarchy)$units = array_keys(OperationTool::getUnitsHierarchy(array_flip(explode(',',$this->paramUnitId))));
}else{//ein Verein, nur noch Prüfung
$units = array($this->paramUnitId);
if($isHierarchy)$units = array_keys(OperationTool::getUnitsHierarchy(array($this->paramUnitId=>$this->paramUnitId)));
}
if($this->ActAct==1) $locl_field = $this->field_1_1;
if($this->ActAct==2) $locl_field = $this->field_1_2;
//Selektieren der Veranstaltungen nur wenn es einen Verein hat
if(count($units)>0){
$objRes = $this->Database->prepare("
SELECT ".$this->gen_select($locl_field)."
FROM tl_calendar_events
WHERE pid = 2
AND published = 1
AND fkEventType IN (".implode(',',$eventType).")
AND id IN (SELECT pid FROM tl_zEventIndex WHERE fkEventSector1 IN (".implode(',',$eventSectorSub).")
OR fkEventSector2 IN (".implode(',',$eventSectorSub).") )
AND fkUnit IN (".implode(',',$units).")
AND startDate >= ?
ORDER BY startDate
")->execute($this->paramDayNow);
}
$this->tab_header = $locl_field;
break;
}
}elseif($this->ActMod==2) //Nicht ausprogrammiert
{
//nichts
}
}
//////
elseif($this->parmId) //Konfigurierteausgabe
{
//nichts
}
// Prepare table
$arrTd = array();
$start = -1;
$limit = $objRes->numRows;
// TBODY
if($limit<>0){
while ($objRes->next())
{
$class = 'row_' . ++$start . (($start == 0) ? ' row_first' : '') . ((($start + 1) == $limit) ? ' row_last' : '') . ((($start % 2) == 0) ? ' even' : ' odd');
if($objRes->cmEventCanceled)$class .= ' eventCanceled';
//Daten automatisch hinzufügen
foreach ($this->tab_header as $key=>$wert)
{
if(!$wert['noout'])$arrTd[$class][$key] = $objRes->$key;
if(!$wert['noout']&&array_key_exists('css',$wert))$arrTd[$class][$key.'_css'] = $wert['css'];
//$arrTd[$class][$key] = $objRes->$key;
}
//Manuelle daten hinzufügen
if(array_key_exists('startDate',$this->tab_header))$arrTd[$class]['startDate'] = date($GLOBALS['TL_CONFIG']['dateFormat'],$objRes->startDate);
if(array_key_exists('startTime',$this->tab_header))$arrTd[$class]['startTime'] = date($GLOBALS['TL_CONFIG']['timeFormat'],$objRes->startTime);
if(array_key_exists('startTime',$this->tab_header))$arrTd[$class]['startTimeStamp'] = $objRes->startTime;
if(array_key_exists('endTime',$this->tab_header))$arrTd[$class]['endTime'] = date($GLOBALS['TL_CONFIG']['timeFormat'],$objRes->endTime);
if(array_key_exists('fkEventType',$this->tab_header)) $arrTd[$class]['fkEventType'] = \Controller::replaceInsertTags('{{CMEvent::eventType::'.$objRes->eveId.'}}');
if(array_key_exists('fkUnit',$this->tab_header))$arrTd[$class]['fkUnit'] = OperationCM::getUnitName($objRes->fkUnit);
//Bedinungen
//Keine Zeit, wenn diese nicht ausgewählt ist
if(array_key_exists('addTime',$this->tab_header)&&!$objRes->addTime)unset($arrTd[$class]['startTime']);
//Keine Endtzeit, wenn diese gleich Startzeit ist
if(array_key_exists('endTime',$this->tab_header)&&$objRes->endTime==$objRes->startTime)unset($arrTd[$class]['endTime']);
//storniert einfügen bei Thema
if($objRes->cmEventCanceled && array_key_exists('title',$this->tab_header))$arrTd[$class]['title'].= ' <font color="red">abgesagt</font>';
//iconInfoBlock
if(array_key_exists('iconInfoBlock',$this->tab_header)){
if($objRes->cmEventHybrid==1)$arrTd[$class]['iconInfoBlock'] = '<img src="bundles/citymountaincoursemanagement/icons/iconHybrid.png" title="Hybrid-Veranstaltung">';
}
//Zentralle verarbeitung am Schluss
foreach ($this->tab_header as $key=>$wert) // Betrifft ganze Linie
{
$id_iframe = '';
//Link setzen für Detailsicht
switch ($this->ActMod){
case 1:
if($this->parmId)$id_iframe= '?id_iframe='.$this->parmId;
$linkurl = \Environment::get('url').'/veranstaltungsuebersicht/'.$objRes->eveId.'.html'.$id_iframe;
if(!$wert['noout']&&array_key_exists('link',$wert)&&$wert['link']&&$objRes->startDate>=$this->paramDayNow)$arrTd[$class][$key] = '<a href="'.$linkurl.'">'.$arrTd[$class][$key].'</a>';
break;
}
//Sprache laden
switch ($this->ActMod){
case 1:
$this->loadLanguageFile('tl_calendar_events');
if(!$this->tab_header[$key]['lang']&& array_key_exists($key,$GLOBALS['TL_LANG']['tl_calendar_events']))$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events'][$key][0];
if(!array_key_exists($key,$GLOBALS['TL_LANG']['tl_calendar_events']) && $this->tab_header[$key]['lang']=="" )$this->tab_header[$key]['lang'] = $key;
if($key=='startDate')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['zstartDate'][0];
if($key=='startTime')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['zstartTime'][0];
if($key=='endTime')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['zendTime'][0];
if($key=='title')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['ztitle'][0];
if($key=='cmLocation')$this->tab_header[$key]['lang'] = $GLOBALS['TL_LANG']['tl_calendar_events']['cmLocationShort'][0];
break;
}
}
}
}else{//keine Einträge
$this->Template->no_entry = 1;
$this->paramNoPrinterIcon = true;
}
//Sortierung der Ausgabe >> wird nicht genutzt
/*if(!$this->Template->no_entry)
{
unset($arrTd2);
$start = -1;
foreach ($arrTd as $key => $row) {
$class = 'row_' . ++$start . (($start == 0) ? ' row_first' : '') . ((($start + 1) == $limit) ? ' row_last' : '') . ((($start % 2) == 0) ? ' even' : ' odd');
$arrTd2[$class] = $arrTd[$key];
}
$arrTd = $arrTd2;
}*/
$url = $this->generate_standard_link();
//Headerverarbeiten
foreach ($this->tab_header as $key=>$wert)
{
if(!$wert['noout'])$tab_header_out[$key] = $wert;
}
$this->Template->link_popup = $url.'&pop=1';
$this->Template->tbody = $arrTd;
$this->Template->tab_header = $tab_header_out;
$this->Template->NoPrinterIcon = $this->paramNoPrinterIcon;
//$this->Template->calendar = $objTemplate->parse();
}
protected function generate_standard_link()
{
//$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $_SERVER['QUERY_STRING']
$url = "http://".$_SERVER['HTTP_HOST']."/interface.html?";
if($this->paramUnitId) $url .= 'organizerId='.$this->paramUnitId;
if(\Input::get('organizerH')) $url .= '&organizerH='.\Input::get('organizerH');
if(\Input::get('eventType')) $url .= '&eventType='.\Input::get('eventType');
if(\Input::get('eventSector')) $url .= '&eventSector='.\Input::get('eventSector');
if(\Input::get('eventSectorSub')) $url .= '&eventSectorSub='.\Input::get('eventSectorSub');
if($this->parmId) $url .= '&id='.$this->parmId;
$url .= '&act='.$this->parmAct;
return $url;
}
protected function gen_select($in)
{
unset($out);
foreach($in as $key=>$wert){
if($wert['sql']) //SQL relevant
{
if(array_key_exists('sql_spz',$wert)&&$wert['sql_spz']) //Wenn es zusatz für die SQL abfrage hat
{
$out[] = $wert['sql_spz'];
}else
{
$out[] = $key;
}
}
}
return implode(',', $out);
}
}
?>