summaryrefslogtreecommitdiff
path: root/admin/schichtplan.php_old
blob: 388b5416d5f682679db0629432965eb9e9cd501d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
$title = "Schichtplan";
$header = "Neue Schichten erfassen";
$submenus = 1;
include ("./inc/header.php");
include ("./inc/funktion_user.php");

if (!IsSet($action)) {
echo "Hallo ".$_SESSION['Nick'].",<br>\n";
echo "hier kannst du Schichten anlegen, &auml;ndern oder l&ouml;schen.<br><br>";
echo "<a href=\"./schichtplan.php?action=new\">Neue Schicht einplanen</a><br><br>\n\n";
?>
<table width="100%" class="border" cellpadding="2" cellspacing="1">
	<tr class="contenttopic">
		<td>Datum</td>
		<td>Raum</td>
		<td>Dauer</td>
		<td>Beschreibung</td>
		<td>&Auml;ndern</td>
	</tr>
<?
$sql = "Select * from Schichtplan ORDER BY RID, Date";
$Erg = mysql_query($sql, $con);
$rowcount = mysql_num_rows($Erg);
for ($i=0; $i<$rowcount; $i++){
  echo "\t<tr class=\"content\">\n";
  echo "\t\t<td>".mysql_result($Erg, $i, "Date")."</td>\n";
  $sql2= "Select * from Raeume where RID=\"".mysql_result($Erg, $i, "RID")."\"";
  $Erg2 = mysql_query($sql2, $con);

  echo "\t\t<td>".mysql_result($Erg2, 0, "Name")."</td>\n";

  echo "\t\t<td>".mysql_result($Erg, $i, "Dauer")." Std. </td>\n";
  echo "\t\t<td>".mysql_result($Erg, $i, "Name")."</td>\n";
  echo "\t\t<td><a href=\"./schichtplan.php?action=change&SID=".mysql_result($Erg, $i, "SID")."\">XXX</a></td>\n";
  echo "\t</tr>\n";
}
echo "</table>";

} else {

switch ($action){

case 'new':
?>
Hier kannst du neue Schichten eintragen. Dazu musst du den Anfang und das Ende der Schichten eintragen.
&Uuml;ber die L&auml;nge der Schichten errechnet sich dadurch die Anzahl dieser. Dadurch k&ouml;nnen gleich
mehrere Schichten auf einmal erfasst werden:

<? /* <form action="<? echo basename (getenv ("PATH_INFO")) ; ?>" method="post"> */ ?>
<form action="<? echo $_SERVER['SCRIPT_NAME']; ?>" >
  <table>
  <tr>
    <td align="right">Name:</td>
    <td><input type="text" name="SchichtName" size="50" value="Engel Schicht X"></td>
  </tr>
  <tr>
    <td align="right">Month.Jahr:</td>
    <td><input type="ext" name="MonthJahr" size="7" value="2003-12"></td>
  </tr>
  <tr>
    <td align="right">Beginn:</td>
    <td>Date<input type="text" name="SDatum" size="5" value="27">
        Time<input type="text" name="STime" size="5" value="10"></td>
  </tr>
  <tr>
    <td align="right">More then One</td>
    <td><input type="checkbox" name="MoreThenOne" value="ON" checked></td>
  </tr>
  <tr>
    <td align="right">End:</td>
    <td>Date<input type="text" name="EDatum" size="5" value="29">
        Time<input type="text" name="ETime" size="5" value="12"></td>
  </tr>
  <tr>
    <td align="right">L&auml;nge in h:</td>
    <td><input type="text" name="len" size="5" value="2"></td>
  </tr>
  <tr>
    <td align="right">Ort:</td>
    <td>

    <select name="RID">
<?
$sql = "select * from Raeume";
$Erg = mysql_query($sql, $con);

$rowcount = mysql_num_rows($Erg);

for ($i=0; $i<$rowcount; $i++) {
	echo "     <option value=\"".mysql_result($Erg, $i, "RID")."\">";
	echo mysql_result($Erg, $i, "Name")."</option>\n";
}
?>
    </select>
    </td>
  </tr>
  <tr>
    <td align="right">Nacht-Sonderschichten ein:</td>
    <td><input type="checkbox" name="NachtON" value="ON"></td>
  </tr>
  <tr>
    <td align="right">L&auml;nge bei Nacht in h (Time;Time):</td>
    <td><input type="text" name="len_night" size="50" value="0;4;8;10;12;14;16;18;20;22;24"></td>
  </tr>
</table>
 <br>
<input type="hidden" name="OnlyShow" value="ON">
<input type="hidden" name="action" value="newsave">
<input type="submit" value="zeig mal Gabriel!">
</form>

<?
	break; // Ende new

case 'newsave':
    if (isset($SDatum) && ($len > 0)) {
	$lenOrg = $len;
	if( $NachtON == "ON" )
	{	
		$lenPos = 0;
		$lenArrayDummy = explode( ";", $len_night);
		$i = -1;
                foreach ( $lenArrayDummy as $Temp )
                {
			$i++;
			if( $i == 0 )
				$lenArray[$i] = $Temp;
			else 
				$lenArray[$i] = $Temp- $lenArrayDummy[$i-1];

			if( $Temp==$STime )
				$lenPos = $i;
        	}//foreach
		$lenPosMax = $i;
	}//IF( $NachtON == "ON" )

	echo "<table border=\"1\">\n";
	echo "<tr>\n";
	echo "\t<td valign=\"top\" align=\"center\">Start</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">End</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">RID</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">len</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">Beschreibung</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">OK?</td>\n";
	echo "</tr>\n";
 	
	$DateEnd = $SDatum;
 	$TimeEnd = $STime;
	do {	
		// define Start time
		$Date = $DateEnd;
		$Time = $TimeEnd;
		$_DateS = $MonthJahr. "-". $Date. " ". $Time. ":00:00";
			
		// define End time
	 	if( $NachtON == "ON" )
		{
			$len = $lenArray[$lenPos++];
			if( $lenPos == $lenPosMax )
				$lenPos = 0;
		}
		$TimeEnd = $Time+ $len;
		
		//Tages�berschreitung
		while( $TimeEnd >= 24 )
		{
			$TimeEnd -= 24;
			$DateEnd += 1;
		}
		//ist schischt zu lang dan verk�rzen	
		if( $DateEnd > $EDatum || ($DateEnd == $EDatum && $TimeEnd >= $ETime) ) 
		{
			$len -= ($DateEnd- $EDatum)*24; 
			$len -= ($TimeEnd- $ETime);		// -(-) ->> +
			$DateEnd = $EDatum;
			$TimeEnd = $ETime;
		}
		$_DateE = $MonthJahr. "-". $DateEnd. " ". $TimeEnd. ":00:00";

		if( $_DateS != $_DateE )
			CreateNewEntry();
		
		if( $MoreThenOne!="ON" ) break;
		if( $DateEnd == $EDatum && $TimeEnd >= $ETime ) break;
	} while( true );
	echo "</table>";
	
	if( $OnlyShow!="" ) 
	{
		echo "<form action=\"". $_SERVER['SCRIPT_NAME']. "\">";
		echo "\n\t<Input type=\"hidden\" name=\"SchichtName\" value=\"$SchichtName\">";
		echo "\n\t<input type=\"hidden\" name=\"MonthJahr\" value=\"$MonthJahr\">";
		echo "\n\t<input type=\"hidden\" name=\"SDatum\" value=\"$SDatum\">";
		echo "\n\t<input type=\"hidden\" name=\"STime\" value=\"$STime\">";
		echo "\n\t<input type=\"hidden\" name=\"MoreThenOne\" value=\"$MoreThenOne\">";
		echo "\n\t<input type=\"hidden\" name=\"EDatum\" value=\"$EDatum\">";
		echo "\n\t<input type=\"hidden\" name=\"ETime\" value=\"$ETime\">";
		echo "\n\t<input type=\"hidden\" name=\"len\" value=\"$lenOrg\">";
		echo "\n\t<input type=\"hidden\" name=\"RID\" value=\"$RID\">";
		echo "\n\t<input type=\"hidden\" name=\"NachtON\" value=\"$NachtON\">";
		echo "\n\t<input type=\"hidden\" name=\"len_night\" value=\"$len_night\">";
		echo "\n\t<input type=\"hidden\" name=\"OnlyShow\" value=\"\">";
		
		echo "\n\t<input type=\"hidden\" name=\"action\" value=\"newsave\">";
		echo "\n\t<input type=\"submit\" value=\"mach mal Gabriel!\">";
		echo "\n</form>";
	} //if
    } //IF
    break;


case 'change':
	if (! IsSet($SID)){
		echo "Fehlerhafter Aufruf!";
	} else {
	 $sql = "select * from Schichtplan where (SID = $SID)";
	 $Erg = mysql_query($sql, $con);

         echo "Schicht ab&auml;ndern: <br>\n";
         echo "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"POST\" >";
         //echo "<form action=\"./schichtplan.php\" method=\"POST\">\n";
         echo "<table>\n";
         echo "  <tr><td>Schichtbeginn</td><td><input value=\"".mysql_result($Erg, 0, "Date")."\" type=\"text\" size=\"40\" name=\"eDate\"></td></tr>\n";
	 echo "  <tr><td>Raum</td><td>\n";
	 echo "  <select name=\"eRID\">\n";

	 $sql2 = "select * from Raeume";
         $Erg2 = mysql_query($sql2, $con);
	 $rowcount = mysql_num_rows($Erg2);
	 for ($i=0; $i<$rowcount; $i++){
	  $RID=mysql_result($Erg2, $i, "RID");
	  echo "   <option value=\"".$RID."\"";
	  if ($RID == mysql_result($Erg, 0, "RID")) {
	  	echo " selected";
	  }
	  echo ">".mysql_result($Erg2, $i, "Name")."</option>\n";
	 }
	 echo "  </select>\n";
//	 <input value=\"".mysql_result($Erg, 0, "RID")."\" type=\"text\" size=\"40\" name=\"eRID\">
	 echo "  </td></tr>\n";
	 echo "  <tr><td>Dauer in h</td><td><input value=\"".mysql_result($Erg, 0, "Dauer")."\" type=\"text\" size=\"40\" name=\"eDauer\"></td></tr>\n";
	 echo "  <tr><td>Beschreibung</td><td><input value=\"".mysql_result($Erg, 0, "Name")."\" type=\"text\" size=\"40\" name=\"eName\"></td></tr>\n";
         echo "</table>\n";
         echo "<input type=\"hidden\" name=\"SID\" value=\"$SID\">\n";
         echo "<input type=\"hidden\" name=\"action\" value=\"changesave\">\n";
         echo "<input type=\"submit\" value=\"sichern...\">\n";
         echo "</form>";
         echo "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"POST\" >\n";
         //echo "<form action=\"./schichtplan.php\" method=\"POST\">\n";
         echo "<input type=\"hidden\" name=\"SID\" value=\"$SID\">\n";
         echo "<input type=\"hidden\" name=\"action\" value=\"delete\">\n";
         echo "<input type=\"submit\" value=\"L&ouml;schen...\">";
         echo "</form>";

	 $sql3 = "select * from Schichtbelegung where SID=$SID";
	 $Erg3 = mysql_query($sql3, $con);
	 $rowcount = mysql_num_rows($Erg3);
	 if ($rowcount > 0) {
		echo "<b>ACHTUNG:</b> Es haben sich bereits Engel f&uuml;r diese Schicht eingetragen!<br>\n";
		echo "Beim L&ouml;schen werden die bisher eingetragenen Engel f&uuml;r diese Schicht mitgel&ouml;scht.<br>\n";
         }

	if ($rowcount > 0) {
		echo "<hr>";
		echo "Ausserdem kannst du hier Engel aus der Schicht austragen, wenn diese nicht zu Schicht erschienen sind:<br>";
		for ($j=0; $j < $rowcount; $j++) {
			$userUID=mysql_result($Erg3, $j, "UID");
			echo "<a href=\"./schichtplan.php?action=engeldel&SID=$SID&eUID=$userUID\">".UID2Nick($userUID)." austragen</a><br>";

		}
	}
		echo "<hr>";
		echo "Hat ein anderer Engel die Schicht &uuml;bernommen, trage ihn hier bitte ein:";
                echo "<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"POST\" >\n";
		echo "<input type=\"hidden\" name=\"SID\" value=\"$SID\">\n";
         	echo "<input type=\"hidden\" name=\"action\" value=\"engeladd\">\n";
	 	echo "<select name=\"eUID\">\n";
		$usql="select * from User order by Nick";
		$uErg = mysql_query($usql, $con);
		$urowcount = mysql_num_rows($uErg);
		for ($k=0; $k<$urowcount; $k++){
			echo "\t<option value=\"".mysql_result($uErg, $k, "UID")."\">".mysql_result($uErg, $k, "Nick")."</option>\n";
		}
		echo "</select>\n";
		echo " als \n";
		echo "<select name=\"Art\">\n";
		$SQL2 = "SELECT * FROM `Raeume` WHERE ";
		$SQL2.= "(RID = '".mysql_result($Erg,0,"RID")."')";
		$Erg2 = mysql_query($SQL2, $con);
	        for ($l = 2; $l < mysql_num_fields($Erg2); $l++) {
		  if (mysql_result($Erg2, 0, $l) > 0)
		    echo "<option value=$l>".mysql_field_name($Erg2,$l)."engel".
 		         "</option>\n";
	        }
     		echo "</select>\n";
		echo "<input type=\"submit\" value=\"eintragen...\">\n";
		echo "</form>";


	}
	break;

case 'engeladd':
	$chSQL="insert into Schichtbelegung values ('$SID', '$eUID', 'Schicht eingetragen durch Erzengel ".$_SESSION['Nick']."', '$Art')";
	echo "Es wird folgende Schicht zus&auml;tzlich eingetragen:<br>\n";
	echo "Engel: ".UID2Nick($eUID)."<br>\n";
	echo "Bemerkung: Schicht eingetragen durch Erzengel ".$_SESSION['Nick']."<br>\n";

	break;

case 'engeldel':
	$chSQL="delete from Schichtbelegung where SID='$SID' and UID='$eUID' LIMIT 1";
	break;

case 'changesave':
	$chSQL="update Schichtplan set Date = '$eDate', RID = '$eRID', Dauer='$eDauer', Name='$eName', ";
	$query = mysql_query("SELECT DATE_ADD('".$eDate."', INTERVAL '+0 ".$eDauer."' DAY_HOUR)", $con);
	$enddate = mysql_fetch_row($query);
	$chSQL .= " EndDate = '".$enddate[0]."' where SID=$SID";
	break;
case 'delete':
	$chSQL="delete from Schichtplan where SID=$SID limit 1";
	$ch2SQL="delete from Schichtbelegung where SID=$SID";
	break;

} // end switch

// Update ???

if (IsSet($chSQL)){
//     echo $chSQL;
     // hier muesste das SQL ausgefuehrt werden...
     $Erg = mysql_query($chSQL, $con);
     if ($Erg == 1) {
       echo "&Auml;nderung wurde gesichert...";
	if (IsSet($ch2SQL)){
		$Erg = mysql_query($ch2SQL, $con);
	}
     } else {
       echo "Fehler beim speichern... bitte noch ein mal probieren :)";
}
} // Ende Update

}



