summaryrefslogtreecommitdiff
path: root/www-ssl/admin/shiftadd.php
blob: 83022668db3f8700be142798da2628bfb8b639ac (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
<?php
$title = "Schicht Hinzuf�gen";
$header = "Neue Schichten erfassen";

include ("./inc/header.php");
include ("./inc/funktion_user.php");

$Time = time()+3600+3600;

echo "Hallo ".$_SESSION['Nick'].",<br>\n";

// erstellt ein Array der Reume
	$sql = "SELECT `RID`, `Name` FROM `Room` ORDER BY `Name`";
	$Erg = mysql_query($sql, $con);
	$rowcount = mysql_num_rows($Erg);

	for ($i=0; $i<$rowcount; $i++) 
	{
		$Room[$i]["RID"]  = mysql_result($Erg, $i, "RID");
		$Room[$i]["Name"] = mysql_result($Erg, $i, "Name");
	}

// erstellt ein Aray der Engeltypen
	$sql = "SELECT `TID`, `Name` FROM `EngelType` ORDER BY `Name`";
	$Erg = mysql_query($sql, $con);
	$rowcount = mysql_num_rows($Erg);

	for ($i=0; $i<$rowcount; $i++) 
	{
		$EngelType[$i]["TID"]  = mysql_result($Erg, $i, "TID");
		$EngelType[$i]["Name"] = mysql_result($Erg, $i, "Name").Get_Text("inc_schicht_engel");
	}

// sesion mit stanadrt werten bef�llen
if( !isset( $_SESSION['shiftadd.php']['SchichtName']))
{
	$_SESSION['shiftadd.php']['SchichtName'] = "--???--";
	$_SESSION['shiftadd.php']['RID'] = "";
	$_SESSION['shiftadd.php']['MonthJahr'] = gmdate("Y-m", $Time);
	$_SESSION['shiftadd.php']['SDatum'] = gmdate("d", $Time);
	$_SESSION['shiftadd.php']['STime'] = "10";
	$_SESSION['shiftadd.php']['MoreThenOne'] = "ON";
	$_SESSION['shiftadd.php']['EDatum'] = gmdate("d", $Time);
	$_SESSION['shiftadd.php']['ETime'] = "12";
	$_SESSION['shiftadd.php']['len'] = "2";
	$_SESSION['shiftadd.php']['NachtON'] = "OFF";
	$_SESSION['shiftadd.php']['len_night'] = "0;4;8;10;12;14;16;18;20;22;24";
}
// wenn werte �bergeben in sesion eintragen
if( !isset($_GET["NachtON"]))
	$_GET["NachtON"] = "OFF";
if( !isset($_GET["MoreThenOne"]))
	$_GET["MoreThenOne"] = "OFF";
if( isset( $_GET["SchichtName"]))
{
	foreach ($_GET as $k => $v)
	{
		$_SESSION['shiftadd.php'][$k] = $v;
	}
}


if (!IsSet($_GET["action"])) 
	$_GET["action"] = "new";

switch( $_GET["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="<?PHP echo $_SERVER['SCRIPT_NAME']; ?>" >
  <table>
  <tr>
    <td align="right">Name:</td>
    <td><input type="text" name="SchichtName" size="50" value="<?PHP echo $_SESSION["shiftadd.php"]["SchichtName"]; ?>"></td>
  </tr>
  <tr>
    <td align="right">Ort:</td>
    <td><select name="RID">
<?PHP
	foreach ($Room As $RTemp)
	{
		echo "\t<option value=\"". $RTemp["RID"]. "\"";
		if( $RTemp["RID"] == $_SESSION["shiftadd.php"]["RID"])
			echo " SELECTED";
		echo ">". $RTemp["Name"]. "</option>\n";
	}
	?>
    </select></td>
  </tr>
  
  <tr><td><u>Zeit:</u></td></tr>
  <tr>
    <td align="right">Month.Jahr:</td>
    <td><input type="ext" name="MonthJahr" size="7" value="<?PHP echo $_SESSION["shiftadd.php"]["MonthJahr"]; ?>"></td>
  </tr>
  <tr>
    <td align="right">Beginn:</td>
    <td>Date<input type="text" name="SDatum" size="5" value="<?PHP echo $_SESSION["shiftadd.php"]["SDatum"]; ?>">
        Time<input type="text" name="STime" size="5" value="<?PHP echo $_SESSION["shiftadd.php"]["STime"]; ?>"></td>
  </tr>
  <tr>
    <td align="right">More then One</td>
    <td><input type="checkbox" name="MoreThenOne" value="ON" <?PHP 
   	if( $_SESSION["shiftadd.php"]["MoreThenOne"]=="ON")
		echo " CHECKED";
	?>></td>
  </tr>
  <tr>
    <td align="right">End:</td>
    <td>Date<input type="text" name="EDatum" size="5" value="<?PHP echo $_SESSION["shiftadd.php"]["EDatum"]; ?>">
        Time<input type="text" name="ETime" size="5" value="<?PHP echo $_SESSION["shiftadd.php"]["ETime"]; ?>"></td>
  </tr>
  <tr>
    <td align="right">L&auml;nge in h:</td>
    <td><input type="text" name="len" size="5" value="<?PHP echo $_SESSION["shiftadd.php"]["len"]; ?>"></td>
  </tr>
  <tr>
    <td align="right">Sonderschichten ein:</td>
    <td><input type="checkbox" name="NachtON" value="ON" <?PHP 
    	if($_SESSION["shiftadd.php"]["NachtON"]=="ON")
		echo " CHECKED";
	?>></td>
  </tr>
  <tr>
    <td align="right">Sonder in h (Time;Time):</td>
    <td><input type="text" name="len_night" size="50" value="<?PHP echo $_SESSION["shiftadd.php"]["len_night"]; ?>"></td>
  </tr>
  
  <tr><td><u>Anzahl Engel je Type:</u></td></tr>
<?PHP
	foreach ($EngelType As $TTemp)
	{
		echo "  <tr><td align=\"right\">". $TTemp["Name"]. ":</td>\n";
		echo "      <td><input type=\"text\" name=\"EngelType". $TTemp["TID"]. "\" size=\"5\" value=\"";
		if( isset($_SESSION["shiftadd.php"][ "EngelType". $TTemp["TID"] ]))
			echo $_SESSION["shiftadd.php"][ "EngelType". $TTemp["TID"] ];
		else
			echo "0";
		echo "\"></td>\n";
	}
?>
</table>
 <br>
<input type="hidden" name="OnlyShow" value="ON">
<input type="hidden" name="action" value="newsave">
<input type="submit" value="zeig mal Gabriel!">
</form>

<?PHP
	break; // Ende new

case 'newsave':
    if (isset($_GET["SDatum"]) && ($_GET["len"] > 0))
    {
	$lenOrg = $_GET["len"];
	if( $_GET["NachtON"] == "ON" )
	{	
		$lenArrayDummy = explode( ";", $_GET["len_night"]);
                foreach ( $lenArrayDummy as $Temp )
                {
			if( isset($Temp2) )
			{
				$lenArray[$Temp2] = $Temp-$Temp2;
			}
			$Temp2 = $Temp;
			
        	}//foreach
	}//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\">len</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">RID</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">Beschreibung</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">Entry 'Shifts'</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">SID</td>\n";
	echo "\t<td valign=\"top\" align=\"center\">Entrys</td>\n";
	echo "</tr>\n";
 	
	$DateEnd = $_GET["SDatum"];
 	$TimeEnd = $_GET["STime"];
	$len=0;
	do
	{	
		// define Start time
		$Date = $DateEnd;
		$Time = $TimeEnd;
		$_DateS = $_GET["MonthJahr"]. "-". $Date. " ". $Time. ":00:00";
			
		// define End time
	 	if( $_GET["NachtON"] == "ON" )
		{
			$_GET["len"] = $lenArray[$Time];
		}
		$TimeEnd = $Time+ $_GET["len"];
		
		//Tages�berschreitung
		while( $TimeEnd >= 24 )
		{
			$TimeEnd -= 24;
			$DateEnd += 1;
		}
		//ist schischt zu lang dan verk�rzen
		if( $DateEnd > $_GET["EDatum"] || ($DateEnd == $_GET["EDatum"] && $TimeEnd >= $_GET["ETime"]) ) 
		{
			$_GET["len"] -= ($DateEnd- $_GET["EDatum"])*24; 
			$_GET["len"] -= ($TimeEnd- $_GET["ETime"]);		// -(-) ->> +
			$DateEnd = $_GET["EDatum"];
			$TimeEnd = $_GET["ETime"];
		}
		$_DateE = $_GET["MonthJahr"]. "-". $DateEnd. " ". $TimeEnd. ":00:00";

		if( $_DateS != $_DateE )
			CreateNewEntry();
		
		if( $_GET["MoreThenOne"]!="ON" ) break;
		if( $DateEnd == $_GET["EDatum"] && $TimeEnd >= $_GET["ETime"] ) break;
	} while( true );
	echo "</table>";
	
	if( $_GET["OnlyShow"]=="ON" ) 
	{
		echo "<form action=\"". $_SERVER['SCRIPT_NAME']. "\">";
		echo "\n\t<Input type=\"hidden\" name=\"SchichtName\" value=\"". $_GET["SchichtName"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"MonthJahr\" value=\"". $_GET["MonthJahr"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"SDatum\" value=\"". $_GET["SDatum"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"STime\" value=\"". $_GET["STime"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"MoreThenOne\" value=\"". $_GET["MoreThenOne"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"EDatum\" value=\"". $_GET["EDatum"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"ETime\" value=\"". $_GET["ETime"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"len\" value=\"". $lenOrg. "\">";
		echo "\n\t<input type=\"hidden\" name=\"RID\" value=\"". $_GET["RID"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"NachtON\" value=\"". $_GET["NachtON"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"len_night\" value=\"". $_GET["len_night"]. "\">";
		echo "\n\t<input type=\"hidden\" name=\"OnlyShow\" value=\"OFF\">";
		foreach ($EngelType As $TTemp)
		{
			$Temp = "EngelType".$TTemp["TID"];
			echo "\n\t<input type=\"hidden\" name=\"". $Temp. "\" value=\"". $_GET[$Temp]. "\">";
		}	
		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 'engeldel':
	break;

} // end switch



function CreateNewEntry() 
{
	global $con, $_DateS, $_DateE, $EngelType, $DEBUG;
	foreach ($EngelType As $TTemp)
	{
		$Temp = "EngelType".$TTemp["TID"];
		global $$Temp;
	}	

	echo "<tr>\n";

	echo "\t<td>$_DateS</td>\n";
	echo "\t<td>$_DateE</td>\n";
	echo "\t<td>". $_GET["len"]. "</td>\n";
	echo "\t<td>". $_GET["RID"]. "</td>\n";
	echo "\t<td>". $_GET["SchichtName"]. "</td>\n";
	
	
	// Ist eintarg schon vorhanden?	
	$SQL  = "SELECT SID FROM `Shifts` ";
	$SQL .=	"WHERE (".
		"`DateS` = '". $_DateS. "' AND ".
		"`DateE` = '". $_DateE. "' AND ".
		"`RID` = '". $_GET["RID"]. "');";
	$Erg = mysql_query($SQL, $con);
	
	if( mysql_num_rows($Erg) != 0 )
		echo "\t<td>exists</td>";
	elseif( $_GET["OnlyShow"] == "OFF" )   
	{
		// erstellt Eintrag in Shifts f�r die algemeine schicht
		$SQL  = "INSERT INTO `Shifts` ( `DateS`, `DateE`, `Len`, `RID`, `Man`) VALUES ( ";
		$SQL .= "'". $_DateS. "', '". $_DateE. "', ";
		$SQL .= "'". $_GET["len"]. "', '". $_GET["RID"]. "', ";
		$SQL .= "'". $_GET["SchichtName"]. "');";
		$Erg = mysql_query($SQL, $con);

		$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";
		
	// sucht SID von eingetragennen schiten
	$SQL  = "SELECT SID FROM `Shifts` ";
	$SQL .=	"WHERE (".
		"`DateS` = '". $_DateS. "' AND ".
		"`DateE` = '". $_DateE. "' AND ".
		"`Len` = '". $_GET["len"]. "' AND ".
		"`RID` = '". $_GET["RID"]. "');";
	$Erg = mysql_query($SQL, $con);
	if( mysql_num_rows($Erg) == 0 )
		echo "\t<td>?</td>";
	else	
	{
		$SID = mysql_result($Erg, 0, "SID");
		echo "\t<td>". $SID. "</td>";
	}

	// erstellt f�r jeden Engeltypen die eintrage in 'ShiftEntry'
	echo "\t<td>";
	foreach ($EngelType As $TTemp)
	{
		$Temp = "EngelType".$TTemp["TID"];
		
		if( $_GET[$Temp] > 0 )
		{
			$i = 0;
			echo $_GET[$Temp]. " ".$TTemp["Name"]. "<br>\t";
			while( $i++ < $_GET[$Temp] )
			{
				if( $_GET["OnlyShow"] == "OFF" )
				{
					$SQL  = "INSERT INTO `ShiftEntry` (`SID`, `TID`) VALUES (";
					$SQL .= "'". $SID. "', ";
					$SQL .= "'". $TTemp["TID"]. "');";

					$Erg = mysql_query($SQL, $con);

					if( $DEBUG ) $SQLFail = "\n\t<br>[".$SQL. "]";

					if ($Erg == 1) echo "'pass' ";
					else           echo "'fail' <u>". mysql_error($con). "</u>$SQLFail</td>\n";

				}
				else
					echo "+";
			}
			echo "<br>";
		} // IF $$TEMP
	} // FOREACH
	echo "</td>";
	
	echo "</tr>\n";
}

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