<?php
  header("Content-type: text/html; charset=iso-8859-1"); 
  define( '_VALID_MOS', 1 );
  include "../includes/definitions.php";
  include ("../includes/database.php");

  include "../includes/validation.php";
  $db = new database( $host, $user, $passwd, $db_name, '' );
  include "../includes/core.php";
  include "../graphite/content/bio_class.php";
  
  $ID=get_param("bio");
  if ( ($ID)&&(IsValidKey($ID)) )
  { // lade Daten in Objekt
    $data=new KR_bio($db);
    $data->load($ID);
  } else
  { // ID nicht vorhanden - Kategorie übergeben
    echo "Not Found</body>
</html>";
	die();
  }
  
// Prüfe verfügbare Sprachen
if (trim($data->bio_textDE)) $LANG_DE=true; else $LANG_DE=false;
if (trim($data->bio_textEN)) $LANG_EN=true; else $LANG_EN=false;

$LANG_SWITCH="";
if (!isset($lang)) $lang="";
switch ($lang)
{
  case "DE":
  if ($LANG_EN) $LANG_SWITCH="EN";

  break;

  case "EN":
  if ($LANG_DE) $LANG_SWITCH="DE";
  
  break;
  
  default:
    if ($LANG_DE)
	{
	  $lang="DE";
	  if ($LANG_EN) $LANG_SWITCH="EN";
	} else
	{
	  if ($LANG_EN)
	  {
	    $lang="EN";
	    if ($LANG_DE) $LANG_SWITCH="DE";
	  }
	}
  
  break;
} 
// Sprache konnte nicht aufgelöst werden - setzte Defaul 
if ($lang=="") $lang="DE";

// Output Functions ====================================================================

function show_links ($ID, $lang)
{
  $TOPIC["DE"]="Weiterführende Links";
  $TOPIC["EN"]="Related Links";
  global $db;
  if (!$ID) return;
  $query = "SELECT *"
  . "\nFROM bio_n_link"
  . "\nWHERE bnl_bio='".$ID."'"
  . ";";
  
  // echo $query;
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  if (sizeof($rows)) echo "<p><strong>".$TOPIC[$lang].":</strong><br/>";
  foreach ($rows as $out)
  {
    mosMakeHtmlSafe($out);
	echo "<a href=\"".$out->bnl_href."\"";
	if ($out->bnl_extern) echo " target=\"kr_extern\"";
	echo ">";
	if (trim($out->bnl_title)!="") echo $out->bnl_title; else echo $out->bnl_href;
	echo "</a><br />";
  };
  if (sizeof($rows)) echo "</p>";
}

function show_cds ($ID, $lang)
{
  global $db;
  $query = "SELECT cd_jahr, cd_titel, cd_seite"
  . "\nFROM bio_rel_cd"
  . "\nLEFT JOIN cd ON cd_id=bc_cd"
  . "\nWHERE bc_bio='".$ID."'"
  . "\nGROUP BY cd_jahr, cd_titel"
  . ";";
  
  // echo $query;
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  if (sizeof($rows)) echo "<p><strong>Kunstradio CDs:</strong><br/>";
  foreach ($rows as $out)
  {
    mosMakeHtmlSafe($out);
	echo $out->cd_jahr." <a href=\"".$out->cd_seite."\"";
	echo ">";
	echo $out->cd_titel;
	echo "</a><br />";
  };
  if (sizeof($rows)) echo "</p>";
}

function show_projekte ($ID, $lang)
{
  global $db;
  $TOPIC["DE"]="Kunstradio Projekte";
  $TOPIC["EN"]="Kunstradio Projects";
  $query = "SELECT projekt_jahr, projekt_titel, projekt_seite, projekt_beschreibung"
  . "\nFROM bio_rel_projekt"
  . "\nLEFT JOIN projekt ON projekt_id=bp_projekt"
  . "\nWHERE bp_bio='".$ID."'"
  . "\nGROUP BY projekt_jahr, projekt_titel"
  . ";";
  
  // echo $query;
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  if (sizeof($rows)) echo "<p><strong>".$TOPIC[$lang].":</strong><br/>";
  foreach ($rows as $out)
  {
    mosMakeHtmlSafe($out);
	echo $out->projekt_jahr." <a href=\"".$out->projekt_seite."\"";
	echo ">";
	echo $out->projekt_titel;
	echo "</a>";
	if (trim($out->projekt_beschreibung)!="") echo ", ".$out->projekt_beschreibung;
	echo "<br />";
  };
  if (sizeof($rows)) echo "</p>";
}

