Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 3 → Rev 4

/pm/trunk/ist.php.old
0,0 → 1,1460
<?php
require_once('version.inc');
require_once('dbaccess.inc');
require_once('header.inc');
require_once('crypt.inc');
require_once('settings.inc');
require_once('menu.inc');
require_once('helper.inc');
require_once('knumber.inc');
 
$func = $_REQUEST['func'];
 
function ShowPeriod($wd_prnum, $user, $nav, $all = false) {
global $phase;
global $pmlight;
global $leneinheit;
global $unum;
 
$db = OpenDB();
$query = "select wd_datum, wd_minum, mi_nname, mi_vname, ta_name, ";
$query .= "wd_task, wd_edit from wdone, mitarbeiter, task ";
$query .= "where mi_num = wd_minum and ta_num = wd_task and ";
$query .= "wd_prnum = $wd_prnum ";
 
if (!$all)
$query .= "and wd_minum = $user order by ta_name, wd_datum";
else
$query .= "order by mi_nname, mi_vname, ta_name, wd_datum";
 
$result = QueryDB($db, $query);
 
if (!$result) {
Error ("Es wurden keine IST-Buchungen gefunden!");
return false;
}
 
# Welches Projekt wurde gewaehlt?
$query = "select pr_name, pr_pl, mi_nname, mi_vname from ";
$query .= "project, mitarbeiter where pr_num = $wd_prnum and ";
$query .= "mi_num = pr_pl";
$respr = QueryDB($db, $query);
 
if (!$respr) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($respr, 0);
$pr_name = $data[0];
$pr_pl = $data[1];
$mi_nname = $data[2];
$mi_vname = $data[3];
 
if ($all)
$cp = 5;
else
$cp = 4;
?>
<table class="sel">
<tr>
<?
echo "<td colspan=$cp class=\"selnf\">";
ButtonLink("Hinzuf&uuml;gen", "ist.php", "func=FormIST&$nav");
?>
</tr>
<tr>
<td colspan=<? echo "$cp"; ?> class="selinfo">
<table border=0>
<tr>
<td class="selnf">Projekt:</td>
<td class="selnf"><? echo "$wd_prnum $pr_name"; ?></td>
</tr>
<tr>
<td class="selnf">Projektleiter:</td>
<td class="selnf"><? echo "$mi_nname $mi_vname"; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<th class="sel">Aktion</td>
<?php
if ($all)
echo "<th class=\"sel\">Mitarbeiter</td>\n";
?>
<th class="sel">Taskname</td>
<th class="sel">Periode</td>
<th class="sel">Tage</td>
</tr>
<?php
$numrows = pg_num_rows($result);
$r = 0;
$oldfdate = 0;
$oldldate = 0;
$oldminum = 0;
$oldtask = 0;
$oldtaname = "";
$oldnname = "";
$oldvname = "";
$sum = 0.0;
$psum = 0.0;
 
while ($r < $numrows) {
$data = pg_fetch_row($result, $r);
$wd_datum = $data[0];
$wd_minum = $data[1];
$mi_nname = $data[2];
$mi_vname = $data[3];
$ta_name = $data[4];
$wd_task = $data[5];
$wd_edit = $data[6];
 
GetDateRange($wd_datum, &$fdate, &$ldate);
 
if ($r == 0) {
$oldfdate = $fdate;
$oldldate = $ldate;
$oldminum = $wd_minum;
$oldtask = $wd_task;
$oldtaname = $ta_name;
$oldnname = $mi_nname;
$oldvname = $mi_vname;
}
 
if ($oldfdate != $fdate || $oldldate != $ldate || $oldminum != $wd_minum || $oldtask != $wd_task) {
# Um auf die Periodensumme pro Task (und Mitarbeiter) zu kommen,
# suchen wir alle Eintraege pro Periode.
$query = "select sum(wd_hours)/$leneinheit from wdone ";
$query .= "where wd_prnum = $wd_prnum and wd_minum = $oldminum ";
$query .= "and wd_datum between $oldfdate and $oldldate ";
$query .= "and wd_task = $oldtask";
$result2 = QueryDB($db, $query);
 
if (!$result2) {
return false;
}
 
$data = pg_fetch_row($result2, 0);
$hours = $data[0];
 
# Einfuegen der Aktionen
echo "<tr><td class=\"selakt\">";
 
if ($wd_edit) {
echo "<a href=\"#\" onClick=\"javascript:MoveTo('ist.php',";
echo "'$nav&wd_minum=$oldminum&wd_datum=$oldfdate&wd_task=$oldtask&wd_hours=$hours&func=FormIST')\">";
echo "<img src=\"image/edit.png\" border=0 alt=\"Edit\"></a>\n";
 
echo "<a href=\"#\" onClick=\"javascript:MoveTo('ist.php',";
echo "'$nav&wd_minum=$oldminum&wd_datum=$oldfdate&wd_task=$oldtask&func=AskISTdel')\">";
echo "<img src=\"image/editdelete.png\" border=0 alt=\"Delete\"></a>\n";
} else {
echo "&nbsp;";
}
 
echo "</td>\n";
 
if ($all)
echo "<td class=\"sel\">$oldnname $oldvname</td>\n";
 
echo "<td class=\"sel\">$oldtaname</td>\n";
$per = date("n.Y", $oldfdate);
echo "<td class=\"selnum\">$per</td>\n";
echo "<td class=\"selnum\">" . FormatNum($hours, 3) . "</td></tr>\n";
$sum += $hours;
$psum += $hours;
 
if ($all && $oldminum != $wd_minum) {
echo "<tr><td class=\"selnum\" colspan=4>Summe f&uuml;r <b>$oldnname $oldvname:</b></td>\n";
echo "<td class=\"lsum\" align=\"right\"><b>" . FormatNum($psum, 3) . "</b></td></tr>\n";
$psum = 0.0;
}
 
$oldfdate = $fdate;
$oldldate = $ldate;
$oldminum = $wd_minum;
$oldtask = $wd_task;
$oldtaname = $ta_name;
$oldnname = $mi_nname;
$oldvname = $mi_vname;
}
 
$r++;
}
 
if ($numrows <= 0) {
echo "</table>\n";
return true;
}
 
$query = "select sum(wd_hours)/$leneinheit from wdone ";
$query .= "where wd_prnum = $wd_prnum and wd_minum = $wd_minum ";
$query .= "and wd_datum between $fdate and $ldate ";
$query .= "and wd_task = $wd_task";
$result2 = QueryDB($db, $query);
 
if (!$result2) {
return false;
}
 
$data = pg_fetch_row($result2, 0);
$hours = $data[0];
 
echo "<tr><td class=\"selakt\">";
 
if ($wd_edit) {
echo "<a href=\"#\" onClick=\"javascript:MoveTo('ist.php',";
echo "'$nav&wd_minum=$oldminum&wd_datum=$oldfdate&wd_task=$oldtask&wd_hours=$hours&func=FormIST')\">";
echo "<img src=\"image/edit.png\" border=0 alt=\"Edit\"></a>\n";
 
echo "<a href=\"#\" onClick=\"javascript:MoveTo('ist.php',";
echo "'$nav&wd_minum=$oldminum&wd_datum=$oldfdate&wd_task=$oldtask&func=AskISTdel')\">";
echo "<img src=\"image/editdelete.png\" border=0 alt=\"Delete\"></a>\n";
} else {
echo "&nbsp;";
}
 
echo "</td>\n";
 
if ($all)
echo "<td class=\"sel\">$mi_nname $mi_vname</td>\n";
 
echo "<td class=\"sel\">$ta_name</td>\n";
$per = date("n.Y", $fdate);
echo "<td class=\"selnum\">$per</td>\n";
echo "<td class=\"selnum\">" . FormatNum($hours, 3) . "</td></tr>\n";
$psum += $hours;
 
if ($all) {
echo "<tr><td class=\"selnum\" colspan=4>Summe f&uuml;r <b>$oldnname $oldvname:</b></td>\n";
echo "<td class=\"lsum\" align=\"right\"><b>" . FormatNum($psum, 3) . "</b></td></tr>\n";
}
 
$sum += $hours;
 
if ($all)
$span = 4;
else
$span = 3;
 
echo "<tr><td class=\"selnum\" colspan=$span>Gesamtsumme:</td>\n";
echo "<td class=\"sum\" align=\"right\"> <b>" . FormatNum($sum, 3) . "</b></td></tr>\n";
echo "</table>\n";
return true;
}
 
