Location: PHPKode > projects > TheoPlan > pm/revisor.php
<?
require_once('version.inc');
require_once('dbaccess.inc');
require_once('language.inc');
require_once('header.inc');
require_once('helper.inc');
require_once('crypt.inc');
require_once('settings.inc');

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

# Auswertungsmenue
//if (isset($_REQUEST['revisor'])) { $knopf = 27; $headline = 34; }

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

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

# This module contains the following functions:
#    Preselect
#    ZSum
#    Cell
#    ProjektMa
#    MitarbeiterPj
#    PrintList

# Folgende Funktion erlaubt die Auswahl einiger Voreinstellungen und
# Einschraenkungen fuer den Statusbericht.
#
function Preselect($repeat=0) {
	global $periode;
	global $phase;
	global $menu;

	$db = OpenDB();
	$nav = "mi_num='+wahl.mi_num.value+'&sort1='+wahl.sort[0].checked+'&sort2='+wahl.sort[1].checked+'&menu=$menu&headline=31";

	if ($repeat == 1)
	   $plnum = $_REQUEST['pl_num'];

	# Folgende Maske zeigt zwei ineinander verschachtelte Tabellen
	# um die einzelnen Wahlelemente optisch voneinader zu trennen.
?>
<form name="wahl" action="auswertung.php" method="post">
<input type="hidden" name="menu" value="<? echo "$menu"; ?>">
<input type="hidden" name="headline" value="31">
<input type="hidden" name="func" value="prlist">

<table class="sel">
<tr><th class="sel" colspan=2>Projektauswahl</th></tr>
<tr><td class="sel">
<?php
	# Auswahl eines freigegebenen oder fertigen Projekts
	echo "Projekte:</td>\n";
	echo "<td class=\"sel\">";

	$query = "select pl_num, pl_prnum, pl_lfd, pr_name, pl_status from plan, project ";
	$query .= "where pr_num = pl_prnum and pl_status in (1,2,3,4) ";
	$query .= "order by pl_prnum, pl_lfd desc";

	$result = QueryDB($db, $query);

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

	echo "<select name=\"pl_num\" ";
	echo "onchange=\"javascript:MoveTo('auswertung.php', ";
	echo "'func=repeatpj&pl_num='+this.value+'&$nav')\">\n";
	$numrows = numrowsDB($result);
	$rows = 0;

	while ($rows < $numrows) {
	   $data = fetchDB($result, $rows);
	   $pl_num = $data[0];
	   $pl_prnum = $data[1];
	   $pl_lfd = $data[2];
	   $pr_name = $data[3];
	   $pl_status = $data[4];

	   if ($rows == 0) {
	      if (isset($plnum) && $plnum == 0)
	         echo "<option value=\"0\" selected>Alle</option>\n";
	      else
	         echo "<option value=\"0\">Alle</option>\n";
	   }

	   if ($pl_status == 1)
	      $vz = "<*>:";
	   else
	      $vz = "$pl_lfd:";

	   if (isset($plnum) && $plnum == $pl_num)
	      echo "<option value=\"$pl_num\" selected>$vz $pl_prnum $pr_name</option>\n";
	   else
	      echo "<option value=\"$pl_num\">$vz $pl_prnum $pr_name</option>\n";
	   $rows++;
	}

	echo "</select></td></tr>\n";
	# Mitarbeiterauswahl
	echo "<tr><th class=\"sel\" colspan=2>Mitarbeiterauswahl</th></tr>\n";
	echo "<tr><td class=\"sel\">Mitarbeiter:</td>";
	echo "<td class=\"sel\">\n";


	if ($repeat == 1 && isset($plnum) && $plnum > 0) {
	   $query = "select distinct wd_minum, mi_nname, mi_vname from ";
	   $query .= "wdone, mitarbeiter, task where mi_num = wd_minum and ";
	   $query .= "ta_num = wd_task and ta_plnum = $plnum ";
	   $query .= "order by mi_nname, mi_vname";
	} else {
	   $query = "select mi_num, mi_nname, mi_vname from mitarbeiter ";
	   $query .= "order by mi_nname, mi_vname";
	}

	$result = QueryDB($db, $query);

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

	echo "<select name=\"mi_num\">\n";
	$numrows = numrowsDB($result);
	$rows = 0;

	while ($rows < $numrows) {
	   $data = fetchDB($result, $rows);
	   $mi_num = $data[0];
	   $mi_nname = $data[1];
	   $mi_vname = $data[2];

	   if ($rows == 0)
	      echo "<option value=\"0\">Alle</option>\n";

	   if ($mi_num == $_REQUEST['mi_num'])
	      echo "<option selected value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
	   else
	      echo "<option value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
	   $rows++;
	}

	echo "</select></td></tr>\n";

	# Zeitraum
	echo "<tr><th class=\"sel\" colspan=2>Anzuzeigender Zeitraum</th></tr>\n";
	echo "<tr><td class=\"sel\">Zeitraum:</td>\n";
	echo "<td class=\"sel\">";
	$query = "select ta_start from task";

	if ($repeat == 1 && isset($plnum) && $plnum > 1)
	   $query .= " where ta_plnum = $plnum ";

	$query .= " order by ta_start";
	$result = QueryDB($db, $query);

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

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

	$query = "select ta_start + (ta_duration * 86400) as ds from task";

	if ($repeat == 1 && isset($plnum) && $plnum > 1)
	   $query .= " where ta_plnum = $plnum ";

	$query .= " order by ds desc";
	$result = QueryDB($db, $query);

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

	$data = fetchDB($result, 0);
	$ldate = $data[0];
	$dt = time();
	$mon = date ("n", $dt);
	$year = date("Y", $dt);

	if ($mon < 6)
	   $mon = 1;
	else
	   $mon = 6;

	$dfirst = mktime(0, 0, 0, $mon, 1, $year);

	if ($ldate < $dt) {
	   $mon = date("n", $ldate);
	   $year = date("Y", $ldate);
	   $dlast = mktime(0, 0, 0, $mon, 1, $year);
	}
	else {
	   if ($mon == 1)
	      $mon = 6;
	   else if ($mon == 6)
	      $mon = 12;

	   $zw = mktime(0, 0, 0, $mon, 1, $year);

	   if ($zw <= $ldate)
	      $dlast = $zw;
	   else {
	      $mon = date("n", $ldate);
	      $dlast = mktime(0, 0, 0, $mon, 1, $year);
	   }
	}

	$cd = $fdate;
	echo "Von:&nbsp;<select name=\"dfrom\">\n";

	while ($cd < $ldate) {
	   $mon = date("n", $cd);
	   $year = date("Y", $cd);
	   $zw = mktime(0, 0, 0, $mon, 1, $year);

	   if ($zw == $dfirst)
	      echo "<option value=\"$zw\" selected>$mon.$year</option>\n";
	   else
	      echo "<option value=\"$zw\">$mon.$year</option>\n";

	   $cd = IncDate($periode, $zw);
	}

	echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;";
	$cd = $fdate;
	echo "Bis:&nbsp;<select name=\"dto\">\n";

	while ($cd < $ldate) {
	   $mon = date("n", $cd);
	   $year = date("Y", $cd);
	   $zw = mktime(0, 0, 0, $mon, 1, $year);

	   if ($zw == $dlast)
	      echo "<option value=\"$zw\" selected>$mon.$year</option>\n";
	   else
	      echo "<option value=\"$zw\">$mon.$year</option>\n";

	   $cd = IncDate($periode, $zw);
	}

	echo "</select></td></tr>\n";
	# Anzeigenauswahl
	echo "<tr><th class=\"sel\" colspan=2>Anzeigenauswahl</th></tr>\n";
	echo "<tr><td class=\"sel\">Spaltenauswahl:</td>\n";
	echo "<td class=\"sel\"><table border=0><tr>";
	echo "<td class=\"selnf\"><input type=\"checkbox\" value=\"1\" name=\"fields_0\">Tasks anzeigen</td>\n";
	echo "<td class=\"selnf\"><input type=\"checkbox\" value=\"2\" name=\"fields_1\">Anmerkungen</td></tr><tr>\n";
	echo "<td class=\"selnf\"><input type=\"checkbox\" value=\"3\" name=\"fields_2\">Gruppe</td>\n";
	echo "<td class=\"selnf\"><input type=\"checkbox\" value=\"4\" name=\"fields_3\" checked ";
	echo "onClick=\"javascript:if (document.wahl.fields_4.checked == false ||";
	echo "document.wahl.fields_5.checked == false) { this.checked = false; }\">IST- Plandifferenz</td></tr><tr>\n";
	echo "<td class=\"selnf\"><input type=\"checkbox\" value=\"5\" name=\"fields_4\" checked ";
	echo "onClick=\"javascript:if (this.checked == false) { document.wahl.fields_3.checked = false; } ";
	echo "if (this.checked == false && document.wahl.fields_5.checked == false) { this.checked = true; }\">IST-Werte</td>\n";
	echo "<td class=\"selnf\"><input type=\"checkbox\" value=\"6\" name=\"fields_5\" checked ";
	echo "onClick=\"javascript:if (this.checked == false) { document.wahl.fields_3.checked = false; } ";
	echo "if (this.checked == false && document.wahl.fields_4.checked == false) { this.checked = true; }\">Planwerte</td></tr>\n";

	if ($phase)
	   echo "<tr><td class=\"selnf\" colspan=2><input type=\"checkbox\" value=\"7\" name=\"fields_6\" checked>Phase</td></tr>\n";

	echo "</table>\n";
	echo "</td></tr>\n";

	echo "<tr><td class=\"sel\">Sortierreihenfolge:</td>\n";

	if ($_REQUEST['sort1'] == "true")
	   $sort = 1;
	else if ($_REQUEST['sort2'] == "true")
	   $sort = 2;
	else
	   $sort = 2;

	echo "<td class=\"sel\">";
	echo "<input type=\"radio\" name=\"sort\" ";

	if ($sort == 1)
	   echo "checked ";

	echo "value=\"1\">Projekte / Mitarbeiter<br>\n";
	echo "<input type=\"radio\" name=\"sort\" ";

	if ($sort == 2)
	   echo "checked ";

	echo "value=\"2\">Mitarbeiter / Projekte\n";
	echo "</td></tr>\n";

	echo "<tr><td class=\"sel\">Plantiefe:</td>\n";
	echo "<td class=\"sel\">";
	echo "<select name=\"level\" disabled>\n";
	echo "<option value=\"-1\">Alle</option>\n";
	echo "<option value=\"0\">0</option>\n";
	echo "<option value=\"1\">1</option>\n";
	echo "<option value=\"2\">2</option>\n";
	echo "<option value=\"3\">3</option>\n";
	echo "<option value=\"4\">4</option>\n";
	echo "<option value=\"5\">5</option>\n";
	echo "<option value=\"6\">6</option>\n";
	echo "<option value=\"7\">7</option>\n";
	echo "<option value=\"8\">8</option>\n";
	echo "<option value=\"9\">9</option>\n";
	echo "</select></td></tr>\n";

	echo "<tr><td class=\"selmid\" colspan=2>";
	ButtonSubmit("Senden", "wahl");
//	echo "<input type=\"submit\" name=\"submit\" value=\"Senden\"> <input type=\"reset\">\n";
	echo "</td></tr></table>\n";
	echo "</form>\n";
	closeDB($db);
}

