<?php
// ======================================================================== //
//                                                                          //
//   KooBI- Webportalsystem                                                 //
//   2003-2005 © dream4 - http://www.dream4.de                              //
//   Removing this Info without permission breaks your License.             //
//   Please note: KooBI is no Freeware! Any Part of the Software is © by    //
//   their owner.                                                           //
//                                                                          //
//   ====================================================================   //
//                                                                          //   
//   dream4 | webservices - Am Michelsgrund 7 - 69469 Weinheim - Germany    //    
//   tel. +49(0) 6201 - 980442 / fax. +49(0) 6201 - 64809                   //
//                                                                          //
// ======================================================================== //
$sname = simpletitle($lang['title_startpage']);
$limit = ($_REQUEST['pp']=="") ? 15 : $_REQUEST['pp'];
if(!isset($page)){$page = 1;}
include(BASEDIR . '/inc/functions_top.php');

// <<-- RSS- LINK ERZEUGEN -->>
if(checkactive(news)){
	if($_REQUEST['categ']!="all" && $_REQUEST['categ']!=""){
		$catq = "  && (newscat='".escs($_REQUEST['categ'])."') ";
		if(MRWRITE==1) { $rsslink = "rss/news/".$_REQUEST['categ']."/".$limit."/".$area.".htm";
		} else { $rsslink = "rss/?rss=news&amp;categ=".$_REQUEST['categ']."&amp;pp=".$limit."&amp;area=".$area."";
		}
	} else {
		if(MRWRITE==1) { $rsslink = "rss/news/".$limit."/".$area.".htm";
		} else{ $rsslink = "rss/?rss=news&amp;pp=".$limit."&amp;area=".$area."";}
	}
	
	$tmpl->assign("rsslink", $rsslink);
	
	// <<-- HIER WIRD UEBERPRUEFT, OB EIN START UND END- DATUM ANGEGEBEN WURDE. WURDE KEIN DATUM
	//      ANGEGEBEN, WIRD DER STARTPUNKT AUF DEN 1.1.2000 UND DER ENDPUNKT AUF DAS AKTUELLE
	//      DATUM GELEGT. -->>
	if($_REQUEST['start']!="") { 
		$show_start = $_REQUEST['start']; 
		$_REQUEST['s_day'] = @date("d",$show_start);
		$_REQUEST['s_month'] = @date("m",$show_start);
		$_REQUEST['s_year'] = @date("Y",$show_start);
	} else { 
		$show_start = mktime(0,0,0,$_REQUEST['s_month'],$_REQUEST['s_day'],$_REQUEST['s_year']); 
	}
	
	if($_REQUEST['end']!="") { 
		$show_end = $_REQUEST['end']; 
		$_REQUEST['e_day'] = @date("d",$show_end);
		$_REQUEST['e_month'] = @date("m",$show_end);
		$_REQUEST['e_year'] = @date("Y",$show_end);
	} else { 
		$show_end = mktime(0,0,0,$_REQUEST['e_month'],$_REQUEST['e_day'],$_REQUEST['e_year']); 
	}
	
	if($show_start<1) { $show_start = mktime(0,0,0,1,1,2000) ;}
	if($show_end<1) { $show_end = time() ;}
	
	if( ($_REQUEST['s_year']>1) && ($_REQUEST['e_year']>1) || ( ($show_start>1) && ($show_end>1) ) ){
		$tbetween = "( ntime between ".escs($show_start)." and  ".escs($show_end)." ) && ";
	}
	
	// <<-- WENN GESUCHT WIRD UND LÄNGE DES STRING > 3 IST, ZUSÄTZLICHEN QUERY ANFÜGEN -->>
	$q = escs(strictify($_REQUEST['q']));
	if(strlen($q)<3) {$q = ""; }
	switch($q){
		case "" : $db_search = ""; break;
		default : 
		$db_search = " && ( (cansearch='yes') && (title like '%".$q."%' or text like '%".$q."%' or textmore like '%".$q."%') )"; 
		$limit = 200; 
		$tmpl->assign('q', strip_tags(stripslashes($_REQUEST['q'])));
		$search = 1;
		break;
	}
	
	// <<-- NEWS UNTER BERUECKSICHTIGUNG ALLER ANGABEN AUSLESEN -->>
	$sql = new dbc("SELECT newsid FROM ".PREFIX."_news WHERE $tbetween ((area_id='$area' || allareas='yes') && ((time_end>=".time().") || (time_end='1') || (time_end='0')) && (((ispublic='1')) && (time_start<=".time().")$catq $db_search))");
	$num = $sql->numrows();
	
	$seiten = ceil($num / $limit);
	$a = prepage() * $limit - $limit;
	
	$ascdesc = ($_REQUEST['ud']=="asc") ? "asc" : "desc";
	
	$sql = new dbc("SELECT inline_screens, shortintro,area_id, isontop, shortintro, newscat, cancomment, uid, hits, image, image_align, newsid, title, text, textmore, time_start, ntime FROM ".PREFIX."_news WHERE $tbetween ((area_id='$area' || allareas='yes') && ((time_end>=".time().") || (time_end='1') || (time_end='0')) && (((ispublic='1')) && (time_start<=".time().")$catq $db_search))  ORDER BY time_start $ascdesc limit $a,$limit");
	$erg = $sql->numrows();
	$num_news = $erg;
	
	// ARRAY FÜR NEWSAUSGABE ZUSAMMENBAUEN...
	$news_array = array();
	$i = 2;
	$week = array();
	$lang['dayarray'] = array("1","2","3","4","5","6","7");
	foreach ($lang['dayarray'] as $day) {
		while ($row = $sql->fetchrow()) {
			
			unset($comments);
			$sql2 = new dbc("SELECT id FROM ".PREFIX."_newscomments WHERE newsid='".$row->newsid."'");
			$comments = $sql2->numrows();
			
			if ($row->cancomment != "yes") {
				$comments = 0;
			}
			$commtext = ($comments > 1) ? $lang['comments'] : $lang['comment'];
			
			// <<-- NEWS- OEFFNEN & SCHLIESSEN HANDLER (NUR FÜR NORMALE NEWSANSICHT) -->>
			$disp = "";
			$plusminus = "";
			$dyn = "";
			$position = strpos($_COOKIE["news"], "newsid" . $row->newsid);
			
			if ( is_numeric($position) ) {
				$disp = "none";
				$plusminus = "plus.gif";
			} else {
				$plusminus = "minus.gif";
			}
			$dyn = "<img border=\"0\" id=\"img_".$row->newsid."\" src=\"templates/".$THEME."/img/page/".$plusminus."\" 
			onmouseover=\"this.style.cursor = 'pointer'\"
			onclick=\"MWJ_changeDisplay('newsid".$row->newsid."', MWJ_getStyle( 'newsid".$row->newsid."', 'display' ) ? '' : 'none');
			koobi4_toggleImage('img_".$row->newsid."', this.src);
			koobi4_setCookie('news', 'newsid".$row->newsid."');\"
			alt=\"\" />";
			$dyntd = " onmouseover=\"this.style.cursor = 'pointer'\"
			ondblclick=\"MWJ_changeDisplay('newsid".$row->newsid."', MWJ_getStyle( 'newsid".$row->newsid."', 'display' ) ? '' : 'none');
			koobi4_toggleImage('img_".$row->newsid."', this.src);
			koobi4_setCookie('news', 'newsid".$row->newsid."');\"";
			
			$newslink = "index.php?area=".$row->area_id."&amp;p=news&amp;newsid=".$row->newsid."";
			$printlink = "index.php?area=".$row->area_id."&amp;p=news&amp;newsid=".$row->newsid."&amp;print=1";
			$userlink = "index.php?area=".$row->area_id."&amp;p=user&amp;id=".$row->uid."";
			
			if($q){
				$row->text = eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $row->text);
			}
			
			$row->textmore = stripslashes($row->textmore);
			$row->text = stripslashes($row->text);
			
			array_push($news_array, array(
			'dyntd' => $dyntd,
			'commtext' => $commtext,
			'comments' => $comments,
			'toggleimage' => $dyn,
			'disp' => $disp,
			'plusminus' => $plusminus,
			'newsid'	=> $row->newsid,
			'area'	=> $row->area_id,
			'image'	=> $row->image,
			'align'	=> $row->image_align,
			'title'	=> kstripslashes(kspecialchars($row->title)),
			'dow'   => $dow,
			'ntime' => mygmt($row->time_start),
			'text'	=> inlinescreens($row->inline_screens,$row->text),
			'more'	=> inlinescreens($row->inline_screens,$row->textmore),
			'hits'	=> $row->hits,
			'printtext'	=> $lang['printtext'],
			'link'	=> $newslink,
			'printlink'	=> $printlink,
			'userlink'	=> $userlink,
			'user'	=> fetchusername($row->uid),
			'shortintro' => $row->shortintro
			)
			);
			//$row->text,
			// <<-- TAG DER WOCHE -->>
			$dow = date("w", $row->time_start);
			$dow = ($dow == 0) ? 7 : $dow;
			
			$year = date("Y", $row->time_start);
			$week = date("W", $row->time_start);
			
			$sql_icon = new dbc("SELECT icon FROM ".PREFIX."_newscat WHERE catid='".$row->newscat."'");
			$row_icon = $sql_icon->fetchrow();
			if(file_exists("uploads/newscat_icons/".$row_icon->icon)){
				$row->icon = $row_icon->icon;
			}
			
			// <<-- 
			//      NACH WOCHENTAG SORTIERTES ARRAY
			//      WIR BENÖTIGEN HIER KEINE INLINESCREENS ODER NEUE SEITEN, DESHALB WERDEN DIESE CODES ENTFERNT
			//      HTML ENTFERNEN WIR ZUSÄTZLICH, BIS AUF <br />,<strong>,<em>,<b>,<i>. 
			//      ANSONSTEN KÖNNTE ES PROBLEME MIT OFFENEN TABELLEN GEBEN.
			// -->>
			if ($row->image != "") {
				$tmpl->assign('newsbild', $row->image);
				$tmpl->assign("align", $row->image_align);
			}
			$row->userlink = $userlink;
			$row->link = $newslink;
			$row->uname = fetchusername($row->uid);
			$row->ctime = mygmt($row->time_start);
			$row->text = eregi_replace("\[SCREEN:([a-zA-Z0-9\\\/\_\.\]*)\]", "", $row->text);
			$row->text = eregi_replace("\[--NEU--\]", "", $row->text);
			$row->text = strip_tags($row->text, "<br />,<strong>,<em>,<b>,<i>,<a>,<img>");
			$row->comments = $comments;
			$row->commtext = ($comments > 1) ? $lang['comments'] : $lang['comment'];
			if($q){
				$row->text = eregi_replace("(".quotemeta($q).")", "<span class=\"highlight\">\\1</span>", $row->text);
			}
			$all_news[$year][$week][$dow][] = $row;
			
			$i++;
		}
	}
	
	
	$tmpl->assign("datum", $datum);
	$tmpl->assign("curr_year", date("Y")+1);
	$tmpl->assign("all_news", $all_news);
}