# Folgende Funktion listet die bereits erfassten IST-Meldungen des
# angemeldeten Users auf und erlaubt deren Editierung, sofern die
# Meldung noch nicht durch den Projektleiter freigegeben wurde.
#
function ShowIST($wd_prnum, $all=false) {
global $unum;
global $rstufe;
global $phase;
global $einheit;
global $leneinheit;
global $dtformatshort;
global $pmlight;
 
$menu = $_REQUEST['menu'];
 
if ($all == true) {
$superall = $_REQUEST['superall'];
$user = $_REQUEST['user'];
 
if (!isset($superall) || !isset($user)) {
Error("Interner Fehler: Zieluser fehlt!<br>");
return;
}
}
else
$superall = 1;
 
if (!isset($wd_prnum) || $wd_prnum <= 0) {
Error("Interner Fehler: Projektnummer fehlt!<br>");
return;
}
 
$db = OpenDB();
# Welches Projekt wurde gewaehlt?
$query = "select pr_name, pr_pl, mi_nname, mi_vname from ";
$query .= "project, mitarbeiter where pr_num = $wd_prnum and ";
$query .= "mi_num = pr_pl";
$result = QueryDB($db, $query);
 
if (!$result) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$pr_name = $data[0];
$pr_pl = $data[1];
$pl_nname = $data[2];
$pl_vname = $data[3];
 
# Wie heisst der angemeldete User?
$query = "select mi_nname, mi_vname from mitarbeiter where ";
$query .= "mi_num = $unum";
$result = QueryDB($db, $query);
 
if (!$result) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$mi_nname = $data[0];
$mi_vname = $data[1];
 
if ($all == false || $rstufe >= 3) {
$user = $unum;
$all = false;
}
 
# Alle IST-Zeiten anzeigen ($superall) und fuer einen anderen User ($user)
if ($all == true && $superall == 1) {
$query = "select mi_nname, mi_vname from mitarbeiter where ";
$query .= "mi_num = $user";
$result = QueryDB($db, $query);
 
if (!$result) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$mi_nname = $data[0];
$mi_vname = $data[1];
echo "<p class=\"cry\">F&uuml;r Mitarbeiter: $mi_vname $mi_nname</p>\n";
}
 
if (!$pmlight && ($all == false || $superall == 1)) {
$query = "select wd_num, wd_datum, wd_hours, wd_phase,";
$query .= "wd_edit, wd_task, wd_rk, ta_plnum, ta_name, ";
$query .= "wd_minum from wdone, task where ";
$query .= "wdone.wd_prnum = $wd_prnum and ";
$query .= "wdone.wd_minum = $user and task.ta_num = wdone.wd_task ";
$query .= "order by ";
 
if ($phase)
$query .= "wdone.wd_phase,";
 
$query .= "wdone.wd_datum";
} else if (!$pmlight && $all == true && $superall == 0) {
$query = "select wd_num, wd_datum, wd_hours, wd_phase,";
$query .= "wd_edit, wd_task, wd_rk, ta_plnum, ta_name, ";
$query .= "wd_minum, mi_vname, mi_nname ";
$query .= "from wdone, task, mitarbeiter where ";
$query .= "wd_prnum = $wd_prnum and mi_num = wd_minum and ";
$query .= "ta_num = wd_task ";
 
if ($phase)
$query .= "order by wd_phase, wd_datum, mi_nname, mi_vname";
else
$query .= "order by wd_datum, mi_nname, mi_vname";
}
 
if (!$pmlight) {
$result = QueryDB($db, $query);
 
if (!result) {
pg_close($db);
return;
}
 
$numrows = pg_num_rows($result);
$row = 0;
}
 
if ($all == true) {
$nav = "user=$user&superall=$superall&menu=$menu&headline=10&";
$nav .= "wd_prnum=$wd_prnum";
} else {
$nav = "menu=$menu&headline=10&wd_prnum=$wd_prnum";
}
 
$sumh = 0;
$gsumh = 0;
$otask = 0;
$oper = 0;
 
if ($rstufe == 1 || $pr_pl == $unum) {
?>
<form name="istlist" action="ist.php" method="post">
<input type="hidden" name="menu" value="<? echo "$menu"; ?>">
<input type="hidden" name="headline" value="10">
<input type="hidden" name="wd_prnum" value="<? echo "$wd_prnum"; ?>">
<input type="hidden" name="func" value="setsuper">
<table class="input">
<tr><td>
<table border=0>
<tr><td class="input"><input type="radio" name="superall" value="0" <? if (!$superall) echo "checked"; ?>>Alle IST</td>
<td class="input"><input type="radio" name="superall" value="1" <? if ($superall) echo "checked"; ?>>Bestimmte IST:</td>
<td class="input"><select name="user">
<?php
$query = "select distinct mi_num, mi_vname, mi_nname from mitarbeiter,";
$query .= "allocation, task, plan where pl_prnum = $wd_prnum and ";
$query .= "ta_num = al_task and mi_num = al_ressource and ";
$query .= "pl_num = ta_plnum order by mi_nname, mi_vname";
$result2 = QueryDB($db, $query);
$nr = pg_num_rows($result2);
$r = 0;
 
while ($r < $nr) {
$data = pg_fetch_row($result2, $r);
$mi_num = $data[0];
$mi_vname = $data[1];
$mi_nname = $data[2];
 
if ($mi_num == $user)
echo "<option value=\"$mi_num\" selected>$mi_nname $mi_vname</option>\n";
else
echo "<option value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
 
$r++;
}
?>
</select></td>
<td class="input"><? Button("Go", "istlist"); ?></td>
</tr>
</table>
</td></tr></table>
</form>
<br>
<?php
}
 
$hd = GetStrEinheit($einheit, false);
 
# Ist die Periodensicht gewaehlt, brauchen wir eine vollkommen
# andere Darstellung. Diese rufen wir an dieser Stelle auf.
#
if ($pmlight) {
ShowPeriod($wd_prnum, $user, $nav, !$superall);
pg_close($db);
return;
}
 
$cp = ($all && !$superall) ? 10 : 9;
?>
<table class="sel">
<tr>
<?
echo "<td colspan=$cp class=\"selnf\">";
ButtonLink("Hinzuf&uuml;gen", "ist.php", "func=FormIST&$nav");
?>
</td>
<tr>
<td colspan=<? echo "$cp"; ?> class="selinfo">
<table border=0>
<tr>
<td>Projekt:</td>
<td><? echo "$wd_prnum $pr_name"; ?></td>
</tr>
<tr>
<td>Projektleiter:</td>
<td><? echo "$pl_nname $pl_vname"; ?></td>
</tr>
</table>
</td>
</tr>
<tr>
<th class="sel">Aktion</td>
<?php
if ($all == true && $superall == 0) {
echo "<th class=\"sel\">Mitarbeiter</th>\n";
}
?>
<th class="sel">Taskname</th>
<th class="sel">Datum</th>
<? if ($phase) { ?>
<th class="sel">Phase</th>
<? } ?>
<th class="sel">Stunden</th>
<th class="sel"><? echo "$hd"; ?></th>
<? if (!$pmlight) { ?>
<th class="sel">Rk.</th>
<? } ?>
<th class="sel">Plan</th>
<th class="sel">Rest</th>
</tr>
<?php
$ohour = 0;
$srest = 0;
 
while ($row < $numrows) {
$data = pg_fetch_row($result, $row);
$wd_num = $data[0];
$wd_datum = $data[1];
$wd_hours = $data[2];
$wd_phase = $data[3];
$wd_edit = $data[4];
$wd_task = $data[5];
$wd_rk = $data[6];
$ta_plnum = $data[7];
$ta_name = $data[8];
$wd_minum = $data[9];
 
if ($all == true && $superall == 0) {
$mi_vname = $data[10];
$mi_nname = $data[11];
}
 
GetDateRange($wd_datum, &$fdate, &$ldate);
$aktper = GetPeriode($wd_datum);
 
$query = "select al_hours, al_phase, al_pstart from allocation ";
$query .= "where al_task = $wd_task and al_ressource = $wd_minum ";
$query .= "and al_pstart between $fdate and $ldate";
$res = QueryDB($db, $query);
 
if (!$res) {
pg_close($db);
return;
}
 
$nr = pg_num_rows($res);
$r = 0;
$su = 0;
 
while ($r < $nr) {
$data = pg_fetch_row($res, 0);
$al_hours = $data[0];
$al_phase = $data[1];
$al_pstart = $data[2];
$su += $al_hours;
$r++;
}
 
$al_hours = $su;
unset($su);
unset($r);
unset($nr);
unset($res);
 
if ($row > 0 && ($otask != $wd_task || $oper != $aktper)) {
if ($oper != $aktper && $otask == $wd_task)
$class = "lsum";
else
$class = "sum";
 
if ($phase) {
if ($all && !$superall)
echo "<tr><td class=\"$class\" colspan=5 align=\"right\">Zwischensummen:</td>\n";
else
echo "<tr><td class=\"$class\" colspan=4 align=\"right\">Zwischensummen:</td>\n";
} else {
if ($all && !$superall)
echo "<tr><td class=\"$class\" colspan=4 align=\"right\">Zwischensummen:</td>\n";
else
echo "<tr><td class=\"$class\" colspan=3 align=\"right\">Zwischensummen:</td>\n";
}
 
echo "<td class=\"$class\" align=\"right\"><b>$sumh</b></td>\n";
printf ("<td class=\"$class\" align=\"right\"><b>%s</b></td>", FormatNum($sumh / $leneinheit, 3));
 
if ($superall) {
if ($pmlight)
printf ("<td class=\"$class\" align=\"right\">%s</td>", FormatNum($ohour, 3));
else
printf ("<td class=\"$class\" align=\"right\">&nbsp;</td><td class=\"$class\">%s</td>", FormatNum($ohour, 3));
 
printf ("<td class=\"$class\" align=\"right\">%s</td></tr>\n", FormatNum($rest / $leneinheit, 3));
} else {
if ($pmlight)
echo "<td colspan=2 class=\"$class\">&nbsp;</td></tr>\n";
else
echo "<td colspan=3 class=\"$class\">&nbsp;</td></tr>\n";
}
 
$srest += $rest;
$sumh = 0;
$sump = 0;
$otask = $wd_task;
$ohour = $al_hours;
$oper = $aktper;
} else if ($row == 0) {
$otask = $wd_task;
$ohour = $al_hours;
$oper = $aktper;
}
 
echo "<tr><td class=\"selakt\">\n";
 
if ($wd_edit) {
echo "<a href=\"#\" onClick=\"javascript:MoveTo('ist.php',";
echo "'$nav&wd_num=$wd_num&func=FormShowIST')\">";
echo "<img src=\"image/edit.png\" border=0 alt=\"Edit\"></a>\n";
echo "<a href=\"#\" onClick=\"javascript:MoveTo('ist.php',";
echo "'$nav&wd_num=$wd_num&func=AskISTdel')\">";
echo "<img src=\"image/editdelete.png\" border=0 alt=\"Delete\"></a>\n";
echo "</td>\n";
} else {
echo "<td class=\"sel\"> /td>\n";
}
 
if ($all && !$superall)
echo "<td class=\"sel\">$mi_nname $mi_vname</td>\n";
 
echo "<td class=\"sel\">$ta_name</td>\n";
$datum = date($dtformatshort, $wd_datum);
echo "<td class=\"sel\">$datum</td>\n";
 
if ($phase)
echo "<td class=\"selnum\" align=\"right\">$wd_phase</td>\n";
 
echo "<td class=\"selnum\" align=\"right\">$wd_hours</td>\n";
printf ("<td class=\"selnum\" align=\"right\">%s</td>\n", FormatNum($wd_hours / $leneinheit, 3));
 
if (!$pmlight) {
if ($wd_rk)
echo "<td class=\"sel\"><b>Ja</b></td>\n";
else
echo "<td class=\"sel\">Nein</td>\n";
}
 
echo "<td class=\"sel\"> </td>";
 
if ($superall) {
$rest = ($al_hours * $leneinheit) - $wd_hours - $sumh;
 
if ($rest < 0)
printf ("<td class=\"five\" align=\"right\">%s</td>", FormatNum($rest / $leneinheit, 3));
else
printf ("<td class=\"selnum\" align=\"right\">%s</td>", FormatNum($rest / $leneinheit, 3));
} else {
echo "<td class=\"sel\"> </td>";
}
 
echo "</tr>\n";
$sumh += $wd_hours;
$gsumh += $wd_hours;
$row++;
}
 
if ($phase) {
$span1 = 5;
$span2 = 4;
} else {
$span1 = 4;
$span2 = 3;
}
 
if ($all && !$superall)
echo "<tr><td class=\"sum\" colspan=$span1 align=\"right\">Zwischensummen:</td>\n";
else
echo "<tr><td class=\"sum\" colspan=$span2 align=\"right\">Zwischensummen:</td>\n";
 
echo "<td class=\"sum\" align=\"right\"><b>$sumh</b></td>\n";
printf ("<td class=\"sum\" align=\"right\"><b>%s</b></td>", FormatNum($sumh / $leneinheit, 3));
 
if ($superall) {
if ($pmlight)
printf ("<td class=\"sum\" align=\"right\">%s</td>", FormatNum($al_hours, 3));
else
printf ("<td class=\"sum\"> </td><td class=\"sum\" align=\"right\">%s</td>", FormatNum($al_hours, 3));
 
printf ("<td class=\"sum\" align=\"right\">%s</td></tr>\n", FormatNum($rest / $leneinheit, 3));
} else {
if ($pmlight)
echo "<td colspan=2 class=\"sum\"> </td></tr>\n";
else
echo "<td colspan=3 class=\"sum\"> </td></tr>\n";
}
 
if ($all && !$superall)
echo "<tr><td class=\"sum\" colspan=$span1 align=\"right\">Summen:</td>\n";
else
echo "<tr><td class=\"sum\" colspan=$span2 align=\"right\">Summen:</td>\n";
 
echo "<td class=\"sum\" align=\"right\"><b>$gsumh</b></td>\n";
 
if ($pmlight)
printf ("<td class=\"sum\" align=\"right\"><b>%s</b></td><td class=\"sum\"> </td>\n", FormatNum($gsumh / $leneinheit, 3));
else
printf ("<td class=\"sum\" align=\"right\"><b>%s</b></td><td colspan=2 class=\"sum\"> </td>\n", FormatNum($gsumh / $leneinheit, 3));
 
$srest += $rest;
 
if ($srest < 0)
printf ("<td class=\"five\" align=\"right\"><b>%s</b></td></tr>", FormatNum($srest / $leneinheit, 3));
else
printf ("<td class=\"sum\" align=\"right\"><b>%s</b></td></tr>", FormatNum($srest / $leneinheit, 3));
 
echo "<tr><td colspan=$cp class=\"selnf\">";
ButtonLink("Hinzuf&uuml;gen", "ist.php", "func=FormIST&$nav");
echo "</td></tr>\n";
echo "</table>\n";
pg_close($db);
}
 
 
function FormIST($wd_prnum, $wd_num=0) {
$menu = $_REQUEST['menu'];
global $unum;
global $rstufe;
global $phase;
global $dtformatshort;
global $pmlight;
global $leneinheit;
$user = $_REQUEST['user'];
$superall = $_REQUEST['superall'];
 
if ($pmlight) {
$wd_minum = $_REQUEST['wd_minum'];
$wd_datum = $_REQUEST['wd_datum'];
 
if (!isset($wd_datum) || $wd_datum <= 0)
$wd_datum = time();
 
$datum = date("n.Y", $wd_datum);
}
 
if (!isset($user) || $user <= 0)
$user = $unum;
 
$pmlg = $pmlight;
$db = OpenDB();
 
if (isset($wd_num) && $wd_num > 0) {
$pmlg = false;
$query = "select wd_prnum, wd_minum, wd_datum, wd_hours,";
$query .= "wd_phase, wd_task, wd_rk, wd_text, wd_verr from wdone ";
$query .= "where wd_num = $wd_num";
$result = QueryDB($db, $query);
 
if (!$result) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$wd_prnum = $data[0];
$wd_minum = $data[1];
$wd_datum = $data[2];
$wd_hours = $data[3];
$wd_phase = $data[4];
$wd_task = $data[5];
$wd_rk = $data[6];
$wd_text = $data[7];
$wd_verr = $data[8];
$user = $wd_minum;
$datum = date($dtformatshort, $wd_datum);
}
 
$query = "select pr_name, mi_nname, mi_vname from project, mitarbeiter ";
$query .= "where mi_num = pr_pl and pr_num = $wd_prnum";
 
if (!($result = QueryDB($db, $query))) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$pr_name = $data[0];
$mi_nname = $data[1];
$mi_vname = $data[2];
 
echo "<p class=\"cry\">Projekt: $wd_prnum $pr_name<br>\nProjektleiter: $mi_vname $mi_nname</p>\n";
$query = "select mi_vname, mi_nname from mitarbeiter where mi_num = $user";
 
if (!($result = QueryDB($db, $query))) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$mi_vname = $data[0];
$mi_nname = $data[1];
 
echo "<form name=\"tatsache\" action=\"ist.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"headline\" value=\"10\">\n";
echo "<input type=\"hidden\" name=\"menu\" value=\"$menu\">\n";
echo "<input type=\"hidden\" name=\"func\" value=\"SaveIST\">\n";
echo "<input type=\"hidden\" name=\"wd_prnum\" value=\"$wd_prnum\">\n";
echo "<input type=\"hidden\" name=\"user\" value=\"$user\">\n";
echo "<input type=\"hidden\" name=\"superall\" value=\"$superall\">\n";
echo "<input type=\"hidden\" name=\"pmlg\" value=\"$pmlg\">\n";
 
if (isset($wd_num) && $wd_num > 0) {
echo "<input type=\"hidden\" name=\"wd_num\" value=\"$wd_num\">\n";
} else {
if (!isset($datum))
$datum = $_REQUEST['datum'];
 
$wd_hours = $_REQUEST['wd_hours'];
$wd_phase = $_REQUEST['wd_phase'];
$wd_task = $_REQUEST['wd_task'];
$wd_rk = $_REQUEST['wd_rk'];
$wd_verr = $_REQUEST['wd_verr'];
 
if (isset($wd_hours) && $wd_hours > 0)
echo "<input type=\"hidden\" name=\"edit\" value=\"1\">\n";
else
echo "<input type=\"hidden\" name=\"edit\" value=\"0\">\n";
}
 
$VD = GetVisualDate ($dtformatshort, $pmlg);
 
if ($pmlg)
$mx = 7;
else
$mx = 10;
?>
<table class="input">
<tr>
<td>IST-Erfassung f&uuml;r:</td>
<td><u><? echo "$mi_vname $mi_nname"; ?></u></td>
</tr>
<tr>
<td>Datum (<? echo "$VD"; ?>):</td>
<td><input type="text" name="datum" class="inputmust" value="<? echo "$datum"; ?>" size=<? echo "$mx"; ?> maxlength=<? echo "$mx"; ?>>
<? if (!$pmlg) {?>
<input type="button" value="..." onClick="javascript:open_window('calendar.php?header=1&target=window.opener.document.tatsache.datum', 'Calendar', 200, 250)">
<? }?>
</td>
</tr>
<tr>
<?
if ($pmlg)
echo " <td>Geleistete Tage:</td>\n";
else
echo " <td>Geleistete Stunden:</td>\n";
?>
<td><input type="text" class="inputmust" name="wd_hours" value="<? echo "$wd_hours"; ?>" size=6 maxlength=6></td>
</tr>
<?php
if ($phase == 1) {
echo "<tr><td>Projektphase:</td>\n";
$query = "select kp_num, kp_phase from key_phase order by kp_num";
$result = QueryDB($db, $query);
 
if (!result) {
pg_close($db);
return;
}
 
$numrows = pg_num_rows($result);
$row = 0;
echo "<td><select name=\"wd_phase\">\n";
 
while ($row < $numrows) {
$data = pg_fetch_row($result, $row);
$kp_num = $data[0];
$kp_phase = $data[1];
 
if ($wd_phase == $kp_num)
echo "<option value=\"$kp_num\" selected>$kp_num $kp_phase</option>\n";
else
echo "<option value=\"$kp_num\">$kp_num $kp_phase</option>\n";
 
$row++;
}
 
echo "</select></td></tr>\n";
} else {
$wd_phase = 0;
}
?>
<tr>
<td>Taskzuordnung:</td>
<td><select name="wd_task">
<?php
$query = "select pl_num from plan where pl_prnum = $wd_prnum and ";
$query .= "pl_status in (2,3,4) order by pl_lfd desc";
$result = QueryDB($db, $query);
 
if (!$result) {
pg_close($db);
return;
}
 
$data = pg_fetch_row($result, 0);
$pl_num = $data[0];
 
SelectTask($pl_num, false, $wd_task);
?>
</select>
</td>
</tr>
<tr>
<td>IST-Zeit Verrechenbar?</td>
<td><input type="checkbox" name="wd_verr" <? if (!isset($wd_verr) || $wd_verr == true) echo "checked"; ?>></td>
</tr>
<?
if (!$pmlight) {?>
<tr>
<td>Reisekosten angefallen?</td>
<td><input type="checkbox" name="wd_rk" <? if ($wd_rk == 1) echo "checked"; ?>></td>
</tr>
<tr>
<td valign="top">Arbeitsbeschreibung:</td>
<td><textarea name="wd_text" rows=5 cols=60><? echo "$wd_text"; ?></textarea></td>
</tr>
<?
} else {
$wd_rk = 0;
$wd_text = "";
}?>
</table>
<table class="indent"><tr><td>
<?
ButtonSubmit("Daten senden", "tatsache");
//<input type="submit" name="submit" value="Daten senden"> <input type="reset">
?>
</td></tr></table>
</form>
<?php
}
 