# Zeilensumme ausgeben
#
function ZSum($sumi, $sump) {
	$fields_3 = $_REQUEST['fields_3'];
	$fields_4 = $_REQUEST['fields_4'];
	$fields_5 = $_REQUEST['fields_5'];

	if ($fields_4 > 0)
	   echo "<td class=\"seldkgray\" align=\"right\">" . FormatNum($sumi, 3) . "</td>";

	if ($fields_3 > 0)
	   echo "<td class=\"seldkgray\" align=\"right\">" . FormatNum($sump - $sumi, 3) . "</td>";

	if ($fields_5 > 0)
	   echo "<td class=\"seldkgray\" align=\"right\">" . FormatNum($sump, 3) . "</td>";

	echo "\n";
}

# Schreiben einer Zelle
#
function Cell($class, $ist, $plan, $blank=false, $per=0) {
	$fields_3 = $_REQUEST['fields_3'];
	$fields_4 = $_REQUEST['fields_4'];
	$fields_5 = $_REQUEST['fields_5'];

	if ($fields_4 > 0) {
	   echo "<td class=\"$class\" align=\"right\">";

	   if ($blank)
	      echo "&nbsp;";
	   else
	      echo FormatNum($ist, 3);

	   if ($per > 0)
	      echo "<br>" . date("n/Y", $per);

	   echo "</td>";
	}

	if ($fields_3 > 0) {
	   echo "<td class=\"$class\" align=\"right\">";

	   if ($blank)
	      echo "&nbsp;";
	   else
	      echo FormatNum($plan - $ist, 3);

	   echo "</td>";
	}

	if ($fields_5 > 0) {
	   echo "<td class=\"$class\" align=\"right\">";

	   if ($blank)
	      echo "&nbsp;";
	   else
	      echo FormatNum($plan, 3);

	   echo "</td>";
	}
}

