<?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_PREFIX;
  $path = 'export';
  $datei = $path.'/'.$Table.'.csv';
  $fp=fopen($datei,"w+");
  // Header definieren
    $Spalten = array ();
    $Header = array ();
    $amountArrayItems = count($Array);
    for ($i=0; $i<$amountArrayItems; $i++)
    {
      $key = key ( $Array );
      if ( $Array[$key][1]==1 )
      {
        array_push ($Spalten, $key);
        $var = $Array[$key][0];
        $var = optimizeExportString ($var);
        array_push ($Header, $var);
      }
      next ( $Array );
    }
    $String = implode(getSetup('SetupExportSeparator'),$Header) . "\n";
    if (!fwrite($fp,$String)) echo '<span class="ERROR">ERROR: Can NOT write the file! ('.$Table.'.csv)</span><br />';
    else
    {
      // Daten ausgeben
        $sql = "SELECT * FROM ".$prefix.$Table;
        $result = mysql_query($sql);
        while ($row = mysql_fetch_array($result))
        {
          extract($row);
          $Zeile = array ();
          $amountSpalten = count($Spalten);
          for ($i=0; $i<$amountSpalten; $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);
?>
