bpm/upload/#upload.php
2023-04-25 13:16:13 +02:00

955 lines
50 KiB
PHP
Executable File

<?php
require_once("../../config.inc.php");
require_once("../func_rollenrechte.php");
require_once "func_genUser_schueler.php";
require_once('../excel/Classes/PHPExcel/IOFactory.php');
#########Konfiguration#######################################
$verz = "upload/"; // relatives Uploadverzeichnis (relativ zum 'Standort' dieser Datei, wohin die Dateien kopiert werden sollen
$trennzeichen_excel = ";"; // Das Trennzeichen das Excel f&uuml;r CVS-Dateien nimmt ist je nach Excelversion unterschiedlich:
// Entweder $trennzeichen_excel = ";"; --> Semikolon
// oder $trennzeichen_excel = ","; --> Komma
#############################################################
############
##
## 13.09.2011: Änderung des Passwortformats von dd.mm.jjjj auf ddmmjjjj weil auf der Loginseite das so angegeben ist.
##
############
setcookie("ck_verz", "$verz"); // Verzeichnis in Cookie speichern
// Rechteüberprüfung
#$db = dbconnect();
if ($user_admin == "") {
require("index.php");
exit;
} //Wenn man nicht angemeldet ist, darf man nicht auf die Seite
if (!rore($user_admin, 'a_import', 'RE')) {
echo "Keine Rechte";
exit;
}
// Rechteüberprüfung ende
if (isset($_GET['action']))
$action = $_GET['action'];
else
$action = "";
switch ($action) {
default:
$heute = mktime(0, 0, 0, date("m"), date("d"), date("Y")); // heutiges Datum
$heute_format = date("Y-m-d", $heute); // ISO-8601 Format wie in der Datenbank: Formatierung f&uuml;r Vergleiche erforderlich
function deleteFiles($verz)
{
$handle = opendir($verz);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
$datei = $verz . $file;
if (@unlink($datei)) {
$error = TRUE;
} else {
$error = FALSE;
}
}
}
closedir($handle);
return $error;
}
deleteFiles($verz); // Dateien werden im Uploadverzeichnis gel&ouml;scht, falls noch welche darin w&auml;ren
echo "
<html>
<!DOCTYPE html>
<html lang=\"en\" class=\"no-js\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<title>Excel Upload</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"css/component.css\" />
<!--[if IE]>
<script src=\"https://html5shiv.googlecode.com/svn/trunk/html5.js\"></script>
<![endif]-->
<!-- remove this if you use Modernizr -->
<script>(function(e,t,n){var r=e.querySelectorAll(\"html\")[0];r.className=r.className.replace(/(^|\s)no-js(\s|$)/,\"$1js$2\")})(document,window,0);</script>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" allign=\"center\" width=\"60%\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<font class=\"hd\">Excel Upload</font><br>
<span class=\"sh\">Import eines Studienjahrgangs.</span><br>
<span class=\"sh\"><b>Erlaubte Dateiendungen: *.xls; *.xlsx</b></span>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></font></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td>
<form action='" . $_SERVER['PHP_SELF'] . "?action=csvimp" . "' enctype=\"multipart/form-data\" method='post'>
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" >
<tr>
<td width=\"100%\"align=\"center\" >
<br>
<br>
<div class=\"box\">
<input type=\"file\" name=\"file\" id=\"file-5\" class=\"inputfile inputfile-4\" />
<label for=\"file-5\"><figure><svg xmlns=\"https://www.w3.org/2000/svg\" width=\"20\" height=\"17\" viewBox=\"0 0 20 17\"><path d=\"M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z\"/></svg></figure> <span style='float:center;'>Excel-Datei ausw&auml;hlen&hellip;<br>(hier klicken)</span></label>
</div>
<script src=\"js/custom-file-input.js\"></script>
<br>
</td>
</tr>
<tr>
<td width=\"100%\" align=\"center\" colspan=\"2\">
<input type=\"submit\" value=\"Excel-Hochladen&hellip;\" name=\"B1\" size=\"20\">
</td>
</tr>
<tr>
<td width=\"100%\" align=\"center\" colspan=\"2\">
&nbsp;
</td>
</tr>
<tr>
<td width=\"100%\" align=\"center\" colspan=\"2\">
&nbsp;
</td>
</tr>
<tr>
<td width=\"100%\" align=\"center\" colspan=\"2\">
<a href='Schülerimport_Beispiele.xlsx' target='_new'>Musterdatei downloaden</a>
</td>
</tr>
</table>
</form>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\">
</td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
break;
case "csvimp":
// https://www.tutorials.de/tutorials65420.html
$tempname = $_FILES['file']['tmp_name'];
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$size = $_FILES['file']['size'];
$einheit = "Byte"; // F&uuml;r die Efolgsmeldung.
$limitedext = array(
".xls",
".xlsx"
); //Erlaubte Dateieindung beim Upload
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded
$ext = strrchr($name, '.');
if (($extlimit == "yes") && (!in_array($ext, $limitedext))) {
$err[] = "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Falscher Dateityp</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<span class=\"sh\">Falscher Dateityp</span>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></font></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td>
<br>
<p align=\"center\">Es d&uuml;rfen nur Excel-Dateien hochgeladen werden!
<p>
<p align=\"center\"><p align=\"center\"><a href=\"?\">
<img border=\"0\" src=\"../../templates/standard/images/zurueck.gif\" width=\"77\" height=\"22\"></a>
</p>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\">
</td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
}
if ($size > "9900000") {
$err[] = "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Datei zu gro&szlig;</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<span class=\"sh\">Datei zu gro&szlig;</span>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></font></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td>
<br>
<p align=\"center\">Die Datei welche Sie hochladen wollen, ist zu gross!<br>Maximale Dateigroesse betr&auml;gt 9.900 KB!
<p>
<p align=\"center\"><p align=\"center\"><a href=\"javascript:history.back()\">
<img border=\"0\" src=\"../../templates/standard/images/zurueck.gif\" width=\"77\" height=\"22\"></a>
</p>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\">
</td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
}
$name = str_replace(array(
"ä",
"ö",
"ü",
"ß",
"Ä",
"Ü",
"Ü",
" "
), array(
"ae",
"oe",
"ue",
"ss",
"Ae",
"Oe",
"Ue",
"_"
), $name);
$heute = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")); // heutiges Datum & Zeit: https://de2.php.net/manual/de/function.date.php
$heuteformat = date("H-i-s_Y-m-d", $heute); // Formatierung, wie es vor dem Dateinamen erscheinen soll
$datum_db = date("Y-m-d H:i:s", $heute); // Formatierung, wie es vor dem Dateinamen erscheinen soll
$neu = $heuteformat . "_" . $name;
setcookie("ck_neu", "$neu");
If (empty($err)) {
move_uploaded_file("$tempname", "$verz$neu"); // Unterverzeichnisse wie folgt: copy("$tempname", "pdf/$neu");
$inputFileName = "$verz$neu";
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheet = $objPHPExcel->getActiveSheet()->toArray(null, true, false, true);
$highestColumm = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
$highestRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
# Ab dem Tag rechnet Excel intern
$datum = '30.12.1899';
echo "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Datens&auml;tze pr&uuml;fen</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width='100%' cellpadding=\"0\" height=\"90%\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width='100%'>
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<font class=\"hd\">Datens&auml;tze pr&uuml;fen</font><br>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td>
<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\" width='100%'>
<tr>
<td width=\"30%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Vorname</font></b>
</td>
<td width=\"30%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Nachname</font></b>
</td>
<td width=\"10%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Religionspflichtig</font></b>
</td>
<td width=\"10%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Einschulungsjahr</font></b>
</td>
<td width=\"10%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Klassenzusatz</font></b>
</td>
<td width=\"20%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Geburtsdatum</font></b>
</td>
</tr>";
for ($i = 1; $i <= $highestRow; $i++) {
$vorname = $sheet[$i]['A'];
$nachname = $sheet[$i]['B'];
$rel = $sheet[$i]['C'];
$eingangsjahr = $sheet[$i]['D'];
$klassenzusatz = $sheet[$i]['E'];
$gebdat = date('m.d.Y', strtotime($sheet[$i]['F']));
# $gebdat = date("d.m.Y", $sheet[$i]['F']);
$gebdatx = $sheet[$i]['F'];
# $gebdat = date('d.m.Y', strtotime($datum . ' + ' . $gebdatx . ' days'));
$gebdat = substr($gebdatx,0,2).".".substr($gebdatx,3,2).".".substr($gebdatx,6,4);
# $gebdat2 = date('Y-m-d', strtotime($datum . ' + ' . $gebdatx . ' days'));
$gebdat2 = substr($gebdatx,6,4)."-".substr($gebdatx,3,2)."-".substr($gebdatx,0,2);
if ($nachname != '') {
print "<tr>";
// for ($c=0; $c < $num; $c++) { // FOR-Schleife: Oder Anzahl der zu importierenden Felder ($num)
print "<td width='30%'><font size=\"1\">$vorname</td>\n"; // Vorname
print "<td width='30%'><font size=\"1\">$nachname</td>\n"; // Nachname
print "<td width='10%'><font size=\"1\">$rel</td>\n"; // religionskenner
print "<td width='10%'><font size=\"1\">$eingangsjahr</td>\n"; // Einschulungsjahr
print "<td width='10%'><font size=\"1\">$klassenzusatz</td>\n"; // klassenzusatz A,B..; Ergibt dann Klasse 6A z.B.
print "<td width='30%'><font size=\"1\">$gebdat</td>\n"; // Geburtsdatum/Passwort
// }
print "</tr>";
$ln_inserts[]++; //z&auml;hlt die Anzahl der importierenden DS
}
}
echo "
</table>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\">
</td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
</table>
<br>";
$zahl = count($ln_inserts);
echo "
<table border=\"0\" style=\"border-collapse: collapse\" width='40%' cellpadding=\"0\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<font class=\"hd\">Sollen die $zahl Datens&auml;tze importiert werden?</font><br>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\">
</td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td>
<form action='" . $_SERVER['PHP_SELF'] . "?action=csvimp2" . "' enctype=\"multipart/form-data\" method='post'>
<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#E7E8ED\">
<tr>
<td width=\"70%\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Auswahl</font></b>
</td>
<td width=\"30%\" align=\"left\" style=\"border-left-style: none; border-left-width: medium; border-right-style: none; border-right-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px\">
<b><font size=\"1\">Markieren</font></b>
</td>
</tr>
<tr>
<td width=\"70%\"><font size=\"1\">Datens&auml;tze nicht importieren
</td>
<td width=\"30%\"><font size=\"1\"><input type=\"radio\" name=\"import\" value=\"0\" checked>
</td>
</tr>
<tr>
<td width=\"70%\"><font size=\"1\">Datens&auml;tze importieren
</td>
<td width=\"30%\"><font size=\"1\"><input type=\"radio\" name=\"import\" value=\"1\">
</td>
</tr>
<tr>
<td width=\"70%\">
&nbsp;
</td>
<td width=\"30%\">
&nbsp;
</td>
</tr>
<tr>
<td width=\"70%\">
&nbsp;
</td width=\"30%\">
<td>
<input type=\"submit\" value=\"Abschicken\" name=\"B1\" size=\"20\">
</td>
</tr>
</table>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\">
</td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\">
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>
";
} else {
foreach ($err as $error)
echo "$error";
exit;
} //Ende if error
break;
case "csvimp2":
$neu = $_COOKIE["ck_neu"]; //Excel-Dateinamen um Datei l&ouml;schen zu k&ouml;nnen
$verz = $_COOKIE["ck_verz"]; //Uploadverzeichnis aus Cookie holen
if ($_POST['import'] == "0") // DS sollen nicht importiert werden
{
$dateiname = "$verz$neu";
if (@unlink($dateiname)) // Funktion l&ouml;scht Dateien und gibt true / false zur&uuml;ck
{
echo "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Import beendet</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\"></td>
<td width=\"95%\" background=\"../../templates/standard/images/box_top.gif\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<span class=\"sh\">Importvorgang abgebrochen</span><br>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td colspan=\"2\"><br>
<p align=\"center\">Datems&auml;tze wurden nicht importiert!<br>Die Excel-Datei wurde vom Server gel&ouml;scht!
</p>
<p align=\"center\"><a href=\"../hauptframe.php\">
<img border=\"0\" src=\"../../templates/standard/images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p><br>
</p>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\" colspan=\"2\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
} else {
echo "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Datei nicht gel&ouml;scht</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\"></td>
<td width=\"95%\" background=\"../../templates/standard/images/box_top.gif\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<span class=\"sh\">Importvorgang abgebrochen</span><br>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td colspan=\"2\"><br>
<p align=\"center\">Datems&auml;tze wurden nicht importiert!<br>Die Excel-Datei ($neu) konnte <b>nicht</b> vom Server gel&ouml;scht werden!
</p>
<p align=\"center\"><a href=\"../hauptframe.php\">
<img border=\"0\" src=\"../../templates/standard/images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p><br>
</p>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\" colspan=\"2\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
} // End if
} elseif ($_POST['import'] == "1") // DS sollen importiert werden
{
$inputFileName = "$verz$neu";
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheet = $objPHPExcel->getActiveSheet()->toArray(null, true, false, true);
$highestColumm = $objPHPExcel->setActiveSheetIndex(0)->getHighestColumn();
$highestRow = $objPHPExcel->setActiveSheetIndex(0)->getHighestRow();
# Ab dem Tag rechnet Excel intern
$datum = '30.12.1899';
for ($i = 1; $i <= $highestRow; $i++) {
$vorname = $sheet[$i]['A'];
$nachname = $sheet[$i]['B'];
$religionskenner = $sheet[$i]['C'];
$eingangsjahr = $sheet[$i]['D'];
$klassenzusatz = $sheet[$i]['E'];
$gebdat = date('m.d.Y', strtotime($sheet[$i]['F']));
$gebdat = date("d.m.Y", $sheet[$i]['F']);
$gebdatx = $sheet[$i]['F'];
# $gebdat = date('d.m.Y', strtotime($datum . ' + ' . $gebdatx . ' days'));
$gebdat = substr($gebdatx,0,2).".".substr($gebdatx,3,2).".".substr($gebdatx,6,4);
# $gebdat2 = date('Y-m-d', strtotime($datum . ' + ' . $gebdatx . ' days'));
$gebdat2 = substr($gebdatx,6,4)."-".substr($gebdatx,3,2)."-".substr($gebdatx,0,2);
$tag = substr($gebdat2, 8, 2);
$mon = substr($gebdat2, 5, 2);
$jahr = substr($gebdat2, 0, 4);
$passwd = md5("$tag" . "$mon" . "$jahr");
if ($nachname != '') {
if ($religionskenner == 'RK' or $religionskenner == 'EV') {
$religionspflicht = 'J';
} else {
$religionspflicht = 'N';
}
$uid = genUser_schueler($vorname, $nachname);
//$passwd = mysql_escape_string($passwd);
#echo "SELECT count(*) Anz FROM users WHERE vorname='$vorname' AND nachname='$nachname' AND geburtstag='$gebtag'<br>";
$result_vorh = $db->query("SELECT count(*) Anz FROM users WHERE vorname='$vorname' AND nachname='$nachname' AND geburtstag='$gebtag2'");
$row_vorh = $result_vorh->fetch_array();
if ($row_vorh['Anz'] == 0) {
// ACHTUNG: AN DIESER ZEILE NICHTS &Auml;NDERN, da die erste Zeile des Strings rausgefiltert wird bei der Ausgabe der nichtimportierten DS
$insert = "INSERT INTO users (user, vorname, nachname, religionspflicht, religionskenner, jahrgang, klassenzusatz, passwort, geburtstag) VALUES ( lower('$uid')
,'$vorname'
,'$nachname'
,'$religionspflicht'
,'$religionskenner'
,'$eingangsjahr'
,'$klassenzusatz'
,'$passwd'
,'$gebdat2'
)";
$sql = $db->query("$insert");
if (!$sql) {
# Bei Fehler
$unimported[] = $insert[$i];
}
} else {
$result_vorh1 = $db->query("SELECT user FROM users WHERE vorname='$vorname' AND nachname='$nachname' AND geburtstag='$gebtag'");
$row_vorh1 = $result_vorh1->fetch_array();
$ber_vorh[] = "$row_vorh1[user]'";
}
}
}
$dateiname = "$verz$neu";
if (@unlink($dateiname)) // Funktion l&ouml;scht Dateien und gibt true / false zur&uuml;ck
{
if (isset($unimported)) {
$imp_err = str_replace(array(
"INSERT INTO users (user, vorname, nachname, religionspflicht, religionskenner, jahrgang, passwort, geburtstag) VALUES ( lower('"
), array(
""
), $unimported);
}
if (sizeof($imp_err) > 0 AND sizeof($ber_vorh) > 0) {
# Array zusaamenführen aus bereits vorhandenen Schülern und fehlerhaftem Insert
$ausgabe = array_merge($imp_err, $ber_vorh);
}
if (sizeof($imp_err) > 0 AND sizeof($ber_vorh) == 0) {
$ausgabe = $imp_err;
}
if (sizeof($imp_err) == 0 AND sizeof($ber_vorh) > 0) {
$ausgabe = $ber_vorh;
}
echo "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Import beendet</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\"></td>
<td width=\"95%\" background=\"../../templates/standard/images/box_top.gif\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<span class=\"sh\">Importvorgang erfolgreich</span><br>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td colspan=\"2\"><br>
<p align=\"center\">Der Importvorgang wurde erfolgreich beendet!<br>Die Excel-Datei wurde vom Server gel&ouml;scht!
</p>";
$num1 = count($ausgabe); // Anzahl der nicht importierten UIDs
if ($ausgabe != "") {
echo "Es wurden $num1 Datens&auml;tze nicht importiert<br>
Wahrscheinlich ist die UID bereits in der Datenbank vorhanden,<br>
oder eines der Felder ist zu lang:
<p>";
}
// Ausgabe der nicht importierten DS
for ($i = 0; $i < sizeof($ausgabe); $i++) {
$b = strpos($ausgabe[$i], "'");
$e = substr($ausgabe[$i], 0, $b);
print strtolower($e); // Ausgabe der nicht importierten UIDs
echo "<br>";
}
echo "
<p align=\"center\"><a href=\"../hauptframe.php\">
<img border=\"0\" src=\"../../templates/standard/images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p><br>
</p>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\" colspan=\"2\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
} else {
echo "
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">
<link rel=\"stylesheet\" href=\"../../templates/standard/css/styles_pc.php\" type=\"text/css\">
<title>Datei nicht gel&ouml;scht</title>
</head>
<body>
<table border=\"0\" style=\"border-collapse: collapse\" width=\"100%\" cellpadding=\"0\" height=\"100%\" id=\"table1\">
<tr>
<td>
<div align=\"center\">
<table cellspacing=\"0\" cellpadding=\"0\" width=\"550\" border=\"0\">
<tr>
<td width=\"10\" background=\"../../templates/standard/images/box_e1.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"3%\" background=\"../../templates/standard/images/box_top.gif\" valign=\"top\"></td>
<td width=\"95%\" background=\"../../templates/standard/images/box_top.gif\">
<img height=\"10\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"><br>
<span class=\"sh\">Importvorgang erfolgreich</span><br>
<img height=\"5\" src=\"../../templates/standard/images/blank.gif\" width=\"1\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e2.gif\">
<img height=\"40\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td width=\"1%\" background=\"../../templates/standard/images/box_l.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td colspan=\"2\"><br>
<p align=\"center\">Der Importvorgang wurde erfolgreich beendet!<br>Die Excel-Datei ($neu) konnte <b>nicht</b> vom Server gel&ouml;scht werden!
</p>";
$num1 = count($ausgabe); // Anzahl der nicht importierten UIDs
if ($ausgabe != "") {
echo "Es wurden $num1 Datens&auml;tze nicht importiert<br>
Wahrscheinlich ist die UID bereits in der Datenbank vorhanden,<br>
oder eines der Felder ist zu lang:
<p>";
}
// Ausgabe der nicht importierten DS
for ($i = 0; $i < sizeof($ausgabe); $i++) {
$b = strpos($ausgabe[$i], "'");
$e = substr($ausgabe[$i], 0, $b);
print strtolower($e); // Ausgabe der nicht importierten UIDs
echo "<br>";
}
echo "
<p align=\"center\"><a href=\"../hauptframe.php\">
<img border=\"0\" src=\"../../templates/standard/images/zurueck.gif\" width=\"77\" height=\"22\"></a><br>
</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p><br>
</p>
</td>
<td width=\"1%\" background=\"../../templates/standard/images/box_r.gif\">
<img height=\"1\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
</tr>
<tr>
<td nowrap=\"nowrap\" align=\"left\" width=\"1%\" background=\"../../templates/standard/images/box_e3.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"></td>
<td nowrap=\"nowrap\" align=\"left\" width=\"98%\" background=\"../../templates/standard/images/box_bottom.gif\" colspan=\"2\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"8\"></td>
<td nowrap=\"nowrap\" align=\"right\" width=\"1%\" background=\"../../templates/standard/images/box_e4.gif\">
<img height=\"16\" src=\"../../templates/standard/images/blank.gif\" width=\"22\"> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</body>
</html>";
} // End if
} else { // Es wurde kein Radiobutton gew&auml;hlt! Technisch aber ausgeschlossen
echo "sie m&uuml;ssen eine Auswahl treffen";
}
function deleteFiles($verz)
{
$handle = opendir($verz);
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
$datei = $verz . $file;
if (@unlink($datei)) {
$error = TRUE;
} else {
$error = FALSE;
}
}
}
closedir($handle);
return $error;
}
deleteFiles($verz); // Dateien werden im Uploadverzeichnis gel&ouml;scht, falls noch welche darin w&auml;ren
} // ende Action
?>