Location: PHPKode > scripts > GigKalender > functions/standard.php
<?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.
*/
include ('calendar/functions_artists.php');
include ('calendar/functions_organizers.php');
include ('calendar/functions_venues.php');

function editSetupGallery ( $SetupGalleryAlbumsOrder, $SetupGalleryAlbumsThumbsHeight,
  $SetupGalleryAlbumsThumbsRandomly, $SetupGalleryAlbumsThumbsWidth, $SetupFrontendGalleryURL )
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $SetupGalleryAlbumsThumbsHeight = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupGalleryAlbumsThumbsWidth = mysql_real_escape_string($SetupGalleryAlbumsThumbsWidth);
    $SetupFrontendGalleryURL = mysql_real_escape_string($SetupFrontendGalleryURL);
  // Leere numerische Variablen als NULL definieren
    if ( $SetupGalleryAlbumsThumbsHeight=='' ) $SetupGalleryAlbumsThumbsHeight="NULL";
    if ( $SetupGalleryAlbumsThumbsWidth=='' ) $SetupGalleryAlbumsThumbsWidth="NULL";
  $sql = "UPDATE ".$prefix."setup SET
    SetupGalleryAlbumsOrder = '$SetupGalleryAlbumsOrder',
    SetupGalleryAlbumsThumbsHeight = $SetupGalleryAlbumsThumbsHeight,
    SetupGalleryAlbumsThumbsRandomly = '$SetupGalleryAlbumsThumbsRandomly,
    SetupGalleryAlbumsThumbsWidth = $SetupGalleryAlbumsThumbsWidth',
    SetupFrontendGalleryURL = '$SetupFrontendGalleryURL'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}

function editSetupNews ( $SetupNewsEntriesPerPage, $SetupNewsChannelTitle, $SetupNewsChannelURL,
  $SetupNewsChannelDescription, $SetupNewsChannelLanguage, $SetupNewsChannelCopyright,
  $SetupFrontendNewsDateFormat )
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $SetupNewsEntriesPerPage = mysql_real_escape_string($SetupNewsEntriesPerPage);
    $SetupNewsChannelTitle = mysql_real_escape_string($SetupNewsChannelTitle);
    $SetupNewsChannelURL = mysql_real_escape_string($SetupNewsChannelURL);
    $SetupNewsChannelDescription = mysql_real_escape_string($SetupNewsChannelDescription);
    $SetupNewsChannelLanguage = mysql_real_escape_string($SetupNewsChannelLanguage);
    $SetupNewsChannelCopyright = mysql_real_escape_string($SetupNewsChannelCopyright);
    $SetupFrontendNewsDateFormat = mysql_real_escape_string($SetupFrontendNewsDateFormat);
  // Leere numerische Variablen als NULL definieren
    if ( $SetupNewsEntriesPerPage=='' ) $SetupNewsEntriesPerPage="NULL";
  $sql = "UPDATE ".$prefix."setup SET
    SetupNewsEntriesPerPage = $SetupNewsEntriesPerPage,
    SetupNewsChannelTitle = '$SetupNewsChannelTitle',
    SetupNewsChannelURL = '$SetupNewsChannelURL',
    SetupNewsChannelDescription = '$SetupNewsChannelDescription',
    SetupNewsChannelLanguage = '$SetupNewsChannelLanguage',
    SetupNewsChannelCopyright = '$SetupNewsChannelCopyright',
    SetupFrontendNewsDateFormat = '$SetupFrontendNewsDateFormat'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}

function editSetupGuestbook ( $SetupGuestbookEntriesPerPage, $SetupGuestbookMail,
  $SetupGuestbookEntriesUnlock, $SetupGuestbookSpamDomains, $SetupGuestbookSpamIPs,
  $SetupGuestbookSpamWords, $SetupGuestbookWriteSpamLog, $SetupGuestbookURL, $SetupGuestbookFormURL,
  $SetupGuestbookEmailURL, $SetupFrontendGuestbookDateFormat )
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $SetupGuestbookEntriesPerPage = mysql_real_escape_string($SetupNewsEntriesPerPage);
    $SetupGuestbookMail = mysql_real_escape_string($SetupGuestbookMail);
    $SetupGuestbookSpamDomains = mysql_real_escape_string($SetupGuestbookSpamDomains);
    $SetupGuestbookSpamIPs = mysql_real_escape_string($SetupGuestbookSpamIPs);
    $SetupGuestbookSpamWords = mysql_real_escape_string($SetupGuestbookSpamWords);
    $SetupGuestbookURL = mysql_real_escape_string($SetupGuestbookURL);
    $SetupGuestbookFormURL = mysql_real_escape_string($SetupGuestbookFormURL);
    $SetupGuestbookEmailURL = mysql_real_escape_string($SetupGuestbookEmailURL);
    $SetupFrontendGuestbookDateFormat = mysql_real_escape_string($SetupFrontendGuestbookDateFormat);
  // Leere numerische Variablen als NULL definieren
    if ( $SetupGuestbookEntriesPerPage=='' ) $SetupGuestbookEntriesPerPage="NULL";
    if ( $SetupGuestbookEntriesUnlock=='' ) $SetupGuestbookEntriesUnlock=1;
    if ( $SetupGuestbookWriteSpamLog=='' ) $SetupGuestbookWriteSpamLog=0;
  $sql = "UPDATE ".$prefix."setup SET
    SetupGuestbookEntriesPerPage = $SetupGuestbookEntriesPerPage,
    SetupGuestbookMail = '$SetupGuestbookMail',
    SetupGuestbookEntriesUnlock = $SetupGuestbookEntriesUnlock,
    SetupGuestbookSpamDomains = '$SetupGuestbookSpamDomains',
    SetupGuestbookSpamIPs = '$SetupGuestbookSpamIPs',
    SetupGuestbookSpamWords = '$SetupGuestbookSpamWords',
    SetupGuestbookWriteSpamLog = $SetupGuestbookWriteSpamLog,
    SetupGuestbookURL = '$SetupGuestbookURL',
    SetupGuestbookFormURL = '$SetupGuestbookFormURL',
    SetupGuestbookEmailURL = '$SetupGuestbookEmailURL',
    SetupFrontendGuestbookDateFormat = '$SetupFrontendGuestbookDateFormat'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}