function show_serien ($ID, $lang)
{
  global $db;
  $TOPIC["DE"]="Kunstradio Serien";
  $TOPIC["EN"]="Kunstradio Series";
  $query = "SELECT serie_jahr, serie_titel, serie_seite, serie_beschreibung"
  . "\nFROM bio_rel_serie"
  . "\nLEFT JOIN serie ON serie_id=bs_serie"
  . "\nWHERE bs_bio='".$ID."'"
  . "\nGROUP BY serie_jahr, serie_titel"
  . ";";
  
  // echo $query;
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  if (sizeof($rows)) echo "<p><strong>".$TOPIC[$lang].":</strong><br/>";
  foreach ($rows as $out)
  {
    mosMakeHtmlSafe($out);
	echo $out->serie_jahr." <a href=\"".$out->serie_seite."\"";
	echo ">";
	echo $out->serie_titel;
	echo "</a>";
	if (trim($out->serie_beschreibung)!="") echo ", ".$out->serie_beschreibung;
	echo "<br />";
  };
  if (sizeof($rows)) echo "</p>";
}

function show_artists ($BEITRAG_ID, $lang, $ID)
{
  global $db;
  $UND["DE"]=" und ";
  $UND["EN"]=" and ";
  $query = "SELECT bb_id, bb_bid, bb_bio, bb_type, bb_funktion, bio_vorname, bio_nachname, bio_show, funktion_DE, funktion_EN, ordering"
  . "\nFROM sendung_beitrag_bio"
  . "\nLEFT JOIN bio ON bio_id=bb_bio"
  . "\nLEFT JOIN funktion ON funktion_id=bb_funktion"
  . "\nWHERE bb_bid='".$BEITRAG_ID."'"
  . "\nORDER BY bb_type, ordering, bio_nachname, bb_funktion"
  . ";";
  
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  $count=0;
  $last_funktion="";
  $mtemp=""; $vonout="";
  foreach ($rows as $out)
  {
	if ($out->bb_type==0)
	{
	  // Show Link for other Biographies
	  if ($out->bb_bio==$ID)
	    $temp=trim($out->bio_vorname." ".$out->bio_nachname);
	  else
	    $temp="<a href=\"artist.php?bio=".$out->bb_bio."\">".trim($out->bio_vorname." ".$out->bio_nachname)."</a>";
	  if ($lang=="DE")
	  {
	    if ($out->funktion_DE) $temp.= " (".$out->funktion_DE.")";
	  }
	  else
	  {
	    if ($out->funktion_EN) $temp.= " (".$out->funktion_EN.")";
	  }
	  $von[]=$temp;
	}
	else
	{
	  $name=trim($out->bio_vorname." ".$out->bio_nachname);
	  if ($lang=="DE") $funktion=$out->funktion_DE; else $funktion=$out->funktion_EN;
	  if ($last_funktion!=$funktion) 
	  { 
	    if ($count) $mtemp.="<br/>";
		$mtemp.=$funktion.": "."<a href=\"artist.php?bio=".$out->bb_bio."\">".$name."</a>";
	  }
	  else
	  {
	    if ($count)
		{ 
		  $mtemp.=", "."<a href=\"artist.php?bio=".$out->bb_bio."\">".$name."</a>";
		}
		else
		{
		  $mtemp.="<a href=\"artist.php?bio=".$out->bb_bio."\">".$name."</a>";
		}
	  }
	  $last_funktion=$funktion;
	  $count++;
	}
  };
  // Render Output
  if (isset($von))
  {
    $vons=sizeof($von);
    if ($vons)
    {
      if ($vons>1)
	  {
	    foreach ($von as $k=>$v)
	    { 
	     if ($k==($vons-1)) 
		 { 
		    if ($k>0) $vonout.=$UND[$lang].$v; else $vonout=$v;
			
		 } else 
		 { 
		    if ($k>0) $vonout.=", ".$v; else $vonout=$v;
		 }
	    }
	  }
	  else
	  {
	    $vonout=$von[0];
	  }
    }

	$mitvon["von"]=$vonout;
  }
  if ($mtemp) $mitvon["mit"]=$mtemp;
  if (isset($mitvon)) return $mitvon;
}

