<?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 Downloads
{
	var $_allowed_html = '<br /><br>';
	
	function Settings()
	{
		$res = $GLOBALS['db']->RowQuery("SELECT * FROM " . PREFIX . "_downloads_einstellungen");
		$GLOBALS['Downloadssettings'] = $res;
		$GLOBALS['tmpl']->assign('Downloadssettings', $GLOBALS['Downloadssettings']);
	}
	
	function SearchDownloads()
	{
		$LC = $_SESSION['Langcode'];
		$Search = preg_replace('/([^-A-Za-zÀ-ÖØ-öø-ÿ0-9_)( ]*)/', '', @$_REQUEST['ql']);
		$Search2 = koobispecialchars($Search);
		$_REQUEST['ql'] = $Search;
		
		if(strlen($Search) < 3) 
		{
			$Search = '';
			$Search2 = '';
		}
		
		$entries = array();
		
		$check = $GLOBALS['db']->RowQuery("SELECT 
			COUNT(Id) AS ResCount 
		FROM 
			" . PREFIX . "_downloads 
		WHERE 
			Aktiv='1' 
		AND
			((Name_{$LC} LIKE '%{$Search}%' OR Beschreibung_{$LC} LIKE '%{$Search}%') OR 
			(Name_{$LC} LIKE '%{$Search2}%' OR Beschreibung_{$LC} LIKE '%{$Search2}%'))
		AND 
			Sektion = '" . AREA . "' 
		ORDER BY Name_{$LC} ASC");
		
		$num = $check->ResCount;
		$limit = GetLim(15);
		$seiten = ceil($num / $limit);
		$a = prepage() * $limit - $limit;
			
		// Such-Abfrage
		$query_items = $GLOBALS['db']->Query("SELECT 
			*,
			Kategorie, 
			Name_{$LC} AS Name,
			Beschreibung_{$LC} AS Beschreibung 
		FROM 
			" . PREFIX . "_downloads 
		WHERE 
			Aktiv='1' 
		AND
			((Name_{$LC} LIKE '%{$Search}%' OR Beschreibung_{$LC} LIKE '%{$Search}%') OR 
			(Name_{$LC} LIKE '%{$Search2}%' OR Beschreibung_{$LC} LIKE '%{$Search2}%'))
		AND 
			Sektion = '" . AREA . "'  
		ORDER BY Name_{$LC} ASC LIMIT $a,$limit");
		
		
		
		while($row_items = $query_items->fetchrow())
		{
			// Wertung
			if($GLOBALS['Downloadssettings']->Wertung==1)
			{
				$row_items->Wertung = getRating($row_items->Id,'downloads');
			}
			
			$res_name = $GLOBALS['db']->RowQuery("SELECT  Name_{$LC} AS Name FROM " . PREFIX . "_downloads_kategorie WHERE Id='$row_items->Kategorie'");
			$row_items->KategName = $res_name->Name;
			$row_items->Link_Categ   = "index.php?p=downloads&amp;area=" . AREA . "&amp;categ=" . $row_items->Kategorie . "&amp;name=" . seotitle($row_items->KategName);
			$row_items->CCount = getPageCommentCount($row_items->Id,'downloads');
			$row_items->Beschreibung  = (strlen($Search) >= 3) ? high(strip_tags($row_items->Beschreibung,'<span>'),$_REQUEST['ql']) : strip_tags($row_items->Beschreibung,$this->_allowed_html);
			$row_items->Beschreibung  = (strlen($Search) >= 3) ? $row_items->Beschreibung = high(strip_tags($row_items->Beschreibung,'<span>'),$Search2) : strip_tags($row_items->Beschreibung,$this->_allowed_html);
			$row_items->Link_Details = "index.php?p=downloads&amp;action=showdetails&amp;area=" . AREA . "&amp;categ=" . $row_items->Kategorie . "&amp;id=" . $row_items->Id . "&amp;name=" . seotitle($row_items->Name);
			array_push($entries, $row_items);
			
		}
		
		// Seiten-Navigation
		$headernav = '<a href="index.php?p=downloads&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Downloads'] . '</a> ';
		
		// Navi
		if($num>$limit)
		{
			$Search = ($Search=='') ? '-' : $Search;
			$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, "", "<a class=\"page_navigation\" href=\"index.php?ql=" . urlencode($Search) . "&amp;action=search&amp;p=downloads&amp;area=".AREA."&amp;page={s}\">{t}</a> "));
		}
			
		$GLOBALS['tmpl']->assign('Entries', $entries);
		$GLOBALS['tmpl']->assign('pagetitle_html', clean_page_title($headernav));
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('Results', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/entries.tpl')); 
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/search_result.tpl')); 
	}
	
	function showDetails($id)
	{

		$LC = $_SESSION['Langcode'];
		$res = $GLOBALS['db']->RowQuery("SELECT *,Kategorie, Name_{$LC} AS Name,Beschreibung_{$LC} AS Beschreibung FROM " . PREFIX . "_downloads WHERE Id='$id' AND Aktiv='1'");
		if(!is_object($res))
		{
			refer('index.php?p=downloads&area=1');
		}
		
		$headernav = '<a href="index.php?p=downloads&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Downloads'] . '</a>' . getNavigationPath($res->Kategorie, 'downloads_kategorie', 'downloads&amp;area=' . AREA, 'categ', 'Id', 'Name_' . $_SESSION['Langcode'], '', '', '', '', 'Parent_Id')  ;
		
		$res->UserName = fetchusername($res->Autor);
			
		//=================================================================
		// Kommentare
		//=================================================================
		if($GLOBALS['Downloadssettings']->Kommentare == 1)
		{
			$comment = new Comments;
			// Kommentar bearbeiten
			if(isset($_POST['comment_action']) && $_POST['comment_action'] == 'edit' && permission('edit_comments')) $comment->EditComment('downloads',$_POST['comment_id']);
			
			// Neuer Kommentar
			if(permission('comments'))
			{
				$comment->NewComment('downloads', @$_POST['Redir'],$id);
			}
			
			// Kommentare holen
			$Comments = $comment->GetComments('downloads',$id,'index.php?p=downloads&amp;action=showdetails&amp;categ=' . $res->Kategorie . '&amp;id=' . $id . '&amp;name=' . seotitle($res->Name));
			$GLOBALS['tmpl']->assign('GetComments',$GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/comments/comments.tpl'));
		}
		
		// Wertung
		if($GLOBALS['Downloadssettings']->Wertung==1)
		{
			$GLOBALS['tmpl']->assign('RatingUrl', 'index.php?p=rating&action=rate&id=' . $id. '&where=downloads');
			$GLOBALS['tmpl']->assign('RatingForm', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/other/rating.tpl')); 
		}
		
		// Seiten-Info
		setMeta($GLOBALS['config_vars']['Downloads'],$res->Beschreibung);
		$res->Beschreibung = autowords($res->Beschreibung);
		$res->Wertung = getRating($res->Id,'downloads');
		
		// Mirrors
		if($res->Mirrors!='')
		{
			$alternatives = array();
			$mirrors = explode("\r\n", $res->Mirrors);
			$i=1;
			foreach($mirrors as $m)
			{
				$mi = '';
				$det = explode(";",$m);
				$mi->Id = $i++;
				$mi->Link = $det[0];
				$mi->Name = $det[1];
				array_push($alternatives, $mi);
			}
			$GLOBALS['tmpl']->assign('alternatives', $alternatives);
		}
		
		//file_size($param)
		if($res->Url_Direct=='')
		{
			$res->Traffic = @file_size(@filesize(BASE_DIR . "/uploads/downloads_files/" . $res->Url)*$res->Hits/1024);
			$res->Size = @file_size(@filesize(BASE_DIR . "/uploads/downloads_files/" . $res->Url)/1024);
		} else {
			$res->Traffic = @file_size($res->Size_Direct*$res->Hits*1024);
			$res->Size = @file_size($res->Size_Direct*1024);
		}
		
			
		$GLOBALS['tmpl']->assign('BrokenLinkSubmit', 'index.php?action=brokenlink&p=downloads&id=' . $id);
		$GLOBALS['tmpl']->assign('link_res', $res);
		$GLOBALS['tmpl']->assign('pagetitle_html', clean_page_title($headernav) . $GLOBALS['config_vars']['PageSep'] . koobispecialchars($res->Name));
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/showdownload.tpl')); 
	}
	
	//=================================================================
	// Download-Kategorien und Downloads anzeigen
	//=================================================================
	function displayCategs()
	{
		$LC = $_SESSION['Langcode'];
		$id = 0;
		$getid = (isset($_REQUEST['categ']) && !empty($_REQUEST['categ'])) ? abs((int)$_REQUEST['categ']) : 0 ;
		
		
		switch(@$_REQUEST['sort'])
		{
			case '':
			default:
			case 'datedesc':
				$req = 'datedesc';
				$defsort = "ORDER BY Sponsor DESC, Datum DESC";
				$defsort_n = "&amp;sort=datedesc";
				$GLOBALS['tmpl']->assign('img_date', 'sorter_down');
				$GLOBALS['tmpl']->assign('datesort', 'dateasc');
			break;
			
			case 'dateasc':
				$req = 'dateasc';
				$defsort = "ORDER BY Sponsor DESC, Datum ASC";
				$defsort_n = "&amp;sort=dateasc";
				$GLOBALS['tmpl']->assign('img_date', 'sorter_up');
				$GLOBALS['tmpl']->assign('datesort', 'datedesc');
			break;
			
			case 'namedesc':
				$req = 'namedesc';
				$defsort = "ORDER BY Sponsor DESC, Name_{$LC} DESC";
				$defsort_n = "&amp;sort=namedesc";
				$GLOBALS['tmpl']->assign('img_name', 'sorter_down');
				$GLOBALS['tmpl']->assign('namesort', 'nameasc');
			break;
			
			case 'nameasc':
				$req = 'nameasc';
				$defsort = "ORDER BY Sponsor DESC, Name_{$LC} ASC";
				$defsort_n = "&amp;sort=nameasc";
				$GLOBALS['tmpl']->assign('img_name', 'sorter_up');
				$GLOBALS['tmpl']->assign('namesort', 'namedesc');
			break;
			
			
			case 'hitsdesc':
				$req = 'hitsdesc';
				$defsort = "ORDER BY Sponsor DESC, Hits DESC";
				$defsort_n = "&amp;sort=hitsdesc";
				$GLOBALS['tmpl']->assign('img_hits', 'sorter_down');
				$GLOBALS['tmpl']->assign('hitssort', 'hitsasc');
			break;
			
			case 'hitsasc':
				$req = 'hitsasc';
				$defsort = "ORDER BY Sponsor DESC, Hits ASC";
				$defsort_n = "&amp;sort=hitsasc";
				$GLOBALS['tmpl']->assign('img_hits', 'sorter_up');
				$GLOBALS['tmpl']->assign('hitssort', 'hitsdesc');
			break;
		}
		
		$_REQUEST['sort'] = $req;
		
		$prefix = '';
		$news_categ = '';
		$area = AREA;
		$news_categ = array();
		
		$Categs = $this->ListCategs($getid, $prefix, $news_categ, $area);
		
		if(isset($_REQUEST['categ']) && !empty($_REQUEST['categ']))
		{
			// Eintraege
			$entries = array();
			$cid = abs((int)$_REQUEST['categ']);
			$items = array();
			
			$res_name = $GLOBALS['db']->RowQuery("SELECT  Name_{$LC} AS Name FROM " . PREFIX . "_downloads_kategorie WHERE Id='$getid'");
			
			$res = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS Gesamt FROM " . PREFIX . "_downloads WHERE Kategorie='$cid' AND Aktiv='1' {$defsort}");
			$num = $res->Gesamt;
			$limit = GetLim(15);
			$seiten = ceil($num / $limit);
			$a = prepage() * $limit - $limit;
			
			$query_items = $GLOBALS['db']->Query("SELECT *,Kategorie, Name_{$LC} AS Name,Beschreibung_{$LC} AS Beschreibung FROM " . PREFIX . "_downloads WHERE Kategorie='$cid' AND Aktiv='1' {$defsort} LIMIT $a,$limit");
			
			while($row_items = $query_items->fetchrow())
			{
				// Wertung
				if($GLOBALS['Downloadssettings']->Wertung==1)
				{
					$row_items->Wertung = getRating($row_items->Id,'downloads');
				}
				
				$row_items->CCount = getPageCommentCount($row_items->Id,'downloads');
				$row_items->KategName = $res_name->Name;
				$row_items->Beschreibung = strip_tags($row_items->Beschreibung,$this->_allowed_html);
				$row_items->Link_Details = "index.php?p=downloads&amp;action=showdetails&amp;area=" . AREA . "&amp;categ=" . $getid . "&amp;id=" . $row_items->Id . "&amp;name=" . seotitle($row_items->Name);
				array_push($entries, $row_items);
			}
			
			// Navi
			if($num>$limit)
			{
				$GLOBALS['tmpl']->assign('Navi', pagenav($seiten, "", "<a class=\"page_navigation\" href=\"index.php?p=downloads&amp;area=".AREA."&amp;categ=".$getid."&amp;name=".seotitle($res_name->Name)."&amp;page={s}{$defsort_n}\">{t}</a> "));
			}
			
			// Uebergeben
			$GLOBALS['tmpl']->assign('Entries',$entries);
		}
		
		// Seiten-Navigation
		
		$headernav = '<a href="index.php?p=downloads&amp;area=' . AREA . '">' . $GLOBALS['config_vars']['Downloads'] . '</a>' . getNavigationPath($getid, 'downloads_kategorie', 'downloads&amp;area=' . AREA, 'categ', 'Id', 'Name_' . $_SESSION['Langcode'], '', '', '', '', 'Parent_Id');
		
		// Seiten-Info
		$hinf = clean_page_title($headernav);
		setMeta($GLOBALS['config_vars']['Downloads'],$hinf);
		
		if(!isset($_REQUEST['categ'])) $GLOBALS['tmpl']->assign('Entries', $this->newEntries());
		$GLOBALS['tmpl']->assign('pagetitle_html', $hinf);
		$GLOBALS['tmpl']->assign('headernav', $headernav);
		$GLOBALS['tmpl']->assign('Categs',$Categs);
		$GLOBALS['tmpl']->assign('CategName',@seotitle($res_name->Name));
		$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/showcategs.tpl')); 
	}
	
	//=================================================================
	// Neueste
	//=================================================================
	function newEntries($search='',$limit=10,$ext='')
	{
		$LC = $_SESSION['Langcode'];
		$entries = array();
		$query_items = $GLOBALS['db']->Query("SELECT *, Kategorie, Name_{$LC} AS Name,Beschreibung_{$LC} AS Beschreibung FROM " . PREFIX . "_downloads WHERE Sektion='" . AREA . "' AND Aktiv='1' ORDER BY Id DESC LIMIT {$limit}");
		while($row_items = $query_items->fetchrow())
		{
			$res_name = $GLOBALS['db']->RowQuery("SELECT  Name_{$LC} AS Name FROM " . PREFIX . "_downloads_kategorie WHERE Id='$row_items->Kategorie'");
			
			// Wertung
			if($GLOBALS['Downloadssettings']->Wertung==1)
			{
				$row_items->Wertung = getRating($row_items->Id,'downloads');
			}
			
			if($ext==1) $this->_allowed_html = '';
			$row_items->CCount = getPageCommentCount($row_items->Id,'downloads');
			$row_items->KategName = $res_name->Name;
			$row_items->Beschreibung = strip_tags($row_items->Beschreibung,$this->_allowed_html);
			$row_items->Link_Categ   = "index.php?p=downloads&amp;area=" . AREA . "&amp;categ=" . $row_items->Kategorie . "&amp;name=" . seotitle($row_items->KategName);
			$row_items->Link_Details = "index.php?p=downloads&amp;action=showdetails&amp;area=" . AREA . "&amp;categ=" . $row_items->Kategorie . "&amp;id=" . $row_items->Id . "&amp;name=" . seotitle($row_items->Name);
			array_push($entries, $row_items);
		}
		return $entries;
	}
	
	//=================================================================
	// Kategorien fuer Seite holen
	//=================================================================
	function ListCategs($id, $prefix, &$news_categ, &$area)
	{
		$LC = $_SESSION['Langcode'];
		$query = $GLOBALS['db']->Query("SELECT Id, Parent_Id, Beschreibung_{$LC} AS Beschreibung, Name_{$LC} AS Name FROM " . PREFIX . "_downloads_kategorie WHERE Parent_Id = '$id' AND Sektion = '$area' ORDER BY Name ASC");
		if (!$query->numrows()) 
		{
			return;
		} 
		
		while ($item = $query->fetchrow())
		{
			$res = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS LinkCount FROM " . PREFIX . "_downloads WHERE Kategorie='$item->Id' AND Aktiv='1'");
			$item->visible_title = $prefix . " " . $item->Name;
			$item->HLink = "index.php?p=downloads&amp;area=" . AREA . "&amp;categ=$item->Id&amp;name=" . seotitle($item->Name);
			$item->LinkCount = ($res->LinkCount + @$this->ReadLinkCount($item->Id));
			
			array_push($news_categ, $item);
		} 
		return $news_categ;
	}
	
	
	//=================================================================
	// Kategorien fuer Dropdown holen
	//=================================================================
	function ListCategsSimple($id, $prefix, &$news_categ, &$area)
	{
		$LC = $_SESSION['Langcode'];
		$query = $GLOBALS['db']->Query("SELECT Id, Parent_Id, Beschreibung_{$LC} AS Beschreibung, Name_{$LC} AS Name FROM " . PREFIX . "_downloads_kategorie WHERE Parent_Id = '$id' AND Sektion = '$area' ORDER BY Name ASC");
		if (!$query->numrows()) 
		{
			return;
		} 
		
		while ($item = $query->fetchrow())
		{
			$res = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS LinkCount FROM " . PREFIX . "_downloads WHERE Kategorie='$item->Id' AND Aktiv='1'");
			$item->visible_title = $prefix . " " . $item->Name;
			$item->HLink = "index.php?p=downloads&amp;area=" . AREA . "&amp;categ=$item->Id&amp;name=" . seotitle($item->Name);
			$item->LinkCount = ($res->LinkCount + @$this->ReadLinkCount($item->Id));
			array_push($news_categ, $item);
		} 
		return $news_categ;
	}
	
	//=================================================================
	// Zaehlfunktion
	// Zaehlt, wie viele Links sich in einer Kategorie befinden (rekursiv)
	//=================================================================
	function ReadLinkCount($categ, &$count)
	{
		$query = $GLOBALS['db']->Query("SELECT Id,Parent_Id FROM " . PREFIX . "_downloads_kategorie WHERE Parent_Id='$categ'");
		if (!$query->numrows()) 
		{
			return 0;
		}
	
		while ($item = $query->fetchrow())
		{
			$res = $GLOBALS['db']->RowQuery("SELECT COUNT(Id) AS LinkCount FROM " . PREFIX . "_downloads WHERE Kategorie='$item->Id' AND Aktiv='1'");
			$count += ($res->LinkCount);
			$this->ReadLinkCount($item->Id,$count);
			
		}
		return $count;
	}
	
	function GetFile($id)
	{
		if(strpos(@$_SERVER['HTTP_REFERER'], HOME_PATH)!==false && permission('downloads_candownload'))
		{
			$res = $GLOBALS['db']->RowQuery("SELECT Url FROM " . PREFIX . "_downloads WHERE Id='$id' AND Aktiv='1'");
			if(!is_object($res) || !@file_exists(BASE_DIR . '/uploads/downloads_files/' . $res->Url))
			{
				
				$GLOBALS['tmpl']->assign('jumpback', @$_SERVER['HTTP_REFERER']);
				$GLOBALS['tmpl']->assign('content', $GLOBALS['tmpl']->fetch($GLOBALS['config']['source'] . '/downloads/notfound.tpl')); 
			} else {
				$GLOBALS['db']->Query("UPDATE " . PREFIX . "_downloads SET Hits=Hits+1 WHERE Id='$id' AND Aktiv='1'");
				ob_start();
				header("Cache-control: private");
				header("Content-type: application/octet-stream"); 
				header("Content-disposition:attachment; filename=" . $res->Url);
				@$this->DL_ReadFile(BASE_DIR . '/uploads/downloads_files/' . $res->Url);
				exit;
			}
		} else {
			refer('index.php?p=downloads&area=' . AREA);
		}
	}
	
	
	function DL_ReadFile($filename,$retbytes=true)
	{
		$chunksize = 1*(1024*1024); 
		$buffer = '';
		$cnt =0;
		
		$handle = fopen($filename, 'rb');
		if ($handle === false)
		{
		   return false;
		}
		while (!feof($handle))
		{
		   $buffer = fread($handle, $chunksize);
		   echo $buffer;
		   flush();
		   if ($retbytes) {
			   $cnt += strlen($buffer);
		   }
		}
		   $status = fclose($handle);
		if ($retbytes && $status)
		{
		   return $cnt; 
		}
		return $status;
	}
	
	//=================================================================
	// Hitcount erhoehen
	//=================================================================
	function Updatehitcount($id)
	{
		// Nur erhoehen, wenn Click von gleicher Seite
		if(strpos(@$_SERVER['HTTP_REFERER'], HOME_PATH)!==false)
		{
			$GLOBALS['db']->Query("UPDATE " . PREFIX . "_downloads Set Hits=Hits+1 WHERE Id='" . abs((int)$id) . "'");
		}
	}
	
	function BrokenLink($id)
	{
		
		$allowed = array('Links_Broken_dnserror',
			'Links_Broken_noconnection',
			'Links_Broken_auth',
			'Links_Broken_notfound',
			'Links_Broken_servererror',
			'Links_Broken_other');
		
		$res = $GLOBALS['db']->RowQuery("SELECT Id,DefektGemeldet FROM " . PREFIX . "_downloads WHERE Id='$id'");
		//
		if(is_object($res) && $res->DefektGemeldet=='' && strpos(@$_SERVER['HTTP_REFERER'], HOME_PATH)!==false && (in_array(@$_REQUEST['BrokenReason'],$allowed)))
		{
			$Reason = $GLOBALS['config_vars'][$_REQUEST['BrokenReason']];
			$Email  = preg_replace('/([^-A-Za-zÀ-ÖØ-öø-ÿ0-9.@]*)/', '', @$_REQUEST['email']);
			$Name = preg_replace('/([^-A-Za-zÀ-ÖØ-öø-ÿ0-9. ]*)/', '', @$_REQUEST['name']);
			$Page = str_replace('&amp;','&',base64_decode(preg_replace('/([^A-Za-zÀ-ÖØ-öø-ÿ0-9]*)/', '', $_REQUEST['dpage'])));
			
			
			$GLOBALS['db']->RowQuery("UPDATE " . PREFIX . "_downloads 
			SET
				DefektGemeldet='$Reason',
				DEmail = '$Email',
				DName = '" . $Name . "',
				DDatum = '" . stime() . "' 
			WHERE Id='$id'");
			
			$Text = str_replace(array('__BENUTZER__','__EMAIL__','__LINK__','__GRUND__'), array($Name,$Email,$Page,$Reason), $GLOBALS['config_vars']['Links_E_BrokenText']);
			$Koobi = new Koobi;
			$Koobi->koobi_mail($GLOBALS['settings']['Mail_Absender'], $Text, $GLOBALS['config_vars']['Links_E_BrokenSubject'], $GLOBALS['settings']['Mail_Absender'], stripslashes($GLOBALS['settings']['Mail_Name']), 'text', '');	
			
			echo $GLOBALS['config_vars']['Links_ErrorSendBrokenOk'];
			exit;
		} else {
			echo $GLOBALS['config_vars']['Links_ErrorSendBrokenAllready'];
			exit;
		}
	}
	
}
?>