<?php
exit('Feed no longer available');
header("Content-type: application/xml");

$dives = array();

$howmany = 25;
$pageSQL = "";
$titleUser = "";

if ($_GET['n'] AND intval($_GET['n']) <= 100) $howmany = intval($_GET['n']);
if ($_GET['p'])
{
	$page = intval($_GET['p'])-1;
	$starting = intval($page)*intval($howmany);
	if ($page > 0) $pageSQL = " $starting, ";
}

$whichuserSQL = "";
if ($_GET['u'] AND strlen($_GET['u']) <= 20)
{
 $whichuserSQL = " AND users.user = '".addslashes($_GET['u'])."'";
 $titleUser = "von ".$_GET['u'];
}

include("divelogs_functions.inc.php");
$db = opendb();
$query = mysqli_query($db,"SELECT tgs.id, tgs.ort, tgs.tplatz, tgs.user, tgs.maxt, DATE_FORMAT(tgs.eingestellt,'%d.%m.%y'), DATE_FORMAT(tgs.eingestellt,'%a, %d %b %Y %H:%m:%s +0100'), DATE_FORMAT(tgs.datum,'%d.%m.%y'), DATE_FORMAT(tgs.uhrzeit, '%H:%m') FROM tgs"
." INNER JOIN users ON tgs.user = users.user"
." WHERE users.privat = 0"
." $whichuserSQL"
." ORDER BY DATE_FORMAT(eingestellt,'%y%m%d') DESC, datum DESC, Uhrzeit DESC LIMIT $pageSQL $howmany ");

while ($row = mysqli_fetch_row($query))
{
 $wann = $row[5];
 $wanntg = $row[7]." um ".$row[8]." Uhr";

 $ort = $row[1];
 if ($ort=="") $ort = "Unbekannter Ort";
 
 $tplatz = $row[2];
 if ($tplatz=="") $tplatz = "Unbekannter Tauchplatz";
 
 $user = $row[3];

 $maxt = $row[4];
 
 $guid = $row[0];
 
 
$dives [] = array(
'title' => ("(".$wann.") ".($ort).", ".($tplatz)." (".$maxt."m)"),
'description' => ('Neuer eingestellter Tauchgang von '.$user."<br>Datum: ".$wanntg."<br>Eingestellt am ".$wann."<br>Ort: ".($ort)."<br>Tauchplatz: ".($tplatz)."<br>Tiefe: ".$maxt." meter"),
'link' => "http://www.divelogs.de/tg.php?id=".$row[0],
'author' => (($row[3])),
'pubDate' => $row[6], 'guid' => "http://www.divelogs.de/tg.php?id=".$row[0]
);



}

closedb($db);



$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;

$rss = $doc->createElement("rss");
$r = $doc->appendChild($rss);
$r->setAttribute("version", "2.0");

$chan = $doc->createElement("channel");
$rss->appendChild($chan);

$title = $doc->createElement("title",("Divelogs.de $howmany neuste Einträge $titleUser"));
$chan->appendChild($title);

$link = $doc->createElement("link","http://www.divelogs.de");
$chan->appendChild($link);

$desc = $doc->createElement("description","Kostenlose online Divelogs");
$chan->appendChild($desc);

$lang = $doc->createElement("language","de-de");
$chan->appendChild($lang);

$copy = $doc->createElement("copyright","Rainer Mohr, www.klemmkeil.de");
$chan->appendChild($copy);

$pubd = $doc->createElement("pubDate",date("D").", ".date("d")." ".date("M")." ".date("Y")." ".date("H").":".date("i").":".date("s")." +0100");
$chan->appendChild($pubd);

$img = $doc->createElement("image");
$chan->appendChild($img);


$imgurl = $doc->createElement("url","http://www.divelogs.de/img/shot_small.png");
$img->appendChild($imgurl);

$imgtitle = $doc->createElement("title","Divelogs.de");
$img->appendChild($imgtitle);

$imglink = $doc->createElement("link","http://www.divelogs.de");
$img->appendChild($imglink);

foreach( $dives as $dive )
{
$b = $doc->createElement( "item" );

    $title = $doc->createElement( "title" );
    $title->appendChild(    $doc->createTextNode( $dive['title'] )    );
    $b->appendChild( $title );

    $description = $doc->createElement( "description" );
    $description->appendChild(    $doc->createTextNode( $dive['description'] )    );
    $b->appendChild( $description );

    $link = $doc->createElement( "link" );
    $link->appendChild(    $doc->createTextNode( $dive['link'] )    );
    $b->appendChild( $link );

    $author = $doc->createElement( "author" );
    $author->appendChild(    $doc->createTextNode( "NO-REPLY@divelogs.de (".$dive['author'].")" )    );
    $b->appendChild( $author );

    $when = $doc->createElement( "pubDate" );
    $when->appendChild(    $doc->createTextNode( $dive['pubDate'] )    );
    $b->appendChild( $when );
	
	$guid = $doc->createElement( "guid" );
    $guid->appendChild(    $doc->createTextNode( $dive['guid'] )    );
    $b->appendChild( $guid );

$chan->appendChild( $b );
}


echo $doc->saveXML();


?>
