Subversion Repositories public

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 andreas 1
<?
2
require_once('version.inc');
3
require_once('dbaccess.inc');
4
require_once('language.inc');
5
require_once('header.inc');
6
require_once('crypt.inc');
7
require_once('settings.inc');
8
require_once('menu.inc');
9
 
10
function NewPj($unum, $headline, $menu, $rstufe) {
11
	global $pmlight;
12
	$db = OpenDB();
13
 
14
	$num = $_REQUEST['num'];
15
	$name = $_REQUEST['name'];
16
	$pl = $_REQUEST['pl'];
17
	$plav = $_REQUEST['plav'];
18
	$sgf = $_REQUEST['sgf'];
19
	$tmgroup = $_REQUEST['tmgroup'];
20
	$status = $_REQUEST['status'];
21
?>
22
<p class="cry">Neues Projekt anlegen</p>
23
<form name="edit" action="edit_pj.php" method="post">
24
<input type="hidden" name="unum" value="<? echo "$unum"; ?>">
25
<input type="hidden" name="headline" value="12">
26
<input type="hidden" name="menu" value="<? echo "$menu"; ?>">
27
<input type="hidden" name="rstufe" value="<? echo "$rstufe"; ?>">
28
<input type="hidden" name="func" value="CheckNewPj">
29
<br>
30
<table class="indent"><tr><td>
31
<?php
32
	ButtonLink("Zur&uuml;ck", "forms.php", "unum=$unum&headline=$headline&menu=$menu&rstufe=$rstufe");
33
//echo "<a href=\"forms.php?unum=$unum&headline=$headline&menu=$menu&rstufe=$rstufe\"><img src=\"image/button_back.png\" border=1 alt=\"Zurueck\"></a>\n";
34
?>
35
</td></tr></table>
36
<table class="input">
37
   <tr>
38
      <td>Projektnummer:</td>
39
      <td><input type="text" class="inputmust" name="num" value="<? echo "$num"; ?>" size=8 maxlength=8></td>
40
   </tr>
41
   <tr>
42
      <td>Bezeichnung:</td>
43
      <td><input type="text" class="inputmust" name="name" value="<? echo "$name"; ?>" size=60 maxlength=100></td>
44
   </tr>
45
   <tr>
46
      <td>Projektleiter:</td>
47
      <td><select name="pl"><?php
48
	$query = "select mi_num, mi_vname, mi_nname from mitarbeiter where ";
49
	$query .= "mi_rstufe in (1,2) and mi_plan = true ";
50
	$query .= "order by mi_nname, mi_vname";
51
	$result = QueryDB($db, $query);
52
	$numrows = numrowsDB($result);
53
	$row = 0;
54
 
55
	while ($row < $numrows) {
56
	   $data = fetchDB($result, $row);
57
	   $mi_num = $data[0];
58
	   $mi_vname = $data[1];
59
	   $mi_nname = $data[2];
60
	   echo "<option value=\"$mi_num\"";
61
 
62
	   if ($pl == $mi_num)
63
	      echo " selected";
64
 
65
	   echo ">$mi_nname $mi_vname</option>\n";
66
	   $row++;
67
	}
68
?>
69
         </select>
70
      </td>
71
   </tr>
72
<?
73
	if (!$pmlight) {
74
?>
75
   <tr>
76
      <td>PLA-V:</td>
77
      <td><select name="plav"><?php
78
	$query = "select mi_num, mi_vname, mi_nname from mitarbeiter where ";
79
	$query .= "mi_rstufe in (1,2) and mi_plan = true ";
80
	$query .= "order by mi_nname, mi_vname";
81
	$result = QueryDB($db, $query);
82
	$numrows = numrowsDB($result);
83
	$row = 0;
84
 
85
	while ($row < $numrows) {
86
	   $data = fetchDB($result, $row);
87
	   $mi_num = $data[0];
88
	   $mi_vname = $data[1];
89
	   $mi_nname = $data[2];
90
 
91
	   echo "<option value=\"$mi_num\"";
92
 
93
	   if ($plav == $mi_num)
94
	      echo " selected";
95
 
96
	   echo ">$mi_nname $mi_vname</option>\n";
97
	   $row++;
98
	}
99
?>
100
         </select>
101
      </td>
102
   </tr>
103
   <tr>
104
      <td>Auftraggeber:</td>
105
      <td><select name="sgf"><?php
106
	$query = "select ks_num, ks_sgf from key_sgf order by ks_sgf";
107
	$result = QueryDB($db, $query);
108
	$numrows = numrowsDB($result);
109
	$row = 0;
110
 
111
	while ($row < $numrows) {
112
	   $data = fetchDB($result, $row);
113
	   $ks_num = $data[0];
114
	   $ks_sgf = $data[1];
115
	   echo "<option value=\"$ks_num\"";
116
 
117
	   if ($sgf == $ks_num)
118
	      echo " selected";
119
 
120
	   echo ">$ks_sgf</option>\n";
121
	   $row++;
122
	}
123
?>
124
         </select>
125
      </td>
126
   </tr>
127
   <tr>
128
      <td>Themenmanagergruppe:</td>
129
      <td><select name="tmgroup"><?php
130
	$query = "select kt_num, kt_tm from key_tmgroup order by kt_tm";
131
	$result = QueryDB($db, $query);
132
	$numrows = numrowsDB($result);
133
	$row = 0;
134
 
135
	while ($row < $numrows) {
136
	   $data = fetchDB($result, $row);
137
	   $kt_num = $data[0];
138
	   $kt_tm = $data[1];
139
	   echo "<option value=\"$kt_num\"";
140
 
141
	   if ($tmgroup == $kt_num)
142
	      echo " selected";
143
 
144
	   echo ">$kt_tm</option>\n";
145
	   $row++;
146
	}
147
?>
148
         </select>
149
      </td>
150
   </tr>
151
<?
152
	}
153
?>
154
   <tr>
155
      <td>Projektart:</td>
156
      <td><select name="status">
157
             <option value="0">Projekt</option>
158
             <option value="1"<? if ($status == 1) echo " selected"; ?>>Konto</option>
159
          </select>
160
      </td>
161
   </tr>
162
<?
163
	if ($pmlight) {
164
	   echo "<input type=\"hidden\" name=\"plav\" value=\"$unum\">\n";
165
	   echo "<input type=\"hidden\" name=\"sgf\" value=\"1\">\n";
166
	   echo "<input type=\"hidden\" name=\"tmgroup\" value=\"1\">\n";
167
	}
168
?>
169
</table>
170
<table class="indent"><tr><td>
171
<?
172
	ButtonSubmit("Speichern", "edit");
173
?>
174
</td></tr></table>
175
</form>
176
<?
177
	closeDB($db);
178
}
179
 
