Location: PHPKode > projects > TheoPlan > pm/planlockm.inc
<?
function AskLockM() {
	global $menu;
	global $headline;
	global $periode;
	global $dtformatshort;

	$pl_num = $_REQUEST['pl_num'];

	if (!isset($pl_num) || $pl_num <= 0) {
	   Error("AskLockM: Interner Fehler: Plannummer fehlt oder ist ung&uuml;ltig!");
	   return;
	}

	$ps_1 = $_REQUEST['ps_1'];
	$ps_2 = $_REQUEST['ps_2'];
	$ps_3 = $_REQUEST['ps_3'];
	$ps_4 = $_REQUEST['ps_4'];
	$ps_5 = $_REQUEST['ps_5'];
	$ps_6 = $_REQUEST['ps_6'];
	$sx_prnum = $_REQUEST['sx_prnum'];
	$sx_prname = $_REQUEST['sx_prname'];
	$nav = "ps_1=$ps_1&ps_2=$ps_2&ps_3=$ps_3&ps_4=$ps_4&ps_5=$ps_5&ps_6=$ps_6&";
	$nav .= "sx_prnum=$sx_prnum&sx_prname=$sx_prname&menu=$menu&headline=$headline";
	$db = OpenDB();
	$query = "select pl_prnum, pr_name from plan, project where ";
	$query .= "pr_num = pl_prnum and pl_num = $pl_num";

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

	$data =fetchDB($result, 0);
	$pr_num = $data[0];
	$pr_name = $data[1];

	# Ermitteln des Anfangsdatums des gewaehlten Projekts.
	$query = "select ta_start from task where ta_plnum = $pl_num order by ta_start";

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

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

	$query = "select ab_datum from abschluss where ab_prnum = $pr_num order by ab_datum desc";

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

	if (numrowsDB($result) > 0) {
	   $data =fetchDB($result, 0);
	   $ab_datum = $data[0];
	} else
	   $ab_datum = 0;

	$mon = gmdate("n", $ta_start);
	$year = gmdate("Y", $ta_start);
	$dt = gmmktime(0, 0, 0, $mon, 1, $year);

	if ($ab_datum > $dt)
	   $dt = $ab_datum;

	$mon = date("n");
	$year = date("Y");
	$dte = gmmktime(0, 0, 0, $mon, 1, $year);
?>
<form name="lock" action="plan.php" method="post">
   <input type="hidden" name="menu" value="<? echo "$menu"; ?>">
   <input type="hidden" name="headline" value="<? echo "$headline"; ?>">
   <input type="hidden" name="pr_num" value="<? echo "$pr_num"; ?>">
   <input type="hidden" name="pl_num" value="<? echo "$pl_num"; ?>">
   <input type="hidden" name="ab_datum" value="<? echo "$ab_datum"; ?>">
   <input type="hidden" name="ps_1" value="<? echo "$ps_1"; ?>">
   <input type="hidden" name="ps_2" value="<? echo "$ps_2"; ?>">
   <input type="hidden" name="ps_3" value="<? echo "$ps_3"; ?>">
   <input type="hidden" name="ps_4" value="<? echo "$ps_4"; ?>">
   <input type="hidden" name="ps_5" value="<? echo "$ps_5"; ?>">
   <input type="hidden" name="ps_6" value="<? echo "$ps_6"; ?>">
   <input type="hidden" name="sx_prnum" value="<? echo "$sx_prnum"; ?>">
   <input type="hidden" name="sx_prname" value="<? echo "$sx_prname"; ?>">
   <input type="hidden" name="func" value="LockProject">
<table class="input">
   <tr>
      <th class="sel" colspan=2>Projekt abschlie&szlig;en</th>
   </tr>
   <tr>
      <td>Projekt:</td>
      <td><? echo "$pr_num $pr_name"; ?></td>
   </tr>
   <tr>
      <td>Letzter Abschlu&szlig;:</td>
      <td><? if ($ab_datum > 0) echo GetShortDate($ab_datum); else echo "- - - - -"; ?></td>
   </tr>
   <tr>
      <td>Projektabschlu├č bis:</td>
      <td><select name="datum">
<?
	$mon = gmdate("n", $dt);
	$year = gmdate("Y", $dt);
	$akt = gmmktime(0, 0, 0, $mon, 1, $year);
	$emon = gmdate("n", $dte);
	$eyear = gmdate("Y", $dte);

	while ($akt < $dte) {
	   echo "<option value=\"$akt\"";

	   $mon++;

	   if ($mon > 12) {
	      $mon = 1;
	      $year++;
	   }

	   if ($mon == $emon && $year == $eyear)
	      echo " selected";

	   echo ">" . GetShortDate($akt) . "</option>\n";
	   $akt = gmmktime(0, 0, 0, $mon, 1, $year);
	}
?>
          </select>
      </td>
   </tr>
</table>
<table class="indent"><tr><td>
<?
	Button("Projekt abschlie&szlig;en", "lock");
	echo "</td><td>";
	ButtonLink("Abbrechen", "plan.php", "plchange=plchange&$nav");
	echo "</td></tr></table></form>\n";
	closeDB($db);
}

function LockProject() {
	global $menu;
	global $headline;
	global $unum;

	$pr_num = $_REQUEST['pr_num'];
	$datum = $_REQUEST['datum'];
	$pl_num = $_REQUEST['pl_num'];
	$ab_datum = $_REQUEST['ab_datum'];

	if (!isset($pr_num) || $pr_num <= 0) {
	   Error("LockProject: Interner Fehler: Projektnummer wurde nicht &uuml;bergeben!");
	   return;
	}

	if (!isset($datum) || $datum <= 0) {
	   Error("LockProject: Interner Fehler: Datum wurde nicht &uuml;bergeben!");
	   return;
	}

	if (!isset($pl_num) || $pl_num <= 0) {
	   Error("LockProject: Interner Fehler: Plannummer wurde nicht &uuml;bergeben!");
	   return;
	}

	if (!isset($ab_datum))
	   $ab_datum = 0;

	$mon = gmdate("n", $datum);
	$year = gmdate("Y", $datum);
	$dat = gmmktime(0, 0, 0, $mon, daysinmonth($mon, $year), $year);
	$db = OpenDB();

	$query = "select co_abschluss from counter";

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

	$data = fetchDB($result, 0);
	$co_abschluss = $data[0] + 1;

	if (!QueryDB($db, "begin")) {
	   closeDB($db);
	   return;
	}

	$query = "update wdone set wd_edit = false where wd_prnum = $pr_num and ";
	$query .= "wd_datum <= $dat";

	if (!QueryDB($db, $query)) {
	   QueryDB($db, "rollback");
	   closeDB($db);
	   return;
	}

	$query = "insert into abschluss (ab_num, ab_datum, ab_user, ab_prnum,";
	$query .= "ab_plnum) values ($co_abschluss, $dat, $unum, $pr_num, ";
	$query .= "$pl_num)";

	if (!QueryDB($db, $query)) {
	   QueryDB($db, "rollback");
	   closeDB($db);
	   return;
	}

	$query = "update counter set co_abschluss = $co_abschluss";

	if (!QueryDB($db, $query)) {
	   QueryDB($db, "rollback");
	   closeDB($db);
	   return;
	}
	
	QueryDB($db, "commit");
	closeDB($db);
}

?>
Return current item: TheoPlan