PHP Code:
<?php
if (!isset($_POST['eintragen'])) {
include('form.html');
exit; }
$server = "localhost";
$user = "root";
$pass = "";
$database = "testing_database";
$timestamp = time();
$date = date("mdHis", $timestamp);
$devtable = "Device_id".$date;
$verbindung = mysql_connect($server, $user, $pass)
or die ("Verbindung zur Datenbank nicht möglich");
mysql_select_db($database, $verbindung);
$layertype = $_POST['layertype1']."_".$_POST['layertype2'];
$voicetype = $_POST['voicetype1']."_".$_POST['voicetype2'];
$dsltype = $_POST['dsltype1']."_".$_POST['dsltype2']."_".$_POST['dsltype3'];
$layertype1 = $_POST['layertype1'];
$layertype2 = $_POST['layertype2'];
$voicetype1 = $_POST['voicetype1'];
$voicetype2 = $_POST['voicetype2'];
$dsltype1 = $_POST['dsltype1'];
$dsltype2 = $_POST['dsltype2'];
$dsltype3 = $_POST['dsltype3'];
function InsertEquipment($name) {
$sql = "CREATE TABLE $name
( type text, vendor text, model text, version text, serial texT, details text)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
}
function createTabelle($LT,$VT,$DT,$ID) {
$inv = $LT."_".$VT."_".$DT."_"."INV_ID".$ID;
$inv_eq = $LT."_".$VT."_".$DT."_"."INV_EQ_ID".$ID;
$pt_hn = $LT."_".$VT."_".$DT."_"."PT_HN_ID".$ID;
$pt_hn_eq = $LT."_".$VT."_".$DT."_"."PT_HN_EQ_ID".$ID;
$pt_ln = $LT."_".$VT."_".$DT."_"."PT_LN_ID".$ID;
$pt_ln_eq = $LT."_".$VT."_".$DT."_"."PT_LN_EQ_ID".$ID;
$bs = $LT."_".$VT."_".$DT."_"."BS_ID".$ID;
$bs_eq = $LT."_".$VT."_".$DT."_"."BS_EQ_ID".$ID;
$recimp = $LT."_".$VT."_".$DT."_"."RECIMP_ID".$ID;
$recimp_eq = $LT."_".$VT."_".$DT."_"."RECIMP_EQ_ID".$ID;
$psd = $LT."_".$VT."_".$DT."_"."PSD_ID".$ID;
$psd_eq = $LT."_".$VT."_".$DT."_"."PSD_EQ_ID".$ID;
InsertEquipment($inv_eq);
InsertEquipment($pt_hn_eq);
InsertEquipment($pt_ln_eq);
InsertEquipment($bs_eq);
InsertEquipment($recimp_eq);
InsertEquipment($psd_eq);
$sql = "CREATE TABLE $inv
(
chipsetVendorId text,
chipsetCountryCode text,
chipsetVendorCode text,
chipsetDetails text,
systemVendorId text,
systemCountryCode text,
systemVendorCode text,
systemDetails text,
chipsetVersionId text,
systemVersionId text
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
$sql = "CREATE TABLE $pt_hn
(
loopLength integer,
iteration integer,
noiseSide text,
adminState boolean,
operationState boolean,
rateUs integer,
rateDs integer,
attainableRateUs integer,
attainableRateDs integer,
inpUs float,
inpDs float,
operationMode text,
transferMode text,
reinitDay integer,
noiseMarginUs float,
noiseMarginDs float,
outputPowerUs float,
outputPowerDs float,
loopAttenuationUs float,
loopAttenuationDs float,
signalAttenuationUs float,
signalAttenuationDs float,
psdUs float,
psdDs float,
highFreqUs integer,
highFreqDs integer,
electricalLength float,
electricalLengthEstimate float,
noiseMarginU0 float,
noiseMarginD1 float,
noiseMarginU1 float,
noiseMarginD2 float,
noiseMarginU2 float,
noiseMarginU3 float,
noiseMarginD3 float,
loopAttenuationU0 float,
loopAttenuationD1 float,
loopAttenuationU1 float,
loopAttenuationD2 float,
loopAttenuationU2 float,
loopAttenuationU3 float,
loopAttenuationD3 float,
signalAttenuationU0 float,
signalAttenuationD1 float,
signalAttenuationU1 float,
signalAttenuationD2 float,
signalAttenuationU2 float,
signalAttenuationU3 float,
signalAttenuationD3 float,
factorAttToEffBitrateUs float,
factorAttToEffBitrateDs float,
syncTime integer
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
$sql = "CREATE TABLE $pt_ln
(
loopLength integer,
iteration integer,
noiseSide text,
adminState boolean,
operationState boolean,
rateUs integer,
rateDs integer,
attainableRateUs integer,
attainableRateDs integer,
inpUs float,
inpDs float,
operationMode text,
transferMode text,
reinitDay integer,
noiseMarginUs float,
noiseMarginDs float,
outputPowerUs float,
outputPowerDs float,
loopAttenuationUs float,
loopAttenuationDs float,
signalAttenuationUs float,
signalAttenuationDs float,
psdUs float,
psdDs float,
highFreqUs integer,
highFreqDs integer,
electricalLength float,
electricalLengthEstimate float,
noiseMarginU0 float,
noiseMarginD1 float,
noiseMarginU1 float,
noiseMarginD2 float,
noiseMarginU2 float,
noiseMarginU3 float,
noiseMarginD3 float,
loopAttenuationU0 float,
loopAttenuationD1 float,
loopAttenuationU1 float,
loopAttenuationD2 float,
loopAttenuationU2 float,
loopAttenuationU3 float,
loopAttenuationD3 float,
signalAttenuationU0 float,
signalAttenuationD1 float,
signalAttenuationU1 float,
signalAttenuationD2 float,
signalAttenuationU2 float,
signalAttenuationU3 float,
signalAttenuationD3 float,
factorAttToEffBitrateUs float,
factorAttToEffBitrateDs float,
syncTime integer
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
$sql = "CREATE TABLE $bs
(
loopLength integer,
noiseChannelUs text,
noiseChannelDs text,
gain integer,
Bitloading text,
noiseStep integer,
minimumLevel integer
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
$sql = "CREATE TABLE $recimp
(
loopLength integer,
noiseChannelUs text,
noiseChannelDs text,
noiseMarginUs integer,
noiseMarginDs integer,
gain integer
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
$sql = "CREATE TABLE $psd
(
loopLength integer,
side text,
frequency1 integer,
psdValue1 integer,
frequency2 integer,
psdValue2 integer,
frequency3 integer,
psdValue3 integer,
frequency4 integer,
psdValue4 integer,
frequency5 integer,
psdValue5 integer,
frequency6 integer,
psdValue6 integer,
frequency7 integer,
psdValue7 integer
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
}
$sql = "CREATE TABLE $devtable
(
Layer_Type text not null,
Name text not null,
Model text not null,
Firmware text not null,
Datapump text not null,
Voice_Type text not null,
DSL_Type text not null
)";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
$sql= "INSERT INTO $devtable (Layer_Type, Name, Model, Firmware, Datapump, Voice_Type, DSL_Type)
VALUES
('$layertype','$_POST[name]','$_POST[model]','$_POST[firmware]','$_POST[datapump]','$voicetype','$dsltype')";
mysql_query($sql) or die ("Fehler, bitte den Datentyp und die Laenge des Texts einhalten. Eventuell ID schon vergeben. Zurueck um einen weiteren Eintrag zu erfassen.");
if (isset($layertype1))
{
if (isset($voicetype1))
{
if (isset($dsltype1))
{ createTabelle($layertype1,$voicetype1,$dsltype1,$date); }
if (isset($dsltype2))
{ createTabelle($layertype1,$voicetype1,$dsltype2,$date); }
if (isset($dsltype3))
{ createTabelle($layertype1,$voicetype1,$dsltype3,$date); }
}
if (isset($voicetype2))
{
if (isset($dsltype1))
{ createTabelle($layertype1,$voicetype2,$dsltype1,$date); }
if (isset($dsltype2))
{ createTabelle($layertype1,$voicetype2,$dsltype2,$date); }
if (isset($dsltype3))
{ createTabelle($layertype1,$voicetype2,$dsltype3,$date); }
}
}
$handle = fopen ( "resultat.txt", "w" );
fwrite ( $handle, "ID: ");
fwrite ( $handle, $date );
fwrite ( $handle, "\r\n" );
fwrite ( $handle, "Layer Type: ");
if (isset($layertype1))
{
fwrite ( $handle, $_POST['layertype1'].";" );
}
elseif (!isset($layertype1))
{
fwrite ( $handle, "none;" );
}
if (isset($layertype2))
{
fwrite ( $handle, $_POST['layertype2'] );
fwrite ( $handle, "\r\n" );
}
elseif (!isset($layertype2))
{
fwrite ( $handle, "none" );
fwrite ( $handle, "\r\n" );
}
fwrite ( $handle, "Name: ");
fwrite ( $handle, $_POST['name'] );
fwrite ( $handle, "\r\n" );
fwrite ( $handle, "Model: ");
fwrite ( $handle, $_POST['model'] );
fwrite ( $handle, "\r\n" );
fwrite ( $handle, "Firmware: ");
fwrite ( $handle, $_POST['firmware'] );
fwrite ( $handle, "\r\n" );
fwrite ( $handle, "Datapump: ");
fwrite ( $handle, $_POST['datapump'] );
fwrite ( $handle, "\r\n" );
fwrite ( $handle, "Voice Type: ");
if (isset($voicetype1))
{
fwrite ( $handle, $_POST['voicetype1'].";" );
}
elseif (!isset($voicetype1))
{
fwrite ( $handle, "none;" );
}
if (isset($voicetype2))
{
fwrite ( $handle, $_POST['voicetype2'] );
fwrite ( $handle, "\r\n" );
}
elseif (!isset($voicetype2))
{
fwrite ( $handle, "none" );
fwrite ( $handle, "\r\n" );
}
fwrite ( $handle, "DSL Type: ");
if (isset($dsltype1))
{
fwrite ( $handle, $_POST['dsltype1'].";" );
}
elseif (!isset($dsltype1))
{
fwrite ( $handle, "none;" );
}
if (isset($dsltype2))
{
fwrite ( $handle, $_POST['dsltype2'].";" );
}
elseif (!isset($dsltype2))
{
fwrite ( $handle, "none;" );
}
if (isset($dsltype3))
{
fwrite ( $handle, $_POST['dsltype3'] );
fwrite ( $handle, "\r\n" );
}
elseif (!isset($dsltype3))
{
fwrite ( $handle, "none" );
fwrite ( $handle, "\r\n" );
}
mkdir("/xampp/htdocs/Struktur/".$_POST['name'], 0777);
mkdir("/xampp/htdocs/Struktur/".$_POST['name']."/".$_POST['model'], 0777);
mkdir("/xampp/htdocs/Struktur/".$_POST['name']."/".$_POST['model']."/".$layertype, 0777);
if (isset($voicetype1,$voicetype2))
mkdir("/xampp/htdocs/Struktur/".$_POST['name']."/".$_POST['model']."/".$layertype."/".$voicetype1, 0777);
mkdir("/xampp/htdocs/Struktur/".$_POST['name']."/".$_POST['model']."/".$layertype."/".$voicetype2, 0777);
if (!isset($voicetype1,$voicetype2))
mkdir("/xampp/htdocs/Struktur/".$_POST['name']."/".$_POST['model']."/".$layertype."/".$voicetype, 0777);
$ausgabe = "Die Eingaben wurden erfolgreich in die Datenbank aufgenommen. Zurueck um einen weiteren Eintrag zu erfassen.";
mysql_close($verbindung);
echo $ausgabe;
Bookmarks