180
function EditPj($pjnum, $unum, $headline, $menu, $rstufe) {
181
	global $pmlight;
182
	global $role;
183
	$db = OpenDB();
184
 
185
	if ($pjnum > 0) {
186
	   $query = "select pr_name, pr_pl, pr_plav, pr_sgf, pr_tmgroup, pr_status ";
187
	   $query = $query . "from project where pr_num = $pjnum";
188
	   $result = QueryDB($db, $query);
189
	   $numrows = numrowsDB($result);
190
 
191
	   if ($numrows != 1) {
192
	      Error("Error: Projekt \"$pjnum\" wurde nicht gefunden!\n");
193
	      return;
194
	   }
195
 
196
	   $data = fetchDB($result, 0);
197
	   $pr_num = $pjnum;
198
	   $pr_name = $data[0];
199
	   $pr_pl = $data[1];
200
	   $pr_plav = $data[2];
201
	   $pr_sgf = $data[3];
202
	   $pr_tmgroup = $data[4];
203
	   $pr_status = $data[5];
204
	   echo "<p class=\"cry\">Projekt Editieren</p>\n";
205
	} else {
206
	   $pr_num = $_REQUEST['num'];
207
	   $pr_name = $_REQUEST['name'];
208
	   $pr_pl = $_REQUEST['pl'];
209
	   $pr_plav = $_REQUEST['plav'];
210
	   $pr_sgf = $_REQUEST['sgf'];
211
	   $pr_tmgroup = $_REQUEST['tmgroup'];
212
	   $pr_status = $_REQUEST['status'];
213
	   $func = $_REQUEST['func'];
214
 
215
	   if ($func != "matoprup")
216
	      echo "<p class=\"cry\">Eingabefehler!</p>\n";
217
	}
218
 
219
	$matopr = $_REQUEST['matopr'];
220
?>
221
<form name="edit" action="edit_pj.php" method="post">
222
<input type="hidden" name="unum" value="<? echo "$unum"; ?>">
223
<?php
224
	if ($pjnum <= 0) {
225
	   echo "<input type=\"hidden\" name=\"headline\" value=\"12\">\n";
226
	} else {
227
	   echo "<input type=\"hidden\" name=\"headline\" value=\"13\">\n";
228
	}
229
?>
230
<input type="hidden" name="menu" value="<? echo "$menu"; ?>">
231
<input type="hidden" name="rstufe" value="<? echo "$rstufe"; ?>">
232
<input type="hidden" name="minum" value="<? echo "$pjnum"; ?>">
233
<input type="hidden" name="status" value="<? echo "$pr_status"; ?>">
234
<input type="hidden" name="num" value="<? echo "$pr_num"; ?>">
235
<input type="hidden" name="func" value="CheckEditPj">
236
<br>
237
<table class="indent"><tr><td>
238
<?php
239
	ButtonLink("Zur&uuml;ck", "forms.php", "unum=$unum&headline=$headline&menu=$menu&rstufe=$rstufe");
240
?>
241
</td></tr></table>
242
<table border=0 cellspacing=0 cellpadding=0><tr><td valign="top">
243
<table class="input">
244
   <tr>
245
      <td>Projektnummer:</td>
246
      <td><input type="text" class="inputmust" name="num" value="<? echo "$pr_num"; ?>" disabled size=8 maxlength=8></td>
247
   </tr>
248
   <tr>
249
      <td>Bezeichnung:</td>
250
      <td><input type="text" class="inputmust" name="name" value="<? echo "$pr_name"; ?>" size=60 maxlength=100></td>
251
   </tr>
252
   <tr>
253
      <td>Projektleiter:</td>
254
      <td><select name="pl"><?php
255
	$query = "select mi_num, mi_vname, mi_nname from mitarbeiter where ";
256
	$query .= "mi_rstufe in (1,2) and mi_plan = true ";
257
	$query .= "order by mi_nname, mi_vname";
258
	$result = QueryDB($db, $query);
259
	$numrows = numrowsDB($result);
260
	$row = 0;
261
 
262
	while ($row < $numrows) {
263
	   $data = fetchDB($result, $row);
264
	   $mi_num = $data[0];
265
	   $mi_vname = $data[1];
266
	   $mi_nname = $data[2];
267
 
268
	   if ($pr_pl == $mi_num) {
269
	      echo "<option selected value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
270
	   } else {
271
	      echo "<option value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
272
	   }
273
 
274
	   $row++;
275
	}
276
?>
277
         </select>
278
      </td>
279
   </tr>
280
<?
281
	if (!$pmlight) {
282
?>
283
   <tr>
284
      <td>PLA-V:</td>
285
      <td><select name="plav"><?php
286
	$query = "select mi_num, mi_vname, mi_nname from mitarbeiter where ";
287
	$query .= "mi_rstufe in (1,2) and mi_plan = true ";
288
	$query .= "order by mi_nname, mi_vname";
289
	$result = QueryDB($db, $query);
290
	$numrows = numrowsDB($result);
291
	$row = 0;
292
 
293
	while ($row < $numrows) {
294
	   $data = fetchDB($result, $row);
295
	   $mi_num = $data[0];
296
	   $mi_vname = $data[1];
297
	   $mi_nname = $data[2];
298
 
299
	   if ($pr_plav == $mi_num) {
300
	      echo "<option selected value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
301
	   } else {
302
	      echo "<option value=\"$mi_num\">$mi_nname $mi_vname</option>\n";
303
	   }
304
 
305
	   $row++;
306
	}
307
?>
308
         </select>
309
      </td>
310
   </tr>
311
   <tr>
312
      <td>Auftraggeber:</td>
313
      <td><select name="sgf"><?php
314
	$query = "select ks_num, ks_sgf from key_sgf order by ks_sgf";
315
	$result = QueryDB($db, $query);
316
	$numrows = numrowsDB($result);
317
	$row = 0;
318
 
319
	while ($row < $numrows) {
320
	   $data = fetchDB($result, $row);
321
	   $ks_num = $data[0];
322
	   $ks_sgf = $data[1];
323
 
324
	   if ($ks_num == $pr_sgf) {
325
	      echo "<option selected value=\"$ks_num\">$ks_sgf</option>\n";
326
	   } else {
327
	      echo "<option value=\"$ks_num\">$ks_sgf</option>\n";
328
	   }
329
 
330
	   $row++;
331
	}
332
?>
333
         </select>
334
      </td>
335
   </tr>
336
   <tr>
337
      <td>Themenmanagergruppe:</td>
338
      <td><select name="tmgroup"><?php
339
	$query = "select kt_num, kt_tm from key_tmgroup order by kt_tm";
340
	$result = QueryDB($db, $query);
341
	$numrows = numrowsDB($result);
342
	$row = 0;
343
 
344
	while ($row < $numrows) {
345
	   $data = fetchDB($result, $row);
346
	   $kt_num = $data[0];
347
	   $kt_tm = $data[1];
348
 
349
	   if ($kt_num == $pr_tmgroup) {
350
	      echo "<option selected value=\"$kt_num\">$kt_tm</option>\n";
351
	   } else {
352
	      echo "<option value=\"$kt_num\">$kt_tm</option>\n";
353
	   }
354
 
355
	   $row++;
356
	}
357
?>
358
         </select>
359
      </td>
360
   </tr>
361
<?
362
	}
363
?>
364
   <tr>
365
      <td>Projektart:</td>
366
      <td><select name="status" disabled>
367
             <option value="0">Projekt</option>
368
             <option value="1" <? if (isset($pr_status) && $pr_status) echo "selected"; ?>>Konto</option>
369
          </select>
370
      </td>
371
   </tr>
372
<?
373
	if ($pmlight) {
374
	   echo "<input type=\"hidden\" name=\"plav\" value=\"$unum\">\n";
375
	   echo "<input type=\"hidden\" name=\"sgf\" value=\"1\">\n";
376
	   echo "<input type=\"hidden\" name=\"tmgroup\" value=\"1\">\n";
377
	}
378
?>
379
</table>
380
</td><td valign="top">
381
<?
382
	# Mitarbeiter und Rolle suchen, falls eine ausgewaehlt wurde
383
	if ($matopr > 0) {
384
	   $query = "select ma_minum, ma_role from matopr ";
385
	   $query .= "where ma_num = $matopr";
386
 
387
	   if (!($result = QueryDB($db, $query))) {
388
	      Error("Interner Fehler: Mitarbeiter und Rolle wurde nicht gefunden!");
389
	      closeDB($db);
390
	      return;
391
	   }
392
 
393
	   if (numrowsDB($result) > 0) {
394
	      $data = fetchDB($result, 0);
395
	      $ma_minum = $data[0];
396
	      $ma_role = $data[1];
397
	   } else {
398
	      $ma_minum = 0;
399
	      $ma_role = 0;
400
	   }
401
	}
402
?>
403
<table class="input">
404
  <tr>
405
    <td colspan=3 align="center">Benutzer und Rolle dem Projekt zuordnen:</td>
406
  </tr>
407
  <tr>
408
    <td><select name="mitarbeiter">
409
<?
410
	$query = "select mi_num, mi_nname, mi_vname from mitarbeiter ";
411
	$query .= "order by mi_nname, mi_vname";
412
 
413
	if (!($result = QueryDB($db, $query))) {
414
	   Error("Interner Fehler: Es konnten keine Mitarbeiter gefunden werden!");
415
	   closeDB($db);
416
	   return;
417
	}
418
 
419
	$anz = numrowsDB($result);
420
	$i = 0;
421
 
422
	while ($i < $anz) {
423
	   $data = fetchDB($result, $i);
424
	   $mi_num = $data[0];
425
	   $mi_nname = $data[1];
426
	   $mi_vname = $data[2];
427
	   echo "<option value=\"$mi_num\"";
428
 
429
	   if ($ma_minum == $mi_num)
430
	      echo " selected";
431
 
432
	   echo ">$mi_nname $mi_vname</option>\n";
433
	   $i++;
434
	}
435
?>
436
      </select>
437
    </td>
438
    <td>
439
<?
440
	if ($role) {
441
?>
442
      <select name="role">
443
<?
444
	   $query = "select kr_num, kr_role from key_role order by kr_role";
445
 
446
	   if (!($result = QueryDB($db, $query))) {
447
	      Error("Interner Fehler: Es konnten keine Mitarbeiterrollen gefunden werden!");
448
	      closeDB($db);
449
	      return;
450
	   }
451
 
452
	   $anz = numrowsDB($result);
453
	   $i = 0;
454
 
455
	   while ($i < $anz) {
456
	      $data = fetchDB($result, $i);
457
	      $kr_num = $data[0];
458
	      $kr_role = $data[1];
459
	      echo "<option value=\"$kr_num\"";
460
 
461
	      if ($ma_role == $kr_num)
462
		 echo " selected";
463
 
464
	      echo ">$kr_role</option>\n";
465
	      $i++;
466
	   }
467
?>
468
      </select>
469
<?
470
	} else {
471
	   echo "&nbsp;";
472
	}
473
?>
474
    </td>
475
    <td>
476
<?
477
	$lines = "num=$pjnum&name='+edit.name.value+'&pl=";
478
	$lines .= "'+edit.pl.value+'&plav='+edit.plav.value+'&sgf=";
479
	$lines .= "'+edit.sgf.value+'&tmgroup='+edit.tmgroup.value+";
480
	$lines .= "'&status='+edit.status.value+'&mitarbeiter='";
481
	$lines .= "+edit.mitarbeiter.value+'&role='+edit.role.value+'";
482
	ButtonLink("Hinzuf&uuml;gen", "edit_pj.php", "pjedit=$pjnum&unum=$unum&headline=$headline&menu=$menu&rstufe=$rstufe&func=matopr&$lines");
483
?>
484
    </td>
485
  </tr>
486
  <tr>
487
     <td colspan=2>
488
       <select size=6 name="matopr" onClick="javascript:MoveTo('edit_pj.php','<? echo "pjedit=$pjnum&unum=$unum&headline=$headline&menu=$menu&rstufe=$rstufe&func=matoprup&matopr='+this.value+'&$lines"; ?>')">
489
<?
490
	$query = "select ma_num, mi_nname, mi_vname, kr_role from matopr ";
491
	$query .= "left join mitarbeiter on mi_num = ma_minum ";
492
	$query .= "left join key_role on kr_num = ma_role ";
493
	$query .= "where ma_prnum = $pjnum ";
494
	$query .= "order by mi_nname, mi_vname";
495
 
496
	if (!($result = QueryDB($db, $query))) {
497
	   Error("Interner Fehler: Keine Mitarbeiterzuordnungen gefunden!");
498
	   closeDB($db);
499
	   return;
500
	}
501
 
502
	$anz = numrowsDB($result);
503
	$i = 0;
504
 
505
	while ($i < $anz) {
506
	   $data = fetchDB($result, $i);
507
	   $ma_num = $data[0];
508
	   $mi_nname = $data[1];
509
	   $mi_vname = $data[2];
510
	   $kr_role = $data[3];
511
	   echo "<option value=\"$ma_num\"";
512
 
513
	   if ($matopr == $ma_num)
514
	      echo " selected";
515
 
516
	   if ($role)
517
	      echo ">$mi_nname $mi_vname, &lt;$kr_role&gt;</option>\n";
518
	   else
519
	      echo ">$mi_nname $mi_vname</option>\n";
520
 
521
	   $i++;
522
	}
523
?>
524
      </select>
525
    </td>
526
    <td valign="bottom">
527
<?
528
	ButtonLink("L&ouml;schen", "edit_pj.php", "pjedit=$pjnum&unum=$unum&headline=$headline&menu=$menu&rstufe=$rstufe&func=matoprdel&matopr='+edit.matopr.value+'");
529
?>
530
    </td>
531
  </tr>
532
</table>
533
</td></tr></table>
534
<table class="indent"><tr><td>
535
<?
536
	ButtonSubmit("Speichern", "edit");
537
?>
538
</td></tr></table>
539
</form>
540
<?
541
	closeDB($db);
542
}
543
 
