|
1 <?php |
|
2 |
|
3 /** |
|
4 * @author Bettina Schwarzer, Fritz-Haber-Institut |
|
5 * @copyright 04/2012 |
|
6 * |
|
7 * Export Vertragsliste als csv-File |
|
8 * |
|
9 */ |
|
10 |
|
11 error_reporting(E_ALL ^ E_NOTICE); |
|
12 |
|
13 include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/dbconnect.inc.php"); |
|
14 if (!isset($dbc) || !$dbc) $dbc = new dbconnection(); |
|
15 |
|
16 $sort = $_GET["s"]; // Sortierung nach Spalte |
|
17 if (!$sort) $sort = 2; |
|
18 $dir = $_GET["d"]; // Sortierrichtung |
|
19 if (!$dir) $dir = ''; |
|
20 $fnum = $_GET["f"]; // Spaltennummer, nach der aktuell gefiltert wird |
|
21 if (!$fnum) $fnum = 1; |
|
22 $filter = $_GET["b"]; // Filterbegriff |
|
23 if (!$filter) $filter = ''; |
|
24 $start = $_GET["st"]; // Start-DS - 1 |
|
25 if (!$start) $start = 0; |
|
26 $zeil = $_GET["z"]; // Anzahl zu zeigender DS |
|
27 if (!$zeil) $zeil = 9999; |
|
28 $listg = $_GET["l"]; // Recht fuer ausgewaehlte Produktgruppen |
|
29 if (!$listg) $listg = ''; |
|
30 |
|
31 $sql = "CALL fhiiqm.vertrag_flist12(" . $sort . ",'" . $dir . "', " . $fnum . ", '" . $filter . "', '" . $listg . "',$start,$zeil, @anz, @ganz)"; |
|
32 |
|
33 $result = $dbc ->queryObjectArray($sql); |
|
34 |
|
35 if ($result) |
|
36 { |
|
37 $crlf = array("\r\n","\n\r","\r","\n"); // Zeilenumbrueche |
|
38 $file ="Vertrag-ID;Bezeichnung;Beschreibung;Typ;zu Produkt;Partner;Bearbeiter;Beginn;Ende;Verlängerung;Künd.Frist(mon);Bemerkung;E-Mail?;Jahr;Kosten\r\n"; |
|
39 |
|
40 foreach ($result as $row) |
|
41 { |
|
42 $file .= $row->contract_ID . ";"; |
|
43 $file .= $row->cname . ";"; |
|
44 $file .= str_replace($crlf,", ",$row->clong) . ";"; |
|
45 $file .= $row->typ . ";"; |
|
46 $file .= str_replace(";",":",$row->prod) . ";"; |
|
47 $file .= $row->partfirma . ";"; |
|
48 $file .= str_replace(";",":",$row->bearb) . ";"; |
|
49 if ($row->cbegin) |
|
50 { |
|
51 $cb = new DateTime($row->cbegin); |
|
52 $file .= $cb->format('d.m.Y').";"; |
|
53 } |
|
54 else $file .= ";"; |
|
55 if ($row->cend) |
|
56 { |
|
57 $cb = new DateTime($row->cend); |
|
58 $file .= $cb->format('d.m.Y').";"; |
|
59 } |
|
60 else $file .= ";"; |
|
61 if ($row->cautoend) $file .= "automatisch;"; else $file .= ";"; |
|
62 $file .= $row->kmon . ";"; |
|
63 $file .= str_replace(";",":",str_replace($crlf,", ",$row->bem)) . ";"; |
|
64 if ($row->email) $file .= "ja;"; else $file .= ";"; |
|
65 |
|
66 if ($row->yearkosten) |
|
67 { // Form: yyyy:nnn.nn|yyyy:nnnnn|yyyy:nn.n usw. |
|
68 $yka = explode('|',$row->yearkosten); |
|
69 $first = true; |
|
70 foreach ($yka as $yk) |
|
71 { |
|
72 if (!$first) $file .= "\r\n$row->contract_ID;;;;;;;;;;;;;"; |
|
73 list($year,$kost) = explode(':',$yk); |
|
74 $file .= $year .";" .number_format($kost,2,",",".") . ";"; |
|
75 $first = false; |
|
76 } |
|
77 } |
|
78 else $file .= ";;"; |
|
79 $file .= "\r\n"; |
|
80 } |
|
81 |
|
82 header( 'Content-Type: text/csv' ); |
|
83 header('Content-Disposition: attachment; filename="vertrag.csv"'); |
|
84 header("Content-Length: " . strlen($file)); |
|
85 |
|
86 echo $file; |
|
87 } |
|
88 else echo "kein Ergebnis!"; |
|
89 ?> |