function editSetupCalendar ( $SetupAllowDoubleDates, $SetupCalendarAttributeInAddGigForm,
  $SetupShowEditorInAddGigForm, $SetupRowsTextareas, $SetupFrontendCalendarShowMonthlySeparator,
  $SetupFrontendCalendarShowTableHeads, $SetupFrontendAllowOptionalGigs,
  $SetupFrontendAllowPrivateGigs, $SetupFrontendCalendarCurrentMonthShowPastGigs,
  $SetupFrontendCalendarGigDetailsShowEmptyAttributes, $SetupFrontendCalendarSelector,
  $SetupFrontendFirstDayOfWeek, $SetupFrontendCalendarPeriodSelector,
  $SetupFrontendCalendarCharsInFields, $SetupFrontendCalendarMaxAmountOfGigs,
  $SetupFrontendCalendarMaxAmountOfGigsPast, $SetupFrontendCalendarDateFormat,
  $SetupFrontendCalendarGigDetailsDateFormat, $SetupFrontendCalendarCurrentMonthLimitFuture,
  $SetupFrontendCalendarCurrentMonthLimitPast, $SetupFrontendCalendarURL,
  $SetupFrontendCalendarGigDetailsURL, $SetupFrontendCalendarCurrentMonthURL,
  $SetupFrontendAttributes, $SetupFrontendDetailAttributes )
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $SetupRowsTextareas = mysql_real_escape_string($SetupRowsTextareas);
    $SetupFrontendCalendarCharsInFields = mysql_real_escape_string($SetupFrontendCalendarCharsInFields);
    $SetupFrontendCalendarMaxAmountOfGigs = mysql_real_escape_string($SetupFrontendCalendarMaxAmountOfGigs);
    $SetupFrontendCalendarMaxAmountOfGigsPast = mysql_real_escape_string($SetupFrontendCalendarMaxAmountOfGigsPast);
    $SetupFrontendCalendarDateFormat = mysql_real_escape_string($SetupFrontendCalendarDateFormat);
    $SetupFrontendCalendarGigDetailsDateFormat = mysql_real_escape_string($SetupFrontendCalendarGigDetailsDateFormat);
    $SetupFrontendCalendarCurrentMonthLimitFuture = mysql_real_escape_string($SetupFrontendCalendarCurrentMonthLimitFuture);
    $SetupFrontendCalendarCurrentMonthLimitPast = mysql_real_escape_string($SetupFrontendCalendarCurrentMonthLimitPast);
    $SetupFrontendCalendarURL = mysql_real_escape_string($SetupFrontendCalendarURL);
    $SetupFrontendCalendarGigDetailsURL = mysql_real_escape_string($SetupFrontendCalendarGigDetailsURL);
    $SetupFrontendCalendarCurrentMonthURL = mysql_real_escape_string($SetupFrontendCalendarCurrentMonthURL);
  // Leere numerische Variablen als NULL definieren
    if ( $SetupAllowDoubleDates=='' ) $SetupAllowDoubleDates=1;
    if ( $SetupShowEditorInAddGigForm=='' ) $SetupShowEditorInAddGigForm=1;
    if ( $SetupRowsTextareas=='' ) $SetupRowsTextareas=5;
    if ( $SetupFrontendCalendarShowMonthlySeparator=='' ) $SetupFrontendCalendarShowMonthlySeparator=1;
    if ( $SetupFrontendCalendarShowTableHeads=='' ) $SetupFrontendCalendarShowTableHeads=1;
    if ( $SetupFrontendAllowOptionalGigs=='' ) $SetupFrontendAllowOptionalGigs=0;
    if ( $SetupFrontendAllowPrivateGigs=='' ) $SetupFrontendAllowPrivateGigs=0;
    if ( $SetupFrontendCalendarCurrentMonthShowPastGigs=='' ) $SetupFrontendCalendarCurrentMonthShowPastGigs=true;
    if ( $SetupFrontendCalendarGigDetailsShowEmptyAttributes=='' ) $SetupFrontendCalendarGigDetailsShowEmptyAttributes=false;
    if ( $SetupFrontendCalendarCharsInFields=='' ) $SetupFrontendCalendarCharsInFields=20;
    if ( $SetupFrontendCalendarMaxAmountOfGigs=='' ) $SetupFrontendCalendarMaxAmountOfGigs=999;
    if ( $SetupFrontendCalendarMaxAmountOfGigsPast=='' ) $SetupFrontendCalendarMaxAmountOfGigsPast=999;
    if ( $SetupFrontendCalendarCurrentMonthLimitFuture=='' ) $SetupFrontendCalendarCurrentMonthLimitFuture=12;
    if ( $SetupFrontendCalendarCurrentMonthLimitPast=='' ) $SetupFrontendCalendarCurrentMonthLimitPast=6;
  $sql = "UPDATE ".$prefix."setup SET
    SetupAllowDoubleDates = $SetupAllowDoubleDates,
    SetupCalendarAttributeInAddGigForm = '$SetupCalendarAttributeInAddGigForm',
    SetupShowEditorInAddGigForm = $SetupShowEditorInAddGigForm,
    SetupRowsTextareas = $SetupRowsTextareas,
    SetupFrontendCalendarShowMonthlySeparator = $SetupFrontendCalendarShowMonthlySeparator,
    SetupFrontendCalendarShowTableHeads = $SetupFrontendCalendarShowTableHeads,
    SetupFrontendAllowOptionalGigs = $SetupFrontendAllowOptionalGigs,
    SetupFrontendAllowPrivateGigs = $SetupFrontendAllowPrivateGigs,
    SetupFrontendCalendarCurrentMonthShowPastGigs = $SetupFrontendCalendarCurrentMonthShowPastGigs,
    SetupFrontendCalendarGigDetailsShowEmptyAttributes = $SetupFrontendCalendarGigDetailsShowEmptyAttributes,
    SetupFrontendCalendarSelector = '$SetupFrontendCalendarSelector',
    SetupFrontendFirstDayOfWeek = '$SetupFrontendFirstDayOfWeek',
    SetupFrontendCalendarPeriodSelector = '$SetupFrontendCalendarPeriodSelector',
    SetupFrontendCalendarCharsInFields = $SetupFrontendCalendarCharsInFields,
    SetupFrontendCalendarMaxAmountOfGigs = $SetupFrontendCalendarMaxAmountOfGigs,
    SetupFrontendCalendarMaxAmountOfGigsPast = $SetupFrontendCalendarMaxAmountOfGigsPast,
    SetupFrontendCalendarDateFormat = '$SetupFrontendCalendarDateFormat',
    SetupFrontendCalendarGigDetailsDateFormat = '$SetupFrontendCalendarGigDetailsDateFormat',
    SetupFrontendCalendarCurrentMonthLimitFuture = $SetupFrontendCalendarCurrentMonthLimitFuture,
    SetupFrontendCalendarCurrentMonthLimitPast = $SetupFrontendCalendarCurrentMonthLimitPast,
    SetupFrontendCalendarURL = '$SetupFrontendCalendarURL',
    SetupFrontendCalendarGigDetailsURL = '$SetupFrontendCalendarGigDetailsURL',
    SetupFrontendCalendarCurrentMonthURL = '$SetupFrontendCalendarCurrentMonthURL',
    SetupFrontendAttributes = '$SetupFrontendAttributes',
    SetupFrontendDetailAttributes = '$SetupFrontendDetailAttributes'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}

function editSetupFrontend (  )
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    // AKTIVIEREN; STAMMT AUS 1.2!!!
    //$xxx = mysql_real_escape_string($xxx);
  // Leere numerische Variablen als NULL definieren
    // später anpassen und erweitern: if ( $SetupAllowDoubleDates=='' ) $SetupAllowDoubleDates=1;
  $sql = "UPDATE ".$prefix."setup SET";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}

