<?php
error_reporting(E_ERROR);

//////////////////////////////////////////////////////////////////////////////////
// Kreative News
// Designed and Built by: Ben Kuskopf
// Copyright Kreative Studios 2002-2003
// You can modify the script files as much as you like
// How ever the copyright and powered by notice must appear on pages using knews.
// Last Modified: Marth 25th 2003
// To Do: Nothing at the moment
/////////////////////////////////////////////////////////////////////////////////
/* ------------------------------------- */


function printerror($error){
	$perror = "<html>
		<head>
		<title>.:: Kreative News ::.</title>
		<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
		<link href=\"template.css\" rel=\"stylesheet\" type=\"text/css\">
		<SCRIPT LANGUAGE=\"JavaScript\">
		<!-- Begin
		function popuphelp(url,size) {
		ElementWindow = window.open(url,'knews',size)
	}
	// End -->
	</SCRIPT>
		
		
		</head>
		
		<body bgcolor=\"e4eaed\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">
		<div align=\"center\">
		<table width=\"770\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">
		<tr>
		<td width=\"764\">
		<img src=\"kreative.gif\" border=\"0\" width=\"296\" height=\"64\">
		</td>
		</tr>
		
		<tr>
		<td width=\"100%\" valign=\"top\">
		
		<!-- Start Nav Bar-->
		
		<!-- General Section -->
		
		<!-- End General Section -->
		
		<table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"006699\" height=\"100%\">
		<tr >
		<td valign=\"top\" >
		<table width=\"100%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\" bgcolor=\"FFFFFF\" height=\"100%\" style=\"border-collapse: collapse\" bordercolor=\"#111111\">
		<tr >
		<td valign=\"top\">
		<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\">
		
		<tr>
		<td width=\"100%\">
		";
		
		if ($error == "connection"){
			
			$perror .="<b><font color=red><img src=images/error.gif>&nbsp;&nbsp;Error, couldn't connect to the server or database.</b></font><br>
				There was an error communicating with the database or mysql server.";
				
		}
		
		$perror .="
			</td>
			
			</tr>
			</table><bR>
			</td>
			</tr>
			</table>
			</td>
			</tr>
			</table>
			
			</td>
			
			</tr>
			
			</table>
			</div>
			</body>
			</html>";
			
			return $perror;
}
$error = printerror('connection');
$dbl = @mysql_pconnect($hn,$un,$pw)    
or die ($error."\n");

mysql_select_db($db);

$sqlnv = mysql_query("SELECT * FROM " . $tprefix . "settings WHERE setname='abpath'");
		if ($sqlnv)
		{
  			while($row = mysql_fetch_array($sqlnv))
  			{
			$abpath = $row['setvalue'];	
			}
		}
require $abpath . "/functions.php";
require $abpath . "/wordlets.php";
$distype = (isset($_GET['Display']) ? $_GET['Display'] : 'News');
$limit = (isset($_GET['Limit']) ? $_GET['Limit'] : 'None');
$temp = (isset($_GET['Template']) ? $_GET['Template'] : 'Normal');
$category = (isset($_GET['Keyword']) ? $_GET['Keyword'] : 'None');
$show = (isset($_GET['Show']) ? $_GET['Show'] : 'None');
$Step = (isset($_GET['Action']) ? $_GET['Action'] : 'None');
$Mesg = (isset($_GET['Mesg']) ? $_GET['Mesg'] : 'None');
$yearp = (isset($_GET['yearp']) ? $_GET['yearp'] : '0');
$monthp = (isset($_GET['monthp']) ? $_GET['monthp'] : '0');
$whatcat = null;		

$newsheader = knews_sql_fetch_field("SELECT * FROM " . $tprefix . "templates WHERE tempname='newshead'",'template');
$newsfooter = knews_sql_fetch_field("SELECT * FROM " . $tprefix . "templates WHERE tempname='newsfoot'",'template');

if ($sqlab = mysql_query_e("SELECT * FROM " . $tprefix . "settings")){
 while($row = mysql_fetch_array($sqlab)) {
  $$row['setname'] = $row['setvalue'];
 }
}

if ($limit == "None") {
 $limit = knews_sql_fetch_field("SELECT * FROM " . $tprefix . "settings WHERE setname='limit'",'setvalue');
}

