Location: PHPKode > projects > WebETB > stats/export.php4
<?php
/******************************************************************************/
/*	MODUL:	stats/export.php4       														*/
/*																										*/
/* DATUM:	27.03.2006, Version 0.1															*/
/* BESCHR.:	Einsatztagebuch ins CSV-Format exportieren                        */
/*																										*/
/*	AUTOR:   Marcus Groh																			*/
/*	LIZENZ:  GPL v2 vom Juni 1991 															*/
/*																										*/
/*	AENDERUNGEN:	13.01.2006        -initiale Version								   */
/*                27.03.2006 v 0.1, -Versionskennzeichnung eingefuehrt        */
/*                                  -Code unter GPL v2 gestellt               */
/*                                  -Tabellenname dynamisiert                 */
/*																										*/
/******************************************************************************/
$allowed_groups=array("elw");
include ('../_include/header_1.php4');

   $myfile="../tmp/etb_export.csv.gz";
   $EXP_FILE=$exp_path.$myfile;
   $FS="~";
   
   
   // open export-file and lock it
   $fp = gzopen($EXP_FILE, "w9");
   flock ( $fp, LOCK_EX);
   
   // CSV-Header
   $CSV_HEAD="Lfd-Nr.".$FS."Datum".$FS."Zeit".$FS."Von".$FS."An".$FS."Text".$FS."Bemerkung".$FS."Bezug".$FS."Bearbeiter";
   gzwrite($fp, $CSV_HEAD ."\n");
   
   // Get data out of db
   $select_etb_log="select * from $T_etb where eid=$eid order by lfdnr";
   $result_etb_log=@mysql_db_query($database["database"],$select_etb_log,$db);
   while ( $row=mysql_fetch_array($result_etb_log) )
   {
           // sort fields
        $lfdnr=$row['lfdnr'];
        $von_kid=$row['von_kid'];
        $an_kid=$row['an_kid'];
        $von_txt=$row['von_txt'];
        $an_txt=$row['an_txt'];
        list ($Y, $M, $D) = split ('[/.-]', $row['datum']);
        $datum="$D-$M-$Y";
        $zeit=$row['zeit'];
        $text=$row['text'];
        $bemerkung=$row['bemerkung'];
        $bezug=$row['bezug'];
        $db_uid=$row['uid'];

        // set readable text for field "VON"
        if ( $von_kid == "0" )
        {
              $von=$von_txt;
        }
        else
        {
           $select_von="select rufname from $T_kraefte where eid=$eid and kid=$von_kid";
           $result_von=@mysql_db_query($database["database"],$select_von,$db);
           while ( $row=mysql_fetch_array($result_von) )
           {
              $von=$row['rufname'];
           }
        }

        // set readable text for field "AN"
        if ( $an_kid == "0" )
        {
              $an=$an_txt;
        }
        else
        {
           $select_an="select rufname from $T_kraefte where eid=$eid and kid=$an_kid";
           $result_an=@mysql_db_query($database["database"],$select_an,$db);
           while ( $row=mysql_fetch_array($result_an) )
           {
              $an=$row['rufname'];
           }
        }

        // set readable text for field "BEARBEITER"
        $select_user="select u_name from $T_user where uid=$db_uid";
        $result_user=@mysql_db_query($database["database"],$select_user,$db);
        while ( $row=mysql_fetch_array($result_user) )
        {
           $user=$row['u_name'];
        }

        // set readable text for field "BEZUG"
        $select_bezug="select pat_nr from $T_patient where eid=$eid and pid=$bezug";
        $result_bezug=@mysql_db_query($database["database"],$select_bezug,$db);
        $count_bezug=mysql_num_rows($result_bezug);
        if ( $count_bezug <= 0 )
        {
           $aufgabe="";
        }
        else
        {
            while ( $row=mysql_fetch_array($result_bezug) )
            {
               $aufgabe=$row['pat_nr'];
            }
        }

        // print values
        gzwrite ($fp, $lfdnr.$FS.$datum.$FS.$zeit.$FS.$von.$FS.$an.$FS.$text.$FS.$bemerkung.$FS.$aufgabe.$FS.$user."\n");
   }       


   // close export-file
   gzclose($zp);
   
   // put file to browser
   echo "<meta http-equiv=\"refresh\" content=\"3; URL=$myfile\">\n";
   ?>
   <br>
   <center>
   <p>Export wurde erstellt. Sollte der download nicht in wenigen Sekunden starten, klicken Sie bitte <a href="<? echo $myfile; ?>">hier</a></p>
   </center>
   <?

   // unlock and delete export-file
   flock ( $fp, LOCK_UN);
   #unlink ($EXP_FILE);

include ('../_include/footer_1.php4');
?>

Return current item: WebETB