Subversion Repositories public

Rev

Blame | Last modification | View Log | RSS feed

<?
require_once('version.inc');
require_once('dbaccess.inc');
require_once('language.inc');
require_once('helper.inc');
require_once('crypt.inc');
require_once('settings.inc');

$knopf = 0;
$func = $_REQUEST['func'];

# Auswertungsmenue
if (isset($_REQUEST['auswertung'])) { $knopf = 27; $headline = 31; }

$drm = array(true, false, false, false, false, true, false);

$helvN = 0;
$helvB = 0;
$page = 0;
$SearchPath = "/usr/share/fonts/afms/adobe";
$pwidth = 842;
$pheight = 595;
//$pwidth = 595;
//$pheight = 842;
$fact = -1;             // Seitenscalierungsfaktor

//require_once('menu.inc');
require_once('knumber.inc');
require_once('tempplan.inc');

# This module contains the following functions:
#    HeadLine
#    ZSumPDF
#    CellPDF
#    ProjektMaPDF
#    MitarbeiterPjPDF
#    PrintListPDF

# Statische Kopfzeile schreiben
#
function HeadLine($ps) {
        global $helvN;
        global $helvB;
        global $page;
        global $pwidth;
        global $pheight;
        global $strVersion;
        global $SearchPath;
        global $title_str;
        global $fact;

        $page++;

        PS_begin_page($ps, $pheight, $pwidth);          // Page: A4 landscape
        PS_translate($ps, $pheight, 0);
        PS_rotate($ps, 90);

        PS_setfont($ps, $helvN, 8.0);
        PS_setlinewidth($ps, 0.4);
        PS_show_xy($ps, "$title_str v" . $strVersion, 10, $pheight - 15);
        $datum = date("j.n.Y", time());
        $len = PS_stringwidth($ps, $datum);
        PS_show_xy($ps, $datum, ($pwidth / 2) - ($len / 2), $pheight - 15);
        $text = "Seite $page";
        $len = PS_stringwidth($ps, $text);
        PS_show_xy($ps, $text, $pwidth - 10 - $len, $pheight - 15);

        if ($fact > -1)
           PS_scale($ps, $fact, 1);
}

# Zeilensumme ausgeben
#
function ZSumPDF($ps, $sumi, $sump, $x, $y, $width) {
        global $helvB;
        global $helvN;
        $fields_3 = $_REQUEST['fields_3'];
        $fields_4 = $_REQUEST['fields_4'];
        $fields_5 = $_REQUEST['fields_5'];

        PS_setcolor($ps, "fill", "gray", 0.8, 0.0, 0.0, 0.0);
        PS_setfont($ps, $helvB, 10.0);

        if ($fields_4 > 0) {
           $num = FormatNum($sumi, 3);
           $len = PS_stringwidth($ps, $num);
           PS_rect($ps, $x - 2, $y - 1, $width + 4, 10);
           PS_fill($ps);
           PS_rect($ps, $x - 2, $y - 1, $width + 4, 10);
           PS_stroke($ps);
           PS_show_xy($ps, $num, $x + $width - $len, $y);
           $x += $width + 4;
        }

        if ($fields_3 > 0) {
           $num = FormatNum($sump - $sumi, 3);
           $len = PS_stringwidth($ps, $num);
           PS_moveto($ps, $x - $len - 2, $y);
           PS_rect($ps, $x - 2, $y - 1, $width + 4, 10);
           PS_fill($ps);
           PS_rect($ps, $x - 2, $y - 1, $width + 4, 10);
           PS_stroke($ps);
           PS_show_xy($ps, $num, $x + $width - $len, $y);
           $x += $width + 4;
        }

        if ($fields_5 > 0) {
           $num = FormatNum($sump, 3);
           $len = PS_stringwidth($ps, $num);
           PS_moveto($ps, $x - $len - 2, $y);
           PS_rect($ps, $x - 2, $y - 1, $width + 4, 10);
           PS_fill($ps);
           PS_rect($ps, $x - 2, $y - 1, $width + 4, 10);
           PS_stroke($ps);
           PS_show_xy($ps, $num, $x + $width - $len, $y);
           $x += $width + 4;
        }

        PS_setcolor($ps, "fill", "gray", 1.0, 0.0, 0.0, 0.0);
        PS_setfont($ps, $helvN, 10.0);
        return $x;
}

# Schreiben einer Zelle
#
function CellPDF($ps, $ist, $plan, $x, $y, $width, $shade, $blank=false) {
        $fields_3 = $_REQUEST['fields_3'];
        $fields_4 = $_REQUEST['fields_4'];
        $fields_5 = $_REQUEST['fields_5'];

        if ($shade)
           PS_setcolor($ps, "fill", "gray", 0.9, 0.0, 0.0, 0.0);
        else
           PS_setcolor($ps, "fill", "gray", 1.0, 0.0, 0.0, 0.0);

        if ($fields_4 > 0) {
           PS_rect($ps, $x-2, $y-1, $width + 4, 10);

           if ($shade) {
              PS_fill($ps);
              PS_rect($ps, $x-2, $y-1, $width + 4, 10);
           }

           PS_stroke($ps);

           if (!$blank) {
              $num = FormatNum($ist, 3);
              $len = PS_stringwidth($ps, $num);
              PS_show_xy($ps, $num, $x + $width - $len, $y);
           }

           $x += $width + 4;
        }

        if ($fields_3 > 0) {
           PS_rect($ps, $x-2, $y-1, $width + 4, 10);

           if ($shade) {
              PS_fill($ps);
              PS_rect($ps, $x-2, $y-1, $width + 4, 10);
           }

           PS_stroke($ps);

           if (!$blank) {
              $num = FormatNum($plan - $ist, 3);
              $len = PS_stringwidth($ps, $num);
              PS_show_xy($ps, $num, $x + $width - $len, $y);
           }

           $x += $width + 4;
        }

        if ($fields_5 > 0) {
           PS_rect($ps, $x-2, $y-1, $width + 4, 10);

           if ($shade) {
              PS_fill($ps);
              PS_rect($ps, $x-2, $y-1, $width + 4, 10);
           }

           PS_stroke($ps);

           if (!$blank) {
              $num = FormatNum($plan, 3);
              $len = PS_stringwidth($ps, $num);
              PS_show_xy($ps, $num, $x + $width - $len, $y);
           }

           $x += $width + 4;
        }

        return $x;
}