544
function CheckNewPj($unum, $headline, $menu, $rstufe) {
545
	$pr_num = $_REQUEST['num'];
546
	$pr_name = $_REQUEST['name'];
547
	$pr_pl = $_REQUEST['pl'];
548
	$pr_plav = $_REQUEST['plav'];
549
	$pr_sgf = $_REQUEST['sgf'];
550
	$pr_tmgroup = $_REQUEST['tmgroup'];
551
	$pr_status = $_REQUEST['status'];
552
	$err = 0;
553
 
554
	if ($pr_num < 1) {
555
	   Error("Sie m&uuml;ssen eine Projektnummer eingeben!\n");
556
	   $err = 1;
557
	}
558
 
559
	if (!strlen($pr_name)) {
560
	   Error("Sie m&uuml;ssen eine Projektbezeichnung eingeben!\n");
561
	   $err = 1;
562
	}
563
 
564
	$db = OpenDB();
565
	$query = "select pr_name from project where pr_num = $pr_num";
566
	$result = QueryDB($db, $query);
567
	$numrows = numrowsDB($result);
568
 
569
	if ($numrows != 0) {
570
	   Error("Ein Projekt mit der Nummer \"$pr_num\" existiert bereits!\n");
571
	   $err = 1;
572
	}
573
 
574
	$query = "select pr_num from project where pr_name = '$pr_name'";
575
	$result = QueryDB($db, $query);
576
	$numrows = numrowsDB($result);
577
 
578
	if ($numrows != 0) {
579
	   Error("Ein Projekt mit dem Namen \"<i>$pr_name</i>\" existiert bereits!\n");
580
	   $err = 1;
581
	}
582
 
583
	if ($err == 1) {
584
	   EditPj(0, $unum, $headline, $menu, $rstufe);
585
	   return false;
586
	}
587
 
588
	# An dieser Stelle haben wir eine gepruefte Datenbasis, welche wir
589
	# als neuen Datensatz speichern koennen.
590
	if (!QueryDB($db, "begin")) {
591
	   closeDB($db);
592
	   return false;
593
	}
594
 
595
	$query = "insert into project (pr_num, pr_name, pr_pl, pr_plav, pr_sgf, pr_tmgroup, pr_status) ";
596
	$query = $query . "values ($pr_num, '$pr_name', $pr_pl, $pr_plav, $pr_sgf, $pr_tmgroup, $pr_status)";
597
 
598
	if (!QueryDB($db, $query)) {
599
	   QueryDB($db, "rollback");
600
	   closeDB($db);
601
	   return false;
602
	}
603
 
604
	# Handelt es sich um ein "Konto" dann muessen wir einen versteckten
605
	# Plan anlegen. Um Den Plan deutlich als Pseudoplan zu kennzeichnen
606
	# bekommt er den Status 0.
607
	if ($pr_status == 1) {
608
	   $query = "select co_plan, co_task from counter";
609
 
610
	   if (!($result = QueryDB($db, $query))) {
611
	      QueryDB($db, "rollback");
612
	      closeDB($db);
613
	      return false;
614
	   }
615
 
616
	   $data = fetchDB($result, 0);
617
	   $co_plan = $data[0] + 1;
618
	   $co_task = $data[1] + 1;
619
	   $query = "insert into plan (pl_num, pl_lfd, pl_prnum, pl_status) ";
620
	   $query .= "values ($co_plan, 0, $pr_num, 0)";
621
 
622
	   if (!QueryDB($db, $query)) {
623
	      QueryDB($db, "rollback");
624
	      closeDB($db);
625
	      return false;
626
	   }
627
 
628
	   $ta_hash = md5($co_task);
629
	   $query = "insert into task (ta_num, ta_plnum, ta_id, ta_name, ";
630
	   $query .= "ta_meeting, ta_start, ta_duration, ta_level, ta_phase, ta_hash) ";
631
	   $query .= "values ($co_task, $co_plan, 0, '$pr_name', 0, 0, ";
632
	   $query .= "-32767, 0, 0, '$ta_hash')";
633
 
634
	   if (!QueryDB($db, $query)) {
635
	      QueryDB($db, "rollback");
636
	      closeDB($db);
637
	      return false;
638
	   }
639
 
640
	   $query = "update counter set co_plan = $co_plan, co_task = $co_task";
641
 
642
	   if (!QueryDB($db, $query)) {
643
	      QueryDB($db, "rollback");
644
	      closeDB($db);
645
	      return false;
646
	   }
647
	}
648
 
649
	QueryDB($db, "commit");
650
	Journal(203, "Projekt: $pr_num $pr_name", $db);
651
 
652
	if ($pr_status == 1)
653
	   Journal(204, "Plan: $co_plan; Projekt: $pr_num", $db);
654
 
655
	closeDB($db);
656
	return true;
657
}
658
 