# Folgende Funktion erzeugt die Liste aller Projekte. Die Liste
# sortiert nach Projekten und Mitarbeitern (Projektsicht).
#
function ProjektMa($db, $pr_num, $mi_num=0) {
	global $periode;
	global $phase;
	$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'];

	# Beim bis-Datum den Monatsletzten ermitteln
	$mon = date("n", $dto);
	$year = date("Y", $dto);
	$day = daysinmonth($mon, $year);
	$dto = mktime(23, 59, 59, $mon, $day, $year);
	# Den Projektnamen ermitteln
	$query = "select pr_num, pr_name 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;

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

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

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

	$csp = 4;

	if ($fields_6 > 0)
	   $csp++;

	if ($fields_0 > 0)
	   $csp++;

	if ($fields_1 > 0)
	   $csp++;

	if ($fields_2 > 0)
	   $csp++;

	$pl_flag = false;
	$TempTable = false;

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

	   # 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];
	   $np = $numper * $mult;
	   $c = $csp + $np;

	   # Zeichnen des Tabellenkopfs
	   echo "<table class=\"sel\"><tr>";
	   echo "<td class=\"sel\" colspan=$c>Projekt: $pr_num $pr_name</td></tr>\n";
	   $c = $csp - 3;
	   echo "<tr><td class=\"sel\" colspan=$c>&nbsp;</td>\n";

	   # 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) {
	      echo "</tr></table>";
	      return;
	   }

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

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

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

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

	      while ($adate < $tmp_periode) {
	         $p = date("n/Y", $adate);
	         echo "<th colspan=$mult class=\"sel\">$p</th>\n";
	         $adate = IncDate($periode, $adate);
	         $sumperp[$x] = 0.0;
	         $sumperi[$x] = 0.0;
	         $totalis[$x] = 0.0;
	         $totalpl[$x] = 0.0;
	         $x++;
	      }

	      echo "<th colspan=$mult class=\"sel\">$mon/$year</th>\n";
	      $sumperp[$x] = 0.0;
	      $sumperi[$x] = 0.0;
	      $totalis[$x] = 0.0;
	      $totalpl[$x] = 0.0;
	      $adate = IncDate($periode, $adate);
	      $r++;
	      $x++;
	   }

	   $ldate = $tmp_periode;
	   echo "<th colspan=$mult class=\"sel\">Summen</th></tr>\n";
	   echo "<tr><th class=\"sel\">Mitarbeiter</th>";

	   if ($fields_2 > 0)
	      echo "<th class=\"sel\">Gruppe</th>";

	   if ($phase && $fields_6 > 0)
	      echo "<th class=\"sel\">Phase</th>";

	   if ($fields_0 > 0)
	      echo "<th class=\"sel\">Tasks</th>";

	   if ($fields_1 > 0)
	      echo "<th class=\"sel\">Anmerkungen</th>";

	   $r = 0;

	   while ($r <= $x) {
	      if ($pist > 0)
	         echo "<th class=\"sel\">IST</th>\n";

	      if ($pplan > 0 && $pdiff > 0)
	         echo "<th class=\"sel\">Diff.</th>\n";

	      if ($pplan > 0)
	         echo "<th class=\"sel\">Plan</th>\n";

	      $r++;
	   }

	   echo "</tr>\n";

	   $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 ";
	   $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 = "nw";

	   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];

	      # 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) {
		       Cell($class, 0, 0, true);

		       if ($class == "selltgray")
		          $class = "selgray";
		       else
		          $class = "selltgray";

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

		    ZSum($sumlis, $sumlpl);
		    echo "</tr>\n";
		 }

		 if (!$first && $oldminame != $tmp_miname) {
		    $cp = $csp - 3;
		    # Monatssummen nach einem Mitarbeiterwechsel
		    #
		    echo "<tr><td class=\"selnum\" colspan=$cp><b>Zwischensumme:</b></td>";
		    $adate = $fdate;
		    $per = 0;
		    $sumi = 0.0;
		    $sump = 0.0;

		    while ($adate <= $ldate) {
		       Cell("lsum", $sumperi[$per], $sumperp[$per]);
		       $adate = IncDate($periode, $adate);
		       $sumi += $sumperi[$per];
		       $sump += $sumperp[$per];
		       $sumperi[$per] = 0.0;
		       $sumperp[$per] = 0.0;
		       $per++;
		    }

		    Zsum($sumi, $sump);
		    echo "\n";
		 }

		 # Beginn der Zeile: Schreiben der ersten fixen Zellen.
		 #
		 echo "<tr><td class=\"selltgray\">$mi_nname $mi_vname</td>\n";

		 if ($fields_2 > 0)
		    echo "<td class=\"selltgray\">$kl_land</td>\n";

		 if ($phase && $fields_6 > 0)
		    echo "<td class=\"selltgray\">$tmp_phase: $kp_phase</td>\n";

		 if ($fields_0 > 0)
		    echo "<td class=\"selltgray\">$tmp_taname</td>\n";

		 if ($fields_1 > 0)
		    echo "<td class=\"selltgray\">$tmp_notiz</td>\n";

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

	      # Stimmt die aktuelle Position nicht mit der Periode ueberein,
	      # uebergehen wir die Zellen.
	      #
	      while ($adate < $tmp_periode) {
		 Cell($class, 0, 0, true);

		 if ($class == "selltgray")
		    $class = "selgray";
		 else
		    $class = "selltgray";

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

	      # Schreiben einer Zelle mit den aktuellen Werten.
	      Cell($class, $tmp_ist, $tmp_plan);

	      if ($class == "selltgray")
	         $class = "selgray";
	      else
	         $class = "selltgray";

	      $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) {
	      Cell($class, 0, 0, true);

	      if ($class == "nw")
	         $class = "nw1";
	      else
	         $class = "nw";

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

	   ZSum($sumlis, $sumlpl);
	   # Summenzeile am Ende der Tabelle fuer den letzten Mitarbeiter
	   # anzeigen.
	   #
	   $cp = $csp - 3;
	   echo "<tr><td class=\"selnum\" colspan=$cp><b>Zwischensumme:</b></td>";
	   $adate = $fdate;
	   $per = 0;
	   $sumi = 0.0;
	   $sump = 0.0;	   # Wurde kein Projekt gewaehlt, dann muessen wir die Plannummer
	   # ermitteln. In diesem Fall zeigen wir immer den aktuelsten Plan
	   # an.


	   while ($adate <= $ldate) {
	      Cell("seldkgray", $sumperi[$per], $sumperp[$per]);
	      $adate = IncDate($periode, $adate);
	      $sumi += $sumperi[$per];
	      $sump += $sumperp[$per];
	      $sumperi[$per] = 0.0;
	      $sumperp[$per] = 0.0;
	      $per++;
	   }

	   ZSum($sumi, $sump);

	   # Monatssummen und Gesamtzeitraumsumme am Ende der Tabelle
	   # anzeigen.
	   #
	   echo "<tr><td class=\"selnum\" colspan=$cp><b>Monatssummen:</b></td>";
	   $adate = $fdate;
	   $per = 0;
	   $sumi = 0.0;
	   $sump = 0.0;

	   while ($adate <= $ldate) {
	      Cell("seldkgray", $totalis[$per], $totalpl[$per]);
	      $adate = IncDate($periode, $adate);
	      $sumi += $totalis[$per];
	      $sump += $totalpl[$per];
	      $per++;
	   }

	   Cell("two", $sumi, $sump);
	   echo "</tr>\n</table><br>\n";
	   $pospr++;
	}
}

