<?
  include ('../functions.php');
  repairbeschreibungen();
  exit;

  $query = "SELECT * FROM praemien, praemienartikel
    WHERE praemien.id= praemienartikel.praemienid
    AND praemien.status = 'ACTIVE'
    AND praemien.geldpraemie = 0";

  $result = mysql_query($query) or error ('Cannot select ' . $query);
  $first = true;
  while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
      if ($first) {
          foreach (array_keys($row) as $key) {
              print utf8_encode($key) . ';';
          }
          print "\n";
          $first = false;
      }

      foreach (array_keys($row) as $key) {
          $value = str_replace("\r",' ', 
                       str_replace("\n",' ',
                           utf8_encode($row[$key])
                       )
                   );
          $value = str_replace('"','',$value);
          print '"'. $value .'";';
      }
      print "\n";
  }


function repairbeschreibungen() {
    $query = 'SELECT id, name, beschreibung FROM praemien WHERE 1';
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        $id = $row['id'];
        $name = $row['name'];
        $beschreibung = $row['beschreibung'];
        $name = html_entity_decode($name,ENT_QUOTES,'ISO-8859-15');
        $beschreibung = html_entity_decode($beschreibung,ENT_QUOTES,'ISO-8859-15');
        $subquery = "UPDATE praemien
                     SET name = '" . _mysqlescapestring($name) . "',
                         beschreibung = '" . _mysqlescapestring($beschreibung) . "'
                     WHERE id = $id";
        mysql_query($subquery) or error("Kann nicht updaten: $subquery");
    }
}
?>