659
function CheckEditPj($unum, $headline, $menu, $rstufe) {
660
	$pr_num = $_REQUEST['num'];
661
	$pr_name = $_REQUEST['name'];
662
	$pr_pl = $_REQUEST['pl'];
663
	$pr_plav = $_REQUEST['plav'];
664
	$pr_sgf = $_REQUEST['sgf'];
665
	$pr_tmgroup = $_REQUEST['tmgroup'];
666
	$pr_status = $_REQUEST['status'];
667
	$err = 0;
668
 
669
	if ($pr_num < 1) {
670
	   Error("Sie m&uuml;ssen eine Projektnummer eingeben!\n");
671
	   $err = 1;
672
	}
673
 
674
	if (!strlen($pr_name)) {
675
	   Error("Sie m&uuml;ssen eine Projektbezeichnung eingeben!\n");
676
	   $err = 1;
677
	}
678
 
679
	$db = OpenDB();
680
	$query = "select pr_name from project where pr_num = $pr_num";
681
	$result = QueryDB($db, $query);
682
	$numrows = numrowsDB($result);
683
 
684
	if ($numrows != 1) {
685
	   Error("Ein Projekt mit der Nummer \"$pr_num\" existiert nicht!\n");
686
	   $err = 1;
687
	}
688
 
689
	if ($err == 1) {
690
	   EditPj(0, $unum, $headline, $menu, $rstufe);
691
	   return false;
692
	}
693
 
694
	# An dieser Stelle haben wir eine gepruefte Datenbasis, welche wir
695
	# speichern koennen.
696
	if (!QueryDB($db, "begin")) {
697
	   closeDB($db);
698
	   return false;
699
	}
700
 
701
	$query = "update project set pr_name = '$pr_name', pr_pl = $pr_pl, pr_plav = $pr_plav, ";
702
	$query .= "pr_sgf = $pr_sgf, pr_tmgroup = $pr_tmgroup, pr_status = $pr_status ";
703
	$query .= "where pr_num = $pr_num";
704
 
705
	if (!QueryDB($db, $query)) {
706
	   QueryDB($db, "rollback");
707
	   closeDB($db);
708
	   return false;
709
	}
710
 
711
	Journal(301, "Projekt: $pr_num $pr_name", $db);
712
	closeDB($db);
713
	return true;
714
}
715
 
