<?php
/*
    CREATIVE COMMONS - Attribution-No Derivative Works 3.0 Germany:
    - You may not alter, transform, or build upon this work.
    - Dieses Werk darf nicht bearbeitet oder in anderer Weise verändert werden.
*/
function getArtistVarFromArtistVar ($FieldName, $FieldValue, $Var)
{
  global $DB_PREFIX;
  $SQL = "SELECT ".$Var." FROM ".DB_PREFIX."artists WHERE ".$FieldName."='".$FieldValue."' LIMIT 1";
  $result = mysql_query($SQL);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    return $temp[$Var];
  }
  else return false;
}

function getArtistVarFromArtistID ($ArtistID, $Var)
{
  global $DB_PREFIX;
  $SQL = "SELECT ".$Var." FROM ".DB_PREFIX."artists WHERE ArtistID='".$ArtistID."' LIMIT 1";
  $result = mysql_query($SQL);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    return $temp[$Var];
  }
  else return false;
}

function isArtistInDatabase($ArtistName)
{
  global $DB_PREFIX;
  $doppelteVorhanden = false;
  $string = strtolower($ArtistName);
  $sql = 'SELECT * FROM ' .$prefix."artists";
  $result = mysql_query($sql);
  $menge = mysql_num_rows($result);
  while($row = mysql_fetch_row($result))
    if (strtolower($row[1]) == $string) $doppelteVorhanden = true;
  if ($doppelteVorhanden) return true;
  else return false;
}

function addArtist ( $Artist, $Job )
{
  global $DB_PREFIX;
  global $L_042;
  $amountArtists = count($Artist);
  for ($i=0; $i<$amountArtists; $i++)
  {
    // Entfernt HTML- und PHP-Tags aus einer Zeichenkette
      $Artist[$i]=strip_tags($Artist[$i]);
    // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
      $Artist[$i] = mysql_real_escape_string($Artist[$i]);
  }
  list( $ArtistID, $ArtistName, $ArtistURL) = $Artist;
  if ( $ArtistURL=='http://' ) $ArtistURL='';
  if ( $ArtistURL!="" AND !stristr( $ArtistURL, 'http://' ) ) $ArtistURL = 'http://'.$ArtistURL;
  // Abschließendes Slash bei URLs entfernen
    $ArtistURL = getURLWithoutFinalSlash ($ArtistURL);
  if ( $Job=="add" )
  {
    $SQL = "INSERT INTO ".DB_PREFIX."artists ( ArtistName, ArtistURL ) VALUES ( '$ArtistName', '$ArtistURL' )";
    $resultat = mysql_query($SQL);
    if ($resultat) return true;
      else return false;
  }
  elseif ( $Job=="edit" )
  {
    $SQL = "UPDATE ".DB_PREFIX."artists SET ArtistName = '$ArtistName', ArtistURL = '$ArtistURL'
      WHERE ArtistID = '$ArtistID' LIMIT 1";
    $resultat = mysql_query($SQL);
    if ($resultat) return true;
      else return false;
  }
}

function AmountOfArtistsInDatabase ()
  {
    global $DB_PREFIX;
    $sql = "SELECT count(*) as zahl  FROM ".DB_PREFIX."artists";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
  }
?>