function editSetupGeneral ( $SetupRefreshtime, $SetupExportSeparator,
  $SetupUserMaximumInactivityTime, $SetupBackendDateFormat, $SetupBackendTimeFormat,
  $SetupBackendUseCache, $SetupFrontendLanguage, $SetupFrontendCssFile )
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $SetupRefreshtime = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupExportSeparator = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupUserMaximumInactivityTime = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupBackendDateFormat = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupBackendTimeFormat = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupFrontendLanguage = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
    $SetupFrontendCssFile = mysql_real_escape_string($SetupGalleryAlbumsThumbsHeight);
  // Leere numerische Variablen als NULL definieren
    if ( $SetupRefreshtime=='' ) $SetupRefreshtime=1;
    if ( $SetupUserMaximumInactivityTime=='' ) $SetupUserMaximumInactivityTime=30;
    if ( $SetupBackendUseCache=='' ) $SetupBackendUseCache=true;
  $sql = "UPDATE ".$prefix."setup SET
    SetupRefreshtime = $SetupRefreshtime,
    SetupExportSeparator = '$SetupExportSeparator',
    SetupUserMaximumInactivityTime = $SetupUserMaximumInactivityTime,
    SetupBackendDateFormat = '$SetupBackendDateFormat',
    SetupBackendTimeFormat = '$SetupBackendTimeFormat',
    SetupBackendUseCache = $SetupBackendUseCache,
    SetupFrontendLanguage = '$SetupFrontendLanguage',
    SetupFrontendCssFile = '$SetupFrontendCssFile'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}

function isEmailDomainValid ($email)
{
  if (!function_exists('checkdnsrr'))
  {
    function checkdnsrr($host, $type='MX')
    {
      if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') return;
      if (empty($host)) return;
      $types=array('A', 'MX', 'NS', 'SOA', 'PTR', 'CNAME', 'AAAA', 'A6', 'SRV', 'NAPTR', 'TXT',
        'ANY');
      if (!in_array($type,$types))
      {
        user_error("checkdnsrr() Type '$type' not supported", E_USER_WARNING);
        return;
      }
      @exec('nslookup -type='.$type.' '.escapeshellcmd($host), $output);
      foreach($output as $line)
        if (preg_match('/^'.$host.'/',$line)) return true;
    }
  }
  if (checkdnsrr(array_pop(explode("@",$email)),"MX")) return true;
}

function isEmailTLDValid($email)
{
  $tld = array('ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'as',
    'at', 'au', 'aw', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn',
    'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci',
    'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj',
    'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm',
    'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq',
    'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im',
    'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg',
    'kh', 'ki', 'km', 'kn', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt',
    'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi',
    'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc',
    'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe',
    'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro',
    'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so',
    'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn',
    'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'um', 'us', 'uy', 'uz',
    'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm');
  $email = rtrim($email);
  $email = substr($email, strrpos($email, '.') + 1);
  if (!$email) return false;
  if (in_array(strtolower($email), $tld)) return true;
  return false;
}
function deleteFileInCache ( $Timestamp )
{
  $Year = date('Y', $Timestamp);
  $Month = date('n', $Timestamp);
  $FileName1 = 'admin-'.$Year.'-'.$Month.'.php';
  $FileName2 = 'user-'.$Year.'-'.$Month.'.php';
  $Path = 'cache/';
  if ( !is_link( $Path.$FileName1 ) AND is_file ( $Path.$FileName1 ) )
    if ( @ !unlink ( $Path.$FileName1 ) )
      print '<span class="ERROR">ERROR: Cache NOT cleared! ('.$FileName1.')</span><br />';
  if ( !is_link( $Path.$FileName2 ) AND is_file ( $Path.$FileName2 ) )
    if ( @ !unlink ( $Path.$FileName2 ) )
      print '<span class="ERROR">ERROR: Cache NOT cleared! ('.$FileName2.')</span><br />';
}
function clearCache ()
{
  $Path = str_replace('\\','/', __FILE__);
  $Path = str_replace('functions/standard.php', '', $Path);
  $Path = $Path.'cache/';
  $oDir = dir( $Path );
  while ( false !== ( $strFile = $oDir->read () ) )
  {
    if ( $strFile != '.' && $strFile != '..' AND ! is_link ( $Path . $strFile )
      AND is_file ( $Path . $strFile ) )
    {
      if ( @ unlink ( $Path . $strFile ) ) {}
      else
        print '<span class="ERROR">ERROR: Cache NOT cleared! ('.$strFile.')</span><br />';
    }
  }
  $oDir->close();
}
function writeToCache ( $Filename, $Content)
{
  echo $Content;
  global $GigKalenderPath;
  $path = 'cache/';
  $datei = $path.$Filename;
  $fp=fopen($datei,"w+");
  fwrite($fp,$Content);
}
function getArrayForAutoSuggest ( $Field )
{
  global $prefix;
  $sql = "SELECT DISTINCT `".$Field."` FROM `".$prefix."gigs` ORDER BY `".$Field."` ASC";
  $result = mysql_query($sql);
  $ArrayForAutoSuggest = array();
  while ($daten = mysql_fetch_assoc($result))
  {
    $temp = $daten[$Field];
    if ($temp!='' OR $temp!=0) array_push($ArrayForAutoSuggest, $temp);
  }
  $String = implode (", ", $ArrayForAutoSuggest);
  $String = str_replace('"', '\"',$String);
  return $String;
}
function getFrontendURL ( $Var )
{
  global $Timestamp;
  global $GuestbookID;
  global $SetupFrontendCalendarCurrentMonthURL;
  global $SetupFrontendCalendarGigDetailsURL;
  global $SetupGuestbookEmailURL;
  global $SetupGalleryURL;
  $URL = ${$Var};
  if (isset($_SERVER['REQUEST_URI'])) $REQUEST_URI=$_SERVER['REQUEST_URI'];
    else $REQUEST_URI = '';
  if ( $URL=='' ) $URL = $REQUEST_URI;
    else $URL = $URL;
  $URL = str_replace("&","&amp;",$URL);
  $URLArray = parse_url ( $URL );
  if (isset($URLArray['query'])) $Query = $URLArray['query'];
    else $Query='';
  parse_str ( $Query );
  if ( $Var=='SetupFrontendCalendarGigDetailsURL' )
    $URL = $URLArray['path'].'?Timestamp='.$Timestamp;
  if ( $Var=='SetupFrontendCalendarCurrentMonthURL' )
  {
    if (!isset($year)) $year='';
    if ($year!='') $temp = strstr ( $Query, 'year' );
      else $temp = '';
    $Query = str_replace('&amp;'.$temp,"",$Query);
    $Query = str_replace($temp,"",$Query);
    $Query = str_replace('&amp;'.$temp,"",$Query);
    $Query = str_replace($temp,"",$Query);
    if ($Query=='') $URL = $URLArray['path'].'?';
      else $URL = $URLArray['path'].'?'.$Query.'&amp;';
  }
  if ( $Var=='SetupGuestbookEmailURL' )
  {
    if ( ereg ( '\?', $URL ) ) $URL = $URL.'&amp;';
      else $URL = $URL.'?';
    $URL = $URL.'id='.$GuestbookID.'&amp;page=mail';
  }
  if ( $Var=='SetupGalleryURL' ) $URL = str_replace('?'.$Query,"",$URL);
  return $URL;
}
 
function getGoogleMapsURL ( $GigCountry, $GigDistrict, $GigPostalCode, $GigCity )
{
  if ($GigPostalCode == "0") $GigPostalCode = "";
  $Location = "";
  if ( $GigCountry!='') $Location .= $GigCountry;
  if ( $GigCountry!='' AND $GigPostalCode!='') $Location .= '-';
  if ( $GigPostalCode!='') $Location .= $GigPostalCode;
  if ( $GigCountry!='' AND $GigPostalCode=='' && $GigCity!='' ) $Location .= ' ';
  if ( $GigPostalCode!='' AND $GigCity!='') $Location .= ' ';
  if ( $GigCity!='') $Location .= $GigCity;
  if ( $GigDistrict!='' AND $GigCity=='') $Location .= $GigDistrict;
  $Location = str_replace(" ","+",$Location);
  return 'http://maps.google.de/maps?f=q&amp;hl=de&amp;geocode=&amp;q='.$Location;
}
 