function AskOldIST () {
global $phase;
 
$headline = $_REQUEST['headline'];
$menu = $_REQUEST['menu'];
$wd_num = $_REQUEST['wd_num'];
$wd_prnum = $_REQUEST['wd_prnum'];
$datum = $_REQUEST['datum'];
$wd_hours = $_REQUEST['wd_hours'];
$wd_task = $_REQUEST['wd_task'];
$wd_rk = $_REQUEST['wd_rk'];
$wd_text = $_REQUEST['wd_text'];
$wd_verr = $_REQUEST['wd_verr'];
$user = $_REQUEST['user'];
$superall = $_REQUEST['superall'];
$pmlg = $_REQUEST['pmlg'];
$edit = $_REQUEST['edit'];
 
if ($phase)
$wd_phase = $_REQUEST['wd_phase'];
else
$wd_phase = 0;
 
if (!isset($wd_rk))
$wd_rk = 0;
else
$wd_rk = 1;
 
$nav = "wd_num=$wd_num&wd_prnum=$wd_prnum&menu=$menu&";
$nav .= "datum=$datum&wd_hours=$wd_hours&wd_phase=$wd_phase&";
$nav .= "wd_task=$wd_task&wd_rk=$wd_rk&wd_text=$wd_text&wd_verr=$wd_verr&";
$nav .= "headline=$headline&user=$user&superall=$superall&";
$nav .= "pmlg=$pmlg&func=SaveISTreal&edit=$edit";
?>
<br>
<form name="Alarm" method="post">
<table border=2 class="alarm">
<tr><td colspan=2><big>Warnung!</big><br><br>
Sie versuchen einen Aufwand f&uuml;r einen Zeitraum zu erfassen,
der schon &auml;lter als 40 Tage ist!<br><br>
<center>Datum: <? echo "$datum"; ?></center><br><br>
Wollen Sie wirklich diesen Aufwand
f&uuml;r dieses Datum erfassen?<br>
</td>
</tr>
<tr>
<td><center><input type="button" name="yes" value="Erfassen" onClick="javascript:MoveTo('ist.php','yes=yes&<? echo "$nav"; ?>')"></center></td>
<td><center><input type="button" name="no" value="Abbruch" onClick="javascript:MoveTo('ist.php','no=no&<? echo "$nav"; ?>')"></center></td>
</tr>
</table>
</form>
<?php
}
 
