Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
timerec3public/transponder.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
131 lines (126 sloc)
5.69 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>timerec</title> | |
<link rel="stylesheet" type="text/css" href="style.css"> | |
<link rel="shortcut icon" href="favicon.ico"> | |
</head> | |
<body> | |
<?php | |
session_start(); | |
if(!$_SESSION['userid']){ | |
session_destroy(); | |
include('login.php'); | |
exit; | |
} | |
include('dbconnect.php'); | |
if(!$_SESSION['userarray']['admin']){ | |
echo "<h3>keine Rechte, diese Seite einzusehen!</h3>"; | |
exit; | |
} | |
if(!empty($_POST)){ | |
//update | |
$fail = false; | |
$dbc->query("start transaction;"); | |
foreach($_POST as $id=>$post){ | |
$id = substr($id, 0, -1); //unterstrich entfernen | |
if(!$fail && ($id != "neu" && $id != "del")){ | |
$update = "update transponder set rfid = '$post[rfid]', name = '$post[name]', maID = '$post[maID]' where rfid = '$id';"; | |
$update = str_replace("''", "NULL", $update); //leere einträge mit NULL füllen statt mit '' | |
//echo $update."<br>"; | |
$dbc->query($update); | |
if($dbc->error){ | |
$fail = "UPDATE ERROR: ".$dbc->error; | |
} | |
} | |
if(!$fail && ($id == "neu" && !empty($post['rfid']))){ | |
$insert = "insert into transponder (rfid, name, maID) values ('$post[rfid]', '$post[name]', '$post[maID]');"; | |
$insert = str_replace("''", "NULL", $insert); //leere einträge mit NULL füllen statt mit '' | |
//echo $insert."<br>"; | |
$dbc->query($insert); | |
if($dbc->error){ | |
$fail = "INSERT ERRROR: ".$dbc->error; | |
} | |
} | |
if(!$fail && $id == "del"){ | |
$delete = "delete from transponder where rfid in ("; | |
foreach($post as $delitem){ | |
$delete .= "'$delitem', "; | |
} | |
$delete = substr($delete, 0, -2); | |
$delete .= ");"; | |
//echo $delete."<br>"; | |
$dbc->query($delete); | |
if($dbc->error){ | |
$fail = "DELETE ERROR: ".$dbc->error; | |
} | |
} | |
} | |
if($fail){ | |
$dbc->query("rollback;"); | |
echo $fail; | |
}else{ | |
$dbc->query("commit;"); | |
header('Location: transponder.php?success=true'); | |
} | |
} | |
echo "<div id='headline'> | |
<div id='home'> | |
<a href='index.php?ma=".$infoarray['maID']."'><button><< Menü</button></a> | |
</div> | |
<div id='back'><a href='transponder.php'><button>Abbrechen</button></a></div> | |
<b>Transponder</b> | |
<div id='forward'><button type='submit' form='azmodell' onclick='return confirm(\"Sicher?\")'>Speichern</button></div> | |
<div class='scroll down' onclick='window.scrollTo(0,document.documentElement.scrollHeight)'>runter ↓</div> | |
<div class='scroll up' onclick='window.scrollTo(0,0)'>↑ rauf</div> | |
</div>"; | |
echo "<form id='azmodell' style='width: 50%; margin-left: -25%;' method='post' action=''>"; | |
if($_GET['success'] === 'true') echo "<h3 class='light-green'>SUCCESS!</h3>"; | |
echo "<b>Tabelle ist editierbar!</b> // Suchen per Strg+F | |
<table> | |
<tr> | |
<th>RFID</th> | |
<th>Beschriftung</th> | |
<th>Zuweisung</th> | |
<td class='help centered red' title='zum Löschen Haken setzen'>X</td> | |
</tr>"; | |
$getchip = $dbc->query("select * from transponder order by name;"); | |
$allma = $dbc->query("select maID, concat(nachname, ', ', vorname) as name from mitarbeiter order by nachname, vorname;"); | |
$switch = true; | |
foreach($getchip as $chip){ | |
if($switch){ | |
$color = "line1"; | |
}else{ | |
$color = "line2"; | |
} | |
$switch = !$switch; | |
$key = $chip['rfid']; | |
echo "<tr class='$color'>"; | |
echo "<td><input type='text' maxlength='20' name='$key [rfid]' value='$chip[rfid]'></td>"; | |
echo "<td><input type='text' maxlength='50' name='$key [name]' value='$chip[name]'></td>"; | |
echo "<td><select class='auswahl' size='1' onmousedown='this.size=10' onblur='this.size=1' name='$key [maID]'> | |
<option value=''> - </option>"; | |
foreach($allma as $ma){ | |
$ma['maID'] == $chip['maID'] ? $selected = 'selected' : $selected = ''; | |
echo "<option $selected value='$ma[maID]'>$ma[name]</option>"; | |
} | |
echo "</select></td>"; | |
echo "<td class='centered'><input id='deletebox$key' type='checkbox' onclick='if(this.checked) alert(\"Dies LÖSCHT den Eintrag!\")' class='checkbox' name='del []' value='$key'><label for='deletebox$key'></label></td>"; | |
echo "</tr>"; | |
} | |
echo "<tr class='topline'><td colspan='10'></td></tr> | |
<tr> | |
<td><input type='text' maxlength='20' name='neu [rfid]' value='' placeholder='neu'></td> | |
<td><input type='text' name='neu [name]' placeholder='name...'></div></td> | |
<td><select class='auswahl' size='1' onmousedown='this.size=10' onblur='this.size=1' name='neu [maID]'> | |
<option value=''> - </option>"; | |
foreach($allma as $ma){ | |
echo "<option value='$ma[maID]'>$ma[name]</option>"; | |
} | |
echo "</select></td>"; | |
echo "</table> | |
</form>"; | |
?> | |
</body> | |
</html> |