function translateLanguageVarString ( $String )
{
  $Array = explode( ', ', $String);
  $amountArrayItems = count($Array);
  for ($i=0; $i<$amountArrayItems; $i++)
  {
    global ${'L_'.$Array[$i]};
    $Array[$i] = ${'L_'.$Array[$i]};
  }
  return implode( ', ', $Array);
}
 
function setSetupVar ( $Var, $Value )
{
  global $prefix;
  $sql = "UPDATE ".$prefix."setup SET $Var = '$Value'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}
 
function setUserVar ( $Var, $Value )
{
  global $prefix;
  $sql = "UPDATE ".$prefix."user SET $Var = '$Value'";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
  else return false;
}
 
function publishedGigOnTimestamp ( $Timestamp )
{
  global $prefix;
  $SQL = "SELECT * FROM ".$prefix."gigs WHERE GigDate = ".$Timestamp." AND (GigStatus = 'Gig'";
  if ( getSetup('SetupFrontendAllowOptionalGigs') ) $SQL .= " OR GigStatus = 'Option'";
  $SQL .= ")";
  if ( !getSetup('SetupFrontendAllowPrivateGigs') ) $SQL .= " AND GigIsPrivate = 0";
  $SQL .= " AND GigPublish = 1";
  $SQL .= " LIMIT 1";
  $resultat = mysql_query($SQL);
  if ( mysql_num_rows($resultat)==1) return true;
  else return false;
}

function convertISO8601ToTimestamp ($ISO8601)
{
  global $L_ERROR_Invalid_date;
  if ( $ISO8601>0)
  {
    $eregStr =  '([0-9]{4})-'. // centuries & years CCYY-
                '([0-9]{2})-'. // months MM-
                '([0-9]{2})'.  // days DD
                'T'.           // separator T
                '([0-9]{2}):'. // hours hh:
                '([0-9]{2}):'. // minutes mm:
                '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
                '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS, for local tz's
    if(ereg($eregStr,$ISO8601,$regs))
    {
      $temp = strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
      // not utc
      if($regs[8] != 'Z')
      {
        $op = substr($regs[8],0,1);
        $h = substr($regs[8],1,2);
        $m = substr($regs[8],strlen($regs[8])-2,2);
        if($op == '-') $temp = $temp+($h*3600+$m*60);
          elseif($op == '+') $temp = $temp-($h*3600+$m*60);
      }
      return $temp;
    }
    else // OpenOffice JJJJ-MM-TT HH:MM:SSZ
    {
      $eregStr =  '([0-9]{4})-'. // centuries & years CCYY-
      '([0-9]{2})-'. // months MM-
      '([0-9]{2})'.  // days DD
      ' '.           // separator ' '
      '([0-9]{2}):'. // hours hh:
      '([0-9]{2}):'. // minutes mm:
      '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
      '(Z|[+\-][0-9]{2}:?[0-9]{2})?'; // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
      if(ereg($eregStr,$ISO8601,$regs))
      {
        $temp = strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
        // not utc
        if($regs[8] != 'Z')
        {
          $op = substr($regs[8],0,1);
          $h = substr($regs[8],1,2);
          $m = substr($regs[8],strlen($regs[8])-2,2);
          if($op == '-') $temp = $temp+($h*3600+$m*60);
            elseif($op == '+') $temp = $temp-($h*3600+$m*60);
        }
        return $temp;
      }
      else // OpenOffice JJJJ-MM-TT
      {
        $eregStr =  '([0-9]{4})-'. // centuries & years CCYY-
                    '([0-9]{2})-'. // months MM-
                    '([0-9]{2})';  // days DD
        if(ereg($eregStr,$ISO8601,$regs))
          return strtotime("$regs[1]-$regs[2]-$regs[3] 0:0:0Z");
        else // Timestamp
        {
          $eregStr =  '([0-9]{9,10})'; // Timestamp
          if(ereg($eregStr,$ISO8601,$regs)) return $regs[0];
          else
          {
            echo '<span class="ERROR">'.$L_ERROR_Invalid_date.' ('.$ISO8601.')</span><br />';
            return false;
          }
        }
      }
    }
  }
  else return '';
}
 
function convertTimestampToISO8601 ($Timestamp)
{ 
  if ( $Timestamp>0 )
  {
    // PHP4
      $temp = date('Y-m-d\TH:i:sO', $Timestamp);
      return substr ( $temp, 0, 22 ).':'.substr ( $temp, 22 );
    // PHP5
      // return date('c',$Timestamp);
  }
  else return '';
}

function AnzahlGigsMitGleichemDatum ( $GigDate )
{
  global $prefix;
  // Diese Funktion optimieren, so dass sie sofort Ergebniss ausgibt, wenn zahl>1
  $sql = "SELECT count(*) as zahl  FROM ".$prefix."gigs WHERE GigDate=".$GigDate;
  $result = mysql_query($sql);
  $row = mysql_fetch_array($result);
  return $row['zahl'];
}
 
function getGigVarFromGigDate ($GigDate, $Var)
{
  global $prefix;
  $SQL = "SELECT ".$Var." FROM ".$prefix."gigs WHERE GigDate='".$GigDate."' LIMIT 1";
  $result = mysql_query($SQL);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    return $temp[$Var];
  }
  else return false;
}
 
function getGigVarFromGigID ($GigID, $Var)
{
  global $prefix;
  $SQL = "SELECT ".$Var." FROM ".$prefix."gigs WHERE GigID='".$GigID."' LIMIT 1";
  $result = mysql_query($SQL);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    return $temp[$Var];
  }
  else return false;
}
 
function changeGigIsPrivate ( $GigID )
{
  global $prefix;
  // aktuellen GigStatus abfragen
  $sql = "SELECT GigIsPrivate FROM ".$prefix."gigs WHERE GigID='".$GigID."' LIMIT 1";
  $result = mysql_query($sql);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    $aktuellerGigStatus = $temp['GigIsPrivate'];
  }
  // neuen GigStatus setzen
  if ( $aktuellerGigStatus=='0' ) $neuerGigStatus = '1';
  if ( $aktuellerGigStatus=='1' ) $neuerGigStatus = '0';
  $DateOfLastEdit = date("U");
  $sql = "UPDATE ".$prefix."gigs SET GigIsPrivate = '".$neuerGigStatus."',
    GigDateOfLastEdit = '".$DateOfLastEdit."', GigLastEditor = '".getCurrentUserVar('UserName')."'
    WHERE GigID = '".$GigID."' LIMIT 1";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
    else return false;
}
 