# Folgende Funktion speichert einen IST-Aufwand. Es werden allerdings
# zuvor einige Plausibilitaetspruefungen durchgefuehrt um sicher zu
# stellen, das nicht auf einen Task gebucht wird, dessen Zeit bereits
# aufgebraucht ist.
#
function SaveIST() {
global $rstufe;
global $unum;
global $phase;
global $leneinheit;
global $pmlight;
 
if ($rstufe < 1 || $rstufe > 3) {
Error("Berechtigungsfehler!<br>\n");
return false;
}
 
$wd_prnum = $_REQUEST['wd_prnum'];
$wd_num = $_REQUEST['wd_num'];
$datum = $_REQUEST['datum'];
$wd_hours = $_REQUEST['wd_hours'];
$wd_hours = str_replace(",", ".", $wd_hours);
 
if ($phase)
$wd_phase = $_REQUEST['wd_phase'];
else
$wd_phase = 0;
 
$wd_task = $_REQUEST['wd_task'];
$wd_rk = $_REQUEST['wd_rk'];
$wd_text = $_REQUEST['wd_text'];
$wd_verr = $_REQUEST['wd_verr'];
$user = $_REQUEST['user'];
$superall = $_REQUEST['superall'];
$pmlg = $_REQUEST['pmlg'];
$edit = $_REQUEST['edit'];
 
if (!isset($pmlg))
$pmlg = $pmlight;
 
if (!isset($edit))
$edit = 0;
 
$err = 0;
$db = OpenDB();
 
if (!isset($wd_prnum) || $wd_prnum <= 0) {
Error("Error: Interner Fehler: Projektnummer fehlt!<br>");
$err = 1;
}
 
if ($pmlg && (!isset($wd_hours) || $wd_hours < 0.1 || $wd_hours > 31)) {
Error("Error: Die Anzahl Tage muss im Bereich 0.1 bis 31 Tage sein!");
$err = 1;
} else if (!$pmlg && (!isset($wd_hours) || $wd_hours < 1 || $wd_hours > 24)) {
Error("Error: Die Anzahl Stunden m&uuml;ssen im Bereich 1 bis 24 sein!");
$err = 1;
}
 
if (!isset($datum)) {
Error("Error: Sie m&uuml;ssen ein Datum angeben!");
$err = 1;
} else if ($pmlg) {
if (strlen($datum) < 5 || strlen($datum) > 7) {
Error("Error: Ung&uuml;ltige Periode!");
$err = 1;
} else {
$dt = explode(".", $datum);
$mon = $dt[0];
$year = $dt[1];
 
if ($year < 50)
$year += 2000;
else if ($year >= 50 && $year < 100)
$year += 1900;
 
$datum = "1.$mon.$year";
}
} else if (strlen($datum) < 8 || strlen($datum) > 10) {
Error("Error: Ung&uuml;ltiges Datum!");
$err = 1;
} else if (strlen($datum == 8)) {
$dt = explode(".", $datum);
$day = $dt[0];
$mon = $dt[1];
$year = $dt[2];
 
if ($year < 50)
$year += 2000;
else if ($year >= 50 && $year < 100)
$year += 1900;
 
$datum = "$day.$mon.$year";
}
 
if (!isset($wd_task) || $wd_task <= 0) {
Error("Error: Sie haben keinen Task ausgew&auml;hlt!<br>");
$err = 1;
}
 
if (!isset($user) || $user <= 0)
$user = $unum;
 
if ($err) {
return false;
}
 
if (isset($wd_rk) && ($wd_rk == 1 || $wd_rk == "on" || $wd_rk == "true" || $wd_rk == "t"))
$wd_rk = 1;
else
$wd_rk = 0;
 
if (isset($wd_verr) && ($wd_verr == 1 || $wd_verr == "on" || $wd_verr == "true" || $wd_verr == "t"))
$wd_verr = "true";
else
$wd_verr = "false";
 
if (!isset($wd_text))
$wd_text = "";
 
$dt = explode(".", $datum);
 
if ($pmlg) {
$fdate = mktime(0, 0, 0, $dt[1], 1, $dt[2]);
$days = daysinmonth($dt[1], $dt[2]);
$ldate = mktime(23, 59, 59, $dt[1], $days, $dt[2]);
$wd_datum = $fdate;
} else {
$wd_datum = mktime(0, 0, 0, $dt[1], $dt[0], $dt[2]);
}
 
if (isset($wd_num) && $wd_num > 0) {
$t = time() - (86400 * 40);
$func = $_REQUEST['func'];
 
if (!$edit && (!isset($func) || $func != "SaveISTreal") && $wd_datum < $t) {
pg_close($db);
AskOldIST();
require('footer.inc');
exit;
}
 
QueryDB($db, "begin");
$query = "update wdone set wd_datum = $wd_datum,";
 
if ($phase)
$query .= "wd_hours = $wd_hours, wd_phase = $wd_phase,";
else
$query .= "wd_hours = $wd_hours, ";
 
$query .= "wd_task = $wd_task, wd_rk = $wd_rk,";
$query .= "wd_text = '$wd_text', wd_verr = $wd_verr ";
$query .= "where wd_num = $wd_num";
$result = QueryDB($db, $query);
 
if (!result) {
QueryDB($db, "rollback");
pg_close($db);
return false;
}
 
QueryDB($db, "commit");
return true;
}
 
$t = time() - (86400 * 40);
$func = $_REQUEST['func'];
 
if (!$edit && (!isset($func) || $func != "SaveISTreal") && $wd_datum < $t) {
pg_close($db);
AskOldIST();
require('footer.inc');
exit;
}
 
# Es soll mindestens ein neuer Datensatz eingefuegt werden.
# Wenn wir die light Version verwenden, wurden nicht Stunden
# fuer einen bestimmten Tag eingegeben, sondern Tage fuer eine
# bestimmte Periode. Diese Tage muessen nun auf die Periode
# aufgeteilt werden, wobei bereits vorhandene Tage in der Periode
# beruecksichtigt werden muessen und nicht doppelt belegt werden
# sollten. Jedenfalls so lange nicht, wie Tage in der Periode
# frei zur Verfuegung stehen.
#
# Finden des naechsten freien Tags in der Periode bei light Version.
if ($pmlg) {
if ($edit) {
QueryDB($db, "begin");
$query = "delete from wdone where wd_task = $wd_task and ";
$query .= "wd_prnum = $wd_prnum and wd_minum = $user and ";
$query .= "wd_datum between $fdate and $ldate";
 
if (!QueryDB($db, $query)) {
QueryDB($db, "rollback");
pg_close($db);
return false;
}
 
QueryDB($db, "commit");
}
 
$query = "select wd_datum from wdone where ";
$query .= "wd_task = $wd_task and wd_prnum = $wd_prnum and ";
$query .= "wd_minum = $user and wd_datum >= $fdate and ";
$query .= "wd_datum <= $ldate ";
$query .= "order by wd_datum desc";
 
$result = QueryDB($db, $query);
 
if (!$result) {
pg_close($db);
return false;
}
 
$numrows = pg_num_rows($result);
 
if ($numrows > 0) {
$data = pg_fetch_row($result, 0);
$dt = $data[0];
$day = date("j", $dt) + 1;
}
else
$day = 1;
 
$query = "select co_wdone from counter";
$result = QueryDB($db, $query);
$data = pg_fetch_row($result, 0);
$co_wdone = $data[0];
 
$j = 0;
$wd_hours *= $leneinheit;
QueryDB($db, "begin");
 
while ($j < $wd_hours) {
if ($day > $days)
$day = 1;
 
$dt = mktime(0, 0, 0, date("n", $wd_datum), $day, date("Y", $wd_datum));
$co_wdone++;
 
if (($wd_hours - $j) < $leneinheit)
$h = $wd_hours - $j;
else
$h = $leneinheit;
 
$query = "insert into wdone (wd_num, wd_prnum, wd_minum, wd_datum,";
$query .= "wd_hours, wd_phase, wd_task, wd_rk, wd_edit, wd_text, wd_verr) ";
$query .= "values ($co_wdone, $wd_prnum, $user, $dt,";
$query .= "$h, $wd_phase, $wd_task, $wd_rk, true, '$wd_text', $wd_verr)";
$result = QueryDB($db, $query);
 
if (!$result) {
QueryDB($db, "rollback");
pg_close($db);
return false;
}
 
$day++;
$j += $leneinheit;
}
 
$query = "update counter set co_wdone = $co_wdone";
$result = QueryDB($db, $query);
 
if (!$result) {
QueryDB($db, "rollback");
pg_close($db);
return false;
}
 
QueryDB($db, "commit");
pg_close($db);
return true;
}
 
$query = "select co_wdone from counter";
$result = QueryDB($db, $query);
$data = pg_fetch_row($result, 0);
$co_wdone = $data[0] + 1;
 
QueryDB($db, "begin");
$query = "insert into wdone (wd_num, wd_prnum, wd_minum, wd_datum,";
$query .= "wd_hours, wd_phase, wd_task, wd_rk, wd_edit, wd_text, wd_verr) ";
$query .= "values ($co_wdone, $wd_prnum, $user, $wd_datum,";
$query .= "$wd_hours, $wd_phase, $wd_task, $wd_rk, true, '$wd_text', $wd_verr)";
$result = QueryDB($db, $query);
 
if (!$result) {
QueryDB($db, "rollback");
pg_close($db);
return false;
}
 
$query = "update counter set co_wdone = $co_wdone";
$result = QueryDB($db, $query);
 
if (!$result) {
QueryDB($db, "rollback");
pg_close($db);
return false;
}
 
QueryDB($db, "commit");
pg_close($db);
return true;
}
 
