fhiiqm/vertrag_list12_csv.php
author Bettina Schwarzer <schwarzer@fhi-berlin.mpg.de>
Thu, 23 Aug 2012 10:17:50 +0200
changeset 29 72f79dab938e
parent 26 3c1e3ac7089f
permissions -rw-r--r--
+ Infotyp 7,8,81, Info-Report, Reports AS, Menu anpassen

<?php

/**
 * @author Bettina Schwarzer, Fritz-Haber-Institut
 * @copyright 04/2012
 * 
 * Export Vertragsliste als csv-File
 * 
 */

    error_reporting(E_ALL ^ E_NOTICE);
    
    include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/dbconnect.inc.php");
    if (!isset($dbc) || !$dbc) $dbc = new dbconnection();
    
	$sort   = $_GET["s"];   // Sortierung nach Spalte
    if (!$sort) $sort   = 2;
    $dir    = $_GET["d"];   // Sortierrichtung
    if (!$dir) $dir    = '';
    $fnum   = $_GET["f"];   // Spaltennummer, nach der aktuell gefiltert wird
    if (!$fnum) $fnum   = 1;
    $filter = $_GET["b"];   // Filterbegriff 
    if (!$filter) $filter = '';
    $start = $_GET["st"];   // Start-DS - 1
    if (!$start) $start  = 0;
    $zeil = $_GET["z"];     // Anzahl zu zeigender DS
    if (!$zeil) $zeil   = 9999;
    $listg  = $_GET["l"];   // Recht fuer ausgewaehlte Produktgruppen
    if (!$listg) $listg = '';

    $sql = "CALL fhiiqm.vertrag_flist12(" . $sort . ",'" . $dir . "', " . $fnum . ", '" . $filter . "', '" . $listg . "',$start,$zeil, @anz, @ganz)";

    $result = $dbc ->queryObjectArray($sql);

    if ($result)
    {
        $crlf = array("\r\n","\n\r","\r","\n"); // Zeilenumbrueche
        $file ="Vertrag-ID;Partner;Bezeichnung;Beschreibung;Typ;zu Produkt;Bearbeiter;Beginn;Ende;Verlängerung;Künd.Frist(mon);Bemerkung;E-Mail?;Jahr;Kosten\r\n";

        foreach ($result as $row)
        {
            $file .= $row->contract_ID . ";";
            $file .= $row->partfirma . ";";
            $file .= $row->cname . ";";
            $file .= str_replace($crlf,", ",$row->clong) . ";";
            $file .= $row->typ . ";";
            $file .= str_replace(";",":",$row->prod) . ";";
            $file .= str_replace(";",":",$row->bearb) . ";";
            if ($row->cbegin)
            {
                $cb = new DateTime($row->cbegin);    
                $file .= $cb->format('d.m.Y').";";
            }
            else $file .= ";";
            if ($row->cend)
            {
                $cb = new DateTime($row->cend);    
                $file .= $cb->format('d.m.Y').";";
            }
            else $file .= ";";
            if ($row->cautoend) $file .= "automatisch;"; else $file .= ";";
            $file .= $row->kmon . ";";
            $file .= str_replace(";",":",str_replace($crlf,", ",$row->bem)) . ";";
            if ($row->email) $file .= "ja;"; else $file .= ";";   
            
            if ($row->yearkosten)
            {   // Form: yyyy:nnn.nn|yyyy:nnnnn|yyyy:nn.n usw. 
                $yka = explode('|',$row->yearkosten);
                $first = true;
                foreach ($yka as $yk)
                {
                    if (!$first) $file .= "\r\n$row->contract_ID;;;;;;;;;;;;;"; 
                    list($year,$kost) = explode(':',$yk);
                    $file .= $year .";" .number_format($kost,2,",",".") . ";";
                    $first = false; 
                }
            }
            else $file .= ";;";    
            $file .= "\r\n";
        }

        header( 'Content-Type: text/csv' );
        header('Content-Disposition: attachment; filename="vertrag.csv"');
        header("Content-Length: " . strlen($file));

        echo $file;
    }
    else echo "kein Ergebnis!";
?>