function changeGigPublishing ( $GigID )
{
  global $prefix;
  // aktuellen GigStatus abfragen
  $sql = "SELECT GigPublish FROM ".$prefix."gigs WHERE GigID='".$GigID."' LIMIT 1";
  $result = mysql_query($sql);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    $aktuellerGigStatus = $temp['GigPublish'];
  }
  // neuen GigStatus setzen
  if ( $aktuellerGigStatus=='0' ) $neuerGigStatus = '1';
  if ( $aktuellerGigStatus=='1' ) $neuerGigStatus = '0';
  $DateOfLastEdit = date("U");
  $sql = "UPDATE ".$prefix."gigs SET GigPublish = '".$neuerGigStatus."',
    GigDateOfLastEdit = '".$DateOfLastEdit."', GigLastEditor = '".getCurrentUserVar('UserName')."'
    WHERE GigID = '".$GigID."' LIMIT 1";
  $resultat = mysql_query($sql);
  if ($resultat) return true;
    else return false;
}
 
function CheckGigPublish ($GigID)
{
  global $prefix;
  $GigPublish = "";
  $GigStatus = "";
  $SQL = "SELECT * FROM ".$prefix."gigs WHERE GigID = ".$GigID." LIMIT 1";
  $resultat = mysql_query($SQL);
  while ($row = mysql_fetch_array($resultat)) 
    extract($row);
  if  (
        ( 
          $GigStatus == 'Gig' 
          OR 
          ( $GigStatus == 'Option' AND getSetup('SetupFrontendAllowOptionalGigs') )
        ) 
        AND 
        ( !$GigIsPrivate OR getSetup('SetupFrontendAllowPrivateGigs') )
        AND
        $GigPublish == '1' 
     ) 
    return true;
  else return false;
} 
 
function TimeStampAusDatumMitUhrzeit ($Date)
{
  if ( $Date != '' )
  {
    $Date = ereg_replace(' ', '', $Date);
    $Date = ereg_replace('-', '.', $Date);
    $Date = ereg_replace(':', '.', $Date);
    $arr = explode ('.', $Date);
    return mktime($arr[3],$arr[4],'',$arr[1],$arr[0],$arr[2]);
  }
  else return '';
} 
 
function DatumMitUhrzeitAusTimestamp ($Timestamp)
{ 
  if ( $Timestamp != '0' AND $Timestamp != '' )
    return date(getSetup('SetupBackendDateFormat'), $Timestamp).' - '
      .date(getSetup('SetupBackendTimeFormat'), $Timestamp);
  else return '-';
} 
 
function checkICQNumber ($ICQNumber)
{ 
  if (eregi("^([0-9]{5,9}$)", $ICQNumber)) return true;
  else return false;
} 
 
function getNameOfWeekday ( $Timestamp )
{ 
  global $L_Mo;
  global $L_Tu;
  global $L_We;
  global $L_Th;
  global $L_Fr;
  global $L_Sa;
  global $L_Su;
  $Weekday = date('w', $Timestamp);
  switch ($Weekday) 
  {
    case 0: return $L_Su; break;
    case 1: return $L_Mo; break;
    case 2: return $L_Tu; break;
    case 3: return $L_We; break;
    case 4: return $L_Th; break;
    case 5: return $L_Fr; break;
    case 6: return $L_Sa; break;
    default: echo "ERROR: Could not calculate name of weekday!<br />";
  }
}

function logoutInactiveUser ()
{
  global $prefix;
  $SetupUserMaximumInactivityTime = getSetup('SetupUserMaximumInactivityTime');
  if ( $SetupUserMaximumInactivityTime<1 ) $SetupUserMaximumInactivityTime = 1;
  $Diff = time()-($SetupUserMaximumInactivityTime*60);
  $sql="UPDATE ".$prefix."user SET UserSession=NULL WHERE UserLastActivityTimestamp<'".$Diff."'";
  mysql_query($sql);
}  

function updateUserActivity ()
{
  global $prefix;
  $sql="UPDATE ".$prefix."user SET UserLastActivityTimestamp=".time()."
    WHERE UserName='".getCurrentUser()."' LIMIT 1";
  mysql_query($sql);
} 
 
function AnzahlAllerGigsInDatenbank ()
  {
    global $prefix;
    $sql = "SELECT count(*) as zahl  FROM ".$prefix."gigs";
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
  } 
 
function AnzahlGigsImZeitraum ( $Zeitraum, $GigStatus )
{
    global $prefix;
    $TimestampVonHeute = TimestampAusDatum(date("d"), date("m"), date("y"));
    $sql = "SELECT count(*) as zahl  FROM ".$prefix."gigs";
    if ( $Zeitraum!='all' OR $GigStatus!='all' ) $sql .= " WHERE";
    if ( $Zeitraum =="future" ) $sql .= " GigDate>=".$TimestampVonHeute;
    if ( $Zeitraum =="past" ) $sql .= " GigDate<=".$TimestampVonHeute;
    if ( $Zeitraum!='all' && $GigStatus!='all' ) $sql .= " AND";
    if ( $GigStatus!='all' ) $zweiterFilter = " GigStatus='".$GigStatus."'";
    else $zweiterFilter = "";
    $sql .= $zweiterFilter;
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    return $row['zahl'];
}
 
function getUserVar ($UserName, $Var)
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $UserName = mysql_real_escape_string($UserName);
  $sql = "SELECT ".$Var." FROM ".$prefix."user WHERE UserName='".$UserName."' LIMIT 1";
  $result = mysql_query($sql);
  if ( mysql_num_rows($result)==1)
  {
    $temp=mysql_fetch_assoc($result);
    return $temp[$Var];
  }
  else return false;
}

function checkURL ($url)
{ 
  if ( !stristr($url, "http://") ) $url = "http://".$url;
  if ( preg_match('#^http\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $url)
    OR ($url == "http://") )
    return true;
}

function getLocationString ( $GigCountry, $GigDistrict, $GigPostalCode, $GigCity )
{
  if ($GigPostalCode == "0") $GigPostalCode = "";
  $Location = "";
  if ( $GigCountry!='') $Location .= $GigCountry;
  if ( $GigCountry!='' && $GigPostalCode!='') $Location .= '-';
  if ( $GigPostalCode!='') $Location .= $GigPostalCode;
  if ( $GigCountry!='' && $GigPostalCode=='' && $GigCity!='' ) $Location .= ' ';
  if ( $GigPostalCode!='' && $GigCity!='') $Location .= ' ';
  if ( $GigCity!='') $Location .= $GigCity;
  if ( $GigDistrict!='') $Location .= ' ('.$GigDistrict.')';
  return $Location;
}

function getCurrentUserVar ($Var)
{
  global $prefix;
  if ($Var>0 OR $Var!='')
  {
    $SQL = "SELECT ".$Var." FROM ".$prefix."user WHERE UserSession='".session_id()."' LIMIT 1";
    $result = mysql_query($SQL);
    if ($result)
    {
      if ( mysql_num_rows($result)==1)
      {
        $temp=mysql_fetch_assoc($result);
        return $temp[$Var];
      }
      else return false;
    }
    else return false;
  }
  else return false;
}

function checkGigDatum ($GigDateDay, $GigDateMonth, $GigDateYear)
{
  if ( checkdate($GigDateMonth, $GigDateDay, $GigDateYear) ) return true;
}

function zukuenftigeTermineEingetragen()
{
  global $prefix;
  global $L_GigStatusGig;
  $TimestampVonHeute = TimestampAusDatum(date("d"), date("m"), date("y"));
  $zukuenftigeTermineEingetragen = false;
  $sql="SELECT GigDate FROM ".$prefix."gigs WHERE GigStatus='Gig' OR GigStatus='Blocked'
    OR GigStatus='Option' OR GigStatus='Rehearsal'";
  $result = mysql_query($sql);
  while($row = mysql_fetch_row($result))
    if (strtolower($row[0]) >= $TimestampVonHeute) $zukuenftigeTermineEingetragen = true;
  if ($zukuenftigeTermineEingetragen) return true;
  else return false;
}

function startTime()
{
  $timeExplode = explode(" ", microtime());
  return $timeExplode[1] + $timeExplode[0];
}

function endTime($timer)
{
  $timeExplode = explode(" ", microtime());
  $time = $timeExplode[1] + $timeExplode[0];
  $finish = $time - $timer;
  return sprintf("%4.3f", $finish);
}

function checkEmail ($email)
{
  if (eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $email) AND isEmailTLDValid($email)
    AND isEmailDomainValid($email))
    return true;
}

