<?php


  ini_set('max_execution_time', '0');

  include "version_config_batch.php";

  $conn = odbc_connect($odbc, $user, $pw);

  $ersatzstring = '';

        for ( $i = 0; $i < count($ViewArr); $i++ ) {
                $sql = 'SELECT ' . $VersionFPFeld . ', ' . $VersionViewFeld . ' FROM cobra.' . $ViewArr[$i] . ';';
print $sql."\n";
    $rs = odbc_exec($conn, $sql);

    odbc_fetch_row($rs);

                if ( $i == 0 ) {
                        $field = odbc_result($rs,$VersionFPFeld);
                        //session_register('versionFP');
                        //$versionFP = $field;
                        //echo "$VersionFPFeldString$field<br>";
                        $ersatzstring .= '"' . $VersionFPFeldString ." ". $field . '", ';
    }


    $field = odbc_result($rs,$VersionViewFeld);
                $str = 'versionView' . $i;
                //session_register($str);
                $$str = $field;
    //echo "$VersionViewFeldString $viewsBezeichnungen[$i]: $field<br>";
    if ( $i == count($ViewArr)-1 ) {
      $ersatzstring .= '"' . $VersionViewFeldString . '&nbsp;' . $ViewDescArr[$i] . ': ' . $field . '"';
    } else {
      $ersatzstring .= '"' . $VersionViewFeldString . '&nbsp;' . $ViewDescArr[$i] . ': ' . $field . '", ';
    }
  }

  $fname = 'version_config.php';

  $fd = fopen($fname, 'r+');
  $str = fread($fd, filesize($fname));
  fclose($fd);


  $str = preg_replace('/(\$vver = array\().*(\);)/', '$1' . $ersatzstring . '$2', $str);

  $fd = fopen($fname, 'w');
  fwrite($fd, $str);
  fclose($fd);

?>