# Folgende Funktion erzeugt die Liste aller Projekte. Die Liste
# sortiert nach Projekten und Mitarbeitern (Projektsicht).
#
function ProjektMaPDF($ps, $db, $pr_num, $ystart, $mi_num=0) {
        global $periode;
        global $phase;
        global $helvN;
        global $helvB;
        global $page;
        global $pwidth;
        global $pheight;
        global $SearchPath;
        global $fact;

        $pl_num = $_REQUEST['pl_num'];
        $dfrom = $_REQUEST['dfrom'];
        $dto = $_REQUEST['dto'];
        $fields_0 = $_REQUEST['fields_0'];
        $fields_1 = $_REQUEST['fields_1'];
        $fields_2 = $_REQUEST['fields_2'];
        $fields_3 = $_REQUEST['fields_3'];
        $fields_4 = $_REQUEST['fields_4'];
        $fields_5 = $_REQUEST['fields_5'];
        $fields_6 = $_REQUEST['fields_6'];
        $sort = $_REQUEST['sort'];
        $level = $_REQUEST['level'];
        $pjclosed = $_REQUEST['pjclosed'];
        $scaled = false;

        if (isset($pjclosed) && CheckTrue($pjclosed))
           $pjc = ",6";

        # Festlegen der Spaltenlaengen
        $lenma = PS_stringwidth($ps, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        $lengr = PS_stringwidth($ps, "XXXXXXXXXXXXXXX");
        $lenph = PS_stringwidth($ps, "9: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        $lenta = $lenma;
        $lenan = PS_stringwidth($ps, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        $lence = PS_stringwidth($ps, "999,999");
        $lentotal = 0;

        # Beim bis-Datum den Monatsletzten ermitteln
        $mon = gmdate("n", $dto);
        $year = gmdate("Y", $dto);
        $day = daysinmonth($mon, $year);
        $dto = gmmktime(23, 59, 59, $mon, $day, $year);
        # Den Projektnamen ermitteln
        $query = "select pr_num, pr_name, pr_status from project ";

        if ($pr_num > 0)
           $query .= "where pr_num = $pr_num ";

        $query .= "order by pr_num";
        $respr = QueryDB($db, $query);

        if (!$respr)
           return;

        $numpr = numrowsDB($respr);
        $pospr = 0;

        $pdiff = $fields_3;
        $pist = $fields_4;
        $pplan = $fields_5;
        $mult = 0;
        $y = $ystart;
        $x = 40;

        if ($pist > 0)
           $mult++;

        if ($pplan > 0)
           $mult++;

        if ($pplan > 0 && $pdiff > 0)
           $mult++;

        # Errechnen der gesamten Laenge; Zu jeder Zelle wird ein Rand von
        # 2 PT gerechnet.
        #
        $lenganz = $lenma + 4 + ($lence * $mult) + ($mult * 4);
        $csp = $lenma + 4;

        if ($fields_6 > 0) {
           $lenganz += ($lenph + 4);
           $csp += ($lenph + 4);
        }

        if ($fields_0 > 0) {
           $lenganz += ($lenta + 4);
           $csp += ($lenta + 4);
        }

        if ($fields_1 > 0) {
           $lenganz += ($lenan + 4);
           $csp += ($lenan + 4);
        }

        if ($fields_2 > 0) {
           $lenganz += ($lengr + 4);
           $csp += ($lengr + 4);
        }

        $pl_flag = false;
        $TempTable = false;

        while ($pospr < $numpr) {
           $data = fetchDB($respr, $pospr);
           $pr_num = $data[0];
           $pr_name = $data[1];
           $pr_status = $data[2];
           $lentotal = $lenganz;

           # Wurde kein Projekt gewaehlt, dann muessen wir die Plannummer
           # ermitteln. In diesem Fall zeigen wir immer den aktuelsten Plan
           # an.
           #
           if ($pl_flag || !isset($pl_num) || $pl_num <= 0) {
              $query = "select pl_num from plan where pl_prnum = $pr_num order by pl_num desc";
              $result = QueryDB($db, $query);

              if (!$result)
                 return;

              if (numrowsDB($result) > 0) {
                 $data = fetchDB($result, 0);
                 $pl_num = $data[0];
                 $pl_flag = true;
              } else {
                 $pl_num = 0;
                 $pl_flag = false;
                 $pospr++;
                 continue;
              }
           }

           if ($TempTable && $pospr > 0)
              TQueryDB($db, "drop table TempPlan");

           $TempTable = true;
           if (!CreateTempPlan($db, $pl_num, $pr_num, $dfrom, $dto, true)) {
              $pospr++;
              continue;
           }

           # Wieviele Perioden gibt es insgesamt?
           $query = "select count(distinct tmp_periode) from TempPlan";
           $result = QueryDB($db, $query);

           if (!$result) {
              closeDB($db);
              return;
           }

           $data = fetchDB($result, 0);
           $numper = $data[0];

           # Keine Datensaetze, dann keine Tabelle malen...
           if ($numper == 0) {
              $pospr++;
              continue;
           }

           # Die totale Laenge ist immer die Maximale, welche auf Grund des
           # ausgewaehlten Zeitraums moeglich ist-
           #
           $dt = $dfrom;
           $r = 0;

           while ($dt < $dto) {
              $dt = IncDate($periode, $dt);
              $r++;
           }

           $len = $lentotal + (($r * ($lence + 4)) * $mult);

           # Wenn die benoetigte Breite die zur Verfuegung stehende
           # ueberschreitet, dann skalieren wir die Ausgabe so, dass sich
           # alles in der Breite ausgeht.
           if ($fact == -1 && $len > ($pwidth - 50)) {
              $fact = ($pwidth - 50) / $len;
              PS_scale($ps, $fact, 1);
           }

           $lentotal += (($numper * ($lence + 4)) * $mult);
           # Zeichnen des Tabellenkopfs
           PS_setcolor($ps, "fill", "gray", 0.7, 0.0, 0.0, 0.0);
           PS_rect($ps, $x - 2, $y-1, $lentotal, 10);
           PS_fill($ps);
           PS_setcolor($ps, "fill", "gray", 1.0, 0.0, 0.0, 0.0);
           PS_setfont($ps, $helvB, 10.0);
           PS_show_xy($ps, "Projekt: $pr_num $pr_name", $x, $y);
           PS_rect($ps, $x - 2, $y-1, $lentotal, 10);
           PS_moveto($ps, $x - 2, $y);
           PS_lineto($ps, $x - 2, $y - 12);
           PS_stroke($ps);
           $y -= 10;
           $x = 38 + $csp;

           # Ermitteln der einzelnen Perioden und Darstellung der Selben.
           #
           $query = "select distinct tmp_periode from TempPlan order by tmp_periode";
           $result = QueryDB($db, $query);

           # Wurde kein Projekt gewaehlt, dann muessen wir die Plannummer
           # ermitteln. In diesem Fall zeigen wir immer den aktuelsten Plan
           # an.

           if (!$result) {
              return;
           }

           $numrows = numrowsDB($result);
           $r = 0;
           $j = 0;

           while ($r < $numrows) {
              $data = fetchDB($result, $r);
              $tmp_periode = $data[0];

              $mon = gmdate("n", $tmp_periode);
              $year = gmdate("Y", $tmp_periode);

              if ($r == 0) {
                 $fdate = $tmp_periode;
                 $adate = $fdate;
              }

              while ($adate < $tmp_periode) {
                 $p = gmdate("n/Y", $adate);
                 $len = ($lence + 4) * $mult;
                 $slen = PS_stringwidth($ps, $p);
                 $mid = $slen / 2 + 2;
                 PS_show_xy($ps, $p, $x + $mid, $y);
                 PS_rect($ps, $x, $y-1, $len, 10);
                 PS_stroke($ps);
                 $adate = IncDate($periode, $adate);
                 $sumperp[$j] = 0.0;
                 $sumperi[$j] = 0.0;
                 $totalis[$j] = 0.0;
                 $totalpl[$j] = 0.0;
                 $x += $len;
                 $j++;
              }

              $len = ($lence + 4) * $mult;
              $slen = PS_stringwidth($ps, "$mon/$year");
              $mid = $slen / 2 + 2;
              PS_show_xy($ps, "$mon/$year", $x + $mid, $y);
              PS_rect($ps, $x, $y-1, $len, 10);
              PS_stroke($ps);
              $sumperp[$j] = 0.0;
              $sumperi[$j] = 0.0;
              $totalis[$j] = 0.0;
              $totalpl[$j] = 0.0;
              $adate = IncDate($periode, $adate);
              $r++;
              $j++;
              $x += $len;
           }

           $ldate = $tmp_periode;
           $slen = PS_stringwidth($ps, GetMessage($db, 290, "Summen"));
           $mid = $slen / 2 + 2;
           PS_show_xy($ps, GetMessage($db, 290, "Summen"), $x + $mid, $y);
           PS_rect($ps, $x, $y-1, $len, 10);
           PS_stroke($ps);
           $y -= 10;
           $x = 40;

           PS_show_xy($ps, GetMessage($db, 66, "Mitarbeiter"), $x, $y);
           PS_rect($ps, $x - 2, $y-1, $lenma + 4, 10);
           PS_stroke($ps);
           $x += $lenma + 2;

           if ($fields_2 > 0) {
              PS_show_xy($ps, GetMessage($db, 291, "Gruppe"), $x, $y);
              PS_rect($ps, $x - 2, $y-1, $lengr + 4, 10);
              PS_stroke($ps);
              $x += $lengr + 4;
           }

           if ($phase && $fields_6 > 0) {
              PS_show_xy($ps, GetMessage($db, 292, "Phase"), $x, $y);
              PS_rect($ps, $x - 2, $y-1, $lenph + 4, 10);
              PS_stroke($ps);
              $x += $lenph + 4;
           }

           if ($fields_0 > 0) {
              PS_show_xy($ps, GetMessage($db, 293, "Tasks"), $x, $y);
              PS_rect($ps, $x - 2, $y-1, $lenta + 4, 10);
              PS_stroke($ps);
              $x += $lenta + 4;
           }

           if ($fields_1 > 0) {
              PS_show_xy($ps, GetMessage($db, 294, "Anmerkungen"), $x, $y);
              PS_rect($ps, $x - 2, $y-1, $lenan + 4, 10);
              PS_stroke($ps);
              $x += $lenan + 4;
           }

           $r = 0;

           while ($r <= $j) {
              if ($pist > 0) {
                 PS_show_xy($ps, GetMessage($db, 260, "IST"), $x, $y);
                 PS_rect($ps, $x - 2, $y-1, $lence + 4, 10);
                 PS_stroke($ps);
                 $x += $lence + 4;
              }

              if ($pplan > 0 && $pdiff > 0) {
                 PS_show_xy($ps, GetMessage($db, 295, "Diff."), $x, $y);
                 PS_rect($ps, $x - 2, $y-1, $lence + 4, 10);
                 PS_stroke($ps);
                 $x += $lence + 4;
              }

              if ($pplan > 0) {
                 PS_show_xy($ps, GetMessage($db, 278, "Plan"), $x, $y);
                 PS_rect($ps, $x - 2, $y-1, $lence + 4, 10);
                 PS_stroke($ps);
                 $x += $lence + 4;
              }

              $r++;
           }

           $x = 40;
           $y -= 10;
           $query = "select tmp_phase, tmp_periode, tmp_plan, tmp_ist,";
           $query .= "tmp_taname, tmp_notiz, mi_nname, mi_vname, kp_phase, ";
           $query .= "kl_land, tmp_miname, tmp_status, tmp_hash ";
           $query .= "from TempPlan, mitarbeiter, key_phase, key_land where ";
           $query .= "mi_num = tmp_miname and kp_num = tmp_phase and kl_num = mi_land ";
           $query .= "order by mi_nname, mi_vname, tmp_phase, tmp_taname, tmp_periode";
           $result = QueryDB($db, $query);
           # Wurde kein Projekt gewaehlt, dann muessen wir die Plannummer
           # ermitteln. In diesem Fall zeigen wir immer den aktuelsten Plan
           # an.

           if (!$result)
              return;

           $numrows = numrowsDB($result);
           $rows = 0;
           $oldminame = 0;
           $oldphase = 0;
           $oldtask = "";
           $sumlpl = 0.0;
           $sumlis = 0.0;
           $per = 0;
           $first = true;
           $adate = $fdate;
           $class = false;

           while ($rows < $numrows) {
              $data = fetchDB($result, $rows);
              $tmp_phase = $data[0];
              $tmp_periode = $data[1];
              $tmp_plan = $data[2];
              $tmp_ist = $data[3];
              $tmp_taname = $data[4];
              $tmp_notiz = $data[5];
              $mi_nname = $data[6];
              $mi_vname = $data[7];
              $kp_phase = $data[8];
              $kl_land = $data[9];
              $tmp_miname = $data[10];
              $tmp_status = $data[11];
              $tmp_hash = $data[12];

              # Summen und Zeilenanfang schreiben
              #
              if ($oldminame != $tmp_miname || $oldphase != $tmp_phase ||
                  $oldtask != $tmp_taname) {
                 # Aktuelle Zeile vervollstaendigen (nur wenn eine Zeile
                 # bereits geschrieben wurde).
                 #
                 if (!$first) {
                    while ($adate <= $ldate) {
                       $x = CellPDF($ps, 0, 0, $x, $y, $lence, $class, true);

                       if ($class)
                          $class = false;
                       else
                          $class = true;

                       $adate = IncDate($periode, $adate);
                    }

                    ZSumPDF($ps, $sumlis, $sumlpl, $x, $y, $lence);
                    $x = 40;

                    if (isset($y_next) && $y_next > 0) {
                       $y = $y_next;
                       $y_next = -1;
                       unset ($y_next);
                    } else
                       $y -= 10;

                    if ($y <= 30) {
                       PS_end_page($ps);
                       HeadLine($ps);
                       $y = $pheight - 30;
                    }
                 }

                 if (!$first && $oldminame != $tmp_miname) {
                    # Monatssummen nach einem Mitarbeiterwechsel
                    #
                    if ($fields_0 > 0 || $fields_6 > 0 && $fields_1 > 0 && $fields_2 > 0) {
                       $len = PS_stringwidth($ps, GetMessage($db, 296, "Zwischensumme: "));
                       $x = 38 + $csp - $len - 4;
                       PS_show_xy($ps, GetMessage($db, 296, "Zwischensumme:"), $x, $y);
                       PS_rect($ps, 38, $y-1, $csp-2, 10);
                       PS_stroke($ps);
                       $x = 38 + $csp;
                    }

                    $adate = $fdate;
                    $per = 0;
                    $sumi = 0.0;
                    $sump = 0.0;

                    while ($adate <= $ldate) {
                       if ($fields_0 > 0 || $fields_6 > 0 && $fields_1 > 0 && $fields_2 > 0)
                          $x = CellPDF($ps, $sumperi[$per], $sumperp[$per], $x, $y, $lence, true);

                       $adate = IncDate($periode, $adate);
                       $sumi += $sumperi[$per];
                       $sump += $sumperp[$per];
                       $sumperi[$per] = 0.0;
                       $sumperp[$per] = 0.0;
                       $per++;
                    }

                    if ($fields_0 > 0 || $fields_6 > 0 && $fields_1 > 0 && $fields_2 > 0) {
                       ZsumPDF($ps, $sumi, $sump, $x, $y, $lence);
                       $y -= 10;
                    }

                    $x = 40;
//                  $y -= 10;

                    if ($y <= 30) {
                       PS_end_page($ps);
                       HeadLine($ps);
                       $y = $pheight - 30;
                    }
                 }

                 # Beginn der Zeile: Schreiben der ersten fixen Zellen.
                 #
                 PS_setfont($ps, $helvN, 10.0);
                 $x = 40;
                 PS_show_xy($ps, "$mi_nname $mi_vname", $x, $y);
                 PS_rect($ps, $x - 2, $y-1, $lenma + 4, 10);
                 PS_stroke($ps);
                 $x += $lenma + 2;

                 if ($fields_2 > 0) {
                    PS_show_xy($ps, $kl_land, $x, $y);
                    PS_rect($ps, $x - 2, $y-1, $lengr + 4, 10);
                    PS_stroke($ps);
                    $x += $lengr + 4;
                 }

                 if ($phase && $fields_6 > 0) {
                    if ($tmp_status == 0)
                       PS_show_xy($ps, "$tmp_phase: $kp_phase", $x, $y);

                    PS_rect($ps, $x - 2, $y-1, $lenph + 4, 10);
                    PS_stroke($ps);
                    $x += $lenph + 4;
                 }

                 if ($fields_0 > 0) {
                    PS_show_xy($ps, $tmp_taname, $x, $y);
                    PS_rect($ps, $x - 2, $y-1, $lenta + 4, 10);
                    PS_stroke($ps);
                    $x += $lenta + 4;
                 }

                 if ($fields_1 > 0) {
                    if (strlen($tmp_notiz) > 0) {
                       $len = PS_stringwidth($ps, $tmp_notiz);

                       if ($len > $lenan)
                          $lines = ceil($len / $lenan);
                       else
                          $lines = 1;

                       PS_show_boxed($ps, $tmp_notiz, $x, ($y + 8) - ($lines * 10), $lenan, $lines * 10, "left");
                       PS_rect($ps, $x - 2, (($y + 10) - ($lines * 10))-1, $lenan + 4, $lines * 10);
                       $y_next = $y - (($lines - 1) * 10);
                    } else {
                       PS_show_xy($ps, $tmp_notiz, $x, $y);
                       PS_rect($ps, $x - 2, $y-1, $lenan + 4, 10);
                    }

                    PS_stroke($ps);
                    $x += $lenan + 4;
                 }

                 # Variablen initialisieren...
                 #
                 $sumlis = 0.0;
                 $sumlpl = 0.0;
                 $per = 0;
                 $adate = $fdate;
                 $oldminame = $tmp_miname;
                 $oldphase = $tmp_phase;
                 $oldtask = $tmp_taname;
                 $first = false;
                 $class = false;
              }

              # Stimmt die aktuelle Position nicht mit der Periode ueberein,
              # uebergehen wir die Zellen.
              #
              while ($adate < $tmp_periode) {
                 $x = CellPDF($ps, 0, 0, $x, $y, $lence, $class, true);

                 if ($class)
                    $class = false;
                 else
                    $class = true;

                 $adate = IncDate($periode, $adate);
                 $per++;
              }

              # Schreiben einer Zelle mit den aktuellen Werten.
              $x = CellPDF($ps, $tmp_ist, $tmp_plan, $x, $y, $lence, $class);

              if ($class)
                 $class = false;
              else
                 $class = true;

              $sumperp[$per] += $tmp_plan;
              $sumperi[$per] += $tmp_ist;
              $totalis[$per] += $tmp_ist;
              $totalpl[$per] += $tmp_plan;
              $sumlpl += $tmp_plan;
              $sumlis += $tmp_ist;
              $adate = IncDate($periode, $adate);
              $per++;
              $rows++;
           }

           # Beenden der der letzten Datenzeile der aktuellen Tabelle.
           #
           while ($adate <= $ldate) {
              $x = CellPDF($ps, 0, 0, $x, $y, $lence, $class, true);

              if ($class)
                 $class = false;
              else
                 $class = true;

              $adate = IncDate($periode, $adate);
           }

           ZSumPDF($ps, $sumlis, $sumlpl, $x, $y, $lence);
           $y -= 10;
           $x = 40;

           if ($y <= 30) {
              PS_end_page($ps);
              HeadLine($ps);
              $y = $pheight - 30;
           }

           # Summenzeile am Ende der Tabelle fuer den letzten Mitarbeiter
           # anzeigen.
           #
           if ($fields_0 > 0 || $fields_6 > 0 && $fields_1 > 0 && $fields_2 > 0) {
              $len = PS_stringwidth($ps, GetMessage($db, 296, "Zwischensumme: "));
              $x = 38 + $csp - $len - 4;
              PS_show_xy($ps, GetMessage($db, 296, "Zwischensumme:"), $x, $y);
              PS_rect($ps, 38, $y-1, $csp-2, 10);
              PS_stroke($ps);
              $x = 38 + $csp;
              $adate = $fdate;
              $per = 0;
              $sumi = 0.0;
              $sump = 0.0;
              PS_setfont($ps, $helvB, 10.0);

              while ($adate <= $ldate) {
                 $x = CellPDF($ps, $sumperi[$per], $sumperp[$per], $x, $y, $lence, true);
                 $adate = IncDate($periode, $adate);
                 $sumi += $sumperi[$per];
                 $sump += $sumperp[$per];
                 $sumperi[$per] = 0.0;
                 $sumperp[$per] = 0.0;
                 $per++;
              }

              ZSumPDF($ps, $sumi, $sump, $x, $y, $lence);
              $y -= 10;
           }

           $x = 40;

           if ($y <= 30) {
              PS_end_page($ps);
              HeadLine($ps);
              $y = $pheight - 30;
           }

           # Monatssummen und Gesamtzeitraumsumme am Ende der Tabelle
           # anzeigen.
           #
           $len = PS_stringwidth($ps, GetMessage($db, 297, "Monatssummen: "));
           $x = 38 + $csp - $len - 4;
           PS_show_xy($ps, GetMessage($db, 297, "Monatssummen:"), $x, $y);
           PS_rect($ps, 38, $y-1, $csp - 2, 10);
           PS_stroke($ps);
           $x = 38 + $csp;
           $adate = $fdate;
           $per = 0;
           $sumi = 0.0;
           $sump = 0.0;
           PS_setfont($ps, $helvB, 10.0);

           while ($adate <= $ldate) {
              $x = CellPDF($ps, $totalis[$per], $totalpl[$per], $x, $y, $lence, true);
              $adate = IncDate($periode, $adate);
              $sumi += $totalis[$per];
              $sump += $totalpl[$per];
              $per++;
           }

           ZSumPDF($ps, $sumi, $sump, $x, $y, $lence);
           $x = 40;
           $y -= 20;

           if ($y <= 30) {
              PS_end_page($ps);
              HeadLine($ps);
              $y = $pheight - 30;
           }

           $pospr++;
        }
}

# Folgende Funktion erzeugt die Liste fuer genau einen Mitarbeiter. Die Liste
# sortiert nach Mitarbeitern und Projekten.
#
function MitarbeiterPjPDF($ps, $db, $mi_num, $ystart, $prp_num=0) {
        global $periode;
        global $phase;
        global $helvN;
        global $helvB;
        global $page;
        global $pwidth;
        global $pheight;
        global $SearchPath;
        global $fact;

        $dfrom = $_REQUEST['dfrom'];
        $dto = $_REQUEST['dto'];
        $fields_0 = $_REQUEST['fields_0'];
        $fields_1 = $_REQUEST['fields_1'];
        $fields_2 = $_REQUEST['fields_2'];
        $fields_3 = $_REQUEST['fields_3'];
        $fields_4 = $_REQUEST['fields_4'];
        $fields_5 = $_REQUEST['fields_5'];
        $fields_6 = $_REQUEST['fields_6'];
        $sort = $_REQUEST['sort'];
        $level = $_REQUEST['level'];
        $pjclosed = $_REQUEST['pjclosed'];

        if (isset($pjclosed) && CheckTrue($pjclosed))
           $pjc = ",6";

        # Festlegen der Spaltenlaengen
        $lenpr = PS_stringwidth($ps, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        $lenph = PS_stringwidth($ps, "9: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        $lenta = $lenpr;
        $lenan = PS_stringwidth($ps, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
        $lence = PS_stringwidth($ps, "999,999");
        $lentotal = 0;

        # Beim bis-Datum den Monatsletzten ermitteln
        $mon = gmdate("n", $dto);
        $year = gmdate("Y", $dto);
        $day = daysinmonth($mon, $year);
        $dto = gmmktime(23, 59, 59, $mon, $day, $year);
        # Auslesen der Mitarbeiter. In einer Schleife werden die Daten
        # fuer jeden Mitarbeiter erstellt und pro Projekt angezeigt.
        #
        $query = "select mi_num, mi_nname, mi_vname, kl_land, ka_abt ";
        $query .= "from mitarbeiter, key_land, key_abt where ";
        $query .= "kl_num = mi_land and ka_num = mi_abt ";

        if ($mi_num > 0)
           $query .= "and mi_num = $mi_num ";

        $query .= "order by mi_nname, mi_vname";
        $resmi = QueryDB($db, $query);

        if (!$resmi)
           return;

        $nummi = numrowsDB($resmi);
        $posmi = 0;

        $pdiff = $fields_3;
        $pist = $fields_4;
        $pplan = $fields_5;
        $mult = 0;
        $y = $ystart;
        $x = 40;

        if ($pist > 0)
           $mult++;

        if ($pplan > 0)
           $mult++;

        if ($pplan > 0 && $pdiff > 0)
           $mult++;

        # Errechnen der gesamten Laenge; Zu jeder Zelle wird ein Rand von
        # 2 PT gerechnet.
        #
        $lentotal = $lenpr + 4 + ($lence * $mult) + ($mult * 4);
        $csp = $lenpr + 4;

        if ($fields_6 > 0) {
           $lentotal += ($lenph + 4);
           $csp += ($lenph + 4);
        }

        if ($fields_0 > 0) {
           $lentotal += ($lenta + 4);
           $csp += ($lenta + 4);
        }

        if ($fields_1 > 0) {
           $lentotal += ($lenan + 4);
           $csp += ($lenan + 4);
        }

        # Die Anzahl der Perioden ergibt sich aus der Auswahl. Die
        # Mitarbeitersicht besteht aus einer einzigen Tabelle in der
        # alle Daten angezeigt werden und mit Zwischensummen versehen
        # werden.
        # In der folgenden Schleife wird die Anzahl der Perioden
        # ermittelt.
        #
        $adate = $dfrom;
        $numper = 0;

        while ($adate <= $dto) {
           $adate = IncDate($periode, $adate);
           $numper++;
        }

        $lentotal += (($numper * ($lence + 4)) * $mult);
        # Wenn die benoetigte Breite die zur Verfuegung stehende
        # ueberschreitet, dann skalieren wir die Ausgabe so, dass sich
        # alles in der Breite ausgeht.
        if ($lentotal > ($pwidth - 50)) {
           $fact = ($pwidth - 50) / $lentotal;
           PS_scale($ps, $fact, 1);
        }

        $TempTable = false;

        while ($posmi < $nummi) {
           $data = fetchDB($resmi, $posmi);
           $mi_num = $data[0];
           $mi_nname = $data[1];
           $mi_vname = $data[2];
           $kl_land = $data[3];
           $ka_abt = $data[4];

           # Pruefen ob der Mitarbeiter in irgend einem Projekt im gewaehlten
           # Zeitraum geplant ist.
           if ($prp_num > 0) {
              $query = "select count(*) from allocation, task, plan where ";
              $query .= "ta_num = al_task and pl_num = ta_plnum and ";
              $query .= "pl_prnum = $prp_num and pl_status in (0,2,3,4,5 $pjc) and ";
           } else {
              $query = "select count(*) from allocation, task, plan where ";
              $query .= "ta_num = al_task and pl_num = ta_plnum and ";
              $query .= "pl_status in (0,2,3,4,5 $pjc) and ";
           }

           $query .= "al_ressource = $mi_num and al_pstart between $dfrom and $dto";
           $result = QueryDB($db, $query);

           if (!$result)
              return;

           $data = fetchDB($result, 0);
           $anzp = $data[0];

           # Pruefen ob es auch keine IST-Buchungen fuer den fraglichen
           # Zeitraum gegeben hat.
           $query = "select count(*) from wdone, plan where ";
           $query .= "pl_prnum = wd_prnum and pl_status in (0,2,3,4,5 $pjc) and ";
           $query .= "wd_datum between $dfrom and $dto and ";
           $query .= "wd_minum = $mi_num ";

           if ($prp_num > 0)
              $query .= "and wd_prnum = $prp_num";

           if (!($result = QueryDB($db, $query)))
              return;

           $data = fetchDB($result, 0);
           $anzi = $data[0];

           if ($anzp < 1 && $anzi < 1) {
              $posmi++;
              continue;
           }

           # Zeichnen des Tabellenkopfs
           # Bei jedem Mitarbeiterwechsel wird ein neuer Tabellenkopf
           # gezeichnet.
           #
           if (($y - 60) <= 30) {
              PS_end_page($ps);
              HeadLine($ps);
              $y = $pheight - 30;
           }

           $c = PS_stringwidth($ps, GetMessage($db, 55, "Abteilung:") . " ");
           PS_setfont($ps, $helvN, 10.0);
           PS_show_xy($ps, GetMessage($db, 298, "Name:"), $x, $y);
           PS_show_xy($ps, "$mi_nname $mi_vname", $x + $c, $y);
           $y -= 10;
           PS_show_xy($ps, GetMessage($db, 299, "Gruppe:"), $x, $y);
           PS_show_xy($ps, $kl_land, $x + $c, $y);
           $y -= 10;
           $lines = 2;

           if (!$pmlight) {
              PS_show_xy($ps, GetMessage($db, 55, "Abteilung:"), $x, $y);
              PS_show_xy($ps, $ka_abt, $x + $c, $y);
              $y -= 10;
              $lines++;
           }

           PS_rect($ps, $x - 2, $y + 9 , $lentotal, $lines * 10);
           PS_moveto($ps, $x - 2, $y + 10);
           PS_lineto($ps, $x - 2, $y - 2);
           PS_stroke($ps);
           $r = 0;
           $adate = $dfrom;
           $c = ($lence + 4) * $mult;
           $x = 38 + $csp;
           PS_setcolor($ps, "fill", "gray", 0.6, 0.0, 0.0, 0.0);
           PS_setfont($ps, $helvB, 10.0);

           while ($r < $numper) {
              $p = gmdate("n/Y", $adate);
              PS_rect($ps, $x - 2, $y - 1, $c, 10);
              PS_fill($ps);
              PS_rect($ps, $x - 2, $y - 1, $c, 10);
              PS_stroke($ps);
              PS_show_boxed($ps, $p, $x, $y-2, $c - 4, 10, "center");
              $adate = IncDate($periode, $adate);
              $sumperp[$r] = 0.0;
              $sumperi[$r] = 0.0;
              $totalis[$r] = 0.0;
              $totalpl[$r] = 0.0;
              $mitotp[$r] = 0.0;
              $mitoti[$r] = 0.0;
              $r++;
              $x += $c;
           }

           PS_rect($ps, $x - 2, $y - 1, $c, 10);
           PS_fill($ps);
           PS_rect($ps, $x - 2, $y - 1, $c, 10);
           PS_stroke($ps);
           PS_show_boxed($ps, GetMessage($db, 290, "Summen"), $x, $y-2, $c - 4, 10, "center");
           $y -= 10;
           $x = 40;
           PS_rect($ps, $x - 2, $y - 1, $lenpr+4, 10);
           PS_fill($ps);
           PS_rect($ps, $x - 2, $y - 1, $lenpr+4, 10);
           PS_stroke($ps);
           PS_show_boxed($ps, GetMessage($db, 277, "Projekt"), $x, $y-2, $lenpr, 10, "center");
           $x += $lenpr + 4;

           if ($phase && $fields_6 > 0) {
              PS_rect($ps, $x - 2, $y - 1, $lenph+4, 10);
              PS_fill($ps);
              PS_rect($ps, $x - 2, $y - 1, $lenph+4, 10);
              PS_stroke($ps);
              PS_show_boxed($ps, GetMessage($db, 292, "Phase"), $x, $y-2, $lenph, 10, "center");
              $x += $lenph + 4;
           }

           if ($fields_0 > 0) {
              PS_rect($ps, $x - 2, $y - 1, $lenta+4, 10);
              PS_fill($ps);
              PS_rect($ps, $x - 2, $y - 1, $lenta+4, 10);
              PS_stroke($ps);
              PS_show_boxed($ps, GetMessage($db, 293, "Tasks"), $x, $y-2, $lenta, 10, "center");
              $x += $lenta + 4;
           }

           if ($fields_1 > 0) {
              PS_rect($ps, $x - 2, $y - 1, $lenan+4, 10);
              PS_fill($ps);
              PS_rect($ps, $x - 2, $y - 1, $lenan+4, 10);
              PS_stroke($ps);
              PS_show_boxed($ps, GetMessage($db, 294, "Anmerkungen"), $x, $y-2, $lenan, 10, "center");
              $x += $lenan + 4;
           }

           $r = 0;

           while ($r <= $numper) {
              if ($pist > 0) {
                 PS_rect($ps, $x - 2, $y - 1, $lence+4, 10);
                 PS_fill($ps);
                 PS_rect($ps, $x - 2, $y - 1, $lence+4, 10);
                 PS_stroke($ps);
                 PS_show_boxed($ps, GetMessage($db, 279, "IST"), $x, $y-2, $lence, 10, "center");
                 $x += $lence + 4;
              }

              if ($pplan > 0 && $pdiff > 0) {
                 PS_rect($ps, $x - 2, $y - 1, $lence+4, 10);
                 PS_fill($ps);
                 PS_rect($ps, $x - 2, $y - 1, $lence+4, 10);
                 PS_stroke($ps);
                 PS_show_boxed($ps, GetMessage($db, 295, "Diff."), $x, $y-2, $lence, 10, "center");
                 $x += $lence + 4;
              }

              if ($pplan > 0) {
                 PS_rect($ps, $x - 2, $y - 1, $lence+4, 10);
                 PS_fill($ps);
                 PS_rect($ps, $x - 2, $y - 1, $lence+4, 10);
                 PS_stroke($ps);
                 PS_show_boxed($ps, GetMessage($db, 278, "Plan"), $x, $y-2, $lence, 10, "center");
                 $x += $lence + 4;
              }

              $r++;
           }

           $y -= 10;
           $x = 40;
           PS_setcolor($ps, "fill", "gray", 1.0, 0.0, 0.0, 0.0);
           PS_setfont($ps, $helvN, 10.0);

           # Projekte waehlen, in denen der Mitarbeiter geplant ist.
           #
           # Wurde kein bestimmter Mitarbeiter gewählt, werden immer alle
           # Mitarbeiter angezeigt. Es werden grundsätzlich alle Projekte
           # angezeigt in denen der Mitarbeiter geplant ist oder wo er
           # IST-Werte hat (das eine bedingt das andere!).
           #
           $query = "select distinct on (pr_num) pr_num, pr_name, pl_num, pl_status from ";
           $query .= "project, plan where pl_prnum = pr_num and pl_status in (0,2,3,4,5 $pjc) ";

           if ($prp_num > 0)
              $query .= "and pr_num = $prp_num ";

           $query .= "order by pr_num asc, pl_lfd desc";
           $respr = QueryDB($db, $query);

           if (!$respr)
              return;

           $numpr = numrowsDB($respr);
           $pospr = 0;
           $old_prnum = 0;
           $pr_flag = false;    // Zwischensumme schreiben

           while ($pospr < $numpr) {
              $data = fetchDB($respr, $pospr);
              $pr_num = $data[0];
              $pr_name = $data[1];
              $pl_num = $data[2];
              $pl_status = $data[3];

              # Pruefen ob fuer den fraglichen Zeitraum Plantage oder
              # IST-Daten vorhanden sind.
              $query = "select count(*) from allocation, task, plan where ";
              $query .= "ta_num = al_task and pl_num = ta_plnum and ";
              $query .= "pl_prnum = $pr_num and al_ressource = $mi_num and ";
              $query .= "al_pstart between $dfrom and $dto and pl_status in (0,2,3,4,5 $pjc)";

              if (!($resco = QueryDB($db, $query)))
                 return;

              $data = fetchDB($resco, 0);
              $anzp = $data[0];

              $query = "select count(*) from wdone where ";
              $query .= "wd_minum = $mi_num and wd_prnum = $pr_num and ";
              $query .= "wd_datum between $dfrom and $dto";

              if (!($resco = QueryDB($db, $query)))
                 return;

              $data = fetchDB($resco, 0);
              $anzi = $data[0];

              # Keine Plan- und IST-Daten? Wenn keine Daten, dann das
              # Projekt ueberspringen.
              if ($anzp == 0 && $anzi == 0) {
                 $pospr++;
                 continue;
              }

              # Falls die temporaere Tabelle existiert, loeschen wir sie.
              if ($TempTable)
                 TQueryDB($db, "drop table TempPlan");

              $TempTable = true;

              if (!CreateTempPlan($db, $pl_num, $pr_num, $dfrom, $dto, true, $mi_num, true)) {
                 $pospr++;
                 continue;
              }

              # Wurden in der temporaeren Tabelle ueberhaupt Datensaetze
              # abgelegt?
              $query = "select count(*) from TempPlan";

              if (!($resanz = QueryDB($db, $query)))
                 return;

              $data = fetchDB($resanz, 0);

              if ($data[0] <= 0) {
                 $pospr++;
                 continue;
              }

              $c = $csp + $np;
              $pr_flag = true;

              # Tabelleninhalt schreiben:
              # Die Inhalte werden der zuvor temporaer erzeugten Tabelle
              # entnommen.
              #
              if ($fields_0 <= 0) {
                 $query = "select sum(tmp_plan), sum(tmp_ist), tmp_periode ";

                 if ($fields_6 > 0)
                    $query .= ", tmp_phase ";

                 $query .= "from TempPlan group by ";

                 if ($fields_6 > 0)
                    $query .= "tmp_phase, ";

                 $query .= "tmp_periode order by ";

                 if ($fields_6 > 0)
                    $query .= "tmp_phase, ";

                 $query .= "tmp_periode";
              } else {
                 $query = "select tmp_phase, tmp_periode, tmp_plan, tmp_ist,";
                 $query .= "tmp_taname, tmp_notiz, kp_phase, tmp_hash ";
                 $query .= "from TempPlan, key_phase where ";
                 $query .= "kp_num = tmp_phase ";
                 $query .= "order by ";

                 if ($phase)
                    $query .= "tmp_phase, ";

                 if ($fields_0 > 0 )
                    $query .= "tmp_taname, ";

                 $query .= "tmp_periode";
              }

              if (!($result = QueryDB($db, $query)))
                 return;

              $numrows = numrowsDB($result);
              $rows = 0;
              $oldphase = -1;
              $oldtask = "";
              $sumlpl = 0.0;
              $sumlis = 0.0;
              $per = 0;
              $first = true;
              $adate = $dfrom;
              $class = false;

              while ($rows < $numrows) {
                 $data = fetchDB($result, $rows);

                 if ($fields_0 > 0) {
                    $tmp_phase = $data[0];
                    $tmp_periode = $data[1];
                    $tmp_plan = $data[2];
                    $tmp_ist = $data[3];
                    $tmp_taname = $data[4];
                    $tmp_notiz = $data[5];
                    $kp_phase = $data[6];
                    $tmp_hash = $data[7];
                 } else {
                    $tmp_plan = $data[0];
                    $tmp_ist = $data[1];
                    $tmp_periode = $data[2];

                    if ($fields_6 > 0) {
                       $tmp_phase = $data[3];

                       $query = "select kp_phase from key_phase where kp_num = $tmp_phase";

                       if (!($reskp = QueryDB($db, $query)))
                          return;

                       if (numrowsDB($reskp) > 0) {
                          $d = fetchDB($reskp, 0);
                          $kp_phase = $d[0];
                       } else
                          $kp_phase = "";
                    } else
                       $tmp_phase = 0;

                    $tmp_taname = "";
                    $tmp_notiz = "";
                    $tmp_hash = "";
                 }

                 # Summen und Zeilenanfang schreiben
                 #
                 if ($oldphase != $tmp_phase || $oldtask != $tmp_taname) {
                    # Aktuelle Zeile vervollstaendigen (nur wenn eine Zeile
                    # bereits geschrieben wurde).
                    #
                    if (!$first) {
                       while ($adate <= $dto) {
                          $x = CellPDF($ps, 0, 0, $x, $y, $lence, $class, true);
                          $class = !$class;
                          $adate = IncDate($periode, $adate);
                       }

                       ZSumPDF($ps, $sumlis, $sumlpl, $x, $y, $lence);
                       $x = 40;
                       $y -= 10;

                       if ($y <= 30) {
                          PS_end_page($ps);
                          HeadLine($ps);
                          $y = $pheight - 30;
                       }
                    }

                    # Beginn der Zeile: Schreiben der ersten fixen Zellen.
                    #
                    PS_show_xy($ps, "$pr_num $pr_name", $x, $y);
                    PS_rect($ps, $x - 2, $y - 1, $lenpr+4, 10);
                    PS_stroke($ps);
                    $x += $lenpr + 2;

                    if ($phase && $fields_6 > 0) {
                       PS_show_xy($ps, "$tmp_phase: $kp_phase", $x, $y);
                       PS_rect($ps, $x - 2, $y - 1, $lenph+4, 10);
                       PS_stroke($ps);
                       $x += $lenph + 2;
                    }

                    if ($fields_0 > 0) {
                       PS_show_xy($ps, "$tmp_taname", $x, $y);
                       PS_rect($ps, $x - 2, $y - 1, $lenta+4, 10);
                       PS_stroke($ps);
                       $x += $lenta + 2;
                    }

                    if ($fields_1 > 0) {
                       PS_show_xy($ps, "$tmp_notiz", $x, $y);
                       PS_rect($ps, $x - 2, $y - 1, $lenan+4, 10);
                       PS_stroke($ps);
                       $x += $lenan + 2;
                    }

                    # Variablen initialisieren...
                    #
                    $sumlis = 0.0;
                    $sumlpl = 0.0;
                    $per = 0;
                    $adate = $dfrom;
                    $oldphase = $tmp_phase;
                    $oldtask = $tmp_taname;
                    $first = false;
                    $class = false;
                    $x = 38 + $csp;
                 }

                 # Stimmt die aktuelle Position nicht mit der Periode ueberein,
                 # uebergehen wir die Zellen.
                 #
                 while ($adate < $tmp_periode) {
                    $x = CellPDF($ps, 0, 0, $x, $y, $lence, $class, true);
                    $class = !$class;
                    $adate = IncDate($periode, $adate);
                    $per++;
                 }

                 # Schreiben einer Zelle mit den aktuellen Werten.
                 $x = CellPDF($ps, $tmp_ist, $tmp_plan, $x, $y, $lence, $class, false);
                 $class = !$class;
                 $sumperp[$per] += $tmp_plan;
                 $sumperi[$per] += $tmp_ist;
                 $totalis[$per] += $tmp_ist;
                 $totalpl[$per] += $tmp_plan;
                 $mitoti[$per] += $tmp_ist;
                 $mitotp[$per] += $tmp_plan;
                 $sumlpl += $tmp_plan;
                 $sumlis += $tmp_ist;
                 $adate = IncDate($periode, $adate);
                 $per++;
                 $rows++;
              }

              # Beenden der letzten Datenzeile der aktuellen Tabelle.
              #
              while ($adate <= $dto) {
                 $x = CellPDF($ps, 0, 0, $x, $y, $lence, $class, true);
                 $class = !$class;
                 $adate = IncDate($periode, $adate);
              }

              ZSumPDF($ps, $sumlis, $sumlpl, $x, $y, $lence);
              $x = 40;
              $y -= 10;

              if ($y <= 30) {
                 PS_end_page($ps);
                 HeadLine($ps);
                 $y = $pheight - 30;
              }

              if ($prp_num == 0 && $numpr > 1 && ($fields_0 || $fields_6)) {
                 PS_show_boxed($ps, GetMessage($db, 300, "Projektsumme:") . " ", $x, $y-2, $csp-4, 10, "right");
                 PS_rect($ps, $x - 2, $y - 1, $csp, 10);
                 PS_stroke($ps);
                 $x = 38 + $csp;
                 $adate = $dfrom;
                 $per = 0;
                 $sumi = 0.0;
                 $sump = 0.0;

                 while ($adate <= $dto) {
                    $x = CellPDF($ps, $sumperi[$per], $sumperp[$per], $x, $y, $lence, true);
                    $adate = IncDate($periode, $adate);
                    $sumi += $sumperi[$per];
                    $sump += $sumperp[$per];
                    $sumperi[$per] = 0.0;
                    $sumperp[$per] = 0.0;
                    $per++;
                 }

                 ZsumPDF($ps, $sumi, $sump, $x, $y, $lence);
                 $y -= 10;
                 $x = 40;

                 if ($y <= 30) {
                    PS_end_page($ps);
                    HeadLine($ps);
                    $y = $pheight - 30;
                 }
              }

              $pospr++;
           }

           PS_show_boxed($ps, GetMessage($db, 301, "Gesamtsumme Mitarbeiter:") . " ", $x, $y-2, $csp-4, 10, "right");
           PS_rect($ps, $x - 2, $y - 1, $csp, 10);
           PS_stroke($ps);
           $x = 38 + $csp;
           $adate = $dfrom;
           $per = 0;
           $sumi = 0.0;
           $sump = 0.0;

           while ($adate <= $dto) {
              $x = CellPDF($ps, $mitoti[$per], $mitotp[$per], $x, $y, $lence, true);
              $adate = IncDate($periode, $adate);
              $sumi += $mitoti[$per];
              $sump += $mitotp[$per];
              $mitoti[$per] = 0.0;
              $mitotp[$per] = 0.0;
              $per++;
           }

           ZsumPDF($ps, $sumi, $sump, $x, $y, $lence);
           $y -= 15;
           $x = 40;

           if ($y <= 30) {
              PS_end_page($ps);
              HeadLine($ps);
              $y = $pheight - 30;
           }

           $posmi++;
        }

        # Monatssummen und Gesamtzeitraumsumme am Ende der Tabelle
        # anzeigen.
        #
        if ($mi_num == 0) {
           PS_show_boxed($ps, GetMessage($db, 297, "Monatssummen:") . " ", $x, $y-2, $csp-4, 10, "right");
           PS_rect($ps, $x - 2, $y - 1, $csp, 10);
           PS_stroke($ps);
           $x = 38 + $csp;
           $adate = $dfrom;
           $per = 0;
           $sumi = 0.0;
           $sump = 0.0;

           while ($adate <= $dto) {
              $x = CellPDF($ps, $totalis[$per], $totalpl[$per], $x, $y, $lence, true);
              $adate = IncDate($periode, $adate);
              $sumi += $totalis[$per];
              $sump += $totalpl[$per];
              $per++;
           }

           $x = ZsumPDF($ps, $sumi, $sump, $x, $y, $lence);
           $y -= 10;
           $x = 40;

           if ($y <= 30) {
              PS_end_page($ps);
              HeadLine($ps);
              $y = $pheight - 30;
           }

           $posmi++;
        }
}

function GetBrowserInfo($key) {
        $browser = get_browser();

        while (list ($schl, $value) = each ($browser)) {
           if ($schl == $key)
              return $value;
        }

        return "";
}

# Folgende Funktion wertet die vom Anwender getroffenen Einstellungen aus
# und ruft die entsprechenden Funktionen auf um die Listen darzustellen.
#
function PrintListPDF() {
        global $phase;
        global $pmlight;
        global $strVersion;
        global $helvN;
        global $helvB;
        global $page;
        global $pwidth;
        global $pheight;
        global $SearchPath;

        $pl_num = $_REQUEST['pl_num'];
        $mi_num = $_REQUEST['mi_num'];
        $dfrom = $_REQUEST['dfrom'];
        $dto = $_REQUEST['dto'];
        $fields_0 = $_REQUEST['fields_0'];
        $fields_1 = $_REQUEST['fields_1'];
        $fields_2 = $_REQUEST['fields_2'];
        $fields_3 = $_REQUEST['fields_3'];
        $fields_4 = $_REQUEST['fields_4'];
        $fields_5 = $_REQUEST['fields_5'];
        $fields_6 = $_REQUEST['fields_6'];
        $sort = $_REQUEST['sort'];
        $level = $_REQUEST['level'];
        $pjclosed = $_REQUEST['pjclosed'];

        # Als erstes pruefen wir, ob die wichtigen Parameter auch korrekt
        # gesetzt wurden.
        if ($dfrom > $dto) {
           Error(GetMessage(-1, 302, "Das Beginndatum darf nicht h&ouml;her sein als das Endedatum!"));
           return;
        }

        $tmpfile = tempnam("/tmp", "pjtool");
        unlink($tmpfile);
        $tmpfileps = $tmpfile . ".ps";
        $tmpfilepdf = $tmpfile . ".pdf";

        $db = OpenDB();
        $ps = PS_new();

        if (PS_open_file($ps, $tmpfileps) == 0) {
           Error(GetMessage($db, 303, "Error: Konnte keine tempor&auml;re Postscriptdatei &ouml;ffnen!"));
           return;
        }

        PS_set_info($ps, "Creator", "Theos Soft Project Manager v$strVersion");
        PS_set_info($ps, "Author", "Andreas Theofilu");
        PS_set_info($ps, "Title", "Auswertung");
        PS_set_info($ps, "Keywords", "TheoSys, TheoPlan, Andreas, Theofilu, Auswertung, ProjectManager");
        PS_set_info($ps, "BoundingBox", "0 0 $pheight $pwidth");
        PS_set_info($ps, "Orientation", "Landscape");
        PS_set_parameter($ps, "hyphenation", "false");
        PS_set_parameter($ps, "warning", "false");
        $helvN = PS_findfont($ps, "$SearchPath/phvr8a", "", "");
        $helvB = PS_findfont($ps, "$SearchPath/phvb8a", "", "");

        $top = $pheight - 30;
        $left = 40;
        HeadLine($ps);          // print static head line

        # In einem ersten Schritt zeichnen wir eine Box in der die gewaehlten
        # Parameter angezeigt werden:
        #
        PS_setfont($ps, $helvN, 10.0);
        $len1 = PS_stringwidth($ps, GetMessage($db, 304, "Sortierreihenfolge:") . " ");
        $chlen = GetMessage($db, 241, "Alle");
        $y = $top;
        $x = $left;
        PS_set_text_pos($ps, $x, $y);
        PS_show($ps, GetMessage($db, 1, "Projekt:"));
        PS_set_text_pos($ps, $x + $len1, $y);

        if ($pl_num == 0) {
           PS_show($ps, GetMessage($db, 241, "Alle"));
        } else {
           $query = "select pl_prnum, pr_name from plan, project ";
           $query .= "where pr_num = pl_prnum and pl_num = $pl_num";
           $result = QueryDB($db, $query);

           if (!$result) {
              closeDB($db);
              return;
           }

           $data = fetchDB($result, 0);
           $pr_num = $data[0];
           $pr_name = $data[1];
           PS_show($ps, "$pr_num $pr_name");
           if (strlen("$pr_num $pr_name") > strlen($chlen))
              $chlen = "$pr_num $pr_name";
        }

        $y -= 10;
        PS_set_text_pos($ps, $x, $y);
        PS_show($ps, GetMessage($db, 305, "Mitarbeiter:"));
        PS_set_text_pos($ps, $x + $len1, $y);

        if ($mi_num == 0) {
           PS_show($ps, GetMessage($db, 241, "Alle"));
        } else {
           $query = "select mi_nname, mi_vname from mitarbeiter where mi_num = $mi_num";
           $result = QueryDB($db, $query);

           if (!$result) {
              closeDB($db);
              return;
           }

           $data = fetchDB($result, 0);
           $mi_nname = $data[0];
           $mi_vname = $data[1];
           PS_show($ps, "$mi_nname $mi_vname");
           if (strlen("$mi_nname $mi_vname") > strlen($chlen))
              $chlen = "$mi_nname $mi_vname";
        }

        $y -= 10;
        PS_set_text_pos($ps, $x, $y);
        PS_show($ps, GetMessage($db, 306, "Zeitraum:"));
        PS_set_text_pos($ps, $x + $len1, $y);
        $text = GetMessage($db, 307, "Von:") . " " . date("n.Y", $dfrom) . " ";
        $text .= GetMessage($db, 308, "Bis:") . " " . date("n.Y", $dto);
        PS_show($ps, $text);

        if (strlen($text) > strlen($chlen))
           $chlen = $text;

        $y -= 10;
        PS_set_text_pos($ps, $x, $y);
        PS_show($ps, GetMessage($db, 309, "Spaltenauswahl:"));
        PS_set_text_pos($ps, $x + $len1, $y);

        if ($fields_2 > 0) {
           PS_show($ps, GetMessage($db, 291, "Gruppe"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        if ($fields_6 > 0) {
           PS_show($ps, GetMessage($db, 206, "Phasen"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        if ($fields_0 > 0) {
           PS_show($ps, GetMessage($db, 310, "Tasks anzeigen"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        if ($fields_1 > 0) {
           PS_show($ps, GetMessage($db, 294, "Anmerkungen"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        if ($fields_4 > 0) {
           PS_show($ps, GetMessage($db, 311, "IST-Werte"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        if ($fields_3 > 0) {
           PS_show($ps, GetMessage($db, 312, "IST- / Plandifferenz"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        if ($fields_5 > 0) {
           PS_show($ps, GetMessage($db, 313, "Planwerte"));
           $y -= 10;
           PS_set_text_pos($ps, $x + $len1, $y);
        }

        PS_set_text_pos($ps, $x, $y);
        ps_show($ps, GetMessage($db, 304, "Sortierreihenfolge:"));
        PS_set_text_pos($ps, $x + $len1, $y);

        if ($sort == 1)
           PS_show($ps, GetMessage($db, 314, "Projekte / Mitarbeiter"));
        else
           PS_show($ps, GetMessage($db, 315, "Mitarbeiter / Projekte"));

/*      $y -= 10;
        PS_set_text_pos($ps, $x, $y);
        PS_show($ps, "Plantiefe:");
        PS_set_text_pos($ps, $x + $len1, $y);

        if ($level == -1)
           PS_show($ps, "Alle");
        else
           PS_show($ps, "Bis zu Level $level");
*/
        $len2 = PS_stringwidth($ps, $chlen);
        PS_setlinewidth($ps, 0.4);
        PS_moveto($ps, $x - 4, $y - 4);
        PS_rect($ps, $x - 4, $y - 4, $len1 + $len2 + 8, $top - $y + 14);
        PS_stroke($ps);
        $y -= 14;

        if ($sort == 1)
           ProjektMaPDF($ps, $db, $pr_num, $y, $mi_num);
        else
           MitarbeiterPjPDF($ps, $db, $mi_num, $y, $pr_num);

        PS_end_page($ps);
        PS_close($ps);
        PS_delete($ps);
        passthru("/usr/bin/ps2pdf -sPAPERSIZE=a4 $tmpfileps $tmpfilepdf");
        closeDB($db);
        unlink($tmpfileps);
        $len = filesize($tmpfilepdf);
        $browser = GetBrowserInfo("browser");

        if ($browser == "IE") {         // workaround for braindead browser!
           header("Pragma: public");
           header("Expires: 0");
           header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
           header("Content-type: application/pdf");
//         header("Content-Length: $len");
           header("Content-Disposition: attachment; filename=\"auswertung.pdf\"");
        } else {
           header("Content-type: application/pdf");
           header("Content-Length: $len");
           header("Content-Disposition: inline; filename=\"auswertung.pdf\"");
        }

        readfile($tmpfilepdf);
        unlink($tmpfilepdf);
}

# Auswertung der Funktionen
if ($func == "prlist") {
   $pl_num = $_REQUEST['pl_num'];
   $mi_num = $_REQUEST['mi_num'];
   $dfrom = $_REQUEST['dfrom'];
   $dto = $_REQUEST['dto'];
   $fields_0 = $_REQUEST['fields_0'];
   $fields_1 = $_REQUEST['fields_1'];
   $fields_2 = $_REQUEST['fields_2'];
   $fields_3 = $_REQUEST['fields_3'];
   $fields_4 = $_REQUEST['fields_4'];
   $fields_5 = $_REQUEST['fields_5'];
   $fields_6 = $_REQUEST['fields_6'];
   $sort = $_REQUEST['sort'];
   $level = $_REQUEST['level'];

   PrintListPDF();
}

if ($func == "pauswertung") {
   PrintListPDF();
}

//require('footer.inc');
?>