function GetTooltip($Timestamp)
{
  global $prefix;
  $Tooltip = "";
  $SQL = "SELECT * FROM " .$prefix."gigs WHERE GigDate = ".$Timestamp;
  $resultat = mysql_query($SQL);
  while ($row = mysql_fetch_array($resultat))
  {
    extract($row);
    $VenueCountry = getVenueVarFromVenueID ($GigVenueID, 'VenueCountry');
    $VenueDistrict = getVenueVarFromVenueID ($GigVenueID, 'VenueDistrict');
    $VenuePostalCode = getVenueVarFromVenueID ($GigVenueID, 'VenuePostalCode');
    $VenueCity = getVenueVarFromVenueID ($GigVenueID, 'VenueCity');
    $ArtistName = getArtistVarFromArtistID ($GigArtistID, 'ArtistName');
    $Tooltip = getLocationString($VenueCountry, $VenueDistrict, $VenuePostalCode, $VenueCity);
    if ( $ArtistName != '') $Tooltip .= '&#10;'.$ArtistName;
    if ( $GigEvent != '') $Tooltip .= '&#10;'.$GigEvent;
  }
  $Tooltip = str_replace('"', '&quot;', $Tooltip);
  $Tooltip = str_replace('<p>', '&#10;', $Tooltip);
  $Tooltip = preg_replace("/\r|\n/s", "", $Tooltip);
  return strip_tags($Tooltip);
}

function GigsPublished( $Zeitraum )
{
  global $prefix;
  $TimestampVonHeute = TimestampAusDatum(date("d"), date("m"), date("y"));
  $SQL = "SELECT * FROM ".$prefix."gigs WHERE GigStatus='Gig' OR GigStatus='Option' AND
    GigPublish=1";
  $resultat = mysql_query($SQL);
  $temp=0;
  while ($row = mysql_fetch_array($resultat))
  {
    extract($row);
    if ( $Zeitraum == 'future' AND $GigDate >= $TimestampVonHeute ) $temp=1;
    elseif ( $Zeitraum == 'past' AND $GigDate < $TimestampVonHeute ) $temp=1;
    elseif ( $Zeitraum == 'all' AND $GigDate > '0' ) $temp=1;
  }
  if ($temp==1) return true;
  else return false;
}

function getSetup ($Var)
{
  global $prefix;
  $SQL="SELECT ".$Var." FROM ".$prefix."setup WHERE SetupID=1 LIMIT 1";
  $result = mysql_query($SQL);
  if ($result)
  {
    if ( mysql_num_rows($result)==1)
    {
      $temp=mysql_fetch_assoc($result);
      return $temp[$Var];
    }
    else return false;
  }
  else return false;
}

function transformPassword ($Password)
{
  $anzahlZeichen = strlen($Password);
  for ($i=0; $i<$anzahlZeichen; $i++) echo "*";
}

function testDoppelteGigs ($GigDateDay, $GigDateMonth, $GigDateYear)
{
  global $prefix;
  $Timestamp = TimestampAusDatum ($GigDateDay, $GigDateMonth, $GigDateYear);
  $doppelteVorhanden = false;
  //$db_select = @mysql_select_db($db_name);
  $sql = 'SELECT * FROM ' .$prefix."gigs";
  $result = mysql_query($sql);
  while($row = mysql_fetch_row($result))
    if (strtolower($row[1]) == $Timestamp) $doppelteVorhanden = true;
  if ($doppelteVorhanden) return true;
  else return false;
}

function IsUserUser ()
{
  global $prefix;
  $sql="SELECT UserStatus FROM ".$prefix."user WHERE UserSession='".session_id()."'";
  $result= mysql_query($sql);
  $temp = mysql_fetch_assoc($result);
  if ($temp['UserStatus'] == "User") return true;
  else return false;
}

function IsUserAdmin ()
{
  global $prefix;
  $sql='SELECT UserStatus FROM '.$prefix.'user WHERE UserSession="'.session_id().'"';
  $result = mysql_query($sql);
  $temp = mysql_fetch_assoc($result);
  if ($temp['UserStatus'] == "Admin") return true;
  else return false;
}

function logout()
{
  global $prefix;
  $sql="UPDATE ".$prefix."user SET UserSession=NULL WHERE UserSession='".session_id()."'";
  mysql_query($sql);
  session_name('GigKalender');
  session_destroy();
}

function login ( $userID )
{
  global $prefix;
  $sql="UPDATE ".$prefix."user SET UserSession='".session_id()."' WHERE UserId=".$userID;
  mysql_query($sql);
}

function loggedIn()
{
  global $prefix;
  $sql="SELECT UserID FROM ".$prefix."user WHERE UserSession='".session_id()."' LIMIT 1";
  $result= mysql_query($sql);
  if ($result) return ( mysql_num_rows($result)==1);
  else return false;
}

function getUID ( $UserName, $UserCurrentPassword )
{
  global $prefix;
  $SQL="SELECT UserId FROM ".$prefix."user WHERE UserName='".$UserName."'
    AND UserCurrentPassword='".$UserCurrentPassword."' LIMIT 1";
  $result = mysql_query($SQL);
  if ($result)
  {
    if ( mysql_num_rows($result)==1)
    {
      $user=mysql_fetch_assoc($result);
      return $user['UserId'];
    }
    else return false;
  }
  else return false;
}

function getCurrentUser ()
{
  global $prefix;
  $SQL="SELECT UserName FROM ".$prefix."user WHERE UserSession='".session_id()."' LIMIT 1";
  $result = mysql_query($SQL);
  if ( mysql_num_rows($result)==1)
  {
    $temp = mysql_fetch_assoc($result);
    return $temp['UserName'];
  }
  else return false;  
}