716
function AskDelete ($pr_num) {
717
	$headline = $_REQUEST['headline'];
718
	$menu = $_REQUEST['menu'];
719
 
720
	$nav = "pr_num=$pr_num&menu=$menu&";
721
	$nav .= "headline=$headline&func=DeletePj";
722
 
723
	# Projektnamen auslesen
724
	$db = OpenDB();
725
	$query = "select pr_name from project where pr_num = $pr_num";
726
 
727
	if (!($result = QueryDB($db, $query))) {
728
	   closeDB($db);
729
	   return;
730
	}
731
 
732
	$data = fetchDB($result, 0);
733
	$pr_name = $data[0];
734
	closeDB($db);
735
?>
736
<br>
737
<form name="Alarm" method="post">
738
<table border=2 class="alarm">
739
   <tr><td colspan=2 style="text-align: center"><big>Warnung!</big><br><br>
740
           Wollen Sie wirklich das Projekt<br>
741
	   <b><? echo "$pr_num $pr_name"; ?></b><br>
742
	   unwiederbringlich l&ouml;schen?<br>
743
	   Es werden alle Pl&auml;ne dieses Projekts und alle
744
	   eventuell angefallenen Aufw&auml;nde der Mitarbeiter
745
	   automatisch gel&ouml;scht!!<br><br>
746
	   Projekt unwiederbringlich l&ouml;schen?
747
      </td>
748
   </tr>
749
   <tr>
750
      <td><center><input type="button" name="yes" value="L&ouml;schen" onClick="javascript:MoveTo('edit_pj.php','yes=yes&<? echo "$nav"; ?>')"></center></td>
751
      <td><center><input type="button" name="no" value="Abbruch" onClick="javascript:MoveTo('edit_pj.php','no=no&<? echo "$nav"; ?>')"></center></td>
752
   </tr>
753
</table>
754
</form>
755
<?php
756
}
757
 
