<?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 iniSetup ()
  {
    global $allBackendCalenderFormAttributes;
    global $CharsSetupNewsChannelCopyright;
    global $CharsSetupNewsChannelDescription;
    global $CharsSetupNewsChannelLanguage;
    global $CharsSetupNewsChannelTitle;
    global $CharsURLs;
    
    global $GIGKALENDERPATH;
    global $DB_PREFIX;
    global $StandardFrontendAttributes;
    global $StandardFrontendDetailAttributes;
    global $language;

    switch ( substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 3, 2) )
    {
      case 'US': $DateFormat = 'm/d/Y'; $TimeFormat = 'H:i'; $FirstDayOfWeek='Sunday'; break;
      case 'CA': $DateFormat = 'm/d/Y'; $TimeFormat = 'H:i'; $FirstDayOfWeek='Sunday'; break;
      case 'AU': $DateFormat = 'm/d/Y'; $TimeFormat = 'H:i'; $FirstDayOfWeek='Sunday'; break;
      case 'DE': $DateFormat = 'd.m.Y'; $TimeFormat = 'H:i'; $FirstDayOfWeek='Monday'; break;
      default: $DateFormat = 'Y-m-d'; $TimeFormat = 'H:i'; $FirstDayOfWeek='Monday';
    }
    // Define Fieldnames, Types and Values

    $Array = array(
                    // General
                    'SetupGeneralBackendUseCache' => array ( 'TINYINT(1)', true),
                    'SetupGeneralRefreshtime' => array ( 'TINYINT(2)', 1),
                    'SetupGeneralBackendCSVSeparator' => array ( 'CHAR(1)', ';'),
                    'SetupGeneralBackendInactivityTime' => array ( 'TINYINT(2)', 60),
                    'SetupGeneralBackendDateFormat' => array ( 'CHAR(20)', $DateFormat),
                    'SetupGeneralBackendTimeFormat' => array ( 'CHAR(20)', 'H:i'),
                    'SetupGeneralFrontendLanguage' => array ( 'CHAR(32)', $language),
                    'SetupGeneralFrontendCssFileURL' => array ( 'CHAR('.$CharsURLs.')', '../styles/gigkalender.css'),
                    // Calendar
                    'SetupAllowDoubleDates' => array ( 'TINYINT(1)', 1),
                    'SetupRowsTextareas' => array ( 'TINYINT(2)', 5),
                    'SetupShowEditorInAddGigForm' => array ( 'TINYINT(1)', 1),
                    'SetupBackendCalendarGigTypes' => array ( 'TEXT', 'Gig, 37A537, Blocked, C80000, Option, DC6D00, Rehearsal, 0000bb'),
                    'SetupCalendarAttributeInAddGigForm' => array ( 'TEXT', $allBackendCalenderFormAttributes),
                    'SetupFrontendCalendarShowMonthlySeparator' => array ( 'TINYINT(1)', 1),
                    'SetupFrontendCalendarShowTableHeads' => array ( 'TINYINT(1)', 1),
                    'SetupFrontendAllowOptionalGigs' => array ( 'TINYINT(1)', 0),
                    'SetupFrontendAllowPrivateGigs' => array ( 'TINYINT(1)', 0),
                    'SetupFrontendCalendarCurrentMonthShowPastGigs' => array ( 'TINYINT(1)', true),
                    'SetupFrontendCalendarGigDetailsShowEmptyAttributes' => array ( 'TINYINT(1)', false),
                    'SetupFrontendCalendarSelector' => array ( 'CHAR(10)', 'list'),
                    'SetupFrontendFirstDayOfWeek' => array ( 'CHAR(9)', $FirstDayOfWeek),
                    'SetupFrontendCalendarPeriodSelector' => array ( 'CHAR(10)', 'future'),
                    'SetupFrontendCalendarCharsInFields' => array ( 'INT', 20),
                    'SetupFrontendCalendarMaxAmountOfGigs' => array ( 'INT', 999),
                    'SetupFrontendCalendarMaxAmountOfGigsPast' => array ( 'INT', 999),
                    'SetupFrontendCalendarDateFormat' => array ( 'CHAR(20)', $DateFormat),
                    'SetupFrontendCalendarGigDetailsDateFormat' => array ( 'CHAR(20)', $DateFormat.' '.$TimeFormat),
                    'SetupFrontendCalendarCurrentMonthLimitFuture' => array ( 'TINYINT(2)', 12),
                    'SetupFrontendCalendarCurrentMonthLimitPast' => array ( 'TINYINT(2)', 6),
                    'SetupFrontendCalendarURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupFrontendCalendarGigDetailsURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupFrontendCalendarCurrentMonthURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupFrontendAttributes' => array ( 'TEXT', $StandardFrontendAttributes),
                    'SetupFrontendDetailAttributes' => array ( 'TEXT', $StandardFrontendDetailAttributes),
                    'SetupFrontendCalendarExternalLinks' => array ( 'TINYINT(1)', '1'),
                    // Guestbook
                    'SetupGuestbookEntriesUnlock' => array ( 'TINYINT(1)', 1),
                    'SetupGuestbookWriteSpamLog' => array ( 'TINYINT(1)', false),
                    'SetupGuestbookEntriesPerPage' => array ( 'TINYINT(2)', 10),
                    'SetupGuestbookMail' => array ( 'CHAR(50)', 'mail@max-mustermann.xyz'),
                    'SetupGuestbookURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupGuestbookFormURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupGuestbookEmailURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupGuestbookSpamDomains' => array ( 'TEXT', 'rubyurl.com'),
                    'SetupGuestbookSpamIPs' => array ( 'TEXT', '212.12.41.130'),
                    'SetupGuestbookSpamWords' => array ( 'TEXT', 'pussy, porn, fetish, anal, gay, ilovecoolgirl, adultsitepoint, sexpasspussy, showforlove, lesbian, viagra, nude, tits, tgp, teenundressed, fucking, busty, hardcore, doyoulovepussy'),
                    'SetupFrontendGuestbookDateFormat' => array ( 'CHAR(20)', $DateFormat.' - H:i'),
                    // News
                    'SetupNewsEntriesPerPage' => array ( 'TINYINT(2)', 10),
                    'SetupNewsChannelTitle' => array ( 'CHAR('.$CharsSetupNewsChannelTitle.')', 'Band-News'),
                    'SetupNewsChannelURL' => array ( 'CHAR('.$CharsURLs.')', GIGKALENDERPATH.'frontend/example_news.php'),
                    'SetupNewsChannelDescription' => array ( 'CHAR('.$CharsSetupNewsChannelDescription.')', 'Band-News...'),
                    'SetupNewsChannelLanguage' => array ( 'CHAR('.$CharsSetupNewsChannelLanguage.')', substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5)),
                    'SetupNewsChannelCopyright' => array ( 'CHAR('.$CharsSetupNewsChannelCopyright.')', 'Max Mustermann'),
                    'SetupFrontendNewsDateFormat' => array ( 'CHAR(20)', $DateFormat.' - H:i'),
                    // Gallery
                    'SetupGalleryAlbumsThumbsRandomly' => array ( 'TINYINT(1)', 1),
                    'SetupGalleryAlbumsOrder' => array ( 'CHAR(20)', ''),
                    'SetupFrontendGalleryURL' => array ( 'CHAR('.$CharsURLs.')', ''),
                    'SetupGalleryAlbumsThumbsHeight' => array ( 'INT', 100),
                    'SetupGalleryAlbumsThumbsWidth' => array ( 'INT', 100)
                  );
    // Define MySQL state to crate the table
      $SQL1 = 'CREATE TABLE '.DB_PREFIX.'setup ( SetupID INTEGER NOT NULL AUTO_INCREMENT, ';
      $count = count($Array);
      for ($i=0; $i<$count; $i++)
      {
        $key = key($Array);
        $SQL1 .= $key.' '.$Array[$key][0];
        if ($i<=($count-1)) $SQL1 .= ', ';
        next($Array);
      }
      reset($Array);
      $SQL1 .= 'PRIMARY KEY (SetupID)) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci';
    if (mysql_query($SQL1))
    {
        // Define MySQL state to insert values into table
          $SQL2 = 'INSERT INTO '.DB_PREFIX.'setup (';
          for ($i=0; $i<$count; $i++)
          {
            $key = key($Array);
            $SQL2 .= $key;
            if ($i<=($count-2)) $SQL2 .= ', ';
            next($Array);
          }
          reset($Array);
          $SQL2 .= ') VALUES (';
          for ($i=0; $i<$count; $i++)
          {
            $key = key($Array);
            $SQL2 .= "'".$Array[$key][1]."'";
            if ($i<=($count-2)) $SQL2 .= ', ';
            next($Array);
          }
          reset($Array);
          $SQL2 .= ')';

        $resultat = mysql_query($SQL2);
        if ($resultat) return true;
          else return false;
        // return true;
      }
      else return false;
  }
?>