<?php
//=================================================================
// KOOBI R7 - CMS - PORTALSOFTWARE(c) DREAM4(r) 
// HTTP://WWW.DREAM4.DE
//=================================================================
// ACHTUNG!
// DIESER PROGRAMMCODE IST URHERRECHTLICH GESCHUETZT
// DIE URHEBERRECHTE LIEGEN BEI DEN JEWEILIGEN AUTOREN.
// AENDERUNGEN IN DIESER DATEI ERFOLGEN AUF EIGENE GEFAHR!
// ES IST NICHT GESTATTET, DEN COPYRIGHTHINWEIS ZU AENDERN ODER ZU
// ENTFERNEN. NUR WENN SIE EINE COPYRIGHTHINWEIS-ENTFERNUNG BESTELLT
// HABEN, DUERFEN SIE DIESEN ENTFERNEN.
//================================================================
// BEI FRAGEN WENDEN SIE SICH BITTE AN: KONTAKT@DREAM4.DE
//=================================================================
class Faq
{
	function displayFaq()
	{
		if( (isset($_REQUEST['faq_id'])) && (is_numeric($_REQUEST['faq_id'])) )
		{
			$fid = abs((int)$_REQUEST['faq_id']); 
		} else {
			$fid = 0;
		}

		$area = AREA;
		$faq = array();
		$curr_faq = 0;
		$this->getFaq($fid, '', $faq, $area, '1', '', '', 1, '','', $curr_faq);
		
		$headernav = ($fid==0) ? $GLOBALS['config_vars']['Faq'] : getNavigationPath($fid, 'faq', 'faq', 'faq_id','Id','Name_1');
		$pagetitle = clean_page_title($headernav);
		
		$GLOBALS['tmpl']->assign('pagetitle_html', $pagetitle);
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('faq', $faq);
		$GLOBALS['tmpl']->assign('curr_faq', $curr_faq);
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/faq/showfaq.tpl'));
	}
	
	function getFaq($id, $prefix, &$faq, &$area, $active, $orderby, $ascdesc, $i, $vor = '', $f, $curr_faq = 0)
	{
		$LC = $_SESSION['Langcode'];
	
		switch (@$_REQUEST['orderby']) 
		{
			case "date" : $orderby = "Datum";
				break;
			case "author" : $orderby = "Benutzer";
				break;
			case "title" : $orderby = "Faq";
				break;
				case '':
			default : $orderby = "Position";
				break;
		} 
	
		switch (@$_REQUEST['ascdesc'])
		{
			case "asc": $ascdesc = "ASC";break;
			case "desc": $ascdesc = "DESC";break;
			case '':default : $ascdesc = "ASC";break;
		} 
	
		if ($active == 1) $zusatz = " AND Aktiv='1'";
		$query = $GLOBALS['db']->Query("SELECT *,Name_1 AS DefFaq, Name_{$LC} AS Faq, Antwort_{$LC} AS Antwort FROM " . PREFIX . "_faq WHERE Parent_Id = $id AND Sektion = '" . AREA . "' $zusatz ORDER BY $orderby $ascdesc");
	
		$i++;
		$f++;
		$a = 0;
	
		$faq_erg = array();
	
		$r_faq = $GLOBALS['db']->Query("SELECT *,Name_1 AS DefFaq, Name_{$LC} AS Faq, Antwort_{$LC} AS Antwort FROM " . PREFIX . "_faq WHERE Id = '$id' AND Sektion = '" . AREA . "'");
		$curr_faq = $r_faq->fetchrow();
		
		if(is_object($curr_faq))
		{
			$curr_faq->visible_title = ($curr_faq->Faq=='') ? $curr_faq->DefFaq : $curr_faq->Faq;
			$curr_faq->main = $curr_faq->Parent_Id;
		}
		if (!$query->numrows()) return;
	
		while ($item = $query->fetchrow()) 
		{
			$a++;
			$firstid = $item->Position ;
			
			$item->Faq = ($item->Faq=='') ? $item->DefFaq : $item->Faq;
		
			if ($item->Parent_Id == 0) {
				$item->visible_title = ($vor) . ($a) . $prefix . ". " . $item->Faq;
			} else {
				$item->visible_title = ($vor) . ($a) . '.' . $prefix . " " . $item->Faq;
			} 
			$tb = "Textbilder_{$LC}";
			$item->Seotitle  = $item->Faq;
			$item->created = $item->Datum;
			$item->user = fetchusername($item->Benutzer);
			$item->hits = $item->Hits;
			$item->posi = $item->Position;
			$item->fid = $item->Id;
			$item->ulid = $f-1;
			$item->text = $item->Antwort;
			$item->faqonce = $item->Faq;
			@$item->main = $item->main;
			$item->Textbilder = $item->$tb;
			$item->text = (!empty($item->Textbilder)) ? inlinescreens($item->Textbilder, $item->text) : $item->text;
			$item->text = cleanEmptyTags($item->text);
			$item->text = autowords($item->text);
			array_push($faq, $item);
	
			$this->getFaq($item->Id, $prefix . "  " , $faq, $area, $active, $orderby, $ascdesc, $i, $vor . $a . ".", $f);
		} 
		return;
	}
}
?>