758
function DeleteProject($pr_num) {
759
	global $rstufe;
760
 
761
	if ($rstufe != 1) {
762
	   Error("Sie sind nicht berechtigt ein Projekt zu l&ouml;schen!");
763
	   return false;
764
	}
765
 
766
	if (!isset($pr_num) || $pr_num <= 0) {
767
	   Error("Interner Fehler: Projektnummer fehlt!");
768
	   return false;
769
	}
770
 
771
	$db = OpenDB();
772
 
773
	if (!QueryDB($db, "begin")) {
774
	   closeDB($db);
775
	   return false;
776
	}
777
 
778
	# Als erstes loeschen wir eventuell vorhandene Kalendereintraege
779
	$query = "delete from calendar where ca_prnum = $pr_num";
780
 
781
	if (!QueryDB($db, $query)) {
782
	   QueryDB($db, "rollback");
783
	   closeDB($db);
784
	   return false;
785
	}
786
 
787
	# Hier loeschen wir die IST-Erfassungen
788
	$query = "delete from wdone where wd_prnum = $pr_num";
789
 
790
	if (!QueryDB($db, $query)) {
791
	   QueryDB($db, "rollback");
792
	   closeDB($db);
793
	   return false;
794
	}
795
 
796
	$query = "select pl_num from plan where pl_prnum = $pr_num";
797
 
798
	if (!($respl = QueryDB($db, $query))) {
799
	   QueryDB($db, "rollback");
800
	   closeDB($db);
801
	   return false;
802
	}
803
 
804
	$numpl = numrowsDB($respl);
805
	$cnumpl = 0;
806
 
807
	while ($cnumpl < $numpl) {
808
	   $data = fetchDB($respl, $cnumpl);
809
	   $pl_num = $data[0];
810
	   $query = "select ta_num from task where ta_plnum = $pl_num";
811
 
812
	   if (!($resta = QueryDB($db, $query))) {
813
	      QueryDB($db, "rollback");
814
	      closeDB($db);
815
	      return false;
816
	   }
817
 
818
	   $numta = numrowsDB($resta);
819
	   $cnumta = 0;
820
 
821
	   while ($cnumta < $numta) {
822
	      $data = fetchDB($resta, $cnumta);
823
	      $ta_num = $data[0];
824
	      # Hier loeschen wir die Ressourcen zum Projekt
825
	      $query = "delete from allocation where al_task = $ta_num";
826
 
827
	      if (!QueryDB($db, $query)) {
828
	         QueryDB($db, "rollback");
829
	         closeDB($db);
830
	         return false;
831
	      }
832
 
833
	      $cnumta++;
834
	   }
835
 
836
	   # Hier loeschen wir die Tasks des Projekts
837
	   $query = "delete from task where ta_plnum = $pl_num";
838
 
839
	   if (!QueryDB($db, $query)) {
840
	      QueryDB($db, "rollback");
841
	      closeDB($db);
842
	      return false;
843
	   }
844
 
845
	   $cnumpl++;
846
	}
847
 
848
	# Hier loeschen wir die Plaene des Projekts
849
	$query = "delete from plan where pl_prnum = $pr_num";
850
 
851
	if (!QueryDB($db, $query)) {
852
	   QueryDB($db, "rollback");
853
	   closeDB($db);
854
	   return false;
855
	}
856
 
857
	# Hier loeschen wir die Mitarbeiter des Projekts
858
	$query = "delete from matopr where ma_prnum = $pr_num";
859
 
860
	if (!QueryDB($db, $query)) {
861
	   QueryDB($db, "rollback");
862
	   closeDB($db);
863
	   return false;
864
	}
865
 
866
	# Schliesslich koennen wir das Projekt selbst loeschen
867
	$query = "delete from project where pr_num = $pr_num";
868
 
869
	if (!QueryDB($db, $query)) {
870
	   QueryDB($db, "rollback");
871
	   closeDB($db);
872
	   return false;
873
	}
874
 
875
	# Jetzt da alles geloescht ist, wird es fix gemacht
876
	QueryDB($db, "commit");
877
	closeDB($db);
878
	return true;
879
}
880
 