function AskISTdel () {
global $pmlight;
 
$headline = $_REQUEST['headline'];
$menu = $_REQUEST['menu'];
$wd_num = $_REQUEST['wd_num'];
$wd_prnum = $_REQUEST['wd_prnum'];
 
if ($pmlight) {
$wd_minum = $_REQUEST['wd_minum'];
$wd_datum = $_REQUEST['wd_datum'];
$wd_task = $_REQUEST['wd_task'];
$wd_prnum = $_REQUEST['wd_prnum'];
}
 
$user = $_REQUEST['user'];
$superall = $_REQUEST['superall'];
 
$nav = "wd_num=$wd_num&wd_prnum=$wd_prnum&user=$user&menu=$menu&";
$nav .= "superall=$superall&headline=$headline&func=DeleteIST&";
$nav .= "user=$user";
 
if ($pmlight)
$nav .= "&wd_minum=$wd_minum&wd_datum=$wd_datum&wd_task=$wd_task&wd_prnum=$wd_prnum";
?>
<br>
<form name="Alarm" method="post">
<table border=2 class="alarm">
<tr><td colspan=2><big>Warnung!</big><br><br>
Sie sind im Begriff einen erfassten Aufwand zu
l&ouml;schen!<br><br>
Wollen Sie wirklich diesen Aufwand
unwiederbringlich l&ouml;schen?<br>
</td>
</tr>
<tr>
<td><center><input type="button" name="yes" value="L&ouml;schen" onClick="javascript:MoveTo('ist.php','yes=yes&<? echo "$nav"; ?>')"></center></td>
<td><center><input type="button" name="no" value="Abbruch" onClick="javascript:MoveTo('ist.php','no=no&<? echo "$nav"; ?>')"></center></td>
</tr>
</table>
</form>
<?php
}
 