function CreateNewEntry() {
  global $con, $_DateS, $_DateE, $RID, $len, $SchichtName, $OnlyShow, $DEBUG;
  
  echo "<tr>\n";
  
  echo "\t<td>$_DateS</td>\n";
  echo "\t<td>$_DateE</td>\n";
  echo "\t<td>$RID</td>\n";
  echo "\t<td>$len</td\n>";
  echo "\t<td>$SchichtName</td>\n";
	    
  if( $OnlyShow == "" ) 
  {
  	$SQL  = "INSERT INTO `Schichtplan` (`Date`, `EndDate`, `RID`, `Dauer`, `Name`) VALUES (";
	$SQL .= "'". $_DateS. "', '". $_DateE. "', ";
	$SQL .= "'". $RID. "', '". $len. "', ";
	$SQL .= "'". $SchichtName. "');";
	$Erg = mysql_query($SQL, $con);
	
	if( $DEBUG ) $SQLFail = "\n\t<br>[".$SQL. "]";
       	
	if ($Erg == 1) echo "\t<td>pass</td>\n";
	else           echo "\t<td>fail <br>\n<u>". mysql_error($con). "</u>$SQLFail</td>\n";
	
  } else
   	echo "\t<td>only show</td>\n";

  echo "</tr>\n";
}

include ("./inc/footer.php");
?>