881
function SaveMaToPr() {
882
	$mitarbeiter = $_REQUEST['mitarbeiter'];
883
	$role = $_REQUEST['role'];
884
	$pr_num = $_REQUEST['num'];
885
 
886
	if (!isset($mitarbeiter) || !isset($role) || $mitarbeiter < 1 || $role < 1) {
887
	   Error("Interner Fehler: Ein Parameter fehlt oder ist ung&uuml;ltig!");
888
	   return;
889
	}
890
 
891
	if (!isset($pr_num) || $pr_num < 1) {
892
	   Error("Sie m&uuml;ssen eine Projektnummer eintragen!");
893
	   return;
894
	}
895
 
896
	$db = OpenDB();
897
	$query = "select count(*) from matopr where ma_minum = $mitarbeiter and ";
898
	$query .= "ma_prnum = $pr_num";
899
 
900
	if (!($result = QueryDB($db, $query))) {
901
	   Error("Interner Fehler: Datens&auml;tze konnten nicht gez&auml;hlt werden!");
902
	   closeDB($db);
903
	   return;
904
	}
905
 
906
	$data = fetchDB($result, 0);
907
 
908
	if ($data[0] > 0)
909
	   $flag = true;
910
	else
911
	   $flag = false;
912
 
913
	$query = "select co_matopr from counter";
914
 
915
	if (!($result = QueryDB($db, $query))) {
916
	   Error("Interner Fehler: Z&auml;hler nicht gefunden!");
917
	   closeDB($db);
918
	   return;
919
	}
920
 
921
	$data = fetchDB($result, 0);
922
	$co_matopr = $data[0] + 1;
923
 
924
	if (!$flag) {
925
	   $query = "insert into matopr (ma_num, ma_minum, ma_prnum, ma_role) ";
926
	   $query .= "values ($co_matopr, $mitarbeiter, $pr_num, $role)";
927
	} else {
928
	   $query = "update matopr set ma_role = $role where ";
929
	   $query .= "ma_minum = $mitarbeiter and ma_prnum = $pr_num";
930
	}
931
 
932
	if (!QueryDB($db, "begin")) {
933
	   Error("Interner Fehler: Transaktion fehlgeschlagen!");
934
	   closeDB($db);
935
	   return;
936
	}
937
 
938
	if (!QueryDB($db, $query)) {
939
	   Error("Interner Fehler: Konnte Datensatz nicht einf&uuml;gen!");
940
	   QueryDB($db, "rollback");
941
	   closeDB($db);
942
	   return;
943
	}
944
 
945
	if (!$flag) {
946
	   $query = "update counter set co_matopr = $co_matopr";
947
 
948
	   if (!QueryDB($db, $query)) {
949
	      Error("Interner Fehler: Z&auml;hlerstand konnte nicht erh&ouml;ht werden!");
950
	      QueryDB($db, "rollback");
951
	      closeDB($db);
952
	      return;
953
	   }
954
	}
955
 
956
	QueryDB($db, "commit");
957
	closeDB($db);
958
}
959
 