function DeleteIST() {
global $pmlight;
 
$wd_num = $_REQUEST['wd_num'];
 
if (!$pmlight && (!isset($wd_num) || $wd_num <= 0)) {
Error("Interner Fehler: Zu l&ouml;schende Datensatznummer fehlt!<br>");
return false;
}
 
if ($pmlight) {
$wd_minum = $_REQUEST['wd_minum'];
$wd_datum = $_REQUEST['wd_datum'];
$wd_task = $_REQUEST['wd_task'];
$wd_prnum = $_REQUEST['wd_prnum'];
 
if (!isset($wd_prnum) || $wd_prnum <= 0) {
Error("Interner Fehler: Projektnummer fehlt!");
return false;
}
 
if (!isset($wd_minum) || $wd_minum <= 0) {
Error("Interner Fehler: Mitarbeiternummer fehlt!");
return false;
}
 
if (!isset($wd_datum) || $wd_datum <= 0) {
Error("Interner Fehler: Periode fehlt!");
return false;
}
 
$mon = date("n", $wd_datum);
$year = date("Y", $wd_datum);
$fdate = mktime(0, 0, 0, $mon, 1, $year);
$days = daysinmonth($mon, $year);
$ldate = mktime(23, 59, 59, $mon, $days, $year);
}
 
$db = OpenDB();
 
if (!$pmlight) {
$query = "delete from wdone where wd_num = $wd_num";
} else {
$query = "delete from wdone where wd_minum = $wd_minum and ";
$query .= "wd_datum between $fdate and $ldate and ";
$query .= "wd_task = $wd_task and wd_prnum = $wd_prnum";
}
 
if (!TQueryDB($db, $query)) {
pg_close($db);
return false;
}
 
pg_close($db);
return true;
}
 