# Folgende Funktion erzeugt die Liste fuer genau einen Mitarbeiter. Die Liste
# sortiert nach Mitarbeitern und Projekten.
#
function MitarbeiterPj($db, $mi_num, $prp_num=0) {
	global $periode;
	global $phase;
//	$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'];

	# Beim bis-Datum den Monatsletzten ermitteln
	$mon = date("n", $dto);
	$year = date("Y", $dto);
	$day = daysinmonth($mon, $year);
	$dto = mktime(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;

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

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

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

	$csp = 4;

	if ($fields_6 > 0)
	   $csp++;

	if ($fields_0 > 0)
	   $csp++;

	if ($fields_1 > 0)
	   $csp++;

	# 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++;
	}

	$np = $numper * $mult;
	$TempTable = false;
	echo "<table class=\"sel\">";

	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.
	   $query = "select al_num from allocation where ";
	   $query .= "al_ressource = $mi_num and al_pstart between $dfrom and $dto";
	   $result = QueryDB($db, $query);

	   if (!$result)
	      return;

	   $anz = numrowsDB($result);

	   if ($anz < 1) {
	      $posmi++;
	      continue;
	   }

	   # Zeichnen des Tabellenkopfs
	   # Bei jedem Mitarbeiterwechsel wird ein neuer Tabellenkopf
	   # gezeichnet.
	   #
	   $c = $csp + $np;
	   echo "<tr><td class=\"sel\" colspan=$c>";
	   echo "<table border=0 cellpadding=0><tr><td>Name:</td><td>$mi_nname $mi_vname</td></tr>\n";
	   echo "<tr><td>Gruppe:</td><td>$kl_land</td></tr>\n";

	   if (!$pmlight)
	      echo "<tr><td>Abteilung:</td><td>$ka_abt</td></tr>\n";

	   echo "</table></td></tr>\n";
	   $c = $csp - 3;
	   echo "<tr><td class=\"sel\" colspan=$c>&nbsp;</td>\n";
	   $r = 0;
	   $adate = $dfrom;

	   while ($r < $numper) {
	      $p = date("n/Y", $adate);
	      echo "<th colspan=$mult class=\"sel\">$p</th>\n";
	      $adate = IncDate($periode, $adate);
/*	      $sumperp[$x] = 0.0;
	      $sumperi[$x] = 0.0;
	      $totalis[$x] = 0.0;
	      $totalpl[$x] = 0.0;
	      $mitotp[$x] = 0.0;
	      $mitoti[$x] = 0.0; */
	      $r++;
	   }

	   echo "<th colspan=$mult class=\"sel\">Summen</th></tr>\n";
	   echo "<tr><th class=\"sel\">Projekt</th>";

	   if ($phase && $fields_6 > 0)
	      echo "<th class=\"sel\">Phase</th>";

	   if ($fields_0 > 0)
	      echo "<th class=\"sel\">Tasks</th>";

	   if ($fields_1 > 0)
	      echo "<th class=\"sel\">Anmerkungen</th>";

	   $r = 0;

	   while ($r <= $numper) {
	      if ($pist > 0)
	         echo "<td class=\"selinfo_l\" align=\"center\"><b>IST</b></td>\n";

	      if ($pplan > 0 && $pdiff > 0)
	         echo "<td class=\"selinfo\" align=\"center\"><b>Diff.</b></td>\n";

	      if ($pplan > 0)
	         echo "<td class=\"selinfo_r\" align=\"center\"><b>Plan</b></td>\n";

	      $r++;
	   }

	   echo "</tr>\n";

	   # 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 ";

	   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];

	      if ($TempTable)
		 TQueryDB($db, "drop table TempPlan");

	      $TempTable = true;

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

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

	      # Tabelleninhalt schreiben:
	      # Die Inhalte werden der zuvor temporaer erzeugten Tabelle
	      # entnommen.
	      #
	      $query = "select tmp_phase, tmp_periode, tmp_plan, tmp_ist,";
	      $query .= "tmp_taname, tmp_notiz, kp_phase ";
	      $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";
	      $result = QueryDB($db, $query);

	      if (!$result)
		 return;

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

	      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];
		 $kp_phase = $data[6];

		 # 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) {
			  Cell($class, 0, 0, true);

			  if ($class == "selltgray")
			     $class = "selgray";
			  else
			     $class = "selltgray";

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

		       ZSum($sumlis, $sumlpl);
		       echo "</tr>\n";
		    }

		    $cp = $csp - 3;
		    # Beginn der Zeile: Schreiben der ersten fixen Zellen.
		    #
		    echo "<tr><td class=\"sel\">$pr_num $pr_name</td>\n";

		    if ($phase && $fields_6 > 0)
		       echo "<td class=\"sel\">$tmp_phase: $kp_phase</td>\n";

		    if ($fields_0 > 0)
		       echo "<td class=\"sel\">$tmp_taname</td>\n";

		    if ($fields_1 > 0)
		       echo "<td class=\"sel\">$tmp_notiz</td>\n";

		    # Variablen initialisieren...
		    #
		    $sumlis = 0.0;
		    $sumlpl = 0.0;
		    $per = 0;
		    $adate = $dfrom;
		    $oldphase = $tmp_phase;
		    $oldtask = $tmp_taname;
		    $first = false;
		    $class = "selltgray";
		 }

		 # Stimmt die aktuelle Position nicht mit der Periode ueberein,
		 # uebergehen wir die Zellen.
		 #
		 while ($adate < $tmp_periode) {
		    Cell($class, 0, 0, true);

		    if ($class == "selltgray")
		       $class = "selgray";
		    else
		       $class = "selltgray";

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

	         # Schreiben einer Zelle mit den aktuellen Werten.
	         Cell($class, $tmp_ist, $tmp_plan, false);

	         if ($class == "selltgray")
	            $class = "selgray";
	         else
	            $class = "selltgray";

	         $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 der letzten Datenzeile der aktuellen Tabelle.
	      #
	      while ($adate <= $dto) {
	         Cell($class, 0, 0, true);

	         if ($class == "selltgray")
	            $class = "selgray";
	         else
	            $class = "selltgray";

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

	      ZSum($sumlis, $sumlpl);
	      echo "</tr>\n";
	      $cp = $csp - 3;

	      if ($prp_num == 0) {
	         echo "<tr><td class=\"selnum\" colspan=$cp><b>Projektsumme:</b></td>";
	         $adate = $dfrom;
	         $per = 0;
	         $sumi = 0.0;
	         $sump = 0.0;

	         while ($adate <= $dto) {
		    Cell("lsum", $sumperi[$per], $sumperp[$per]);
		    $adate = IncDate($periode, $adate);
		    $sumi += $sumperi[$per];
		    $sump += $sumperp[$per];
		    $sumperi[$per] = 0.0;
		    $sumperp[$per] = 0.0;
		    $per++;
	         }

	         Zsum($sumi, $sump);
	         echo "</tr>\n";
	      }

	      $pospr++;
	   }

	   $cp = $csp - 3;
	   echo "<tr><td class=\"selnum\" colspan=$cp><b>Gesamtsumme Mitarbeiter:</b></td>";
	   $adate = $dfrom;
	   $per = 0;
	   $sumi = 0.0;
	   $sump = 0.0;

	   while ($adate <= $dto) {
	      Cell("seldkgray", $mitoti[$per], $mitotp[$per]);
	      $adate = IncDate($periode, $adate);
	      $sumi += $mitoti[$per];
	      $sump += $mitotp[$per];
	      $mitoti[$per] = 0.0;
	      $mitotp[$per] = 0.0;
	      $per++;
	   }

	   Zsum($sumi, $sump);
	   echo "</tr>\n";
	   $posmi++;
	}

	# Monatssummen und Gesamtzeitraumsumme am Ende der Tabelle
	# anzeigen.
	#
	if ($mi_num == 0) {
	   echo "<tr><td class=\"selnum\" colspan=$cp><b>Monatssummen:</b></td>";
	   $adate = $dfrom;
	   $per = 0;
	   $sumi = 0.0;
	   $sump = 0.0;

	   while ($adate <= $dto) {
	      Cell("sum", $totalis[$per], $totalpl[$per]);
	      $adate = IncDate($periode, $adate);
	      $sumi += $totalis[$per];
	      $sump += $totalpl[$per];
	      $per++;
	   }

	   Cell("two", $sumi, $sump);
	   echo "</tr>\n";
	}

	echo "</table><br>\n";
}

