dynamic = false; $this->name = "[Startseite]"; $this->eventList = 0; $this->includeEvents = ""; $this->excludeEvents = ""; $this->headerEvent1 = 0; $this->headerEvent2 = 0; $this->headerEvent3 = 0; $this->headerImage1 = ""; $this->headerImage2 = ""; $this->headerImage3 = ""; $this->headerTitle1 = ""; $this->headerTitle2 = ""; $this->headerTitle3 = ""; $this->headerSubtitle1 = ""; $this->headerSubtitle2 = ""; $this->headerSubtitle3 = ""; } /** @see CmsObject::load() */ //----------------------------------------------- function load($path=array()){ //----------------------------------------------- parent::load($path); if(!$this->classId){ return; } $query = sprintf("SELECT * FROM bruckm_indexpage WHERE id = %d", $this->classId); $result = dbQuery($query); $line = mysqli_fetch_array($result, MYSQLI_ASSOC); $this->template = $line['template']; $this->eventList = $line['eventList']; $this->headerEvent1 = $line['headerEvent1']; $this->headerEvent2 = $line['headerEvent2']; $this->headerEvent3 = $line['headerEvent3']; $this->headerImage1 = $line['headerImage1']; $this->headerImage2 = $line['headerImage2']; $this->headerImage3 = $line['headerImage2']; $this->headerTitle1 = $line['headerTitle1']; $this->headerTitle2 = $line['headerTitle2']; $this->headerTitle3 = $line['headerTitle3']; $this->headerSubtitle1 = $line['headerSubtitle1']; $this->headerSubtitle2 = $line['headerSubtitle2']; $this->headerSubtitle3 = $line['headerSubtitle3']; $this->includeEvents = $line['includeEvents']; $this->excludeEvents = $line['excludeEvents']; $this->buildingBlocks = array(); if(strlen($line['buildingBlocks']) > 0){ $buildingBlocks = explode("\t", $line['buildingBlocks']); foreach($buildingBlocks as $b){ $block = BuildingBlockFactory::instance($b); $block->load(); $this->buildingBlocks[] = $block; } } } /** @see Page::doSave() */ //---------------------------------------------- function doSave(){ //---------------------------------------------- $buildingBlocks = array(); foreach($this->buildingBlocks as $i=>$block){ $this->buildingBlocks[$i]->save(); $buildingBlocks[] = $this->buildingBlocks[$i]->getReference(); } $query = sprintf("UPDATE bruckm_indexpage SET template = %s, eventList = %d, headerEvent1 = %d, headerImage1 = %s, headerTitle1 = %s, headerSubtitle1 = %s, headerEvent2 = %d, headerImage2 = %s, headerTitle2 = %s, headerSubtitle2 = %s, headerEvent3 = %d, headerImage3 = %s, headerTitle3 = %s, headerSubtitle3 = %s, includeEvents = %s, excludeEvents = %s, buildingBlocks = %s WHERE id = %d", sqlstring($this->template), sqlnum($this->eventList), sqlnum($this->headerEvent1), sqlstring($this->headerImage1), sqlstring($this->headerTitle1), sqlstring($this->headerSubtitle1), sqlnum($this->headerEvent2), sqlstring($this->headerImage2), sqlstring($this->headerTitle2), sqlstring($this->headerSubtitle2), sqlnum($this->headerEvent3), sqlstring($this->headerImage3), sqlstring($this->headerTitle3), sqlstring($this->headerSubtitle3), sqlstring($this->includeEvents), sqlstring($this->excludeEvents), sqlstring(implode("\t", $buildingBlocks)), sqlnum($this->classId)); dbQuery($query); Page::doSave(); } /** @see Page::doCreate() */ //---------------------------------------------- function doCreate(){ //---------------------------------------------- $query = sprintf("INSERT INTO bruckm_indexpage (template) VALUES (%s)", sqlstring($this->template)); dbQuery($query); $this->classId = mysql_insert_id(); parent::doCreate(); } /** @see Page::install() */ //----------------------------------------------- function install(){ //----------------------------------------------- $query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_indexpage ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, template VARCHAR(100) NOT NULL, buildingBlocks TEXT NOT NULL DEFAULT '', eventList INT UNSIGNED NOT NULL DEFAULT 0, cache TEXT NOT NULL DEFAULT '', enabled TINYINT NOT NULL DEFAULT 0, quickImage1 VARCHAR(100) NOT NULL, quickImage2 VARCHAR(100) NOT NULL, quickLink1 VARCHAR(100) NOT NULL, quickLink2 VARCHAR(100) NOT NULL, quickText1 VARCHAR(100) NOT NULL, quickText2 VARCHAR(100) NOT NULL, includeEvents VARCHAR(100) NOT NULL, excludeEvents VARCHAR(100) NOT NULL, PRIMARY KEY (id), KEY (enabled) )"); dbQuery($query); TextBlock::install(); HeadingBlock::install(); HtmlBlock::install(); FileBlock::install(); ImageBlock::install(); GalleryBlock::install(); AlternatingImageBlock::install(); } /** @see CmsObject::update() */ //----------------------------------------------- function update(){ //----------------------------------------------- parent::update(); if(isset($_POST['eventList'])){ $this->eventList = $_POST['eventList']; } $this->headerEvent1 = $_POST['headerEvent1']; $this->headerTitle1 = $_POST['headerTitle1']; $this->headerSubtitle1 = $_POST['headerSubtitle1']; $this->headerEvent2 = $_POST['headerEvent2']; $this->headerTitle2 = $_POST['headerTitle2']; $this->headerSubtitle2 = $_POST['headerSubtitle2']; $this->headerEvent3 = $_POST['headerEvent3']; $this->headerTitle3 = $_POST['headerTitle3']; $this->headerSubtitle3 = $_POST['headerSubtitle3']; if(isset($_FILES['headerImage1']) && $_FILES['headerImage1']['error'] == UPLOAD_ERR_OK){ $this->headerImage1 = $this->uploadImage($_FILES['headerImage1'], $this->headerImage1, 1); } else if ($_POST['headerImageDelete1']) { $this->headerImage1 = ""; } if(isset($_FILES['headerImage2']) && $_FILES['headerImage2']['error'] == UPLOAD_ERR_OK){ $this->headerImage2 = $this->uploadImage($_FILES['headerImage2'], $this->headerImage2, 2); } else if ($_POST['headerImageDelete2']) { $this->headerImage2 = ""; } if(isset($_FILES['headerImage3']) && $_FILES['headerImage3']['error'] == UPLOAD_ERR_OK){ $this->headerImage3 = $this->uploadImage($_FILES['headerImage3'], $this->headerImage3, 3); } else if ($_POST['headerImageDelete3']) { $this->headerImage3 = ""; } if(isset($_POST['includeEvents'])){ $this->includeEvents = $_POST['includeEvents']; } if(isset($_POST['excludeEvents'])){ $this->excludeEvents = $_POST['excludeEvents']; } } /** @see CmsObject::doPrintClassContent() */ //----------------------------------------------- function doPrintClassContent(){ //----------------------------------------------- $t = new Template(CMS_TEMPLATE_DIR."indexpage.html"); // templates $templates = ""; $templateFiles = array(); $dir = opendir(TEMPLATE_DIR); while($file = readdir($dir)){ if(is_file(TEMPLATE_DIR.$file)){ $templateFiles[] = $file; } } sort($templateFiles); foreach($templateFiles as $file){ if($file == $this->template){ $templates .= ""; } else{ $templates .= "\n"; } } $t->setVar("TEMPLATES", $templates); // event list $lists = ""; $query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'EventList' ORDER BY name ASC"); $result = dbQuery($query); while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){ if($line['id'] == $this->eventList){ $lists .= ""; } $t->setVar("EVENT_LISTS", $lists); if($_SESSION['userlevel'] == USER_ADMIN){ $t->setVar("TEMPLATE_DISABLED", ""); $t->setVar("EVENT_LIST_DISABLED", ""); } else{ $t->setVar("TEMPLATE_DISABLED", "disabled=\"disabled\""); $t->setVar("EVENT_LIST_DISABLED", "disabled=\"disabled\""); } // include/exclude events if($_SESSION['userlevel'] == USER_ADMIN){ $t->setVar("INCLUDEEVENTS", $this->includeEvents); $t->setVar("EXCLUDEEVENTS", $this->excludeEvents); } else{ $t->removeBlock("ADMIN"); } // load events for header slider $headerEventIds = array(0); if ($this->headerEvent1) { $headerEventIds[] = $this->headerEvent1; } if ($this->headerEvent2) { $headerEventIds[] = $this->headerEvent2; } if ($this->headerEvent3) { $headerEventIds[] = $this->headerEvent3; } $query = sprintf( "SELECT flexiconId,name FROM bruckm_ticketevent WHERE (endDate >= '%s' AND (houseId = 1 OR houseId = 0)) OR flexiconId IN (%s) ORDER BY startDate ASC", date("Y-m-d"), implode(",", $headerEventIds) ); $result = dbQuery($query); $events = array(); while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $events[$line['flexiconId']] = $line['name']; } // header slider 1 if(!empty($this->headerImage1) && file_exists(IMG_DIR.$this->headerImage1)){ $t->setVar("HEADERIMAGE1", IMG_DIR.$this->headerImage1); } else{ $t->removeBlock("HEADERIMAGE1"); } $t->setVar("HEADERTITLE1", htmlspecialchars($this->headerTitle1)); $t->setVar("HEADERSUBTITLE1", htmlspecialchars($this->headerSubtitle1)); $options1 = ''; foreach ($events as $id=>$title) { $options1 .= sprintf('', $id, $id == $this->headerEvent1 ? 'selected' : '', $title ); } $t->setVar("HEADEREVENT1", $options1); // header slider 2 if(!empty($this->headerImage2) && file_exists(IMG_DIR.$this->headerImage2)){ $t->setVar("HEADERIMAGE2", IMG_DIR.$this->headerImage2); } else{ $t->removeBlock("HEADERIMAGE2"); } $t->setVar("HEADERTITLE2", htmlspecialchars($this->headerTitle2)); $t->setVar("HEADERSUBTITLE2", htmlspecialchars($this->headerSubtitle2)); $options2 = ''; foreach ($events as $id=>$title) { $options2 .= sprintf('', $id, $id == $this->headerEvent2 ? 'selected' : '', $title ); } $t->setVar("HEADEREVENT2", $options2); // header slider 3 if(!empty($this->headerImage3) && file_exists(IMG_DIR.$this->headerImage3)){ $t->setVar("HEADERIMAGE3", IMG_DIR.$this->headerImage3); } else{ $t->removeBlock("HEADERIMAGE3"); } $t->setVar("HEADERTITLE3", htmlspecialchars($this->headerTitle3)); $t->setVar("HEADERSUBTITLE3", htmlspecialchars($this->headerSubtitle3)); $options3 = ''; foreach ($events as $id=>$title) { $options3 .= sprintf('', $id, $id == $this->headerEvent3 ? 'selected' : '', $title ); } $t->setVar("HEADEREVENT3", $options3); $out = $t->toString(); $out .= $this->doPrintBuildingBlockInsertBar(0); foreach($this->buildingBlocks as $i=>$block){ $out .= $this->buildingBlocks[$i]->printContent($i); $out .= $this->doPrintBuildingBlockInsertBar($i+1); } return $out; } /** @see CmsObject::publish() */ //--------------------------------------------- function publish(){ //--------------------------------------------- if($this->canBePublished()){ $out = $this->doPublish(); $query = sprintf("UPDATE bruckm_index SET cache = %s WHERE id = %d", sqlstring($out), sqlnum($this->id)); dbQuery($query); $query = sprintf("UPDATE bruckm_indexpage SET cache = %s, enabled = 1 WHERE id = %d", sqlstring($out), sqlnum($this->classId)); dbQuery($query); $query = sprintf("UPDATE bruckm_indexpage SET enabled = 0 WHERE id != %d", sqlnum($this->classId)); dbQuery($query); return true; } return false; } /** @see CmsObject::doPublish() */ //---------------------------------------------- function doPublish(){ //---------------------------------------------- $t = new Template(TEMPLATE_DIR.$this->template); $content = ""; foreach($this->buildingBlocks as $i=>$block){ $content .= $this->buildingBlocks[$i]->publish(); } $t->setVar("CONTENT", $content); if(!$this->parentObj){ $this->parentObj = FlexiconFactory::instanceById($this->parentId); } if(!$this->parentObj->isLoaded()){ $this->parentObj->load(); } $t = $this->parentObj->printMenu($t); $t->setVar("TITLE", $this->toString()); $t->setVar("EVENTS", $this->printEvents()); $t->setVar("SLIDER", $this->printHeaderSlider()); return $t->toString(); } /** @see CmsObject::preview() */ //--------------------------------------------- function preview(){ //--------------------------------------------- return $this->doPublish(); } /** @see CmsObject::canBeDeleted() */ //-------------------------------------------- function canBeDeleted(){ //-------------------------------------------- $this->addError("Die Startseite darf nicht gelöscht werden!"); return false; } // === ADDIDTIONAL METHODS ====================================== // /** prints a bar with buttons for inserting building blocks * @param index position, where the building block will be inserted * @return string */ //----------------------------------------------- function doPrintBuildingBlockInsertBar($index){ //----------------------------------------------- $t = new Template(CMS_TEMPLATE_DIR."insertbar.html"); $button = "