if (isset($func)) {
if ($func == "ShowIST") {
$pr_num = $_REQUEST['pr_num'];
$user = $_REQUEST['user'];
 
if (isset($user) && $user > 0)
$all = true;
else
$all = false;
 
ShowIST($pr_num, $all);
}
 
if ($func == "FormShowIST") {
$wd_prnum = $_REQUEST['wd_prnum'];
$wd_num = $_REQUEST['wd_num'];
FormIST($wd_prnum, $wd_num);
}
 
if ($func == "FormIST") {
$pr_num = $_REQUEST['wd_prnum'];
FormIST($pr_num);
}
 
if ($func == "setsuper" && ($rstufe == 1 || $rstufe == 2)) {
$pr_num = $_REQUEST['wd_prnum'];
ShowIST($pr_num, true);
} else if ($func == "setsuper") {
Error("Ihnen fehlt eine Berechtigung!<br>");
$pr_num = $_REQUEST['wd_prnum'];
ShowIST($pr_num, false);
}
 
if ($func == "SaveIST") {
$user = $_REQUEST['user'];
 
if (isset($user) && $user > 0)
$all = true;
else
$all = false;
 
if (!SaveIST()) {
$pr_num = $_REQUEST['wd_prnum'];
FormIST($pr_num);
} else {
$wd_prnum = $_REQUEST['wd_prnum'];
ShowIST($wd_prnum, $all);
}
}
 
if ($func == "AskISTdel") {
AskISTdel();
}
 
if ($func == "DeleteIST") {
if ($_REQUEST['yes'] == "yes")
DeleteIST();
 
$wd_prnum = $_REQUEST['wd_prnum'];
ShowIST($wd_prnum);
}
 
if ($func == "SaveISTreal") {
$user = $_REQUEST['user'];
 
if (isset($user) && $user > 0)
$all = true;
else
$all = false;
 
if ($_REQUEST['yes'] == "yes") {
if (!SaveIST()) {
$pr_num = $_REQUEST['wd_prnum'];
FormIST($pr_num);
} else {
$wd_prnum = $_REQUEST['wd_prnum'];
ShowIST($wd_prnum, $all);
}
} else {
$wd_prnum = $_REQUEST['wd_prnum'];
ShowIST($wd_prnum, $all);
}
}
}
 
require('footer.inc');
?>