# Folgende Funktion wertet die vom Anwender getroffenen Einstellungen aus
# und ruft die entsprechenden Funktionen auf um die Listen darzustellen.
#
function PrintList() {
	global $phase;
	global $pmlight;
	$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'];

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

	$db = OpenDB();
	# In einem ersten Schritt zeichnen wir eine Box in der die gewaehlten
	# Parameter angezeigt werden:
	#
	echo "<table class=\"input\">\n";
	echo "<tr><td><table border=0 cellpadding=0 cellspacing=0>\n";
	echo "<tr><td>Projekt:</td><td>";

	if ($pl_num == 0) {
	   echo "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];
	   echo "$pr_num $pr_name";
	}

	echo "</td></tr>\n";
	echo "<tr><td>Mitarbeiter:</td><td>";

	if ($mi_num == 0) {
	   echo "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];
	   echo "$mi_nname $mi_vname";
	}

	echo "</td></tr>\n";
	echo "<tr><td>Zeitraum:</td><td class=\"selnf\">";
	echo "Von: " . date("n.Y", $dfrom) . " ";
	echo "Bis: " . date("n.Y", $dto);
	echo "</td></tr>\n";

	echo "<tr><td valign=\"top\">Spaltenauswahl:</td>\n";
	echo "<td class=\"selnf\">";

	if ($fields_2 > 0)
	   echo "Gruppe<br>\n";

	if ($fields_6 > 0)
	   echo "Phasen<br>\n";

	if ($fields_0 > 0)
	   echo "Tasks anzeigen<br>\n";

	if ($fields_1 > 0)
	   echo "Anmerkungen<br>\n";

	if ($fields_4 > 0)
	   echo "IST-Werte<br>\n";

	if ($fields_3 > 0)
	   echo "IST- / Plandifferenz<br>\n";

	if ($fields_5 > 0)
	   echo "Planwerte<br>\n";

	echo "</td></tr>\n";

	echo "<tr><td>Sortierreihenfolge:</td><td>\n";

	if ($sort == 1)
	   echo "Projekte / Mitarbeiter";
	else
	   echo "Mitarbeiter / Projekte";

	echo "</td></tr>\n";

/*	echo "<tr><td>Plantiefe:</td><td>\n";

	if ($level == -1)
	   echo "Alle";
	else
	   echo "Bis zu Level $level";

	echo "</td></tr>\n"; */
	echo "</table></td></tr></table><br>\n";

	if ($sort == 1)
	   ProjektMa($db, $pr_num, $mi_num);
	else
	   MitarbeiterPj($db, $mi_num, $pr_num);

	closeDB($db);
}

