<?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.
*/
  global $db;
  global $prefix;
  global $exportDirectory;
  $datei = $exportDirectory.'/'.$Table.'.csv';
  $fp=fopen($datei,"w+");
  // Header definieren
    $Spalten = array ();
    $Header = array ();
    for ($i=0; $i<count($Array); $i++)
    {
      $key = key ( $Array );
      if ( $Array[$key][1]==1 )
      {
        array_push ($Spalten, $key);
        $var = $Array[$key][0];
        $var = optimizeString ($var);
        array_push ($Header, $var);
      }
      next ( $Array );
    }
    $String = implode(getSetup('SetupExportSeparator'),$Header) . "\n";
    if (!fwrite($fp,$String)) echo '<span class="ErrorMessage">ERROR: Can NOT write the file! ('.$Table.'.csv)</span><br />';
    else
    {
      // Daten ausgeben
        $SQLQuery = "SELECT * FROM ".$prefix.$Table;
        $Result = mysqli_query($db, $SQLQuery);
        while ($row = mysqli_fetch_array($Result))
        {
          extract($row);
          $Zeile = array ();
          for ($i=0; $i<count($Spalten); $i++)
          {
            $key = $Spalten[$i];
            $pos = $$key;
            if ( $Array[$key][2]==1 ) $pos = optimizeString ($pos);
            else include ('functions/export/optimize_'.$Table.'.php');
            array_push ($Zeile, $pos);
          }
          $String = implode(getSetup('SetupExportSeparator'),$Zeile) . "\n";
          fwrite($fp,$String);
        }
    }
    fclose ($fp);
?>