960
function DeleteMaToPr() {
961
	$ma_num = $_REQUEST['matopr'];
962
 
963
	if (!isset($ma_num) || $ma_num < 1) {
964
	   Error("Interner Fehler: Falsche oder fehlende Referenznummer!");
965
	   return;
966
	}
967
 
968
	$db = OpenDB();
969
	$query = "select ma_minum, ma_prnum from matopr where ma_num = $ma_num";
970
 
971
	if (!($result = QueryDB($db, $query))) {
972
	   closeDB($db);
973
	   return;
974
	}
975
 
976
	if (numrowsDB($result) <= 0) {
977
	   Error("Interner Fehler: Referenznummer wurde nicht gefunden!");
978
	   closeDB($db);
979
	   return;
980
	}
981
 
982
	$data = fetchDB($result, 0);
983
	$ma_minum = $data[0];
984
	$ma_prnum = $data[1];
985
 
986
	$query = "select count(*) from allocation ";
987
	$query .= "left join task on ta_num = al_task ";
988
	$query .= "left join plan on pl_num = ta_plnum ";
989
	$query .= "where al_ressource = $ma_minum and pl_prnum = $ma_prnum";
990
 
991
	if (!($result = QueryDB($db, $query))) {
992
	   closeDB($db);
993
	   return;
994
	}
995
 
996
	$data = fetchDB($result, 0);
997
	$anz = $data[0];
998
 
999
	if ($anz > 0) {
1000
	   Error("Mitarbeiter ist bereits im Projekt verplant und kann daher nicht gel&ouml;scht werden!");
1001
	   closeDB($db);
1002
	   return;
1003
	}
1004
 
1005
	$query = "delete from matopr where ma_num = $ma_num";
1006
 
1007
	if (!QueryDB($db, $query)) {
1008
	   closeDB($db);
1009
	   return;
1010
	}
1011
 
1012
	closeDB($db);
1013
}
1014
 
1015
$pjnew = $_REQUEST['pjnew'];
1016
$pjedit = $_REQUEST['pjedit'];
1017
$pjdel = $_REQUEST['pjdel'];
1018
$func = $_REQUEST['func'];
1019
$yes = $_REQUEST['yes'];
1020
 
1021
if (isset($func)) {
1022
   if ($func == "CheckNewPj") {
1023
      if (CheckNewPj($unum, $headline, $menu, $rstufe)) {
1024
         echo "<p>Daten wurden erfolgreich gespeichert!</p>\n";
1025
	 echo "<form name=\"forms\" action=\"forms.php\" method=\"post\">";
1026
	 echo "<input type=\"hidden\" name=\"unum\" value=\"$unum\">";
1027
	 echo "<input type=\"hidden\" name=\"headline\" value=\"4\">";
1028
	 echo "<input type=\"hidden\" name=\"menu\" value=\"$menu\">";
1029
	 echo "<input type=\"hidden\" name=\"rstufe\" value=\"$rstufe\">";
1030
	 echo "<input type=\"hidden\" name=\"knopf\" value=\"31\">";
1031
	 Button("Weiter -->", "forms");
1032
//	 echo "<input type=\"submit\" name=\"submit\" value=\"Weiter -->\">";
1033
	 echo "</form>\n";
1034
      }
1035
   }
1036
 
1037
   if ($func == "CheckEditPj") {
1038
      if (CheckEditPj($unum, $headline, $menu, $rstufe)) {
1039
         echo "<p>Daten wurden erfolgreich gespeichert!</p>\n";
1040
	 echo "<form name=\"forms\" action=\"forms.php\" method=\"post\">";
1041
	 echo "<input type=\"hidden\" name=\"unum\" value=\"$unum\">";
1042
	 echo "<input type=\"hidden\" name=\"headline\" value=\"4\">";
1043
	 echo "<input type=\"hidden\" name=\"menu\" value=\"$menu\">";
1044
	 echo "<input type=\"hidden\" name=\"rstufe\" value=\"$rstufe\">";
1045
	 echo "<input type=\"hidden\" name=\"knopf\" value=\"31\">";
1046
	 Button("Weiter -->", "forms");
1047
//	 echo "<input type=\"submit\" name=\"submit\" value=\"Weiter -->\">";
1048
	 echo "</form>\n";
1049
      }
1050
   }
1051
 
1052
   if ($func == "DeletePj" && isset($yes) && $yes == "yes") {
1053
      $pr_num = $_REQUEST['pr_num'];
1054
      if (DeleteProject($pr_num)) {
1055
         echo "<p>Projekt $pr_num wurde unwiederbringlich gel&ouml;scht!</p>\n";
1056
         Journal(102, "Projekt: $pr_num");
1057
      }
1058
 
1059
      echo "<form name=\"forms\" action=\"forms.php\" method=\"post\">";
1060
      echo "<input type=\"hidden\" name=\"unum\" value=\"$unum\">";
1061
      echo "<input type=\"hidden\" name=\"headline\" value=\"4\">";
1062
      echo "<input type=\"hidden\" name=\"menu\" value=\"$menu\">";
1063
      echo "<input type=\"hidden\" name=\"rstufe\" value=\"$rstufe\">";
1064
      echo "<input type=\"hidden\" name=\"knopf\" value=\"31\">";
1065
      Button("Weiter -->", "forms");
1066
//      echo "<input type=\"submit\" name=\"submit\" value=\"Weiter -->\">";
1067
      echo "</form>\n";
1068
   }
1069
 
1070
   if ($func == "matopr")
1071
      SaveMaToPr();
1072
 
1073
   if ($func == "matoprdel")
1074
      DeleteMaToPr();
1075
}
1076
 
1077
if (isset($pjnew)) {
1078
   NewPj($unum, $headline, $menu, $rstufe);
1079
}
1080
 
1081
if (isset($pjedit)) {
1082
   EditPj($pjedit, $unum, $headline, $menu, $rstufe);
1083
}
1084
 
1085
if (isset($pjdel)) {
1086
   AskDelete($pjdel);
1087
}
1088
 
1089
require('footer.inc');
1090
?>