# Auswertung des Menues:
#
if ($knopf == 27)		// Ressourcenauslastung
   Preselect();

if ($func == "repeatpj")
   Preselect(1);

# 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'];

   echo "<table class=\"indent\"><tr><td>";
   ButtonPrint("Drucken", "auswertung.php",
//   echo "<a href=\"#\" onClick=\"javascript:open_mwindow('auswertung.php?";
   "pl_num=$pl_num&dfrom=$dfrom&dto=$dto&fields_0=$fields_0" .
   "&fields_1=$fields_1&fields_2=$fields_2&fields_3=$fields_3" .
   "&fields_4=$fields_4&fields_5=$fields_5&fields_6=$fields_6" .
   "&mi_num=$mi_num&sort=$sort&level=$level&header=2&" .
   "func=pauswertung"); //', 'Auswertung', 1000, 650)");
//   echo "<img src=\"image/print.png\" border=0 alt=\"Drucken\"></a>\n";
   echo "</td><td>";
   ButtonPrint("PDF Ausgabe", "auswertpdf.php",
   "pl_num=$pl_num&dfrom=$dfrom&dto=$dto&fields_0=$fields_0" .
   "&fields_1=$fields_1&fields_2=$fields_2&fields_3=$fields_3" .
   "&fields_4=$fields_4&fields_5=$fields_5&fields_6=$fields_6" .
   "&mi_num=$mi_num&sort=$sort&level=$level&header=2&" .
   "func=pauswertung", true);
//   echo "</td></tr><tr><td colspan=2>";
//   phpinfo();
   echo "</td></tr></table>";
   PrintList();
}

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

require('footer.inc');
?>
Return current item: TheoPlan