// Do output
if ($Step == "None"){
// Get Template
$sqldt = mysql_query_e("SELECT * FROM " . $tprefix . "templates WHERE tempname='newshead'");
				if ($sqldt)
				{
					while($row = mysql_fetch_array($sqldt))
					{
					$newsheader = $row['template'];	
					}
				}
	// Print news display header
ob_start(); eval('?>' . $newsheader); $newsheader = ob_get_contents(); ob_end_clean();
	echo $newsheader;
	
	
$finalcoms = getthenews($distype,$temp,$category,$limit,$tprefix,$show,$monthp,$yearp,$whatcat);

ob_start(); eval('?>' . $finalcoms); $finalcoms = ob_get_contents(); ob_end_clean();

if ($finalcoms == ""){
echo "<b>No news Submitted yet!</b><Br><BR>";
}

if ($Mesg == "invalidemail") {
  echo $wordlets['invalidemail'];
 }
 elseif ($Mesg == "letterdel") {
  echo $wordlets['listremoval'];
 }
 elseif ($Mesg == "letteradd") {
  echo $wordlets['listadded'];
 }
 elseif ($Mesg == "emailexist") {
  echo $wordlets['emailexist'];
 }

echo $finalcoms;

if ($distype == "Search"){

$getthese = null;
		$numresults=mysql_query_e("SELECT * FROM " . $tprefix . "newsfields WHERE search='yes'");
		$sfields=mysql_num_rows($numresults);
		$snum = 0;
		
		$sqlgci = mysql_query_e("SELECT * FROM " . $tprefix . "newsfields WHERE search='yes'");
		if ($sqlgci)
		{
			while($row = mysql_fetch_array($sqlgci))
			{
				$snum++;
				if ($sfields == 1 OR $snum == 1){
					$getthese = $row['intname'] . " LIKE '%" . $category . "%' ";
				}else{
					$getthese .= "OR " . $row['intname'] . " LIKE '%" . $category . "%' ";
				}	
			}
		}



$numresults=mysql_query_e("SELECT * FROM " . $tprefix . "news WHERE " . $getthese ." AND status='public' ORDER by sticky DESC, id DESC");
$sresults=mysql_num_rows($numresults);
}
	
	$sqldt = mysql_query_e("SELECT * FROM " . $tprefix . "templates WHERE tempname='newsfoot'");
				if ($sqldt)
				{
					while($row = mysql_fetch_array($sqldt))
					{
					$newsfooter = $row['template'];	
					}
				}
$newsfooter = str_replace('%', '$', $newsfooter);
				
ob_start();
eval('?>' . $newsfooter); 
$footer = ob_get_contents();
ob_end_clean();


	// Print news display header
	if ($distype == "Search"){
	if ($category == ""){
	$category = "*";
	}
	print("<hr><b>$sresults</b> search result(s) found for the word <b>$category</b>.<br><BR>");
	}
	echo $powertext;
   echo $footer;



}elseif ($Step == "Oldnews"){
// News archive
if (isset($_GET['Offset'])) $offset = $_GET['Offset']; else $offset = $limit;

$sqldt = mysql_query_e("SELECT * FROM " . $tprefix . "templates WHERE tempname='newshead'");
				if ($sqldt)
				{
					while($row = mysql_fetch_array($sqldt))
					{
					$newsheader = $row['template'];	
					}
				}
$newsheader = str_replace('%', '$', $newsheader);				
ob_start(); eval('?>' . $newsheader); $newsheader = ob_get_contents(); ob_end_clean();
	echo $newsheader;
$cyear = null;
 $cmonth = null;


	$sqldt = mysql_query_e("SELECT * FROM " . $tprefix . "news WHERE status='public' ORDER BY YearP DESC, MonthP ASC");
				if ($sqldt)
				{
					while($row = mysql_fetch_array($sqldt))
					{
					if ($row['YearP'] == $cyear && $row['MonthP'] == $cmonth){
					// Nothing
					}else{
					$sqlga = mysql_query_e("SELECT * FROM " . $tprefix . "templates WHERE tempname='archive'");
				if ($sqlga)
				{
					while($row2 = mysql_fetch_array($sqlga))
					{
					$arctemp = $row2['template'];	
					}
				}
					$MonthP =  $row['MonthP'];
					$YearP = $row['YearP'];
					
					$cyear = $row['YearP'];
					$cmonth = $row['MonthP'];
$arctemp = addslashes($arctemp); 
eval("\$arctemp = \"$arctemp\";"); 
$arctemp = stripslashes($arctemp); 
			ob_start(); eval('?>' . $arctemp); $arctemp = ob_get_contents(); ob_end_clean();
			echo $arctemp;
					}
						
					}
				}
				
	$sqldt = mysql_query_e("SELECT * FROM " . $tprefix . "templates WHERE tempname='newsfoot'");
				if ($sqldt)
				{
					while($row = mysql_fetch_array($sqldt))
					{
					$newsfooter = $row['template'];	
					}
				}
		
$newsfooter = str_replace('%', '$', $newsfooter);
ob_start(); eval('?>' . $newsfooter); $newsfooter = ob_get_contents(); ob_end_clean();

echo $powertext;
	echo $newsfooter;

}

mysql_close();
?>