function addUser ($UserName, $UserStatus, $UserCurrentPassword, $UserEmailadress, $UserSession,
  $UserLanguage, $UserLastActivityTimestamp, $UserBackendCalenderListCols, $UserRightEmail,
  $UserRightAddNews, $UserRightEditNews, $UserRightDeleteNews, $UserCharsCalenderListFields,
  $UserCharsGuestbookListFields, $UserEmailCopyToOwnAdress, $UserFirstDayOfWeek)
{
  global $prefix;
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $UserName = mysql_real_escape_string($UserName);
    $UserCurrentPassword = mysql_real_escape_string($UserCurrentPassword);
    $UserEmailadress = mysql_real_escape_string($UserEmailadress);
  // Leere numerische Variablen als NULL definieren
    if ( $UserLastActivityTimestamp=='' ) $UserLastActivityTimestamp="NULL";
    if ( $UserRightEmail=='' ) $UserRightEmail=0;
    if ( $UserRightAddNews=='' ) $UserRightAddNews=0;
    if ( $UserRightEditNews=='' ) $UserRightEditNews=0;
    if ( $UserRightDeleteNews=='' ) $UserRightDeleteNews=0;
    if ( $UserCharsCalenderListFields=='' ) $UserCharsCalenderListFields=10;
    if ( $UserEmailCopyToOwnAdress=='' ) $UserEmailCopyToOwnAdress=1;
  if (!testDoppelteUser($UserName))
  {
    $SQL = "INSERT INTO ".$prefix."user (UserName, UserStatus, UserCurrentPassword,
      UserEmailadress, UserSession, UserLanguage, UserLastActivityTimestamp,
      UserBackendCalenderListCols, UserRightEmail, UserRightAddNews, UserRightEditNews,
      UserRightDeleteNews, UserCharsCalenderListFields, UserCharsGuestbookListFields,
      UserEmailCopyToOwnAdress, UserFirstDayOfWeek) VALUES ('$UserName', '$UserStatus',
      '$UserCurrentPassword', '$UserEmailadress', '$UserSession', '$UserLanguage',
      $UserLastActivityTimestamp, '$UserBackendCalenderListCols', $UserRightEmail,
      $UserRightAddNews, $UserRightEditNews, $UserRightDeleteNews,
      '$UserCharsCalenderListFields', $UserCharsGuestbookListFields,
      $UserEmailCopyToOwnAdress, '$UserFirstDayOfWeek')";
    $resultat = mysql_query($SQL);
    if ($resultat) return true;
    else return false;
  }
  else return false;
}