function show_broadcasts ($ID, $lang)
{
  global $db;
  $TOPIC["DE"]="Kunstradio Sendungen";
  $TOPIC["EN"]="Kunstradio Broadcasts";
  $VON["DE"]=" von ";
  $VON["EN"]=" by ";
  
  $query = "SELECT bb_bid"
  . "\nFROM sendung_beitrag_bio"
  . "\nWHERE bb_bio='".$ID."'"
  . ";";
  
  // echo $query;
  $db->setQuery( $query );
  $rows = $db->loadObjectList();
  if (sizeof($rows))
  {
    echo "<p><strong>".$TOPIC[$lang].":</strong><br/>";
	// Get Beitrag IDs
	foreach ($rows as $row)
    {
      $keys_beitrag[]=$row->bb_bid;
    };
	$keys_beitr=implode (",",$keys_beitrag);
	
	$query = "SELECT s_datum, sb_id, sb_sid, ordering, sb_titel"
    . "\nFROM sendung_beitrag"
	. "\nLEFT JOIN sendung ON sb_sid=s_id"
    . "\nWHERE sb_id IN (".$keys_beitr.")"
    . "\nORDER BY ordering;";
    // echo $query;
    $db->setQuery( $query );
    $rows = $db->loadObjectList();
	// Output Sendungen
	if (sizeof($rows))
    {
	  foreach ($rows as $row)
      {
        $mitvon=show_artists($row->sb_id, $lang, $ID);
		echo ReFormatSQLDate($row->s_datum)." <strong>".$row->sb_titel."</strong>";
		if (isset($mitvon["von"])) echo $VON[$lang].$mitvon["von"];
		echo "<br />";
      };
	}
  }
  
}

function show_language_switch ($LANG_SWITCH)
{
  global $bio, $PHP_SELF;
  if ($LANG_SWITCH=="DE") echo "
  <div style=\"position: absolute; top: 0px; right: 0px; color: red; padding: 5px;\"> [ <a href=\"".$PHP_SELF."?bio=".$bio."&amp;lang=DE\" style=\"color: red\">DEUTSCH</a> ]</div>";
  if ($LANG_SWITCH=="EN") echo "
  <div style=\"position: absolute; top: 0px; right: 0px; color: red; padding: 5px;\"> [ <a href=\"".$PHP_SELF."?bio=".$bio."&amp;lang=EN\" style=\"color: red\">ENGLISH</a> ]</div>";
}


function show_email ($email)
{
  if ($email) 
  { 
    $parts=explode("@", $email);
    echo "<br /><br /><script type=\"text/javascript\">spam_stopper(\"".$parts[0]."\",\"".$parts[1]."\");</script>";
  }
}

function show_credit ($string)
{
  if (trim($string)!="") 
  { 
    echo "<div style=\"font-family: Helvetica,Arial,Sans-Serif; font-size: 10px; margin-top: 8px;\">".$string."</div>";
  }
}




?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><? echo trim($data->bio_vorname." ".$data->bio_nachname); ?></title>
<script type="text/javascript">
function spam_stopper(u,d) { document.write('<a href=\"mailto:'+u+'@'+d+'\">');document.write(u+'@'+d +'<\/a>'); }
</script>
</head>

<BODY bgcolor="#C0C0C0" onload="self.focus();">

<div align="center">
  <p>&nbsp;</p>
  <h2><? echo trim($data->bio_vorname." ".$data->bio_nachname); ?></h2>
  <br />  
<?  
if (trim($data->bio_bild!="")) echo "<img src=\"".$data->bio_bild."\" border=\"0\" alt=\"".trim($data->bio_vorname." ".$data->bio_nachname)."\"/>"; 
show_credit($data->bio_credit);
show_email($data->bio_email);
?>

  <hr />
<table width="90%">
<tr>
      <td style="text-align: left"> 
<? 
// Bio Text ausgeben
$TEXT=trim($data->{"bio_text".$lang});
if ($TEXT!="") {
	if (substr($TEXT,0,3)!="<p>") echo '<p>';
 	echo $TEXT;
 	if (substr($TEXT,-4)!="</p>") echo ' </p>';
} ?>

        <!-- <P><strong>Boadcast at ORF KUNSTRADIO:        </strong><br>
        05. 02. 2006: <a href="../2006A/05_02_06.html">Ghostengine - Sprechen ohne Sprachen</a><br> -->
<? 
// Links ausgeben
show_links($ID, $lang); 
show_cds($ID, $lang); 
show_projekte($ID, $lang); 
show_serien($ID, $lang); 
show_broadcasts($ID, $lang); 
?>        
      </td>
</tr>
</table>
<br />
<hr size="10" />
<br />
<a href="../ARCHIVE/artists.html"><img border=0 align="middle" vspace="6" src="../KRLOGOS/button1.gif" /><br /><? 
if ($lang=="DE") 
  echo "BIOGRAFIEN";
else
  echo "BIOGRAPHIES";
?></a>


</div>
<hr size="10" />
<? show_language_switch($LANG_SWITCH); ?>
</body>
</html>