if($num > $limit) { $donav = 1; }
$tmpl->assign("categ", $_GET['categ']);
$tmpl->assign("pps", $pps);
$tmpl->assign("pps_sel", $pps_sel);
$tmpl->assign("charactersmore_text", $lang['charactersmore']);
$tmpl->assign("num_topnews", $num_topnews);
$tmpl->assign("num_news", $num_news);
$tmpl->assign("donav", $donav);
$tmpl->assign("lang", $lang);
$tmpl->assign('topnews_array', $topnews_array);
$tmpl->assign('news_array', $news_array);
$tmpl->assign('pps_array', $pps_array);
$tmpl->assign('categ_array', $categ_array);
$tmpl->assign('area', $area);
$tmpl->assign('printlink', redir()."&amp;print=1");
$tmpl->register_function('printpanel', 'printpanel');

// WENN USER NICHT ANGEMELDET IST, LOGINBOX ANZEIGEN
if ($islogged == 1) {
	$tmpl->assign("login", 1);
	$tmpl->assign("name", $BENUTZER);
	} else {
	$tmpl->assign("login", 0);
	$tmpl->assign("gast", $GROUPSINGLE);
}

// BERECHTIGUNG FÜR PN UND ADMINLINK
if (permission("canpn")) { $tmpl->assign('pn', 1); } else { $tmpl->assign('pn', 0); }
if(permission("adminpanel")){ $tmpl->assign('adminlink', 1);}
$tmpl->assign('redir', redir());

$dropdown = array();
getNews(0, "", $dropdown, $area);
$tmpl->assign("dropdown", $dropdown);

// <<-- NAVIGATION ERZEUGEN -->>
$tmpl->assign('pages', pagenav($seiten, $lang['aktpos'], " <a class=\"page_navigation\" href=\"index.php?p=index&amp;area=".$area."&amp;categ=".$_REQUEST['categ']."&amp;ud=".$_REQUEST['ud']."&amp;selby=".$_REQUEST['selby']."&amp;show=".$_REQUEST['show']."$sp&amp;pp=".$limit."&amp;page={s}&amp;start=".$show_start."&amp;end=".$show_end."\">{t}</a> "));

// <<-- AUSGABE -->>
$tmpl->assign("content", $tmpl->fetch('start/startpage.tpl'));
?>