function testDoppelteUser ($Username)
{
  global $prefix;
  $string = strtolower($Username);
  $db_select = @mysql_select_db($db_name);
  $sql = 'SELECT * FROM ' .$prefix."user";
  $result = mysql_query($sql);
  $doppelteVorhanden = false;
  $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 TimestampAusDatum ($Tag, $Monat, $Jahr)
{
  $str = $Jahr."-".$Monat."-".$Tag;
  return strtotime($str);
}

function DatumAusTimestamp ($Timestamp)
{ 
  if ( $Timestamp != '' )
  {
    $Tag = date('d', $Timestamp);
    $Monat = date('m', $Timestamp);
    $Jahr = date('Y', $Timestamp);
    return $Tag.".".$Monat.".".$Jahr;
  }
  else return '-';
}

function isDatabasePresent ()
{
  global $db_name;
  if (mysql_select_db($db_name)) return true;
  else return false;
}

function addGig ( $Gig, $Job )
{
  global $prefix;
  global $L_042;
  global $L_107;
  $amountAttributes = count($Gig);
  for ($i=0; $i<$amountAttributes; $i++)
  {
    if ( $i!=13 ) // Notizen werden ausgeklammert
      $Gig[$i]=strip_tags($Gig[$i]);
    // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
      $Gig[$i] = mysql_real_escape_string($Gig[$i]);
  }
  list( $GigID, $GigDateDay, $GigDateMonth, $GigDateYear, $GigEvent, $GigEventURL, $GigEntranceFee,
        $GigLineup, $GigVisitors, $GigStageBuilding, $GigBeginning, $GigDuration, $GigEnding,
        $GigNotes, $GigStatus, $GigPublish, $GigIsPrivate, $GigDateOfLastEdit, $GigLastEditor,
        $GigAddedFrom, $GigDateOfAdding, $GigVenueID, $GigOrganizerID, $GigArtistID )
        = $Gig;
  if ( $GigEventURL=='http://' ) $GigEventURL='';
  if ( $GigEventURL!="" AND !stristr( $GigEventURL, 'http://' ) )
    $GigEventURL = 'http://'.$GigEventURL;
  // Leere numerische Variablen als NULL definieren
    if ( $GigPublish=='' ) $GigPublish=0;
    if ( $GigIsPrivate=='' ) $GigIsPrivate=0;
    if ( $GigDateOfLastEdit=='' ) $GigDateOfLastEdit="NULL";
    if ( $GigDateOfAdding=='' ) $GigDateOfAdding="NULL";
    if ( $GigVenueID=='' ) $GigVenueID="NULL";
    if ( $GigOrganizerID=='' ) $GigOrganizerID="NULL";
    if ( $GigArtistID=='' ) $GigArtistID="NULL";
  $GigDateNew = TimestampAusDatum ($GigDateDay, $GigDateMonth, $GigDateYear);
  if ( $Job=="add" )
  {
    if ($GigDateNew != -1)
    {
        $SQL = "INSERT INTO ".$prefix."gigs
        (
          GigDate, GigEvent, GigEventURL, GigEntranceFee, GigLineup, GigVisitors, GigStageBuilding,
          GigBeginning, GigDuration, GigEnding, GigNotes, GigStatus, GigPublish, GigIsPrivate,
          GigDateOfLastEdit, GigLastEditor, GigAddedFrom, GigDateOfAdding, GigVenueID,
          GigOrganizerID, GigArtistID
        )
        VALUES
        (
          '$GigDateNew', '$GigEvent', '$GigEventURL', '$GigEntranceFee', '$GigLineup',
          '$GigVisitors', '$GigStageBuilding', '$GigBeginning', '$GigDuration', '$GigEnding',
          '$GigNotes', '$GigStatus', $GigPublish, $GigIsPrivate, $GigDateOfLastEdit,
          '$GigLastEditor', '$GigAddedFrom', $GigDateOfAdding, $GigVenueID, $GigOrganizerID,
          $GigArtistID)";
        $resultat = mysql_query($SQL);
        if ($resultat) { deleteFileInCache($GigDateNew); return true; }
        else return false;
    }
    else
    {
      echo "ERROR: The date is wrong! (Timestamp -1) ".DatumAusTimestamp($GigDateNew)."<br />";
      return false;
    }
  }
  if ( $Job=="edit" )
  {
    if (  getGigVarFromGigID ($GigID, 'GigDate') == $GigDateNew)
    {
      $GigLastEditor = getCurrentUserVar("UserName");
      $GigDateOfLastEdit = date("U");
      $SQL = "UPDATE ".$prefix."gigs SET
        GigEvent = '$GigEvent', GigEventURL = '$GigEventURL', GigEntranceFee = '$GigEntranceFee',
        GigLineup = '$GigLineup', GigVisitors = '$GigVisitors',
        GigStageBuilding = '$GigStageBuilding', GigBeginning = '$GigBeginning',
        GigDuration = '$GigDuration', GigEnding = '$GigEnding', GigNotes = '$GigNotes',
        GigStatus = '$GigStatus', GigPublish = $GigPublish, GigIsPrivate = $GigIsPrivate,
        GigDateOfLastEdit = $GigDateOfLastEdit, GigLastEditor = '".getCurrentUserVar('UserName')."',
        GigVenueID = $GigVenueID, GigOrganizerID = $GigOrganizerID, GigArtistID = 'GigArtistID
        WHERE GigID = $GigID LIMIT 1";
      $resultat = mysql_query($SQL);
      if ($resultat) { deleteFileInCache($GigDateNew); return true; }
      else return false;
    }
    else
    {
      $GigDateOld = getGigVarFromGigID ($GigID, 'GigDate');
      $SQL = "UPDATE ".$prefix."gigs SET
        GigDate = $GigDateNew, GigEvent = '$GigEvent', GigEventURL = '$GigEventURL',
        GigEntranceFee = '$GigEntranceFee', GigLineup = '$GigLineup', GigVisitors = '$GigVisitors',
        GigStageBuilding = '$GigStageBuilding', GigBeginning = '$GigBeginning',
        GigEnding = '$GigEnding', GigNotes = '$GigNotes', GigStatus = '$GigStatus',
        GigPublish = $GigPublish, GigIsPrivate = $GigIsPrivate,
        GigDateOfLastEdit = $GigDateOfLastEdit, GigVenueID = $GigVenueID,
        GigOrganizerID = $GigOrganizerID, GigArtistID = $GigArtistID
        WHERE GigID = $GigID LIMIT 1";
      $resultat = mysql_query($SQL);
      if ($resultat)
      {
        deleteFileInCache($GigDateOld);
        deleteFileInCache($GigDateNew);
        echo $L_107."<br />";
        return true;
      }
      else return false;
    }
  }
}

function editUser ($UserName, $UserStatus, $UserCurrentPassword, $UserEmailadress, $UserNameOld,
  $UserLanguage, $UserBackendCalenderListCols, $UserRightEmail, $UserRightAddNews,
  $UserRightEditNews, $UserRightDeleteNews, $UserFirstDayOfWeek)
{
  global $prefix;
  // HTML-Tags entfernen
    $UserName = strip_tags($UserName);
    $UserCurrentPassword = strip_tags($UserCurrentPassword);
    $UserEmailadress = strip_tags($UserEmailadress);
    $UserNameOld = strip_tags($UserNameOld);
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $UserName = mysql_real_escape_string($UserName);
    $UserCurrentPassword = mysql_real_escape_string($UserCurrentPassword);
    $UserEmailadress = mysql_real_escape_string($UserEmailadress);
    $UserNameOld = mysql_real_escape_string($UserNameOld);
  // Leere numerische Variablen als NULL definieren
    if ( $UserRightEmail=='' ) $UserRightEmail=0;
    if ( $UserRightAddNews=='' ) $UserRightAddNews=0;
    if ( $UserRightEditNews=='' ) $UserRightEditNews=0;
    if ( $UserRightDeleteNews=='' ) $UserRightDeleteNews=0;
    // später aktivieren: if ( $UserEmailCopyToOwnAdress=='' ) $UserEmailCopyToOwnAdress=1;
  $SQL = "UPDATE ".$prefix."user SET
    UserName = '$UserName', UserStatus = '$UserStatus',
    UserCurrentPassword = '$UserCurrentPassword', UserEmailadress = '$UserEmailadress',
    UserLanguage = '$UserLanguage', UserBackendCalenderListCols = '$UserBackendCalenderListCols',
    UserRightEmail = $UserRightEmail, UserRightAddNews = $UserRightAddNews, UserRightEditNews = $UserRightEditNews,
    UserRightDeleteNews = $UserRightDeleteNews, UserFirstDayOfWeek = '$UserFirstDayOfWeek'
    WHERE UserName = '$UserNameOld'
    LIMIT 1";
  $resultat = mysql_query($SQL);
  if ($resultat) return true;
  else return false;
}

function editCurrentUser ($UserCurrentPassword, $UserEmailadress, $UserLanguage, $UserFirstDayOfWeek )
{
  global $prefix;
  // Cache löschen
    if ( $UserFirstDayOfWeek!=getCurrentUserVar('UserFirstDayOfWeek')) echo 'Cache leeren<br />';
  // HTML- und PHP-Tags entfernen
    $UserCurrentPassword = strip_tags($UserCurrentPassword);
    $UserEmailadress = strip_tags($UserEmailadress);
  // Maskieren spezieller Zeichen für die Verwendung in einer SQL-Anweisung
    $UserCurrentPassword = mysql_real_escape_string($UserCurrentPassword);
    $UserEmailadress = mysql_real_escape_string($UserEmailadress);
  $SQL = "UPDATE ".$prefix."user SET UserCurrentPassword = '$UserCurrentPassword',
    UserEmailadress = '$UserEmailadress', UserLanguage = '$UserLanguage',
    UserFirstDayOfWeek = '$UserFirstDayOfWeek' WHERE UserName = '".getCurrentUser()."'
    LIMIT 1";
  $resultat = mysql_query($SQL);
  if ($resultat) return true;
  else return false;
}

function DatumInZukunft ($Timestamp)
{
  $TimestampVonHeute = TimestampAusDatum(date("d"), date("m"), date("y"));
  if ($Timestamp >= $TimestampVonHeute) return true;
    else return false;
}

function CheckGigStatusDesTages ($Timestamp)
{
  global $prefix;
  $GigStatus = "";
  $SQL = "SELECT * FROM ".$prefix."gigs WHERE GigDate = ".$Timestamp." LIMIT 1";
  $resultat = mysql_query($SQL);
  while ($row = mysql_fetch_array($resultat)) 
    extract($row);
  if ($GigStatus!='') return $GigStatus;
    else return 'Normal';
}

function AnzahlTagedesMonats ($Monat, $Jahr)
{
  $unixtimestamp = mktime(0, 0, 0, $Monat, 1 , $Jahr);
  return date('t', $unixtimestamp);
}

function WochentagsNameVonTimestamp ($Timestamp)
{
  global $L_Monday;
  global $L_Tuesday;
  global $L_Wednesday;
  global $L_Thursday;
  global $L_Friday;
  global $L_Saturday;
  global $L_Sunday;
  return ${"L_".date('l', $Timestamp)};
}

function WochentagsNameVonDatum ($Tag, $Monat, $Jahr)
{
  $wochentage = Array ( 'Sunday', 'Monday','Tuesday','Wednesday', 'Thursday', 'Friday',
    'Saturday' );
  $unixtimestamp = mktime(0, 0, 0, $Monat, $Tag, $Jahr);
  $wochentag = date('w', $unixtimestamp);
  return $wochentage[$wochentag];
}

function WochentagVonDatum ($Tag, $Monat, $Jahr)
{
  $unixtimestamp = mktime(0, 0, 0, $Monat, $Tag, $Jahr);
  $wochentag = date('w', $unixtimestamp);
  if($wochentag == 0) $wochentag = 7;
  return $wochentag;
}

function MonatsNameVonDatum ($Monat)
{
  if($Monat == 1) {global $L_January; $Monatsname = $L_January;}
  else if($Monat == 2) {global $L_February; $Monatsname = $L_February;}
  else if($Monat == 3) {global $L_March; $Monatsname = $L_March;}
  else if($Monat == 4) {global $L_April; $Monatsname = $L_April;}
  else if($Monat == 5) {global $L_May; $Monatsname = $L_May;}
  else if($Monat == 6) {global $L_June;  $Monatsname = $L_June;}
  else if($Monat == 7) {global $L_July; $Monatsname = $L_July;}
  else if($Monat == 8) {global $L_August; $Monatsname = $L_August;}
  else if($Monat == 9) {global $L_September; $Monatsname = $L_September;}
  else if($Monat == 10) {global $L_October; $Monatsname = $L_October;}
  else if($Monat == 11) {global $L_November; $Monatsname = $L_November;}
  else if($Monat == 12) {global $L_December; $Monatsname = $L_December;}
  return $Monatsname;
}
?>
Return current item: GigKalender